Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Added DAE.STMT_FAILURE, and handling of Absyn.ALG_FAILURE. Simplified generation of code for failure()
- Added HashTable testing


git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6509 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 21, 2010
1 parent d1a0be6 commit 71e9184
Show file tree
Hide file tree
Showing 22 changed files with 579 additions and 359 deletions.
2 changes: 1 addition & 1 deletion Compiler/Absyn.mo
Expand Up @@ -586,7 +586,7 @@ uniontype Algorithm "The Algorithm type describes one algorithm statement in an
end ALG_LABEL;

record ALG_FAILURE
AlgorithmItem equ;
list<AlgorithmItem> equ;
end ALG_FAILURE;
//-------------------------------

Expand Down
5 changes: 5 additions & 0 deletions Compiler/Algorithm.mo
Expand Up @@ -755,6 +755,7 @@ algorithm
case DAE.STMT_ASSERT(cond = e1,msg= e2) then {e1,e2};
case DAE.STMT_BREAK(source = _) then {};
case DAE.STMT_RETURN(source = _) then {};
case DAE.STMT_FAILURE(body = stmts) then getAllExpsStmts(stmts);
case DAE.STMT_THROW(source = _) then {};
case DAE.STMT_TRY(tryBody = stmts)
equation
Expand Down Expand Up @@ -973,6 +974,10 @@ algorithm
talst2;
case (DAE.STMT_BREAK(source = _),_,_) then {};
case (DAE.STMT_RETURN(source = _),_,_) then {};
case (DAE.STMT_FAILURE(body = stmts),func,inTypeA)
equation
talst = traverseExpsStmts(stmts,func,inTypeA);
then talst;
case (DAE.STMT_THROW(source = _),_,_) then {};
case (DAE.STMT_TRY(tryBody = stmts),func,inTypeA)
equation
Expand Down
6 changes: 6 additions & 0 deletions Compiler/BackendVarTransform.mo
Expand Up @@ -538,6 +538,12 @@ algorithm
then
(DAE.STMT_BREAK(source):: es_1);
// MetaModelica extension. KS
case ((DAE.STMT_FAILURE(body=statementLst,source=source)::es),repl)
equation
statementLst_1 = replaceStatementLst(statementLst, repl);
es_1 = replaceStatementLst(es, repl);
then
(DAE.STMT_FAILURE(statementLst_1,source):: es_1);
case ((DAE.STMT_TRY(tryBody=statementLst,source=source)::es),repl)
equation
statementLst_1 = replaceStatementLst(statementLst, repl);
Expand Down
5 changes: 5 additions & 0 deletions Compiler/DAE.mo
Expand Up @@ -546,6 +546,11 @@ uniontype Statement "There are four kinds of statements. Assignments (`a := b;\
end STMT_BREAK;

// MetaModelica extension. KS
record STMT_FAILURE
list<Statement> body;
ElementSource source "the origin of the component/equation/algorithm";
end STMT_FAILURE;

record STMT_TRY
list<Statement> tryBody;
ElementSource source "the origin of the component/equation/algorithm";
Expand Down
8 changes: 8 additions & 0 deletions Compiler/DAEDump.mo
Expand Up @@ -1551,6 +1551,14 @@ algorithm
Print.printBuf(");\n");
then
();
case (DAE.STMT_FAILURE(body = stmts),i)
equation
indent(i);
Print.printBuf("begin failure\n");
ppStmtList(stmts, i+2);
Print.printBuf("end try;\n");
then
();
case (DAE.STMT_TRY(tryBody = stmts),i)
equation
indent(i);
Expand Down
12 changes: 12 additions & 0 deletions Compiler/DAELow.mo
Expand Up @@ -9805,6 +9805,12 @@ algorithm
st = replaceDummyDerAlgs1(rest,inExp2,inExp3);
then
(DAE.STMT_BREAK(source)::st);
case (DAE.STMT_FAILURE(body=stlst,source=source)::rest,inExp2,inExp3)
equation
stlst1 = replaceDummyDerAlgs1(stlst,inExp2,inExp3);
st = replaceDummyDerAlgs1(rest,inExp2,inExp3);
then
(DAE.STMT_FAILURE(stlst1,source)::st);
case (DAE.STMT_TRY(tryBody=stlst,source=source)::rest,inExp2,inExp3)
equation
stlst1 = replaceDummyDerAlgs1(stlst,inExp2,inExp3);
Expand Down Expand Up @@ -10148,6 +10154,12 @@ algorithm
(st,vars) = replaceDummyDerOthersAlgs1(rest,inVariables);
then
(DAE.STMT_BREAK(source)::st,vars);
case (DAE.STMT_FAILURE(body=stlst,source=source)::rest,inVariables)
equation
(stlst1,vars) = replaceDummyDerOthersAlgs1(stlst,inVariables);
(st,vars1) = replaceDummyDerOthersAlgs1(rest,vars);
then
(DAE.STMT_FAILURE(stlst1,source)::st,vars1);
case (DAE.STMT_TRY(tryBody=stlst,source=source)::rest,inVariables)
equation
(stlst1,vars) = replaceDummyDerOthersAlgs1(stlst,inVariables);
Expand Down
24 changes: 18 additions & 6 deletions Compiler/Dump.mo
Expand Up @@ -2954,13 +2954,18 @@ algorithm
Print.printBuf("BREAK()");
then
();
case Absyn.ALG_FAILURE(algItem)
case Absyn.ALG_FAILURE({algItem})
equation
Print.printBuf("FAILURE(");
printAlgorithmitem(algItem);
Print.printBuf(")");
then
();
case Absyn.ALG_FAILURE(_)
equation
Print.printBuf("FAILURE(...)");
then
();
case (_)
equation
Print.printBuf(" ** UNKNOWN ALGORITHM CLAUSE ** ");
Expand Down Expand Up @@ -3131,14 +3136,21 @@ algorithm
str = is +& "break" +& s3 +& ";";
then
str;
case (i,Absyn.ALGORITHMITEM(algorithm_ = Absyn.ALG_FAILURE(algItem),comment = optcmt)) /* ALG_FAILURE */
case (i,Absyn.ALGORITHMITEM(algorithm_ = Absyn.ALG_FAILURE({algItem}),comment = optcmt)) /* ALG_FAILURE */
equation
s1 = unparseAlgorithmStr(0, algItem);
s3 = unparseCommentOption(optcmt);
is = indentStr(i);
str = is +& "failure(" +& s1 +& ")" +& s3 +& ";";
then
str;
case (i,Absyn.ALGORITHMITEM(algorithm_ = Absyn.ALG_FAILURE(_),comment = optcmt)) /* ALG_FAILURE */
equation
s3 = unparseCommentOption(optcmt);
is = indentStr(i);
str = is +& "failure(...)" +& s3 +& ";";
then
str;
case (i,Absyn.ALGORITHMITEM(algorithm_ = Absyn.ALG_MATCHCASES(matchType=matchType,switchCases=explist), comment = optcmt))
local
Absyn.MatchType matchType;
Expand Down Expand Up @@ -5991,7 +6003,7 @@ algorithm
local
Absyn.Exp assignComponent, value, ifExp, boolExpr;
list<tuple<Absyn.Exp, list<Absyn.AlgorithmItem>>> elseIfAlgorithmBranch,elseWhenAlgorithmBranch;
list<Absyn.AlgorithmItem> trueBranch,elseBranch,forBody,whileBody,whenBody,tryBody,catchBody;
list<Absyn.AlgorithmItem> trueBranch,elseBranch,forBody,whileBody,whenBody,tryBody,catchBody,body;
Absyn.ForIterators iterators;
Absyn.ComponentRef functionCall;
Absyn.FunctionArgs functionArgs;
Expand Down Expand Up @@ -6099,10 +6111,10 @@ algorithm
Print.printBuf(label);
Print.printBuf("\" end Absyn.ALG_LABEL;");
then ();
case Absyn.ALG_FAILURE(equ)
case Absyn.ALG_FAILURE(body)
equation
Print.printBuf("record Absyn.ALG_FAILURE equ = ");
printAlgorithmItemAsCorbaString(equ);
Print.printBuf("record Absyn.ALG_FAILURE body = ");
printListAsCorbaString(body, printAlgorithmItemAsCorbaString, ",");
Print.printBuf(" end Absyn.ALG_FAILURE;");
then ();
end matchcontinue;
Expand Down
7 changes: 3 additions & 4 deletions Compiler/HashTable2.mo
Expand Up @@ -193,9 +193,9 @@ public function delete "
"
input Key key;
input HashTable hashTable;
output HashTable outHahsTable;
output HashTable outHashTable;
algorithm
outVariables:=
outHashTable :=
matchcontinue (key,hashTable)
local
Integer hval,indx,newpos,n,n_1,bsize,indx_1;
Expand All @@ -204,7 +204,6 @@ algorithm
array<list<tuple<Key,Integer>>> hashvec_1,hashvec;
String name_str;
tuple<Key,Value> v,newv;
Key key;
Value value;
/* adding when already present => Updating value */
case (key,(hashTable as HASHTABLE(hashvec,varr,bsize,n)))
Expand Down Expand Up @@ -499,7 +498,7 @@ algorithm
matchcontinue (valueArray,pos)
local
array<Option<tuple<Key,Value>>> arr_1,arr;
Integer n,size,pos;
Integer n,size;
case (VALUE_ARRAY(n,size,arr),pos)
equation
(pos < size) = true;
Expand Down
5 changes: 5 additions & 0 deletions Compiler/Inline.mo
Expand Up @@ -884,6 +884,11 @@ algorithm
e_1 = inlineExp(e,fns);
then
DAE.STMT_NORETCALL(e_1,source);
case(DAE.STMT_FAILURE(stmts,source),fns)
equation
stmts_1 = Util.listMap1(stmts,inlineStatement,fns);
then
DAE.STMT_FAILURE(stmts_1,source);
case(DAE.STMT_TRY(stmts,source),fns)
equation
stmts_1 = Util.listMap1(stmts,inlineStatement,fns);
Expand Down
15 changes: 13 additions & 2 deletions Compiler/InstSection.mo
Expand Up @@ -2811,9 +2811,20 @@ algorithm
then
(cache,{stmt});

//------------------------------------------
// Part of MetaModelica extension. KS
//------------------------------------------
// Part of MetaModelica extension.
//------------------------------------------
case (cache,env,ih,pre,SCode.ALG_FAILURE(stmts = sl, comment = comment, info = info),source,initial_,impl,unrollForLoops)
local
String s;
equation
true = RTOpts.acceptMetaModelicaGrammar();
(cache,sl_1) = instStatements(cache,env,ih,pre,sl,source,initial_,impl,unrollForLoops);
source = DAEUtil.addElementSourceFileInfo(source, info);
stmt = DAE.STMT_FAILURE(sl_1,source);
then
(cache,{stmt});

/* try */
case (cache,env,ih,pre,SCode.ALG_TRY(tryBody = sl, comment = comment, info = info),source,initial_,impl,unrollForLoops)
equation
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Lookup.mo
Expand Up @@ -2126,7 +2126,7 @@ algorithm
SCode.Class c;
list<Env.Frame> env_1,env,fs,i_env,prevFrames;
Env.Frame frame,f;
String id,sid,scope;
String sid,scope;
Boolean msg,msgflag;
Absyn.Path aid,path;
Env.Cache cache;
Expand Down
12 changes: 12 additions & 0 deletions Compiler/PartFn.mo
Expand Up @@ -924,6 +924,12 @@ algorithm
(cdr_1,dae) = elabStmts(cdr,dae);
then
(DAE.STMT_NORETCALL(e_1,source) :: cdr_1,dae);
case(DAE.STMT_FAILURE(stmts,source) :: cdr,dae)
equation
(stmts_1,dae) = elabStmts(stmts,dae);
(cdr_1,dae) = elabStmts(cdr,dae);
then
(DAE.STMT_FAILURE(stmts_1,source) :: cdr_1,dae);
case(DAE.STMT_TRY(stmts,source) :: cdr,dae)
equation
(stmts_1,dae) = elabStmts(stmts,dae);
Expand Down Expand Up @@ -1646,6 +1652,12 @@ algorithm
cdr_1 = fixCallsAlg(cdr,dae,p,inputs,current);
then
DAE.STMT_NORETCALL(e,source) :: cdr_1;
case(DAE.STMT_FAILURE(stmts,source) :: cdr,dae,p,inputs,current)
equation
stmts_1 = fixCallsAlg(stmts,dae,p,inputs,current);
cdr_1 = fixCallsAlg(cdr,dae,p,inputs,current);
then
DAE.STMT_FAILURE(stmts_1,source) :: cdr_1;
case(DAE.STMT_TRY(stmts,source) :: cdr,dae,p,inputs,current)
equation
stmts_1 = fixCallsAlg(stmts,dae,p,inputs,current);
Expand Down
11 changes: 11 additions & 0 deletions Compiler/PrefixUtil.mo
Expand Up @@ -1096,6 +1096,17 @@ algorithm
localAccList = listAppend(localAccList,Util.listCreate(elem));
(localCache,elems) = prefixStatements(localCache,localEnv,ih,rest,localAccList,pre);
then (localCache,elems);
case (localCache,localEnv,ih,DAE.STMT_FAILURE(b,source) :: rest,localAccList,pre)
local
list<DAE.Statement> b;
DAE.Statement elem;
list<DAE.Statement> elems;
equation
(localCache,b) = prefixStatements(localCache,localEnv,ih,b,{},pre);
elem = DAE.STMT_FAILURE(b,source);
localAccList = listAppend(localAccList,Util.listCreate(elem));
(localCache,elems) = prefixStatements(localCache,localEnv,ih,rest,localAccList,pre);
then (localCache,elems);
case (localCache,localEnv,ih,DAE.STMT_TRY(b,source) :: rest,localAccList,pre)
local
list<DAE.Statement> b;
Expand Down
8 changes: 4 additions & 4 deletions Compiler/SCode.mo
Expand Up @@ -427,7 +427,7 @@ public uniontype Statement "The Statement type describes one algorithm statement
end ALG_LABEL;

record ALG_FAILURE
Statement equ;
list<Statement> stmts;
Option<Comment> comment;
Absyn.Info info;
end ALG_FAILURE;
Expand Down Expand Up @@ -2595,10 +2595,10 @@ algorithm
case ALG_GOTO(labelName,comment,info)
then Absyn.ALGORITHMITEM(Absyn.ALG_GOTO(labelName),NONE(),info);

case ALG_FAILURE(equ,comment,info)
case ALG_FAILURE(body,comment,info)
equation
alg = statementToAlgorithmItem(equ);
then Absyn.ALGORITHMITEM(Absyn.ALG_FAILURE(alg),NONE(),info);
algs1 = Util.listMap(body,statementToAlgorithmItem);
then Absyn.ALGORITHMITEM(Absyn.ALG_FAILURE(algs1),NONE(),info);
end matchcontinue;
end statementToAlgorithmItem;

Expand Down
6 changes: 3 additions & 3 deletions Compiler/SCodeUtil.mo
Expand Up @@ -755,10 +755,10 @@ algorithm
case (Absyn.ALG_GOTO(labelName),comment,info)
then SCode.ALG_GOTO(labelName,comment,info);

case (Absyn.ALG_FAILURE(algi),comment,info)
case (Absyn.ALG_FAILURE(body),comment,info)
equation
{stmt} = translateClassdefAlgorithmitems({algi});
then SCode.ALG_FAILURE(stmt,comment,info);
stmts = translateClassdefAlgorithmitems(body);
then SCode.ALG_FAILURE(stmts,comment,info);

/*
case (_,comment,info)
Expand Down

0 comments on commit 71e9184

Please sign in to comment.