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

varargs support

This commit is contained in:
Kevin Glynn 2010-12-20 10:00:43 +01:00
parent 19bf099ae4
commit 710d887c7b
5 changed files with 34 additions and 4 deletions

View File

@ -16,6 +16,16 @@ namespace RusticiSoftware.Translator.CSharp
: base(input, state)
{ }
protected void Error(int line, String s)
{
Console.Error.WriteLine("{0}({1}) error: {2}", Filename, line, s);
}
protected void Error(String s)
{
Console.Error.WriteLine("{0} error: {1}", Filename, s);
}
protected void Warning(int line, String s)
{
if (Cfg.Warnings)

View File

@ -1001,7 +1001,23 @@ default_argument:
parameter_modifier:
'ref' | 'out' | 'this' ;
parameter_array:
'params' type identifier ;
p='params'^ t=type identifier
{
// type will be an array, need to strip the final [] for java
int numComponents = adaptor.GetChildCount($t.tree);
// sanity check
if (numComponents >= 3 &&
adaptor.GetType(adaptor.GetChild($t.tree, numComponents-2)) == OPEN_BRACKET &&
adaptor.GetType(adaptor.GetChild($t.tree, numComponents-1)) == CLOSE_BRACKET)
{
adaptor.DeleteChild($t.tree, numComponents-1);
adaptor.DeleteChild($t.tree, numComponents-2);
}
else {
Error($p.line, "[SOURCE ERROR] params type must be an array");
}
}
;
///////////////////////////////////////////////////////
interface_declaration returns [string name]

View File

@ -987,7 +987,7 @@ return_type:
formal_parameter_list:
^(PARAMS fps+=formal_parameter+) -> list(items= {$fps}, sep={", "});
formal_parameter:
attributes? (fixed_parameter -> { $fixed_parameter.st }| parameter_array)
attributes? (fixed_parameter -> { $fixed_parameter.st }| parameter_array -> { $parameter_array.st })
| '__arglist'; // __arglist is undocumented, see google
//fixed_parameters:
// fps+=fixed_parameter (',' fps+=fixed_parameter)* -> { $fps };
@ -1000,7 +1000,7 @@ default_argument:
parameter_modifier:
(m='ref' | m='out' | m='this') -> inline_comment(payload={ $m.text }, explanation={ "parameter modifiers are not yet supported" }) ;
parameter_array:
'params' type identifier ;
^('params' type identifier) -> varargs(type={ $type.st }, name = { $identifier.st }) ;
///////////////////////////////////////////////////////
interface_declaration[StringTemplate modifiersST]

View File

@ -703,7 +703,7 @@ default_argument:
parameter_modifier:
'ref' | 'out' | 'this' ;
parameter_array:
'params' type identifier ;
^('params' type identifier) ;
///////////////////////////////////////////////////////
interface_declaration:

View File

@ -80,6 +80,10 @@ fixed_parameter(mod,type,name,def) ::= <<
<mod> <type> <name><if(def)> = <def><endif>
>>
varargs(type,name) ::= <<
<type>... <name>
>>
identifier(id, id2) ::= "<id><if(id2)>::<id2><endif>"
statement_list(statements) ::= <<