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

Commit

Permalink
[FMI2] Copy resources into the FMU
Browse files Browse the repository at this point in the history
Also fixes some other issues:
- Annotations are now inherited when handling for example derivative
  and inline annotations (for functions only)
- Assertions in FMUs (using omc_assert) now print to the FMI logger

Belonging to [master]:
  - #2116
  - OpenModelica/OpenModelica-testsuite#829
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jan 29, 2018
1 parent 103b435 commit 1b2f2b9
Show file tree
Hide file tree
Showing 34 changed files with 548 additions and 162 deletions.
3 changes: 3 additions & 0 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -377,6 +377,9 @@ public uniontype Element
list<Element> dAElist "a component with subelements";
end SM_COMP;

record COMMENT
SCode.Comment cmt "Functions store the inherited class annotations in the DAE";
end COMMENT;

end Element;

Expand Down
9 changes: 8 additions & 1 deletion Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -2748,11 +2748,13 @@ algorithm
IOStream.IOStream str;
list<DAE.Element> v,o,ie,ia,e,a,ca,co;
list<compWithSplitElements> sm;
list<SCode.Comment> comments;
Option<SCode.Annotation> ann;

case (_, str)
equation
// classify DAE
(v,ie,ia,e,a,_,co,_,sm) = DAEUtil.splitElements(l);
(v,ie,ia,e,a,_,co,_,sm,comments) = DAEUtil.splitElements(l);

// dump components with split elements (e.g., state machines)
str = dumpCompWithSplitElementsStream(sm, str);
Expand All @@ -2772,6 +2774,11 @@ algorithm

str = IOStream.append(str, if listEmpty(co) then "" else "constraint\n");
str = dumpConstraintStream(co, str);

str = IOStream.append(str, stringAppendList(list(match cmt
case SCode.COMMENT(annotation_=ann as SOME(_))
then SCodeDump.printCommentStr(SCode.COMMENT(ann,NONE()));
else ""; end match for cmt in comments)));
then
str;
end match;
Expand Down
18 changes: 17 additions & 1 deletion Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -1771,6 +1771,16 @@ algorithm
end match;
end isFunctionRefVar;

function isComment
input DAE.Element elt;
output Boolean b;
algorithm
b := match elt
case DAE.COMMENT(__) then true;
else false;
end match;
end isComment;

public function isAlgorithm "author: LS
Succeeds if Element is an algorithm."
input DAE.Element inElement;
Expand Down Expand Up @@ -2304,7 +2314,6 @@ algorithm
list<list<DAE.Element>> trueBranches, trueBranches_1;
Boolean partialPrefix;
list<DAE.FunctionDefinition> derFuncs;
DAE.InlineType inlineType;
DAE.ElementSource source "the element origin";
DAE.Algorithm alg;

Expand Down Expand Up @@ -4283,6 +4292,8 @@ algorithm
then
();

case DAE.COMMENT()
then ();
else
equation
Error.addMessage(Error.INTERNAL_ERROR,
Expand Down Expand Up @@ -5096,6 +5107,7 @@ public function splitElements
output list<DAE.Element> constraints = {};
output list<DAE.Element> externalObjects = {};
output list<DAEDump.compWithSplitElements> stateMachineComps = {};
output list<SCode.Comment> comments = {};
protected
DAEDump.compWithSplitElements split_comp;
algorithm
Expand Down Expand Up @@ -5170,6 +5182,10 @@ algorithm
stateMachineComps := split_comp :: stateMachineComps;
then
();

case DAE.COMMENT()
algorithm comments := e.cmt :: comments; then ();

else
algorithm
Error.addInternalError("DAEUtil.splitElements got unknown element.", Absyn.dummyInfo);
Expand Down
17 changes: 17 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -5271,6 +5271,23 @@ algorithm
otpl := if referenceEq(ext_arg, ext_arg2) then itpl else (rel,ext_arg2);
end traverseSubexpressionsHelper;

public function traverseSubexpressions
"This function is used as input to a traverse function that does not traverse all subexpressions.
The extra argument is a tuple of the actul function to call on each subexpression and the extra argument."
replaceable type Type_a subtypeof Any;
input output DAE.Exp e;
input output Type_a arg;
input FuncExpType func;
partial function FuncExpType
input DAE.Exp inExp;
input Type_a inTypeA;
output DAE.Exp outExp;
output Type_a outA;
end FuncExpType;
algorithm
(e, arg) := traverseExpBottomUp(e, func, arg);
end traverseSubexpressions;

public function traverseSubexpressionsDummyHelper
"This function is used as input to a traverse function that does not traverse all subexpressions.
The extra argument is a tuple of the actul function to call on each subexpression and the extra argument.
Expand Down
12 changes: 11 additions & 1 deletion Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -1096,7 +1096,7 @@ algorithm
Integer i,i1,i2,dim;
Real r1;
array<array<DAE.Exp>> marr;
String name;
String name, s1, s2;

// If the argument to min/max is an array, try to flatten it.
case (DAE.CALL(path=Absyn.IDENT(name),expLst={e as DAE.ARRAY()},
Expand Down Expand Up @@ -1457,6 +1457,16 @@ algorithm
case (DAE.CALL(path=Absyn.IDENT("solverClock"),expLst={e1,e2}))
then DAE.CLKCONST(DAE.SOLVER_CLOCK(e1, e2));

case (DAE.CALL(path=Absyn.IDENT("OpenModelica_uriToFilename"),expLst={DAE.SCONST(s1)}))
algorithm
s2 := OpenModelica.Scripting.uriToFilename(s1);
if Flags.getConfigBool(Flags.BUILDING_FMU) then
e := Expression.makeImpureBuiltinCall("OpenModelica_fmuLoadResource",{DAE.SCONST(s2)},DAE.T_STRING_DEFAULT);
else
e := DAE.SCONST(s2);
end if;
then e;

end matchcontinue;
end simplifyBuiltinCalls;

Expand Down
6 changes: 6 additions & 0 deletions Compiler/FrontEnd/Inline.mo
Expand Up @@ -56,6 +56,7 @@ import Ceval;
import ClassInf;
import ComponentReference;
import Config;
import DAEDump;
import Debug;
import ElementSource;
import Error;
Expand Down Expand Up @@ -1124,6 +1125,7 @@ algorithm
VarTransform.VariableReplacements repl;
Option<DAE.Exp> binding;
DAE.Type tp;
DAE.Element elt;
case ({},_,_,_,_) then (listReverse(iInputs),listReverse(iOutput),iBody,iRepl);
case (DAE.VAR(componentRef=cr,direction=DAE.INPUT())::rest,_,_,_,_)
equation
Expand Down Expand Up @@ -1152,6 +1154,10 @@ algorithm
(oInputs,oOutput,oBody,repl) = getFunctionInputsOutputBody(rest,iInputs,iOutput,st,iRepl);
then
(oInputs,oOutput,oBody,repl);
case (elt::rest,_,_,_,_)
algorithm
Error.addInternalError("Unknown element: " + DAEDump.dumpElementsStr({elt}), sourceInfo());
then fail();
end match;
end getFunctionInputsOutputBody;

Expand Down
48 changes: 41 additions & 7 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -620,7 +620,7 @@ algorithm
dae = ConnectUtil.equations(callscope_1, csets, dae1_1, graph, Absyn.pathString(Absyn.makeNotFullyQualified(fq_class)));
//System.stopTimer();
//print("\nConnect and Overconstrained: " + realString(System.getTimerIntervalTime()) + "\n");
ty = InstUtil.mktype(fq_class, ci_state_1, tys, bc_ty, equalityConstraint, c);
ty = InstUtil.mktype(fq_class, ci_state_1, tys, bc_ty, equalityConstraint, c, InstUtil.extractComment(dae.elementLst));
dae = InstUtil.updateDeducedUnits(callscope_1,store,dae);

// Fixes partial functions.
Expand Down Expand Up @@ -711,7 +711,7 @@ algorithm
(cache,fq_class) = makeFullyQualifiedIdent(cache,env_3, n);
dae1_1 = DAEUtil.addComponentType(dae1, fq_class);
dae = dae1_1;
ty = InstUtil.mktypeWithArrays(fq_class, ci_state_1, tys, bc_ty, c);
ty = InstUtil.mktypeWithArrays(fq_class, ci_state_1, tys, bc_ty, c, InstUtil.extractComment(dae.elementLst));
then
(cache,env_3,ih,store,dae,csets,ty,tys,ci_state_1);

Expand Down Expand Up @@ -1097,7 +1097,7 @@ algorithm
ty2 = DAE.T_ENUMERATION(NONE(), fq_class, names, tys1, tys);
bc = arrayBasictypeBaseclass(inst_dims, ty2);
bc = if isSome(bc) then bc else SOME(ty2);
ty = InstUtil.mktype(fq_class, ci_state_1, tys1, bc, eqConstraint, c);
ty = InstUtil.mktype(fq_class, ci_state_1, tys1, bc, eqConstraint, c, SCode.noComment);
// update Enumerationtypes in environment
(cache,env_3) = InstUtil.updateEnumerationEnvironment(cache,env_2,ty,c,ci_state_1);
tys2 = listAppend(tys, tys1); // <--- this is wrong as the tys belong to the component variable not the Enumeration Class!
Expand Down Expand Up @@ -1875,7 +1875,7 @@ algorithm
FCore.Graph env1,env2,env3,env,env5,cenv,cenv_2,env_2,parentEnv,parentClassEnv;
list<tuple<SCode.Element, DAE.Mod>> cdefelts_1,extcomps,compelts_1,compelts_2, comp_cond, derivedClassesWithConstantMods;
Connect.Sets csets,csets1,csets2,csets3,csets4,csets5,csets_1;
DAE.DAElist dae1,dae2,dae3,dae4,dae5,dae6,dae7,dae;
DAE.DAElist dae1,dae2,dae3,dae4,dae5,dae6,dae7,dae8,dae;
ClassInf.State ci_state1,ci_state,ci_state2,ci_state3,ci_state4,ci_state5,ci_state6,ci_state7,new_ci_state,ci_state_1;
list<DAE.Var> vars;
Option<DAE.Type> bc;
Expand Down Expand Up @@ -1903,6 +1903,7 @@ algorithm
SCode.Mod mod;
FCore.Cache cache;
Option<SCode.Attributes> oDA;
list<SCode.Comment> comments;
DAE.EqualityConstraint eqConstraint;
InstTypes.CallingScope callscope;
ConnectionGraph.ConnectionGraph graph;
Expand Down Expand Up @@ -1957,7 +1958,7 @@ algorithm
(cdefelts,extendsclasselts,extendselts as _::_,{}) = InstUtil.splitElts(els);
extendselts = SCodeUtil.addRedeclareAsElementsToExtends(extendselts, List.select(els, SCodeUtil.isRedeclareElement));
(cache,env1,ih) = InstUtil.addClassdefsToEnv(cache, env, ih, pre, cdefelts, impl, SOME(mods));
(cache,_,_,_,extcomps,{},{},{},{}) =
(cache,_,_,_,extcomps,{},{},{},{},_) =
InstExtends.instExtendsAndClassExtendsList(cache, env1, ih, mods, pre, extendselts, extendsclasselts, els, ci_state, className, impl, false);

compelts_2_elem = List.map(extcomps,Util.tuple21);
Expand Down Expand Up @@ -2027,7 +2028,7 @@ algorithm
// if a record -> components ok
// checkRestrictionsOnTheKindOfBaseClass(cache, env, ih, re, extendselts);

(cache,env2,ih,emods,extcomps,eqs2,initeqs2,alg2,initalg2) =
(cache,env2,ih,emods,extcomps,eqs2,initeqs2,alg2,initalg2,comments) =
InstExtends.instExtendsAndClassExtendsList(cache, env1, ih, mods, pre, extendselts, extendsclasselts, els, ci_state, className, impl, false)
"2. EXTENDS Nodes inst_extends_list only flatten inhteritance structure. It does not perform component instantiations.";

Expand Down Expand Up @@ -2146,13 +2147,15 @@ algorithm
(cache,env5,dae7,_) =
instConstraints(cache,env5, pre, ci_state6, constrs, impl);

dae8 = instFunctionAnnotations(comment::comments, ci_state6);

// BTH: Relate state machine components to the flat state machine that they are part of
smCompToFlatSM = InstStateMachineUtil.createSMNodeToFlatSMGroupTable(dae2);
// BTH: Wrap state machine components (including transition statements) into corresponding flat state machine containers
(dae1,dae2) = InstStateMachineUtil.wrapSMCompsInFlatSMs(ih, dae1, dae2, smCompToFlatSM, smInitialCrefs);

//Collect the DAE's
dae = DAEUtil.joinDaeLst({dae1,dae2,dae3,dae4,dae5,dae6,dae7});
dae = DAEUtil.joinDaeLst({dae1,dae2,dae3,dae4,dae5,dae6,dae7,dae8});

//Change outer references to corresponding inner reference
// adrpo: TODO! FIXME! very very very expensive function, try to get rid of it!
Expand Down Expand Up @@ -5594,5 +5597,36 @@ algorithm
end if;
end showCacheInfo;

function instFunctionAnnotations "Merges the function's comments from inherited classes"
input list<SCode.Comment> comments;
input ClassInf.State state;
output DAE.DAElist dae=DAE.emptyDae;
protected
Option<String> comment=NONE();
SCode.Mod mod=SCode.NOMOD(), mod2;
algorithm
if not ClassInf.isFunction(state) then
return;
end if;

for cmt in comments loop

if isNone(comment) then
comment := cmt.comment;
end if;

mod := match cmt
case SCode.COMMENT(annotation_=SOME(SCode.ANNOTATION(modification=mod2)))
then SCode.mergeModifiers(mod2, mod);
else mod;
end match;

end for;
dae := match mod
case SCode.NOMOD() then if isNone(comment) then dae else DAE.DAE({DAE.COMMENT(SCode.COMMENT(NONE(),comment))});
else DAE.DAE({DAE.COMMENT(SCode.COMMENT(SOME(SCode.ANNOTATION(mod)), comment))});
end match;
end instFunctionAnnotations;

annotation(__OpenModelica_Interface="frontend");
end Inst;

0 comments on commit 1b2f2b9

Please sign in to comment.