Changeset 77 for branches/Transpascal/Compiler
- Timestamp:
- Oct 22, 2010, 9:22:55 AM (15 years ago)
- Location:
- branches/Transpascal/Compiler
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Transpascal/Compiler/Analyze/UParser.pas
r76 r77 64 64 procedure Expect(Code: string); 65 65 procedure ErrorMessage(const Text: string; const Arguments: array of const; 66 TokenOffset: Integer );66 TokenOffset: Integer = -1); 67 67 property OnErrorMessage: TErrorMessageEvent read FOnErrorMessage write FOnErrorMessage; 68 68 property OnDebugLog: TDebugLogEvent read FOnDebugLog write FOnDebugLog; … … 80 80 81 81 procedure TBaseParser.ErrorMessage(const Text: string; const Arguments: array of const; 82 TokenOffset: Integer );82 TokenOffset: Integer = -1); 83 83 begin 84 84 if Assigned(FOnErrorMessage) then -
branches/Transpascal/Compiler/Analyze/UPascalParser.pas
r76 r77 32 32 procedure ParseBeginEnd(SourceCode: TBeginEnd); 33 33 procedure ParseFunctionList(SourceCode: TFunctionList; Exported: Boolean = False); 34 procedure ParseFunctionParameters(SourceCode: TFunction); 34 35 procedure ParseIfThenElse(SourceCode: TIfThenElse); 35 36 procedure ParseForToDo(SourceCode: TForToDo); … … 58 59 SUndefinedConstant = 'Undefined constant "%s".'; 59 60 SUnitNotFound = 'Unit "%s" not found.'; 61 SFunctionNotDeclared = 'Function "%s" not declared.'; 62 SUnknownProcName = 'Unknown proc name "%s".'; 60 63 61 64 … … 507 510 { TParserParseFunctionList } 508 511 509 procedure TPascalParser.ParseFunctionList(SourceCode: TFunctionList; Exported: Boolean = False);510 var 511 Identifiers: TStringList; 512 procedure TPascalParser.ParseFunctionList(SourceCode: TFunctionList; 513 Exported: Boolean = False); 514 var 512 515 NewValueType: TType; 513 516 TypeName: string; 517 UseName: string; 518 I: Integer; 519 UseType: TType; 520 UseFunction: TFunction; 521 FunctionType: TFunctionType; 522 begin 523 with SourceCode do begin 524 if NextToken = 'procedure' then begin 525 Expect('procedure'); 526 FunctionType := ftProcedure; 527 end else 528 if NextToken = 'function' then begin 529 Expect('function'); 530 FunctionType := ftFunction; 531 end else 532 if NextToken = 'constructor' then begin 533 Expect('constructor'); 534 FunctionType := ftConstructor; 535 end else 536 if NextToken = 'destructor' then begin 537 Expect('destructor'); 538 FunctionType := ftDestructor; 539 end else ErrorMessage(SUnknownProcName, [NextToken]); 540 541 // Read function name 542 UseName := ReadCode; 543 UseType := SourceCode.Parent.Types.Search(UseName); 544 if Assigned(UseType) and ((UseType is TTypeRecord) or 545 (UseType is TTypeClass)) then begin 546 Expect('.'); 547 UseName := ReadCode; 548 if UseType is TTypeRecord then begin 549 UseFunction := TTypeRecord(UseType).CommonBlock.Functions.Search(UseName); 550 if not Assigned(UseFunction) then begin 551 ErrorMessage(SFunctionNotDeclared, [UseName]); 552 Exit; 553 end; 554 end; 555 end else begin 556 // Create new function 557 UseFunction := TFunction.Create; 558 UseFunction.Parent := SourceCode.Parent; 559 UseFunction.Name := UseName; 560 UseFunction.FunctionType := FunctionType; 561 Add(UseFunction); 562 end; 563 with UseFunction do begin 564 // Parse parameters 565 if NextToken = '(' then 566 ParseFunctionParameters(UseFunction); 567 568 // Parse function result type 569 if FunctionType = ftFunction then begin 570 Expect(':'); 571 TypeName := ReadCode; 572 NewValueType := Parent.Types.Search(TypeName); 573 if not Assigned(NewValueType) then 574 ErrorMessage(SUndefinedType, [TypeName], -1); 575 (* else 576 begin 577 ResultType := NewValueType; 578 with TVariable(Parent.Variables.Items[Parent.Variables.Add( 579 TVariable.Create)]) do 580 begin 581 Name := 'Result'; 582 ValueType := NewValueType; 583 end; 584 end; *) 585 end; 586 Expect(';'); 587 588 // Check directives 589 if NextToken = 'internal' then begin 590 Expect('internal'); 591 Expect(';'); 592 Internal := True; 593 end; 594 end; 595 596 if not Exported then ParseCommonBlock(UseFunction); 597 // if UseFunction then UseFunction.Code ; 598 end; 599 end; 600 601 procedure TPascalParser.ParseFunctionParameters(SourceCode: TFunction); 602 var 603 Identifiers: TStringList; 514 604 VariableName: string; 515 Variable: TParameter; 516 I: integer; 517 begin 605 UseVariable: TParameter; 606 TypeName: string; 607 UseType: TType; 608 I: Integer; 609 begin 610 with SourceCode do 518 611 try 519 Identifiers := TStringList.Create; 520 with SourceCode do begin 521 with TFunction(Items[Add(TFunction.Create)]) do begin 522 Parent := SourceCode.Parent; 523 if NextToken = 'procedure' then begin 524 Expect('procedure'); 525 HaveResult := False; 526 end else begin 527 Expect('function'); 528 HaveResult := True; 529 end; 530 Name := ReadCode; 531 532 if NextToken = '(' then begin 612 Identifiers := TStringList.Create; 533 613 Expect('('); 534 614 while NextToken <> ')' do begin … … 540 620 if VariableName = 'const' then begin 541 621 end else begin 542 Variable := Search(VariableName);543 if not Assigned( Variable) then begin622 UseVariable := Search(VariableName); 623 if not Assigned(UseVariable) then begin 544 624 Identifiers.Add(VariableName); 545 625 while NextToken = ',' do begin … … 551 631 Expect(':'); 552 632 TypeName := ReadCode; 553 NewValueType := Parent.Types.Search(TypeName);554 if not Assigned( NewValueType) then633 UseType := Parent.Types.Search(TypeName); 634 if not Assigned(UseType) then 555 635 ErrorMessage(SUndefinedType, [TypeName], -1) 556 636 else … … 559 639 begin 560 640 Name := Identifiers[I]; 561 ValueType := NewValueType;641 ValueType := UseType; 562 642 end; 563 643 end; … … 566 646 end; 567 647 Expect(')'); 568 569 // Parse function result type570 if HaveResult then begin571 Expect(':');572 TypeName := ReadCode;573 NewValueType := Parent.Types.Search(TypeName);574 if not Assigned(NewValueType) then575 ErrorMessage(SUndefinedType, [TypeName], -1);576 (* else577 begin578 ResultType := NewValueType;579 with TVariable(Parent.Variables.Items[Parent.Variables.Add(580 TVariable.Create)]) do581 begin582 Name := 'Result';583 ValueType := NewValueType;584 end;585 end; *)586 end;587 end;588 Expect(';');589 590 // Check directives591 if NextToken = 'internal' then begin592 Expect('internal');593 Expect(';');594 System := True;595 end;596 end;597 598 if not Exported then ParseCommonBlock(TFunction(Last));599 end;600 648 finally 601 649 Identifiers.Free; … … 924 972 if NextToken = 'var' then begin 925 973 Expect('var'); 926 SectionType := stVar 974 SectionType := stVar; 927 975 end else 928 976 if NextToken = 'const' then begin 929 977 Expect('const'); 930 SectionType := stConst 978 SectionType := stConst; 931 979 end else 932 980 if NextToken = 'type' then begin -
branches/Transpascal/Compiler/Produce/UProducerPascal.pas
r68 r77 144 144 for I := 0 to Types.Count - 1 do 145 145 with TType(Types[I]) do 146 if (not System) then begin146 if (not Internal) then begin 147 147 GenerateType(TType(Types[I]), '='); 148 148 Emit(';'); … … 178 178 for I := 0 to Functions.Count - 1 do 179 179 with TFunction(Functions[I]) do 180 if not Systemthen180 if not Internal then 181 181 begin 182 if HaveResultthen182 if FunctionType = ftFunction then 183 183 Line := 'function ' + Name 184 184 else Line := 'procedure ' + Name; … … 192 192 Line := Line + ')'; 193 193 end; 194 if HaveResultand Assigned(ResultType) then194 if (FunctionType = ftFunction) and Assigned(ResultType) then 195 195 Line := Line + ': ' + ResultType.Name; 196 196 Emit(Line + ';'); -
branches/Transpascal/Compiler/Produce/UProducerTreeView.pas
r68 r77 227 227 for I := 0 to Types.Count - 1 do 228 228 with TType(Types[I]) do 229 if not Systemthen AddNodeType(NewNode, TType(Types[I]));229 if (not Internal) then AddNodeType(NewNode, TType(Types[I])); 230 230 end; 231 231 end; … … 265 265 for I := 0 to Methods.Count - 1 do 266 266 with TFunction(Methods[I]) do 267 if not Systemthen begin268 if HaveResultthen267 if (not Internal) then begin 268 if FunctionType = ftFunction then 269 269 NewNode := TreeView.Items.AddChild(Node, 'function ' + Name) 270 270 else NewNode := TreeView.Items.AddChild(Node, 'procedure ' + Name); … … 301 301 for I := 0 to TypeRecord.CommonBlock.Types.Count - 1 do 302 302 with TType(TypeRecord.CommonBlock.Types[I]) do 303 if not Systemthen303 if not Internal then 304 304 AddNodeType(Node, TType(TypeRecord.CommonBlock.Types[I])); 305 305 end; -
branches/Transpascal/Compiler/TranspascalCompiler.lpk
r72 r77 15 15 </Other> 16 16 </CompilerOptions> 17 <Files Count="1 0">17 <Files Count="11"> 18 18 <Item1> 19 19 <Filename Value="UCompiler.pas"/> … … 37 37 </Item5> 38 38 <Item6> 39 <Filename Value="Produce\UProducer C.pas"/>40 <UnitName Value="UProducer C"/>39 <Filename Value="Produce\UProducerDynamicC.pas"/> 40 <UnitName Value="UProducerDynamicC"/> 41 41 </Item6> 42 42 <Item7> … … 56 56 <UnitName Value="UGrammer"/> 57 57 </Item10> 58 <Item11> 59 <Filename Value="Produce\UProducerGCCC.pas"/> 60 <UnitName Value="UProducerGCCC"/> 61 </Item11> 58 62 </Files> 59 63 <Type Value="RunAndDesignTime"/> -
branches/Transpascal/Compiler/TranspascalCompiler.pas
r72 r77 9 9 uses 10 10 UCompiler, USourceCode, UProducerTreeView, UProducer, UProducerAsm8051, 11 UProducer C, UProducerPascal, UParser, UPascalParser, UGrammer,12 LazarusPackageIntf;11 UProducerDynamicC, UProducerPascal, UParser, UPascalParser, UGrammer, 12 UProducerGCCC, LazarusPackageIntf; 13 13 14 14 implementation -
branches/Transpascal/Compiler/UCompiler.pas
r76 r77 8 8 SysUtils, Variants, Classes, 9 9 Dialogs, USourceCode, UProducer, UPascalParser, UParser, 10 UProducerC, Contnrs; 10 UProducerDynamicC, Contnrs, UProducerTreeView, UProducerASM8051, 11 UProducerPascal, UProducerGCCC; 11 12 12 13 type 14 TProducerType = (ptGCCC, ptDynamicC, ptPascal, ptAssembler, ptXML); 13 15 14 16 TErrorMessage = class … … 33 35 private 34 36 FOnErrorMessage: TErrorMessageEvent; 37 FProducerType: TProducerType; 35 38 procedure ErrorMessage(Text: string; Position: TPoint; FileName: string); 39 procedure SetProducerType(const AValue: TProducerType); 36 40 public 37 41 ProgramCode: TProgram; … … 49 53 property OnErrorMessage: TErrorMessageEvent read FOnErrorMessage 50 54 write FOnErrorMessage; 55 property ProducerType: TProducerType read FProducerType 56 write SetProducerType; 51 57 end; 58 59 const 60 ProducerTypeName: array[TProducerType] of string = ( 61 'GCC C', 'Rabbit Dynamic C', 'Generic Pascal', 'Assembler', 'XML'); 62 52 63 53 64 implementation … … 93 104 94 105 ProgramCode := TProgram.Create; 95 Producer := TProducer C.Create;106 Producer := TProducerGCCC.Create; 96 107 Parser := TPascalParser.Create; 97 108 Parser.OnErrorMessage := ErrorMessage; … … 127 138 end; 128 139 140 procedure TCompiler.SetProducerType(const AValue: TProducerType); 141 begin 142 if FProducerType = AValue then Exit; 143 FProducerType := AValue; 144 Producer.Free; 145 case AValue of 146 ptGCCC: Producer := TProducerGCCC.Create; 147 ptDynamicC: Producer := TProducerDynamicC.Create; 148 ptPascal: Producer := TProducerPascal.Create; 149 ptAssembler: Producer := TProducerGCCC.Create; 150 ptXML: Producer := TProducerTreeView.Create; 151 end; 152 end; 153 129 154 { TCompilerTargetList } 130 155 -
branches/Transpascal/Compiler/USourceCode.pas
r76 r77 153 153 154 154 TType = class 155 System: Boolean;155 Internal: Boolean; 156 156 Parent: TTypeList; 157 157 Name: string; … … 259 259 end; 260 260 261 TFunctionType = (ftFunction, ftProcedure, ftConstructor, ftDestructor); 262 261 263 TFunction = class(TCommonBlock) 262 264 public 263 System: Boolean;264 HaveResult: Boolean;265 Internal: Boolean; 266 FunctionType: TFunctionType; 265 267 Parameters: TParameterList; 266 268 ResultType: TType; … … 769 771 while (I < UsedModules.Count) and (not Assigned(Result)) do begin 770 772 with TUsedModule(UsedModules[I]) do 773 if Assigned(Module) then 771 774 with Module do 772 775 Result := SearchType(AName, False);
Note:
See TracChangeset
for help on using the changeset viewer.