- Timestamp:
- Aug 1, 2012, 12:16:08 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 13 added
- 6 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/Modules/Pascal/UAnalyzerPascal.pas
r70 r72 6 6 7 7 uses 8 Classes, SysUtils, UAnalyzer, USourceCode , Dialogs;8 Classes, SysUtils, UAnalyzer, USourceCodePascal, Dialogs, USourceConvertor; 9 9 10 10 type … … 12 12 { TAnalyzerPascal } 13 13 14 TAnalyzerPascal = class(T Analyzer)14 TAnalyzerPascal = class(TConvertor) 15 15 private 16 16 public 17 Parser: TAnalyzer; 17 18 function DebugExpressions(List: TListExpression): string; 18 19 function ParseFile(Name: string): Boolean; … … 29 30 function ParseUses(SourceCode: TUsedModuleList; AExported: Boolean): Boolean; 30 31 function ParseUsesItem(SourceCode: TUsedModuleList; AExported: Boolean): Boolean; 31 function ParseModule(ProgramCode: TProgram): TSourceModule; override;32 function ParseModule(ProgramCode: TProgram): TSourceModule; 32 33 function ParseUnit(var SourceCode: TModuleUnit; ProgramCode: TProgram): Boolean; 33 34 function ParseUnitInterface(SourceCode: TModuleUnit): Boolean; … … 63 64 constructor Create; 64 65 destructor Destroy; override; 66 procedure Convert(Input, Output: TSourceList); override; 65 67 end; 66 68 … … 108 110 NewModule: TSourceModule; 109 111 begin 110 try112 (* try 111 113 Parser := TAnalyzerPascal.Create; 112 114 Parser.OnDebugLog := OnDebugLog; … … 126 128 finally 127 129 Parser.Free; 128 end; 130 end; *) 129 131 end; 130 132 131 133 function TAnalyzerPascal.ParseWhileDo(var WhileDo: TWhileDo; SourceCode: TCommonBlock): Boolean; 132 134 begin 135 (* with Parser do 133 136 if NextToken = 'while' then begin 134 137 Expect('while'); … … 142 145 end; 143 146 Result := True; 144 end else Result := False; 147 end else Result := False;*) 145 148 end; 146 149 … … 153 156 II: Integer; 154 157 begin 158 (* with Parser do 155 159 try 156 160 Expressions := TListExpression.Create; … … 198 202 finally 199 203 Expressions.Free; 200 end; 204 end; *) 201 205 end; 202 206 … … 206 210 NewExpression: TExpression; 207 211 begin 208 if NextToken = '(' then begin212 (* if NextToken = '(' then begin 209 213 Expect('('); 210 214 // Subexpression … … 222 226 Expect(')'); 223 227 Result := True; 224 end else Result := False; 228 end else Result := False;*) 225 229 end; 226 230 … … 228 232 Expressions: TListExpression): Boolean; 229 233 begin 230 if IsOperator(NextToken) then begin234 (*if IsOperator(NextToken) then begin 231 235 // Operator 232 236 TExpression(Expressions.Last).OperatorName := ReadToken; 233 237 TExpression(Expressions.Last).NodeType := ntOperator; 234 238 Result := True; 235 end else Result := False; 239 end else Result := False; *) 236 240 end; 237 241 … … 249 253 begin 250 254 NewExpression := nil; 255 with Parser do 251 256 with SourceCode do begin 252 257 // if IsIdentificator(NextToken) then begin … … 367 372 begin 368 373 Func := nil; 369 with SourceCode do begin374 with Parser, SourceCode do begin 370 375 UseFunction := CommonBlock.Functions.Search(NextToken); 371 376 if Assigned(UseFunction) then begin … … 402 407 FunctionName: string; 403 408 begin 409 with PArser do 404 410 begin 405 411 if not ParseBeginEnd(TBeginEnd(Result), SourceCode) then … … 422 428 function TAnalyzerPascal.ParseModule(ProgramCode: TProgram): TSourceModule; 423 429 begin 424 Self.ProgramCode := ProgramCode;430 (* Output := TSource(ProgramCode); 425 431 if not ParseUnit(TModuleUnit(Result), ProgramCode) then 426 432 if not ParseProgram(TModuleProgram(Result), ProgramCode) then 427 ErrorMessage(SUnknownModuleType, [NextToken]); 433 ErrorMessage(SUnknownModuleType, [NextToken]);*) 428 434 end; 429 435 … … 432 438 Identifier: string; 433 439 begin 434 with SourceCode do begin440 with Parser, SourceCode do begin 435 441 SourceCode := TModuleProgram.Create; 436 442 SourceCode.ParentProgram := ProgramCode; … … 457 463 NewCommand: TCommand; 458 464 begin 465 with Parser do 459 466 if NextToken = 'unit' then begin 460 467 SourceCode := TModuleUnit.Create; … … 507 514 function TAnalyzerPascal.ParseUnitInterface(SourceCode: TModuleUnit): Boolean; 508 515 begin 516 with Parser do 509 517 if NextToken = 'interface' then begin 510 518 Expect('interface'); … … 519 527 function TAnalyzerPascal.ParseUnitImplementation(SourceCode: TModuleUnit): Boolean; 520 528 begin 529 with Parser do 521 530 if NextToken = 'implementation' then begin 522 531 Expect('implementation'); … … 539 548 NewType: TType; 540 549 begin 541 with SourceCode do begin550 with Parser, SourceCode do begin 542 551 while (NextToken <> EndSymbol) and (NextTokenType <> ttEndOfFile) do begin 543 552 if NextToken = 'var' then begin … … 591 600 begin 592 601 Log('ParseCommonBlockInterface'); 593 with SourceCode do begin602 with Parser, SourceCode do begin 594 603 while (NextToken <> 'implementation') and (NextTokenType <> ttEndOfFile) do begin 595 604 if NextToken = 'var' then begin … … 632 641 NewCommand: TCommand; 633 642 begin 643 with Parser do 634 644 if NextToken = 'begin' then begin 635 645 //ShowMessage(IntToStr(Integer(SourceCode)) + ' ' + IntToStr(Integer(SourceCode.CommonBlock))); … … 668 678 ValidParams: Boolean; 669 679 begin 680 with Parser do 670 681 if (NextToken = 'procedure') or (NextToken = 'function') then begin 671 682 with SourceCode do begin … … 779 790 I: Integer; 780 791 begin 781 with SourceCode do792 with Parser, SourceCode do 782 793 try 783 794 Identifiers := TStringList.Create; … … 837 848 function TAnalyzerPascal.ParseIfThenElse(var IfThenElse: TIfThenElse; SourceCode: TCommonBlock): Boolean; 838 849 begin 850 with Parser do 839 851 if NextToken = 'if' then begin 840 852 IfThenElse := TIfThenElse.Create; … … 860 872 VariableName: string; 861 873 begin 874 with Parser do 862 875 if NextToken = 'for' then begin 863 876 ForToDo := TForToDo.Create; … … 888 901 IdentName: string; 889 902 begin 903 with Parser do 890 904 if IsIdentificator(NextToken) then begin 891 905 Variable := SourceCode.Variables.Search(NextToken); … … 910 924 FunctionName: string; 911 925 begin 926 with Parser do 912 927 if IsIdentificator(NextToken) then begin 913 928 if Assigned(SourceCode.Functions.Search(NextToken)) then begin … … 939 954 I: integer; 940 955 begin 956 with Parser do 941 957 if NextToken = 'var' then begin 942 958 Expect('var'); … … 962 978 NewVariable: TVariable; 963 979 begin 980 with Parser do 964 981 try 965 982 Identifiers := TStringList.Create; … … 1001 1018 function TAnalyzerPascal.ParseConstantList(SourceCode: TConstantList; Exported: Boolean = False): Boolean; 1002 1019 begin 1020 with Parser do 1003 1021 if NextToken = 'const' then begin 1004 1022 Expect('const'); … … 1023 1041 ConstantValue: string; 1024 1042 begin 1025 with SourceCode do1043 with Parser, SourceCode do 1026 1044 try 1027 1045 Identifiers := TStringList.Create; … … 1070 1088 NewType.Parent := TypeList; 1071 1089 //with SourceCode do 1090 with Parser do 1072 1091 begin 1073 1092 if ExpectName then begin … … 1097 1116 NewType2: TType; 1098 1117 begin 1118 with Parser do 1099 1119 if NextToken = '<' then begin 1100 1120 Expect('<'); … … 1119 1139 Result := False; 1120 1140 // Use existed type 1141 with Parser do 1121 1142 if NextTokenType = ttIdentifier then begin 1122 1143 TypeName := ReadToken; … … 1146 1167 begin 1147 1168 // Buildin base type construction 1169 with Parser do 1148 1170 if NextToken = 'type' then begin 1149 1171 Expect('type'); … … 1165 1187 TempType: TType; 1166 1188 begin 1189 with Parser do 1167 1190 if NextToken = '^' then begin 1168 1191 Expect('^'); … … 1180 1203 TempType: TType; 1181 1204 begin 1205 with Parser do 1182 1206 if NextToken = '(' then begin 1183 1207 Expect('('); … … 1218 1242 TempType: TType; 1219 1243 begin 1244 with Parser do 1220 1245 if NextToken = 'record' then begin 1221 1246 Expect('record'); … … 1292 1317 TempType: TType; 1293 1318 begin 1319 with Parser do 1294 1320 if NextToken = 'class' then begin 1295 1321 Expect('class'); … … 1364 1390 TempType: TType; 1365 1391 begin 1392 with Parser do 1366 1393 if NextToken = 'array' then begin 1367 1394 Expect('array'); … … 1399 1426 TempType: TType; 1400 1427 begin 1428 with Parser do 1401 1429 if NextTokenType = ttConstantString then begin 1402 1430 TempType := NewType; … … 1424 1452 begin 1425 1453 inherited; 1454 Parser := TAnalyzer.Create; 1426 1455 Name := 'Delphi'; 1456 InputType := TSourceFileLink; 1457 OutputType := TProgram; 1427 1458 end; 1428 1459 1429 1460 destructor TAnalyzerPascal.Destroy; 1430 1461 begin 1462 Parser.Free; 1431 1463 inherited Destroy; 1432 1464 end; 1433 1465 1466 procedure TAnalyzerPascal.Convert(Input, Output: TSourceList); 1467 begin 1468 1469 end; 1470 1434 1471 { TParserUsedModuleList } 1435 1472 … … 1438 1475 NewUsedModule: TUsedModule; 1439 1476 begin 1477 with Parser do 1440 1478 if NextToken = 'uses' then begin 1441 1479 Expect('uses'); … … 1453 1491 AExported: Boolean): Boolean; 1454 1492 begin 1493 with Parser do 1455 1494 with TUsedModule(SourceCode.Items[SourceCode.Add(TUsedModule.Create)]) do begin 1456 1495 Name := ReadToken; -
trunk/Compiler/Modules/Pascal/UModulePascal.pas
r71 r72 44 44 begin 45 45 with TCompilerAPI(API) do begin 46 Analyzer := TAnalyzerPascal.Create; 47 Analyzers.Add(Analyzer); 46 RegisterConvertor(TAnalyzerPascal); 48 47 end; 49 48 inherited Install; … … 54 53 inherited Uninstall; 55 54 with TCompilerAPI(API) do begin 56 Analyzers.Remove(Analyzer);55 UnregisterConvertor(TAnalyzerPascal); 57 56 end; 58 57 end; -
trunk/Compiler/Target/Dynamic C/UProducerDynamicc.pas
r68 r72 7 7 uses 8 8 SysUtils, Variants, Classes, Graphics, Controls, Forms, 9 Dialogs, StdCtrls, USourceCode , UProducer, StrUtils;9 Dialogs, StdCtrls, USourceCodePascal, UProducer, StrUtils; 10 10 11 11 type -
trunk/Compiler/Target/XML/UTargetXML.pas
r68 r72 6 6 7 7 uses 8 Classes, SysUtils, UTarget, UProducer, USourceCode ;8 Classes, SysUtils, UTarget, UProducer, USourceCodePascal; 9 9 10 10 type -
trunk/Compiler/TranspascalCompiler.lpk
r71 r72 9 9 <PathDelim Value="\"/> 10 10 <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"/> 12 12 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 13 13 </SearchPaths> … … 25 25 </CompilerOptions> 26 26 <Version Minor="1"/> 27 <Files Count="2 2">27 <Files Count="24"> 28 28 <Item1> 29 29 <Filename Value="UCompiler.pas"/> … … 31 31 </Item1> 32 32 <Item2> 33 <Filename Value=" USourceCode.pas"/>34 <UnitName Value="USourceCode "/>33 <Filename Value="Modules\Pascal\USourceCodePascal.pas"/> 34 <UnitName Value="USourceCodePascal"/> 35 35 </Item2> 36 36 <Item3> … … 59 59 </Item8> 60 60 <Item9> 61 <Filename Value=" Target\ASM8051\UProducerASM8051.pas"/>61 <Filename Value="Modules\ASM8051\UProducerASM8051.pas"/> 62 62 <UnitName Value="UProducerAsm8051"/> 63 63 </Item9> 64 64 <Item10> 65 <Filename Value=" Target\ASM8051\UTargetASM8051.pas"/>65 <Filename Value="Modules\ASM8051\UTargetASM8051.pas"/> 66 66 <UnitName Value="UTargetASM8051"/> 67 67 </Item10> … … 75 75 </Item12> 76 76 <Item13> 77 <Filename Value=" Target\Delphi\UProducerPascal.pas"/>78 <UnitName Value="UProducer Pascal"/>77 <Filename Value="Modules\Delphi\UProducerDelphi.pas"/> 78 <UnitName Value="UProducerDelphi"/> 79 79 </Item13> 80 80 <Item14> 81 <Filename Value=" Target\Delphi\UTargetDelphi.pas"/>82 <UnitName Value="U TargetDelphi"/>81 <Filename Value="Modules\Delphi\UModuleDelphi.pas"/> 82 <UnitName Value="UModuleDelphi"/> 83 83 </Item14> 84 84 <Item15> … … 95 95 </Item17> 96 96 <Item18> 97 <Filename Value=" Target\Interpretter\UTargetInterpretter.pas"/>98 <UnitName Value="U TargetInterpretter"/>97 <Filename Value="Modules\Interpretter\UModuleInterpretter.pas"/> 98 <UnitName Value="UModuleInterpretter"/> 99 99 </Item18> 100 100 <Item19> … … 114 114 <UnitName Value="UModuleGCC"/> 115 115 </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> 116 124 </Files> 117 125 <Type Value="RunAndDesignTime"/> -
trunk/Compiler/TranspascalCompiler.pas
r71 r72 8 8 9 9 uses 10 UCompiler, USourceCode , UProducer, UAnalyzer, UTarget, UExecutor,10 UCompiler, USourceCodePascal, UProducer, UAnalyzer, UTarget, UExecutor, 11 11 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; 15 16 16 17 implementation -
trunk/Compiler/UAnalyzer.pas
r70 r72 8 8 uses 9 9 SysUtils, Variants, Classes, Contnrs, 10 Dialogs, USourceCode , FileUtil, SpecializedList;10 Dialogs, USourceCodePascal, FileUtil, SpecializedList; 11 11 12 12 type … … 53 53 CodeStreamPosition: Integer; 54 54 CodePosition: TPoint; 55 SourceCode : string;55 SourceCode2: string; 56 56 Tokens: TObjectList; // TObjectList<TToken> 57 57 TokenIndex: Integer; … … 242 242 Tokens.Clear; 243 243 TokenIndex := 0; 244 while CodeStreamPosition < Length(SourceCode ) do begin244 while CodeStreamPosition < Length(SourceCode2) do begin 245 245 NewToken := TToken.Create; 246 246 GetNextToken; … … 274 274 275 275 while True do begin 276 if CodeStreamPosition < Length(SourceCode ) then begin277 CurrentChar := SourceCode [CodeStreamPosition];276 if CodeStreamPosition < Length(SourceCode2) then begin 277 CurrentChar := SourceCode2[CodeStreamPosition]; 278 278 end else begin 279 279 FNextToken := ''; -
trunk/Compiler/UCompiler.pas
r71 r72 7 7 uses 8 8 SysUtils, Variants, Classes, Contnrs, FileUtil, UModularSystem, UCompilerAPI, 9 Dialogs, USourceCode , UProducer, UAnalyzer, SpecializedList, UTarget;9 Dialogs, USourceCodePascal, UProducer, UAnalyzer, SpecializedList, UTarget; 10 10 11 11 type … … 47 47 CompiledFolder: string; 48 48 49 Targets: TListTarget; 50 Analyzers: TListAnalyzer; 51 Convertors: TListObject; 52 Executors: TListObject; 49 53 API: TCompilerAPI; 50 54 TargetFolder: string; … … 163 167 constructor TCompiler.Create; 164 168 begin 169 Targets := TListTarget.Create; 170 Analyzers := TListAnalyzer.Create; 171 Convertors := TListObject.Create; 172 Executors := TListObject.Create; 165 173 API := TCompilerAPI.Create; 166 174 AbstractCode := TProgram.Create; … … 182 190 FreeAndNil(AbstractCode); 183 191 FreeAndNil(ErrorMessages); 192 FreeAndNil(Targets); 193 FreeAndNil(Analyzers); 194 FreeAndNil(Executors); 195 FreeAndNil(Convertors); 184 196 end; 185 197 … … 210 222 if MainSource <> '' then begin 211 223 Analyzer.FileName := MainSource; 212 Analyzer.OnGetSource(ExtractFileName(Analyzer.FileName), Analyzer.SourceCode );224 Analyzer.OnGetSource(ExtractFileName(Analyzer.FileName), Analyzer.SourceCode2); 213 225 Analyzer.Process; 214 226 //ShowMessage(IntToHex(Integer(Addr(Analyzer.OnGetSource)), 8)); -
trunk/Compiler/UCompilerAPI.pas
r71 r72 6 6 7 7 uses 8 Classes, SysUtils, UModularSystem, UAnalyzer, UTarget; 8 Classes, SysUtils, UModularSystem, UAnalyzer, UTarget, USourceConvertor, 9 SpecializedList, UExecutor; 9 10 10 11 type … … 13 14 14 15 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); 17 21 constructor Create; 18 22 destructor Destroy; override; … … 21 25 implementation 22 26 27 uses 28 UCompiler; 29 30 23 31 { TCompilerAPI } 32 33 procedure TCompilerAPI.RegisterConvertor(AClass: TConvertorClass); 34 begin 35 TCompiler(Compiler).Convertors.Add(TObject(AClass)); 36 end; 37 38 procedure TCompilerAPI.UnregisterConvertor(AClass: TConvertorClass); 39 begin 40 TCompiler(Compiler).Convertors.Remove(TObject(AClass)); 41 end; 42 43 procedure TCompilerAPI.RegisterExecutor(AClass: TExecutorClass); 44 begin 45 TCompiler(Compiler).Executors.Add(TObject(AClass)); 46 end; 47 48 procedure TCompilerAPI.UnregisterExecutor(AClass: TExecutorClass); 49 begin 50 TCompiler(Compiler).Executors.Remove(TObject(AClass)); 51 end; 24 52 25 53 constructor TCompilerAPI.Create; 26 54 begin 27 Targets := TListTarget.Create;28 Analyzers := TListAnalyzer.Create;29 55 end; 30 56 31 57 destructor TCompilerAPI.Destroy; 32 58 begin 33 Targets.Free;34 Analyzers.Free;35 59 inherited Destroy; 36 60 end; -
trunk/Compiler/UExecutor.pas
r60 r72 31 31 end; 32 32 33 TExecutorClass = class of TExecutor; 34 33 35 implementation 34 36 -
trunk/Compiler/UProducer.pas
r68 r72 6 6 7 7 uses 8 USourceCode , Classes, SysUtils, StrUtils, SpecializedList, Process,8 USourceCodePascal, Classes, SysUtils, StrUtils, SpecializedList, Process, 9 9 FileUtil, Forms; 10 10 -
trunk/IDE/Forms/UFormMain.pas
r71 r72 330 330 331 331 UpdateMenu; 332 Core.Compiler. API.Targets.LoadToStrings(ComboBoxTarget.Items);333 ComboBoxTarget.ItemIndex := Core.Compiler. API.Targets.IndexOf(Core.Compiler.Target);332 Core.Compiler.Targets.LoadToStrings(ComboBoxTarget.Items); 333 ComboBoxTarget.ItemIndex := Core.Compiler.Targets.IndexOf(Core.Compiler.Target); 334 334 FormSourceCode.UpdateInterface; 335 335 FormTargetCode.UpdateInterface; … … 435 435 begin 436 436 with TMenuItem(Sender) do begin 437 Core.Compiler.Target := TTarget(Core.Compiler. API.Targets[MenuIndex]);437 Core.Compiler.Target := TTarget(Core.Compiler.Targets[MenuIndex]); 438 438 UpdateInterface; 439 439 end; -
trunk/IDE/Forms/UFormTargets.pas
r71 r72 62 62 procedure TFormTargets.ListView1Data(Sender: TObject; Item: TListItem); 63 63 begin 64 if (Item.Index >= 0) and (Item.Index < Core.Compiler. API.Targets.Count) then65 with TTarget(Core.Compiler. API.Targets[Item.Index]) do begin64 if (Item.Index >= 0) and (Item.Index < Core.Compiler.Targets.Count) then 65 with TTarget(Core.Compiler.Targets[Item.Index]) do begin 66 66 Item.Caption := Name; 67 Item.Data := Core.Compiler. API.Targets[Item.Index];67 Item.Data := Core.Compiler.Targets[Item.Index]; 68 68 //Item.SubItems.Add(Producer.CompilerPath); 69 69 end; … … 72 72 procedure TFormTargets.ReloadList; 73 73 begin 74 ListView1.Items.Count := Core.Compiler. API.Targets.Count;74 ListView1.Items.Count := Core.Compiler.Targets.Count; 75 75 ListView1.Refresh; 76 76 end; -
trunk/IDE/UCore.pas
r71 r72 8 8 Classes, SysUtils, FileUtil, ULastOpenedList, UProject, UApplicationInfo, 9 9 UCompiler, URegistry, Registry, UDebugLog, UCoolTranslator, UTarget, 10 USourceCode , UModularSystem;10 USourceCodePascal, UModularSystem; 11 11 12 12 type
Note:
See TracChangeset
for help on using the changeset viewer.