Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- do not die on getComponents(Modelica.Media.Examples.*)
- modifications of extends have to be fixed (qualified) in the env of extends and local names should not be qualified!
- some more tweaks in testsuite/openmodelica/bootstrapping/LinkMain.makefile.mingw
- test bug fix with: testsuite/openmodelica/interactive-API/Modelica.Media.Examples.getComponents.mos

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15902 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Apr 24, 2013
1 parent da99105 commit daef9b7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 51 deletions.
28 changes: 12 additions & 16 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -3475,7 +3475,7 @@ algorithm
// checkRestrictionsOnTheKindOfBaseClass(cache, env, ih, re, extendselts);

(cache,env2,ih,emods,extcomps,eqs2,initeqs2,alg2,initalg2) =
InstExtends.instExtendsAndClassExtendsList(cache, env1, ih, mods, pre, extendselts, extendsclasselts, ci_state, className, impl, false)
InstExtends.instExtendsAndClassExtendsList(cache, env1, ih, mods, pre, extendselts, extendsclasselts, els, ci_state, className, impl, false)
"2. EXTENDS Nodes inst_extends_list only flatten inhteritance structure. It does not perform component instantiations.";

//Debug.fprint(Flags.INST_EXT_TRACE, "EXTENDS RETURNS:\n" +& Debug.fcallret1(Flags.INST_EXT_TRACE, printElementAndModList, extcomps, "") +& "\n");
Expand Down Expand Up @@ -3525,18 +3525,13 @@ algorithm
(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);
(cache,env4,ih,compelts_2) = updateCompeltsMods(cache, env3, ih, pre, compelts_1, ci_state, impl);
//compelts_2 = extcomps;
//env4 = env3;

compelts_1 = addNomod(compelts);
cdefelts_1 = addNomod(cdefelts);
compelts_2 = List.flatten({compelts_2, compelts_1, cdefelts_1});

// adrpo: MAKE SURE inner objects ARE FIRST in the list for instantiation!
// TODO! FIXME! CHECKME! join this function with splitElts to make it faster
// do not bother to sort here, do it in sortElementList in instElementList!
// compelts_2 = sortInnerFirstTplLstElementMod(compelts_2);
//compelts_1 = addNomod(compelts);
//cdefelts_1 = addNomod(cdefelts);
//compelts_2 = List.flatten({compelts_2, compelts_1, cdefelts_1});

//Instantiate components
compelts_2_elem = List.map(compelts_2,Util.tuple21);
Expand Down Expand Up @@ -4942,7 +4937,7 @@ algorithm
(cdefelts,classextendselts,extendselts,_) = splitElts(els);
(env1,ih) = addClassdefsToEnv(env, ih, pre, cdefelts, true, SOME(mods)) " CLASS & IMPORT nodes are added to env" ;
(cache,env2,ih,emods,extcomps,_,_,_,_) =
InstExtends.instExtendsAndClassExtendsList(cache, env1, ih, mods, pre, extendselts, classextendselts, ci_state, className, true, isPartialInst)
InstExtends.instExtendsAndClassExtendsList(cache, env1, ih, mods, pre, extendselts, classextendselts, els, ci_state, className, true, isPartialInst)
"2. EXTENDS Nodes inst_Extends_List only flatten inhteritance structure. It does not perform component instantiations." ;

// this does not work, see Modelica.Media SingleGasNasa!
Expand Down Expand Up @@ -5104,7 +5099,7 @@ algorithm
end matchcontinue;
end partialInstClassdef;

protected function constantEls
public function constantEls
"Returns only elements that are constants or have annotation(Evaluate = true)!
author: PA & adrpo
Used buy partialInstClassdef to instantiate constants in packages."
Expand Down Expand Up @@ -5141,7 +5136,7 @@ algorithm
end matchcontinue;
end constantEls;

protected function constantAndParameterEls
public function constantAndParameterEls
"Returns only elements that are constants.
author: @adrpo
Used by partialInstClassdef to instantiate constants and parameters in packages."
Expand Down Expand Up @@ -5459,6 +5454,7 @@ algorithm
//Debug.fprintln(Flags.IDEP, "Before:\n" +& stringDelimitList(List.map(List.map(inElements, Util.tuple21), SCodeDump.unparseElementStr), "\n"));
//System.startTimer();
el := sortElementList(inElements, inEnv, Env.inFunctionScope(inEnv));
// adrpo: MAKE SURE inner objects ARE FIRST in the list for instantiation!
el := sortInnerFirstTplLstElementMod(el);
//System.stopTimer();
//Debug.fprintln(Flags.IDEP, "After: " +& stringDelimitList(List.map(List.map(el, Util.tuple21), SCode.elementName), ", "));
Expand Down Expand Up @@ -8071,7 +8067,7 @@ algorithm
equation
(_,(cl as SCode.CLASS(name = name, classDef = SCode.PARTS(elementLst=selems))), _) = Lookup.lookupClass(Env.emptyCache(),env,path,false);
(_,classextendselts,extendselts,compelts) = splitElts(selems);
(_,_,_,_,extcomps,_,_,_,_) = InstExtends.instExtendsAndClassExtendsList(Env.emptyCache(), env, InnerOuter.emptyInstHierarchy, DAE.NOMOD(), pre, extendselts, classextendselts, ClassInf.UNKNOWN(Absyn.IDENT("")), name, true, false);
(_,_,_,_,extcomps,_,_,_,_) = InstExtends.instExtendsAndClassExtendsList(Env.emptyCache(), env, InnerOuter.emptyInstHierarchy, DAE.NOMOD(), pre, extendselts, classextendselts, selems, ClassInf.UNKNOWN(Absyn.IDENT("")), name, true, false);
extcompelts = List.map(extcomps,Util.tuple21);
compelts = listAppend(compelts,extcompelts);
then
Expand Down Expand Up @@ -13045,7 +13041,7 @@ algorithm
Absyn.Exp absynExp;
Prefix.Prefix pre;

/* special case for size */
// special case for size
case (cache,env,(call as Absyn.CALL(function_ = Absyn.CREF_IDENT(name = "size"),
functionArgs = Absyn.FUNCTIONARGS(args = (args as {arraycr,dim}),argNames = nargs))),impl,st,pre,_)
equation
Expand All @@ -13056,7 +13052,7 @@ algorithm
exp = DAE.SIZE(arraycrefe,SOME(dimp));
then
(cache,exp,DAE.PROP(DAE.T_INTEGER_DEFAULT,DAE.C_VAR()),st);
/* For all other expressions, use normal elaboration */
// For all other expressions, use normal elaboration
case (cache,env,absynExp,impl,st,pre,_)
equation
(cache,e,prop,st) = Static.elabExp(cache, env, absynExp, impl, st,false,pre,info);
Expand Down
71 changes: 39 additions & 32 deletions Compiler/FrontEnd/InstExtends.mo
Expand Up @@ -83,6 +83,7 @@ protected function instExtendsList "
input DAE.Mod inMod;
input Prefix.Prefix inPrefix;
input list<SCode.Element> inSCodeElementLst;
input list<SCode.Element> inElementsFromExtendsScope;
input ClassInf.State inState;
input String inClassName; // the class name whose elements are getting instantiated.
input Boolean inImplicit;
Expand All @@ -98,7 +99,7 @@ protected function instExtendsList "
output list<SCode.AlgorithmSection> outSCodeAlgorithmLst7;
algorithm
(outCache,outEnv1,outIH,outMod2,outTplSCodeElementModLst3,outSCodeEquationLst4,outSCodeEquationLst5,outSCodeAlgorithmLst6,outSCodeAlgorithmLst7):=
matchcontinue (inCache,inEnv,inIH,inMod,inPrefix,inSCodeElementLst,inState,inClassName,inImplicit,isPartialInst)
matchcontinue (inCache,inEnv,inIH,inMod,inPrefix,inSCodeElementLst,inElementsFromExtendsScope,inState,inClassName,inImplicit,isPartialInst)
local
SCode.Element c;
String cn,s,scope_str,className;
Expand All @@ -107,7 +108,7 @@ algorithm
SCode.Restriction r;
list<Env.Frame> cenv,cenv1,cenv3,env2,env,env_1;
DAE.Mod outermod,mods,mods_1,emod_1,mod;
list<SCode.Element> importelts,els,els_1,rest,cdefelts,classextendselts;
list<SCode.Element> importelts,els,els_1,rest,cdefelts,classextendselts, elsExtendsScope;
list<SCode.Equation> eq1,ieq1,eq1_1,ieq1_1,eq2,ieq2,eq3,ieq3,eq,ieq,initeq2;
list<SCode.AlgorithmSection> alg1,ialg1,alg1_1,ialg1_1,alg2,ialg2,alg3,ialg3,alg,ialg;
Absyn.Path tp_1,tp;
Expand All @@ -126,11 +127,11 @@ algorithm
Option<SCode.Comment> cmt;
SCode.Visibility vis;

/* no further elements to instantiate */
case (cache,env,ih,mod,pre,{},ci_state,className,impl,_) then (cache,env,ih,mod,{},{},{},{},{});
// no further elements to instantiate
case (cache,env,ih,mod,pre,{},_,ci_state,className,impl,_) then (cache,env,ih,mod,{},{},{},{},{});

/* instantiate a base class */
case (cache,env,ih,mod,pre,(elt as SCode.EXTENDS(info = info, baseClassPath = tp, modifications = emod, visibility = vis)) :: rest,ci_state,className,impl,_)
// instantiate a base class
case (cache,env,ih,mod,pre,(elt as SCode.EXTENDS(info = info, baseClassPath = tp, modifications = emod, visibility = vis)) :: rest,elsExtendsScope,ci_state,className,impl,_)
equation
// Debug.fprintln(Flags.INST_TRACE, "EXTENDS: " +& Env.printEnvPathStr(env) +& " el: " +& SCodeDump.unparseElementStr(elt) +& " mods: " +& Mod.printModStr(mod));
//print("EXTENDS: " +& Env.printEnvPathStr(env) +& "/" +& Absyn.pathString(tp) +& "(" +& SCodeDump.printModStr(emod) +& ") outemod: " +& Mod.printModStr(mod) +& "\n");
Expand All @@ -147,9 +148,11 @@ algorithm
//print("Type: " +& Absyn.pathString(tp) +& "(" +& SCodeDump.printModStr(emod) +& ")\n");

emod = Inst.chainRedeclares(mod, emod);

// fully qualify modifiers in extends in this environment!
(cache, emod) = fixModifications(cache, env, emod, HashTableStringToPath.emptyHashTable());

// build a ht with the constant elements from the extends scope
ht = getLocalIdentList(Inst.constantAndParameterEls(elsExtendsScope),HashTableStringToPath.emptyHashTable(),getLocalIdentElement);
// fully qualify modifiers in extends in the extends environment!
(cache, emod) = fixModifications(cache, env, emod, ht);

// Debug.fprintln(Flags.INST_TRACE, "EXTENDS (FULLY QUAL): " +& Env.printEnvPathStr(env) +& " el: " +& SCodeDump.printModStr(emod));

Expand All @@ -162,7 +165,7 @@ algorithm
(cache,cenv1,ih,els,eq1,ieq1,alg1,ialg1) = instDerivedClasses(cache,cenv,ih,outermod,pre,c,impl,info);
els = updateElementListVisibility(els, vis);

(cache,tp_1) = Inst.makeFullyQualified(cache,/* adrpo: cenv1?? FIXME */env, tp);
//(cache,tp_1) = Inst.makeFullyQualified(cache,/* adrpo: cenv1?? FIXME */env, tp);

eq1_1 = Util.if_(isPartialInst, {}, eq1);
ieq1_1 = Util.if_(isPartialInst, {}, ieq1);
Expand All @@ -178,7 +181,7 @@ algorithm

els_1 = SCodeUtil.addRedeclareAsElementsToExtends(els_1, SCodeUtil.getRedeclareAsElements(els_1));

(cache,_,ih,mods,compelts1,eq2,ieq2,alg2,ialg2) = instExtendsAndClassExtendsList2(cache,cenv3,ih,outermod,pre,els_1,classextendselts,ci_state,className,impl,isPartialInst)
(cache,_,ih,mods,compelts1,eq2,ieq2,alg2,ialg2) = instExtendsAndClassExtendsList2(cache,cenv3,ih,outermod,pre,els_1,classextendselts,els,ci_state,className,impl,isPartialInst)
"recurse to fully flatten extends elements env";

ht = getLocalIdentList(compelts1,HashTableStringToPath.emptyHashTable(),getLocalIdentElementTpl);
Expand All @@ -193,7 +196,7 @@ algorithm
(cache,ialg1_1) = fixList(cache, cenv3, ialg1_1, ht,fixAlgorithm);
//Debug.traceln("fixed local idents " +& intString(tmp));

(cache,env2,ih,mods_1,compelts2,eq3,ieq3,alg3,ialg3) = instExtendsList(cache,env,ih,mod,pre,rest,ci_state,className,impl,isPartialInst)
(cache,env2,ih,mods_1,compelts2,eq3,ieq3,alg3,ialg3) = instExtendsList(cache,env,ih,mod,pre,rest,elsExtendsScope,ci_state,className,impl,isPartialInst)
"continue with next element in list" ;
/*
corresponding elements. But emod is Absyn.Mod and can not Must merge(mod,emod)
Expand All @@ -220,7 +223,7 @@ algorithm
(cache,env2,ih,mods_1,compelts3,eq,ieq,alg,ialg);

// base class was not found
case (cache,env,ih,mod,pre,(SCode.EXTENDS(info = info, baseClassPath = tp,modifications = emod) :: rest),ci_state,className,impl,_)
case (cache,env,ih,mod,pre,(SCode.EXTENDS(info = info, baseClassPath = tp,modifications = emod) :: rest),_,ci_state,className,impl,_)
equation
failure((_,c,cenv) = Lookup.lookupClass(cache, env, tp, false));
s = Absyn.pathString(tp);
Expand All @@ -229,17 +232,17 @@ algorithm
then
fail();

// Extending a component means copying it. It might fail above, try again
// extending a component means copying it. It might fail above, try again
case (cache,env,ih,mod,pre,
(elt as SCode.COMPONENT(name = s, attributes =
SCode.ATTR(variability = var),
modifications = scodeMod,
prefixes = SCode.PREFIXES(finalPrefix=finalPrefix),
comment = cmt)) :: rest,
comment = cmt)) :: rest,elsExtendsScope,
ci_state,className,impl,_)
equation
(cache,env_1,ih,mods,compelts2,eq2,initeq2,alg2,ialg2) =
instExtendsList(cache, env, ih, mod, pre, rest, ci_state, className, impl, isPartialInst);
instExtendsList(cache, env, ih, mod, pre, rest, elsExtendsScope, ci_state, className, impl, isPartialInst);
// Filter out non-constants or parameters if partial inst
notConst = not SCode.isConstant(var); // not (SCode.isConstant(var) or SCode.getEvaluateAnnotation(cmt));
// we should always add it as the class that variable represents might contain constants!
Expand All @@ -248,24 +251,24 @@ algorithm
(cache,env_1,ih,mods,compelts2,eq2,initeq2,alg2,ialg2);

// Classdefs
case (cache,env,ih,mod,pre,(elt as SCode.CLASS(name = cn)) :: rest,
case (cache,env,ih,mod,pre,(elt as SCode.CLASS(name = cn)) :: rest, elsExtendsScope,
ci_state,className,impl,_)
equation
(cache,env_1,ih,mods,compelts2,eq2,initeq2,alg2,ialg2) =
instExtendsList(cache, env, ih, mod, pre, rest, ci_state, className, impl, isPartialInst);
instExtendsList(cache, env, ih, mod, pre, rest, elsExtendsScope, ci_state, className, impl, isPartialInst);
then
(cache,env_1,ih,mods,((elt,DAE.NOMOD(),false) :: compelts2),eq2,initeq2,alg2,ialg2);

/* instantiate elements that are not extends */
case (cache,env,ih,mod,pre,(elt as SCode.IMPORT(imp = _)) :: rest,ci_state,className,impl,_)
// instantiate elements that are not extends
case (cache,env,ih,mod,pre,(elt as SCode.IMPORT(imp = _)) :: rest, elsExtendsScope, ci_state,className,impl,_)
equation
(cache,env_1,ih,mods,compelts2,eq2,initeq2,alg2,ialg2) =
instExtendsList(cache,env,ih, mod, pre, rest, ci_state, className, impl, isPartialInst);
instExtendsList(cache,env,ih, mod, pre, rest, elsExtendsScope, ci_state, className, impl, isPartialInst);
then
(cache,env_1,ih,mods,((elt,DAE.NOMOD(),false) :: compelts2),eq2,initeq2,alg2,ialg2);

/* instantiation failed */
case (cache,env,ih,mod,pre,rest,ci_state,className,_,_)
case (cache,env,ih,mod,pre,rest, elsExtendsScope, ci_state,className,_,_)
equation
true = Flags.isSet(Flags.FAILTRACE);
Debug.traceln("- Inst.instExtendsList failed on:\n\t" +&
Expand Down Expand Up @@ -302,6 +305,7 @@ public function instExtendsAndClassExtendsList "
input Prefix.Prefix inPrefix;
input list<SCode.Element> inExtendsElementLst;
input list<SCode.Element> inClassExtendsElementLst;
input list<SCode.Element> inElementsFromExtendsScope;
input ClassInf.State inState;
input String inClassName; // the class name whose elements are getting instantiated.
input Boolean inImpl;
Expand All @@ -321,7 +325,7 @@ protected
algorithm
//Debug.fprintln(Flags.DEBUG,"instExtendsAndClassExtendsList: " +& inClassName);
(outCache,outEnv,outIH,outMod,outTplSCodeElementModLstTpl3,outSCodeNormalEquationLst,outSCodeInitialEquationLst,outSCodeNormalAlgorithmLst,outSCodeInitialAlgorithmLst):=
instExtendsAndClassExtendsList2(inCache,inEnv,inIH,inMod,inPrefix,inExtendsElementLst,inClassExtendsElementLst,inState,inClassName,inImpl,isPartialInst);
instExtendsAndClassExtendsList2(inCache,inEnv,inIH,inMod,inPrefix,inExtendsElementLst,inClassExtendsElementLst,inElementsFromExtendsScope,inState,inClassName,inImpl,isPartialInst);
// Filter out the last boolean in the tuple
outTplSCodeElementModLst := List.map(outTplSCodeElementModLstTpl3, Util.tuple312);
// Create a list of the class definitions, since these can't be properly added in the recursive call
Expand All @@ -344,6 +348,7 @@ protected function instExtendsAndClassExtendsList2 "
input Prefix.Prefix inPrefix;
input list<SCode.Element> inExtendsElementLst;
input list<SCode.Element> inClassExtendsElementLst;
input list<SCode.Element> inElementsFromExtendsScope;
input ClassInf.State inState;
input String inClassName; // the class name whose elements are getting instantiated.
input Boolean inImpl;
Expand All @@ -359,7 +364,7 @@ protected function instExtendsAndClassExtendsList2 "
output list<SCode.AlgorithmSection> outSCodeInitialAlgorithmLst;
algorithm
(outCache,outEnv,outIH,outMod,outTplSCodeElementModLst,outSCodeNormalEquationLst,outSCodeInitialEquationLst,outSCodeNormalAlgorithmLst,outSCodeInitialAlgorithmLst):=
instExtendsList(inCache,inEnv,inIH,inMod,inPrefix,inExtendsElementLst,inState,inClassName,inImpl,isPartialInst);
instExtendsList(inCache,inEnv,inIH,inMod,inPrefix,inExtendsElementLst, inElementsFromExtendsScope,inState,inClassName,inImpl,isPartialInst);
(outMod,outTplSCodeElementModLst):=instClassExtendsList(inEnv,outMod,inClassExtendsElementLst,outTplSCodeElementModLst);
end instExtendsAndClassExtendsList2;

Expand Down Expand Up @@ -800,13 +805,12 @@ end getLocalIdentElementTpl;

protected function getLocalIdentElement
" Analyzes an element of a class and fetches a list of components and classdefs,
as well as aliases from imports to paths.
"
as well as aliases from imports to paths."
input SCode.Element elt;
input HashTableStringToPath.HashTable inHt;
output HashTableStringToPath.HashTable outHt;
algorithm
(outHt) := match (elt,inHt)
(outHt) := matchcontinue (elt,inHt)
local
String id;
Absyn.Path p;
Expand Down Expand Up @@ -843,8 +847,9 @@ algorithm
failure(_ = BaseHashTable.get(id, ht));
ht = BaseHashTable.add((id,p), ht);
then ht;

end match;

else inHt;
end matchcontinue;
end getLocalIdentElement;

protected function fixLocalIdents
Expand Down Expand Up @@ -1403,8 +1408,7 @@ end fixTypeSpec;
protected function fixPath
" All of the fix functions do the following:
Analyzes the SCode datastructure and replace paths with a new path (from
local lookup or fully qualified in the environment.
"
local lookup or fully qualified in the environment."
input Env.Cache inCache;
input Env.Env inEnv;
input Absyn.Path inPath;
Expand Down Expand Up @@ -1508,6 +1512,7 @@ algorithm
Env.Env env;
HashTableStringToPath.HashTable ht;
Absyn.ComponentRef cref;
SCode.Element c;

case (cache,env,cref,ht)
equation
Expand Down Expand Up @@ -1554,7 +1559,9 @@ algorithm
equation
id = Absyn.crefFirstIdent(cref);
//Debug.fprintln(Flags.DEBUG,"Try lookupC " +& id);
(_,_,env) = Lookup.lookupClass(cache,env,Absyn.IDENT(id),false);
(_,c,env) = Lookup.lookupClass(cache,env,Absyn.IDENT(id),false);
// id might come from named import, make sure you use the actual class name!
id = SCode.getElementName(c);
//Debug.fprintln(Flags.DEBUG,"Got env " +& intString(listLength(env)));
env = Env.openScope(env,SCode.ENCAPSULATED(),SOME(id),NONE());
cref = Absyn.crefReplaceFirstIdent(cref,Env.getEnvName(env));
Expand Down

0 comments on commit daef9b7

Please sign in to comment.