Changeset 44 for branches/DelphiToC
- Timestamp:
- Aug 9, 2010, 10:22:30 AM (14 years ago)
- Location:
- branches/DelphiToC
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/Analyze/UPascalParser.pas
r43 r44 12 12 EEndOfData = class(Exception); 13 13 14 T PascalParser = class;14 TBaseParser = class; 15 15 16 16 TOnErrorMessage = procedure (Text: string) of object; 17 17 18 { TParserWhileDo } 19 20 TParserWhileDo = class 21 class procedure Parse(Parser: TPascalParser; SourceCode: TWhileDo); 22 end; 23 24 { TParserExpression } 25 26 TParserExpression = class 27 class function Parse(Parser: TPascalParser; SourceCode: TExpression): TExpression; 28 end; 29 30 { TParserUsedModuleList } 31 32 TParserUsedModuleList = class 33 class procedure Parse(Parser: TPascalParser; SourceCode: TUsedModuleList); 34 end; 35 36 { TParserModule } 37 38 TParserModule = class 39 class procedure Parse(Parser: TPascalParser; SourceCode: TModule); 40 class procedure ParseUnit(Parser: TPascalParser; SourceCode: TModule); 41 class procedure ParseProgram(Parser: TPascalParser; SourceCode: TModule); 42 end; 43 44 TParserProgram = class 45 class procedure Parse(Parser: TPascalParser; SourceCode: TProgram); 46 end; 47 48 { TParserCommonBlock } 49 50 TParserCommonBlock = class 51 class procedure Parse(Parser: TPascalParser; SourceCode: TCommonBlock; EndSymbol: Char = ';'); 52 class function ParseCommand(Parser: TPascalParser; SourceCode: TCommonBlock): TCommand; 53 end; 54 55 { TParserBeginEnd } 56 57 TParserBeginEnd = class 58 class procedure Parse(Parser: TPascalParser; SourceCode: TBeginEnd); 59 end; 60 61 TParserFunctionList = class 62 class procedure Parse(Parser: TPascalParser; SourceCode: TFunctionList); 63 end; 64 65 TParserIfThenElse = class 66 class procedure Parse(Parser: TPascalParser; SourceCode: TIfThenElse); 67 end; 68 69 TParserVariableList = class 70 class procedure Parse(Parser: TPascalParser; SourceCode: TVariableList); 71 end; 72 73 TParserVariable = class 74 class procedure Parse(Parser: TPascalParser; SourceCode: TVariable); 75 end; 76 77 TParserConstantList = class 78 class procedure Parse(Parser: TPascalParser; SourceCode: TConstantList); 79 end; 80 81 TParserTypeList = class 82 class procedure Parse(Parser: TPascalParser; SourceCode: TTypeList); 83 end; 84 85 TParserType = class 86 class procedure Parse(Parser: TPascalParser; SourceCode: TType); 87 end; 88 89 TPascalParser = class 18 TTokenType = (ttNone, ttIdentifier, ttConstantNumber, ttConstantString, 19 ttOperator, ttEndOfFile, ttLineComment, ttBlockComment1, ttBlockComment2, 20 ttUnknown, ttWhiteSpace); 21 22 { TBaseParser } 23 24 TBaseParser = class 90 25 private 91 26 ProgramCode: TProgram; 92 27 FOnErrorMessage: TOnErrorMessage; 28 FNextToken: string; 29 FNextTokenType: TTokenType; 30 PreviousChar: Char; 31 CurrentChar: Char; 93 32 procedure ErrorMessage(const Text: string; const Arguments: array of const); 94 33 public 95 CodePosition: Integer; 34 CodeStreamPosition: Integer; 35 CodePosition: TPoint; 96 36 SourceCodeText: TStringList; 97 37 function IsAlphanumeric(Character: Char): Boolean; 98 function NextCode(Shift: Boolean = False): string;38 procedure GetNextToken; 99 39 function ReadCode: string; 100 40 procedure Expect(Code: string); … … 106 46 procedure Log(Text: string); 107 47 property OnErrorMessage: TOnErrorMessage read FOnErrorMessage write FOnErrorMessage; 108 end; 48 procedure Init; 49 end; 50 51 { TPascalParser } 52 53 TPascalParser = class(TBaseParser) 54 procedure ParseWhileDo(SourceCode: TWhileDo); 55 function ParseExpression(SourceCode: TExpression): TExpression; 56 procedure ParseUsedModuleList(SourceCode: TUsedModuleList); 57 procedure ParseModule(SourceCode: TModule); 58 procedure ParseUnit(SourceCode: TModule); 59 procedure ParseProgram(SourceCode: TModule); 60 procedure ParseAll(SourceCode: TProgram); 61 procedure ParseCommonBlock(SourceCode: TCommonBlock; EndSymbol: Char = ';'); 62 function ParseCommand(SourceCode: TCommonBlock): TCommand; 63 procedure ParseBeginEnd(SourceCode: TBeginEnd); 64 procedure ParseFunctionList(SourceCode: TFunctionList); 65 procedure ParseIfThenElse(SourceCode: TIfThenElse); 66 procedure ParseVariableList(SourceCode: TVariableList); 67 procedure ParseVariable(SourceCode: TVariable); 68 procedure ParseConstantList(SourceCode: TConstantList); 69 procedure ParseTypeList(SourceCode: TTypeList); 70 procedure ParseType(SourceCode: TType); 71 private 72 end; 73 109 74 110 75 implementation … … 119 84 120 85 121 { T PascalParser }122 123 procedure T PascalParser.ErrorMessage(const Text: string; const Arguments: array of const);86 { TBaseParser } 87 88 procedure TBaseParser.ErrorMessage(const Text: string; const Arguments: array of const); 124 89 begin 125 90 if Assigned(FOnErrorMessage) then … … 127 92 end; 128 93 129 procedure T PascalParser.Expect(Code: string);130 begin 131 Log('Expected: ' + Code + ' Readed: ' + NextCode);132 if NextCode<> Code then begin133 ErrorMessage(SExpectedButFound, [Code, NextCode]);94 procedure TBaseParser.Expect(Code: string); 95 begin 96 Log('Expected: ' + Code + ' Readed: ' + FNextToken); 97 if FNextToken <> Code then begin 98 ErrorMessage(SExpectedButFound, [Code, FNextToken]); 134 99 135 100 // Recovery: try to find nearest same code 136 while NextCode<> Code do137 ReadCode;138 end; 139 ReadCode;140 end; 141 142 function T PascalParser.IsAlphabetic(Character: Char): Boolean;101 while FNextToken <> Code do 102 GetNextToken; 103 end; 104 GetNextToken; 105 end; 106 107 function TBaseParser.IsAlphabetic(Character: Char): Boolean; 143 108 begin 144 109 Result := (Character in ['a'..'z']) or (Character in ['A'..'Z']); 145 110 end; 146 111 147 function T PascalParser.IsAlphanumeric(Character: Char): Boolean;112 function TBaseParser.IsAlphanumeric(Character: Char): Boolean; 148 113 begin 149 114 Result := IsAlphabetic(Character) or (Character in ['0'..'9']); 150 115 end; 151 116 152 function T PascalParser.IsKeyword(Text: string): Boolean;117 function TBaseParser.IsKeyword(Text: string): Boolean; 153 118 var 154 119 I: Integer; … … 160 125 end; 161 126 162 function T PascalParser.IsOperator(Text: string): Boolean;127 function TBaseParser.IsOperator(Text: string): Boolean; 163 128 var 164 129 I: Integer; … … 170 135 end; 171 136 172 function T PascalParser.IsIdentificator(Text: string): Boolean;137 function TBaseParser.IsIdentificator(Text: string): Boolean; 173 138 var 174 139 I: Integer; … … 185 150 end; 186 151 187 function T PascalParser.IsWhiteSpace(Character: Char): Boolean;152 function TBaseParser.IsWhiteSpace(Character: Char): Boolean; 188 153 begin 189 154 Result := (Character = ' ') or (Character = #13) or (Character = #10); 190 155 end; 191 156 192 procedure T PascalParser.Log(Text: string);157 procedure TBaseParser.Log(Text: string); 193 158 const 194 159 LogFileName = 'ParseLog.txt'; … … 209 174 end; 210 175 211 function TPascalParser.NextCode(Shift: Boolean = False): string; 176 procedure TBaseParser.Init; 177 begin 178 CurrentChar := #0; 179 PreviousChar := #0; 180 FNextToken := ''; 181 FNextTokenType := ttNone; 182 CodeStreamPosition := 1; 183 GetNextToken; 184 end; 185 186 procedure TBaseParser.GetNextToken; 212 187 var 213 188 I: Integer; … … 219 194 DoubleSpecChar : array[0..6] of string = (':=', '..', '<=', '>=', '<>', '+=', '-='); 220 195 begin 221 Result := ''; 222 J := CodePosition; 223 I := CodePosition; 224 with SourceCodeText do 225 while Result = '' do begin 226 while IsWhiteSpace(Text[I]) and (I < Length(Text)) do Inc(I); 227 if I = Length(Text) then 228 raise EEndOfData.Create(SEndOfDataReached); 229 J := I; 230 if Copy(Text, J, 2) = '//' then begin 231 // Line comment 232 while (Text[I] <> #13) and (Text[I] <> #10) do Inc(I); 233 Result := ''; 234 end else 235 if Copy(Text, J, 1) = '{' then begin 236 // Block comment 1 237 while (Text[I] <> '}') do Inc(I); 238 Result := ''; 239 end else 240 if Copy(Text, J, 2) = '(*' then begin 241 // Block comment 2 242 while not((Text[I] = '*') and (Text[I + 1] = ')')) do Inc(I); 243 Result := ''; 244 end else 245 if Text[J] = '''' then begin 246 // String constant 247 I := J + 1; 248 while not ((Text[I] = '''') and (Text[I + 1] <> '''')) do Inc(I); 249 Inc(I); 250 Result := Copy(Text, J, I - J); 251 end else 252 if (Text[J] in SpecChar) then begin 253 // Special char token 254 if (Text[J + 1] in SpecChar) then begin 255 for II := 0 to High(DoubleSpecChar) do 256 if Copy(Text, J, 2) = DoubleSpecChar[II] then begin 257 Result := Copy(Text, J, 2); 258 Inc(J, 2); 259 Break; 260 end; 261 I := J; 196 FNextToken := ''; 197 FNextTokenType := ttNone; 198 with SourceCodeText do 199 while True do begin 200 if CodeStreamPosition < Length(Text) then begin 201 CurrentChar := Text[CodeStreamPosition]; 202 end else begin 203 FNextToken := ''; 204 FNextTokenType := ttEndOfFile; 205 Break; 262 206 end; 263 if Result = '' then begin 264 Result := Text[J]; 265 Inc(I); 207 if FNextTokenType = ttNone then begin 208 if IsWhiteSpace(CurrentChar) then FNextTokenType := ttWhiteSpace 209 else 210 if CurrentChar = '{' then begin 211 FNextTokenType := ttBlockComment1; 212 end else 213 if CurrentChar = '''' then begin 214 FNextTokenType := ttConstantString; 215 end else 216 if CurrentChar in SpecChar then begin 217 FNextTokenType := ttOperator; 218 FNextToken := FNextToken + CurrentChar; 219 end else 220 if IsAlphanumeric(CurrentChar) then begin 221 FNextTokenType := ttIdentifier; 222 FNextToken := FNextToken + CurrentChar; 223 end else FNextTokenType := ttUnknown; 224 end else 225 if FNextTokenType = ttLineComment then begin 226 if (CurrentChar = #13) or (CurrentChar = #10) then 227 FNextTokenType := ttNone; 228 end else 229 if FNextTokenType = ttBlockComment1 then begin 230 if (CurrentChar = '}') then 231 FNextTokenType := ttNone; 232 end else 233 if FNextTokenType = ttBlockComment2 then begin 234 if (PreviousChar = '*') and (CurrentChar = ')') then 235 FNextTokenType := ttNone; 236 end else 237 if FNextTokenType = ttConstantString then begin 238 if (CurrentChar = '''') and (PreviousChar = '''') then 239 Break else 240 FNextToken := FNextToken + CurrentChar; 241 end else 242 if FNextTokenType = ttOperator then begin 243 if (CurrentChar = '*') and (PreviousChar = '(') then begin 244 FNextToken := ''; 245 FNextTokenType := ttBlockComment2; 246 end else 247 if (CurrentChar = '/') and (PreviousChar = '/') then begin 248 FNextToken := ''; 249 FNextTokenType := ttLineComment; 250 end else 251 if not (CurrentChar in SpecChar) then 252 Break else begin 253 J := 0; 254 while (J < Length(DoubleSpecChar)) and ((PreviousChar + CurrentChar) <> DoubleSpecChar[J]) do Inc(J); 255 if J < Length(DoubleSpecChar) then 256 FNextToken := FNextToken + CurrentChar else Break; 257 end; 258 end else 259 if FNextTokenType = ttIdentifier then begin 260 if not IsAlphanumeric(CurrentChar) then 261 Break else 262 FNextToken := FNextToken + CurrentChar; 263 end 264 else if FNextTokenType = ttWhiteSpace then 265 FNextTokenType := ttNone; 266 267 if FNextTokenType <> ttNone then begin 268 Inc(CodeStreamPosition); 269 PreviousChar := CurrentChar; 266 270 end; 267 end else begin 268 if IsAlphabetic(Text[I]) then begin 269 // Identifier 270 while IsAlphanumeric(Text[I]) do Inc(I); 271 Result := Copy(Text, J, I - J); 272 end else begin 273 while not IsWhiteSpace(Text[I]) do Inc(I); 274 Result := Copy(Text, J, I - J); 275 end; 276 end; 277 J := I; 278 end; 279 if Shift then CodePosition := J; 280 end; 281 282 function TPascalParser.ReadCode: string; 283 begin 284 Result := NextCode(True); 271 end; 272 end; 273 274 function TBaseParser.ReadCode: string; 275 begin 276 Result := FNextToken; 277 GetNextToken; 285 278 Log('Read: ' + Result); 286 279 end; … … 288 281 { TParserWhileDo } 289 282 290 class procedure TParserWhileDo.Parse(Parser: TPascalParser;SourceCode: TWhileDo);291 begin 292 with Parser,SourceCode do begin283 procedure TPascalParser.ParseWhileDo(SourceCode: TWhileDo); 284 begin 285 with SourceCode do begin 293 286 Expect('while'); 294 287 Condition.CommonBlock := CommonBlock; 295 TParserExpression.Parse(Parser,Condition);288 ParseExpression(Condition); 296 289 Expect('do'); 297 Command := TParserCommonBlock.ParseCommand(Parser,CommonBlock);290 Command := ParseCommand(CommonBlock); 298 291 end; 299 292 end; … … 301 294 { TExpression } 302 295 303 class function TParserExpression.Parse(Parser: TPascalParser; 304 SourceCode: TExpression): TExpression; 296 function TPascalParser.ParseExpression(SourceCode: TExpression): TExpression; 305 297 var 306 298 Identifier: string; … … 316 308 Expressions := TExpressionList.Create; 317 309 Expressions.Add(TExpression.Create); 318 with Parser,SourceCode do begin319 while (( NextCode <> ';') and (NextCode <> ',') and (not IsKeyWord(NextCode))) and320 not ((( NextCode = ')') or (NextCode= ']'))) do begin310 with SourceCode do begin 311 while ((FNextToken <> ';') and (FNextToken <> ',') and (not IsKeyWord(FNextToken))) and 312 not (((FNextToken = ')') or (FNextToken = ']'))) do begin 321 313 Identifier := ReadCode; 322 314 if Identifier = '(' then begin … … 324 316 with TExpression(Expressions.Last) do begin 325 317 SubItems[1] := TExpression.Create; 326 TParserExpression.Parse(Parser,TExpression(SubItems[1]));318 ParseExpression(TExpression(SubItems[1])); 327 319 end; 328 320 with TExpression(Expressions.Items[Expressions.Add(TExpression.Create)]) do begin … … 357 349 with TExpression(Expressions.Last) do begin 358 350 SubItems[1] := TExpression.Create; 359 if NextCode= '(' then // Method with parameters351 if FNextToken = '(' then // Method with parameters 360 352 with TExpression(SubItems[1]) do begin 361 353 Expect('('); 362 354 NewExpression := TExpression.Create; 363 355 NewExpression.CommonBlock := CommonBlock; 364 TParserExpression.Parse(Parser,NewExpression);356 ParseExpression(NewExpression); 365 357 SubItems.Add(NewExpression); 366 while NextCode= ',' do begin358 while FNextToken = ',' do begin 367 359 Expect(','); 368 360 NewExpression := TExpression.Create; 369 361 NewExpression.CommonBlock := CommonBlock; 370 TParserExpression.Parse(Parser,NewExpression);362 ParseExpression(NewExpression); 371 363 SubItems.Add(NewExpression); 372 364 end; … … 444 436 end; 445 437 446 class function TParserCommonBlock.ParseCommand(Parser: TPascalParser;SourceCode: TCommonBlock): TCommand;438 function TPascalParser.ParseCommand(SourceCode: TCommonBlock): TCommand; 447 439 var 448 440 Identifier: string; … … 455 447 IdentName: string; 456 448 begin 457 with Parser dobegin458 if NextCode= 'begin' then begin449 begin 450 if FNextToken = 'begin' then begin 459 451 Result := TBeginEnd.Create; 460 452 TBeginEnd(Result).CommonBlock := SourceCode; 461 453 //ShowMessage(IntToStr(Integer(SourceCode)) 462 454 // + ' ' + IntToStr(Integer(Result))); 463 TParserBeginEnd.Parse(Parser,TBeginEnd(Result));455 ParseBeginEnd(TBeginEnd(Result)); 464 456 end else 465 if NextCode= 'if' then begin457 if FNextToken = 'if' then begin 466 458 Result := TIfThenElse.Create; 467 459 TIfThenElse(Result).CommonBlock := SourceCode; 468 TParserIfThenElse.Parse(Parser,TIfThenElse(Result));460 ParseIfThenElse(TIfThenElse(Result)); 469 461 end else 470 if NextCode= 'while' then begin462 if FNextToken = 'while' then begin 471 463 Result := TWhileDo.Create; 472 464 TWhileDo(Result).CommonBlock := SourceCode; 473 TParserWhileDo.Parse(Parser,TWhileDo(Result));465 ParseWhileDo(TWhileDo(Result)); 474 466 end else 475 if IsIdentificator( NextCode) then begin476 if Assigned(SourceCode.Variables.Search( NextCode)) then begin467 if IsIdentificator(FNextToken) then begin 468 if Assigned(SourceCode.Variables.Search(FNextToken)) then begin 477 469 Result := TAssignment.Create; 478 470 TAssignment(Result).CommonBlock := SourceCode; … … 482 474 TAssignment(Result).Source := TExpression.Create; 483 475 TAssignment(Result).Source.CommonBlock := SourceCode; 484 TParserExpression.Parse(Parser,TAssignment(Result).Source);476 ParseExpression(TAssignment(Result).Source); 485 477 end else 486 if Assigned(SourceCode.Methods.Search( NextCode)) then begin478 if Assigned(SourceCode.Methods.Search(FNextToken)) then begin 487 479 Result := TMethodCall.Create; 488 480 TMethodCall(Result).CommonBlock := SourceCode; 489 TMethodCall(Result).Method := SourceCode.Methods.Search( NextCode);481 TMethodCall(Result).Method := SourceCode.Methods.Search(FNextToken); 490 482 ReadCode; 491 483 // ParseMetVariable(TMethodCall(Result).Target); … … 503 495 { TParserModule } 504 496 505 class procedure TParserModule.Parse(Parser: TPascalParser; SourceCode: TModule); 506 begin 507 with Parser do begin 508 if NextCode = 'program' then 509 ParseProgram(Parser, SourceCode) 510 else if NextCode = 'unit' then 511 ParseUnit(Parser, SourceCode) 512 else ParseProgram(Parser, SourceCode); 513 end; 514 end; 515 516 class procedure TParserModule.ParseProgram(Parser: TPascalParser; SourceCode: TModule); 497 procedure TPascalParser.ParseModule(SourceCode: TModule); 498 begin 499 if FNextToken = 'program' then 500 ParseProgram(SourceCode) 501 else if FNextToken = 'unit' then 502 ParseUnit(SourceCode) 503 else ParseProgram(SourceCode); 504 end; 505 506 procedure TPascalParser.ParseProgram(SourceCode: TModule); 517 507 var 518 508 Identifier: string; 519 509 begin 520 with Parser,SourceCode do begin521 if NextCode= 'program' then begin510 with SourceCode do begin 511 if FNextToken = 'program' then begin 522 512 Expect('program'); 523 513 Name := ReadCode; … … 527 517 528 518 // Uses section 529 if NextCode = 'uses' then 530 TParserUsedModuleList.Parse(Parser, UsedModules); 531 532 TParserCommonBlock.Parse(Parser, SourceCode, '.'); 533 end; 534 end; 535 536 class procedure TParserModule.ParseUnit(Parser: TPascalParser; SourceCode: TModule); 537 begin 538 with Parser do begin 539 Expect('unit'); 540 with TModule(ProgramCode.Modules[0]) do begin 541 Name := ReadCode; 542 ModuleType := mdUnit; 543 end; 544 Expect(';'); 545 //ParseInterface; 546 //ParseImplementation; 547 end; 519 if FNextToken = 'uses' then 520 ParseUsedModuleList(UsedModules); 521 522 ParseCommonBlock(SourceCode, '.'); 523 end; 524 end; 525 526 procedure TPascalParser.ParseUnit(SourceCode: TModule); 527 begin 528 Expect('unit'); 529 with TModule(ProgramCode.Modules[0]) do begin 530 Name := ReadCode; 531 ModuleType := mdUnit; 532 end; 533 Expect(';'); 534 //ParseInterface; 535 //ParseImplementation; 548 536 end; 549 537 550 538 { TParserProgram } 551 539 552 class procedure TParserProgram.Parse(Parser: TPascalParser; SourceCode: TProgram); 553 var 554 I: Integer; 555 begin 556 with Parser, SourceCode do begin 557 Log('==== Parse start ===='); 558 Modules.Clear; 559 with TModule(Modules[Modules.Add(TModule.Create)]) do begin 560 Name := 'Main'; 561 with TType(Types[Types.Add(TType.Create)]) do begin 562 Name := 'Void'; 563 Size := 0; 564 UsedType := nil; 565 end; 566 with TType(Types[Types.Add(TType.Create)]) do begin 567 Name := 'Byte'; 568 Size := 1; 569 UsedType := nil; 570 end; 571 with TFunction(Methods[Methods.Add(TFunction.Create)]) do begin 572 Name := 'Exit'; 573 ResultType := TType(TModule(Modules[0]).Types[0]); 574 end; 575 with TFunction(Methods[Methods.Add(TFunction.Create)]) do begin 576 Name := 'WriteLn'; 577 ResultType := TType(TModule(Modules[0]).Types[0]); 578 end; 579 end; 580 TParserModule.Parse(Parser, TModule(Modules[0])); 540 procedure TPascalParser.ParseAll(SourceCode: TProgram); 541 var 542 I: Integer; 543 begin 544 with SourceCode do begin 545 ParseModule(TModule(Modules[0])); 581 546 end; 582 547 end; … … 584 549 { TParserCommonBlock } 585 550 586 class procedure TParserCommonBlock.Parse(Parser: TPascalParser;SourceCode: TCommonBlock; EndSymbol: Char = ';');587 begin 588 with Parser,SourceCode do begin589 while NextCode<> EndSymbol do begin590 if NextCode= 'var' then591 TParserVariableList.Parse(Parser,Variables)592 else if NextCode= 'const' then593 TParserConstantList.Parse(Parser,Constants)594 else if NextCode= 'type' then595 TParserTypeList.Parse(Parser,Types)596 else if NextCode= 'procedure' then597 TParserFunctionList.Parse(Parser,Methods)551 procedure TPascalParser.ParseCommonBlock(SourceCode: TCommonBlock; EndSymbol: Char = ';'); 552 begin 553 with SourceCode do begin 554 while FNextToken <> EndSymbol do begin 555 if FNextToken = 'var' then 556 ParseVariableList(Variables) 557 else if FNextToken = 'const' then 558 ParseConstantList(Constants) 559 else if FNextToken = 'type' then 560 ParseTypeList(Types) 561 else if FNextToken = 'procedure' then 562 ParseFunctionList(Methods) 598 563 else begin 599 TParserBeginEnd.Parse(Parser,Code);564 ParseBeginEnd(Code); 600 565 Break; 601 566 end; … … 607 572 { TParserBeginEnd } 608 573 609 class procedure TParserBeginEnd.Parse(Parser: TPascalParser;SourceCode: TBeginEnd);574 procedure TPascalParser.ParseBeginEnd(SourceCode: TBeginEnd); 610 575 var 611 576 NewCommand: TCommand; 612 577 begin 613 578 //ShowMessage(IntToStr(Integer(SourceCode)) + ' ' + IntToStr(Integer(SourceCode.CommonBlock))); 614 with Parser,SourceCode do begin579 with SourceCode do begin 615 580 Expect('begin'); 616 while NextCode <> 'end' do begin 617 NewCommand := TParserCommonBlock.ParseCommand(Parser, CommonBlock); 581 while FNextToken <> 'end' do begin 582 Commands.Add(nil); 583 NewCommand := ParseCommand(CommonBlock); 618 584 if Assigned(NewCommand) then Commands.Add(NewCommand); 619 585 //ShowMessage(NextCode); 620 if NextCode= ';' then ReadCode;586 if FNextToken = ';' then ReadCode; 621 587 end; 622 588 Expect('end'); … … 626 592 { TParserParseFunctionList } 627 593 628 class procedure TParserFunctionList.Parse(Parser: TPascalParser;SourceCode: TFunctionList);594 procedure TPascalParser.ParseFunctionList(SourceCode: TFunctionList); 629 595 var 630 596 Identifiers: TStringList; … … 636 602 begin 637 603 Identifiers := TStringList.Create; 638 with Parser,SourceCode do begin604 with SourceCode do begin 639 605 with TFunction(Items[Add(TFunction.Create)]) do begin 640 606 Parent := SourceCode.Parent; 641 607 Expect('procedure'); 642 608 Name := ReadCode; 643 if NextCode= '(' then begin609 if FNextToken = '(' then begin 644 610 Expect('('); 645 while NextCode<> ')' do begin611 while FNextToken <> ')' do begin 646 612 // while IsIdentificator(NextCode) do begin 647 613 with TParameterList(Parameters) do begin … … 650 616 if not Assigned(Variable) then begin 651 617 Identifiers.Add(VariableName); 652 while NextCode= ',' do begin618 while FNextToken = ',' do begin 653 619 Expect(','); 654 620 Identifiers.Add(ReadCode); … … 670 636 end; 671 637 Expect(';'); 672 TParserCommonBlock.Parse(Parser,TFunction(Items[Count - 1]));638 ParseCommonBlock(TFunction(Items[Count - 1])); 673 639 end; 674 640 Identifiers.Destroy; … … 677 643 { TParserIfThenElse } 678 644 679 class procedure TParserIfThenElse.Parse(Parser: TPascalParser;SourceCode: TIfThenElse);680 begin 681 with Parser,Sourcecode do begin645 procedure TPascalParser.ParseIfThenElse(SourceCode: TIfThenElse); 646 begin 647 with Sourcecode do begin 682 648 Expect('if'); 683 649 Condition.CommonBlock := CommonBlock; 684 TParserExpression.Parse(Parser,Condition);650 ParseExpression(Condition); 685 651 Expect('then'); 686 Command := TParserCommonBlock.ParseCommand(Parser,CommonBlock);687 if NextCode= 'else' then begin652 Command := ParseCommand(CommonBlock); 653 if FNextToken = 'else' then begin 688 654 Expect('else'); 689 ElseCommand := TParserCommonBlock.ParseCommand(Parser,CommonBlock);655 ElseCommand := ParseCommand(CommonBlock); 690 656 end; 691 657 end; … … 694 660 { TParserVariableList } 695 661 696 class procedure TParserVariableList.Parse(Parser: TPascalParser;SourceCode: TVariableList);662 procedure TPascalParser.ParseVariableList(SourceCode: TVariableList); 697 663 var 698 664 Identifiers: TStringList; … … 704 670 begin 705 671 Identifiers := TStringList.Create; 706 with Parser,SourceCode do begin672 with SourceCode do begin 707 673 Expect('var'); 708 while IsIdentificator( NextCode) do begin674 while IsIdentificator(FNextToken) do begin 709 675 Identifiers.Clear; 710 676 VariableName := ReadCode; … … 712 678 if not Assigned(Variable) then begin 713 679 Identifiers.Add(VariableName); 714 while NextCode= ',' do begin680 while FNextToken = ',' do begin 715 681 Expect(','); 716 682 Identifiers.Add(ReadCode); … … 734 700 { TParserVariable } 735 701 736 class procedure TParserVariable.Parse(Parser: TPascalParser;SourceCode: TVariable);737 begin 738 with Parser,SourceCode do begin739 Name := NextCode;702 procedure TPascalParser.ParseVariable(SourceCode: TVariable); 703 begin 704 with SourceCode do begin 705 Name := FNextToken; 740 706 Expect(':='); 741 707 … … 745 711 { TParserConstantList } 746 712 747 class procedure TParserConstantList.Parse(Parser: TPascalParser;SourceCode: TConstantList);713 procedure TPascalParser.ParseConstantList(SourceCode: TConstantList); 748 714 var 749 715 Identifiers: TStringList; … … 756 722 begin 757 723 Identifiers := TStringList.Create; 758 with Parser,SourceCode do begin724 with SourceCode do begin 759 725 Expect('const'); 760 while IsIdentificator( NextCode) do begin726 while IsIdentificator(FNextToken) do begin 761 727 ConstantName := ReadCode; 762 728 Constant := Search(ConstantName); 763 729 if not Assigned(Constant) then begin 764 730 Identifiers.Add(ConstantName); 765 while NextCode= ',' do begin731 while FNextToken = ',' do begin 766 732 Expect(','); 767 733 Identifiers.Add(ReadCode); … … 789 755 { TParserTypeList } 790 756 791 class procedure TParserTypeList.Parse(Parser: TPascalParser;SourceCode: TTypeList);792 begin 793 with Parser,SourceCode do begin757 procedure TPascalParser.ParseTypeList(SourceCode: TTypeList); 758 begin 759 with SourceCode do begin 794 760 Expect('type'); 795 while IsIdentificator( NextCode) do761 while IsIdentificator(FNextToken) do 796 762 with TType(Items[Add(TType.Create)]) do begin 797 763 Parent := SourceCode; 798 TParserType.Parse(Parser,TType(Items[Count - 1]));764 ParseType(TType(Items[Count - 1])); 799 765 end; 800 766 end; … … 803 769 { TParserType } 804 770 805 class procedure TParserType.Parse(Parser: TPascalParser;SourceCode: TType);806 begin 807 with Parser,SourceCode do begin808 Name := NextCode;771 procedure TPascalParser.ParseType(SourceCode: TType); 772 begin 773 with SourceCode do begin 774 Name := FNextToken; 809 775 Expect('='); 810 UsedType := Parent.Search( NextCode);776 UsedType := Parent.Search(FNextToken); 811 777 end; 812 778 end; … … 814 780 { TParserUsedModuleList } 815 781 816 class procedure TParserUsedModuleList.Parse(Parser: TPascalParser; 817 SourceCode: TUsedModuleList); 782 procedure TPascalParser.ParseUsedModuleList(SourceCode: TUsedModuleList); 818 783 var 819 784 NewUsedModule: TUsedModule; 820 785 begin 821 with Parser do begin 822 Expect('uses'); 786 Expect('uses'); 787 with TUsedModule(SourceCode.Items[SourceCode.Add(TUsedModule.Create)]) do begin 788 Name := ReadCode; 789 end; 790 while FNextToken = ',' do begin 791 Expect(','); 823 792 with TUsedModule(SourceCode.Items[SourceCode.Add(TUsedModule.Create)]) do begin 824 793 Name := ReadCode; 825 794 end; 826 while NextCode = ',' do begin 827 Expect(','); 828 with TUsedModule(SourceCode.Items[SourceCode.Add(TUsedModule.Create)]) do begin 829 Name := ReadCode; 830 end; 831 end; 832 Expect(';'); 833 end; 795 end; 796 Expect(';'); 834 797 end; 835 798 -
branches/DelphiToC/DelphiToC.lpi
r43 r44 40 40 <Filename Value="DelphiToC.lpr"/> 41 41 <IsPartOfProject Value="True"/> 42 <IsVisibleTab Value="True"/>43 42 <EditorIndex Value="11"/> 44 43 <WindowIndex Value="0"/> 45 44 <TopLine Value="4"/> 46 <CursorPos X=" 27" Y="16"/>47 <UsageCount Value=" 66"/>45 <CursorPos X="1" Y="27"/> 46 <UsageCount Value="103"/> 48 47 <Loaded Value="True"/> 49 48 </Unit0> … … 57 56 <EditorIndex Value="7"/> 58 57 <WindowIndex Value="0"/> 59 <TopLine Value=" 69"/>60 <CursorPos X=" 1" Y="91"/>61 <UsageCount Value=" 66"/>58 <TopLine Value="34"/> 59 <CursorPos X="40" Y="49"/> 60 <UsageCount Value="103"/> 62 61 <Loaded Value="True"/> 63 62 <LoadedDesigner Value="True"/> … … 70 69 <TopLine Value="1"/> 71 70 <CursorPos X="1" Y="1"/> 72 <UsageCount Value=" 66"/>71 <UsageCount Value="103"/> 73 72 </Unit2> 74 73 <Unit3> … … 78 77 <EditorIndex Value="5"/> 79 78 <WindowIndex Value="0"/> 80 <TopLine Value=" 15"/>81 <CursorPos X=" 19" Y="34"/>82 <UsageCount Value=" 66"/>79 <TopLine Value="294"/> 80 <CursorPos X="25" Y="296"/> 81 <UsageCount Value="103"/> 83 82 <Loaded Value="True"/> 84 83 </Unit3> … … 90 89 <WindowIndex Value="0"/> 91 90 <TopLine Value="25"/> 92 <CursorPos X=" 21" Y="38"/>93 <UsageCount Value=" 66"/>91 <CursorPos X="1" Y="38"/> 92 <UsageCount Value="103"/> 94 93 <Loaded Value="True"/> 95 94 </Unit4> … … 102 101 <TopLine Value="1"/> 103 102 <CursorPos X="9" Y="12"/> 104 <UsageCount Value=" 66"/>103 <UsageCount Value="103"/> 105 104 <Loaded Value="True"/> 106 105 </Unit5> … … 113 112 <TopLine Value="1"/> 114 113 <CursorPos X="1" Y="1"/> 115 <UsageCount Value=" 66"/>114 <UsageCount Value="103"/> 116 115 <Loaded Value="True"/> 117 116 </Unit6> … … 124 123 <TopLine Value="75"/> 125 124 <CursorPos X="63" Y="89"/> 126 <UsageCount Value=" 66"/>125 <UsageCount Value="103"/> 127 126 <Loaded Value="True"/> 128 127 </Unit7> … … 131 130 <IsPartOfProject Value="True"/> 132 131 <UnitName Value="UPascalParser"/> 132 <IsVisibleTab Value="True"/> 133 133 <EditorIndex Value="0"/> 134 134 <WindowIndex Value="0"/> 135 <TopLine Value=" 136"/>136 <CursorPos X=" 1" Y="149"/>137 <UsageCount Value=" 66"/>135 <TopLine Value="540"/> 136 <CursorPos X="3" Y="544"/> 137 <UsageCount Value="103"/> 138 138 <Loaded Value="True"/> 139 139 </Unit8> … … 143 143 <TopLine Value="1"/> 144 144 <CursorPos X="1" Y="1"/> 145 <UsageCount Value=" 5"/>145 <UsageCount Value="2"/> 146 146 <DefaultSyntaxHighlighter Value="LFM"/> 147 147 </Unit9> … … 153 153 <TopLine Value="68"/> 154 154 <CursorPos X="14" Y="90"/> 155 <UsageCount Value=" 33"/>155 <UsageCount Value="51"/> 156 156 <Loaded Value="True"/> 157 157 </Unit10> … … 162 162 <TopLine Value="1555"/> 163 163 <CursorPos X="1" Y="1"/> 164 <UsageCount Value=" 9"/>164 <UsageCount Value="6"/> 165 165 </Unit11> 166 166 <Unit12> … … 170 170 <TopLine Value="61"/> 171 171 <CursorPos X="7" Y="68"/> 172 <UsageCount Value=" 16"/>172 <UsageCount Value="34"/> 173 173 <Loaded Value="True"/> 174 174 </Unit12> … … 179 179 <TopLine Value="139"/> 180 180 <CursorPos X="16" Y="146"/> 181 <UsageCount Value=" 16"/>181 <UsageCount Value="34"/> 182 182 <Loaded Value="True"/> 183 183 </Unit13> … … 187 187 <TopLine Value="934"/> 188 188 <CursorPos X="10" Y="947"/> 189 <UsageCount Value="1 3"/>189 <UsageCount Value="10"/> 190 190 </Unit14> 191 191 <Unit15> … … 194 194 <TopLine Value="834"/> 195 195 <CursorPos X="11" Y="847"/> 196 <UsageCount Value=" 9"/>196 <UsageCount Value="6"/> 197 197 </Unit15> 198 198 <Unit16> … … 201 201 <TopLine Value="153"/> 202 202 <CursorPos X="8" Y="166"/> 203 <UsageCount Value=" 12"/>203 <UsageCount Value="9"/> 204 204 </Unit16> 205 205 <Unit17> … … 209 209 <EditorIndex Value="2"/> 210 210 <WindowIndex Value="0"/> 211 <TopLine Value="1 12"/>212 <CursorPos X="1" Y=" 128"/>213 <UsageCount Value=" 28"/>211 <TopLine Value="198"/> 212 <CursorPos X="1" Y="215"/> 213 <UsageCount Value="65"/> 214 214 <Loaded Value="True"/> 215 215 </Unit17> … … 220 220 <TopLine Value="2656"/> 221 221 <CursorPos X="3" Y="2669"/> 222 <UsageCount Value=" 9"/>222 <UsageCount Value="6"/> 223 223 </Unit18> 224 224 </Units> 225 225 <JumpHistory Count="30" HistoryIndex="29"> 226 226 <Position1> 227 <Filename Value=" Analyze\UPascalParser.pas"/>228 <Caret Line="2 34" Column="1" TopLine="213"/>227 <Filename Value="Visual\USourceTree.pas"/> 228 <Caret Line="228" Column="1" TopLine="220"/> 229 229 </Position1> 230 230 <Position2> 231 <Filename Value=" Analyze\UPascalParser.pas"/>232 <Caret Line="2 38" Column="1" TopLine="217"/>231 <Filename Value="Visual\USourceTree.pas"/> 232 <Caret Line="211" Column="22" TopLine="198"/> 233 233 </Position2> 234 234 <Position3> 235 <Filename Value=" Analyze\UPascalParser.pas"/>236 <Caret Line="24 2" Column="1" TopLine="221"/>235 <Filename Value="Visual\USourceTree.pas"/> 236 <Caret Line="24" Column="15" TopLine="11"/> 237 237 </Position3> 238 238 <Position4> 239 <Filename Value=" Analyze\UPascalParser.pas"/>240 <Caret Line="2 48" Column="1" TopLine="235"/>239 <Filename Value="Visual\USourceTree.pas"/> 240 <Caret Line="211" Column="16" TopLine="198"/> 241 241 </Position4> 242 242 <Position5> 243 <Filename Value=" Analyze\UPascalParser.pas"/>244 <Caret Line="2 64" Column="1" TopLine="251"/>243 <Filename Value="Visual\USourceTree.pas"/> 244 <Caret Line="228" Column="32" TopLine="215"/> 245 245 </Position5> 246 246 <Position6> 247 <Filename Value=" Analyze\UPascalParser.pas"/>248 <Caret Line="2 66" Column="1" TopLine="251"/>247 <Filename Value="Visual\USourceTree.pas"/> 248 <Caret Line="237" Column="1" TopLine="216"/> 249 249 </Position6> 250 250 <Position7> 251 <Filename Value=" Analyze\UPascalParser.pas"/>252 <Caret Line="2 25" Column="1" TopLine="212"/>251 <Filename Value="Visual\USourceTree.pas"/> 252 <Caret Line="238" Column="1" TopLine="217"/> 253 253 </Position7> 254 254 <Position8> 255 <Filename Value=" Analyze\UPascalParser.pas"/>256 <Caret Line="2 27" Column="1" TopLine="212"/>255 <Filename Value="Visual\USourceTree.pas"/> 256 <Caret Line="239" Column="1" TopLine="218"/> 257 257 </Position8> 258 258 <Position9> 259 <Filename Value=" Analyze\UPascalParser.pas"/>260 <Caret Line="2 29" Column="1" TopLine="212"/>259 <Filename Value="Visual\USourceTree.pas"/> 260 <Caret Line="202" Column="1" TopLine="189"/> 261 261 </Position9> 262 262 <Position10> 263 <Filename Value=" Analyze\UPascalParser.pas"/>264 <Caret Line="2 30" Column="1" TopLine="212"/>263 <Filename Value="Visual\USourceTree.pas"/> 264 <Caret Line="203" Column="1" TopLine="189"/> 265 265 </Position10> 266 266 <Position11> 267 <Filename Value=" Analyze\UPascalParser.pas"/>268 <Caret Line="2 34" Column="1" TopLine="213"/>267 <Filename Value="Visual\USourceTree.pas"/> 268 <Caret Line="205" Column="1" TopLine="189"/> 269 269 </Position11> 270 270 <Position12> 271 <Filename Value=" Analyze\UPascalParser.pas"/>272 <Caret Line="2 38" Column="1" TopLine="217"/>271 <Filename Value="Visual\USourceTree.pas"/> 272 <Caret Line="209" Column="1" TopLine="195"/> 273 273 </Position12> 274 274 <Position13> 275 <Filename Value=" Analyze\UPascalParser.pas"/>276 <Caret Line="2 42" Column="1" TopLine="221"/>275 <Filename Value="Visual\USourceTree.pas"/> 276 <Caret Line="210" Column="20" TopLine="195"/> 277 277 </Position13> 278 278 <Position14> 279 <Filename Value=" Analyze\UPascalParser.pas"/>280 <Caret Line="2 48" Column="1" TopLine="235"/>279 <Filename Value="Visual\USourceTree.pas"/> 280 <Caret Line="235" Column="1" TopLine="222"/> 281 281 </Position14> 282 282 <Position15> 283 <Filename Value=" Analyze\UPascalParser.pas"/>284 <Caret Line="2 63" Column="18" TopLine="251"/>283 <Filename Value="Visual\USourceTree.pas"/> 284 <Caret Line="236" Column="1" TopLine="222"/> 285 285 </Position15> 286 286 <Position16> 287 <Filename Value=" Analyze\UPascalParser.pas"/>288 <Caret Line=" 149" Column="3" TopLine="147"/>287 <Filename Value="Visual\USourceTree.pas"/> 288 <Caret Line="237" Column="1" TopLine="222"/> 289 289 </Position16> 290 290 <Position17> 291 <Filename Value=" Analyze\UPascalParser.pas"/>292 <Caret Line="2 66" Column="1" TopLine="253"/>291 <Filename Value="Visual\USourceTree.pas"/> 292 <Caret Line="202" Column="1" TopLine="201"/> 293 293 </Position17> 294 294 <Position18> 295 <Filename Value=" Analyze\UPascalParser.pas"/>296 <Caret Line="2 25" Column="1" TopLine="212"/>295 <Filename Value="Visual\USourceTree.pas"/> 296 <Caret Line="203" Column="1" TopLine="198"/> 297 297 </Position18> 298 298 <Position19> 299 <Filename Value=" Analyze\UPascalParser.pas"/>300 <Caret Line="2 27" Column="1" TopLine="212"/>299 <Filename Value="Visual\USourceTree.pas"/> 300 <Caret Line="205" Column="1" TopLine="198"/> 301 301 </Position19> 302 302 <Position20> 303 <Filename Value=" Analyze\UPascalParser.pas"/>304 <Caret Line="2 29" Column="1" TopLine="212"/>303 <Filename Value="Visual\USourceTree.pas"/> 304 <Caret Line="209" Column="1" TopLine="198"/> 305 305 </Position20> 306 306 <Position21> 307 <Filename Value=" Analyze\UPascalParser.pas"/>308 <Caret Line="2 30" Column="1" TopLine="212"/>307 <Filename Value="Visual\USourceTree.pas"/> 308 <Caret Line="210" Column="1" TopLine="198"/> 309 309 </Position21> 310 310 <Position22> 311 <Filename Value=" Analyze\UPascalParser.pas"/>312 <Caret Line="2 34" Column="1" TopLine="213"/>311 <Filename Value="Visual\USourceTree.pas"/> 312 <Caret Line="211" Column="1" TopLine="198"/> 313 313 </Position22> 314 314 <Position23> 315 <Filename Value=" Analyze\UPascalParser.pas"/>316 <Caret Line="2 38" Column="1" TopLine="217"/>315 <Filename Value="Visual\USourceTree.pas"/> 316 <Caret Line="212" Column="1" TopLine="198"/> 317 317 </Position23> 318 318 <Position24> 319 <Filename Value=" Analyze\UPascalParser.pas"/>320 <Caret Line="2 42" Column="1" TopLine="221"/>319 <Filename Value="Visual\USourceTree.pas"/> 320 <Caret Line="213" Column="1" TopLine="198"/> 321 321 </Position24> 322 322 <Position25> 323 <Filename Value=" Analyze\UPascalParser.pas"/>324 <Caret Line="2 48" Column="1" TopLine="235"/>323 <Filename Value="Visual\USourceTree.pas"/> 324 <Caret Line="214" Column="1" TopLine="198"/> 325 325 </Position25> 326 326 <Position26> 327 327 <Filename Value="Analyze\UPascalParser.pas"/> 328 <Caret Line=" 149" Column="1" TopLine="136"/>328 <Caret Line="625" Column="33" TopLine="610"/> 329 329 </Position26> 330 330 <Position27> 331 331 <Filename Value="Analyze\UPascalParser.pas"/> 332 <Caret Line=" 150" Column="1" TopLine="136"/>332 <Caret Line="605" Column="16" TopLine="604"/> 333 333 </Position27> 334 334 <Position28> 335 335 <Filename Value="Analyze\UPascalParser.pas"/> 336 <Caret Line=" 250" Column="36" TopLine="228"/>336 <Caret Line="606" Column="23" TopLine="589"/> 337 337 </Position28> 338 338 <Position29> 339 <Filename Value=" DelphiToC.lpr"/>340 <Caret Line=" 12" Column="39" TopLine="3"/>339 <Filename Value="Analyze\UPascalParser.pas"/> 340 <Caret Line="522" Column="19" TopLine="506"/> 341 341 </Position29> 342 342 <Position30> 343 <Filename Value=" DelphiToC.lpr"/>344 <Caret Line=" 16" Column="38" TopLine="4"/>343 <Filename Value="Analyze\UPascalParser.pas"/> 344 <Caret Line="562" Column="22" TopLine="551"/> 345 345 </Position30> 346 346 </JumpHistory> … … 383 383 </CompilerOptions> 384 384 <Debugging> 385 <BreakPoints Count=" 1">385 <BreakPoints Count="3"> 386 386 <Item1> 387 <Source Value="Visual\USourceTree.pas"/> 388 <Line Value="234"/> 389 </Item1> 390 <Item2> 391 <Source Value="Visual\USourceTree.pas"/> 392 <Line Value="202"/> 393 </Item2> 394 <Item3> 387 395 <Source Value="Analyze\UPascalParser.pas"/> 388 <Line Value=" 456"/>389 </Item 1>396 <Line Value="543"/> 397 </Item3> 390 398 </BreakPoints> 391 399 <Exceptions Count="3"> -
branches/DelphiToC/Example.pas
r43 r44 28 28 end; 29 29 while A < 1 do A := A + 1; 30 31 32 {33 Block comment 234 }35 30 WriteLn; 36 31 end. -
branches/DelphiToC/UPascalCompiler.pas
r43 r44 11 11 12 12 type 13 14 { TCompiler } 15 13 16 TCompiler = class 14 17 private 15 18 FOnErrorMessage: TOnErrorMessage; 16 19 procedure ErrorMessage(Text: string); 20 procedure Init; 17 21 public 18 22 ProgramCode: TProgram; … … 32 36 procedure TCompiler.Compile; 33 37 begin 34 Parser.CodePosition := 1; 38 Init; 39 Parser.Init; 35 40 try 36 TParserProgram.Parse(Parser,ProgramCode);41 Parser.ParseAll(ProgramCode); 37 42 except 38 43 on EEndOfData do ; … … 65 70 end; 66 71 72 procedure TCompiler.Init; 73 begin 74 with Parser do begin 75 Log('==== Parse start ===='); 76 with ProgramCode do begin 77 Modules.Clear; 78 79 with TModule(Modules[Modules.Add(TModule.Create)]) do begin 80 Name := 'Main'; 81 with TType(Types[Types.Add(TType.Create)]) do begin 82 Name := 'Void'; 83 Size := 0; 84 UsedType := nil; 85 end; 86 with TType(Types[Types.Add(TType.Create)]) do begin 87 Name := 'Byte'; 88 Size := 1; 89 UsedType := nil; 90 end; 91 with TFunction(Methods[Methods.Add(TFunction.Create)]) do begin 92 Name := 'Exit'; 93 ResultType := TType(TModule(Modules[0]).Types[0]); 94 end; 95 with TFunction(Methods[Methods.Add(TFunction.Create)]) do begin 96 Name := 'WriteLn'; 97 ResultType := TType(TModule(Modules[0]).Types[0]); 98 end; 99 end; 100 end; 101 end; 102 end; 103 67 104 end. -
branches/DelphiToC/UPascalSource.pas
r43 r44 241 241 TFunction = class(TCommonBlock) 242 242 public 243 Parameters: T ObjectList; // TObjectList<TVariable>243 Parameters: TParameterList; 244 244 ResultType: TType; 245 245 constructor Create; override; … … 296 296 inherited; 297 297 Parameters := TParameterList.Create; 298 TParameterList(Parameters).Parent := Self;298 Parameters.Parent := Self; 299 299 //ResultType := TType.Create; 300 300 end; -
branches/DelphiToC/Visual/USourceTree.pas
r42 r44 23 23 procedure AddNodeConstantList(Node: TTreeNode; Constants: TConstantList); 24 24 procedure AddNodeModule(Node: TTreeNode; Module: TModule); 25 procedure AddNodeUses(Node: TTreeNode; UsedModuleList: TUsedModuleList); 25 26 procedure AddNodeProgram(Node: TTreeNode; Code: TProgram); 26 27 procedure AddNodeWhileDo(Node: TTreeNode; WhileDo: TWhileDo); … … 207 208 end; 208 209 NewNode := TreeView.Items.AddChild(Node, TypeName + ' ' + Module.Name); 209 for I := 0 to Module.Constants.Count - 1 do begin 210 AddNodeMethodList(NewNode, Module.Methods); 211 AddNodeConstantList(NewNode, Module.Constants); 212 AddNodeVariableList(NewNode, Module.Variables); 213 AddNodeTypeList(NewNode, Module.Types); 214 AddNodeBeginEnd(NewNode, Module.Code); 210 AddNodeUses(NewNode, Module.UsedModules); 211 AddNodeMethodList(NewNode, Module.Methods); 212 AddNodeConstantList(NewNode, Module.Constants); 213 AddNodeVariableList(NewNode, Module.Variables); 214 AddNodeTypeList(NewNode, Module.Types); 215 AddNodeBeginEnd(NewNode, Module.Code); 216 end; 217 218 procedure TSourceTree.AddNodeUses(Node: TTreeNode; 219 UsedModuleList: TUsedModuleList); 220 var 221 NewNode: TTreeNode; 222 I: Integer; 223 begin 224 NewNode := TreeView.Items.AddChild(Node, 'uses'); 225 for I := 0 to UsedModuleList.Count - 1 do begin 226 TreeView.Items.AddChild(NewNode, TUsedModule(UsedModuleList[I]).Name); 215 227 end; 216 228 end;
Note:
See TracChangeset
for help on using the changeset viewer.