Hi Thomas,
Did you integrate the patch in the grammar?
If so did you create and include a testcase for it as well?
Den 02/12/2011 kl. 12.00 skrev Thomas Schwinge:
> Hi!
>
> On Mon, 21 Nov 2011 17:00:26 +0100, I wrote:
>> Today I found an issue with the default case in switch statements:
>>
>> switch_statement {-> statement} =
>> switch condition switch_block {-> New
>> statement.switch(condition.expression, [switch_block.statement])};
>>
>> switch_block {-> statement*} =
>> l_brc switch_block_statement_group* switch_label* r_brc {->
>> [switch_block_statement_group.statement, New
>> statement.switch_block([switch_label.expression], [])]} ;
>>
>> switch_block_statement_group {-> statement} =
>> switch_label+ block_statement+ {-> New
>> statement.switch_block([switch_label.expression],
>> [block_statement.statement])};
>>
>> switch_label {-> expression?} =
>> {expression} case constant_exp colon {-> constant_exp.expression} |
>> {default} default colon {-> Null};
>>
>> (Please see
>> <https://bitbucket.org/jdn/java5grammar/src/eb90e50d0139/grammar/java5.sablecc>
>> for the whole grammar.)
>>
>> [...]
>>
>> But, in the following case:
>>
>> switch (x)
>> {
>> [...]
>>
>> case 30:
>> default:
>> case 300:
>> a = 0;
>> break;
>>
>> [...]
>> }
>>
>> ..., the 30 and 300 cases will build a switch_label list, but the default
>> case will no longer be detectable: due to its mapping to Null, it will
>> simply not be added to this switch_label list, and will thus no longer be
>> detectable, contrary to the empty list case in the example before.
>
> Here is a patch; Janus has confirmed in private email that this matches
> the method he'd use to address the issue:
>
> --- java5.sablecc
> +++ java5.sablecc
> @@ -1075,9 +1075,9 @@ switch_block {-> statement*} =
> switch_block_statement_group {-> statement} =
> switch_label+ block_statement+ {-> New
> statement.switch_block([switch_label.expression],
> [block_statement.statement])};
>
> -switch_label {-> expression?} =
> +switch_label {-> expression} =
> {expression} case constant_exp colon {-> constant_exp.expression} |
> - {default} default colon {-> Null};
> + {default} default colon {-> New expression.default()};
>
> while_statement {-> statement} =
> while condition statement {-> New statement.while(condition.expression,
> statement)};
> @@ -1677,6 +1677,7 @@ finally_clause =
> statement*;
>
> expression =
> + {default} |
> {annotation} annotation |
> {values} [values]:expression* |
> {value_pair} identifier [value]:expression |
>
>
> Grüße,
> Thomas
____________________________________________________
Janus Dam Nielsen
Research and Innovationspecialist, CSM, PhD.
CENTRE FOR IT-SECURITY
THE ALEXANDRA INSTITUTE LTD.
T +45 40 83 09 10
E [email protected]
W alexandra.dk
See our blog about security at blog.sikkerhed.alexandra.dk
____________________________________________________
_______________________________________________
SableCC-Discussion mailing list
[email protected]
http://lists.sablecc.org/listinfo/sablecc-discussion