Skip to content

Commit

Permalink
- last fixes for ExternalMedia
Browse files Browse the repository at this point in the history
  + fully qualify paths in ClassInf.State
  + do List.unique on records so we don't get duplicates
  + now at least 5 models in ExternalMedia can be compiled
- fix an issue with lookup where path to be looked up 
  contains the name of the model in the scope we're in.
  this fixes instantiation of 
  ThermoPower.Examples.BraytonCycle.ClosedLoopSimulator,
  probably more models in ThemoPower.
  added test:
  testsuite/flattening/modelica/others/ThermoPower.Examples.BraytonCycle.ClosedLoopSimulator.mos



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17667 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 13, 2013
1 parent 80315b1 commit 4aa49f0
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 42 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/SimCodeUtil.mo
Expand Up @@ -622,6 +622,7 @@ protected
algorithm
(extraRecordDecls, outRecordTypes) := elaborateRecordDeclarationsForMetarecords(literals, {}, {});
(functions, outRecordTypes, extraRecordDecls, outIncludes, includeDirs, libs) := elaborateFunctions2(program, daeElements, {}, outRecordTypes, extraRecordDecls, includes, {}, {});
extraRecordDecls := List.unique(extraRecordDecls);
(extraRecordDecls, _) := elaborateRecordDeclarationsFromTypes(metarecordTypes, extraRecordDecls, outRecordTypes);
extraRecordDecls := List.sort(extraRecordDecls, orderRecordDecls);
end elaborateFunctions;
Expand Down
18 changes: 9 additions & 9 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -2081,7 +2081,7 @@ algorithm
equation
(cr, tup) = traverseExpBidirCref(cr, inTuple);
then
(CREF_FULLYQUALIFIED(cr), tup);
(crefMakeFullyQualified(cr), tup);

case (CREF_QUAL(name = name, subscripts = subs, componentRef = cr), _)
equation
Expand Down Expand Up @@ -3106,7 +3106,7 @@ algorithm
equation
cr = addSubscriptsLast(cr,i);
then
CREF_FULLYQUALIFIED(cr);
crefMakeFullyQualified(cr);
end match;
end addSubscriptsLast;

Expand All @@ -3126,7 +3126,7 @@ algorithm
case (CREF_FULLYQUALIFIED(componentRef = cr),_)
equation
cr = crefReplaceFirstIdent(cr,replPath);
then CREF_FULLYQUALIFIED(cr);
then crefMakeFullyQualified(cr);
case (CREF_QUAL(componentRef = cr, subscripts = subs),_)
equation
cref = pathToCref(replPath);
Expand Down Expand Up @@ -3798,7 +3798,7 @@ algorithm
equation
c_1 = crefStripLast(c);
then
CREF_FULLYQUALIFIED(c_1);
crefMakeFullyQualified(c_1);
end match;
end crefStripLast;

Expand Down Expand Up @@ -3917,7 +3917,7 @@ algorithm
case(FULLYQUALIFIED(p))
equation
c = pathToCref(p);
then CREF_FULLYQUALIFIED(c);
then crefMakeFullyQualified(c);
end match;
end pathToCref;

Expand Down Expand Up @@ -3946,7 +3946,7 @@ algorithm
equation
c = pathToCrefWithSubs(p, inSubs);
then
CREF_FULLYQUALIFIED(c);
crefMakeFullyQualified(c);
end match;
end pathToCrefWithSubs;

Expand Down Expand Up @@ -4128,7 +4128,7 @@ algorithm
equation
cr_1 = crefStripLastSubs(cr);
then
CREF_FULLYQUALIFIED(cr_1);
crefMakeFullyQualified(cr_1);
end match;
end crefStripLastSubs;

Expand Down Expand Up @@ -4156,7 +4156,7 @@ algorithm
equation
cr_1 = joinCrefs(cr, cr2);
then
CREF_FULLYQUALIFIED(cr_1);
crefMakeFullyQualified(cr_1);
end match;
end joinCrefs;

Expand Down Expand Up @@ -5397,7 +5397,7 @@ algorithm
equation
cref2 = crefInsertSubscriptLstLst2(cref, subs);
then
CREF_FULLYQUALIFIED(cref2);
crefMakeFullyQualified(cref2);
case (CREF_INVALID(componentRef = cref), subs)
equation
cref2 = crefInsertSubscriptLstLst2(cref, subs);
Expand Down
19 changes: 13 additions & 6 deletions Compiler/FrontEnd/ClassInf.mo
Expand Up @@ -380,18 +380,25 @@ algorithm
end match;
end printEventStr;

public function start "!includecode
- Transitions
public function start "
This is the state machine initialization function."
input SCode.Restriction inRestriction;
input Absyn.Path inPath;
output State outState;
algorithm
outState := start_dispatch(inRestriction, Absyn.makeFullyQualified(inPath));
end start;

This is the state machine initialization function.
"
// Transitions
protected function start_dispatch "
This is the state machine initialization function."
input SCode.Restriction inRestriction;
input Absyn.Path inPath;
output State outState;
algorithm
outState:=
match (inRestriction,inPath)
local Absyn.Path p; Boolean isExpandable, isImpure;
local Absyn.Path p; Boolean isExpandable, isImpure;
case (SCode.R_CLASS(),p) then UNKNOWN(p);
case (SCode.R_OPTIMIZATION(),p) then OPTIMIZATION(p);
case (SCode.R_MODEL(),p) then MODEL(p);
Expand All @@ -414,7 +421,7 @@ algorithm
case (SCode.R_UNIONTYPE(),p) then META_UNIONTYPE(p);
case (SCode.R_METARECORD(index=_),p) then META_RECORD(p);
end match;
end start;
end start_dispatch;

public function trans "
This is the state machine transition function. It describes the
Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -5608,18 +5608,18 @@ algorithm
DAE.FunctionTree tree;

case ({},tree) then tree;
/*
case (func::funcs,tree)
equation
true = Flags.isSet(Flags.FAILTRACE);
// print("Add to cache [check] : " +& Absyn.pathString(functionName(func)) +& "\n");
// print("Function added: \n" +& DAEDump.dumpFunctionStr(func) +& "\n");
fOld = Util.getOption(avlTreeGet(tree, functionName(func)));
failure(equality(fOld = func));
print("Function already in the tree and different:" +&
print("Function already in the tree and different (keep the one already in the tree):" +&
"\nnew:\n" +& DAEDump.dumpFunctionStr(func) +&
"\nold:\n" +& DAEDump.dumpFunctionStr(fOld) +& "\n");
then
fail();*/
fail();
case (func::funcs,tree)
equation
// print("Add to cache: " +& Absyn.pathString(functionName(func)) +& "\n");
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Dump.mo
Expand Up @@ -1291,7 +1291,7 @@ algorithm
();
case _
equation
Print.printBuf("Error print_elementitems\n");
Print.printBuf("Error Dump.printElementitems2\n");
then
();
end matchcontinue;
Expand Down
18 changes: 16 additions & 2 deletions Compiler/FrontEnd/Env.mo
Expand Up @@ -1618,7 +1618,20 @@ algorithm
end getClassName;

public function getEnvName
"Returns the FQ name of the environment, see also getEnvPath"
"Returns the FQ name of the environment, see also getEnvPath"
input Env inEnv;
output Absyn.Path outPath;
protected
Ident id;
Env rest;
Absyn.Path p;
algorithm
// outPath := Absyn.makeFullyQualified(getEnvName_dispatch(inEnv));
outPath := getEnvName_dispatch(inEnv);
end getEnvName;

protected function getEnvName_dispatch
"Returns the Q name of the environment, see also getEnvPath"
input Env inEnv;
output Absyn.Path outPath;
protected
Expand All @@ -1633,7 +1646,7 @@ algorithm
then
outPath;
end match;
end getEnvName;
end getEnvName_dispatch;

public function getEnvName2
input Env inEnv;
Expand Down Expand Up @@ -1717,6 +1730,7 @@ algorithm
case (_,_)
equation
SOME(envPath) = getEnvPath(inEnv);
//envPath = Absyn.makeFullyQualified(Absyn.joinPaths(envPath,inPath));
envPath = Absyn.joinPaths(envPath,inPath);
then envPath;
case (_,_)
Expand Down
14 changes: 7 additions & 7 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -2697,8 +2697,8 @@ algorithm
//cenv_2 = Env.mergeEnv(cenv_2, env, "$derived_" +& cn2, c, Env.M(pre, className, adno, mods_1, parentEnv, inst_dims_1));
cenv_2 = Env.addModification(cenv_2, Env.M(pre, className, adno, mods_1, parentEnv, inst_dims_1));
(cache,env_2,ih,store,dae,csets_1,ci_state_1,vars,bc,oDA,eqConstraint,graph) = instClassIn(cache, cenv_2, ih, store, mods_1, pre, new_ci_state, c, vis,
inst_dims_1, impl, callscope, graph, inSets, instSingleCref) "instantiate class in opened scope. " ;

inst_dims_1, impl, callscope, graph, inSets, instSingleCref) "instantiate class in opened scope. " ;
ClassInf.assertValid(ci_state_1, re, info) "Check for restriction violations" ;
oDA = SCode.mergeAttributes(DA,oDA);
then
Expand Down Expand Up @@ -5035,23 +5035,23 @@ algorithm
(cache,cl as SCode.CLASS(name = name),env_1) = Lookup.lookupClass(cache, env, path, false);
path_2 = makeFullyQualified2(env_1,Absyn.IDENT(name));
then
(cache,Absyn.FULLYQUALIFIED(path_2));
(cache,Absyn.makeFullyQualified(path_2));

// Needed to make external objects fully-qualified
case (cache,env as (Env.FRAME(name = SOME(name))::_),Absyn.IDENT(s))
equation
true = name ==& s;
SOME(path_2) = Env.getEnvPath(env);
then
(cache,Absyn.FULLYQUALIFIED(path_2));
(cache,Absyn.makeFullyQualified(path_2));

// A type can exist without a class (i.e. builtin functions)
case (cache,env,path as Absyn.IDENT(s))
equation
(cache,_,env_1) = Lookup.lookupType(cache,env, Absyn.IDENT(s), NONE());
path_2 = makeFullyQualified2(env_1,path);
then
(cache,Absyn.FULLYQUALIFIED(path_2));
(cache,Absyn.makeFullyQualified(path_2));

// A package constant, first try to look it up local(top frame)
case (cache,(f::fs) ,path)
Expand All @@ -5060,7 +5060,7 @@ algorithm
(cache,_,_,_,_,_,env,_,name) = Lookup.lookupVarInternal(cache, {f}, crPath,InstTypes.SEARCH_ALSO_BUILTIN());
path3 = makeFullyQualified2(env,Absyn.IDENT(name));
then
(cache,Absyn.FULLYQUALIFIED(path3));
(cache,Absyn.makeFullyQualified(path3));

// TODO! FIXME! what do we do here??!!
case (cache,env,path)
Expand All @@ -5069,7 +5069,7 @@ algorithm
(cache,env,_,_,_,_,_,_,name) = Lookup.lookupVarInPackages(cache, env, crPath, {}, Util.makeStatefulBoolean(false));
path3 = makeFullyQualified2(env,Absyn.IDENT(name));
then
(cache,Absyn.FULLYQUALIFIED(path3));
(cache,Absyn.makeFullyQualified(path3));

// If it fails, leave name unchanged.
case (cache,env,path)
Expand Down
12 changes: 8 additions & 4 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -1221,8 +1221,8 @@ algorithm
then
(cache,f::fs,attr,ty,bind,cnstForRange,splicedExpData,componentEnv,name);

// lookup of constants on form A.B in packages. instantiate package and look inside.
case (cache,env,cr as DAE.CREF_QUAL(ident = id,subscriptLst = {},componentRef = cref),prevFrames,_) /* First part of name is a class. */
/*/ lookup of constants on form A.B in packages. instantiate package and look inside.
case (cache,env,cr as DAE.CREF_QUAL(ident = id,subscriptLst = {},componentRef = cref),prevFrames,_)
equation
(NONE(),prevFrames) = lookupPrevFrames(id,prevFrames);
(cache,(c as SCode.CLASS(name=n,encapsulatedPrefix=encflag,restriction=r)),env2,prevFrames) =
Expand All @@ -1231,17 +1231,21 @@ algorithm
env,
Absyn.IDENT(id),
prevFrames,
Util.makeStatefulBoolean(true) /* In order to use the prevFrames, we need to make sure we can't instantiate one of the classes too soon! */,
Util.makeStatefulBoolean(true), // In order to use the prevFrames, we need to make sure we can't instantiate one of the classes too soon!
false);
Util.setStatefulBoolean(inState,true);
true = Env.hasModifications(env2);
// env <> env2!
env2 = selectUpdatedEnv(env, env2);
// search directly in env2
(_, env5) = lookupClassLocal(env2, n);
(cache,p_env,attr,ty,bind,cnstForRange,splicedExpData,componentEnv,name) = lookupVarInPackages(cache,env5,cref,prevFrames,inState);
then
(cache,p_env,attr,ty,bind,cnstForRange,splicedExpData,componentEnv,name);
(cache,p_env,attr,ty,bind,cnstForRange,splicedExpData,componentEnv,name); */

// lookup of constants on form A.B in packages. instantiate package and look inside.
case (cache,env,cr as DAE.CREF_QUAL(ident = id,subscriptLst = {},componentRef = cref),prevFrames,_) /* First part of name is a class. */
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/MetaUtil.mo
Expand Up @@ -554,7 +554,7 @@ algorithm

case (ClassInf.META_UNIONTYPE(p),_,SCode.PARTS(elementLst = els))
equation
p = Absyn.FULLYQUALIFIED(p);
p = Absyn.makeFullyQualified(p);
slst = getListOfStrings(els);
paths = List.map1r(slst, Absyn.pathReplaceIdent, p);
b = listLength(paths)==1;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/NFSCodeFlattenImports.mo
Expand Up @@ -731,7 +731,7 @@ algorithm
equation
cref = flattenComponentRefSubs(cref, inEnv, inInfo);
then
Absyn.CREF_FULLYQUALIFIED(cref);
Absyn.crefMakeFullyQualified(cref);

end match;
end flattenComponentRefSubs;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/NFSCodeLookup.mo
Expand Up @@ -1409,7 +1409,7 @@ algorithm
equation
path = joinPaths(path, inPath2);
then
Absyn.FULLYQUALIFIED(path);
Absyn.makeFullyQualified(path);
end match;
end joinPaths;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/SCode.mo
Expand Up @@ -2577,7 +2577,7 @@ algorithm
equation
(cr, tup) = traverseComponentRefExps(cr, inTuple);
then
(Absyn.CREF_FULLYQUALIFIED(cr), tup);
(Absyn.crefMakeFullyQualified(cr), tup);

case (Absyn.CREF_QUAL(name = name, subscripts = subs, componentRef = cr), _)
equation
Expand Down
32 changes: 27 additions & 5 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -7531,7 +7531,7 @@ algorithm
slots) := elabTypes(cache, inEnv, args, nargs, typelist, true/* Check types*/, impl,isExternalObject,st,pre,info)
"The constness of a function depends on the inputs. If all inputs are constant the call itself is constant." ;

(fn_1,functype) := deoverloadFuncname(fn, functype);
(fn_1,functype) := deoverloadFuncname(fn, functype, inEnv);
tuple_ := isTuple(restype);
(isBuiltin,builtin,fn_1) := isBuiltinFunc(fn_1,functype);
inlineType := inlineBuiltin(isBuiltin,inlineType);
Expand Down Expand Up @@ -8449,24 +8449,46 @@ protected function deoverloadFuncname
so this is returned. Otherwise return input."
input Absyn.Path inPath;
input DAE.Type inType;
input Env.Env inEnv;
output Absyn.Path outPath;
output DAE.Type outType;
algorithm
(outPath,outType) := match (inPath,inType)
(outPath,outType) := matchcontinue (inPath,inType,inEnv)
local
Absyn.Path fn;
String name;
DAE.Type tty;
case (_,tty as DAE.T_FUNCTION(functionAttributes = DAE.FUNCTION_ATTRIBUTES(isBuiltin=DAE.FUNCTION_BUILTIN(SOME(name)))))

case (_,tty as DAE.T_FUNCTION(functionAttributes = DAE.FUNCTION_ATTRIBUTES(isBuiltin=DAE.FUNCTION_BUILTIN(SOME(name)))), _)
equation
true = Flags.isSet(Flags.FAILTRACE);
fn = Absyn.IDENT(name);
false = Absyn.pathEqual(inPath, fn);
print("P1: " +& Env.getEnvNameStr(inEnv) +& "/" +& Absyn.pathString(inPath) +& "\n" +&
"N1: " +& name +& "\n-------------\n");
then
fail();

case (_,DAE.T_FUNCTION(funcArg = _, source = {fn}), _)
equation
true = Flags.isSet(Flags.FAILTRACE);
false = Absyn.pathEqual(inPath, fn);
print("P2: " +& Env.getEnvNameStr(inEnv) +& "/" +& Absyn.pathString(inPath) +& "\n" +&
"N2: " +& Absyn.pathString(fn) +& "\n-------------\n");
then
fail();

case (_,tty as DAE.T_FUNCTION(functionAttributes = DAE.FUNCTION_ATTRIBUTES(isBuiltin=DAE.FUNCTION_BUILTIN(SOME(name)))), _)
equation
fn = Absyn.IDENT(name);
tty = Types.setTypeSource(tty,Types.mkTypeSource(SOME(fn)));
then (fn,tty);

case (_,DAE.T_FUNCTION(funcArg = _, source = {fn})) then (fn,inType);
case (_,DAE.T_FUNCTION(funcArg = _, source = {fn}), _)
then (fn,inType);

else (inPath,inType);
end match;
end matchcontinue;
end deoverloadFuncname;

protected function isTuple
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Script/Interactive.mo
Expand Up @@ -2386,7 +2386,7 @@ algorithm
model_path = Absyn.crefToPath(class_) "class in package" ;
cl = getPathedClassInProgram(model_path, p);
cl = renameComponentInClass(cl, old_comp, new_comp);
w = buildWithin(Absyn.FULLYQUALIFIED(model_path));
w = buildWithin(Absyn.makeFullyQualified(model_path));
p = updateProgram(Absyn.PROGRAM({cl}, w, Absyn.dummyTimeStamp), p);
str = Absyn.pathString(model_path);
paths_2 = stringAppendList({"{",str,"}"});
Expand Down

0 comments on commit 4aa49f0

Please sign in to comment.