Changeset 12 for trunk/Compiler


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.
Location:
trunk/Compiler
Files:
4 added
3 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/Produce/UProducer.pas

    r6 r12  
    22
    33{$MODE Delphi}
     4{$MACRO ON}
    45
    56interface
    67
    78uses
    8   USourceCode, Classes;
     9  USourceCode, Classes, SysUtils;
    910
    1011type
    1112  TProducer = class
     13    Name: string;
    1214    procedure AssignToStringList(Target: TStringList); virtual; abstract;
    1315    procedure Produce(Module: TModule); virtual; abstract;
    1416  end;
    1517
     18  // TListProducer = TGObjectList<Integer, TProducer>
     19  {$DEFINE TGObjectListIndex := Integer}
     20  {$DEFINE TGObjectListItem := TProducer}
     21  {$DEFINE TGObjectListList := TObjectListProducer}
     22  {$DEFINE TGObjectList := TListProducer}
     23  {$DEFINE TGObjectListSortCompare := TObjectListSortCompareProducer}
     24  {$DEFINE TGObjectListStringConverter := TObjectListStringConverterProducer}
     25  {$DEFINE INTERFACE}
     26  {$I 'GenericObjectList.inc'}
     27
    1628implementation
    1729
     30{$DEFINE IMPLEMENTATION_USES}
     31{$I 'GenericObjectList.inc'}
     32
     33// TListProducer = TGObjectList<Integer, TProducer>
     34{$DEFINE TGObjectListIndex := Integer}
     35{$DEFINE TGObjectListItem := TProducer}
     36{$DEFINE TGObjectListList := TObjectListProducer}
     37{$DEFINE TGObjectList := TListProducer}
     38{$DEFINE TGObjectListSortCompare := TObjectListSortCompareProducer}
     39{$DEFINE TGObjectListStringConverter := TObjectListStringConverterProducer}
     40{$DEFINE IMPLEMENTATION}
     41{$I 'GenericObjectList.inc'}
     42
    1843end.
  • trunk/Compiler/Produce/UProducerAsm8051.pas

    r6 r12  
    108108begin
    109109  AssemblyCode := TObjectList.Create;
     110  Name := 'ASM 8051';
    110111end;
    111112
  • trunk/Compiler/Produce/UProducerDynamicC.pas

    r6 r12  
    5656  TextSource := TStringList.Create;
    5757  IndentationLength := 2;
     58  Name := 'Dynamic C';
    5859end;
    5960
  • trunk/Compiler/Produce/UProducerGCCC.pas

    r6 r12  
    5656  TextSource := TStringList.Create;
    5757  IndentationLength := 2;
     58  Name := 'GCC C';
    5859end;
    5960
  • trunk/Compiler/Produce/UProducerPascal.pas

    r6 r12  
    5252  IndentationLength := 2;
    5353  TextSource := TStringList.Create;
     54  Name := 'Delphi';
    5455end;
    5556
  • trunk/Compiler/TranspascalCompiler.lpk

    r3 r12  
    1616    </CompilerOptions>
    1717    <Version Minor="1"/>
    18     <Files Count="11">
     18    <Files Count="12">
    1919      <Item1>
    2020        <Filename Value="UCompiler.pas"/>
     
    4646      </Item7>
    4747      <Item8>
    48         <Filename Value="Analyze\UParser.pas"/>
    49         <UnitName Value="UParser"/>
     48        <Filename Value="Analyze\UAnalyzer.pas"/>
     49        <UnitName Value="UAnalyzer"/>
    5050      </Item8>
    5151      <Item9>
    52         <Filename Value="Analyze\UPascalParser.pas"/>
    53         <UnitName Value="UPascalParser"/>
     52        <Filename Value="Analyze\UAnalyzerPascal.pas"/>
     53        <UnitName Value="UAnalyzerPascal"/>
    5454      </Item9>
    5555      <Item10>
    56         <Filename Value="Analyze\UGrammer.pas"/>
    57         <UnitName Value="UGrammer"/>
     56        <Filename Value="Produce\UProducerGCCC.pas"/>
     57        <UnitName Value="UProducerGCCC"/>
    5858      </Item10>
    5959      <Item11>
    60         <Filename Value="Produce\UProducerGCCC.pas"/>
    61         <UnitName Value="UProducerGCCC"/>
     60        <Filename Value="Analyze\UAnalyzers.pas"/>
     61        <UnitName Value="UAnalyzers"/>
    6262      </Item11>
     63      <Item12>
     64        <Filename Value="Produce\UProducers.pas"/>
     65        <UnitName Value="UProducers"/>
     66      </Item12>
    6367    </Files>
    6468    <Type Value="RunAndDesignTime"/>
  • trunk/Compiler/TranspascalCompiler.pas

    r2 r12  
    99uses
    1010    UCompiler, USourceCode, UProducerTreeView, UProducer, UProducerAsm8051,
    11   UProducerDynamicC, UProducerPascal, UParser, UPascalParser, UGrammer,
    12   UProducerGCCC, LazarusPackageIntf;
     11  UProducerDynamicC, UProducerPascal, UAnalyzer, UAnalyzerPascal,
     12  UProducerGCCC, UAnalyzers, UProducers, LazarusPackageIntf;
    1313
    1414implementation
  • 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.