+ static void Error_NegativeArrayIndex (Location loc)
+ {
+ Report.Error (284, loc, "Can not create array with a negative size");
+ }
+
+ //
+ // Converts `source' to an int, uint, long or ulong.
+ //
+ public Expression ExpressionToArrayArgument (EmitContext ec, Expression source, Location loc)
+ {
+ Expression target;
+
+ bool old_checked = ec.CheckState;
+ ec.CheckState = true;
+
+ target = ConvertImplicit (ec, source, TypeManager.int32_type, loc);
+ if (target == null){
+ target = ConvertImplicit (ec, source, TypeManager.uint32_type, loc);
+ if (target == null){
+ target = ConvertImplicit (ec, source, TypeManager.int64_type, loc);
+ if (target == null){
+ target = ConvertImplicit (ec, source, TypeManager.uint64_type, loc);
+ if (target == null)
+ Expression.Error_CannotConvertImplicit (loc, source.Type, TypeManager.int32_type);
+ }
+ }
+ }
+ ec.CheckState = old_checked;
+
+ //
+ // Only positive constants are allowed at compile time
+ //
+ if (target is Constant){
+ if (target is IntConstant){
+ if (((IntConstant) target).Value < 0){
+ Error_NegativeArrayIndex (loc);
+ return null;
+ }
+ }
+
+ if (target is LongConstant){
+ if (((LongConstant) target).Value < 0){
+ Error_NegativeArrayIndex (loc);
+ return null;
+ }
+ }
+
+ }
+
+ return target;
+ }
+
+ }
+
+ /// <summary>
+ /// This is just a base class for expressions that can
+ /// appear on statements (invocations, object creation,
+ /// assignments, post/pre increment and decrement). The idea
+ /// being that they would support an extra Emition interface that
+ /// does not leave a result on the stack.
+ /// </summary>
+ public abstract class ExpressionStatement : Expression {
+
+ /// <summary>
+ /// Requests the expression to be emitted in a `statement'
+ /// context. This means that no new value is left on the
+ /// stack after invoking this method (constrasted with
+ /// Emit that will always leave a value on the stack).
+ /// </summary>