Skip to content

Commit

Permalink
Fix #3247
Browse files Browse the repository at this point in the history
- use the class modification from the environment

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25277 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Mar 26, 2015
1 parent 3e8fc88 commit 936a7af
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
16 changes: 6 additions & 10 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -3576,18 +3576,14 @@ 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;
cls_mod = Mod.removeMod(class_mod, SCode.className(cls));
if not Mod.isEmptyMod(cls_mod)
cls_mod = Mod.getClassModifier(cenv, SCode.className(cls));
if not Mod.isEmptyMod(cls_mod)
then
if not listEmpty(ad) // add each if needed
then
if not listEmpty(ad) // add each if needed
then
cls_mod = Mod.addEachIfNeeded(cls_mod, {DAE.DIM_INTEGER(1)});
end if;
mod_1 = Mod.merge(mod_1, cls_mod, env2, pre);
cls_mod = Mod.addEachIfNeeded(cls_mod, {DAE.DIM_INTEGER(1)});
end if;
mod_1 = Mod.merge(mod_1, cls_mod, env2, pre);
end if;
attr = SCode.mergeAttributesFromClass(attr, cls);

Expand Down
24 changes: 18 additions & 6 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -194,6 +194,7 @@ algorithm
ClassInf.State ci_state;
SCode.Encapsulated encflag;
DAE.TypeSource ts;
DAE.Mod mod;

// Record constructors
case (cache,env_1,_,c as SCode.CLASS(restriction=SCode.R_RECORD(_)))
Expand All @@ -208,10 +209,11 @@ algorithm
env_2 = FGraph.openScope(env_1, encflag, SOME(id), SOME(FCore.CLASS_SCOPE()));
ci_state = ClassInf.start(r, FGraph.getGraphName(env_2));
// fprintln(Flags.INST_TRACE, "LOOKUP TYPE ICD: " + FGraph.printGraphPathStr(env_1) + " path:" + Absyn.pathString(path));
mod = Mod.getClassModifier(env_1, id);
(cache,env_3,_,_,_,_,_,types,_,_,_,_) =
Inst.instClassIn(
cache,env_2,InnerOuter.emptyInstHierarchy,UnitAbsyn.noStore,
DAE.NOMOD(), Prefix.NOPRE(),
mod, Prefix.NOPRE(),
ci_state, c, SCode.PUBLIC(), {}, false, InstTypes.INNER_CALL(),
ConnectionGraph.EMPTY, Connect.emptySet, NONE());
// build names
Expand Down Expand Up @@ -589,6 +591,7 @@ algorithm
String id;
SCode.Element c;
FCore.Ref r;
DAE.Mod mod;

case (cache,env,_,_,SOME(frame),prevFrames,_,_)
equation
Expand All @@ -612,10 +615,11 @@ algorithm
env = FGraph.openScope(env, encflag, SOME(id), FGraph.restrictionToScopeType(restr));
ci_state = ClassInf.start(restr, FGraph.getGraphName(env));
// fprintln(Flags.INST_TRACE, "LOOKUP CLASS QUALIFIED PARTIALICD: " + FGraph.printGraphPathStr(env) + " path: " + Absyn.pathString(path) + " class: " + SCodeDump.shortElementStr(c));
mod = Mod.getClassModifier(inEnv, id);
(cache,env,_,_,_) =
Inst.partialInstClassIn(
cache,env,InnerOuter.emptyInstHierarchy,
DAE.NOMOD(), Prefix.NOPRE(),
mod, Prefix.NOPRE(),
ci_state, inC, SCode.PUBLIC(), {}, 0);
// Was 2 cases for package/non-package - all they did was fail or succeed on this
// If we comment it out, we get faster code, and less of it to maintain
Expand Down Expand Up @@ -878,6 +882,7 @@ algorithm
list<Absyn.Import> rest;
FCore.Cache cache;
FCore.Ref r;
DAE.Mod mod;

// Not found, instantiate
case (cache,Absyn.UNQUAL_IMPORT(path = path) :: _,env,ident)
Expand All @@ -887,7 +892,8 @@ algorithm
env2 = FGraph.openScope(env_1, encflag, SOME(id), FGraph.restrictionToScopeType(restr));
ci_state = ClassInf.start(restr, FGraph.getGraphName(env2));
// fprintln(Flags.INST_TRACE, "LOOKUP MORE UNQUALIFIED IMPORTED ICD: " + FGraph.printGraphPathStr(env) + "." + ident);
(cache, env, _,_,_) = Inst.partialInstClassIn(cache, env2, InnerOuter.emptyInstHierarchy, DAE.NOMOD(), Prefix.NOPRE(), ci_state, c, SCode.PUBLIC(), {}, 0);
mod = Mod.getClassModifier(env_1, id);
(cache, env, _,_,_) = Inst.partialInstClassIn(cache, env2, InnerOuter.emptyInstHierarchy, mod, Prefix.NOPRE(), ci_state, c, SCode.PUBLIC(), {}, 0);
r = FGraph.lastScopeRef(env);
env = FGraph.setScope(env, {r});
(cache,_,_) = lookupClass(cache, env, Absyn.IDENT(ident), false);
Expand Down Expand Up @@ -934,6 +940,7 @@ algorithm
list<Absyn.Import> rest;
FCore.Cache cache;
Absyn.Ident firstIdent;
DAE.Mod mod;

// Not in cache, instantiate, unique
case (cache,Absyn.UNQUAL_IMPORT(path = path) :: rest,env,ident)
Expand All @@ -944,9 +951,10 @@ algorithm
env2 = FGraph.openScope(env_1, encflag, SOME(id), FGraph.restrictionToScopeType(restr));
ci_state = ClassInf.start(restr, FGraph.getGraphName(env2));
// fprintln(Flags.INST_TRACE, "LOOKUP UNQUALIFIED IMPORTED ICD: " + FGraph.printGraphPathStr(env) + "." + ident);
mod = Mod.getClassModifier(env_1, id);
(cache,env2,_,_,_) =
Inst.partialInstClassIn(cache, env2, InnerOuter.emptyInstHierarchy,
DAE.NOMOD(), Prefix.NOPRE(), ci_state, c, SCode.PUBLIC(), {}, 0);
mod, Prefix.NOPRE(), ci_state, c, SCode.PUBLIC(), {}, 0);
// Restrict import to the imported scope only, not its parents, thus {f} below
(cache,c_1,env2,prevFrames) = lookupClass2(cache,env2,Absyn.IDENT(ident),prevFrames,Util.makeStatefulBoolean(true),false) "Restrict import to the imported scope only, not its parents..." ;
(cache,more) = moreLookupUnqualifiedImportedClassInFrame(cache, rest, env, ident);
Expand Down Expand Up @@ -1280,6 +1288,7 @@ algorithm
Boolean unique;
FCore.Children ht;
list<Absyn.Import> qimports, uqimports;
DAE.Mod mod;

// If we search for A1.A2....An.x while in scope A1.A2...An, just search for x.
// Must do like this to ensure finite recursion
Expand Down Expand Up @@ -1314,9 +1323,10 @@ algorithm
env3 = FGraph.openScope(env2, encflag, SOME(n), FGraph.restrictionToScopeType(r));
ci_state = ClassInf.start(r, FGraph.getGraphName(env3));
// fprintln(Flags.INST_TRACE, "LOOKUP VAR IN PACKAGES ICD: " + FGraph.printGraphPathStr(env3) + " var: " + ComponentReference.printComponentRefStr(cref));
mod = Mod.getClassModifier(env2, n);
(cache,env5,_,_,_,_,_,_,_,_,_,_) =
Inst.instClassIn(cache,env3,InnerOuter.emptyInstHierarchy,UnitAbsyn.noStore,
DAE.NOMOD(), Prefix.NOPRE(), ci_state, c, SCode.PUBLIC(), {},
mod, Prefix.NOPRE(), ci_state, c, SCode.PUBLIC(), {},
/*true*/false, InstTypes.INNER_CALL(), ConnectionGraph.EMPTY,
Connect.emptySet, NONE());
end if;
Expand Down Expand Up @@ -1707,6 +1717,7 @@ algorithm
FCore.Ref r;
FCore.Scope rs;
FCore.Cache cache;
DAE.Mod mod;

// Simple name, search frame
case (cache, FCore.G(scope = r::_),Absyn.IDENT(name = str),_,_)
Expand Down Expand Up @@ -1749,10 +1760,11 @@ algorithm
env2 = FGraph.openScope(env_1, encflag, SOME(str), FGraph.restrictionToScopeType(restr));
ci_state = ClassInf.start(restr, FGraph.getGraphName(env2));
// fprintln(Flags.INST_TRACE, "LOOKUP FUNCTIONS IN ENV QUAL ICD: " + FGraph.printGraphPathStr(env2) + "." + str);
mod = Mod.getClassModifier(env_1, str);
(cache,env2,_,_,_) =
Inst.partialInstClassIn(
cache, env2, InnerOuter.emptyInstHierarchy,
DAE.NOMOD(), Prefix.NOPRE(),
mod, Prefix.NOPRE(),
ci_state, c, SCode.PUBLIC(), {}, 0);
end if;
(cache,res) = lookupFunctionsInEnv2(cache, env2, path, true, info);
Expand Down
34 changes: 34 additions & 0 deletions Compiler/FrontEnd/Mod.mo
Expand Up @@ -3332,6 +3332,40 @@ algorithm
end match;
end isRedeclareMod;


public function getClassModifier
"return the modifier present in the environment for this class or DAE.NOMOD if ther is none"
input FCore.Graph inEnv;
input FCore.Name inName;
output DAE.Mod outMod;
protected
FCore.Node n;
DAE.Mod mod;
algorithm
outMod := matchcontinue(inEnv, inName)

case (_, _)
equation
n = FNode.fromRef(FNode.child(FGraph.lastScopeRef(inEnv), inName));
if (not FNode.isInstance(FNode.fromRef(FGraph.lastScopeRef(inEnv)))) then
FCore.N(data=FCore.CL(mod = mod)) = n;
mod = Mod.removeMod(mod, inName);
/*
if not isEmptyMod(mod)
then
print("Env: " + FGraph.printGraphPathStr(inEnv) + " " + inName + "(" + printModStr(mod) + ")" + "\n");
end if;
*/
else
mod = DAE.NOMOD();
end if;
then mod;

else DAE.NOMOD();

end matchcontinue;
end getClassModifier;

annotation(__OpenModelica_Interface="frontend");
end Mod;

0 comments on commit 936a7af

Please sign in to comment.