Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Started looking for undefined outputs of record components in functions
- Patched MSL 3.2.1 in the places we had these (mostly Spice3, some Fluid)
- Updated tests that use this (mosty ThermoSysPro and Modelica 3.1; I don't care enough to make them run without warning)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15249 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 20, 2013
1 parent b9d0391 commit 057630d
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 48 deletions.
28 changes: 27 additions & 1 deletion Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -18308,11 +18308,12 @@ algorithm
local
list<DAE.Element> rest;
list<DAE.Statement> stmts;
list<String> unbound,outputs;
list<String> unbound,outputs,names,outNames;
String name;
DAE.Type ty;
DAE.InstDims dims;
DAE.VarDirection dir;
list<DAE.Var> vars;
case ({},NONE(),unbound,outputs,_)
// This would run also for partial function inst... So let's skip it
// equation
Expand All @@ -18327,6 +18328,19 @@ algorithm
equation
unbound = checkFunctionDefUse2(rest,alg,unbound,inOutputs,inInfo);
then unbound;
case (DAE.VAR(direction=dir,componentRef=DAE.CREF_IDENT(ident=name),ty=DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_),varLst=vars),dims=dims,binding=NONE())::rest,_,unbound,outputs,_)
equation
vars = List.filterOnTrue(vars, Types.varIsVariable);
// TODO: We filter out parameters at the moment. I'm unsure if this is correct. Might be that this is an automatic error...
names = List.map1r(List.map(vars, Types.varName), stringAppend, name +& ".");
// print("for record: " +& stringDelimitList(names,",") +& "\n");
// Arrays with unknown bounds (size(cr,1), etc) are treated as initialized because they may have 0 dimensions checked for in the code
outNames = Util.if_(DAEUtil.varDirectionEqual(dir,DAE.OUTPUT()), names, {});
names = Util.if_(List.fold(dims,foldIsKnownSubscriptDimensionNonZero,true), names, {});
unbound = listAppend(names,unbound);
outputs = listAppend(outNames,inOutputs);
unbound = checkFunctionDefUse2(rest,alg,unbound,outputs,inInfo);
then unbound;
case (DAE.VAR(direction=dir,componentRef=DAE.CREF_IDENT(ident=name),dims=dims,binding=NONE())::rest,_,unbound,outputs,_)
equation
// Arrays with unknown bounds (size(cr,1), etc) are treated as initialized because they may have 0 dimensions checked for in the code
Expand Down Expand Up @@ -18539,7 +18553,19 @@ algorithm
DAE.ComponentRef cr;
DAE.Exp exp;
DAE.Pattern pattern;
String id1,id2;
case (DAE.CREF(componentRef=DAE.WILD()),_) then inUnbound;
// Assignment to part of a record
case (DAE.CREF(componentRef=DAE.CREF_QUAL(ident=id1,componentRef=DAE.CREF_IDENT(ident=id2))),unbound)
equation
unbound = List.filter1OnTrue(unbound,Util.stringNotEqual,id1 +& "." +& id2);
then unbound;
// Assignment to the whole record - filter out everything it is prefix of
case (DAE.CREF(componentRef=DAE.CREF_IDENT(ident=id1),ty=DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(_))),unbound)
equation
id1 = id1 +& ".";
unbound = List.filter2OnTrue(unbound,Util.notStrncmp,id1,stringLength(id1));
then unbound;
case (DAE.CREF(componentRef=cr),unbound)
equation
unbound = List.filter1OnTrue(unbound,Util.stringNotEqual,ComponentReference.crefFirstIdent(cr));
Expand Down
11 changes: 11 additions & 0 deletions Compiler/FrontEnd/Types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,17 @@ algorithm
end match;
end getVarType;

public function varIsVariable
input Var v;
output Boolean b;
algorithm
b := match v
case DAE.TYPES_VAR(attributes=DAE.ATTR(variability=SCode.VAR())) then true;
case DAE.TYPES_VAR(attributes=DAE.ATTR(variability=SCode.DISCRETE())) then true;
else false;
end match;
end varIsVariable;

public function getVarName "Return the name of a Var"
input Var v;
output String name;
Expand Down
54 changes: 54 additions & 0 deletions Compiler/Util/List.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7294,6 +7294,60 @@ algorithm
end match;
end filter1rOnTrue_tail;

public function filter2OnTrue
"Takes a list of values and a filter function over the values and returns a
sub list of values for which the matching function returns true."
input list<ElementType> inList;
input FilterFunc inFilterFunc;
input ArgType1 inArg1;
input ArgType2 inArg2;
output list<ElementType> outList;

partial function FilterFunc
input ElementType inElement;
input ArgType1 inArg1;
input ArgType2 inArg2;
output Boolean outResult;
end FilterFunc;
algorithm
outList := filter2OnTrue_tail(inList, inFilterFunc, inArg1, inArg2, {});
end filter2OnTrue;

protected function filter2OnTrue_tail
"Tail recursive implementation of filter1OnTrue."
input list<ElementType> inList;
input FilterFunc inFilterFunc;
input ArgType1 inArg1;
input ArgType2 inArg2;
input list<ElementType> inAccumList;
output list<ElementType> outList;

partial function FilterFunc
input ElementType inElement;
input ArgType1 inArg1;
input ArgType2 inArg2;
output Boolean outResult;
end FilterFunc;
algorithm
outList := match(inList, inFilterFunc, inArg1, inArg2, inAccumList)
local
ElementType e;
list<ElementType> rest, accum;
Boolean filter;

// Reverse at the end.
case ({}, _, _, _, _) then listReverse(inAccumList);

case (e :: rest, _, _, _, _)
equation
filter = inFilterFunc(e, inArg1, inArg2);
accum = consOnTrue(filter, e, inAccumList);
then
filter2OnTrue_tail(rest, inFilterFunc, inArg1, inArg2, accum);

end match;
end filter2OnTrue_tail;

public function removeOnTrue
"Goes through a list and removes all elements which are equal to the given
value, using the given comparison function."
Expand Down
56 changes: 9 additions & 47 deletions Compiler/Util/Util.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2148,33 +2148,6 @@ algorithm
end matchcontinue;
end systemCallWithErrorMsg;

/* adrpo - 2007-02-19 - not used anymore
public function charListCompare "function: charListCompare
Compares two char lists up to the nth
position and returns true if they are equal."
input list<String> inStringLst1;
input list<String> inStringLst2;
input Integer inInteger3;
output Boolean outBoolean;
algorithm
outBoolean:=
matchcontinue (inStringLst1,inStringLst2,inInteger3)
local
String a,b;
Integer n1,n;
list<String> l1,l2;
case ((a :: _),(b :: _),1) then stringEq(a, b);
case ((a :: l1),(b :: l2),n)
equation
n1 = n - 1;
true = stringEq(a, b);
true = charListCompare(l1, l2, n1);
then
true;
case (_,_,_) then false;
end matchcontinue;
end charListCompare;
*/
public function strncmp "function: strncmp
Compare two strings up to the nth character
Returns true if they are equal."
Expand All @@ -2184,28 +2157,17 @@ public function strncmp "function: strncmp
output Boolean outBoolean;
algorithm
outBoolean := (0==System.strncmp(inString1,inString2,inInteger3));
/*
matchcontinue (inString1,inString2,inInteger3)
local
list<String> clst1,clst2;
Integer s1len,s2len,n;
String s1,s2;
case (s1,s2,n)
equation
clst1 = stringListStringChar(s1);
clst2 = stringListStringChar(s2);
s1len = stringLength(s1);
s2len = stringLength(s2);
(s1len >= n) = true;
(s2len >= n) = true;
true = charListCompare(clst1, clst2, n);
then
true;
case (_,_,_) then false;
end matchcontinue;
*/
end strncmp;

public function notStrncmp
input String inString1;
input String inString2;
input Integer inInteger3;
output Boolean outBoolean;
algorithm
outBoolean := not strncmp(inString1,inString2,inInteger3);
end notStrncmp;

public function tickStr "function: tickStr
author: PA
Returns tick as a string, i.e. an unique number."
Expand Down

0 comments on commit 057630d

Please sign in to comment.