Changeset 19 for trunk/Compiler/Produce/UProducerPascal.pas
- Timestamp:
- Nov 9, 2010, 11:19:28 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/Produce/UProducerPascal.pas
r18 r19 22 22 procedure GenerateType(AType: TType; AssignSymbol: Char = ':'); 23 23 procedure GenerateTypes(Types: TTypeList); 24 procedure GenerateCommonBlock(CommonBlock: TCommonBlock; 24 procedure GenerateCommonBlockInterface(CommonBlock: TCommonBlock; 25 LabelPrefix: string); 26 procedure GenerateCommonBlockImplementation(CommonBlock: TCommonBlock; 25 27 LabelPrefix: string); 26 28 procedure GenerateFunctions(Functions: TFunctionList); 29 procedure GenerateFunction(AFunction: TFunction); 30 procedure GenerateFunctionHead(AFunction: TFunction); 27 31 procedure GenerateConstants(Constants: TConstantList); 32 procedure GenerateConstant(Constant: TConstant); 28 33 procedure GenerateBeginEnd(BeginEnd: TBeginEnd); 29 34 procedure GenerateVariableList(Variables: TVariableList); 35 procedure GenerateVariable(Variable: TVariable); 30 36 procedure GenerateCommand(Command: TCommand); 31 37 procedure GenerateWhileDo(WhileDo: TWhileDo); … … 78 84 EmitLn(';'); 79 85 Dec(Indetation); 86 EmitLn; 80 87 end; 81 88 … … 87 94 Module.TargetFile := Module.Name + '.dpr'; 88 95 EmitLn('program ' + Name + ';'); 96 EmitLn; 89 97 GenerateUses(UsedModules); 90 GenerateCommonBlock (Body, '');98 GenerateCommonBlockImplementation(Body, ''); 91 99 EmitLn('.'); 92 100 end else … … 102 110 EmitLn('interface'); 103 111 EmitLn; 104 GenerateCommonBlock(TModuleUnit(Module).Body, '.'); 112 GenerateCommonBlockInterface(TModuleUnit(Module).Body, '.'); 113 EmitLn; 105 114 EmitLn('implementation'); 106 115 EmitLn; 107 EmitLn('end.'); 116 GenerateCommonBlockImplementation(TModuleUnit(Module).Body, '.'); 117 EmitLn('.'); 108 118 end; 109 119 … … 196 206 var 197 207 I: Integer; 208 begin 209 for I := 0 to Functions.Count - 1 do 210 GenerateFunction(TFunction(Functions[I])); 211 end; 212 213 procedure TProducerPascal.GenerateFunction(AFunction: TFunction); 214 var 215 I: Integer; 198 216 P: Integer; 199 217 Line: string; 200 218 begin 201 for I := 0 to Functions.Count - 1 do 202 with TFunction(Functions[I]) do 219 with AFunction do 203 220 if not Internal then 204 221 begin 222 GenerateFunctionHead(AFunction); 223 GenerateBeginEnd(Code); 224 EmitLn(';'); 225 EmitLn; 226 end; 227 end; 228 229 procedure TProducerPascal.GenerateFunctionHead(AFunction: TFunction); 230 var 231 Line: string; 232 P: Integer; 233 begin 234 with AFunction do begin 205 235 if FunctionType = ftFunction then 206 236 Line := 'function ' + Name … … 218 248 Line := Line + ': ' + ResultType.Name; 219 249 EmitLn(Line + ';'); 220 GenerateBeginEnd(Code);221 EmitLn(';');222 EmitLn;223 250 end; 224 251 end; … … 232 259 Inc(Indetation); 233 260 for I := 0 to Constants.Count - 1 do 234 with TConstant(Constants[I]) do 235 if not System then begin 236 //Emit(Name + ': '); 237 //if Assigned(ValueType) then Emit(ValueType.Name); 238 //Emit(' = ' + Value + ';'); 239 end; 261 GenerateConstant(Constants[I]); 240 262 Dec(Indetation); 241 263 Emit(''); 264 end; 265 end; 266 267 procedure TProducerPascal.GenerateConstant(Constant: TConstant); 268 begin 269 with Constant do begin 270 Emit(Name); 271 //if Assigned(ValueType) then Emit(': ' + ValueType.Name); 272 EmitLn(' = ' + Value + ';'); 242 273 end; 243 274 end; … … 266 297 Inc(Indetation); 267 298 for I := 0 to Variables.Count - 1 do 268 with TVariable(Variables[I]) do 299 GenerateVariable(TVariable(Variables[I])); 300 Dec(Indetation); 301 EmitLn; 302 end; 303 304 procedure TProducerPascal.GenerateVariable(Variable: TVariable); 305 begin 306 with Variable do 269 307 EmitLn(Name + ': ' + ValueType.Name + ';'); 270 Dec(Indetation);271 EmitLn;272 308 end; 273 309 … … 362 398 end; 363 399 364 procedure TProducerPascal.GenerateCommonBlock (CommonBlock: TCommonBlock; LabelPrefix: string);400 procedure TProducerPascal.GenerateCommonBlockInterface(CommonBlock: TCommonBlock; LabelPrefix: string); 365 401 var 366 402 I: Integer; 367 403 LabelName: string; 368 begin 404 Section: TCommonBlockSection; 405 begin 406 Inc(Indetation); 369 407 with CommonBlock do begin 370 GenerateTypes(Types); 371 GenerateFunctions(Functions); 372 GenerateConstants(Constants); 373 GenerateVariableList(Variables); 408 for I := 0 to Order.Count - 1 do begin 409 if (Order[I] is TType) and (TType(Order[I]).Exported) then begin 410 if Section <> cbsType then begin 411 EmitLn; 412 Dec(Indetation); 413 EmitLn('type'); 414 Inc(Indetation); 415 end; 416 Emit(TType(Order[I]).Name + ' = '); 417 GenerateType(TType(Order[I])); 418 EmitLn(';'); 419 Section := cbsType; 420 end else 421 if (Order[I] is TVariable) and (TVariable(Order[I]).Exported) then begin 422 if Section <> cbsVariable then begin 423 EmitLn; 424 Dec(Indetation); 425 EmitLn('var'); 426 Inc(Indetation); 427 end; 428 GenerateVariable(TVariable(Order[I])); 429 Section := cbsVariable; 430 end else 431 if (Order[I] is TConstant) and (TConstant(Order[I]).Exported) then begin 432 if Section <> cbsConstant then begin 433 EmitLn; 434 Dec(Indetation); 435 EmitLn('const'); 436 Inc(Indetation); 437 end; 438 GenerateConstant(TConstant(Order[I])); 439 Section := cbsConstant; 440 end else 441 if (Order[I] is TFunction) and (TFunction(Order[I]).Exported) then begin 442 GenerateFunctionHead(TFunction(Order[I])); 443 end; 444 end; 445 end; 446 Dec(Indetation); 447 end; 448 449 procedure TProducerPascal.GenerateCommonBlockImplementation( 450 CommonBlock: TCommonBlock; LabelPrefix: string); 451 var 452 I: Integer; 453 LabelName: string; 454 Section: TCommonBlockSection; 455 begin 456 with CommonBlock do begin 457 for I := 0 to Order.Count - 1 do begin 458 if (Order[I] is TType) and (not TType(Order[I]).Exported) then begin 459 if Section <> cbsType then begin 460 EmitLn; 461 EmitLn('type'); 462 end; 463 Emit(TType(Order[I]).Name + ' = '); 464 GenerateType(TType(Order[I])); 465 EmitLn(';'); 466 Section := cbsType; 467 end else 468 if (Order[I] is TVariable) and (not TVariable(Order[I]).Exported) then begin 469 if Section <> cbsVariable then begin 470 EmitLn; 471 EmitLn('var'); 472 end; 473 GenerateVariable(TVariable(Order[I])); 474 Section := cbsVariable; 475 end else 476 if (Order[I] is TConstant) and (not TConstant(Order[I]).Exported) then begin 477 if Section <> cbsConstant then begin 478 EmitLn; 479 EmitLn('const'); 480 end; 481 GenerateConstant(TConstant(Order[I])); 482 Section := cbsConstant; 483 end else 484 if Order[I] is TFunction then begin 485 GenerateFunction(TFunction(Order[I])); 486 end; 487 end; 374 488 GenerateBeginEnd(Code); 375 489 end;
Note:
See TracChangeset
for help on using the changeset viewer.