Changeset 233 for branches/xpascal/Source.pas
- Timestamp:
- Jun 26, 2023, 6:08:23 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/xpascal/Source.pas
r232 r233 148 148 end; 149 149 150 { TProcedure } 151 152 TProcedure = class(TSourceNode) 153 protected 154 function GetFieldsCount: Integer; override; 155 public 156 Name: string; 157 InternalName: string; 158 Params: TFunctionParameters; 159 Block: TBlock; 160 ParentType: TType; 161 procedure GetValue(Index: Integer; out Value); override; 162 function GetField(Index: Integer): TField; override; 163 procedure SetValue(Index: Integer; var Value); override; 164 constructor Create; 165 destructor Destroy; override; 166 end; 167 168 { TProcedures } 169 170 TProcedures = class(TSourceNodeList<TProcedure>) 171 ParentType: TType; 172 function SearchByName(Name: string): TProcedure; 173 function AddNew(Name: string): TProcedure; 174 end; 175 150 176 TCommand = class(TSourceNode) 151 177 end; … … 164 190 public 165 191 FunctionDef: TFunction; 192 Params: TExpressions; 193 procedure GetValue(Index: Integer; out Value); override; 194 function GetField(Index: Integer): TField; override; 195 procedure SetValue(Index: Integer; var Value); override; 196 constructor Create; 197 destructor Destroy; override; 198 end; 199 200 { TProcedureCall } 201 202 TProcedureCall = class(TCommand) 203 protected 204 function GetFieldsCount: Integer; override; 205 public 206 ProcedureDef: TProcedure; 166 207 Params: TExpressions; 167 208 procedure GetValue(Index: Integer; out Value); override; … … 365 406 Constants: TConstants; 366 407 Functions: TFunctions; 408 Procedures: TProcedures; 367 409 Types: TTypes; 368 410 BeginEnd: TBeginEnd; … … 375 417 function GetVariable(Name: string): TVariable; 376 418 function GetFunction(Name: string): TFunction; 419 function GetProcedure(Name: string): TProcedure; 377 420 constructor Create; 378 421 destructor Destroy; override; … … 426 469 end; 427 470 471 { TProcedureCall } 472 473 function TProcedureCall.GetFieldsCount: Integer; 474 begin 475 Result := 2; 476 end; 477 478 procedure TProcedureCall.GetValue(Index: Integer; out Value); 479 begin 480 if Index = 0 then TProcedure(Value) := ProcedureDef 481 else if Index = 1 then TExpressions(Value) := Params 482 else inherited; 483 end; 484 485 function TProcedureCall.GetField(Index: Integer): TField; 486 begin 487 if Index = 0 then Result := TField.Create(dtObject, 'Procedure') 488 else if Index = 1 then Result := TField.Create(dtObject, 'Parameters') 489 else inherited; 490 end; 491 492 procedure TProcedureCall.SetValue(Index: Integer; var Value); 493 begin 494 if Index = 0 then ProcedureDef := TProcedure(Value) 495 else if Index = 1 then Params := TExpressions(Value) 496 else inherited; 497 end; 498 499 constructor TProcedureCall.Create; 500 begin 501 Params := TExpressions.Create; 502 end; 503 504 destructor TProcedureCall.Destroy; 505 begin 506 FreeAndNil(Params); 507 inherited; 508 end; 509 510 { TProcedure } 511 512 function TProcedures.SearchByName(Name: string): TProcedure; 513 var 514 I: Integer; 515 begin 516 I := 0; 517 while (I < Count) and (TProcedure(Items[I]).Name <> Name) do Inc(I); 518 if I < Count then Result := TProcedure(Items[I]) 519 else Result := nil; 520 end; 521 522 function TProcedures.AddNew(Name: string): TProcedure; 523 begin 524 Result := TProcedure.Create; 525 Result.Name := Name; 526 Result.ParentType := ParentType; 527 Add(Result); 528 end; 529 530 function TProcedure.GetFieldsCount: Integer; 531 begin 532 Result := 3; 533 end; 534 535 procedure TProcedure.GetValue(Index: Integer; out Value); 536 begin 537 if Index = 0 then TBlock(Value) := Block 538 else if Index = 1 then TFunctionParameters(Value) := Params 539 else if Index = 2 then string(Value) := Name 540 else inherited; 541 end; 542 543 function TProcedure.GetField(Index: Integer): TField; 544 begin 545 if Index = 0 then Result := TField.Create(dtObject, 'Block') 546 else if Index = 1 then Result := TField.Create(dtList, 'Parameters') 547 else if Index = 2 then Result := TField.Create(dtString, 'Name') 548 else inherited; 549 end; 550 551 procedure TProcedure.SetValue(Index: Integer; var Value); 552 begin 553 if Index = 0 then Block := TBlock(Value) 554 else if Index = 1 then Params := TFunctionParameters(Value) 555 else if Index = 2 then Name := string(Value) 556 else inherited; 557 end; 558 559 constructor TProcedure.Create; 560 begin 561 Params := TFunctionParameters.Create; 562 Block := TBlock.Create; 563 end; 564 565 destructor TProcedure.Destroy; 566 begin 567 FreeAndNil(Block); 568 FreeAndNil(Params); 569 inherited; 570 end; 571 428 572 { TExpressionBrackets } 429 573 … … 771 915 if Index = 0 then TBlock(Value) := Block 772 916 else if Index = 1 then TFunctionParameters(Value) := Params 773 else if Index = 2 then TType(Value) := ResultType774 else if Index = 3 then string(Value) := Name917 else if Index = 2 then string(Value) := Name 918 else if Index = 3 then TType(Value) := ResultType 775 919 else inherited; 776 920 end; … … 780 924 if Index = 0 then Result := TField.Create(dtObject, 'Block') 781 925 else if Index = 1 then Result := TField.Create(dtList, 'Parameters') 782 else if Index = 2 then Result := TField.Create(dt Object, 'ResultType')783 else if Index = 3 then Result := TField.Create(dt String, 'Name')926 else if Index = 2 then Result := TField.Create(dtString, 'Name') 927 else if Index = 3 then Result := TField.Create(dtObject, 'ResultType') 784 928 else inherited; 785 929 end; … … 794 938 if Index = 0 then Block := TBlock(Value) 795 939 else if Index = 1 then Params := TFunctionParameters(Value) 796 else if Index = 2 then ResultType := TType(Value)797 else if Index = 3 then Name := string(Value)940 else if Index = 2 then Name := string(Value) 941 else if Index = 3 then ResultType := TType(Value) 798 942 else inherited; 799 943 end; … … 1052 1196 begin 1053 1197 if Index = 0 then Result := TField.Create(dtObject, 'Function') 1054 else if Index = 1 then Result := TField.Create(dt Object, 'Parameters')1198 else if Index = 1 then Result := TField.Create(dtList, 'Parameters') 1055 1199 else inherited; 1056 1200 end; … … 1139 1283 else if Index = 3 then TConstants(Value) := Constants 1140 1284 else if Index = 4 then TFunctions(Value) := Functions 1285 else if Index = 5 then TProcedures(Value) := Procedures 1141 1286 else inherited; 1142 1287 end; … … 1144 1289 function TBlock.GetField(Index: Integer): TField; 1145 1290 begin 1146 if Index = 0 then Result := TField.Create(dtObject, 'B lock')1291 if Index = 0 then Result := TField.Create(dtObject, 'BeginEnd') 1147 1292 else if Index = 1 then Result := TField.Create(dtList, 'Types') 1148 1293 else if Index = 2 then Result := TField.Create(dtList, 'Variables') 1149 1294 else if Index = 3 then Result := TField.Create(dtList, 'Constants') 1150 1295 else if Index = 4 then Result := TField.Create(dtList, 'Functions') 1296 else if Index = 5 then Result := TField.Create(dtList, 'Procedures') 1151 1297 else inherited; 1152 1298 end; … … 1154 1300 function TBlock.GetFieldsCount: Integer; 1155 1301 begin 1156 Result := 5;1302 Result := 6; 1157 1303 end; 1158 1304 … … 1164 1310 else if Index = 3 then Constants := TConstants(Value) 1165 1311 else if Index = 4 then Functions := TFunctions(Value) 1312 else if Index = 5 then Procedures := TProcedures(Value) 1166 1313 else inherited; 1167 1314 end; … … 1170 1317 begin 1171 1318 Functions.Clear; 1319 Procedures.Clear; 1172 1320 Constants.Clear; 1173 1321 Variables.Clear; … … 1201 1349 if not Assigned(Result) and Assigned(ParentBlock) then 1202 1350 Result := ParentBlock.GetFunction(Name); 1351 end; 1352 1353 function TBlock.GetProcedure(Name: string): TProcedure; 1354 begin 1355 Result := Procedures.SearchByName(Name); 1356 if not Assigned(Result) and Assigned(ParentBlock) then 1357 Result := ParentBlock.GetProcedure(Name); 1203 1358 end; 1204 1359 … … 1211 1366 Functions := TFunctions.Create; 1212 1367 Functions.Parent := Self; 1368 Procedures := TProcedures.Create; 1369 Procedures.Parent := Self; 1213 1370 Types := TTypes.Create; 1214 1371 Types.Parent := Self; … … 1224 1381 FreeAndNil(Constants); 1225 1382 FreeAndNil(Functions); 1383 FreeAndNil(Procedures); 1226 1384 inherited; 1227 1385 end; … … 1237 1395 function TBeginEnd.GetField(Index: Integer): TField; 1238 1396 begin 1239 if Index = 0 then Result := TField.Create(dtList, 'Command ')1397 if Index = 0 then Result := TField.Create(dtList, 'Commands') 1240 1398 else inherited; 1241 1399 end;
Note:
See TracChangeset
for help on using the changeset viewer.