@@ -3836,6 +3836,9 @@ algorithm
38363836end getHomotopyArguments;
38373837
38383838protected function elabBuiltinDynamicSelect
3839+ "Elaborates DynamicSelect statements in annotations for OMEdit.
3840+ Currently only text annotations with one String statement accessing
3841+ one variable are supported. Otherwise the first argument is returned."
38393842 input FCore . Cache inCache;
38403843 input FCore . Graph inEnv;
38413844 input list< Absyn . Exp > inPosArgs;
@@ -3846,9 +3849,44 @@ protected function elabBuiltinDynamicSelect
38463849 output FCore . Cache outCache = inCache;
38473850 output DAE . Exp outExp;
38483851 output DAE . Properties outProperties;
3852+ protected
3853+ String msg_str;
3854+ Absyn . Exp astatic, adynamic;
38493855algorithm
3850- (outCache, outExp, outProperties) := elabExpInExpression(inCache, inEnv,
3851- listHead(inPosArgs), inImplicit, NONE (), true , inPrefix, inInfo);
3856+ if listLength(inPosArgs) <> 2 or not listEmpty(inNamedArgs) then
3857+ msg_str := ", expected DynamicSelect(staticExp, dynamicExp)" ;
3858+ printBuiltinFnArgError("DynamicSelect" , msg_str, inPosArgs, inNamedArgs, inPrefix, inInfo);
3859+ end if ;
3860+ {astatic, adynamic} := inPosArgs;
3861+ _ := match adynamic
3862+ local
3863+ DAE . Exp dstatic, ddynamic;
3864+ DAE . Type ty;
3865+ Absyn . ComponentRef acref;
3866+ Integer digits;
3867+ list< Absyn . NamedArg > namedArgs;
3868+ case Absyn . CALL (function_ = Absyn . CREF_IDENT (name = "String" ), functionArgs = Absyn . FUNCTIONARGS (args = {Absyn . CREF (componentRef = acref)}, argNames = namedArgs)) algorithm
3869+ // keep DynamicSelect for String with cref arg
3870+ (outCache, dstatic, outProperties as DAE . PROP (ty, _), _) :=
3871+ elabExpInExpression(inCache, inEnv, astatic, inImplicit, NONE (), true , inPrefix, inInfo);
3872+ ddynamic := Expression . crefToExp(absynCrefToComponentReference(acref));
3873+ // Note: can't generate Modelica syntax as OMEdit only parses lists
3874+ // outExp := Expression.makePureBuiltinCall("DynamicSelect", {dstatic,
3875+ // Expression.makePureBuiltinCall("String", {ddynamic}, ty)}, ty);
3876+ outExp := match namedArgs
3877+ case {Absyn . NAMEDARG (argName = "significantDigits" , argValue = Absyn . INTEGER (value = digits))}
3878+ then Expression . makeArray({dstatic, ddynamic, DAE . ICONST (digits)}, ty, true );
3879+ case {Absyn . NAMEDARG (), Absyn . NAMEDARG (argName = "significantDigits" , argValue = Absyn . INTEGER (value = digits))}
3880+ then Expression . makeArray({dstatic, ddynamic, DAE . ICONST (digits)}, ty, true );
3881+ else Expression . makeArray({dstatic, ddynamic}, ty, true );
3882+ end match;
3883+ then ();
3884+ else algorithm
3885+ // return static first argument of DynamicSelect per default
3886+ (outCache, outExp, outProperties) := elabExpInExpression(inCache, inEnv,
3887+ astatic, inImplicit, NONE (), true , inPrefix, inInfo);
3888+ then ();
3889+ end match;
38523890end elabBuiltinDynamicSelect;
38533891
38543892protected function elabBuiltinTranspose
0 commit comments