Skip to content

Commit

Permalink
- more API using the NF
Browse files Browse the repository at this point in the history
- fix ticket:5482 handle getIconAnnotation and getDiagramAnnotation via the NF
- cache results of the NF instantiation
- better fix for ticket:5484
- change annotation Text record to have defaults for fontName and testStyle
- update tests due to changes to Text annotation
  • Loading branch information
adrpo committed May 21, 2019
1 parent ad11e88 commit 0e102be
Show file tree
Hide file tree
Showing 16 changed files with 564 additions and 543 deletions.
89 changes: 56 additions & 33 deletions OMCompiler/Compiler/FFrontEnd/FBuiltin.mo
Expand Up @@ -352,20 +352,20 @@ public function getInitialFunctions
output Absyn.Program initialProgram;
output SCode.Program initialSCodeProgram;
protected
String fileModelica,fileMetaModelica,fileParModelica,filePDEModelica;
// legend: NF = new frontend; CF = current frontend
String fileModelicaNF,fileModelicaCF,fileMetaModelica,fileParModelica,filePDEModelica;
list<tuple<tuple<Integer,Boolean>,tuple<Absyn.Program,SCode.Program>>> assocLst;
list<Absyn.Class> classesNF,classesCF,classes1NF,classes1CF,classes2;
Absyn.Program p, pNF, pCF;
SCode.Program sp, spNF, spCF;
algorithm
fileModelica := if Flags.isSet(Flags.SCODE_INST) then Settings.getInstallationDirectoryPath() + "/lib/omc/NFModelicaBuiltin.mo"
else Settings.getInstallationDirectoryPath() + "/lib/omc/ModelicaBuiltin.mo";
fileModelicaNF := Settings.getInstallationDirectoryPath() + "/lib/omc/NFModelicaBuiltin.mo";
fileModelicaCF := Settings.getInstallationDirectoryPath() + "/lib/omc/ModelicaBuiltin.mo";
fileMetaModelica := Settings.getInstallationDirectoryPath() + "/lib/omc/MetaModelicaBuiltin.mo";
fileParModelica := Settings.getInstallationDirectoryPath() + "/lib/omc/ParModelicaBuiltin.mo";
filePDEModelica := Settings.getInstallationDirectoryPath() + "/lib/omc/PDEModelicaBuiltin.mo";

(initialProgram,initialSCodeProgram) := matchcontinue ()
local
list<tuple<Integer,tuple<Absyn.Program,SCode.Program>>> assocLst;
list<Absyn.Class> classes,classes1,classes2;
Absyn.Program p;
SCode.Program sp;
case ()
equation
failure(_ = getGlobalRoot(Global.builtinIndex));
Expand All @@ -374,56 +374,79 @@ algorithm
case ()
equation
assocLst = getGlobalRoot(Global.builtinIndex);
((p,sp)) = Util.assoc(Flags.getConfigEnum(Flags.GRAMMAR), assocLst);
((p,sp)) = Util.assoc(Util.makeTuple(Flags.getConfigEnum(Flags.GRAMMAR), Flags.isSet(Flags.SCODE_INST)) , assocLst);
then (p,sp);
case ()
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.METAMODELICA);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelica),Error.FILE_NOT_FOUND_ERROR,{fileModelica},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaNF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaNF},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaCF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaCF},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileMetaModelica),Error.FILE_NOT_FOUND_ERROR,{fileMetaModelica},Absyn.dummyInfo);
Absyn.PROGRAM(classes=classes1,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes1NF,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelicaNF,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes1CF,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelicaCF,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes2,within_=Absyn.TOP()) = Parser.parsebuiltin(fileMetaModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
classes = listAppend(classes1,classes2);
p = Absyn.PROGRAM(classes,Absyn.TOP());
(p as Absyn.PROGRAM(classes=classes)) = MetaUtil.createMetaClassesInProgram(p);
sp = List.map(classes, SCodeUtil.translateClass);
classesNF = listAppend(classes1NF,classes2);
classesCF = listAppend(classes1CF,classes2);
pNF = Absyn.PROGRAM(classesNF,Absyn.TOP());
pCF = Absyn.PROGRAM(classesCF,Absyn.TOP());
(pNF as Absyn.PROGRAM(classes=classesNF)) = MetaUtil.createMetaClassesInProgram(pNF);
(pCF as Absyn.PROGRAM(classes=classesCF)) = MetaUtil.createMetaClassesInProgram(pCF);
spNF = List.map(classesNF, SCodeUtil.translateClass);
spCF = List.map(classesCF, SCodeUtil.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, (Flags.METAMODELICA,(p,sp))::assocLst);
setGlobalRoot(Global.builtinIndex, ((Flags.METAMODELICA, true), (pNF,spNF))::((Flags.METAMODELICA, false), (pCF,spCF))::assocLst);
(p, sp) = if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF);
then (p,sp);
case ()
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PARMODELICA);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelica),Error.FILE_NOT_FOUND_ERROR,{fileModelica},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileParModelica),Error.FILE_NOT_FOUND_ERROR,{fileParModelica},Absyn.dummyInfo);
Absyn.PROGRAM(classes=classes1,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaNF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaNF},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaCF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaCF},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileMetaModelica),Error.FILE_NOT_FOUND_ERROR,{fileMetaModelica},Absyn.dummyInfo);
Absyn.PROGRAM(classes=classes1NF,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelicaNF,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes1CF,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelicaCF,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes2,within_=Absyn.TOP()) = Parser.parsebuiltin(fileParModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
classes = listAppend(classes1,classes2);
p = Absyn.PROGRAM(classes,Absyn.TOP());
sp = List.map(classes, SCodeUtil.translateClass);
classesNF = listAppend(classes1NF,classes2);
classesCF = listAppend(classes1CF,classes2);
pNF = Absyn.PROGRAM(classesNF,Absyn.TOP());
pCF = Absyn.PROGRAM(classesCF,Absyn.TOP());
spNF = List.map(classesNF, SCodeUtil.translateClass);
spCF = List.map(classesCF, SCodeUtil.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, (Flags.PARMODELICA,(p,sp))::assocLst);
setGlobalRoot(Global.builtinIndex, ((Flags.PARMODELICA, true), (pNF,spNF))::((Flags.PARMODELICA, false), (pCF,spCF))::assocLst);
(p, sp) = if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF);
then (p,sp);
case ()
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.MODELICA) or intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.OPTIMICA);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelica),Error.FILE_NOT_FOUND_ERROR,{fileModelica},Absyn.dummyInfo);
(p as Absyn.PROGRAM(classes=classes)) = Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
sp = List.map(classes, SCodeUtil.translateClass);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaNF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaNF},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaCF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaCF},Absyn.dummyInfo);
(pNF as Absyn.PROGRAM(classes=classes1NF,within_=Absyn.TOP())) = Parser.parsebuiltin(fileModelicaNF,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
(pCF as Absyn.PROGRAM(classes=classes1CF,within_=Absyn.TOP())) = Parser.parsebuiltin(fileModelicaCF,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
spNF = List.map(classes1NF, SCodeUtil.translateClass);
spCF = List.map(classes1CF, SCodeUtil.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, (Flags.MODELICA,(p,sp))::assocLst);
setGlobalRoot(Global.builtinIndex, ((Flags.MODELICA, true), (pNF,spNF))::((Flags.MODELICA, false), (pCF,spCF))::assocLst);
(p, sp) = if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF);
then (p,sp);
case ()
equation
true = intEq(Flags.getConfigEnum(Flags.GRAMMAR), Flags.PDEMODELICA);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelica),Error.FILE_NOT_FOUND_ERROR,{fileModelica},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaNF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaNF},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(fileModelicaCF),Error.FILE_NOT_FOUND_ERROR,{fileModelicaCF},Absyn.dummyInfo);
Error.assertionOrAddSourceMessage(System.regularFileExists(filePDEModelica),Error.FILE_NOT_FOUND_ERROR,{filePDEModelica},Absyn.dummyInfo);
Absyn.PROGRAM(classes=classes1,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes1NF,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelicaNF,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes1CF,within_=Absyn.TOP()) = Parser.parsebuiltin(fileModelicaCF,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
Absyn.PROGRAM(classes=classes2,within_=Absyn.TOP()) = Parser.parsebuiltin(filePDEModelica,"UTF-8","",NONE(),acceptedGram=Flags.METAMODELICA);
classes = listAppend(classes1,classes2);
p = Absyn.PROGRAM(classes,Absyn.TOP());
sp = List.map(classes, SCodeUtil.translateClass);
classesNF = listAppend(classes1NF,classes2);
classesCF = listAppend(classes1CF,classes2);
pNF = Absyn.PROGRAM(classesNF,Absyn.TOP());
pCF = Absyn.PROGRAM(classesCF,Absyn.TOP());
spNF = List.map(classesNF, SCodeUtil.translateClass);
spCF = List.map(classesCF, SCodeUtil.translateClass);
assocLst = getGlobalRoot(Global.builtinIndex);
setGlobalRoot(Global.builtinIndex, (Flags.PDEMODELICA,(p,sp))::assocLst);
setGlobalRoot(Global.builtinIndex, ((Flags.PDEMODELICA, true), (pNF,spNF))::((Flags.PDEMODELICA, false), (pCF,spCF))::assocLst);
(p, sp) = if Flags.isSet(Flags.SCODE_INST) then (pNF, spNF) else (pCF, spCF);
then (p,sp);

else
Expand Down
49 changes: 48 additions & 1 deletion OMCompiler/Compiler/FrontEnd/Absyn.mo
Expand Up @@ -5023,7 +5023,7 @@ algorithm
end matchcontinue;
end onlyLiteralsInAnnotationMod;

protected function onlyLiteralsInEqMod
public function onlyLiteralsInEqMod
"@author: adrpo
This function checks if an optional expression only contains literal expressions"
input EqMod eqMod;
Expand Down Expand Up @@ -6950,5 +6950,52 @@ algorithm
end for;
end getAnnotationsFromItems;

public function stripGraphicsAndInteractionModification
" This function strips out the `graphics\' modification from an ElementArg
list and return two lists, one with the other modifications and the
second with the `graphics\' modification"
input list<Absyn.ElementArg> inAbsynElementArgLst;
output list<Absyn.ElementArg> outAbsynElementArgLst1;
output list<Absyn.ElementArg> outAbsynElementArgLst2;
algorithm
(outAbsynElementArgLst1,outAbsynElementArgLst2) := matchcontinue (inAbsynElementArgLst)
local
Absyn.ElementArg mod;
list<Absyn.ElementArg> rest,l1,l2;

// handle empty
case ({}) then ({},{});

// adrpo: remove interaction annotations as we don't handle them currently
case (((Absyn.MODIFICATION(path = Absyn.IDENT(name = "interaction"))) :: rest))
equation
(l1,l2) = stripGraphicsAndInteractionModification(rest);
then
(l1,l2);

// adrpo: remove empty annotations, to handle bad Dymola annotations, for example: Diagram(graphics)
case (((Absyn.MODIFICATION(modification = NONE(), path = Absyn.IDENT(name = "graphics"))) :: rest))
equation
(l1,l2) = stripGraphicsAndInteractionModification(rest);
then
(l1,l2);

// add graphics to the second tuple
case (((mod as Absyn.MODIFICATION(modification = SOME(_), path = Absyn.IDENT(name = "graphics"))) :: rest))
equation
(l1,l2) = stripGraphicsAndInteractionModification(rest);
then
(l1,mod::l2);

// collect in the first tuple
case (((mod as Absyn.MODIFICATION()) :: rest))
equation
(l1,l2) = stripGraphicsAndInteractionModification(rest);
then
((mod :: l1),l2);

end matchcontinue;
end stripGraphicsAndInteractionModification;

annotation(__OpenModelica_Interface="frontend");
end Absyn;
12 changes: 6 additions & 6 deletions OMCompiler/Compiler/FrontEnd/Constants.mo
Expand Up @@ -191,12 +191,12 @@ end CoordinateSystem;
// i.e. a coordinate system with width 20 units and height 20 units.
record Icon \"Representation of the icon layer\"
CoordinateSystem coordinateSystem(extent = {{-100, -100}, {100, 100}});
parameter CoordinateSystem coordinateSystem(extent = {{-100, -100}, {100, 100}});
//GraphicItem[:] graphics;
end Icon;
record Diagram \"Representation of the diagram layer\"
CoordinateSystem coordinateSystem(extent = {{-100, -100}, {100, 100}});
parameter CoordinateSystem coordinateSystem(extent = {{-100, -100}, {100, 100}});
//GraphicItem[:] graphics;
end Diagram;
Expand Down Expand Up @@ -249,7 +249,7 @@ record Line
Real rotation/*(quantity=\"angle\", unit=\"deg\")*/ = 0;
// end GraphicItem
Real points[2,:]/*(each final unit=\"mm\")*/;
Real points[:, 2]/*(each final unit=\"mm\")*/;
Integer color[3] = {0, 0, 0};
LinePattern pattern = LinePattern.Solid;
Real thickness/*(final unit=\"mm\")*/ = 0.25;
Expand All @@ -273,7 +273,7 @@ record Polygon
Real lineThickness = 0.25 \"Line thickness\";
// end FilledShape
Real points[2,:]/*(each final unit=\"mm\")*/;
Real points[:,2]/*(each final unit=\"mm\")*/;
Smooth smooth = Smooth.None \"Spline outline\";
end Polygon;
Expand Down Expand Up @@ -336,8 +336,8 @@ record Text
String textString;
Real fontSize = 0 \"unit pt\";
Integer textColor[3] = {-1, -1, -1} \"defaults to fillColor\";
String fontName;
TextStyle textStyle[:];
String fontName = \"\";
TextStyle textStyle[:] = fill(TextStyle.Bold, 0);
TextAlignment horizontalAlignment = TextAlignment.Center;
end Text;
Expand Down
4 changes: 4 additions & 0 deletions OMCompiler/Compiler/Global/Global.mo
Expand Up @@ -50,6 +50,8 @@ constant Integer symbolTable = 3;

// Global roots start at index=9
constant Integer instHashIndex = 9;
constant Integer instNFInstCacheIndex = 10;
constant Integer instNFNodeCacheIndex = 11;
constant Integer builtinIndex = 12;
constant Integer builtinEnvIndex = 13;
constant Integer profilerTime1Index = 14;
Expand Down Expand Up @@ -93,6 +95,8 @@ algorithm
setGlobalRoot(inlineHashTable, NONE());
setGlobalRoot(currentInstVar, NONE());
setGlobalRoot(interactiveCache, NONE());
setGlobalRoot(instNFInstCacheIndex, {});
setGlobalRoot(instNFNodeCacheIndex, {});
end initialize;

annotation(__OpenModelica_Interface="util");
Expand Down
23 changes: 13 additions & 10 deletions OMCompiler/Compiler/NFFrontEnd/NFTypeCheck.mo
Expand Up @@ -46,6 +46,7 @@ import NFBinding.Binding;
import NFPrefixes.Variability;

protected
import Config;
import Debug;
import DAEExpression = Expression;
import Error;
Expand Down Expand Up @@ -3026,16 +3027,18 @@ algorithm
Type.arrayElementType(componentType),
Expression.EMPTY(bindingType), true);

if isValidAssignmentMatch(mk) then
Error.addMultiSourceMessage(Error.VARIABLE_BINDING_DIMS_MISMATCH,
{name, Binding.toString(binding),
Dimension.toStringList(Type.arrayDims(componentType)),
Dimension.toStringList(Type.arrayDims(bindingType))},
{binding_info, comp_info});
else
Error.addMultiSourceMessage(Error.VARIABLE_BINDING_TYPE_MISMATCH,
{name, Binding.toString(binding), Type.toString(componentType),
Type.toString(bindingType)}, {binding_info, comp_info});
if not Config.getGraphicsExpMode() then // forget errors when handling annotations
if isValidAssignmentMatch(mk) then
Error.addMultiSourceMessage(Error.VARIABLE_BINDING_DIMS_MISMATCH,
{name, Binding.toString(binding),
Dimension.toStringList(Type.arrayDims(componentType)),
Dimension.toStringList(Type.arrayDims(bindingType))},
{binding_info, comp_info});
else
Error.addMultiSourceMessage(Error.VARIABLE_BINDING_TYPE_MISMATCH,
{name, Binding.toString(binding), Type.toString(componentType),
Type.toString(bindingType)}, {binding_info, comp_info});
end if;
end if;
end if;
end printBindingTypeError;
Expand Down
16 changes: 11 additions & 5 deletions OMCompiler/Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -62,6 +62,7 @@ import BuiltinCall = NFBuiltinCall;
import Ceval = NFCeval;
import ClassInf;
import ComponentRef = NFComponentRef;
import Config;
import Origin = NFComponentRef.Origin;
import ExecStat.execStat;
import Inst = NFInst;
Expand Down Expand Up @@ -830,7 +831,9 @@ algorithm
checkBindingEach(c.binding);
binding := typeBinding(binding, ExpOrigin.setFlag(origin, ExpOrigin.BINDING));

binding := TypeCheck.matchBinding(binding, c.ty, name, node);
if not (Config.getGraphicsExpMode() and stringEq(name, "graphics")) then
binding := TypeCheck.matchBinding(binding, c.ty, name, node);
end if;
comp_var := Component.variability(c);
comp_eff_var := Prefixes.effectiveVariability(comp_var);
bind_var := Binding.variability(binding);
Expand All @@ -857,6 +860,7 @@ algorithm
if Binding.isBound(c.condition) then
binding := Binding.INVALID_BINDING(binding, ErrorExt.getMessages());
else
ErrorExt.delCheckpoint(getInstanceName());
fail();
end if;
end try;
Expand Down Expand Up @@ -1663,10 +1667,12 @@ algorithm
(exp, , mk) := TypeCheck.matchTypes(ty2, ty1, e);
expl2 := exp::expl2;
n := n-1;
if TypeCheck.isIncompatibleMatch(mk) then
Error.addSourceMessage(Error.NF_ARRAY_TYPE_MISMATCH, {String(n), Expression.toString(exp), Type.toString(ty2), Type.toString(ty1)}, info);
fail();
end if;
if not Config.getGraphicsExpMode() then // forget errors when handling annotations
if TypeCheck.isIncompatibleMatch(mk) then
Error.addSourceMessage(Error.NF_ARRAY_TYPE_MISMATCH, {String(n), Expression.toString(exp), Type.toString(ty2), Type.toString(ty1)}, info);
fail();
end if;
end if;
end for;

arrayType := Type.liftArrayLeft(ty1, Dimension.fromExpList(expl2));
Expand Down
7 changes: 0 additions & 7 deletions OMCompiler/Compiler/Script/CevalScript.mo
Expand Up @@ -977,15 +977,8 @@ algorithm

case (_,_,"setCommandLineOptions",{Values.STRING(str)},_)
equation
new_inst = Flags.isSet(Flags.SCODE_INST) or Flags.isSet(Flags.NF_API);
args = System.strtok(str, " ");
{} = Flags.readArgs(args);

// Invalidate the builtin cache if the newInst flag was toggled,
// so we don't reuse the wrong builtin program.
if new_inst <> (Flags.isSet(Flags.SCODE_INST) or Flags.isSet(Flags.NF_API)) then
setGlobalRoot(Global.builtinIndex, {});
end if;
then
(FCore.emptyCache(),Values.BOOL(true));

Expand Down

0 comments on commit 0e102be

Please sign in to comment.