Changeset 93 for branches/dcomp


Ignore:
Timestamp:
Nov 4, 2016, 9:17:57 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Use generic lists in supported analyzers and parsers.
  • Fixed: Build under Delphi.
Location:
branches/dcomp/CmdLine
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/dcomp/CmdLine/Compiler/UAnalyzerPascal.pas

    r92 r93  
    11unit UAnalyzerPascal;
    2 
    3 {$mode delphi}
    42
    53interface
  • branches/dcomp/CmdLine/Compiler/UCompiler.pas

    r92 r93  
    44
    55uses
    6   SysUtils, UAnalyzer, UTarget;
     6  SysUtils, Generics.Collections, UAnalyzer, UTarget;
    77
    88type
     
    1111
    1212  TCompiler = class
    13     Analyzers: array of TAnalyzer;
    14     Targets: array of TTarget;
     13    SupportedAnalyzers: TObjectList<TAnalyzer>;
     14    SupportedTargets: TObjectList<TTarget>;
    1515    Analyzer: TAnalyzer;
    1616    Target: TTarget;
     17    MainSourceFile: string;
    1718    procedure Compile;
    1819    procedure RegisterTarget(TargetClass: TTargetClass);
    1920    procedure RegisterAnalyzer(AnalyzerClass: TAnalyzerClass);
     21    constructor Create;
     22    destructor Destroy; override;
    2023  end;
    2124
     
    3336procedure TCompiler.RegisterTarget(TargetClass: TTargetClass);
    3437begin
    35   SetLength(Targets, Length(Targets) + 1);
    36   Targets[Length(Targets) - 1] := TargetClass.Create;
     38  SupportedTargets.Add(TargetClass.Create);
    3739  if not Assigned(Target) then
    38     Target := Targets[Length(Targets) - 1];
     40    Target := SupportedTargets.Last;
     41end;
     42
     43constructor TCompiler.Create;
     44begin
     45  SupportedTargets := TObjectList<TTarget>.Create;
     46  SupportedAnalyzers := TObjectList<TAnalyzer>.Create;
     47end;
     48
     49destructor TCompiler.Destroy;
     50begin
     51  SupportedTargets.Free;
     52  SupportedAnalyzers.Free;
     53  inherited;
    3954end;
    4055
    4156procedure TCompiler.RegisterAnalyzer(AnalyzerClass: TAnalyzerClass);
    4257begin
    43   SetLength(Analyzers, Length(Analyzers) + 1);
    44   Analyzers[Length(Analyzers) - 1] := AnalyzerClass.Create;
     58  SupportedAnalyzers.Add(AnalyzerClass.Create);
    4559  if not Assigned(Analyzer) then
    46     Analyzer := Analyzers[Length(Analyzers) - 1];
     60    Analyzer := SupportedAnalyzers.Last;
    4761end;
    4862
  • branches/dcomp/CmdLine/dcomp.dpr

    r92 r93  
    11program dcomp;
    22
     3{$APPTYPE CONSOLE}
     4
    35uses
    4   UCompiler, UTargetPHP, UAnalyzerPascal;
     6  System.SysUtils,
     7  UCompiler in 'Compiler\UCompiler.pas',
     8  UTargetPHP in 'TargetPHP\UTargetPHP.pas',
     9  UAnalyzerPascal in 'Compiler\UAnalyzerPascal.pas',
     10  UAnalyzer in 'Compiler\UAnalyzer.pas',
     11  UTarget in 'Compiler\UTarget.pas';
    512
     13type
     14  TApplication = class
     15    procedure Run;
     16  end;
     17
     18{ TApplication }
     19
     20procedure TApplication.Run;
    621var
    722  Compiler: TCompiler;
    823begin
    924  Compiler := TCompiler.Create;
     25  if ParamCount > 0 then
     26    Compiler.MainSourceFile := ParamStr(1);
    1027  Compiler.RegisterTarget(TTargetPHP);
    1128  Compiler.RegisterAnalyzer(TAnalyzerPascal);
    1229  Compiler.Compile;
    13   Compiler.Free;
     30end;
     31
     32var
     33  Application: TApplication;
     34begin
     35  try
     36    Application := TApplication.Create;
     37    Application.Run;
     38    Application.Free;
     39    ReadLn;
     40    { TODO -oUser -cConsole Main : Insert code here }
     41  except
     42    on E: Exception do
     43      Writeln(E.ClassName, ': ', E.Message);
     44  end;
    1445end.
     46
Note: See TracChangeset for help on using the changeset viewer.