Skip to content

Commit

Permalink
- Added check for public non-formal function parameters, and fixed th…
Browse files Browse the repository at this point in the history
…e compiler

  code and test cases.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9822 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 15, 2011
1 parent c65a89c commit bfbfaff
Show file tree
Hide file tree
Showing 25 changed files with 127 additions and 37 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -271,6 +271,7 @@ public function assignmentsCreate
input Integer memsize;
input Integer v;
output BackendDAE.Assignments outAssignments;
protected
list<BackendDAE.Value> lst;
array<BackendDAE.Value> arr;
algorithm
Expand Down
3 changes: 3 additions & 0 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -1294,6 +1294,7 @@ public function dumpIncidenceMatrix
author: PA
Prints the incidence matrix on stdout."
input BackendDAE.IncidenceMatrix m;
protected
BackendDAE.Value mlen;
String mlen_str;
list<list<BackendDAE.Value>> m_1;
Expand All @@ -1314,6 +1315,7 @@ public function dumpIncidenceMatrixT
author: PA
Prints the transposed incidence matrix on stdout."
input BackendDAE.IncidenceMatrix m;
protected
BackendDAE.Value mlen;
String mlen_str;
list<list<BackendDAE.Value>> m_1;
Expand Down Expand Up @@ -1383,6 +1385,7 @@ public function dumpMatching
author: PA
prints the matching information on stdout."
input array<Integer> v;
protected
BackendDAE.Value len;
String len_str;
algorithm
Expand Down
3 changes: 3 additions & 0 deletions Compiler/BackEnd/BackendQSS.mo
Expand Up @@ -2186,6 +2186,7 @@ protected function replaceExpOnEq
input DAE.Exp zc;
input Integer inp;
output DAE.Exp eqout;
protected
DAE.Exp temp;
algorithm
/*
Expand All @@ -2210,6 +2211,7 @@ protected function replaceCrossingLstOnExp
input list<DAE.Exp> zce1;
input Integer index1;
output DAE.Exp expOut;
protected
DAE.Exp e1,e2;
algorithm
expOut := matchcontinue (exp1,zce1,index1)
Expand Down Expand Up @@ -2801,6 +2803,7 @@ public function dumpDEVSstruct
"
input array<list<list<Integer>>> m;
input String text;
protected
list<list<list<Integer>>> m_1;
algorithm
print("====================================\n");
Expand Down
1 change: 1 addition & 0 deletions Compiler/BackEnd/DAEQuery.mo
Expand Up @@ -178,6 +178,7 @@ protected function getIncidenceMatrix "function: getIncidenceMatrix
gets the incidence matrix as a string"
input array<list<String>> m;
output String strIMatrix;
protected
Integer mlen;
String mlen_str;
list<list<String>> m_1;
Expand Down
1 change: 1 addition & 0 deletions Compiler/BackEnd/PartFn.mo
Expand Up @@ -1049,6 +1049,7 @@ protected function makeNewFnPath
input Absyn.Path inCaller;
input Absyn.Path inCallee;
output Absyn.Path newPath;
protected
String s1,s2,s;
algorithm
s1 := Absyn.pathStringNoQual(inCaller);
Expand Down
8 changes: 7 additions & 1 deletion Compiler/BackEnd/SimCode.mo
Expand Up @@ -2624,6 +2624,7 @@ protected function findDelaySubExpressions
"Return all subexpressions of inExp that are calls to delay()"
input tuple<DAE.Exp,list<DAE.Exp>> itpl;
output tuple<DAE.Exp,list<DAE.Exp>> otpl;
protected
DAE.Exp e;
list<DAE.Exp> el;
algorithm
Expand Down Expand Up @@ -7816,7 +7817,7 @@ protected function buildDiscreteVarChangesAddEvent
input Integer indx;
input Expression.ComponentRef cr;
output String str;
protected
protected
String crStr,indxStr;
algorithm
crStr := ComponentReference.printComponentRefStr(cr);
Expand All @@ -7830,6 +7831,7 @@ protected function mixedCollectRelations "function: mixedCollectRelations
input list<BackendDAE.Equation> c_eqn;
input list<BackendDAE.Equation> d_eqn;
output list<DAE.Exp> res;
protected
list<DAE.Exp> l1,l2;
algorithm
l1 := mixedCollectRelations2(c_eqn);
Expand Down Expand Up @@ -8201,6 +8203,7 @@ protected function makeResidualReplacements "function: makeResidualReplacements
"
input list<Expression.ComponentRef> crefs;
output VarTransform.VariableReplacements repl_1;
protected
VarTransform.VariableReplacements repl;
algorithm
repl := VarTransform.emptyReplacements();
Expand Down Expand Up @@ -8674,6 +8677,7 @@ end filterNg;

protected function useZerocrossing
output Boolean res;
protected
Boolean flagSet;
algorithm
flagSet := RTOpts.debugFlag("noevents");
Expand Down Expand Up @@ -9822,6 +9826,7 @@ protected function hashFunc "
"
input Key cr;
output Integer res;
protected
String crstr;
algorithm
crstr := ComponentReference.printComponentRefStr(cr);
Expand Down Expand Up @@ -9905,6 +9910,7 @@ public function emptyHashTable "
Returns an empty HashTable.
Using the bucketsize 100 and array size 10."
output HashTableCrefToSimVar hashTable;
protected
array<list<tuple<Key,Integer>>> arr;
list<Option<tuple<Key,Value>>> lst;
array<Option<tuple<Key,Value>>> emptyarr;
Expand Down
2 changes: 2 additions & 0 deletions Compiler/BackEnd/TaskGraph.mo
Expand Up @@ -461,6 +461,7 @@ protected function makeResidualReplacements "function: makeResidualReplacements
"
input list<DAE.Exp> expl;
output VarTransform.VariableReplacements repl_1;
protected
VarTransform.VariableReplacements repl;
algorithm
repl := VarTransform.emptyReplacements();
Expand Down Expand Up @@ -983,6 +984,7 @@ protected function buildCallStr
input String str;
input Integer n;
output String res;
protected
list<String> ns;
String ns_1;
algorithm
Expand Down
2 changes: 2 additions & 0 deletions Compiler/BackEnd/XMLDump.mo
Expand Up @@ -2148,6 +2148,7 @@ This function dumps a matrix using an xml representation.
</matrix>
"
input BackendDAE.IncidenceMatrix m;
protected
list<list<BackendDAE.Value>> m_1;
algorithm
/* _:=
Expand Down Expand Up @@ -2517,6 +2518,7 @@ public function dumpMatching
author: PA
prints the matching information on stdout."
input array<Integer> v;
protected
BackendDAE.Value len;
String len_str;
algorithm
Expand Down
5 changes: 5 additions & 0 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -1776,6 +1776,7 @@ public function traverseExpBidir

replaceable type Argument subtypeof Any;

protected
FuncType enterFunc, exitFunc;
Argument arg;
Exp e;
Expand Down Expand Up @@ -2083,6 +2084,7 @@ public function traverseExpBidirElseIf

replaceable type Argument subtypeof Any;

protected
Exp e1, e2;
tuple<FuncType, FuncType, Argument> tup;
algorithm
Expand Down Expand Up @@ -2148,6 +2150,7 @@ public function traverseExpBidirNamedArg

replaceable type Argument subtypeof Any;

protected
Ident name;
Exp value;
algorithm
Expand All @@ -2171,6 +2174,7 @@ public function traverseExpBidirIterator

replaceable type Argument subtypeof Any;

protected
Ident name;
Option<Exp> guardExp,range;
algorithm
Expand Down Expand Up @@ -2692,6 +2696,7 @@ public function stringPath
input String str;
output Path qualifiedPath;

protected
list<String> paths;
algorithm
paths := Util.stringSplitAtChar(str, ".");
Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/Ceval.mo
Expand Up @@ -4785,6 +4785,7 @@ protected function cevalRelation
input Values.Value inValue2;
output Values.Value outValue;

protected
Boolean result;
algorithm
result := cevalRelation_dispatch(inValue1, inOperator, inValue2);
Expand Down
3 changes: 3 additions & 0 deletions Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -671,6 +671,7 @@ end dumpStateSelectStr;
public function dumpVariableAttributes "function: dumpVariableAttributes
Dump VariableAttributes option."
input Option<DAE.VariableAttributes> attr;
protected
String res;
algorithm
res := dumpVariableAttributesStr(attr);
Expand Down Expand Up @@ -933,6 +934,7 @@ end dumpAnnotationStr;
protected function dumpCommentOption "function: dumpCommentOption_str
Dump Comment option."
input Option<SCode.Comment> comment;
protected
String str;
algorithm
str := dumpCommentOptionStr(comment);
Expand Down Expand Up @@ -2313,6 +2315,7 @@ public function dumpGraphviz "
the dae
"
input DAE.DAElist dae;
protected
Graphviz.Node r;
algorithm
r := buildGraphviz(dae);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Expression.mo
Expand Up @@ -4277,7 +4277,7 @@ public function traverseExpBidir
end FuncType;

replaceable type Argument subtypeof Any;

protected
FuncType enterFunc, exitFunc;
Argument arg;
DAE.Exp e;
Expand Down
76 changes: 50 additions & 26 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -977,6 +977,7 @@ public function makeSimpleEnvFromProgram
input SCode.Path c;
output Env.Cache outCache;
output Env.Env env_1;
protected
list<Env.Frame> env;
algorithm
env := Builtin.simpleInitialEnv();
Expand Down Expand Up @@ -7926,6 +7927,7 @@ algorithm
case (cache,env,ih,store,ci_state,mod,pre,n,cl,attr,pf,dims,idxs,inst_dims,impl,comment,info,graph,csets)
equation
ClassInf.isFunction(ci_state);
checkFunctionVar(n, attr, pf, info);

//Do not flatten because it is a function
dims_1 = instDimExpLst(dims, impl);
Expand Down Expand Up @@ -7965,6 +7967,8 @@ algorithm
case (cache,env,ih,store,ci_state,mod,pre,n,(cl as SCode.CLASS(name=n2)),attr,pf,dims,idxs,inst_dims,impl,comment,info,graph,csets)
equation
ClassInf.isFunction(ci_state);
checkFunctionVar(n, attr, pf, info);

//Instantiate type of the component, skip dae/not flattening
(cache,env_1,ih,store,dae1,csets,ty,st,_,_) =
instClass(cache, env, ih, store, mod, pre, cl, inst_dims, impl, INNER_CALL(), ConnectionGraph.EMPTY, csets);
Expand Down Expand Up @@ -8294,6 +8298,43 @@ algorithm
end match;
end checkModificationOnOuter;

protected function checkFunctionVar
"Checks that a function variable is valid."
input String inName;
input SCode.Attributes inAttributes;
input SCode.Prefixes inPrefixes;
input Absyn.Info inInfo;
algorithm
_ := match(inName, inAttributes, inPrefixes, inInfo)
// Public non-formal parameters are not allowed, but since they're used in
// the MSL we just issue a warning for now.
case (_, SCode.ATTR(direction = Absyn.BIDIR()),
SCode.PREFIXES(visibility = SCode.PUBLIC()), _)
equation
Error.addSourceMessage(Error.NON_FORMAL_PUBLIC_FUNCTION_VAR,
{inName}, inInfo);
then
();

// Protected non-formal parameters are ok.
case (_, SCode.ATTR(direction = Absyn.BIDIR()),
SCode.PREFIXES(visibility = SCode.PROTECTED()), _)
then ();

// Protected formal parameters are not allowed.
case (_, SCode.ATTR(direction = _),
SCode.PREFIXES(visibility = SCode.PROTECTED()), _)
equation
Error.addSourceMessage(Error.PROTECTED_FORMAL_FUNCTION_VAR,
{inName}, inInfo);
then
fail();

// Everything else, i.e. public formal parameters, are ok.
else ();
end match;
end checkFunctionVar;

protected function checkFunctionVarType
input DAE.Type inType;
input ClassInf.State inState;
Expand Down Expand Up @@ -16171,37 +16212,20 @@ public input/output, protected variable/parameter/constant or algorithm section"
algorithm
_ := match (elt,isExternal,info)
local
DAE.ComponentRef cr;
String name,str;
DAE.ElementSource source;
// Until we fix warnings, we need to pass these through... Also, it's used in MSL
case (DAE.VAR(protection=DAE.PUBLIC()),_,_) then ();
/*
case (DAE.VAR(protection=DAE.PUBLIC(),direction=DAE.INPUT()),_) then ();
case (DAE.VAR(protection=DAE.PUBLIC(),direction=DAE.OUTPUT()),_) then ();
case (DAE.VAR(protection=DAE.PUBLIC(),direction=DAE.BIDIR(),kind=DAE.VARIABLE()),_)
equation
// TODO: Implement warnings for this case...
then ();
case (DAE.VAR(source=source,componentRef=cr,protection=DAE.PUBLIC()),_)
equation
name = ComponentReference.printComponentRefStr(cr);
Error.addSourceMessage(Error.FUNCTION_ELEMENT_WRONG_PROTECTION,{name,"public","protected"},DAEUtil.getElementSourceFileInfo(source));
then fail();
*/
case (DAE.VAR(protection=DAE.PROTECTED(),direction=DAE.BIDIR()),_,_) then ();
case (DAE.VAR(source=source,componentRef=cr,protection=DAE.PROTECTED()),_,_)
equation
name = ComponentReference.printComponentRefStr(cr);
Error.addSourceMessage(Error.FUNCTION_ELEMENT_WRONG_PROTECTION,{name,"protected","public"},DAEUtil.getElementSourceFileInfo(source));
then fail();
String str;

// Variables have already been checked in checkFunctionVar.
case (DAE.VAR(componentRef = _), _, _) then ();

case (DAE.ALGORITHM(algorithm_=DAE.ALGORITHM_STMTS({DAE.STMT_ASSIGN(exp=DAE.METARECORDCALL(path=_))})),_,info)
case (DAE.ALGORITHM(algorithm_= DAE.ALGORITHM_STMTS({DAE.STMT_ASSIGN(
exp = DAE.METARECORDCALL(path = _))})), _, info)
equation
// We need to know the inlineType to make a good notification
// Error.addSourceMessage(true,Error.COMPILER_NOTIFICATION, {"metarecordcall"}, info);
then ();
case (DAE.ALGORITHM(algorithm_=_),false,_) then ();

case (DAE.ALGORITHM(algorithm_ = _), false, _) then ();

else
equation
str = DAEDump.dumpElementsStr({elt});
Expand Down
6 changes: 4 additions & 2 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -2096,6 +2096,7 @@ algorithm
// adrpo: 2010-11-09 : TODO! FIXME! why is this?? keep the variability!
// var = SCode.VAR();
// dir = Absyn.INPUT();
vis = SCode.PROTECTED();
then
(SCode.COMPONENT(id,SCode.PREFIXES(vis,redecl,f,io,repl),SCode.ATTR(d,fl,st,var,dir),tp,umod,comment,cond,info) :: res);

Expand All @@ -2121,7 +2122,8 @@ algorithm
// - Prefixes (constant, parameter, final, discrete, input, output, ...) of the remaining record components are removed.
// adrpo: 2010-11-09 : TODO! FIXME! why is this?? keep the variability!
// var = SCode.VAR();
dir = Absyn.INPUT();
//dir = Absyn.INPUT();
vis = SCode.PROTECTED();
then
(SCode.COMPONENT(id,SCode.PREFIXES(vis,redecl,f,io,repl),SCode.ATTR(d,fl,st,var,dir),tp,umod,comment,cond,info) :: res);

Expand Down Expand Up @@ -2881,7 +2883,7 @@ algorithm
(outCache,outEnv,_,_,_,_,_,varlst,_) := Inst.instElementList(
cache,env,InnerOuter.emptyInstHierarchy, UnitAbsyn.noStore,
DAE.NOMOD(),Prefix.NOPRE(),
ClassInf.FUNCTION(Absyn.IDENT("")), Util.listMap1(els,Util.makeTuple2,DAE.NOMOD()),
ClassInf.META_RECORD(Absyn.IDENT("")), Util.listMap1(els,Util.makeTuple2,DAE.NOMOD()),
{}, false, Inst.INNER_CALL(), ConnectionGraph.EMPTY, Connect.emptySet, true);
varlst := Types.boxVarLst(varlst);
ftype := (DAE.T_METARECORD(utPath,index,varlst,singleton),SOME(path));
Expand Down

0 comments on commit bfbfaff

Please sign in to comment.