Ignore:
Timestamp:
Apr 16, 2020, 7:40:38 PM (4 years ago)
Author:
chronos
Message:
  • Fixed: Memory leaks.
Location:
branches/interpreter2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2

    • Property svn:ignore set to
      lib
      interpreter
      interpreter.lps
      interpreter.res
      heaptrclog.trc
  • branches/interpreter2/USource.pas

    r200 r201  
    3030  TConstants = class(TObjectList)
    3131    function SearchByName(Name: string): TConstant;
     32    function AddNew(Name: string): TConstant;
    3233  end;
    3334
     
    6667
    6768  TExpression = class
    68     Variable: TVariable;
    69     Constant: TConstant;
     69    VariableRef: TVariable;
     70    ConstantRef: TConstant;
    7071    FunctionCall: TFunctionCall;
    7172  end;
     
    7374  TExpressions = class(TObjectList)
    7475  end;
     76
     77  { TAssignment }
    7578
    7679  TAssignment = class(TCommand)
    7780    Variable: TVariable;
    7881    Expression: TExpression;
    79   end;
     82    constructor Create;
     83    destructor Destroy; override;
     84  end;
     85
     86  { TIfThenElse }
    8087
    8188  TIfThenElse = class(TCommand)
     
    8390    CommandThen: TCommand;
    8491    CommandElse: TCommand;
    85   end;
     92    constructor Create;
     93    destructor Destroy; override;
     94  end;
     95
     96  { TWhileDo }
    8697
    8798  TWhileDo = class(TCommand)
    8899    Expression: TExpression;
    89100    Command: TCommand;
     101    constructor Create;
     102    destructor Destroy; override;
    90103  end;
    91104
     
    98111    Functions: TFunctions;
    99112    BeginEnd: TBeginEnd;
     113    procedure Clear;
    100114    function GetFunction(Name: string): TFunction;
    101115    constructor Create;
     
    116130implementation
    117131
     132{ TAssignment }
     133
     134constructor TAssignment.Create;
     135begin
     136  Variable := nil;
     137  Expression := TExpression.Create;
     138end;
     139
     140destructor TAssignment.Destroy;
     141begin
     142  Variable := nil;
     143  Expression.Free;
     144  inherited Destroy;
     145end;
     146
     147{ TIfThenElse }
     148
     149constructor TIfThenElse.Create;
     150begin
     151  Expression := TExpression.Create;
     152  CommandThen := TCommand.Create;
     153  CommandElse := TCommand.Create;
     154end;
     155
     156destructor TIfThenElse.Destroy;
     157begin
     158  Expression.Free;
     159  CommandThen.Free;
     160  CommandElse.Free;
     161  inherited Destroy;
     162end;
     163
     164{ TWhileDo }
     165
     166constructor TWhileDo.Create;
     167begin
     168  Expression := TExpression.Create;
     169  Command := TCommand.Create;
     170end;
     171
     172destructor TWhileDo.Destroy;
     173begin
     174  Expression.Free;
     175  Command.Free;
     176  inherited Destroy;
     177end;
     178
    118179{ TFunctionCall }
    119180
     
    160221end;
    161222
     223function TConstants.AddNew(Name: string): TConstant;
     224begin
     225  Result := TConstant.Create;
     226  Result.Name := Name;
     227  Add(Result);
     228end;
     229
    162230{ TVariables }
    163231
     
    174242{ TBlock }
    175243
     244procedure TBlock.Clear;
     245begin
     246  Functions.Clear;
     247  Constants.Clear;
     248  Variables.Clear;
     249end;
     250
    176251function TBlock.GetFunction(Name: string): TFunction;
    177252begin
Note: See TracChangeset for help on using the changeset viewer.