Skip to content

Commit

Permalink
[NF] Enable flat output with instantiateModel.
Browse files Browse the repository at this point in the history
- Break out the instantiateModel handling from
  CevalScriptBackend.cevalInteractiveFunctions3 to its own function and
  make it handle flat modelica output when -f is set.
- Change NFInst.instClassInProgram to return NF structures instead of
  DAE, and convert to DAE in CevalScriptBackend.runFrontEndWork instead.
- Rename getCommentsFromSource to getComments in ElementSource, since
  the FromSource part can be inferred from it being in ElementSource.
- Added ElementSource.getOptComment to fetch the first added comment.
- Simplify flat model handling by changing the Comment in FlatModel into
  a ElementSource, to also embed the SourceInfo in the flat model.
- Remove the name of the class from all the execStat calls in the NF
  except for the first to simplify the interface between the modules,
  since it doesn't provide any extra information.
  • Loading branch information
perost committed May 25, 2020
1 parent edc4067 commit 5c1cf16
Show file tree
Hide file tree
Showing 16 changed files with 244 additions and 146 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/FrontEnd/Algorithm.mo
Expand Up @@ -288,7 +288,7 @@ algorithm
case DAE.CALL(attr=DAE.CALL_ATTR(builtin=true), path=Absyn.IDENT("listAppend"), expLst=(e1 as DAE.CREF())::_)
guard Expression.expEqual(lhs, e1)
algorithm
if Flags.isSet(Flags.LIST_REVERSE_WRONG_ORDER) and not max(SCodeUtil.commentHasBooleanNamedAnnotation(comment, "__OpenModelica_DisableListAppendWarning") for comment in ElementSource.getCommentsFromSource(source)) then
if Flags.isSet(Flags.LIST_REVERSE_WRONG_ORDER) and not max(SCodeUtil.commentHasBooleanNamedAnnotation(comment, "__OpenModelica_DisableListAppendWarning") for comment in ElementSource.getComments(source)) then
Error.addSourceMessage(Error.LIST_REVERSE_WRONG_ORDER, {ExpressionDump.printExpStr(e1)}, ElementSource.getElementSourceFileInfo(source));
fail();
end if;
Expand Down
64 changes: 32 additions & 32 deletions OMCompiler/Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -989,7 +989,7 @@ algorithm

case (DAE.INITIAL_ASSERT(condition=e1,message = e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -1000,7 +1000,7 @@ algorithm

case (DAE.INITIAL_TERMINATE(message=e1,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s = stringAppendList({" terminate(",s1,") ", sourceStr, ";\n"});
Expand Down Expand Up @@ -1035,7 +1035,7 @@ algorithm

case (DAE.EQUATION(exp = e1,scalar = e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -1045,7 +1045,7 @@ algorithm

case (DAE.EQUEQUATION(cr1=cr1,cr2=cr2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ComponentReference.printComponentRefStr(cr1);
s2 = ComponentReference.printComponentRefStr(cr2);
Expand All @@ -1055,7 +1055,7 @@ algorithm

case(DAE.ARRAY_EQUATION(exp=e1,array=e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -1065,7 +1065,7 @@ algorithm

case(DAE.COMPLEX_EQUATION(lhs=e1,rhs=e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -1075,7 +1075,7 @@ algorithm

case (DAE.DEFINE(componentRef = c,exp = e,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ComponentReference.printComponentRefStr(c);
s2 = stringAppend(" ", s1);
Expand All @@ -1088,7 +1088,7 @@ algorithm

case (DAE.ASSERT(condition=e1,message = e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -1098,7 +1098,7 @@ algorithm

case (DAE.TERMINATE(message=e1,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
str = stringAppendList({" terminate(",s1,") ", sourceStr, ";\n"});
Expand All @@ -1107,7 +1107,7 @@ algorithm

case (DAE.NORETCALL(exp=e1,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
str = stringAppendList({" ", s1, sourceStr, ";\n"});
Expand Down Expand Up @@ -3847,7 +3847,7 @@ algorithm

case (DAE.DEFINE(componentRef = c,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ComponentReference.printComponentRefStr(c);
str = stringAppend(s1, sourceStr + ";\n");
Expand All @@ -3856,7 +3856,7 @@ algorithm

case (DAE.INITIALDEFINE(componentRef = c,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ComponentReference.printComponentRefStr(c);
str = stringAppend(s1, sourceStr + ";\n");
Expand All @@ -3865,7 +3865,7 @@ algorithm

case (DAE.EQUATION(exp = e1,scalar = e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -3875,7 +3875,7 @@ algorithm

case (DAE.EQUEQUATION(cr1=cr1,cr2=cr2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ComponentReference.printComponentRefStr(cr1);
s2 = ComponentReference.printComponentRefStr(cr2);
Expand All @@ -3885,7 +3885,7 @@ algorithm

case(DAE.ARRAY_EQUATION(exp=e1,array=e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -3895,7 +3895,7 @@ algorithm

case(DAE.INITIAL_ARRAY_EQUATION(exp=e1,array=e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -3905,7 +3905,7 @@ algorithm

case(DAE.COMPLEX_EQUATION(lhs=e1,rhs=e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -3915,7 +3915,7 @@ algorithm

case(DAE.INITIAL_COMPLEX_EQUATION(lhs=e1,rhs=e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -3925,7 +3925,7 @@ algorithm

case (DAE.WHEN_EQUATION(condition = e1,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
str = stringAppendList({"WHEN_EQUATION: ", s1, sourceStr, ";\n"});
Expand All @@ -3934,23 +3934,23 @@ algorithm

case (DAE.IF_EQUATION(source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
str = stringAppendList({"IF_EQUATION: ", sourceStr, ";\n"});
then
str;

case (DAE.INITIAL_IF_EQUATION(source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
str = stringAppendList({"INITIAL_IF_EQUATION: ", sourceStr, ";\n"});
then
str;

case (DAE.INITIALEQUATION(exp1 = e1,exp2 = e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -3960,23 +3960,23 @@ algorithm

case (DAE.ALGORITHM(source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
str = stringAppendList({"ALGO ", sourceStr, ";\n"});
then
str;

case (DAE.INITIALALGORITHM(source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
str = stringAppendList({"INITIALALGORITHM ", sourceStr, ";\n"});
then
str;

case (DAE.COMP(source = src, dAElist = elst))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = stringDelimitList(List.map(elst,DAEDump.dumpDebugElementStr),"\n");
str = stringAppendList({"COMP ",s1, sourceStr, ";\n"});
Expand All @@ -3985,7 +3985,7 @@ algorithm

case (DAE.EXTOBJECTCLASS(path = path, source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = AbsynUtil.pathString(path);
str = stringAppendList({"EXTOBJ ",s1," ", sourceStr, ";\n"});
Expand All @@ -3994,7 +3994,7 @@ algorithm

case (DAE.ASSERT(condition=e1,message = e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -4004,7 +4004,7 @@ algorithm

case (DAE.INITIAL_ASSERT(condition=e1,message = e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
Expand All @@ -4014,7 +4014,7 @@ algorithm

case (DAE.TERMINATE(message=e1,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
str = stringAppendList({" terminate(",s1,") ", sourceStr, ";\n"});
Expand All @@ -4023,7 +4023,7 @@ algorithm

case (DAE.INITIAL_TERMINATE(message=e1,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
str = stringAppendList({" /* initial */ terminate(",s1,") ", sourceStr, ";\n"});
Expand All @@ -4032,15 +4032,15 @@ algorithm

case (DAE.REINIT(source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
str = stringAppendList({" reinit(",") ", sourceStr, ";\n"});
then
str;

case (DAE.NORETCALL(exp=e1,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
cmt = ElementSource.getComments(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
str = stringAppendList({" ", s1, sourceStr, ";\n"});
Expand Down
16 changes: 14 additions & 2 deletions OMCompiler/Compiler/FrontEnd/ElementSource.mo
Expand Up @@ -137,7 +137,7 @@ algorithm
end match;
end addAnnotation;

function getCommentsFromSource
function getComments
input DAE.ElementSource source;
output list<SCode.Comment> outComments;
algorithm
Expand All @@ -148,7 +148,19 @@ algorithm
case (DAE.SOURCE(comment = comment)) then comment;

end match;
end getCommentsFromSource;
end getComments;

function getOptComment
"Returns the first added comment if there is one, otherwise NONE."
input DAE.ElementSource source;
output Option<SCode.Comment> outComment;
algorithm
if not listEmpty(source.comment) then
outComment := SOME(List.last(source.comment));
else
outComment := NONE();
end if;
end getOptComment;

function addSymbolicTransformation
input output DAE.ElementSource source;
Expand Down
5 changes: 3 additions & 2 deletions OMCompiler/Compiler/Main/Main.mo
Expand Up @@ -444,7 +444,7 @@ algorithm

Print.clearBuf();
execStat("Transformations before Dump");
s := if Config.silent() or Flags.getConfigBool(Flags.FLAT_MODELICA) then "" else DAEDump.dumpStr(d, funcs);
s := if Config.silent() or Config.flatModelica() then "" else DAEDump.dumpStr(d, funcs);
execStat("DAEDump done");
Print.printBuf(s);
if Flags.isSet(Flags.DAE_DUMP_GRAPHV) then
Expand Down Expand Up @@ -530,7 +530,8 @@ algorithm
// If no class was explicitly specified, instantiate the last class in the
// program. Otherwise, instantiate the given class name.
cname := if stringEmpty(cls) then AbsynUtil.lastClassname(SymbolTable.getAbsyn()) else AbsynUtil.stringPath(cls);
(cache, env, SOME(dae)) := CevalScriptBackend.runFrontEnd(FCore.emptyCache(), FGraph.empty(), cname, true);
(cache, env, SOME(dae)) := CevalScriptBackend.runFrontEnd(FCore.emptyCache(),
FGraph.empty(), cname, relaxedFrontEnd = true, dumpFlat = Config.flatModelica());
end instantiate;

protected function optimizeDae
Expand Down
6 changes: 2 additions & 4 deletions OMCompiler/Compiler/NFFrontEnd/NFConvertDAE.mo
Expand Up @@ -70,8 +70,6 @@ public
function convert
input FlatModel flatModel;
input FunctionTree functions;
input String name;
input SourceInfo info;
output DAE.DAElist dae;
output DAE.FunctionTree daeFunctions;
protected
Expand All @@ -86,10 +84,10 @@ algorithm
elems := convertAlgorithms(flatModel.algorithms, elems);
elems := convertInitialAlgorithms(flatModel.initialAlgorithms, elems);

class_elem := DAE.COMP(name, elems, ElementSource.createElementSource(info), flatModel.comment);
class_elem := DAE.COMP(flatModel.name, elems, flatModel.source, ElementSource.getOptComment(flatModel.source));
dae := DAE.DAE({class_elem});

execStat(getInstanceName() + "(" + name + ")");
execStat(getInstanceName());
end convert;

protected
Expand Down
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFlatModel.mo
Expand Up @@ -49,6 +49,7 @@ protected
import NFClassTree.ClassTree;
import Component = NFComponent;
import NFComponentRef.ComponentRef;
import DAE.ElementSource;
import MetaModelica.Dangerous.listReverseInPlace;

import FlatModel = NFFlatModel;
Expand Down Expand Up @@ -90,7 +91,7 @@ public
list<Equation> initialEquations;
list<Algorithm> algorithms;
list<Algorithm> initialAlgorithms;
Option<SCode.Comment> comment;
ElementSource source;
end FLAT_MODEL;

function toString
Expand Down

0 comments on commit 5c1cf16

Please sign in to comment.