Skip to content

Commit

Permalink
Modified the pattern match algorithm.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2864 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Kristian Stavåker committed Aug 7, 2007
1 parent 540d466 commit 36dbfc4
Show file tree
Hide file tree
Showing 10 changed files with 1,565 additions and 756 deletions.
21 changes: 21 additions & 0 deletions Compiler/Absyn.mo
Expand Up @@ -560,7 +560,28 @@ uniontype Algorithm "The Algorithm type describes one algorithm statement in an

record ALG_BREAK
end ALG_BREAK;

// Part of MetaModelica extension. KS
record ALG_TRY
list<AlgorithmItem> tryBody;
end ALG_TRY;

record ALG_CATCH
list<AlgorithmItem> catchBody;
end ALG_CATCH;

record ALG_THROW
end ALG_THROW;

record ALG_GOTO
String labelName;
end ALG_GOTO;

record ALG_LABEL
String labelName;
end ALG_LABEL;
//-------------------------------

end Algorithm;

public
Expand Down
23 changes: 22 additions & 1 deletion Compiler/Algorithm.mo
Expand Up @@ -143,7 +143,28 @@ uniontype Statement "There are four kinds of statements. Assignments (`a := b;\

record BREAK
end BREAK;


// MetaModelica extension. KS
record TRY
list<Statement> tryBody;
end TRY;

record CATCH
list<Statement> catchBody;
end CATCH;

record THROW
end THROW;

record GOTO
String labelName;
end GOTO;

record LABEL
String labelName;
end LABEL;
//-----

end Statement;

public
Expand Down
61 changes: 54 additions & 7 deletions Compiler/Codegen.mo
Expand Up @@ -2699,7 +2699,53 @@ algorithm
equation
cfn = cAddStatements(cEmptyFunction, {"break;"});
then
(cfn,tnr);
(cfn,tnr);
// Part of MetaModelica Extension. KS
//--------------------------------
case (Algorithm.TRY(stmts),tnr,context)
equation
//cfn1 = cAddStatements(cEmptyFunction, {"{"}); // try
(cfn2,tnr2) = generateAlgorithmStatements(stmts, tnr,
context);
//cfn2_1 = cAddStatements(cfn2, {"}"});
//cfn = cMergeFns({cfn1,cfn2_1});
then
(cfn2,tnr2);

case (Algorithm.CATCH(stmts),tnr,context)
equation
//cfn1 = cAddStatements(cEmptyFunction, {"{"}); //catch(int i)
//(cfn2,tnr2) = generateAlgorithmStatements(stmts, tnr,
// context);
//cfn2_1 = cAddStatements(cfn2, {"}"});
//cfn = cMergeFns({cfn1,cfn2_1});
then
(cEmptyFunction,tnr);

case (Algorithm.THROW(),tnr,context)
equation
cfn = cAddStatements(cEmptyFunction, {"throw 1;"});
then (cfn,tnr);

case (Algorithm.GOTO(s),tnr,context)
local
String s,s2;
equation
s2 = stringAppend("goto ",s);
s2 = stringAppend(s2,";");
cfn = cAddStatements(cEmptyFunction, {s2});
then (cfn,tnr);

case (Algorithm.LABEL(s),tnr,context)
local
String s,s2;
equation
s2 = stringAppend(s,":");
cfn = cAddStatements(cEmptyFunction, {s2});
then (cfn,tnr);

//-------------------------------

case (stmt,_,_)
local Algorithm.Statement stmt;
equation
Expand Down Expand Up @@ -3773,16 +3819,17 @@ algorithm
b2 = Convert.fromExpElemToDAEElem(b);

(cfn,tnr_1) = generateVars(ld2, isVarQ, tnr, funContext);
cfn = cMoveDeclsAndInitsToStatements(cfn);

(cfn1,tnr2) = generateAlgorithms(Util.listCreate(b2), tnr_1, context);

(cfn1_2,var,tnr3) = generateExpression(res, tnr2, context);

//-----
(cfn1_2,tnr4,var) = addValueblockRetVar(ty,cfn1_2,tnr3,var,context);
//-----
(cfn1_2,var,tnr3) = generateExpression(res, tnr2, context);

cfn1_2 = cMergeFns({cfn,cfn1,cfn1_2});

cfn1_2 = cMoveDeclsAndInitsToStatements(cfn1_2);
//-----
(cfn1_2,tnr4,var) = addValueblockRetVar(ty,cfn1_2,tnr3,var,context);
//-----

cfn1_2 = cAddBlockAroundStatements(cfn1_2);
then (cfn1_2,var,tnr4);
Expand Down
52 changes: 41 additions & 11 deletions Compiler/Convert.mo
Expand Up @@ -548,8 +548,9 @@ algorithm
Exp.Statement elem;
equation
elem = Exp.BREAK();
then elem;
/* case (Algorithm.TRY(b))
then elem;
// Part of MetaModelica extension
case (Algorithm.TRY(b))
local
list<Algorithm.Statement> b;
Exp.Statement elem;
Expand All @@ -568,11 +569,25 @@ algorithm
elem = Exp.CATCH(b2);
then elem;
case (Algorithm.THROW())
local
local
Exp.Statement elem;
equation
elem = Exp.THROW();
then elem; */
then elem;
case (Algorithm.GOTO(s))
local
Exp.Statement elem;
String s;
equation
elem = Exp.GOTO(s);
then elem;
case (Algorithm.LABEL(s))
local
Exp.Statement elem;
String s;
equation
elem = Exp.LABEL(s);
then elem;
end matchcontinue;
end fromAlgStateToExpState;

Expand Down Expand Up @@ -1111,8 +1126,9 @@ algorithm
Algorithm.Statement elem;
equation
elem = Algorithm.BREAK();
then elem;
/* case (Exp.TRY(b))
then elem;
// Part of MetaModelica extension
case (Exp.TRY(b))
local
list<Exp.Statement> b;
Algorithm.Statement elem;
Expand All @@ -1131,11 +1147,25 @@ algorithm
elem = Algorithm.CATCH(b2);
then elem;
case (Exp.THROW())
local
Algorithm.Statement elem;
equation
elem = Algorithm.THROW();
then elem; */
local
Algorithm.Statement elem;
equation
elem = Algorithm.THROW();
then elem;
case (Exp.GOTO(s))
local
Algorithm.Statement elem;
String s;
equation
elem = Algorithm.GOTO(s);
then elem;
case (Exp.LABEL(s))
local
String s;
Algorithm.Statement elem;
equation
elem = Algorithm.LABEL(s);
then elem;
end matchcontinue;
end fromExpStateToAlgState;

Expand Down

0 comments on commit 36dbfc4

Please sign in to comment.