Skip to content

Commit

Permalink
- use Expression.crefExp or Expression.makeCrefExp to create DAE.CREF
Browse files Browse the repository at this point in the history
- use ComponentReference.makeCrefIdent and ComponentReference.makeCrefQual when building DAE.CREF_IDENT and DAE.CREF_QUAL

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7237 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Nov 29, 2010
1 parent 28b548a commit 126049f
Show file tree
Hide file tree
Showing 18 changed files with 572 additions and 351 deletions.
144 changes: 72 additions & 72 deletions Compiler/Derive.mo

Large diffs are not rendered by default.

99 changes: 66 additions & 33 deletions Compiler/Expression.mo
Expand Up @@ -328,11 +328,11 @@ public function stringifyCrefs
"function: stringifyCrefs
This function takes an expression and transforms all component
reference names contained in the expression to a simpler form.
For instance DAE.CREF_QUAL(\"a\",{}, DAE.CREF_IDENT(\"b\",{})) becomes
DAE.CREF_IDENT(\"a.b\",{})
For instance DAE.CREF_QUAL(a,{}, DAE.CREF_IDENT(b,{})) becomes
DAE.CREF_IDENT(a.b,{})

NOTE: This function should not be used in OMC, since the OMC backend no longer
uses stringified components. It is still used by MathCore though."
uses stringified components. It is still used by MathCore though."
input DAE.Exp inExp;
output DAE.Exp outExp;
algorithm
Expand Down Expand Up @@ -360,17 +360,20 @@ algorithm
DAE.Exp e;
list<Boolean> blist;

case ((e as DAE.CREF(ty = DAE.ET_FUNCTION_REFERENCE_VAR()), ilst)) then ((e, ilst));
case ((e as DAE.CREF(ty = DAE.ET_FUNCTION_REFERENCE_VAR()), ilst))
then ((e, ilst));

case ((e as DAE.CREF(ty = DAE.ET_FUNCTION_REFERENCE_FUNC(builtin = _)), ilst)) then ((e, ilst));
case ((e as DAE.CREF(ty = DAE.ET_FUNCTION_REFERENCE_FUNC(builtin = _)), ilst))
then ((e, ilst));

case( (DAE.CREF(cr,ty), ilst) )
equation
crs = ComponentReference.stringifyComponentRef(cr);
then
((DAE.CREF(crs,ty), ilst ));
((makeCrefExp(crs,ty), ilst ));

case(inExp) then inExp;

end matchcontinue;
end traversingstringifyCrefFinder;

Expand All @@ -382,16 +385,21 @@ algorithm
local
ComponentRef e_cref;
Absyn.ComponentRef cref;
DAE.Exp e;

case(DAE.CODE(Absyn.C_VARIABLENAME(cref),_))
equation
(_,e_cref) = Static.elabUntypedCref(Env.emptyCache(),Env.emptyEnv,cref,false,Prefix.NOPRE(),Absyn.dummyInfo);
then DAE.CREF(e_cref,DAE.ET_OTHER());
e = crefExp(e_cref);
then
e;

case(DAE.CODE(Absyn.C_EXPRESSION(Absyn.CALL(Absyn.CREF_IDENT("der",{}),Absyn.FUNCTIONARGS({Absyn.CREF(cref)},{}))),_))
equation
(_,e_cref) = Static.elabUntypedCref(Env.emptyCache(),Env.emptyEnv,cref,false,Prefix.NOPRE(),Absyn.dummyInfo);
then DAE.CALL(Absyn.IDENT("der"),{DAE.CREF(e_cref,DAE.ET_OTHER())},false,false,DAE.ET_OTHER(),DAE.NO_INLINE());
e = crefExp(e_cref);
then
DAE.CALL(Absyn.IDENT("der"),{e},false,false,DAE.ET_OTHER(),DAE.NO_INLINE());
end matchcontinue;
end CodeVarToCref;

Expand Down Expand Up @@ -663,15 +671,18 @@ algorithm
equation
ty = ComponentReference.crefLastType(cr);
cr_1 = ComponentReference.crefStripLastSubs(cr);
then DAE.CREF(cr_1,ty);
e = makeCrefExp(cr_1, ty);
then
e;

case (DAE.UNARY(operator=op,exp=e))
equation
e_1 = expStripLastSubs(e);
ty = typeof(e_1);
b = DAEUtil.expTypeArray(ty);
op1 = Util.if_(b,DAE.UMINUS_ARR(ty),DAE.UMINUS(ty));
then DAE.UNARY(op1,e_1);
then
DAE.UNARY(op1,e_1);
end matchcontinue;
end expStripLastSubs;

Expand All @@ -689,18 +700,23 @@ algorithm
Operator op,op1;
DAE.Exp e,e_1;
Boolean b;

case (DAE.CREF(componentRef=cr))
equation
cr_1 = ComponentReference.crefStripLastIdent(cr);
ty = ComponentReference.crefLastType(cr_1);
then DAE.CREF(cr_1,ty);
e = makeCrefExp(cr_1, ty);
then
e;

case (DAE.UNARY(operator=op,exp=e))
equation
e_1 = expStripLastIdent(e);
ty = typeof(e_1);
b = DAEUtil.expTypeArray(ty);
op1 = Util.if_(b,DAE.UMINUS_ARR(ty),DAE.UMINUS(ty));
then DAE.UNARY(op1,e_1);
then
DAE.UNARY(op1,e_1);
end matchcontinue;
end expStripLastIdent;

Expand All @@ -712,13 +728,19 @@ public function prependSubscriptExp
output DAE.Exp outExp;
algorithm
outExp := matchcontinue(exp,subscr)
local Type t; ComponentRef cr,cr1,cr2;
list<Subscript> subs;
case(DAE.CREF(cr,t),subscr) equation
cr1 = ComponentReference.crefStripLastSubs(cr);
subs = ComponentReference.crefLastSubs(cr);
cr2 = ComponentReference.subscriptCref(cr1,subscr::subs);
then DAE.CREF(cr2,t);
local
Type t; ComponentRef cr,cr1,cr2;
list<Subscript> subs;
DAE.Exp e;

case(DAE.CREF(cr,t),subscr)
equation
cr1 = ComponentReference.crefStripLastSubs(cr);
subs = ComponentReference.crefLastSubs(cr);
cr2 = ComponentReference.subscriptCref(cr1,subscr::subs);
e = makeCrefExp(cr2, t);
then
e;
end matchcontinue;
end prependSubscriptExp;

Expand All @@ -734,18 +756,20 @@ alternative names: subsriptExp (but already taken), subscriptToAsub"
output DAE.Exp res;
algorithm
res := matchcontinue(e,subs)
local list<DAE.Exp> expl;
DAE.Exp s;
DAE.Subscript sub;
local
list<DAE.Exp> expl;
DAE.Exp s;
DAE.Subscript sub;

case(e,{}) then e;

case(e,sub::subs) equation
// Apply one subscript at a time, so simplify works fine on it.
s = subscriptExp(sub);
res = applyExpSubscripts(ExpressionSimplify.simplify(DAE.ASUB(e,{s})),subs);
then res;

case(e,sub::subs)
equation
// Apply one subscript at a time, so simplify works fine on it.
s = subscriptExp(sub);
res = applyExpSubscripts(ExpressionSimplify.simplify(DAE.ASUB(e,{s})),subs);
then
res;
end matchcontinue;
end applyExpSubscripts ;

Expand Down Expand Up @@ -783,12 +807,14 @@ algorithm
list<DAE.Exp> a;
Integer i;
list<list<tuple<DAE.Exp, Boolean>>> mat;
DAE.Exp expCref;

case DAE.CREF(componentRef = cr, ty = ty)
equation
ty = unliftArray(ty);
expCref = makeCrefExp(cr, ty);
then
DAE.CREF(cr, ty);
expCref;

case DAE.ARRAY(ty = ty, scalar = s, array = a)
equation
Expand All @@ -803,6 +829,7 @@ algorithm
DAE.MATRIX(ty, i, mat);

case (_) then inExp;

end matchcontinue;
end unliftExp;

Expand Down Expand Up @@ -1213,10 +1240,12 @@ algorithm
ComponentRef cr;
list<Subscript> subs;
DAE.Exp e;

case (DAE.CREF(componentRef=cr))
equation
subs = ComponentReference.crefLastSubs(cr);
then subs;

case (DAE.UNARY(exp=e))
equation
subs = expLastSubs(e);
Expand Down Expand Up @@ -3128,7 +3157,8 @@ algorithm
case(DAE.CREF(componentRef = cr, ty = ety),source,target)
equation
(cr1,c) = replaceCrefExpSubs(cr,source,target);
then (DAE.CREF(cr1,ety),c);
e = makeCrefExp(cr1,ety);
then (e,c);

case(DAE.CREF(cr as DAE.CREF_IDENT(id,t2,ssl),ety),_,_)
equation
Expand All @@ -3138,8 +3168,9 @@ algorithm
id = stringAppendList({"$",id});
id = Util.stringReplaceChar(id,".","$p");
cr_1 = ComponentReference.makeCrefIdent(id,t2,ssl);
e = makeCrefExp(cr_1,ety);
then
(DAE.CREF(cr_1,ety),1);
(e,1);

// no replacement
case (e,s,_) then (e,0);
Expand Down Expand Up @@ -4097,13 +4128,15 @@ algorithm
list<ComponentRef> crefs;
ComponentRef cr;
Type ty;
list<Boolean> blist;
list<Boolean> blist;
DAE.Exp e;

case((DAE.CREF(cr,ty), crefs))
equation
crefs = Util.listUnionEltOnTrue(cr,crefs,ComponentReference.crefEqual);
e = makeCrefExp(cr,ty);
then
((DAE.CREF(cr,ty), crefs ));
((e, crefs ));

case(inExp) then inExp;

Expand Down
10 changes: 7 additions & 3 deletions Compiler/ExpressionSimplify.mo
Expand Up @@ -664,11 +664,13 @@ algorithm
ComponentRef cr;
Ident idn;
list<DAE.Exp> expl_1;
DAE.Exp expCref;

case(DAE.CREF_IDENT(idn,t2,(ssl as ((DAE.SLICE(DAE.ARRAY(_,_,expl_1))) :: _))),t)
equation
cr = ComponentReference.makeCrefIdent(idn,t2,{});
exp = simplifyCref2(DAE.CREF(cr,t),ssl);
expCref = Expression.makeCrefExp(cr,t);
exp = simplifyCref2(expCref,ssl);
then
exp;
end matchcontinue;
Expand Down Expand Up @@ -2270,16 +2272,18 @@ algorithm
t = Expression.unliftArray(t);
s_1 = Expression.subscriptsAppend(s, DAE.ICONST(sub));
c_1 = ComponentReference.makeCrefIdent(idn,t2,s_1);
exp = Expression.makeCrefExp(c_1, t);
then
DAE.CREF(c_1,t);
exp;

// qualified name subscript
case(DAE.CREF(DAE.CREF_QUAL(idn,t2,s,c),t),sub)
equation
DAE.CREF(c_1,t) = simplify1(DAE.ASUB(DAE.CREF(c,t),{DAE.ICONST(sub)}));
c_1 = ComponentReference.makeCrefQual(idn,t2,s,c_1);
exp = Expression.makeCrefExp(c_1, t);
then
DAE.CREF(c_1,t);
exp;

end matchcontinue;
end simplifyAsub0;
Expand Down
7 changes: 5 additions & 2 deletions Compiler/Inline.mo
Expand Up @@ -1076,11 +1076,14 @@ algorithm
DAE.ExpType tp;
String name;
DAE.ComponentRef c1,e1;
DAE.Exp exp;

case(DAE.COMPLEX_VAR(name=name,tp=tp),c,e)
equation
c1 = ComponentReference.crefPrependIdent(c,name,{},tp);
e1 = ComponentReference.crefPrependIdent(e,name,{},tp);
then ((c1,DAE.CREF(e1,tp)));
e1 = ComponentReference.crefPrependIdent(e,name,{},tp);
exp = Expression.makeCrefExp(e1,tp);
then ((c1,exp));
case(_,_,_)
equation
Debug.fprintln("failtrace","Inline.extendCrefRecords1 failed");
Expand Down
4 changes: 2 additions & 2 deletions Compiler/InnerOuter.mo
Expand Up @@ -486,13 +486,13 @@ algorithm
outerCrs = Util.listMap(outerVars,DAEUtil.varCref);
ourOuterCrs = Util.listSelect1(outerCrs,cr,isInnerOuterMatch);
cr = DAEUtil.nameInnerouterUniqueCref(cr);
repl = Util.listFold_2r(ourOuterCrs,VarTransform.addReplacement,repl,DAE.CREF(cr,DAE.ET_OTHER()));
repl = Util.listFold_2r(ourOuterCrs,VarTransform.addReplacement,repl,Expression.crefExp(cr));
then repl;
case(DAE.VAR(componentRef = cr),outerVars,repl)
equation
outerCrs = Util.listMap(outerVars,DAEUtil.varCref);
ourOuterCrs = Util.listSelect1(outerCrs,cr,isInnerOuterMatch);
repl = Util.listFold_2r(ourOuterCrs,VarTransform.addReplacement,repl,DAE.CREF(cr,DAE.ET_OTHER()));
repl = Util.listFold_2r(ourOuterCrs,VarTransform.addReplacement,repl,Expression.crefExp(cr));
then repl;
end matchcontinue;
end buildInnerOuterReplVar;
Expand Down

0 comments on commit 126049f

Please sign in to comment.