Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Fix so that X.identity does not lookup the builtin identity function
  - This is just a partial fix of the problems we have with builtin functions


git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6342 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 12, 2010
1 parent 1f5f5ec commit 080ea0e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 58 deletions.
88 changes: 45 additions & 43 deletions Compiler/Lookup.mo
Expand Up @@ -1543,19 +1543,41 @@ algorithm
Env.Frame f;
list<DAE.Type> res;
DAE.DAElist dae;
Env.AvlTree httypes;
Env.AvlTree ht;
String str;

case (cache,env,Absyn.FULLYQUALIFIED(id))
/* Builtin operators are looked up in top frame directly */
case (cache,env,(id as Absyn.IDENT(name = str)))
equation
f = Env.topFrame(env);
(cache,res) = lookupFunctionsInEnv2(cache, {f}, id);
then (cache,res);
_ = Static.elabBuiltinHandler(str) "Check for builtin operators" ;
(cache,env as {Env.FRAME(clsAndVars = ht,types = httypes)}) = Builtin.initialEnv(cache);
(cache,res) = lookupFunctionsInFrame(cache, ht, httypes, env, str);
then
(cache,res);

/* Check for special builtin operators that can not be represented in environment like for instance cardinality.*/
case (cache,_,id as Absyn.IDENT(name = str))
equation
_ = Static.elabBuiltinHandlerGeneric(str);
(cache,env) = Builtin.initialEnv(cache);
res = createGenericBuiltinFunctions(env, str);
then
(cache,res);

case (cache,env,id)
equation
failure(Absyn.FULLYQUALIFIED(_) = id);
(cache,res) = lookupFunctionsInEnv2(cache,env,id);
(cache,res) = lookupFunctionsInEnv2(cache,env,id,false);
then (cache,res);

case (cache,env,Absyn.FULLYQUALIFIED(id))
equation
f = Env.topFrame(env);
(cache,res) = lookupFunctionsInEnv2(cache,{f},id,true);
then (cache,res);

case (cache,_,_) then (cache,{});
case (_,_,id)
equation
true = RTOpts.debugFlag("failtrace");
Expand All @@ -1571,10 +1593,11 @@ protected function lookupFunctionsInEnv2
input Env.Cache inCache;
input Env.Env inEnv;
input Absyn.Path inPath;
input Boolean followedQual "cannot pop frames if we followed a qualified path at any point";
output Env.Cache outCache;
output list<DAE.Type> outTypesTypeLst;
algorithm
(outCache,outTypesTypeLst) := matchcontinue (inCache,inEnv,inPath)
(outCache,outTypesTypeLst) := matchcontinue (inCache,inEnv,inPath,followedQual)
local
Absyn.Path id,iid,path;
Option<String> sid;
Expand All @@ -1590,34 +1613,16 @@ algorithm
Env.Frame f;
Env.Cache cache;
DAE.DAElist dae;
case (cache,{},id) then (cache,{});

/* Builtin operators are looked up in top frame directly */
case (cache,env,(id as Absyn.IDENT(name = str)))
equation
_ = Static.elabBuiltinHandler(str) "Check for builtin operators" ;
Env.FRAME(clsAndVars = ht,types = httypes) = Env.topFrame(env);
(cache,res) = lookupFunctionsInFrame(cache, ht, httypes, env, str);
then
(cache,res);

/* Check for special builtin operators that can not be represented in environment like for instance cardinality.*/
case (cache,env,id as Absyn.IDENT(name = str))
equation
_ = Static.elabBuiltinHandlerGeneric(str);
res = createGenericBuiltinFunctions(env, str);
then
(cache,res);

/* Simple name, search frame */
case (cache,(env as (Env.FRAME(optName = sid,clsAndVars = ht,types = httypes) :: fs)),id as Absyn.IDENT(name = str))
case (cache,(env as (Env.FRAME(optName = sid,clsAndVars = ht,types = httypes) :: fs)),id as Absyn.IDENT(name = str),followedQual)
equation
(cache,res as _::_)= lookupFunctionsInFrame(cache, ht, httypes, env, str);
then
(cache,res);

/* Simple name, if class with restriction function found in frame instantiate to get type. */
case (cache, f::fs, id as Absyn.IDENT(name = str))
case (cache, f::fs, id as Absyn.IDENT(name = str),followedQual)
equation
// adrpo: do not search in the entire environment as we anyway recurse with the fs argument!
// just search in {f} not f::fs as otherwise we might get us in an infinite loop
Expand All @@ -1634,7 +1639,7 @@ algorithm
(cache,res);

/* For qualified function names, e.g. Modelica.Math.sin */
case (cache,(env as (Env.FRAME(optName = sid,clsAndVars = ht,types = httypes) :: fs)),id as Absyn.QUALIFIED(name = pack,path = path))
case (cache,(env as (Env.FRAME(optName = sid,clsAndVars = ht,types = httypes) :: fs)),id as Absyn.QUALIFIED(name = pack,path = path),followedQual)
equation
(cache,(c as SCode.CLASS(name=str,encapsulatedPrefix=encflag,restriction=restr)),env_1) = lookupClass(cache, env, Absyn.IDENT(pack), false) ;
env2 = Env.openScope(env_1, encflag, SOME(str), Env.restrictionToScopeType(restr));
Expand All @@ -1647,14 +1652,21 @@ algorithm
cache, env2, InnerOuter.emptyInstHierarchy,
DAE.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
ci_state, c, false, {});
(cache,res) = lookupFunctionsInEnv2(cache, env_2, path);
(cache,res) = lookupFunctionsInEnv2(cache, env_2, path, true);
then
(cache,res);

/* Did not match. Search next frame. */
case (cache,f::fs,id)
case (cache,Env.FRAME(isEncapsulated = false)::fs,id,false)
equation
(cache,res) = lookupFunctionsInEnv2(cache, fs, id);
(cache,res) = lookupFunctionsInEnv2(cache, fs, id, false);
then
(cache,res);

case (cache,Env.FRAME(isEncapsulated = true)::env,id as Absyn.IDENT(name = str),false)
equation
(cache,env) = Builtin.initialEnv(cache);
(cache,res) = lookupFunctionsInEnv2(cache, env, id, true);
then
(cache,res);

Expand Down Expand Up @@ -1873,7 +1885,7 @@ algorithm
(cache,env_1,_) =
Inst.implicitFunctionTypeInstantiation(cache,cenv,InnerOuter.emptyInstHierarchy,cdef) ;

(cache,tps) = lookupFunctionsInEnv2(cache,env_1, Absyn.IDENT(id));
(cache,tps) = lookupFunctionsInEnv2(cache,env_1,Absyn.IDENT(id),true);
then
(cache,tps);

Expand Down Expand Up @@ -2113,20 +2125,10 @@ algorithm
case (cache,path)
equation
(cache,i_env) = Builtin.initialEnv(cache);
(cache,{}) = lookupFunctionsInEnv2(cache,i_env, path);
then
(cache,false);
case (cache,path)
equation
(cache,i_env) = Builtin.initialEnv(cache);
(cache,_) = lookupFunctionsInEnv2(cache,i_env, path);
(cache,_::_) = lookupFunctionsInEnv2(cache,i_env,path,true);
then
(cache,true);
case (cache,path)
equation
Debug.fprintln("failtrace", "is_in_builtin_env failed");
then
fail();
case (cache,path) then (cache,false);
end matchcontinue;
end isInBuiltinEnv;

Expand Down
26 changes: 11 additions & 15 deletions Compiler/Static.mo
Expand Up @@ -2857,7 +2857,7 @@ algorithm
// verify type here to see that input arguments are okay.
ty2 = Types.arrayElementType(ty);
true = typeChecker(ty2);
(cache,s1_1,(prop as DAE.PROP(ty,c))) = elabCallArgs(cache,env, Absyn.IDENT(fnName), {s1}, {}, impl, NONE,pre);
(cache,s1_1,(prop as DAE.PROP(ty,c))) = elabCallArgs(cache,env, Absyn.FULLYQUALIFIED(Absyn.IDENT(fnName)), {s1}, {}, impl, NONE,pre);
then
(cache,s1_1,prop);
end matchcontinue;
Expand Down Expand Up @@ -5979,11 +5979,6 @@ algorithm
then
(cache, call, DAE.PROP(ty,DAE.C_VAR));

case (cache,env,{dim},_,impl,pre)
equation
print("-elab_builtin_identity failed\n");
then
fail();
end matchcontinue;
end elabBuiltinIdentity;

Expand Down Expand Up @@ -6747,8 +6742,9 @@ protected function isBuiltinFunc "function: isBuiltinFunc
input Prefix inPrefix;
output Env.Cache outCache;
output Boolean outBoolean;
output Absyn.Path outPath "make the path non-FQ";
algorithm
(outCache,outBoolean) := matchcontinue (inCache,inPath,inPrefix)
(outCache,outBoolean,outPath) := matchcontinue (inCache,inPath,inPrefix)
local
Ident id;
Absyn.Path path;
Expand All @@ -6758,23 +6754,23 @@ algorithm
equation
_ = elabBuiltinHandler(id);
then
(cache,true);
(cache,true,inPath);
case (cache,Absyn.FULLYQUALIFIED(path),pre)
equation
(cache,true) = isBuiltinFunc(cache,path,pre);
(cache,true,path) = isBuiltinFunc(cache,path,pre);
then
(cache,true);
(cache,true,path);
case (cache, Absyn.QUALIFIED("Connections", Absyn.IDENT("isRoot")),_)
then
(cache,true);
(cache,true,inPath);
case (cache,path,pre)
equation
failure(Absyn.FULLYQUALIFIED(_) = path);
(cache,true) = Lookup.isInBuiltinEnv(cache,path);
checkSemiSupportedFunctions(path,pre);
then
(cache,true);
case (cache,_,_) then (cache,false);
(cache,true,inPath);
case (cache,_,_) then (cache,false,inPath);
end matchcontinue;
end isBuiltinFunc;

Expand Down Expand Up @@ -8667,7 +8663,7 @@ algorithm
"The constness of a function depends on the inputs. If all inputs are constant the call itself is constant." ;
fn_1 = deoverloadFuncname(fn, functype);
tuple_ = isTuple(restype);
(cache,builtin) = isBuiltinFunc(cache,fn_1,pre);
(cache,builtin,fn_1) = isBuiltinFunc(cache,fn_1,pre);
const = Util.listFold(constlist, Types.constAnd, DAE.C_CONST());
(cache,const) = determineConstSpecialFunc(cache,env,const,fn);
tyconst = elabConsts(restype, const);
Expand Down Expand Up @@ -10356,7 +10352,7 @@ algorithm
//true = RTOpts.debugFlag("fnptr") or RTOpts.acceptMetaModelicaGrammar();
path = Absyn.crefToPath(c);
(cache,typelist) = Lookup.lookupFunctionsInEnv(cache,env,path);
(cache, isBuiltinFunc) = isBuiltinFunc(cache,path,pre);
(cache, isBuiltinFunc, path) = isBuiltinFunc(cache,path,pre);
{t} = typelist;
(tt,optPath) = t;
t = (tt, Util.if_(isBuiltinFunc, SOME(path), optPath)) "builtin functions store NONE there";
Expand Down
8 changes: 8 additions & 0 deletions Compiler/Types.mo
Expand Up @@ -5145,12 +5145,20 @@ algorithm

case (exp,actual,expected,polymorphicBindings,printFailtrace)
equation
false = RTOpts.acceptMetaModelicaGrammar();
(e_1,e_type_1) = matchType(exp,actual,expected,printFailtrace);
then
(e_1,e_type_1,polymorphicBindings);
case (exp,actual,expected,polymorphicBindings,printFailtrace)
equation
true = RTOpts.acceptMetaModelicaGrammar();
{} = getAllInnerTypesOfType(expected, isPolymorphic);
(e_1,e_type_1) = matchType(exp,actual,expected,printFailtrace);
then
(e_1,e_type_1,polymorphicBindings);
case (exp,actual,expected,polymorphicBindings,_)
equation
true = RTOpts.acceptMetaModelicaGrammar();
_::_ = getAllInnerTypesOfType(expected, isPolymorphic);
(exp,actual) = matchType(exp,actual,(DAE.T_BOXED((DAE.T_NOTYPE(),NONE())),NONE()),printFailtrace);
polymorphicBindings = subtypePolymorphic(actual,expected,polymorphicBindings);
Expand Down

0 comments on commit 080ea0e

Please sign in to comment.