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.
File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.