Skip to content

Commit

Permalink
Fixed bug with connectors extending basictype and matrix concatenatio…
Browse files Browse the repository at this point in the history
…n (MC bug #643). See mosfiles/Extends4.mo

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2447 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jul 11, 2006
1 parent 3305ab6 commit b8cf227
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 48 deletions.
4 changes: 3 additions & 1 deletion Compiler/Inst.mo
Expand Up @@ -1126,6 +1126,7 @@ algorithm

t1 = clock();


(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);
t2 = clock();
time = t2 -. t1;
Expand All @@ -1135,7 +1136,7 @@ algorithm
//print(s);
//print(Util.if_(b,s,""));
//print("instClassDef, outenv:");print(Env.printEnvStr(env_1));
cache = addCachedEnv(cache,n,env_1);
cache = addCachedEnv(cache,n,env_1);
then
(cache,l,env_1,csets_1,ci_state_1,tys,bc);
case (cache,env,mods,pre,csets,ci_state,(c as SCode.CLASS(name = n,restricion = r,parts = d)),prot,inst_dims,impl)
Expand Down Expand Up @@ -5502,6 +5503,7 @@ algorithm
needed when deoverloading */
equation
(cache,(c as SCode.CLASS(id,_,encflag,SCode.R_FUNCTION(),_)),cenv) = Lookup.lookupClass(cache,env, fn, true);

(cache,dae,_,_,(Types.T_FUNCTION(args,tp),_),st) = instClass(cache,cenv, Types.NOMOD(), Prefix.NOPRE(), Connect.emptySet, c,
{}, true, INNER_CALL());
(cache,fpath) = makeFullyQualified(cache,env, Absyn.IDENT(overloadname));
Expand Down
21 changes: 13 additions & 8 deletions Compiler/Lookup.mo
Expand Up @@ -267,7 +267,6 @@ algorithm
(cache,(c as SCode.CLASS(id,_,encflag,restr,_)),env_1) = lookupClass(cache,env, Absyn.IDENT(pack), msgflag);
env2 = Env.openScope(env_1, encflag, SOME(id));
ci_state = ClassInf.start(restr, id);

(cache,_,env_2,_,cistate1,_,_) = Inst.instClassIn(cache,env2, Types.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
ci_state, c, false/*FIXME:prot*/, {}, false);
failure(ClassInf.valid(cistate1, SCode.R_PACKAGE()));
Expand Down Expand Up @@ -1212,6 +1211,8 @@ algorithm
Env.Frame f;
Env.Cache cache;
case (cache,{},id) then (cache,{});

/* Builtin operators are looked up in top frame directly */
case (cache,env,(iid as Absyn.IDENT(name = id)))
local String id;
equation
Expand All @@ -1230,18 +1231,19 @@ algorithm
reslist = createGenericBuiltinFunctions(env, id);
then
(cache,reslist);
/* Simple name, search frame */
case (cache,(env as (Env.FRAME(class_1 = sid,list_2 = ht,list_3 = httypes) :: fs)),(iid as Absyn.IDENT(name = id)))
local String id,s;
equation
(cache,c1)= lookupFunctionsInFrame(cache,ht, httypes, env, id);
(cache,c2)= lookupFunctionsInEnv(cache,fs, iid);
reslist = listAppend(c1, c2);
(cache,c1 as _::_)= lookupFunctionsInFrame(cache,ht, httypes, env, id);
then
(cache,reslist);
(cache,c1);

/*For qualified function names, e.g. Modelica.Math.sin */
case (cache,(env as (Env.FRAME(class_1 = sid,list_2 = ht,list_3 = httypes) :: fs)),(iid as Absyn.QUALIFIED(name = pack,path = path)))
local String id,s;
equation
(cache,(c as SCode.CLASS(id,_,encflag,restr,_)),env_1) = lookupClass(cache,env, Absyn.IDENT(pack), false) "For qualified function names, e.g. Modelica.Math.sin" ;
(cache,(c as SCode.CLASS(id,_,encflag,restr,_)),env_1) = lookupClass(cache,env, Absyn.IDENT(pack), false) ;
env2 = Env.openScope(env_1, encflag, SOME(id));
ci_state = ClassInf.start(restr, id);

Expand All @@ -1253,8 +1255,9 @@ algorithm
(cache,reslist) = lookupFunctionsInEnv(cache,env_2, path);
then
(cache,reslist);

case (cache,(f :: fs),id) /* Did not match. Continue */

/* Did not match. Search next frame. */
case (cache,(f :: fs),id)
local list<tuple<Types.TType, Option<Absyn.Path>>> c;
equation
(cache,c) = lookupFunctionsInEnv(cache,fs, id);
Expand Down Expand Up @@ -1987,6 +1990,8 @@ algorithm
t_1 = checkSubscripts(t, ys);
then
t_1;
case ((Types.T_COMPLEX(_,_,SOME(t)),_),ys)
then checkSubscripts(t,ys);
case (t,s)
equation
Debug.fprint("failtrace", "- check_subscripts failed ( ");
Expand Down
72 changes: 33 additions & 39 deletions Compiler/Static.mo
Expand Up @@ -1582,7 +1582,7 @@ algorithm
(cache,Exp.ARRAY(at,a,(el_2 :: els_1)),props,dim1,dim2_1);
case (_,_,_,_,_,_,_)
equation
Debug.fprint("failtrace", "- elab_matrix_comma failed\n");
Debug.fprint("failtrace", "- elabMatrixComma failed\n");
then
fail();
end matchcontinue;
Expand Down Expand Up @@ -1766,6 +1766,9 @@ algorithm
(e_2,prop_1) = promoteExp(e_1, Types.PROP(tp_1,c), n_1);
then
(e_2,prop_1);
case(_,_,_) equation
Debug.fprint("failtrace","-promoteExp failed\n");
then fail();
end matchcontinue;
end promoteExp;

Expand Down Expand Up @@ -4909,17 +4912,8 @@ algorithm
then
(cache,call_exp,prop_1);

case (cache,env,fn,args,nargs,impl,st) /* No functions found. */
equation
(cache,{}) = Lookup.lookupFunctionsInEnv(cache,env, fn);
print("NO FUNCTION Found\nenv:");
print(Env.printEnvStr(env));print("\n");

then
fail();

/*case above failed. Also consider koening lookup.*/
case (cache,env,fn,args,nargs,impl,st)
/*case (cache,env,fn,args,nargs,impl,st)
equation
(cache,ktypelist) = getKoeningFunctionTypes(cache,env, fn, args, nargs, impl) ;
(cache,args_1,constlist,restype,functype,vect_dims,slots) = elabTypes(cache,env, args, nargs, ktypelist, impl);
Expand All @@ -4933,7 +4927,7 @@ algorithm
(call_exp,prop_1) = vectorizeCall(Exp.CALL(fn_1,args_1,tuple_,builtin), restype, vect_dims,
slots, prop);
then
(cache,call_exp,prop);
(cache,call_exp,prop);*/
case (cache,env,fn,args,nargs,impl,st) /* no matching type found. */
equation
(cache,typelist) = Lookup.lookupFunctionsInEnv(cache,env, fn);
Expand Down Expand Up @@ -7548,7 +7542,7 @@ algorithm
end matchcontinue;
end computeReturnType;

protected function nDims "function nDims
public function nDims "function nDims
Returns the number of dimensions of a Type.
"
input Types.Type inType;
Expand Down Expand Up @@ -7675,9 +7669,9 @@ algorithm
{(Types.T_REAL({}),NONE),(Types.T_REAL({}),NONE)},(Types.T_REAL({}),NONE)),
(Exp.ADD(Exp.STRING()),
{(Types.T_STRING({}),NONE),(Types.T_STRING({}),NONE)},(Types.T_STRING({}),NONE))};
(cache,userops) = getKoeningOperatorTypes(cache,"plus", env, t1, t2);
/*(cache,userops) = getKoeningOperatorTypes(cache,"plus", env, t1, t2);*/
arrays = Util.listFlatten({intarrs,realarrs,stringarrs});
types = Util.listFlatten({scalars,arrays,userops});
types = Util.listFlatten({scalars,arrays/*,userops*/});
then
(cache,types);
case (cache,Absyn.SUB(),env,t1,t2)
Expand All @@ -7693,8 +7687,8 @@ algorithm
{(Types.T_INTEGER({}),NONE),(Types.T_INTEGER({}),NONE)},(Types.T_INTEGER({}),NONE)),
(Exp.SUB(Exp.REAL()),
{(Types.T_REAL({}),NONE),(Types.T_REAL({}),NONE)},(Types.T_REAL({}),NONE))};
(cache,userops) = getKoeningOperatorTypes(cache,"minus", env, t1, t2);
types = Util.listFlatten({scalars,intarrs,realarrs,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"minus", env, t1, t2);*/
types = Util.listFlatten({scalars,intarrs,realarrs/*,userops*/});
then
(cache,types);
case (cache,Absyn.MUL(),env,t1,t2)
Expand Down Expand Up @@ -7731,10 +7725,10 @@ algorithm
intarrtypes);
realarrsscalar = operatorReturn(Exp.MUL_ARRAY_SCALAR(Exp.REAL()), realarrtypes, realtypes,
realarrtypes);
(cache,userops) = getKoeningOperatorTypes(cache,"times", env, t1, t2);
/*(cache,userops) = getKoeningOperatorTypes(cache,"times", env, t1, t2);*/
types = Util.listFlatten(
{scalars,intscalararrs,realscalararrs,intarrsscalar,
realarrsscalar,scalarprod,matrixprod,userops});
realarrsscalar,scalarprod,matrixprod/*,userops*/});
then
(cache,types);
case (cache,Absyn.DIV(),env,t1,t2)
Expand All @@ -7746,8 +7740,8 @@ algorithm
scalars = {(real_div,{real_scalar,real_scalar},real_scalar)};
realarrscalar = operatorReturn(Exp.DIV_ARRAY_SCALAR(Exp.REAL()), realarrtypes, realtypes,
realarrtypes);
(cache,userops) = getKoeningOperatorTypes(cache,"divide", env, t1, t2);
types = Util.listFlatten({scalars,realarrscalar,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"divide", env, t1, t2);*/
types = Util.listFlatten({scalars,realarrscalar/*,userops*/});
then
(cache,types);
case (cache,Absyn.POW(),env,t1,t2)
Expand All @@ -7764,8 +7758,8 @@ algorithm
arrscalar = {
(Exp.POW_ARR(Exp.REAL()),{real_matrix,int_scalar},
real_matrix)};
(cache,userops) = getKoeningOperatorTypes(cache,"power", env, t1, t2);
types = Util.listFlatten({scalars,arrscalar,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"power", env, t1, t2);*/
types = Util.listFlatten({scalars,arrscalar/*,userops*/});
then
(cache,types);
case (cache,Absyn.UMINUS(),env,t1,t2)
Expand All @@ -7779,8 +7773,8 @@ algorithm
realarrtypes = arrayTypeList(9, (Types.T_REAL({}),NONE));
intarrs = operatorReturnUnary(Exp.UMINUS_ARR(Exp.INT()), intarrtypes, intarrtypes);
realarrs = operatorReturnUnary(Exp.UMINUS_ARR(Exp.REAL()), realarrtypes, realarrtypes);
(cache,userops) = getKoeningOperatorTypes(cache,"unaryMinus", env, t1, t2);
types = Util.listFlatten({scalars,intarrs,realarrs,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"unaryMinus", env, t1, t2);*/
types = Util.listFlatten({scalars,intarrs,realarrs/*,userops*/});
then
(cache,types);
case (cache,Absyn.UPLUS(),env,t1,t2)
Expand All @@ -7794,8 +7788,8 @@ algorithm
realarrtypes = arrayTypeList(9, (Types.T_REAL({}),NONE));
intarrs = operatorReturnUnary(Exp.UPLUS(Exp.INT()), intarrtypes, intarrtypes);
realarrs = operatorReturnUnary(Exp.UPLUS(Exp.REAL()), realarrtypes, realarrtypes);
(cache,userops) = getKoeningOperatorTypes(cache,"unaryPlus", env, t1, t2);
types = Util.listFlatten({scalars,intarrs,realarrs,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"unaryPlus", env, t1, t2);*/
types = Util.listFlatten({scalars,intarrs,realarrs/*,userops*/});
then
(cache,types);
case (cache,Absyn.AND(),env,t1,t2) then (cache,{
Expand All @@ -7813,8 +7807,8 @@ algorithm
{(Types.T_INTEGER({}),NONE),(Types.T_INTEGER({}),NONE)},(Types.T_BOOL({}),NONE)),
(Exp.LESS(Exp.REAL()),
{(Types.T_REAL({}),NONE),(Types.T_REAL({}),NONE)},(Types.T_BOOL({}),NONE))} "\'<\' operator" ;
(cache,userops) = getKoeningOperatorTypes(cache,"less", env, t1, t2);
types = Util.listFlatten({scalars,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"less", env, t1, t2);*/
types = Util.listFlatten({scalars/*,userops*/});
then
(cache,types);
case (cache,Absyn.LESSEQ(),env,t1,t2)
Expand All @@ -7824,8 +7818,8 @@ algorithm
{(Types.T_INTEGER({}),NONE),(Types.T_INTEGER({}),NONE)},(Types.T_BOOL({}),NONE)),
(Exp.LESSEQ(Exp.REAL()),
{(Types.T_REAL({}),NONE),(Types.T_REAL({}),NONE)},(Types.T_BOOL({}),NONE))} "\'<=\' operator" ;
(cache,userops) = getKoeningOperatorTypes(cache,"lessEqual", env, t1, t2);
types = Util.listFlatten({scalars,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"lessEqual", env, t1, t2);*/
types = Util.listFlatten({scalars/*,userops*/});
then
(cache,types);
case (cache,Absyn.GREATER(),env,t1,t2)
Expand All @@ -7835,8 +7829,8 @@ algorithm
{(Types.T_INTEGER({}),NONE),(Types.T_INTEGER({}),NONE)},(Types.T_BOOL({}),NONE)),
(Exp.GREATER(Exp.REAL()),
{(Types.T_REAL({}),NONE),(Types.T_REAL({}),NONE)},(Types.T_BOOL({}),NONE))} "\'>\' operator" ;
(cache,userops) = getKoeningOperatorTypes(cache,"greater", env, t1, t2);
types = Util.listFlatten({scalars,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"greater", env, t1, t2);*/
types = Util.listFlatten({scalars/*,userops*/});
then
(cache,types);
case (cache,Absyn.GREATEREQ(),env,t1,t2)
Expand All @@ -7846,8 +7840,8 @@ algorithm
{(Types.T_INTEGER({}),NONE),(Types.T_INTEGER({}),NONE)},(Types.T_BOOL({}),NONE)),
(Exp.GREATEREQ(Exp.REAL()),
{(Types.T_REAL({}),NONE),(Types.T_REAL({}),NONE)},(Types.T_BOOL({}),NONE))} "\'>=\' operator" ;
(cache,userops) = getKoeningOperatorTypes(cache,"greaterEqual", env, t1, t2);
types = Util.listFlatten({scalars,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"greaterEqual", env, t1, t2);*/
types = Util.listFlatten({scalars/*,userops*/});
then
(cache,types);
case (cache,Absyn.EQUAL(),env,t1,t2)
Expand All @@ -7861,8 +7855,8 @@ algorithm
{(Types.T_STRING({}),NONE),(Types.T_STRING({}),NONE)},(Types.T_BOOL({}),NONE)),
(Exp.EQUAL(Exp.BOOL()),
{(Types.T_BOOL({}),NONE),(Types.T_BOOL({}),NONE)},(Types.T_BOOL({}),NONE))} "\'==\' operator" ;
(cache,userops) = getKoeningOperatorTypes(cache,"equal", env, t1, t2);
types = Util.listFlatten({scalars,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"equal", env, t1, t2);*/
types = Util.listFlatten({scalars/*,userops*/});
then
(cache,types);
case (cache,Absyn.NEQUAL(),env,t1,t2)
Expand All @@ -7876,8 +7870,8 @@ algorithm
{(Types.T_STRING({}),NONE),(Types.T_STRING({}),NONE)},(Types.T_BOOL({}),NONE)),
(Exp.NEQUAL(Exp.BOOL()),
{(Types.T_BOOL({}),NONE),(Types.T_BOOL({}),NONE)},(Types.T_BOOL({}),NONE))} "\'!=\' operator" ;
(cache,userops) = getKoeningOperatorTypes(cache,"notEqual", env, t1, t2);
types = Util.listFlatten({scalars,userops});
/*(cache,userops) = getKoeningOperatorTypes(cache,"notEqual", env, t1, t2);*/
types = Util.listFlatten({scalars/*,userops*/});
then
(cache,types);
case (cache,op,env,t1,t2)
Expand Down
35 changes: 35 additions & 0 deletions Compiler/Types.mo
Expand Up @@ -380,7 +380,9 @@ public function isArray "function: isArray
algorithm
outBoolean:=
matchcontinue (inType)
local Type t;
case ((T_ARRAY(arrayDim = _),_)) then true;
case ((T_COMPLEX(_,_,SOME(t)),_)) then isArray(t);
case ((_,_)) then false;
end matchcontinue;
end isArray;
Expand Down Expand Up @@ -440,6 +442,9 @@ algorithm
n = ndims(t);
then
n + 1;
case ((T_COMPLEX(_,_,SOME(t)),_)) equation
n = ndims(t);
then n;
case ((_,_)) then 0;
end matchcontinue;
end ndims;
Expand Down Expand Up @@ -506,6 +511,8 @@ algorithm
res = getDimensionSizes(tp);
then
(i :: res);
case ((T_COMPLEX(_,_,SOME(tp)),_))
then getDimensionSizes(tp);
case ((_,_)) then {};
end matchcontinue;
end getDimensionSizes;
Expand Down Expand Up @@ -1178,11 +1185,17 @@ algorithm
ArrayDim dim;
Option<Absyn.Path> path;
Option<Integer> i;
ClassInf.State ci;
list<Var> varlst;
case ((T_ARRAY(arrayDim = dim,arrayType = ty),path),i)
equation
ty_1 = liftArrayRight(ty, i);
then
((T_ARRAY(dim,ty_1),path));
case((T_COMPLEX(ci,varlst,SOME(ty)),path),i)
equation
ty_1 = liftArrayRight(ty,i);
then ((T_COMPLEX(ci,varlst,SOME(ty_1)),path));
case ((ty,path),i)
local TType ty;
then
Expand All @@ -1201,6 +1214,7 @@ algorithm
matchcontinue (inType)
local Type ty;
case ((T_ARRAY(arrayDim = DIM(integerOption = _),arrayType = ty),_)) then ty;
case ((T_COMPLEX(_,_,SOME(ty)),_)) then unliftArray(ty);
end matchcontinue;
end unliftArray;

Expand Down Expand Up @@ -2112,6 +2126,14 @@ algorithm
res = boolOr(r1, r2);
then
res;

case ((T_COMPLEX(_,_,SOME(tp)),_)::xs)
equation
r1 = containReal({tp});
r2 = containReal(xs);
res = boolOr(r1,r2);
then res;

case (((T_REAL(varLstReal = _),_) :: _)) then true;
case ((_ :: xs))
equation
Expand Down Expand Up @@ -2434,6 +2456,8 @@ algorithm
dims = getDimensionSizes(t);
then
Exp.T_ARRAY(t_1,dims);
case ( (T_COMPLEX(_,_,SOME(t)),_))
then elabType(t);
case ((_,_)) then Exp.OTHER();
end matchcontinue;
end elabType;
Expand Down Expand Up @@ -2864,6 +2888,14 @@ algorithm
Option<Absyn.Path> p2,p;
Boolean havereal;
list<Var> v;

case (PROP((T_COMPLEX(_,_,SOME(t1)),_),c1),PROP(t2,c2),havereal)
then matchWithPromote(PROP(t1,c1),PROP(t2,c2),havereal);

case (PROP(t1,c1),PROP((T_COMPLEX(_,_,SOME(t2)),_),c2),havereal)
then matchWithPromote(PROP(t1,c1),PROP(t2,c2),havereal);


case (PROP(type_ = (T_ARRAY(arrayDim = dim1,arrayType = t1),_),constFlag = c1),PROP(type_ = (T_ARRAY(arrayDim = dim2,arrayType = t2),p2),constFlag = c2),havereal) /* Allow Integer => Real */
equation
PROP(t,c) = matchWithPromote(PROP(t1,c1), PROP(t2,c2), havereal);
Expand Down Expand Up @@ -2911,6 +2943,9 @@ algorithm
c = constAnd(c1, c2) "Have real and both Integer" ;
then
PROP((T_REAL({}),p2),c);
case(_,_,_) equation
Debug.fprint("failtrace","-matchWithPromote failed\n");
then fail();
end matchcontinue;
end matchWithPromote;

Expand Down

0 comments on commit b8cf227

Please sign in to comment.