mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
-translator-blanket-throw=false stops adding "throws Exception" to methods and constructors
This commit is contained in:
parent
669566fc45
commit
317aa189f2
@ -129,6 +129,7 @@ namespace Twiglet.CS2J.Translator
|
|||||||
.Add ("keyfile=", v => cfg.KeyFile = v)
|
.Add ("keyfile=", v => cfg.KeyFile = v)
|
||||||
.Add ("translator-keep-parens=", v => cfg.TranslatorKeepParens = Boolean.Parse(v))
|
.Add ("translator-keep-parens=", v => cfg.TranslatorKeepParens = Boolean.Parse(v))
|
||||||
.Add ("translator-timestamp-files=", v => cfg.TranslatorAddTimeStamp = Boolean.Parse(v))
|
.Add ("translator-timestamp-files=", v => cfg.TranslatorAddTimeStamp = Boolean.Parse(v))
|
||||||
|
.Add ("translator-blanket-throw=", v => cfg.TranslatorBlanketThrow = Boolean.Parse(v))
|
||||||
.Add ("translator-exception-is-throwable=", v => cfg.TranslatorExceptionIsThrowable = Boolean.Parse(v))
|
.Add ("translator-exception-is-throwable=", v => cfg.TranslatorExceptionIsThrowable = Boolean.Parse(v))
|
||||||
.Add ("experimental-enums-numericconsts", v => cfg.EnumsAsNumericConsts = true)
|
.Add ("experimental-enums-numericconsts", v => cfg.EnumsAsNumericConsts = true)
|
||||||
.Add ("experimental-unsigned-translatesigned", v => cfg.UnsignedNumbersToSigned = true)
|
.Add ("experimental-unsigned-translatesigned", v => cfg.UnsignedNumbersToSigned = true)
|
||||||
|
@ -56,6 +56,11 @@ namespace Twiglet.CS2J.Translator
|
|||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool TranslatorBlanketThrow
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
public bool EnumsAsNumericConsts
|
public bool EnumsAsNumericConsts
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
@ -108,6 +113,7 @@ namespace Twiglet.CS2J.Translator
|
|||||||
TranslatorKeepParens = true;
|
TranslatorKeepParens = true;
|
||||||
TranslatorAddTimeStamp = true;
|
TranslatorAddTimeStamp = true;
|
||||||
TranslatorExceptionIsThrowable = false;
|
TranslatorExceptionIsThrowable = false;
|
||||||
|
TranslatorBlanketThrow = true;
|
||||||
|
|
||||||
EnumsAsNumericConsts = false;
|
EnumsAsNumericConsts = false;
|
||||||
UnsignedNumbersToSigned = false;
|
UnsignedNumbersToSigned = false;
|
||||||
|
@ -1369,7 +1369,7 @@ method_declaration [CommonTree atts, CommonTree mods, List<string> modList, Comm
|
|||||||
method_body [bool smotherExceptions] returns [CommonTree exceptionList, bool isEmpty]:
|
method_body [bool smotherExceptions] returns [CommonTree exceptionList, bool isEmpty]:
|
||||||
{smotherExceptions}? b=block nb=magicSmotherExceptions[dupTree($b.tree) ]
|
{smotherExceptions}? b=block nb=magicSmotherExceptions[dupTree($b.tree) ]
|
||||||
-> $nb
|
-> $nb
|
||||||
| b=block el=magicThrowsException[true,$b.tree.Token] { $exceptionList=$el.tree; $isEmpty = $b.isEmpty; }
|
| b=block el=magicThrowsException[Cfg.TranslatorBlanketThrow,$b.tree.Token] { $exceptionList=$el.tree; $isEmpty = $b.isEmpty; }
|
||||||
-> $b
|
-> $b
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -1676,9 +1676,9 @@ interface_property_declaration [CommonTree atts, CommonTree mods, CommonTree typ
|
|||||||
i=identifier '{' iads=interface_accessor_declarations[atts, mods, type, $i.text] '}' -> $iads ;
|
i=identifier '{' iads=interface_accessor_declarations[atts, mods, type, $i.text] '}' -> $iads ;
|
||||||
interface_method_declaration [CommonTree atts, CommonTree mods, CommonTree type]:
|
interface_method_declaration [CommonTree atts, CommonTree mods, CommonTree type]:
|
||||||
identifier type_parameter_list?
|
identifier type_parameter_list?
|
||||||
'(' formal_parameter_list? ')' type_parameter_constraints_clauses? s=';' magicThrowsException[true,$s.token]
|
'(' formal_parameter_list? ')' type_parameter_constraints_clauses? s=';' magicThrowsException[Cfg.TranslatorBlanketThrow,$s.token]
|
||||||
-> ^(METHOD { dupTree($atts) } { dupTree($mods) } { dupTree($type) }
|
-> ^(METHOD { dupTree($atts) } { dupTree($mods) } { dupTree($type) }
|
||||||
identifier type_parameter_constraints_clauses? type_parameter_list? formal_parameter_list? magicThrowsException);
|
identifier type_parameter_constraints_clauses? type_parameter_list? formal_parameter_list? magicThrowsException?);
|
||||||
interface_event_declaration [CommonTree atts, CommonTree mods]:
|
interface_event_declaration [CommonTree atts, CommonTree mods]:
|
||||||
//attributes? 'new'?
|
//attributes? 'new'?
|
||||||
e='event' type identifier ';' -> ^(EVENT[$e.token, "EVENT"] { dupTree($atts) } { dupTree($mods) } type identifier)
|
e='event' type identifier ';' -> ^(EVENT[$e.token, "EVENT"] { dupTree($atts) } { dupTree($mods) } type identifier)
|
||||||
@ -1690,8 +1690,8 @@ interface_accessor_declarations [CommonTree atts, CommonTree mods, CommonTree ty
|
|||||||
interface_accessor_declaration[atts, mods, type, propName]+
|
interface_accessor_declaration[atts, mods, type, propName]+
|
||||||
;
|
;
|
||||||
interface_accessor_declaration [CommonTree atts, CommonTree mods, CommonTree type, string propName]:
|
interface_accessor_declaration [CommonTree atts, CommonTree mods, CommonTree type, string propName]:
|
||||||
la=attributes? (g='get' gbe=semi magicPropGetter[atts, $la.tree, mods, null, type, $g.token, $gbe.tree, propName, false, ""] -> magicPropGetter
|
la=attributes? (g='get' gbe=semi magicPropGetter[atts, $la.tree, mods, null, type, $g.token, null, propName, false, ""] -> magicPropGetter
|
||||||
| s='set' sbe=semi magicPropSetter[atts, $la.tree, mods, null, type, $s.token, $sbe.tree, propName, false, ""] -> magicPropSetter)
|
| s='set' sbe=semi magicPropSetter[atts, $la.tree, mods, null, type, $s.token, null, propName, false, ""] -> magicPropSetter)
|
||||||
;
|
;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
@ -1755,8 +1755,8 @@ operator_body:
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
constructor_declaration[CommonTree atts, CommonTree mods, List<string> modList]:
|
constructor_declaration[CommonTree atts, CommonTree mods, List<string> modList]:
|
||||||
i=identifier '(' p=formal_parameter_list? s=')' init=constructor_initializer? b=constructor_body[$init.tree] magicThrowsException[true,$s.token]
|
i=identifier '(' p=formal_parameter_list? s=')' init=constructor_initializer? b=constructor_body[$init.tree] magicThrowsException[Cfg.TranslatorBlanketThrow,$s.token]
|
||||||
-> ^(CONSTRUCTOR[$i.tree.Token, "CONSTRUCTOR"] { dupTree($atts) } { dupTree($mods) } $i $p? $b magicThrowsException);
|
-> ^(CONSTRUCTOR[$i.tree.Token, "CONSTRUCTOR"] { dupTree($atts) } { dupTree($mods) } $i $p? $b magicThrowsException?);
|
||||||
constructor_initializer:
|
constructor_initializer:
|
||||||
':' tok='this' '(' argument_list? ')'
|
':' tok='this' '(' argument_list? ')'
|
||||||
-> ^(APPLY[$tok.token, "APPLY"] $tok argument_list?) SEMI[$tok.token, ";"]
|
-> ^(APPLY[$tok.token, "APPLY"] $tok argument_list?) SEMI[$tok.token, ";"]
|
||||||
@ -2087,18 +2087,16 @@ magicCatchVar:
|
|||||||
magicPropGetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTree localmods, CommonTree type, IToken getTok, CommonTree body, string propName, bool mkBody, string varName]
|
magicPropGetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTree localmods, CommonTree type, IToken getTok, CommonTree body, string propName, bool mkBody, string varName]
|
||||||
@init {
|
@init {
|
||||||
CommonTree realBody = body;
|
CommonTree realBody = body;
|
||||||
CommonTree exceptionList = null;
|
|
||||||
}:
|
}:
|
||||||
b=magicGetterBody[mkBody,getTok,varName] { if (mkBody) realBody = $b.tree; } e=magicThrowsException[!mkBody,getTok] { if (!mkBody) exceptionList = $e.tree; }
|
b=magicGetterBody[mkBody,getTok,varName] { if (mkBody) realBody = $b.tree; } e=magicThrowsException[!mkBody && Cfg.TranslatorBlanketThrow,getTok]
|
||||||
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } { dupTree(type)} IDENTIFIER[getTok, "get"+propName] { dupTree(realBody) } { exceptionList })
|
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } { dupTree(type)} IDENTIFIER[getTok, "get"+propName] { dupTree(realBody) } magicThrowsException?)
|
||||||
;
|
;
|
||||||
magicPropSetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTree localmods, CommonTree type, IToken setTok, CommonTree body, string propName, bool mkBody, string varName]
|
magicPropSetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTree localmods, CommonTree type, IToken setTok, CommonTree body, string propName, bool mkBody, string varName]
|
||||||
@init {
|
@init {
|
||||||
CommonTree realBody = body;
|
CommonTree realBody = body;
|
||||||
CommonTree exceptionList = null;
|
|
||||||
}:
|
}:
|
||||||
b=magicSetterBody[mkBody,setTok,varName] { if (mkBody) realBody = $b.tree; } e=magicThrowsException[!mkBody,setTok] { if (!mkBody) exceptionList = $e.tree; }
|
b=magicSetterBody[mkBody,setTok,varName] { if (mkBody) realBody = $b.tree; } e=magicThrowsException[!mkBody && Cfg.TranslatorBlanketThrow,setTok]
|
||||||
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } ^(TYPE[setTok, "TYPE"] IDENTIFIER[setTok, "void"] ) IDENTIFIER[setTok, "set"+propName] ^(PARAMS[setTok, "PARAMS"] { dupTree(type)} IDENTIFIER[setTok, "value"]) { dupTree(realBody) } { exceptionList } )
|
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } ^(TYPE[setTok, "TYPE"] IDENTIFIER[setTok, "void"] ) IDENTIFIER[setTok, "set"+propName] ^(PARAMS[setTok, "PARAMS"] { dupTree(type)} IDENTIFIER[setTok, "value"]) { dupTree(realBody) } magicThrowsException? )
|
||||||
;
|
;
|
||||||
|
|
||||||
magicSemi:
|
magicSemi:
|
||||||
@ -2128,8 +2126,8 @@ magicIdxGetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTre
|
|||||||
adaptor.AddChild(name, (CommonTree)adaptor.Create(IDENTIFIER, getTok, "get___idx"));
|
adaptor.AddChild(name, (CommonTree)adaptor.Create(IDENTIFIER, getTok, "get___idx"));
|
||||||
}
|
}
|
||||||
}:
|
}:
|
||||||
magicThrowsException[true,getTok]
|
magicThrowsException[Cfg.TranslatorBlanketThrow,getTok]
|
||||||
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } { dupTree(type)} { name } { dupTree(idxparams) } { dupTree(body) } magicThrowsException)
|
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } { dupTree(type)} { name } { dupTree(idxparams) } { dupTree(body) } magicThrowsException?)
|
||||||
;
|
;
|
||||||
magicIdxSetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTree localmods, CommonTree type, CommonTree iface, IToken setTok, CommonTree body, CommonTree idxparams]
|
magicIdxSetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTree localmods, CommonTree type, CommonTree iface, IToken setTok, CommonTree body, CommonTree idxparams]
|
||||||
@init {
|
@init {
|
||||||
@ -2146,8 +2144,8 @@ magicIdxSetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTre
|
|||||||
adaptor.AddChild(augParams, (CommonTree)adaptor.Create(IDENTIFIER, setTok, "value"));
|
adaptor.AddChild(augParams, (CommonTree)adaptor.Create(IDENTIFIER, setTok, "value"));
|
||||||
}
|
}
|
||||||
:
|
:
|
||||||
magicThrowsException[true,setTok]
|
magicThrowsException[Cfg.TranslatorBlanketThrow,setTok]
|
||||||
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } ^(TYPE[setTok, "TYPE"] IDENTIFIER[setTok, "void"] ) { name } { augParams } { dupTree(body) } magicThrowsException )
|
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } ^(TYPE[setTok, "TYPE"] IDENTIFIER[setTok, "void"] ) { name } { augParams } { dupTree(body) } magicThrowsException? )
|
||||||
;
|
;
|
||||||
|
|
||||||
// keving: can't get this to work reasonably
|
// keving: can't get this to work reasonably
|
||||||
@ -2200,7 +2198,7 @@ magicMainWrapper[bool isOn, IToken tok, CommonTree body]:
|
|||||||
^(TYPE[tok, "TYPE"] IDENTIFIER[tok, "void"])
|
^(TYPE[tok, "TYPE"] IDENTIFIER[tok, "void"])
|
||||||
IDENTIFIER[tok, "main"] ^(PARAMS[tok, "PARAMS"] ^(TYPE[tok, "TYPE"] IDENTIFIER[tok,"String"] OPEN_BRACKET[tok, "["] CLOSE_BRACKET[tok, "]"]) IDENTIFIER[tok, "args"])
|
IDENTIFIER[tok, "main"] ^(PARAMS[tok, "PARAMS"] ^(TYPE[tok, "TYPE"] IDENTIFIER[tok,"String"] OPEN_BRACKET[tok, "["] CLOSE_BRACKET[tok, "]"]) IDENTIFIER[tok, "args"])
|
||||||
OPEN_BRACE[tok, "{"] { dupTree(body) } SEMI[tok, ";"] CLOSE_BRACE[tok, "}"]
|
OPEN_BRACE[tok, "{"] { dupTree(body) } SEMI[tok, ";"] CLOSE_BRACE[tok, "}"]
|
||||||
magicThrowsException)
|
magicThrowsException?)
|
||||||
->
|
->
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -2220,7 +2218,7 @@ magicFinally[IToken tok, CommonTree statement_list]:
|
|||||||
;
|
;
|
||||||
|
|
||||||
magicFinalize[IToken tok, CommonTree body]:
|
magicFinalize[IToken tok, CommonTree body]:
|
||||||
magicThrowsException[true,tok]
|
magicThrowsException[Cfg.TranslatorBlanketThrow,tok]
|
||||||
->
|
->
|
||||||
^(METHOD[tok, "METHOD"]
|
^(METHOD[tok, "METHOD"]
|
||||||
PROTECTED[tok, "protected"]
|
PROTECTED[tok, "protected"]
|
||||||
@ -2252,18 +2250,18 @@ magicDelegateInterface[IToken tok, CommonTree return_type, CommonTree identifier
|
|||||||
@init {
|
@init {
|
||||||
AddToImports("java.util.List");
|
AddToImports("java.util.List");
|
||||||
}:
|
}:
|
||||||
e1=magicThrowsException[true, tok]
|
e1=magicThrowsException[Cfg.TranslatorBlanketThrow, tok]
|
||||||
e2=magicThrowsException[true, tok]
|
e2=magicThrowsException[Cfg.TranslatorBlanketThrow, tok]
|
||||||
-> OPEN_BRACE[tok, "{"] // System.Collections.Generic.IList
|
-> OPEN_BRACE[tok, "{"] // System.Collections.Generic.IList
|
||||||
^(METHOD[tok, "METHOD"] { dupTree(return_type) } IDENTIFIER[tok,"Invoke"] { dupTree(formal_parameter_list) } $e1)
|
^(METHOD[tok, "METHOD"] { dupTree(return_type) } IDENTIFIER[tok,"Invoke"] { dupTree(formal_parameter_list) } $e1?)
|
||||||
^(METHOD[tok, "METHOD"] ^(TYPE ^(DOT[tok, "."] ^(DOT[tok, "."] ^(DOT[tok, "."] IDENTIFIER[tok, "System"] IDENTIFIER[tok, "Collections"]) IDENTIFIER[tok, "Generic"]) IDENTIFIER[tok, "IList"] LTHAN[tok,"<"] ^(TYPE { dupTree( identifier) } { mkGenericArgs(tok, tyArgs) }) GT[tok,">"])) IDENTIFIER[tok,"GetInvocationList"] $e2)
|
^(METHOD[tok, "METHOD"] ^(TYPE ^(DOT[tok, "."] ^(DOT[tok, "."] ^(DOT[tok, "."] IDENTIFIER[tok, "System"] IDENTIFIER[tok, "Collections"]) IDENTIFIER[tok, "Generic"]) IDENTIFIER[tok, "IList"] LTHAN[tok,"<"] ^(TYPE { dupTree( identifier) } { mkGenericArgs(tok, tyArgs) }) GT[tok,">"])) IDENTIFIER[tok,"GetInvocationList"] $e2?)
|
||||||
CLOSE_BRACE[tok, "}"]
|
CLOSE_BRACE[tok, "}"]
|
||||||
;
|
;
|
||||||
|
|
||||||
// First execute all but the last one, then execute the last one and (if non-void) return its result.
|
// First execute all but the last one, then execute the last one and (if non-void) return its result.
|
||||||
magicMultiInvokerMethod[IToken tok, CommonTree return_type, bool retIsVoid, CommonTree type, CommonTree formal_parameter_list, CommonTree argument_list, List<String> tyArgs]
|
magicMultiInvokerMethod[IToken tok, CommonTree return_type, bool retIsVoid, CommonTree type, CommonTree formal_parameter_list, CommonTree argument_list, List<String> tyArgs]
|
||||||
:
|
:
|
||||||
e1=magicThrowsException[true, tok]
|
e1=magicThrowsException[Cfg.TranslatorBlanketThrow, tok]
|
||||||
-> {retIsVoid}?
|
-> {retIsVoid}?
|
||||||
^(METHOD[tok, "METHOD"] PUBLIC[tok, "public"] { dupTree($return_type) } IDENTIFIER[tok,"Invoke"] { dupTree($formal_parameter_list) }
|
^(METHOD[tok, "METHOD"] PUBLIC[tok, "public"] { dupTree($return_type) } IDENTIFIER[tok,"Invoke"] { dupTree($formal_parameter_list) }
|
||||||
OPEN_BRACE[tok, "{"]
|
OPEN_BRACE[tok, "{"]
|
||||||
@ -2275,7 +2273,7 @@ magicMultiInvokerMethod[IToken tok, CommonTree return_type, bool retIsVoid, Comm
|
|||||||
CLOSE_BRACE[tok, "}"]
|
CLOSE_BRACE[tok, "}"]
|
||||||
)
|
)
|
||||||
CLOSE_BRACE[tok, "}"]
|
CLOSE_BRACE[tok, "}"]
|
||||||
magicThrowsException
|
magicThrowsException?
|
||||||
)
|
)
|
||||||
-> ^(METHOD[tok, "METHOD"] PUBLIC[tok, "public"] { dupTree($return_type) } IDENTIFIER[tok,"Invoke"] { dupTree($formal_parameter_list) }
|
-> ^(METHOD[tok, "METHOD"] PUBLIC[tok, "public"] { dupTree($return_type) } IDENTIFIER[tok,"Invoke"] { dupTree($formal_parameter_list) }
|
||||||
OPEN_BRACE[tok, "{"]
|
OPEN_BRACE[tok, "{"]
|
||||||
@ -2290,7 +2288,7 @@ magicMultiInvokerMethod[IToken tok, CommonTree return_type, bool retIsVoid, Comm
|
|||||||
)
|
)
|
||||||
^(RETURN[tok, "return"] ^(APPLY[tok, "APPLY"] ^(DOT[tok,"."] IDENTIFIER[tok,"prev"] IDENTIFIER[tok,"Invoke"]) { $argument_list }))
|
^(RETURN[tok, "return"] ^(APPLY[tok, "APPLY"] ^(DOT[tok,"."] IDENTIFIER[tok,"prev"] IDENTIFIER[tok,"Invoke"]) { $argument_list }))
|
||||||
CLOSE_BRACE[tok, "}"]
|
CLOSE_BRACE[tok, "}"]
|
||||||
magicThrowsException
|
magicThrowsException?
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user