Skip to content

Commit

Permalink
- more fixes for fixes for bugs: #1917, #1983 :) isn't that recursive?
Browse files Browse the repository at this point in the history
- get rid of wrong error messages of type:
  [package.mo:4549:7-4549:59:writable] 
  Error: Variable reference_X not found in scope Modelica.Media.Interfaces.PartialMedium.specificEnthalpy_pTX
- let's see how many tests we break/fix now :)

Inst.mo
- better analysis of dependencies between elements in Inst.getElementDependencies but 
  commented out for now as it moves things around and breaks a lot of flattening models.

Lookup.mo
- use the updated environment, not the one stored in Env.CLASS whenever possible.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14365 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Dec 13, 2012
1 parent 1f4d159 commit a8660ae
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 26 deletions.
69 changes: 67 additions & 2 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -5412,13 +5412,15 @@ algorithm
local
list<Absyn.Exp> rest;
Absyn.Exp e;
list<tuple<SCode.Element, DAE.Mod>> deps;
list<tuple<SCode.Element, DAE.Mod>> deps, els;

// handle the empty case
case ({}, _, _) then inDependencies;
// handle the normal case
case (e::rest, _, deps)
equation
//(_, (_, _, (els, deps))) = Absyn.traverseExpBidir(e, (getElementDependenciesTraverserEnter, getElementDependenciesTraverserExit, (inAllElements, deps)));
//deps = getDepsFromExps(rest, els, deps);
(_, (_, _, (_, deps))) = Absyn.traverseExpBidir(e, (getElementDependenciesTraverserEnter, getElementDependenciesTraverserExit, (inAllElements, deps)));
deps = getDepsFromExps(rest, inAllElements, deps);
then
Expand Down Expand Up @@ -5550,6 +5552,7 @@ algorithm
Boolean hasUnknownDims;
Absyn.Direction direction;
list<tuple<SCode.Element, DAE.Mod>> inAllElements;
list<SCode.Element> els;

// For constants and parameters we check the component conditional, array dimensions, modifiers and binding
case ((SCode.COMPONENT(name = name, condition = cExpOpt, attributes = SCode.ATTR(arrayDims = ad, variability = var),
Expand Down Expand Up @@ -5611,10 +5614,58 @@ algorithm
then
deps;

// We might have functions here and their input/output elements can have bindings from the list
// see reference_X in PartialMedium.
/* this might not be really needed for now.
case ((SCode.CLASS(name = name, restriction = SCode.R_FUNCTION(_), classDef = SCode.PARTS(elementLst = els)),
daeMod), (inAllElements, _))
equation
exps = getExpsFromDefaults(els, {});
(bexps, sexps) = getExpsFromMod(Mod.unelabMod(daeMod));
exps = listAppend(bexps, listAppend(sexps, exps));
deps = getDepsFromExps(exps, inAllElements, {});
then
deps;*/

else then {};
end matchcontinue;
end getElementDependencies;

protected function getExpsFromDefaults
input SCode.Program inEls;
input list<Absyn.Exp> inAcc;
output list<Absyn.Exp> outExps;
algorithm
outExps := matchcontinue(inEls, inAcc)
local
SCode.Program rest;
list<Absyn.Exp> exps, acc;
SCode.Mod m;

case ({}, _) then inAcc;

case (SCode.COMPONENT(attributes = SCode.ATTR(direction = Absyn.INPUT()), modifications = m)::rest, _)
equation
(exps, _) = getExpsFromMod(m);
exps = getExpsFromDefaults(rest, listAppend(exps, inAcc));
then
exps;

case (SCode.COMPONENT(attributes = SCode.ATTR(direction = Absyn.OUTPUT()), modifications = m)::rest, _)
equation
(exps, _) = getExpsFromMod(m);
exps = getExpsFromDefaults(rest, listAppend(exps, inAcc));
then
exps;

case (_::rest, _)
equation
exps = getExpsFromDefaults(rest, inAcc);
then
exps;
end matchcontinue;
end getExpsFromDefaults;

protected function getElementDependenciesTraverserEnter
"Traverse function used by getElementDependencies to collect all dependencies
for an element. The first ElementList in the input argument is a list of all
Expand All @@ -5640,6 +5691,19 @@ algorithm
(all_el, SOME(e)) = List.deleteMemberOnTrue(id, all_el, isElementNamed);
then
((exp, (all_el, e :: accum_el)));

/* adpro: add function calls crefs too!
this works fine but changes order in too many
models, i'll enable this and update them later
case ((exp as Absyn.CALL(function_ = cref), (all_el, accum_el)))
equation
id = Absyn.crefFirstIdent(cref);
// Try and delete the element with the given name from the list of all
// elements. If this succeeds, add it to the list of elements. This
// ensures that we don't add any dependency more than once.
(all_el, SOME(e)) = List.deleteMemberOnTrue(id, all_el, isElementNamed);
then
((exp, (all_el, e :: accum_el)));*/

else then inTuple;
end matchcontinue;
Expand Down Expand Up @@ -9624,7 +9688,7 @@ algorithm
(cache,tyVar,SCode.COMPONENT(n,_,_,Absyn.TPATH(t, _),_,comment,cond,info),_,_,idENV)
= Lookup.lookupIdent(cache, env, id);

ci_state = updateClassInfState(cache, idENV, env, inCIState);
ci_state = updateClassInfState(cache, idENV, env, inCIState);

//Debug.traceln("update comp " +& n +& " with mods:" +& Mod.printModStr(mods) +& " m:" +& SCodeDump.printModStr(m) +& " cm:" +& Mod.printModStr(cmod));
(cache,cl,cenv) = Lookup.lookupClass(cache, env, t, false);
Expand Down Expand Up @@ -16909,6 +16973,7 @@ algorithm
// This case catches when we want to update an already typed and bound var.
case (cache,env,ih,_,mods,(Absyn.CREF_IDENT(name = n, subscripts = {}) :: rest),_,_,updatedComps,_)
equation
// (_,DAE.TYPES_VAR(binding = binding),_,_,_,_) = Lookup.lookupIdent(cache, env, n);
(_,DAE.TYPES_VAR(binding = binding),_,_,_,_) = Lookup.lookupIdentLocal(cache, env, n);
true = DAEUtil.isBound(binding);
(cache,env_2,ih,updatedComps) = updateComponentsInEnv2(cache, env, ih,
Expand Down
87 changes: 63 additions & 24 deletions Compiler/FrontEnd/Lookup.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1769,11 +1769,11 @@ algorithm
end match;
end createGenericBuiltinFunctions;

protected function lookupTypeInEnv "- Internal functions
Type lookup
function: lookupTypeInEnv
// - Internal functions
// Type lookup

"
protected function lookupTypeInEnv
"function: lookupTypeInEnv"
input Env.Cache inCache;
input Env.Env inEnv;
input Absyn.Path inPath;
Expand All @@ -1793,11 +1793,13 @@ algorithm
Env.Frame f;
Env.Cache cache;
Absyn.Path path;

case (cache,(env as (Env.FRAME(name = sid,clsAndVars = ht,types = httypes) :: fs)),Absyn.IDENT(name = id))
equation
(cache,c,env_1) = lookupTypeInFrame(cache,ht, httypes, env, id);
(cache,c,env_1) = lookupTypeInFrame(cache, ht, httypes, env, id);
then
(cache,c,env_1);

case (cache,f::fs,path)
equation
(cache,c,env_1) = lookupTypeInEnv(cache,fs,path);
Expand All @@ -1806,10 +1808,9 @@ algorithm
end matchcontinue;
end lookupTypeInEnv;

protected function lookupTypeInFrame "function: lookupTypeInFrame

Searches a frame for a type.
"
protected function lookupTypeInFrame
"function: lookupTypeInFrame
Searches a frame for a type."
input Env.Cache inCache;
input Env.AvlTree inBinTree1;
input Env.AvlTree inBinTree2;
Expand Down Expand Up @@ -1838,10 +1839,9 @@ algorithm
end match;
end lookupTypeInFrame;

protected function lookupTypeInFrame2 "function: lookupTypeInFrame

Searches a frame for a type.
"
protected function lookupTypeInFrame2
"function: lookupTypeInFrame
Searches a frame for a type."
input Env.Cache inCache;
input Env.Item item;
input Env.Env inEnv3;
Expand Down Expand Up @@ -1884,9 +1884,14 @@ algorithm
case (cache,Env.CLASS((cdef as SCode.CLASS(restriction=SCode.R_FUNCTION(_))),cenv,_),env,id)
equation
// Debug.fprintln(Flags.INST_TRACE, "LOOKUP TYPE IN FRAME ICD: " +& Env.printEnvPathStr(env) +& " id:" +& id);

// select the env if is the same as cenv as is updated!
cenv = selectUpdatedEnv(env, cenv);

(cache ,env_1,_) = Inst.implicitFunctionInstantiation(
cache,cenv,InnerOuter.emptyInstHierarchy,
DAE.NOMOD(), Prefix.NOPRE(), cdef, {});

(cache,ty,env_3) = lookupTypeInEnv(cache, env_1, Absyn.IDENT(id));
then
(cache,ty,env_3);
Expand Down Expand Up @@ -1955,6 +1960,10 @@ algorithm
equation
Env.CLASS((cdef as SCode.CLASS(restriction=restr)),cenv,_) = Env.avlTreeGet(ht, id);
true = SCode.isFunctionRestriction(restr) "If found class that is function.";

// select the env if is the same as cenv as is updated!
cenv = selectUpdatedEnv(env, cenv);

//function dae collected from instantiation
// Debug.fprintln(Flags.INST_TRACE, "LOOKUP FUNCTIONS IN FRAME ICD: " +& Env.printEnvPathStr(env) +& "." +& id);
(cache,env_1,_) =
Expand All @@ -1964,25 +1973,55 @@ algorithm
then
(cache,tps);

// Found class that is is external object
case (cache,ht,httypes,env,id,_)
equation
Env.CLASS(cdef,cenv,_) = Env.avlTreeGet(ht, id);
true = Inst.classIsExternalObject(cdef);
// Debug.fprintln(Flags.INST_TRACE, "LOOKUP FUNCTIONS IN FRAME ICD: " +& Env.printEnvPathStr(env) +& "." +& id);
(cache,env_1,_,_,_,_,t,_,_,_) =
// Found class that is is external object
case (cache,ht,httypes,env,id,_)
equation
Env.CLASS(cdef,cenv,_) = Env.avlTreeGet(ht, id);
true = Inst.classIsExternalObject(cdef);

// select the env if is the same as cenv as is updated!
cenv = selectUpdatedEnv(env, cenv);

// Debug.fprintln(Flags.INST_TRACE, "LOOKUP FUNCTIONS IN FRAME ICD: " +& Env.printEnvPathStr(env) +& "." +& id);
(cache,env_1,_,_,_,_,t,_,_,_) =
Inst.instClass(cache,cenv,InnerOuter.emptyInstHierarchy,UnitAbsyn.noStore,
DAE.NOMOD(), Prefix.NOPRE(), cdef, {}, false, Inst.TOP_CALL(),
ConnectionGraph.EMPTY, Connect.emptySet);
(cache,t,_) = lookupTypeInEnv(cache,env_1, Absyn.IDENT(id));
// s = Types.unparseType(t);
// print("type :");print(s);print("\n");
then
(cache,t,_) = lookupTypeInEnv(cache,env_1, Absyn.IDENT(id));
// s = Types.unparseType(t);
// print("type :");print(s);print("\n");
then
(cache,{t});

end matchcontinue;
end lookupFunctionsInFrame;

protected function selectUpdatedEnv
input Env.Env inNewEnv;
input Env.Env inOldEnv;
output Env.Env outEnv;
algorithm
outEnv := matchcontinue(inNewEnv, inOldEnv)
local Env.Env env;

// return old if is top scope!
case (_, _)
equation
true = Env.isTopScope(inNewEnv);
then
inOldEnv;
// if they point to the same env, return the new one
case (_, _)
equation
true = stringEq(Env.getEnvNameStr(inNewEnv),
Env.getEnvNameStr(inOldEnv));
then
inNewEnv;

else then inOldEnv;
end matchcontinue;
end selectUpdatedEnv;

protected function buildRecordType ""
input Env.Cache cache;
input Env.Env env;
Expand Down

0 comments on commit a8660ae

Please sign in to comment.