mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
add mkNonGeneric scope so that we can remove generic arguments from a type if we want to (these aren't carried at runtime, so instanceof has to just check against the base type)
This commit is contained in:
parent
e0893b1e6f
commit
158e22b44f
@ -247,6 +247,10 @@ options {
|
|||||||
// (${var}) -> ()
|
// (${var}) -> ()
|
||||||
ret = Regex.Replace(ret, "\\$\\{[\\w:]+?\\}", String.Empty);
|
ret = Regex.Replace(ret, "\\$\\{[\\w:]+?\\}", String.Empty);
|
||||||
}
|
}
|
||||||
|
// If we have a generic type then we can scrub its generic arguments
|
||||||
|
// by susbstituting with an empty dictionary, now tidy up the brackets
|
||||||
|
// and commas
|
||||||
|
ret = Regex.Replace(ret, "\\s*<(\\s*,\\s*)*>\\s*", String.Empty);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,13 @@ scope PrimitiveRep {
|
|||||||
bool primitiveTypeAsObject;
|
bool primitiveTypeAsObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When this scope is true, then strip generic arguments from types
|
||||||
|
// (In Java the runtime doesn't know the generic types so e.g. instanceof Set<T>
|
||||||
|
// must be just instanceof Set).
|
||||||
|
scope MkNonGeneric {
|
||||||
|
bool scrubGenericArgs;
|
||||||
|
}
|
||||||
|
|
||||||
@namespace { Twiglet.CS2J.Translator.Transform }
|
@namespace { Twiglet.CS2J.Translator.Transform }
|
||||||
|
|
||||||
@header
|
@header
|
||||||
@ -497,12 +504,13 @@ scope PrimitiveRep {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public compilation_unit
|
public compilation_unit
|
||||||
scope NSContext, PrimitiveRep;
|
scope NSContext, PrimitiveRep, MkNonGeneric;
|
||||||
@init {
|
@init {
|
||||||
|
|
||||||
Imports = new Set<string>();
|
Imports = new Set<string>();
|
||||||
|
|
||||||
$PrimitiveRep::primitiveTypeAsObject = false;
|
$PrimitiveRep::primitiveTypeAsObject = false;
|
||||||
|
$MkNonGeneric::scrubGenericArgs = false;
|
||||||
|
|
||||||
// TODO: Do we need to ensure we have access to System? If so, can add it here.
|
// TODO: Do we need to ensure we have access to System? If so, can add it here.
|
||||||
$NSContext::namespaces = SearchPath ?? new List<string>();
|
$NSContext::namespaces = SearchPath ?? new List<string>();
|
||||||
@ -1020,7 +1028,7 @@ type_or_generic[String prefix] returns [TypeRepTemplate dotNetType, List<CommonT
|
|||||||
{
|
{
|
||||||
$dotNetType = findType(prefix+$t.thetext, $ga.argTypes);
|
$dotNetType = findType(prefix+$t.thetext, $ga.argTypes);
|
||||||
if (!$dotNetType.IsUnknownType) {
|
if (!$dotNetType.IsUnknownType) {
|
||||||
if ($hasTyArgs && $dotNetType.TypeParams.Length == $ga.argTrees.Count) {
|
if (!$MkNonGeneric::scrubGenericArgs && $hasTyArgs && $dotNetType.TypeParams.Length == $ga.argTrees.Count) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (CommonTree ty in $ga.argTrees) {
|
foreach (CommonTree ty in $ga.argTrees) {
|
||||||
tyMap[$dotNetType.TypeParams[i]] = wrapType(ty, $t.tree.Token);
|
tyMap[$dotNetType.TypeParams[i]] = wrapType(ty, $t.tree.Token);
|
||||||
@ -1323,7 +1331,9 @@ shortcut_assignment_operator: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '
|
|||||||
// '&' unary_expression ;
|
// '&' unary_expression ;
|
||||||
|
|
||||||
non_assignment_expression returns [TypeRepTemplate dotNetType, string rmId, TypeRepTemplate typeofType, string thedottedtext]
|
non_assignment_expression returns [TypeRepTemplate dotNetType, string rmId, TypeRepTemplate typeofType, string thedottedtext]
|
||||||
|
scope MkNonGeneric;
|
||||||
@init {
|
@init {
|
||||||
|
$MkNonGeneric::scrubGenericArgs = false;
|
||||||
bool nullArg = false;
|
bool nullArg = false;
|
||||||
bool stringArgs = false;
|
bool stringArgs = false;
|
||||||
bool dateArgs = false;
|
bool dateArgs = false;
|
||||||
@ -1453,7 +1463,7 @@ non_assignment_expression returns [TypeRepTemplate dotNetType, string rmId, Type
|
|||||||
-> {dateArgs}?
|
-> {dateArgs}?
|
||||||
$ople
|
$ople
|
||||||
->^($le $le1 $le2)
|
->^($le $le1 $le2)
|
||||||
| ^(INSTANCEOF non_assignment_expression non_nullable_type) {$dotNetType = BoolType; }
|
| ^(INSTANCEOF non_assignment_expression { $MkNonGeneric::scrubGenericArgs = true; } non_nullable_type) {$dotNetType = BoolType; }
|
||||||
| ^('<<' n7=non_assignment_expression non_assignment_expression) {$dotNetType = $n7.dotNetType; }
|
| ^('<<' n7=non_assignment_expression non_assignment_expression) {$dotNetType = $n7.dotNetType; }
|
||||||
| ^(RIGHT_SHIFT n8=non_assignment_expression non_assignment_expression) {$dotNetType = $n8.dotNetType; }
|
| ^(RIGHT_SHIFT n8=non_assignment_expression non_assignment_expression) {$dotNetType = $n8.dotNetType; }
|
||||||
// TODO: need to munge these numeric types
|
// TODO: need to munge these numeric types
|
||||||
|
Loading…
x
Reference in New Issue
Block a user