Skip to content

Commit

Permalink
- some support for ExternalMedia (some more work is needed for full s…
Browse files Browse the repository at this point in the history
…upport)

- add function calls and external function inputs to dependency analysis in element sorting
- use Inst.updateCompeltsMods just in Inst.instElementList2


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17614 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 8, 2013
1 parent 2f33393 commit daeed2f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 35 deletions.
48 changes: 33 additions & 15 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2130,9 +2130,13 @@ algorithm

(env1,ih) = InstUtil.addClassdefsToEnv(env, ih, pre, cdefelts, impl, SOME(mods)) "1. CLASS & IMPORT nodes and COMPONENT nodes(add to env)" ;
cdefelts_1 = InstUtil.addNomod(cdefelts) "instantiate CDEFS so redeclares are carried out" ;
(cache,env2,ih,cdefelts_2) = updateCompeltsMods(cache,env1,ih, pre, cdefelts_1, ci_state, impl);
//env2 = env1;
//cdefelts_2 = cdefelts_1;
/*
(cache,env2,ih,cdefelts_2) =
updateCompeltsMods(cache, env1, ih, pre,
InstUtil.sortElementList(cdefelts_1, env1, Env.inFunctionScope(env1)),
ci_state, impl);*/
env2 = env1;
cdefelts_2 = cdefelts_1;

//(cache, cdefelts_2) = removeConditionalComponents(cache, env2, cdefelts_2, pre);
(cache,env3,ih,store,dae1,csets,ci_state1,tys,graph) =
Expand Down Expand Up @@ -2416,9 +2420,13 @@ algorithm
(cache,env3,ih) = InstUtil.addComponentsToEnv(cache, env2, ih, mods, pre, ci_state, compelts_1, compelts_1, eqs_1, inst_dims, impl);
//Update the modifiers of elements to typed ones, needed for modifiers
//on components that are inherited.
(cache,env4,ih,compelts_2) = updateCompeltsMods(cache, env3, ih, pre, compelts_1, ci_state, impl);
//compelts_2 = extcomps;
//env4 = env3;
/*
(cache,env4,ih,compelts_2) =
updateCompeltsMods(cache, env3, ih, pre,
InstUtil.sortElementList(compelts_1, env3, Env.inFunctionScope(env3)),
ci_state, impl);*/
compelts_2 = compelts_1;
env4 = env3;

//compelts_1 = InstUtil.addNomod(compelts);
//cdefelts_1 = InstUtil.addNomod(cdefelts);
Expand Down Expand Up @@ -3191,7 +3199,10 @@ algorithm
lst_constantEls, lst_constantEls, {},
inst_dims, false); // adrpo: here SHOULD BE IMPL=TRUE! not FALSE!

(cache,env3,ih,lst_constantEls) = updateCompeltsMods(cache, env3, ih, pre, lst_constantEls, ci_state, true);
/*(cache,env3,ih,lst_constantEls) =
updateCompeltsMods(cache, env3, ih, pre,
InstUtil.sortElementList(lst_constantEls, env3, Env.inFunctionScope(env3)),
ci_state, true);*/

(cache,env3,ih,_,_,_,ci_state2,vars,_) =
instElementList(cache, env3, ih, UnitAbsyn.noStore, mods, pre, ci_state1, lst_constantEls,
Expand Down Expand Up @@ -3550,6 +3561,7 @@ algorithm
String comp_name;
UnitAbsyn.InstStore store;
list<DAE.Element> elts;
DAE.Mod daeMod;

// Don't instantiate conditional components with condition = false.
case (cache, env, ih, store, mod, pre, ci_state,
Expand All @@ -3569,10 +3581,11 @@ algorithm
then
(cache, env, ih, store, {}, csets, ci_state, {}, graph);

/* most work done in inst_element. */
// most work done in inst_element.
case (cache,env,ih,store,mod,pre,ci_state,el,inst_dims,impl,callscope,graph, csets, _)
equation
ErrorExt.setCheckpoint("instElementList2");
(cache,env,ih,{el}) = updateCompeltsMods(cache, env, ih, pre, {el}, ci_state, impl);
// Debug.fprintln(Flags.INST_TRACE, "INST ELEMENT: " +& Env.printEnvPathStr(env) +& " el: " +& SCodeDump.shortElementStr(Util.tuple21(el)) +& " mods: " +& Mod.printModStr(mod));
// check for duplicate modifications
ele = Util.tuple21(el);
Expand Down Expand Up @@ -4082,6 +4095,18 @@ algorithm

case (cache,env,ih,pre,{},_,_) then (cache,env,ih,{});

// Instantiate the element if there is no mod
case (cache,env,ih,pre,((elMod as (comp,DAE.NOMOD())) :: xs),ci_state,impl)
equation
/*
name = SCode.elementName(comp);
cref = Absyn.CREF_IDENT(name,{});
(cache,env,ih) = updateComponentsInEnv(cache, env, ih, pre, DAE.NOMOD(), {cref}, ci_state, impl);
*/
(cache,env,ih,res) = updateCompeltsMods_dispatch(cache, env, ih, pre, xs, ci_state, impl);
then
(cache,env,ih,elMod::res);

// Special case for components being redeclared, we might instantiate partial classes when instantiating var(-> instVar2->instClass) to update component in env.
case (cache,env,ih,pre,((comp,(cmod as DAE.REDECL(_,_,{(redComp,redMod)}))) :: xs),ci_state,impl)
equation
Expand All @@ -4107,13 +4132,6 @@ algorithm
then
(cache,env3,ih,((comp,cmod_1) :: res));

// No need to update a mod unless there's actually anything there.
case (cache,env,ih,pre,((elMod as (_,DAE.NOMOD())) :: xs),ci_state,impl)
equation
(cache,env,ih,res) = updateCompeltsMods_dispatch(cache, env, ih, pre, xs, ci_state, impl);
then
(cache,env,ih,elMod::res);

// If the modifier has already been updated, just update the environment with it.
case (cache,env,ih,pre,((comp, cmod as DAE.MOD(subModLst = _)) :: xs),ci_state,impl)
equation
Expand Down
64 changes: 44 additions & 20 deletions Compiler/FrontEnd/InstUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,8 @@ algorithm
Absyn.Direction direction;
list<tuple<SCode.Element, DAE.Mod>> inAllElements;
SCode.Replaceable rp;
list<SCode.Element> els;
Option<SCode.ExternalDecl> externalDecl;

// For constants and parameters we check the component conditional, array dimensions, modifiers and binding
case ((SCode.COMPONENT(name = name, condition = cExpOpt,
Expand Down Expand Up @@ -2052,26 +2054,50 @@ algorithm
(_, sexps) = getExpsFromMod(Mod.unelabMod(daeMod));
exps = listAppend(sexps, exps);
deps = getDepsFromExps(exps, inAllElements, {});
deps = removeCurrentElementFromArrayDimDeps(name, deps);
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)),
// see reference_X in PartialMedium
// see ExternalMedia.Media.ExternalTwoPhaseMedium.FluidConstants
// which depends on function calls which depend on package constants inside external decl
case ((SCode.CLASS(name = name,
prefixes = SCode.PREFIXES(replaceablePrefix = rp),
classDef = SCode.PARTS(elementLst = els, externalDecl = externalDecl)),
daeMod), (inAllElements, _))
equation
exps = getExpsFromDefaults(els, {});
exps = getExpsFromExternalDecl(externalDecl);
/*
exps = getExpsFromDefaults(els, exps);
(bexps, sexps) = getExpsFromConstrainClass(rp);
exps = listAppend(bexps, listAppend(sexps, exps));
(bexps, sexps) = getExpsFromMod(Mod.unelabMod(daeMod));
exps = listAppend(bexps, listAppend(sexps, exps));
*/
deps = getDepsFromExps(exps, inAllElements, {});
deps = removeCurrentElementFromArrayDimDeps(name, deps);
then
deps;*/
deps;

else then {};
end matchcontinue;
end getElementDependencies;

protected function getExpsFromExternalDecl
"get dependencies from external declarations"
input Option<SCode.ExternalDecl> inExternalDecl;
output list<Absyn.Exp> outExps;
algorithm
outExps := match(inExternalDecl)
local list<Absyn.Exp> exps;
case (NONE()) then {};
case (SOME(SCode.EXTERNALDECL(args = exps)))
then
exps;
end match;
end getExpsFromExternalDecl;

protected function getExpsFromDefaults
input SCode.Program inEls;
input list<Absyn.Exp> inAcc;
Expand All @@ -2080,22 +2106,22 @@ algorithm
outExps := matchcontinue(inEls, inAcc)
local
SCode.Program rest;
list<Absyn.Exp> exps, acc;
list<Absyn.Exp> exps, sexps, bexps, acc;
SCode.Mod m;
SCode.Replaceable rp;

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, _)
case (SCode.COMPONENT(
prefixes = SCode.PREFIXES(replaceablePrefix = rp),
modifications = m)::rest, _)
equation
(exps, _) = getExpsFromMod(m);
exps = getExpsFromDefaults(rest, listAppend(exps, inAcc));
exps = inAcc;
(bexps, sexps) = getExpsFromConstrainClass(rp);
exps = listAppend(bexps, listAppend(sexps, exps));
(bexps, sexps) = getExpsFromMod(m);
exps = listAppend(bexps, listAppend(sexps, exps));
exps = getExpsFromDefaults(rest, exps);
then
exps;

Expand Down Expand Up @@ -2133,9 +2159,7 @@ algorithm
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
// adpro: add function calls crefs too!
case ((exp as Absyn.CALL(function_ = cref), (all_el, accum_el)))
equation
id = Absyn.crefFirstIdent(cref);
Expand All @@ -2144,7 +2168,7 @@ algorithm
// 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)));*/
((exp, (all_el, e :: accum_el)));

else then inTuple;
end matchcontinue;
Expand Down

0 comments on commit daeed2f

Please sign in to comment.