Skip to content

Commit

Permalink
- Removed some of the ErrorExt.rollback and setCheckpoint I added for…
Browse files Browse the repository at this point in the history
… pointless error messages.

- We now check if the modifications could possibly generate basic types (only start,nominal,etc NAMEMOD's allowed).
  + This also removes the old error messages.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5119 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 10, 2010
1 parent dab774d commit e01b561
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 19 deletions.
25 changes: 14 additions & 11 deletions Compiler/Inst.mo
Expand Up @@ -1632,8 +1632,7 @@ algorithm
end matchcontinue;
end instClassBasictype;

public function instClassIn
"function: instClassIn
public function instClassIn "
This rule instantiates the contents of a class definition, with a new
environment already setup.
The *implicitInstantiation* boolean indicates if the class should be
Expand Down Expand Up @@ -2680,8 +2679,7 @@ algorithm
end matchcontinue;
end handleUnitChecking;

protected function instClassdef
"function: instClassdef
protected function instClassdef "
There are two kinds of class definitions, either explicit
definitions SCode.PARTS() or
derived definitions SCode.DERIVED() or
Expand Down Expand Up @@ -3719,7 +3717,7 @@ algorithm
case (cache,env,ih,store,{SCode.EXTENDS(baseClassPath = path,modifications = mod)},{},mods,inst_dims)
equation
ErrorExt.setCheckpoint();
(cache,m_1,_) = Mod.elabModOrRollback(cache,env, Prefix.NOPRE(), mod, true);
(cache,m_1,_) = Mod.elabModForBasicType(cache,env, Prefix.NOPRE(), mod, true);
m_2 = Mod.merge(mods, m_1, env, Prefix.NOPRE());
(cache,cdef,cenv) = Lookup.lookupClass(cache,env, path, true);
(cache,env_1,ih,store,dae,_,ty,tys,st) = instClassBasictype(cache,cenv,ih, store,m_2, Prefix.NOPRE(), Connect.emptySet, cdef, inst_dims, false, INNER_CALL());
Expand Down Expand Up @@ -3800,7 +3798,7 @@ Handles the fail case rollbacks/deleteCheckpoint of errors.
InstanceHierarchy ih;
case (cache,env,ih,store,{SCode.EXTENDS(baseClassPath = path,modifications = mod)},(_ :: _),mods,inst_dims) /* Inherits baseclass -and- has components */
equation
(cache,m_1,_) = Mod.elabMod(cache,env, Prefix.NOPRE(), mod, true) "impl" ;
(cache,m_1,_) = Mod.elabModForBasicType(cache,env, Prefix.NOPRE(), mod, true);
(cache,cdef,cenv) = Lookup.lookupClass(cache,env, path, true);
cdef_1 = SCode.classSetPartial(cdef, false);
(cache,env_1,ih,_,dae,_,ty,st,_,_) = instClass(cache,cenv,ih,store, m_1, Prefix.NOPRE(), Connect.emptySet, cdef_1, inst_dims, false, INNER_CALL(), ConnectionGraph.EMPTY) "impl" ;
Expand All @@ -3813,8 +3811,10 @@ Handles the fail case rollbacks/deleteCheckpoint of errors.
then
();
// if not error above, then do not report error at all, try another case in instClassdef.
case (_,_,_,_,_,_,_,_) equation
ErrorExt.rollBack(); then ();
case (_,_,_,_,_,_,_,_)
equation
ErrorExt.rollBack();
then ();
end matchcontinue;
end instBasictypeBaseclass2;

Expand Down Expand Up @@ -4698,12 +4698,13 @@ algorithm
SCode.ClassDef classDef;
Absyn.Info info;
SCode.BaseClassList bc;
Absyn.Path p;

case ({},_) then {};

case ((SCode.COMPONENT(component = a,innerOuter=io,finalPrefix = b,replaceablePrefix = c,
protectedPrefix = d,attributes = e,typeSpec = f,modifications = g,
comment = comment,condition=cond,info=infoOpt,cc=cc,baseClassPath = bc) :: xs),tp)
comment = comment,condition=cond,info=infoOpt,cc=cc,baseClassPath = bc) :: xs),tp as (p,_))
equation
res = addInheritScope(xs, tp);
then
Expand Down Expand Up @@ -7595,10 +7596,12 @@ algorithm
initialAlgorithmLst={},
externalDecl=_)),
dims,impl)
local list<SCode.Element> els, extendsels; SCode.Path path;
local
list<SCode.Element> els, extendsels;
SCode.Path path;
equation
(_,_,{SCode.EXTENDS(path, mod,_)},{}) = splitElts(els); // ONLY ONE extends!
(cache,mod_1,fdae) = Mod.elabMod(cache,env, pre, mod, impl);
(cache,mod_1,fdae) = Mod.elabModForBasicType(cache,env, pre, mod, impl);
mods_2 = Mod.merge(mods, mod_1, env, pre);
(cache,cl,cenv) = Lookup.lookupClass(cache,env, path, true);
(cache,res,cl,fdae2) = getUsertypeDimensions(cache,env,mods_2,pre,cl,{},impl);
Expand Down
65 changes: 57 additions & 8 deletions Compiler/Mod.mo
Expand Up @@ -60,7 +60,6 @@ protected import DAEUtil;
protected import Dump;
protected import Debug;
protected import Error;
protected import ErrorExt;
protected import Exp;
protected import Inst;
protected import PrefixUtil;
Expand Down Expand Up @@ -159,8 +158,8 @@ algorithm
end matchcontinue;
end elabMod;

public function elabModOrRollback "
Same as elabMod, but if it fails it will rollback error messages."
public function elabModForBasicType "
Same as elabMod, but if a named Mod is not part of a basic type, fail instead."
input Env.Cache inCache;
input Env.Env inEnv;
input Prefix.Prefix inPrefix;
Expand All @@ -173,14 +172,64 @@ algorithm
(outCache,outMod,outDae) := matchcontinue (inCache,inEnv,inPrefix,inMod,inBoolean)
case (inCache,inEnv,inPrefix,inMod,inBoolean)
equation
(outCache,outMod,outDae) = elabMod(inCache,inEnv,inPrefix,inMod,inBoolean);
checkIfModsAreBasicTypeMods(inMod);
(outCache,outMod,outDae) = elabMod(inCache,inEnv,inPrefix,inMod,inBoolean);
then (outCache,outMod,outDae);
case (inCache,inEnv,inPrefix,inMod,inBoolean)
end matchcontinue;
end elabModForBasicType;

protected constant list<String> basicTypeMods = {
"quantity",
"unit",
"displayUnit",
"min",
"max",
"start",
"fixed",
"nominal",
"stateSelect"
};

protected function checkIfModsAreBasicTypeMods "
Verifies that a list of submods only have named modifications that could be
used for basic types.
"
input SCode.Mod mod;
algorithm
_ := matchcontinue mod
local
list<SCode.SubMod> subs;
case SCode.NOMOD() then ();
case SCode.MOD(subModLst = subs)
equation
ErrorExt.rollBack();
then fail();
checkIfSubmodsAreBasicTypeMods(subs);
then ();
end matchcontinue;
end checkIfModsAreBasicTypeMods;

protected function checkIfSubmodsAreBasicTypeMods "
Verifies that a list of submods only have named modifications that could be
used for basic types.
"
input list<SCode.SubMod> subs;
algorithm
_ := matchcontinue subs
local
SCode.Mod mod;
String ident;
case {} then ();
case SCode.NAMEMOD(ident = ident)::subs
equation
true = listMember(ident,basicTypeMods);
checkIfSubmodsAreBasicTypeMods(subs);
then ();
case SCode.IDXMOD(an = mod)::subs
equation
checkIfModsAreBasicTypeMods(mod);
checkIfSubmodsAreBasicTypeMods(subs);
then ();
end matchcontinue;
end elabModOrRollback;
end checkIfSubmodsAreBasicTypeMods;

protected function elabModRedeclareElements
input Env.Cache inCache;
Expand Down

0 comments on commit e01b561

Please sign in to comment.