Changeset 72 for trunk/Compiler


Ignore:
Timestamp:
Aug 1, 2012, 12:16:08 PM (12 years ago)
Author:
chronos
Message:
  • Added: Introduced concept of graph of source file set converters similar to IntToStr, StrToInt, FloatToStr, StrToFloat, e.g.
  • Modified: Some target definitions transformed to loadable modules.
Location:
trunk/Compiler
Files:
13 added
6 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/Modules/Pascal/UAnalyzerPascal.pas

    r70 r72  
    66
    77uses
    8   Classes, SysUtils, UAnalyzer, USourceCode, Dialogs;
     8  Classes, SysUtils, UAnalyzer, USourceCodePascal, Dialogs, USourceConvertor;
    99
    1010type
     
    1212  { TAnalyzerPascal }
    1313
    14   TAnalyzerPascal = class(TAnalyzer)
     14  TAnalyzerPascal = class(TConvertor)
    1515  private
    1616  public
     17    Parser: TAnalyzer;
    1718    function DebugExpressions(List: TListExpression): string;
    1819    function ParseFile(Name: string): Boolean;
     
    2930    function ParseUses(SourceCode: TUsedModuleList; AExported: Boolean): Boolean;
    3031    function ParseUsesItem(SourceCode: TUsedModuleList; AExported: Boolean): Boolean;
    31     function ParseModule(ProgramCode: TProgram): TSourceModule; override;
     32    function ParseModule(ProgramCode: TProgram): TSourceModule;
    3233    function ParseUnit(var SourceCode: TModuleUnit; ProgramCode: TProgram): Boolean;
    3334    function ParseUnitInterface(SourceCode: TModuleUnit): Boolean;
     
    6364    constructor Create;
    6465    destructor Destroy; override;
     66    procedure Convert(Input, Output: TSourceList); override;
    6567  end;
    6668
     
    108110  NewModule: TSourceModule;
    109111begin
    110   try
     112(*  try
    111113    Parser := TAnalyzerPascal.Create;
    112114    Parser.OnDebugLog := OnDebugLog;
     
    126128  finally
    127129    Parser.Free;
    128   end;
     130  end;  *)
    129131end;
    130132
    131133function TAnalyzerPascal.ParseWhileDo(var WhileDo: TWhileDo; SourceCode: TCommonBlock): Boolean;
    132134begin
     135(*  with Parser do
    133136  if NextToken = 'while' then begin
    134137    Expect('while');
     
    142145    end;
    143146    Result := True;
    144   end else Result := False;
     147  end else Result := False;*)
    145148end;
    146149
     
    153156  II: Integer;
    154157begin
     158(*  with Parser do
    155159  try
    156160    Expressions := TListExpression.Create;
     
    198202  finally
    199203    Expressions.Free;
    200   end;
     204  end;     *)
    201205end;
    202206
     
    206210  NewExpression: TExpression;
    207211begin
    208   if NextToken = '(' then begin
     212 (* if NextToken = '(' then begin
    209213    Expect('(');
    210214    // Subexpression
     
    222226    Expect(')');
    223227    Result := True;
    224   end else Result := False;
     228  end else Result := False;*)
    225229end;
    226230
     
    228232  Expressions: TListExpression): Boolean;
    229233begin
    230   if IsOperator(NextToken) then begin
     234  (*if IsOperator(NextToken) then begin
    231235    // Operator
    232236    TExpression(Expressions.Last).OperatorName := ReadToken;
    233237    TExpression(Expressions.Last).NodeType := ntOperator;
    234238    Result := True;
    235   end else Result := False;
     239  end else Result := False;   *)
    236240end;
    237241
     
    249253begin
    250254  NewExpression := nil;
     255  with Parser do
    251256  with SourceCode do begin
    252257//  if IsIdentificator(NextToken) then begin
     
    367372begin
    368373  Func := nil;
    369   with SourceCode do begin
     374  with Parser, SourceCode do begin
    370375    UseFunction := CommonBlock.Functions.Search(NextToken);
    371376    if Assigned(UseFunction) then begin
     
    402407  FunctionName: string;
    403408begin
     409  with PArser do
    404410  begin
    405411    if not ParseBeginEnd(TBeginEnd(Result), SourceCode) then
     
    422428function TAnalyzerPascal.ParseModule(ProgramCode: TProgram): TSourceModule;
    423429begin
    424   Self.ProgramCode := ProgramCode;
     430(*  Output := TSource(ProgramCode);
    425431  if not ParseUnit(TModuleUnit(Result), ProgramCode) then
    426432  if not ParseProgram(TModuleProgram(Result), ProgramCode) then
    427     ErrorMessage(SUnknownModuleType, [NextToken]);
     433    ErrorMessage(SUnknownModuleType, [NextToken]);*)
    428434end;
    429435
     
    432438  Identifier: string;
    433439begin
    434   with SourceCode do begin
     440  with Parser, SourceCode do begin
    435441    SourceCode := TModuleProgram.Create;
    436442    SourceCode.ParentProgram := ProgramCode;
     
    457463  NewCommand: TCommand;
    458464begin
     465  with Parser do
    459466  if NextToken = 'unit' then begin
    460467    SourceCode := TModuleUnit.Create;
     
    507514function TAnalyzerPascal.ParseUnitInterface(SourceCode: TModuleUnit): Boolean;
    508515begin
     516  with Parser do
    509517  if NextToken = 'interface' then begin
    510518    Expect('interface');
     
    519527function TAnalyzerPascal.ParseUnitImplementation(SourceCode: TModuleUnit): Boolean;
    520528begin
     529  with Parser do
    521530  if NextToken = 'implementation' then begin
    522531    Expect('implementation');
     
    539548  NewType: TType;
    540549begin
    541   with SourceCode do begin
     550  with Parser, SourceCode do begin
    542551    while (NextToken <> EndSymbol) and (NextTokenType <> ttEndOfFile) do begin
    543552      if NextToken = 'var' then begin
     
    591600begin
    592601  Log('ParseCommonBlockInterface');
    593   with SourceCode do begin
     602  with Parser, SourceCode do begin
    594603    while (NextToken <> 'implementation') and (NextTokenType <> ttEndOfFile) do begin
    595604      if NextToken = 'var' then begin
     
    632641  NewCommand: TCommand;
    633642begin
     643  with Parser do
    634644  if NextToken = 'begin' then begin
    635645    //ShowMessage(IntToStr(Integer(SourceCode)) + ' ' + IntToStr(Integer(SourceCode.CommonBlock)));
     
    668678  ValidParams: Boolean;
    669679begin
     680  with Parser do
    670681  if (NextToken = 'procedure') or (NextToken = 'function') then begin
    671682  with SourceCode do begin
     
    779790  I: Integer;
    780791begin
    781   with SourceCode do
     792  with Parser, SourceCode do
    782793  try
    783794    Identifiers := TStringList.Create;
     
    837848function TAnalyzerPascal.ParseIfThenElse(var IfThenElse: TIfThenElse; SourceCode: TCommonBlock): Boolean;
    838849begin
     850  with Parser do
    839851  if NextToken = 'if' then begin
    840852    IfThenElse := TIfThenElse.Create;
     
    860872  VariableName: string;
    861873begin
     874  with Parser do
    862875  if NextToken = 'for' then begin
    863876    ForToDo := TForToDo.Create;
     
    888901  IdentName: string;
    889902begin
     903  with Parser do
    890904  if IsIdentificator(NextToken) then begin
    891905    Variable := SourceCode.Variables.Search(NextToken);
     
    910924  FunctionName: string;
    911925begin
     926  with Parser do
    912927  if IsIdentificator(NextToken) then begin
    913928    if Assigned(SourceCode.Functions.Search(NextToken)) then begin
     
    939954  I: integer;
    940955begin
     956  with Parser do
    941957  if NextToken = 'var' then begin
    942958    Expect('var');
     
    962978  NewVariable: TVariable;
    963979begin
     980  with Parser do
    964981  try
    965982    Identifiers := TStringList.Create;
     
    10011018function TAnalyzerPascal.ParseConstantList(SourceCode: TConstantList; Exported: Boolean = False): Boolean;
    10021019begin
     1020  with Parser do
    10031021  if NextToken = 'const' then begin
    10041022    Expect('const');
     
    10231041  ConstantValue: string;
    10241042begin
    1025   with SourceCode do
     1043  with Parser, SourceCode do
    10261044  try
    10271045    Identifiers := TStringList.Create;
     
    10701088  NewType.Parent := TypeList;
    10711089  //with SourceCode do
     1090  with Parser do
    10721091  begin
    10731092    if ExpectName then begin
     
    10971116  NewType2: TType;
    10981117begin
     1118  with Parser do
    10991119  if NextToken = '<' then begin
    11001120    Expect('<');
     
    11191139  Result := False;
    11201140  // Use existed type
     1141  with Parser do
    11211142  if NextTokenType = ttIdentifier then begin
    11221143    TypeName := ReadToken;
     
    11461167begin
    11471168  // Buildin base type construction
     1169  with Parser do
    11481170  if NextToken = 'type' then begin
    11491171    Expect('type');
     
    11651187  TempType: TType;
    11661188begin
     1189  with Parser do
    11671190  if NextToken = '^' then begin
    11681191    Expect('^');
     
    11801203  TempType: TType;
    11811204begin
     1205  with Parser do
    11821206  if NextToken = '(' then begin
    11831207      Expect('(');
     
    12181242  TempType: TType;
    12191243begin
     1244  with Parser do
    12201245  if NextToken = 'record' then begin
    12211246    Expect('record');
     
    12921317  TempType: TType;
    12931318begin
     1319  with Parser do
    12941320  if NextToken = 'class' then begin
    12951321    Expect('class');
     
    13641390  TempType: TType;
    13651391begin
     1392  with Parser do
    13661393  if NextToken = 'array' then begin
    13671394    Expect('array');
     
    13991426  TempType: TType;
    14001427begin
     1428  with Parser do
    14011429  if NextTokenType = ttConstantString then begin
    14021430    TempType := NewType;
     
    14241452begin
    14251453  inherited;
     1454  Parser := TAnalyzer.Create;
    14261455  Name := 'Delphi';
     1456  InputType := TSourceFileLink;
     1457  OutputType := TProgram;
    14271458end;
    14281459
    14291460destructor TAnalyzerPascal.Destroy;
    14301461begin
     1462  Parser.Free;
    14311463  inherited Destroy;
    14321464end;
    14331465
     1466procedure TAnalyzerPascal.Convert(Input, Output: TSourceList);
     1467begin
     1468
     1469end;
     1470
    14341471{ TParserUsedModuleList }
    14351472
     
    14381475  NewUsedModule: TUsedModule;
    14391476begin
     1477  with Parser do
    14401478  if NextToken = 'uses' then begin
    14411479    Expect('uses');
     
    14531491  AExported: Boolean): Boolean;
    14541492begin
     1493  with Parser do
    14551494    with TUsedModule(SourceCode.Items[SourceCode.Add(TUsedModule.Create)]) do begin
    14561495      Name := ReadToken;
  • trunk/Compiler/Modules/Pascal/UModulePascal.pas

    r71 r72  
    4444begin
    4545  with TCompilerAPI(API) do begin
    46     Analyzer := TAnalyzerPascal.Create;
    47     Analyzers.Add(Analyzer);
     46    RegisterConvertor(TAnalyzerPascal);
    4847  end;
    4948  inherited Install;
     
    5453  inherited Uninstall;
    5554  with TCompilerAPI(API) do begin
    56     Analyzers.Remove(Analyzer);
     55    UnregisterConvertor(TAnalyzerPascal);
    5756  end;
    5857end;
  • trunk/Compiler/Target/Dynamic C/UProducerDynamicc.pas

    r68 r72  
    77uses
    88  SysUtils, Variants, Classes, Graphics, Controls, Forms,
    9   Dialogs, StdCtrls, USourceCode, UProducer, StrUtils;
     9  Dialogs, StdCtrls, USourceCodePascal, UProducer, StrUtils;
    1010
    1111type
  • trunk/Compiler/Target/XML/UTargetXML.pas

    r68 r72  
    66
    77uses
    8   Classes, SysUtils, UTarget, UProducer, USourceCode;
     8  Classes, SysUtils, UTarget, UProducer, USourceCodePascal;
    99
    1010type
  • trunk/Compiler/TranspascalCompiler.lpk

    r71 r72  
    99      <PathDelim Value="\"/>
    1010      <SearchPaths>
    11         <OtherUnitFiles Value="Analyze;Target;Target\Interpretter;Target\ASM8051;Target\Java;Target\GCC;Target\PHP;Target\Delphi;Target\Dynamic C;Target\XML;Target\NASM;Modules\Pascal;Modules\GCC"/>
     11        <OtherUnitFiles Value="Analyze;Target;Target\Interpretter;Target\ASM8051;Target\Java;Target\GCC;Target\PHP;Target\Delphi;Target\Dynamic C;Target\XML;Target\NASM;Modules\Pascal;Modules\GCC;Modules\ASM8051;Modules\Brainfuck;Modules\Interpretter;Modules\Delphi"/>
    1212        <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
    1313      </SearchPaths>
     
    2525    </CompilerOptions>
    2626    <Version Minor="1"/>
    27     <Files Count="22">
     27    <Files Count="24">
    2828      <Item1>
    2929        <Filename Value="UCompiler.pas"/>
     
    3131      </Item1>
    3232      <Item2>
    33         <Filename Value="USourceCode.pas"/>
    34         <UnitName Value="USourceCode"/>
     33        <Filename Value="Modules\Pascal\USourceCodePascal.pas"/>
     34        <UnitName Value="USourceCodePascal"/>
    3535      </Item2>
    3636      <Item3>
     
    5959      </Item8>
    6060      <Item9>
    61         <Filename Value="Target\ASM8051\UProducerASM8051.pas"/>
     61        <Filename Value="Modules\ASM8051\UProducerASM8051.pas"/>
    6262        <UnitName Value="UProducerAsm8051"/>
    6363      </Item9>
    6464      <Item10>
    65         <Filename Value="Target\ASM8051\UTargetASM8051.pas"/>
     65        <Filename Value="Modules\ASM8051\UTargetASM8051.pas"/>
    6666        <UnitName Value="UTargetASM8051"/>
    6767      </Item10>
     
    7575      </Item12>
    7676      <Item13>
    77         <Filename Value="Target\Delphi\UProducerPascal.pas"/>
    78         <UnitName Value="UProducerPascal"/>
     77        <Filename Value="Modules\Delphi\UProducerDelphi.pas"/>
     78        <UnitName Value="UProducerDelphi"/>
    7979      </Item13>
    8080      <Item14>
    81         <Filename Value="Target\Delphi\UTargetDelphi.pas"/>
    82         <UnitName Value="UTargetDelphi"/>
     81        <Filename Value="Modules\Delphi\UModuleDelphi.pas"/>
     82        <UnitName Value="UModuleDelphi"/>
    8383      </Item14>
    8484      <Item15>
     
    9595      </Item17>
    9696      <Item18>
    97         <Filename Value="Target\Interpretter\UTargetInterpretter.pas"/>
    98         <UnitName Value="UTargetInterpretter"/>
     97        <Filename Value="Modules\Interpretter\UModuleInterpretter.pas"/>
     98        <UnitName Value="UModuleInterpretter"/>
    9999      </Item18>
    100100      <Item19>
     
    114114        <UnitName Value="UModuleGCC"/>
    115115      </Item22>
     116      <Item23>
     117        <Filename Value="USourceConvertor.pas"/>
     118        <UnitName Value="USourceConvertor"/>
     119      </Item23>
     120      <Item24>
     121        <Filename Value="Modules\Brainfuck\UModuleBrainfuck.pas"/>
     122        <UnitName Value="UModuleBrainfuck"/>
     123      </Item24>
    116124    </Files>
    117125    <Type Value="RunAndDesignTime"/>
  • trunk/Compiler/TranspascalCompiler.pas

    r71 r72  
    88
    99uses
    10   UCompiler, USourceCode, UProducer, UAnalyzer, UTarget, UExecutor,
     10  UCompiler, USourceCodePascal, UProducer, UAnalyzer, UTarget, UExecutor,
    1111  UAnalyzerPascal, UProducerDynamicc, UProducerASM8051, UTargetASM8051,
    12   UTargetGCC, UProducerGCC, UProducerPascal, UTargetDelphi, UTargetPHP,
    13   UTargetJava, UTargetXML, UTargetInterpretter, UTargetNASM, UModulePascal,
    14   UCompilerAPI, UModuleGCC, LazarusPackageIntf;
     12  UTargetGCC, UProducerGCC, UProducerDelphi, UModuleDelphi, UTargetPHP,
     13  UTargetJava, UTargetXML, UModuleInterpretter, UTargetNASM, UModulePascal,
     14  UCompilerAPI, UModuleGCC, USourceConvertor, UModuleBrainfuck,
     15  LazarusPackageIntf;
    1516
    1617implementation
  • trunk/Compiler/UAnalyzer.pas

    r70 r72  
    88uses
    99  SysUtils, Variants, Classes, Contnrs,
    10   Dialogs, USourceCode, FileUtil, SpecializedList;
     10  Dialogs, USourceCodePascal, FileUtil, SpecializedList;
    1111
    1212type
     
    5353    CodeStreamPosition: Integer;
    5454    CodePosition: TPoint;
    55     SourceCode: string;
     55    SourceCode2: string;
    5656    Tokens: TObjectList; // TObjectList<TToken>
    5757    TokenIndex: Integer;
     
    242242  Tokens.Clear;
    243243  TokenIndex := 0;
    244   while CodeStreamPosition < Length(SourceCode) do begin
     244  while CodeStreamPosition < Length(SourceCode2) do begin
    245245    NewToken := TToken.Create;
    246246    GetNextToken;
     
    274274
    275275    while True do begin
    276       if CodeStreamPosition < Length(SourceCode) then begin
    277         CurrentChar := SourceCode[CodeStreamPosition];
     276      if CodeStreamPosition < Length(SourceCode2) then begin
     277        CurrentChar := SourceCode2[CodeStreamPosition];
    278278      end else begin
    279279        FNextToken := '';
  • trunk/Compiler/UCompiler.pas

    r71 r72  
    77uses
    88  SysUtils, Variants, Classes, Contnrs, FileUtil, UModularSystem, UCompilerAPI,
    9   Dialogs, USourceCode, UProducer, UAnalyzer, SpecializedList, UTarget;
     9  Dialogs, USourceCodePascal, UProducer, UAnalyzer, SpecializedList, UTarget;
    1010
    1111type
     
    4747    CompiledFolder: string;
    4848
     49    Targets: TListTarget;
     50    Analyzers: TListAnalyzer;
     51    Convertors: TListObject;
     52    Executors: TListObject;
    4953    API: TCompilerAPI;
    5054    TargetFolder: string;
     
    163167constructor TCompiler.Create;
    164168begin
     169  Targets := TListTarget.Create;
     170  Analyzers := TListAnalyzer.Create;
     171  Convertors := TListObject.Create;
     172  Executors := TListObject.Create;
    165173  API := TCompilerAPI.Create;
    166174  AbstractCode := TProgram.Create;
     
    182190  FreeAndNil(AbstractCode);
    183191  FreeAndNil(ErrorMessages);
     192  FreeAndNil(Targets);
     193  FreeAndNil(Analyzers);
     194  FreeAndNil(Executors);
     195  FreeAndNil(Convertors);
    184196end;
    185197
     
    210222  if MainSource <> '' then begin
    211223    Analyzer.FileName := MainSource;
    212     Analyzer.OnGetSource(ExtractFileName(Analyzer.FileName), Analyzer.SourceCode);
     224    Analyzer.OnGetSource(ExtractFileName(Analyzer.FileName), Analyzer.SourceCode2);
    213225    Analyzer.Process;
    214226    //ShowMessage(IntToHex(Integer(Addr(Analyzer.OnGetSource)), 8));
  • trunk/Compiler/UCompilerAPI.pas

    r71 r72  
    66
    77uses
    8   Classes, SysUtils, UModularSystem, UAnalyzer, UTarget;
     8  Classes, SysUtils, UModularSystem, UAnalyzer, UTarget, USourceConvertor,
     9  SpecializedList, UExecutor;
    910
    1011type
     
    1314
    1415  TCompilerAPI = class(TAPI)
    15     Targets: TListTarget;
    16     Analyzers: TListAnalyzer;
     16    Compiler: TObject; //TCompiler;
     17    procedure RegisterConvertor(AClass: TConvertorClass);
     18    procedure UnregisterConvertor(AClass: TConvertorClass);
     19    procedure RegisterExecutor(AClass: TExecutorClass);
     20    procedure UnregisterExecutor(AClass: TExecutorClass);
    1721    constructor Create;
    1822    destructor Destroy; override;
     
    2125implementation
    2226
     27uses
     28  UCompiler;
     29
     30
    2331{ TCompilerAPI }
     32
     33procedure TCompilerAPI.RegisterConvertor(AClass: TConvertorClass);
     34begin
     35  TCompiler(Compiler).Convertors.Add(TObject(AClass));
     36end;
     37
     38procedure TCompilerAPI.UnregisterConvertor(AClass: TConvertorClass);
     39begin
     40  TCompiler(Compiler).Convertors.Remove(TObject(AClass));
     41end;
     42
     43procedure TCompilerAPI.RegisterExecutor(AClass: TExecutorClass);
     44begin
     45  TCompiler(Compiler).Executors.Add(TObject(AClass));
     46end;
     47
     48procedure TCompilerAPI.UnregisterExecutor(AClass: TExecutorClass);
     49begin
     50  TCompiler(Compiler).Executors.Remove(TObject(AClass));
     51end;
    2452
    2553constructor TCompilerAPI.Create;
    2654begin
    27   Targets := TListTarget.Create;
    28   Analyzers := TListAnalyzer.Create;
    2955end;
    3056
    3157destructor TCompilerAPI.Destroy;
    3258begin
    33   Targets.Free;
    34   Analyzers.Free;
    3559  inherited Destroy;
    3660end;
  • trunk/Compiler/UExecutor.pas

    r60 r72  
    3131  end;
    3232
     33  TExecutorClass = class of TExecutor;
     34
    3335implementation
    3436
  • trunk/Compiler/UProducer.pas

    r68 r72  
    66
    77uses
    8   USourceCode, Classes, SysUtils, StrUtils, SpecializedList, Process,
     8  USourceCodePascal, Classes, SysUtils, StrUtils, SpecializedList, Process,
    99  FileUtil, Forms;
    1010
Note: See TracChangeset for help on using the changeset viewer.