Skip to content

Commit

Permalink
- Added new module SCodeDependency for SCode dependency analysis.
Browse files Browse the repository at this point in the history
- Added new debugflag +d=scodeFlatten to enable SCode flattening.
- Removed environment path when printing error for components with same name,
  since it sometimes printed nonsense paths otherwise.
- Updated test cases that changed due to above change.
- Renamed absynExpOption to binding in SCode.Mod.
- Added function Util.listMap02.
- Added some more builtin Modelica functions (assert, constrain).


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7965 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Feb 18, 2011
1 parent f73b1bf commit 3d07acb
Show file tree
Hide file tree
Showing 14 changed files with 597 additions and 235 deletions.
27 changes: 27 additions & 0 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -3862,6 +3862,33 @@ algorithm
end match;
end crefToPath;

public function crefToPathIgnoreSubs
"Converts a ComponentRef to a Path, ignoring any subscripts."
input ComponentRef inComponentRef;
output Path outPath;
algorithm
outPath := match(inComponentRef)
local
Ident i;
Path p;
ComponentRef c;

case CREF_IDENT(name = i) then IDENT(i);

case CREF_QUAL(name = i, componentRef = c)
equation
p = crefToPathIgnoreSubs(c);
then
QUALIFIED(i, p);

case CREF_FULLYQUALIFIED(componentRef = c)
equation
p = crefToPathIgnoreSubs(c);
then
FULLYQUALIFIED(p);
end match;
end crefToPathIgnoreSubs;

public function pathToCref "function: pathToCref
This function converts a Path to a ComponentRef."
input Path inPath;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -2561,7 +2561,7 @@ algorithm
SCode.SubMod submod;
SCode.Mod mod;
String id;
case (SCode.NAMEMOD(ident = id,A=SCode.MOD(absynExpOption=SOME((Absyn.BOOL(value=true),_)))) :: rest,namedAnnotation)
case (SCode.NAMEMOD(ident = id,A=SCode.MOD(binding=SOME((Absyn.BOOL(value=true),_)))) :: rest,namedAnnotation)
equation
true = id ==& namedAnnotation;
then true;
Expand Down
43 changes: 29 additions & 14 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -204,7 +204,7 @@ algorithm
InstanceHierarchy oIH1, oIH2, iIH;
case (cache,iIH,p)
equation
//p = SCodeFlatten.flattenProgram(p);
p = SCodeFlatten.flattenProgram(p);
// Debug.fprintln("insttr", "instantiate");
pnofunc = Util.listSelect(p, isNotFunction);
pfunc = Util.listSelect(p, SCode.isFunction);
Expand Down Expand Up @@ -307,7 +307,7 @@ algorithm

case (cache,ih,(cdecls as (_ :: _)),(path as Absyn.IDENT(name = name2))) /* top level class */
equation
//cdecls = SCodeFlatten.flattenProgram(cdecls);
cdecls = SCodeFlatten.flattenClassInProgram(inPath, cdecls);
(cache,env) = Builtin.initialEnv(cache);
(cache,env_1,ih,dae1) = instClassDecls(cache, env, ih, cdecls, path);
(cache,env_2,ih,dae2) = instClassInProgram(cache, env_1, ih, cdecls, path);
Expand All @@ -327,7 +327,7 @@ algorithm

case (cache,ih,(cdecls as (_ :: _)),(path as Absyn.QUALIFIED(name = name))) /* class in package */
equation
//cdecls = SCodeFlatten.flattenProgram(cdecls);
cdecls = SCodeFlatten.flattenClassInProgram(inPath, cdecls);
pathstr = Absyn.pathString(path);

//System.startTimer();
Expand Down Expand Up @@ -3983,6 +3983,10 @@ algorithm outComps := matchcontinue(acrefs,remainingComps,className,existing)
list<String> names;
DAE.ComponentRef cref_;
case({},_,_,_) then {};

case (Absyn.CREF_FULLYQUALIFIED(acr) :: acrefs, remainingComps, className, existing)
then extractConstantPlusDeps3(acr :: acrefs, remainingComps, className, existing);

case(Absyn.CREF_QUAL(s1,_,(acr as Absyn.CREF_IDENT(s2,_)))::acrefs,remainingComps,className,existing)
equation
true = stringEq(className,s1); // in same scope look up.
Expand Down Expand Up @@ -5459,7 +5463,7 @@ algorithm
((comp as SCode.COMPONENT(component = n,typeSpec = (tss as Absyn.TPATH(tpp, _)), info = aInfo)),cmod)::xs, _, _, instdims,impl)
equation
true = stringEq(n, Absyn.pathLastIdent(tpp));
ns = Env.printEnvPathStr(env) +& "." +& Absyn.pathString(tpp);
ns = Absyn.pathString(tpp);
Error.addSourceMessage(Error.COMPONENT_NAME_SAME_AS_TYPE_NAME, {n,ns}, aInfo);
then
fail();
Expand Down Expand Up @@ -7986,14 +7990,14 @@ algorithm
case (SCode.REDECL(finalPrefix = b,elementLst = {})) then {};

/* Find in sub modifications e.g A(B=3) find B */
case ((mod as SCode.MOD(subModLst = submods,absynExpOption = SOME((e,_)))))
case ((mod as SCode.MOD(subModLst = submods,binding = SOME((e,_)))))
equation
l1 = getCrefFromSubmods(submods);
l2 = Absyn.getCrefFromExp(e,true);
res = listAppend(l2, l1);
then
res;
case (SCode.MOD(subModLst = submods,absynExpOption = NONE()))
case (SCode.MOD(subModLst = submods,binding = NONE()))
equation
res = getCrefFromSubmods(submods);
then
Expand Down Expand Up @@ -9969,7 +9973,9 @@ algorithm
Absyn.Path p;
Env.Env cenv;
SCode.Class cdef;

case(cache,env,ih,{},path) then (cache);

/* Skipped recursive calls (by looking in cache) */
case(cache,env,ih,p::paths,path)
equation
Expand All @@ -9979,7 +9985,6 @@ algorithm
cache = instantiateDerivativeFuncs2(cache,env,ih,paths,path);
then (cache);


case(cache,env,ih,p::paths,path)
equation
(cache,cdef,cenv) = Lookup.lookupClass(cache,env,p,true);
Expand All @@ -9992,6 +9997,16 @@ algorithm
cache = Env.addDaeFunction(cache, funcs);
cache = instantiateDerivativeFuncs2(cache,env,ih,paths,path);
then (cache);

else
equation
true = RTOpts.debugFlag("failtrace");
p :: _ = paths;
Debug.traceln("- Inst.instantiateDerivativeFuncs2 failed for " +&
Absyn.pathString(p));
then
fail();

end matchcontinue;
end instantiateDerivativeFuncs2;

Expand Down Expand Up @@ -10139,7 +10154,7 @@ algorithm element := matchcontinue(subs,elemDecl,baseFunc,inCache,inEnv,inIH,inP

case({},_,_,_,_,_,_,_) then fail();

case(SCode.NAMEMOD("derivative",(m as SCode.MOD(subModLst = subs2,absynExpOption=SOME(((ae as Absyn.CREF(acr)),_)))))::subs,
case(SCode.NAMEMOD("derivative",(m as SCode.MOD(subModLst = subs2,binding=SOME(((ae as Absyn.CREF(acr)),_)))))::subs,
elemDecl,baseFunc,inCache,inEnv,inIH,inPrefix,info)
equation
deriveFunc = Absyn.crefToPath(acr);
Expand Down Expand Up @@ -10197,23 +10212,23 @@ algorithm

case({},_,_,_,_,_,_) then {};

case(SCode.NAMEMOD("noDerivative",(m as SCode.MOD(absynExpOption = SOME(((Absyn.CREF(acr)),_)))))::subs,elemDecl,inCache,inEnv,inIH,inPrefix,info)
case(SCode.NAMEMOD("noDerivative",(m as SCode.MOD(binding = SOME(((Absyn.CREF(acr)),_)))))::subs,elemDecl,inCache,inEnv,inIH,inPrefix,info)
equation
name = Absyn.printComponentRefStr(acr);
outconds = getDeriveCondition(subs,elemDecl,inCache,inEnv,inIH,inPrefix,info);
varPos = setFunctionInputIndex(elemDecl,name,1);
then
(varPos,DAE.NO_DERIVATIVE(DAE.ICONST(99)))::outconds;

case(SCode.NAMEMOD("zeroDerivative",(m as SCode.MOD(absynExpOption = SOME(((Absyn.CREF(acr)),_)) )))::subs,elemDecl,inCache,inEnv,inIH,inPrefix,info)
case(SCode.NAMEMOD("zeroDerivative",(m as SCode.MOD(binding = SOME(((Absyn.CREF(acr)),_)) )))::subs,elemDecl,inCache,inEnv,inIH,inPrefix,info)
equation
name = Absyn.printComponentRefStr(acr);
outconds = getDeriveCondition(subs,elemDecl,inCache,inEnv,inIH,inPrefix,info);
varPos = setFunctionInputIndex(elemDecl,name,1);
then
(varPos,DAE.ZERO_DERIVATIVE())::outconds;

case(SCode.NAMEMOD("noDerivative",(m as SCode.MOD(absynExpOption=_)))::subs,elemDecl,inCache,inEnv,inIH,inPrefix,info)
case(SCode.NAMEMOD("noDerivative",(m as SCode.MOD(binding=_)))::subs,elemDecl,inCache,inEnv,inIH,inPrefix,info)
equation
(inCache,(elabedMod as DAE.MOD(subModLst={sub}))) = Mod.elabMod(inCache, inEnv, inIH, inPrefix, m, false,info);
(name,cond) = extractNameAndExp(sub);
Expand Down Expand Up @@ -10299,7 +10314,7 @@ algorithm defaultDerivative := matchcontinue(subs,inCache,inEnv,inPrefix)
Absyn.Exp ae;
SCode.Mod m;
case({},inCache,inEnv,inPrefix) then NONE();
case(SCode.NAMEMOD("derivative",(m as SCode.MOD(absynExpOption =SOME(((ae as Absyn.CREF(acr)),_)))))::subs,inCache,inEnv,inPrefix)
case(SCode.NAMEMOD("derivative",(m as SCode.MOD(binding =SOME(((ae as Absyn.CREF(acr)),_)))))::subs,inCache,inEnv,inPrefix)
equation
p = Absyn.crefToPath(acr);
(_,p) = makeFullyQualified(inCache,inEnv, p);
Expand All @@ -10320,7 +10335,7 @@ algorithm order := matchcontinue(subs)
Absyn.Exp ae;
SCode.Mod m;
case({}) then 1;
case(SCode.NAMEMOD("order",(m as SCode.MOD(absynExpOption= SOME(((ae as Absyn.INTEGER(order)),_)))))::subs)
case(SCode.NAMEMOD("order",(m as SCode.MOD(binding= SOME(((ae as Absyn.INTEGER(order)),_)))))::subs)
then order;
case(_::subs) then getDerivativeOrder(subs);
end matchcontinue;
Expand Down Expand Up @@ -10462,7 +10477,7 @@ algorithm
case (e as SCode.COMPONENT(component = id, innerOuter = inOut, finalPrefix = finPre, replaceablePrefix = repPre,
protectedPrefix = proPre, attributes = attr as SCode.ATTR(direction = Absyn.OUTPUT()),
typeSpec = typeSpc,
modifications = SCode.MOD(finalPrefix = modFinPre, eachPrefix = modEachPre, subModLst = modSubML, absynExpOption = SOME(_)),
modifications = SCode.MOD(finalPrefix = modFinPre, eachPrefix = modEachPre, subModLst = modSubML, binding = SOME(_)),
comment = comm, condition = cond, info = info, cc = cc_))
equation
modBla = SCode.MOD(modFinPre,modEachPre,modSubML,NONE());
Expand Down
10 changes: 5 additions & 5 deletions Compiler/FrontEnd/Mod.mo
Expand Up @@ -127,14 +127,14 @@ algorithm
case (cache,_,_,_,SCode.NOMOD(),impl,_) then (cache,DAE.NOMOD());

// no top binding
case (cache,env,ih,pre,(m as SCode.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,absynExpOption = NONE())),impl,info)
case (cache,env,ih,pre,(m as SCode.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,binding = NONE())),impl,info)
equation
(cache,subs_1) = elabSubmods(cache, env, ih, pre, subs, impl,info);
then
(cache,DAE.MOD(finalPrefix,each_,subs_1,NONE()));

// Only elaborate expressions with non-delayed type checking, see SCode.MOD.
case (cache,env,ih,pre,(m as SCode.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,absynExpOption = SOME((e,false)))),impl,info)
case (cache,env,ih,pre,(m as SCode.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,binding = SOME((e,false)))),impl,info)
equation
(cache,subs_1) = elabSubmods(cache, env, ih, pre, subs, impl,info);
// print("Mod.elabMod: calling elabExp on mod exp: " +& Dump.printExpStr(e) +& " in env: " +& Env.printEnvPathStr(env) +& "\n");
Expand All @@ -148,7 +148,7 @@ algorithm
(cache,DAE.MOD(finalPrefix,each_,subs_1,SOME(DAE.TYPED(e_2,e_val,prop,SOME(e)))));

// Delayed type checking
case (cache,env,ih,pre,(m as SCode.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,absynExpOption = SOME((e,true)))),impl,info)
case (cache,env,ih,pre,(m as SCode.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,binding = SOME((e,true)))),impl,info)
equation
// print("Mod.elabMod: delayed mod : " +& Dump.printExpStr(e) +& " in env: " +& Env.printEnvPathStr(env) +& "\n");
(cache,subs_1) = elabSubmods(cache, env, ih, pre, subs, impl, info);
Expand Down Expand Up @@ -651,12 +651,12 @@ algorithm
list<SCode.Element> elist;
Ident s;
case (SCode.NOMOD(),_,_) then DAE.NOMOD();
case ((m as SCode.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,absynExpOption = NONE())),env,pre)
case ((m as SCode.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,binding = NONE())),env,pre)
equation
subs_1 = elabUntypedSubmods(subs, env, pre);
then
DAE.MOD(finalPrefix,each_,subs_1,NONE());
case ((m as SCode.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,absynExpOption = SOME((e,_)))),env,pre)
case ((m as SCode.MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,binding = SOME((e,_)))),env,pre)
equation
subs_1 = elabUntypedSubmods(subs, env, pre);
then
Expand Down
17 changes: 17 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -48,6 +48,23 @@ function terminal
external "builtin";
end terminal;

type AssertionLevel_ = enumeration(error, warning);

function assert
input Boolean condition;
input String message;
input AssertionLevel_ level;
external "builtin";
end assert;

function constrain
input Real i1;
input Real i2;
input Real i3;
output Real o1;
external "builtin";
end constrain;

function sample
input Real start;
input Real interval;
Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/SCode.mo
Expand Up @@ -96,7 +96,7 @@ uniontype Mod "- Modifications"
Boolean finalPrefix "final" ;
Absyn.Each eachPrefix;
list<SubMod> subModLst;
Option<tuple<Absyn.Exp,Boolean>> absynExpOption "The binding expression of a modification
Option<tuple<Absyn.Exp,Boolean>> binding "The binding expression of a modification
has an expression and a Boolean delayElaboration which is true if elaboration(type checking)
should be delayed. This can for instance be used when having A a(x = a.y) where a.y can not be
type checked -before- a is instantiated, which is the current design in instantiation process.";
Expand Down Expand Up @@ -714,7 +714,7 @@ algorithm
list<SubMod> subs;
Option<tuple<Absyn.Exp,Boolean>> e;
Mod m;
case (MOD(finalPrefix = f,eachPrefix = each_,subModLst = subs,absynExpOption = e)) then MOD(f,each_,{},e);
case (MOD(finalPrefix = f,eachPrefix = each_,subModLst = subs,binding = e)) then MOD(f,each_,{},e);
case (m) then m;
end matchcontinue;
end stripSubmod;
Expand Down Expand Up @@ -836,7 +836,7 @@ algorithm
res = stringAppendList({"redeclare(",finalPrefixstr,str,")"});
then
res;
case MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,absynExpOption = ass)
case MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,binding = ass)
equation
finalPrefixstr = Util.if_(finalPrefix, "final", "");
each_str = Dump.unparseEachStr(each_);
Expand Down

0 comments on commit 3d07acb

Please sign in to comment.