Author: sudha
Date: 2005-03-11 03:42:39 -0500 (Fri, 11 Mar 2005)
New Revision: 41680
Modified:
trunk/mcs/mbas/ChangeLog
trunk/mcs/mbas/assign.cs
trunk/mcs/mbas/ecore.cs
trunk/mcs/mbas/expression.cs
Log:
* expression.cs :
Support for 'Nothing' with all operators.
A few fixes to the 'DoNumericPromotions' method
* ecore.cs :
Fixed Boolean constant conversions
Supported conversion of 'nothing' to value types
Modified: trunk/mcs/mbas/ChangeLog
===================================================================
--- trunk/mcs/mbas/ChangeLog 2005-03-11 07:36:58 UTC (rev 41679)
+++ trunk/mcs/mbas/ChangeLog 2005-03-11 08:42:39 UTC (rev 41680)
@@ -1,3 +1,11 @@
+2005-03-11 Satya Sudha K <[EMAIL PROTECTED]>
+ * expression.cs :
+ Support for 'Nothing' with all operators.
+ A few fixes to the 'DoNumericPromotions' method
+ * ecore.cs :
+ Fixed Boolean constant conversions
+ Supported conversion of 'nothing' to value types
+
2005-03-10 Manjula GHM <[EMAIL PROTECTED]>
*expression.cs :
Support 'Is' for all reference types
Modified: trunk/mcs/mbas/assign.cs
===================================================================
--- trunk/mcs/mbas/assign.cs 2005-03-11 07:36:58 UTC (rev 41679)
+++ trunk/mcs/mbas/assign.cs 2005-03-11 08:42:39 UTC (rev 41680)
@@ -228,38 +228,38 @@
//To support 'Mid' Assignment Statement
if(target is Invocation) {
- Invocation i = (Invocation) target;
- Expression mid_expr;
- mid_expr = i.Expr;
+ Invocation i = (Invocation) target;
+ Expression mid_expr;
+ mid_expr = i.Expr;
- if (mid_expr is SimpleName) {
- SimpleName sn = mid_expr as SimpleName;
- string s = sn.Name;
+ if (mid_expr is SimpleName) {
+ SimpleName sn = mid_expr as SimpleName;
+ string s = sn.Name;
- if (s == "Mid" || s == "Mid$") {
- //It is Mid statement. Construct the function and
- //call corresponding
Microsoft.VisualBasic.CompilerServices function
- Expression etmp;
- ArrayList arglist = new ArrayList();
-
- Argument arg4;
- Expression e = null;
- eclass = ExprClass.Value;
-
- arglist = i.Arguments;
-
- etmp =
Mono.MonoBASIC.Parser.DecomposeQI("Microsoft.VisualBasic.CompilerServices.StringType.MidStmtStr",
loc);
- //Get fourth argument and add it to argument list
-
- arg4 = new Argument (source,
Argument.AType.Expression);
- arglist.Add (arg4);
- e = (Expression) new Invocation (etmp,
arglist, loc);
- e = e.Resolve(ec);
- return e;
- }
+ if (s == "Mid" || s == "Mid$") {
+ //It is Mid statement. Construct the
function and
+ //call corresponding
Microsoft.VisualBasic.CompilerServices function
+ Expression etmp;
+ ArrayList arglist = new
ArrayList();
+
+ Argument arg4;
+ Expression e = null;
+ eclass = ExprClass.Value;
+
+ arglist = i.Arguments;
+
+ etmp =
Mono.MonoBASIC.Parser.DecomposeQI("Microsoft.VisualBasic.CompilerServices.StringType.MidStmtStr",
loc);
+ //Get fourth argument and add
it to argument list
+
+ arg4 = new Argument (source,
Argument.AType.Expression);
+ arglist.Add (arg4);
+ e = (Expression) new Invocation
(etmp, arglist, loc);
+ e = e.Resolve(ec);
+ return e;
+ }
+ }
+
}
-
- }
target = target.ResolveLValue (ec, source);
if (target == null)
Modified: trunk/mcs/mbas/ecore.cs
===================================================================
--- trunk/mcs/mbas/ecore.cs 2005-03-11 07:36:58 UTC (rev 41679)
+++ trunk/mcs/mbas/ecore.cs 2005-03-11 08:42:39 UTC (rev 41680)
@@ -788,7 +788,7 @@
//
// Attempt to do the implicit constant expression
conversions
- if (expr is IntConstant || expr is LongConstant || expr
is DoubleConstant || expr is FloatConstant){
+ if (expr is BoolConstant || expr is IntConstant || expr
is LongConstant || expr is DoubleConstant || expr is FloatConstant){
Expression e;
e = TryImplicitNumericConversion (target_type,
(Constant) expr);
@@ -2210,6 +2210,35 @@
}
return null;
}
+
+ static public Expression ConvertNothingToDefaultValues
(EmitContext ec, Expression expr,
+ Type
target_type, Location loc)
+ {
+ switch (Type.GetTypeCode (target_type)) {
+ case TypeCode.Boolean :
+ return new BoolConstant (false);
+ case TypeCode.Byte :
+ return new ByteConstant (0);
+ case TypeCode.Char :
+ return new CharConstant ((char)0);
+ case TypeCode.SByte :
+ return new SByteConstant (0);
+ case TypeCode.Int16 :
+ return new ShortConstant (0);
+ case TypeCode.Int32 :
+ return new IntConstant (0);
+ case TypeCode.Int64 :
+ return new LongConstant (0);
+ case TypeCode.Decimal :
+ return new DecimalConstant
(System.Decimal.Zero);
+ case TypeCode.Single :
+ return new FloatConstant (0.0F);
+ case TypeCode.Double :
+ return new DoubleConstant (0.0);
+ }
+
+ return null;
+ }
/// <summary>
/// Attempts to apply the 'Standard Implicit
@@ -2227,6 +2256,14 @@
Type expr_type = expr.Type;
Expression e;
+ if (expr is NullLiteral) {
+ if (target_type == TypeManager.string_type)
+ return expr;
+ e = ConvertNothingToDefaultValues (ec, expr,
target_type, loc);
+ if (e != null)
+ return e;
+ }
+
if (expr_type == target_type)
return expr;
@@ -2281,6 +2318,15 @@
static protected Expression TryImplicitNumericConversion (Type
target_type, Constant ic)
{
double value = 0;
+ if (ic is BoolConstant) {
+ bool val = (bool) ((BoolConstant)ic).Value;
+ if (val) {
+ if (target_type ==
TypeManager.byte_type)
+ value = Byte.MaxValue;
+ else
+ value = -1;
+ }
+ }
if (ic is IntConstant)
value = (double)((IntConstant)ic).Value;
@@ -2298,7 +2344,11 @@
//
// FIXME: This could return constants instead of
EmptyCasts
//
- if (target_type == TypeManager.sbyte_type){
+ if (target_type == TypeManager.bool_type){
+ if (value != 0)
+ return new BoolConstant (true);
+ return new BoolConstant (false);
+ } else if (target_type == TypeManager.sbyte_type){
if (value >= SByte.MinValue && value <=
SByte.MaxValue)
return new SByteConstant ((sbyte)
System.Math.Round (value));
} else if (target_type == TypeManager.byte_type){
Modified: trunk/mcs/mbas/expression.cs
===================================================================
--- trunk/mcs/mbas/expression.cs 2005-03-11 07:36:58 UTC (rev 41679)
+++ trunk/mcs/mbas/expression.cs 2005-03-11 08:42:39 UTC (rev 41680)
@@ -4,6 +4,7 @@
// Author:
// Miguel de Icaza ([EMAIL PROTECTED])
// Manjula GHM ([EMAIL PROTECTED])
+// Satya Sudha K ([EMAIL PROTECTED])
//
// (C) 2001 Ximian, Inc.
//
@@ -1576,6 +1577,15 @@
Type l = left.Type;
Type r = right.Type;
+ if (left is NullLiteral && right is NullLiteral) {
+ Error_OperatorCannotBeApplied (loc, "^", l, r);
+ return null;
+ }
+ if (left is NullLiteral)
+ l = r;
+ if (right is NullLiteral)
+ r = l;
+
if (l == TypeManager.object_type || r ==
TypeManager.object_type) {
if (r.IsValueType)
right = ConvertImplicit (ec, right,
TypeManager.object_type, loc);
@@ -1932,19 +1942,22 @@
//
bool DoNumericPromotions (EmitContext ec, Type l, Type r,
Operator oper)
{
- // Need not do anything for shift operators, as this
will be handled by the
- // 'cHECKsHiftArguments' method
Type conv_left_as = null;
Type conv_right_as = null;
+ if (left is NullLiteral)
+ conv_left_as = r;
+ if (right is NullLiteral)
+ conv_right_as = l;
+
+ // Need not do anything for shift operators, as this
will be handled by the
+ // 'CheckShiftArguments' method
if (oper == Operator.LeftShift || oper ==
Operator.RightShift)
return true;
if (l == TypeManager.bool_type && r ==
TypeManager.bool_type) {
- if (IsBitwiseOperator (oper) ||
IsRelationalOperator (oper) || IsLogicalOperator (oper))
- return true;
if (IsArithmaticOperator (oper) && oper !=
Operator.Division) {
type = TypeManager.int32_type;
- conv_left_as = conv_left_as =
TypeManager.short_type;
+ conv_left_as = conv_right_as =
TypeManager.short_type;
}
}
@@ -1969,8 +1982,6 @@
conv_left_as = TypeManager.bool_type;
else if (r == TypeManager.decimal_type)
conv_right_as = TypeManager.bool_type;
- else
- return true;
} else if ((l == TypeManager.double_type || r ==
TypeManager.double_type) ||
(oper == Operator.Division &&
!(l == TypeManager.decimal_type || r ==
TypeManager.decimal_type))) {
@@ -1997,11 +2008,12 @@
} else if (l == TypeManager.int32_type || r ==
TypeManager.int32_type){
type = conv_left_as = conv_right_as =
TypeManager.int32_type;
} else if (l == TypeManager.short_type || r ==
TypeManager.short_type){
- conv_left_as = conv_right_as =
TypeManager.int32_type;
+ conv_left_as = conv_right_as =
TypeManager.short_type;
type = TypeManager.int32_type;
} else {
type = TypeManager.int32_type;
}
+
if (conv_left_as != null)
left = ConvertImplicit (ec, left, conv_left_as,
loc);
if (conv_right_as != null)
@@ -2046,7 +2058,27 @@
}
type = left.Type;
+ if (left is NullLiteral) {
+ type = right.Type;
+ if (right.Type != TypeManager.bool_type) {
+ left = ConvertImplicit (ec, left,
right.Type, loc);
+ if (left == null) {
+ Error_OperatorCannotBeApplied
(loc, OperName (oper), left.Type, right.Type);
+ return null;
+ }
+ }
+ }
right = e;
+
+ if (type == TypeManager.bool_type) {
+ left = ConvertImplicit (ec, left,
TypeManager.short_type, loc);
+ if (left == null) {
+ Error_OperatorCannotBeApplied (loc,
OperName (oper), left.Type, right.Type);
+ return null;
+ }
+ type = left.Type;
+ }
+
int mask = 0;
if ( type == TypeManager.byte_type)
mask = 7;
@@ -2061,19 +2093,15 @@
right = right.DoResolve (ec);
}
- if (type == TypeManager.bool_type) {
- left = ConvertImplicit (ec, left,
TypeManager.short_type, loc);
- if (left == null) {
- Error_OperatorCannotBeApplied (loc,
OperName (oper), left.Type, right.Type);
- return null;
- }
- }
if (type == TypeManager.byte_type ||
type == TypeManager.short_type ||
- type == TypeManager.int32_type ||
- type == TypeManager.int64_type)
+ type == TypeManager.int32_type) {
+ type = TypeManager.int32_type;
return this;
+ }
+ if (type == TypeManager.int64_type)
+ return this;
if ((e = ConvertImplicit (ec, left,
TypeManager.int64_type, loc)) != null) {
left = e;
type = TypeManager.int64_type;
@@ -2154,6 +2182,20 @@
Type conv_left_as = null;
Type conv_right_as = null;
+ if (left is NullLiteral && (r.IsValueType || r ==
TypeManager.string_type)) {
+ // Just treat nothing as the other type,
implicit conversion
+ // will return the default value
+ conv_left_as = r;
+ l = r;
+ }
+
+ if (right is NullLiteral && (l.IsValueType || l ==
TypeManager.string_type)) {
+ // Just treat nothing as the other type,
implicit conversion
+ // will return the default value
+ conv_right_as = l;
+ r = l;
+ }
+
// deal with objects and reference types first
if (l == TypeManager.object_type || r ==
TypeManager.object_type) {
@@ -2310,7 +2352,15 @@
bool right_is_string = (right.Type ==
TypeManager.string_type);
if (left_is_string || right_is_string) {
-
+
+ if (left is NullLiteral) {
+ left_is_string = true;
+ l = r;
+ }
+ if (right is NullLiteral) {
+ right_is_string = true;
+ r = l;
+ }
if (left_is_string && right_is_string) {
if (oper == Operator.Addition) {
// Both operands are string
@@ -2332,7 +2382,7 @@
return e.Resolve(ec);
}
}
-
+
Expression other = right_is_string ?
left: right;
Type other_type = other.Type;
@@ -2493,6 +2543,9 @@
l = left.Type;
r = right.Type;
+ // Required conversions done by
'DoNumericPromotions' method
+ // So Reset 'conv_left_as', 'conv_right_as'
+ conv_left_as = conv_right_as = null;
if (l == TypeManager.decimal_type && r ==
TypeManager.decimal_type) {
if (IsRelationalOperator (oper)) {
Expression etmp =
Mono.MonoBASIC.Parser.DecomposeQI ("System.Decimal.Compare", Location.Null);
@@ -2664,14 +2717,25 @@
return e;
}
+ Expression etmp = ResolveOperator (ec);
Type l = left.Type;
- Expression etmp = ResolveOperator (ec);
+
// if the operands are of type byte/short, convert the
result back to short/byte
- if ((l == TypeManager.short_type || l ==
TypeManager.byte_type) &&
- (IsArithmaticOperator (oper) || IsBitwiseOperator
(oper) || IsShiftOperator (oper))) {
- Expression conv_exp = ConvertImplicit (ec,
etmp, left.Type, loc);
- if (conv_exp != null)
- return conv_exp;
+ if (l == TypeManager.bool_type || l ==
TypeManager.short_type || l == TypeManager.byte_type) {
+ if (l == TypeManager.bool_type)
+ l = TypeManager.short_type;
+ if (IsArithmaticOperator (oper) && oper !=
Operator.Division) {
+ Expression conv_exp = ConvertImplicit
(ec, etmp, l, loc);
+ if (conv_exp != null)
+ return conv_exp;
+ }
+ if (IsShiftOperator (oper)) {
+ // No overflow checks are needed
+ if (l == TypeManager.byte_type)
+ return new OpcodeCast (etmp, l,
OpCodes.Conv_U1);
+ else
+ return new OpcodeCast (etmp, l,
OpCodes.Conv_I2);
+ }
}
return etmp;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches