| 1 | unit Source;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, Generics.Collections, SourceNode;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | TExpressions = class;
|
|---|
| 10 | TFunctions = class;
|
|---|
| 11 | TBeginEnd = class;
|
|---|
| 12 | TBlock = class;
|
|---|
| 13 |
|
|---|
| 14 | { TValue }
|
|---|
| 15 |
|
|---|
| 16 | TValue = class
|
|---|
| 17 | function Clone: TValue; virtual;
|
|---|
| 18 | end;
|
|---|
| 19 |
|
|---|
| 20 | { TValueString }
|
|---|
| 21 |
|
|---|
| 22 | TValueString = class(TValue)
|
|---|
| 23 | Value: string;
|
|---|
| 24 | function Clone: TValue; override;
|
|---|
| 25 | end;
|
|---|
| 26 |
|
|---|
| 27 | { TValueInteger }
|
|---|
| 28 |
|
|---|
| 29 | TValueInteger = class(TValue)
|
|---|
| 30 | Value: Integer;
|
|---|
| 31 | function Clone: TValue; override;
|
|---|
| 32 | end;
|
|---|
| 33 |
|
|---|
| 34 | { TValueBoolean }
|
|---|
| 35 |
|
|---|
| 36 | TValueBoolean = class(TValue)
|
|---|
| 37 | Value: Boolean;
|
|---|
| 38 | function Clone: TValue; override;
|
|---|
| 39 | end;
|
|---|
| 40 |
|
|---|
| 41 | TValueClass = class of TValue;
|
|---|
| 42 |
|
|---|
| 43 | { TType }
|
|---|
| 44 |
|
|---|
| 45 | TType = class(TSourceNode)
|
|---|
| 46 | protected
|
|---|
| 47 | function GetFieldsCount: Integer; override;
|
|---|
| 48 | public
|
|---|
| 49 | Name: string;
|
|---|
| 50 | Functions: TFunctions;
|
|---|
| 51 | ValueClass: TValueClass;
|
|---|
| 52 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 53 | function GetField(Index: Integer): TField; override;
|
|---|
| 54 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 55 | constructor Create;
|
|---|
| 56 | destructor Destroy; override;
|
|---|
| 57 | end;
|
|---|
| 58 |
|
|---|
| 59 | { TTypes }
|
|---|
| 60 |
|
|---|
| 61 | TTypes = class(TSourceNodeList<TType>)
|
|---|
| 62 | function SearchByName(Name: string): TType;
|
|---|
| 63 | function AddNew(Name: string): TType;
|
|---|
| 64 | end;
|
|---|
| 65 |
|
|---|
| 66 | { TVariable }
|
|---|
| 67 |
|
|---|
| 68 | TVariable = class(TSourceNode)
|
|---|
| 69 | protected
|
|---|
| 70 | function GetFieldsCount: Integer; override;
|
|---|
| 71 | public
|
|---|
| 72 | Name: string;
|
|---|
| 73 | TypeRef: TType;
|
|---|
| 74 | Internal: Boolean;
|
|---|
| 75 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 76 | function GetField(Index: Integer): TField; override;
|
|---|
| 77 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 78 | end;
|
|---|
| 79 |
|
|---|
| 80 | { TVariables }
|
|---|
| 81 |
|
|---|
| 82 | TVariables = class(TSourceNodeList<TVariable>)
|
|---|
| 83 | function SearchByName(Name: string): TVariable;
|
|---|
| 84 | end;
|
|---|
| 85 |
|
|---|
| 86 | { TConstant }
|
|---|
| 87 |
|
|---|
| 88 | TConstant = class(TSourceNode)
|
|---|
| 89 | protected
|
|---|
| 90 | function GetFieldsCount: Integer; override;
|
|---|
| 91 | public
|
|---|
| 92 | Name: string;
|
|---|
| 93 | TypeRef: TType;
|
|---|
| 94 | Value: TValue;
|
|---|
| 95 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 96 | function GetField(Index: Integer): TField; override;
|
|---|
| 97 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 98 | destructor Destroy; override;
|
|---|
| 99 | end;
|
|---|
| 100 |
|
|---|
| 101 | { TConstants }
|
|---|
| 102 |
|
|---|
| 103 | TConstants = class(TSourceNodeList<TConstant>)
|
|---|
| 104 | function SearchByName(Name: string): TConstant;
|
|---|
| 105 | function AddNew(Name: string): TConstant;
|
|---|
| 106 | end;
|
|---|
| 107 |
|
|---|
| 108 | TFunctionParamKind = (pkNormal, pkVar, pkConst);
|
|---|
| 109 |
|
|---|
| 110 | TFunctionParameter = class(TSourceNode)
|
|---|
| 111 | Name: string;
|
|---|
| 112 | TypeRef: TType;
|
|---|
| 113 | Kind: TFunctionParamKind;
|
|---|
| 114 | end;
|
|---|
| 115 |
|
|---|
| 116 | { TFunctionParameters }
|
|---|
| 117 |
|
|---|
| 118 | TFunctionParameters = class(TSourceNodeList<TFunctionParameter>)
|
|---|
| 119 | function SearchByName(Name: string): TFunctionParameter;
|
|---|
| 120 | function AddNew(Name: string; TypeRef: TType): TFunctionParameter;
|
|---|
| 121 | end;
|
|---|
| 122 |
|
|---|
| 123 | { TFunction }
|
|---|
| 124 |
|
|---|
| 125 | TFunction = class(TSourceNode)
|
|---|
| 126 | protected
|
|---|
| 127 | function GetFieldsCount: Integer; override;
|
|---|
| 128 | public
|
|---|
| 129 | Name: string;
|
|---|
| 130 | InternalName: string;
|
|---|
| 131 | Params: TFunctionParameters;
|
|---|
| 132 | ResultType: TType;
|
|---|
| 133 | Block: TBlock;
|
|---|
| 134 | ParentType: TType;
|
|---|
| 135 | procedure InitVariables;
|
|---|
| 136 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 137 | function GetField(Index: Integer): TField; override;
|
|---|
| 138 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 139 | constructor Create;
|
|---|
| 140 | destructor Destroy; override;
|
|---|
| 141 | end;
|
|---|
| 142 |
|
|---|
| 143 | { TFunctions }
|
|---|
| 144 |
|
|---|
| 145 | TFunctions = class(TSourceNodeList<TFunction>)
|
|---|
| 146 | ParentType: TType;
|
|---|
| 147 | function SearchByName(Name: string): TFunction;
|
|---|
| 148 | function AddNew(Name: string): TFunction;
|
|---|
| 149 | end;
|
|---|
| 150 |
|
|---|
| 151 | { TProcedure }
|
|---|
| 152 |
|
|---|
| 153 | TProcedure = class(TSourceNode)
|
|---|
| 154 | protected
|
|---|
| 155 | function GetFieldsCount: Integer; override;
|
|---|
| 156 | public
|
|---|
| 157 | Name: string;
|
|---|
| 158 | InternalName: string;
|
|---|
| 159 | Params: TFunctionParameters;
|
|---|
| 160 | Block: TBlock;
|
|---|
| 161 | ParentType: TType;
|
|---|
| 162 | procedure InitVariables;
|
|---|
| 163 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 164 | function GetField(Index: Integer): TField; override;
|
|---|
| 165 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 166 | constructor Create;
|
|---|
| 167 | destructor Destroy; override;
|
|---|
| 168 | end;
|
|---|
| 169 |
|
|---|
| 170 | { TProcedures }
|
|---|
| 171 |
|
|---|
| 172 | TProcedures = class(TSourceNodeList<TProcedure>)
|
|---|
| 173 | ParentType: TType;
|
|---|
| 174 | function SearchByName(Name: string): TProcedure;
|
|---|
| 175 | function AddNew(Name: string): TProcedure;
|
|---|
| 176 | end;
|
|---|
| 177 |
|
|---|
| 178 | TCommand = class(TSourceNode)
|
|---|
| 179 | end;
|
|---|
| 180 |
|
|---|
| 181 | TCommands = class(TSourceNodeList<TCommand>)
|
|---|
| 182 | end;
|
|---|
| 183 |
|
|---|
| 184 | TEmptyCommand = class(TCommand)
|
|---|
| 185 | end;
|
|---|
| 186 |
|
|---|
| 187 | { TFunctionCall }
|
|---|
| 188 |
|
|---|
| 189 | TFunctionCall = class(TCommand)
|
|---|
| 190 | protected
|
|---|
| 191 | function GetFieldsCount: Integer; override;
|
|---|
| 192 | public
|
|---|
| 193 | FunctionDef: TFunction;
|
|---|
| 194 | Params: TExpressions;
|
|---|
| 195 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 196 | function GetField(Index: Integer): TField; override;
|
|---|
| 197 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 198 | constructor Create;
|
|---|
| 199 | destructor Destroy; override;
|
|---|
| 200 | end;
|
|---|
| 201 |
|
|---|
| 202 | { TProcedureCall }
|
|---|
| 203 |
|
|---|
| 204 | TProcedureCall = class(TCommand)
|
|---|
| 205 | protected
|
|---|
| 206 | function GetFieldsCount: Integer; override;
|
|---|
| 207 | public
|
|---|
| 208 | ProcedureDef: TProcedure;
|
|---|
| 209 | Params: TExpressions;
|
|---|
| 210 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 211 | function GetField(Index: Integer): TField; override;
|
|---|
| 212 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 213 | constructor Create;
|
|---|
| 214 | destructor Destroy; override;
|
|---|
| 215 | end;
|
|---|
| 216 |
|
|---|
| 217 | { TBeginEnd }
|
|---|
| 218 |
|
|---|
| 219 | TBeginEnd = class(TCommand)
|
|---|
| 220 | protected
|
|---|
| 221 | function GetFieldsCount: Integer; override;
|
|---|
| 222 | public
|
|---|
| 223 | Commands: TCommands;
|
|---|
| 224 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 225 | function GetField(Index: Integer): TField; override;
|
|---|
| 226 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 227 | procedure Clear;
|
|---|
| 228 | constructor Create;
|
|---|
| 229 | destructor Destroy; override;
|
|---|
| 230 | end;
|
|---|
| 231 |
|
|---|
| 232 | TExpressionOperator = (eoNone, eoAdd, eoSub, eoMultiply, eoDivide, eoIntDivide,
|
|---|
| 233 | eoModulo, eoAnd, eoXor, eoOr, eoShl, eoShr, eoEqual, eoNotEqual, eoLesser,
|
|---|
| 234 | eoHigher, eoLesserOrEqual, eoHigherOrEqual, eoNot);
|
|---|
| 235 |
|
|---|
| 236 | { TExpression }
|
|---|
| 237 |
|
|---|
| 238 | TExpression = class(TSourceNode)
|
|---|
| 239 | function GetType: TType; virtual;
|
|---|
| 240 | end;
|
|---|
| 241 |
|
|---|
| 242 | { TExpressionOperation }
|
|---|
| 243 |
|
|---|
| 244 | TExpressionOperation = class(TExpression)
|
|---|
| 245 | protected
|
|---|
| 246 | function GetFieldsCount: Integer; override;
|
|---|
| 247 | public
|
|---|
| 248 | TypeRef: TType;
|
|---|
| 249 | FunctionRef: TFunction;
|
|---|
| 250 | Operation: TExpressionOperator;
|
|---|
| 251 | Items: TExpressions;
|
|---|
| 252 | function GetFunctionName: string;
|
|---|
| 253 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 254 | function GetField(Index: Integer): TField; override;
|
|---|
| 255 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 256 | constructor Create;
|
|---|
| 257 | destructor Destroy; override;
|
|---|
| 258 | function GetType: TType; override;
|
|---|
| 259 | end;
|
|---|
| 260 |
|
|---|
| 261 | TExpressionOperandType = (otVariableRef, otConstantRef, otConstantDirect,
|
|---|
| 262 | otFunctionCall);
|
|---|
| 263 |
|
|---|
| 264 | { TExpressionOperand }
|
|---|
| 265 |
|
|---|
| 266 | TExpressionOperand = class(TExpression)
|
|---|
| 267 | protected
|
|---|
| 268 | function GetFieldsCount: Integer; override;
|
|---|
| 269 | public
|
|---|
| 270 | OperandType: TExpressionOperandType;
|
|---|
| 271 | VariableRef: TVariable;
|
|---|
| 272 | ConstantRef: TConstant;
|
|---|
| 273 | ConstantDirect: TConstant;
|
|---|
| 274 | FunctionCall: TFunctionCall;
|
|---|
| 275 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 276 | function GetField(Index: Integer): TField; override;
|
|---|
| 277 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 278 | function GetType: TType; override;
|
|---|
| 279 | constructor Create;
|
|---|
| 280 | destructor Destroy; override;
|
|---|
| 281 | end;
|
|---|
| 282 |
|
|---|
| 283 | { TExpressionBrackets }
|
|---|
| 284 |
|
|---|
| 285 | TExpressionBrackets = class(TExpression)
|
|---|
| 286 | Expression: TExpression;
|
|---|
| 287 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 288 | function GetField(Index: Integer): TField; override;
|
|---|
| 289 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 290 | function GetType: TType; override;
|
|---|
| 291 | destructor Destroy; override;
|
|---|
| 292 | end;
|
|---|
| 293 |
|
|---|
| 294 | TExpressions = class(TSourceNodeList<TExpression>)
|
|---|
| 295 | end;
|
|---|
| 296 |
|
|---|
| 297 | { TAssignment }
|
|---|
| 298 |
|
|---|
| 299 | TAssignment = class(TCommand)
|
|---|
| 300 | protected
|
|---|
| 301 | function GetFieldsCount: Integer; override;
|
|---|
| 302 | public
|
|---|
| 303 | Variable: TVariable;
|
|---|
| 304 | Expression: TExpression;
|
|---|
| 305 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 306 | function GetField(Index: Integer): TField; override;
|
|---|
| 307 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 308 | constructor Create;
|
|---|
| 309 | destructor Destroy; override;
|
|---|
| 310 | end;
|
|---|
| 311 |
|
|---|
| 312 | { TReturn }
|
|---|
| 313 |
|
|---|
| 314 | TReturn = class(TCommand)
|
|---|
| 315 | protected
|
|---|
| 316 | function GetFieldsCount: Integer; override;
|
|---|
| 317 | public
|
|---|
| 318 | Expression: TExpression;
|
|---|
| 319 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 320 | function GetField(Index: Integer): TField; override;
|
|---|
| 321 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 322 | constructor Create;
|
|---|
| 323 | destructor Destroy; override;
|
|---|
| 324 | end;
|
|---|
| 325 |
|
|---|
| 326 | { TIfThenElse }
|
|---|
| 327 |
|
|---|
| 328 | TIfThenElse = class(TCommand)
|
|---|
| 329 | protected
|
|---|
| 330 | function GetFieldsCount: Integer; override;
|
|---|
| 331 | public
|
|---|
| 332 | Expression: TExpression;
|
|---|
| 333 | CommandThen: TCommand;
|
|---|
| 334 | CommandElse: TCommand;
|
|---|
| 335 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 336 | function GetField(Index: Integer): TField; override;
|
|---|
| 337 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 338 | constructor Create;
|
|---|
| 339 | destructor Destroy; override;
|
|---|
| 340 | end;
|
|---|
| 341 |
|
|---|
| 342 | TLoop = class(TCommand)
|
|---|
| 343 | DoBreak: Boolean;
|
|---|
| 344 | DoContinue: Boolean;
|
|---|
| 345 | end;
|
|---|
| 346 |
|
|---|
| 347 | { TWhileDo }
|
|---|
| 348 |
|
|---|
| 349 | TWhileDo = class(TLoop)
|
|---|
| 350 | protected
|
|---|
| 351 | function GetFieldsCount: Integer; override;
|
|---|
| 352 | public
|
|---|
| 353 | Expression: TExpression;
|
|---|
| 354 | Command: TCommand;
|
|---|
| 355 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 356 | function GetField(Index: Integer): TField; override;
|
|---|
| 357 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 358 | constructor Create;
|
|---|
| 359 | destructor Destroy; override;
|
|---|
| 360 | end;
|
|---|
| 361 |
|
|---|
| 362 | { TRepeatUntil }
|
|---|
| 363 |
|
|---|
| 364 | TRepeatUntil = class(TLoop)
|
|---|
| 365 | protected
|
|---|
| 366 | function GetFieldsCount: Integer; override;
|
|---|
| 367 | public
|
|---|
| 368 | Expression: TExpression;
|
|---|
| 369 | Commands: TCommands;
|
|---|
| 370 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 371 | function GetField(Index: Integer): TField; override;
|
|---|
| 372 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 373 | constructor Create;
|
|---|
| 374 | destructor Destroy; override;
|
|---|
| 375 | end;
|
|---|
| 376 |
|
|---|
| 377 | TBreak = class(TCommand)
|
|---|
| 378 | end;
|
|---|
| 379 |
|
|---|
| 380 | TContinue = class(TCommand)
|
|---|
| 381 | end;
|
|---|
| 382 |
|
|---|
| 383 | { TForToDo }
|
|---|
| 384 |
|
|---|
| 385 | TForToDo = class(TLoop)
|
|---|
| 386 | protected
|
|---|
| 387 | function GetFieldsCount: Integer; override;
|
|---|
| 388 | public
|
|---|
| 389 | VariableRef: TVariable;
|
|---|
| 390 | ExpressionFrom: TExpression;
|
|---|
| 391 | ExpressionTo: TExpression;
|
|---|
| 392 | Command: TCommand;
|
|---|
| 393 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 394 | function GetField(Index: Integer): TField; override;
|
|---|
| 395 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 396 | constructor Create;
|
|---|
| 397 | destructor Destroy; override;
|
|---|
| 398 | end;
|
|---|
| 399 |
|
|---|
| 400 | { TBlock }
|
|---|
| 401 |
|
|---|
| 402 | TBlock = class(TSourceNode)
|
|---|
| 403 | protected
|
|---|
| 404 | function GetFieldsCount: Integer; override;
|
|---|
| 405 | public
|
|---|
| 406 | ParentBlock: TBlock;
|
|---|
| 407 | Variables: TVariables;
|
|---|
| 408 | Constants: TConstants;
|
|---|
| 409 | Functions: TFunctions;
|
|---|
| 410 | Procedures: TProcedures;
|
|---|
| 411 | Types: TTypes;
|
|---|
| 412 | BeginEnd: TBeginEnd;
|
|---|
| 413 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 414 | function GetField(Index: Integer): TField; override;
|
|---|
| 415 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 416 | procedure Clear;
|
|---|
| 417 | function GetType(Name: string): TType;
|
|---|
| 418 | function GetConstant(Name: string): TConstant;
|
|---|
| 419 | function GetVariable(Name: string): TVariable;
|
|---|
| 420 | function GetFunction(Name: string): TFunction;
|
|---|
| 421 | function GetProcedure(Name: string): TProcedure;
|
|---|
| 422 | constructor Create;
|
|---|
| 423 | destructor Destroy; override;
|
|---|
| 424 | end;
|
|---|
| 425 |
|
|---|
| 426 | { TProgram }
|
|---|
| 427 |
|
|---|
| 428 | TProgram = class(TSourceNode)
|
|---|
| 429 | protected
|
|---|
| 430 | function GetFieldsCount: Integer; override;
|
|---|
| 431 | public
|
|---|
| 432 | Name: string;
|
|---|
| 433 | SystemBlock: TBlock;
|
|---|
| 434 | Block: TBlock;
|
|---|
| 435 | procedure GetValue(Index: Integer; out Value); override;
|
|---|
| 436 | function GetField(Index: Integer): TField; override;
|
|---|
| 437 | procedure SetValue(Index: Integer; var Value); override;
|
|---|
| 438 | procedure Clear;
|
|---|
| 439 | constructor Create;
|
|---|
| 440 | destructor Destroy; override;
|
|---|
| 441 | end;
|
|---|
| 442 |
|
|---|
| 443 | const
|
|---|
| 444 | ExpressionOperatorText: array[TExpressionOperator] of string = ('', '+',
|
|---|
| 445 | '-', '*', '/', 'div', 'mod', 'and', 'xor', 'or', 'shl',
|
|---|
| 446 | 'shr', '=', '<>', '<', '>', '<=','>=', 'not');
|
|---|
| 447 | ExpressionOperatorFuncText: array[TExpressionOperator] of string = ('', '_Add',
|
|---|
| 448 | '_Sub', '_Mul', '_Div', '_IntDiv', '_Mod', '_And', '_Xor', '_Or', '_Shl',
|
|---|
| 449 | '_Shr', '_Equal', '_NotEqual', '_Lesser', '_Higher', '_LesserOrEqual',
|
|---|
| 450 | '_HigherOrEqual', '_Not');
|
|---|
| 451 |
|
|---|
| 452 | function GetOperatorByName(Name: string): TExpressionOperator;
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 | implementation
|
|---|
| 456 |
|
|---|
| 457 | resourcestring
|
|---|
| 458 | SIndexError = 'Index error';
|
|---|
| 459 |
|
|---|
| 460 | function GetOperatorByName(Name: string): TExpressionOperator;
|
|---|
| 461 | var
|
|---|
| 462 | I: TExpressionOperator;
|
|---|
| 463 | begin
|
|---|
| 464 | Result := eoNone;
|
|---|
| 465 | for I := Succ(Low(TExpressionOperator)) to High(TExpressionOperator) do begin
|
|---|
| 466 | if ExpressionOperatorText[I] = Name then begin
|
|---|
| 467 | Result := I;
|
|---|
| 468 | Break;
|
|---|
| 469 | end;
|
|---|
| 470 | end;
|
|---|
| 471 | end;
|
|---|
| 472 |
|
|---|
| 473 | { TProcedureCall }
|
|---|
| 474 |
|
|---|
| 475 | function TProcedureCall.GetFieldsCount: Integer;
|
|---|
| 476 | begin
|
|---|
| 477 | Result := 2;
|
|---|
| 478 | end;
|
|---|
| 479 |
|
|---|
| 480 | procedure TProcedureCall.GetValue(Index: Integer; out Value);
|
|---|
| 481 | begin
|
|---|
| 482 | if Index = 0 then TProcedure(Value) := ProcedureDef
|
|---|
| 483 | else if Index = 1 then TExpressions(Value) := Params
|
|---|
| 484 | else inherited;
|
|---|
| 485 | end;
|
|---|
| 486 |
|
|---|
| 487 | function TProcedureCall.GetField(Index: Integer): TField;
|
|---|
| 488 | begin
|
|---|
| 489 | if Index = 0 then Result := TField.Create(dtObject, 'Procedure')
|
|---|
| 490 | else if Index = 1 then Result := TField.Create(dtObject, 'Parameters')
|
|---|
| 491 | else inherited;
|
|---|
| 492 | end;
|
|---|
| 493 |
|
|---|
| 494 | procedure TProcedureCall.SetValue(Index: Integer; var Value);
|
|---|
| 495 | begin
|
|---|
| 496 | if Index = 0 then ProcedureDef := TProcedure(Value)
|
|---|
| 497 | else if Index = 1 then Params := TExpressions(Value)
|
|---|
| 498 | else inherited;
|
|---|
| 499 | end;
|
|---|
| 500 |
|
|---|
| 501 | constructor TProcedureCall.Create;
|
|---|
| 502 | begin
|
|---|
| 503 | Params := TExpressions.Create;
|
|---|
| 504 | end;
|
|---|
| 505 |
|
|---|
| 506 | destructor TProcedureCall.Destroy;
|
|---|
| 507 | begin
|
|---|
| 508 | FreeAndNil(Params);
|
|---|
| 509 | inherited;
|
|---|
| 510 | end;
|
|---|
| 511 |
|
|---|
| 512 | { TProcedure }
|
|---|
| 513 |
|
|---|
| 514 | function TProcedures.SearchByName(Name: string): TProcedure;
|
|---|
| 515 | var
|
|---|
| 516 | I: Integer;
|
|---|
| 517 | begin
|
|---|
| 518 | I := 0;
|
|---|
| 519 | while (I < Count) and (TProcedure(Items[I]).Name <> Name) do Inc(I);
|
|---|
| 520 | if I < Count then Result := TProcedure(Items[I])
|
|---|
| 521 | else Result := nil;
|
|---|
| 522 | end;
|
|---|
| 523 |
|
|---|
| 524 | function TProcedures.AddNew(Name: string): TProcedure;
|
|---|
| 525 | begin
|
|---|
| 526 | Result := TProcedure.Create;
|
|---|
| 527 | Result.Name := Name;
|
|---|
| 528 | Result.ParentType := ParentType;
|
|---|
| 529 | Add(Result);
|
|---|
| 530 | end;
|
|---|
| 531 |
|
|---|
| 532 | function TProcedure.GetFieldsCount: Integer;
|
|---|
| 533 | begin
|
|---|
| 534 | Result := 3;
|
|---|
| 535 | end;
|
|---|
| 536 |
|
|---|
| 537 | procedure TProcedure.InitVariables;
|
|---|
| 538 | var
|
|---|
| 539 | I: Integer;
|
|---|
| 540 | Variable: TVariable;
|
|---|
| 541 | begin
|
|---|
| 542 | for I := 0 to Params.Count - 1 do begin
|
|---|
| 543 | Variable := TVariable.Create;
|
|---|
| 544 | Variable.Name := Params[I].Name;
|
|---|
| 545 | Variable.TypeRef := Params[I].TypeRef;
|
|---|
| 546 | Variable.Internal := True;
|
|---|
| 547 | Block.Variables.Add(Variable);
|
|---|
| 548 | end;
|
|---|
| 549 | end;
|
|---|
| 550 |
|
|---|
| 551 | procedure TProcedure.GetValue(Index: Integer; out Value);
|
|---|
| 552 | begin
|
|---|
| 553 | if Index = 0 then TBlock(Value) := Block
|
|---|
| 554 | else if Index = 1 then TFunctionParameters(Value) := Params
|
|---|
| 555 | else if Index = 2 then string(Value) := Name
|
|---|
| 556 | else inherited;
|
|---|
| 557 | end;
|
|---|
| 558 |
|
|---|
| 559 | function TProcedure.GetField(Index: Integer): TField;
|
|---|
| 560 | begin
|
|---|
| 561 | if Index = 0 then Result := TField.Create(dtObject, 'Block')
|
|---|
| 562 | else if Index = 1 then Result := TField.Create(dtList, 'Parameters')
|
|---|
| 563 | else if Index = 2 then Result := TField.Create(dtString, 'Name')
|
|---|
| 564 | else inherited;
|
|---|
| 565 | end;
|
|---|
| 566 |
|
|---|
| 567 | procedure TProcedure.SetValue(Index: Integer; var Value);
|
|---|
| 568 | begin
|
|---|
| 569 | if Index = 0 then Block := TBlock(Value)
|
|---|
| 570 | else if Index = 1 then Params := TFunctionParameters(Value)
|
|---|
| 571 | else if Index = 2 then Name := string(Value)
|
|---|
| 572 | else inherited;
|
|---|
| 573 | end;
|
|---|
| 574 |
|
|---|
| 575 | constructor TProcedure.Create;
|
|---|
| 576 | begin
|
|---|
| 577 | Params := TFunctionParameters.Create;
|
|---|
| 578 | Block := TBlock.Create;
|
|---|
| 579 | end;
|
|---|
| 580 |
|
|---|
| 581 | destructor TProcedure.Destroy;
|
|---|
| 582 | begin
|
|---|
| 583 | FreeAndNil(Block);
|
|---|
| 584 | FreeAndNil(Params);
|
|---|
| 585 | inherited;
|
|---|
| 586 | end;
|
|---|
| 587 |
|
|---|
| 588 | { TExpressionBrackets }
|
|---|
| 589 |
|
|---|
| 590 | procedure TExpressionBrackets.GetValue(Index: Integer; out Value);
|
|---|
| 591 | begin
|
|---|
| 592 | if Index = 0 then begin
|
|---|
| 593 | TExpression(Value) := Expression;
|
|---|
| 594 | end
|
|---|
| 595 | else inherited;
|
|---|
| 596 | end;
|
|---|
| 597 |
|
|---|
| 598 | function TExpressionBrackets.GetField(Index: Integer): TField;
|
|---|
| 599 | begin
|
|---|
| 600 | if Index = 0 then Result := TField.Create(dtObject, 'Expression')
|
|---|
| 601 | else inherited;
|
|---|
| 602 | end;
|
|---|
| 603 |
|
|---|
| 604 | procedure TExpressionBrackets.SetValue(Index: Integer; var Value);
|
|---|
| 605 | begin
|
|---|
| 606 | if Index = 0 then begin
|
|---|
| 607 | Expression := TExpression(Value);
|
|---|
| 608 | end
|
|---|
| 609 | else inherited;
|
|---|
| 610 | end;
|
|---|
| 611 |
|
|---|
| 612 | function TExpressionBrackets.GetType: TType;
|
|---|
| 613 | begin
|
|---|
| 614 | Result := Expression.GetType;
|
|---|
| 615 | end;
|
|---|
| 616 |
|
|---|
| 617 | destructor TExpressionBrackets.Destroy;
|
|---|
| 618 | begin
|
|---|
| 619 | FreeAndNil(Expression);
|
|---|
| 620 | inherited;
|
|---|
| 621 | end;
|
|---|
| 622 |
|
|---|
| 623 | { TReturn }
|
|---|
| 624 |
|
|---|
| 625 | function TReturn.GetFieldsCount: Integer;
|
|---|
| 626 | begin
|
|---|
| 627 | Result := 1;
|
|---|
| 628 | end;
|
|---|
| 629 |
|
|---|
| 630 | procedure TReturn.GetValue(Index: Integer; out Value);
|
|---|
| 631 | begin
|
|---|
| 632 | if Index = 0 then TExpression(Value) := Expression
|
|---|
| 633 | else inherited;
|
|---|
| 634 | end;
|
|---|
| 635 |
|
|---|
| 636 | function TReturn.GetField(Index: Integer): TField;
|
|---|
| 637 | begin
|
|---|
| 638 | if Index = 0 then Result := TField.Create(dtObject, 'Expression')
|
|---|
| 639 | else inherited;
|
|---|
| 640 | end;
|
|---|
| 641 |
|
|---|
| 642 | procedure TReturn.SetValue(Index: Integer; var Value);
|
|---|
| 643 | begin
|
|---|
| 644 | if Index = 0 then Expression := TExpression(Value)
|
|---|
| 645 | else inherited;
|
|---|
| 646 | end;
|
|---|
| 647 |
|
|---|
| 648 | constructor TReturn.Create;
|
|---|
| 649 | begin
|
|---|
| 650 | Expression := TExpression.Create;
|
|---|
| 651 | end;
|
|---|
| 652 |
|
|---|
| 653 | destructor TReturn.Destroy;
|
|---|
| 654 | begin
|
|---|
| 655 | FreeAndNil(Expression);
|
|---|
| 656 | inherited;
|
|---|
| 657 | end;
|
|---|
| 658 |
|
|---|
| 659 | { TVariable }
|
|---|
| 660 |
|
|---|
| 661 | procedure TVariable.GetValue(Index: Integer; out Value);
|
|---|
| 662 | begin
|
|---|
| 663 | if Index = 0 then string(Value) := Name
|
|---|
| 664 | else if Index = 1 then TType(Value) := TypeRef
|
|---|
| 665 | else inherited;
|
|---|
| 666 | end;
|
|---|
| 667 |
|
|---|
| 668 | function TVariable.GetField(Index: Integer): TField;
|
|---|
| 669 | begin
|
|---|
| 670 | if Index = 0 then Result := TField.Create(dtString, 'Name')
|
|---|
| 671 | else if Index = 1 then Result := TField.Create(dtObject, 'Type')
|
|---|
| 672 | else inherited;
|
|---|
| 673 | end;
|
|---|
| 674 |
|
|---|
| 675 | function TVariable.GetFieldsCount: Integer;
|
|---|
| 676 | begin
|
|---|
| 677 | Result := 2;
|
|---|
| 678 | end;
|
|---|
| 679 |
|
|---|
| 680 | procedure TVariable.SetValue(Index: Integer; var Value);
|
|---|
| 681 | begin
|
|---|
| 682 | if Index = 0 then Name := string(Value)
|
|---|
| 683 | else if Index = 1 then TypeRef := TType(Value)
|
|---|
| 684 | else inherited;
|
|---|
| 685 | end;
|
|---|
| 686 |
|
|---|
| 687 | { TConstant }
|
|---|
| 688 |
|
|---|
| 689 | procedure TConstant.GetValue(Index: Integer; out Value);
|
|---|
| 690 | begin
|
|---|
| 691 | if Index = 0 then string(Value) := Name
|
|---|
| 692 | else if Index = 1 then TType(Value) := TypeRef
|
|---|
| 693 | else inherited;
|
|---|
| 694 | end;
|
|---|
| 695 |
|
|---|
| 696 | function TConstant.GetField(Index: Integer): TField;
|
|---|
| 697 | begin
|
|---|
| 698 | if Index = 0 then Result := TField.Create(dtString, 'Name')
|
|---|
| 699 | else if Index = 1 then Result := TField.Create(dtObject, 'Type')
|
|---|
| 700 | else inherited;
|
|---|
| 701 | end;
|
|---|
| 702 |
|
|---|
| 703 | function TConstant.GetFieldsCount: Integer;
|
|---|
| 704 | begin
|
|---|
| 705 | Result := 2;
|
|---|
| 706 | end;
|
|---|
| 707 |
|
|---|
| 708 | procedure TConstant.SetValue(Index: Integer; var Value);
|
|---|
| 709 | begin
|
|---|
| 710 | if Index = 0 then Name := string(Value)
|
|---|
| 711 | else if Index = 1 then TypeRef := TType(Value)
|
|---|
| 712 | else inherited;
|
|---|
| 713 | end;
|
|---|
| 714 |
|
|---|
| 715 | destructor TConstant.Destroy;
|
|---|
| 716 | begin
|
|---|
| 717 | FreeAndNil(Value);
|
|---|
| 718 | inherited;
|
|---|
| 719 | end;
|
|---|
| 720 |
|
|---|
| 721 | { TRepeatUntil }
|
|---|
| 722 |
|
|---|
| 723 | procedure TRepeatUntil.GetValue(Index: Integer; out Value);
|
|---|
| 724 | begin
|
|---|
| 725 | if Index = 0 then TExpression(Value) := Expression
|
|---|
| 726 | else if Index = 1 then TCommands(Value) := Commands
|
|---|
| 727 | else inherited;
|
|---|
| 728 | end;
|
|---|
| 729 |
|
|---|
| 730 | function TRepeatUntil.GetField(Index: Integer): TField;
|
|---|
| 731 | begin
|
|---|
| 732 | if Index = 0 then Result := TField.Create(dtObject, 'Expression')
|
|---|
| 733 | else if Index = 1 then Result := TField.Create(dtList, 'Commands')
|
|---|
| 734 | else inherited;
|
|---|
| 735 | end;
|
|---|
| 736 |
|
|---|
| 737 | function TRepeatUntil.GetFieldsCount: Integer;
|
|---|
| 738 | begin
|
|---|
| 739 | Result := 2;
|
|---|
| 740 | end;
|
|---|
| 741 |
|
|---|
| 742 | procedure TRepeatUntil.SetValue(Index: Integer; var Value);
|
|---|
| 743 | begin
|
|---|
| 744 | if Index = 0 then Expression := TExpression(Value)
|
|---|
| 745 | else if Index = 1 then Commands := TCommands(Value)
|
|---|
| 746 | else inherited;
|
|---|
| 747 | end;
|
|---|
| 748 |
|
|---|
| 749 | constructor TRepeatUntil.Create;
|
|---|
| 750 | begin
|
|---|
| 751 | Expression := TExpression.Create;
|
|---|
| 752 | Commands := TCommands.Create;
|
|---|
| 753 | end;
|
|---|
| 754 |
|
|---|
| 755 | destructor TRepeatUntil.Destroy;
|
|---|
| 756 | begin
|
|---|
| 757 | FreeAndNil(Expression);
|
|---|
| 758 | FreeAndNil(Commands);
|
|---|
| 759 | inherited;
|
|---|
| 760 | end;
|
|---|
| 761 |
|
|---|
| 762 | { TValueBoolean }
|
|---|
| 763 |
|
|---|
| 764 | function TValueBoolean.Clone: TValue;
|
|---|
| 765 | begin
|
|---|
| 766 | Result := TValueBoolean.Create;
|
|---|
| 767 | TValueBoolean(Result).Value := Value;
|
|---|
| 768 | end;
|
|---|
| 769 |
|
|---|
| 770 | { TValueInteger }
|
|---|
| 771 |
|
|---|
| 772 | function TValueInteger.Clone: TValue;
|
|---|
| 773 | begin
|
|---|
| 774 | Result := TValueInteger.Create;
|
|---|
| 775 | TValueInteger(Result).Value := Value;
|
|---|
| 776 | end;
|
|---|
| 777 |
|
|---|
| 778 | { TValueString }
|
|---|
| 779 |
|
|---|
| 780 | function TValueString.Clone: TValue;
|
|---|
| 781 | begin
|
|---|
| 782 | Result := TValueString.Create;
|
|---|
| 783 | TValueString(Result).Value := Value;
|
|---|
| 784 | end;
|
|---|
| 785 |
|
|---|
| 786 | { TValue }
|
|---|
| 787 |
|
|---|
| 788 | function TValue.Clone: TValue;
|
|---|
| 789 | begin
|
|---|
| 790 | Result := nil;
|
|---|
| 791 | end;
|
|---|
| 792 |
|
|---|
| 793 | { TForToDo }
|
|---|
| 794 |
|
|---|
| 795 | procedure TForToDo.GetValue(Index: Integer; out Value);
|
|---|
| 796 | begin
|
|---|
| 797 | if Index = 0 then TVariable(Value) := VariableRef
|
|---|
| 798 | else if Index = 1 then TExpression(Value) := ExpressionFrom
|
|---|
| 799 | else if Index = 2 then TExpression(Value) := ExpressionTo
|
|---|
| 800 | else if Index = 3 then TCommand(Value) := Command
|
|---|
| 801 | else inherited;
|
|---|
| 802 | end;
|
|---|
| 803 |
|
|---|
| 804 | function TForToDo.GetField(Index: Integer): TField;
|
|---|
| 805 | begin
|
|---|
| 806 | if Index = 0 then Result := TField.Create(dtObject, 'Variable')
|
|---|
| 807 | else if Index = 1 then Result := TField.Create(dtObject, 'To')
|
|---|
| 808 | else if Index = 2 then Result := TField.Create(dtObject, 'From')
|
|---|
| 809 | else if Index = 3 then Result := TField.Create(dtObject, 'Do')
|
|---|
| 810 | else inherited;
|
|---|
| 811 | end;
|
|---|
| 812 |
|
|---|
| 813 | function TForToDo.GetFieldsCount: Integer;
|
|---|
| 814 | begin
|
|---|
| 815 | Result := 4;
|
|---|
| 816 | end;
|
|---|
| 817 |
|
|---|
| 818 | procedure TForToDo.SetValue(Index: Integer; var Value);
|
|---|
| 819 | begin
|
|---|
| 820 | if Index = 0 then VariableRef := TVariable(Value)
|
|---|
| 821 | else if Index = 1 then ExpressionFrom := TExpression(Value)
|
|---|
| 822 | else if Index = 2 then ExpressionTo := TExpression(Value)
|
|---|
| 823 | else if Index = 3 then Command := TCommand(Value)
|
|---|
| 824 | else inherited;
|
|---|
| 825 | end;
|
|---|
| 826 |
|
|---|
| 827 | constructor TForToDo.Create;
|
|---|
| 828 | begin
|
|---|
| 829 | ExpressionFrom := TExpression.Create;
|
|---|
| 830 | ExpressionTo := TExpression.Create;
|
|---|
| 831 | Command := TEmptyCommand.Create;
|
|---|
| 832 | end;
|
|---|
| 833 |
|
|---|
| 834 | destructor TForToDo.Destroy;
|
|---|
| 835 | begin
|
|---|
| 836 | FreeAndNil(Command);
|
|---|
| 837 | FreeAndNil(ExpressionTo);
|
|---|
| 838 | FreeAndNil(ExpressionFrom);
|
|---|
| 839 | inherited;
|
|---|
| 840 | end;
|
|---|
| 841 |
|
|---|
| 842 | { TExpression }
|
|---|
| 843 |
|
|---|
| 844 | function TExpression.GetType: TType;
|
|---|
| 845 | begin
|
|---|
| 846 | Result := nil;
|
|---|
| 847 | end;
|
|---|
| 848 |
|
|---|
| 849 | { TExpressionOperand }
|
|---|
| 850 |
|
|---|
| 851 | procedure TExpressionOperand.GetValue(Index: Integer; out Value);
|
|---|
| 852 | begin
|
|---|
| 853 | if Index = 0 then begin
|
|---|
| 854 | case OperandType of
|
|---|
| 855 | otConstantDirect: TConstant(Value) := ConstantDirect;
|
|---|
| 856 | otConstantRef: TConstant(Value) := ConstantRef;
|
|---|
| 857 | otFunctionCall: TFunctionCall(Value) := FunctionCall;
|
|---|
| 858 | otVariableRef: TVariable(Value) := VariableRef;
|
|---|
| 859 | end;
|
|---|
| 860 | end
|
|---|
| 861 | else inherited;
|
|---|
| 862 | end;
|
|---|
| 863 |
|
|---|
| 864 | function TExpressionOperand.GetField(Index: Integer): TField;
|
|---|
| 865 | begin
|
|---|
| 866 | if Index = 0 then Result := TField.Create(dtObject, 'Value')
|
|---|
| 867 | else inherited;
|
|---|
| 868 | end;
|
|---|
| 869 |
|
|---|
| 870 | function TExpressionOperand.GetFieldsCount: Integer;
|
|---|
| 871 | begin
|
|---|
| 872 | Result := 1;
|
|---|
| 873 | end;
|
|---|
| 874 |
|
|---|
| 875 | procedure TExpressionOperand.SetValue(Index: Integer; var Value);
|
|---|
| 876 | begin
|
|---|
| 877 | if Index = 0 then begin
|
|---|
| 878 | case OperandType of
|
|---|
| 879 | otConstantDirect: ConstantDirect := TConstant(Value);
|
|---|
| 880 | otConstantRef: ConstantRef := TConstant(Value);
|
|---|
| 881 | otFunctionCall: FunctionCall := TFunctionCall(Value);
|
|---|
| 882 | otVariableRef: VariableRef := TVariable(Value);
|
|---|
| 883 | end;
|
|---|
| 884 | end
|
|---|
| 885 | else inherited;
|
|---|
| 886 | end;
|
|---|
| 887 |
|
|---|
| 888 | function TExpressionOperand.GetType: TType;
|
|---|
| 889 | begin
|
|---|
| 890 | if OperandType = otFunctionCall then Result := FunctionCall.FunctionDef.ResultType
|
|---|
| 891 | else if OperandType = otConstantRef then Result := ConstantRef.TypeRef
|
|---|
| 892 | else if OperandType = otConstantDirect then Result := ConstantDirect.TypeRef
|
|---|
| 893 | else if OperandType = otVariableRef then Result := VariableRef.TypeRef
|
|---|
| 894 | else raise Exception.Create('Unsupported operand type');
|
|---|
| 895 | end;
|
|---|
| 896 |
|
|---|
| 897 | constructor TExpressionOperand.Create;
|
|---|
| 898 | begin
|
|---|
| 899 | end;
|
|---|
| 900 |
|
|---|
| 901 | destructor TExpressionOperand.Destroy;
|
|---|
| 902 | begin
|
|---|
| 903 | if Assigned(ConstantDirect) then FreeAndNil(ConstantDirect);
|
|---|
| 904 | if Assigned(FunctionCall) then FreeAndNil(FunctionCall);
|
|---|
| 905 | end;
|
|---|
| 906 |
|
|---|
| 907 | { TFunctionParameters }
|
|---|
| 908 |
|
|---|
| 909 | function TFunctionParameters.SearchByName(Name: string): TFunctionParameter;
|
|---|
| 910 | var
|
|---|
| 911 | I: Integer;
|
|---|
| 912 | begin
|
|---|
| 913 | I := 0;
|
|---|
| 914 | while (I < Count) and (TFunctionParameter(Items[I]).Name <> Name) do Inc(I);
|
|---|
| 915 | if I < Count then Result := TFunctionParameter(Items[I])
|
|---|
| 916 | else Result := nil;
|
|---|
| 917 | end;
|
|---|
| 918 |
|
|---|
| 919 | function TFunctionParameters.AddNew(Name: string; TypeRef: TType): TFunctionParameter;
|
|---|
| 920 | begin
|
|---|
| 921 | Result := TFunctionParameter.Create;
|
|---|
| 922 | Result.Name := Name;
|
|---|
| 923 | Result.TypeRef := TypeRef;
|
|---|
| 924 | Add(Result);
|
|---|
| 925 | end;
|
|---|
| 926 |
|
|---|
| 927 | { TFunction }
|
|---|
| 928 |
|
|---|
| 929 | procedure TFunction.GetValue(Index: Integer; out Value);
|
|---|
| 930 | begin
|
|---|
| 931 | if Index = 0 then TBlock(Value) := Block
|
|---|
| 932 | else if Index = 1 then TFunctionParameters(Value) := Params
|
|---|
| 933 | else if Index = 2 then string(Value) := Name
|
|---|
| 934 | else if Index = 3 then TType(Value) := ResultType
|
|---|
| 935 | else inherited;
|
|---|
| 936 | end;
|
|---|
| 937 |
|
|---|
| 938 | function TFunction.GetField(Index: Integer): TField;
|
|---|
| 939 | begin
|
|---|
| 940 | if Index = 0 then Result := TField.Create(dtObject, 'Block')
|
|---|
| 941 | else if Index = 1 then Result := TField.Create(dtList, 'Parameters')
|
|---|
| 942 | else if Index = 2 then Result := TField.Create(dtString, 'Name')
|
|---|
| 943 | else if Index = 3 then Result := TField.Create(dtObject, 'ResultType')
|
|---|
| 944 | else inherited;
|
|---|
| 945 | end;
|
|---|
| 946 |
|
|---|
| 947 | function TFunction.GetFieldsCount: Integer;
|
|---|
| 948 | begin
|
|---|
| 949 | Result := 4;
|
|---|
| 950 | end;
|
|---|
| 951 |
|
|---|
| 952 | procedure TFunction.InitVariables;
|
|---|
| 953 | var
|
|---|
| 954 | I: Integer;
|
|---|
| 955 | Variable: TVariable;
|
|---|
| 956 | begin
|
|---|
| 957 | for I := 0 to Params.Count - 1 do begin
|
|---|
| 958 | Variable := TVariable.Create;
|
|---|
| 959 | Variable.Name := Params[I].Name;
|
|---|
| 960 | Variable.TypeRef := Params[I].TypeRef;
|
|---|
| 961 | Variable.Internal := True;
|
|---|
| 962 | Block.Variables.Add(Variable);
|
|---|
| 963 | end;
|
|---|
| 964 |
|
|---|
| 965 | Variable := TVariable.Create;
|
|---|
| 966 | Variable.Name := 'Result';
|
|---|
| 967 | Variable.TypeRef := ResultType;
|
|---|
| 968 | Variable.Internal := True;
|
|---|
| 969 | Block.Variables.Add(Variable);
|
|---|
| 970 | end;
|
|---|
| 971 |
|
|---|
| 972 | procedure TFunction.SetValue(Index: Integer; var Value);
|
|---|
| 973 | begin
|
|---|
| 974 | if Index = 0 then Block := TBlock(Value)
|
|---|
| 975 | else if Index = 1 then Params := TFunctionParameters(Value)
|
|---|
| 976 | else if Index = 2 then Name := string(Value)
|
|---|
| 977 | else if Index = 3 then ResultType := TType(Value)
|
|---|
| 978 | else inherited;
|
|---|
| 979 | end;
|
|---|
| 980 |
|
|---|
| 981 | constructor TFunction.Create;
|
|---|
| 982 | begin
|
|---|
| 983 | Params := TFunctionParameters.Create;
|
|---|
| 984 | Block := TBlock.Create;
|
|---|
| 985 | end;
|
|---|
| 986 |
|
|---|
| 987 | destructor TFunction.Destroy;
|
|---|
| 988 | begin
|
|---|
| 989 | FreeAndNil(Block);
|
|---|
| 990 | FreeAndNil(Params);
|
|---|
| 991 | inherited;
|
|---|
| 992 | end;
|
|---|
| 993 |
|
|---|
| 994 | { TType }
|
|---|
| 995 |
|
|---|
| 996 | procedure TType.GetValue(Index: Integer; out Value);
|
|---|
| 997 | begin
|
|---|
| 998 | if Index = 0 then string(Value) := Name
|
|---|
| 999 | else inherited;
|
|---|
| 1000 | end;
|
|---|
| 1001 |
|
|---|
| 1002 | function TType.GetField(Index: Integer): TField;
|
|---|
| 1003 | begin
|
|---|
| 1004 | if Index = 0 then Result := TField.Create(dtString, 'Name')
|
|---|
| 1005 | else inherited;
|
|---|
| 1006 | end;
|
|---|
| 1007 |
|
|---|
| 1008 | function TType.GetFieldsCount: Integer;
|
|---|
| 1009 | begin
|
|---|
| 1010 | Result := 1;
|
|---|
| 1011 | end;
|
|---|
| 1012 |
|
|---|
| 1013 | procedure TType.SetValue(Index: Integer; var Value);
|
|---|
| 1014 | begin
|
|---|
| 1015 | if Index = 0 then Name := string(Value)
|
|---|
| 1016 | else inherited;
|
|---|
| 1017 | end;
|
|---|
| 1018 |
|
|---|
| 1019 | constructor TType.Create;
|
|---|
| 1020 | begin
|
|---|
| 1021 | Functions := TFunctions.Create;
|
|---|
| 1022 | Functions.ParentType := Self;
|
|---|
| 1023 | end;
|
|---|
| 1024 |
|
|---|
| 1025 | destructor TType.Destroy;
|
|---|
| 1026 | begin
|
|---|
| 1027 | FreeAndNil(Functions);
|
|---|
| 1028 | inherited;
|
|---|
| 1029 | end;
|
|---|
| 1030 |
|
|---|
| 1031 | { TTypes }
|
|---|
| 1032 |
|
|---|
| 1033 | function TTypes.SearchByName(Name: string): TType;
|
|---|
| 1034 | var
|
|---|
| 1035 | I: Integer;
|
|---|
| 1036 | begin
|
|---|
| 1037 | I := 0;
|
|---|
| 1038 | while (I < Count) and (TType(Items[I]).Name <> Name) do Inc(I);
|
|---|
| 1039 | if I < Count then Result := TType(Items[I])
|
|---|
| 1040 | else Result := nil;
|
|---|
| 1041 | end;
|
|---|
| 1042 |
|
|---|
| 1043 | function TTypes.AddNew(Name: string): TType;
|
|---|
| 1044 | begin
|
|---|
| 1045 | Result := TType.Create;
|
|---|
| 1046 | Result.Name := Name;
|
|---|
| 1047 | Add(Result);
|
|---|
| 1048 | end;
|
|---|
| 1049 |
|
|---|
| 1050 | { TExpressionOperation }
|
|---|
| 1051 |
|
|---|
| 1052 | procedure TExpressionOperation.GetValue(Index: Integer; out Value);
|
|---|
| 1053 | begin
|
|---|
| 1054 | TObject(Value) := Items[Index];
|
|---|
| 1055 | end;
|
|---|
| 1056 |
|
|---|
| 1057 | function TExpressionOperation.GetField(Index: Integer): TField;
|
|---|
| 1058 | begin
|
|---|
| 1059 | if Index < Items.Count then Result := TField.Create(dtObject, 'Expression')
|
|---|
| 1060 | else inherited;
|
|---|
| 1061 | end;
|
|---|
| 1062 |
|
|---|
| 1063 | function TExpressionOperation.GetFunctionName: string;
|
|---|
| 1064 | begin
|
|---|
| 1065 | Result := ExpressionOperatorFuncText[Operation];
|
|---|
| 1066 | end;
|
|---|
| 1067 |
|
|---|
| 1068 | function TExpressionOperation.GetFieldsCount: Integer;
|
|---|
| 1069 | begin
|
|---|
| 1070 | Result := Items.Count;
|
|---|
| 1071 | end;
|
|---|
| 1072 |
|
|---|
| 1073 | procedure TExpressionOperation.SetValue(Index: Integer; var Value);
|
|---|
| 1074 | begin
|
|---|
| 1075 | Items[Index] := TExpression(Value);
|
|---|
| 1076 | end;
|
|---|
| 1077 |
|
|---|
| 1078 | constructor TExpressionOperation.Create;
|
|---|
| 1079 | begin
|
|---|
| 1080 | Items := TExpressions.Create;
|
|---|
| 1081 | end;
|
|---|
| 1082 |
|
|---|
| 1083 | destructor TExpressionOperation.Destroy;
|
|---|
| 1084 | begin
|
|---|
| 1085 | FreeAndNil(Items);
|
|---|
| 1086 | inherited;
|
|---|
| 1087 | end;
|
|---|
| 1088 |
|
|---|
| 1089 | function TExpressionOperation.GetType: TType;
|
|---|
| 1090 | begin
|
|---|
| 1091 | Result := TypeRef;
|
|---|
| 1092 | end;
|
|---|
| 1093 |
|
|---|
| 1094 | { TAssignment }
|
|---|
| 1095 |
|
|---|
| 1096 | procedure TAssignment.GetValue(Index: Integer; out Value);
|
|---|
| 1097 | begin
|
|---|
| 1098 | if Index = 0 then TExpression(Value) := Expression
|
|---|
| 1099 | else if Index = 1 then TVariable(Value) := Variable
|
|---|
| 1100 | else inherited;
|
|---|
| 1101 | end;
|
|---|
| 1102 |
|
|---|
| 1103 | function TAssignment.GetField(Index: Integer): TField;
|
|---|
| 1104 | begin
|
|---|
| 1105 | if Index = 0 then Result := TField.Create(dtObject, 'Expression')
|
|---|
| 1106 | else if Index = 1 then Result := TField.Create(dtObject, 'Variable')
|
|---|
| 1107 | else inherited;
|
|---|
| 1108 | end;
|
|---|
| 1109 |
|
|---|
| 1110 | function TAssignment.GetFieldsCount: Integer;
|
|---|
| 1111 | begin
|
|---|
| 1112 | Result := 2;
|
|---|
| 1113 | end;
|
|---|
| 1114 |
|
|---|
| 1115 | procedure TAssignment.SetValue(Index: Integer; var Value);
|
|---|
| 1116 | begin
|
|---|
| 1117 | if Index = 0 then Expression := TExpression(Value)
|
|---|
| 1118 | else if Index = 1 then Variable := TVariable(Value)
|
|---|
| 1119 | else inherited;
|
|---|
| 1120 | end;
|
|---|
| 1121 |
|
|---|
| 1122 | constructor TAssignment.Create;
|
|---|
| 1123 | begin
|
|---|
| 1124 | Variable := nil;
|
|---|
| 1125 | Expression := TExpression.Create;
|
|---|
| 1126 | end;
|
|---|
| 1127 |
|
|---|
| 1128 | destructor TAssignment.Destroy;
|
|---|
| 1129 | begin
|
|---|
| 1130 | Variable := nil;
|
|---|
| 1131 | FreeAndNil(Expression);
|
|---|
| 1132 | inherited;
|
|---|
| 1133 | end;
|
|---|
| 1134 |
|
|---|
| 1135 | { TIfThenElse }
|
|---|
| 1136 |
|
|---|
| 1137 | procedure TIfThenElse.GetValue(Index: Integer; out Value);
|
|---|
| 1138 | begin
|
|---|
| 1139 | if Index = 0 then TExpression(Value) := Expression
|
|---|
| 1140 | else if Index = 1 then TCommand(Value) := CommandElse
|
|---|
| 1141 | else if Index = 2 then TCommand(Value) := CommandThen
|
|---|
| 1142 | else inherited;
|
|---|
| 1143 | end;
|
|---|
| 1144 |
|
|---|
| 1145 | function TIfThenElse.GetField(Index: Integer): TField;
|
|---|
| 1146 | begin
|
|---|
| 1147 | if Index = 0 then Result := TField.Create(dtObject, 'Expression')
|
|---|
| 1148 | else if Index = 1 then Result := TField.Create(dtObject, 'Else')
|
|---|
| 1149 | else if Index = 2 then Result := TField.Create(dtObject, 'Then')
|
|---|
| 1150 | else inherited;
|
|---|
| 1151 | end;
|
|---|
| 1152 |
|
|---|
| 1153 | function TIfThenElse.GetFieldsCount: Integer;
|
|---|
| 1154 | begin
|
|---|
| 1155 | Result := 3;
|
|---|
| 1156 | end;
|
|---|
| 1157 |
|
|---|
| 1158 | procedure TIfThenElse.SetValue(Index: Integer; var Value);
|
|---|
| 1159 | begin
|
|---|
| 1160 | if Index = 0 then Expression := TExpression(Value)
|
|---|
| 1161 | else if Index = 1 then CommandElse := TCommand(Value)
|
|---|
| 1162 | else if Index = 2 then CommandThen := TCommand(Value)
|
|---|
| 1163 | else inherited;
|
|---|
| 1164 | end;
|
|---|
| 1165 |
|
|---|
| 1166 | constructor TIfThenElse.Create;
|
|---|
| 1167 | begin
|
|---|
| 1168 | Expression := TExpression.Create;
|
|---|
| 1169 | CommandThen := TEmptyCommand.Create;
|
|---|
| 1170 | CommandElse := TEmptyCommand.Create;
|
|---|
| 1171 | end;
|
|---|
| 1172 |
|
|---|
| 1173 | destructor TIfThenElse.Destroy;
|
|---|
| 1174 | begin
|
|---|
| 1175 | FreeAndNil(Expression);
|
|---|
| 1176 | FreeAndNil(CommandThen);
|
|---|
| 1177 | FreeAndNil(CommandElse);
|
|---|
| 1178 | inherited;
|
|---|
| 1179 | end;
|
|---|
| 1180 |
|
|---|
| 1181 | { TWhileDo }
|
|---|
| 1182 |
|
|---|
| 1183 | procedure TWhileDo.GetValue(Index: Integer; out Value);
|
|---|
| 1184 | begin
|
|---|
| 1185 | if Index = 0 then TExpression(Value) := Expression
|
|---|
| 1186 | else if Index = 1 then TCommand(Value) := Command
|
|---|
| 1187 | else inherited;
|
|---|
| 1188 | end;
|
|---|
| 1189 |
|
|---|
| 1190 | function TWhileDo.GetField(Index: Integer): TField;
|
|---|
| 1191 | begin
|
|---|
| 1192 | if Index = 0 then Result := TField.Create(dtObject, 'Expression')
|
|---|
| 1193 | else if Index = 1 then Result := TField.Create(dtObject, 'Do')
|
|---|
| 1194 | else inherited;
|
|---|
| 1195 | end;
|
|---|
| 1196 |
|
|---|
| 1197 | function TWhileDo.GetFieldsCount: Integer;
|
|---|
| 1198 | begin
|
|---|
| 1199 | Result := 2;
|
|---|
| 1200 | end;
|
|---|
| 1201 |
|
|---|
| 1202 | procedure TWhileDo.SetValue(Index: Integer; var Value);
|
|---|
| 1203 | begin
|
|---|
| 1204 | if Index = 0 then Expression := TExpression(Value)
|
|---|
| 1205 | else if Index = 1 then Command := TCommand(Value)
|
|---|
| 1206 | else inherited;
|
|---|
| 1207 | end;
|
|---|
| 1208 |
|
|---|
| 1209 | constructor TWhileDo.Create;
|
|---|
| 1210 | begin
|
|---|
| 1211 | Expression := TExpression.Create;
|
|---|
| 1212 | Command := TEmptyCommand.Create;
|
|---|
| 1213 | end;
|
|---|
| 1214 |
|
|---|
| 1215 | destructor TWhileDo.Destroy;
|
|---|
| 1216 | begin
|
|---|
| 1217 | FreeAndNil(Expression);
|
|---|
| 1218 | FreeAndNil(Command);
|
|---|
| 1219 | inherited;
|
|---|
| 1220 | end;
|
|---|
| 1221 |
|
|---|
| 1222 | { TFunctionCall }
|
|---|
| 1223 |
|
|---|
| 1224 | procedure TFunctionCall.GetValue(Index: Integer; out Value);
|
|---|
| 1225 | begin
|
|---|
| 1226 | if Index = 0 then TFunction(Value) := FunctionDef
|
|---|
| 1227 | else if Index = 1 then TExpressions(Value) := Params
|
|---|
| 1228 | else inherited;
|
|---|
| 1229 | end;
|
|---|
| 1230 |
|
|---|
| 1231 | function TFunctionCall.GetField(Index: Integer): TField;
|
|---|
| 1232 | begin
|
|---|
| 1233 | if Index = 0 then Result := TField.Create(dtObject, 'Function')
|
|---|
| 1234 | else if Index = 1 then Result := TField.Create(dtList, 'Parameters')
|
|---|
| 1235 | else inherited;
|
|---|
| 1236 | end;
|
|---|
| 1237 |
|
|---|
| 1238 | function TFunctionCall.GetFieldsCount: Integer;
|
|---|
| 1239 | begin
|
|---|
| 1240 | Result := 2;
|
|---|
| 1241 | end;
|
|---|
| 1242 |
|
|---|
| 1243 | procedure TFunctionCall.SetValue(Index: Integer; var Value);
|
|---|
| 1244 | begin
|
|---|
| 1245 | if Index = 0 then FunctionDef := TFunction(Value)
|
|---|
| 1246 | else if Index = 1 then Params := TExpressions(Value)
|
|---|
| 1247 | else inherited;
|
|---|
| 1248 | end;
|
|---|
| 1249 |
|
|---|
| 1250 | constructor TFunctionCall.Create;
|
|---|
| 1251 | begin
|
|---|
| 1252 | Params := TExpressions.Create;
|
|---|
| 1253 | end;
|
|---|
| 1254 |
|
|---|
| 1255 | destructor TFunctionCall.Destroy;
|
|---|
| 1256 | begin
|
|---|
| 1257 | FreeAndNil(Params);
|
|---|
| 1258 | inherited;
|
|---|
| 1259 | end;
|
|---|
| 1260 |
|
|---|
| 1261 | { TFunctions }
|
|---|
| 1262 |
|
|---|
| 1263 | function TFunctions.SearchByName(Name: string): TFunction;
|
|---|
| 1264 | var
|
|---|
| 1265 | I: Integer;
|
|---|
| 1266 | begin
|
|---|
| 1267 | I := 0;
|
|---|
| 1268 | while (I < Count) and (TFunction(Items[I]).Name <> Name) do Inc(I);
|
|---|
| 1269 | if I < Count then Result := TFunction(Items[I])
|
|---|
| 1270 | else Result := nil;
|
|---|
| 1271 | end;
|
|---|
| 1272 |
|
|---|
| 1273 | function TFunctions.AddNew(Name: string): TFunction;
|
|---|
| 1274 | begin
|
|---|
| 1275 | Result := TFunction.Create;
|
|---|
| 1276 | Result.Name := Name;
|
|---|
| 1277 | Result.ParentType := ParentType;
|
|---|
| 1278 | Add(Result);
|
|---|
| 1279 | end;
|
|---|
| 1280 |
|
|---|
| 1281 | { TConstants }
|
|---|
| 1282 |
|
|---|
| 1283 | function TConstants.SearchByName(Name: string): TConstant;
|
|---|
| 1284 | var
|
|---|
| 1285 | I: Integer;
|
|---|
| 1286 | begin
|
|---|
| 1287 | I := 0;
|
|---|
| 1288 | while (I < Count) and (TConstant(Items[I]).Name <> Name) do Inc(I);
|
|---|
| 1289 | if I < Count then Result := TConstant(Items[I])
|
|---|
| 1290 | else Result := nil;
|
|---|
| 1291 | end;
|
|---|
| 1292 |
|
|---|
| 1293 | function TConstants.AddNew(Name: string): TConstant;
|
|---|
| 1294 | begin
|
|---|
| 1295 | Result := TConstant.Create;
|
|---|
| 1296 | Result.Name := Name;
|
|---|
| 1297 | Add(Result);
|
|---|
| 1298 | end;
|
|---|
| 1299 |
|
|---|
| 1300 | { TVariables }
|
|---|
| 1301 |
|
|---|
| 1302 | function TVariables.SearchByName(Name: string): TVariable;
|
|---|
| 1303 | var
|
|---|
| 1304 | I: Integer;
|
|---|
| 1305 | begin
|
|---|
| 1306 | I := 0;
|
|---|
| 1307 | while (I < Count) and (TVariable(Items[I]).Name <> Name) do Inc(I);
|
|---|
| 1308 | if I < Count then Result := TVariable(Items[I])
|
|---|
| 1309 | else Result := nil;
|
|---|
| 1310 | end;
|
|---|
| 1311 |
|
|---|
| 1312 | { TBlock }
|
|---|
| 1313 |
|
|---|
| 1314 | procedure TBlock.GetValue(Index: Integer; out Value);
|
|---|
| 1315 | begin
|
|---|
| 1316 | if Index = 0 then TBeginEnd(Value) := BeginEnd
|
|---|
| 1317 | else if Index = 1 then TTypes(Value) := Types
|
|---|
| 1318 | else if Index = 2 then TVariables(Value) := Variables
|
|---|
| 1319 | else if Index = 3 then TConstants(Value) := Constants
|
|---|
| 1320 | else if Index = 4 then TFunctions(Value) := Functions
|
|---|
| 1321 | else if Index = 5 then TProcedures(Value) := Procedures
|
|---|
| 1322 | else inherited;
|
|---|
| 1323 | end;
|
|---|
| 1324 |
|
|---|
| 1325 | function TBlock.GetField(Index: Integer): TField;
|
|---|
| 1326 | begin
|
|---|
| 1327 | if Index = 0 then Result := TField.Create(dtObject, 'BeginEnd')
|
|---|
| 1328 | else if Index = 1 then Result := TField.Create(dtList, 'Types')
|
|---|
| 1329 | else if Index = 2 then Result := TField.Create(dtList, 'Variables')
|
|---|
| 1330 | else if Index = 3 then Result := TField.Create(dtList, 'Constants')
|
|---|
| 1331 | else if Index = 4 then Result := TField.Create(dtList, 'Functions')
|
|---|
| 1332 | else if Index = 5 then Result := TField.Create(dtList, 'Procedures')
|
|---|
| 1333 | else inherited;
|
|---|
| 1334 | end;
|
|---|
| 1335 |
|
|---|
| 1336 | function TBlock.GetFieldsCount: Integer;
|
|---|
| 1337 | begin
|
|---|
| 1338 | Result := 6;
|
|---|
| 1339 | end;
|
|---|
| 1340 |
|
|---|
| 1341 | procedure TBlock.SetValue(Index: Integer; var Value);
|
|---|
| 1342 | begin
|
|---|
| 1343 | if Index = 0 then BeginEnd := TBeginEnd(Value)
|
|---|
| 1344 | else if Index = 1 then Types := TTypes(Value)
|
|---|
| 1345 | else if Index = 2 then Variables := TVariables(Value)
|
|---|
| 1346 | else if Index = 3 then Constants := TConstants(Value)
|
|---|
| 1347 | else if Index = 4 then Functions := TFunctions(Value)
|
|---|
| 1348 | else if Index = 5 then Procedures := TProcedures(Value)
|
|---|
| 1349 | else inherited;
|
|---|
| 1350 | end;
|
|---|
| 1351 |
|
|---|
| 1352 | procedure TBlock.Clear;
|
|---|
| 1353 | begin
|
|---|
| 1354 | Functions.Clear;
|
|---|
| 1355 | Procedures.Clear;
|
|---|
| 1356 | Constants.Clear;
|
|---|
| 1357 | Variables.Clear;
|
|---|
| 1358 | Types.Clear;
|
|---|
| 1359 | end;
|
|---|
| 1360 |
|
|---|
| 1361 | function TBlock.GetType(Name: string): TType;
|
|---|
| 1362 | begin
|
|---|
| 1363 | Result := Types.SearchByName(Name);
|
|---|
| 1364 | if not Assigned(Result) and Assigned(ParentBlock) then
|
|---|
| 1365 | Result := ParentBlock.GetType(Name);
|
|---|
| 1366 | end;
|
|---|
| 1367 |
|
|---|
| 1368 | function TBlock.GetConstant(Name: string): TConstant;
|
|---|
| 1369 | begin
|
|---|
| 1370 | Result := Constants.SearchByName(Name);
|
|---|
| 1371 | if not Assigned(Result) and Assigned(ParentBlock) then
|
|---|
| 1372 | Result := ParentBlock.GetConstant(Name);
|
|---|
| 1373 | end;
|
|---|
| 1374 |
|
|---|
| 1375 | function TBlock.GetVariable(Name: string): TVariable;
|
|---|
| 1376 | begin
|
|---|
| 1377 | Result := Variables.SearchByName(Name);
|
|---|
| 1378 | if not Assigned(Result) and Assigned(ParentBlock) then
|
|---|
| 1379 | Result := ParentBlock.GetVariable(Name);
|
|---|
| 1380 | end;
|
|---|
| 1381 |
|
|---|
| 1382 | function TBlock.GetFunction(Name: string): TFunction;
|
|---|
| 1383 | begin
|
|---|
| 1384 | Result := Functions.SearchByName(Name);
|
|---|
| 1385 | if not Assigned(Result) and Assigned(ParentBlock) then
|
|---|
| 1386 | Result := ParentBlock.GetFunction(Name);
|
|---|
| 1387 | end;
|
|---|
| 1388 |
|
|---|
| 1389 | function TBlock.GetProcedure(Name: string): TProcedure;
|
|---|
| 1390 | begin
|
|---|
| 1391 | Result := Procedures.SearchByName(Name);
|
|---|
| 1392 | if not Assigned(Result) and Assigned(ParentBlock) then
|
|---|
| 1393 | Result := ParentBlock.GetProcedure(Name);
|
|---|
| 1394 | end;
|
|---|
| 1395 |
|
|---|
| 1396 | constructor TBlock.Create;
|
|---|
| 1397 | begin
|
|---|
| 1398 | Constants := TConstants.Create;
|
|---|
| 1399 | Constants.Parent := Self;
|
|---|
| 1400 | Variables := TVariables.Create;
|
|---|
| 1401 | Variables.Parent := Self;
|
|---|
| 1402 | Functions := TFunctions.Create;
|
|---|
| 1403 | Functions.Parent := Self;
|
|---|
| 1404 | Procedures := TProcedures.Create;
|
|---|
| 1405 | Procedures.Parent := Self;
|
|---|
| 1406 | Types := TTypes.Create;
|
|---|
| 1407 | Types.Parent := Self;
|
|---|
| 1408 | BeginEnd := TBeginEnd.Create;
|
|---|
| 1409 | BeginEnd.Parent := Self;
|
|---|
| 1410 | end;
|
|---|
| 1411 |
|
|---|
| 1412 | destructor TBlock.Destroy;
|
|---|
| 1413 | begin
|
|---|
| 1414 | FreeAndNil(BeginEnd);
|
|---|
| 1415 | FreeAndNil(Types);
|
|---|
| 1416 | FreeAndNil(Variables);
|
|---|
| 1417 | FreeAndNil(Constants);
|
|---|
| 1418 | FreeAndNil(Functions);
|
|---|
| 1419 | FreeAndNil(Procedures);
|
|---|
| 1420 | inherited;
|
|---|
| 1421 | end;
|
|---|
| 1422 |
|
|---|
| 1423 | { TBeginEnd }
|
|---|
| 1424 |
|
|---|
| 1425 | procedure TBeginEnd.GetValue(Index: Integer; out Value);
|
|---|
| 1426 | begin
|
|---|
| 1427 | if Index = 0 then TCommands(Value) := Commands
|
|---|
| 1428 | else inherited;
|
|---|
| 1429 | end;
|
|---|
| 1430 |
|
|---|
| 1431 | function TBeginEnd.GetField(Index: Integer): TField;
|
|---|
| 1432 | begin
|
|---|
| 1433 | if Index = 0 then Result := TField.Create(dtList, 'Commands')
|
|---|
| 1434 | else inherited;
|
|---|
| 1435 | end;
|
|---|
| 1436 |
|
|---|
| 1437 | function TBeginEnd.GetFieldsCount: Integer;
|
|---|
| 1438 | begin
|
|---|
| 1439 | Result := 1;
|
|---|
| 1440 | end;
|
|---|
| 1441 |
|
|---|
| 1442 | procedure TBeginEnd.SetValue(Index: Integer; var Value);
|
|---|
| 1443 | begin
|
|---|
| 1444 | if Index = 0 then Commands := TCommands(Value)
|
|---|
| 1445 | else inherited;
|
|---|
| 1446 | end;
|
|---|
| 1447 |
|
|---|
| 1448 | procedure TBeginEnd.Clear;
|
|---|
| 1449 | begin
|
|---|
| 1450 | Commands.Clear;
|
|---|
| 1451 | end;
|
|---|
| 1452 |
|
|---|
| 1453 | constructor TBeginEnd.Create;
|
|---|
| 1454 | begin
|
|---|
| 1455 | Commands := TCommands.Create;
|
|---|
| 1456 | end;
|
|---|
| 1457 |
|
|---|
| 1458 | destructor TBeginEnd.Destroy;
|
|---|
| 1459 | begin
|
|---|
| 1460 | FreeAndNil(Commands);
|
|---|
| 1461 | inherited;
|
|---|
| 1462 | end;
|
|---|
| 1463 |
|
|---|
| 1464 | { TProgram }
|
|---|
| 1465 |
|
|---|
| 1466 | procedure TProgram.GetValue(Index: Integer; out Value);
|
|---|
| 1467 | begin
|
|---|
| 1468 | if Index = 0 then string(Value) := Name
|
|---|
| 1469 | else if Index = 1 then TBlock(Value) := Block
|
|---|
| 1470 | else raise Exception.Create(SIndexError);
|
|---|
| 1471 | end;
|
|---|
| 1472 |
|
|---|
| 1473 | function TProgram.GetField(Index: Integer): TField;
|
|---|
| 1474 | begin
|
|---|
| 1475 | if Index = 0 then Result := TField.Create(dtString, 'Name')
|
|---|
| 1476 | else if Index = 1 then Result := TField.Create(dtObject, 'Block')
|
|---|
| 1477 | else inherited;
|
|---|
| 1478 | end;
|
|---|
| 1479 |
|
|---|
| 1480 | function TProgram.GetFieldsCount: Integer;
|
|---|
| 1481 | begin
|
|---|
| 1482 | Result := 2;
|
|---|
| 1483 | end;
|
|---|
| 1484 |
|
|---|
| 1485 | procedure TProgram.SetValue(Index: Integer; var Value);
|
|---|
| 1486 | begin
|
|---|
| 1487 | if Index = 0 then Name := string(Value)
|
|---|
| 1488 | else if Index = 0 then Block := TBlock(Value)
|
|---|
| 1489 | else raise Exception.Create(SIndexError);
|
|---|
| 1490 | end;
|
|---|
| 1491 |
|
|---|
| 1492 | procedure TProgram.Clear;
|
|---|
| 1493 | begin
|
|---|
| 1494 | Name := '';
|
|---|
| 1495 | end;
|
|---|
| 1496 |
|
|---|
| 1497 | constructor TProgram.Create;
|
|---|
| 1498 | begin
|
|---|
| 1499 | SystemBlock := TBlock.Create;
|
|---|
| 1500 | Block := TBlock.Create;
|
|---|
| 1501 | end;
|
|---|
| 1502 |
|
|---|
| 1503 | destructor TProgram.Destroy;
|
|---|
| 1504 | begin
|
|---|
| 1505 | FreeAndNil(Block);
|
|---|
| 1506 | FreeAndNil(SystemBlock);
|
|---|
| 1507 | inherited;
|
|---|
| 1508 | end;
|
|---|
| 1509 |
|
|---|
| 1510 | end.
|
|---|
| 1511 |
|
|---|