Skip to content

Commit

Permalink
- latest modifications from MathCoreOSMC branch
Browse files Browse the repository at this point in the history
Revision: 4296
Author: bjozac
Date: 09:56:29, den 2 oktober 2009
Message:
While instantiating parameters componentreferenses in subscripts where not instantiated in order.
----
Modified : /branches/MathCoreOSMC/Compiler/Absyn.mo
Modified : /branches/MathCoreOSMC/Compiler/Inst.mo
Modified : /branches/MathCoreOSMC/Compiler/Static.mo

Revision: 4291
Author: bjozac
Date: 11:28:01, den 1 oktober 2009
Message:
Exteded AbsynDep with getUsedBySub which does the same as "getUsedBy" with the extra function it returns sub path.
----
Modified : /branches/MathCoreOSMC/Compiler/Absyn.mo
Modified : /branches/MathCoreOSMC/Compiler/AbsynDep.mo



git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/OpenModelica1.5.0@4301 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 4, 2009
1 parent 4aaf6b1 commit 41f29df
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 67 deletions.
125 changes: 74 additions & 51 deletions Compiler/Absyn.mo
Expand Up @@ -1793,21 +1793,23 @@ algorithm crefs := matchcontinue(subs)
case(SUBSCRIPT(exp)::subs)
equation
crefs1 = getCrefsFromSubs(subs);
crefs = getCrefFromExp(exp);
crefs = getCrefFromExp(exp,true);
crefs = listAppend(crefs,crefs1);
//crefs = Util.listUnionOnTrue(crefs,crefs1,crefEqual);
then
crefs;
end matchcontinue;
end getCrefsFromSubs;

public function getCrefFromExp "function: getCrefFromExp
public function getCrefFromExp "
Returns a flattened list of the
component references in an expression"
input Exp inExp;
input Boolean checkSubs;
output list<ComponentRef> outComponentRefLst;
algorithm
outComponentRefLst:=
matchcontinue (inExp)
matchcontinue (inExp,checkSubs)
local
ComponentRef cr;
list<ComponentRef> l1,l2,res,res1,l3;
Expand All @@ -1818,88 +1820,100 @@ algorithm
list<list<ComponentRef>> res2;
list<ComponentCondition> expl;
list<list<ComponentCondition>> expll;
case (INTEGER(value = _)) then {};
case (REAL(value = _)) then {};
case (STRING(value = _)) then {};
case (BOOL(value = _)) then {};
case (CREF(componentReg = cr)) then {cr};
case (BINARY(exp1 = e1,op = op,exp2 = e2))
case (INTEGER(value = _),checkSubs) then {};
case (REAL(value = _),checkSubs) then {};
case (STRING(value = _),checkSubs) then {};
case (BOOL(value = _),checkSubs) then {};
case (CREF(componentReg = cr),false) then {cr};
case (CREF(componentReg = (cr as WILD)),_) then {};

case (CREF(componentReg = (cr)),true)
local
list<Subscript> subs;
equation
subs = getSubsFromCref(cr);
l1 = getCrefsFromSubs(subs);
then cr::l1;

case (BINARY(exp1 = e1,op = op,exp2 = e2),checkSubs)
equation
l1 = getCrefFromExp(e1);
l2 = getCrefFromExp(e2);
l1 = getCrefFromExp(e1,checkSubs);
l2 = getCrefFromExp(e2,checkSubs);
res = listAppend(l1, l2);
then
res;
case (UNARY(op = op,exp = e1))
case (UNARY(op = op,exp = e1),checkSubs)
equation
res = getCrefFromExp(e1);
res = getCrefFromExp(e1,checkSubs);
then
res;
case (LBINARY(exp1 = e1,op = op,exp2 = e2))
case (LBINARY(exp1 = e1,op = op,exp2 = e2),checkSubs)
equation
l1 = getCrefFromExp(e1);
l2 = getCrefFromExp(e2);
l1 = getCrefFromExp(e1,checkSubs);
l2 = getCrefFromExp(e2,checkSubs);
res = listAppend(l1, l2);
then
res;
case (LUNARY(op = op,exp = e1))
case (LUNARY(op = op,exp = e1),checkSubs)
equation
res = getCrefFromExp(e1);
res = getCrefFromExp(e1,checkSubs);
then
res;
case (RELATION(exp1 = e1,op = op,exp2 = e2))
case (RELATION(exp1 = e1,op = op,exp2 = e2),checkSubs)
equation
l1 = getCrefFromExp(e1);
l2 = getCrefFromExp(e2);
l1 = getCrefFromExp(e1,checkSubs);
l2 = getCrefFromExp(e2,checkSubs);
res = listAppend(l1, l2);
then
res;
case (IFEXP(ifExp = e1,trueBranch = e2,elseBranch = e3,elseIfBranch = e4))
case (IFEXP(ifExp = e1,trueBranch = e2,elseBranch = e3,elseIfBranch = e4),checkSubs)
equation
l1 = getCrefFromExp(e1);
l2 = getCrefFromExp(e2);
l1 = getCrefFromExp(e1,checkSubs);
l2 = getCrefFromExp(e2,checkSubs);
res1 = listAppend(l1, l2);
l3 = getCrefFromExp(e3);
l3 = getCrefFromExp(e3,checkSubs);
res = listAppend(res1, l3) "TODO elseif\'s e4" ;
then
res;
case (CALL(functionArgs = farg))
case (CALL(functionArgs = farg),checkSubs)
equation
res = getCrefFromFarg(farg) "res = Util.listMap(expl,get_cref_from_exp)" ;
res = getCrefFromFarg(farg,checkSubs) "res = Util.listMap(expl,get_cref_from_exp)" ;
then
res;
case (ARRAY(arrayExp = expl))
case (ARRAY(arrayExp = expl),checkSubs)
local list<list<ComponentRef>> res1;
equation
res1 = Util.listMap(expl, getCrefFromExp);
res1 = Util.listMap1(expl, getCrefFromExp,checkSubs);
res = Util.listFlatten(res1);
then
res;
case (MATRIX(matrix = expll))
case (MATRIX(matrix = expll),checkSubs)
local list<list<list<ComponentRef>>> res1;
equation
res1 = Util.listListMap(expll, getCrefFromExp);
res1 = Util.listListMap1(expll, getCrefFromExp,checkSubs);
res2 = Util.listFlatten(res1);
res = Util.listFlatten(res2);
then
res;
case (RANGE(start = e1,step = SOME(e3),stop = e2))
case (RANGE(start = e1,step = SOME(e3),stop = e2),checkSubs)
equation
l1 = getCrefFromExp(e1);
l2 = getCrefFromExp(e2);
l1 = getCrefFromExp(e1,checkSubs);
l2 = getCrefFromExp(e2,checkSubs);
res1 = listAppend(l1, l2);
l3 = getCrefFromExp(e3);
l3 = getCrefFromExp(e3,checkSubs);
res = listAppend(res1, l3);
then
res;
case (RANGE(start = e1,step = NONE,stop = e2))
case (RANGE(start = e1,step = NONE,stop = e2),checkSubs)
equation
l1 = getCrefFromExp(e1);
l2 = getCrefFromExp(e2);
l1 = getCrefFromExp(e1,checkSubs);
l2 = getCrefFromExp(e2,checkSubs);
res = listAppend(l1, l2);
then
res;
case (TUPLE(expressions = expl))
case (END,checkSubs) then {};

case (TUPLE(expressions = expl),checkSubs)
equation
print("#- Absyn.getCrefFromExp is not implemented yet for Abyn.TUPLE\n")
"res = Util.listMap(expl,getCrefFromExp)" ;
Expand All @@ -1912,20 +1926,19 @@ protected function getCrefFromFarg "function: getCrefFromFarg
Returns the flattened list of all component references
present in a list of function arguments."
input FunctionArgs inFunctionArgs;
input Boolean checkSubs;
output list<ComponentRef> outComponentRefLst;
algorithm
outComponentRefLst:=
matchcontinue (inFunctionArgs)
algorithm outComponentRefLst := matchcontinue (inFunctionArgs,checkSubs)
local
list<list<ComponentRef>> l1,l2;
list<ComponentRef> fl1,fl2,res;
list<ComponentCondition> expl;
list<NamedArg> nargl;
case (FUNCTIONARGS(args = expl,argNames = nargl))
case (FUNCTIONARGS(args = expl,argNames = nargl),checkSubs)
equation
l1 = Util.listMap(expl, getCrefFromExp);
l1 = Util.listMap1(expl, getCrefFromExp,checkSubs);
fl1 = Util.listFlatten(l1);
l2 = Util.listMap(nargl, getCrefFromNarg);
l2 = Util.listMap1(nargl, getCrefFromNarg,checkSubs);
fl2 = Util.listFlatten(l2);
res = listAppend(fl1, fl2);
then
Expand All @@ -1937,16 +1950,15 @@ protected function getCrefFromNarg "function: getCrefFromNarg
Returns the flattened list of all component references
present in a list of named function arguments."
input NamedArg inNamedArg;
input Boolean checkSubs;
output list<ComponentRef> outComponentRefLst;
algorithm
outComponentRefLst:=
matchcontinue (inNamedArg)
algorithm outComponentRefLst := matchcontinue (inNamedArg,checkSubs)
local
list<ComponentRef> res;
ComponentCondition exp;
case (NAMEDARG(argValue = exp))
case (NAMEDARG(argValue = exp),checkSubs)
equation
res = getCrefFromExp(exp);
res = getCrefFromExp(exp,checkSubs);
then
res;
end matchcontinue;
Expand Down Expand Up @@ -2049,7 +2061,18 @@ algorithm (outPath1,outPath2) := matchcontinue(inPath)
case(QUALIFIED(name=s1, path=qPath)) equation
(curPath,identPath) = splitQualAndIdentPath(qPath);
then (QUALIFIED(s1,curPath),identPath);
end matchcontinue;
case(FULLYQUALIFIED(qPath))
equation
(curPath,identPath) = splitQualAndIdentPath(qPath);
then
(curPath,identPath);
case(qPath)
equation
print(" Failure in: " +& pathString(qPath) +& "\n");
then
fail();
case(_) equation print(" failure in splitQualAndIdentPath\n"); then fail();
end matchcontinue;
end splitQualAndIdentPath;

public function stripFirst "function: stripFirst
Expand Down
66 changes: 64 additions & 2 deletions Compiler/AbsynDep.mo
Expand Up @@ -90,9 +90,8 @@ public function addDependency "add a dependency tha a class 'cl' uses another cl
local
AvlTree uses, usedBy;
case(DEPENDS(uses,usedBy),cl,usesClass) equation
//print("ADD "+&Absyn.pathString(cl)+&" -> {"+&Absyn.pathString(usesClass)+&"}\n");
uses = avlTreeAdd(uses,cl,{usesClass});
usedBy = avlTreeAdd(usedBy,usesClass,{cl});
usedBy = avlTreeAdd(usedBy,usesClass,{cl});
then DEPENDS(uses,usedBy);
end matchcontinue;
end addDependency;
Expand Down Expand Up @@ -224,6 +223,24 @@ public function getUsedBy "returns the classes that uses the class 'cl' e.g. as
end matchcontinue;
end getUsedBy;

public function getUsedBySub "
Author BZ, 2009-10
If inpu cl is 'A.B' it returns classes using A.B, but also classes that uses A.B.C.D and A.B.R, it returns all classes that equals or are a subpath of provided path.
"
input Depends depends;
input Absyn.Path cl;
output AvlTree usedBy;
algorithm
usedBy := matchcontinue(depends,cl)
local AvlValue v;
case(DEPENDS(_,usedBy),cl) equation
v = avlTreeGetSubs(usedBy,cl);
//print("included: " +& Util.stringDelimitList(Util.listMap(v,Absyn.pathString),", ") +& "\n");
usedBy= avlAddUses(avlTreeNew(),v);
then usedBy;
end matchcontinue;
end getUsedBySub;

/*
*
* Generic AVL tree implementation below (copied from Env)
Expand Down Expand Up @@ -316,6 +333,7 @@ algorithm
Option<AvlTree> left,right;
Integer rhval,h;
AvlTree t_1,t,right_1,left_1,bt;

/* empty tree*/
case (AVLTREENODE(value = NONE,height=h,left = NONE,right = NONE),key,value)
then AVLTREENODE(SOME(AVLTREEVALUE(key,value)),1,NONE,NONE);
Expand Down Expand Up @@ -615,6 +633,50 @@ algorithm
end matchcontinue;
end avlTreeGet;

protected function avlTreeGetSubsopt
input Option<AvlTree> inAvlTree;
input AvlKey inKey;
output AvlValue outValue;
AvlTree item;
algorithm outValue := matchcontinue(inAvlTree,inKey)
case(NONE,_) then {};
case(SOME(item),inKey) then avlTreeGetSubs (item,inKey);
end matchcontinue;
end avlTreeGetSubsopt;

public function avlTreeGetSubs " Get values from the binary tree given a key.
"
input AvlTree inAvlTree;
input AvlKey inKey;
output AvlValue outValue;
algorithm outValue:= matchcontinue (inAvlTree,inKey)
local
AvlKey rkey,key;
AvlValue rval,res,res2;
Option<AvlTree> left,right;
Integer rhval;
Boolean b1,b2;
String s1;
// end of tree case
case (AVLTREENODE(value = SOME(AVLTREEVALUE(rkey,rval)),left = NONE,right = NONE),key)
equation
b2 = Absyn.pathPrefixOf(key,rkey);
rval = Util.if_(b2,rval,{});
then
rval;
// Normal case, compare current node and search left+right
case (AVLTREENODE(value = SOME(AVLTREEVALUE(rkey,rval)),left = left,right = right),key)
equation
b1 = Absyn.pathPrefixOf(key,rkey);
rval = Util.if_(b1,rval,{});
res = avlTreeGetSubsopt(left, key);
res2 = avlTreeGetSubsopt(right, key);
rval = listAppend(rval,listAppend(res,res2));
then
rval;
end matchcontinue;
end avlTreeGetSubs;

protected function getOptionStr "function getOptionStr
Retrieve the string from a string option.
Expand Down
13 changes: 7 additions & 6 deletions Compiler/CevalScript.mo
Expand Up @@ -3255,9 +3255,10 @@ algorithm
Print.clearErrorBuf() "Clear error buffer";
p_1 = SCode.elaborate(ptot);

UnitParserExt.clear();
UnitAbsynBuilder.registerUnits(ptot);
UnitParserExt.commit();
//UnitParserExt.clear();
//UnitAbsynBuilder.registerUnits(ptot);
//UnitParserExt.commit();

(cache, env, _, dae as DAE.DAE(dael)) =
Inst.instantiateClass(inCache, InstanceHierarchy.emptyInstanceHierarchy, p_1, className);
((dae as DAE.DAE(dael))) = DAE.transformIfEqToExpr(dae);
Expand Down Expand Up @@ -3290,9 +3291,9 @@ algorithm
Print.clearErrorBuf() "Clear error buffer";
p_1 = SCode.elaborate(ptot);

UnitParserExt.clear();
UnitAbsynBuilder.registerUnits(ptot);
UnitParserExt.commit();
//UnitParserExt.clear();
//UnitAbsynBuilder.registerUnits(ptot);
//UnitParserExt.commit();

(cache, env, _, dae as DAE.DAE(dael)) =
Inst.instantiateFunctionImplicit(inCache, InstanceHierarchy.emptyInstanceHierarchy, p_1, className);
Expand Down
8 changes: 4 additions & 4 deletions Compiler/Inst.mo
Expand Up @@ -4718,7 +4718,7 @@ algorithm
case (_,{}) then false;
case (compname,(SCode.EQUATION(eEquation = SCode.EQ_IF(condition = conds)) :: _))
equation
crefs = Util.listFlatten(Util.listMap(conds,Absyn.getCrefFromExp));
crefs = Util.listFlatten(Util.listMap1(conds,Absyn.getCrefFromExp,false));
true = memberCrefs(compname, crefs);
then
true;
Expand Down Expand Up @@ -6599,7 +6599,7 @@ algorithm
case ((mod as SCode.MOD(subModLst = submods,absynExpOption = SOME((e,_)))))
equation
l1 = getCrefFromSubmods(submods);
l2 = Absyn.getCrefFromExp(e);
l2 = Absyn.getCrefFromExp(e,true);
res = listAppend(l2, l1);
then
res;
Expand Down Expand Up @@ -6634,7 +6634,7 @@ algorithm
case ((Absyn.SUBSCRIPT(subScript = exp) :: rest))
equation
l1 = getCrefFromDim(rest);
l2 = Absyn.getCrefFromExp(exp);
l2 = Absyn.getCrefFromExp(exp,true);
res = listAppend(l1, l2);
then
res;
Expand Down Expand Up @@ -15098,7 +15098,7 @@ algorithm
crefs := matchcontinue(cond)
local Absyn.Exp e;
case(NONE) then {};
case SOME(e) then Absyn.getCrefFromExp(e);
case SOME(e) then Absyn.getCrefFromExp(e,true);
end matchcontinue;
end getCrefFromCond;

Expand Down

0 comments on commit 41f29df

Please sign in to comment.