Changeset 212 for branches/interpreter2/UGeneratorPhp.pas
- Timestamp:
- Apr 22, 2020, 12:04:22 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter2/UGeneratorPhp.pas
r208 r212 15 15 private 16 16 procedure GenerateProgram(Block: TBlock; Prog:TProgram); 17 procedure GenerateFunction(ParentBlock: TBlock; FunctionDef: TFunction); 17 18 procedure GenerateBlock(ParentBlock: TBlock; Block: TBlock); 18 19 procedure GenerateBlockConst(ParentBlock: TBlock; Block: TBlock); … … 201 202 end; 202 203 204 procedure TGeneratorPhp.GenerateFunction(ParentBlock: TBlock; 205 FunctionDef: TFunction); 206 var 207 I: Integer; 208 begin 209 AddText('function ' + FunctionDef.Name + '('); 210 for I := 0 to FunctionDef.Params.Count - 1 do begin 211 AddText('$' + TFunctionParameter(FunctionDef.Params[I]).Name); 212 if I > 0 then AddText(', '); 213 end; 214 AddTextLine(')'); 215 if FunctionDef.InternalName <> '' then begin 216 AddTextLine('{'); 217 Indent := Indent + 1; 218 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('echo($Text."\n");') 219 else if FunctionDef.InternalName = 'Write' then AddTextLine('echo($Text);') 220 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;') 221 else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return $Value;'); 222 Indent := Indent - 1; 223 AddTextLine('}'); 224 end else begin 225 GenerateBlock(ParentBlock, FunctionDef.Block); 226 AddTextLine; 227 end; 228 end; 229 203 230 procedure TGeneratorPhp.GenerateBlock(ParentBlock: TBlock; Block: TBlock); 204 231 begin … … 228 255 var 229 256 I: Integer; 230 J: Integer;231 FunctionDef: TFunction;232 257 begin 233 258 for I := 0 to Block.Functions.Count - 1 do begin 234 FunctionDef := TFunction(Block.Functions[I]); 235 AddText('function ' + FunctionDef.Name + '('); 236 for J := 0 to FunctionDef.Params.Count - 1 do begin 237 AddText('$' + TFunctionParameter(FunctionDef.Params[J]).Name); 238 if J > 0 then AddText(', '); 239 end; 240 AddTextLine(')'); 241 if FunctionDef.InternalName <> '' then begin 242 AddTextLine('{'); 243 Indent := Indent + 1; 244 if FunctionDef.InternalName = 'WriteLn' then AddTextLine('echo($Text."\n");') 245 else if FunctionDef.InternalName = 'Write' then AddTextLine('echo($Text);') 246 else if FunctionDef.InternalName = 'IntToStr' then AddTextLine('return $Value;') 247 else if FunctionDef.InternalName = 'StrToInt' then AddTextLine('return $Value;'); 248 Indent := Indent - 1; 249 AddTextLine('}'); 250 end else begin 251 GenerateBeginEnd(ParentBlock, FunctionDef.BeginEnd); 252 AddTextLine; 253 end; 259 GenerateFunction(ParentBlock, TFunction(Block.Functions[I])); 254 260 AddTextLine; 255 261 end;
Note:
See TracChangeset
for help on using the changeset viewer.