public override void Emit (EmitContext ec)
{
if (args != null)
- Invocation.EmitArguments (ec, mi, args);
+ Invocation.EmitArguments (ec, mi, args, false, null);
ec.ig.Emit (OpCodes.Call, mi);
return;
}
- static public Expression MakeSimpleCall (EmitContext ec, MethodGroupExpr mg,
+ static public StaticCallExpr MakeSimpleCall (EmitContext ec, MethodGroupExpr mg,
Expression e, Location loc)
{
ArrayList args;
return null;
args.Add (a);
- method = Invocation.OverloadResolve (ec, (MethodGroupExpr) mg, args, loc);
+ method = Invocation.OverloadResolve (
+ ec, (MethodGroupExpr) mg, args, false, loc);
if (method == null)
return null;
if (TypeManager.TypeToCoreType (type) != TypeManager.void_type)
ec.ig.Emit (OpCodes.Pop);
}
+
+ public MethodInfo Method {
+ get { return mi; }
+ }
}
public class ParenthesizedExpression : Expression
return ResolveOperator (ec);
}
+ public override Expression DoResolveLValue (EmitContext ec, Expression right)
+ {
+ if (Oper == Operator.Indirection)
+ return base.DoResolveLValue (ec, right);
+
+ Error (131, "The left-hand side of an assignment must be a " +
+ "variable, property or indexer");
+ return null;
+ }
+
public override void Emit (EmitContext ec)
{
ILGenerator ig = ec.ig;
public class Indirection : Expression, IMemoryLocation, IAssignMethod {
Expression expr;
LocalTemporary temporary;
- bool have_temporary;
+ bool prepared;
public Indirection (Expression expr, Location l)
{
public override void Emit (EmitContext ec)
{
- ILGenerator ig = ec.ig;
-
- if (temporary != null){
- if (have_temporary) {
- temporary.Emit (ec);
- } else {
- expr.Emit (ec);
- ec.ig.Emit (OpCodes.Dup);
- temporary.Store (ec);
- have_temporary = true;
- }
- } else
+ if (!prepared)
expr.Emit (ec);
- LoadFromPtr (ig, Type);
+ LoadFromPtr (ec.ig, Type);
}
- public void EmitAssign (EmitContext ec, Expression source)
+ public void Emit (EmitContext ec, bool leave_copy)
{
- if (temporary != null){
- if (have_temporary)
- temporary.Emit (ec);
- else {
- expr.Emit (ec);
- ec.ig.Emit (OpCodes.Dup);
- temporary.Store (ec);
- have_temporary = true;
- }
- } else
- expr.Emit (ec);
+ Emit (ec);
+ if (leave_copy) {
+ ec.ig.Emit (OpCodes.Dup);
+ temporary = new LocalTemporary (ec, expr.Type);
+ temporary.Store (ec);
+ }
+ }
+
+ public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
+ {
+ prepared = prepare_for_load;
+
+ expr.Emit (ec);
+ if (prepare_for_load)
+ ec.ig.Emit (OpCodes.Dup);
+
source.Emit (ec);
+ if (leave_copy) {
+ ec.ig.Emit (OpCodes.Dup);
+ temporary = new LocalTemporary (ec, expr.Type);
+ temporary.Store (ec);
+ }
+
StoreFromPtr (ec.ig, type);
+
+ if (temporary != null)
+ temporary.Emit (ec);
}
public void AddressOf (EmitContext ec, AddressOp Mode)
{
- if (temporary != null){
- if (have_temporary){
- temporary.Emit (ec);
- return;
- }
- expr.Emit (ec);
- ec.ig.Emit (OpCodes.Dup);
- temporary.Store (ec);
- have_temporary = true;
- } else
- expr.Emit (ec);
+ expr.Emit (ec);
}
public override Expression DoResolve (EmitContext ec)
//
return this;
}
-
- public new void CacheTemporaries (EmitContext ec)
- {
- temporary = new LocalTemporary (ec, expr.Type);
- }
-
+
public override string ToString ()
{
return "*(" + expr + ")";
}
Mode mode;
+ bool is_expr = false;
+ bool recurse = false;
+
Expression expr;
- LocalTemporary temp_storage;
//
// This is expensive for the simplest case.
//
- Expression method;
+ StaticCallExpr method;
public UnaryMutator (Mode m, Expression e, Location l)
{
} else if (expr.eclass == ExprClass.IndexerAccess){
IndexerAccess ia = (IndexerAccess) expr;
- temp_storage = new LocalTemporary (ec, expr.Type);
-
- expr = ia.ResolveLValue (ec, temp_storage);
+ expr = ia.ResolveLValue (ec, this);
if (expr == null)
return null;
}
}
-
- static EmptyExpression empty_expr;
void EmitCode (EmitContext ec, bool is_expr)
{
- ILGenerator ig = ec.ig;
- IAssignMethod ia = (IAssignMethod) expr;
- Type expr_type = expr.Type;
-
- ia.CacheTemporaries (ec);
+ recurse = true;
+ this.is_expr = is_expr;
+ ((IAssignMethod) expr).EmitAssign (ec, this, is_expr && (mode == Mode.PreIncrement || mode == Mode.PreDecrement), true);
+ }
+
+ public override void Emit (EmitContext ec)
+ {
//
- // NOTE: We should probably handle three cases:
- //
- // * method invocation required.
- // * direct stack manipulation possible
- // * the object requires an "instance" field
+ // We use recurse to allow ourselfs to be the source
+ // of an assignment. This little hack prevents us from
+ // having to allocate another expression
//
- if (temp_storage == null){
- //
- // Temporary improvement: if we are dealing with something that does
- // not require complicated instance setup, avoid using a temporary
- //
- // For now: only localvariables when not remapped
- //
-
- if (method == null &&
- ((expr is LocalVariableReference) ||(expr is FieldExpr && ((FieldExpr) expr).FieldInfo.IsStatic))){
- if (empty_expr == null)
- empty_expr = new EmptyExpression ();
-
- switch (mode){
- case Mode.PreIncrement:
- case Mode.PreDecrement:
- expr.Emit (ec);
-
- LoadOneAndEmitOp (ec, expr_type);
- if (is_expr)
- ig.Emit (OpCodes.Dup);
- ia.EmitAssign (ec, empty_expr);
- break;
-
- case Mode.PostIncrement:
- case Mode.PostDecrement:
- expr.Emit (ec);
- if (is_expr)
- ig.Emit (OpCodes.Dup);
-
- LoadOneAndEmitOp (ec, expr_type);
- ia.EmitAssign (ec, empty_expr);
- break;
- }
- return;
- }
- temp_storage = new LocalTemporary (ec, expr_type);
+ if (recurse) {
+ ((IAssignMethod) expr).Emit (ec, is_expr && (mode == Mode.PostIncrement || mode == Mode.PostDecrement));
+ if (method == null)
+ LoadOneAndEmitOp (ec, expr.Type);
+ else
+ ec.ig.Emit (OpCodes.Call, method.Method);
+ recurse = false;
+ return;
}
- switch (mode){
- case Mode.PreIncrement:
- case Mode.PreDecrement:
- if (method == null){
- expr.Emit (ec);
-
- LoadOneAndEmitOp (ec, expr_type);
- } else
- method.Emit (ec);
-
- temp_storage.Store (ec);
- ia.EmitAssign (ec, temp_storage);
- if (is_expr)
- temp_storage.Emit (ec);
- break;
-
- case Mode.PostIncrement:
- case Mode.PostDecrement:
- if (is_expr)
- expr.Emit (ec);
-
- if (method == null){
- if (!is_expr)
- expr.Emit (ec);
- else
- ig.Emit (OpCodes.Dup);
-
- LoadOneAndEmitOp (ec, expr_type);
- } else {
- method.Emit (ec);
- }
-
- temp_storage.Store (ec);
- ia.EmitAssign (ec, temp_storage);
- break;
- }
-
- temp_storage.Release (ec);
- }
-
- public override void Emit (EmitContext ec)
- {
EmitCode (ec, true);
-
}
public override void EmitStatement (EmitContext ec)
{
EmitCode (ec, false);
}
-
}
/// <summary>
if (probe_type == null)
return null;
+ CheckObsoleteAttribute (probe_type);
+
expr = expr.Resolve (ec);
if (expr == null)
return null;
warning_never_matches = true;
}
- if (RootContext.WarningLevel >= 1){
- if (warning_always_matches)
- Warning (183, "The expression is always of type `" +
- TypeManager.CSharpName (probe_type) + "'");
- else if (warning_never_matches){
- if (!(probe_type.IsInterface || expr.Type.IsInterface))
- Warning (184,
- "The expression is never of type `" +
- TypeManager.CSharpName (probe_type) + "'");
- }
+ if (warning_always_matches)
+ Warning (183, "The given expression is always of the provided ('{0}') type", TypeManager.CSharpName (probe_type));
+ else if (warning_never_matches){
+ if (!(probe_type.IsInterface || expr.Type.IsInterface))
+ Warning (184, "The given expression is never of the provided ('{0}') type", TypeManager.CSharpName (probe_type));
}
return this;
if (type == null)
return null;
+ CheckObsoleteAttribute (type);
+
+ if (type.IsAbstract && type.IsSealed) {
+ Report.Error (716, loc, "Cannot convert to static type '{0}'", TypeManager.CSharpName (type));
+ return null;
+ }
+
eclass = ExprClass.Value;
if (expr is Constant){
return e;
}
+ if (type.IsPointer && !ec.InUnsafe) {
+ UnsafeError (loc);
+ return null;
+ }
expr = Convert.ExplicitConversion (ec, expr, type, loc);
return expr;
}
} else if (right is LongConstant){
long ll = ((LongConstant) right).Value;
- if (ll > 0)
+ if (ll >= 0)
right = new ULongConstant ((ulong) ll);
} else {
e = Convert.ImplicitNumericConversion (ec, right, l, loc);
(other == TypeManager.int32_type) ||
(other == TypeManager.int64_type))
Error_OperatorAmbiguous (loc, oper, l, r);
+ else {
+ left = ForceConversion (ec, left, TypeManager.uint64_type);
+ right = ForceConversion (ec, right, TypeManager.uint64_type);
+ }
type = TypeManager.uint64_type;
} else if (IsOfType (ec, l, r, TypeManager.int64_type, check_user_conv)){
//
Type l = left.Type;
Type r = right.Type;
- bool overload_failed = false;
-
//
// Special cases: string comapred to null
//
return this;
}
+
+ // IntPtr equality
+ if (l == TypeManager.intptr_type && r == TypeManager.intptr_type) {
+ Type = TypeManager.bool_type;
+
+ return this;
+ }
}
//
args.Add (new Argument (left, Argument.AType.Expression));
args.Add (new Argument (right, Argument.AType.Expression));
- MethodBase method = Invocation.OverloadResolve (ec, union, args, Location.Null);
+ MethodBase method = Invocation.OverloadResolve (
+ ec, union, args, true, Location.Null);
+
if (method != null) {
MethodInfo mi = (MethodInfo) method;
return new BinaryMethod (mi.ReturnType, method, args);
- } else {
- overload_failed = true;
}
}
}
//
if (oper == Operator.Addition || oper == Operator.Subtraction) {
if (l.IsSubclassOf (TypeManager.delegate_type)){
- if (right.eclass == ExprClass.MethodGroup && RootContext.V2){
+ if ((right.eclass == ExprClass.MethodGroup) &&
+ (RootContext.Version != LanguageVersion.ISO_1)){
Expression tmp = Convert.ImplicitConversionRequired (ec, right, l, loc);
if (tmp == null)
return null;
if (r == l)
return new PointerArithmetic (
false, left, right, TypeManager.int64_type,
- loc);
+ loc).Resolve (ec);
} else {
Expression t = Make32or64 (ec, right);
if (t != null)
- return new PointerArithmetic (oper == Operator.Addition, left, t, l, loc);
+ return new PointerArithmetic (oper == Operator.Addition, left, t, l, loc).Resolve (ec);
}
} else if (r.IsPointer && oper == Operator.Addition){
Expression t = Make32or64 (ec, left);
if (t != null)
- return new PointerArithmetic (true, right, t, r, loc);
+ return new PointerArithmetic (true, right, t, r, loc).Resolve (ec);
}
}
}
}
- //
- // We are dealing with numbers
- //
- if (overload_failed){
- Error_OperatorCannotBeApplied ();
- return null;
- }
-
//
// This will leave left or right set to null if there is an error
//
oper == Operator.BitwiseOr ||
oper == Operator.ExclusiveOr){
if (l == r){
- if (!((l == TypeManager.int32_type) ||
- (l == TypeManager.uint32_type) ||
- (l == TypeManager.short_type) ||
- (l == TypeManager.ushort_type) ||
- (l == TypeManager.int64_type) ||
- (l == TypeManager.uint64_type))){
+ if (((l == TypeManager.int32_type) ||
+ (l == TypeManager.uint32_type) ||
+ (l == TypeManager.short_type) ||
+ (l == TypeManager.ushort_type) ||
+ (l == TypeManager.int64_type) ||
+ (l == TypeManager.uint64_type))){
type = l;
+ } else {
+ Error_OperatorCannotBeApplied ();
+ return null;
}
} else {
Error_OperatorCannotBeApplied ();
ig.MarkLabel (end);
return;
}
-
+
left.Emit (ec);
right.Emit (ec);
ILGenerator ig = ec.ig;
if (Arguments != null)
- Invocation.EmitArguments (ec, method, Arguments);
+ Invocation.EmitArguments (ec, method, Arguments, false, null);
if (method is MethodInfo)
ig.Emit (OpCodes.Call, (MethodInfo) method);
break;
}
- Invocation.EmitArguments (ec, concat_method, operands);
+ Invocation.EmitArguments (ec, concat_method, operands, false, null);
ec.ig.Emit (OpCodes.Call, concat_method);
}
}
{
ILGenerator ig = ec.ig;
- Invocation.EmitArguments (ec, method, args);
+ Invocation.EmitArguments (ec, method, args, false, null);
ig.Emit (OpCodes.Call, (MethodInfo) method);
ig.Emit (OpCodes.Castclass, type);
}
Expression op_true, op_false, op;
+ LocalTemporary left_temp;
public override Expression DoResolve (EmitContext ec)
{
return null;
}
+ left_temp = new LocalTemporary (ec, type);
+
ArrayList arguments = new ArrayList ();
- arguments.Add (new Argument (left, Argument.AType.Expression));
+ arguments.Add (new Argument (left_temp, Argument.AType.Expression));
arguments.Add (new Argument (right, Argument.AType.Expression));
- method = Invocation.OverloadResolve (ec, (MethodGroupExpr) operator_group, arguments, loc) as MethodInfo;
+ method = Invocation.OverloadResolve (
+ ec, (MethodGroupExpr) operator_group, arguments, false, loc)
+ as MethodInfo;
if ((method == null) || (method.ReturnType != type)) {
Error19 ();
return null;
op = new StaticCallExpr (method, arguments, loc);
- op_true = GetOperatorTrue (ec, left, loc);
- op_false = GetOperatorFalse (ec, left, loc);
+ op_true = GetOperatorTrue (ec, left_temp, loc);
+ op_false = GetOperatorFalse (ec, left_temp, loc);
if ((op_true == null) || (op_false == null)) {
Error218 ();
return null;
ig.Emit (OpCodes.Nop);
- (is_and ? op_false : op_true).EmitBranchable (ec, false_target, false);
left.Emit (ec);
+ left_temp.Store (ec);
+
+ (is_and ? op_false : op_true).EmitBranchable (ec, false_target, false);
+ left_temp.Emit (ec);
ig.Emit (OpCodes.Br, end_target);
ig.MarkLabel (false_target);
op.Emit (ec);
public PointerArithmetic (bool is_addition, Expression l, Expression r, Type t, Location loc)
{
type = t;
- eclass = ExprClass.Variable;
this.loc = loc;
left = l;
right = r;
public override Expression DoResolve (EmitContext ec)
{
- //
- // We are born fully resolved
- //
+ eclass = ExprClass.Variable;
+
+ if (left.Type == TypeManager.void_ptr_type) {
+ Error (242, "The operation in question is undefined on void pointers");
+ return null;
+ }
+
return this;
}
{
Type op_type = left.Type;
ILGenerator ig = ec.ig;
- int size = GetTypeSize (TypeManager.GetElementType (op_type));
+ Type element = TypeManager.GetElementType (op_type);
+ int size = GetTypeSize (element);
Type rtype = right.Type;
if (rtype.IsPointer){
if (size != 1){
if (size == 0)
- ig.Emit (OpCodes.Sizeof, op_type);
+ ig.Emit (OpCodes.Sizeof, element);
else
IntLiteral.EmitInt (ig, size);
ig.Emit (OpCodes.Div);
right.Emit (ec);
if (size != 1){
if (size == 0)
- ig.Emit (OpCodes.Sizeof, op_type);
+ ig.Emit (OpCodes.Sizeof, element);
else
IntLiteral.EmitInt (ig, size);
if (rtype == TypeManager.int64_type)
if (e != null) {
local_info.Used = true;
eclass = ExprClass.Value;
- return e;
+ return e.Resolve (ec);
}
VariableInfo variable_info = local_info.VariableInfo;
return null;
}
+ CheckObsoleteAttribute (e.Type);
+
if (local_info.LocalBuilder == null)
return ec.RemapLocalLValue (local_info, right_side);
ig.Emit (OpCodes.Ldloc, local_info.LocalBuilder);
}
- public void EmitAssign (EmitContext ec, Expression source)
+ public void Emit (EmitContext ec, bool leave_copy)
+ {
+ Emit (ec);
+ if (leave_copy)
+ ec.ig.Emit (OpCodes.Dup);
+ }
+
+ public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
{
- ILGenerator ig = ec.ig;
-
source.Emit (ec);
- ig.Emit (OpCodes.Stloc, local_info.LocalBuilder);
+ if (leave_copy)
+ ec.ig.Emit (OpCodes.Dup);
+ ec.ig.Emit (OpCodes.Stloc, local_info.LocalBuilder);
}
public void AddressOf (EmitContext ec, AddressOp mode)
Block block;
VariableInfo vi;
public Parameter.Modifier mod;
- public bool is_ref, is_out;
+ public bool is_ref, is_out, prepared;
+ LocalTemporary temp;
public ParameterReference (Parameters pars, Block block, int idx, string name, Location loc)
{
}
public override void Emit (EmitContext ec)
+ {
+ Emit (ec, false);
+ }
+
+ public void Emit (EmitContext ec, bool leave_copy)
{
ILGenerator ig = ec.ig;
EmitLdArg (ig, arg_idx);
- if (!is_ref)
- return;
-
- //
- // If we are a reference, we loaded on the stack a pointer
- // Now lets load the real value
- //
- LoadFromPtr (ig, type);
+ if (is_ref) {
+ if (prepared)
+ ec.ig.Emit (OpCodes.Dup);
+
+ //
+ // If we are a reference, we loaded on the stack a pointer
+ // Now lets load the real value
+ //
+ LoadFromPtr (ig, type);
+ }
+
+ if (leave_copy) {
+ ec.ig.Emit (OpCodes.Dup);
+
+ if (is_ref) {
+ temp = new LocalTemporary (ec, type);
+ temp.Store (ec);
+ }
+ }
}
-
- public void EmitAssign (EmitContext ec, Expression source)
+
+ public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
{
ILGenerator ig = ec.ig;
-
int arg_idx = idx;
-
+
+ prepared = prepare_for_load;
+
if (!ec.IsStatic)
arg_idx++;
- if (is_ref)
+ if (is_ref && !prepared)
EmitLdArg (ig, arg_idx);
source.Emit (ec);
- if (is_ref)
+ if (leave_copy)
+ ec.ig.Emit (OpCodes.Dup);
+
+ if (is_ref) {
+ if (leave_copy) {
+ temp = new LocalTemporary (ec, type);
+ temp.Store (ec);
+ }
+
StoreFromPtr (ig, type);
- else {
+
+ if (temp != null)
+ temp.Emit (ec);
+ } else {
if (arg_idx <= 255)
ig.Emit (OpCodes.Starg_S, (byte) arg_idx);
else
public enum AType : byte {
Expression,
Ref,
- Out
+ Out,
+ ArgList
};
public readonly AType ArgType;
this.ArgType = type;
}
+ public Argument (Expression expr)
+ {
+ this.Expr = expr;
+ this.ArgType = AType.Expression;
+ }
+
public Type Type {
get {
if (ArgType == AType.Ref || ArgType == AType.Out)
public static string FullDesc (Argument a)
{
+ if (a.ArgType == AType.ArgList)
+ return "__arglist";
+
return (a.ArgType == AType.Ref ? "ref " :
(a.ArgType == AType.Out ? "out " : "")) +
TypeManager.CSharpName (a.Expr.Type);
return (ParameterData) ip;
} else {
- ParameterInfo [] pi = mb.GetParameters ();
- ReflectionParameters rp = new ReflectionParameters (pi);
+ ReflectionParameters rp = new ReflectionParameters (mb);
method_parameter_cache [mb] = rp;
return (ParameterData) rp;
throw new Exception ("Expression of type " + a.Expr +
" does not resolve its type");
+ if (p == null || q == null)
+ throw new InternalErrorException ("BetterConversion Got a null conversion");
+
//
// This is a special case since csc behaves this way.
//
// I can't find this anywhere in the spec but we can interpret this
// to mean that null can be of any type you wish in such a context
//
- if (p != null && q != null) {
- if (argument_expr is NullLiteral &&
- !p.IsValueType &&
- q == TypeManager.object_type)
- return 1;
- else if (argument_expr is NullLiteral &&
- !q.IsValueType &&
- p == TypeManager.object_type)
- return 0;
- }
+ if (argument_expr is NullLiteral &&
+ !p.IsValueType &&
+ q == TypeManager.object_type)
+ return 1;
+ else if (argument_expr is NullLiteral &&
+ !q.IsValueType &&
+ p == TypeManager.object_type)
+ return 0;
+
if (p == q)
return 0;
if (argument_type == q)
return 0;
- //
- // Now probe whether an implicit constant expression conversion
- // can be used.
- //
- // An implicit constant expression conversion permits the following
- // conversions:
- //
- // * A constant-expression of type `int' can be converted to type
- // sbyte, byute, short, ushort, uint, ulong provided the value of
- // of the expression is withing the range of the destination type.
- //
- // * A constant-expression of type long can be converted to type
- // ulong, provided the value of the constant expression is not negative
- //
- // FIXME: Note that this assumes that constant folding has
- // taken place. We dont do constant folding yet.
- //
-
- if (argument_expr is IntConstant){
- IntConstant ei = (IntConstant) argument_expr;
- int value = ei.Value;
-
- if (p == TypeManager.sbyte_type){
- if (value >= SByte.MinValue && value <= SByte.MaxValue)
- return 1;
- } else if (p == TypeManager.byte_type){
- if (q == TypeManager.sbyte_type &&
- value >= SByte.MinValue && value <= SByte.MaxValue)
- return 0;
- else if (Byte.MinValue >= 0 && value <= Byte.MaxValue)
- return 1;
- } else if (p == TypeManager.short_type){
- if (value >= Int16.MinValue && value <= Int16.MaxValue)
- return 1;
- } else if (p == TypeManager.ushort_type){
- if (q == TypeManager.short_type &&
- value >= Int16.MinValue && value <= Int16.MaxValue)
- return 0;
- else if (value >= UInt16.MinValue && value <= UInt16.MaxValue)
- return 1;
- } else if (p == TypeManager.int32_type){
- if (value >= Int32.MinValue && value <= Int32.MaxValue)
- return 1;
- } else if (p == TypeManager.uint32_type){
- //
- // we can optimize this case: a positive int32
- // always fits on a uint32
- //
- if (value >= 0)
- return 1;
- } else if (p == TypeManager.uint64_type){
- //
- // we can optimize this case: a positive int32
- // always fits on a uint64
- //
-
- //
- // This special case is needed because csc behaves like this.
- // int -> uint is better than int -> ulong!
- //
- if (q == TypeManager.uint32_type)
- return 0;
-
- if (q == TypeManager.int64_type)
- return 0;
- else if (value >= 0)
- return 1;
- } else if (p == TypeManager.int64_type){
- return 1;
- }
- } else if (argument_type == TypeManager.int64_type && argument_expr is LongConstant){
- LongConstant lc = (LongConstant) argument_expr;
-
- if (p == TypeManager.uint64_type){
- if (lc.Value > 0)
- return 1;
- }
- }
-
- if (q == null) {
- Expression tmp = Convert.ImplicitConversion (ec, argument_expr, p, loc);
-
- if (tmp != null)
- return 1;
- else
- return 0;
- }
-
Expression p_tmp = new EmptyExpression (p);
Expression q_tmp = new EmptyExpression (q);
/// 0 if candidate ain't better
/// 1 if candidate is better than the current best match
/// </remarks>
- static int BetterFunction (EmitContext ec, ArrayList args,
+ static int BetterFunction (EmitContext ec, ArrayList args, int argument_count,
MethodBase candidate, bool candidate_params,
- MethodBase best, bool best_params,
- Location loc)
+ MethodBase best, bool best_params, Location loc)
{
ParameterData candidate_pd = GetParameterData (candidate);
- ParameterData best_pd;
- int argument_count;
+ ParameterData best_pd = GetParameterData (best);
- if (args == null)
- argument_count = 0;
- else
- argument_count = args.Count;
-
int cand_count = candidate_pd.Count;
//
// Trim (); is better than Trim (params char[] chars);
//
if (cand_count == 0 && argument_count == 0)
- return best == null || best_params ? 1 : 0;
+ return best_params ? 1 : 0;
- if (candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.PARAMS)
+ if ((candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.PARAMS) &&
+ (candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.ARGLIST))
if (cand_count != argument_count)
return 0;
- if (best == null) {
- int x = 0;
-
- if (argument_count == 0 && cand_count == 1 &&
- candidate_pd.ParameterModifier (cand_count - 1) == Parameter.Modifier.PARAMS)
- return 1;
-
- for (int j = 0; j < argument_count; ++j) {
-
- Argument a = (Argument) args [j];
- Type t = candidate_pd.ParameterType (j);
-
- if (candidate_pd.ParameterModifier (j) == Parameter.Modifier.PARAMS)
- if (candidate_params)
- t = TypeManager.GetElementType (t);
-
- x = BetterConversion (ec, a, t, null, loc);
-
- if (x <= 0)
- break;
- }
-
- if (x > 0)
- return 1;
- else
- return 0;
- }
-
- best_pd = GetParameterData (best);
int rating1 = 0, rating2 = 0;
return union;
}
+ static bool IsParamsMethodApplicable (EmitContext ec, MethodGroupExpr me,
+ ArrayList arguments, int arg_count,
+ ref MethodBase candidate)
+ {
+ return IsParamsMethodApplicable (
+ ec, me, arguments, arg_count, false, ref candidate) ||
+ IsParamsMethodApplicable (
+ ec, me, arguments, arg_count, true, ref candidate);
+
+
+ }
+
+ static bool IsParamsMethodApplicable (EmitContext ec, MethodGroupExpr me,
+ ArrayList arguments, int arg_count,
+ bool do_varargs, ref MethodBase candidate)
+ {
+ return IsParamsMethodApplicable (
+ ec, arguments, arg_count, candidate, do_varargs);
+ }
+
/// <summary>
/// Determines if the candidate method, if a params method, is applicable
/// in its expanded form to the given set of arguments
/// </summary>
- static bool IsParamsMethodApplicable (EmitContext ec, ArrayList arguments, MethodBase candidate)
+ static bool IsParamsMethodApplicable (EmitContext ec, ArrayList arguments,
+ int arg_count, MethodBase candidate,
+ bool do_varargs)
{
- int arg_count;
-
- if (arguments == null)
- arg_count = 0;
- else
- arg_count = arguments.Count;
-
ParameterData pd = GetParameterData (candidate);
-
- int pd_count = pd.Count;
+ int pd_count = pd.Count;
if (pd_count == 0)
return false;
+
+ int count = pd_count - 1;
+ if (do_varargs) {
+ if (pd.ParameterModifier (count) != Parameter.Modifier.ARGLIST)
+ return false;
+ if (pd_count != arg_count)
+ return false;
+ } else {
+ if (pd.ParameterModifier (count) != Parameter.Modifier.PARAMS)
+ return false;
+ }
- if (pd.ParameterModifier (pd_count - 1) != Parameter.Modifier.PARAMS)
- return false;
-
- if (pd_count - 1 > arg_count)
+ if (count > arg_count)
return false;
if (pd_count == 1 && arg_count == 0)
// remains is when the number of parameters is
// less than or equal to the argument count.
//
- for (int i = 0; i < pd_count - 1; ++i) {
+ for (int i = 0; i < count; ++i) {
Argument a = (Argument) arguments [i];
}
- Type element_type = TypeManager.GetElementType (pd.ParameterType (pd_count - 1));
+ if (do_varargs) {
+ Argument a = (Argument) arguments [count];
+ if (!(a.Expr is Arglist))
+ return false;
- for (int i = pd_count - 1; i < arg_count; i++) {
+ return true;
+ }
+
+ Type element_type = TypeManager.GetElementType (pd.ParameterType (pd_count - 1));
+
+ for (int i = pd_count - 1; i < arg_count; i++) {
Argument a = (Argument) arguments [i];
-
+
if (!Convert.ImplicitConversionExists (ec, a.Expr, element_type))
return false;
}
return true;
}
+ static bool IsApplicable (EmitContext ec, MethodGroupExpr me,
+ ArrayList arguments, int arg_count,
+ ref MethodBase candidate)
+ {
+ return IsApplicable (ec, arguments, arg_count, candidate);
+ }
+
/// <summary>
/// Determines if the candidate method is applicable (section 14.4.2.1)
/// to the given set of arguments
/// </summary>
- static bool IsApplicable (EmitContext ec, ArrayList arguments, MethodBase candidate)
+ static bool IsApplicable (EmitContext ec, ArrayList arguments, int arg_count,
+ MethodBase candidate)
{
- int arg_count;
-
- if (arguments == null)
- arg_count = 0;
- else
- arg_count = arguments.Count;
-
-
ParameterData pd = GetParameterData (candidate);
if (arg_count != pd.Count)
return true;
}
+
+ static private bool IsAncestralType (Type first_type, Type second_type)
+ {
+ return first_type != second_type &&
+ (second_type.IsSubclassOf (first_type) ||
+ TypeManager.ImplementsInterface (second_type, first_type));
+ }
/// <summary>
/// Find the Applicable Function Members (7.4.2.1)
///
/// </summary>
public static MethodBase OverloadResolve (EmitContext ec, MethodGroupExpr me,
- ArrayList Arguments, Location loc)
+ ArrayList Arguments, bool may_fail,
+ Location loc)
{
MethodBase method = null;
+ bool method_params = false;
Type applicable_type = null;
- int argument_count;
+ int arg_count = 0;
ArrayList candidates = new ArrayList ();
//
//
// false is normal form, true is expanded form
//
- Hashtable candidate_to_form = new PtrHashtable ();
+ Hashtable candidate_to_form = null;
+ if (Arguments != null)
+ arg_count = Arguments.Count;
- //
- // First we construct the set of applicable methods
- //
- // We start at the top of the type hierarchy and
- // go down to find applicable methods
- //
- applicable_type = me.DeclaringType;
-
- if (me.Name == "Invoke" && TypeManager.IsDelegateType (applicable_type)) {
+ if ((me.Name == "Invoke") &&
+ TypeManager.IsDelegateType (me.DeclaringType)) {
Error_InvokeOnDelegate (loc);
return null;
}
- bool found_applicable = false;
+ MethodBase[] methods = me.Methods;
- foreach (MethodBase candidate in me.Methods){
- Type decl_type = candidate.DeclaringType;
+ //
+ // First we construct the set of applicable methods
+ //
+ bool is_sorted = true;
+ for (int i = 0; i < methods.Length; i++){
+ Type decl_type = methods [i].DeclaringType;
//
// If we have already found an applicable method
// we eliminate all base types (Section 14.5.5.1)
//
- if (decl_type != applicable_type &&
- (applicable_type.IsSubclassOf (decl_type) ||
- TypeManager.ImplementsInterface (applicable_type, decl_type)) &&
- found_applicable)
- continue;
-
+ if ((applicable_type != null) &&
+ IsAncestralType (decl_type, applicable_type))
+ continue;
+ //
// Check if candidate is applicable (section 14.4.2.1)
- if (IsApplicable (ec, Arguments, candidate)) {
- // Candidate is applicable in normal form
- candidates.Add (candidate);
- applicable_type = candidate.DeclaringType;
- found_applicable = true;
- candidate_to_form [candidate] = false;
- } else if (IsParamsMethodApplicable (ec, Arguments, candidate)) {
- // Candidate is applicable in expanded form
- candidates.Add (candidate);
- applicable_type = candidate.DeclaringType;
- found_applicable = true;
- candidate_to_form [candidate] = true;
- }
- }
-
+ // Is candidate applicable in normal form?
+ //
+ bool is_applicable = IsApplicable (
+ ec, me, Arguments, arg_count, ref methods [i]);
- //
- // Now we actually find the best method
- //
- int candidate_top = candidates.Count;
- for (int ix = 0; ix < candidate_top; ix++){
- MethodBase candidate = (MethodBase) candidates [ix];
+ if (!is_applicable &&
+ (IsParamsMethodApplicable (
+ ec, me, Arguments, arg_count, ref methods [i]))) {
+ MethodBase candidate = methods [i];
+ if (candidate_to_form == null)
+ candidate_to_form = new PtrHashtable ();
+ candidate_to_form [candidate] = candidate;
+ // Candidate is applicable in expanded form
+ is_applicable = true;
+ }
- bool cand_params = (bool) candidate_to_form [candidate];
- bool method_params = false;
+ if (!is_applicable)
+ continue;
- if (method != null)
- method_params = (bool) candidate_to_form [method];
-
- int x = BetterFunction (ec, Arguments,
- candidate, cand_params,
- method, method_params,
- loc);
-
- if (x == 0)
- continue;
-
- method = candidate;
- }
+ candidates.Add (methods [i]);
- if (Arguments == null)
- argument_count = 0;
- else
- argument_count = Arguments.Count;
-
+ if (applicable_type == null)
+ applicable_type = decl_type;
+ else if (applicable_type != decl_type) {
+ is_sorted = false;
+ if (IsAncestralType (applicable_type, decl_type))
+ applicable_type = decl_type;
+ }
+ }
+
+ int candidate_top = candidates.Count;
- if (method == null) {
+ if (candidate_top == 0) {
//
// Okay so we have failed to find anything so we
// return by providing info about the closest match
//
- for (int i = 0; i < me.Methods.Length; ++i) {
-
- MethodBase c = (MethodBase) me.Methods [i];
+ for (int i = 0; i < methods.Length; ++i) {
+ MethodBase c = (MethodBase) methods [i];
ParameterData pd = GetParameterData (c);
- if (pd.Count != argument_count)
+ if (pd.Count != arg_count)
continue;
- VerifyArgumentsCompat (ec, Arguments, argument_count, c, false,
- null, loc);
- break;
+ VerifyArgumentsCompat (ec, Arguments, arg_count,
+ c, false, null, may_fail, loc);
+ break;
}
- if (!Location.IsNull (loc)) {
+ if (!may_fail) {
string report_name = me.Name;
if (report_name == ".ctor")
report_name = me.DeclaringType.ToString ();
- Error_WrongNumArguments (loc, report_name, argument_count);
+ Error_WrongNumArguments (
+ loc, report_name, arg_count);
+ return null;
}
return null;
}
+ if (!is_sorted) {
+ //
+ // At this point, applicable_type is _one_ of the most derived types
+ // in the set of types containing the methods in this MethodGroup.
+ // Filter the candidates so that they only contain methods from the
+ // most derived types.
+ //
+
+ int finalized = 0; // Number of finalized candidates
+
+ do {
+ // Invariant: applicable_type is a most derived type
+
+ // We'll try to complete Section 14.5.5.1 for 'applicable_type' by
+ // eliminating all it's base types. At the same time, we'll also move
+ // every unrelated type to the end of the array, and pick the next
+ // 'applicable_type'.
+
+ Type next_applicable_type = null;
+ int j = finalized; // where to put the next finalized candidate
+ int k = finalized; // where to put the next undiscarded candidate
+ for (int i = finalized; i < candidate_top; ++i) {
+ Type decl_type = ((MethodBase) candidates[i]).DeclaringType;
+
+ if (decl_type == applicable_type) {
+ candidates[k++] = candidates[j];
+ candidates[j++] = candidates[i];
+ continue;
+ }
+
+ if (IsAncestralType (decl_type, applicable_type))
+ continue;
+
+ if (next_applicable_type != null &&
+ IsAncestralType (decl_type, next_applicable_type))
+ continue;
+
+ candidates[k++] = candidates[i];
+
+ if (next_applicable_type == null ||
+ IsAncestralType (next_applicable_type, decl_type))
+ next_applicable_type = decl_type;
+ }
+
+ applicable_type = next_applicable_type;
+ finalized = j;
+ candidate_top = k;
+ } while (applicable_type != null);
+ }
+
+ //
+ // Now we actually find the best method
+ //
+
+ method = (MethodBase) candidates[0];
+ method_params = candidate_to_form != null && candidate_to_form.Contains (method);
+ for (int ix = 1; ix < candidate_top; ix++){
+ MethodBase candidate = (MethodBase) candidates [ix];
+ bool cand_params = candidate_to_form != null && candidate_to_form.Contains (candidate);
+
+ if (BetterFunction (ec, Arguments, arg_count,
+ candidate, cand_params,
+ method, method_params, loc) != 0) {
+ method = candidate;
+ method_params = cand_params;
+ }
+ }
+
//
// Now check that there are no ambiguities i.e the selected method
// should be better than all the others
//
- bool best_params = (bool) candidate_to_form [method];
-
+ bool ambiguous = false;
for (int ix = 0; ix < candidate_top; ix++){
MethodBase candidate = (MethodBase) candidates [ix];
if (candidate == method)
continue;
-
- //
- // If a normal method is applicable in
- // the sense that it has the same
- // number of arguments, then the
- // expanded params method is never
- // applicable so we debar the params
- // method.
- //
- // if ((IsParamsMethodApplicable (ec, Arguments, candidate) &&
-// IsApplicable (ec, Arguments, method)))
-// continue;
-
- bool cand_params = (bool) candidate_to_form [candidate];
- int x = BetterFunction (ec, Arguments,
- method, best_params,
- candidate, cand_params,
- loc);
-
- if (x != 1) {
- Report.Error (
- 121, loc,
- "Ambiguous call when selecting function due to implicit casts");
- return null;
- }
+
+ bool cand_params = candidate_to_form != null && candidate_to_form.Contains (candidate);
+ if (BetterFunction (ec, Arguments, arg_count,
+ method, method_params,
+ candidate, cand_params,
+ loc) != 1) {
+ Report.SymbolRelatedToPreviousError (candidate);
+ ambiguous = true;
+ }
+ }
+
+ if (ambiguous) {
+ Report.SymbolRelatedToPreviousError (method);
+ Report.Error (121, loc, "Ambiguous call when selecting function due to implicit casts");
+ return null;
}
+
//
// And now check if the arguments are all
// compatible, perform conversions if
// necessary etc. and return if everything is
// all right
//
- if (!VerifyArgumentsCompat (ec, Arguments, argument_count, method,
- best_params, null, loc))
+ if (!VerifyArgumentsCompat (ec, Arguments, arg_count, method,
+ method_params, null, may_fail, loc))
return null;
return method;
}
public static bool VerifyArgumentsCompat (EmitContext ec, ArrayList Arguments,
- int argument_count,
- MethodBase method,
+ int arg_count, MethodBase method,
bool chose_params_expanded,
- Type delegate_type,
+ Type delegate_type, bool may_fail,
Location loc)
{
ParameterData pd = GetParameterData (method);
int pd_count = pd.Count;
-
- for (int j = 0; j < argument_count; j++) {
+
+ for (int j = 0; j < arg_count; j++) {
Argument a = (Argument) Arguments [j];
Expression a_expr = a.Expr;
Type parameter_type = pd.ParameterType (j);
if (pm == Parameter.Modifier.PARAMS){
if ((pm & ~Parameter.Modifier.PARAMS) != a.GetParameterModifier ()) {
- if (!Location.IsNull (loc))
+ if (!may_fail)
Error_InvalidArguments (
loc, j, method, delegate_type,
Argument.FullDesc (a), pd.ParameterDesc (j));
if (chose_params_expanded)
parameter_type = TypeManager.GetElementType (parameter_type);
+ } else if (pm == Parameter.Modifier.ARGLIST){
+ continue;
} else {
//
// Check modifiers
//
if (pd.ParameterModifier (j) != a.GetParameterModifier ()){
- if (!Location.IsNull (loc))
+ if (!may_fail)
Error_InvalidArguments (
loc, j, method, delegate_type,
Argument.FullDesc (a), pd.ParameterDesc (j));
//
// Check Type
//
- if (a.Type != parameter_type){
+ if (!a.Type.Equals (parameter_type)){
Expression conv;
conv = Convert.ImplicitConversion (ec, a_expr, parameter_type, loc);
if (conv == null) {
- if (!Location.IsNull (loc))
+ if (!may_fail)
Error_InvalidArguments (
loc, j, method, delegate_type,
Argument.FullDesc (a), pd.ParameterDesc (j));
if (a_mod != p_mod &&
pd.ParameterModifier (pd_count - 1) != Parameter.Modifier.PARAMS) {
- if (!Location.IsNull (loc)) {
+ if (!may_fail) {
Report.Error (1502, loc,
"The best overloaded match for method '" + FullMethodDesc (method)+
"' has some invalid arguments");
}
MethodGroupExpr mg = (MethodGroupExpr) expr;
- method = OverloadResolve (ec, mg, Arguments, loc);
+ method = OverloadResolve (ec, mg, Arguments, false, loc);
- if (method == null){
- Error (-6,
- "Could not find any applicable function for this argument list");
+ if (method == null)
return null;
- }
-
+
MethodInfo mi = method as MethodInfo;
if (mi != null) {
type = TypeManager.TypeToCoreType (mi.ReturnType);
- if (!mi.IsStatic && !mg.IsExplicitImpl && (mg.InstanceExpression == null))
+ if (!mi.IsStatic && !mg.IsExplicitImpl && (mg.InstanceExpression == null)) {
SimpleName.Error_ObjectRefRequired (ec, loc, mi.Name);
+ return null;
+ }
+
+ Expression iexpr = mg.InstanceExpression;
+ if (mi.IsStatic && (iexpr != null) && !(iexpr is This)) {
+ if (mg.IdenticalTypeName)
+ mg.InstanceExpression = null;
+ else {
+ MemberAccess.error176 (loc, mi.Name);
+ return null;
+ }
+ }
}
if (type.IsPointer){
if (TypeManager.IsSpecialMethod (method))
Report.Error (571, loc, method.Name + ": can not call operator or accessor");
}
-
+
eclass = ExprClass.Value;
return this;
}
/// emission of the arguments is known not to contain
/// a `params' field (for example in constructors or other routines
/// that keep their arguments in this structure)
+ ///
+ /// if `dup_args' is true, a copy of the arguments will be left
+ /// on the stack. If `dup_args' is true, you can specify `this_arg'
+ /// which will be duplicated before any other args. Only EmitCall
+ /// should be using this interface.
/// </summary>
- public static void EmitArguments (EmitContext ec, MethodBase mb, ArrayList arguments)
+ public static void EmitArguments (EmitContext ec, MethodBase mb, ArrayList arguments, bool dup_args, LocalTemporary this_arg)
{
ParameterData pd;
if (mb != null)
pd = GetParameterData (mb);
else
pd = null;
+
+ LocalTemporary [] temps = null;
+
+ if (dup_args)
+ temps = new LocalTemporary [arguments.Count];
//
// If we are calling a params method with no arguments, special case it
}
a.Emit (ec);
+ if (dup_args) {
+ ec.ig.Emit (OpCodes.Dup);
+ (temps [i] = new LocalTemporary (ec, a.Type)).Store (ec);
+ }
+ }
+
+ if (dup_args) {
+ if (this_arg != null)
+ this_arg.Emit (ec);
+
+ for (int i = 0; i < top; i ++)
+ temps [i].Emit (ec);
}
if (pd != null && pd.Count > top &&
}
}
+ static Type[] GetVarargsTypes (EmitContext ec, MethodBase mb,
+ ArrayList arguments)
+ {
+ ParameterData pd = GetParameterData (mb);
+
+ if (arguments == null)
+ return new Type [0];
+
+ Argument a = (Argument) arguments [pd.Count - 1];
+ Arglist list = (Arglist) a.Expr;
+
+ return list.ArgumentTypes;
+ }
+
+ /// <summary>
+ /// This checks the ConditionalAttribute on the method
+ /// </summary>
+ static bool IsMethodExcluded (MethodBase method, EmitContext ec)
+ {
+ if (method.IsConstructor)
+ return false;
+
+ IMethodData md = TypeManager.GetMethod (method);
+ if (md != null)
+ return md.IsExcluded (ec);
+
+ // For some methods (generated by delegate class) GetMethod returns null
+ // because they are not included in builder_to_method table
+ if (method.DeclaringType is TypeBuilder)
+ return false;
+
+ return AttributeTester.IsConditionalMethodExcluded (method);
+ }
+
/// <remarks>
/// is_base tells whether we want to force the use of the `call'
/// opcode instead of using callvirt. Call is required to call
public static void EmitCall (EmitContext ec, bool is_base,
bool is_static, Expression instance_expr,
MethodBase method, ArrayList Arguments, Location loc)
+ {
+ EmitCall (ec, is_base, is_static, instance_expr, method, Arguments, loc, false, false);
+ }
+
+ // `dup_args' leaves an extra copy of the arguments on the stack
+ // `omit_args' does not leave any arguments at all.
+ // So, basically, you could make one call with `dup_args' set to true,
+ // and then another with `omit_args' set to true, and the two calls
+ // would have the same set of arguments. However, each argument would
+ // only have been evaluated once.
+ public static void EmitCall (EmitContext ec, bool is_base,
+ bool is_static, Expression instance_expr,
+ MethodBase method, ArrayList Arguments, Location loc,
+ bool dup_args, bool omit_args)
{
ILGenerator ig = ec.ig;
bool struct_call = false;
bool this_call = false;
+ LocalTemporary this_arg = null;
Type decl_type = method.DeclaringType;
}
//
- // This checks the `ConditionalAttribute' on the method, and the
- // ObsoleteAttribute
+ // This checks ObsoleteAttribute on the method and on the declaring type
//
- TypeManager.MethodFlags flags = TypeManager.GetMethodFlags (method, loc);
- if ((flags & TypeManager.MethodFlags.IsObsoleteError) != 0)
- return;
- if ((flags & TypeManager.MethodFlags.ShouldIgnore) != 0)
- return;
+ ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (method);
+ if (oa != null)
+ AttributeTester.Report_ObsoleteMessage (oa, TypeManager.CSharpSignature (method), loc);
+
+
+ oa = AttributeTester.GetObsoleteAttribute (method.DeclaringType);
+ if (oa != null) {
+ AttributeTester.Report_ObsoleteMessage (oa, method.DeclaringType.FullName, loc);
+ }
+
+ if (IsMethodExcluded (method, ec))
+ return;
if (!is_static){
- if (decl_type.IsValueType)
+ this_call = instance_expr == null;
+ if (decl_type.IsValueType || (!this_call && instance_expr.Type.IsValueType))
struct_call = true;
+
//
// If this is ourselves, push "this"
//
- if (instance_expr == null) {
- this_call = true;
+ if (!omit_args) {
+ Type t = null;
+ if (this_call) {
ig.Emit (OpCodes.Ldarg_0);
+ t = decl_type;
} else {
//
// Push the instance expression
//
- if (instance_expr.Type.IsValueType){
+ if (instance_expr.Type.IsValueType) {
//
// Special case: calls to a function declared in a
// reference-type with a value-type argument need
- // to have their value boxed.
-
- struct_call = true;
- if (decl_type.IsValueType){
+ // to have their value boxed.
+ if (decl_type.IsValueType) {
//
// If the expression implements IMemoryLocation, then
// we can optimize and use AddressOf on the
//
// If not we have to use some temporary storage for
// it.
- if (instance_expr is IMemoryLocation){
+ if (instance_expr is IMemoryLocation) {
((IMemoryLocation)instance_expr).
AddressOf (ec, AddressOp.LoadStore);
- }
- else {
- Type t = instance_expr.Type;
-
+ } else {
+ LocalTemporary temp = new LocalTemporary (ec, instance_expr.Type);
instance_expr.Emit (ec);
- LocalBuilder temp = ig.DeclareLocal (t);
- ig.Emit (OpCodes.Stloc, temp);
- ig.Emit (OpCodes.Ldloca, temp);
+ temp.Store (ec);
+ temp.AddressOf (ec, AddressOp.Load);
}
+
+ // avoid the overhead of doing this all the time.
+ if (dup_args)
+ t = TypeManager.GetReferenceType (instance_expr.Type);
} else {
instance_expr.Emit (ec);
ig.Emit (OpCodes.Box, instance_expr.Type);
+ t = TypeManager.object_type;
}
- } else
+ } else {
instance_expr.Emit (ec);
+ t = instance_expr.Type;
+ }
+ }
+
+ if (dup_args) {
+ this_arg = new LocalTemporary (ec, t);
+ ig.Emit (OpCodes.Dup);
+ this_arg.Store (ec);
+ }
}
}
- EmitArguments (ec, method, Arguments);
+ if (!omit_args)
+ EmitArguments (ec, method, Arguments, dup_args, this_arg);
+
+ OpCode call_op;
+ if (is_static || struct_call || is_base || (this_call && !method.IsVirtual))
+ call_op = OpCodes.Call;
+ else
+ call_op = OpCodes.Callvirt;
+
+ if ((method.CallingConvention & CallingConventions.VarArgs) != 0) {
+ Type[] varargs_types = GetVarargsTypes (ec, method, Arguments);
+ ig.EmitCall (call_op, (MethodInfo) method, varargs_types);
+ return;
+ }
+
//
// If you have:
// this.DoFoo ();
// and DoFoo is not virtual, you can omit the callvirt,
// because you don't need the null checking behavior.
//
- if (is_static || struct_call || is_base || (this_call && !method.IsVirtual)){
- if (method is MethodInfo) {
- ig.Emit (OpCodes.Call, (MethodInfo) method);
- } else
- ig.Emit (OpCodes.Call, (ConstructorInfo) method);
- } else {
- if (method is MethodInfo)
- ig.Emit (OpCodes.Callvirt, (MethodInfo) method);
- else
- ig.Emit (OpCodes.Callvirt, (ConstructorInfo) method);
- }
+ if (method is MethodInfo)
+ ig.Emit (call_op, (MethodInfo) method);
+ else
+ ig.Emit (call_op, (ConstructorInfo) method);
}
public override void Emit (EmitContext ec)
if (type == null)
return null;
+ CheckObsoleteAttribute (type);
+
bool IsDelegate = TypeManager.IsDelegateType (type);
if (IsDelegate){
return RequestedType;
}
+ if (type.IsAbstract && type.IsSealed) {
+ Report.Error (712, loc, "Cannot create an instance of the static class '{0}'", TypeManager.CSharpName (type));
+ return null;
+ }
+
if (type.IsInterface || type.IsAbstract){
Error (144, "It is not possible to create instances of interfaces or abstract classes");
return null;
return this;
Expression ml;
- ml = MemberLookupFinal (ec, null, type, ".ctor",
+ // For member-lookup, treat 'new Foo (bar)' as call to 'foo.ctor (bar)', where 'foo' is of type 'Foo'.
+ ml = MemberLookupFinal (ec, type, type, ".ctor",
MemberTypes.Constructor,
AllBindingFlags | BindingFlags.DeclaredOnly, loc);
}
}
- method = Invocation.OverloadResolve (ec, (MethodGroupExpr) ml, Arguments, loc);
+ method = Invocation.OverloadResolve (
+ ec, (MethodGroupExpr) ml, Arguments, false, loc);
}
}
if (method != null)
- Invocation.EmitArguments (ec, method, Arguments);
+ Invocation.EmitArguments (ec, method, Arguments, false, null);
if (is_value_type){
if (method == null)
IMemoryLocation ml = (IMemoryLocation) value_target;
ml.AddressOf (ec, AddressOp.Store);
if (method != null)
- Invocation.EmitArguments (ec, method, Arguments);
+ Invocation.EmitArguments (ec, method, Arguments, false, null);
if (method == null)
ec.ig.Emit (OpCodes.Initobj, type);
/// initialization data and the other which does not need dimensions
/// specified but where initialization data is mandatory.
/// </remarks>
- public class ArrayCreation : ExpressionStatement {
+ public class ArrayCreation : Expression {
Expression requested_base_type;
ArrayList initializers;
if (type == null)
return false;
-
- underlying_type = type;
- if (underlying_type.IsArray)
- underlying_type = TypeManager.GetElementType (underlying_type);
+
+ if (!type.IsArray) {
+ Error (622, "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
+ return false;
+ }
+ underlying_type = TypeManager.GetElementType (type);
dimensions = type.GetArrayRank ();
return true;
array_element_type = TypeManager.GetElementType (type);
+ if (array_element_type.IsAbstract && array_element_type.IsSealed) {
+ Report.Error (719, loc, "'{0}': array elements cannot be of static type", TypeManager.CSharpName (array_element_type));
+ return null;
+ }
+
if (arg_count == 1) {
is_one_dimensional = true;
eclass = ExprClass.Value;
return null;
}
- new_method = Invocation.OverloadResolve (ec, (MethodGroupExpr) ml, arguments, loc);
+ new_method = Invocation.OverloadResolve (
+ ec, (MethodGroupExpr) ml, arguments, false, loc);
if (new_method == null) {
Error (-6, "New invocation: Can not find a constructor for " +
//
// Emits the initializers for the array
//
- void EmitStaticInitializers (EmitContext ec, bool is_expression)
+ void EmitStaticInitializers (EmitContext ec)
{
//
// First, the static data
fb = RootContext.MakeStaticData (data);
- if (is_expression)
- ig.Emit (OpCodes.Dup);
+ ig.Emit (OpCodes.Dup);
ig.Emit (OpCodes.Ldtoken, fb);
ig.Emit (OpCodes.Call,
TypeManager.void_initializearray_array_fieldhandle);
//
// This always expect the top value on the stack to be the array
//
- void EmitDynamicInitializers (EmitContext ec, bool is_expression)
+ void EmitDynamicInitializers (EmitContext ec)
{
ILGenerator ig = ec.ig;
int dims = bounds.Count;
num_automatic_initializers <= max_automatic_initializers) {
Type etype = e.Type;
- if (is_expression || i != top - 1)
- ig.Emit (OpCodes.Dup);
+ ig.Emit (OpCodes.Dup);
for (int idx = 0; idx < dims; idx++)
IntConstant.EmitInt (ig, current_pos [idx]);
e.Emit (ec);
- if (dims == 1)
- ArrayAccess.EmitStoreOpcode (ig, array_element_type);
- else
+ if (dims == 1) {
+ bool is_stobj;
+ OpCode op = ArrayAccess.GetStoreOpcode (etype, out is_stobj);
+ if (is_stobj)
+ ig.Emit (OpCodes.Stobj, etype);
+ else
+ ig.Emit (op);
+ } else
ig.Emit (OpCodes.Call, set);
}
}
}
- void DoEmit (EmitContext ec, bool is_statement)
+ public override void Emit (EmitContext ec)
{
ILGenerator ig = ec.ig;
// initialized. num_automatic_initializers will always be zero. See
// CheckIndices.
if (num_automatic_initializers > max_automatic_initializers)
- EmitStaticInitializers (ec, dynamic_initializers || !is_statement);
+ EmitStaticInitializers (ec);
if (dynamic_initializers)
- EmitDynamicInitializers (ec, !is_statement);
+ EmitDynamicInitializers (ec);
}
}
-
- public override void Emit (EmitContext ec)
- {
- DoEmit (ec, false);
- }
-
- public override void EmitStatement (EmitContext ec)
- {
- DoEmit (ec, true);
- }
public object EncodeAsAttribute ()
{
if (e is NullLiteral)
v = null;
else {
- if (!Attribute.GetAttributeArgumentExpression (e, Location, out v))
+ if (!Attribute.GetAttributeArgumentExpression (e, Location, array_element_type, out v))
return null;
}
ret [i++] = v;
return this;
}
- public override void Emit (EmitContext ec)
+ public void Emit (EmitContext ec, bool leave_copy)
{
- ILGenerator ig = ec.ig;
-
- ec.EmitThis ();
- if (ec.TypeContainer is Struct)
- ig.Emit (OpCodes.Ldobj, type);
+ Emit (ec);
+ if (leave_copy)
+ ec.ig.Emit (OpCodes.Dup);
}
-
- public void EmitAssign (EmitContext ec, Expression source)
+
+ public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
{
ILGenerator ig = ec.ig;
if (ec.TypeContainer is Struct){
ec.EmitThis ();
source.Emit (ec);
+ if (leave_copy)
+ ec.ig.Emit (OpCodes.Dup);
ig.Emit (OpCodes.Stobj, type);
} else {
- source.Emit (ec);
- ig.Emit (OpCodes.Starg, 0);
+ throw new Exception ("how did you get here");
}
}
+
+ public override void Emit (EmitContext ec)
+ {
+ ILGenerator ig = ec.ig;
+
+ ec.EmitThis ();
+ if (ec.TypeContainer is Struct)
+ ig.Emit (OpCodes.Ldobj, type);
+ }
public void AddressOf (EmitContext ec, AddressOp mode)
{
}
}
+ /// <summary>
+ /// Represents the `__arglist' construct
+ /// </summary>
+ public class ArglistAccess : Expression
+ {
+ public ArglistAccess (Location loc)
+ {
+ this.loc = loc;
+ }
+
+ public bool ResolveBase (EmitContext ec)
+ {
+ eclass = ExprClass.Variable;
+ type = TypeManager.runtime_argument_handle_type;
+ return true;
+ }
+
+ public override Expression DoResolve (EmitContext ec)
+ {
+ if (!ResolveBase (ec))
+ return null;
+
+ if (ec.IsFieldInitializer || !ec.CurrentBlock.HasVarargs) {
+ Error (190, "The __arglist construct is valid only within " +
+ "a variable argument method.");
+ return null;
+ }
+
+ return this;
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ ec.ig.Emit (OpCodes.Arglist);
+ }
+ }
+
+ /// <summary>
+ /// Represents the `__arglist (....)' construct
+ /// </summary>
+ public class Arglist : Expression
+ {
+ public readonly Argument[] Arguments;
+
+ public Arglist (Argument[] args, Location l)
+ {
+ Arguments = args;
+ loc = l;
+ }
+
+ public Type[] ArgumentTypes {
+ get {
+ Type[] retval = new Type [Arguments.Length];
+ for (int i = 0; i < Arguments.Length; i++)
+ retval [i] = Arguments [i].Type;
+ return retval;
+ }
+ }
+
+ public override Expression DoResolve (EmitContext ec)
+ {
+ eclass = ExprClass.Variable;
+ type = TypeManager.runtime_argument_handle_type;
+
+ foreach (Argument arg in Arguments) {
+ if (!arg.Resolve (ec, loc))
+ return null;
+ }
+
+ return this;
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ foreach (Argument arg in Arguments)
+ arg.Emit (ec);
+ }
+ }
+
//
// This produces the value that renders an instance, used by the iterators code
//
return null;
}
+ CheckObsoleteAttribute (typearg);
+
type = TypeManager.type_type;
eclass = ExprClass.Type;
return this;
if (type_queried == null)
return null;
+ CheckObsoleteAttribute (type_queried);
+
if (!TypeManager.IsUnmanagedType (type_queried)){
Report.Error (208, loc, "Cannot take the size of an unmanaged type (" + TypeManager.CSharpName (type_queried) + ")");
return null;
}
}
- static void error176 (Location loc, string name)
+ public static void error176 (Location loc, string name)
{
Report.Error (176, loc, "Static member `" +
name + "' cannot be accessed " +
"type name instead");
}
- static bool IdenticalNameAndTypeName (EmitContext ec, Expression left_original, Location loc)
+ public static bool IdenticalNameAndTypeName (EmitContext ec, Expression left_original, Expression left, Location loc)
{
- if (left_original == null)
+ SimpleName sn = left_original as SimpleName;
+ if (sn == null || left == null || left.Type.Name != sn.Name)
return false;
- if (!(left_original is SimpleName))
- return false;
-
- SimpleName sn = (SimpleName) left_original;
-
- Type t = RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc);
- if (t != null)
- return true;
-
- return false;
+ return RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc) != null;
}
public static Expression ResolveMemberAccess (EmitContext ec, Expression member_lookup,
Const c = TypeManager.LookupConstant ((FieldBuilder) fi);
if (c != null) {
- object o = c.LookupConstantValue ();
- if (o == null)
+ object o;
+ if (!c.LookupConstantValue (out o))
return null;
-
+
object real_value = ((Constant) c.Expr).GetValue ();
return Constantify (real_value, fi.FieldType);
if (decl_type.IsSubclassOf (TypeManager.enum_type)) {
if (left_is_explicit && !left_is_type &&
- !IdenticalNameAndTypeName (ec, left_original, loc)) {
+ !IdenticalNameAndTypeName (ec, left_original, member_lookup, loc)) {
error176 (loc, fe.FieldInfo.Name);
return null;
}
// accessors and private field etc so there's no need
// to transform ourselves.
//
+ ee.InstanceExpression = left;
return ee;
}
if (!left_is_explicit)
left = null;
-
+
+ ee.InstanceExpression = left;
+
return ResolveMemberAccess (ec, ml, left, loc, left_original);
}
}
if (member_lookup is IMemberExpr) {
IMemberExpr me = (IMemberExpr) member_lookup;
+ MethodGroupExpr mg = me as MethodGroupExpr;
if (left_is_type){
- MethodGroupExpr mg = me as MethodGroupExpr;
if ((mg != null) && left_is_explicit && left.Type.IsInterface)
mg.IsExplicitImpl = left_is_explicit;
if (!me.IsStatic){
if ((ec.IsFieldInitializer || ec.IsStatic) &&
- IdenticalNameAndTypeName (ec, left_original, loc))
+ IdenticalNameAndTypeName (ec, left_original, member_lookup, loc))
return member_lookup;
-
+
SimpleName.Error_ObjectRefRequired (ec, loc, me.Name);
return null;
}
} else {
- if (!me.IsInstance){
- if (IdenticalNameAndTypeName (ec, left_original, loc))
+ if (!me.IsInstance) {
+ if (IdenticalNameAndTypeName (ec, left_original, left, loc))
return member_lookup;
if (left_is_explicit) {
error176 (loc, me.Name);
return null;
}
- }
+ }
//
// Since we can not check for instance objects in SimpleName,
}
}
+ if ((mg != null) && IdenticalNameAndTypeName (ec, left_original, left, loc))
+ mg.IdenticalTypeName = true;
+
me.InstanceExpression = left;
}
Console.WriteLine ("Left is: " + left);
Report.Error (-100, loc, "Support for [" + member_lookup + "] is not present yet");
- Environment.Exit (0);
+ Environment.Exit (1);
return null;
}
//
Expression original = expr;
- expr = expr.Resolve (ec, flags | ResolveFlags.DisableFlowAnalysis);
+ expr = expr.Resolve (ec, flags | ResolveFlags.Intermediate | ResolveFlags.DisableFlowAnalysis);
if (expr == null)
return null;
Type expr_type = expr.Type;
if (expr is TypeExpr){
if (!ec.DeclSpace.CheckAccessLevel (expr_type)){
- Error (122, "`" + expr_type + "' " +
- "is inaccessible because of its protection level");
+ Report.Error (122, loc, "'{0}' is inaccessible due to its protection level", expr_type);
return null;
}
object value = en.LookupEnumValue (ec, Identifier, loc);
if (value != null){
+ MemberCore mc = en.GetDefinition (Identifier);
+ ObsoleteAttribute oa = mc.GetObsoleteAttribute (en);
+ if (oa != null) {
+ AttributeTester.Report_ObsoleteMessage (oa, mc.GetSignatureForError (), Location);
+ }
+ oa = en.GetObsoleteAttribute (en);
+ if (oa != null) {
+ AttributeTester.Report_ObsoleteMessage (oa, en.GetSignatureForError (), Location);
+ }
+
Constant c = Constantify (value, en.UnderlyingType);
return new EnumConstant (c, expr_type);
}
+ } else {
+ CheckObsoleteAttribute (expr_type);
+
+ FieldInfo fi = expr_type.GetField (Identifier);
+ if (fi != null) {
+ ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (fi);
+ if (oa != null)
+ AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (fi), Location);
+ }
}
}
}
return true;
}
- Expression MakePointerAccess ()
+ Expression MakePointerAccess (EmitContext ec)
{
Type t = Expr.Type;
}
Expression p;
- p = new PointerArithmetic (true, Expr, ((Argument)Arguments [0]).Expr, t, loc);
- return new Indirection (p, loc);
+ p = new PointerArithmetic (true, Expr, ((Argument)Arguments [0]).Expr, t, loc).Resolve (ec);
+ if (p == null)
+ return null;
+ return new Indirection (p, loc).Resolve (ec);
}
public override Expression DoResolve (EmitContext ec)
if (t.IsArray)
return (new ArrayAccess (this, loc)).Resolve (ec);
else if (t.IsPointer)
- return MakePointerAccess ();
+ return MakePointerAccess (ec);
else
return (new IndexerAccess (this, loc)).Resolve (ec);
}
if (t.IsArray)
return (new ArrayAccess (this, loc)).ResolveLValue (ec, right_side);
else if (t.IsPointer)
- return MakePointerAccess ();
+ return MakePointerAccess (ec);
else
return (new IndexerAccess (this, loc)).ResolveLValue (ec, right_side);
}
//
ElementAccess ea;
- LocalTemporary [] cached_locations;
+ LocalTemporary temp;
+ bool prepared;
public ArrayAccess (ElementAccess ea_data, Location l)
{
ig.Emit (OpCodes.Ldelem_Ref);
}
- /// <summary>
- /// Emits the right opcode to store an object of Type `t'
- /// from an array of T.
- /// </summary>
- static public void EmitStoreOpcode (ILGenerator ig, Type t)
- {
- bool is_stobj;
- OpCode op = GetStoreOpcode (t, out is_stobj);
- if (is_stobj)
- ig.Emit (OpCodes.Stobj, t);
- else
- ig.Emit (op);
- }
-
/// <summary>
/// Returns the right opcode to store an object of Type `t'
/// from an array of T.
//Console.WriteLine (new System.Diagnostics.StackTrace ());
is_stobj = false;
t = TypeManager.TypeToCoreType (t);
- if (TypeManager.IsEnumType (t) && t != TypeManager.enum_type)
+ if (TypeManager.IsEnumType (t))
t = TypeManager.EnumToUnderlying (t);
if (t == TypeManager.byte_type || t == TypeManager.sbyte_type ||
t == TypeManager.bool_type)
{
ILGenerator ig = ec.ig;
- if (cached_locations == null){
- ea.Expr.Emit (ec);
- foreach (Argument a in ea.Arguments){
- Type argtype = a.Expr.Type;
-
- a.Expr.Emit (ec);
-
- if (argtype == TypeManager.int64_type)
- ig.Emit (OpCodes.Conv_Ovf_I);
- else if (argtype == TypeManager.uint64_type)
- ig.Emit (OpCodes.Conv_Ovf_I_Un);
- }
- return;
- }
-
- if (cached_locations [0] == null){
- cached_locations [0] = new LocalTemporary (ec, ea.Expr.Type);
- ea.Expr.Emit (ec);
- ig.Emit (OpCodes.Dup);
- cached_locations [0].Store (ec);
+ ea.Expr.Emit (ec);
+ foreach (Argument a in ea.Arguments){
+ Type argtype = a.Expr.Type;
- int j = 1;
+ a.Expr.Emit (ec);
- foreach (Argument a in ea.Arguments){
- Type argtype = a.Expr.Type;
-
- cached_locations [j] = new LocalTemporary (ec, TypeManager.intptr_type /* a.Expr.Type */);
- a.Expr.Emit (ec);
- if (argtype == TypeManager.int64_type)
- ig.Emit (OpCodes.Conv_Ovf_I);
- else if (argtype == TypeManager.uint64_type)
- ig.Emit (OpCodes.Conv_Ovf_I_Un);
-
- ig.Emit (OpCodes.Dup);
- cached_locations [j].Store (ec);
- j++;
- }
- return;
+ if (argtype == TypeManager.int64_type)
+ ig.Emit (OpCodes.Conv_Ovf_I);
+ else if (argtype == TypeManager.uint64_type)
+ ig.Emit (OpCodes.Conv_Ovf_I_Un);
}
-
- foreach (LocalTemporary lt in cached_locations)
- lt.Emit (ec);
}
- public new void CacheTemporaries (EmitContext ec)
- {
- cached_locations = new LocalTemporary [ea.Arguments.Count + 1];
- }
-
- public override void Emit (EmitContext ec)
+ public void Emit (EmitContext ec, bool leave_copy)
{
int rank = ea.Expr.Type.GetArrayRank ();
ILGenerator ig = ec.ig;
- LoadArrayAndArguments (ec);
-
- if (rank == 1)
- EmitLoadOpcode (ig, type);
- else {
- MethodInfo method;
+ if (!prepared) {
+ LoadArrayAndArguments (ec);
- method = FetchGetMethod ();
- ig.Emit (OpCodes.Call, method);
+ if (rank == 1)
+ EmitLoadOpcode (ig, type);
+ else {
+ MethodInfo method;
+
+ method = FetchGetMethod ();
+ ig.Emit (OpCodes.Call, method);
+ }
+ } else
+ LoadFromPtr (ec.ig, this.type);
+
+ if (leave_copy) {
+ ec.ig.Emit (OpCodes.Dup);
+ temp = new LocalTemporary (ec, this.type);
+ temp.Store (ec);
}
}
+
+ public override void Emit (EmitContext ec)
+ {
+ Emit (ec, false);
+ }
- public void EmitAssign (EmitContext ec, Expression source)
+ public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
{
int rank = ea.Expr.Type.GetArrayRank ();
ILGenerator ig = ec.ig;
Type t = source.Type;
+ prepared = prepare_for_load;
- LoadArrayAndArguments (ec);
-
- //
- // The stobj opcode used by value types will need
- // an address on the stack, not really an array/array
- // pair
- //
- if (rank == 1){
- if (t == TypeManager.enum_type || t == TypeManager.decimal_type ||
- (t.IsSubclassOf (TypeManager.value_type) && !TypeManager.IsEnumType (t) && !TypeManager.IsBuiltinType (t)))
- ig.Emit (OpCodes.Ldelema, t);
+ if (prepare_for_load) {
+ AddressOf (ec, AddressOp.LoadStore);
+ ec.ig.Emit (OpCodes.Dup);
+ source.Emit (ec);
+ if (leave_copy) {
+ ec.ig.Emit (OpCodes.Dup);
+ temp = new LocalTemporary (ec, this.type);
+ temp.Store (ec);
+ }
+ StoreFromPtr (ec.ig, t);
+
+ if (temp != null)
+ temp.Emit (ec);
+
+ return;
}
- source.Emit (ec);
+ LoadArrayAndArguments (ec);
- if (rank == 1)
- EmitStoreOpcode (ig, t);
- else {
+ if (rank == 1) {
+ bool is_stobj;
+ OpCode op = GetStoreOpcode (t, out is_stobj);
+ //
+ // The stobj opcode used by value types will need
+ // an address on the stack, not really an array/array
+ // pair
+ //
+ if (is_stobj)
+ ig.Emit (OpCodes.Ldelema, t);
+
+ source.Emit (ec);
+ if (leave_copy) {
+ ec.ig.Emit (OpCodes.Dup);
+ temp = new LocalTemporary (ec, this.type);
+ temp.Store (ec);
+ }
+
+ if (is_stobj)
+ ig.Emit (OpCodes.Stobj, t);
+ else
+ ig.Emit (op);
+ } else {
ModuleBuilder mb = CodeGen.Module.Builder;
int arg_count = ea.Arguments.Count;
Type [] args = new Type [arg_count + 1];
MethodInfo set;
+ source.Emit (ec);
+ if (leave_copy) {
+ ec.ig.Emit (OpCodes.Dup);
+ temp = new LocalTemporary (ec, this.type);
+ temp.Store (ec);
+ }
+
for (int i = 0; i < arg_count; i++){
//args [i++] = a.Type;
args [i] = TypeManager.int32_type;
ig.Emit (OpCodes.Call, set);
}
+
+ if (temp != null)
+ temp.Emit (ec);
}
public void AddressOf (EmitContext ec, AddressOp mode)
MemberInfo [] mi = TypeManager.MemberLookup (
caller_type, caller_type, lookup_type, MemberTypes.Property,
BindingFlags.Public | BindingFlags.Instance |
- BindingFlags.DeclaredOnly, p_name);
+ BindingFlags.DeclaredOnly, p_name, null);
if (mi == null || mi.Length == 0)
return null;
if (AllGetters.Count > 0) {
found_any_getters = true;
get = (MethodInfo) Invocation.OverloadResolve (
- ec, new MethodGroupExpr (AllGetters, loc), arguments, loc);
+ ec, new MethodGroupExpr (AllGetters, loc),
+ arguments, false, loc);
}
if (!found_any) {
set_arguments.Add (new Argument (right_side, Argument.AType.Expression));
set = (MethodInfo) Invocation.OverloadResolve (
ec, new MethodGroupExpr (AllSetters, loc),
- set_arguments, loc);
+ set_arguments, false, loc);
}
if (!found_any) {
return this;
}
- public override void Emit (EmitContext ec)
+ bool prepared = false;
+ LocalTemporary temp;
+
+ public void Emit (EmitContext ec, bool leave_copy)
{
- Invocation.EmitCall (ec, is_base_indexer, false, instance_expr, get, arguments, loc);
+ Invocation.EmitCall (ec, is_base_indexer, false, instance_expr, get, arguments, loc, prepared, false);
+ if (leave_copy) {
+ ec.ig.Emit (OpCodes.Dup);
+ temp = new LocalTemporary (ec, Type);
+ temp.Store (ec);
+ }
}
-
+
//
// source is ignored, because we already have a copy of it from the
// LValue resolution and we have already constructed a pre-cached
// version of the arguments (ea.set_arguments);
//
- public void EmitAssign (EmitContext ec, Expression source)
+ public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
{
- Invocation.EmitCall (ec, is_base_indexer, false, instance_expr, set, set_arguments, loc);
+ prepared = prepare_for_load;
+ Argument a = (Argument) set_arguments [set_arguments.Count - 1];
+
+ if (prepared) {
+ source.Emit (ec);
+ if (leave_copy) {
+ ec.ig.Emit (OpCodes.Dup);
+ temp = new LocalTemporary (ec, Type);
+ temp.Store (ec);
+ }
+ } else if (leave_copy) {
+ temp = new LocalTemporary (ec, Type);
+ source.Emit (ec);
+ temp.Store (ec);
+ a.Expr = temp;
+ }
+
+ Invocation.EmitCall (ec, is_base_indexer, false, instance_expr, set, set_arguments, loc, false, prepared);
+
+ if (temp != null)
+ temp.Emit (ec);
+ }
+
+
+ public override void Emit (EmitContext ec)
+ {
+ Emit (ec, false);
}
}
pe.IsBase = true;
}
+
+ if (e is MethodGroupExpr)
+ ((MethodGroupExpr) e).IsBase = true;
return e;
}
if (ltype == null)
return null;
+ if ((ltype == TypeManager.void_type) && (dim != "*")) {
+ Report.Error (1547, Location,
+ "Keyword 'void' cannot be used in this context");
+ return null;
+ }
+
//
// ltype.Fullname is already fully qualified, so we can skip
// a lot of probes, and go directly to TypeManager.LookupType
return null;
}
+ Constant c = count as Constant;
+ // TODO: because we don't have property IsNegative
+ if (c != null && c.ConvertToUInt () == null) {
+ Report.Error (247, loc, "Cannot use a negative size with stackalloc");
+ return null;
+ }
+
if (ec.CurrentBranching.InCatch () ||
ec.CurrentBranching.InFinally (true)) {
Error (255,