Skip to content

Commit

Permalink
- Better element redeclare support in SCodeFlatten.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8851 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed May 6, 2011
1 parent 640ba8c commit 5924dbb
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 138 deletions.
22 changes: 8 additions & 14 deletions Compiler/FrontEnd/SCodeDependency.mo
Expand Up @@ -320,6 +320,7 @@ algorithm
local
SCodeEnv.Frame cls_env;
Util.StatefulBoolean is_used;
String name;

case (SCodeEnv.VAR(isUsed = is_used), _)
equation
Expand All @@ -328,7 +329,7 @@ algorithm
then
();

case (SCodeEnv.CLASS(env = {cls_env}), _)
case (SCodeEnv.CLASS(env = {cls_env}, cls = SCode.CLASS(name = name)), _)
equation
markFrameAsUsed(cls_env);
markEnvAsUsed(inEnv);
Expand Down Expand Up @@ -633,7 +634,7 @@ protected function analyseRedeclaredClass
input SCode.Element inClass;
input Env inEnv;
algorithm
_ := match(inClass, inEnv)
_ := matchcontinue(inClass, inEnv)
local
Item item;
String name;
Expand All @@ -650,7 +651,7 @@ algorithm
then
();

end match;
end matchcontinue;
end analyseRedeclaredClass;

protected function analyseRedeclaredClass2
Expand All @@ -664,18 +665,11 @@ algorithm
Env env;
SCode.Element cls;

case (SCodeEnv.CLASS(cls = cls as SCode.CLASS(name = _)), _)
equation
false = SCode.isElementRedeclare(cls);
markItemAsUsed(inItem, inEnv);
then
();

case (SCodeEnv.CLASS(cls = cls as SCode.CLASS(name = name)), _)
equation
true = SCode.isElementRedeclare(cls);
//(item, _, _, env) = SCodeLookup.lookupInBaseClasses(name, inEnv, false);
(SOME(item), _, SOME(env)) = SCodeLookup.lookupInLocalScope(name, inEnv);
(SOME(item), _, _, SOME(env)) = SCodeLookup.lookupInBaseClasses(name,
inEnv, SCodeLookup.IGNORE_REDECLARES);
//(SOME(item), _, SOME(env)) = SCodeLookup.lookupInLocalScope(name, inEnv);
//analyseRedeclaredClass2(item, env);
markItemAsUsed(item, env);
then
Expand Down Expand Up @@ -1629,7 +1623,7 @@ algorithm
then
();

else then ();
else ();

end matchcontinue;
end analyseClassExtendsDef;
Expand Down
28 changes: 28 additions & 0 deletions Compiler/FrontEnd/SCodeEnv.mo
Expand Up @@ -399,6 +399,34 @@ algorithm
end match;
end isItemUsed;

public function linkItemUsage
"'Links' two items to each other, by making them share the same isUsed
variable."
input Item inSrcItem;
input Item inDestItem;
output Item outDestItem;
algorithm
outDestItem := match(inSrcItem, inDestItem)
local
Util.StatefulBoolean is_used;
SCode.Element elem;
ClassType cls_ty;
Option<String> name;
FrameType ft;
AvlTree cv;
ExtendsTable exts;
ImportTable imps;

case (VAR(isUsed = is_used), VAR(var = elem))
then VAR(elem, is_used);

case (CLASS(env = {FRAME(isUsed = is_used)}),
CLASS(cls = elem, classType = cls_ty, env =
{FRAME(name, ft, cv, exts, imps, _)}))
then CLASS(elem, {FRAME(name, ft, cv, exts, imps, is_used)}, cls_ty);
end match;
end linkItemUsage;

protected function extendEnvWithClassDef
"Extends the environment with a class definition."
input SCode.Element inClassDefElement;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/SCodeFlatten.mo
Expand Up @@ -117,7 +117,7 @@ algorithm
env = SCodeEnv.buildInitialEnv();
env = SCodeEnv.extendEnvWithClasses(prog, env);
env = SCodeEnv.updateExtendsInEnv(env);

(prog, env) = SCodeDependency.analyse(inClassName, env, prog);
(prog, env) = SCodeFlattenImports.flattenProgram(prog, env);
prog = SCodeFlattenExtends.flattenProgram(prog, env);
Expand Down
14 changes: 7 additions & 7 deletions Compiler/FrontEnd/SCodeFlattenRedeclare.mo
Expand Up @@ -394,20 +394,16 @@ public function qualifyRedeclare
algorithm
outElement := match(inElement, inEnv)
local
SCode.Ident name, name2;
Absyn.Ident id;
SCode.Ident name;
SCode.Partial pp;
SCode.Encapsulated ep;
SCode.Prefixes prefixes;
Option<Absyn.ConstrainClass> cc;
Option<Absyn.ArrayDim> ad;
Absyn.Path path;
SCode.Mod mods;
Option<SCode.Comment> cmt;
Env env;
SCode.Restriction res;
Absyn.Info info;
Absyn.InnerOuter io;
SCode.Attributes attr;
Option<Absyn.Exp> cond;
Option<Absyn.ArrayDim> array_dim;
Expand Down Expand Up @@ -829,13 +825,17 @@ algorithm
SCodeEnv.ImportTable imps;
Env env, class_env;
Util.StatefulBoolean is_used;
Item old_item, new_item;

case (_, SCode.CLASS(name = _),
SCodeEnv.FRAME(name, ty, tree, exts, imps, is_used) :: env)
equation
old_item = SCodeEnv.avlTreeGet(tree, inElementName);
class_env = SCodeEnv.makeClassEnvironment(inElement, true);
tree = SCodeEnv.avlTreeReplace(tree, inElementName,
SCodeEnv.newClassItem(inElement, class_env, SCodeEnv.USERDEFINED()));
new_item = SCodeEnv.newClassItem(inElement, class_env,
SCodeEnv.USERDEFINED());
new_item = SCodeEnv.linkItemUsage(old_item, new_item);
tree = SCodeEnv.avlTreeReplace(tree, inElementName, new_item);
then
SCodeEnv.FRAME(name, ty, tree, exts, imps, is_used) :: env;

Expand Down

0 comments on commit 5924dbb

Please sign in to comment.