Changeset 48 for branches/DelphiToC
- Timestamp:
- Aug 9, 2010, 1:53:33 PM (14 years ago)
- Location:
- branches/DelphiToC
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/Analyze/UPascalParser.pas
r47 r48 49 49 TPascalParser = class(TBaseParser) 50 50 procedure ParseWhileDo(SourceCode: TWhileDo); 51 function ParseExpression(SourceCode: TExpression): TExpression;51 procedure ParseExpression(SourceCode: TExpression); 52 52 procedure ParseUsedModuleList(SourceCode: TUsedModuleList); 53 53 procedure ParseModule(SourceCode: TModule); … … 290 290 { TExpression } 291 291 292 function TPascalParser.ParseExpression(SourceCode: TExpression): TExpression;292 procedure TPascalParser.ParseExpression(SourceCode: TExpression); 293 293 var 294 294 Identifier: string; … … 340 340 end; 341 341 end else begin 342 Method := CommonBlock. Methods.Search(Identifier);342 Method := CommonBlock.Functions.Search(Identifier); 343 343 if Assigned(Method) then begin 344 344 // Referenced method … … 444 444 LoopVariable: TVariable; 445 445 IdentName: string; 446 FunctionName: string; 446 447 begin 447 448 begin … … 465 466 if IsIdentificator(FNextToken) then begin 466 467 if Assigned(SourceCode.Variables.Search(FNextToken)) then begin 468 // Variable assignment 467 469 Result := TAssignment.Create; 468 470 TAssignment(Result).CommonBlock := SourceCode; … … 474 476 ParseExpression(TAssignment(Result).Source); 475 477 end else 476 if Assigned(SourceCode.Methods.Search(FNextToken)) then begin 478 if Assigned(SourceCode.Functions.Search(FNextToken)) then begin 479 // Function call 480 FunctionName := ReadCode; 477 481 Result := TFunctionCall.Create; 478 482 TFunctionCall(Result).CommonBlock := SourceCode; 479 TFunctionCall(Result).FunctionRef := SourceCode.Methods.Search(FNextToken); 480 ReadCode; 481 // ParseMetVariable(TFunctionCall(Result).Target); 483 TFunctionCall(Result).FunctionRef := SourceCode.Functions.Search(FunctionName); 484 if FNextToken = '(' then begin 485 Expect('('); 486 with TFunctionCall(Result) do begin 487 ParameterExpression.Add(TExpression.Create); 488 TExpression(ParameterExpression.Last).CommonBlock := SourceCode; 489 ParseExpression(TExpression(ParameterExpression.Last)); 490 end; 491 Expect(')'); 492 end; 482 493 end else begin 483 494 Result := nil; … … 561 572 ParseTypeList(Types) 562 573 else if FNextToken = 'procedure' then 563 ParseFunctionList( Methods)574 ParseFunctionList(Functions) 564 575 else if FNextToken = 'function' then 565 ParseFunctionList( Methods)576 ParseFunctionList(Functions) 566 577 else begin 567 578 ParseBeginEnd(Code); … … 583 594 Expect('begin'); 584 595 while (FNextToken <> 'end') and (FNextTokenType <> ttEndOfFile) do begin 585 Commands.Add(nil);586 596 NewCommand := ParseCommand(CommonBlock); 587 597 if Assigned(NewCommand) then Commands.Add(NewCommand); -
branches/DelphiToC/DelphiToC.lpi
r47 r48 48 48 <TopLine Value="4"/> 49 49 <CursorPos X="1" Y="29"/> 50 <UsageCount Value="1 07"/>50 <UsageCount Value="110"/> 51 51 <Loaded Value="True"/> 52 52 </Unit0> … … 62 62 <TopLine Value="56"/> 63 63 <CursorPos X="1" Y="79"/> 64 <UsageCount Value="1 07"/>64 <UsageCount Value="110"/> 65 65 <Loaded Value="True"/> 66 66 <LoadedDesigner Value="True"/> … … 73 73 <TopLine Value="1"/> 74 74 <CursorPos X="1" Y="1"/> 75 <UsageCount Value="1 07"/>75 <UsageCount Value="110"/> 76 76 </Unit2> 77 77 <Unit3> … … 81 81 <EditorIndex Value="5"/> 82 82 <WindowIndex Value="0"/> 83 <TopLine Value="2 21"/>84 <CursorPos X=" 25" Y="240"/>85 <UsageCount Value="1 07"/>83 <TopLine Value="264"/> 84 <CursorPos X="5" Y="277"/> 85 <UsageCount Value="110"/> 86 86 <Loaded Value="True"/> 87 87 </Unit3> … … 92 92 <EditorIndex Value="13"/> 93 93 <WindowIndex Value="0"/> 94 <TopLine Value=" 36"/>95 <CursorPos X=" 1" Y="41"/>96 <UsageCount Value="1 07"/>94 <TopLine Value="76"/> 95 <CursorPos X="53" Y="96"/> 96 <UsageCount Value="110"/> 97 97 <Loaded Value="True"/> 98 98 </Unit4> … … 105 105 <TopLine Value="112"/> 106 106 <CursorPos X="48" Y="128"/> 107 <UsageCount Value="1 07"/>107 <UsageCount Value="110"/> 108 108 <Loaded Value="True"/> 109 109 </Unit5> … … 116 116 <TopLine Value="1"/> 117 117 <CursorPos X="15" Y="13"/> 118 <UsageCount Value="1 07"/>118 <UsageCount Value="110"/> 119 119 <Loaded Value="True"/> 120 120 </Unit6> … … 125 125 <EditorIndex Value="10"/> 126 126 <WindowIndex Value="0"/> 127 <TopLine Value=" 171"/>128 <CursorPos X="4 5" Y="175"/>129 <UsageCount Value="1 07"/>127 <TopLine Value="89"/> 128 <CursorPos X="44" Y="96"/> 129 <UsageCount Value="110"/> 130 130 <Loaded Value="True"/> 131 131 </Unit7> … … 137 137 <EditorIndex Value="0"/> 138 138 <WindowIndex Value="0"/> 139 <TopLine Value=" 641"/>140 <CursorPos X=" 45" Y="653"/>141 <UsageCount Value="1 07"/>139 <TopLine Value="588"/> 140 <CursorPos X="1" Y="596"/> 141 <UsageCount Value="110"/> 142 142 <Loaded Value="True"/> 143 143 </Unit8> … … 147 147 <TopLine Value="1"/> 148 148 <CursorPos X="1" Y="1"/> 149 <UsageCount Value=" 1"/>149 <UsageCount Value="0"/> 150 150 <DefaultSyntaxHighlighter Value="LFM"/> 151 151 </Unit9> … … 157 157 <TopLine Value="78"/> 158 158 <CursorPos X="14" Y="91"/> 159 <UsageCount Value="5 4"/>159 <UsageCount Value="55"/> 160 160 <Loaded Value="True"/> 161 161 </Unit10> … … 166 166 <TopLine Value="1555"/> 167 167 <CursorPos X="1" Y="1"/> 168 <UsageCount Value=" 5"/>168 <UsageCount Value="4"/> 169 169 </Unit11> 170 170 <Unit12> … … 174 174 <TopLine Value="61"/> 175 175 <CursorPos X="7" Y="68"/> 176 <UsageCount Value="3 7"/>176 <UsageCount Value="38"/> 177 177 <Loaded Value="True"/> 178 178 </Unit12> … … 183 183 <TopLine Value="139"/> 184 184 <CursorPos X="16" Y="146"/> 185 <UsageCount Value="3 7"/>185 <UsageCount Value="38"/> 186 186 <Loaded Value="True"/> 187 187 </Unit13> … … 191 191 <TopLine Value="934"/> 192 192 <CursorPos X="10" Y="947"/> 193 <UsageCount Value=" 9"/>193 <UsageCount Value="8"/> 194 194 </Unit14> 195 195 <Unit15> … … 198 198 <TopLine Value="834"/> 199 199 <CursorPos X="11" Y="847"/> 200 <UsageCount Value=" 5"/>200 <UsageCount Value="4"/> 201 201 </Unit15> 202 202 <Unit16> … … 206 206 <TopLine Value="153"/> 207 207 <CursorPos X="8" Y="166"/> 208 <UsageCount Value="1 2"/>208 <UsageCount Value="13"/> 209 209 <Loaded Value="True"/> 210 210 </Unit16> … … 215 215 <EditorIndex Value="2"/> 216 216 <WindowIndex Value="0"/> 217 <TopLine Value=" 178"/>218 <CursorPos X=" 67" Y="190"/>219 <UsageCount Value=" 69"/>217 <TopLine Value="247"/> 218 <CursorPos X="56" Y="267"/> 219 <UsageCount Value="72"/> 220 220 <Loaded Value="True"/> 221 221 </Unit17> … … 226 226 <TopLine Value="2656"/> 227 227 <CursorPos X="3" Y="2669"/> 228 <UsageCount Value=" 5"/>228 <UsageCount Value="4"/> 229 229 </Unit18> 230 230 <Unit19> … … 232 232 <EditorIndex Value="11"/> 233 233 <WindowIndex Value="0"/> 234 <TopLine Value=" 263"/>235 <CursorPos X=" 14" Y="276"/>236 <UsageCount Value="1 2"/>234 <TopLine Value="559"/> 235 <CursorPos X="57" Y="571"/> 236 <UsageCount Value="13"/> 237 237 <Loaded Value="True"/> 238 238 </Unit19> … … 243 243 <EditorIndex Value="8"/> 244 244 <WindowIndex Value="0"/> 245 <TopLine Value="1 03"/>246 <CursorPos X=" 21" Y="116"/>247 <UsageCount Value="2 3"/>245 <TopLine Value="138"/> 246 <CursorPos X="52" Y="151"/> 247 <UsageCount Value="26"/> 248 248 <Loaded Value="True"/> 249 249 </Unit20> 250 250 </Units> 251 <JumpHistory Count=" 29" HistoryIndex="28">251 <JumpHistory Count="30" HistoryIndex="29"> 252 252 <Position1> 253 <Filename Value=" UPascalSource.pas"/>254 <Caret Line=" 441" Column="20" TopLine="429"/>253 <Filename Value="Produce\UProducerPascal.pas"/> 254 <Caret Line="245" Column="17" TopLine="226"/> 255 255 </Position1> 256 256 <Position2> 257 <Filename Value=" UPascalSource.pas"/>258 <Caret Line=" 448" Column="49" TopLine="432"/>257 <Filename Value="Produce\UProducerPascal.pas"/> 258 <Caret Line="152" Column="1" TopLine="143"/> 259 259 </Position2> 260 260 <Position3> 261 <Filename Value=" Analyze\UPascalParser.pas"/>262 <Caret Line=" 329" Column="1" TopLine="316"/>261 <Filename Value="Produce\UProducerPascal.pas"/> 262 <Caret Line="59" Column="1" TopLine="46"/> 263 263 </Position3> 264 264 <Position4> 265 <Filename Value=" UPascalSource.pas"/>266 <Caret Line=" 435" Column="1" TopLine="430"/>265 <Filename Value="Produce\UProducerPascal.pas"/> 266 <Caret Line="60" Column="1" TopLine="46"/> 267 267 </Position4> 268 268 <Position5> 269 <Filename Value=" UPascalSource.pas"/>270 <Caret Line=" 436" Column="1" TopLine="430"/>269 <Filename Value="Produce\UProducerPascal.pas"/> 270 <Caret Line="61" Column="1" TopLine="46"/> 271 271 </Position5> 272 272 <Position6> 273 <Filename Value=" UPascalSource.pas"/>274 <Caret Line=" 437" Column="1" TopLine="430"/>273 <Filename Value="Produce\UProducerPascal.pas"/> 274 <Caret Line="59" Column="1" TopLine="46"/> 275 275 </Position6> 276 276 <Position7> 277 <Filename Value=" UPascalSource.pas"/>278 <Caret Line=" 438" Column="1" TopLine="430"/>277 <Filename Value="Produce\UProducerPascal.pas"/> 278 <Caret Line="62" Column="1" TopLine="46"/> 279 279 </Position7> 280 280 <Position8> 281 <Filename Value=" UPascalSource.pas"/>282 <Caret Line=" 440" Column="1" TopLine="430"/>281 <Filename Value="Produce\UProducerPascal.pas"/> 282 <Caret Line="59" Column="1" TopLine="46"/> 283 283 </Position8> 284 284 <Position9> 285 <Filename Value=" UPascalSource.pas"/>286 <Caret Line=" 441" Column="1" TopLine="430"/>285 <Filename Value="Produce\UProducerPascal.pas"/> 286 <Caret Line="62" Column="1" TopLine="46"/> 287 287 </Position9> 288 288 <Position10> 289 <Filename Value=" UPascalSource.pas"/>290 <Caret Line=" 442" Column="1" TopLine="430"/>289 <Filename Value="Produce\UProducerPascal.pas"/> 290 <Caret Line="150" Column="1" TopLine="137"/> 291 291 </Position10> 292 292 <Position11> 293 <Filename Value=" UPascalSource.pas"/>294 <Caret Line=" 446" Column="1" TopLine="430"/>293 <Filename Value="Produce\UProducerPascal.pas"/> 294 <Caret Line="152" Column="8" TopLine="134"/> 295 295 </Position11> 296 296 <Position12> 297 <Filename Value=" UPascalSource.pas"/>298 <Caret Line=" 447" Column="1" TopLine="430"/>297 <Filename Value="Produce\UProducerPascal.pas"/> 298 <Caret Line="61" Column="18" TopLine="58"/> 299 299 </Position12> 300 300 <Position13> 301 <Filename Value=" UPascalSource.pas"/>302 <Caret Line=" 448" Column="1" TopLine="430"/>301 <Filename Value="Produce\UProducerPascal.pas"/> 302 <Caret Line="34" Column="23" TopLine="21"/> 303 303 </Position13> 304 304 <Position14> 305 <Filename Value=" UPascalSource.pas"/>306 <Caret Line=" 452" Column="1" TopLine="431"/>305 <Filename Value="E:\Programy\Lazarus\fpc\2.4.0\source\rtl\objpas\classes\classesh.inc"/> 306 <Caret Line="604" Column="27" TopLine="591"/> 307 307 </Position14> 308 308 <Position15> 309 <Filename Value=" UPascalSource.pas"/>310 <Caret Line=" 453" Column="1" TopLine="432"/>309 <Filename Value="Produce\UProducerPascal.pas"/> 310 <Caret Line="152" Column="6" TopLine="135"/> 311 311 </Position15> 312 312 <Position16> 313 <Filename Value=" UPascalSource.pas"/>314 <Caret Line=" 455" Column="1" TopLine="434"/>313 <Filename Value="Produce\UProducerPascal.pas"/> 314 <Caret Line="8" Column="49" TopLine="1"/> 315 315 </Position16> 316 316 <Position17> 317 <Filename Value=" Analyze\UPascalParser.pas"/>318 <Caret Line=" 329" Column="1" TopLine="316"/>317 <Filename Value="Produce\UProducerPascal.pas"/> 318 <Caret Line="9" Column="51" TopLine="1"/> 319 319 </Position17> 320 320 <Position18> 321 <Filename Value=" UPascalSource.pas"/>322 <Caret Line=" 448" Column="1" TopLine="436"/>321 <Filename Value="Produce\UProducerPascal.pas"/> 322 <Caret Line="74" Column="18" TopLine="61"/> 323 323 </Position18> 324 324 <Position19> 325 <Filename Value=" UPascalSource.pas"/>326 <Caret Line=" 544" Column="1" TopLine="531"/>325 <Filename Value="Produce\UProducerPascal.pas"/> 326 <Caret Line="82" Column="11" TopLine="61"/> 327 327 </Position19> 328 328 <Position20> 329 <Filename Value=" UPascalSource.pas"/>330 <Caret Line=" 545" Column="1" TopLine="531"/>329 <Filename Value="Produce\UProducerPascal.pas"/> 330 <Caret Line="124" Column="20" TopLine="105"/> 331 331 </Position20> 332 332 <Position21> 333 <Filename Value=" UPascalSource.pas"/>334 <Caret Line=" 546" Column="62" TopLine="532"/>333 <Filename Value="Produce\UProducerPascal.pas"/> 334 <Caret Line="126" Column="1" TopLine="105"/> 335 335 </Position21> 336 336 <Position22> 337 337 <Filename Value="Produce\UProducerPascal.pas"/> 338 <Caret Line="1 54" Column="51" TopLine="139"/>338 <Caret Line="138" Column="60" TopLine="125"/> 339 339 </Position22> 340 340 <Position23> 341 <Filename Value=" DelphiToC.lpr"/>342 <Caret Line="15 " Column="42" TopLine="4"/>341 <Filename Value="Produce\UProducerPascal.pas"/> 342 <Caret Line="152" Column="13" TopLine="139"/> 343 343 </Position23> 344 344 <Position24> 345 <Filename Value=" UPascalSource.pas"/>346 <Caret Line=" 241" Column="20" TopLine="221"/>345 <Filename Value="Produce\UProducerPascal.pas"/> 346 <Caret Line="7" Column="62" TopLine="1"/> 347 347 </Position24> 348 348 <Position25> 349 <Filename Value=" Analyze\UPascalParser.pas"/>350 <Caret Line=" 565" Column="22" TopLine="552"/>349 <Filename Value="Produce\UProducerPascal.pas"/> 350 <Caret Line="74" Column="18" TopLine="61"/> 351 351 </Position25> 352 352 <Position26> 353 <Filename Value=" Visual\USourceTree.pas"/>354 <Caret Line=" 194" Column="57" TopLine="186"/>353 <Filename Value="Produce\UProducerPascal.pas"/> 354 <Caret Line="82" Column="11" TopLine="61"/> 355 355 </Position26> 356 356 <Position27> 357 357 <Filename Value="Produce\UProducerPascal.pas"/> 358 <Caret Line="12 0" Column="1" TopLine="99"/>358 <Caret Line="124" Column="20" TopLine="111"/> 359 359 </Position27> 360 360 <Position28> 361 <Filename Value=" Analyze\UPascalParser.pas"/>362 <Caret Line=" 653" Column="28" TopLine="632"/>361 <Filename Value="Produce\UProducerPascal.pas"/> 362 <Caret Line="138" Column="60" TopLine="125"/> 363 363 </Position28> 364 364 <Position29> 365 <Filename Value=" Analyze\UPascalParser.pas"/>366 <Caret Line=" 654" Column="40" TopLine="632"/>365 <Filename Value="Produce\UProducerPascal.pas"/> 366 <Caret Line="152" Column="13" TopLine="139"/> 367 367 </Position29> 368 <Position30> 369 <Filename Value="Produce\UProducerPascal.pas"/> 370 <Caret Line="171" Column="47" TopLine="154"/> 371 </Position30> 368 372 </JumpHistory> 369 373 </ProjectOptions> -
branches/DelphiToC/Example.pas
r47 r48 19 19 D: Byte; 20 20 begin 21 WriteLn ;21 WriteLn(A); 22 22 begin 23 23 WriteLn; -
branches/DelphiToC/Produce/UProducerC.pas
r47 r48 23 23 LabelPrefix: string); 24 24 procedure GenerateProgram(ProgramBlock: TProgram); 25 procedure Generate Methods(Methods: TFunctionList);25 procedure GenerateFunctions(Functions: TFunctionList); 26 26 procedure GenerateBeginEnd(BeginEnd: TBeginEnd); 27 27 procedure GenerateCommand(Command: TCommand); … … 29 29 procedure GenerateIfThenElse(IfThenElse: TIfThenElse); 30 30 procedure GenerateAssignment(Assignment: TAssignment); 31 procedure Generate MethodCall(MethodCall: TFunctionCall);31 procedure GenerateFunctionCall(FunctionCall: TFunctionCall); 32 32 function GenerateExpression(Expression: TExpression): string; 33 33 public … … 58 58 function TCProducer.TranslateType(Name: string): string; 59 59 begin 60 if Name = 'Byte' then Result := 'uint8_t'; 61 if Name = 'Word' then Result := 'uint16_t'; 62 if Name = 'Void' then Result := 'void'; 60 if Name = 'Byte' then Result := 'uint8' 61 else if Name = 'ShortInt' then Result := 'int8' 62 else if Name = 'Word' then Result := 'int16' 63 else if Name = 'SmallInt' then Result := 'int16' 64 else if Name = 'Cardinal' then Result := 'uint32' 65 else if Name = 'Integer' then Result := 'int32' 66 else if Name = 'Void' then Result := 'void'; 63 67 end; 64 68 … … 115 119 end; 116 120 117 procedure TCProducer.GenerateMethods(Methods: TFunctionList); 118 var 119 I: Integer; 120 begin 121 for I := 0 to Methods.Count - 1 do 122 with TFunction(Methods[I]) do 121 procedure TCProducer.GenerateFunctions(Functions: TFunctionList); 122 var 123 I: Integer; 124 J: Integer; 125 Line: string; 126 begin 127 for I := 0 to Functions.Count - 1 do 128 with TFunction(Functions[I]) do 123 129 begin 124 Emit('void ' + Name + '()'); 130 if HaveResult then Line := TranslateType(ResultType.Name) + ' ' 131 else Line := 'void '; 132 Line := Line + Name + '('; 133 if Parameters.Count > 0 then 134 for J := 0 to Parameters.Count - 1 do begin 135 Line := Line + TranslateType(TParameter(Parameters[J]).ValueType.Name) + 136 ' ' + TParameter(Parameters[J]).Name; 137 if J < Parameters.Count - 1 then Line := Line + ', '; 138 end; 139 Line := Line + ')'; 140 Emit(Line); 125 141 GenerateBeginEnd(Code); 126 142 Emit(''); … … 158 174 else if Command is TIfThenElse then GenerateIfThenElse(TIfThenElse(Command)) 159 175 else if Command is TAssignment then GenerateAssignment(TAssignment(Command)) 160 else if Command is TFunctionCall then Generate MethodCall(TFunctionCall(Command));176 else if Command is TFunctionCall then GenerateFunctionCall(TFunctionCall(Command)); 161 177 end; 162 178 … … 182 198 end; 183 199 184 procedure TCProducer.GenerateMethodCall(MethodCall: TFunctionCall); 185 begin 186 Emit(MethodCall.FunctionRef.Name + '();'); 200 procedure TCProducer.GenerateFunctionCall(FunctionCall: TFunctionCall); 201 var 202 Line: string; 203 begin 204 Line := FunctionCall.FunctionRef.Name + '('; 205 Line := Line + ');'; 206 Emit(Line); 187 207 end; 188 208 … … 208 228 begin 209 229 with CommonBlock do begin 210 Generate Methods(Methods);230 GenerateFunctions(Functions); 211 231 Emit('void ' + Name + '()'); 212 232 GenerateBeginEnd(Code); -
branches/DelphiToC/Produce/UProducerPascal.pas
r47 r48 15 15 TProducerPascal = class(TCodeProducer) 16 16 private 17 procedure Emit(Text: string );17 procedure Emit(Text: string; NewLine: Boolean = True); 18 18 procedure GenerateUses(UsedModules: TUsedModuleList); 19 19 procedure GenerateModule(Module: TModule); … … 22 22 procedure GenerateProgram(ProgramBlock: TProgram); 23 23 procedure GenerateFunctions(Functions: TFunctionList); 24 procedure GenerateConstants(Constants: TConstantList); 24 25 procedure GenerateBeginEnd(BeginEnd: TBeginEnd); 25 26 procedure GenerateVariableList(Variables: TVariableList); … … 28 29 procedure GenerateIfThenElse(IfThenElse: TIfThenElse); 29 30 procedure GenerateAssignment(Assignment: TAssignment); 30 procedure Generate MethodCall(MethodCall: TFunctionCall);31 procedure GenerateFunctionCall(ConstantCall: TFunctionCall); 31 32 function GenerateExpression(Expression: TExpression): string; 32 33 public … … 55 56 end; 56 57 57 procedure TProducerPascal.Emit(Text: string); 58 begin 59 TextSource.Add(DupeString(' ', IndentationLength * Indetation) + Text); 58 procedure TProducerPascal.Emit(Text: string; NewLine: Boolean = True); 59 begin 60 if NewLine then TextSource.Add(DupeString(' ', IndentationLength * Indetation) + Text) 61 else TextSource.Strings[TextSource.Count - 1] := TextSource.Strings[TextSource.Count - 1] + Text; 60 62 end; 61 63 … … 68 70 for I := 0 to UsedModules.Count - 1 do begin 69 71 Line := Line + TUsedModule(UsedModules[I]).Name; 70 if I < UsedModules.Count then Line := Line + ', ';71 end; 72 Emit(Line );72 if I < UsedModules.Count - 1 then Line := Line + ', '; 73 end; 74 Emit(Line + ';'); 73 75 Emit(''); 74 76 end; … … 78 80 GenerateUses(Module.UsedModules); 79 81 GenerateCommonBlock(Module, ''); 82 Emit(';', False); 80 83 end; 81 84 … … 125 128 end; 126 129 130 procedure TProducerPascal.GenerateConstants(Constants: TConstantList); 131 var 132 I: Integer; 133 begin 134 Emit('const'); 135 Inc(Indetation); 136 for I := 0 to Constants.Count - 1 do 137 with TConstant(Constants[I]) do 138 Emit(Name + ': ' + ValueType.Name + ' = ' + Value + ';'); 139 Dec(Indetation); 140 Emit(''); 141 end; 142 127 143 procedure TProducerPascal.GenerateBeginEnd(BeginEnd: TBeginEnd); 128 144 var … … 132 148 Inc(Indetation); 133 149 // Commands 134 for I := 0 to BeginEnd.Commands.Count - 1 do 150 for I := 0 to BeginEnd.Commands.Count - 1 do begin 135 151 GenerateCommand(TCommand(BeginEnd.Commands[I])); 152 Emit(';', False); 153 end; 136 154 137 155 Dec(Indetation); 138 Emit('end ;');156 Emit('end'); 139 157 end; 140 158 … … 144 162 begin 145 163 Emit('var'); 164 Inc(Indetation); 146 165 for I := 0 to Variables.Count - 1 do 147 166 with TVariable(Variables[I]) do 148 167 Emit(Name + ': ' + ValueType.Name + ';'); 168 Dec(Indetation); 149 169 Emit(''); 150 170 end; … … 156 176 else if Command is TIfThenElse then GenerateIfThenElse(TIfThenElse(Command)) 157 177 else if Command is TAssignment then GenerateAssignment(TAssignment(Command)) 158 else if Command is TFunctionCall then Generate MethodCall(TFunctionCall(Command));178 else if Command is TFunctionCall then GenerateFunctionCall(TFunctionCall(Command)); 159 179 end; 160 180 … … 177 197 procedure TProducerPascal.GenerateAssignment(Assignment: TAssignment); 178 198 begin 179 Emit(Assignment.Target.Name + ' := ' + GenerateExpression(Assignment.Source) + ';'); 180 end; 181 182 procedure TProducerPascal.GenerateMethodCall(MethodCall: TFunctionCall); 183 begin 184 Emit(MethodCall.FunctionRef.Name + ';'); 199 Emit(Assignment.Target.Name + ' := ' + GenerateExpression(Assignment.Source)); 200 end; 201 202 procedure TProducerPascal.GenerateFunctionCall(ConstantCall: TFunctionCall); 203 var 204 Line: string; 205 I: Integer; 206 begin 207 with ConstantCall do begin 208 Line := FunctionRef.Name; 209 if ParameterExpression.Count > 0 then begin 210 Line := Line + '('; 211 for I := 0 to ParameterExpression.Count - 1 do begin 212 Line := Line + GenerateExpression(TExpression(ParameterExpression[I])); 213 if I < ParameterExpression.Count - 1 then Line := Line + ', '; 214 end; 215 Line := Line + ')'; 216 end; 217 end; 218 Emit(Line); 185 219 end; 186 220 … … 206 240 begin 207 241 with CommonBlock do begin 208 GenerateFunctions(Methods); 209 Emit('procedure ' + Name + ''); 242 GenerateFunctions(Functions); 243 GenerateConstants(Constants); 244 GenerateVariableList(Variables); 210 245 GenerateBeginEnd(Code); 211 246 end; -
branches/DelphiToC/UPascalCompiler.pas
r46 r48 85 85 UsedType := nil; 86 86 end; 87 with TFunction( Methods[Methods.Add(TFunction.Create)]) do begin87 with TFunction(Functions[Functions.Add(TFunction.Create)]) do begin 88 88 Name := 'Exit'; 89 89 ResultType := TType(TModule(Modules[0]).Types[0]); 90 90 end; 91 with TFunction( Methods[Methods.Add(TFunction.Create)]) do begin91 with TFunction(Functions[Functions.Add(TFunction.Create)]) do begin 92 92 Name := 'WriteLn'; 93 93 ResultType := TType(TModule(Modules[0]).Types[0]); 94 with TParameter(Parameters[Parameters.Add(TParameter.Create)]) do begin 95 Name := 'Text'; 96 ValueType := TType(TModule(Modules[0]).Types[1]); 97 end; 94 98 end; 95 99 end; -
branches/DelphiToC/UPascalSource.pas
r47 r48 57 57 end; 58 58 59 { TFunctionCall } 60 59 61 TFunctionCall = class(TCommand) 60 62 FunctionRef: TFunction; 63 ParameterExpression: TObjectList; // TObjectList<TExpression> 64 constructor Create; 65 destructor Destroy; override; 61 66 end; 62 67 … … 136 141 Types: TTypeList; 137 142 Variables: TVariableList; 138 Methods: TFunctionList;143 Functions: TFunctionList; 139 144 Code: TBeginEnd; 140 145 constructor Create; virtual; … … 349 354 Variables.Clear; 350 355 Constants.Clear; 351 Methods.Clear;356 Functions.Clear; 352 357 Code.Clear; 353 358 end; … … 386 391 Variables := TVariableList.Create; 387 392 Variables.Parent := Self; 388 Methods := TFunctionList.Create;389 Methods.Parent := Self;393 Functions := TFunctionList.Create; 394 Functions.Parent := Self; 390 395 Code := TBeginEnd.Create; 391 396 Code.Parent := Self; … … 398 403 Types.Destroy; 399 404 Variables.Destroy; 400 Methods.Destroy;405 Functions.Destroy; 401 406 Code.Destroy; 402 407 inherited; … … 416 421 I := 0; 417 422 while (I < Count) and (LowerCase(TType(Items[I]).Name) <> LowerCase(Name)) do Inc(I); 418 if I < Count then Result := TType(Items[I]) else begin 419 if Assigned(Parent.Parent) then Result := Parent.Parent.Types.Search(Name) 420 else begin 421 Result := nil; 422 end; 423 end; 423 if I < Count then Result := TType(Items[I]) else Result := nil; 424 425 if not Assigned(Result) and Assigned(Parent.Parent) then 426 Result := Parent.Parent.Types.Search(Name); 424 427 end; 425 428 … … 477 480 while (I < Count) and (LowerCase(TFunction(Items[I]).Name) <> LowerCase(Name)) do Inc(I); 478 481 if I < Count then Result := TFunction(Items[I]) else begin 479 if Assigned(Parent.Parent) then Result := Parent.Parent. Methods.Search(Name)482 if Assigned(Parent.Parent) then Result := Parent.Parent.Functions.Search(Name) 480 483 else begin 481 484 Result := nil; … … 624 627 end; 625 628 629 { TFunctionCall } 630 631 constructor TFunctionCall.Create; 632 begin 633 inherited; 634 ParameterExpression := TObjectList.Create; 635 end; 636 637 destructor TFunctionCall.Destroy; 638 begin 639 ParameterExpression.Free; 640 inherited Destroy; 641 end; 642 626 643 end. 627 644 -
branches/DelphiToC/Visual/USourceTree.pas
r47 r48 191 191 else NewNode := TreeView.Items.AddChild(Node, 'procedure ' + Name); 192 192 AddNodeParameterList(NewNode, Parameters); 193 AddNodeMethodList(NewNode, Methods);193 AddNodeMethodList(NewNode, Functions); 194 194 AddNodeConstantList(NewNode, Constants); 195 195 AddNodeVariableList(NewNode, Variables); … … 228 228 NewNode := TreeView.Items.AddChild(Node, TypeName + ' ' + Module.Name); 229 229 AddNodeUses(NewNode, Module.UsedModules); 230 AddNodeMethodList(NewNode, Module. Methods);230 AddNodeMethodList(NewNode, Module.Functions); 231 231 AddNodeConstantList(NewNode, Module.Constants); 232 232 AddNodeVariableList(NewNode, Module.Variables);
Note:
See TracChangeset
for help on using the changeset viewer.