Changeset 59 for branches/Transpascal/Analyze/UParser.pas
- Timestamp:
- Oct 14, 2010, 8:41:34 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Transpascal/Analyze/UParser.pas
r58 r59 45 45 end; 46 46 47 TGetSourceEvent = function (Name: string; Source: TStringList): Boolean of object; 48 47 49 { TPascalParser } 48 50 49 51 TPascalParser = class(TBaseParser) 52 private 53 FOnGetSource: TGetSourceEvent; 54 public 55 function ParseFile(Name: string): Boolean; 50 56 procedure ParseWhileDo(SourceCode: TWhileDo); 51 57 procedure ParseExpression(SourceCode: TExpression); 52 procedure ParseUse dModuleList(SourceCode: TUsedModuleList);53 function ParseModule : TModule;58 procedure ParseUses(SourceCode: TUsedModuleList); 59 function ParseModule(ProgramCode: TProgram): TModule; 54 60 procedure ParseUnit(SourceCode: TModuleUnit); 55 61 procedure ParseUnitInterface(SourceCode: TUnitInterface); … … 68 74 procedure ParseTypeList(SourceCode: TTypeList); 69 75 function ParseType(TypeList: TTypeList; ExpectName: Boolean = True; AssignSymbol: string = '='): TType; 70 private 76 property OnGetSource: TGetSourceEvent read FOnGetSource 77 write FOnGetSource; 78 constructor Create; 79 destructor Destroy; override; 71 80 end; 72 81 … … 84 93 SUndefinedType = 'Undefined type "%s".'; 85 94 SUndefinedConstant = 'Undefined constant "%s".'; 95 SUnitNotFound = 'Unit "%s" not found.'; 86 96 87 97 { TBaseParser } … … 335 345 end; 336 346 337 { TParserWhileDo } 347 { TPascalParser } 348 349 function TPascalParser.ParseFile(Name: string): Boolean; 350 var 351 Parser: TPascalParser; 352 NewModule: TModule; 353 begin 354 try 355 Parser := TPascalParser.Create; 356 Parser.SourceCodeText := TStringList.Create; 357 Parser.ProgramCode := ProgramCode; 358 if Assigned(FOnGetSource) then begin 359 if FOnGetSource(Name, Parser.SourceCodeText) then begin 360 Parser.Init; 361 NewModule := Parser.ParseModule(ProgramCode); 362 ProgramCode.Modules.Add(NewModule); 363 Result := True; 364 end else Result := False; 365 end else Result := False; 366 finally 367 Parser.SourceCodeText.Free; 368 Parser.Free; 369 end; 370 end; 338 371 339 372 procedure TPascalParser.ParseWhileDo(SourceCode: TWhileDo); … … 631 664 { TParserModule } 632 665 633 function TPascalParser.ParseModule: TModule; 634 begin 666 function TPascalParser.ParseModule(ProgramCode: TProgram): TModule; 667 begin 668 Self.ProgramCode := ProgramCode; 635 669 if FNextToken = 'unit' then begin 636 670 Result := TModuleUnit.Create; 671 Result.ParentProgram := ProgramCode; 637 672 ParseUnit(TModuleUnit(Result)); 638 673 end else begin //if FNextToken = 'program' then begin 639 674 Result := TModuleProgram.Create; 675 Result.ParentProgram := ProgramCode; 640 676 ParseProgram(TModuleProgram(Result)); 641 677 end; … … 655 691 // Uses section 656 692 if FNextToken = 'uses' then 657 ParseUse dModuleList(UsedModules);693 ParseUses(UsedModules); 658 694 659 695 ParseCommonBlock(Body, '.'); … … 681 717 // Uses section 682 718 if FNextToken = 'uses' then 683 ParseUse dModuleList(SourceCode.UsedModules);719 ParseUses(SourceCode.UsedModules); 684 720 685 721 ParseCommonBlockInterface(SourceCode.Body); … … 692 728 // Uses section 693 729 if FNextToken = 'uses' then 694 ParseUse dModuleList(SourceCode.UsedModules);730 ParseUses(SourceCode.UsedModules); 695 731 696 732 ParseCommonBlock(SourceCode.Body, '.'); … … 1103 1139 end; 1104 1140 1141 constructor TPascalParser.Create; 1142 begin 1143 end; 1144 1145 destructor TPascalParser.Destroy; 1146 begin 1147 inherited Destroy; 1148 end; 1149 1105 1150 { TParserUsedModuleList } 1106 1151 1107 procedure TPascalParser.ParseUse dModuleList(SourceCode: TUsedModuleList);1152 procedure TPascalParser.ParseUses(SourceCode: TUsedModuleList); 1108 1153 var 1109 1154 NewUsedModule: TUsedModule; … … 1113 1158 begin 1114 1159 Name := ReadCode; 1115 end; 1116 while FNextToken = ',' do 1117 begin 1160 Module := SourceCode.ParentModule.ParentProgram.Modules.Search(Name); 1161 if not Assigned(Module) then begin 1162 if not ParseFile(Name) then ErrorMessage(SUnitNotFound, [Name]); 1163 end; 1164 end; 1165 while FNextToken = ',' do begin 1118 1166 Expect(','); 1119 1167 with TUsedModule(SourceCode.Items[SourceCode.Add(TUsedModule.Create)]) do 1120 1168 begin 1121 1169 Name := ReadCode; 1170 Module := SourceCode.ParentModule.ParentProgram.Modules.Search(Name); 1171 if not Assigned(Module) then begin 1172 if not ParseFile(Name) then ErrorMessage(SUnitNotFound, [Name]); 1173 end; 1122 1174 end; 1123 1175 end;
Note:
See TracChangeset
for help on using the changeset viewer.