Author: sudha
Date: 2005-03-24 03:49:11 -0500 (Thu, 24 Mar 2005)
New Revision: 42196
Modified:
trunk/mcs/mbas/ChangeLog
trunk/mcs/mbas/cfold.cs
trunk/mcs/mbas/expression.cs
trunk/mcs/mbas/mb-parser.jay
Log:
* Constant Arithmatic Fixes
* Dictionary member access support
* Minor fixes for exponentiation in compound assignment
Modified: trunk/mcs/mbas/ChangeLog
===================================================================
--- trunk/mcs/mbas/ChangeLog 2005-03-24 07:50:10 UTC (rev 42195)
+++ trunk/mcs/mbas/ChangeLog 2005-03-24 08:49:11 UTC (rev 42196)
@@ -1,3 +1,10 @@
+2005-03-24 Satya Sudha K <[EMAIL PROTECTED]>
+ * mb-parser.jay :
+ - Support for Dictionary Member Access Expressions
+ - Exponentiation operator in compound assignments
+ * expression.cs : Merged 'Exponentiation' class with 'Binary' class
+ * cfold.cs : Fixed constant division (both '\' and '/')
+
2005-03-24 Manjula GHM <[EMAIL PROTECTED]>
* mb-parser.jay,mb-tokenizer.cs: Support 'End Statement' in parser
and tokenizer file
Modified: trunk/mcs/mbas/cfold.cs
===================================================================
--- trunk/mcs/mbas/cfold.cs 2005-03-24 07:50:10 UTC (rev 42195)
+++ trunk/mcs/mbas/cfold.cs 2005-03-24 08:49:11 UTC (rev 42196)
@@ -31,7 +31,8 @@
ref Constant left, ref
Constant right,
Location loc)
{
- if (left is DoubleConstant || right is DoubleConstant
|| oper == Binary.Operator.Exponentiation){
+ if (left is DoubleConstant || right is DoubleConstant
||
+ oper == Binary.Operator.Exponentiation || oper ==
Binary.Operator.Division) {
//
// If either side is a double, convert the
other to a double
//
@@ -647,46 +648,46 @@
}
break;
- case Binary.Operator.Division:
+ case Binary.Operator.IntDivision:
DoConstantNumericPromotions (ec, oper, ref
left, ref right, loc);
if (left == null || right == null)
return null;
try {
- if (left is DoubleConstant){
- double res;
+ if (left is DoubleConstant) {
+ long left_val, right_val, res;
+ left_val = (long)
((DoubleConstant) left).Value;
+ right_val = (long)
((DoubleConstant) right).Value;
if (ec.ConstantCheckState)
- res = checked
(((DoubleConstant) left).Value /
-
((DoubleConstant) right).Value);
+ res = checked (left_val
/ right_val);
else
- res = unchecked
(((DoubleConstant) left).Value /
-
((DoubleConstant) right).Value);
+ res = unchecked
(left_val / right_val);
- return new DoubleConstant (res);
- } else if (left is FloatConstant){
- float res;
+ return new LongConstant (res);
+ } else if (left is FloatConstant) {
+ long left_val, right_val, res;
+ left_val = (long)
((FloatConstant) left).Value;
+ right_val = (long)
((FloatConstant) right).Value;
if (ec.ConstantCheckState)
- res = checked
(((FloatConstant) left).Value /
-
((FloatConstant) right).Value);
+ res = checked (left_val
/ right_val);
else
- res = unchecked
(((FloatConstant) left).Value /
-
((FloatConstant) right).Value);
+ res = unchecked
(left_val / right_val);
- return new FloatConstant (res);
- } else if (left is ULongConstant){
- ulong res;
+ return new LongConstant (res);
+ } else if (left is DecimalConstant) {
+ long left_val, right_val, res;
+ left_val = (long)
((DecimalConstant) left).Value;
+ right_val = (long)
((DecimalConstant) right).Value;
if (ec.ConstantCheckState)
- res = checked
(((ULongConstant) left).Value /
-
((ULongConstant) right).Value);
+ res = checked (left_val
/ right_val);
else
- res = unchecked
(((ULongConstant) left).Value /
-
((ULongConstant) right).Value);
+ res = unchecked
(left_val / right_val);
- return new ULongConstant (res);
- } else if (left is LongConstant){
+ return new LongConstant (res);
+ } else if (left is LongConstant) {
long res;
if (ec.ConstantCheckState)
@@ -697,30 +698,17 @@
((LongConstant) right).Value);
return new LongConstant (res);
- } else if (left is UIntConstant){
- uint res;
+ } else {
+ int res;
if (ec.ConstantCheckState)
- res = checked
(((UIntConstant) left).Value /
-
((UIntConstant) right).Value);
- else
- res = unchecked
(((UIntConstant) left).Value /
-
((UIntConstant) right).Value);
-
- return new UIntConstant (res);
- } else if (left is IntConstant){
- int res;
-
- if (ec.ConstantCheckState)
res = checked
(((IntConstant) left).Value /
((IntConstant) right).Value);
else
res = unchecked
(((IntConstant) left).Value /
((IntConstant) right).Value);
-
+
return new IntConstant (res);
- } else {
- throw new Exception (
"Unexepected input: " + left);
}
} catch (OverflowException){
Error_CompileTimeOverflow (loc);
@@ -730,7 +718,31 @@
}
break;
+ case Binary.Operator.Division:
+ DoConstantNumericPromotions (ec, oper, ref
left, ref right, loc);
+ if (left == null || right == null)
+ return null;
+
+ try {
+ double res;
+
+ if (ec.ConstantCheckState)
+ res = checked
(((DoubleConstant) left).Value /
+
((DoubleConstant) right).Value);
+ else
+ res = unchecked
(((DoubleConstant) left).Value /
+
((DoubleConstant) right).Value);
+
+ return new DoubleConstant (res);
+ } catch (OverflowException){
+ Error_CompileTimeOverflow (loc);
+
+ } catch (DivideByZeroException) {
+ Report.Error (30542, loc, "Division by
constant zero");
+ }
+ break;
+
case Binary.Operator.Modulus:
DoConstantNumericPromotions (ec, oper, ref
left, ref right, loc);
if (left == null || right == null)
Modified: trunk/mcs/mbas/expression.cs
===================================================================
--- trunk/mcs/mbas/expression.cs 2005-03-24 07:50:10 UTC (rev 42195)
+++ trunk/mcs/mbas/expression.cs 2005-03-24 08:49:11 UTC (rev 42196)
@@ -1527,137 +1527,6 @@
}
}
- public class Exponentiation : Expression {
-
- Expression left, right;
- ArrayList Arguments;
- protected MethodBase method;
-
- public Exponentiation(Location loc, Expression left, Expression
right) {
- this.left = left;
- this.right = right;
- this.loc = loc;
- }
-
- public override Expression DoResolve (EmitContext ec)
- {
- left = left.Resolve (ec);
- right = right.Resolve (ec);
-
- if (left == null || right == null)
- return null;
-
- if (left.Type == null)
- throw new Exception (
- "Resolve returned non null, but did not
set the type! (" +
- left + ") at Line: " + loc.Row);
- if (right.Type == null)
- throw new Exception (
- "Resolve returned non null, but did not
set the type! (" +
- right + ") at Line: "+ loc.Row);
-
- eclass = ExprClass.Value;
- Expression e = null;
-
- if (left is EnumConstant) {
- left = ((EnumConstant)
left).WidenToCompilerConstant();
- }
-
- if (right is EnumConstant) {
- right = ((EnumConstant)
right).WidenToCompilerConstant();
- }
-
- if (left is Constant && right is Constant){
- e = ConstantFold.BinaryFold (
- ec, Binary.Operator.Exponentiation, (Constant)
left, (Constant) right, loc);
- if (e != null)
- return e;
- }
-
- 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);
- if (l.IsValueType)
- left = ConvertImplicit (ec, left,
TypeManager.object_type, loc);
- if (left == null || right == null) {
- Error_OperatorCannotBeApplied (loc,
"^", l, r);
- return null;
- }
-
- l = left.Type;
- r = right.Type;
-
- Expression tmp =
Mono.MonoBASIC.Parser.DecomposeQI (
-
"Microsoft.VisualBasic.CompilerServices.ObjectType.PowObj",
- Location.Null);
-
- ArrayList arguments = new ArrayList ();
- arguments.Add (new Argument (left,
Argument.AType.Expression));
- arguments.Add (new Argument (right,
Argument.AType.Expression));
- e = new Invocation (tmp, arguments, loc);
- return e.Resolve (ec);
- }
-
- if (l == TypeManager.date_type || r ==
TypeManager.date_type ||
- l == TypeManager.char_type || r ==
TypeManager.char_type ||
- ! l.IsValueType || ! r.IsValueType) {
- Error_OperatorCannotBeApplied (loc, "^", l, r);
- return null;
- }
-
- if (l != TypeManager.double_type) {
- left = ConvertImplicit (ec, left,
TypeManager.double_type, loc);
- if (left == null){
- Error_OperatorCannotBeApplied (loc,
"&", l, r);
- return null;
- }
- type = TypeManager.double_type;
- }
-
- if (r != TypeManager.double_type) {
- right = ConvertImplicit (ec, right,
TypeManager.double_type, loc);
- if (right == null){
- Error_OperatorCannotBeApplied (loc,
"^", l, r);
- return null;
- }
-
- type = TypeManager.double_type;
- }
-
- Expression etmp =
Mono.MonoBASIC.Parser.DecomposeQI("System.Math.Pow", loc);
- ArrayList args = new ArrayList();
- args.Add (new Argument (left,
Argument.AType.Expression));
- args.Add (new Argument (right,
Argument.AType.Expression));
- e = (Expression) new Invocation (etmp, args, loc);
- return e.Resolve(ec);
- }
-
- public override void Emit (EmitContext ec)
- {
- throw new Exception ("Should not happen");
- }
-
- static public void Error_OperatorCannotBeApplied (Location
loc, string name, Type l, Type r)
- {
- Report.Error (19, loc,
- "Operator " + name + " cannot be applied to
operands of type '" +
- TypeManager.MonoBASIC_Name (l) + "' and '" +
- TypeManager.MonoBASIC_Name (r) + "'");
- }
-
- }
public class StringConcat : Expression {
Expression left, right;
@@ -1994,8 +1863,9 @@
else if (r == TypeManager.decimal_type)
conv_right_as = TypeManager.bool_type;
} else if ((l == TypeManager.double_type || r ==
TypeManager.double_type) ||
- (oper == Operator.Division &&
- !(l == TypeManager.decimal_type || r ==
TypeManager.decimal_type))) {
+ (oper == Operator.Exponentiation) ||
+ (oper == Operator.Division &&
+ !(l == TypeManager.decimal_type || r ==
TypeManager.decimal_type))) {
//
// If either operand is of type double, the
other operand is
// conveted to type double.
@@ -2478,6 +2348,8 @@
conv_left_as =
conv_right_as = TypeManager.int64_type;
type =
TypeManager.int64_type;
}
+ } else if (oper ==
Operator.Exponentiation) {
+ conv_left_as = conv_right_as =
TypeManager.double_type;
} else if (oper ==
Operator.IntDivision) {
conv_left_as = conv_right_as =
TypeManager.int64_type;
} else {
@@ -2590,6 +2462,7 @@
// 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);
@@ -2652,6 +2525,16 @@
if (conv_done)
return ResolveOperator (ec);
+
+ if (oper == Operator.Exponentiation) {
+ Expression etmp =
Mono.MonoBASIC.Parser.DecomposeQI("System.Math.Pow", loc);
+ ArrayList args = new ArrayList();
+ args.Add (new Argument (left,
Argument.AType.Expression));
+ args.Add (new Argument (right,
Argument.AType.Expression));
+ Expression e = (Expression) new Invocation
(etmp, args, loc);
+ return e.Resolve(ec);
+ }
+
bool overload_failed = false;
string op = oper_names [(int) oper];
MethodGroupExpr union = null;
Modified: trunk/mcs/mbas/mb-parser.jay
===================================================================
--- trunk/mcs/mbas/mb-parser.jay 2005-03-24 07:50:10 UTC (rev 42195)
+++ trunk/mcs/mbas/mb-parser.jay 2005-03-24 08:49:11 UTC (rev 42196)
@@ -4299,6 +4299,19 @@
$$ = new Invocation ((Expression) $2, (ArrayList) $3,
(Location)$5);
// Console.WriteLine ("Invocation: {0} with {1} arguments", $2,
($3 != null) ? ((ArrayList) $3).Count : 0);
}
+ | primary_expression EXCLAMATION _mark_ identifier // FIXME : This
should be identifier-or-keyword
+ {
+ if ($1 == null) {
+ Location l = (Location)$3;
+ Report.Error (1, l, "THIS IS CRAZY");
+ }
+
+ ArrayList args = new ArrayList ();
+ Expression etmp = new StringLiteral ((string)$4);
+
+ args.Add (new Argument (etmp, Argument.AType.Expression));
+ $$ = new Invocation ((Expression) $1, args, (Location)$3);
+ }
;
base_access
@@ -4391,9 +4404,7 @@
}
| MYCLASS
{
- // FIXME: This is actually somewhat different from Me
- // because it is for accessing static (classifier)
methods/properties/fields
- $$ = new This (current_block, lexer.Location);
+ $$ = new This (This.TypeOfAccess.MyClass, current_block,
lexer.Location);
}
;
@@ -4435,15 +4446,16 @@
;
exponentiation_expression
- : primary_expression
+ : prefixed_unary_expression
| exponentiation_expression OP_EXP _mark_ primary_expression
{
- $$ = new Exponentiation ((Location)$3, (Expression) $1,
(Expression) $4);
+ $$ = new Binary (Binary.Operator.Exponentiation,
+ (Expression) $1, (Expression) $4,
(Location)$3);
}
;
prefixed_unary_expression
- : exponentiation_expression
+ : primary_expression
| PLUS _mark_ prefixed_unary_expression
{
//FIXME: Is this rule correctly defined ?
@@ -4457,7 +4469,7 @@
;
multiplicative_expression
- : prefixed_unary_expression
+ : exponentiation_expression
| multiplicative_expression STAR _mark_ prefixed_unary_expression
{
$$ = new Binary (Binary.Operator.Multiply,
@@ -4627,6 +4639,13 @@
{
$$ = new Assign ((Expression) $1, (Expression) $4,
(Location)$3);
}
+ | prefixed_unary_expression OP_EXP ASSIGN _mark_ expression
+ {
+ Location l = (Location)$4;
+
+ $$ = new CompoundAssign (
+ Binary.Operator.Exponentiation, (Expression) $1,
(Expression) $5, l);
+ }
| prefixed_unary_expression STAR ASSIGN _mark_ expression
{
Location l = (Location)$4;
@@ -4677,13 +4696,6 @@
$$ = new CompoundAssign (
Binary.Operator.Addition, (Expression) $1, (Expression)
$5, l);
}
- | prefixed_unary_expression OP_EXP ASSIGN _mark_ expression
- {
- /*Location l = (Location)$4;
-
- TODO: $$ = new CompoundAssign (
- Binary.Operator.ExclusiveOr, (Expression) $1,
(Expression) $5, l); */
- }
| prefixed_unary_expression ASSIGN ADDRESSOF _mark_ expression
{
ArrayList args = new ArrayList();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches