Skip to content

Commit

Permalink
fix ticket #6300, use NF for getElementAnnotations if -d=nfAPI is on
Browse files Browse the repository at this point in the history
- add Documentation record to Constants.mo
- add a test for the ticket
  • Loading branch information
adrpo committed Dec 20, 2020
1 parent 5961394 commit ee13cc6
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 16 deletions.
6 changes: 6 additions & 0 deletions OMCompiler/Compiler/FrontEnd/Constants.mo
Expand Up @@ -451,6 +451,12 @@ end choices;
// group = \"Shape definition\"));
// ...
// end BodyShape;
record Documentation
String info = \"\" \"Description of the class\";
String revisions = \"\" \"Revision history\";
// Spec 3.5 Figure[:] figures = {}; \"Simulation result figures\";
end Documentation;
"
;

Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Script/Interactive.mo
Expand Up @@ -13536,7 +13536,7 @@ algorithm
end getComponentitemsModification;


protected function cacheProgramAndPath
public function cacheProgramAndPath
input GraphicEnvCache inCache;
output Absyn.Program outProgram;
output Absyn.Path outPath;
Expand Down
42 changes: 28 additions & 14 deletions OMCompiler/Compiler/Script/InteractiveUtil.mo
Expand Up @@ -80,6 +80,7 @@ import List;
import Lookup;
import MetaUtil;
import Mod;
import NFApi;
import Parser;
import Print;
import SCodeUtil;
Expand Down Expand Up @@ -8012,19 +8013,19 @@ public function getElementAnnotations " This function takes a `ComponentRef\', a
protected
Absyn.Path model_path;
Absyn.Class cdef;
list<Absyn.Element> comps1, comps2, comps;
list<Absyn.Element> els1, els2, els;
algorithm
try
model_path := AbsynUtil.crefToPath(inClassPath);
cdef := getPathedClassInProgram(model_path, inProgram);
comps1 := getPublicElementsInClass(cdef);
els1 := getPublicElementsInClass(cdef);
if (inAccess >= 4) then // i.e., Access.diagram
comps2 := getProtectedElementsInClass(cdef);
els2 := getProtectedElementsInClass(cdef);
else
comps2 := {};
els2 := {};
end if;
comps := listAppend(comps1, comps2);
outString := getElementAnnotationsFromElts(comps, cdef, inProgram, model_path);
els := listAppend(els1, els2);
outString := getElementAnnotationsFromElts(els, cdef, inProgram, model_path);
outString := stringAppendList({"{", outString, "}"});
else
outString := "Error";
Expand Down Expand Up @@ -11079,7 +11080,7 @@ end getConnectionsInEquations;

protected function getElementAnnotationsFromElts
"Helper function to getElementAnnotations."
input list<Absyn.Element> comps;
input list<Absyn.Element> els;
input Absyn.Class inClass;
input Absyn.Program inFullProgram;
input Absyn.Path inModelPath;
Expand All @@ -11091,11 +11092,15 @@ protected
Absyn.Program placementProgram;
GraphicEnvCache cache;
algorithm
placementProgram := modelicaAnnotationProgram(Config.getAnnotationVersion());
graphicProgramSCode := AbsynToSCode.translateAbsyn2SCode(placementProgram);
(_,env) := Inst.makeEnvFromProgram(graphicProgramSCode);
if not Flags.isSet(Flags.NF_API) then
placementProgram := modelicaAnnotationProgram(Config.getAnnotationVersion());
graphicProgramSCode := AbsynToSCode.translateAbsyn2SCode(placementProgram);
(_,env) := Inst.makeEnvFromProgram(graphicProgramSCode);
else
env := FGraph.emptyGraph;
end if;
cache := Interactive.GRAPHIC_ENV_NO_CACHE(inFullProgram, inModelPath);
res := getElementitemsAnnotations(comps, env, inClass, cache);
res := getElementitemsAnnotations(els, env, inClass, cache);
resStr := stringDelimitList(res, ",");
end getElementAnnotationsFromElts;

Expand All @@ -11113,7 +11118,16 @@ protected
Option<Absyn.ConstrainClass> cc;
list<Absyn.ElementArg> annotations;
Option<Absyn.Comment> cmt;
Absyn.Program fullProgram;
Absyn.Path modelPath;
algorithm

if Flags.isSet(Flags.NF_API) then
(fullProgram, modelPath) := Interactive.cacheProgramAndPath(inCache);
outStringLst := NFApi.evaluateAnnotations(fullProgram, modelPath, inElements);
return;
end if;

for e in listReverse(inElements) loop
outStringLst := matchcontinue e
case Absyn.ELEMENT(specification = Absyn.COMPONENTS(components = items), constrainClass = cc)
Expand Down Expand Up @@ -11511,7 +11525,7 @@ algorithm
(outCache, outEnv, outGraphicProgram, outGraphicEnvCache);

// No cache, make partial or full cache as needed.
case Interactive.GRAPHIC_ENV_NO_CACHE()
case Interactive.Interactive.GRAPHIC_ENV_NO_CACHE()
algorithm
if AbsynUtil.onlyLiteralsInAnnotationMod(inAnnotationMod) then
outGraphicProgram := modelicaAnnotationProgram(Config.getAnnotationVersion());
Expand Down Expand Up @@ -11606,12 +11620,12 @@ algorithm
ErrorExt.setCheckpoint("buildEnvForGraphicProgram");
try
(cache, env, graphic_prog) :=
buildEnvForGraphicProgram(Interactive.GRAPHIC_ENV_NO_CACHE(inFullProgram, inModelPath), mod);
buildEnvForGraphicProgram(Interactive.Interactive.GRAPHIC_ENV_NO_CACHE(inFullProgram, inModelPath), mod);
ErrorExt.rollBack("buildEnvForGraphicProgram");
else
ErrorExt.delCheckpoint("buildEnvForGraphicProgram");
// Fallback to only the graphical primitives left in the program
(cache, env, graphic_prog) := buildEnvForGraphicProgram(Interactive.GRAPHIC_ENV_NO_CACHE(inFullProgram, inModelPath), {});
(cache, env, graphic_prog) := buildEnvForGraphicProgram(Interactive.Interactive.GRAPHIC_ENV_NO_CACHE(inFullProgram, inModelPath), {});
end try;

smod := AbsynToSCode.translateMod(SOME(Absyn.CLASSMOD(stripped_mod, Absyn.NOMOD())),
Expand Down
22 changes: 21 additions & 1 deletion OMCompiler/Compiler/Script/NFApi.mo
Expand Up @@ -317,12 +317,13 @@ protected
list<Absyn.ComponentItem> items;
Option<Absyn.ConstrainClass> cc;
SourceInfo info;
list<Absyn.ElementArg> mod;
list<Absyn.ElementArg> mod, anns;
Absyn.EqMod eqmod;
SCode.Mod smod;
DAE.DAElist dae;
Type ty;
Variability var;
Option<Absyn.Comment> cmt;
algorithm
// handle the annotations
for i in inElements loop
Expand All @@ -336,6 +337,25 @@ algorithm
case Absyn.ELEMENT(specification = Absyn.COMPONENTS())
then {}::elArgs;

case Absyn.ELEMENT(specification = Absyn.CLASSDEF(
class_ = Absyn.CLASS(body = Absyn.DERIVED(comment = cmt))),
constrainClass = cc)
algorithm
anns := match cmt
case SOME(Absyn.COMMENT(annotation_ = SOME(Absyn.ANNOTATION(anns))))
then anns;
else {};
end match;
then
listAppend(anns, AbsynUtil.getAnnotationsFromConstraintClass(cc))::elArgs;

case Absyn.ELEMENT(specification = Absyn.COMPONENTS())
then {} :: elArgs;

case Absyn.ELEMENT(specification = Absyn.CLASSDEF(class_ = Absyn.CLASS(body = Absyn.DERIVED())))
then {} :: elArgs;


else elArgs;
end matchcontinue;
end for;
Expand Down
1 change: 1 addition & 0 deletions testsuite/openmodelica/interactive-API/Makefile
Expand Up @@ -86,6 +86,7 @@ Ticket5680.mos \
Ticket5696.mos \
Ticket5871.mos \
Ticket6167.mos \
Ticket6300.mos \
ReadOnlyPkg.mos

# test that currently fail. Move up when fixed.
Expand Down
29 changes: 29 additions & 0 deletions testsuite/openmodelica/interactive-API/Ticket6300.mos
@@ -0,0 +1,29 @@
// name: Ticket6300.mos
// keywords:
// status: correct
//
// Tests if -d=nfAPI will use the NF for getElementAnnotations
//

setCommandLineOptions("-d=nfAPI"); getErrorString();

loadModel(Modelica); getErrorString();
getElementAnnotations(Modelica.Mechanics.MultiBody.World); getErrorString();

// Result:
// true
// ""
// true
// ""
// {{Placement(true,-,-,84.0,-16.0,116.0,16.0,-,-,-,-,-,-,-,)},{},{Dialog("General","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("General","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("General","Parameters",true,false,false,-,-,-,-,"",false)},{},{},{Evaluate=true},{Dialog("General","Parameters",true,false,false,-,-,-,-,"",false)},{Evaluate=true, Dialog("General","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("General","Parameters",false,false,false,-,-,-,-,"",false)},{},{Dialog("Animation","if animateWorld = true",true,false,false,-,-,-,-,"",false)},{Dialog("Animation","if animateWorld = true",true,false,false,-,-,-,-,"",false)},{Dialog("Animation","if animateWorld = true",true,false,false,-,-,-,-,"",false)},{Dialog("Animation","if animateWorld = true",true,false,true,-,-,-,-,"",false)},{Dialog("Animation","if animateWorld = true",true,false,true,-,-,-,-,"",false)},{Dialog("Animation","if animateWorld = true",true,false,true,-,-,-,-,"",false)},{Dialog("Animation","if animateGravity = true and gravityType = UniformGravity",true,false,false,-,-,-,-,"",false)},{Dialog("Animation","if animateGravity = true and gravityType = UniformGravity",true,false,false,-,-,-,-,"",false)},{Dialog("Animation","if animateGravity = true and gravityType = UniformGravity",true,false,false,-,-,-,-,"",false)},{Dialog("Animation","if animateGravity = true and gravityType = UniformGravity",true,false,true,-,-,-,-,"",false)},{Dialog("Animation","if animateGravity = true and gravityType = PointGravity",false,false,false,-,-,-,-,"",false)},{Dialog("Animation","if animateGravity = true and gravityType = PointGravity",false,false,true,-,-,-,-,"",false)},{Dialog("Animation","if animateGround = true and gravityType = UniformGravity",false,false,false,-,-,-,-,"",false)},{Dialog("Animation","if animateGround = true and gravityType = UniformGravity",false,false,false,-,-,-,-,"",false)},{Dialog("Animation","if animateGround = true and gravityType = UniformGravity",false,false,false,-,-,-,-,"",false)},{Dialog("Animation","if animateGround = true and gravityType = UniformGravity",false,false,true,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{Dialog("Defaults","Parameters",true,false,false,-,-,-,-,"",false)},{choicesAllMatching=true, Dialog("General","Parameters",false,false,false,-,-,-,-,"",false), Documentation("<html>
// <p>Replaceable function to define the gravity field.
// Default is function
// <a href=\"modelica://Modelica.Mechanics.MultiBody.Forces.Internal.standardGravityAcceleration\">standardGravityAcceleration</a>
// that provides some simple gravity fields (no gravity, constant parallel gravity field,
// point gravity field).
// By redeclaring this function, any type of gravity field can be defined, see example
// <a href=\"modelica://Modelica.Mechanics.MultiBody.Examples.Elementary.UserDefinedGravityField\">Examples.Elementary.UserDefinedGravityField</a>.
// </p>
// </html>","")},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}}
// ""
// endResult

0 comments on commit ee13cc6

Please sign in to comment.