Skip to content

Commit

Permalink
Fixed bug in lookup of constants in packages throuh inherited classes.
Browse files Browse the repository at this point in the history
Partly fixed bug in array equations.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2428 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jun 13, 2006
1 parent dd08d14 commit 3944c4b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 93 deletions.
22 changes: 13 additions & 9 deletions Compiler/DAELow.mo
Expand Up @@ -10205,22 +10205,26 @@ algorithm
es_1 = replaceVariables(es, s, t);
then
(WHEN_EQUATION(WHEN_EQ(i,cr_1,e2_1)) :: es_1);
case ((ALGORITHM(index = indx,in_ = inputs,out = outputs) :: es),s,t) /* algorithms are replaced separately in translate_dae_replace */

/* algorithms are replaced also in translateDaeReplace */
case ((ALGORITHM(index = indx,in_ = inputs,out = outputs) :: es),s,t)
equation
es_1 = replaceVariables(es, s, t);
inputs = Util.listMap(Util.listMap22(inputs,Exp.replaceExpList,s,t),Util.tuple21);

inputs = Util.listMap(Util.listMap22(inputs,Exp.replaceExpList,s,t),Util.tuple21);
outputs = Util.listMap(Util.listMap22(outputs,Exp.replaceExpList,s,t),Util.tuple21);
es_1 = replaceVariables(es, s, t);
then
(ALGORITHM(indx,inputs,outputs) :: es_1);
case ((ARRAY_EQUATION(index = indx,crefOrDerCref = expl) :: es),s,t) /* array eqns are replaced separatedly in translate_dae_replace */

/* array eqns are also replaced in translateDaeReplace */
case ((ARRAY_EQUATION(index = indx,crefOrDerCref = expl) :: es),s,t)
equation
expl = Util.listMap(Util.listMap22(expl,Exp.replaceExpList,s,t),Util.tuple21);
es_1 = replaceVariables(es, s, t);
then
(ARRAY_EQUATION(indx,expl) :: es_1);
case (_,_,_)
equation
print("-replace_variables failed\n");
print("-replaceVariables failed\n");
then
fail();
end matchcontinue;
Expand Down Expand Up @@ -10421,7 +10425,7 @@ algorithm
(s,t);
case (vars,eqns)
equation
print("-variable_replacements failed\n");
print("-variableReplacements failed\n");
then
fail();
end matchcontinue;
Expand Down Expand Up @@ -10456,7 +10460,7 @@ algorithm
(s,t);
case (vars,knvars,extvars)
equation
print("-variable_replacements_no_dollar failed\n");
print("-variableReplacementsNoDollar failed\n");
then
fail();
end matchcontinue;
Expand Down Expand Up @@ -10505,7 +10509,7 @@ algorithm
fail();
case (_)
equation
print("-variable_replacements_remove_dollar failed\n");
print("-variableReplacementsRemoveDollar failed\n");
then
fail();
end matchcontinue;
Expand Down
6 changes: 2 additions & 4 deletions Compiler/Env.mo
Expand Up @@ -719,8 +719,7 @@ algorithm
s4 = printEnvStr(bcframes);
res = Util.stringAppendList(
{"FRAME: ",sid," (enc=",encflag_str,
") \nclasses and vars:\n=============\n",s1," Types:\n======\n",s2," Imports:\n=======\n",s3,
" bcframes:\n=======\n",s4,"\n\n\n"});
") \nclasses and vars:\n=============\n",s1," Types:\n======\n",s2," Imports:\n=======\n",s3,"\n"});
then
res;
case FRAME(class_1 = NONE,list_2 = ht,list_3 = httypes,list_4 = imps,list_5 = bcframes,current6 = crs,encapsulated_7 = encflag)
Expand All @@ -732,8 +731,7 @@ algorithm
encflag_str = Util.boolString(encflag);
res = Util.stringAppendList(
{"FRAME: unnamed (enc=",encflag_str,
") \nclasses and vars:\n=============\n",s1," Types:\n======\n",s2," Imports:\n=======\n",s3,
" bcframes:\n=======\n",s4,"\n\n\n"});
") \nclasses and vars:\n=============\n",s1," Types:\n======\n",s2," Imports:\n=======\n",s3,"\n"});
then
res;
end matchcontinue;
Expand Down
4 changes: 3 additions & 1 deletion Compiler/Inst.mo
Expand Up @@ -911,7 +911,7 @@ algorithm
(cache,dae1,env_3,(csets_1 as Connect.SETS(_,crs)),ci_state_1,tys,bc_ty)
= instClassIn(cache,env_1, mod, pre, csets, ci_state, c, false, inst_dims, impl) ;
(cache,fq_class) = makeFullyQualified(cache,env, Absyn.IDENT(n));

dae1_1 = DAE.setComponentType(dae1, fq_class);
callscope_1 = isTopCall(callscope);
dae2 = Connect.equations(csets_1);
Expand Down Expand Up @@ -1089,7 +1089,9 @@ algorithm
//Debug.fprint("insttr", implstr);
//Debug.fprint("insttr", clsname);
//Debug.fprint("insttr", "\n");
//print("instClassDef, ");print(n);print(" env:");print(Env.printEnvStr(env));
(cache,l,env_1,csets_1,ci_state_1,tys,bc) = instClassdef(cache,env, mods, pre, csets, ci_state, d, r, prot, inst_dims, impl);
//print("instClassDef, outenv:");print(Env.printEnvStr(env));
cache = addCachedEnv(cache,n,env_1);
then
(cache,l,env_1,csets_1,ci_state_1,tys,bc);
Expand Down
104 changes: 25 additions & 79 deletions Compiler/Lookup.mo
Expand Up @@ -259,7 +259,7 @@ algorithm
ClassInf.State ci_state,cistate1;

/* First look in cache for environment. If found look up class in that environment*/
case (cache,env,path,msg)
case (cache,env,path,msg)
equation
SOME(scope) = Env.getEnvPath(env);
f::fs = Env.cacheGet(scope,path,cache);
Expand Down Expand Up @@ -785,13 +785,14 @@ algorithm
(cache,attr,ty,binding) = lookupVarInternal(cache,env, cref);
then
(cache,attr,ty,binding);
case (cache,env,cref) /* then look in classes (implicitly instantiated packages)
*/
case (cache,env,cref) /* then look in classes (implicitly instantiated packages) */
equation
//print("calling lookupVarInPackages env:");print(Env.printEnvStr(env)); print("END ENV\n");
(cache,attr,ty,binding) = lookupVarInPackages(cache,env, cref);
then
(cache,attr,ty,binding);
case (_,_,_) /* Debug.fprint(\"failtrace\", \"- lookup_var failed\\n\") */ then fail();
case (_,env,cref) equation
/* Debug.fprint(\"failtrace\", \"- lookup_var failed\\n\") */ then fail();
end matchcontinue;
end lookupVar;

Expand All @@ -817,10 +818,12 @@ algorithm
Env.BinTree ht;
list<Env.Item> imps;
list<Env.Frame> fs;
Env.Frame frame;
Exp.ComponentRef ref;
Env.Cache cache;
case (cache,(Env.FRAME(class_1 = sid,list_2 = ht,list_4 = imps) :: fs),ref)
case (cache,((frame as Env.FRAME(class_1 = sid,list_2 = ht,list_4 = imps)) :: fs),ref)
equation
//print("lookup var in frame:");print(Env.printEnvStr({frame}));print("end lookupVar frame\n");
(cache,attr,ty,binding) = lookupVarF(cache,ht, ref);
then
(cache,attr,ty,binding);
Expand Down Expand Up @@ -859,7 +862,7 @@ algorithm
String n,id1,id;
Boolean encflag;
SCode.Restriction r;
list<Env.Frame> env2,env3,env5,env,fs;
list<Env.Frame> env2,env3,env5,env,fs,bcframes;
ClassInf.State ci_state;
list<Types.Var> types;
Types.Attributes attr;
Expand Down Expand Up @@ -915,6 +918,14 @@ algorithm
(cache,attr,ty,bind) = lookupVarLocal(cache,env, cr);
then
(cache,attr,ty,bind);

/* Search base classes */
case (cache,Env.FRAME(list_5 = (bcframes as (_ :: _)))::fs,cref)
equation
(cache,attr,ty,bind) = lookupVar(cache,bcframes, cref);
then
(cache,attr,ty,bind);

case (cache,(env as (Env.FRAME(class_1 = sid,list_4 = items) :: _)),(cr as Exp.CREF_IDENT(ident = id,subscriptLst = sb)))
equation
(cache,attr,ty,bind) = lookupQualifiedImportedVarInFrame(cache,items, env, id);
Expand Down Expand Up @@ -971,17 +982,19 @@ algorithm
Types.Binding binding;
Option<String> sid;
Env.BinTree ht;
list<Env.Frame> fs,env;
Exp.ComponentRef ref;
list<Env.Frame> fs,env,bcframes;
Exp.ComponentRef cref;
Env.Cache cache;
case (cache,(Env.FRAME(class_1 = sid,list_2 = ht) :: fs),ref)
/* Lookup in frame */
case (cache,(Env.FRAME(class_1 = sid,list_2 = ht) :: fs),cref)
equation
(cache,attr,ty,binding) = lookupVarF(cache,ht, ref);
(cache,attr,ty,binding) = lookupVarF(cache,ht, cref);
then
(cache,attr,ty,binding);
case (cache,(Env.FRAME(class_1 = SOME("$for loop scope$")) :: env),ref)

case (cache,(Env.FRAME(class_1 = SOME("$for loop scope$")) :: env),cref)
equation
(cache,attr,ty,binding) = lookupVarLocal(cache,env, ref) "Exception, when in for loop scope allow search of next scope" ;
(cache,attr,ty,binding) = lookupVarLocal(cache,env, cref) "Exception, when in for loop scope allow search of next scope" ;
then
(cache,attr,ty,binding);
end matchcontinue;
Expand Down Expand Up @@ -1960,72 +1973,6 @@ algorithm
end matchcontinue;
end checkSubscripts;

// protected function checkSubscriptsBinding "function: checkSubscriptsBinding

// This function checks a list of subscripts agains type, and removes
// dimensions from the type according to the subscripting.
// "
// input Types.Binding inBinding;
// input list<Exp.Subscript> inExpSubscriptLst;
// output Types.Binding outBinding;
// algorithm
// outBinding:=
// matchcontinue (inType,inBinding,inExpSubscriptLst)
// local
// Types.Binding t,t_1;
// Types.ArrayDim dim;
// Option<Absyn.Path> p;
// list<Exp.Subscript> ys,s;
// Integer sz,ind;
// list<Exp.Exp> se;
// Types.Binding binding;
// Exp.Exp exp;
// Option<Values.Value> eExp "evaluatedExp; evaluated exp" ;
// Types.Const const "constant" ;
// Values.Value v,v2;
// case (binding,{}) then binding;
// case (Types.UNBOUND(),_) then Types.UNBOUND();
// case (Types.EQBOUND(exp,eExp,const),
// (Exp.INDEX(a = Exp.ICONST(integer = ind)) :: ys))
// equation
// Debug.fprint("tcvt", "*** checkSubscriptsBinding Types.EQBOUND\n");
// t_1 = checkSubscriptsBinding(Types.EQBOUND(Exp.ASUB(exp,ind),eExp,const), ys);
// then
// t_1;



// case (Types.VALBOUND(v),(Exp.INDEX(a = Exp.ICONST(integer = ind)) :: ys))
// equation
// Debug.fprint("tcvt", "*** checkSubscriptsBinding before ntharrayelt Types.VALBOUND\n");
// v2= Values.nthArrayelt(v,ind);
// Debug.fprint("tcvt", "*** checkSubscriptsBinding after ntharrayelt Types.VALBOUND\n");
// t_1 = checkSubscriptsBinding(Types.VALBOUND(v2), ys);
// then t_1;


// case (binding,_)
// equation
// Debug.fprint("tcvt", "*** checkSubscriptsBinding binding\n");


// then binding;


// case (binding,s)
// local String str;
// equation
// Debug.fprint("failtrace", "- checkSubscriptsBinding failed ( ");
// str = Types.printBindingStr(binding);
// Debug.fprint("failtrace", str);
// Debug.fprint("failtrace", ")\n");
// then
// fail();
// end matchcontinue;
// end checkSubscriptsBinding;



protected function lookupVarF "function: lookupVarF
This function looks in a frame to find a declared variable. If
Expand Down Expand Up @@ -2061,7 +2008,6 @@ algorithm
equation
(cache,Types.VAR(n,Types.ATTR(f,acc,vt,di),_,ty,bind),_,_,_) = lookupVar2(cache,ht, id);
ty_1 = checkSubscripts(ty, ss);
// binding2 = checkSubscriptsBinding(bind,ss);
then
(cache,Types.ATTR(f,acc,vt,di),ty_1,bind);
case (cache,ht,Exp.CREF_QUAL(ident = id,subscriptLst = ss,componentRef = ids)) /* Qualified variables looked up through component environment. */
Expand Down

0 comments on commit 3944c4b

Please sign in to comment.