Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Do not evaluate a function that returns MM arrays


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12662 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Aug 24, 2012
1 parent f6228ca commit 4f9b56c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Compiler/FrontEnd/Ceval.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,9 @@ algorithm
Absyn.Path complexName;
list<Expression.Var> varLst;
list<String> varNames;
DAE.Type ty;
Absyn.Info info;
String str;

// External functions that are "known" should be evaluated without compilation, e.g. all math functions
case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl)),vallst,impl,st,msg)
Expand All @@ -1134,12 +1137,13 @@ algorithm
(cache,Values.RECORD(funcpath,vallst,varNames,-1),st);

// evaluate or generate non-partial and non-replaceable functions
case (cache,env, DAE.CALL(path = funcpath, attr = DAE.CALL_ATTR(builtin = false)), vallst, impl, st, msg)
case (cache,env, DAE.CALL(path = funcpath, attr = DAE.CALL_ATTR(ty = ty, builtin = false)), vallst, impl, st, msg)
equation
failure(cevalIsExternalObjectConstructor(cache, funcpath, env, msg));
Debug.fprintln(Flags.DYN_LOAD, "CALL: try to evaluate or generate function: " +& Absyn.pathString(funcpath));

true = isCompleteFunction(cache, env, funcpath);
false = Types.hasMetaArray(ty);

(cache, newval, st) = cevalCallFunctionEvaluateOrGenerate(inCache,inEnv,inExp,inValuesValueLst,impl,inSymTab,inMsg);

Expand All @@ -1148,7 +1152,7 @@ algorithm
(cache, newval, st);

// partial and replaceable functions should not be evaluated!
case (cache,env, DAE.CALL(path = funcpath, attr = DAE.CALL_ATTR(builtin = false)), vallst, impl, st, msg)
case (cache,env, DAE.CALL(path = funcpath, attr = DAE.CALL_ATTR(ty = ty, builtin = false)), vallst, impl, st, msg)
equation
failure(cevalIsExternalObjectConstructor(cache, funcpath, env, msg));
Debug.fprintln(Flags.DYN_LOAD, "CALL: try to evaluate or generate function: " +& Absyn.pathString(funcpath));
Expand All @@ -1159,6 +1163,15 @@ algorithm
then
fail();

case (cache,env, DAE.CALL(path = funcpath, attr = DAE.CALL_ATTR(ty = ty, builtin = false)), vallst, impl, st, msg as MSG(info))
equation
failure(cevalIsExternalObjectConstructor(cache, funcpath, env, msg));
true = isCompleteFunction(cache, env, funcpath);
true = Types.hasMetaArray(ty);
str = ExpressionDump.printExpStr(inExp);
Error.addSourceMessage(Error.FUNCTION_RETURNS_META_ARRAY, {str}, info);
then fail();

end matchcontinue;
end cevalCallFunction;

Expand Down Expand Up @@ -1271,9 +1284,10 @@ algorithm
SCode.Restriction res;
Interactive.SymbolTable syt;
Absyn.FunctionRestriction funcRest;
DAE.Type ty;

// try function interpretation
case (cache,env, DAE.CALL(path = funcpath, attr = DAE.CALL_ATTR(builtin = false)), vallst, impl, st, msg)
case (cache,env, DAE.CALL(path = funcpath, attr = DAE.CALL_ATTR(ty = ty, builtin = false)), vallst, impl, st, msg)
equation
false = boolOr(Flags.isSet(Flags.NO_EVAL_FUNC), Flags.isSet(Flags.GEN_DEBUG_SYMBOLS));
failure(cevalIsExternalObjectConstructor(cache, funcpath, env, msg));
Expand Down
28 changes: 28 additions & 0 deletions Compiler/FrontEnd/Types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,8 @@ algorithm
then
res;

case (DAE.T_METATYPE(ty = ty)) then unparseType(ty);

case (DAE.T_NORETCALL(_)) then "#NORETCALL#";
case (DAE.T_UNKNOWN(_)) then "#T_UNKNOWN#";
case (DAE.T_ANYTYPE(anyClassType = _)) then "#ANYTYPE#";
Expand Down Expand Up @@ -6429,6 +6431,13 @@ algorithm
tpl = fn((ty,a));
then tpl;

case ((DAE.T_METATYPE(ty,ts),a),_)
equation
((ty,a)) = traverseType((ty,a),fn);
ty = DAE.T_METATYPE(ty,ts);
tpl = fn((ty,a));
then tpl;

case ((DAE.T_METALIST(ty,ts),a),_)
equation
((ty,a)) = traverseType((ty,a),fn);
Expand Down Expand Up @@ -7143,6 +7152,25 @@ algorithm
end match;
end isOverdeterminedType;

public function hasMetaArray
input Type ty;
output Boolean b;
algorithm
((_,b)) := traverseType((ty,false),hasMetaArrayWork);
end hasMetaArray;

protected function hasMetaArrayWork
input tuple<Type,Boolean> inTpl;
output tuple<Type,Boolean> outTpl;
algorithm
outTpl := match inTpl
local
Type ty;
case ((ty as DAE.T_METAARRAY(ty=_), false)) then ((ty,true));
else inTpl;
end match;
end hasMetaArrayWork;

end Types;

/*
Expand Down
2 changes: 2 additions & 0 deletions Compiler/Util/Error.mo
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ public constant Message ORDER_FILE_COMPONENTS = MESSAGE(240, GRAMMAR(), ERROR(),
Util.gettext("Components referenced in the package.order file must be moved in full chunks. Either split the constants to different lines or make them subsequent in the package.order file."));
public constant Message GUARD_EXPRESSION_TYPE_MISMATCH = MESSAGE(241, GRAMMAR(), ERROR(),
Util.gettext("Guard expressions need to be Boolean, got expression of type %s."));
public constant Message FUNCTION_RETURNS_META_ARRAY = MESSAGE(242, TRANSLATION(), ERROR(),
Util.gettext("User-defined function calls that return Array<...> are not supported: %s."));

public constant Message UNBOUND_PARAMETER_WARNING = MESSAGE(500, TRANSLATION(), WARNING(),
Util.gettext("Parameter %s has neither value nor start value, and is fixed during initialization (fixed=true)"));
Expand Down

0 comments on commit 4f9b56c

Please sign in to comment.