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:
'new' | '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 */;
'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' | e='extern' { Warning($e.line, "[UNSUPPORTED] 'extern' modifier"); } | 'virtual' -> | 'override' -> /* not in Java, maybe convert to override annotation */;
class_member_declaration:
a=attributes?

View File

@ -244,10 +244,13 @@ namespace_name
modifiers:
ms+=modifier+ -> modifiers(mods={$ms});
modifier
@init {
String thetext = null;
}
:
(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)
-> string(payload={$m.text});
| m='readonly' | m='volatile' | m='extern' { thetext = "/* [UNSUPPORTED] 'extern' modifier not supported */"; } | m='virtual' | m='override' | m=FINAL)
-> string(payload={ (thetext == null ? $m.text : thetext) });
class_member_declaration returns [List<String> preComments]:
^(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]:
^('new'
(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*
| ( ((arguments ('['|'.'|'->')) => arguments invocation_part)// new object[2].GetEnumerator()
| invocation_part)* arguments
) // new int[4]()
| array_initializer
| ai2=array_initializer -> array_construct(type = { $type.st }, inits = { $ai2.st })
)
| rank_specifier // [,]
(array_initializer // var a = new[] { 1, 10, 100, 1000 }; // int[]
)
)) { $precedence = precedence[NEW]; };
array_initializer:
'{' variable_initializer_list? ','? '}' ;
'{' variable_initializer_list? ','? '}' -> array_initializer(init = { $variable_initializer_list.st });
variable_initializer_list:
variable_initializer (',' variable_initializer)* ;
vs+=variable_initializer (',' vs+=variable_initializer)* -> seplist(items = { $vs }, sep = {", "});
variable_initializer:
expression -> { $expression.st } | array_initializer -> { $array_initializer.st };
sizeof_expression:

View File

@ -225,7 +225,8 @@ block(statements,issemi,isbraces) ::= <<
cast_expr(type, exp) ::= "(<type>)<exp>"
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>)"
index(func, funcparens, args) ::= "<optparens(parens=funcparens,e=func)>[<args>]"
stackalloc(type, exp) ::= "stackalloc <type>[<exp>]"