Skip to content

Commit 87ce925

Browse files
authored
Better approach to hide protected variables of encrypted classes (#12421)
* Better approach to hide protected variables of encrypted classes #11718 This reverts the changes done in #12351 and #12372 and adds a new approach The value of `NFVariable.isEncrypted` is passed to `SimVar` and is dumped in the `model_init.xml` file * Updated tests
1 parent 6ba1f8e commit 87ce925

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+220
-211
lines changed

OMCompiler/Compiler/BackEnd/BackendDAE.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ uniontype Var "variables"
253253
.DAE.VarInnerOuter innerOuter "inner, outer, inner outer or unspecified";
254254
Boolean unreplaceable "indicates if it is allowed to replace this variable";
255255
Boolean initNonlinear "indicates if the variable is a nonlinear iteration variable during initialization";
256+
Boolean encrypted "true if the variable belongs to an encrypted class";
256257
end VAR;
257258
end Var;
258259

OMCompiler/Compiler/BackEnd/BackendDAECreate.mo

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,7 @@ algorithm
12501250
DAE.VarVisibility protection;
12511251
Boolean b;
12521252
Absyn.InnerOuter io;
1253+
Boolean encrypted;
12531254

12541255
case DAE.VAR(componentRef = name,
12551256
kind = kind,
@@ -1262,7 +1263,8 @@ algorithm
12621263
source = source,
12631264
variableAttributesOption = dae_var_attr,
12641265
comment = comment,
1265-
innerOuter = io)
1266+
innerOuter = io,
1267+
encrypted = encrypted)
12661268
equation
12671269
(kind_1) = lowerVarkind(kind, t, name, dir, ct, dae_var_attr, protection);
12681270
tp = lowerType(t);
@@ -1272,7 +1274,7 @@ algorithm
12721274
ts = BackendDAEUtil.setTearingSelectAttribute(comment);
12731275
hideResult = BackendDAEUtil.setHideResultAttribute(comment, name);
12741276
then
1275-
(BackendDAE.VAR(name, kind_1, dir, prl, tp, NONE(), NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false, false));
1277+
(BackendDAE.VAR(name, kind_1, dir, prl, tp, NONE(), NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false, false, encrypted));
12761278
end match;
12771279
end lowerDynamicVar;
12781280

@@ -1311,6 +1313,7 @@ algorithm
13111313
list<DAE.Statement> assrtLst;
13121314
list<BackendDAE.Equation> eqLst;
13131315
Absyn.InnerOuter io;
1316+
Boolean encrypted;
13141317
case DAE.VAR(componentRef = name,
13151318
kind = kind,
13161319
direction = dir,
@@ -1323,7 +1326,8 @@ algorithm
13231326
source = source,
13241327
variableAttributesOption = dae_var_attr,
13251328
comment = comment,
1326-
innerOuter = io)
1329+
innerOuter = io,
1330+
encrypted = encrypted)
13271331
equation
13281332
kind_1 = lowerKnownVarkind(kind, name, dir, ct, protection);
13291333
// bind = fixParameterStartBinding(bind, t, dae_var_attr, kind_1);
@@ -1337,7 +1341,7 @@ algorithm
13371341
ts = NONE();
13381342
hideResult = BackendDAEUtil.setHideResultAttribute(comment, name);
13391343
then
1340-
(BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false, false), iInlineHT, eqLst);
1344+
(BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false, false, encrypted), iInlineHT, eqLst);
13411345

13421346
else
13431347
equation
@@ -1378,7 +1382,8 @@ algorithm
13781382
connectorType = element.connectorType,
13791383
innerOuter = DAEUtil.toDAEInnerOuter(element.innerOuter),
13801384
unreplaceable = false,
1381-
initNonlinear = false
1385+
initNonlinear = false,
1386+
encrypted = elem.encrypted
13821387
);
13831388
then SOME(var);
13841389
else NONE();
@@ -1680,6 +1685,7 @@ algorithm
16801685
Option<SCode.Comment> comment;
16811686
DAE.Type t;
16821687
Absyn.InnerOuter io;
1688+
Boolean encrypted;
16831689

16841690
case DAE.VAR(componentRef = name,
16851691
direction = dir,
@@ -1691,14 +1697,15 @@ algorithm
16911697
source = source,
16921698
variableAttributesOption = dae_var_attr,
16931699
comment = comment,
1694-
innerOuter=io)
1700+
innerOuter=io,
1701+
encrypted=encrypted)
16951702
equation
16961703
kind_1 = lowerExtObjVarkind(t);
16971704
tp = lowerType(t);
16981705
ts = NONE();
16991706
hideResult = NONE();
17001707
then
1701-
BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false, false);
1708+
BackendDAE.VAR(name, kind_1, dir, prl, tp, bind, NONE(), dims, source, dae_var_attr, ts, hideResult, comment, ct, DAEUtil.toDAEInnerOuter(io), false, false, encrypted);
17021709
end match;
17031710
end lowerExtObjVar;
17041711

@@ -2408,7 +2415,7 @@ algorithm
24082415
arryDim = {}, source = DAE.emptyElementSource,
24092416
values = NONE(), tearingSelectOption = SOME(BackendDAE.DEFAULT()), hideResult = NONE(),
24102417
comment = NONE(), connectorType = DAE.NON_CONNECTOR(),
2411-
innerOuter = DAE.NOT_INNER_OUTER(), unreplaceable = true, initNonlinear = false) :: inVars;
2418+
innerOuter = DAE.NOT_INNER_OUTER(), unreplaceable = true, initNonlinear = false, encrypted = false) :: inVars;
24122419
outEqs := BackendDAE.EQUATION( exp = DAE.CREF(componentRef = cr, ty = DAE.T_CLOCK_DEFAULT),
24132420
scalar = e, source = DAE.emptyElementSource,
24142421
attr = BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC ) :: inEqs;

OMCompiler/Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5664,7 +5664,7 @@ protected
56645664
algorithm
56655665
(BackendDAE.DAE(eqs, shared), _) := BackendDAEUtil.mapEqSystemAndFold(inDAE, addTimeAsState1, 0);
56665666
orderedVars := BackendVariable.emptyVars();
5667-
var := BackendDAE.VAR(DAE.crefTimeState, BackendDAE.STATE(1, NONE(), true), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true, false);
5667+
var := BackendDAE.VAR(DAE.crefTimeState, BackendDAE.STATE(1, NONE(), true), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true, false, false);
56685668
var := BackendVariable.setVarFixed(var, true);
56695669
var := BackendVariable.setVarStartValue(var, DAE.CREF(DAE.crefTime, DAE.T_REAL_DEFAULT));
56705670
orderedVars := BackendVariable.addVar(var, orderedVars);
@@ -6170,7 +6170,7 @@ algorithm
61706170

61716171
if homotopyLoopBeginning > 0 then
61726172
// Add homotopy lambda to system
6173-
lambda := BackendDAE.VAR(ComponentReference.makeCrefIdent(BackendDAE.homotopyLambda, DAE.T_REAL_DEFAULT, {}), BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true, false);
6173+
lambda := BackendDAE.VAR(ComponentReference.makeCrefIdent(BackendDAE.homotopyLambda, DAE.T_REAL_DEFAULT, {}), BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true, false, false);
61746174
system.orderedVars := BackendVariable.addVar(lambda, system.orderedVars);
61756175
lambdaIdx := BackendVariable.varsSize(system.orderedVars);
61766176

@@ -6356,7 +6356,7 @@ algorithm
63566356

63576357
if hasAnyHomotopy then
63586358
// Add homotopy lambda to system
6359-
lambda := BackendDAE.VAR(ComponentReference.makeCrefIdent(BackendDAE.homotopyLambda, DAE.T_REAL_DEFAULT, {}), BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true, false);
6359+
lambda := BackendDAE.VAR(ComponentReference.makeCrefIdent(BackendDAE.homotopyLambda, DAE.T_REAL_DEFAULT, {}), BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true, false, false);
63606360
system.orderedVars := BackendVariable.addVar(lambda, system.orderedVars);
63616361
end if;
63626362
comps := listReverse(newComps);

OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ protected
401401
algorithm
402402
name := Expression.reductionIterName(iter);
403403
cr := ComponentReference.makeCrefIdent(name,DAE.T_INTEGER_DEFAULT,{});
404-
backendVar := BackendDAE.VAR(cr, BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_INTEGER_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false);
404+
backendVar := BackendDAE.VAR(cr, BackendDAE.VARIABLE(), DAE.BIDIR(), DAE.NON_PARALLEL(), DAE.T_INTEGER_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false, false);
405405
end makeIterVariable;
406406

407407
protected function checkEquationSize"author: Frenkel TUD 2010-12
@@ -7271,30 +7271,30 @@ algorithm
72717271
Option<SCode.Comment> comment;
72727272
DAE.ConnectorType ct;
72737273
DAE.VarInnerOuter io;
7274-
Boolean unreplaceable, initNonlinear;
7274+
Boolean unreplaceable, initNonlinear, encrypted;
72757275
String name;
72767276
Option<BackendDAE.Var> v;
72777277
Option<DAE.Exp> tplExp;
72787278

72797279
case NONE()
72807280
then (NONE(), inTypeA);
72817281

7282-
case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1), tplExp, instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable, initNonlinear)) equation
7282+
case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1), tplExp, instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable, initNonlinear, encrypted)) equation
72837283
(e1_, ext_arg_1) = func(e1, inTypeA);
72847284
(attr_, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, ext_arg_1);
72857285
if referenceEq(e1,e1_) and referenceEq(attr,attr_) then
72867286
v = inVar;
72877287
else
7288-
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1_), tplExp, instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable, initNonlinear));
7288+
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, SOME(e1_), tplExp, instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable, initNonlinear, encrypted));
72897289
end if;
72907290
then (v, ext_arg_2);
72917291

7292-
case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), tplExp, instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable, initNonlinear)) equation
7292+
case SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), tplExp, instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable, initNonlinear, encrypted)) equation
72937293
(attr_, ext_arg_2) = traverseBackendDAEVarAttr(attr, func, inTypeA);
72947294
if referenceEq(attr,attr_) then
72957295
v = inVar;
72967296
else
7297-
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), tplExp, instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable, initNonlinear));
7297+
v = SOME(BackendDAE.VAR(cref, varKind, varDirection, varParallelism, varType, NONE(), tplExp, instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable, initNonlinear, encrypted));
72987298
end if;
72997299
then (v, ext_arg_2);
73007300

OMCompiler/Compiler/BackEnd/BackendEquation.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ algorithm
22792279

22802280
case (_, DAE.RELATION(e1, DAE.LESS(_), e2, _, _)) equation
22812281
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
2282-
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false);
2282+
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false, false);
22832283
rhs = Expression.expSub(e1,e2);
22842284
(rhs, _) = ExpressionSimplify.simplify1(rhs);
22852285
expNull = DAE.RCONST(0.0);
@@ -2289,7 +2289,7 @@ algorithm
22892289

22902290
case (_, DAE.RELATION(e1, DAE.LESSEQ(_), e2, _, _)) equation
22912291
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
2292-
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false);
2292+
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false, false);
22932293
rhs = Expression.expSub(e1,e2);
22942294
(rhs, _) = ExpressionSimplify.simplify1(rhs);
22952295
expNull = DAE.RCONST(0.0);
@@ -2299,7 +2299,7 @@ algorithm
22992299

23002300
case (_, DAE.RELATION(e1, DAE.GREATER(_), e2, _, _)) equation
23012301
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
2302-
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false);
2302+
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false, false);
23032303
rhs = Expression.expSub(e2,e1);
23042304
(rhs, _) = ExpressionSimplify.simplify1(rhs);
23052305
expNull = DAE.RCONST(0.0);
@@ -2309,7 +2309,7 @@ algorithm
23092309

23102310
case (_, DAE.RELATION(e1, DAE.GREATEREQ(_), e2, _, _)) equation
23112311
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
2312-
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false);
2312+
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false, false);
23132313
rhs = Expression.expSub(e2,e1);
23142314
(rhs, _) = ExpressionSimplify.simplify(rhs);
23152315
expNull = DAE.RCONST(0.0);
@@ -2319,7 +2319,7 @@ algorithm
23192319

23202320
case (_, DAE.RELATION(e1, DAE.EQUAL(_), e2, _, _)) equation
23212321
lhs = ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
2322-
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false);
2322+
dummyVar = BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false, false);
23232323
rhs = Expression.expSub(e2,e1);
23242324
(rhs, _) = ExpressionSimplify.simplify(rhs);
23252325
expNull = DAE.RCONST(0.0);
@@ -2334,7 +2334,7 @@ algorithm
23342334
end try;
23352335

23362336
lhs := ComponentReference.makeCrefIdent(conCrefName, DAE.T_REAL_DEFAULT, {});
2337-
dummyVar := BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false);
2337+
dummyVar := BackendDAE.VAR(lhs, conKind, DAE.OUTPUT(), DAE.NON_PARALLEL(), DAE.T_REAL_DEFAULT, NONE(), NONE(), {}, DAE.emptyElementSource, NONE(), NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), false, false, false);
23382338
dummyVar := BackendVariable.mergeAliasVars(dummyVar, v, false, knvars);
23392339
eqn := BackendDAE.SOLVED_EQUATION(lhs, e1, Source, BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN);
23402340

OMCompiler/Compiler/BackEnd/BackendInline.mo

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,12 @@ algorithm
510510
Boolean b1,b2;
511511
DAE.VarInnerOuter io;
512512
Boolean unreplaceable;
513+
Boolean e;
513514

514-
case BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,tplExp,arrayDim,source,values,ts,hideResult,comment,ct,io,unreplaceable) equation
515+
case BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,tplExp,arrayDim,source,values,ts,hideResult,comment,ct,io,unreplaceable,_,e) equation
515516
(bind,source,b1) = Inline.inlineExpOpt(bind,inElementList,source);
516517
(values1,source,b2) = Inline.inlineStartAttribute(values,source,inElementList);
517-
then (BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,tplExp,arrayDim,source,values1,ts,hideResult,comment,ct,io,unreplaceable,false), b1 or b2);
518+
then (BackendDAE.VAR(varName,varKind,varDirection,varParallelism,varType,bind,tplExp,arrayDim,source,values1,ts,hideResult,comment,ct,io,unreplaceable,false,e), b1 or b2);
518519

519520
else (inVar, false);
520521
end match;

0 commit comments

Comments
 (0)