Changeset 33 for branches/Syntetizer/USyntetizer.pas
- Timestamp:
- Aug 4, 2010, 1:53:01 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Syntetizer/USyntetizer.pas
r27 r33 26 26 TCommand = class(TInterfacedObject, ISyntetizable) 27 27 procedure Syntetize(Syntetizer: TSyntetizer); virtual; 28 end;29 30 TProcedureParameter = class(TElement)31 Value: string;32 end;33 34 { TProcedureCall }35 36 TProcedureCall = class(TCommand)37 Name: string;38 Parameters: TList; // TList<TProcedureParameter>39 constructor Create;40 destructor Destroy; override;41 procedure Syntetize(Syntetizer: TSyntetizer); override;42 28 end; 43 29 … … 56 42 end; 57 43 58 { TVariableSection }59 60 44 TVariableSection = class(TInterfacedObject, ISyntetizable) 61 45 Variables: TList; // TList<TVariableDeclaration> … … 65 49 end; 66 50 51 TProcedure = class(TInterfacedObject, ISyntetizable) 52 Name: string; 53 Parameters: TList; 54 Code: TBeginEnd; 55 constructor Create; 56 destructor Destroy; override; 57 procedure Syntetize(Syntetizer: TSyntetizer); 58 end; 59 60 TProcedureList = class(TInterfacedObject, ISyntetizable) 61 Procedures: TList; // TList<TProcedure> 62 procedure Syntetize(Syntetizer: TSyntetizer); 63 constructor Create; 64 destructor Destroy; override; 65 end; 66 67 TProcedureParameter = class(TInterfacedObject) 68 Name: string; 69 VarType: string; 70 end; 71 72 TProcedureParameterValue = class(TInterfacedObject) 73 Value: string; 74 end; 75 76 TProcedureCall = class(TCommand) 77 Name: string; 78 Parameters: TList; // TList<TProcedureParameter> 79 constructor Create; 80 destructor Destroy; override; 81 procedure Syntetize(Syntetizer: TSyntetizer); override; 82 end; 83 67 84 TProgram = class(TInterfacedObject, ISyntetizable) 68 85 Name: string; 69 86 Code: TBeginend; 70 87 CompilerDirectives: TList; // TList<TCompilerDirective> 88 Procedures: TProcedureList; // TList<TProcedure> 71 89 Variables: TVariableSection; 72 90 procedure Syntetize(Syntetizer: TSyntetizer); … … 74 92 destructor Destroy; override; 75 93 end; 76 77 { TSyntetizer }78 94 79 95 TSyntetizer = class … … 126 142 begin 127 143 Syntetizer.AddLine('program ' + Name + ';'); 144 Syntetizer.AddLine(''); 128 145 for I := 0 to CompilerDirectives.Count - 1 do 129 146 TCompilerDirective(CompilerDirectives[I]).Syntetize(Syntetizer); 147 Syntetizer.AddLine(''); 148 Procedures.Syntetize(Syntetizer); 130 149 Variables.Syntetize(Syntetizer); 131 150 Code.Syntetize(Syntetizer); … … 137 156 CompilerDirectives := TList.Create; 138 157 Variables := TVariableSection.Create; 158 Procedures := TProcedureList.Create; 139 159 Code := TBeginEnd.Create; 140 160 Code.LastEnd := True; … … 145 165 I: Integer; 146 166 begin 167 Procedures.Destroy; 147 168 Variables.Destroy; 148 169 for I := 0 to CompilerDirectives.Count - 1 do … … 207 228 begin 208 229 for I := 0 to Parameters.Count - 1 do 209 ParameterString := ParameterString + TProcedureParameter (Parameters[I]).Value;230 ParameterString := ParameterString + TProcedureParameterValue(Parameters[I]).Value; 210 231 if Parameters.Count > 0 then 211 232 ParameterString := '(' + ParameterString + ')'; … … 264 285 end; 265 286 287 { TProcedure } 288 289 constructor TProcedure.Create; 290 begin 291 Parameters := TList.Create; 292 Code := TBeginEnd.Create; 293 end; 294 295 destructor TProcedure.Destroy; 296 var 297 I: Integer; 298 begin 299 Code.Destroy; 300 //for I := 0 to Parameters.Count - 1 do 301 // TParameter(Parameters[I]).Destroy; 302 Parameters.Destroy; 303 inherited Destroy; 304 end; 305 306 procedure TProcedure.Syntetize(Syntetizer: TSyntetizer); 307 var 308 I: Integer; 309 ParameterString: string; 310 begin 311 with Syntetizer do begin 312 for I := 0 to Parameters.Count - 1 do 313 with TProcedureParameter(Parameters[I]) do begin 314 ParameterString := ParameterString + Name + ': ' + VarType; 315 316 end; 317 if Parameters.Count > 0 then 318 ParameterString := '(' + ParameterString + ')'; 319 AddLine('procedure ' + Name + ParameterString + ';'); 320 Code.Syntetize(Syntetizer); 321 AddLine(''); 322 end; 323 end; 324 325 { TProcedureList } 326 327 procedure TProcedureList.Syntetize(Syntetizer: TSyntetizer); 328 var 329 I: Integer; 330 begin 331 for I := 0 to Procedures.Count - 1 do 332 TProcedure(Procedures[I]).Syntetize(Syntetizer); 333 end; 334 335 constructor TProcedureList.Create; 336 begin 337 Procedures := TList.Create; 338 end; 339 340 destructor TProcedureList.Destroy; 341 var 342 I: Integer; 343 begin 344 for I := 0 to Procedures.Count - 1 do 345 TProcedure(Procedures[I]).Destroy; 346 Procedures.Destroy; 347 inherited Destroy; 348 end; 349 266 350 end. 267 351
Note:
See TracChangeset
for help on using the changeset viewer.