Changeset 54
- Timestamp:
- Aug 10, 2010, 11:54:18 AM (14 years ago)
- Location:
- branches/DelphiToC
- Files:
-
- 4 added
- 2 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/Analyze/UParser.pas
r53 r54 54 54 procedure ParseUnit(SourceCode: TModule); 55 55 procedure ParseProgram(SourceCode: TModule); 56 procedure ParseAll(SourceCode: TProgram);57 56 procedure ParseCommonBlock(SourceCode: TCommonBlock; EndSymbol: char = ';'); 58 57 function ParseCommand(SourceCode: TCommonBlock): TCommand; … … 651 650 ModuleType := mdProgram; 652 651 Expect(';'); 653 end 654 else 655 Name := ''; 652 end else Name := ''; 656 653 657 654 // Uses section … … 664 661 665 662 procedure TPascalParser.ParseUnit(SourceCode: TModule); 663 var 664 NewModule: TModule; 666 665 begin 667 666 Expect('unit'); 668 with TModule(ProgramCode.Modules[0])do667 with Sourcecode do 669 668 begin 670 669 Name := ReadCode; … … 677 676 678 677 { TParserProgram } 679 680 procedure TPascalParser.ParseAll(SourceCode: TProgram);681 var682 I: integer;683 begin684 with SourceCode do685 begin686 for I := 0 to Modules.Count - 1 do687 ParseModule(TModule(Modules[I]));688 end;689 end;690 678 691 679 { TParserCommonBlock } -
branches/DelphiToC/Forms/UMainForm.lfm
r53 r54 1 1 object MainForm: TMainForm 2 Left = 14 13 Height = 49 84 Top = 10 55 Width = 88 12 Left = 148 3 Height = 494 4 Top = 103 5 Width = 884 6 6 Caption = 'Transpascal ' 7 ClientHeight = 49 88 ClientWidth = 88 17 ClientHeight = 494 8 ClientWidth = 884 9 9 Font.Height = -11 10 10 Font.Name = 'Tahoma' … … 16 16 LCLVersion = '0.9.29' 17 17 object ButtonCompile: TButton 18 Left = 80118 Left = 736 19 19 Height = 22 20 Top = 40121 Width = 7520 Top = 397 21 Width = 144 22 22 Anchors = [akRight, akBottom] 23 23 Caption = 'Kompilovat' … … 29 29 end 30 30 inline SynEdit1: TSynEdit 31 Left = 832 Height = 38 833 Top = 834 Width = 48831 Left = 248 32 Height = 384 33 Top = 6 34 Width = 392 35 35 Anchors = [akTop, akLeft, akBottom] 36 36 Font.Height = -13 … … 723 723 end 724 724 object ComboBox1: TComboBox 725 Left = 504725 Left = 735 726 726 Height = 21 727 Top = 8728 Width = 373729 Anchors = [ak Top, akLeft, akRight]727 Top = 424 728 Width = 144 729 Anchors = [akLeft, akRight, akBottom] 730 730 ItemHeight = 13 731 731 ItemIndex = 0 … … 744 744 Left = 8 745 745 Height = 91 746 Top = 402747 Width = 7 85746 Top = 398 747 Width = 720 748 748 Anchors = [akLeft, akRight, akBottom] 749 749 ItemHeight = 0 … … 752 752 end 753 753 object Panel1: TPanel 754 Left = 504755 Height = 3 54756 Top = 40757 Width = 372754 Left = 648 755 Height = 382 756 Top = 8 757 Width = 231 758 758 Anchors = [akTop, akLeft, akRight, akBottom] 759 759 BevelOuter = bvNone 760 760 TabOrder = 4 761 761 end 762 object TreeViewProject: TTreeView 763 Left = 7 764 Height = 383 765 Top = 8 766 Width = 233 767 Anchors = [akTop, akLeft, akBottom] 768 DefaultItemHeight = 15 769 ReadOnly = True 770 TabOrder = 5 771 OnChange = TreeViewProjectChange 772 Options = [tvoAutoItemHeight, tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw] 773 end 762 774 object SynPasSyn1: TSynPasSyn 763 775 CompilerMode = pcmDelphi 764 776 NestedComments = False 765 left = 183766 top = 48777 left = 328 778 top = 32 767 779 end 768 780 end -
branches/DelphiToC/Forms/UMainForm.pas
r53 r54 9 9 Dialogs, StdCtrls, USourceCode, UCompiler, UProducerAsm8051, 10 10 UProducerC, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, UProducerTreeView, 11 UProducerPascal, Contnrs ;11 UProducerPascal, Contnrs, UProject; 12 12 13 13 const 14 ExampleFileName = '../../Example.pas';14 ProjectDir = '../../Project/'; 15 15 16 16 type … … 24 24 SynEdit1: TSynEdit; 25 25 SynPasSyn1: TSynPasSyn; 26 TreeViewProject: TTreeView; 26 27 procedure ComboBox1Change(Sender: TObject); 27 28 procedure FormShow(Sender: TObject); … … 31 32 procedure FormDestroy(Sender: TObject); 32 33 procedure ListBox1Click(Sender: TObject); 34 procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode); 35 private 33 36 procedure LoadErrorMessages; 34 private 37 procedure UpdateProjectTree; 38 procedure UpdateProjectGroup(Node: TTreeNode; Group: TProjectGroup); 35 39 public 40 Project: TProject; 36 41 ProducerControl: TControl; 37 42 Compiler: TCompiler; 38 SourceTree: TProducerTreeView;39 43 end; 40 44 … … 52 56 I: Integer; 53 57 begin 54 MainForm.ListBox1.Clear;55 Compiler.SourceCode.Assign(SynEdit1.Lines);56 57 58 ProducerControl.Free; 58 59 if ComboBox1.ItemIndex = 0 then begin 59 60 Compiler.Producer.Free; 60 61 Compiler.Producer := TProducerPascal.Create; 61 Compiler.Producer.ProgramCode := Compiler.ProgramCode; 62 Compiler.Compile; 62 end else 63 if ComboBox1.ItemIndex = 1 then begin 64 Compiler.Producer.Free; 65 Compiler.Producer := TProducerC.Create; 66 end else 67 if ComboBox1.ItemIndex = 2 then begin 68 Compiler.Producer.Free; 69 Compiler.Producer := TProducerAsm8051.Create; 70 end else 71 if ComboBox1.ItemIndex = 3 then begin 72 Compiler.Producer.Free; 73 Compiler.Producer := TProducerTreeView.Create; 74 ProducerControl := TTreeView.Create(Self); 75 ProducerControl.Parent := Panel1; 76 ProducerControl.Align := alClient; 77 TProducerTreeView(Compiler.Producer).TreeView := TTreeView(ProducerControl); 78 end; 79 80 // Compile all project files 81 for I := 0 to Project.Items.Count - 1 do begin 82 if TProjectNode(Project.Items[I]) is TProjectFile then begin 83 Compiler.Compile(TProjectFile(Project.Items[I]).Source, 84 TProjectFile(Project.Items[I]).ProducedCode); 85 end; 86 end; 87 88 if ComboBox1.ItemIndex = 0 then begin 63 89 ProducerControl := TMemo.Create(Self); 64 90 ProducerControl.Parent := Panel1; … … 66 92 ProducerControl.Font.Name := 'Courier New'; 67 93 TMemo(ProducerControl).ScrollBars := ssAutoBoth; 68 with TProducerPascal(Compiler.Producer) do69 TMemo(ProducerControl).Lines.Assign(TextSource);70 94 end else 71 95 if ComboBox1.ItemIndex = 1 then begin 72 Compiler.Producer.Free;73 Compiler.Producer := TProducerC.Create;74 Compiler.Producer.ProgramCode := Compiler.ProgramCode;75 Compiler.Compile;76 96 ProducerControl := TMemo.Create(Self); 77 97 ProducerControl.Parent := Panel1; … … 79 99 ProducerControl.Font.Name := 'Courier New'; 80 100 TMemo(ProducerControl).ScrollBars := ssAutoBoth; 81 with TProducerC(Compiler.Producer) do82 TMemo(ProducerControl).Lines.Assign(TextSource);83 101 end else 84 102 if ComboBox1.ItemIndex = 2 then begin 85 Compiler.Producer.Free;86 Compiler.Producer := TProducerAsm8051.Create;87 Compiler.Producer.ProgramCode := Compiler.ProgramCode;88 Compiler.Compile;89 103 ProducerControl := TMemo.Create(Self); 90 104 ProducerControl.Parent := Panel1; … … 92 106 ProducerControl.Font.Name := 'Courier New'; 93 107 TMemo(ProducerControl).ScrollBars := ssAutoBoth; 94 with TProducerAsm8051(Compiler.Producer) do 95 for I := 0 to AssemblyCode.Count - 1 do 96 TMemo(ProducerControl).Lines.Add(TAssemblerLine(AssemblyCode[I]).AsString); 97 end; 108 end else 98 109 if ComboBox1.ItemIndex = 3 then begin 99 Compiler.Producer.Free; 100 Compiler.Producer := TProducerTreeView.Create; 101 Compiler.Producer.ProgramCode := Compiler.ProgramCode; 102 ProducerControl := TTreeView.Create(Self); 103 ProducerControl.Parent := Panel1; 104 ProducerControl.Align := alClient; 105 TProducerTreeView(Compiler.Producer).TreeView := TTreeView(ProducerControl); 106 Compiler.Compile; 107 end; 110 end; 111 108 112 LoadErrorMessages; 109 113 end; … … 128 132 end; 129 133 134 procedure TMainForm.TreeViewProjectChange(Sender: TObject; Node: TTreeNode); 135 begin 136 if Assigned(Node) then begin 137 if TProjectNode(Node.Data) is TProjectFile then begin 138 SynEdit1.Lines.Assign(TProjectFile(Node.Data).Source); 139 if ProducerControl is TMemo then 140 TMemo(ProducerControl).Lines.Assign(TProjectFile(Node.Data).ProducedCode); 141 end; 142 end; 143 end; 144 145 procedure TMainForm.UpdateProjectTree; 146 var 147 NewNode: TTreeNode; 148 begin 149 with TreeViewProject, Items do begin 150 BeginUpdate; 151 Clear; 152 NewNode := AddChild(nil, Project.Name); 153 UpdateProjectGroup(NewNode, Project); 154 NewNode.Expand(True); 155 EndUpdate; 156 end; 157 TreeViewProject.TopItem.Items[0].Selected := True; 158 end; 159 160 procedure TMainForm.UpdateProjectGroup(Node: TTreeNode; Group: TProjectGroup); 161 var 162 I: Integer; 163 NewNode: TTreeNode; 164 begin 165 for I := 0 to Group.Items.Count - 1 do begin 166 NewNode := TreeViewProject.Items.AddChild(Node, 167 TProjectNode(Group.Items[I]).Name); 168 NewNode.Data := Pointer(Group.Items[I]); 169 if TProjectNode(Group.Items[I]) is TProjectGroup then 170 UpdateProjectGroup(NewNode, TProjectGroup(Group.Items[I])); 171 end; 172 end; 173 130 174 procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction); 131 175 begin 132 SynEdit1.Lines.SaveToFile(ExampleFileName);176 Project.Save; 133 177 end; 134 178 … … 136 180 begin 137 181 Compiler := TCompiler.Create; 138 SourceTree := TProducerTreeView.Create;182 Project := TProject.Create; 139 183 end; 140 184 141 185 procedure TMainForm.FormDestroy(Sender: TObject); 142 186 begin 187 Project.Free; 143 188 Compiler.Free; 144 SourceTree.Free;145 189 end; 146 190 147 191 procedure TMainForm.FormShow(Sender: TObject); 148 begin 192 var 193 NewProjectFile: TProjectFile; 194 begin 195 Project.Name := 'Project'; 196 NewProjectFile := TProjectFile.Create; 197 NewProjectFile.Name := 'Project.pas'; 198 NewProjectFile.FileName := ProjectDir + 'Project.pas'; 199 Project.Items.Add(NewProjectFile); 200 NewProjectFile := TProjectFile.Create; 201 NewProjectFile.Name := 'System.pas'; 202 NewProjectFile.FileName := ProjectDir + 'System.pas'; 203 Project.Items.Add(NewProjectFile); 204 Project.Load; 205 UpdateProjectTree; 206 149 207 WindowState := wsMaximized; 150 SynEdit1.Lines.LoadFromFile(ExampleFileName);151 208 ButtonCompileClick(Self); 152 209 end; -
branches/DelphiToC/Produce/UProducer.pas
r52 r54 6 6 7 7 uses 8 USourceCode ;8 USourceCode, Classes; 9 9 10 10 type 11 11 TProducer = class 12 ProgramCode: TProgram; 13 procedure Produce; virtual; abstract; 12 procedure Produce(Module: TModule; ProducedCode: TStringList); virtual; abstract; 14 13 end; 15 14 -
branches/DelphiToC/Produce/UProducerAsm8051.pas
r52 r54 26 26 end; 27 27 28 { TProducerAsm8051 } 29 28 30 TProducerAsm8051 = class(TProducer) 29 31 private … … 33 35 procedure GenerateExpression(Expression: TExpression; LabelPrefix: string); 34 36 procedure GenerateProgram(ProgramBlock: TProgram); 37 procedure GenerateModule(Module: TModule); 35 38 public 36 39 AssemblyCode: TList; // TList<TAssemblerLine> 37 procedure Produce ; override;40 procedure Produce(Module: TModule; ProducedCode: TStringList); override; 38 41 constructor Create; 39 42 destructor Destroy; override; … … 189 192 end; 190 193 191 procedure TProducerAsm8051.Produce; 192 begin 193 GenerateProgram(ProgramCode); 194 procedure TProducerAsm8051.GenerateModule(Module: TModule); 195 begin 196 197 end; 198 199 procedure TProducerAsm8051.Produce(Module: TModule; ProducedCode: TStringList); 200 begin 201 GenerateModule(Module); 194 202 end; 195 203 -
branches/DelphiToC/Produce/UProducerC.pas
r53 r54 38 38 IndentationLength: Integer; 39 39 Indetation: Integer; 40 procedure Produce ; override;40 procedure Produce(Module: TModule; ProducedCode: TStringList); override; 41 41 constructor Create; 42 42 destructor Destroy; override; … … 119 119 end; 120 120 121 procedure TProducerC.Produce ;121 procedure TProducerC.Produce(Module: TModule; ProducedCode: TStringList); 122 122 begin 123 123 inherited; 124 124 TextSource.Clear; 125 Generate Program(ProgramCode);125 GenerateModule(Module); 126 126 end; 127 127 -
branches/DelphiToC/Produce/UProducerPascal.pas
r53 r54 38 38 IndentationLength: Integer; 39 39 Indetation: Integer; 40 procedure Produce ; override;40 procedure Produce(Module: TModule; ProducedCode: TStringList); override; 41 41 constructor Create; 42 42 destructor Destroy; override; … … 49 49 constructor TProducerPascal.Create; 50 50 begin 51 TextSource := TStringList.Create;52 51 IndentationLength := 2; 53 52 end; … … 55 54 destructor TProducerPascal.Destroy; 56 55 begin 57 TextSource.Free;58 56 inherited; 59 57 end; … … 86 84 procedure TProducerPascal.GenerateModule(Module: TModule); 87 85 begin 88 Emit('program ' + Module.Name + ';'); 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 + ';'); 89 93 Emit(''); 90 94 GenerateUses(Module.UsedModules); … … 144 148 end; 145 149 146 procedure TProducerPascal.Produce ;150 procedure TProducerPascal.Produce(Module: TModule; ProducedCode: TStringList); 147 151 begin 148 152 inherited; 153 TextSource := ProducedCode; 149 154 TextSource.Clear; 150 Generate Program(ProgramCode);155 GenerateModule(Module); 151 156 end; 152 157 … … 183 188 Line := Line + ')'; 184 189 end; 185 if HaveResult then Line := Line + ': ' + ResultType.Name; 190 if HaveResult and Assigned(ResultType) then 191 Line := Line + ': ' + ResultType.Name; 186 192 Emit(Line + ';'); 187 193 GenerateBeginEnd(Code); … … 256 262 begin 257 263 with ForToDo do begin 264 if Assigned(ControlVariable) and Assigned(Start) and Assigned(Stop) then 258 265 Emit('for ' + ControlVariable.Name + ' := ' + 259 266 GenerateExpression(Start) + ' to ' + GenerateExpression(Stop) + ' do '); -
branches/DelphiToC/Produce/UProducerTreeView.pas
r53 r54 34 34 public 35 35 TreeView: TTreeView; 36 procedure Produce ; override;36 procedure Produce(Module: TModule; ProducedCode: TStringList); override; 37 37 end; 38 38 … … 322 322 end; 323 323 324 procedure TProducerTreeView.Produce ;324 procedure TProducerTreeView.Produce(Module: TModule; ProducedCode: TStringList); 325 325 begin 326 326 with TreeView do begin 327 327 BeginUpdate; 328 328 Items.Clear; 329 AddNode Program(TopItem, ProgramCode);329 AddNodeModule(TopItem, Module); 330 330 TopItem.Expand(True); 331 331 EndUpdate; -
branches/DelphiToC/Transpascal.lpi
r53 r54 41 41 </Item2> 42 42 </RequiredPackages> 43 <Units Count="2 0">43 <Units Count="21"> 44 44 <Unit0> 45 45 <Filename Value="Transpascal.lpr"/> … … 49 49 <WindowIndex Value="0"/> 50 50 <TopLine Value="4"/> 51 <CursorPos X=" 26" Y="23"/>51 <CursorPos X="1" Y="29"/> 52 52 <UsageCount Value="148"/> 53 53 <Loaded Value="True"/> … … 62 62 <EditorIndex Value="6"/> 63 63 <WindowIndex Value="0"/> 64 <TopLine Value=" 69"/>65 <CursorPos X=" 1" Y="94"/>64 <TopLine Value="91"/> 65 <CursorPos X="40" Y="106"/> 66 66 <UsageCount Value="148"/> 67 67 <Loaded Value="True"/> … … 83 83 <EditorIndex Value="5"/> 84 84 <WindowIndex Value="0"/> 85 <TopLine Value="1 46"/>86 <CursorPos X=" 5" Y="159"/>85 <TopLine Value="1"/> 86 <CursorPos X="29" Y="14"/> 87 87 <UsageCount Value="148"/> 88 88 <Loaded Value="True"/> … … 92 92 <IsPartOfProject Value="True"/> 93 93 <UnitName Value="UCompiler"/> 94 <EditorIndex Value="1 2"/>95 <WindowIndex Value="0"/> 96 <TopLine Value=" 102"/>97 <CursorPos X="2 4" Y="98"/>94 <EditorIndex Value="13"/> 95 <WindowIndex Value="0"/> 96 <TopLine Value="37"/> 97 <CursorPos X="29" Y="50"/> 98 98 <UsageCount Value="148"/> 99 99 <Loaded Value="True"/> … … 105 105 <EditorIndex Value="10"/> 106 106 <WindowIndex Value="0"/> 107 <TopLine Value="1 5"/>108 <CursorPos X=" 19" Y="28"/>107 <TopLine Value="179"/> 108 <CursorPos X="3" Y="196"/> 109 109 <UsageCount Value="148"/> 110 110 <Loaded Value="True"/> … … 117 117 <WindowIndex Value="0"/> 118 118 <TopLine Value="1"/> 119 <CursorPos X=" 5" Y="13"/>119 <CursorPos X="38" Y="12"/> 120 120 <UsageCount Value="148"/> 121 121 <Loaded Value="True"/> … … 125 125 <IsPartOfProject Value="True"/> 126 126 <UnitName Value="UProducerC"/> 127 <IsVisibleTab Value="True"/> 128 <EditorIndex Value="11"/> 129 <WindowIndex Value="0"/> 130 <TopLine Value="57"/> 131 <CursorPos X="46" Y="69"/> 127 <EditorIndex Value="12"/> 128 <WindowIndex Value="0"/> 129 <TopLine Value="121"/> 130 <CursorPos X="17" Y="125"/> 132 131 <UsageCount Value="148"/> 133 132 <Loaded Value="True"/> … … 139 138 <EditorIndex Value="0"/> 140 139 <WindowIndex Value="0"/> 141 <TopLine Value=" 1042"/>142 <CursorPos X=" 29" Y="1061"/>140 <TopLine Value="619"/> 141 <CursorPos X="1" Y="632"/> 143 142 <UsageCount Value="148"/> 144 143 <Loaded Value="True"/> … … 207 206 <EditorIndex Value="2"/> 208 207 <WindowIndex Value="0"/> 209 <TopLine Value=" 166"/>210 <CursorPos X=" 33" Y="179"/>208 <TopLine Value="280"/> 209 <CursorPos X="45" Y="294"/> 211 210 <UsageCount Value="110"/> 212 211 <Loaded Value="True"/> … … 231 230 <IsPartOfProject Value="True"/> 232 231 <UnitName Value="UProducerPascal"/> 232 <IsVisibleTab Value="True"/> 233 233 <EditorIndex Value="8"/> 234 234 <WindowIndex Value="0"/> 235 <TopLine Value=" 61"/>236 <CursorPos X="1 " Y="70"/>235 <TopLine Value="74"/> 236 <CursorPos X="14" Y="92"/> 237 237 <UsageCount Value="64"/> 238 238 <Loaded Value="True"/> 239 239 </Unit19> 240 <Unit20> 241 <Filename Value="UProject.pas"/> 242 <IsPartOfProject Value="True"/> 243 <UnitName Value="UProject"/> 244 <EditorIndex Value="11"/> 245 <WindowIndex Value="0"/> 246 <TopLine Value="24"/> 247 <CursorPos X="16" Y="37"/> 248 <UsageCount Value="20"/> 249 <Loaded Value="True"/> 250 </Unit20> 240 251 </Units> 241 252 <JumpHistory Count="30" HistoryIndex="29"> 242 253 <Position1> 243 254 <Filename Value="Produce\UProducerPascal.pas"/> 244 <Caret Line="1 86" Column="17" TopLine="171"/>255 <Caret Line="149" Column="18" TopLine="144"/> 245 256 </Position1> 246 257 <Position2> 247 258 <Filename Value="Produce\UProducerPascal.pas"/> 248 <Caret Line=" 217" Column="11" TopLine="209"/>259 <Caret Line="40" Column="23" TopLine="27"/> 249 260 </Position2> 250 261 <Position3> 251 <Filename Value="Produce\UProducer Pascal.pas"/>252 <Caret Line=" 244" Column="48" TopLine="238"/>262 <Filename Value="Produce\UProducerC.pas"/> 263 <Caret Line="40" Column="38" TopLine="27"/> 253 264 </Position3> 254 265 <Position4> 255 <Filename Value="Produce\UProducer Pascal.pas"/>256 <Caret Line=" 278" Column="40" TopLine="263"/>266 <Filename Value="Produce\UProducerC.pas"/> 267 <Caret Line="121" Column="29" TopLine="107"/> 257 268 </Position4> 258 269 <Position5> 259 <Filename Value=" Forms\UMainForm.pas"/>260 <Caret Line=" 29" Column="44" TopLine="15"/>270 <Filename Value="Produce\UProducerC.pas"/> 271 <Caret Line="40" Column="66" TopLine="39"/> 261 272 </Position5> 262 273 <Position6> 263 <Filename Value=" Forms\UMainForm.pas"/>264 <Caret Line=" 66" Column="43" TopLine="56"/>274 <Filename Value="UCompiler.pas"/> 275 <Caret Line="50" Column="1" TopLine="29"/> 265 276 </Position6> 266 277 <Position7> 267 <Filename Value=" Forms\UMainForm.pas"/>268 <Caret Line=" 146" Column="16" TopLine="129"/>278 <Filename Value="Produce\UProducerAsm8051.pas"/> 279 <Caret Line="37" Column="38" TopLine="24"/> 269 280 </Position7> 270 281 <Position8> 271 <Filename Value="Produce\UProducer Pascal.pas"/>272 <Caret Line=" 31" Column="48" TopLine="20"/>282 <Filename Value="Produce\UProducerAsm8051.pas"/> 283 <Caret Line="191" Column="35" TopLine="171"/> 273 284 </Position8> 274 285 <Position9> 275 <Filename Value="Produce\UProducer Pascal.pas"/>276 <Caret Line=" 243" Column="46" TopLine="238"/>286 <Filename Value="Produce\UProducerAsm8051.pas"/> 287 <Caret Line="37" Column="66" TopLine="37"/> 277 288 </Position9> 278 289 <Position10> 279 <Filename Value=" Forms\UMainForm.pas"/>280 <Caret Line=" 67" Column="33" TopLine="55"/>290 <Filename Value="Produce\UProducerAsm8051.pas"/> 291 <Caret Line="193" Column="24" TopLine="171"/> 281 292 </Position10> 282 293 <Position11> 283 <Filename Value="Produce\UProducer C.pas"/>284 <Caret Line=" 29" Column="30" TopLine="14"/>294 <Filename Value="Produce\UProducerAsm8051.pas"/> 295 <Caret Line="35" Column="45" TopLine="24"/> 285 296 </Position11> 286 297 <Position12> 287 <Filename Value="Produce\UProducer C.pas"/>288 <Caret Line=" 24" Column="1" TopLine="14"/>298 <Filename Value="Produce\UProducerAsm8051.pas"/> 299 <Caret Line="37" Column="15" TopLine="22"/> 289 300 </Position12> 290 301 <Position13> 291 <Filename Value="Produce\UProducer C.pas"/>292 <Caret Line=" 25" Column="38" TopLine="11"/>302 <Filename Value="Produce\UProducerTreeView.pas"/> 303 <Caret Line="325" Column="1" TopLine="311"/> 293 304 </Position13> 294 305 <Position14> 295 <Filename Value="Produce\UProducer C.pas"/>296 <Caret Line="3 12" Column="16" TopLine="294"/>306 <Filename Value="Produce\UProducerTreeView.pas"/> 307 <Caret Line="36" Column="23" TopLine="23"/> 297 308 </Position14> 298 309 <Position15> 299 <Filename Value="Produce\UProducer C.pas"/>300 <Caret Line=" 24" Column="40" TopLine="11"/>310 <Filename Value="Produce\UProducerTreeView.pas"/> 311 <Caret Line="329" Column="13" TopLine="311"/> 301 312 </Position15> 302 313 <Position16> 303 <Filename Value=" Produce\UProducerC.pas"/>304 <Caret Line=" 268" Column="47" TopLine="268"/>314 <Filename Value="Analyze\UParser.pas"/> 315 <Caret Line="635" Column="12" TopLine="630"/> 305 316 </Position16> 306 317 <Position17> 307 <Filename Value=" Produce\UProducerC.pas"/>308 <Caret Line=" 281" Column="8" TopLine="268"/>318 <Filename Value="Analyze\UParser.pas"/> 319 <Caret Line="632" Column="1" TopLine="627"/> 309 320 </Position17> 310 321 <Position18> 311 <Filename Value=" Produce\UProducerC.pas"/>312 <Caret Line=" 19" Column="31" TopLine="6"/>322 <Filename Value="Analyze\UParser.pas"/> 323 <Caret Line="634" Column="1" TopLine="627"/> 313 324 </Position18> 314 325 <Position19> 315 <Filename Value=" Produce\UProducerC.pas"/>316 <Caret Line=" 91" Column="1" TopLine="87"/>326 <Filename Value="Analyze\UParser.pas"/> 327 <Caret Line="635" Column="1" TopLine="627"/> 317 328 </Position19> 318 329 <Position20> 319 <Filename Value=" Produce\UProducerC.pas"/>320 <Caret Line=" 87" Column="27" TopLine="74"/>330 <Filename Value="Analyze\UParser.pas"/> 331 <Caret Line="665" Column="1" TopLine="652"/> 321 332 </Position20> 322 333 <Position21> 323 <Filename Value=" Produce\UProducerC.pas"/>324 <Caret Line=" 19" Column="33" TopLine="18"/>334 <Filename Value="Analyze\UParser.pas"/> 335 <Caret Line="666" Column="1" TopLine="652"/> 325 336 </Position21> 326 337 <Position22> 327 <Filename Value=" Produce\UProducerC.pas"/>328 <Caret Line=" 87" Column="21" TopLine="74"/>338 <Filename Value="Analyze\UParser.pas"/> 339 <Caret Line="669" Column="1" TopLine="652"/> 329 340 </Position22> 330 341 <Position23> 331 <Filename Value=" Produce\UProducerC.pas"/>332 <Caret Line=" 19" Column="20" TopLine="18"/>342 <Filename Value="Analyze\UParser.pas"/> 343 <Caret Line="670" Column="1" TopLine="652"/> 333 344 </Position23> 334 345 <Position24> 335 <Filename Value="Produce\UProducer C.pas"/>336 <Caret Line="8 7" Column="28" TopLine="87"/>346 <Filename Value="Produce\UProducerPascal.pas"/> 347 <Caret Line="88" Column="25" TopLine="84"/> 337 348 </Position24> 338 349 <Position25> 339 <Filename Value="Produce\UProducer C.pas"/>340 <Caret Line=" 290" Column="17" TopLine="277"/>350 <Filename Value="Produce\UProducerPascal.pas"/> 351 <Caret Line="86" Column="23" TopLine="74"/> 341 352 </Position25> 342 353 <Position26> 343 <Filename Value=" Produce\UProducerC.pas"/>344 <Caret Line="27 8" Column="3" TopLine="274"/>354 <Filename Value="USourceCode.pas"/> 355 <Caret Line="274" Column="25" TopLine="261"/> 345 356 </Position26> 346 357 <Position27> 347 <Filename Value="Produce\UProducer C.pas"/>348 <Caret Line=" 290" Column="45" TopLine="277"/>358 <Filename Value="Produce\UProducerPascal.pas"/> 359 <Caret Line="86" Column="23" TopLine="74"/> 349 360 </Position27> 350 361 <Position28> 351 <Filename Value="Produce\UProducer C.pas"/>352 <Caret Line=" 117" Column="18" TopLine="94"/>362 <Filename Value="Produce\UProducerPascal.pas"/> 363 <Caret Line="89" Column="10" TopLine="74"/> 353 364 </Position28> 354 365 <Position29> 355 <Filename Value="Produce\UProducer C.pas"/>356 <Caret Line=" 288" Column="27" TopLine="275"/>366 <Filename Value="Produce\UProducerPascal.pas"/> 367 <Caret Line="92" Column="8" TopLine="74"/> 357 368 </Position29> 358 369 <Position30> 359 <Filename Value="Produce\UProducer C.pas"/>360 <Caret Line=" 69" Column="39" TopLine="61"/>370 <Filename Value="Produce\UProducerPascal.pas"/> 371 <Caret Line="88" Column="23" TopLine="74"/> 361 372 </Position30> 362 373 </JumpHistory> -
branches/DelphiToC/Transpascal.lpr
r53 r54 15 15 UProducer, 16 16 UProducerC, UProducerPascal, 17 UParser, UProducerTreeView ;17 UParser, UProducerTreeView, UProject; 18 18 19 19 {$R *.res} -
branches/DelphiToC/UCompiler.pas
r53 r54 23 23 FOnErrorMessage: TOnErrorMessage; 24 24 procedure ErrorMessage(Text: string; Position: TPoint); 25 procedure InitSystem;26 25 public 27 26 ProgramCode: TProgram; 28 SourceCode: TStringList;29 27 Parser: TPascalParser; 30 28 Producer: TProducer; 31 29 ErrorMessages: TObjectList; 32 30 constructor Create; 33 procedure Compile; 31 procedure Init; 32 procedure Compile(Source: TStringList; ProducedCode: TStringList); 34 33 destructor Destroy; override; 35 34 property OnErrorMessage: TOnErrorMessage read FOnErrorMessage write FOnErrorMessage; … … 40 39 { TCompiler } 41 40 42 procedure TCompiler.Compile; 41 procedure TCompiler.Compile(Source: TStringList; ProducedCode: TStringList); 42 var 43 NewModule: TModule; 43 44 begin 44 InitSystem; 45 ErrorMessages.Clear; 45 Parser.SourceCodeText := Source; 46 46 Parser.Init; 47 Parser.ParseAll(ProgramCode); 48 Producer.Produce; 47 NewModule := TModule.Create; 48 ProgramCode.Modules.Add(NewModule); 49 Parser.ParseModule(NewModule); 50 Producer.Produce(NewModule, ProducedCode); 49 51 end; 50 52 51 53 constructor TCompiler.Create; 52 54 begin 53 SourceCode := TStringList.Create;54 55 ProgramCode := TProgram.Create; 55 56 Producer := TProducerC.Create; 56 Producer.ProgramCode := ProgramCode;57 57 Parser := TPascalParser.Create; 58 Parser.SourceCodeText := SourceCode;59 58 Parser.OnErrorMessage := ErrorMessage; 60 59 ErrorMessages := TObjectList.Create; 60 end; 61 62 procedure TCompiler.Init; 63 begin 64 ErrorMessages.Clear; 65 ProgramCode.Modules.Clear; 61 66 end; 62 67 … … 64 69 begin 65 70 ProgramCode.Free; 66 SourceCode.Free;67 71 Parser.Free; 68 72 Producer.Free; … … 81 85 end; 82 86 83 procedure TCompiler.InitSystem;84 begin85 with Parser do begin86 Log('==== Parse start ====');87 with ProgramCode do begin88 Modules.Clear;89 90 with TModule(Modules[Modules.Add(TModule.Create)]) do begin91 Name := 'Main';92 with TType(Types[Types.Add(TType.Create)]) do begin93 Name := 'Void';94 System := True;95 Size := 0;96 UsedType := nil;97 end;98 with TType(Types[Types.Add(TType.Create)]) do begin99 Name := 'Byte';100 System := True;101 Size := 1;102 UsedType := nil;103 end;104 with TType(Types[Types.Add(TType.Create)]) do begin105 Name := 'ShortInt';106 System := True;107 Size := 1;108 UsedType := nil;109 end;110 with TType(Types[Types.Add(TType.Create)]) do begin111 Name := 'Word';112 System := True;113 Size := 2;114 UsedType := nil;115 end;116 with TType(Types[Types.Add(TType.Create)]) do begin117 Name := 'SmallInt';118 System := True;119 Size := 2;120 UsedType := nil;121 end;122 with TType(Types[Types.Add(TType.Create)]) do begin123 Name := 'Cardinal';124 System := True;125 Size := 3;126 UsedType := nil;127 end;128 with TType(Types[Types.Add(TType.Create)]) do begin129 Name := 'Integer';130 System := True;131 Size := 3;132 UsedType := nil;133 end;134 with TType(Types[Types.Add(TType.Create)]) do begin135 Name := 'Char';136 System := True;137 Size := 1;138 UsedType := nil;139 end;140 with TType(Types[Types.Add(TType.Create)]) do begin141 Name := 'String';142 System := True;143 Size := 1;144 UsedType := nil;145 end;146 with TFunction(Functions[Functions.Add(TFunction.Create)]) do begin147 Name := 'Exit';148 System := True;149 ResultType := TType(TModule(Modules[0]).Types[0]);150 end;151 with TFunction(Functions[Functions.Add(TFunction.Create)]) do begin152 Name := 'Break';153 System := True;154 ResultType := TType(TModule(Modules[0]).Types[0]);155 end;156 with TFunction(Functions[Functions.Add(TFunction.Create)]) do begin157 Name := 'Continue';158 System := True;159 ResultType := TType(TModule(Modules[0]).Types[0]);160 end;161 with TFunction(Functions[Functions.Add(TFunction.Create)]) do begin162 Name := 'WriteLn';163 ResultType := TType(TModule(Modules[0]).Types[0]);164 with TParameter(Parameters[Parameters.Add(TParameter.Create)]) do begin165 Name := 'Text';166 ValueType := TType(TModule(Modules[0]).Types[1]);167 end;168 end;169 end;170 end;171 end;172 end;173 174 87 end. -
branches/DelphiToC/USourceCode.pas
r53 r54 279 279 end; 280 280 281 { TModuleList } 282 283 TModuleList = class(TObjectList) 284 function Search(Name: string): TModule; 285 end; 286 281 287 TProgram = class 282 288 Device: TDevice; 283 Modules: T ObjectList; // TObjectList<TModule>289 Modules: TModuleList; 284 290 constructor Create; 285 291 destructor Destroy; override; … … 321 327 begin 322 328 Device := TDevice.Create; 323 Modules := T ObjectList.Create;329 Modules := TModuleList.Create; 324 330 end; 325 331 … … 677 683 end; 678 684 685 { TModuleList } 686 687 function TModuleList.Search(Name: string): TModule; 688 var 689 I: Integer; 690 begin 691 I := 0; 692 while (I < Count) and (LowerCase(TModule(Items[I]).Name) <> LowerCase(Name)) do Inc(I); 693 if I < Count then Result := TModule(Items[I]) else Result := nil; 694 end; 695 679 696 end. 680 697
Note:
See TracChangeset
for help on using the changeset viewer.