mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
NEW -> NEW, NEW_ARRAY, NEW_DELEGATE, NEW_ANON_OBJECT
replace var and dynamic by imaginary nodes TYPE_VAR and TYPE_DYNAMIC
This commit is contained in:
parent
2b87e38000
commit
f92d26412d
@ -474,10 +474,10 @@ dim_separators
|
||||
|
||||
delegate_creation_expression:
|
||||
// 'new'
|
||||
t1=type_name '(' t2=type_name ')' -> ^(NEW[$t1.start.Token, "new"] ^(TYPE[$t1.start.Token, "TYPE"] $t1) ^(ARGS[$t2.start.Token, "ARGS"] $t2));
|
||||
t1=type_name '(' t2=type_name ')' -> ^(NEW_DELEGATE[$t1.start.Token, "new(delegate)"] ^(TYPE[$t1.start.Token, "TYPE"] $t1) ^(ARGS[$t2.start.Token, "ARGS"] $t2));
|
||||
anonymous_object_creation_expression:
|
||||
// 'new'
|
||||
anonymous_object_initializer ;
|
||||
i=anonymous_object_initializer -> ^(NEW_ANON_OBJECT[$i.tree.Token, "new(anonobj)"] anonymous_object_initializer);
|
||||
anonymous_object_initializer:
|
||||
'{' (member_declarator_list ','?)? '}';
|
||||
member_declarator_list:
|
||||
@ -515,7 +515,7 @@ array_creation_expression
|
||||
}
|
||||
}
|
||||
}:
|
||||
n=NEWARRAY
|
||||
n=NEW_ARRAY
|
||||
(type ((o='[' expression_list c=']' -> ^($n type $o expression_list $c)) { ret = (CommonTree)adaptor.RulePostProcessing($array_creation_expression.tree); }
|
||||
( (rank_specifiers { adaptor.AddChild(ret, $rank_specifiers.tree); })?
|
||||
(ai1=array_initializer { adaptor.AddChild(ret, $ai1.tree);
|
||||
@ -1402,8 +1402,8 @@ declaration_statement:
|
||||
local_variable_declaration returns [List<string> variableNames]:
|
||||
local_variable_type local_variable_declarators { $variableNames = $local_variable_declarators.variableNames; };
|
||||
local_variable_type:
|
||||
('var') => 'var'
|
||||
| ('dynamic') => 'dynamic'
|
||||
('var') => v='var' -> TYPE_VAR[$v.token, "var"]
|
||||
| ('dynamic') => d='dynamic' -> TYPE_DYNAMIC[$d.token,"dynamic"]
|
||||
| type ;
|
||||
local_variable_declarators returns [List<string> variableNames]
|
||||
@init {
|
||||
|
@ -375,11 +375,8 @@ primary_expression returns [int precedence]
|
||||
// | ('base' brackets) => 'this' brackets primary_expression_part*
|
||||
// | primary_expression_start primary_expression_part*
|
||||
| ^(NEW type argument_list? object_or_collection_initializer?) { $precedence = precedence[NEW]; }-> construct(type = {$type.st}, args = {$argument_list.st}, inits = {$object_or_collection_initializer.st})
|
||||
| 'new' (
|
||||
// (try the simple one first, this has no argS and no expressions
|
||||
// symantically could be object creation)
|
||||
| (delegate_creation_expression) => delegate_creation_expression // new FooDelegate (MyFunction)
|
||||
| anonymous_object_creation_expression) // new {int X, string Y}
|
||||
| ^(NEW_DELEGATE delegate_creation_expression) // new FooDelegate (MyFunction)
|
||||
| ^(NEW_ANON_OBJECT anonymous_object_creation_expression) // new {int X, string Y}
|
||||
| sizeof_expression // sizeof (struct)
|
||||
| checked_expression -> { $checked_expression.st } // checked (...
|
||||
| unchecked_expression -> { $unchecked_expression.st } // unchecked {...}
|
||||
@ -503,7 +500,7 @@ primary_or_array_creation_expression returns [int precedence]:
|
||||
;
|
||||
// new Type[2] { }
|
||||
array_creation_expression returns [int precedence]:
|
||||
^(NEWARRAY
|
||||
^(NEW_ARRAY
|
||||
(type ('[' expression_list ']'
|
||||
( rank_specifiers? ai1=array_initializer? -> array_construct(type = { $type.st }, args = { $expression_list.st }, inits = { $ai1.st }) // new int[4]
|
||||
// | invocation_part*
|
||||
@ -1231,8 +1228,8 @@ declaration_statement
|
||||
local_variable_declaration:
|
||||
local_variable_type local_variable_declarators -> local_variable_declaration(type={ $local_variable_type.st }, decs = { $local_variable_declarators.st } );
|
||||
local_variable_type:
|
||||
('var') => 'var' -> unsupported(reason = {"'var' as type is unsupported"}, text = { "var" } )
|
||||
| ('dynamic') => 'dynamic' -> unsupported(reason = {"'dynamic' as type is unsupported"}, text = { "dynamic" } )
|
||||
TYPE_VAR -> unsupported(reason = {"'var' as type is unsupported"}, text = { "var" } )
|
||||
| TYPE_DYNAMIC -> unsupported(reason = {"'dynamic' as type is unsupported"}, text = { "dynamic" } )
|
||||
| type -> { $type.st } ;
|
||||
local_variable_declarators:
|
||||
vs+=local_variable_declarator (',' vs+=local_variable_declarator)* -> list(items={$vs}, sep={", "});
|
||||
|
@ -767,11 +767,8 @@ scope {
|
||||
WarningFailedResolve($n.token.Line, "Could not resolve constructor against " + conType.TypeName);
|
||||
}
|
||||
}
|
||||
| 'new' (
|
||||
// (try the simple one first, this has no argS and no expressions
|
||||
// symantically could be object creation)
|
||||
| (delegate_creation_expression) => delegate_creation_expression // new FooDelegate (MyFunction)
|
||||
| anonymous_object_creation_expression) // new {int X, string Y}
|
||||
| ^(NEW_DELEGATE delegate_creation_expression) // new FooDelegate (MyFunction)
|
||||
| ^(NEW_ANON_OBJECT anonymous_object_creation_expression) // new {int X, string Y}
|
||||
| sizeof_expression // sizeof (struct)
|
||||
| checked_expression // checked (...
|
||||
| unchecked_expression // unchecked {...}
|
||||
@ -856,7 +853,7 @@ primary_or_array_creation_expression returns [TypeRepTemplate dotNetType, string
|
||||
;
|
||||
// new Type[2] { }
|
||||
array_creation_expression returns [TypeRepTemplate dotNetType]:
|
||||
^(NEWARRAY
|
||||
^(NEW_ARRAY
|
||||
(type ('[' expression_list ']'
|
||||
( rank_specifiers[$type.dotNetType]? array_initializer? // new int[4]
|
||||
// | invocation_part*
|
||||
@ -2014,8 +2011,8 @@ local_variable_type returns [bool isTypeNode, TypeRepTemplate dotNetType]
|
||||
@init {
|
||||
$isTypeNode = false;
|
||||
}:
|
||||
('var') => 'var' { $dotNetType = new UnknownRepTemplate("System.Object"); }
|
||||
| ('dynamic') => 'dynamic' { $dotNetType = new UnknownRepTemplate("System.Object"); }
|
||||
TYPE_VAR { $dotNetType = new UnknownRepTemplate("System.Object"); }
|
||||
| TYPE_DYNAMIC { $dotNetType = new UnknownRepTemplate("System.Object"); }
|
||||
| type { $dotNetType = $type.dotNetType; $isTypeNode = true; };
|
||||
local_variable_declarators[CommonTree tyTree, TypeRepTemplate ty]:
|
||||
local_variable_declarator[$tyTree, $ty] (',' local_variable_declarator[$tyTree, $ty])* ;
|
||||
|
@ -303,7 +303,7 @@ primary_or_array_creation_expression:
|
||||
;
|
||||
// new Type[2] { }
|
||||
array_creation_expression:
|
||||
NEWARRAY
|
||||
NEW_ARRAY
|
||||
(type ('[' expression_list ']'
|
||||
( rank_specifiers? array_initializer? // new int[4]
|
||||
// | invocation_part*
|
||||
|
@ -48,7 +48,9 @@ tokens {
|
||||
APPLY;
|
||||
ARGS;
|
||||
NEW;
|
||||
NEWARRAY;
|
||||
NEW_ARRAY;
|
||||
NEW_DELEGATE;
|
||||
NEW_ANON_OBJECT;
|
||||
STATIC_CONSTRUCTOR;
|
||||
|
||||
RETURN = 'return';
|
||||
@ -123,6 +125,8 @@ tokens {
|
||||
STAR = '*';
|
||||
|
||||
TYPE;
|
||||
TYPE_VAR;
|
||||
TYPE_DYNAMIC;
|
||||
ENUM_BODY;
|
||||
TYPE_PARAM_CONSTRAINT;
|
||||
UNARY_EXPR;
|
||||
@ -359,7 +363,7 @@ public array_creation_expression:
|
||||
)
|
||||
) ;
|
||||
public new_array:
|
||||
n='new' -> NEWARRAY[$n, "newarray"];
|
||||
n='new' -> NEW_ARRAY[$n, "newarray"];
|
||||
public array_initializer:
|
||||
'{' variable_initializer_list? ','? '}' ;
|
||||
public variable_initializer_list:
|
||||
|
Loading…
x
Reference in New Issue
Block a user