Skip to content

Commit 83251a0

Browse files
committed
- Make Mod.elabModValue fail if Ceval prints an error message.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25153 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent a4e433a commit 83251a0

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

Compiler/FrontEnd/Absyn.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6255,5 +6255,15 @@ algorithm
62556255
end match;
62566256
end elementArgEqualName;
62576257

6258+
public function optMsg
6259+
"Creates a Msg based on a boolean value."
6260+
input Boolean inShowMessage;
6261+
input SourceInfo inInfo;
6262+
output Msg outMsg;
6263+
algorithm
6264+
outMsg := if inShowMessage then MSG(inInfo) else NO_MSG();
6265+
annotation(__OpenModelica_EarlyInline = true);
6266+
end optMsg;
6267+
62586268
annotation(__OpenModelica_Interface="frontend");
62596269
end Absyn;

Compiler/FrontEnd/Mod.mo

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ algorithm
165165
// print("Mod.elabMod: calling elabExp on mod exp: " + Dump.printExpStr(e) + " in env: " + FGraph.printGraphPathStr(env) + "\n");
166166
(cache,e_1,prop,_) = Static.elabExp(cache, env, e, impl, NONE(), Config.splitArrays(), pre, info); // Vectorize only if arrays are expanded
167167
(cache, e_1, prop) = Ceval.cevalIfConstant(cache, env, e_1, prop, impl, info);
168-
(cache,e_val) = elabModValue(cache, env, e_1, prop, impl, info);
168+
(e_val) = elabModValue(cache, env, e_1, prop, impl, info);
169169
(cache,e_2) = PrefixUtil.prefixExp(cache, env, ih, e_1, pre)
170170
"Bug: will cause elaboration of parameters without value to fail,
171171
But this can be ok, since a modifier is present, giving it a value from outer modifications.." ;
@@ -403,40 +403,40 @@ algorithm
403403
end elabModQualifyTypespec;
404404

405405
protected function elabModValue
406-
"author: PA
407-
Helper function to elabMod. Builds values from modifier expressions if possible.
408-
Tries to Constant evaluate an expressions an create a Value option for it."
406+
"Helper function to elabMod. Tries to constant evaluate a modifier expression."
409407
input FCore.Cache inCache;
410408
input FCore.Graph inEnv;
411409
input DAE.Exp inExp;
412410
input DAE.Properties inProp;
413-
input Boolean impl;
411+
input Boolean inImpl;
414412
input SourceInfo inInfo;
415-
output FCore.Cache outCache;
416-
output Option<Values.Value> outValuesValueOption;
417-
algorithm
418-
(outCache,outValuesValueOption) :=
419-
matchcontinue (inCache,inEnv,inExp,inProp,impl,inInfo)
420-
local
421-
Values.Value v;
422-
Absyn.Msg msg;
423-
FCore.Cache cache;
424-
DAE.Const c;
425-
case (_,_,_,_,_,_)
426-
equation
427-
c = Types.propAllConst(inProp);
428-
// Don't ceval variables.
429-
false = Types.constIsVariable(c);
430-
// Show error messages from ceval only if the expression is a constant.
431-
msg = if Types.constIsConst(c) and not impl then Absyn.MSG(inInfo) else Absyn.NO_MSG();
432-
(_,v,_) = Ceval.ceval(inCache,inEnv,inExp,false,NONE(),msg,0);
433-
then
434-
(inCache /*Yeah; this makes sense :)*/,SOME(v));
435-
// Constant evaluation failed, return no value.
436-
else (inCache,NONE());
437-
end matchcontinue;
413+
output Option<Values.Value> outValue = NONE();
414+
protected
415+
Integer err_count;
416+
Absyn.Msg msg;
417+
DAE.Const c;
418+
Values.Value v;
419+
algorithm
420+
c := Types.propAllConst(inProp);
421+
422+
// If the expression is a parameter or constant expression:
423+
if not Types.constIsVariable(c) then
424+
// Show error messages from ceval only if the expression is constant.
425+
msg := Absyn.optMsg(Types.constIsConst(c) and not inImpl, inInfo);
426+
err_count := Error.getNumErrorMessages();
427+
428+
try
429+
(_, v) := Ceval.ceval(inCache, inEnv, inExp, false, NONE(), msg, 0);
430+
outValue := SOME(v);
431+
else
432+
// Fail if ceval gave an error.
433+
if err_count <> Error.getNumErrorMessages() then
434+
fail();
435+
end if;
436+
end try;
437+
end if;
438438
end elabModValue;
439-
439+
440440
public function unelabMod
441441
"Transforms Mod back to SCode.Mod, loosing type information."
442442
input DAE.Mod inMod;
@@ -616,7 +616,7 @@ algorithm
616616
(cache,subs_1) = updateSubmods(cache, env, ih, pre, subs, impl, info);
617617
(cache,e_1,prop,_) = Static.elabExp(cache, env, e, impl,NONE(), true, pre, info);
618618
(cache, e_1, prop) = Ceval.cevalIfConstant(cache, env, e_1, prop, impl, info);
619-
(cache,e_val) = elabModValue(cache,env,e_1,prop,impl,info);
619+
(e_val) = elabModValue(cache,env,e_1,prop,impl,info);
620620
(cache,e_2) = PrefixUtil.prefixExp(cache, env, ih, e_1, pre);
621621
if Flags.isSet(Flags.UPDMOD) then
622622
Debug.trace("Updated mod: ");

0 commit comments

Comments
 (0)