mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
extract overloadable unary and binary operators
This commit is contained in:
parent
d971e37728
commit
c89a5ba6c5
@ -13,7 +13,7 @@ namespace cs2jTest.Various.Features.join.yield
|
|||||||
|
|
||||||
public const int MY_IMPORTANT_INT = 23;
|
public const int MY_IMPORTANT_INT = 23;
|
||||||
public const String MY_IMPORTANT_STRING = "Kevin";
|
public const String MY_IMPORTANT_STRING = "Kevin";
|
||||||
|
private int myInt = 0;
|
||||||
private System.Collections.Generic.IDictionary<int,short> myDict;
|
private System.Collections.Generic.IDictionary<int,short> myDict;
|
||||||
|
|
||||||
public string TestRWProperty {get; set;}
|
public string TestRWProperty {get; set;}
|
||||||
@ -55,7 +55,11 @@ namespace cs2jTest.Various.Features.join.yield
|
|||||||
return "Various";
|
return "Various";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Various operator ++(Various v) {
|
||||||
|
Various temp = new Various();
|
||||||
|
temp.myInt = v.myInt+1;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1452,6 +1452,26 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<MethodRepTemplate> _unaryOps = null;
|
||||||
|
[XmlArrayItem("UnaryOp")]
|
||||||
|
public List<MethodRepTemplate> UnaryOps {
|
||||||
|
get {
|
||||||
|
if (_unaryOps == null)
|
||||||
|
_unaryOps = new List<MethodRepTemplate> ();
|
||||||
|
return _unaryOps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MethodRepTemplate> _binaryOps = null;
|
||||||
|
[XmlArrayItem("BinaryOp")]
|
||||||
|
public List<MethodRepTemplate> BinaryOps {
|
||||||
|
get {
|
||||||
|
if (_binaryOps == null)
|
||||||
|
_binaryOps = new List<MethodRepTemplate> ();
|
||||||
|
return _binaryOps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ClassRepTemplate ()
|
public ClassRepTemplate ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -1515,6 +1535,25 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (UnaryOps != other.UnaryOps) {
|
||||||
|
if (UnaryOps == null || other.UnaryOps == null || UnaryOps.Count != other.UnaryOps.Count)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < UnaryOps.Count; i++) {
|
||||||
|
if (UnaryOps[i] != other.UnaryOps[i])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BinaryOps != other.BinaryOps) {
|
||||||
|
if (BinaryOps == null || other.BinaryOps == null || BinaryOps.Count != other.BinaryOps.Count)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < BinaryOps.Count; i++) {
|
||||||
|
if (BinaryOps[i] != other.BinaryOps[i])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return base.Equals(other);
|
return base.Equals(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ class_member_declaration:
|
|||||||
| (member_name '.' 'this') => type_name '.' indexer_declaration[$rt.thetext, $type_name.thetext+"."]
|
| (member_name '.' 'this') => type_name '.' indexer_declaration[$rt.thetext, $type_name.thetext+"."]
|
||||||
| indexer_declaration[$rt.thetext, ""] //this
|
| indexer_declaration[$rt.thetext, ""] //this
|
||||||
| field_declaration[$rt.thetext] // qid
|
| field_declaration[$rt.thetext] // qid
|
||||||
| operator_declaration
|
| operator_declaration[$rt.thetext]
|
||||||
)
|
)
|
||||||
// common_modifiers// (method_modifiers | field_modifiers)
|
// common_modifiers// (method_modifiers | field_modifiers)
|
||||||
|
|
||||||
@ -948,7 +948,7 @@ struct_member_declaration:
|
|||||||
| (member_name '.' 'this') => type_name '.' indexer_declaration[$rt.thetext, $type_name.thetext+"."]
|
| (member_name '.' 'this') => type_name '.' indexer_declaration[$rt.thetext, $type_name.thetext+"."]
|
||||||
| indexer_declaration[$rt.thetext, ""] //this
|
| indexer_declaration[$rt.thetext, ""] //this
|
||||||
| field_declaration[$rt.thetext] // qid
|
| field_declaration[$rt.thetext] // qid
|
||||||
| operator_declaration
|
| operator_declaration[$rt.thetext]
|
||||||
)
|
)
|
||||||
// common_modifiers// (method_modifiers | field_modifiers)
|
// common_modifiers// (method_modifiers | field_modifiers)
|
||||||
|
|
||||||
@ -971,19 +971,33 @@ indexer_declarator [string returnType, string prefix]:
|
|||||||
;
|
;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
operator_declaration:
|
operator_declaration [string returnType]:
|
||||||
operator_declarator operator_body ;
|
operator_declarator[$returnType] operator_body ;
|
||||||
operator_declarator:
|
operator_declarator [string returnType]
|
||||||
|
@init {
|
||||||
|
string opText = "";
|
||||||
|
List<ParamRepTemplate> paramList = new List<ParamRepTemplate>();
|
||||||
|
bool unaryOp = false;
|
||||||
|
}
|
||||||
|
@after {
|
||||||
|
MethodRepTemplate meth = new MethodRepTemplate($returnType, opText, null, paramList);
|
||||||
|
if (unaryOp) {
|
||||||
|
((ClassRepTemplate)$NSContext::currentTypeRep).UnaryOps.Add(meth);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
((ClassRepTemplate)$NSContext::currentTypeRep).BinaryOps.Add(meth);
|
||||||
|
}
|
||||||
|
}:
|
||||||
'operator'
|
'operator'
|
||||||
(('+' | '-') '(' type identifier (binary_operator_declarator | unary_operator_declarator)
|
(('+' { opText = "+"; } | '-' { opText = "-"; }) '(' t0=type i0=identifier { paramList.Add(new ParamRepTemplate($t0.thetext, $i0.text)); } (binary_operator_declarator[paramList] | unary_operator_declarator { unaryOp = true; })
|
||||||
| overloadable_unary_operator unary_operator_declarator
|
| overloadable_unary_operator { opText = $overloadable_unary_operator.text; } '(' t1=type i1=identifier { paramList.Add(new ParamRepTemplate($t1.thetext, $i1.text)); } unary_operator_declarator { unaryOp = true; }
|
||||||
| overloadable_binary_operator binary_operator_declarator) ;
|
| overloadable_binary_operator { opText = $overloadable_binary_operator.text; } '(' t2=type i2=identifier { paramList.Add(new ParamRepTemplate($t2.thetext, $i2.text)); } binary_operator_declarator[paramList] ) ;
|
||||||
unary_operator_declarator:
|
unary_operator_declarator:
|
||||||
')' ;
|
')' ;
|
||||||
overloadable_unary_operator:
|
overloadable_unary_operator:
|
||||||
/*'+' | '-' | */ '!' | '~' | '++' | '--' | 'true' | 'false' ;
|
/*'+' | '-' | */ '!' | '~' | '++' | '--' | 'true' | 'false' ;
|
||||||
binary_operator_declarator:
|
binary_operator_declarator [List<ParamRepTemplate> paramList]:
|
||||||
',' type identifier ')' ;
|
',' type identifier ')' { $paramList.Add(new ParamRepTemplate($type.thetext, $identifier.text)); } ;
|
||||||
// >> check needed
|
// >> check needed
|
||||||
overloadable_binary_operator:
|
overloadable_binary_operator:
|
||||||
/*'+' | '-' | */ '*' | '/' | '%' | '&' | '|' | '^' | '<<' | '>' '>' | '==' | '!=' | '>' | '<' | '>=' | '<=' ;
|
/*'+' | '-' | */ '*' | '/' | '%' | '&' | '|' | '^' | '<<' | '>' '>' | '==' | '!=' | '>' | '<' | '>=' | '<=' ;
|
||||||
@ -991,7 +1005,9 @@ overloadable_binary_operator:
|
|||||||
conversion_operator_declaration:
|
conversion_operator_declaration:
|
||||||
conversion_operator_declarator operator_body ;
|
conversion_operator_declarator operator_body ;
|
||||||
conversion_operator_declarator:
|
conversion_operator_declarator:
|
||||||
('implicit' | 'explicit') 'operator' type '(' type identifier ')' ;
|
(i='implicit' { Warning($i.line, "[UNSUPPORTED] implicit user defined casts, an explicit cast is always required."); } | 'explicit') 'operator' tt=type '(' tf=type identifier ')'
|
||||||
|
{ ((ClassRepTemplate)$NSContext::currentTypeRep).Casts.Add(new CastRepTemplate($tf.thetext, $tt.thetext)); }
|
||||||
|
;
|
||||||
operator_body:
|
operator_body:
|
||||||
block ;
|
block ;
|
||||||
|
|
||||||
|
@ -812,8 +812,8 @@ operator_declaration:
|
|||||||
operator_declarator:
|
operator_declarator:
|
||||||
'operator'
|
'operator'
|
||||||
(('+' | '-') '(' type identifier (binary_operator_declarator | unary_operator_declarator)
|
(('+' | '-') '(' type identifier (binary_operator_declarator | unary_operator_declarator)
|
||||||
| overloadable_unary_operator unary_operator_declarator
|
| overloadable_unary_operator '(' type identifier unary_operator_declarator
|
||||||
| overloadable_binary_operator binary_operator_declarator) ;
|
| overloadable_binary_operator '(' type identifier binary_operator_declarator) ;
|
||||||
unary_operator_declarator:
|
unary_operator_declarator:
|
||||||
')' ;
|
')' ;
|
||||||
overloadable_unary_operator:
|
overloadable_unary_operator:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user