Changeset 232
- Timestamp:
- Jun 26, 2023, 12:51:06 PM (18 months ago)
- Location:
- branches/xpascal
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/xpascal/Generators/GeneratorPhp.pas
r230 r232 231 231 AddText('function ' + FunctionDef.Name + '('); 232 232 for I := 0 to FunctionDef.Params.Count - 1 do begin 233 if FunctionDef.Params[I].Kind = pkVar then 234 AddText('&'); 233 235 AddText('$' + TFunctionParameter(FunctionDef.Params[I]).Name); 234 236 if I > 0 then AddText(', '); … … 240 242 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('echo($Text."\n");') 241 243 else if FunctionDef.InternalName = 'Write' then AddTextLine('echo($Text);') 244 else if FunctionDef.InternalName = 'ReadLn' then AddTextLine('$Text = readline();') 245 else if FunctionDef.InternalName = 'Read' then AddTextLine('$Text = readline();') 242 246 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;') 243 247 else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return $Value;') -
branches/xpascal/Generators/GeneratorXml.pas
r231 r232 42 42 Field: TField; 43 43 Obj: TObject; 44 List: TSourceNodeList<TSourceNode>; 44 45 begin 45 if SourceNode = nil then begin46 end else47 if SourceNode is TSourceNodeList<TSourceNode> then begin48 GenerateNodes(TSourceNodeList<TSourceNode>(SourceNode))49 end else50 46 if SourceNode is TSourceNode then begin 51 47 AddTextLine('<' + SourceNode.ClassName + '>'); … … 57 53 if Obj is TSourceNode then 58 54 GenerateNode(TSourceNode(Obj)); 55 end else 56 if Field.DataType = dtList then begin 57 SourceNode.GetValue(I, List); 58 GenerateNodes(List); 59 59 end else 60 60 if Field.DataType = dtString then begin -
branches/xpascal/Optimizer.pas
r231 r232 55 55 Obj: TObject; 56 56 TempNewNode: TSourceNode; 57 ListValue: TSourceNodeList<TSourceNode>; 57 58 begin 58 59 NewNode := nil; 59 if SourceNode = nil then begin60 end else61 if SourceNode is TSourceNodeList<TSourceNode> then begin62 OptimizeNodes(TSourceNodeList<TSourceNode>(SourceNode), NewNode)63 end else64 60 if (ofReplaceRepeatUntilByWhileDo in Features) and (SourceNode is TRepeatUntil) then begin 65 61 WhileDo := TWhileDo.Create; … … 113 109 end else 114 110 raise Exception.Create(SUnsupportedNodeType); 111 112 for I := 0 to SourceNode.FieldsCount - 1 do begin 113 Field := SourceNode.GetField(I); 114 if Field.DataType = dtList then begin 115 SourceNode.GetValue(I, ListValue); 116 OptimizeNodes(TSourceNodeList<TSourceNode>(ListValue), NewNode) 117 end; 118 end; 115 119 end; 116 120 -
branches/xpascal/Source.pas
r231 r232 44 44 45 45 TType = class(TSourceNode) 46 pr ivate46 protected 47 47 function GetFieldsCount: Integer; override; 48 48 public … … 67 67 68 68 TVariable = class(TSourceNode) 69 pr ivate69 protected 70 70 function GetFieldsCount: Integer; override; 71 71 public … … 87 87 88 88 TConstant = class(TSourceNode) 89 pr ivate89 protected 90 90 function GetFieldsCount: Integer; override; 91 91 public … … 124 124 125 125 TFunction = class(TSourceNode) 126 pr ivate126 protected 127 127 function GetFieldsCount: Integer; override; 128 128 public … … 160 160 161 161 TFunctionCall = class(TCommand) 162 pr ivate162 protected 163 163 function GetFieldsCount: Integer; override; 164 164 public … … 175 175 176 176 TBeginEnd = class(TCommand) 177 pr ivate177 protected 178 178 function GetFieldsCount: Integer; override; 179 179 public … … 200 200 201 201 TExpressionOperation = class(TExpression) 202 pr ivate202 protected 203 203 function GetFieldsCount: Integer; override; 204 204 public … … 222 222 223 223 TExpressionOperand = class(TExpression) 224 pr ivate224 protected 225 225 function GetFieldsCount: Integer; override; 226 226 public … … 255 255 256 256 TAssignment = class(TCommand) 257 pr ivate257 protected 258 258 function GetFieldsCount: Integer; override; 259 259 public … … 270 270 271 271 TReturn = class(TCommand) 272 pr ivate272 protected 273 273 function GetFieldsCount: Integer; override; 274 274 public … … 284 284 285 285 TIfThenElse = class(TCommand) 286 pr ivate286 protected 287 287 function GetFieldsCount: Integer; override; 288 288 public … … 305 305 306 306 TWhileDo = class(TLoop) 307 pr ivate307 protected 308 308 function GetFieldsCount: Integer; override; 309 309 public … … 320 320 321 321 TRepeatUntil = class(TLoop) 322 pr ivate322 protected 323 323 function GetFieldsCount: Integer; override; 324 324 public … … 341 341 342 342 TForToDo = class(TLoop) 343 pr ivate343 protected 344 344 function GetFieldsCount: Integer; override; 345 345 public … … 358 358 359 359 TBlock = class(TSourceNode) 360 pr ivate360 protected 361 361 function GetFieldsCount: Integer; override; 362 362 public … … 382 382 383 383 TProgram = class(TSourceNode) 384 pr ivate384 protected 385 385 function GetFieldsCount: Integer; override; 386 386 public … … 571 571 begin 572 572 if Index = 0 then Result := TField.Create(dtObject, 'Expression') 573 else if Index = 1 then Result := TField.Create(dt Object, 'Commands')573 else if Index = 1 then Result := TField.Create(dtList, 'Commands') 574 574 else inherited; 575 575 end; … … 779 779 begin 780 780 if Index = 0 then Result := TField.Create(dtObject, 'Block') 781 else if Index = 1 then Result := TField.Create(dt Object, 'Parameters')781 else if Index = 1 then Result := TField.Create(dtList, 'Parameters') 782 782 else if Index = 2 then Result := TField.Create(dtObject, 'ResultType') 783 783 else if Index = 3 then Result := TField.Create(dtString, 'Name') … … 1145 1145 begin 1146 1146 if Index = 0 then Result := TField.Create(dtObject, 'Block') 1147 else if Index = 1 then Result := TField.Create(dt Object, 'Types')1148 else if Index = 2 then Result := TField.Create(dt Object, 'Variables')1149 else if Index = 3 then Result := TField.Create(dt Object, 'Constants')1150 else if Index = 4 then Result := TField.Create(dt Object, 'Functions')1147 else if Index = 1 then Result := TField.Create(dtList, 'Types') 1148 else if Index = 2 then Result := TField.Create(dtList, 'Variables') 1149 else if Index = 3 then Result := TField.Create(dtList, 'Constants') 1150 else if Index = 4 then Result := TField.Create(dtList, 'Functions') 1151 1151 else inherited; 1152 1152 end; … … 1237 1237 function TBeginEnd.GetField(Index: Integer): TField; 1238 1238 begin 1239 if Index = 0 then Result := TField.Create(dt Object, 'Command')1239 if Index = 0 then Result := TField.Create(dtList, 'Command') 1240 1240 else inherited; 1241 1241 end; -
branches/xpascal/SourceNode.pas
r231 r232 8 8 type 9 9 TDataType = (dtNone, dtString, dtBoolean, dtInteger, dtFloat, dtColor, 10 dtTime, dtDate, dtDateTime, dtEnumeration, dtObject );10 dtTime, dtDate, dtDateTime, dtEnumeration, dtObject, dtList); 11 11 12 12 { TField } … … 47 47 { TSourceNodeList } 48 48 49 TSourceNodeList<T > = class(TSourceNode)49 TSourceNodeList<T: TSourceNode> = class(TObjectList<T>) 50 50 private 51 51 Parent: TSourceNode; 52 function GetCount: Integer;53 function GetItem(Index: Integer): T;54 procedure SetItem(Index: Integer; AValue: T);55 public56 List: TObjectList<TSourceNode>;57 procedure Clear;58 function Add(AObject: T): Integer;59 constructor Create;60 destructor Destroy; override;61 property Items[Index: Integer]: T read GetItem write SetItem; default;62 property Count: Integer read GetCount;63 52 end; 64 53 … … 75 64 DataTypeStr: array[TDataType] of string = ('None', 'String', 'Boolean', 76 65 'Integer', 'Float', 'Color', 'Time', 'Date', 'DateTime', 'Enumeration', 77 'Reference' );66 'Reference', 'List'); 78 67 79 68 { TField } … … 83 72 DataType := ADataType; 84 73 Name := AName; 85 end;86 87 { TSourceNodeList }88 89 function TSourceNodeList<T>.GetCount: Integer;90 begin91 Result := List.Count;92 end;93 94 function TSourceNodeList<T>.GetItem(Index: Integer): T;95 begin96 Result := T(List[Index]);97 end;98 99 procedure TSourceNodeList<T>.SetItem(Index: Integer; AValue: T);100 begin101 List[Index] := AValue;102 end;103 104 procedure TSourceNodeList<T>.Clear;105 begin106 List.Clear;107 end;108 109 function TSourceNodeList<T>.Add(AObject: T): Integer;110 begin111 Result := List.Add(AObject);112 end;113 114 constructor TSourceNodeList<T>.Create;115 begin116 List := TObjectList<TSourceNode>.Create;117 end;118 119 destructor TSourceNodeList<T>.Destroy;120 begin121 FreeAndNil(List);122 inherited;123 74 end; 124 75
Note:
See TracChangeset
for help on using the changeset viewer.