Skip to content

Commit c230daa

Browse files
committed
new try catch syntax
1 parent 8f1ca77 commit c230daa

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

src/common/stmt-syntax.k

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,20 @@ syntax SwitchBlock::= "{" KListWrap KListWrap "}" [klabel('SwitchBlock)]
4343
syntax DoStmt ::="do" "{" K "}" "while" "(" K ")"[strict(2),klabel('DoWhile)]
4444
syntax TryStmt ::= "try" Block KListWrap "finally" Block [klabel('Try)]
4545
|"try" Block KListWrap [klabel('Try)]
46-
|"catch" "(" K ")" Block [klabel('Catch)]
47-
//todo:catches
48-
//syntax Catches ::= List{CatchClause,""}
49-
//syntax KItem ::= toCatches( KListWrap ) [function]
50-
// | toCatches( KListWrap , Catches ) [function]
51-
//rule [L:KList,,C:CatchClause] => toCatches([L,,C])
52-
//rule toCatches([KLCatches:KList]) => toCatches([KLCatches],.Catches)
53-
//rule toCatches([KLCatches:KList,, C:CatchClause], Catches:Catches) => toCatches([KLCatches], (C Catches))
54-
//rule toCatches([.KList], Catches:Catches) => Catches
46+
47+
syntax Param ::= Type Id
48+
syntax CatchClause ::= "catch" "(" Param ")" Block [klabel('Catch)]
49+
syntax CatchClauses ::= List{CatchClause,""}
50+
syntax CatchClauses ::= toCatchClauses( KListWrap ) [function]
51+
| toCatchClauses( KListWrap , CatchClauses ) [function]
52+
rule [L:KList,,C:CatchClause] => toCatchClauses([L,,C])
53+
rule toCatchClauses([KLCatchClauses:KList]) => toCatchClauses([KLCatchClauses],.CatchClauses)
54+
rule toCatchClauses([KLCatchClauses:KList,, C:CatchClause], CatchClauses:CatchClauses) => toCatchClauses([KLCatchClauses], (C CatchClauses))
55+
rule toCatchClauses([.KList], CatchClauses:CatchClauses) => CatchClauses
56+
57+
//syntax TryStmt ::= "try" Block CatcheClauses "finally" Block [klabel('Try)]
58+
// |"try" Block CatcheClauses [klabel('Try)]
59+
//rule 'Try(B1)
5560

5661
syntax StackConsumerStmt ::= "dummyStackConsumerStmt"|ThrowStmt|ContinueStmt|BreakStmt|ReturnStmt
5762
syntax ThrowStmt ::= "throw" K ";" [strict, klabel('Throw)]

src/exec/method-invoke.k

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ syntax KItem ::= initParams ( Params, // {T:Type X:Id},... - parameter declara
767767
)
768768

769769
rule [initParams]:
770-
initParams(P{T:Type X:Id}, RestP:Params, (TV:TypedVal, RestV:TypedVals))
770+
initParams((T:Type X:Id, RestP:Params), (TV:TypedVal, RestV:TypedVals))
771771
=> T X;
772772
~> (X = ((T) TV:TypedVal));
773773
~> initParams(RestP, RestV)

src/exec/statements.k

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ rule [Throw]:
358358
(. => checkCatch(subtype(typeOf(TV), T)))
359359
// ~> 'Throw(TV:TypedVal)
360360
~> throw TV:TypedVal;
361-
~> catchBlocks([catchImpl('ParamImpl(T:Type,, X:Id),_),, _])
361+
~> catchBlocks([catchImpl(T:Type X:Id,_),, _])
362362

363363
syntax KItem ::= checkCatch ( K )
364364
context checkCatch(HOLE)
@@ -426,7 +426,7 @@ context try _:K [_,, HOLE,, _]
426426

427427
context catch(HOLE)_ [result(ExtKResult)]
428428

429-
rule catch(KR:ExtKResult)S:K => catchImpl(KR,S)
429+
rule catch(KR:Param)S:K => catchImpl(KR,S)
430430

431431
/*@ Extended K Result.
432432
Represents KLabels that should be treated as KResult during execution phase, but not during elaboration phase.
@@ -435,7 +435,7 @@ syntax ExtKResult ::= "dummy"
435435

436436
rule isExtKResult(KR:KResult) => true
437437

438-
rule isExtKResult('ParamImpl(T:Type,, _:Id)) => true
438+
rule isExtKResult(T:Type _:Id) => true
439439

440440
//@ Internal representation of a preprocessed catch clause
441441
syntax KResult ::= catchImpl (

src/exec/syntax-conversions.k

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,20 @@ module SYNTAX-CONVERSIONS
1313
// 'Param(\_:K,, T:Type,, X:Id). Consumed by initParams().
1414
syntax KLabel ::= "'Param"
1515

16-
//Required for catch
17-
rule 'Param(_,, K:K,, X:Id) => P{K X} [structural]
18-
19-
//add P to {} in case of ambiguity
20-
syntax Param ::= "P{" K Id "}" [klabel('ParamImpl)]
16+
//Required for catch, 'Param cannot be added as klabel attribute for Param ::= Type Id
17+
rule 'Param(_,, K:Type,, X:Id) => K X [structural]
2118

2219
syntax Params ::= List{Param, ","}
2320

2421
syntax KItem ::= toParams( KListWrap ) [function]
2522
| toParams( KListWrap , Params ) [function]
2623

2724
rule toParams([KLParams:KList]) => toParams([KLParams], .Params)
28-
rule toParams([KLParams:KList,, 'Param(_,, K:K,, X:Id)], Params:Params) => toParams([KLParams], (P{K X},Params))
25+
rule toParams([KLParams:KList,, 'Param(_,, K:Type,, X:Id)], Params:Params) => toParams([KLParams], (K X,Params))
2926
rule toParams([.KList], Params:Params) => Params
3027

3128
// Required for getTypes()
32-
rule typeOf('ParamImpl(T:Type,, _:Id)) => T
29+
rule typeOf(T:Type _:Id) => T
3330

3431
/*@ \subsection{Method invocation}*/
3532

0 commit comments

Comments
 (0)