Skip to content

Commit daeed2f

Browse files
committed
- some support for ExternalMedia (some more work is needed for full support)
- 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
1 parent 2f33393 commit daeed2f

File tree

2 files changed

+77
-35
lines changed

2 files changed

+77
-35
lines changed

Compiler/FrontEnd/Inst.mo

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,9 +2130,13 @@ algorithm
21302130

21312131
(env1,ih) = InstUtil.addClassdefsToEnv(env, ih, pre, cdefelts, impl, SOME(mods)) "1. CLASS & IMPORT nodes and COMPONENT nodes(add to env)" ;
21322132
cdefelts_1 = InstUtil.addNomod(cdefelts) "instantiate CDEFS so redeclares are carried out" ;
2133-
(cache,env2,ih,cdefelts_2) = updateCompeltsMods(cache,env1,ih, pre, cdefelts_1, ci_state, impl);
2134-
//env2 = env1;
2135-
//cdefelts_2 = cdefelts_1;
2133+
/*
2134+
(cache,env2,ih,cdefelts_2) =
2135+
updateCompeltsMods(cache, env1, ih, pre,
2136+
InstUtil.sortElementList(cdefelts_1, env1, Env.inFunctionScope(env1)),
2137+
ci_state, impl);*/
2138+
env2 = env1;
2139+
cdefelts_2 = cdefelts_1;
21362140

21372141
//(cache, cdefelts_2) = removeConditionalComponents(cache, env2, cdefelts_2, pre);
21382142
(cache,env3,ih,store,dae1,csets,ci_state1,tys,graph) =
@@ -2416,9 +2420,13 @@ algorithm
24162420
(cache,env3,ih) = InstUtil.addComponentsToEnv(cache, env2, ih, mods, pre, ci_state, compelts_1, compelts_1, eqs_1, inst_dims, impl);
24172421
//Update the modifiers of elements to typed ones, needed for modifiers
24182422
//on components that are inherited.
2419-
(cache,env4,ih,compelts_2) = updateCompeltsMods(cache, env3, ih, pre, compelts_1, ci_state, impl);
2420-
//compelts_2 = extcomps;
2421-
//env4 = env3;
2423+
/*
2424+
(cache,env4,ih,compelts_2) =
2425+
updateCompeltsMods(cache, env3, ih, pre,
2426+
InstUtil.sortElementList(compelts_1, env3, Env.inFunctionScope(env3)),
2427+
ci_state, impl);*/
2428+
compelts_2 = compelts_1;
2429+
env4 = env3;
24222430

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

3194-
(cache,env3,ih,lst_constantEls) = updateCompeltsMods(cache, env3, ih, pre, lst_constantEls, ci_state, true);
3202+
/*(cache,env3,ih,lst_constantEls) =
3203+
updateCompeltsMods(cache, env3, ih, pre,
3204+
InstUtil.sortElementList(lst_constantEls, env3, Env.inFunctionScope(env3)),
3205+
ci_state, true);*/
31953206

31963207
(cache,env3,ih,_,_,_,ci_state2,vars,_) =
31973208
instElementList(cache, env3, ih, UnitAbsyn.noStore, mods, pre, ci_state1, lst_constantEls,
@@ -3550,6 +3561,7 @@ algorithm
35503561
String comp_name;
35513562
UnitAbsyn.InstStore store;
35523563
list<DAE.Element> elts;
3564+
DAE.Mod daeMod;
35533565

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

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

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

4098+
// Instantiate the element if there is no mod
4099+
case (cache,env,ih,pre,((elMod as (comp,DAE.NOMOD())) :: xs),ci_state,impl)
4100+
equation
4101+
/*
4102+
name = SCode.elementName(comp);
4103+
cref = Absyn.CREF_IDENT(name,{});
4104+
(cache,env,ih) = updateComponentsInEnv(cache, env, ih, pre, DAE.NOMOD(), {cref}, ci_state, impl);
4105+
*/
4106+
(cache,env,ih,res) = updateCompeltsMods_dispatch(cache, env, ih, pre, xs, ci_state, impl);
4107+
then
4108+
(cache,env,ih,elMod::res);
4109+
40854110
// Special case for components being redeclared, we might instantiate partial classes when instantiating var(-> instVar2->instClass) to update component in env.
40864111
case (cache,env,ih,pre,((comp,(cmod as DAE.REDECL(_,_,{(redComp,redMod)}))) :: xs),ci_state,impl)
40874112
equation
@@ -4107,13 +4132,6 @@ algorithm
41074132
then
41084133
(cache,env3,ih,((comp,cmod_1) :: res));
41094134

4110-
// No need to update a mod unless there's actually anything there.
4111-
case (cache,env,ih,pre,((elMod as (_,DAE.NOMOD())) :: xs),ci_state,impl)
4112-
equation
4113-
(cache,env,ih,res) = updateCompeltsMods_dispatch(cache, env, ih, pre, xs, ci_state, impl);
4114-
then
4115-
(cache,env,ih,elMod::res);
4116-
41174135
// If the modifier has already been updated, just update the environment with it.
41184136
case (cache,env,ih,pre,((comp, cmod as DAE.MOD(subModLst = _)) :: xs),ci_state,impl)
41194137
equation

Compiler/FrontEnd/InstUtil.mo

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,8 @@ algorithm
19811981
Absyn.Direction direction;
19821982
list<tuple<SCode.Element, DAE.Mod>> inAllElements;
19831983
SCode.Replaceable rp;
1984+
list<SCode.Element> els;
1985+
Option<SCode.ExternalDecl> externalDecl;
19841986

19851987
// For constants and parameters we check the component conditional, array dimensions, modifiers and binding
19861988
case ((SCode.COMPONENT(name = name, condition = cExpOpt,
@@ -2052,26 +2054,50 @@ algorithm
20522054
(_, sexps) = getExpsFromMod(Mod.unelabMod(daeMod));
20532055
exps = listAppend(sexps, exps);
20542056
deps = getDepsFromExps(exps, inAllElements, {});
2057+
deps = removeCurrentElementFromArrayDimDeps(name, deps);
20552058
then
20562059
deps;
20572060

20582061
// We might have functions here and their input/output elements can have bindings from the list
2059-
// see reference_X in PartialMedium.
2060-
/* this might not be really needed for now.
2061-
case ((SCode.CLASS(name = name, restriction = SCode.R_FUNCTION(_), classDef = SCode.PARTS(elementLst = els)),
2062+
// see reference_X in PartialMedium
2063+
// see ExternalMedia.Media.ExternalTwoPhaseMedium.FluidConstants
2064+
// which depends on function calls which depend on package constants inside external decl
2065+
case ((SCode.CLASS(name = name,
2066+
prefixes = SCode.PREFIXES(replaceablePrefix = rp),
2067+
classDef = SCode.PARTS(elementLst = els, externalDecl = externalDecl)),
20622068
daeMod), (inAllElements, _))
20632069
equation
2064-
exps = getExpsFromDefaults(els, {});
2070+
exps = getExpsFromExternalDecl(externalDecl);
2071+
/*
2072+
exps = getExpsFromDefaults(els, exps);
2073+
(bexps, sexps) = getExpsFromConstrainClass(rp);
2074+
exps = listAppend(bexps, listAppend(sexps, exps));
20652075
(bexps, sexps) = getExpsFromMod(Mod.unelabMod(daeMod));
20662076
exps = listAppend(bexps, listAppend(sexps, exps));
2077+
*/
20672078
deps = getDepsFromExps(exps, inAllElements, {});
2079+
deps = removeCurrentElementFromArrayDimDeps(name, deps);
20682080
then
2069-
deps;*/
2081+
deps;
20702082

20712083
else then {};
20722084
end matchcontinue;
20732085
end getElementDependencies;
20742086

2087+
protected function getExpsFromExternalDecl
2088+
"get dependencies from external declarations"
2089+
input Option<SCode.ExternalDecl> inExternalDecl;
2090+
output list<Absyn.Exp> outExps;
2091+
algorithm
2092+
outExps := match(inExternalDecl)
2093+
local list<Absyn.Exp> exps;
2094+
case (NONE()) then {};
2095+
case (SOME(SCode.EXTERNALDECL(args = exps)))
2096+
then
2097+
exps;
2098+
end match;
2099+
end getExpsFromExternalDecl;
2100+
20752101
protected function getExpsFromDefaults
20762102
input SCode.Program inEls;
20772103
input list<Absyn.Exp> inAcc;
@@ -2080,22 +2106,22 @@ algorithm
20802106
outExps := matchcontinue(inEls, inAcc)
20812107
local
20822108
SCode.Program rest;
2083-
list<Absyn.Exp> exps, acc;
2109+
list<Absyn.Exp> exps, sexps, bexps, acc;
20842110
SCode.Mod m;
2111+
SCode.Replaceable rp;
20852112

20862113
case ({}, _) then inAcc;
20872114

2088-
case (SCode.COMPONENT(attributes = SCode.ATTR(direction = Absyn.INPUT()), modifications = m)::rest, _)
2089-
equation
2090-
(exps, _) = getExpsFromMod(m);
2091-
exps = getExpsFromDefaults(rest, listAppend(exps, inAcc));
2092-
then
2093-
exps;
2094-
2095-
case (SCode.COMPONENT(attributes = SCode.ATTR(direction = Absyn.OUTPUT()), modifications = m)::rest, _)
2115+
case (SCode.COMPONENT(
2116+
prefixes = SCode.PREFIXES(replaceablePrefix = rp),
2117+
modifications = m)::rest, _)
20962118
equation
2097-
(exps, _) = getExpsFromMod(m);
2098-
exps = getExpsFromDefaults(rest, listAppend(exps, inAcc));
2119+
exps = inAcc;
2120+
(bexps, sexps) = getExpsFromConstrainClass(rp);
2121+
exps = listAppend(bexps, listAppend(sexps, exps));
2122+
(bexps, sexps) = getExpsFromMod(m);
2123+
exps = listAppend(bexps, listAppend(sexps, exps));
2124+
exps = getExpsFromDefaults(rest, exps);
20992125
then
21002126
exps;
21012127

@@ -2133,9 +2159,7 @@ algorithm
21332159
then
21342160
((exp, (all_el, e :: accum_el)));
21352161

2136-
/* adpro: add function calls crefs too!
2137-
this works fine but changes order in too many
2138-
models, i'll enable this and update them later
2162+
// adpro: add function calls crefs too!
21392163
case ((exp as Absyn.CALL(function_ = cref), (all_el, accum_el)))
21402164
equation
21412165
id = Absyn.crefFirstIdent(cref);
@@ -2144,7 +2168,7 @@ algorithm
21442168
// ensures that we don't add any dependency more than once.
21452169
(all_el, SOME(e)) = List.deleteMemberOnTrue(id, all_el, isElementNamed);
21462170
then
2147-
((exp, (all_el, e :: accum_el)));*/
2171+
((exp, (all_el, e :: accum_el)));
21482172

21492173
else then inTuple;
21502174
end matchcontinue;

0 commit comments

Comments
 (0)