Changeset 92 for branches/dcomp


Ignore:
Timestamp:
Nov 4, 2016, 4:25:29 PM (8 years ago)
Author:
chronos
Message:
  • Added: Allow to register analyzer.
Location:
branches/dcomp/CmdLine
Files:
1 added
3 edited

Legend:

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

    r91 r92  
    55type
    66  TAnalyzer = class
    7     procedure Analyze;
     7    procedure Analyze; virtual;
    88  end;
     9
     10  TAnalyzerClass = class of TAnalyzer;
    911
    1012implementation
  • branches/dcomp/CmdLine/Compiler/UCompiler.pas

    r91 r92  
    77
    88type
     9
     10  { TCompiler }
     11
    912  TCompiler = class
     13    Analyzers: array of TAnalyzer;
    1014    Targets: array of TTarget;
    1115    Analyzer: TAnalyzer;
     
    1317    procedure Compile;
    1418    procedure RegisterTarget(TargetClass: TTargetClass);
     19    procedure RegisterAnalyzer(AnalyzerClass: TAnalyzerClass);
    1520  end;
    1621
     
    1924procedure TCompiler.Compile;
    2025begin
     26  if Assigned(Analyzer) then Analyzer.Analyze
     27    else raise Exception.Create('Undefined analyzer');
    2128  if Assigned(Target) then Target.Produce
    2229    else raise Exception.Create('Undefined target');
     
    3239end;
    3340
     41procedure TCompiler.RegisterAnalyzer(AnalyzerClass: TAnalyzerClass);
     42begin
     43  SetLength(Analyzers, Length(Analyzers) + 1);
     44  Analyzers[Length(Analyzers) - 1] := AnalyzerClass.Create;
     45  if not Assigned(Analyzer) then
     46    Analyzer := Analyzers[Length(Analyzers) - 1];
     47end;
     48
    3449end.
  • branches/dcomp/CmdLine/dcomp.dpr

    r91 r92  
    22
    33uses
    4   UCompiler, UTargetPHP;
     4  UCompiler, UTargetPHP, UAnalyzerPascal;
    55
    66var
     
    99  Compiler := TCompiler.Create;
    1010  Compiler.RegisterTarget(TTargetPHP);
     11  Compiler.RegisterAnalyzer(TAnalyzerPascal);
    1112  Compiler.Compile;
    1213  Compiler.Free;
Note: See TracChangeset for help on using the changeset viewer.