Changeset 213 for branches/interpreter2/UGeneratorCSharp.pas
- Timestamp:
- Apr 22, 2020, 10:23:31 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter2/UGeneratorCSharp.pas
r212 r213 20 20 procedure GenerateBlockVar(ParentBlock: TBlock; Block: TBlock); 21 21 procedure GenerateBlockFunctions(ParentBlock: TBlock; Block: TBlock); 22 procedure GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd );22 procedure GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd; Enclosed: Boolean = True); 23 23 procedure GenerateCommand(Block: TBlock; Command: TCommand); 24 24 procedure GenerateIfThenElse(Block: TBlock; IfThenElse: TIfThenElse); … … 33 33 procedure GenerateBreak(Block: TBlock; BreakCmd: TBreak); 34 34 procedure GenerateContinue(Block: TBlock; ContinueCmd: TContinue); 35 procedure GenerateReturn(Block: TBlock; Return: TReturn); 35 36 procedure GenerateTypeRef(TypeRef: TType); 36 37 procedure GenerateValue(Value: TValue); … … 55 56 else if Command is TBreak then GenerateBreak(Block, TBreak(Command)) 56 57 else if Command is TContinue then GenerateContinue(Block, TContinue(Command)) 58 else if Command is TReturn then GenerateReturn(Block, TReturn(Command)) 57 59 else if Command is TEmptyCommand then 58 60 else raise Exception.Create('Unsupported command type'); … … 184 186 end; 185 187 188 procedure TGeneratorCSharp.GenerateReturn(Block: TBlock; Return: TReturn); 189 begin 190 AddText('return '); 191 GenerateExpression(Block, Return.Expression); 192 end; 193 186 194 procedure TGeneratorCSharp.GenerateTypeRef(TypeRef: TType); 187 195 begin … … 209 217 AddTextLine('{'); 210 218 Indent := Indent + 1; 219 GenerateBlockFunctions(nil, Prog.SystemBlock); 211 220 GenerateBlock(nil, Prog.SystemBlock); 212 221 AddTextLine('public static void Main()'); … … 216 225 AddTextLine('}'); 217 226 AddTextLine(); 227 GenerateBlockFunctions(Prog.Block, Prog.Block); 218 228 AddTextLine('public void Entry()'); 219 229 GenerateBlock(Block, Prog.Block); … … 223 233 224 234 procedure TGeneratorCSharp.GenerateBlock(ParentBlock: TBlock; Block: TBlock); 225 begin 226 GenerateBlockVar(Block, Block); 227 GenerateBlockConst(Block, Block); 228 GenerateBlockFunctions(Block, Block); 235 var 236 I: Integer; 237 begin 229 238 if Block.BeginEnd.Commands.Count > 0 then begin 230 GenerateBeginEnd(ParentBlock, Block.BeginEnd); 231 AddTextLine; 239 AddTextLine('{'); 240 Indent := Indent + 1; 241 GenerateBlockVar(Block, Block); 242 GenerateBlockConst(Block, Block); 243 GenerateBeginEnd(ParentBlock, Block.BeginEnd, False); 244 Indent := Indent - 1; 245 AddTextLine('}'); 232 246 end; 233 247 end; … … 245 259 AddTextLine(';'); 246 260 end; 261 if Block.Constants.Count > 0 then AddTextLine; 247 262 end; 248 263 … … 251 266 I: Integer; 252 267 Variable: TVariable; 253 begin 254 if Block.Variables.Count > 0 then begin 268 VarCount: Integer; 269 begin 270 VarCount := 0; 271 for I := 0 to Block.Variables.Count - 1 do 272 if not TVariable(Block.Variables[I]).Internal then Inc(VarCount); 273 if VarCount > 0 then begin 255 274 for I := 0 to Block.Variables.Count - 1 do 256 275 if not TVariable(Block.Variables[I]).Internal then begin … … 259 278 AddTextLine(' ' + Variable.Name + ';'); 260 279 end; 261 AddTextLine;262 end;280 end; 281 if VarCount > 0 then AddTextLine; 263 282 end; 264 283 … … 310 329 end; 311 330 312 procedure TGeneratorCSharp.GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd); 313 var 314 I: Integer; 315 begin 316 AddTextLine('{'); 317 Indent := Indent + 1; 331 procedure TGeneratorCSharp.GenerateBeginEnd(Block: TBlock; BeginEnd: TBeginEnd; Enclosed: Boolean = True); 332 var 333 I: Integer; 334 begin 335 if Enclosed then begin 336 AddTextLine('{'); 337 Indent := Indent + 1; 338 end; 318 339 for I := 0 to BeginEnd.Commands.Count - 1 do begin 319 340 GenerateCommand(Block, TCommand(BeginEnd.Commands[I])); 320 341 AddTextLine(';'); 321 342 end; 322 Indent := Indent - 1; 323 AddText('}'); 343 if Enclosed then begin 344 Indent := Indent - 1; 345 AddText('}'); 346 end; 324 347 end; 325 348
Note:
See TracChangeset
for help on using the changeset viewer.