@@ -51,6 +51,13 @@ public
5151 Variability conditionVar;
5252 list< Equation > body;
5353 end BRANCH ;
54+
55+ function toString
56+ input Branch branch;
57+ output String str;
58+ algorithm
59+ str := Expression . toString(branch. condition) + " then \n " + toStringList(branch. body);
60+ end toString;
5461 end Branch ;
5562
5663 record EQUALITY
@@ -518,5 +525,66 @@ public
518525 end match;
519526 end foldExp;
520527
528+ function toString
529+ input Equation eq;
530+ output String str;
531+ algorithm
532+ str := match eq
533+ local
534+ String s1, s2;
535+
536+ case EQUALITY ()
537+ then Expression . toString(eq. lhs) + " = " + Expression . toString(eq. rhs);
538+
539+ case CREF_EQUALITY ()
540+ then ComponentRef . toString(eq. lhs) + " = " + ComponentRef . toString(eq. rhs);
541+
542+ case ARRAY_EQUALITY ()
543+ then Expression . toString(eq. lhs) + " = " + Expression . toString(eq. rhs);
544+
545+ case CONNECT ()
546+ then "connect(" + Expression . toString(eq. lhs) + ", " + Expression . toString(eq. rhs) + ")" ;
547+
548+ case FOR ()
549+ algorithm
550+ s1 := if isSome(eq. range) then " in " + Expression . toString(Util . getOption(eq. range)) else "" ;
551+ s2 := toStringList(eq. body);
552+ then
553+ "for " + InstNode . name(eq. iterator) + s1 + " loop \n " + s2 + "end for" ;
554+
555+ case IF ()
556+ then "if " + Branch . toString(listHead(eq. branches)) +
557+ List . toString(listRest(eq. branches), Branch . toString, "" , "elseif " , " \n elseif " , "" , false ) +
558+ " \n end if" ;
559+
560+ case WHEN ()
561+ then "when " + Branch . toString(listHead(eq. branches)) +
562+ List . toString(listRest(eq. branches), Branch . toString, "" , "elsewhen " , " \n elsewhen " , "" , false ) +
563+ " \n end when" ;
564+
565+ case ASSERT ()
566+ then "assert(" + Expression . toString(eq. condition) + ", " +
567+ Expression . toString(eq. message) + ", " + Expression . toString(eq. level) + ")" ;
568+
569+ case TERMINATE ()
570+ then "terminate( " + Expression . toString(eq. message) + ")" ;
571+
572+ case REINIT ()
573+ then "reinit(" + Expression . toString(eq. cref) + ", " + Expression . toString(eq. reinitExp) + ")" ;
574+
575+ case NORETCALL ()
576+ then Expression . toString(eq. exp);
577+
578+ else "#UNKNOWN EQUATION#" ;
579+ end match;
580+ end toString;
581+
582+ function toStringList
583+ input list< Equation > eql;
584+ output String str;
585+ algorithm
586+ str := List . toString(eql, toString, "" , " " , " \n " , "" , false ) + " \n " ;
587+ end toStringList;
588+
521589annotation(__OpenModelica_Interface= "frontend" );
522590end NFEquation ;
0 commit comments