Skip to content

Commit

Permalink
- Fix propagation of redeclared redeclare modifiers in new instantiat…
Browse files Browse the repository at this point in the history
…ion.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13687 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Oct 29, 2012
1 parent e5bb25b commit 95d80ea
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 291 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/InstSymbolTable.mo
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ protected function addAliases
a lot of things such as inner/outer handling a lot more complicated. Another
solution would be to simply add the top-level components twice with the two
different names they are referred by, but that will cause unnecessary
instantiation and possible introduce subtle bugs in the typing. Instead
instantiation and possibly introduce subtle bugs in the typing. Instead
we add aliases to the symboltable, so that whenever a top-level component is
referred to by its fully qualified name we find an alias that points to its
non-qualified name, and look up that component instead.
Expand Down
9 changes: 9 additions & 0 deletions Compiler/FrontEnd/SCodeCheck.mo
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public import SCode;
public import SCodeEnv;

protected import Config;
protected import Debug;
protected import Dump;
protected import Error;
protected import Flags;
protected import InstDump;
protected import List;
protected import SCodeDump;
Expand Down Expand Up @@ -648,6 +650,13 @@ algorithm
then
fail();

else
equation
true = Flags.isSet(Flags.FAILTRACE);
Debug.traceln("- SCodeCheck.checkInstanceRestriction failed on unknown item.");
then
fail();

end matchcontinue;
end checkInstanceRestriction;

Expand Down
10 changes: 8 additions & 2 deletions Compiler/FrontEnd/SCodeDependency.mo
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ algorithm
case (_, _, _, _)
equation
(item, env) = lookupClass2(inPath, inEnv, inInfo, inErrorType);
(item, env) = SCodeEnv.resolveRedeclaredItem(item, env);
then
(item, env);

Expand Down Expand Up @@ -183,6 +184,7 @@ algorithm
equation
(item, _, env, _) =
SCodeLookup.lookupNameSilent(Absyn.IDENT(id), inEnv, inInfo);
(item, env) = SCodeEnv.resolveRedeclaredItem(item, env);
analyseItem(item, env);
(item, env) = lookupNameInItem(rest_path, item, env, inErrorType);
then
Expand Down Expand Up @@ -479,6 +481,7 @@ algorithm
env = Util.if_(inInModifierScope, inEnv, env);
analyseTypeSpec(ty, env, inInfo);
(ty_item, ty_env) = SCodeLookup.lookupTypeSpec(ty, env, inInfo);
(ty_item, ty_env) = SCodeEnv.resolveRedeclaredItem(ty_item, ty_env);
ty_env = SCodeEnv.mergeItemEnv(ty_item, ty_env);
// TODO! Analyse array dimensions from attributes!
analyseModifier(mods, inEnv, ty_env, inInfo);
Expand Down Expand Up @@ -737,6 +740,7 @@ algorithm
analyseAttributes(attr, inEnv, info);
analyseTypeSpec(ty, inEnv, info);
(ty_item, ty_env) = SCodeLookup.lookupTypeSpec(ty, inEnv, info);
(ty_item, ty_env) = SCodeEnv.resolveRedeclaredItem(ty_item, ty_env);
ty_env = SCodeEnv.mergeItemEnv(ty_item, ty_env);
SCodeCheck.checkRecursiveComponentDeclaration(name, info, ty_env,
ty_item, inEnv);
Expand Down Expand Up @@ -877,7 +881,7 @@ algorithm
case (_, _, _, _)
equation
id = Absyn.pathFirstIdent(inBaseClass);
(bc, _, _) = SCodeLookup.lookupBaseClass(id, inEnv, inInfo);
bc = SCodeLookup.lookupBaseClass(id, inEnv);
bc_name = Absyn.pathString(bc);
Error.addSourceMessage(Error.EXTENDS_INHERITED_FROM_LOCAL_EXTENDS,
{bc_name, id}, inInfo);
Expand Down Expand Up @@ -999,7 +1003,7 @@ algorithm
case (SOME(SCode.CONSTRAINCLASS(constrainingClass = path, modifier = mod)), _, _)
equation
analyseClass(path, inEnv, inInfo);
(_, _, env) = SCodeLookup.lookupClassName(path, inEnv, inInfo);
(_, env) = lookupClass(path, inEnv, inInfo, SOME(Error.LOOKUP_ERROR));
analyseModifier(mod, inEnv, env, inInfo);
then
();
Expand Down Expand Up @@ -1095,6 +1099,7 @@ algorithm
case (_, _, _)
equation
(item, _, env, _) = SCodeLookup.lookupNameSilent(inPath, inEnv, inInfo);
(item, env) = SCodeEnv.resolveRedeclaredItem(item, env);
then
(SOME(item), SOME(env));

Expand Down Expand Up @@ -1283,6 +1288,7 @@ protected
algorithm
(item, _, env, _) :=
SCodeLookup.lookupNameSilent(Absyn.IDENT(inName), inEnv, inInfo);
(item, env) := SCodeEnv.resolveRedeclaredItem(item, env);
analyseItem(item, env);
end analyseAnnotationName;

Expand Down
90 changes: 79 additions & 11 deletions Compiler/FrontEnd/SCodeEnv.mo
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ public uniontype Redeclaration
element redeclare). The RAW_MODIFIER stores a 'raw' modifier, i.e. the raw
element stored in the SCode representation. These are processed when they are
used, i.e. when replacements are done, and converted into PROCESSED_MODIFIERs
which are environment items ready to be replaced in the environment.
This processing happens in two places. Element redeclares are processed
immediately when they are converted to redeclare modifiers and inserted into
the environment in addElementRedeclarationsToEnv. Element modifiers are
processed just before they are replaced, in replaceRedeclaredElementInEnv."
which are environment items ready to be replaced in the environment."

record RAW_MODIFIER
SCode.Element modifier;
end RAW_MODIFIER;
Expand Down Expand Up @@ -149,6 +145,11 @@ public uniontype Item
Option<Absyn.Path> path;
Absyn.Info info;
end ALIAS;

record REDECLARED_ITEM
Item item;
Env declaredEnv;
end REDECLARED_ITEM;
end Item;

public type Env = list<Frame>;
Expand Down Expand Up @@ -554,6 +555,7 @@ algorithm
isUsed := match(inItem)
local
Util.StatefulBoolean is_used;
Item item;

case CLASS(env = {FRAME(isUsed = SOME(is_used))})
then Util.getStatefulBoolean(is_used);
Expand All @@ -563,6 +565,8 @@ algorithm

case ALIAS(name = _) then true;

case REDECLARED_ITEM(item = item) then isItemUsed(item);

else false;
end match;
end isItemUsed;
Expand All @@ -584,6 +588,8 @@ algorithm
AvlTree cv;
ExtendsTable exts;
ImportTable imps;
Item item;
Env env;

case (VAR(isUsed = is_used), VAR(var = elem))
then VAR(elem, is_used);
Expand All @@ -593,6 +599,12 @@ algorithm
{FRAME(name, ft, cv, exts, imps, _)}))
then CLASS(elem, {FRAME(name, ft, cv, exts, imps, is_used)}, cls_ty);

case (_, REDECLARED_ITEM(item, env))
equation
item = linkItemUsage(inSrcItem, item);
then
REDECLARED_ITEM(item, env);

else inDestItem;
end match;
end linkItemUsage;
Expand All @@ -602,7 +614,11 @@ public function isClassItem
output Boolean outIsClass;
algorithm
outIsClass := match(inItem)
local
Item item;

case CLASS(cls = _) then true;
case REDECLARED_ITEM(item = item) then isClassItem(item);
else false;
end match;
end isClassItem;
Expand All @@ -612,7 +628,11 @@ public function isVarItem
output Boolean outIsVar;
algorithm
outIsVar := match(inItem)
local
Item item;

case VAR(var = _) then true;
case REDECLARED_ITEM(item = item) then isVarItem(item);
else false;
end match;
end isVarItem;
Expand All @@ -622,7 +642,11 @@ public function isClassExtendsItem
output Boolean outIsClassExtends;
algorithm
outIsClassExtends := match(inItem)
local
Item item;

case CLASS(classType = CLASS_EXTENDS()) then true;
case REDECLARED_ITEM(item = item) then isClassExtendsItem(item);
else false;
end match;
end isClassExtendsItem;
Expand Down Expand Up @@ -964,7 +988,6 @@ algorithm
equation
SCodeCheck.checkExtendsReplaceability(item, obc, inEnv, info);
bc = Absyn.makeFullyQualified(bc);
rl = List.map2(rl, SCodeFlattenRedeclare.qualifyRedeclare, inEnv, InstTypes.emptyPrefix);
List.map2_0(rl, SCodeCheck.checkRedeclareModifier, bc, inEnv);
then
EXTENDS(bc, rl, info);
Expand Down Expand Up @@ -1500,10 +1523,12 @@ algorithm
outInfo := match(inItem)
local
Absyn.Info info;
Item item;

case VAR(var = SCode.COMPONENT(info = info)) then info;
case CLASS(cls = SCode.CLASS(info = info)) then info;
case ALIAS(info = info) then info;
case REDECLARED_ITEM(item = item) then getItemInfo(item);
end match;
end getItemInfo;

Expand All @@ -1514,13 +1539,28 @@ public function itemStr
algorithm
outName := match(inItem)
local
String name;
String name, alias_str;
SCode.Element el;
Absyn.Path path;
Item item;

case VAR(var = el)
then SCodeDump.printElementStr(el);
case CLASS(cls = el)
then SCodeDump.printElementStr(el);
case ALIAS(name = name, path = SOME(path))
equation
alias_str = Absyn.pathString(path);
then
"alias " +& name +& " -> " +& alias_str;
case ALIAS(name = name, path = NONE())
then "alias " +& name +& " ->";
case REDECLARED_ITEM(item = item)
equation
name = itemStr(item);
then
"redeclared " +& name;

end match;
end itemStr;

Expand All @@ -1530,11 +1570,14 @@ public function getItemName
output String outName;
algorithm
outName := match(inItem)
local String name;
local
String name;
Item item;

case VAR(var = SCode.COMPONENT(name = name)) then name;
case CLASS(cls = SCode.CLASS(name = name)) then name;
case ALIAS(name = name) then name;
case REDECLARED_ITEM(item = item) then getItemName(item);
end match;
end getItemName;

Expand All @@ -1546,8 +1589,10 @@ algorithm
outEnv := match(inItem)
local
Env env;
Item item;

case (CLASS(env = env)) then env;
case CLASS(env = env) then env;
case REDECLARED_ITEM(item = item) then getItemEnv(item);
end match;
end getItemEnv;

Expand All @@ -1560,9 +1605,11 @@ algorithm
outEnv := match(inItem, inEnv)
local
Frame cls_env;
Item item;

case (CLASS(env = {cls_env}), _) then enterFrame(cls_env, inEnv);
else then inEnv;
case (REDECLARED_ITEM(item = item), _) then mergeItemEnv(item, inEnv);
else inEnv;
end match;
end mergeItemEnv;

Expand All @@ -1573,12 +1620,30 @@ algorithm
outPrefixes := match(inItem)
local
SCode.Prefixes pf;
Item item;

case CLASS(cls = SCode.CLASS(prefixes = pf)) then pf;
case VAR(var = SCode.COMPONENT(prefixes = pf)) then pf;
case REDECLARED_ITEM(item = item) then getItemPrefixes(item);
end match;
end getItemPrefixes;

public function resolveRedeclaredItem
input Item inItem;
input Env inEnv;
output Item outItem;
output Env outEnv;
algorithm
(outItem, outEnv) := match(inItem, inEnv)
local
Item item;
Env env;

case (REDECLARED_ITEM(item = item, declaredEnv = env), _) then (item, env);
else (inItem, inEnv);
end match;
end resolveRedeclaredItem;

public function getEnvExtendsTable
input Env inEnv;
output ExtendsTable outExtendsTable;
Expand Down Expand Up @@ -1677,10 +1742,13 @@ algorithm
outElement := match(inRedeclare)
local
SCode.Element e;
Item item;

case RAW_MODIFIER(modifier = e) then e;
case PROCESSED_MODIFIER(modifier = CLASS(cls = e)) then e;
case PROCESSED_MODIFIER(modifier = VAR(var = e)) then e;
case PROCESSED_MODIFIER(modifier = REDECLARED_ITEM(item = item))
then getRedeclarationElement(PROCESSED_MODIFIER(item));
end match;
end getRedeclarationElement;

Expand Down

0 comments on commit 95d80ea

Please sign in to comment.