@@ -420,58 +420,60 @@ public
420420
421421 function toString
422422 input Statement stmt;
423+ input String indent = "" ;
423424 output String str;
424425 algorithm
425426 str := match stmt
426427 local
427428 String s1, s2;
428429
429430 case ASSIGNMENT ()
430- then Expression . toString(stmt. lhs) + " := " + Expression . toString(stmt. rhs);
431+ then indent + Expression . toString(stmt. lhs) + " := " + Expression . toString(stmt. rhs) + ";" ;
431432
432433 case FUNCTION_ARRAY_INIT ()
433- then "array init " + stmt. name;
434+ then indent + "array init " + stmt. name;
434435
435436 case FOR ()
436437 algorithm
437438 s1 := if isSome(stmt. range) then " in " + Expression . toString(Util . getOption(stmt. range)) else "" ;
438- s2 := toStringList(stmt. body);
439+ s2 := toStringList(stmt. body, indent + " " );
439440 then
440- "for " + InstNode . name(stmt. iterator) + s1 + " loop \n " + s2 + "end for" ;
441+ indent + "for " + InstNode . name(stmt. iterator) + s1 + " loop \n " + s2 + indent + "end for; " ;
441442
442443 case IF ()
443- then branchString(listHead(stmt. branches), "if" , true ) +
444- stringDelimitList(list(branchString(b, "if" , false ) for b in listRest(stmt. branches)), " \n " ) +
445- " \n end if" ;
444+ then branchString(listHead(stmt. branches), "if" , indent, true ) +
445+ stringDelimitList(list(branchString(b, "if" , indent, false ) for b in listRest(stmt. branches)), " \n " ) +
446+ indent + "end if; " ;
446447
447448 case WHEN ()
448- then branchString(listHead(stmt. branches), "when" , true ) +
449- stringDelimitList(list(branchString(b, "when" , false ) for b in listRest(stmt. branches)), " \n " ) +
450- " \n when if" ;
449+ then branchString(listHead(stmt. branches), "when" , indent, true ) +
450+ stringDelimitList(list(branchString(b, "when" , indent, false ) for b in listRest(stmt. branches)), " \n " ) +
451+ indent + "when if; " ;
451452
452453 case ASSERT ()
453- then "assert(" + Expression . toString(stmt. condition) + ", " +
454- Expression . toString(stmt. message) + ", " + Expression . toString(stmt. level) + ")" ;
454+ then indent + "assert(" + Expression . toString(stmt. condition) + ", " +
455+ Expression . toString(stmt. message) + ", " + Expression . toString(stmt. level) + "); " ;
455456
456457 case TERMINATE ()
457- then "terminate( " + Expression . toString(stmt. message) + ")" ;
458+ then indent + "terminate( " + Expression . toString(stmt. message) + "); " ;
458459
459460 case NORETCALL ()
460- then Expression . toString(stmt. exp);
461+ then indent + Expression . toString(stmt. exp) + ";" ;
461462
462463 case WHILE ()
463- then "while " + Expression . toString(stmt. condition) + " then \n " +
464- toStringList(stmt. body) + " \n end while" ;
464+ then indent + "while " + Expression . toString(stmt. condition) + " then \n " +
465+ toStringList(stmt. body, indent + " " ) + " \n end while; " ;
465466
466- case RETURN () then "return" ;
467- case BREAK () then "break" ;
468- else "#UNKNOWN STATEMENT#" ;
467+ case RETURN () then indent + "return; " ;
468+ case BREAK () then indent + "break; " ;
469+ else indent + "#UNKNOWN STATEMENT#" ;
469470 end match;
470471 end toString;
471472
472473 function branchString
473474 input tuple< Expression , list< Statement >> branch;
474475 input String stmtType;
476+ input String indent;
475477 input Boolean firstBranch;
476478 output String str;
477479 protected
@@ -480,15 +482,16 @@ public
480482 algorithm
481483 (cond, body) := branch;
482484
483- str := (if firstBranch then stmtType elseif Expression . isTrue(cond) then "else" else "else" + stmtType) +
484- " " + Expression . toString(cond) + "then \n " + toStringList(body);
485+ str := indent + (if firstBranch then stmtType elseif Expression . isTrue(cond) then "else" else "else" + stmtType) +
486+ " " + Expression . toString(cond) + " then \n " + toStringList(body, indent + " " );
485487 end branchString;
486488
487489 function toStringList
488490 input list< Statement > stmtl;
491+ input String indent = "" ;
489492 output String str;
490493 algorithm
491- str := List . toString(stmtl, toString, "" , " " , " \n " , "" , false ) + " \n " ;
494+ str := List . toString(stmtl, function toString(indent = indent) , "" , "" , " \n " , "" , false ) + " \n " ;
492495 end toStringList;
493496
494497annotation(__OpenModelica_Interface= "frontend" );
0 commit comments