Skip to content

Commit 99a56f3

Browse files
committed
more support for replaceable #2079
- new APIs getElement* similar to getComponent* but handling also the redeclares - add OMJava to .gitignore - touch *.mat expanded from *.mat.xz to not unpack them each time you run make
1 parent b5a4acc commit 99a56f3

File tree

10 files changed

+379
-249
lines changed

10 files changed

+379
-249
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ autom4te.cache/
1717
build/
1818
NewDocumentation/
1919
OMEncryption/
20+
OMJava/
2021
OMPublicKey/
2122
OMPython/
2223
OMSetup/

OMCompiler/Compiler/FrontEnd/AbsynUtil.mo

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6448,5 +6448,115 @@ algorithm
64486448
end match;
64496449
end isUniontype;
64506450

6451+
public function traverseClassElements<ArgT>
6452+
input Class inClass;
6453+
input FuncType inFunc;
6454+
input ArgT inArg;
6455+
output Class outClass = inClass;
6456+
output ArgT outArg;
6457+
6458+
partial function FuncType
6459+
input Element inElement;
6460+
input ArgT inArg;
6461+
output Element outElement;
6462+
output ArgT outArg;
6463+
output Boolean outContinue;
6464+
end FuncType;
6465+
algorithm
6466+
outClass := match(outClass)
6467+
local
6468+
ClassDef body;
6469+
6470+
case CLASS()
6471+
algorithm
6472+
(body, outArg) := traverseClassDef(outClass.body,
6473+
function traverseClassPartElements(inFunc = inFunc), inArg);
6474+
if not referenceEq(body, outClass.body) then outClass.body := body; end if;
6475+
then
6476+
outClass;
6477+
6478+
end match;
6479+
end traverseClassElements;
6480+
6481+
protected function traverseClassPartElements<ArgT>
6482+
input ClassPart inClassPart;
6483+
input FuncType inFunc;
6484+
input ArgT inArg;
6485+
output ClassPart outClassPart = inClassPart;
6486+
output ArgT outArg = inArg;
6487+
output Boolean outContinue = true;
6488+
6489+
partial function FuncType
6490+
input Element inElement;
6491+
input ArgT inArg;
6492+
output Element outElement;
6493+
output ArgT outArg;
6494+
output Boolean outContinue;
6495+
end FuncType;
6496+
algorithm
6497+
_ := match(outClassPart)
6498+
local
6499+
list<ElementItem> items;
6500+
6501+
case PUBLIC()
6502+
algorithm
6503+
(items, outArg, outContinue) :=
6504+
traverseListGeneric(outClassPart.contents,
6505+
function traverseElementItem(inFunc = inFunc), inArg);
6506+
outClassPart.contents := items;
6507+
then
6508+
();
6509+
6510+
case PROTECTED()
6511+
algorithm
6512+
(items, outArg, outContinue) :=
6513+
traverseListGeneric(outClassPart.contents,
6514+
function traverseElementItem(inFunc = inFunc), inArg);
6515+
outClassPart.contents := items;
6516+
then
6517+
();
6518+
6519+
else ();
6520+
end match;
6521+
end traverseClassPartElements;
6522+
6523+
protected function traverseElementItem<ArgT>
6524+
input ElementItem inItem;
6525+
input FuncType inFunc;
6526+
input ArgT inArg;
6527+
output ElementItem outItem;
6528+
output ArgT outArg;
6529+
output Boolean outContinue;
6530+
6531+
partial function FuncType
6532+
input Element inElement;
6533+
input ArgT inArg;
6534+
output Element outElement;
6535+
output ArgT outArg;
6536+
output Boolean outContinue;
6537+
end FuncType;
6538+
algorithm
6539+
(outItem, outArg, outContinue) := match(inItem)
6540+
local
6541+
Element elem;
6542+
6543+
case ELEMENTITEM()
6544+
algorithm
6545+
(elem, outArg, outContinue) := inFunc(inItem.element, inArg);
6546+
outItem := if referenceEq(elem, inItem.element) then inItem else ELEMENTITEM(elem);
6547+
then
6548+
(outItem, outArg, outContinue);
6549+
6550+
else (inItem, inArg, true);
6551+
end match;
6552+
end traverseElementItem;
6553+
6554+
public function elementSpec
6555+
input Element el;
6556+
output ElementSpec elSpec;
6557+
algorithm
6558+
ELEMENT(specification = elSpec) := el;
6559+
end elementSpec;
6560+
64516561
annotation(__OpenModelica_Interface="frontend");
64526562
end AbsynUtil;

OMCompiler/Compiler/Script/CevalScriptBackend.mo

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ algorithm
15031503
else
15041504
b := false;
15051505
end try;
1506-
1506+
15071507
compileDir := System.pwd() + Autoconf.pathDelimiter;
15081508
executable := filenameprefix;
15091509
initfilename := filenameprefix + "_init_xml";
@@ -2699,6 +2699,52 @@ algorithm
26992699
then
27002700
(cache,Values.BOOL(b));
27012701

2702+
case (cache,_,"getElementModifierNames",{Values.CODE(Absyn.C_TYPENAME(path)),Values.STRING(str1)},_)
2703+
equation
2704+
strings = InteractiveUtil.getElementModifierNames(path, str1, SymbolTable.getAbsyn());
2705+
vals = List.map(strings, ValuesUtil.makeString);
2706+
v = ValuesUtil.makeArray(vals);
2707+
then
2708+
(cache,v);
2709+
2710+
case (cache,_,"getElementModifierValue",{Values.CODE(Absyn.C_TYPENAME(classpath)),Values.CODE(Absyn.C_TYPENAME(path))},_)
2711+
equation
2712+
cr = AbsynUtil.pathToCref(path);
2713+
if AbsynUtil.crefIsIdent(cr) then
2714+
Absyn.CREF_IDENT(name = s1) = cr;
2715+
str = InteractiveUtil.getElementBinding(classpath, s1, SymbolTable.getAbsyn());
2716+
else
2717+
s1 = AbsynUtil.crefFirstIdent(cr);
2718+
cr_1 = AbsynUtil.crefStripFirst(cr);
2719+
str = InteractiveUtil.getElementModifierValue(AbsynUtil.pathToCref(classpath), Absyn.CREF_IDENT(s1, {}), cr_1, SymbolTable.getAbsyn());
2720+
end if;
2721+
then
2722+
(cache,Values.STRING(str));
2723+
2724+
case (cache,_,"getElementModifierValues",{Values.CODE(Absyn.C_TYPENAME(classpath)),Values.CODE(Absyn.C_TYPENAME(path))},_)
2725+
equation
2726+
cr = AbsynUtil.pathToCref(path);
2727+
if AbsynUtil.crefIsIdent(cr) then
2728+
Absyn.CREF_IDENT(name = s1) = cr;
2729+
str = InteractiveUtil.getElementBinding(classpath, s1, SymbolTable.getAbsyn());
2730+
else
2731+
s1 = AbsynUtil.crefFirstIdent(cr);
2732+
cr_1 = AbsynUtil.crefStripFirst(cr);
2733+
str = InteractiveUtil.getElementModifierValues(AbsynUtil.pathToCref(classpath), Absyn.CREF_IDENT(s1, {}), cr_1, SymbolTable.getAbsyn());
2734+
end if;
2735+
then
2736+
(cache,Values.STRING(str));
2737+
2738+
case (cache,_,"removeElementModifiers",
2739+
Values.CODE(Absyn.C_TYPENAME(path))::
2740+
Values.STRING(str1)::
2741+
Values.BOOL(keepRedeclares)::_,_)
2742+
equation
2743+
(p,b) = InteractiveUtil.removeElementModifiers(path, str1, SymbolTable.getAbsyn(), keepRedeclares);
2744+
SymbolTable.setAbsyn(p);
2745+
then
2746+
(cache,Values.BOOL(b));
2747+
27022748
case (cache,_,"removeExtendsModifiers",
27032749
Values.CODE(Absyn.C_TYPENAME(classpath))::
27042750
Values.CODE(Absyn.C_TYPENAME(baseClassPath))::
@@ -3739,7 +3785,7 @@ protected
37393785
Boolean debug = false;
37403786

37413787
algorithm
3742-
3788+
37433789
cache := inCache;
37443790
if not FMI.checkFMIVersion(FMUVersion) then
37453791
outValue := Values.STRING("");
@@ -4006,8 +4052,8 @@ algorithm
40064052
stoptime_r = ValuesUtil.valueReal(stoptime_v);
40074053
tolerance_r = ValuesUtil.valueReal(tolerance_v);
40084054
outSimSettings = SimCodeMain.createSimulationSettings(starttime_r,stoptime_r,interval_i,tolerance_r,method_str,options_str,outputFormat_str,variableFilter_str,cflags);
4009-
4010-
4055+
4056+
40114057
then
40124058
(cache, outSimSettings);
40134059
else
@@ -5317,8 +5363,8 @@ algorithm
53175363
(_,vals) := getListFirstShowError(vals, "while retreaving the tolerance (5 arg) from the buildModel arguments");
53185364
(_,vals) := getListFirstShowError(vals, "while retreaving the method (6 arg) from the buildModel arguments");
53195365
(Values.STRING(filenameprefix),vals) := getListFirstShowError(vals, "while retreaving the fileNamePrefix (7 arg) from the buildModel arguments");
5320-
5321-
5366+
5367+
53225368
(_,vals) := getListFirstShowError(vals, "while retreaving the options (8 arg) from the buildModel arguments");
53235369
(_,vals) := getListFirstShowError(vals, "while retreaving the outputFormat (9 arg) from the buildModel arguments");
53245370
(_,vals) := getListFirstShowError(vals, "while retreaving the variableFilter (10 arg) from the buildModel arguments");

OMCompiler/Compiler/Script/Interactive.mo

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,8 @@ protected
933933
GraphicEnvCache genv;
934934
Absyn.Exp exp;
935935
list<Absyn.Exp> dimensions;
936+
Absyn.CodeNode cn;
937+
Absyn.Element el;
936938
algorithm
937939
fn_name := getApiFunctionNameInfo(inStatement);
938940
p := SymbolTable.getAbsyn();
@@ -948,6 +950,19 @@ algorithm
948950
then
949951
outResult;
950952

953+
case "setElementModifierValue"
954+
algorithm
955+
{Absyn.CREF(componentRef = class_),
956+
Absyn.CREF(componentRef = cr),
957+
Absyn.CODE(code = cn)} := args;
958+
mod := match cn
959+
case Absyn.C_MODIFICATION(modification = mod) then mod;
960+
case Absyn.C_ELEMENT(element = el) then fail();
961+
end match;
962+
(p, outResult) := InteractiveUtil.setElementModifier(class_, cr, mod, p);
963+
then
964+
outResult;
965+
951966
case "setParameterValue"
952967
algorithm
953968
{Absyn.CREF(componentRef = class_), Absyn.CREF(componentRef = crident), exp} := args;
@@ -5936,7 +5951,7 @@ algorithm
59365951
inComponentName, inMod = inMod), false);
59375952
end setComponentSubmodifierInClass;
59385953

5939-
protected function setComponentSubmodifierInCompitems
5954+
public function setComponentSubmodifierInCompitems
59405955
"Helper function to setComponentSubmodifierInClass. Sets the modifier in a
59415956
ComponentItem."
59425957
input list<Absyn.ComponentItem> inComponents;
@@ -5987,7 +6002,7 @@ algorithm
59876002
outContinue := true;
59886003
end setComponentSubmodifierInCompitems;
59896004

5990-
protected function propagateMod
6005+
public function propagateMod
59916006
input Absyn.Path inComponentName;
59926007
input Absyn.Modification inNewMod;
59936008
input Option<Absyn.Modification> inOldMod;
@@ -6115,10 +6130,18 @@ protected function createNestedSubMod
61156130
input Absyn.Path inComponentName;
61166131
input Absyn.Modification inMod;
61176132
output Absyn.ElementArg outSubMod;
6133+
protected
6134+
Absyn.ElementArg e;
61186135
algorithm
61196136
if AbsynUtil.pathIsIdent(inComponentName) then
6120-
outSubMod := Absyn.MODIFICATION(false, Absyn.NON_EACH(), inComponentName,
6121-
SOME(inMod), NONE(), AbsynUtil.dummyInfo);
6137+
outSubMod := match inMod
6138+
case Absyn.CLASSMOD(elementArgLst = {e as Absyn.REDECLARATION()})
6139+
then
6140+
e;
6141+
else
6142+
Absyn.MODIFICATION(false, Absyn.NON_EACH(), inComponentName,
6143+
SOME(inMod), NONE(), AbsynUtil.dummyInfo);
6144+
end match;
61226145
else
61236146
outSubMod := createNestedSubMod(AbsynUtil.pathRest(inComponentName), inMod);
61246147
outSubMod := Absyn.MODIFICATION(false, Absyn.NON_EACH(),

0 commit comments

Comments
 (0)