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

Commit ad34730

Browse files
adrpoOpenModelica-Hudson
authored andcommitted
[FE] new API and replaceable support
- work in progress - to use, just add +d=nfAPI to the OMEdit simulation flags - handling of getComponentAnnotations via NF (some models are about 6x faster) - some crashes in OMEdit, not debugged yet, for example: Modelica.Fluid.Examples.AST_BatchPlant.BatchPlant_StandardWater Belonging to [master]: - OpenModelica/OpenModelica#175 - #3087
1 parent 92a4119 commit ad34730

File tree

15 files changed

+17022
-96
lines changed

15 files changed

+17022
-96
lines changed

Compiler/FrontEnd/Absyn.mo

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6917,5 +6917,38 @@ algorithm
69176917
end match;
69186918
end pathPartCount;
69196919

6920+
public function getAnnotationsFromConstraintClass
6921+
input Option<ConstrainClass> inCC;
6922+
output list<ElementArg> outElArgLst;
6923+
algorithm
6924+
outElArgLst := match(inCC)
6925+
local list<ElementArg> elementArgs;
6926+
case SOME(CONSTRAINCLASS(comment = SOME(COMMENT(annotation_ = SOME(ANNOTATION(elementArgs))))))
6927+
then elementArgs;
6928+
else {};
6929+
end match;
6930+
end getAnnotationsFromConstraintClass;
6931+
6932+
public function getAnnotationsFromItems
6933+
input list<ComponentItem> inComponentItems;
6934+
input list<ElementArg> ccAnnotations;
6935+
output list<list<ElementArg>> outLst = {};
6936+
protected
6937+
list<Absyn.ElementArg> annotations;
6938+
list<String> res;
6939+
String str;
6940+
algorithm
6941+
for comp in listReverse(inComponentItems) loop
6942+
annotations := match comp
6943+
case Absyn.COMPONENTITEM(comment = SOME(Absyn.COMMENT(annotation_ =
6944+
SOME(Absyn.ANNOTATION(annotations)))))
6945+
then listAppend(annotations, ccAnnotations);
6946+
else ccAnnotations;
6947+
end match;
6948+
6949+
outLst := annotations :: outLst;
6950+
end for;
6951+
end getAnnotationsFromItems;
6952+
69206953
annotation(__OpenModelica_Interface="frontend");
69216954
end Absyn;

Compiler/FrontEnd/Constants.mo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ record Transformation
227227
end Transformation;
228228
229229
record Placement
230-
Boolean visible = true;
231-
Transformation transformation \"Placement in the dagram layer\";
232-
Transformation iconTransformation \"Placement in the icon layer\";
230+
parameter Boolean visible = true;
231+
parameter Transformation transformation \"Placement in the dagram layer\";
232+
parameter Transformation iconTransformation \"Placement in the icon layer\";
233233
end Placement;
234234
235235
record IconMap
@@ -413,9 +413,9 @@ end OnMouseDownEditString;
413413
//
414414
record Dialog
415415
parameter String tab = \"General\";
416-
parameter String group = \"\";
416+
parameter String group = \"Parameters\";
417417
parameter Boolean enable = true;
418-
parameter Boolean showStartAttribute;
418+
parameter Boolean showStartAttribute = false;
419419
parameter Boolean colorSelector = false;
420420
parameter Selector loadSelector;
421421
parameter Selector saveSelector;

Compiler/FrontEnd/DAEUtil.mo

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,10 +1930,16 @@ public function getVariableBindingsStr "
19301930
input list<DAE.Element> elts;
19311931
output String str;
19321932
protected
1933-
list<DAE.Element> varlst;
1933+
list<DAE.Element> varlst, els;
19341934
algorithm
1935-
varlst := getVariableList(elts);
1936-
str := getBindingsStr(varlst);
1935+
str := match elts
1936+
case {DAE.COMP(dAElist = els)} then getVariableBindingsStr(els);
1937+
else
1938+
algorithm
1939+
varlst := getVariableList(elts);
1940+
str := getBindingsStr(varlst);
1941+
then str;
1942+
end match;
19371943
end getVariableBindingsStr;
19381944

19391945
protected function getVariableList "

Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ package Internal "Contains internal implementations, e.g. overloaded builtin fun
893893

894894
function solverClock
895895
input Clock c;
896-
input String solverMethod;
896+
parameter input String solverMethod;
897897
output Clock clk;
898898
external "builtin";
899899
end solverClock;
@@ -2743,6 +2743,18 @@ external "builtin";
27432743
annotation(preferredView="text");
27442744
end getPackages;
27452745

2746+
function getAllSubtypeOf
2747+
"Returns the list of all classes that extend from class_ given a parentClass where the lookup for class_ should start"
2748+
input TypeName parentClass = $TypeName(AllLoadedClasses);
2749+
input TypeName class_;
2750+
input Boolean qualified = false;
2751+
input Boolean includePartial = false;
2752+
input Boolean sort = false;
2753+
output TypeName classNames[:];
2754+
external "builtin";
2755+
annotation(preferredView="text");
2756+
end getAllSubtypeOf;
2757+
27462758
partial function basePlotFunction "Extending this does not seem to work at the moment. A real shame; functions below are copy-paste and all need to be updated if the interface changes."
27472759
input String fileName = "<default>" "The filename containing the variables. <default> will read the last simulation result";
27482760
input String interpolation = "linear" "

Compiler/NFFrontEnd/NFBuiltin.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ constant InstNode TIME =
390390
NFBinding.EMPTY_BINDING,
391391
NFComponent.INPUT_ATTR,
392392
NONE(),
393+
NONE(),
393394
Absyn.dummyInfo)),
394395
InstNode.EMPTY_NODE(),
395396
InstNodeType.NORMAL_COMP());

Compiler/NFFrontEnd/NFBuiltinFuncs.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ constant SCode.Element DUMMY_ELEMENT = SCode.CLASS(
7777

7878
// Default Integer parameter.
7979
constant Component INT_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
80-
Type.INTEGER(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), Absyn.dummyInfo);
80+
Type.INTEGER(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), NONE(), Absyn.dummyInfo);
8181

8282
constant InstNode INT_PARAM = InstNode.COMPONENT_NODE("i",
8383
Visibility.PUBLIC,
@@ -86,7 +86,7 @@ constant InstNode INT_PARAM = InstNode.COMPONENT_NODE("i",
8686

8787
// Default Real parameter.
8888
constant Component REAL_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
89-
Type.REAL(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), Absyn.dummyInfo);
89+
Type.REAL(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), NONE(), Absyn.dummyInfo);
9090

9191
constant InstNode REAL_PARAM = InstNode.COMPONENT_NODE("r",
9292
Visibility.PUBLIC,
@@ -95,7 +95,7 @@ constant InstNode REAL_PARAM = InstNode.COMPONENT_NODE("r",
9595

9696
// Default Boolean parameter.
9797
constant Component BOOL_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
98-
Type.BOOLEAN(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), Absyn.dummyInfo);
98+
Type.BOOLEAN(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), NONE(), Absyn.dummyInfo);
9999

100100
constant InstNode BOOL_PARAM = InstNode.COMPONENT_NODE("b",
101101
Visibility.PUBLIC,
@@ -104,7 +104,7 @@ constant InstNode BOOL_PARAM = InstNode.COMPONENT_NODE("b",
104104

105105
// Default String parameter.
106106
constant Component STRING_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
107-
Type.STRING(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), Absyn.dummyInfo);
107+
Type.STRING(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), NONE(), Absyn.dummyInfo);
108108

109109
constant InstNode STRING_PARAM = InstNode.COMPONENT_NODE("s",
110110
Visibility.PUBLIC,
@@ -113,7 +113,7 @@ constant InstNode STRING_PARAM = InstNode.COMPONENT_NODE("s",
113113

114114
// Default enumeration(:) parameter.
115115
constant Component ENUM_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
116-
Type.ENUMERATION_ANY(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), Absyn.dummyInfo);
116+
Type.ENUMERATION_ANY(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), NONE(), Absyn.dummyInfo);
117117

118118
constant InstNode ENUM_PARAM = InstNode.COMPONENT_NODE("e",
119119
Visibility.PUBLIC,
@@ -290,7 +290,7 @@ constant Function SMOOTH = Function.FUNCTION(Path.IDENT("smooth"),
290290

291291

292292
constant Component CLOCK_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
293-
Type.CLOCK(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), Absyn.dummyInfo);
293+
Type.CLOCK(), NFBinding.EMPTY_BINDING, NFBinding.EMPTY_BINDING, NFComponent.DEFAULT_ATTR, NONE(), NONE(), Absyn.dummyInfo);
294294

295295
constant InstNode CLOCK_PARAM = InstNode.COMPONENT_NODE("s",
296296
Visibility.PUBLIC,

Compiler/NFFrontEnd/NFComponent.mo

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ uniontype Component
177177
Binding binding;
178178
Binding condition;
179179
Component.Attributes attributes;
180+
Option<Modifier> ann "the annotation from SCode.Comment as a modifier";
180181
Option<SCode.Comment> comment;
181182
SourceInfo info;
182183
end TYPED_COMPONENT;
@@ -342,7 +343,7 @@ uniontype Component
342343
component := match component
343344
case UNTYPED_COMPONENT()
344345
then TYPED_COMPONENT(component.classInst, ty, component.binding,
345-
component.condition, component.attributes, component.comment, component.info);
346+
component.condition, component.attributes, NONE(), component.comment, component.info);
346347

347348
case TYPED_COMPONENT()
348349
algorithm
@@ -807,6 +808,16 @@ uniontype Component
807808
end match;
808809
end comment;
809810

811+
function ann
812+
input Component component;
813+
output Option<Modifier> ann;
814+
algorithm
815+
ann := match component
816+
case TYPED_COMPONENT() then component.ann;
817+
else NONE();
818+
end match;
819+
end ann;
820+
810821
function getEvaluateAnnotation
811822
input Component component;
812823
output Boolean evaluate;

Compiler/NFFrontEnd/NFModelicaBuiltin.mo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,6 +2914,18 @@ external "builtin";
29142914
annotation(preferredView="text");
29152915
end getPackages;
29162916

2917+
function getAllSubtypeOf
2918+
"Returns the list of all classes that extend from class_ given a parentClass where the lookup for class_ should start"
2919+
input TypeName parentClass = $TypeName(AllLoadedClasses);
2920+
input TypeName class_;
2921+
input Boolean qualified = false;
2922+
input Boolean includePartial = false;
2923+
input Boolean sort = false;
2924+
output TypeName classNames[:];
2925+
external "builtin";
2926+
annotation(preferredView="text");
2927+
end getAllSubtypeOf;
2928+
29172929
partial function basePlotFunction "Extending this does not seem to work at the moment. A real shame; functions below are copy-paste and all need to be updated if the interface changes."
29182930
input String fileName = "<default>" "The filename containing the variables. <default> will read the last simulation result";
29192931
input String interpolation = "linear" "

Compiler/Script/CevalScript.mo

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import Graph;
8888
import HashSetString;
8989
import Inst;
9090
import InstFunction;
91+
import InteractiveUtil;
9192
import List;
9293
import Lookup;
9394
import Mod;
@@ -533,7 +534,7 @@ algorithm
533534
systemPath, gccVersion, gd, strlinearizeTime, direction, suffix;
534535
list<DAE.Exp> simOptions;
535536
list<Values.Value> vals;
536-
Absyn.Path path,classpath,className,baseClassPath;
537+
Absyn.Path path,classpath,className,baseClassPath,parentClass;
537538
SCode.Program scodeP,sp;
538539
Option<list<SCode.Element>> fp;
539540
FCore.Graph env;
@@ -558,7 +559,9 @@ algorithm
558559
Real timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2,r,r1,r2,linearizeTime,curveWidth,offset,offset1,offset2,scaleFactor,scaleFactor1,scaleFactor2;
559560
GlobalScript.Statements istmts;
560561
list<GlobalScript.Statements> istmtss;
561-
Boolean have_corba, bval, anyCode, b, b1, b2, externalWindow, logX, logY, autoScale, forceOMPlot, gcc_res, omcfound, rm_res, touch_res, uname_res, ifcpp, ifmsvc,sort, builtin, showProtected, includeConstants, inputConnectors, outputConnectors, mergeAST;
562+
Boolean have_corba, bval, anyCode, b, b1, b2, externalWindow, logX, logY, autoScale, forceOMPlot,
563+
gcc_res, omcfound, rm_res, touch_res, uname_res, ifcpp, ifmsvc,sort, builtin, showProtected,
564+
includeConstants, inputConnectors, outputConnectors, mergeAST, includePartial, qualified;
562565
FCore.Cache cache;
563566
Absyn.ComponentRef crefCName;
564567
list<tuple<String,Values.Value>> resultValues;
@@ -1766,6 +1769,20 @@ algorithm
17661769
v = Values.REAL(r);
17671770
then (cache,v);
17681771

1772+
case (cache,_,"getAllSubtypeOf",{
1773+
Values.CODE(Absyn.C_TYPENAME(parentClass)),
1774+
Values.CODE(Absyn.C_TYPENAME(path)),
1775+
Values.BOOL(qualified),
1776+
Values.BOOL(includePartial),
1777+
Values.BOOL(sort)},_)
1778+
equation
1779+
paths = InteractiveUtil.getAllSubtypeOf(parentClass, path, SymbolTable.getAbsyn(), qualified, includePartial);
1780+
paths = listReverse(paths);
1781+
paths = if sort then List.sort(paths, Absyn.pathGe) else paths;
1782+
vals = List.map(paths,ValuesUtil.makeCodeTypeName);
1783+
then
1784+
(cache,ValuesUtil.makeArray(vals));
1785+
17691786
else
17701787
algorithm
17711788
(cache,v) := CevalScriptBackend.cevalInteractiveFunctions3(inCache,inEnv,inFunctionName,inVals,msg);

Compiler/Script/CevalScriptBackend.mo

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,8 +3138,8 @@ algorithm
31383138
Absyn.Class absynClass;
31393139
String str,re;
31403140
Option<SCode.Program> fp;
3141-
SCode.Program scodeP, scodePNew, scode_builtin;
3142-
Absyn.Program p,ptot,p_builtin;
3141+
SCode.Program scodeP, scodePNew, scode_builtin, graphicProgramSCode;
3142+
Absyn.Program p,ptot,p_builtin, placementProgram;
31433143
DAE.FunctionTree funcs;
31443144

31453145
case (cache,env,_)
@@ -3168,6 +3168,14 @@ algorithm
31683168
scodeP := listAppend(scode_builtin, SymbolTable.getSCode());
31693169
ExecStat.execStat("FrontEnd - Absyn->SCode");
31703170

3171+
// add also the graphics annotations if we are using the NF_API
3172+
if Flags.isSet(Flags.NF_API) then
3173+
placementProgram := Interactive.modelicaAnnotationProgram(Config.getAnnotationVersion());
3174+
graphicProgramSCode := SCodeUtil.translateAbsyn2SCode(placementProgram);
3175+
scodeP := listAppend(scode_builtin, SymbolTable.getSCode());
3176+
scodeP := listAppend(scodeP, graphicProgramSCode);
3177+
end if;
3178+
31713179
(dae, funcs) := NFInst.instClassInProgram(className, scodeP);
31723180

31733181
cache := FCore.emptyCache();

0 commit comments

Comments
 (0)