Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 177b914

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Do not elaborate using scripting functions in models
For example, looking in OpenModelica.Scripting.xxx should not succeed in models when performing model translation. It should only be performed in the scripting context. Belonging to [master]: - #2126 - OpenModelica/OpenModelica-testsuite#834
1 parent fbbbe20 commit 177b914

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

Compiler/FrontEnd/BackendInterface.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ algorithm
7171
(outCache, outValue) := CevalScript.cevalCallFunction(inCache, inEnv, inExp, inValues, inImplInst, inMsg, inNumIter);
7272
end cevalCallFunction;
7373

74-
public function elabCallInteractive
74+
public function elabCallInteractive "Note: elabCall_InteractiveFunction is set in the error buffer; the called function should pop it"
7575
input FCore.Cache inCache;
7676
input FCore.Graph inEnv;
7777
input Absyn.ComponentRef inCref;

Compiler/FrontEnd/Static.mo

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6737,24 +6737,10 @@ algorithm
67376737
then
67386738
fail();
67396739

6740-
case () /* impl LS: Check if a builtin function call, e.g. size() and calculate if so */
6740+
case ()
6741+
/* Handle the scripting interface */
67416742
algorithm
6742-
/* Remove errors relating to elabCallArgs, keeping only elabCallInteractive messages.
6743-
* Push these messages back if BackendInterface fails.
6744-
* This order is necessary if getErrorString() is called in the Backend (runScript, etc)
6745-
*/
6746-
handles := ErrorExt.popCheckPoint("elabCall_InteractiveFunction");
6747-
try
6748-
/* An extra try-block to avoid the assignment to handles being optimized away */
6749-
ErrorExt.setCheckpoint("elabCall_InteractiveFunction1");
6750-
(cache,e,prop) := BackendInterface.elabCallInteractive(cache, env, fn, args, nargs, impl, pre, info) "Elaborate interactive function calls, such as simulate(), plot() etc." ;
6751-
ErrorExt.delCheckpoint("elabCall_InteractiveFunction1");
6752-
else
6753-
ErrorExt.rollBack("elabCall_InteractiveFunction1");
6754-
ErrorExt.pushMessages(handles);
6755-
fail();
6756-
end try;
6757-
ErrorExt.freeMessages(handles);
6743+
(cache,e,prop) := BackendInterface.elabCallInteractive(cache, env, fn, args, nargs, impl, pre, info) "Elaborate interactive function calls, such as simulate(), plot() etc." ;
67586744
then (cache,e,prop);
67596745

67606746
end matchcontinue;

Compiler/Script/StaticScript.mo

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,40 @@ algorithm
239239
end getSimulationArguments;
240240

241241
public function elabCallInteractive "This function elaborates the functions defined in the interactive environment.
242+
Since some of these functions are meta-functions, they can not be described in the type
243+
system, and is thus given the the type T_UNKNOWN"
244+
input output FCore.Cache cache;
245+
input FCore.Graph env;
246+
input Absyn.ComponentRef fn;
247+
input list<Absyn.Exp> args;
248+
input list<Absyn.NamedArg> nargs;
249+
input Boolean impl;
250+
input Prefix.Prefix pre;
251+
input SourceInfo info;
252+
output DAE.Exp e;
253+
output DAE.Properties prop;
254+
protected
255+
list<Integer> handles;
256+
algorithm
257+
if Flags.getConfigBool(Flags.BUILDING_MODEL) then
258+
ErrorExt.delCheckpoint("elabCall_InteractiveFunction");
259+
fail();
260+
end if;
261+
handles := ErrorExt.popCheckPoint("elabCall_InteractiveFunction");
262+
try
263+
/* An extra try-block to avoid the assignment to handles being optimized away */
264+
ErrorExt.setCheckpoint("elabCall_InteractiveFunction1");
265+
(cache,e,prop) := elabCallInteractive_work(cache, env, fn, args, nargs, impl, pre, info) "Elaborate interactive function calls, such as simulate(), plot() etc." ;
266+
ErrorExt.delCheckpoint("elabCall_InteractiveFunction1");
267+
else
268+
ErrorExt.rollBack("elabCall_InteractiveFunction1");
269+
ErrorExt.pushMessages(handles);
270+
fail();
271+
end try;
272+
ErrorExt.freeMessages(handles);
273+
end elabCallInteractive;
274+
275+
protected function elabCallInteractive_work "This function elaborates the functions defined in the interactive environment.
242276
Since some of these functions are meta-functions, they can not be described in the type
243277
system, and is thus given the the type T_UNKNOWN"
244278
input FCore.Cache inCache;
@@ -252,7 +286,7 @@ public function elabCallInteractive "This function elaborates the functions defi
252286
output FCore.Cache outCache;
253287
output DAE.Exp outExp;
254288
output DAE.Properties outProperties;
255-
algorithm
289+
algorithm
256290
(outCache,outExp,outProperties):=
257291
matchcontinue
258292
(inCache,inEnv,inComponentRef,inExps,inNamedArgs,inImplInst,inPrefix,info)
@@ -467,7 +501,7 @@ public function elabCallInteractive "This function elaborates the functions defi
467501
DAE.T_STRING_DEFAULT),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_CONST()));
468502

469503
end matchcontinue;
470-
end elabCallInteractive;
504+
end elabCallInteractive_work;
471505

472506
public function elabExp "
473507
function: elabExp
@@ -560,7 +594,7 @@ algorithm
560594
Prefix.Prefix pre;
561595
case (cache,env,fn,args,nargs,impl,pre,_,_)
562596
equation
563-
(cache,e,prop) = elabCallInteractive(cache, env, fn, args, nargs, impl, pre, info) "Elaborate interactive function calls, such as simulate(), plot() etc." ;
597+
(cache,e,prop) = elabCallInteractive_work(cache, env, fn, args, nargs, impl, pre, info) "Elaborate interactive function calls, such as simulate(), plot() etc." ;
564598
then
565599
(cache,e,prop);
566600
end match;

0 commit comments

Comments
 (0)