Changeset 145


Ignore:
Timestamp:
Jan 17, 2018, 1:11:56 PM (6 years ago)
Author:
chronos
Message:
  • Added: Check memory leaks in debug build mode.
  • Fixed: Various memory leaks.
Location:
branches/easy compiler
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/easy compiler

    • Property svn:ignore
      •  

        old new  
        22*.exe
        33*.lps
         4heaptrclog.trc
  • branches/easy compiler/UCompiler.pas

    r142 r145  
    262262          for Param in Funct.Parameters do
    263263          if Param.Kind = pkString then begin
    264             TSourceFunctionCall(Instruction).AddParameter(ParseReference)
     264            TSourceFunctionCall(Instruction).Parameters.Add(ParseReference)
    265265          end else
    266266          if Param.Kind = pkVariable then begin
    267             TSourceFunctionCall(Instruction).AddParameter(ParseReferenceVariable(True));
     267            TSourceFunctionCall(Instruction).Parameters.Add(ParseReferenceVariable(True));
    268268          end else
    269269          raise Exception.Create('Unsupported parameter type.');
  • branches/easy compiler/UFormMain.pas

    r142 r145  
    5151procedure TForm1.FormShow(Sender: TObject);
    5252begin
    53   with MemoSource.Lines do begin
     53{  with MemoSource.Lines do begin
     54    Add('var I Integer');
     55    Add('Assign I 10');
     56    Add('Repeat');
     57    Add('Begin');
     58    Add('Decrement I 1');
     59    Add('IfZero I');
     60    Add('Break');
     61    Add('End');
     62  end;
     63 } with MemoSource.Lines do begin
    5464    Add('PrintLn ''Super Calculator''');
    5565    Add('var Value1 Integer');
     
    6373    Add('InputLn Value2');
    6474
    65     Add('begin');
    6675    Add('Assign Result Value1');
    6776    Add('Increment Result Value2');
    6877    Add('Print ''Sum of two values is: ''');
    6978    Add('PrintLn Result');
    70     Add('end');
    7179  end;
    7280{  with MemoSource.Lines do begin
  • branches/easy compiler/USourceCode.pas

    r143 r145  
    1616
    1717  TSourceReference = class
     18  end;
     19
     20  TSourceReferences = class(TObjectList)
    1821  end;
    1922
     
    7477  end;
    7578
     79  { TSourceConstant }
     80
    7681  TSourceConstant = class
    7782    Name: string;
    7883    Value: TSourceValue;
     84    destructor Destroy; override;
    7985  end;
    8086
     
    123129  TSourceFunctionCall = class(TSourceInstruction)
    124130    Name: string;
    125     Parameters: array of TSourceReference;
    126     procedure AddParameter(Value: TSourceReference);
     131    Parameters: TSourceReferences;
     132    constructor Create;
     133    destructor Destroy; override;
    127134  end;
    128135
     
    156163implementation
    157164
     165{ TSourceConstant }
     166
     167destructor TSourceConstant.Destroy;
     168begin
     169  Value.Free;
     170  inherited Destroy;
     171end;
     172
     173{ TSourceFunctionCall }
     174
     175constructor TSourceFunctionCall.Create;
     176begin
     177  Parameters := TSourceReferences.Create;
     178end;
     179
     180destructor TSourceFunctionCall.Destroy;
     181begin
     182  Parameters.Free;
     183  inherited Destroy;
     184end;
     185
    158186{ TSourceBeginEnd }
    159187
     
    324352
    325353{ TSourceFunctionCall }
    326 
    327 procedure TSourceFunctionCall.AddParameter(Value: TSourceReference);
    328 begin
    329   SetLength(Parameters, Length(Parameters) + 1);
    330   Parameters[Length(Parameters) - 1] := Value;
    331 end;
    332354
    333355{ TSourceCode }
  • branches/easy compiler/USourceExecutor.pas

    r144 r145  
    1212  TInputEvent = function: string of object;
    1313
     14  { TExecutorVariable }
     15
    1416  TExecutorVariable = class
    1517    Variable: TSourceVariable;
    1618    Value: TSourceValue;
     19    destructor Destroy; override;
    1720  end;
    1821
     
    3942
    4043implementation
     44
     45{ TExecutorVariable }
     46
     47destructor TExecutorVariable.Destroy;
     48begin
     49  Value.Free;
     50  inherited Destroy;
     51end;
    4152
    4253
     
    110121      if Name = 'print' then begin
    111122        if Assigned(FOnOutput) then begin
    112           Value := ReadValueReference(Parameters[0]);
     123          Value := ReadValueReference(TSourceReference(Parameters[0]));
    113124          if Value is TSourceValueString then
    114125            FOnOutput(TSourceValueString(Value).Value)
     
    120131      if Name = 'println' then begin
    121132        if Assigned(FOnOutput) then begin
    122           Value := ReadValueReference(Parameters[0]);
     133          Value := ReadValueReference(TSourceReference(Parameters[0]));
    123134          if Value is TSourceValueString then
    124135            FOnOutput(TSourceValueString(Value).Value + LineEnding)
     
    130141      if Name = 'inputln' then begin
    131142        if Assigned(FOnInput) then begin
    132           Variable := ReadVarReference(Parameters[0]);
     143          Variable := ReadVarReference(TSourceReference(Parameters[0]));
    133144          ExecutorVar := Variables.Search(Variable);
    134145          if ExecutorVar.Value is TSourceValueString then begin
     
    147158      end else
    148159      if Name = 'assign' then begin
    149         Variable := ReadVarReference(Parameters[0]);
    150         Value := ReadValueReference(Parameters[1]);
     160        Variable := ReadVarReference(TSourceReference(Parameters[0]));
     161        Value := ReadValueReference(TSourceReference(Parameters[1]));
    151162        ExecutorVar := Variables.Search(Variable);
    152163        if not Assigned(ExecutorVar) then begin
     
    159170      end else
    160171      if Name = 'increment' then begin
    161         Variable := ReadVarReference(Parameters[0]);
    162         Value := ReadValueReference(Parameters[1]);
     172        Variable := ReadVarReference(TSourceReference(Parameters[0]));
     173        Value := ReadValueReference(TSourceReference(Parameters[1]));
    163174        ExecutorVar := Variables.Search(Variable);
    164175        if not Assigned(ExecutorVar) then raise Exception.Create('Variable not found');
  • branches/easy compiler/USourceGenerator.pas

    r143 r145  
    8181    with TSourceFunctionCall(Instruction) do begin
    8282      if Name = 'print' then begin
    83         Result := Result + IndentStr + 'Write(' + GenerateRef(Parameters[0]) + ');' +
     83        Result := Result + IndentStr + 'Write(' + GenerateRef(TSourceReference(Parameters[0])) + ');' +
    8484          LineEnding;
    8585      end else
    8686      if Name = 'println' then begin
    87         Result := Result + IndentStr + 'WriteLn(' + GenerateRef(Parameters[0]) + ');' +
     87        Result := Result + IndentStr + 'WriteLn(' + GenerateRef(TSourceReference(Parameters[0])) + ');' +
    8888          LineEnding;
    8989      end else
    9090      if Name = 'assign' then begin
    91         Result := Result + IndentStr + GenerateRef(Parameters[0]) + ' := ' +
    92           GenerateRef(Parameters[1]) + ';' + LineEnding;
     91        Result := Result + IndentStr + GenerateRef(TSourceReference(Parameters[0])) + ' := ' +
     92          GenerateRef(TSourceReference(Parameters[1])) + ';' + LineEnding;
    9393      end else
    9494      if Name = 'inputln' then begin
    95         Result := Result + IndentStr + 'ReadLn(' + GenerateRef(Parameters[0]) + ');' + LineEnding;
     95        Result := Result + IndentStr + 'ReadLn(' + GenerateRef(TSourceReference(Parameters[0])) + ');' + LineEnding;
    9696      end else
    9797      if Name = 'increment' then begin
    98         Result := Result + IndentStr + 'Inc(' + GenerateRef(Parameters[0]) + ', ' +
    99           GenerateRef(Parameters[1]) + ');' + LineEnding;
     98        Result := Result + IndentStr + 'Inc(' + GenerateRef(TSourceReference(Parameters[0])) + ', ' +
     99          GenerateRef(TSourceReference(Parameters[1])) + ');' + LineEnding;
    100100      end else
    101101      raise Exception.Create('Unsupported instruction name.');
  • branches/easy compiler/project1.lpi

    r140 r145  
    1212      <Icon Value="0"/>
    1313    </General>
    14     <BuildModes Count="1">
    15       <Item1 Name="Default" Default="True"/>
     14    <BuildModes Count="2">
     15      <Item1 Name="Debug" Default="True"/>
     16      <Item2 Name="Release">
     17        <CompilerOptions>
     18          <Version Value="11"/>
     19          <PathDelim Value="\"/>
     20          <Target>
     21            <Filename Value="project1"/>
     22          </Target>
     23          <SearchPaths>
     24            <IncludeFiles Value="$(ProjOutDir)"/>
     25            <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     26          </SearchPaths>
     27          <Parsing>
     28            <SyntaxOptions>
     29              <SyntaxMode Value="Delphi"/>
     30              <CStyleOperator Value="False"/>
     31              <AllowLabel Value="False"/>
     32              <CPPInline Value="False"/>
     33            </SyntaxOptions>
     34          </Parsing>
     35          <CodeGeneration>
     36            <SmartLinkUnit Value="True"/>
     37            <Optimizations>
     38              <OptimizationLevel Value="3"/>
     39            </Optimizations>
     40          </CodeGeneration>
     41          <Linking>
     42            <Debugging>
     43              <GenerateDebugInfo Value="False"/>
     44            </Debugging>
     45            <LinkSmart Value="True"/>
     46            <Options>
     47              <Win32>
     48                <GraphicApplication Value="True"/>
     49              </Win32>
     50            </Options>
     51          </Linking>
     52          <Other>
     53            <CompilerMessages>
     54              <IgnoredMessages idx5024="True"/>
     55            </CompilerMessages>
     56          </Other>
     57        </CompilerOptions>
     58      </Item2>
    1659    </BuildModes>
    1760    <PublishOptions>
     
    75118      <SyntaxOptions>
    76119        <SyntaxMode Value="Delphi"/>
     120        <CStyleOperator Value="False"/>
    77121        <IncludeAssertionCode Value="True"/>
     122        <AllowLabel Value="False"/>
     123        <CPPInline Value="False"/>
    78124      </SyntaxOptions>
    79125    </Parsing>
     
    88134    </CodeGeneration>
    89135    <Linking>
     136      <Debugging>
     137        <UseHeaptrc Value="True"/>
     138      </Debugging>
    90139      <Options>
    91140        <Win32>
     
    98147        <IgnoredMessages idx5024="True"/>
    99148      </CompilerMessages>
     149      <CustomOptions Value="-dDEBUG"/>
    100150    </Other>
    101151  </CompilerOptions>
  • branches/easy compiler/project1.lpr

    r140 r145  
    99  Interfaces, // this includes the LCL widgetset
    1010  Forms, UFormMain, UCompiler, USourceCode, UTargetCode, USourceExecutor, USourceGenerator
    11   { you can add units after this };
    12 
     11  { you can add units after this },
     12  SysUtils;
    1313{$R *.res}
    1414
     15{$IFDEF DEBUG}
     16const
     17  HeapTraceLog = 'heaptrclog.trc';
     18{$ENDIF}
     19
     20
    1521begin
     22  {$IFDEF DEBUG}
     23  // Heap trace
     24  DeleteFile(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     25  SetHeapTraceOutput(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     26  {$ENDIF}
     27
    1628  RequireDerivedFormResource:=True;
    1729  Application.Initialize;
Note: See TracChangeset for help on using the changeset viewer.