Author: martin
Date: 2005-03-14 10:39:16 -0500 (Mon, 14 Mar 2005)
New Revision: 41796
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/cs-parser.jay
trunk/mcs/gmcs/generic.cs
Log:
2005-03-14 Martin Baulig <[EMAIL PROTECTED]>
* generic.cs (Nullable.NullCoalescingOperator): Implemented.
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-03-14 15:17:54 UTC (rev 41795)
+++ trunk/mcs/gmcs/ChangeLog 2005-03-14 15:39:16 UTC (rev 41796)
@@ -1,5 +1,9 @@
2005-03-14 Martin Baulig <[EMAIL PROTECTED]>
+ * generic.cs (Nullable.NullCoalescingOperator): Implemented.
+
+2005-03-14 Martin Baulig <[EMAIL PROTECTED]>
+
* generic.cs (Nullable.LiftedBinaryOperator): Added support for
the comparision operators `<', `>', `<=' and `>='.
Modified: trunk/mcs/gmcs/cs-parser.jay
===================================================================
--- trunk/mcs/gmcs/cs-parser.jay 2005-03-14 15:17:54 UTC (rev 41795)
+++ trunk/mcs/gmcs/cs-parser.jay 2005-03-14 15:39:16 UTC (rev 41796)
@@ -3440,7 +3440,7 @@
}
| conditional_or_expression INTERR INTERR expression
{
- $$ = new NullCoalescingOperator ((Expression) $1, (Expression)
$4, lexer.Location);
+ $$ = new Nullable.NullCoalescingOperator ((Expression) $1,
(Expression) $4, lexer.Location);
}
// We'll be resolved into a `parenthesized_expression_0' later on.
| conditional_or_expression INTERR CLOSE_PARENS
Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs 2005-03-14 15:17:54 UTC (rev 41795)
+++ trunk/mcs/gmcs/generic.cs 2005-03-14 15:39:16 UTC (rev 41796)
@@ -2267,29 +2267,6 @@
}
}
- public class NullCoalescingOperator : Expression
- {
- Expression left;
- Expression right;
-
- public NullCoalescingOperator (Expression left, Expression
right, Location loc)
- {
- this.left = left;
- this.right = right;
- this.loc = loc;
- }
-
- public override Expression DoResolve (EmitContext ec)
- {
- Error (-1, "The ?? operator is not yet implemented.");
- return null;
- }
-
- public override void Emit (EmitContext ec)
- {
- }
- }
-
public abstract class Nullable
{
protected sealed class NullableInfo
@@ -2899,5 +2876,97 @@
ig.MarkLabel (end_label);
}
}
+
+ public class NullCoalescingOperator : Expression
+ {
+ Expression left, right;
+ Expression expr;
+ Unwrap unwrap;
+
+ public NullCoalescingOperator (Expression left,
Expression right, Location loc)
+ {
+ this.left = left;
+ this.right = right;
+ this.loc = loc;
+
+ eclass = ExprClass.Value;
+ }
+
+ public override Expression DoResolve (EmitContext ec)
+ {
+ if (type != null)
+ return this;
+
+ left = left.Resolve (ec);
+ if (left == null)
+ return null;
+
+ right = right.Resolve (ec);
+ if (right == null)
+ return null;
+
+ Type ltype = left.Type, rtype = right.Type;
+
+ if (!TypeManager.IsNullableType (ltype) &&
ltype.IsValueType) {
+ Binary.Error_OperatorCannotBeApplied
(loc, "??", ltype, rtype);
+ return null;
+ }
+
+ if (TypeManager.IsNullableType (ltype)) {
+ NullableInfo info = new NullableInfo
(ltype);
+
+ unwrap = (Unwrap) new Unwrap (left,
loc).Resolve (ec);
+ if (unwrap == null)
+ return null;
+
+ expr = Convert.ImplicitConversion (ec,
right, info.UnderlyingType, loc);
+ if (expr != null) {
+ left = unwrap;
+ type = expr.Type;
+ return this;
+ }
+ }
+
+ expr = Convert.ImplicitConversion (ec, right,
ltype, loc);
+ if (expr != null) {
+ type = expr.Type;
+ return this;
+ }
+
+ if (unwrap != null) {
+ expr = Convert.ImplicitConversion (ec,
unwrap, rtype, loc);
+ if (expr != null) {
+ left = expr;
+ expr = right;
+ type = expr.Type;
+ return this;
+ }
+ }
+
+ Binary.Error_OperatorCannotBeApplied (loc,
"??", ltype, rtype);
+ return null;
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ ILGenerator ig = ec.ig;
+
+ Label is_null_label = ig.DefineLabel ();
+ Label end_label = ig.DefineLabel ();
+
+ if (unwrap != null) {
+ unwrap.EmitCheck (ec);
+ ig.Emit (OpCodes.Brfalse,
is_null_label);
+ }
+
+ left.Emit (ec);
+ ig.Emit (OpCodes.Br, end_label);
+
+ ig.MarkLabel (is_null_label);
+ expr.Emit (ec);
+
+ ig.MarkLabel (end_label);
+ }
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches