Skip to content

Commit

Permalink
- getting the testsuite closer to 100%
Browse files Browse the repository at this point in the history
- more fixes are on the way for redeclares.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9944 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Sep 27, 2011
1 parent ba4a7a8 commit 43c3ef9
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Env.mo
Expand Up @@ -31,7 +31,7 @@

encapsulated package Env
"
file: Env.mo
file: Env.mo
package: Env
description: Environmane management

Expand Down
88 changes: 78 additions & 10 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -8073,14 +8073,12 @@ algorithm
(cache,compenv,ih,store,dae,csets,ty,graph);

// Array variable with unknown dimensions, but no binding
/*
case (cache,env,ih,store,ci_state,DAE.NOMOD(),pre,csets,n,cl,attr,pf,
((dim as DAE.DIM_UNKNOWN()) :: dims),idxs,inst_dims,impl,comment,info,graph)
case (cache,env,ih,store,ci_state,DAE.NOMOD(),pre,n,cl,attr,pf,
((dim as DAE.DIM_UNKNOWN()) :: dims),idxs,inst_dims,impl,comment,info,graph,csets)
equation
Error.addSourceMessage(Error.FAILURE_TO_DEDUCE_DIMS_NO_MOD,{n},info);
then
fail();
*/

// failtrace
case (_,env,ih,_,_,mod,pre,n,_,_,_,_,_,_,_,_,_,_,_)
Expand Down Expand Up @@ -9083,6 +9081,7 @@ algorithm
then
(cache,env_1,ih,updatedComps);

/*
case (cache,env,ih,pre,mods,cref,ci_state,impl,updatedComps)
equation
id = Absyn.crefFirstIdent(cref);
Expand All @@ -9092,6 +9091,7 @@ algorithm
Error.addSourceMessage(Error.COMPILER_WARNING, {str}, info);
then
(cache,env,ih,updatedComps);
*/

// report an error!
case (cache,env,ih,pre,mod,cref,ci_state,impl,updatedComps)
Expand All @@ -9110,6 +9110,62 @@ algorithm
end updateComponentInEnv;

protected function updateComponentInEnv2
" Helper function, checks if the component was already instantiated.
If it was, don't do it again."
input Env.Cache cache;
input Env.Env env;
input Env.Env cenv;
input InstanceHierarchy inIH;
input Prefix.Prefix pre;
input Absyn.Path path;
input String name;
input list<Absyn.Subscript> ad;
input SCode.Element cl;
input SCode.Attributes attr;
input SCode.Prefixes inPrefixes;
input DAE.Attributes dattr;
input Absyn.Info info;
input SCode.Mod m;
input DAE.Mod cmod;
input DAE.Mod mod;
input Absyn.ComponentRef cref;
input ClassInf.State ci_state;
input Boolean impl;
input HashTable5.HashTable updatedComps;
output Env.Cache outCache;
output Env.Env outEnv;
output InstanceHierarchy outIH;
output HashTable5.HashTable outUpdatedComps;
algorithm
(outCache,outEnv,outIH,outUpdatedComps) := matchcontinue (cache,env,cenv,inIH,pre,path,name,ad,cl,attr,inPrefixes,dattr,info,m,cmod,mod,cref,ci_state,impl,updatedComps)
local
DAE.Type ty;
DAE.Mod m_1,classmod,mm,mod_1,mod_2,mod_3;
list<Env.Frame> compenv;
Option<DAE.EqMod> eq;
list<DAE.Dimension> dims;
DAE.Binding binding;
Absyn.ComponentRef owncref;
InstanceHierarchy ih;
SCode.Visibility vis;

case (cache,env,cenv,ih,pre,path,name,ad,cl,attr,_,dattr,info,m,cmod,mod,cref,ci_state,impl,updatedComps)
equation
ErrorExt.setCheckpoint("Inst.updateComponentInEnv2");
(cache,env,ih,updatedComps) = updateComponentInEnv2_dispatch(cache,env,cenv,ih,pre,path,name,ad,cl,attr,inPrefixes,dattr,info,m,cmod,mod,cref,ci_state,impl,updatedComps);
ErrorExt.delCheckpoint("Inst.updateComponentInEnv2");
then
(cache,env,ih,updatedComps);

case (cache,env,cenv,ih,pre,path,name,ad,cl,attr,_,dattr,info,m,cmod,mod,cref,ci_state,impl,updatedComps)
equation
ErrorExt.rollBack("Inst.updateComponentInEnv2");
then
fail();
end matchcontinue;
end updateComponentInEnv2;

protected function updateComponentInEnv2_dispatch
" Helper function, checks if the component was already instantiated.
If it was, don't do it again."
input Env.Cache cache;
Expand Down Expand Up @@ -9215,7 +9271,7 @@ algorithm
eq = Mod.modEquation(m_1);

owncref = Absyn.CREF_IDENT(name,{});
(cache,dims) = elabArraydim(cache,env,owncref,path,ad,eq,impl,NONE(),true, false,pre,info,{})
(cache,dims) = elabArraydim(cache,env,owncref,path,ad,eq,impl,NONE(),true,false,pre,info,{})
"The variable declaration and the (optional) equation modification are inspected for array dimensions." ;

/*
Expand All @@ -9231,7 +9287,7 @@ algorithm

// Instantiate the component */
(cache,compenv,ih,_,_,_,ty,_) =
instVar(cache, cenv, ih, UnitAbsyn.noStore, ci_state, classmod, pre,
instVar(cache, cenv, ih, UnitAbsyn.noStore, ci_state, m_1 /* classmod */, pre,
name, cl, attr, inPrefixes, dims, {}, {}, impl, NONE(), info, ConnectionGraph.EMPTY, Connect.emptySet, env);

// print("updateComponentInEnv -> 1 component: " +& n +& " ty: " +& Types.printTypeStr(ty) +& "\n");
Expand All @@ -9253,7 +9309,7 @@ algorithm
//Debug.traceln("- Inst.updateComponentInEnv2 failed");
then fail();
end matchcontinue;
end updateComponentInEnv2;
end updateComponentInEnv2_dispatch;

protected function updateComponentInEnv3
input Env.Cache inCache;
Expand Down Expand Up @@ -15237,21 +15293,33 @@ algorithm
_,impl,inst_dims,pre,mods,info)
// we have reference to ourself, try to instantiate type.
equation
ErrorExt.setCheckpoint("Inst.removeSelfReferenceAndUpdate");
cl2 = removeCrefFromCrefs(cl1, c1);
(cache,c,cenv) = Lookup.lookupClass(cache,env, sty, true);
(cache,dims) = elabArraydim(cache,cenv, c1, sty, ad,NONE(), impl,NONE(),true, false,pre,info,inst_dims);
(cache,dims) = elabArraydim(cache,cenv, c1, sty, ad, NONE(), impl, NONE(), true, false, pre, info, inst_dims);

(cache,compenv,ih,store,_,_,ty,_) =
instVar(cache,cenv,ih, store,state, DAE.NOMOD(), pre, n, c, attr,
inPrefixes, dims, {}, inst_dims, true,NONE(),info,ConnectionGraph.EMPTY, Connect.emptySet, env);
instVar(cache, cenv, ih, store, state, DAE.NOMOD(), pre, n, c, attr,
inPrefixes, dims, {}, inst_dims, true, NONE(), info, ConnectionGraph.EMPTY, Connect.emptySet, env);

// print("component: " +& n +& " ty: " +& Types.printTypeStr(ty) +& "\n");

io = SCode.prefixesInnerOuter(inPrefixes);
vis = SCode.prefixesVisibility(inPrefixes);
new_var = DAE.TYPES_VAR(n,DAE.ATTR(flowPrefix,streamPrefix,param,dir,io),vis,ty,DAE.UNBOUND(),NONE());
env = Env.updateFrameV(env, new_var, Env.VAR_TYPED(), compenv);
ErrorExt.delCheckpoint("Inst.removeSelfReferenceAndUpdate");
then
(cache,env,ih,store,cl2);

case(cache,env,ih,store,cl1,c1 as Absyn.CREF_IDENT(name = n) ,sty,state,
(attr as SCode.ATTR(arrayDims = ad, flowPrefix = flowPrefix, streamPrefix = streamPrefix,
variability = param, direction = dir)),
_,impl,inst_dims,pre,mods,info)
equation
ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate");
then
fail();

case(cache,env,ih,store,cl1,c1,_,_,_,_,_,_,_,_,_)
equation
Expand Down
68 changes: 46 additions & 22 deletions Compiler/FrontEnd/InstExtends.mo
Expand Up @@ -180,11 +180,11 @@ algorithm
ht = getLocalIdentList(importelts,ht,getLocalIdentElement);

//tmp = tick(); Debug.traceln("try fix local idents " +& intString(tmp));
(cache,compelts1) = fixLocalIdents(cache, cenv1, compelts1, ht);
(cache,eq1_1) = fixList(cache, cenv1, eq1_1, ht,fixEquation);
(cache,ieq1_1) = fixList(cache, cenv1, ieq1_1, ht,fixEquation);
(cache,alg1_1) = fixList(cache, cenv1, alg1_1, ht,fixAlgorithm);
(cache,ialg1_1) = fixList(cache, cenv1, ialg1_1, ht,fixAlgorithm);
(cache,compelts1) = fixLocalIdents(cache, cenv3, compelts1, ht);
(cache,eq1_1) = fixList(cache, cenv3, eq1_1, ht,fixEquation);
(cache,ieq1_1) = fixList(cache, cenv3, ieq1_1, ht,fixEquation);
(cache,alg1_1) = fixList(cache, cenv3, alg1_1, ht,fixAlgorithm);
(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)
Expand Down Expand Up @@ -1285,9 +1285,10 @@ algorithm
local
String id;
Absyn.Path path1,path2;

case (cache,env,path1 as Absyn.FULLYQUALIFIED(_),ht)
equation
Debug.fprintln("debug", "Path FULLYQUAL: " +& Absyn.pathString(path));
//Debug.fprintln("debug", "Path FULLYQUAL: " +& Absyn.pathString(path));
then
(cache,path1);

Expand All @@ -1296,7 +1297,7 @@ algorithm
id = Absyn.pathFirstIdent(path1);
path2 = BaseHashTable.get(id,ht);
path2 = Absyn.pathReplaceFirstIdent(path1,path2);
Debug.fprintln("debug", "Replacing: " +& Absyn.pathString(path1) +& " with " +& Absyn.pathString(path2) +& " s:" +& Env.printEnvPathStr(env));
//Debug.fprintln("debug", "Replacing: " +& Absyn.pathString(path1) +& " with " +& Absyn.pathString(path2) +& " s:" +& Env.printEnvPathStr(env));
then (cache,path2);
/*
// when a class is partial, do not fully qualify as it SHOULD POINT TO THE ONE IN THE DERIVED CLASS!
Expand All @@ -1317,19 +1318,42 @@ algorithm

case (cache,env,path,ht)
equation
Debug.fprintln("debug","Try makeFullyQualified " +& Absyn.pathString(path));
//Debug.fprintln("debug","Try makeFullyQualified " +& Absyn.pathString(path));
(cache,path) = Inst.makeFullyQualified(cache,env,path);
Debug.fprintln("debug","FullyQual: " +& Absyn.pathString(path));
//Debug.fprintln("debug","FullyQual: " +& Absyn.pathString(path));
then (cache,path);

case (cache,env,path,_)
equation
Debug.fprintln("debug", "Path not fixed: " +& Absyn.pathString(path) +& "\n");
//Debug.fprintln("debug", "Path not fixed: " +& Absyn.pathString(path) +& "\n");
then
(cache,path);
end matchcontinue;
end fixPath;

protected function lookupVarNoErrorMessage
input Env.Cache inCache;
input Env.Env inEnv;
input DAE.ComponentRef inComponentRef;
output Env.Env outEnv;
output String id;
algorithm
(outEnv, id) := matchcontinue(inCache, inEnv, inComponentRef)
case (inCache, inEnv, inComponentRef)
equation
ErrorExt.setCheckpoint("InstExtends.lookupVarNoErrorMessage");
(_,_,_,_,_,_,outEnv,_,id) = Lookup.lookupVar(inCache, inEnv, inComponentRef);
ErrorExt.rollBack("InstExtends.lookupVarNoErrorMessage");
then
(outEnv, id);
case (_, _, _)
equation
ErrorExt.rollBack("InstExtends.lookupVarNoErrorMessage");
then
fail();
end matchcontinue;
end lookupVarNoErrorMessage;

protected function fixCref
" All of the fix functions do the following:
Analyzes the SCode datastructure and replace paths with a new path (from
Expand All @@ -1350,24 +1374,24 @@ algorithm
case (cache,env,cref,ht)
equation
id = Absyn.crefFirstIdent(cref);
Debug.fprintln("debug","Try ht lookup " +& id);
//Debug.fprintln("debug","Try ht lookup " +& id);
path = BaseHashTable.get(id,ht);
Debug.fprintln("debug","Got path " +& Absyn.pathString(path));
//Debug.fprintln("debug","Got path " +& Absyn.pathString(path));
cref = Absyn.crefReplaceFirstIdent(cref,path);
Debug.fprintln("debug", "Cref HT fixed: " +& Absyn.printComponentRefStr(cref));
//Debug.fprintln("debug", "Cref HT fixed: " +& Absyn.printComponentRefStr(cref));
then (cache,cref);

// try lookup var
// try lookup var (constant in a package?)
case (cache,env,cref,ht)
equation
id = Absyn.crefFirstIdent(cref);
cref_ = ComponentReference.makeCrefIdent(id,DAE.ET_OTHER(),{});
Debug.fprintln("debug","Try lookupV " +& id);
(_,_,_,_,_,_,env,_,id) = Lookup.lookupVar(cache,env,cref_);
Debug.fprintln("debug","Got env " +& intString(listLength(env)));
//Debug.fprintln("debug","Try lookupV " +& id);
(env,id) = lookupVarNoErrorMessage(cache,env,cref_);
//Debug.fprintln("debug","Got env " +& intString(listLength(env)));
env = Env.openScope(env,SCode.ENCAPSULATED(),SOME(id),NONE());
cref = Absyn.crefReplaceFirstIdent(cref,Env.getEnvName(env));
Debug.fprintln("debug", "Cref VAR fixed: " +& Absyn.printComponentRefStr(cref));
//Debug.fprintln("debug", "Cref VAR fixed: " +& Absyn.printComponentRefStr(cref));
then (cache,cref);

/*// when a class is partial, do not fully qualify as it SHOULD POINT TO THE ONE IN THE DERIVED CLASS!
Expand All @@ -1391,17 +1415,17 @@ algorithm
case (cache,env,cref,ht)
equation
id = Absyn.crefFirstIdent(cref);
Debug.fprintln("debug","Try lookupC " +& id);
//Debug.fprintln("debug","Try lookupC " +& id);
(_,_,env) = Lookup.lookupClass(cache,env,Absyn.IDENT(id),false);
Debug.fprintln("debug","Got env " +& intString(listLength(env)));
//Debug.fprintln("debug","Got env " +& intString(listLength(env)));
env = Env.openScope(env,SCode.ENCAPSULATED(),SOME(id),NONE());
cref = Absyn.crefReplaceFirstIdent(cref,Env.getEnvName(env));
Debug.fprintln("debug", "Cref CLASS fixed: " +& Absyn.printComponentRefStr(cref));
//Debug.fprintln("debug", "Cref CLASS fixed: " +& Absyn.printComponentRefStr(cref));
then (cache,cref);

case (cache,env,cref,_)
equation
Debug.fprintln("debug", "Cref not fixed: " +& Absyn.printComponentRefStr(cref));
//Debug.fprintln("debug", "Cref not fixed: " +& Absyn.printComponentRefStr(cref));
then
(cache,cref);

Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -1239,6 +1239,7 @@ algorithm
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);

env3 = Env.openScope(env2, encflag, SOME(n), Env.restrictionToScopeType(r));
ci_state = ClassInf.start(r, Env.getEnvName(env3));
// Debug.fprintln("instTrace", "LOOKUP VAR IN PACKAGES ICD: " +& Env.printEnvPathStr(env3) +& " var: " +& ComponentReference.printComponentRefStr(cref));
Expand Down
7 changes: 6 additions & 1 deletion Compiler/FrontEnd/Mod.mo
Expand Up @@ -844,16 +844,21 @@ algorithm
list<Env.Frame> env;
Prefix.Prefix pre;
list<Absyn.Subscript> subcr;
list<DAE.Subscript> sList;
list<DAE.SubMod> smods;

case (SCode.NAMEMOD(ident = i,A = m),env,pre)
equation
m_1 = elabUntypedMod(m, env, pre);
then
{DAE.NAMEMOD(i,m_1)};
case (SCode.IDXMOD(subscriptLst = subcr,an = m),env,pre)
equation
(_,sList,DAE.C_CONST()) = Static.elabSubscripts(Env.emptyCache(), env, subcr, true, pre, Absyn.dummyInfo);
m_1 = elabUntypedMod(m, env, pre);
smods = makeIdxmods(sList, m_1);
then
{DAE.IDXMOD({-1},m_1)};
smods;
end match;
end elabUntypedSubmod;

Expand Down
36 changes: 33 additions & 3 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -9815,9 +9815,10 @@ algorithm
// MetaModelica Partial Function
case (cache,env,c,impl,doVect,pre,evalCref,info)
equation
//true = RTOpts.debugFlag("fnptr") or RTOpts.acceptMetaModelicaGrammar();
// true = RTOpts.debugFlag("fnptr") or RTOpts.acceptMetaModelicaGrammar();
path = Absyn.crefToPath(c);
(cache,{t}) = Lookup.lookupFunctionsInEnv(cache,env,path,info);
// call the lookup function that removes errors when it fails!
(cache, {t}) = lookupFunctionsInEnvNoError(cache, env, path, info);
(isBuiltin,isBuiltinFn,path) = isBuiltinFunc(path,t);
isBuiltinFnOrInlineBuiltin = not valueEq(DAE.FUNCTION_NOT_BUILTIN(),isBuiltin);
(tt,optPath) = t;
Expand All @@ -9831,7 +9832,7 @@ algorithm
(cache,Util.SUCCESS()) = instantiateDaeFunction(cache,env,path,isBuiltinFn,NONE(),true);
then
(cache,SOME((exp,DAE.PROP(t,DAE.C_CONST()),DAE.dummyAttrConst /* RO */)));

// MetaModelica extension
case (cache,env,Absyn.CREF_IDENT("NONE",{}),impl,doVect,_,_,info)
equation
Expand Down Expand Up @@ -9877,6 +9878,35 @@ algorithm
end matchcontinue;
end elabCref1;

protected function lookupFunctionsInEnvNoError
input Env.Cache inCache;
input Env.Env inEnv;
input Absyn.Path inPath;
input Absyn.Info inInfo;
output Env.Cache outCache;
output list<DAE.Type> outTypesTypeLst;
algorithm
(outCache, outTypesTypeLst) := matchcontinue(inCache, inEnv, inPath, inInfo)

case (inCache, inEnv, inPath, inInfo)
equation
ErrorExt.setCheckpoint("Static.lookupFunctionsInEnvNoError");
(outCache, outTypesTypeLst) = Lookup.lookupFunctionsInEnv(inCache, inEnv, inPath, inInfo);
// rollback lookup errors!
ErrorExt.rollBack("Static.lookupFunctionsInEnvNoError");
then
(outCache, outTypesTypeLst);

case (inCache, inEnv, inPath, inInfo)
equation
// rollback lookup errors!
ErrorExt.rollBack("Static.lookupFunctionsInEnvNoError");
then
fail();
end matchcontinue;
end lookupFunctionsInEnvNoError;


protected function evaluateEmptyVariable
"A variable with a 0-length dimension can be evaluated.
This is good to do because otherwise the C-code contains references to non-existing variables"
Expand Down

0 comments on commit 43c3ef9

Please sign in to comment.