Skip to content

Commit

Permalink
Fix for #2964.
Browse files Browse the repository at this point in the history
- Move SourceInfo from DAE.EqMod to DAE.Mod, so we don't loose them
  for modifiers without bindings.
- Rename DAE.MOD.eqModOption to binding,
         DAE.REDECL.tplSCodeElementModLst to elements.
- Add check for final modification in Mod.merge.
  • Loading branch information
perost authored and unknown committed Nov 19, 2015
1 parent c7b7e74 commit d110f64
Show file tree
Hide file tree
Showing 11 changed files with 545 additions and 621 deletions.
10 changes: 10 additions & 0 deletions Compiler/FrontEnd/ClassInf.mo
Expand Up @@ -759,6 +759,16 @@ algorithm
end match;
end isTypeOrRecord;

public function isRecord
input State inState;
output Boolean outIsRecord;
algorithm
outIsRecord := match inState
case RECORD() then true;
else false;
end match;
end isRecord;

public function stateToSCodeRestriction
"@author: adrpo
ClassInf.State -> SCode.Restriction"
Expand Down
9 changes: 3 additions & 6 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -1197,12 +1197,10 @@ uniontype EqMod "To generate the correct set of equations, the translator has to
Option<Values.Value> modifierAsValue "modifier as Value option" ;
Properties properties "properties" ;
Absyn.Exp modifierAsAbsynExp "keep the untyped modifier as an absyn expression for modification comparison";
SourceInfo info;
end TYPED;

record UNTYPED
Absyn.Exp exp;
SourceInfo info;
end UNTYPED;

end EqMod;
Expand All @@ -1221,20 +1219,19 @@ uniontype Mod "Modification"
SCode.Final finalPrefix "final prefix";
SCode.Each eachPrefix "each prefix";
list<SubMod> subModLst;
Option<EqMod> eqModOption;
Option<EqMod> binding;
SourceInfo info;
end MOD;

record REDECL
SCode.Final finalPrefix "final prefix";
SCode.Each eachPrefix "each prefix";
list<tuple<SCode.Element, Mod>> tplSCodeElementModLst;
list<tuple<SCode.Element, Mod>> elements;
end REDECL;

record NOMOD end NOMOD;

end Mod;


public
uniontype ClockKind
record INFERRED_CLOCK
Expand Down
343 changes: 134 additions & 209 deletions Compiler/FrontEnd/Inst.mo

Large diffs are not rendered by default.

36 changes: 19 additions & 17 deletions Compiler/FrontEnd/InstBinding.mo
Expand Up @@ -158,7 +158,7 @@ algorithm
case (mod,_,expected_type,{},bind_name) /* No subscript/index */
equation
mod2 = Mod.lookupCompModification(mod, bind_name);
SOME(DAE.TYPED(e,optVal,DAE.PROP(ty2,_),_,_)) = Mod.modEquation(mod2);
SOME(DAE.TYPED(e,optVal,DAE.PROP(ty2,_),_)) = Mod.modEquation(mod2);
(e_1,_) = Types.matchType(e, ty2, expected_type, true);
e_1 = InstUtil.checkUseConstValue(useConstValue,e_1,optVal);
then
Expand Down Expand Up @@ -216,7 +216,7 @@ algorithm
case (mod,etype,(index :: {}),_) /* Only one element in the index-list */
equation
mod2 = Mod.lookupIdxModification(mod, DAE.ICONST(index));
SOME(DAE.TYPED(e,optVal,DAE.PROP(ty2,_),_,_)) = Mod.modEquation(mod2);
SOME(DAE.TYPED(e,optVal,DAE.PROP(ty2,_),_)) = Mod.modEquation(mod2);
(e_1,_) = Types.matchType(e, ty2, etype, true);
e_1 = InstUtil.checkUseConstValue(useConstValue,e_1,optVal);
then
Expand Down Expand Up @@ -532,20 +532,20 @@ algorithm
// Record constructors are different
// If it's a constant binding, all fields will already be bound correctly. Don't return a DAE.
case (DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(_)),
DAE.MOD(eqModOption = SOME(DAE.TYPED(_,SOME(_),DAE.PROP(_,DAE.C_CONST()),_,_))))
DAE.MOD(binding = SOME(DAE.TYPED(_,SOME(_),DAE.PROP(_,DAE.C_CONST()),_))))
then DAE.emptyDae;

// Special case if the dimensions of the expression is 0.
// If this is true, and it is instantiated normally, matching properties
// will result in error messages (Real[0] is not Real), so we handle it here.
case (_, DAE.MOD(eqModOption = SOME(DAE.TYPED(properties = prop2))))
case (_, DAE.MOD(binding = SOME(DAE.TYPED(properties = prop2))))
algorithm
DAE.T_ARRAY(dims = {DAE.DIM_INTEGER(0)}) := Types.getPropType(prop2);
then
DAE.emptyDae;

// Regular cases
case (_, DAE.MOD(eqModOption = SOME(DAE.TYPED(e,_,prop2,aexp2,info))))
case (_, DAE.MOD(binding = SOME(DAE.TYPED(e,_,prop2,aexp2)), info = info))
algorithm
t := Types.simplifyType(inType);
lhs := Expression.makeCrefExp(inComponentRef, t);
Expand All @@ -557,7 +557,7 @@ algorithm
then
dae;

case (_, DAE.MOD(eqModOption = NONE())) then DAE.emptyDae;
case (_, DAE.MOD(binding = NONE())) then DAE.emptyDae;
case (_, DAE.NOMOD()) then DAE.emptyDae;
case (_, DAE.REDECL()) then DAE.emptyDae;

Expand Down Expand Up @@ -628,7 +628,7 @@ algorithm
// Modelica.Electrical.Machines.Examples.SMEE_Generator
// (BUG: #1156 at https://openmodelica.org:8443/cb/issue/1156)
// and maybe a lot others.
case (cache,SCode.ATTR(variability = SCode.PARAM()),DAE.MOD(eqModOption = NONE()),tp)
case (cache,SCode.ATTR(variability = SCode.PARAM()),DAE.MOD(binding = NONE()),tp)
equation
true = Types.getFixedVarAttributeParameterOrConstant(tp);
// this always succeeds but return NOMOD if there is no (start = x)
Expand Down Expand Up @@ -658,17 +658,17 @@ algorithm
then
(cache, binding);

case (cache,_,DAE.MOD(eqModOption = NONE()),_) then (cache,DAE.UNBOUND());
case (cache,_,DAE.MOD(binding = NONE()),_) then (cache,DAE.UNBOUND());
/* adrpo: CHECK! do we need this here? numerical values
case (cache,env,_,DAE.MOD(eqModOption = SOME(DAE.TYPED(e,_,DAE.PROP(e_tp,_)))),tp,_,_)
case (cache,env,_,DAE.MOD(binding = SOME(DAE.TYPED(e,_,DAE.PROP(e_tp,_)))),tp,_,_)
equation
(e_1,_) = Types.matchType(e, e_tp, tp);
(cache,v,_) = Ceval.ceval(cache,env, e_1, false,NONE(), NONE(), Absyn.NO_MSG(),0);
then
(cache,DAE.VALBOUND(v, DAE.BINDING_FROM_DEFAULT_VALUE()));
*/

case (cache,_,DAE.MOD(eqModOption = SOME(DAE.TYPED(e,SOME(v),prop,_,_))),e_tp) /* default */
case (cache,_,DAE.MOD(binding = SOME(DAE.TYPED(e,SOME(v),prop,_))),e_tp) /* default */
equation
c = Types.propAllConst(prop);
tp = Types.getPropType(prop);
Expand All @@ -686,7 +686,7 @@ algorithm
then
(cache,DAE.EQBOUND(e_1,e_val,c,DAE.BINDING_FROM_DEFAULT_VALUE()));

case (cache,_,DAE.MOD(eqModOption = SOME(DAE.TYPED(e,e_val,prop,_,_))),e_tp) /* default */
case (cache,_,DAE.MOD(binding = SOME(DAE.TYPED(e,e_val,prop,_))),e_tp) /* default */
equation
c = Types.propAllConst(prop);
tp = Types.getPropType(prop);
Expand All @@ -698,7 +698,7 @@ algorithm
then
(cache,DAE.EQBOUND(e_1,e_val,c,DAE.BINDING_FROM_DEFAULT_VALUE()));

case (_,_,DAE.MOD(eqModOption = SOME(DAE.TYPED(e,_,prop,_,info))),tp)
case (_,_,DAE.MOD(binding = SOME(DAE.TYPED(e,_,prop,_)), info = info),tp)
equation
e_tp = Types.getPropType(prop);
_ = Types.propAllConst(prop);
Expand Down Expand Up @@ -823,27 +823,27 @@ algorithm
String binding_str, expected_type_str, given_type_str;

// Array type and each prefix => return the expression and value.
case (SOME(DAE.NAMEMOD(mod = DAE.MOD(eachPrefix = SCode.EACH(), eqModOption =
case (SOME(DAE.NAMEMOD(mod = DAE.MOD(eachPrefix = SCode.EACH(), binding =
SOME(DAE.TYPED(modifierAsExp = exp, modifierAsValue = SOME(val)))))))
then (exp, val);

// Scalar type and no each prefix => return the expression and value.
case (SOME(DAE.NAMEMOD(mod = DAE.MOD(eachPrefix = SCode.NOT_EACH(), eqModOption =
case (SOME(DAE.NAMEMOD(mod = DAE.MOD(eachPrefix = SCode.NOT_EACH(), binding =
SOME(DAE.TYPED(modifierAsExp = exp, modifierAsValue = SOME(val), properties = DAE.PROP(type_ = ty)))))))
algorithm
(exp, ty) := Types.matchType(exp, ty, inType, true);
then
(exp, val);

// Scalar type and no each prefix => bindings given by expressions myRecord(v1 = inV1, v2 = inV2)
case (SOME(DAE.NAMEMOD(mod = DAE.MOD(eachPrefix = SCode.NOT_EACH(), eqModOption =
case (SOME(DAE.NAMEMOD(mod = DAE.MOD(eachPrefix = SCode.NOT_EACH(), binding =
SOME(DAE.TYPED(modifierAsExp = exp, modifierAsValue = NONE(), properties = DAE.PROP(type_ = ty)))))))
algorithm
(exp, ty) := Types.matchType(exp, ty, inType, true);
then
(exp, Values.OPTION(NONE()));

case (SOME(DAE.NAMEMOD(ident = ident, mod = DAE.MOD(eqModOption =
case (SOME(DAE.NAMEMOD(ident = ident, mod = DAE.MOD(binding =
SOME(DAE.TYPED(modifierAsExp = exp, properties = DAE.PROP(type_ = ty)))))))
equation
binding_str = ExpressionDump.printExpStr(exp);
Expand Down Expand Up @@ -880,7 +880,7 @@ algorithm
return;
end if;

SOME(DAE.TYPED(modifierAsExp = e, properties = p, info = info)) := oeq_mod;
SOME(DAE.TYPED(modifierAsExp = e, properties = p)) := oeq_mod;

if Types.isExternalObject(inType) then
// For external objects the binding contains the constructor call. Return it as it is.
Expand All @@ -889,6 +889,8 @@ algorithm
// An empty array has unknown type, skip type matching.
outBinding := NONE();
else
info := Mod.getModInfo(inMod);

// For normal variables, make sure the types match.
try
(e2, DAE.PROP(constFlag = c)) :=
Expand Down
12 changes: 6 additions & 6 deletions Compiler/FrontEnd/InstExtends.mo
Expand Up @@ -178,8 +178,8 @@ algorithm
rest_els := SCodeUtil.addRedeclareAsElementsToExtends(rest_els,
list(e for e guard(SCodeUtil.isRedeclareElement(e)) in rest_els));

outMod := Mod.elabUntypedMod(emod, inEnv, Prefix.NOPRE(), Mod.EXTENDS(el.baseClassPath));
outMod := Mod.merge(mod, outMod, inEnv, Prefix.NOPRE());
outMod := Mod.elabUntypedMod(emod, Mod.EXTENDS(el.baseClassPath));
outMod := Mod.merge(mod, outMod, "", false);

(outCache, _, outIH, _, els2, eq2, ieq2, alg2, ialg2) :=
instExtendsAndClassExtendsList2(outCache, cenv, outIH, outMod, inPrefix,
Expand Down Expand Up @@ -659,9 +659,9 @@ algorithm
dmod = InstUtil.chainRedeclares(mod, dmod);
// false = Absyn.pathEqual(FGraph.getGraphName(env),FGraph.getGraphName(cenv)) and SCode.elementEqual(c,inClass);
// modifiers should be evaluated in the current scope for derived!
//daeDMOD = Mod.elabUntypedMod(dmod, env, Prefix.NOPRE(), Mod.DERIVED(tp));
//daeDMOD = Mod.elabUntypedMod(dmod, Mod.DERIVED(tp));
(cache,daeDMOD) = Mod.elabMod(cache, env, ih, pre, dmod, impl, Mod.DERIVED(tp), info);
mod = Mod.merge(mod, daeDMOD, env, pre);
mod = Mod.merge(mod, daeDMOD);
// print("DER: " + SCodeDump.unparseElementStr(inClass, SCodeDump.defaultOptions) + "\n");
(cache,env,ih,elt,eq,ieq,alg,ialg,mod) = instDerivedClassesWork(cache, cenv, ih, mod, pre, c, impl, info, numIter >= Global.recursionDepthLimit, numIter+1)
"Mod.lookup_modification_p(mod, c) => innermod & We have to merge and apply modifications as well!" ;
Expand Down Expand Up @@ -757,7 +757,7 @@ algorithm
// cmod2 = Mod.getModifs(inMod, id, m);
cmod2 = Mod.lookupCompModificationFromEqu(inMod, id);
// Debug.traceln("\tSpecific mods on comp: " + Mod.printModStr(cmod2));
cmod = Mod.merge(cmod2, cmod, inEnv, Prefix.NOPRE());
cmod = Mod.merge(cmod2, cmod, id, false);
mod_rest = inMod; //mod_rest = Mod.removeMod(inMod, id);
then
((comp, cmod, b), mod_rest);
Expand All @@ -772,7 +772,7 @@ algorithm
equation
DAE.REDECL(_, _, (comp2, cmod2)::_) = Mod.lookupCompModification(inMod, id);
mod_rest = inMod; //mod_rest = Mod.removeMod(inMod, id);
cmod2 = Mod.merge(cmod2, cmod1, inEnv, Prefix.NOPRE());
cmod2 = Mod.merge(cmod2, cmod1, id, false);
comp2 = SCode.mergeWithOriginal(comp2, comp1);
// comp2 = SCode.renameElement(comp2, id);
then
Expand Down
37 changes: 19 additions & 18 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -1465,7 +1465,7 @@ algorithm
equation
name2 = Absyn.printComponentRefStr(dep);
true = stringEq(name2,name1);
cmod = DAE.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{DAE.NAMEMOD(name2,cmod)},NONE());
cmod = DAE.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{DAE.NAMEMOD(name2,cmod)},NONE(), Absyn.dummyInfo);
then
cmod;
case(dep,_::elems)
Expand Down Expand Up @@ -2685,7 +2685,7 @@ algorithm
equation
// compmod = Mod.getModifs(mods, n, m);
compmod = Mod.lookupCompModification(mods, n);
cmod_1 = Mod.merge(compmod, cmod, env, pre);
cmod_1 = Mod.merge(compmod, cmod);

/*
print("InstUtil.addCompToEnv: " +
Expand Down Expand Up @@ -2810,7 +2810,7 @@ algorithm
case (_,SCode.REDECL(f, e, SCode.CLASS(name = nInner, classDef = SCode.DERIVED(typeSpec = Absyn.TPATH(path = Absyn.IDENT(nDerivedInner))))))
equation
// lookup the class mod in the outer
(DAE.REDECL(tplSCodeElementModLst = (cls,_)::_)) = Mod.lookupModificationP(inModOuter, Absyn.IDENT(nDerivedInner));
(DAE.REDECL(elements = (cls,_)::_)) = Mod.lookupModificationP(inModOuter, Absyn.IDENT(nDerivedInner));
cls = SCode.setClassName(nInner, cls);
then
SCode.REDECL(f, e, cls);
Expand All @@ -2819,7 +2819,7 @@ algorithm
case (_,SCode.REDECL(f, e, SCode.CLASS(name = nInner, classDef = SCode.DERIVED(typeSpec = Absyn.TPATH(path = Absyn.IDENT(_))))))
equation
// lookup the class mod in the outer
(DAE.REDECL(tplSCodeElementModLst = (cls,_)::_)) = Mod.lookupModificationP(inModOuter, Absyn.IDENT(nInner));
(DAE.REDECL(elements = (cls,_)::_)) = Mod.lookupModificationP(inModOuter, Absyn.IDENT(nInner));
then
SCode.REDECL(f, e, cls);

Expand Down Expand Up @@ -3236,16 +3236,17 @@ algorithm
Option<DAE.EqMod> oe;
list<DAE.SubMod> subs;
list<String> compNames;
SourceInfo info;

case (_,{}) then inMod;
case(DAE.NOMOD(),_ ) then DAE.NOMOD();
case(DAE.REDECL(_,_,_),_) then inMod;
case(DAE.MOD(f,e,subs,oe),_)
case(DAE.MOD(f,e,subs,oe,info),_)
equation
compNames = List.map(elems,SCode.elementName);
subs = keepConstrainingTypeModifersOnly2(subs,compNames);
then
DAE.MOD(f,e,subs,oe);
DAE.MOD(f,e,subs,oe,info);
end matchcontinue;
end keepConstrainingTypeModifersOnly;

Expand Down Expand Up @@ -3705,7 +3706,7 @@ algorithm
type_mods = Mod.addEachIfNeeded(type_mods, dim2);
// do not add each to mod_1, it should have it already!
// mod_1 = Mod.addEachIfNeeded(mod_1, dim2);
type_mods = Mod.merge(mod_1, type_mods, env, pre);
type_mods = Mod.merge(mod_1, type_mods);
res = listAppend(dim2, dim1);
then
(cache,res,cl,type_mods);
Expand All @@ -3725,7 +3726,7 @@ algorithm
(cache,cl,_) = Lookup.lookupClass(cache, env, path);
(cache,res,cl,type_mods) = getUsertypeDimensions(cache,env,ih,pre,cl,{},impl);
// type_mods = Mod.addEachIfNeeded(type_mods, res);
type_mods = Mod.merge(mod_1, type_mods, env, pre);
type_mods = Mod.merge(mod_1, type_mods);
then
(cache,res,cl,type_mods);

Expand Down Expand Up @@ -3890,7 +3891,7 @@ algorithm
DAE.Exp exp;
String exp_str;

case (DAE.DIM_UNKNOWN(), DAE.MOD(eqModOption =
case (DAE.DIM_UNKNOWN(), DAE.MOD(binding =
SOME(DAE.TYPED(modifierAsExp = exp))), _, _)
equation
(d :: _) = Expression.expDimensions(exp);
Expand All @@ -3899,7 +3900,7 @@ algorithm
// TODO: We should print an error if we fail to deduce the dimensions from
// the modifier, but we do not yet handle some cases (such as
// Modelica.Blocks.Sources.KinematicPTP), so just print a warning for now.
case (DAE.DIM_UNKNOWN(), DAE.MOD(eqModOption =
case (DAE.DIM_UNKNOWN(), DAE.MOD(binding =
SOME(DAE.TYPED(modifierAsExp = exp))), _, _)
equation
exp_str = ExpressionDump.printExpStr(exp);
Expand Down Expand Up @@ -4272,7 +4273,7 @@ algorithm
cmod_1 = Mod.stripSubmod(cmod);
m_1 = SCode.stripSubmod(m);
(cache,m_2) = Mod.elabMod(cache, env, InnerOuter.emptyInstHierarchy, Prefix.NOPRE(), m_1, false, Mod.COMPONENT(id), info);
mod_2 = Mod.merge(cmod_1, m_2, env, Prefix.NOPRE());
mod_2 = Mod.merge(cmod_1, m_2);
SOME(eq) = Mod.modEquation(mod_2);
(cache,dims) = elabComponentArraydimFromEnv2(cache,eq, env);
then
Expand Down Expand Up @@ -4437,7 +4438,7 @@ algorithm
then
(cache,dim);

case (cache,env,cref,_,ad,SOME(DAE.TYPED(e,_,prop,_,info)),impl,st,doVect,_ ,pre,_,inst_dims) /* Untyped expressions must be elaborated. */
case (cache,env,cref,_,ad,SOME(DAE.TYPED(e,_,prop,_)),impl,st,doVect,_ ,pre,info,inst_dims) /* Untyped expressions must be elaborated. */
equation
t = Types.getPropType(prop);
(cache,dim1) = Static.elabArrayDims(cache,env, cref, ad, impl, st,doVect,pre,info);
Expand All @@ -4447,7 +4448,7 @@ algorithm
then
(cache,dim3);

case (cache,env,cref,_,ad,SOME(DAE.UNTYPED(aexp,info)),impl,st,doVect, _,pre,_,inst_dims)
case (cache,env,cref,_,ad,SOME(DAE.UNTYPED(aexp)),impl,st,doVect, _,pre,info,inst_dims)
equation
(cache,e_1,prop,_) = Static.elabExp(cache,env, aexp, impl, st,doVect,pre,info);
(cache, e_1, prop) = Ceval.cevalIfConstant(cache, env, e_1, prop, impl, info);
Expand All @@ -4459,7 +4460,7 @@ algorithm
then
(cache,dim3);

case (cache,env,cref,_,ad,SOME(DAE.TYPED(e,_,DAE.PROP(t,_),_,info)),impl,st,doVect, _,pre,_,inst_dims)
case (cache,env,cref,_,ad,SOME(DAE.TYPED(e,_,DAE.PROP(t,_),_)),impl,st,doVect, _,pre,info,inst_dims)
equation
// adrpo: do not display error when running checkModel
// TODO! FIXME! check if this doesn't actually get rid of useful error messages
Expand Down Expand Up @@ -4912,13 +4913,13 @@ algorithm
local
DAE.EqMod eq;
DAE.Exp e;
case(DAE.NAMEMOD(inputVar,mod = DAE.MOD(eqModOption = SOME(DAE.TYPED(modifierAsExp=e)))))
case(DAE.NAMEMOD(inputVar,mod = DAE.MOD(binding = SOME(DAE.TYPED(modifierAsExp=e)))))
equation
then (inputVar,DAE.NO_DERIVATIVE(e));
case(DAE.NAMEMOD(inputVar,mod = DAE.MOD(eqModOption = NONE())))
case(DAE.NAMEMOD(inputVar,mod = DAE.MOD(binding = NONE())))
equation
then (inputVar,DAE.NO_DERIVATIVE(DAE.ICONST(1)));
case(DAE.NAMEMOD(inputVar,mod = DAE.MOD(eqModOption = NONE()))) // zeroderivative
case(DAE.NAMEMOD(inputVar,mod = DAE.MOD(binding = NONE()))) // zeroderivative
then (inputVar,DAE.ZERO_DERIVATIVE());

else ("",DAE.ZERO_DERIVATIVE());
Expand Down Expand Up @@ -6818,7 +6819,7 @@ algorithm

case(_,_,_,_,NONE(),_) then fail();

case(cache, _, ih, pre, SOME(DAE.MOD(_,_, lsm ,_)), SCode.CLASS(name=str))
case(cache, _, ih, pre, SOME(DAE.MOD(subModLst = lsm)), SCode.CLASS(name=str))
equation
// fprintln(Flags.INST_TRACE, "Mods in addClassdefsToEnv3: " + Mod.printModStr(mo) + " class name: " + str);
(mo2,_) = extractCorrectClassMod2(lsm,str,{});
Expand Down

0 comments on commit d110f64

Please sign in to comment.