Changeset 55 for branches/DelphiToC
- Timestamp:
- Aug 10, 2010, 1:48:38 PM (14 years ago)
- Location:
- branches/DelphiToC
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/Analyze/UParser.pas
r54 r55 51 51 procedure ParseExpression(SourceCode: TExpression); 52 52 procedure ParseUsedModuleList(SourceCode: TUsedModuleList); 53 procedure ParseModule(SourceCode: TModule); 54 procedure ParseUnit(SourceCode: TModule); 55 procedure ParseProgram(SourceCode: TModule); 53 function ParseModule: TModule; 54 procedure ParseUnit(SourceCode: TModuleUnit); 55 procedure ParseUnitInterface(SourceCode: TUnitInterface); 56 procedure ParseUnitImplementation(SourceCode: TUnitImplementation); 57 procedure ParseProgram(SourceCode: TModuleProgram); 56 58 procedure ParseCommonBlock(SourceCode: TCommonBlock; EndSymbol: char = ';'); 57 59 function ParseCommand(SourceCode: TCommonBlock): TCommand; … … 628 630 { TParserModule } 629 631 630 procedure TPascalParser.ParseModule(SourceCode: TModule); 631 begin 632 if FNextToken = 'program' then 633 ParseProgram(SourceCode) 634 else if FNextToken = 'unit' then 635 ParseUnit(SourceCode) 636 else 637 ParseProgram(SourceCode); 638 end; 639 640 procedure TPascalParser.ParseProgram(SourceCode: TModule); 632 function TPascalParser.ParseModule: TModule; 633 begin 634 if FNextToken = 'unit' then begin 635 Result := TModuleUnit.Create; 636 ParseUnit(TModuleUnit(Result)); 637 end else begin //if FNextToken = 'program' then begin 638 Result := TModuleProgram.Create; 639 ParseProgram(TModuleProgram(Result)); 640 end; 641 end; 642 643 procedure TPascalParser.ParseProgram(SourceCode: TModuleProgram); 641 644 var 642 645 Identifier: string; 643 646 begin 644 with SourceCode do 645 begin 646 if FNextToken = 'program' then 647 begin 647 with SourceCode do begin 648 if FNextToken = 'program' then begin 648 649 Expect('program'); 649 650 Name := ReadCode; 650 ModuleType := mdProgram;651 651 Expect(';'); 652 652 end else Name := ''; … … 656 656 ParseUsedModuleList(UsedModules); 657 657 658 ParseCommonBlock( SourceCode, '.');659 end; 660 end; 661 662 procedure TPascalParser.ParseUnit(SourceCode: TModule );658 ParseCommonBlock(Body, '.'); 659 end; 660 end; 661 662 procedure TPascalParser.ParseUnit(SourceCode: TModuleUnit); 663 663 var 664 664 NewModule: TModule; 665 665 begin 666 666 Expect('unit'); 667 with Sourcecode do 668 begin 667 with Sourcecode do begin 669 668 Name := ReadCode; 670 ModuleType := mdUnit;671 669 end; 672 670 Expect(';'); 673 //ParseInterface; 674 //ParseImplementation; 675 end; 676 677 { TParserProgram } 671 672 ParseUnitInterface(SourceCode.InterfaceSection); 673 if FNextToken = 'implementation' then 674 ParseUnitImplementation(SourceCode.ImplementationSection); 675 end; 676 677 procedure TPascalParser.ParseUnitInterface(SourceCode: TUnitInterface); 678 begin 679 Expect('interface'); 680 // Uses section 681 if FNextToken = 'uses' then 682 ParseUsedModuleList(SourceCode.UsedModules); 683 684 ParseCommonBlock(SourceCode.Body, '.'); 685 end; 686 687 procedure TPascalParser.ParseUnitImplementation(SourceCode: TUnitImplementation); 688 begin 689 Expect('implementation'); 690 691 // Uses section 692 if FNextToken = 'uses' then 693 ParseUsedModuleList(SourceCode.UsedModules); 694 695 ParseCommonBlock(SourceCode.Body, '.'); 696 end; 678 697 679 698 { TParserCommonBlock } -
branches/DelphiToC/Forms/UMainForm.lfm
r54 r55 3 3 Height = 494 4 4 Top = 103 5 Width = 8 845 Width = 861 6 6 Caption = 'Transpascal ' 7 7 ClientHeight = 494 8 ClientWidth = 8 848 ClientWidth = 861 9 9 Font.Height = -11 10 10 Font.Name = 'Tahoma' … … 16 16 LCLVersion = '0.9.29' 17 17 object ButtonCompile: TButton 18 Left = 7 3618 Left = 713 19 19 Height = 22 20 20 Top = 397 … … 28 28 TabOrder = 0 29 29 end 30 inline SynEdit 1: TSynEdit30 inline SynEditSource: TSynEdit 31 31 Left = 248 32 32 Height = 384 … … 611 611 end> 612 612 Lines.Strings = ( 613 'SynEdit 1'613 'SynEditSource' 614 614 ) 615 615 BracketHighlightStyle = sbhsBoth … … 723 723 end 724 724 object ComboBox1: TComboBox 725 Left = 7 35725 Left = 712 726 726 Height = 21 727 727 Top = 424 728 728 Width = 144 729 Anchors = [ak Left, akRight, akBottom]729 Anchors = [akRight, akBottom] 730 730 ItemHeight = 13 731 731 ItemIndex = 0 … … 741 741 Text = 'Pascal' 742 742 end 743 object ListBox 1: TListBox743 object ListBoxMessages: TListBox 744 744 Left = 8 745 745 Height = 91 746 746 Top = 398 747 Width = 720747 Width = 697 748 748 Anchors = [akLeft, akRight, akBottom] 749 749 ItemHeight = 0 750 OnClick = ListBox 1Click750 OnClick = ListBoxMessagesClick 751 751 TabOrder = 3 752 752 end … … 755 755 Height = 382 756 756 Top = 8 757 Width = 2 31757 Width = 208 758 758 Anchors = [akTop, akLeft, akRight, akBottom] 759 759 BevelOuter = bvNone -
branches/DelphiToC/Forms/UMainForm.pas
r54 r55 20 20 ButtonCompile: TButton; 21 21 ComboBox1: TComboBox; 22 ListBox 1: TListBox;22 ListBoxMessages: TListBox; 23 23 Panel1: TPanel; 24 SynEdit 1: TSynEdit;24 SynEditSource: TSynEdit; 25 25 SynPasSyn1: TSynPasSyn; 26 26 TreeViewProject: TTreeView; … … 31 31 procedure FormCreate(Sender: TObject); 32 32 procedure FormDestroy(Sender: TObject); 33 procedure ListBox 1Click(Sender: TObject);33 procedure ListBoxMessagesClick(Sender: TObject); 34 34 procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode); 35 35 private … … 79 79 80 80 // Compile all project files 81 Compiler.Init; 81 82 for I := 0 to Project.Items.Count - 1 do begin 82 if TProjectNode(Project.Items[I]) is TProjectFile then begin83 Compiler.Compile(TProjectFile(Project.Items[I]).Source,84 TProjectFile(Project.Items[I]).ProducedCode);83 if TProjectNode(Project.Items[I]) is TProjectFile then 84 with TProjectFile(Project.Items[I]) do begin 85 Compiler.Compile(Parent.GetDir + Name, Source, ProducedCode); 85 86 end; 86 87 end; … … 113 114 end; 114 115 115 procedure TMainForm.ListBox1Click(Sender: TObject); 116 begin 117 if ListBox1.ItemIndex <> - 1 then begin 118 SynEdit1.CaretXY := TErrorMessage(Compiler.ErrorMessages[ListBox1.ItemIndex]).Position; 119 SynEdit1.SetFocus; 116 procedure TMainForm.ListBoxMessagesClick(Sender: TObject); 117 var 118 ProjectFile: TProjectFile; 119 begin 120 if ListBoxMessages.ItemIndex <> -1 then 121 with TErrorMessage(Compiler.ErrorMessages[ListBoxMessages.ItemIndex]) do begin 122 ProjectFile := Project.SearchFile(fileName); 123 if Assigned(ProjectFile) then 124 SynEditSource.Lines.Assign(ProjectFile.Source); 125 SynEditSource.CaretXY := Position; 126 SynEditSource.SetFocus; 120 127 end; 121 128 end; … … 125 132 I: Integer; 126 133 begin 127 ListBox 1.Clear;134 ListBoxMessages.Clear; 128 135 for I := 0 to Compiler.ErrorMessages.Count - 1 do 129 136 with TErrorMessage(Compiler.ErrorMessages[I]) do 130 MainForm.ListBox 1.Items.Add('(' + IntToStr(Position.X) +137 MainForm.ListBoxMessages.Items.Add(FileName + '(' + IntToStr(Position.X) + 131 138 ',' + IntToStr(Position.Y) + ') ' + Text); 132 139 end; … … 136 143 if Assigned(Node) then begin 137 144 if TProjectNode(Node.Data) is TProjectFile then begin 138 SynEdit 1.Lines.Assign(TProjectFile(Node.Data).Source);145 SynEditSource.Lines.Assign(TProjectFile(Node.Data).Source); 139 146 if ProducerControl is TMemo then 140 147 TMemo(ProducerControl).Lines.Assign(TProjectFile(Node.Data).ProducedCode); … … 193 200 NewProjectFile: TProjectFile; 194 201 begin 202 Project.RootDir := '../../Project/'; 195 203 Project.Name := 'Project'; 204 196 205 NewProjectFile := TProjectFile.Create; 206 NewProjectFile.Parent := Project; 197 207 NewProjectFile.Name := 'Project.pas'; 198 NewProjectFile.FileName := ProjectDir + 'Project.pas';199 208 Project.Items.Add(NewProjectFile); 209 200 210 NewProjectFile := TProjectFile.Create; 211 NewProjectFile.Parent := Project; 201 212 NewProjectFile.Name := 'System.pas'; 202 NewProjectFile.FileName := ProjectDir + 'System.pas';203 213 Project.Items.Add(NewProjectFile); 214 215 NewProjectFile := TProjectFile.Create; 216 NewProjectFile.Parent := Project; 217 NewProjectFile.Name := 'Console.pas'; 218 Project.Items.Add(NewProjectFile); 219 204 220 Project.Load; 205 221 UpdateProjectTree; -
branches/DelphiToC/Produce/UProducerC.pas
r54 r55 115 115 Emit('#define uint32 unsigned long'); 116 116 Emit(''); 117 GenerateUses(Module.UsedModules); 118 GenerateCommonBlock(Module, ''); 117 if Module is TModuleProgram then begin 118 GenerateUses(TModuleProgram(Module).UsedModules); 119 GenerateCommonBlock(TModuleProgram(Module).Body, ''); 120 end; 119 121 end; 120 122 -
branches/DelphiToC/Produce/UProducerPascal.pas
r54 r55 84 84 procedure TProducerPascal.GenerateModule(Module: TModule); 85 85 begin 86 case Module.ModuleType of 87 mdProgram: Emit('program', False); 88 mdUnit: Emit('unit', False); 89 mdLibrary: Emit('library', False); 90 mdPackage: Emit('package', False); 91 end; 92 Emit(' ' + Module.Name + ';'); 93 Emit(''); 94 GenerateUses(Module.UsedModules); 95 GenerateCommonBlock(Module, ''); 96 Emit('.', False); 86 if Module is TModuleProgram then 87 with TModuleProgram(Module) do begin 88 Emit('program', False); 89 Emit(' ' + Name + ';'); 90 Emit(''); 91 GenerateUses(UsedModules); 92 GenerateCommonBlock(Body, ''); 93 Emit('.', False); 94 end else 95 if Module is TModuleUnit then Emit('unit', False) 96 else if Module is TModuleLibrary then Emit('library', False) 97 else if Module is TModulePackage then Emit('package', False); 97 98 end; 98 99 -
branches/DelphiToC/Produce/UProducerTreeView.pas
r54 r55 284 284 TypeName: string; 285 285 begin 286 case Module.ModuleType of 287 mdPackage: TypeName := 'package'; 288 mdProgram: TypeName := 'program'; 289 mdUnit: TypeName := 'unit'; 290 mdLibrary: TypeName := 'library'; 291 end; 292 NewNode := TreeView.Items.AddChild(Node, TypeName + ' ' + Module.Name); 293 AddNodeUses(NewNode, Module.UsedModules); 294 AddNodeMethodList(NewNode, Module.Functions); 295 AddNodeConstantList(NewNode, Module.Constants); 296 AddNodeVariableList(NewNode, Module.Variables); 297 AddNodeTypeList(NewNode, Module.Types); 298 AddNodeBeginEnd(NewNode, Module.Code); 286 if Module is TModulePackage then TypeName := 'package' 287 else if Module is TModuleProgram then 288 with TModuleProgram(Module) do begin 289 TypeName := 'program'; 290 NewNode := TreeView.Items.AddChild(Node, TypeName + ' ' + Module.Name); 291 AddNodeUses(NewNode, UsedModules); 292 AddNodeMethodList(NewNode, Body.Functions); 293 AddNodeConstantList(NewNode, Body.Constants); 294 AddNodeVariableList(NewNode, Body.Variables); 295 AddNodeTypeList(NewNode, Body.Types); 296 AddNodeBeginEnd(NewNode, Body.Code); 297 end else if Module is TModuleUnit then TypeName := 'unit' 298 else if Module is TModuleLibrary then TypeName := 'library'; 299 299 300 end; 300 301 -
branches/DelphiToC/Project/System.pas
r54 r55 1 1 unit System; 2 3 interface 2 4 3 5 type … … 15 17 String = array of Char; 16 18 19 17 20 procedure Exit; system; 18 begin 19 end;21 procedure Break; system; 22 procedure Continue; system; 20 23 21 procedure Break; system; 22 begin 23 end; 24 implementation 24 25 25 procedure Continue; system;26 begin27 end;28 26 29 27 end. -
branches/DelphiToC/Transpascal.lpi
r54 r55 41 41 </Item2> 42 42 </RequiredPackages> 43 <Units Count="2 1">43 <Units Count="22"> 44 44 <Unit0> 45 45 <Filename Value="Transpascal.lpr"/> … … 60 60 <ResourceBaseClass Value="Form"/> 61 61 <UnitName Value="UMainForm"/> 62 <IsVisibleTab Value="True"/> 62 63 <EditorIndex Value="6"/> 63 64 <WindowIndex Value="0"/> 64 <TopLine Value=" 91"/>65 <CursorPos X=" 40" Y="106"/>65 <TopLine Value="207"/> 66 <CursorPos X="10" Y="224"/> 66 67 <UsageCount Value="148"/> 67 68 <Loaded Value="True"/> … … 83 84 <EditorIndex Value="5"/> 84 85 <WindowIndex Value="0"/> 85 <TopLine Value=" 1"/>86 <CursorPos X=" 29" Y="14"/>86 <TopLine Value="761"/> 87 <CursorPos X="13" Y="784"/> 87 88 <UsageCount Value="148"/> 88 89 <Loaded Value="True"/> … … 92 93 <IsPartOfProject Value="True"/> 93 94 <UnitName Value="UCompiler"/> 94 <EditorIndex Value="1 3"/>95 <WindowIndex Value="0"/> 96 <TopLine Value=" 37"/>97 <CursorPos X=" 29" Y="50"/>95 <EditorIndex Value="14"/> 96 <WindowIndex Value="0"/> 97 <TopLine Value="1"/> 98 <CursorPos X="5" Y="17"/> 98 99 <UsageCount Value="148"/> 99 100 <Loaded Value="True"/> … … 125 126 <IsPartOfProject Value="True"/> 126 127 <UnitName Value="UProducerC"/> 127 <EditorIndex Value="1 2"/>128 <WindowIndex Value="0"/> 129 <TopLine Value="1 21"/>130 <CursorPos X=" 17" Y="125"/>128 <EditorIndex Value="13"/> 129 <WindowIndex Value="0"/> 130 <TopLine Value="104"/> 131 <CursorPos X="52" Y="119"/> 131 132 <UsageCount Value="148"/> 132 133 <Loaded Value="True"/> … … 138 139 <EditorIndex Value="0"/> 139 140 <WindowIndex Value="0"/> 140 <TopLine Value="6 19"/>141 <CursorPos X=" 1" Y="632"/>141 <TopLine Value="680"/> 142 <CursorPos X="25" Y="689"/> 142 143 <UsageCount Value="148"/> 143 144 <Loaded Value="True"/> … … 206 207 <EditorIndex Value="2"/> 207 208 <WindowIndex Value="0"/> 208 <TopLine Value="2 80"/>209 <CursorPos X=" 45" Y="294"/>209 <TopLine Value="277"/> 210 <CursorPos X="26" Y="291"/> 210 211 <UsageCount Value="110"/> 211 212 <Loaded Value="True"/> … … 230 231 <IsPartOfProject Value="True"/> 231 232 <UnitName Value="UProducerPascal"/> 232 <IsVisibleTab Value="True"/>233 233 <EditorIndex Value="8"/> 234 234 <WindowIndex Value="0"/> 235 <TopLine Value="7 4"/>236 <CursorPos X=" 14" Y="92"/>235 <TopLine Value="77"/> 236 <CursorPos X="34" Y="93"/> 237 237 <UsageCount Value="64"/> 238 238 <Loaded Value="True"/> … … 244 244 <EditorIndex Value="11"/> 245 245 <WindowIndex Value="0"/> 246 <TopLine Value=" 24"/>247 <CursorPos X="1 6" Y="37"/>246 <TopLine Value="78"/> 247 <CursorPos X="1" Y="99"/> 248 248 <UsageCount Value="20"/> 249 249 <Loaded Value="True"/> 250 250 </Unit20> 251 <Unit21> 252 <Filename Value="E:\Programy\Lazarus\fpc\2.4.0\source\rtl\inc\wstringh.inc"/> 253 <EditorIndex Value="12"/> 254 <WindowIndex Value="0"/> 255 <TopLine Value="17"/> 256 <CursorPos X="11" Y="30"/> 257 <UsageCount Value="10"/> 258 <Loaded Value="True"/> 259 </Unit21> 251 260 </Units> 252 261 <JumpHistory Count="30" HistoryIndex="29"> 253 262 <Position1> 254 <Filename Value=" Produce\UProducerPascal.pas"/>255 <Caret Line="1 49" Column="18" TopLine="144"/>263 <Filename Value="Forms\UMainForm.pas"/> 264 <Caret Line="131" Column="21" TopLine="118"/> 256 265 </Position1> 257 266 <Position2> 258 <Filename Value=" Produce\UProducerPascal.pas"/>259 <Caret Line=" 40" Column="23" TopLine="27"/>267 <Filename Value="Forms\UMainForm.pas"/> 268 <Caret Line="120" Column="40" TopLine="109"/> 260 269 </Position2> 261 270 <Position3> 262 <Filename Value=" Produce\UProducerC.pas"/>263 <Caret Line=" 40" Column="38" TopLine="27"/>271 <Filename Value="UProject.pas"/> 272 <Caret Line="30" Column="58" TopLine="14"/> 264 273 </Position3> 265 274 <Position4> 266 <Filename Value=" Produce\UProducerC.pas"/>267 <Caret Line=" 121" Column="29" TopLine="107"/>275 <Filename Value="UProject.pas"/> 276 <Caret Line="91" Column="49" TopLine="82"/> 268 277 </Position4> 269 278 <Position5> 270 <Filename Value=" Produce\UProducerC.pas"/>271 <Caret Line=" 40" Column="66" TopLine="39"/>279 <Filename Value="UProject.pas"/> 280 <Caret Line="92" Column="49" TopLine="82"/> 272 281 </Position5> 273 282 <Position6> 274 <Filename Value="U Compiler.pas"/>275 <Caret Line=" 50" Column="1" TopLine="29"/>283 <Filename Value="UProject.pas"/> 284 <Caret Line="44" Column="3" TopLine="19"/> 276 285 </Position6> 277 286 <Position7> 278 <Filename Value=" Produce\UProducerAsm8051.pas"/>279 <Caret Line=" 37" Column="38" TopLine="24"/>287 <Filename Value="Forms\UMainForm.pas"/> 288 <Caret Line="120" Column="40" TopLine="109"/> 280 289 </Position7> 281 290 <Position8> 282 <Filename Value=" Produce\UProducerAsm8051.pas"/>283 <Caret Line="1 91" Column="35" TopLine="171"/>291 <Filename Value="Forms\UMainForm.pas"/> 292 <Caret Line="122" Column="39" TopLine="106"/> 284 293 </Position8> 285 294 <Position9> 286 <Filename Value=" Produce\UProducerAsm8051.pas"/>287 <Caret Line=" 37" Column="66" TopLine="37"/>295 <Filename Value="Forms\UMainForm.pas"/> 296 <Caret Line="121" Column="22" TopLine="108"/> 288 297 </Position9> 289 298 <Position10> 290 <Filename Value=" Produce\UProducerAsm8051.pas"/>291 <Caret Line="1 93" Column="24" TopLine="171"/>299 <Filename Value="Forms\UMainForm.pas"/> 300 <Caret Line="124" Column="52" TopLine="110"/> 292 301 </Position10> 293 302 <Position11> 294 <Filename Value=" Produce\UProducerAsm8051.pas"/>295 <Caret Line=" 35" Column="45" TopLine="24"/>303 <Filename Value="Forms\UMainForm.pas"/> 304 <Caret Line="123" Column="1" TopLine="110"/> 296 305 </Position11> 297 306 <Position12> 298 <Filename Value=" Produce\UProducerAsm8051.pas"/>299 <Caret Line=" 37" Column="15" TopLine="22"/>307 <Filename Value="Forms\UMainForm.pas"/> 308 <Caret Line="125" Column="1" TopLine="110"/> 300 309 </Position12> 301 310 <Position13> 302 <Filename Value=" Produce\UProducerTreeView.pas"/>303 <Caret Line=" 325" Column="1" TopLine="311"/>311 <Filename Value="Forms\UMainForm.pas"/> 312 <Caret Line="122" Column="1" TopLine="110"/> 304 313 </Position13> 305 314 <Position14> 306 <Filename Value=" Produce\UProducerTreeView.pas"/>307 <Caret Line=" 36" Column="23" TopLine="23"/>315 <Filename Value="UProject.pas"/> 316 <Caret Line="86" Column="1" TopLine="74"/> 308 317 </Position14> 309 318 <Position15> 310 <Filename Value=" Produce\UProducerTreeView.pas"/>311 <Caret Line=" 329" Column="13" TopLine="311"/>319 <Filename Value="UProject.pas"/> 320 <Caret Line="87" Column="1" TopLine="74"/> 312 321 </Position15> 313 322 <Position16> 314 <Filename Value=" Analyze\UParser.pas"/>315 <Caret Line=" 635" Column="12" TopLine="630"/>323 <Filename Value="UProject.pas"/> 324 <Caret Line="86" Column="44" TopLine="74"/> 316 325 </Position16> 317 326 <Position17> 318 <Filename Value=" Analyze\UParser.pas"/>319 <Caret Line=" 632" Column="1" TopLine="627"/>327 <Filename Value="Forms\UMainForm.pas"/> 328 <Caret Line="122" Column="1" TopLine="110"/> 320 329 </Position17> 321 330 <Position18> 322 <Filename Value=" Analyze\UParser.pas"/>323 <Caret Line=" 634" Column="1" TopLine="627"/>331 <Filename Value="UProject.pas"/> 332 <Caret Line="86" Column="1" TopLine="74"/> 324 333 </Position18> 325 334 <Position19> 326 <Filename Value=" Analyze\UParser.pas"/>327 <Caret Line=" 635" Column="1" TopLine="627"/>335 <Filename Value="UProject.pas"/> 336 <Caret Line="87" Column="1" TopLine="74"/> 328 337 </Position19> 329 338 <Position20> 330 <Filename Value=" Analyze\UParser.pas"/>331 <Caret Line=" 665" Column="1" TopLine="652"/>339 <Filename Value="UProject.pas"/> 340 <Caret Line="89" Column="1" TopLine="74"/> 332 341 </Position20> 333 342 <Position21> 334 <Filename Value=" Analyze\UParser.pas"/>335 <Caret Line=" 666" Column="1" TopLine="652"/>343 <Filename Value="UProject.pas"/> 344 <Caret Line="90" Column="1" TopLine="74"/> 336 345 </Position21> 337 346 <Position22> 338 <Filename Value=" Analyze\UParser.pas"/>339 <Caret Line=" 669" Column="1" TopLine="652"/>347 <Filename Value="UProject.pas"/> 348 <Caret Line="91" Column="1" TopLine="74"/> 340 349 </Position22> 341 350 <Position23> 342 <Filename Value=" Analyze\UParser.pas"/>343 <Caret Line=" 670" Column="1" TopLine="652"/>351 <Filename Value="UProject.pas"/> 352 <Caret Line="92" Column="1" TopLine="74"/> 344 353 </Position23> 345 354 <Position24> 346 <Filename Value=" Produce\UProducerPascal.pas"/>347 <Caret Line=" 88" Column="25" TopLine="84"/>355 <Filename Value="UProject.pas"/> 356 <Caret Line="93" Column="1" TopLine="74"/> 348 357 </Position24> 349 358 <Position25> 350 <Filename Value=" Produce\UProducerPascal.pas"/>351 <Caret Line="86" Column=" 23" TopLine="74"/>359 <Filename Value="UProject.pas"/> 360 <Caret Line="86" Column="1" TopLine="74"/> 352 361 </Position25> 353 362 <Position26> 354 <Filename Value="U SourceCode.pas"/>355 <Caret Line=" 274" Column="25" TopLine="261"/>363 <Filename Value="UProject.pas"/> 364 <Caret Line="99" Column="1" TopLine="78"/> 356 365 </Position26> 357 366 <Position27> 358 <Filename Value=" Produce\UProducerPascal.pas"/>359 <Caret Line="86" Column=" 23" TopLine="74"/>367 <Filename Value="UProject.pas"/> 368 <Caret Line="86" Column="1" TopLine="78"/> 360 369 </Position27> 361 370 <Position28> 362 <Filename Value=" Produce\UProducerPascal.pas"/>363 <Caret Line=" 89" Column="10" TopLine="74"/>371 <Filename Value="UProject.pas"/> 372 <Caret Line="99" Column="1" TopLine="78"/> 364 373 </Position28> 365 374 <Position29> 366 <Filename Value=" Produce\UProducerPascal.pas"/>367 <Caret Line=" 92" Column="8" TopLine="74"/>375 <Filename Value="Forms\UMainForm.pas"/> 376 <Caret Line="123" Column="1" TopLine="110"/> 368 377 </Position29> 369 378 <Position30> 370 <Filename Value=" Produce\UProducerPascal.pas"/>371 <Caret Line=" 88" Column="23" TopLine="74"/>379 <Filename Value="Forms\UMainForm.pas"/> 380 <Caret Line="124" Column="1" TopLine="110"/> 372 381 </Position30> 373 382 </JumpHistory> -
branches/DelphiToC/UCompiler.pas
r54 r55 15 15 Text: string; 16 16 Position: TPoint; 17 FileName: string; 17 18 end; 18 19 … … 22 23 private 23 24 FOnErrorMessage: TOnErrorMessage; 25 FFileName: string; 24 26 procedure ErrorMessage(Text: string; Position: TPoint); 25 27 public … … 30 32 constructor Create; 31 33 procedure Init; 32 procedure Compile( Source: TStringList; ProducedCode: TStringList);34 procedure Compile(ModuleName: string; Source: TStringList; ProducedCode: TStringList); 33 35 destructor Destroy; override; 34 property OnErrorMessage: TOnErrorMessage read FOnErrorMessage write FOnErrorMessage; 36 property OnErrorMessage: TOnErrorMessage read FOnErrorMessage 37 write FOnErrorMessage; 35 38 end; 36 39 … … 39 42 { TCompiler } 40 43 41 procedure TCompiler.Compile( Source: TStringList; ProducedCode: TStringList);44 procedure TCompiler.Compile(ModuleName: string; Source: TStringList; ProducedCode: TStringList); 42 45 var 43 46 NewModule: TModule; 44 47 begin 48 FFileName := ModuleName; 45 49 Parser.SourceCodeText := Source; 46 50 Parser.Init; 47 NewModule := TModule.Create; 48 ProgramCode.Modules.Add(NewModule); 49 Parser.ParseModule(NewModule); 51 ProgramCode.Modules.Add(Parser.ParseModule); 50 52 Producer.Produce(NewModule, ProducedCode); 51 53 end; … … 81 83 NewMessage.Text := Text; 82 84 NewMessage.Position := Position; 85 NewMessage.FileName := FFileName; 83 86 ErrorMessages.Add(NewMessage); 84 87 if Assigned(FOnErrorMessage) then FOnErrorMessage(Text, Position); -
branches/DelphiToC/UProject.pas
r54 r55 6 6 7 7 uses 8 Classes, SysUtils, Contnrs ;8 Classes, SysUtils, Contnrs, Dialogs; 9 9 10 10 type … … 13 13 14 14 TProjectNode = class 15 Parent: TProjectNode; 15 16 Name: string; 16 17 procedure Load; virtual; 17 18 procedure Save; virtual; 19 function GetDir(IncludeRoot: Boolean = False): string; virtual; 20 end; 21 22 { TProjectFile } 23 24 TProjectFile = class(TProjectNode) 25 Source: TStringList; 26 ProducedCode: TStringList; 27 constructor Create; 28 destructor Destroy; override; 29 procedure Load; override; 30 procedure Save; override; 18 31 end; 19 32 … … 26 39 procedure Load; override; 27 40 procedure Save; override; 28 end; 29 30 { TProjectFile } 31 32 TProjectFile = class(TProjectNode) 33 Source: TStringList; 34 ProducedCode: TStringList; 35 FileName: string; 36 constructor Create; 37 destructor Destroy; override; 38 procedure Load; override; 39 procedure Save; override; 41 function SearchFile(FileName: string): TProjectFile; 40 42 end; 41 43 42 44 TProject = class(TProjectGroup) 45 RootDir: string; 46 function GetDir(IncludeRoot: Boolean = False): string; override; 43 47 end; 44 48 … … 76 80 end; 77 81 82 function TProjectGroup.SearchFile(FileName: string): TProjectFile; 83 var 84 NamePart: string; 85 I: Integer; 86 begin 87 if Pos('/', FileName) > 0 then 88 NamePart := Copy(FileName, 1, Pos('/', FileName)) 89 else NamePart := FileName; 90 I := 0; 91 while (I < Items.Count) and (TProjectNode(Items[I]).Name <> NamePart) do Inc(I); 92 if I < Items.Count then begin 93 if TProjectNode(Items[I]) is TProjectFile then Result := TProjectFile(Items[I]) 94 else begin 95 Delete(FileName, 1, Length(FileName) + 1); 96 TProjectGroup(Items[I]).SearchFile(FileName); 97 end; 98 end else Result := nil; 99 end; 100 78 101 { TProjectFile } 79 102 … … 94 117 begin 95 118 inherited Load; 96 Source.LoadFromFile( FileName);119 Source.LoadFromFile(Parent.GetDir(True) + Name); 97 120 end; 98 121 … … 100 123 begin 101 124 inherited Save; 102 Source.SaveToFile( FileName);125 Source.SaveToFile(Parent.GetDir(True) + Name); 103 126 end; 104 127 … … 115 138 end; 116 139 140 function TProjectNode.GetDir(IncludeRoot: Boolean = False): string; 141 begin 142 if Assigned(Parent) then Result := Parent.GetDir(IncludeRoot) + Name + '/' 143 else Result := Name + '/'; 144 end; 145 146 { TProject } 147 148 function TProject.GetDir(IncludeRoot: Boolean): string; 149 begin 150 if IncludeRoot then Result := RootDir else Result := ''; 151 end; 152 117 153 end. 118 154 -
branches/DelphiToC/USourceCode.pas
r54 r55 270 270 end; 271 271 272 TModule = class (TCommonBlock)272 TModule = class 273 273 public 274 ModuleType: TModuleType; 274 Name: string; 275 constructor Create; 276 destructor Destroy; override; 277 end; 278 279 { TModuleProgram } 280 281 TModuleProgram = class(TModule) 275 282 UsedModules: TUsedModuleList; 276 constructor Create; override; 277 procedure Clear; 278 destructor Destroy; override; 283 Body: TCommonBlock; 284 constructor Create; 285 destructor Destroy; override; 286 end; 287 288 { TUnitInterface } 289 290 TUnitInterface = class 291 UsedModules: TUsedModuleList; 292 Body: TCommonBlock; 293 constructor Create; 294 destructor Destroy; override; 295 end; 296 297 { TUnitImplementation } 298 299 TUnitImplementation = class 300 UsedModules: TUsedModuleList; 301 Body: TCommonBlock; 302 constructor Create; 303 destructor Destroy; override; 304 end; 305 306 { TModuleUnit } 307 308 TModuleUnit = class(TModule) 309 InterfaceSection: TUnitInterface; 310 ImplementationSection: TUnitImplementation; 311 constructor Create; 312 destructor Destroy; override; 313 end; 314 315 TModulePackage = class(TModule) 316 317 end; 318 319 TModuleLibrary = class(TModule) 279 320 end; 280 321 … … 362 403 { TModule } 363 404 364 procedure TModule.Clear;365 begin366 Variables.Clear;367 Constants.Clear;368 Functions.Clear;369 Code.Clear;370 end;371 372 405 constructor TModule.Create; 373 406 begin 374 407 inherited; 375 UsedModules := TUsedModuleList.Create;376 408 end; 377 409 378 410 destructor TModule.Destroy; 379 411 begin 380 UsedModules.Destroy;381 412 inherited; 382 413 end; … … 694 725 end; 695 726 727 { TModuleProgram } 728 729 constructor TModuleProgram.Create; 730 begin 731 inherited; 732 UsedModules := TUsedModuleList.Create; 733 Body := TCommonBlock.Create; 734 end; 735 736 destructor TModuleProgram.Destroy; 737 begin 738 UsedModules.Free; 739 Body.Free; 740 inherited Destroy; 741 end; 742 743 { TModuleUnit } 744 745 constructor TModuleUnit.Create; 746 begin 747 ImplementationSection := TUnitImplementation.Create; 748 InterfaceSection := TUnitInterface.Create; 749 end; 750 751 destructor TModuleUnit.Destroy; 752 begin 753 ImplementationSection.Free; 754 InterfaceSection.Free; 755 inherited Destroy; 756 end; 757 758 { TUnitImplementation } 759 760 constructor TUnitImplementation.Create; 761 begin 762 UsedModules := TUsedModuleList.Create; 763 Body := TCommonBlock.Create; 764 end; 765 766 destructor TUnitImplementation.Destroy; 767 begin 768 UsedModules.Free; 769 Body.Free; 770 inherited Destroy; 771 end; 772 773 { TUnitInterface } 774 775 constructor TUnitInterface.Create; 776 begin 777 UsedModules := TUsedModuleList.Create; 778 Body := TCommonBlock.Create; 779 end; 780 781 destructor TUnitInterface.Destroy; 782 begin 783 UsedModules.Free; 784 Body.Free; 785 inherited Destroy; 786 end; 787 696 788 end. 697 789
Note:
See TracChangeset
for help on using the changeset viewer.