Skip to content

Commit

Permalink
Fix #3051
Browse files Browse the repository at this point in the history
- merge modifiers for the class from the environment
- add tests: testsuite/flattening/modelica/modification/MissingModifiers.mo, testsuite/flattening/modelica/modification/TestMissingModifiers.mos
  


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24987 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Mar 9, 2015
1 parent d0a0016 commit 8ce63e5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
23 changes: 22 additions & 1 deletion Compiler/FrontEnd/Inst.mo
Expand Up @@ -3440,6 +3440,7 @@ algorithm
SCode.Visibility vis;
String name, id, ns, s, scope_str;
UnitAbsyn.InstStore store;
FCore.Node node;

// Imports are simply added to the current frame, so that the lookup rule can find them.
// Import have already been added to the environment so there is nothing more to do here.
Expand Down Expand Up @@ -3571,6 +3572,12 @@ algorithm
= redeclareType(cache, env2, ih, mod, comp, pre, ci_state, impl, DAE.NOMOD());

(cache, cls, cenv) = Lookup.lookupClass(cache, env2 /* env */, t, true);
node = FNode.fromRef(FNode.child(FGraph.lastScopeRef(cenv), SCode.className(cls)));
if (not FNode.isInstance(FNode.fromRef(FGraph.lastScopeRef(cenv)))) then
FCore.N(data=FCore.CL(mod = class_mod)) = node;
class_mod = Mod.removeMod(class_mod, SCode.className(cls));
mod_1 = Mod.merge(mod_1, class_mod, env2, pre);
end if;
attr = SCode.mergeAttributesFromClass(attr, cls);

// If the element is protected, and an external modification
Expand Down Expand Up @@ -4212,7 +4219,7 @@ algorithm
Absyn.TypeSpec tsNew;
SCode.Mod m;
SCode.Comment comment;
DAE.Mod cmod,mods;
DAE.Mod cmod,mods,rmod;
SCode.Element cl, compNew;
FCore.Graph cenv,env2,env_1;
list<Absyn.ComponentRef> crefs,crefs2,crefs3,crefs_1,crefs_2;
Expand Down Expand Up @@ -4242,6 +4249,20 @@ algorithm
// then
// (cache,env,ih,csets,updatedComps);

// if we have a redeclare for a component
/*case (cache,env,ih,_,
DAE.MOD(eqModOption = NONE(),
subModLst = {
DAE.NAMEMOD(ident=n,
mod = rmod as DAE.REDECL(_, _, {(SCode.COMPONENT(name = name),_)}))}),_,_,_,_,_)
equation
id = Absyn.crefFirstIdent(cref);
true = stringEq(id, name);
true = stringEq(id, n);
(outCache,outEnv,outIH,outUpdatedComps) = updateComponentInEnv(inCache,inEnv,inIH,pre,rmod,cref,inCIState,impl,inUpdatedComps,currentCref);
then
(outCache,outEnv,outIH,outUpdatedComps);*/

// if we have a redeclare for a component
case (cache,env,ih,_,
DAE.REDECL(_, _, {
Expand Down
19 changes: 19 additions & 0 deletions Compiler/FrontEnd/InstBinding.mo
Expand Up @@ -881,6 +881,25 @@ algorithm
then
binding;

/*/ If the previous case fails, then there is no binding for this component, ignore it
case (_, _, _, _, DAE.TYPES_VAR(name = name, binding = DAE.UNBOUND(), ty = ty) :: rest_vars, sub_mods, _, _, _, _)
equation
// make sure there is no binding for it
// The previous cases can also fail for other reasons. e.g type mismatch.
(sub_mods, NONE()) = List.deleteMemberOnTrue(name, sub_mods, InstUtil.isSubModNamed);
binding = makeRecordBinding2(
inCache, inEnv,
inRecordName,
inRecordType,
rest_vars,
sub_mods,
inInfo,
inAccumExps,
inAccumVals,
inAccumNames);
then
binding; */

case (_, _, _, _, DAE.TYPES_VAR(name = name) :: _, _, _, _, _, _)
equation
true = Flags.isSet(Flags.FAILTRACE);
Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -2417,6 +2417,7 @@ algorithm
// we do have a redeclaration of class.
case (cache,env,ih,pre,( (sel1 as SCode.CLASS())),_,SOME(m))
equation
m = Mod.lookupCompModification(m, sel1.name);
false = valueEq(m, DAE.NOMOD());
env_1 = FGraph.mkClassNode(env, sel1, pre, m);
// call to redeclareType which calls updateComponents in env wich updates the class frame
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Lookup.mo
Expand Up @@ -2728,7 +2728,7 @@ algorithm
(DAE.TYPES_VAR(_,DAE.ATTR(variability = vt2),tyParent,parentBinding,_),_,_,_,componentEnv) = lookupVar2(ht, id, inEnv);

// leave just the last scope from component env as it SHOULD BE ONLY THERE, i.e. don't go on searching the parents!
componentEnv = FGraph.setScope(componentEnv, List.create(FGraph.lastScopeRef(componentEnv)));
// componentEnv = FGraph.setScope(componentEnv, List.create(FGraph.lastScopeRef(componentEnv)));

(cache,DAE.ATTR(ct,prl,vt,di,io,vis),tyChild,binding,cnstForRange,InstTypes.SPLICEDEXPDATA(texp,idTp),_,componentEnv,name) = lookupVar(cache, componentEnv, ids);

Expand Down
10 changes: 10 additions & 0 deletions Compiler/FrontEnd/Mod.mo
Expand Up @@ -481,6 +481,16 @@ algorithm
then
SCode.MOD(finalPrefix,each_,subs_1,SOME((e_1,false)),info); // default typechecking non-delayed

/* / use the expression second
case ((DAE.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,
eqModOption = SOME(DAE.TYPED(modifierAsExp = dexp, info = info)))))
equation
//es = ExpressionDump.printExpStr(e);
subs_1 = unelabSubmods(subs);
e_1 = Expression.unelabExp(dexp);
then
SCode.MOD(finalPrefix,each_,subs_1,SOME((e_1,false)),info); // default typechecking non-delayed */

case ((DAE.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,
eqModOption = SOME(DAE.TYPED(_,_,_,absynExp,info)))))
equation
Expand Down

0 comments on commit 8ce63e5

Please sign in to comment.