Skip to content

Commit

Permalink
[NF] Flat modelica improvements.
Browse files Browse the repository at this point in the history
- Quote record calls.
- Print the whole path of complex type names, not just the node name.
- Collect and dump record and enumeration types that are used in the
  flat model.
  • Loading branch information
perost committed Apr 8, 2020
1 parent c5be668 commit 0d25be9
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 14 deletions.
66 changes: 66 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFClass.mo
Expand Up @@ -47,7 +47,9 @@ protected
import NFBinding.Binding;
import ComplexType = NFComplexType;
import System;
import AbsynUtil;
import SCodeUtil;
import IOStream;

public

Expand Down Expand Up @@ -692,6 +694,70 @@ uniontype Class
end if;
end hasOperator;

function toFlatStream
input Class cls;
input InstNode clsNode;
input output IOStream.IOStream s;
protected
String name;
algorithm
name := AbsynUtil.pathString(InstNode.scopePath(clsNode));

s := match cls
case INSTANCED_CLASS()
algorithm
s := IOStream.append(s, Restriction.toString(cls.restriction));
s := IOStream.append(s, " '");
s := IOStream.append(s, name);
s := IOStream.append(s, "'\n");

for comp in ClassTree.getComponents(cls.elements) loop
s := IOStream.append(s, " ");
s := IOStream.append(s, InstNode.toFlatString(comp));
s := IOStream.append(s, ";\n");
end for;

s := IOStream.append(s, "end '");
s := IOStream.append(s, name);
s := IOStream.append(s, "'");
then
s;

case INSTANCED_BUILTIN()
algorithm
s := IOStream.append(s, "INSTANCED_BUILTIN(");
s := IOStream.append(s, name);
s := IOStream.append(s, ")");
then
s;

case TYPED_DERIVED()
algorithm
s := IOStream.append(s, Restriction.toString(cls.restriction));
s := IOStream.append(s, " '");
s := IOStream.append(s, name);
s := IOStream.append(s, "' = '");
s := IOStream.append(s, AbsynUtil.pathString(InstNode.scopePath(cls.baseClass)));
s := IOStream.append(s, "'");
then
s;

else IOStream.append(s, "UNKNOWN_CLASS(" + name + ")");
end match;
end toFlatStream;

function toFlatString
input Class cls;
input InstNode clsNode;
output String str;
protected
IOStream.IOStream s;
algorithm
s := IOStream.create(getInstanceName(), IOStream.IOStreamType.LIST());
s := toFlatStream(cls, clsNode, s);
str := IOStream.string(s);
IOStream.delete(s);
end toFlatString;
end Class;

annotation(__OpenModelica_Interface="frontend");
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -1668,7 +1668,7 @@ public
) + ":" + operandFlatString(exp.stop, exp, false);

case TUPLE() then "(" + stringDelimitList(list(toFlatString(e) for e in exp.elements), ", ") + ")";
case RECORD() then List.toString(exp.elements, toFlatString, AbsynUtil.pathString(exp.path), "(", ", ", ")", true);
case RECORD() then List.toString(exp.elements, toFlatString, "'" + AbsynUtil.pathString(exp.path), "'(", ", ", ")", true);
case CALL() then Call.toFlatString(exp.call);
case SIZE() then "size(" + toFlatString(exp.exp) +
(
Expand Down

0 comments on commit 0d25be9

Please sign in to comment.