1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

translate new T[] {e,e,e} don't emit 'new' modifier, comment 'extern'

This commit is contained in:
Kevin Glynn 2010-12-17 13:48:09 +01:00
parent 22caf78c9d
commit a9c0e5acc6
3 changed files with 13 additions and 9 deletions

View File

@ -201,8 +201,8 @@ modifiers returns [List<string> modList]
}: }:
(modifier { if ($modifier.tree != null) $modList.Add( $modifier.tree.Text); })+ ; (modifier { if ($modifier.tree != null) $modList.Add( $modifier.tree.Text); })+ ;
modifier: modifier:
'new' | 'public' | 'protected' | 'private' | 'internal' -> /* translate to package-private */| 'unsafe' -> | 'abstract' | 'sealed' -> FINAL["final"] | 'static' 'new' -> /* No new in Java*/ | 'public' | 'protected' | 'private' | 'internal' -> /* translate to package-private */| 'unsafe' -> | 'abstract' | 'sealed' -> FINAL["final"] | 'static'
| 'readonly' -> /* no equivalent in C# (this is like a const that can be initialized separately in the constructor) */ | 'volatile' | 'extern' | 'virtual' -> | 'override' -> /* not in Java,maybe convert to override annotation */; | 'readonly' -> /* no equivalent in C# (this is like a const that can be initialized separately in the constructor) */ | 'volatile' | e='extern' { Warning($e.line, "[UNSUPPORTED] 'extern' modifier"); } | 'virtual' -> | 'override' -> /* not in Java, maybe convert to override annotation */;
class_member_declaration: class_member_declaration:
a=attributes? a=attributes?

View File

@ -244,10 +244,13 @@ namespace_name
modifiers: modifiers:
ms+=modifier+ -> modifiers(mods={$ms}); ms+=modifier+ -> modifiers(mods={$ms});
modifier modifier
@init {
String thetext = null;
}
: :
(m='new' | m='public' | m='protected' | m='private' | m='abstract' | m='sealed' | m='static' (m='new' | m='public' | m='protected' | m='private' | m='abstract' | m='sealed' | m='static'
| m='readonly' | m='volatile' | m='extern' | m='virtual' | m='override' | m=FINAL) | m='readonly' | m='volatile' | m='extern' { thetext = "/* [UNSUPPORTED] 'extern' modifier not supported */"; } | m='virtual' | m='override' | m=FINAL)
-> string(payload={$m.text}); -> string(payload={ (thetext == null ? $m.text : thetext) });
class_member_declaration returns [List<String> preComments]: class_member_declaration returns [List<String> preComments]:
^(CONST attributes? modifiers? type { $preComments = CollectedComments; } constant_declarators) ^(CONST attributes? modifiers? type { $preComments = CollectedComments; } constant_declarators)
@ -431,21 +434,21 @@ primary_or_array_creation_expression returns [int precedence]:
array_creation_expression returns [int precedence]: array_creation_expression returns [int precedence]:
^('new' ^('new'
(type ('[' expression_list ']' (type ('[' expression_list ']'
( rank_specifiers? array_initializer? -> array_construct(type = { $type.st }, args = { $expression_list.st }) // new int[4] ( rank_specifiers? ai1=array_initializer? -> array_construct(type = { $type.st }, args = { $expression_list.st }, inits = { $ai1.st }) // new int[4]
// | invocation_part* // | invocation_part*
| ( ((arguments ('['|'.'|'->')) => arguments invocation_part)// new object[2].GetEnumerator() | ( ((arguments ('['|'.'|'->')) => arguments invocation_part)// new object[2].GetEnumerator()
| invocation_part)* arguments | invocation_part)* arguments
) // new int[4]() ) // new int[4]()
| array_initializer | ai2=array_initializer -> array_construct(type = { $type.st }, inits = { $ai2.st })
) )
| rank_specifier // [,] | rank_specifier // [,]
(array_initializer // var a = new[] { 1, 10, 100, 1000 }; // int[] (array_initializer // var a = new[] { 1, 10, 100, 1000 }; // int[]
) )
)) { $precedence = precedence[NEW]; }; )) { $precedence = precedence[NEW]; };
array_initializer: array_initializer:
'{' variable_initializer_list? ','? '}' ; '{' variable_initializer_list? ','? '}' -> array_initializer(init = { $variable_initializer_list.st });
variable_initializer_list: variable_initializer_list:
variable_initializer (',' variable_initializer)* ; vs+=variable_initializer (',' vs+=variable_initializer)* -> seplist(items = { $vs }, sep = {", "});
variable_initializer: variable_initializer:
expression -> { $expression.st } | array_initializer -> { $array_initializer.st }; expression -> { $expression.st } | array_initializer -> { $array_initializer.st };
sizeof_expression: sizeof_expression:

View File

@ -225,7 +225,8 @@ block(statements,issemi,isbraces) ::= <<
cast_expr(type, exp) ::= "(<type>)<exp>" cast_expr(type, exp) ::= "(<type>)<exp>"
construct(type, args, inits) ::= "new <type>(<args>)<if(inits)> /* [UNIMPLEMENTED] <inits> */<endif>" construct(type, args, inits) ::= "new <type>(<args>)<if(inits)> /* [UNIMPLEMENTED] <inits> */<endif>"
array_construct(type, args, inits) ::= "new <type>[<args>]<if(inits)> /* [UNIMPLEMENTED] <inits> */<endif>" array_construct(type, args, inits) ::= "new <type><if(args)>[<args>]<endif><if(inits)><inits><endif>"
array_initializer(init) ::= "{ <init> }"
application(func, funcparens, args) ::= "<optparens(parens=funcparens,e=func)>(<args>)" application(func, funcparens, args) ::= "<optparens(parens=funcparens,e=func)>(<args>)"
index(func, funcparens, args) ::= "<optparens(parens=funcparens,e=func)>[<args>]" index(func, funcparens, args) ::= "<optparens(parens=funcparens,e=func)>[<args>]"
stackalloc(type, exp) ::= "stackalloc <type>[<exp>]" stackalloc(type, exp) ::= "stackalloc <type>[<exp>]"