Changeset 148 for branches/easy compiler/USourceCode.pas
- Timestamp:
- Jan 17, 2018, 5:27:23 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/easy compiler/USourceCode.pas
r147 r148 28 28 end; 29 29 30 TSourceValues = class(TObjectList) 31 end; 32 30 33 TSourceValueClass = class of TSourceValue; 31 34 … … 34 37 TSourceType = class 35 38 Name: string; 36 ValueClass: TSourceValueClass; 37 end; 39 function GetValueType: TSourceValueClass; virtual; 40 end; 41 42 TSourceTypeClass = class of TSourceType; 38 43 39 44 { TSourceTypes } … … 41 46 TSourceTypes = class(TObjectList) 42 47 Parent: TSourceTypes; 43 function AddNew(Name: string; ClassType: TSource ValueClass): TSourceType;48 function AddNew(Name: string; ClassType: TSourceTypeClass): TSourceType; 44 49 function Search(Name: string): TSourceType; 45 50 end; 51 52 { TSourceTypeInteger } 53 54 TSourceTypeInteger = class(TSourceType) 55 function GetValueType: TSourceValueClass; override; 56 end; 57 58 { TSourceTypeString } 59 60 TSourceTypeString = class(TSourceType) 61 function GetValueType: TSourceValueClass; override; 62 end; 63 64 { TSourceTypeArray } 65 66 TSourceTypeArray = class(TSourceType) 67 ItemType: TSourceType; 68 function GetValueType: TSourceValueClass; override; 69 end; 70 46 71 47 72 { TSourceVariable } … … 64 89 end; 65 90 91 TSourceReferenceArray = class(TSourceReference) 92 ArrayRef: TSourceVariable; 93 Index: TSourceReference; 94 end; 95 66 96 { TSourceValueString } 67 97 … … 76 106 Value: Integer; 77 107 procedure Assign(Source: TSourceValue); override; 108 end; 109 110 { TSourceValueArray } 111 112 TSourceValueArray = class(TSourceValue) 113 Items: TSourceValues; 114 procedure Assign(Source: TSourceValue); override; 115 constructor Create; 116 destructor Destroy; override; 78 117 end; 79 118 … … 146 185 end; 147 186 148 { TCommandIfZero } 149 150 TCommandIfZero = class(TSourceCommand) 151 Variable: TSourceReferenceVariable; 187 { TCommandIfEqual } 188 189 TCommandIfEqual = class(TSourceCommand) 190 Reference1: TSourceReference; 191 Reference2: TSourceReference; 152 192 destructor Destroy; override; 153 193 end; … … 184 224 implementation 185 225 186 { TCommandIfZero } 187 188 destructor TCommandIfZero.Destroy; 189 begin 190 Variable.Free; 226 { TSourceType } 227 228 function TSourceType.GetValueType: TSourceValueClass; 229 begin 230 Result := nil; 231 end; 232 233 { TSourceTypeInteger } 234 235 function TSourceTypeInteger.GetValueType: TSourceValueClass; 236 begin 237 Result := TSourceValueInteger; 238 end; 239 240 { TSourceTypeString } 241 242 function TSourceTypeString.GetValueType: TSourceValueClass; 243 begin 244 Result := TSourceValueString; 245 end; 246 247 { TSourceTypeArray } 248 249 function TSourceTypeArray.GetValueType: TSourceValueClass; 250 begin 251 Result := TSourceValueArray; 252 end; 253 254 { TSourceValueArray } 255 256 procedure TSourceValueArray.Assign(Source: TSourceValue); 257 var 258 I: Integer; 259 Value: TSourceValue; 260 begin 261 if Source is TSourceValueInteger then begin 262 while Items.Count < TSourceValueArray(Source).Items.Count do begin 263 Value := TSourceValue(TSourceValue(TSourceValueArray(Source).Items[Items.Count]).ClassType.Create); 264 Items.Add(Value); 265 end; 266 while Items.Count > TSourceValueArray(Source).Items.Count do begin 267 Items.Delete(Items.Count - 1); 268 end; 269 for I := 0 to Items.Count - 1 do 270 TSourceValue(Items[I]).Assign(TSourceValue(TSourceValueArray(Source).Items[I])); 271 end else raise Exception.Create('Type for assignment not matches'); 272 end; 273 274 constructor TSourceValueArray.Create; 275 begin 276 Items := TSourceValues.Create; 277 end; 278 279 destructor TSourceValueArray.Destroy; 280 begin 281 Items.Free; 282 inherited Destroy; 283 end; 284 285 { TCommandIfEqual } 286 287 destructor TCommandIfEqual.Destroy; 288 begin 289 Reference1.Free; 290 Reference2.Free; 191 291 inherited Destroy; 192 292 end; … … 236 336 { TSourceTypes } 237 337 238 function TSourceTypes.AddNew(Name: string; ClassType: TSource ValueClass): TSourceType;239 begin 240 Result := TSourceType.Create;338 function TSourceTypes.AddNew(Name: string; ClassType: TSourceTypeClass): TSourceType; 339 begin 340 Result := ClassType.Create; 241 341 Result.Name := Name; 242 Result.ValueClass := ClassType;243 342 Add(Result); 244 343 end; … … 395 494 var 396 495 Funct: TSourceFunction; 496 Typ: TSourceType; 397 497 begin 398 498 Functions.Clear; 399 499 400 500 // Init types 401 Types.AddNew('Integer', TSourceValueInteger); 402 Types.AddNew('String', TSourceValueString); 501 Types.AddNew('Integer', TSourceTypeInteger); 502 Types.AddNew('String', TSourceTypeString); 503 Typ := Types.AddNew('StringArray', TSourceTypeArray); 504 TSourceTypeArray(Typ).ItemType := TSourceTypeString.Create; 505 Typ := Types.AddNew('IntegerArray', TSourceTypeArray); 506 TSourceTypeArray(Typ).ItemType := TSourceTypeInteger.Create; 403 507 404 508 // Init functions
Note:
See TracChangeset
for help on using the changeset viewer.