Ignore:
Timestamp:
Nov 8, 2010, 10:06:37 AM (14 years ago)
Author:
george
Message:
  • Parser renamed to Analyzer.
  • Modified: Specialized parsers and analyzers separated from compiler for purpose of creating custom parsers and analyzers. Units UParsers and UAnalyzers determine which classes will be really used.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/UCompiler.pas

    r6 r12  
    66
    77uses
    8   SysUtils, Variants, Classes,
    9   Dialogs, USourceCode, UProducer, UPascalParser, UParser,
    10   UProducerDynamicC, Contnrs, UProducerTreeView, UProducerASM8051,
    11   UProducerPascal, UProducerGCCC;
     8  SysUtils, Variants, Classes, Contnrs, UAnalyzers, UProducers,
     9  Dialogs, USourceCode, UProducer, UAnalyzer;
    1210
    1311type
     
    3533  TCompiler = class
    3634  private
     35    FAnalyzer: TAnalyzer;
    3736    FOnErrorMessage: TErrorMessageEvent;
    3837    FProducerType: TProducerType;
    3938    procedure ErrorMessage(Text: string; Position: TPoint; FileName: string);
    40     procedure SetProducerType(const AValue: TProducerType);
     39    procedure SetAnalyzer(const AValue: TAnalyzer);
    4140  public
    4241    ProgramCode: TProgram;
    43     Parser: TPascalParser;
    4442    Producer: TProducer;
    4543    ErrorMessages: TObjectList;
     
    4846    Target: TCompilerTarget;
    4947    TargetFolder: string;
     48    Producers: TListProducer;
     49    Analyzers: TListAnalyzer;
    5050    constructor Create;
    5151    destructor Destroy; override;
     
    5454    property OnErrorMessage: TErrorMessageEvent read FOnErrorMessage
    5555      write FOnErrorMessage;
    56     property ProducerType: TProducerType read FProducerType
    57       write SetProducerType;
     56    property Analyzer: TAnalyzer read FAnalyzer write SetAnalyzer;
    5857  end;
    59 
    60 const
    61   ProducerTypeName: array[TProducerType] of string = (
    62     'GCC C', 'Rabbit Dynamic C', 'Generic Pascal', 'Assembler', 'XML');
    63   AnalyzerTypeName: array[TAnalyzerType] of string = (
    64     'Custom pascal', 'Delphi');
    6558
    6659implementation
     
    7770  try
    7871    ProducedCode := TStringList.Create;
    79     Parser.FileName := ModuleName;
    80     Parser.SourceCodeText := Source;
    81     Parser.Process;
    82     //ShowMessage(IntToHex(Integer(Addr(Parser.OnGetSource)), 8));
    83     Parser.ParseModule(ProgramCode);
     72    Analyzer.FileName := ModuleName;
     73    Analyzer.SourceCodeText := Source;
     74    Analyzer.Process;
     75    //ShowMessage(IntToHex(Integer(Addr(Analyzer.OnGetSource)), 8));
     76    Analyzer.ParseModule(ProgramCode);
    8477    with ProgramCode do
    8578    for I := 0 to Modules.Count - 1 do begin
     
    9992constructor TCompiler.Create;
    10093begin
     94  Analyzers := TListAnalyzer.Create;
     95  Producers := TListProducer.Create;
     96
     97  RegisterAnalyzers(Self);
     98  RegisterProducers(Self);
     99
    101100  SupportedTargets := TCompilerTargetList.Create;
    102101  SupportedTargets.Add('AMD', 'Athlon II', 'amd64');
     
    108107
    109108  ProgramCode := TProgram.Create;
    110   Producer := TProducerGCCC.Create;
    111   Parser := TPascalParser.Create;
    112   Parser.OnErrorMessage := ErrorMessage;
     109  Producer := nil;
     110  Analyzer := nil;
    113111  ErrorMessages := TObjectList.Create;
    114112  CompiledFolder := 'Compiled';
     
    124122begin
    125123  ProgramCode.Free;
    126   Parser.Free;
    127   Producer.Free;
     124  Analyzers.Free;
     125  Producers.Free;
    128126  ErrorMessages.Free;
    129127  SupportedTargets.Free;
     
    142140end;
    143141
    144 procedure TCompiler.SetProducerType(const AValue: TProducerType);
     142procedure TCompiler.SetAnalyzer(const AValue: TAnalyzer);
    145143begin
    146   if FProducerType = AValue then Exit;
    147   FProducerType := AValue;
    148   Producer.Free;
    149   case AValue of
    150     ptGCCC: Producer := TProducerGCCC.Create;
    151     ptDynamicC: Producer := TProducerDynamicC.Create;
    152     ptPascal: Producer := TProducerPascal.Create;
    153     ptAssembler: Producer := TProducerGCCC.Create;
    154     ptXML: Producer := TProducerTreeView.Create;
    155   end;
     144  if FAnalyzer = AValue then exit;
     145  FAnalyzer := AValue;
     146  if Assigned(Analyzer) then
     147    Analyzer.OnErrorMessage := ErrorMessage;
    156148end;
    157149
Note: See TracChangeset for help on using the changeset viewer.