Skip to content

Commit

Permalink
- properly propagate attributes of components on redeclare
Browse files Browse the repository at this point in the history
- properly fill cref subscripts in Static.fillCrefSubscripts (still stuck in old days with T_ARRAY of only one dim)
- show the connector components when there is a connection mismatch


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22596 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 5, 2014
1 parent 1808e46 commit f04d176
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 39 deletions.
8 changes: 8 additions & 0 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -3455,6 +3455,14 @@ algorithm
list<DAE.Exp> expl;
DAE.Exp exp;

/*/ allow index 0 with dimension 0
case (DAE.INDEX(exp = exp as DAE.ICONST(integer = idx)),
DAE.DIM_INTEGER(integer = dim), _, _, _)
equation
true = idx == 0 and dim == 0;
then
true;*/

case (DAE.INDEX(exp = exp as DAE.ICONST(integer = idx)),
DAE.DIM_INTEGER(integer = dim), _, _, _)
equation
Expand Down
26 changes: 12 additions & 14 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -153,6 +153,7 @@ protected import ValuesUtil;
protected import System;
protected import SCodeDump;
protected import UnitAbsynBuilder;
protected import NFSCodeFlattenRedeclare;

protected function instantiateClass_dispatch
" instantiate a class.
Expand Down Expand Up @@ -4027,7 +4028,7 @@ algorithm


// constrainting type on the component
case (cache,env,ih,(DAE.REDECL(tplSCodeElementModLst = ((( SCode.COMPONENT(name = n1,
case (cache,env,ih,(DAE.REDECL(tplSCodeElementModLst = ((( redComp as SCode.COMPONENT(name = n1,
prefixes = SCode.PREFIXES(
finalPrefix = finalPrefix,
replaceablePrefix = _,
Expand All @@ -4037,7 +4038,7 @@ algorithm
attributes = at,condition = cond, info = info
)),rmod) :: _))),
// adrpo: always take the inner outer from the component, not the redeclaration!!!!
SCode.COMPONENT(name = n2,
comp as SCode.COMPONENT(name = n2,
prefixes = SCode.PREFIXES(
finalPrefix = SCode.NOT_FINAL(),
replaceablePrefix = repl2 as SCode.REPLACEABLE((cc as SOME(_))),
Expand All @@ -4050,7 +4051,6 @@ algorithm
equation
true = stringEq(n1, n2);
mod = InstUtil.chainRedeclares(inMod, mod);
at = SCodeUtil.mergeDimensions(at, at2); // take the array dims from the original if the redeclare does not have any
compsOnConstrain = InstUtil.extractConstrainingComps(cc,env,pre) "extract components belonging to constraining class";
crefs = InstUtil.getCrefFromMod(mod);
(cache,env_1,ih) = updateComponentsInEnv(cache, env, ih, pre, DAE.NOMOD(), crefs, ci_state, impl);
Expand All @@ -4064,14 +4064,13 @@ algorithm
m_3 = Mod.merge(m_2, old_m_1, env_1, pre);
m_3 = Mod.merge(m_3, cmod, env_1, pre);

redComp = SCode.COMPONENT(n1,
SCode.PREFIXES(vis, redeclp, finalPrefix, io, repl2),
at,t,mod,comment,cond,info);
redecl = NFSCodeFlattenRedeclare.propagateAttributesVar(comp, redComp);
redecl = SCode.setComponentMod(redecl, mod);
then
(cache,env_1,ih,redComp,m_3);
(cache,env_1,ih,redecl,m_3);

// no constraining type on comp, throw away modifiers prior to redeclaration
case (cache,env,ih,(DAE.REDECL(tplSCodeElementModLst = (((redecl as
case (cache,env,ih,(DAE.REDECL(tplSCodeElementModLst = (((redComp as
SCode.COMPONENT(name = n1,
prefixes = SCode.PREFIXES(
finalPrefix = finalPrefix,
Expand All @@ -4082,7 +4081,7 @@ algorithm
attributes = at,condition = cond, info = info
)),rmod) :: _))),
// adrpo: always take the inner outer from the component, not the redeclaration!!!!
SCode.COMPONENT(name = n2,
comp as SCode.COMPONENT(name = n2,
prefixes = SCode.PREFIXES(
finalPrefix = SCode.NOT_FINAL(),
replaceablePrefix = repl2 as SCode.REPLACEABLE(NONE()),
Expand All @@ -4095,19 +4094,18 @@ algorithm
equation
true = stringEq(n1, n2);
mod = InstUtil.chainRedeclares(inMod, mod);
at = SCodeUtil.mergeDimensions(at, at2); // take the array dims from the original if the redeclare does not have any
crefs = InstUtil.getCrefFromMod(mod);
(cache,env_1,ih) = updateComponentsInEnv(cache,env,ih, pre, DAE.NOMOD(), crefs, ci_state, impl) "m" ;
(cache,m_1) = Mod.elabMod(cache, env_1, ih, pre, mod, impl, Mod.COMPONENT(n1), info);
(cache,old_m_1) = Mod.elabMod(cache, env_1, ih, pre, old_mod, impl, Mod.COMPONENT(n2), info);
m_2 = Mod.merge(m_1, rmod, env_1, pre);
m_3 = Mod.merge(m_2, old_m_1, env_1, pre);
m_3 = Mod.merge(m_3,cmod,env_1,pre);
redComp = SCode.COMPONENT(n1,
SCode.PREFIXES(vis, redeclp, finalPrefix, io, repl),
at,t,mod,comment,cond,info);

redecl = NFSCodeFlattenRedeclare.propagateAttributesVar(comp, redComp);
redecl = SCode.setComponentMod(redecl, mod);
then
(cache,env_1,ih,redComp,m_3);
(cache,env_1,ih,redecl,m_3);

// redeclaration of classes:
case (cache,env,ih,
Expand Down
29 changes: 26 additions & 3 deletions Compiler/FrontEnd/InstSection.mo
Expand Up @@ -4317,6 +4317,29 @@ algorithm
then
(cache,env,ih,sets_1,DAE.emptyDae,graph);

/* - weird, seems not to be needed
// Connection of arrays of size zero!
case (cache,env,ih,sets,pre,
c1,f1,t1 as DAE.T_ARRAY(dims = {dim1}, ty = _),_,
c2,f2,t2 as DAE.T_ARRAY(dims = {dim2}, ty = _),_,
ct,_,_,graph,_)
equation
0 = Expression.dimensionSize(dim1);
0 = Expression.dimensionSize(dim2);
(cache,_) = PrefixUtil.prefixCref(cache,env,ih,pre,c1);
(cache,_) = PrefixUtil.prefixCref(cache,env,ih,pre,c2);
c1_str = Types.connectorTypeStr(ct) +& ComponentReference.printComponentRefStr(c1);
(t1, _) = Types.stripTypeVars(t1);
t1_str = Types.unparseType(t1);
c2_str = Types.connectorTypeStr(ct) +& ComponentReference.printComponentRefStr(c2);
(t2, _) = Types.stripTypeVars(t2);
t2_str = Types.unparseType(t2);
c1_str = stringAppendList({c1_str," type: ",t1_str});
c2_str = stringAppendList({c2_str," type: ",t2_str});
Error.addSourceMessage(Error.CONNECT_ARRAY_SIZE_ZERO, {c1_str,c2_str},info);
then
(cache,env,ih,sets,DAE.emptyDae,graph);*/

// Connection of arrays of complex types
case (cache,env,ih,sets,pre,
c1,f1,DAE.T_ARRAY(dims = {dim1}, ty = t1),_,
Expand Down Expand Up @@ -4501,9 +4524,9 @@ algorithm
t1_str = Types.unparseType(t1);
c2_str = ComponentReference.printComponentRefStr(c2);
t2_str = Types.unparseType(t2);
c1_str = stringAppendList({c1_str," and ",c2_str});
t1_str = stringAppendList({t1_str," and ",t2_str});
Error.addSourceMessage(Error.INVALID_CONNECTOR_VARIABLE, {c1_str,t1_str},info);
c1_str = stringAppendList({"\n",c1_str," type:\n",t1_str});
c2_str = stringAppendList({"\n",c2_str," type:\n",t2_str});
Error.addSourceMessage(Error.INVALID_CONNECTOR_VARIABLE, {c1_str,c2_str},info);
then
fail();

Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -2764,8 +2764,8 @@ algorithm
equation
(cache,DAE.TYPES_VAR(name,attr,ty,bind,cnstForRange),_,_,_,componentEnv) = lookupVar2(cache, ht, id, inEnv);
ty_1 = checkSubscripts(ty, ss);
ss = addArrayDimensions(ty,ss);
tty = Types.simplifyType(ty);
ss = addArrayDimensions(tty,ss);
cref_ = ComponentReference.makeCrefIdent(id,tty, ss);
splicedExp = Expression.makeCrefExp(cref_,tty);
//print("splicedExp ="+&ExpressionDump.dumpExpStr(splicedExp,0)+&"\n");
Expand All @@ -2785,8 +2785,8 @@ algorithm
(tCref::_) = elabComponentRecursive((texp));
ty1 = checkSubscripts(tyParent, ss);
ty = sliceDimensionType(ty1,ty);
ss = addArrayDimensions(tyParent,ss);
ty2_2 = Types.simplifyType(tyParent);
ss = addArrayDimensions(ty2_2,ss);
xCref = ComponentReference.makeCrefQual(id,ty2_2,ss,tCref);
eType = Types.simplifyType(ty);
splicedExp = Expression.makeCrefExp(xCref,eType);
Expand Down
25 changes: 11 additions & 14 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -11890,24 +11890,21 @@ protected function fillSubscripts
algorithm
outExpSubscriptLst := matchcontinue (inExpSubscriptLst,inType)
local
list<DAE.Subscript> subs_1,subs_2,subs;
DAE.Type t;
DAE.Subscript fs;
// empty list
case ({},DAE.T_ARRAY(ty = t))
equation
subs_1 = fillSubscripts({}, t);
subs_2 = listAppend({DAE.WHOLEDIM()}, subs_1);
then
subs_2;
// some subscripts present
case ((fs :: subs),DAE.T_ARRAY(ty = t))
list<DAE.Subscript> subs;
DAE.Dimensions dims;

// an array
case (_, DAE.T_ARRAY(ty = _))
equation
subs_1 = fillSubscripts(subs, t);
subs = List.fill(DAE.WHOLEDIM(), listLength(Types.getDimensions(inType)));
subs = List.stripN(subs, listLength(inExpSubscriptLst));
subs = listAppend(inExpSubscriptLst, subs);
then
(fs :: subs_1);
subs;

// not an array type!
case (subs,_) then subs;

end matchcontinue;
end fillSubscripts;

Expand Down
37 changes: 33 additions & 4 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -2096,6 +2096,7 @@ algorithm
list<DAE.Type> tys;
DAE.CodeType codeType;
DAE.TypeSource ts;
Boolean b;

case (DAE.T_INTEGER(varLst = {})) then "Integer";
case (DAE.T_REAL(varLst = {})) then "Real";
Expand Down Expand Up @@ -2152,6 +2153,16 @@ algorithm
then
res;

case (DAE.T_COMPLEX(complexClassType = ClassInf.CONNECTOR(_, b),varLst = vs, source = {path}))
equation
name = Absyn.pathStringNoQual(path);
vars = List.map(vs, unparseVar);
vstr = stringAppendList(vars);
str = Util.if_(b, "expandable ", "");
res = stringAppendList({str, "connector ",name,"\n",vstr,"end ", name, ";"});
then
res;

case (DAE.T_SUBTYPE_BASIC(complexClassType = ci_state, varLst = _, complexType = bc_tp))
equation
res = Absyn.pathString(ClassInf.getStateName(ci_state));
Expand Down Expand Up @@ -2653,18 +2664,36 @@ public function unparseVar
algorithm
outString := match (inVar)
local
String t,res,n;
String t,res,n, s;
DAE.Type typ;
SCode.ConnectorType ct;

case DAE.TYPES_VAR(name = n,ty = typ)
case DAE.TYPES_VAR(name = n,ty = typ,attributes = DAE.ATTR(connectorType = ct))
equation
s = connectorTypeStr(ct);
t = unparseType(typ);
res = stringAppendList({t," ",n,";\n"});
res = stringAppendList({" ", s, t," ", n, ";\n"});
then
res;

end match;
end unparseVar;

public function connectorTypeStr
input SCode.ConnectorType ct;
output String str;
algorithm
str := matchcontinue(ct)
local String s;
case (_)
equation
"" = SCodeDump.connectorTypeStr(ct);
then
"";
else SCodeDump.connectorTypeStr(ct) +& " ";
end matchcontinue;
end connectorTypeStr;

protected function unparseParam "Prints a function argument to a string."
input DAE.FuncArg inFuncArg;
output String outString;
Expand Down Expand Up @@ -3846,7 +3875,7 @@ algorithm
DAE.T_ARRAY(t_1,dims,DAE.emptyTypeSource);

// do NOT simplify out equality constraint
// case (DAE.T_SUBTYPE_BASIC(complexType = t, equalityConstraint = SOME(_))) then simplifyType(t);
case (DAE.T_SUBTYPE_BASIC(complexType = t, equalityConstraint = SOME(_))) then simplifyType(t);
case (DAE.T_SUBTYPE_BASIC(complexType = t)) then simplifyType(t);

case (DAE.T_INTEGER(source = _)) then DAE.T_INTEGER_DEFAULT;
Expand Down
5 changes: 3 additions & 2 deletions Compiler/Util/Error.mo
Expand Up @@ -228,7 +228,7 @@ public constant Message UNDECLARED_CONNECTION = MESSAGE(50, TRANSLATION(), ERROR
public constant Message CONNECT_PREFIX_MISMATCH = MESSAGE(51, TRANSLATION(), ERROR(),
Util.gettext("Cannot connect %1 component %2 to non-%1 component %3."));
public constant Message INVALID_CONNECTOR_VARIABLE = MESSAGE(52, TRANSLATION(), ERROR(),
Util.gettext("The type of variables %s (%s) are inconsistent in connect equations."));
Util.gettext("The type of variables %s and %s\nare inconsistent in connect equations."));
public constant Message TYPE_ERROR = MESSAGE(53, TRANSLATION(), ERROR(),
Util.gettext("Wrong type on %s, expected %s."));
public constant Message MODIFY_PROTECTED = MESSAGE(54, TRANSLATION(), WARNING(),
Expand Down Expand Up @@ -756,7 +756,8 @@ public constant Message EXEC_STAT = MESSAGE(547, TRANSLATION(), NOTIFICATION(),
Util.gettext("Performance of %s: time %s/%s, memory: %s/%s MB (%s)."));
public constant Message NON_STANDARD_OPERATOR = MESSAGE(547, TRANSLATION(), WARNING(),
Util.gettext("Usage of non-standard operator (not specified in the Modelica specification): %s. Functionality might be partially supported but is not guaranteed."));

public constant Message CONNECT_ARRAY_SIZE_ZERO = MESSAGE(548, TRANSLATION(), WARNING(),
Util.gettext("Ignoring connection of array components having size zero: %s and %s."));

public constant Message MATCH_SHADOWING = MESSAGE(5001, TRANSLATION(), ERROR(),
Util.gettext("Local variable '%s' shadows another variable."));
Expand Down

0 comments on commit f04d176

Please sign in to comment.