Skip to content

Commit 5ed2c5e

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Detect cardinality being used
1 parent c914d20 commit 5ed2c5e

File tree

2 files changed

+10
-33
lines changed

2 files changed

+10
-33
lines changed

Compiler/FrontEnd/NFSCodeDependency.mo

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ protected function analyseItem
277277
input Item inItem;
278278
input Env inEnv;
279279
algorithm
280-
_ := matchcontinue(inItem, inEnv)
280+
// Check if the item is already marked as used, then we can stop here.
281+
if NFSCodeEnv.isItemUsed(inItem) then
282+
return;
283+
end if;
284+
_ := match(inItem, inEnv)
281285
local
282286
SCode.ClassDef cdef;
283287
NFSCodeEnv.Frame cls_env;
@@ -287,13 +291,6 @@ algorithm
287291
SCode.Element cls;
288292
SCode.Comment cmt;
289293

290-
// Check if the item is already marked as used, then we can stop here.
291-
case (_, _)
292-
equation
293-
true = NFSCodeEnv.isItemUsed(inItem);
294-
then
295-
();
296-
297294
// A component, mark it and it's environment as used.
298295
case (NFSCodeEnv.VAR(), env)
299296
equation
@@ -311,6 +308,9 @@ algorithm
311308
equation
312309
markItemAsUsed(inItem, env);
313310
env = NFSCodeEnv.enterFrame(cls_env, env);
311+
if (if cls.name=="cardinality" then match inEnv case {NFSCodeEnv.FRAME(name=NONE())} then true; else false; end match else false) then
312+
System.setUsesCardinality(true);
313+
end if;
314314
analyseClassDef(cdef, res, env, false, info);
315315
analyseMetaType(res, env, info);
316316
analyseComment(cmt, env, info);
@@ -328,7 +328,7 @@ algorithm
328328
then
329329
fail();
330330

331-
end matchcontinue;
331+
end match;
332332
end analyseItem;
333333

334334
protected function analyseItemIfRedeclares

Compiler/FrontEnd/NFSCodeFlatten.mo

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ algorithm
114114
//System.startTimer();
115115
System.tmpTickResetIndex(0, NFSCodeEnv.tmpTickIndex);
116116
System.tmpTickResetIndex(1, NFSCodeEnv.extendsTickIndex);
117+
System.setUsesCardinality(false);
117118
// TODO: Enable this when NFSCodeEnv.tmpTickIndex is removed.
118119
//System.tmpTickResetIndex(0, NFSCodeEnv.tmpTickIndex);
119120

@@ -122,7 +123,6 @@ algorithm
122123
env = NFEnvExtends.update(env);
123124

124125
(prog, env) = NFSCodeDependency.analyse(inClassName, env, prog);
125-
checkForCardinality(env);
126126
(prog, env) = NFSCodeFlattenImports.flattenProgram(prog, env);
127127

128128
//System.stopTimer();
@@ -143,29 +143,6 @@ algorithm
143143
end matchcontinue;
144144
end flattenClassInProgram;
145145

146-
protected function checkForCardinality
147-
"Checks if the cardinality operator is used or not and sets the system flag,
148-
so that some work can be avoided in Inst if cardinality isn't used."
149-
input Env inEnv;
150-
algorithm
151-
_ := matchcontinue(inEnv)
152-
case _
153-
equation
154-
(_, _, _) = NFSCodeLookup.lookupNameSilent(Absyn.IDENT("cardinality"),
155-
inEnv, Absyn.dummyInfo);
156-
System.setUsesCardinality(true);
157-
then
158-
();
159-
160-
else
161-
equation
162-
System.setUsesCardinality(false);
163-
then
164-
();
165-
166-
end matchcontinue;
167-
end checkForCardinality;
168-
169146
public function flattenCompleteProgram
170147
input SCode.Program inProgram;
171148
output SCode.Program outProgram;

0 commit comments

Comments
 (0)