Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 8ffc95a

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve functions called through components.
- Clone all classes except operators (because operators are special and cloning them causes typing loops) when instantiating a class tree, to ensure that classes inside of instantiated components have unique caches. - Remove cloning of extends nodes, since cloning all classes makes that unnecessary. - Implemented Statement.toString for debugging. Belonging to [master]: - #2815 - OpenModelica/OpenModelica-testsuite#1085
1 parent e7d386d commit 8ffc95a

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed

Compiler/NFFrontEnd/NFClassTree.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@ public
554554
// Copy the local classes into the new class array, and set the
555555
// class we're instantiating to be their parent.
556556
for c in old_clss loop
557+
if not InstNode.isOperator(c) then
558+
c := InstNode.clone(c);
559+
end if;
560+
557561
c := InstNode.setParent(clsNode, c);
558562

559563
// If the class is outer, check that it's valid and link it with

Compiler/NFFrontEnd/NFInst.mo

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ algorithm
431431
checkExtendsLoop(base_node, base_path, info);
432432
checkReplaceableBaseClass(base_nodes, base_path, info);
433433
base_node := expand(base_node);
434-
base_node := InstNode.clone(base_node);
435434

436435
ext := InstNode.setNodeType(InstNodeType.BASE_CLASS(scope, def), base_node);
437436

@@ -657,7 +656,6 @@ algorithm
657656
end if;
658657

659658
ext_node := expand(ext_node);
660-
ext_node := InstNode.clone(ext_node);
661659

662660
// Fetch the needed information from the class definition and construct a EXPANDED_DERIVED.
663661
cls := InstNode.getClass(node);

Compiler/NFFrontEnd/NFInstNode.mo

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,17 @@ uniontype InstNode
442442
end while;
443443
end hasParentExpandableConnector;
444444

445+
function isOperator
446+
input InstNode node;
447+
output Boolean op;
448+
algorithm
449+
op := match node
450+
case CLASS_NODE() then SCode.isOperator(node.definition);
451+
case INNER_OUTER_NODE() then isOperator(node.innerNode);
452+
else false;
453+
end match;
454+
end isOperator;
455+
445456
function name
446457
input InstNode node;
447458
output String name;

Compiler/NFFrontEnd/NFStatement.mo

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,78 @@ public
418418
end match;
419419
end foldExp;
420420

421+
function toString
422+
input Statement stmt;
423+
output String str;
424+
algorithm
425+
str := match stmt
426+
local
427+
String s1, s2;
428+
429+
case ASSIGNMENT()
430+
then Expression.toString(stmt.lhs) + " := " + Expression.toString(stmt.rhs);
431+
432+
case FUNCTION_ARRAY_INIT()
433+
then "array init " + stmt.name;
434+
435+
case FOR()
436+
algorithm
437+
s1 := if isSome(stmt.range) then " in " + Expression.toString(Util.getOption(stmt.range)) else "";
438+
s2 := toStringList(stmt.body);
439+
then
440+
"for " + InstNode.name(stmt.iterator) + s1 + " loop\n" + s2 + "end for";
441+
442+
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+
"\nend if";
446+
447+
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+
"\nwhen if";
451+
452+
case ASSERT()
453+
then "assert(" + Expression.toString(stmt.condition) + ", " +
454+
Expression.toString(stmt.message) + ", " + Expression.toString(stmt.level) + ")";
455+
456+
case TERMINATE()
457+
then "terminate( " + Expression.toString(stmt.message) + ")";
458+
459+
case NORETCALL()
460+
then Expression.toString(stmt.exp);
461+
462+
case WHILE()
463+
then "while " + Expression.toString(stmt.condition) + " then\n" +
464+
toStringList(stmt.body) + "\nend while";
465+
466+
case RETURN() then "return";
467+
case BREAK() then "break";
468+
else "#UNKNOWN STATEMENT#";
469+
end match;
470+
end toString;
471+
472+
function branchString
473+
input tuple<Expression, list<Statement>> branch;
474+
input String stmtType;
475+
input Boolean firstBranch;
476+
output String str;
477+
protected
478+
Expression cond;
479+
list<Statement> body;
480+
algorithm
481+
(cond, body) := branch;
482+
483+
str := (if firstBranch then stmtType elseif Expression.isTrue(cond) then "else" else "else" + stmtType) +
484+
" " + Expression.toString(cond) + "then\n" + toStringList(body);
485+
end branchString;
486+
487+
function toStringList
488+
input list<Statement> stmtl;
489+
output String str;
490+
algorithm
491+
str := List.toString(stmtl, toString, "", " " , "\n ", "", false) + "\n";
492+
end toStringList;
493+
421494
annotation(__OpenModelica_Interface="frontend");
422495
end NFStatement;

0 commit comments

Comments
 (0)