mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
drop explicit dimensions when we have array initializer list
This commit is contained in:
parent
9732e938bd
commit
932115aa62
@ -339,10 +339,32 @@ primary_or_array_creation_expression:
|
|||||||
| primary_expression
|
| primary_expression
|
||||||
;
|
;
|
||||||
// new Type[2] { }
|
// new Type[2] { }
|
||||||
array_creation_expression:
|
array_creation_expression
|
||||||
'new'^
|
@init {
|
||||||
|
bool removeDimensions = false;
|
||||||
|
}
|
||||||
|
@after {
|
||||||
|
if (removeDimensions) {
|
||||||
|
if ($array_creation_expression.tree != null &&
|
||||||
|
adaptor.GetChildCount($array_creation_expression.tree) > 3 &&
|
||||||
|
adaptor.GetType(adaptor.GetChild($array_creation_expression.tree, 1)) == OPEN_BRACKET) {
|
||||||
|
// Delete until CLOSE_BRACKET
|
||||||
|
while (adaptor.GetType(adaptor.GetChild($array_creation_expression.tree, 2)) != CLOSE_BRACKET) {
|
||||||
|
adaptor.DeleteChild($array_creation_expression.tree, 2);
|
||||||
|
}
|
||||||
|
// push open / close bracket into type.
|
||||||
|
CommonTree type = (CommonTree)adaptor.GetChild($array_creation_expression.tree, 0);
|
||||||
|
adaptor.AddChild(type, adaptor.DupTree(adaptor.GetChild($array_creation_expression.tree, 1)));
|
||||||
|
adaptor.AddChild(type, adaptor.DupTree(adaptor.GetChild($array_creation_expression.tree, 2)));
|
||||||
|
adaptor.DeleteChild($array_creation_expression.tree, 2);
|
||||||
|
adaptor.DeleteChild($array_creation_expression.tree, 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}:
|
||||||
|
n='new'^
|
||||||
(type ('[' expression_list ']'
|
(type ('[' expression_list ']'
|
||||||
( rank_specifiers? array_initializer? // new int[4]
|
( rank_specifiers? (array_initializer { removeDimensions = true; /* If an initializer is provided then drop the dimensions */} )? // new int[4]
|
||||||
// | invocation_part*
|
// | invocation_part*
|
||||||
| ( ((arguments[null] ('['|'.'|'->')) => arguments[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ] invocation_part)// new object[2].GetEnumerator()
|
| ( ((arguments[null] ('['|'.'|'->')) => arguments[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ] invocation_part)// new object[2].GetEnumerator()
|
||||||
| invocation_part)* arguments[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ]
|
| invocation_part)* arguments[ (CommonTree)adaptor.Create(KGHOLE, "KGHOLE") ]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user