Skip to content

Commit

Permalink
- playing with modifiers to fix: Modelica.Electrical.Digital.Examples…
Browse files Browse the repository at this point in the history
….DFFREGL and others.

- do not apply redeclares in operators
- make the error about modification or redeclaration of protected elements a warning
  plenty of models in MSL that have these!
- display the dimensionality in the connect mismatch.
- some models will fail, I'll deal with them next.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14523 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Dec 23, 2012
1 parent cda1a87 commit 3e011e8
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 151 deletions.
93 changes: 41 additions & 52 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ encapsulated package Inst
This module uses Lookup to lookup classes and variables from the
environment defined in Env. It uses Connect for generating equations from
connect statements. The type system defined in Types is used for
variable instantiation and type . DAE.Mod is used for modifiers and
variable instantiation and type. DAE.Mod is used for modifiers and
merging of modifiers.

The extends language feature is performed by InstExtends. Instantiation of
Expand Down Expand Up @@ -3522,7 +3522,9 @@ algorithm

//Add variables to env, wihtout type and binding, which will be added
//later in instElementList (where update_variable is called)"
(cache,env3,ih) = addComponentsToEnv(cache, env2, ih, emods, pre, ci_state, compelts_1, compelts_1, eqs_1, inst_dims, impl);
checkMods = Mod.merge(mods,emods,env2,pre);
mods = checkMods;
(cache,env3,ih) = 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, extcomps, ci_state, impl);
Expand All @@ -3544,9 +3546,6 @@ algorithm
// Debug.fprintln(Flags.INNER_OUTER, "Number of components: " +& intString(listLength(compelts_2_elem)));
// Debug.fprintln(Flags.INNER_OUTER, stringDelimitList(List.map(compelts_2_elem, SCodeDump.printElementStr), "\n"));

checkMods = Mod.merge(mods,emods,env4,pre);
mods = checkMods;

//print("To match modifiers,\n" +& Mod.printModStr(checkMods) +& "\n on components: ");
//print(" (" +& stringDelimitList(List.map(compelts_2_elem,SCode.elementName),", ") +& ") \n");
matchModificationToComponents(compelts_2_elem,checkMods,Env.printEnvPathStr(env4));
Expand Down Expand Up @@ -3738,7 +3737,6 @@ algorithm
// elab the modifiers in the parent environment!!
parentEnv = List.stripFirst(env);
(cache, mod_1) = Mod.elabMod(cache, parentEnv, ih, pre, mod, false, info);
// mods_1 = Mod.merge(mods, buildDerivedModifier(mod_1, cn2), parentEnv, pre);
// print("mods: " +& Absyn.pathString(cn) +& " " +& Mod.printModStr(mods_1) +& "\n");
mods_1 = Mod.merge(mods, mod_1, parentEnv, pre);

Expand Down Expand Up @@ -4879,18 +4877,6 @@ algorithm
end matchcontinue;
end filterConnectionSetCrefs;

protected function buildDerivedModifier
input DAE.Mod inMod;
input String className;
output DAE.Mod outMod;
algorithm
outMod := match(inMod, className)
case (DAE.NOMOD(), _) then DAE.NOMOD();
case (DAE.MOD(_,_,{},NONE()), _) then DAE.NOMOD();
case (inMod, className) then DAE.MOD(SCode.NOT_FINAL(), SCode.NOT_EACH(), {DAE.NAMEMOD(className, inMod)}, NONE());
end match;
end buildDerivedModifier;

protected function partialInstClassdef
"function: partialInstClassdef
This function is used by partialInstClassIn for instantiating local
Expand Down Expand Up @@ -5044,7 +5030,6 @@ algorithm
// elab the modifiers in the parent environment!!
parentEnv = List.stripFirst(env);
(cache, mod_1) = Mod.elabMod(cache, parentEnv, ih, pre, mod, false, info);
// mods_1 = Mod.merge(mods, buildDerivedModifier(mod_1, cn2), parentEnv, pre);
// print("mods: " +& Absyn.pathString(cn) +& " " +& Mod.printModStr(mods_1) +& "\n");
mods_1 = Mod.merge(mods, mod_1, parentEnv, pre);

Expand Down Expand Up @@ -5319,6 +5304,7 @@ algorithm
InstanceHierarchy ih;
String name;
Absyn.Info info;
SCode.Final fprefix;

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

Expand All @@ -5334,13 +5320,14 @@ algorithm
cref = Absyn.CREF_IDENT(name,{});
ltmod = List.map1(crefs,getModsForDep,xs);
cmod2 = List.fold2r(cmod::ltmod,Mod.merge,env,pre,DAE.NOMOD());
SCode.PREFIXES(finalPrefix = fprefix) = SCode.elementPrefixes(comp);

//print("("+&intString(listLength(ltmod))+&")UpdateCompeltsMods_(" +& stringDelimitList(List.map(crefs,Absyn.printComponentRefStr),",") +& ") subs: " +& stringDelimitList(List.map(crefs,Absyn.printComponentRefStr),",")+& "\n");
//print("REDECL acquired mods: " +& Mod.printModStr(cmod2) +& "\n");
(cache,env2,ih) = updateComponentsInEnv(cache, env, ih, pre, cmod2, crefs, ci_state, impl);
ErrorExt.setCheckpoint("updateCompeltsMods");
(cache,env2,ih) = updateComponentsInEnv(cache, env2, ih, pre,
DAE.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{DAE.NAMEMOD(name, cmod)},NONE()),
DAE.MOD(fprefix,SCode.NOT_EACH(),{DAE.NAMEMOD(name, cmod)},NONE()),
{cref}, ci_state, impl);
ErrorExt.rollBack("updateCompeltsMods") "roll back any errors";
(cache,cmod_1) = Mod.updateMod(cache, env2, ih, pre, cmod, impl, info);
Expand All @@ -5361,8 +5348,11 @@ algorithm
false = Mod.isUntypedMod(cmod);
name = SCode.elementName(comp);
cref = Absyn.CREF_IDENT(name,{});
SCode.PREFIXES(finalPrefix = fprefix) = SCode.elementPrefixes(comp);

(cache,env2,ih) = updateComponentsInEnv(cache, env, ih, pre, DAE.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{DAE.NAMEMOD(name, cmod)},NONE()), {cref}, ci_state, impl);
(cache,env2,ih) = updateComponentsInEnv(cache, env, ih, pre,
DAE.MOD(fprefix,SCode.NOT_EACH(),{DAE.NAMEMOD(name, cmod)},NONE()),
{cref}, ci_state, impl);
(cache,env3,ih,res) = updateCompeltsMods(cache, env2, ih, pre, xs, ci_state, impl);
then
(cache,env3,ih,((comp,cmod) :: res));
Expand All @@ -5379,12 +5369,15 @@ algorithm

ltmod = List.map1(crefs,getModsForDep,xs);
cmod2 = List.fold2r(ltmod,Mod.merge,env,pre,DAE.NOMOD());
SCode.PREFIXES(finalPrefix = fprefix) = SCode.elementPrefixes(comp);

//print("("+&intString(listLength(ltmod))+&")UpdateCompeltsMods_(" +& stringDelimitList(List.map(crefs,Absyn.printComponentRefStr),",") +& ") subs: " +& stringDelimitList(List.map(crefs,Absyn.printComponentRefStr),",")+& "\n");
//print(" acquired mods: " +& Mod.printModStr(cmod2) +& "\n");

(cache,env2,ih) = updateComponentsInEnv(cache, env, ih, pre, cmod2, crefs, ci_state, impl);
(cache,env2,ih) = updateComponentsInEnv(cache, env2, ih, pre, DAE.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{DAE.NAMEMOD(name, cmod)},NONE()), {cref}, ci_state, impl);
(cache,env2,ih) = updateComponentsInEnv(cache, env2, ih, pre,
DAE.MOD(fprefix,SCode.NOT_EACH(),{DAE.NAMEMOD(name, cmod)},NONE()),
{cref}, ci_state, impl);

(cache,cmod_1) = Mod.updateMod(cache, env2, ih, pre, cmod, impl, info);
(cache,env3,ih,res) = updateCompeltsMods(cache, env2, ih, pre, xs, ci_state, impl);
Expand Down Expand Up @@ -6703,6 +6696,7 @@ algorithm
Option<Absyn.Exp> condition;
InstanceHierarchy ih;
Env.Cache cache;
list<SCode.Ident> named;

// a component
case (cache,env,ih,mods,pre,ci_state,
Expand All @@ -6711,18 +6705,8 @@ algorithm
t,m,comment,condition,info),cmod) :: xs),
inst_dims,impl)
equation
compmod = Mod.lookupCompModification(mods, n)
"PA: PROBLEM, Modifiers should be merged in this phase, but
since undeclared components can not be found (is done in this phase)
the modifiers can not be elaborated to get a variable binding.
Thus, we need to store the merged modifier for elaboration in
the next stage.

Solution: Save all modifiers in environment...
Use type T_UNKNOWN instead of as earier trying to instantiate,
since instanitation might fail without having correct
modifications, e.g. when instanitating a partial class that must
be redeclared through a modification" ;
// compmod = Mod.getModifs(mods, n, m);
compmod = Mod.lookupCompModification(mods, n);
cmod_1 = Mod.merge(compmod, cmod, env, pre);

/*
Expand All @@ -6744,8 +6728,10 @@ algorithm
(cache,env_2,ih) = addComponentsToEnv2(cache, env_1, ih, mods, pre, ci_state, xs, inst_dims, impl);
then
(cache,env_2,ih);

// no components in list
case (cache,env,ih,_,_,_,{},_,_) then (cache,env,ih);

// failtrace
case (cache,env,ih,_,_,_,comps,_,_)
equation
Expand Down Expand Up @@ -7117,12 +7103,12 @@ algorithm

// If the element is protected, and an external modification
// is applied, it is an error.
checkProt(vis, mm, vn);
checkProt(vis, mm, vn, info);

//Instantiate the component
// Start a new "set" of inst_dims for this component (in instance hierarchy), see InstDims
inst_dims = listAppend(inst_dims,{{}});
(cache,mod_1) = Mod.updateMod(cache, cenv, ih, pre, mod_1, impl, info);
(cache,mod_1) = Mod.updateMod(cache, env2 /* cenv */, ih, pre, mod_1, impl, info);

// print("Before selectModifiers:\n\tmod: " +& Mod.printModStr(mod) +& "\n\t" +&"mod_1: " +& Mod.printModStr(mod_1) +& "\n\t" +&"comp: " +& SCodeDump.unparseElementStr(comp) +& "\n");

Expand Down Expand Up @@ -9849,14 +9835,6 @@ algorithm
//print("updateComponentInEnv: NEW ENV:\n" +& Env.printEnvStr(env) +& "\n");
then
(cache,env,ih,updatedComps);

// If first part of ident is a class, e.g StateSelect.None, nothing to update
case (cache,env,ih,_,mods,_,_,_,updatedComps,_)
equation
id = Absyn.crefFirstIdent(cref);
(cache,cl,cenv) = Lookup.lookupClass(cache,env, Absyn.IDENT(id), false);
then
(cache,env,ih,updatedComps);

// Variable with NONE() element is already instantiated.
case (cache,env,ih,_,mods,_,_,_,updatedComps,_)
Expand Down Expand Up @@ -9901,6 +9879,14 @@ algorithm
then
(cache,env_1,ih,updatedComps);

// If first part of ident is a class, e.g StateSelect.None, nothing to update
case (cache,env,ih,_,mods,_,_,_,updatedComps,_)
equation
id = Absyn.crefFirstIdent(cref);
(cache,cl,cenv) = Lookup.lookupClass(cache,env, Absyn.IDENT(id), false);
then
(cache,env,ih,updatedComps);

/*
case (cache,env,ih,pre,mods,cref,ci_state,impl,updatedComps)
equation
Expand Down Expand Up @@ -14846,19 +14832,22 @@ protected function checkProt
input SCode.Visibility inVisibility;
input DAE.Mod inMod;
input DAE.ComponentRef inComponentRef;
input Absyn.Info info;
algorithm
_ := matchcontinue (inVisibility,inMod,inComponentRef)
_ := matchcontinue (inVisibility,inMod,inComponentRef,info)
local
DAE.ComponentRef cref;
String str;
case (SCode.PUBLIC(),_,cref) then ();
case (_,DAE.NOMOD(),_) then ();
case (SCode.PROTECTED(),_,cref)
String str1, str2;
case (SCode.PUBLIC(),_,cref,_) then ();
case (_,DAE.NOMOD(),_,_) then ();
case (_,DAE.MOD(_, _, {}, NONE()),_,_) then ();
case (SCode.PROTECTED(),_,cref,_)
equation
str = ComponentReference.printComponentRefStr(cref);
Error.addMessage(Error.MODIFY_PROTECTED, {str});
str1 = ComponentReference.printComponentRefStr(cref);
str2 = Mod.prettyPrintMod(inMod, 0);
Error.addSourceMessage(Error.MODIFY_PROTECTED, {str1, str2}, info);
then
fail();
();
end matchcontinue;
end checkProt;

Expand Down
9 changes: 6 additions & 3 deletions Compiler/FrontEnd/InstExtends.mo
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ algorithm

//print("Found " +& cn +& "\n");
outermod = Mod.lookupModificationP(mod, Absyn.IDENT(cn));
// outermod = mod;

(cache,cenv1,ih,els,eq1,ieq1,alg1,ialg1) = instDerivedClasses(cache,cenv,ih,outermod,pre,c,impl,info);
els = updateElementListVisibility(els, vis);
Expand Down Expand Up @@ -642,15 +643,17 @@ algorithm
DAE.Mod cmod, cmod2, mod_rest;
String id;
Boolean b;
SCode.Mod m;

case ((comp as SCode.COMPONENT(name = id), cmod, b), _, _)
case ((comp as SCode.COMPONENT(name = id, modifications = m), cmod, b), _, _)
equation
// Debug.traceln(" comp: " +& id +& " " +& Mod.printModStr(mod));
// take ONLY the modification from the equation if is typed
// cmod2 = Mod.getModifs(inMod, id, m);
cmod2 = Mod.lookupCompModificationFromEqu(inMod, id);
// Debug.traceln("\tSpecific mods on comp: " +& Mod.printModStr(cmod2));
cmod = Mod.merge(cmod2, cmod, inEnv, Prefix.NOPRE());
mod_rest = Mod.removeMod(inMod, id);
mod_rest = inMod; //mod_rest = Mod.removeMod(inMod, id);
then
((comp, cmod, b), mod_rest);

Expand All @@ -663,7 +666,7 @@ algorithm
case ((comp as SCode.CLASS(name = id, prefixes = SCode.PREFIXES(replaceablePrefix = SCode.REPLACEABLE(_))), _, b), _, _)
equation
DAE.REDECL(_, _, (comp, cmod)::_) = Mod.lookupCompModification(inMod, id);
mod_rest = Mod.removeMod(inMod, id);
mod_rest = inMod; //mod_rest = Mod.removeMod(inMod, id);
comp = SCode.renameElement(comp, id);
then
((comp, cmod, b), mod_rest);
Expand Down
8 changes: 6 additions & 2 deletions Compiler/FrontEnd/InstSection.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3891,7 +3891,7 @@ algorithm
_ := matchcontinue(inLhsType, inRhsType, inLhsCref, inRhsCref, inInfo)
local
DAE.Type t1, t2;
String cs1, cs2, cref_str1, cref_str2;
String cs1, cs2, cref_str1, cref_str2, str1, str2;
list<Integer> dims1, dims2;

case (_, _, _, _, _)
Expand Down Expand Up @@ -3924,8 +3924,12 @@ algorithm
false = (listLength(dims1) + listLength(dims2)) == 0;
cref_str1 = ComponentReference.printComponentRefStr(inLhsCref);
cref_str2 = ComponentReference.printComponentRefStr(inRhsCref);
str1 = stringDelimitList(List.map(dims1, intString), ", ");
str1 = "[" +& str1 +& "]";
str2 = stringDelimitList(List.map(dims2, intString), ", ");
str2 = "[" +& str2 +& "]";
Error.addSourceMessage(Error.CONNECTOR_ARRAY_DIFFERENT,
{cref_str1, cref_str2}, inInfo);
{cref_str1, cref_str2, str1, str2}, inInfo);
then
fail();

Expand Down
5 changes: 3 additions & 2 deletions Compiler/FrontEnd/Lookup.mo
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ algorithm
outCache := inCache;
*/
// print("Lookup C1: " +& Absyn.pathString(inPath) +& " env: " +& Env.printEnvPathStr(inEnv) +& " msg: " +& boolString(msg) +& "\n");
(outCache,outClass,outEnv,_) := lookupClass1(inCache,inEnv, inPath, {}, Util.makeStatefulBoolean(false), msg);
(outCache,outClass,outEnv,_) := lookupClass1(inCache, inEnv, inPath, {}, Util.makeStatefulBoolean(false), msg);
// outEnv := selectUpdatedEnv(inEnv, outEnv);
// print("Lookup C2: " +& " outenv: " +& Env.printEnvPathStr(outEnv) +& "\n");
end lookupClass;

Expand Down Expand Up @@ -1996,7 +1997,7 @@ algorithm
end matchcontinue;
end lookupFunctionsInFrame;

protected function selectUpdatedEnv
public function selectUpdatedEnv
input Env.Env inNewEnv;
input Env.Env inOldEnv;
output Env.Env outEnv;
Expand Down

0 comments on commit 3e011e8

Please sign in to comment.