Skip to content

Commit

Permalink
- Absyn.mo: add crefFirstEqual
Browse files Browse the repository at this point in the history
- ClassInf.mo: add stateToSCodeRestriction
- Expression.mo: add DAE.ENUM_LITERAL in unelabExp
- Inst.mo: try to handle Modelica.Mechanics.MultiBody.Examples.Elementary.Surfaces but it doesn't work yet.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13612 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 24, 2012
1 parent 775c773 commit 9acb77f
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 11 deletions.
11 changes: 11 additions & 0 deletions Compiler/FrontEnd/Absyn.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4300,6 +4300,17 @@ algorithm
end matchcontinue;
end crefEqual;

public function crefFirstEqual
"@author: adrpo
a.b, a -> true
b.c, a -> false"
input ComponentRef iCr1;
input ComponentRef iCr2;
output Boolean outBoolean;
algorithm
outBoolean := stringEq(crefFirstIdent(iCr1),crefFirstIdent(iCr2));
end crefFirstEqual;

public function subscriptsEqual "
Checks if two subscript lists are equal.
See also crefEqual."
Expand Down
31 changes: 31 additions & 0 deletions Compiler/FrontEnd/ClassInf.mo
Original file line number Diff line number Diff line change
Expand Up @@ -712,5 +712,36 @@ algorithm
end match;
end isTypeOrRecord;

public function stateToSCodeRestriction
"@author: adrpo
ClassInf.State -> SCode.Restriction"
input State inState;
output SCode.Restriction outRestriction;
output Absyn.Path outPath;
algorithm
(outRestriction, outPath) := match (inState)
local Absyn.Path p; Boolean isExpandable;

case UNKNOWN(p) then (SCode.R_CLASS(),p);
case OPTIMIZATION(p) then (SCode.R_OPTIMIZATION(),p);
case MODEL(p) then (SCode.R_MODEL(),p);
case RECORD(p) then (SCode.R_RECORD(),p);
case BLOCK(p) then (SCode.R_BLOCK(),p) ;
case CONNECTOR(p,isExpandable) then (SCode.R_CONNECTOR(isExpandable),p);
case TYPE(p) then (SCode.R_TYPE(),p);
case PACKAGE(p) then (SCode.R_PACKAGE(),p) ;
case FUNCTION(p) then (SCode.R_FUNCTION(SCode.FR_NORMAL_FUNCTION()),p);
case ENUMERATION(p) then (SCode.R_ENUMERATION(),p);
case TYPE_INTEGER(p) then (SCode.R_PREDEFINED_INTEGER(),p);
case TYPE_REAL(p) then (SCode.R_PREDEFINED_REAL(),p);
case TYPE_STRING(p) then (SCode.R_PREDEFINED_STRING(),p);
case TYPE_BOOL(p) then (SCode.R_PREDEFINED_BOOLEAN(),p);
case TYPE_ENUM(p) then (SCode.R_PREDEFINED_ENUMERATION(),p);
/* Meta Modelica extensions */
case META_UNIONTYPE(p) then (SCode.R_UNIONTYPE(),p);
case META_RECORD(p) then (SCode.R_METARECORD(p, 0, false),p);
end match;
end stateToSCodeRestriction;

end ClassInf;

5 changes: 5 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ algorithm
case (DAE.RCONST(real = r)) then Absyn.REAL(r);
case (DAE.SCONST(string = s)) then Absyn.STRING(s);
case (DAE.BCONST(bool = b)) then Absyn.BOOL(b);
case (DAE.ENUM_LITERAL(name = path))
equation
cr_1 = Absyn.pathToCref(path);
then Absyn.CREF(cr_1);

case (DAE.CREF(componentRef = cr))
equation
cr_1 = ComponentReference.unelabCref(cr);
Expand Down
65 changes: 54 additions & 11 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ protected import ValuesUtil;
protected import System;
protected import SCodeFlatten;
protected import SCodeDump;
protected import SCodeMod;
//protected import Database;

public function newIdent
Expand Down Expand Up @@ -6800,12 +6801,12 @@ algorithm
crefs1 = getCrefFromMod(m);
crefs2 = getCrefFromDim(ad);
crefs3 = getCrefFromCond(cond);
crefs = List.flatten({crefs1, crefs2, crefs3});
crefs = List.unionList({crefs1, crefs2, crefs3});

// can call instVar
(cache, env, ih, store, crefs) = removeSelfReferenceAndUpdate(cache,
env, ih, store, crefs, own_cref, t, ci_state, attr, prefixes,
impl, inst_dims, pre, mods, info);
impl, inst_dims, pre, mods, m, info);

// can call instVar
(cache, env2, ih) = updateComponentsInEnv(cache, env, ih, pre, mods, crefs, ci_state, impl);
Expand Down Expand Up @@ -9192,7 +9193,7 @@ algorithm
equation
l1 = getCrefFromSubmods(submods);
l2 = Absyn.getCrefFromExp(e,true);
res = listAppend(l2, l1);
res = List.union(l2, l1);
then
res;
case (SCode.MOD(subModLst = submods,binding = NONE()))
Expand Down Expand Up @@ -9227,7 +9228,7 @@ algorithm
equation
l1 = getCrefFromDim(rest);
l2 = Absyn.getCrefFromExp(exp,true);
res = listAppend(l1, l2);
res = List.union(l1, l2);
then
res;
case ((Absyn.NOSUB() :: rest))
Expand Down Expand Up @@ -16125,6 +16126,7 @@ protected function removeSelfReferenceAndUpdate
input InstDims inst_dims;
input Prefix.Prefix pre;
input DAE.Mod mods;
input SCode.Mod scodeMod;
input Absyn.Info info;
output Env.Cache outCache;
output Env.Env outEnv;
Expand All @@ -16133,7 +16135,7 @@ protected function removeSelfReferenceAndUpdate
output list<Absyn.ComponentRef> o1;
algorithm
(outCache,outEnv,outIH,outStore,o1) :=
matchcontinue(inCache,inEnv,inIH,inStore,inRefs,inRef,inPath,inState,iattr,inPrefixes,impl,inst_dims,pre,mods,info)
matchcontinue(inCache,inEnv,inIH,inStore,inRefs,inRef,inPath,inState,iattr,inPrefixes,impl,inst_dims,pre,mods,scodeMod,info)
local
Absyn.Path sty;
Absyn.ComponentRef c1;
Expand All @@ -16157,8 +16159,11 @@ algorithm
InstanceHierarchy ih;
Absyn.InnerOuter io;
UnitAbsyn.InstStore store;
DAE.Mod dM;
SCode.Mod sM;
String mname;

case(cache,env,ih,store,cl1,c1,_,_,_,_,_,_,_,_,_)
case(cache,env,ih,store,cl1,c1,_,_,_,_,_,_,_,_,_,_)
equation
cl2 = removeCrefFromCrefs(cl1, c1);
i1 = listLength(cl2);
Expand All @@ -16167,17 +16172,17 @@ algorithm
then
(cache,env,ih,store,cl2);

case(cache,env,ih,store,cl1,c1 as Absyn.CREF_IDENT(name = n) ,sty,state,
case(cache,env,ih,store,cl1,c1 as Absyn.CREF_IDENT(name = n),sty,state,
(attr as SCode.ATTR(arrayDims = ad, connectorType = ct,
parallelism= prl1, variability = var1, direction = dir)),
_,_,_,_,_,_)
_,_,_,_,_,_,_)
// 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,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);
Expand All @@ -16192,13 +16197,51 @@ algorithm
then
(cache,env,ih,store,cl2);

case(_, _, _, _, _, Absyn.CREF_IDENT(name = n), _, _, _, _, _, _, _, _, _)
case(_, _, _, _, _, Absyn.CREF_IDENT(name = n), _, _, _, _, _, _, _, _, _, _)
equation
ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate");
then
fail();

/*
// adrpo, try to remove the modifier containing the self expression and use that to instantiate the type!
case(cache,env,ih,store,cl1,c1 as Absyn.CREF_IDENT(name = n), sty, state,
(attr as SCode.ATTR(arrayDims = ad, connectorType = ct,
parallelism= prl1, variability = var1, direction = dir)),
_,_,_,_,_,_,_)
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);

sM = SCodeMod.removeCrefPrefixFromModExp(scodeMod, inRef);

//(cache, dM) = elabMod(cache, env, ih, pre, sM, impl, info);
dM = Mod.elabUntypedMod(sM, env, pre);

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

case(cache,env,ih,store,cl1,c1,_,_,_,_,_,_,_,_,_)
// print("component: " +& n +& " ty: " +& Types.printTypeStr(ty) +& "\n");

io = SCode.prefixesInnerOuter(inPrefixes);
vis = SCode.prefixesVisibility(inPrefixes);
new_var = DAE.TYPES_VAR(n,DAE.ATTR(ct,prl1,var1,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(_, _, _, _, _, Absyn.CREF_IDENT(name = n), _, _, _, _, _, _, _, _, _, _)
equation
ErrorExt.rollBack("Inst.removeSelfReferenceAndUpdate");
then
fail();
*/

case(cache,env,ih,store,cl1,c1,_,_,_,_,_,_,_,_,_,_)
equation
cl2 = removeCrefFromCrefs(cl1, c1);
then
Expand Down

0 comments on commit 9acb77f

Please sign in to comment.