Skip to content

Commit

Permalink
MetaUtil cleanup and fixes.
Browse files Browse the repository at this point in the history
- Update uniontypes when converting records to metarecords, to make
  functions inside uniontypes work.
- Cleaned up a lot of code and removed unused code.
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jul 3, 2015
1 parent b876223 commit ce51c36
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 610 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Inst.mo
Expand Up @@ -2319,7 +2319,7 @@ algorithm
eqConstraint = InstUtil.equalityConstraint(env5, els, info);
ci_state6 = if Util.isSome(ed) then ClassInf.assertTrans(ci_state6,ClassInf.FOUND_EXT_DECL(),info) else ci_state6;
then
(cache,env5,ih,store,dae,csets5,ci_state6,vars,MetaUtil.fixUniontype(ci_state6,NONE()/* no basictype bc*/,inClassDef6),NONE(),eqConstraint,graph);
(cache,env5,ih,store,dae,csets5,ci_state6,vars,MetaUtil.fixUniontype(ci_state6,inClassDef6),NONE(),eqConstraint,graph);

// This rule describes how to instantiate class definition derived from an enumeration
case (cache,env,ih,store,mods,pre,_,_,
Expand Down
5 changes: 2 additions & 3 deletions Compiler/FrontEnd/InstSection.mo
Expand Up @@ -71,7 +71,6 @@ protected import InstTypes;
protected import NFInstUtil;
protected import List;
protected import Lookup;
protected import MetaUtil;
protected import Patternm;
protected import PrefixUtil;
protected import Static;
Expand Down Expand Up @@ -5015,7 +5014,7 @@ algorithm
// (v1,v2,..,vn) := func(...)
case (cache,env,ih,pre,Absyn.TUPLE(expressions = expl),e_1,eprop,_,source,_,impl,_,_)
equation
true = MetaUtil.onlyCrefExpressions(expl);
true = List.all(expl, Absyn.isCref);
(cache, e_1 as DAE.CALL(), eprop) = Ceval.cevalIfConstant(cache, env, e_1, eprop, impl, info);
(cache,e_2) = PrefixUtil.prefixExp(cache, env, ih, e_1, pre);
(cache,expl_1,cprops,attrs,_) = Static.elabExpCrefNoEvalList(cache, env, expl, impl, NONE(), false, pre, info);
Expand All @@ -5030,7 +5029,7 @@ algorithm
case (cache,env,ih,pre,Absyn.TUPLE(expressions = expl),e_1,eprop,_,source,_,impl,_,_)
equation
true = Config.acceptMetaModelicaGrammar();
true = MetaUtil.onlyCrefExpressions(expl);
true = List.all(expl, Absyn.isCref);
true = Types.isTuple(Types.getPropType(eprop));
(cache, e_1 as DAE.MATCHEXPRESSION(), eprop) = Ceval.cevalIfConstant(cache, env, e_1, eprop, impl, info);
(cache,e_2) = PrefixUtil.prefixExp(cache, env, ih, e_1, pre);
Expand Down
95 changes: 19 additions & 76 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -2309,82 +2309,25 @@ algorithm
end componentElts;

public function addClassdefsToEnv
"author: PA

This function adds classdefinitions and
import statements to the environment."
"This function adds class definitions and import statements to the environment."
input FCore.Cache inCache;
input FCore.Graph inEnv;
input InnerOuter.InstHierarchy inIH;
input Prefix.Prefix inPrefix;
input list<SCode.Element> inSCodeElementLst;
input Boolean inBoolean;
input Option<DAE.Mod> redeclareMod;
output FCore.Cache outCache;
output FCore.Graph outEnv;
output InnerOuter.InstHierarchy outIH;
algorithm
(outCache,outEnv,outIH) := matchcontinue (inCache,inEnv,inIH,inPrefix,inSCodeElementLst,inBoolean,redeclareMod)
local
FCore.Cache cache;
FCore.Graph env,env_1,env_2;
list<SCode.Element> els;
Boolean impl;
Prefix.Prefix pre;
InstanceHierarchy ih;

case (cache,env,ih,pre,els,impl,_)
equation
(cache,env_1,ih) = addClassdefsToEnv2(cache,env,ih,pre,els,impl,redeclareMod);
env_2 = env_1 //env_2 = Env.updateEnvClasses(env_1,env_1)
"classes added with correct env.
This is needed to store the correct env in Env.CLASS.
It is required to get external objects to work";
then (cache,env_2,ih);

else
equation
true = Flags.isSet(Flags.FAILTRACE);
Debug.trace("- InstUtil.addClassdefsToEnv failed\n");
then fail();

end matchcontinue;
input list<SCode.Element> inClasses;
input Boolean inImpl;
input Option<DAE.Mod> inRedeclareMod;
output FCore.Cache outCache = inCache;
output FCore.Graph outEnv = inEnv;
output InnerOuter.InstHierarchy outIH = inIH;
algorithm
for c in inClasses loop
(outCache, outEnv, outIH) :=
addClassdefToEnv(outCache, outEnv, outIH, inPrefix, c, inImpl, inRedeclareMod);
end for;
end addClassdefsToEnv;

protected function addClassdefsToEnv2
"author: PA
Helper relation to addClassdefsToEnv"
input FCore.Cache inCache;
input FCore.Graph inEnv;
input InnerOuter.InstHierarchy inIH;
input Prefix.Prefix inPrefix;
input list<SCode.Element> inSCodeElementLst;
input Boolean inBoolean;
input Option<DAE.Mod> redeclareMod;
output FCore.Cache outCache;
output FCore.Graph outEnv;
output InnerOuter.InstHierarchy outIH;
algorithm
(outCache,outEnv,outIH) := match (inCache,inEnv,inIH,inPrefix,inSCodeElementLst,inBoolean,redeclareMod)
local
FCore.Cache cache;
FCore.Graph env;
SCode.Element elt;
list<SCode.Element> xs;
Boolean impl;
InstanceHierarchy ih;
Prefix.Prefix pre;

case (cache,env,ih,_,{},_,_) then (cache,env,ih);
case (cache,env,ih,_,elt::xs,_,_)
equation
(cache,env,ih) = addClassdefToEnv2(cache,env,ih,inPrefix,elt,inBoolean,redeclareMod);
(cache,env,ih) = addClassdefsToEnv2(cache,env,ih,inPrefix,xs,inBoolean,redeclareMod);
then (cache,env,ih);
end match;
end addClassdefsToEnv2;

protected function addClassdefToEnv2
protected function addClassdefToEnv
"author: PA
Helper relation to addClassdefsToEnv"
input FCore.Cache inCache;
Expand All @@ -2398,7 +2341,7 @@ protected function addClassdefToEnv2
output FCore.Graph outEnv;
output InnerOuter.InstHierarchy outIH;
algorithm
(outCache,outEnv,outIH) := matchcontinue (inCache,inEnv,inIH,inPrefix,inSCodeElement,inBoolean,redeclareMod)
(outCache,outEnv,outIH) := matchcontinue (inCache,inEnv,inIH,inPrefix,inSCodeElement,redeclareMod)
local
FCore.Cache cache;
FCore.Graph env,env_1;
Expand All @@ -2415,7 +2358,7 @@ algorithm
DAE.Mod m;

// we do have a redeclaration of class.
case (cache,env,ih,pre,( (sel1 as SCode.CLASS())),_,SOME(m))
case (cache,env,ih,pre,( (sel1 as SCode.CLASS())),SOME(m))
equation
m = Mod.lookupCompModification(m, sel1.name);
false = valueEq(m, DAE.NOMOD());
Expand All @@ -2427,7 +2370,7 @@ algorithm
(cache,env_1,ih);

// otherwise, extend frame with in class.
case (cache,env,ih,pre,(sel1 as SCode.CLASS()),_,_)
case (cache,env,ih,pre,(sel1 as SCode.CLASS()),_)
equation
// Debug.traceln("Extend frame " + FGraph.printGraphPathStr(env) + " with " + SCode.className(cl));
env_1 = FGraph.mkClassNode(env, sel1, pre, DAE.NOMOD());
Expand All @@ -2438,13 +2381,13 @@ algorithm
// adrpo: we should have no imports after SCodeFlatten!
// unfortunately we do because of the way we evaluate
// programs for interactive evaluation
case (cache,env,ih,_,(imp as SCode.IMPORT()),_,_)
case (cache,env,ih,_,(imp as SCode.IMPORT()),_)
equation
env_1 = FGraph.mkImportNode(env, imp);
then
(cache,env_1,ih);

case(cache,env,ih,_,((elt as SCode.DEFINEUNIT())), _,_)
case(cache,env,ih,_,((elt as SCode.DEFINEUNIT())),_)
equation
env_1 = FGraph.mkDefunitNode(env,elt);
then (cache,env_1,ih);
Expand All @@ -2456,7 +2399,7 @@ algorithm
then
fail();
end matchcontinue;
end addClassdefToEnv2;
end addClassdefToEnv;

protected function checkCompEnvPathVsCompTypePath
"fails if the comp env path is NOT a prefix of comp type path"
Expand Down

0 comments on commit ce51c36

Please sign in to comment.