mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
Include explicit BoxedJava field in translation templates for primitives
This commit is contained in:
parent
87e67c5035
commit
946bd4741a
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -10,6 +10,7 @@
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>boolean</Java>
|
||||
<BoxedJava>Boolean</BoxedJava>
|
||||
<Name>System.Boolean</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -10,6 +10,7 @@
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>byte</Java>
|
||||
<BoxedJava>Byte</BoxedJava>
|
||||
<Name>System.Byte</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -10,6 +10,7 @@
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>char</Java>
|
||||
<BoxedJava>Character</BoxedJava>
|
||||
<Name>System.Char</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -10,6 +10,7 @@
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>double</Java>
|
||||
<BoxedJava>Double</BoxedJava>
|
||||
<Name>System.Decimal</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -10,6 +10,7 @@
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>double</Java>
|
||||
<BoxedJava>Double</BoxedJava>
|
||||
<Name>System.Double</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -9,7 +9,8 @@
|
||||
-->
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>int</Java>
|
||||
<Java>short</Java>
|
||||
<BoxedJava>Short</BoxedJava>
|
||||
<Name>System.Int16</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -10,6 +10,7 @@
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>int</Java>
|
||||
<BoxedJava>Integer</BoxedJava>
|
||||
<Name>System.Int32</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -10,6 +10,7 @@
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>long</Java>
|
||||
<BoxedJava>Long</BoxedJava>
|
||||
<Name>System.Int64</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -10,6 +10,7 @@
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>byte</Java>
|
||||
<BoxedJava>Byte</BoxedJava>
|
||||
<Name>System.SByte</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -10,6 +10,7 @@
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>float</Java>
|
||||
<BoxedJava>Float</BoxedJava>
|
||||
<Name>System.Single</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -10,6 +10,7 @@
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>long</Java>
|
||||
<BoxedJava>Long</BoxedJava>
|
||||
<Name>System.UInt32</Name>
|
||||
<Uses />
|
||||
<Inherits>
|
||||
|
@ -1826,7 +1826,7 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
||||
}
|
||||
}
|
||||
|
||||
// Client can set _isUnboxedType. If so then we know the expression / type is inboxed
|
||||
// Client can set _isUnboxedType. If so then we know the expression / type is unboxed
|
||||
private bool _isUnboxedType = false;
|
||||
[XmlIgnore]
|
||||
public bool IsUnboxedType
|
||||
@ -1841,18 +1841,19 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
||||
}
|
||||
}
|
||||
|
||||
// Client can set BoxedName. If so then we know how to cast an expression to its boxed type
|
||||
private string _boxedName = null;
|
||||
[XmlIgnore]
|
||||
public string BoxedName
|
||||
{
|
||||
private String _boxedJava = null;
|
||||
public String BoxedJava {
|
||||
get
|
||||
{
|
||||
return _boxedName;
|
||||
if (String.IsNullOrEmpty(_boxedJava))
|
||||
{
|
||||
_boxedJava = Java;
|
||||
}
|
||||
return _boxedJava;
|
||||
}
|
||||
set
|
||||
{
|
||||
_boxedName = value;
|
||||
_boxedJava = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1861,7 +1862,7 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
||||
{
|
||||
get
|
||||
{
|
||||
return (String.IsNullOrEmpty(BoxedName) ? "" : "((" + BoxedName + ")${expr})");
|
||||
return (String.IsNullOrEmpty(BoxedJava) ? "" : "((" + BoxedJava + ")${expr})");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1980,6 +1981,7 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
||||
IsExplicitNull = copyFrom.IsExplicitNull;
|
||||
IsUnboxedType = copyFrom.IsUnboxedType;
|
||||
Variant = copyFrom.Variant;
|
||||
BoxedJava = copyFrom.BoxedJava;
|
||||
}
|
||||
|
||||
protected TypeRepTemplate(string tName, string[] tParams, string[] usePath, AliasRepTemplate[] aliases, string[] imports, string javaTemplate)
|
||||
@ -2515,7 +2517,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
||||
}
|
||||
}
|
||||
|
||||
return IsExplicitNull == other.IsExplicitNull && IsUnboxedType == other.IsUnboxedType && TypeName == other.TypeName && Variant == other.Variant && base.Equals(other);
|
||||
return IsExplicitNull == other.IsExplicitNull && IsUnboxedType == other.IsUnboxedType &&
|
||||
TypeName == other.TypeName && Variant == other.Variant && BoxedJava == other.BoxedJava && base.Equals(other);
|
||||
}
|
||||
|
||||
public override bool Equals (object obj)
|
||||
@ -2569,7 +2572,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
||||
}
|
||||
}
|
||||
|
||||
return (Java ?? String.Empty).GetHashCode() ^ IsExplicitNull.GetHashCode() ^ IsUnboxedType.GetHashCode() ^ Variant.GetHashCode() ^ hashCode;
|
||||
return (Java ?? String.Empty).GetHashCode() ^ IsExplicitNull.GetHashCode() ^ IsUnboxedType.GetHashCode() ^
|
||||
Variant.GetHashCode() ^ BoxedJava.GetHashCode() ^ hashCode;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -209,20 +209,6 @@ scope MkNonGeneric {
|
||||
}
|
||||
}
|
||||
|
||||
// Map of Java built in types to their object based equivalents
|
||||
Dictionary<string, string> primitive_to_object_type_map = new Dictionary<string, string>()
|
||||
{
|
||||
{"byte", "Byte"},
|
||||
{"short", "Short"},
|
||||
{"int", "Integer"},
|
||||
{"long", "Long"},
|
||||
{"float", "Float"},
|
||||
{"double", "Double"},
|
||||
{"boolean", "Boolean"},
|
||||
{"char", "Character"}
|
||||
};
|
||||
|
||||
|
||||
protected TypeRepTemplate SymTabLookup(string name) {
|
||||
return SymTabLookup(name, null);
|
||||
}
|
||||
@ -1229,6 +1215,7 @@ scope {
|
||||
// Not a variable, not a property read, is it a type name?
|
||||
TypeRepTemplate staticType = findType(textSoFar);
|
||||
if (!staticType.IsUnknownType) {
|
||||
ret = mkJavaWrapper(staticType.Java, new Dictionary<string,CommonTree>(), $i.tree.Token);
|
||||
AddToImports(staticType.Imports);
|
||||
$dotNetType = staticType;
|
||||
$thedottedtext = (implicitThis || String.IsNullOrEmpty($e1.thedottedtext) ? "" : $e1.thedottedtext + ".") + $i.thetext;
|
||||
@ -1632,7 +1619,6 @@ type returns [TypeRepTemplate dotNetType, List<CommonTree> argTrees]
|
||||
bool hasRank = false;
|
||||
bool isPredefined = false;
|
||||
CommonTree pTree = null;
|
||||
string boxedName = null;
|
||||
}
|
||||
@after {
|
||||
if ($dotNetType.Tree == null) {
|
||||
@ -1640,14 +1626,14 @@ type returns [TypeRepTemplate dotNetType, List<CommonTree> argTrees]
|
||||
}
|
||||
}
|
||||
:
|
||||
^(TYPE (p=predefined_type { isPredefined = true; $dotNetType = $predefined_type.dotNetType; pTree = $p.tree; boxedName = $predefined_type.dotNetType.BoxedName; }
|
||||
^(t=TYPE (p=predefined_type { isPredefined = true; $dotNetType = $predefined_type.dotNetType; pTree = $p.tree; }
|
||||
| type_name { $dotNetType = $type_name.dotNetType; $argTrees = $type_name.argTrees; }
|
||||
| 'void' { $dotNetType = VoidType; } )
|
||||
(rank_specifiers[$dotNetType] { isPredefined = false; $dotNetType = $rank_specifiers.dotNetType; $argTrees = null; hasRank = true; })? '*'* '?'?)
|
||||
magicBoxedType[isPredefined && pTree != null && !String.IsNullOrEmpty(boxedName), (pTree != null ? pTree.Token : null), boxedName]
|
||||
magicBoxedType[$dotNetType != null && !String.IsNullOrEmpty($dotNetType.BoxedJava), $t.token, $dotNetType == null ? "" : $dotNetType.BoxedJava]
|
||||
{ $dotNetType.Tree = ($magicBoxedType.tree != null ? dupTree($magicBoxedType.tree) : null); }
|
||||
-> { $PrimitiveRep::primitiveTypeAsObject && $p.tree != null && !hasRank && !String.IsNullOrEmpty($dotNetType.BoxedName) }? ^(TYPE[$p.tree.Token, "TYPE"] IDENTIFIER[$p.tree.Token,$dotNetType.BoxedName] '*'* '?'?)
|
||||
-> ^(TYPE predefined_type? type_name? 'void'? rank_specifiers? '*'* '?'?)
|
||||
-> { $PrimitiveRep::primitiveTypeAsObject && !hasRank && !String.IsNullOrEmpty($dotNetType.BoxedJava) }? ^(TYPE[$t.token, "TYPE"] IDENTIFIER[$t.token,$dotNetType.BoxedJava] '*'* '?'?)
|
||||
-> ^(TYPE[$t.token, "TYPE"] predefined_type? type_name? 'void'? rank_specifiers? '*'* '?'?)
|
||||
;
|
||||
|
||||
non_nullable_type returns [TypeRepTemplate dotNetType]:
|
||||
@ -3066,9 +3052,6 @@ predefined_type returns [TypeRepTemplate dotNetType]
|
||||
$dotNetType = new ClassRepTemplate((ClassRepTemplate)AppEnv.Search(ns, new UnknownRepTemplate(ns)));
|
||||
$dotNetType.IsUnboxedType = true;
|
||||
string newText = null;
|
||||
if (primitive_to_object_type_map.TryGetValue($predefined_type.tree.Token.Text, out newText))
|
||||
$dotNetType.BoxedName = newText;
|
||||
|
||||
}:
|
||||
'bool' { ns = "System.Boolean"; }
|
||||
| 'byte' { ns = Cfg.UnsignedNumbersToSigned ? "System.SByte" : "System.Byte"; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user