// Marek Safar (marek.safar@seznam.cz)
//
// Copyright 2002, 2003 Ximian, Inc.
-// Copyright 2003-2008, Novell, Inc.
+// Copyright 2003-2011, Novell, Inc.
//
using System;
public static class ConstantFold
{
- public static TypeSpec[] CreateBinaryPromotionsTypes (BuildinTypes types)
+ public static TypeSpec[] CreateBinaryPromotionsTypes (BuiltinTypes types)
{
return new TypeSpec[] {
types.Decimal, types.Double, types.Float,
TypeSpec ltype = left.Type;
TypeSpec rtype = right.Type;
- foreach (TypeSpec t in rc.BuildinTypes.BinaryPromotionsTypes) {
+ foreach (TypeSpec t in rc.BuiltinTypes.BinaryPromotionsTypes) {
if (t == ltype)
return t == rtype || ConvertPromotion (rc, ref right, ref left, t);
return t == ltype || ConvertPromotion (rc, ref left, ref right, t);
}
- left = left.ConvertImplicitly (rc.BuildinTypes.Int);
- right = right.ConvertImplicitly (rc.BuildinTypes.Int);
+ left = left.ConvertImplicitly (rc.BuiltinTypes.Int);
+ right = right.ConvertImplicitly (rc.BuiltinTypes.Int);
return left != null && right != null;
}
return true;
}
- if (type.BuildinType == BuildinTypeSpec.Type.UInt) {
- type = rc.BuildinTypes.Long;
+ if (type.BuiltinType == BuiltinTypeSpec.Type.UInt) {
+ type = rc.BuiltinTypes.Long;
prim = prim.ConvertImplicitly (type);
second = second.ConvertImplicitly (type);
return prim != null && second != null;
TypeSpec rt = right.Type;
bool bool_res;
- if (lt.BuildinType == BuildinTypeSpec.Type.Bool && lt == rt) {
+ if (lt.BuiltinType == BuiltinTypeSpec.Type.Bool && lt == rt) {
bool lv = (bool) left.GetValue ();
bool rv = (bool) right.GetValue ();
switch (oper) {
case Binary.Operator.BitwiseAnd:
case Binary.Operator.LogicalAnd:
- return new BoolConstant (ec.BuildinTypes, lv && rv, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, lv && rv, left.Location);
case Binary.Operator.BitwiseOr:
case Binary.Operator.LogicalOr:
- return new BoolConstant (ec.BuildinTypes, lv || rv, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, lv || rv, left.Location);
case Binary.Operator.ExclusiveOr:
- return new BoolConstant (ec.BuildinTypes, lv ^ rv, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, lv ^ rv, left.Location);
case Binary.Operator.Equality:
- return new BoolConstant (ec.BuildinTypes, lv == rv, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, lv == rv, left.Location);
case Binary.Operator.Inequality:
- return new BoolConstant (ec.BuildinTypes, lv != rv, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, lv != rv, left.Location);
}
return null;
}
case Binary.Operator.ExclusiveOr:
result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
if (result != null)
- result = result.TryReduce (ec, lt, loc);
+ result = result.TryReduce (ec, lt);
return result;
///
case Binary.Operator.Subtraction:
result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
if (result != null)
- result = result.TryReduce (ec, EnumSpec.GetUnderlyingType (lt), loc);
+ result = result.TryReduce (ec, EnumSpec.GetUnderlyingType (lt));
return result;
///
//
// bool? operator &(bool? x, bool? y);
//
- if ((lt.BuildinType == BuildinTypeSpec.Type.Bool && right is NullLiteral) ||
- (rt.BuildinType == BuildinTypeSpec.Type.Bool && left is NullLiteral)) {
- var b = new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+ if ((lt.BuiltinType == BuiltinTypeSpec.Type.Bool && right is NullLiteral) ||
+ (rt.BuiltinType == BuiltinTypeSpec.Type.Bool && left is NullLiteral)) {
+ var b = new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
// false | null => null
// null | false => null
// true | null => true
// null | true => true
- return ReducedExpression.Create (new BoolConstant (ec.BuildinTypes, true, loc), b);
+ return ReducedExpression.Create (new BoolConstant (ec.BuiltinTypes, true, loc), b);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
if (left is IntConstant){
int res = ((IntConstant) left).Value | ((IntConstant) right).Value;
- return new IntConstant (ec.BuildinTypes, res, left.Location);
+ return new IntConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is UIntConstant){
uint res = ((UIntConstant)left).Value | ((UIntConstant)right).Value;
- return new UIntConstant (ec.BuildinTypes, res, left.Location);
+ return new UIntConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is LongConstant){
long res = ((LongConstant)left).Value | ((LongConstant)right).Value;
- return new LongConstant (ec.BuildinTypes, res, left.Location);
+ return new LongConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is ULongConstant){
ulong res = ((ULongConstant)left).Value |
((ULongConstant)right).Value;
- return new ULongConstant (ec.BuildinTypes, res, left.Location);
+ return new ULongConstant (ec.BuiltinTypes, res, left.Location);
}
break;
//
// bool? operator &(bool? x, bool? y);
//
- if ((lt.BuildinType == BuildinTypeSpec.Type.Bool && right is NullLiteral) ||
- (rt.BuildinType == BuildinTypeSpec.Type.Bool && left is NullLiteral)) {
- var b = new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+ if ((lt.BuiltinType == BuiltinTypeSpec.Type.Bool && right is NullLiteral) ||
+ (rt.BuiltinType == BuiltinTypeSpec.Type.Bool && left is NullLiteral)) {
+ var b = new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
// false & null => false
// null & false => false
if ((right is NullLiteral && left.IsDefaultValue) || (left is NullLiteral && right.IsDefaultValue))
- return ReducedExpression.Create (new BoolConstant (ec.BuildinTypes, false, loc), b);
+ return ReducedExpression.Create (new BoolConstant (ec.BuiltinTypes, false, loc), b);
// true & null => null
// null & true => null
///
if (left is IntConstant){
int res = ((IntConstant) left).Value & ((IntConstant) right).Value;
- return new IntConstant (ec.BuildinTypes, res, left.Location);
+ return new IntConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is UIntConstant){
uint res = ((UIntConstant)left).Value & ((UIntConstant)right).Value;
- return new UIntConstant (ec.BuildinTypes, res, left.Location);
+ return new UIntConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is LongConstant){
long res = ((LongConstant)left).Value & ((LongConstant)right).Value;
- return new LongConstant (ec.BuildinTypes, res, left.Location);
+ return new LongConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is ULongConstant){
ulong res = ((ULongConstant)left).Value &
((ULongConstant)right).Value;
- return new ULongConstant (ec.BuildinTypes, res, left.Location);
+ return new ULongConstant (ec.BuiltinTypes, res, left.Location);
}
break;
if (left is IntConstant){
int res = ((IntConstant) left).Value ^ ((IntConstant) right).Value;
- return new IntConstant (ec.BuildinTypes, res, left.Location);
+ return new IntConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is UIntConstant){
uint res = ((UIntConstant)left).Value ^ ((UIntConstant)right).Value;
- return new UIntConstant (ec.BuildinTypes, res, left.Location);
+ return new UIntConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is LongConstant){
long res = ((LongConstant)left).Value ^ ((LongConstant)right).Value;
- return new LongConstant (ec.BuildinTypes, res, left.Location);
+ return new LongConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is ULongConstant){
ulong res = ((ULongConstant)left).Value ^
((ULongConstant)right).Value;
- return new ULongConstant (ec.BuildinTypes, res, left.Location);
+ return new ULongConstant (ec.BuiltinTypes, res, left.Location);
}
break;
// one is a string, and the other is not, then defer
// to runtime concatenation
//
- if (lt.BuildinType == BuildinTypeSpec.Type.String || rt.BuildinType == BuildinTypeSpec.Type.String){
+ if (lt.BuiltinType == BuiltinTypeSpec.Type.String || rt.BuiltinType == BuiltinTypeSpec.Type.String){
if (lt == rt)
- return new StringConstant (ec.BuildinTypes, (string)left.GetValue () + (string)right.GetValue (),
+ return new StringConstant (ec.BuiltinTypes, (string)left.GetValue () + (string)right.GetValue (),
left.Location);
return null;
if (result == null)
return null;
- result = result.TryReduce (ec, lt, loc);
+ result = result.TryReduce (ec, lt);
if (result == null)
return null;
res = unchecked (((DoubleConstant) left).Value +
((DoubleConstant) right).Value);
- return new DoubleConstant (ec.BuildinTypes, res, left.Location);
+ return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is FloatConstant){
float res;
res = unchecked (((FloatConstant) left).Value +
((FloatConstant) right).Value);
- result = new FloatConstant (ec.BuildinTypes, res, left.Location);
+ result = new FloatConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is ULongConstant){
ulong res;
res = unchecked (((ULongConstant) left).Value +
((ULongConstant) right).Value);
- result = new ULongConstant (ec.BuildinTypes, res, left.Location);
+ result = new ULongConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is LongConstant){
long res;
res = unchecked (((LongConstant) left).Value +
((LongConstant) right).Value);
- result = new LongConstant (ec.BuildinTypes, res, left.Location);
+ result = new LongConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is UIntConstant){
uint res;
res = unchecked (((UIntConstant) left).Value +
((UIntConstant) right).Value);
- result = new UIntConstant (ec.BuildinTypes, res, left.Location);
+ result = new UIntConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is IntConstant){
int res;
res = unchecked (((IntConstant) left).Value +
((IntConstant) right).Value);
- result = new IntConstant (ec.BuildinTypes, res, left.Location);
+ result = new IntConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is DecimalConstant) {
decimal res;
res = unchecked (((DecimalConstant) left).Value +
((DecimalConstant) right).Value);
- result = new DecimalConstant (ec.BuildinTypes, res, left.Location);
+ result = new DecimalConstant (ec.BuiltinTypes, res, left.Location);
}
} catch (OverflowException){
Error_CompileTimeOverflow (ec, loc);
if (result == null)
return null;
- result = result.TryReduce (ec, lt, loc);
+ result = result.TryReduce (ec, lt);
if (result == null)
return null;
}
if (left is NullLiteral && right is NullLiteral) {
- var lifted_int = new Nullable.NullableType (ec.BuildinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+ var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+ lifted_int.ResolveAsType (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
res = unchecked (((DoubleConstant) left).Value -
((DoubleConstant) right).Value);
- result = new DoubleConstant (ec.BuildinTypes, res, left.Location);
+ result = new DoubleConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is FloatConstant){
float res;
res = unchecked (((FloatConstant) left).Value -
((FloatConstant) right).Value);
- result = new FloatConstant (ec.BuildinTypes, res, left.Location);
+ result = new FloatConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is ULongConstant){
ulong res;
res = unchecked (((ULongConstant) left).Value -
((ULongConstant) right).Value);
- result = new ULongConstant (ec.BuildinTypes, res, left.Location);
+ result = new ULongConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is LongConstant){
long res;
res = unchecked (((LongConstant) left).Value -
((LongConstant) right).Value);
- result = new LongConstant (ec.BuildinTypes, res, left.Location);
+ result = new LongConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is UIntConstant){
uint res;
res = unchecked (((UIntConstant) left).Value -
((UIntConstant) right).Value);
- result = new UIntConstant (ec.BuildinTypes, res, left.Location);
+ result = new UIntConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is IntConstant){
int res;
res = unchecked (((IntConstant) left).Value -
((IntConstant) right).Value);
- result = new IntConstant (ec.BuildinTypes, res, left.Location);
+ result = new IntConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is DecimalConstant) {
decimal res;
res = unchecked (((DecimalConstant) left).Value -
((DecimalConstant) right).Value);
- return new DecimalConstant (ec.BuildinTypes, res, left.Location);
+ return new DecimalConstant (ec.BuiltinTypes, res, left.Location);
} else {
throw new Exception ( "Unexepected subtraction input: " + left);
}
case Binary.Operator.Multiply:
if (left is NullLiteral && right is NullLiteral) {
- var lifted_int = new Nullable.NullableType (ec.BuildinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+ var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+ lifted_int.ResolveAsType (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
res = unchecked (((DoubleConstant) left).Value *
((DoubleConstant) right).Value);
- return new DoubleConstant (ec.BuildinTypes, res, left.Location);
+ return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is FloatConstant){
float res;
res = unchecked (((FloatConstant) left).Value *
((FloatConstant) right).Value);
- return new FloatConstant (ec.BuildinTypes, res, left.Location);
+ return new FloatConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is ULongConstant){
ulong res;
res = unchecked (((ULongConstant) left).Value *
((ULongConstant) right).Value);
- return new ULongConstant (ec.BuildinTypes, res, left.Location);
+ return new ULongConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is LongConstant){
long res;
res = unchecked (((LongConstant) left).Value *
((LongConstant) right).Value);
- return new LongConstant (ec.BuildinTypes, res, left.Location);
+ return new LongConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is UIntConstant){
uint res;
res = unchecked (((UIntConstant) left).Value *
((UIntConstant) right).Value);
- return new UIntConstant (ec.BuildinTypes, res, left.Location);
+ return new UIntConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is IntConstant){
int res;
res = unchecked (((IntConstant) left).Value *
((IntConstant) right).Value);
- return new IntConstant (ec.BuildinTypes, res, left.Location);
+ return new IntConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is DecimalConstant) {
decimal res;
res = unchecked (((DecimalConstant) left).Value *
((DecimalConstant) right).Value);
- return new DecimalConstant (ec.BuildinTypes, res, left.Location);
+ return new DecimalConstant (ec.BuiltinTypes, res, left.Location);
} else {
throw new Exception ( "Unexepected multiply input: " + left);
}
case Binary.Operator.Division:
if (left is NullLiteral && right is NullLiteral) {
- var lifted_int = new Nullable.NullableType (ec.BuildinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+ var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+ lifted_int.ResolveAsType (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
res = unchecked (((DoubleConstant) left).Value /
((DoubleConstant) right).Value);
- return new DoubleConstant (ec.BuildinTypes, res, left.Location);
+ return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is FloatConstant){
float res;
res = unchecked (((FloatConstant) left).Value /
((FloatConstant) right).Value);
- return new FloatConstant (ec.BuildinTypes, res, left.Location);
+ return new FloatConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is ULongConstant){
ulong res;
res = unchecked (((ULongConstant) left).Value /
((ULongConstant) right).Value);
- return new ULongConstant (ec.BuildinTypes, res, left.Location);
+ return new ULongConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is LongConstant){
long res;
res = unchecked (((LongConstant) left).Value /
((LongConstant) right).Value);
- return new LongConstant (ec.BuildinTypes, res, left.Location);
+ return new LongConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is UIntConstant){
uint res;
res = unchecked (((UIntConstant) left).Value /
((UIntConstant) right).Value);
- return new UIntConstant (ec.BuildinTypes, res, left.Location);
+ return new UIntConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is IntConstant){
int res;
res = unchecked (((IntConstant) left).Value /
((IntConstant) right).Value);
- return new IntConstant (ec.BuildinTypes, res, left.Location);
+ return new IntConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is DecimalConstant) {
decimal res;
res = unchecked (((DecimalConstant) left).Value /
((DecimalConstant) right).Value);
- return new DecimalConstant (ec.BuildinTypes, res, left.Location);
+ return new DecimalConstant (ec.BuiltinTypes, res, left.Location);
} else {
throw new Exception ( "Unexepected division input: " + left);
}
case Binary.Operator.Modulus:
if (left is NullLiteral && right is NullLiteral) {
- var lifted_int = new Nullable.NullableType (ec.BuildinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+ var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+ lifted_int.ResolveAsType (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
res = unchecked (((DoubleConstant) left).Value %
((DoubleConstant) right).Value);
- return new DoubleConstant (ec.BuildinTypes, res, left.Location);
+ return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is FloatConstant){
float res;
res = unchecked (((FloatConstant) left).Value %
((FloatConstant) right).Value);
- return new FloatConstant (ec.BuildinTypes, res, left.Location);
+ return new FloatConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is ULongConstant){
ulong res;
res = unchecked (((ULongConstant) left).Value %
((ULongConstant) right).Value);
- return new ULongConstant (ec.BuildinTypes, res, left.Location);
+ return new ULongConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is LongConstant){
long res;
res = unchecked (((LongConstant) left).Value %
((LongConstant) right).Value);
- return new LongConstant (ec.BuildinTypes, res, left.Location);
+ return new LongConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is UIntConstant){
uint res;
res = unchecked (((UIntConstant) left).Value %
((UIntConstant) right).Value);
- return new UIntConstant (ec.BuildinTypes, res, left.Location);
+ return new UIntConstant (ec.BuiltinTypes, res, left.Location);
} else if (left is IntConstant){
int res;
res = unchecked (((IntConstant) left).Value %
((IntConstant) right).Value);
- return new IntConstant (ec.BuildinTypes, res, left.Location);
+ return new IntConstant (ec.BuiltinTypes, res, left.Location);
} else {
throw new Exception ( "Unexepected modulus input: " + left);
}
//
case Binary.Operator.LeftShift:
if (left is NullLiteral && right is NullLiteral) {
- var lifted_int = new Nullable.NullableType (ec.BuildinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+ var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+ lifted_int.ResolveAsType (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
}
- IntConstant ic = right.ConvertImplicitly (ec.BuildinTypes.Int) as IntConstant;
+ IntConstant ic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant;
if (ic == null){
Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
return null;
}
int lshift_val = ic.Value;
- switch (left.Type.BuildinType) {
- case BuildinTypeSpec.Type.ULong:
- return new ULongConstant (ec.BuildinTypes, ((ULongConstant) left).Value << lshift_val, left.Location);
- case BuildinTypeSpec.Type.Long:
- return new LongConstant (ec.BuildinTypes, ((LongConstant) left).Value << lshift_val, left.Location);
- case BuildinTypeSpec.Type.UInt:
- return new UIntConstant (ec.BuildinTypes, ((UIntConstant) left).Value << lshift_val, left.Location);
+ switch (left.Type.BuiltinType) {
+ case BuiltinTypeSpec.Type.ULong:
+ return new ULongConstant (ec.BuiltinTypes, ((ULongConstant) left).Value << lshift_val, left.Location);
+ case BuiltinTypeSpec.Type.Long:
+ return new LongConstant (ec.BuiltinTypes, ((LongConstant) left).Value << lshift_val, left.Location);
+ case BuiltinTypeSpec.Type.UInt:
+ return new UIntConstant (ec.BuiltinTypes, ((UIntConstant) left).Value << lshift_val, left.Location);
}
// null << value => null
if (left is NullLiteral)
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
- left = left.ConvertImplicitly (ec.BuildinTypes.Int);
- if (left.Type.BuildinType == BuildinTypeSpec.Type.Int)
- return new IntConstant (ec.BuildinTypes, ((IntConstant) left).Value << lshift_val, left.Location);
+ left = left.ConvertImplicitly (ec.BuiltinTypes.Int);
+ if (left.Type.BuiltinType == BuiltinTypeSpec.Type.Int)
+ return new IntConstant (ec.BuiltinTypes, ((IntConstant) left).Value << lshift_val, left.Location);
Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
break;
//
case Binary.Operator.RightShift:
if (left is NullLiteral && right is NullLiteral) {
- var lifted_int = new Nullable.NullableType (ec.BuildinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+ var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+ lifted_int.ResolveAsType (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
}
- IntConstant sic = right.ConvertImplicitly (ec.BuildinTypes.Int) as IntConstant;
+ IntConstant sic = right.ConvertImplicitly (ec.BuiltinTypes.Int) as IntConstant;
if (sic == null){
Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc); ;
return null;
}
int rshift_val = sic.Value;
- switch (left.Type.BuildinType) {
- case BuildinTypeSpec.Type.ULong:
- return new ULongConstant (ec.BuildinTypes, ((ULongConstant) left).Value >> rshift_val, left.Location);
- case BuildinTypeSpec.Type.Long:
- return new LongConstant (ec.BuildinTypes, ((LongConstant) left).Value >> rshift_val, left.Location);
- case BuildinTypeSpec.Type.UInt:
- return new UIntConstant (ec.BuildinTypes, ((UIntConstant) left).Value >> rshift_val, left.Location);
+ switch (left.Type.BuiltinType) {
+ case BuiltinTypeSpec.Type.ULong:
+ return new ULongConstant (ec.BuiltinTypes, ((ULongConstant) left).Value >> rshift_val, left.Location);
+ case BuiltinTypeSpec.Type.Long:
+ return new LongConstant (ec.BuiltinTypes, ((LongConstant) left).Value >> rshift_val, left.Location);
+ case BuiltinTypeSpec.Type.UInt:
+ return new UIntConstant (ec.BuiltinTypes, ((UIntConstant) left).Value >> rshift_val, left.Location);
}
// null >> value => null
if (left is NullLiteral)
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
- left = left.ConvertImplicitly (ec.BuildinTypes.Int);
- if (left.Type.BuildinType == BuildinTypeSpec.Type.Int)
- return new IntConstant (ec.BuildinTypes, ((IntConstant) left).Value >> rshift_val, left.Location);
+ left = left.ConvertImplicitly (ec.BuiltinTypes.Int);
+ if (left.Type.BuiltinType == BuiltinTypeSpec.Type.Int)
+ return new IntConstant (ec.BuiltinTypes, ((IntConstant) left).Value >> rshift_val, left.Location);
Binary.Error_OperatorCannotBeApplied (ec, left, right, oper, loc);
break;
case Binary.Operator.Equality:
- if (TypeManager.IsReferenceType (lt) && TypeManager.IsReferenceType (rt) ||
+ if (TypeSpec.IsReferenceType (lt) && TypeSpec.IsReferenceType (rt) ||
(left is Nullable.LiftedNull && right.IsNull) ||
(right is Nullable.LiftedNull && left.IsNull)) {
if (left.IsNull || right.IsNull) {
return ReducedExpression.Create (
- new BoolConstant (ec.BuildinTypes, left.IsNull == right.IsNull, left.Location),
- new Binary (oper, left, right, loc));
+ new BoolConstant (ec.BuiltinTypes, left.IsNull == right.IsNull, left.Location),
+ new Binary (oper, left, right));
}
if (left is StringConstant && right is StringConstant)
- return new BoolConstant (ec.BuildinTypes,
+ return new BoolConstant (ec.BuiltinTypes,
((StringConstant) left).Value == ((StringConstant) right).Value, left.Location);
return null;
else
return null;
- return new BoolConstant (ec.BuildinTypes, bool_res, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location);
case Binary.Operator.Inequality:
- if (TypeManager.IsReferenceType (lt) && TypeManager.IsReferenceType (rt) ||
+ if (TypeSpec.IsReferenceType (lt) && TypeSpec.IsReferenceType (rt) ||
(left is Nullable.LiftedNull && right.IsNull) ||
(right is Nullable.LiftedNull && left.IsNull)) {
if (left.IsNull || right.IsNull) {
return ReducedExpression.Create (
- new BoolConstant (ec.BuildinTypes, left.IsNull != right.IsNull, left.Location),
- new Binary (oper, left, right, loc));
+ new BoolConstant (ec.BuiltinTypes, left.IsNull != right.IsNull, left.Location),
+ new Binary (oper, left, right));
}
if (left is StringConstant && right is StringConstant)
- return new BoolConstant (ec.BuildinTypes,
+ return new BoolConstant (ec.BuiltinTypes,
((StringConstant) left).Value != ((StringConstant) right).Value, left.Location);
return null;
else
return null;
- return new BoolConstant (ec.BuildinTypes, bool_res, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location);
case Binary.Operator.LessThan:
if (right is NullLiteral) {
if (left is NullLiteral) {
- var lifted_int = new Nullable.NullableType (ec.BuildinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+ var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+ lifted_int.ResolveAsType (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
}
if (left is Nullable.LiftedNull) {
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
}
}
else
return null;
- return new BoolConstant (ec.BuildinTypes, bool_res, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location);
case Binary.Operator.GreaterThan:
if (right is NullLiteral) {
if (left is NullLiteral) {
- var lifted_int = new Nullable.NullableType (ec.BuildinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+ var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+ lifted_int.ResolveAsType (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
}
if (left is Nullable.LiftedNull) {
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
}
}
else
return null;
- return new BoolConstant (ec.BuildinTypes, bool_res, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location);
case Binary.Operator.GreaterThanOrEqual:
if (right is NullLiteral) {
if (left is NullLiteral) {
- var lifted_int = new Nullable.NullableType (ec.BuildinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+ var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+ lifted_int.ResolveAsType (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
}
if (left is Nullable.LiftedNull) {
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
}
}
else
return null;
- return new BoolConstant (ec.BuildinTypes, bool_res, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location);
case Binary.Operator.LessThanOrEqual:
if (right is NullLiteral) {
if (left is NullLiteral) {
- var lifted_int = new Nullable.NullableType (ec.BuildinTypes.Int, loc).ResolveAsTypeTerminal (ec, false);
- return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
+ var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc);
+ lifted_int.ResolveAsType (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right).Resolve (ec);
}
if (left is Nullable.LiftedNull) {
- return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
+ return (Constant) new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
}
}
else
return null;
- return new BoolConstant (ec.BuildinTypes, bool_res, left.Location);
+ return new BoolConstant (ec.BuiltinTypes, bool_res, left.Location);
}
return null;