- foreach (Argument a in ea.Arguments) {
- if (a is NamedArgument)
- ElementAccess.Error_NamedArgument ((NamedArgument) a, ec.Report);
-
- a.Expr = ConvertExpressionToArrayIndex (ec, a.Expr);
- }
-
- eclass = ExprClass.Variable;
-
- return this;
- }
-
- /// <summary>
- /// Emits the right opcode to load an object of Type `t'
- /// from an array of T
- /// </summary>
- void EmitLoadOpcode (ILGenerator ig, Type type, int rank)
- {
- if (rank > 1) {
- MethodInfo get = FetchGetMethod ();
- ig.Emit (OpCodes.Call, get);
- return;
- }
-
- if (type == TypeManager.byte_type || type == TypeManager.bool_type)
- ig.Emit (OpCodes.Ldelem_U1);
- else if (type == TypeManager.sbyte_type)
- ig.Emit (OpCodes.Ldelem_I1);
- else if (type == TypeManager.short_type)
- ig.Emit (OpCodes.Ldelem_I2);
- else if (type == TypeManager.ushort_type || type == TypeManager.char_type)
- ig.Emit (OpCodes.Ldelem_U2);
- else if (type == TypeManager.int32_type)
- ig.Emit (OpCodes.Ldelem_I4);
- else if (type == TypeManager.uint32_type)
- ig.Emit (OpCodes.Ldelem_U4);
- else if (type == TypeManager.uint64_type)
- ig.Emit (OpCodes.Ldelem_I8);
- else if (type == TypeManager.int64_type)
- ig.Emit (OpCodes.Ldelem_I8);
- else if (type == TypeManager.float_type)
- ig.Emit (OpCodes.Ldelem_R4);
- else if (type == TypeManager.double_type)
- ig.Emit (OpCodes.Ldelem_R8);
- else if (type == TypeManager.intptr_type)
- ig.Emit (OpCodes.Ldelem_I);
- else if (TypeManager.IsEnumType (type)){
- EmitLoadOpcode (ig, TypeManager.GetEnumUnderlyingType (type), rank);
- } else if (TypeManager.IsStruct (type)){
- ig.Emit (OpCodes.Ldelema, type);
- ig.Emit (OpCodes.Ldobj, type);
- } else if (type.IsGenericParameter) {
- ig.Emit (OpCodes.Ldelem, type);
- } else if (type.IsPointer)
- ig.Emit (OpCodes.Ldelem_I);
- else
- ig.Emit (OpCodes.Ldelem_Ref);
- }
-
- protected override void Error_NegativeArrayIndex (ResolveContext ec, Location loc)
- {
- ec.Report.Warning (251, 2, loc, "Indexing an array with a negative index (array indices always start at zero)");
- }
-
- /// <summary>
- /// Returns the right opcode to store an object of Type `t'
- /// from an array of T.
- /// </summary>
- static public OpCode GetStoreOpcode (Type t, out bool is_stobj, out bool has_type_arg)
- {
- has_type_arg = false; is_stobj = false;
- t = TypeManager.TypeToCoreType (t);
- if (TypeManager.IsEnumType (t))
- t = TypeManager.GetEnumUnderlyingType (t);
- if (t == TypeManager.byte_type || t == TypeManager.sbyte_type ||
- t == TypeManager.bool_type)
- return OpCodes.Stelem_I1;
- else if (t == TypeManager.short_type || t == TypeManager.ushort_type ||
- t == TypeManager.char_type)
- return OpCodes.Stelem_I2;
- else if (t == TypeManager.int32_type || t == TypeManager.uint32_type)
- return OpCodes.Stelem_I4;
- else if (t == TypeManager.int64_type || t == TypeManager.uint64_type)
- return OpCodes.Stelem_I8;
- else if (t == TypeManager.float_type)
- return OpCodes.Stelem_R4;
- else if (t == TypeManager.double_type)
- return OpCodes.Stelem_R8;
- else if (t == TypeManager.intptr_type) {
- has_type_arg = true;
- is_stobj = true;
- return OpCodes.Stobj;
- } else if (TypeManager.IsStruct (t)) {
- has_type_arg = true;
- is_stobj = true;
- return OpCodes.Stobj;
- } else if (t.IsGenericParameter) {
- has_type_arg = true;
- return OpCodes.Stelem;
- } else if (t.IsPointer)
- return OpCodes.Stelem_I;
- else
- return OpCodes.Stelem_Ref;
- }