op_name = oper_names [(int) Oper];
- mg = MemberLookup (ec, expr_type, op_name, MemberTypes.Method, AllBindingFlags, loc);
+ mg = MemberLookup (ec.ContainerType, expr_type, op_name, MemberTypes.Method, AllBindingFlags, loc);
if (mg != null) {
Expression e = StaticCallExpr.MakeSimpleCall (
// According to the specs, a variable is considered definitely assigned if you take
// its address.
- if ((variable != null) && (variable.VariableInfo != null))
+ if ((variable != null) && (variable.VariableInfo != null)){
variable.VariableInfo.SetAssigned (ec);
+ }
type = TypeManager.GetPointerType (Expr.Type);
return this;
if (Expr == null)
return null;
- if (TypeManager.IsNullableType (Expr.Type))
+ if (TypeManager.IsNullableValueType (Expr.Type))
return new Nullable.LiftedUnaryOperator (Oper, Expr, loc).Resolve (ec);
eclass = ExprClass.Value;
Expr.Emit (ec);
ig.Emit (OpCodes.Sub_Ovf);
} else {
- Expr.Emit (ec);
- ig.Emit (OpCodes.Neg);
+ Expr.Emit (ec);
+ ig.Emit (OpCodes.Neg);
}
break;
{
if (!prepared)
expr.Emit (ec);
-
+
LoadFromPtr (ec.ig, 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)
{
expr.Emit (ec);
else
op_name = "op_Decrement";
- mg = MemberLookup (ec, expr_type, op_name, MemberTypes.Method, AllBindingFlags, loc);
+ mg = MemberLookup (ec.ContainerType, expr_type, op_name, MemberTypes.Method, AllBindingFlags, loc);
if (mg != null) {
method = StaticCallExpr.MakeSimpleCall (
if (expr == null)
return null;
} else {
- expr.Error_UnexpectedKind (ec, "variable, indexer or property access", loc);
+ expr.Error_UnexpectedKind (ec.DeclContainer, "variable, indexer or property access", loc);
return null;
}
eclass = ExprClass.Value;
- if (TypeManager.IsNullableType (expr.Type))
+ if (TypeManager.IsNullableValueType (expr.Type))
return new Nullable.LiftedUnaryMutator (mode, expr, loc).Resolve (ec);
return ResolveOperator (ec);
public override Expression DoResolve (EmitContext ec)
{
- probe_type_expr = ProbeType.ResolveAsTypeTerminal (ec);
+ probe_type_expr = ProbeType.ResolveAsTypeTerminal (ec, false);
if (probe_type_expr == null)
return null;
- if (probe_type_expr.ResolveType (ec) == null)
- return null;
expr = expr.Resolve (ec);
if (expr == null)
action = Action.AlwaysFalse;
else
action = Action.Probe;
+ } else if (etype.ContainsGenericParameters || probe_type.ContainsGenericParameters) {
+ expr = new BoxedCast (expr, etype);
+ action = Action.Probe;
} else {
action = Action.AlwaysFalse;
warning_never_matches = true;
return this;
}
+ if (etype.ContainsGenericParameters || type.ContainsGenericParameters) {
+ expr = new BoxedCast (expr, etype);
+ do_isinst = true;
+ return this;
+ }
+
Error_CannotConvertType (etype, type, loc);
return null;
- }
+ }
+
+ public override bool GetAttributableValue (out object value)
+ {
+ return expr.GetAttributableValue (out value);
+ }
}
/// <summary>
this.target_type = cast_type;
this.expr = expr;
this.loc = loc;
+
+ if (target_type == TypeManager.system_void_expr) {
+ Report.Error (1547, loc, "Keyword `void' cannot be used in this context");
+ }
}
public Expression TargetType {
Expression ResolveRest (EmitContext ec)
{
- TypeExpr target = target_type.ResolveAsTypeTerminal (ec);
+ TypeExpr target = target_type.ResolveAsTypeTerminal (ec, false);
if (target == null)
return null;
- type = target.ResolveType (ec);
+ type = target.Type;
if (type.IsAbstract && type.IsSealed) {
Report.Error (716, loc, "Cannot convert to static type `{0}'", TypeManager.CSharpName (type));
Constant c = expr as Constant;
if (c != null) {
- c = c.TryReduce (ec, type, loc);
- if (c != null)
- return c;
+ try {
+ c = c.TryReduce (ec, type, loc);
+ if (c != null)
+ return c;
+ }
+ catch (OverflowException) {
+ return null;
+ }
}
if (type.IsPointer && !ec.InUnsafe) {
if (ll >= 0)
right = new ULongConstant ((ulong) ll, right.Location);
} else {
- e = Convert.ImplicitNumericConversion (ec, right, l);
+ e = Convert.ImplicitNumericConversion (right, l);
if (e != null)
right = e;
}
if (ll > 0)
left = new ULongConstant ((ulong) ll, right.Location);
} else {
- e = Convert.ImplicitNumericConversion (ec, left, r);
+ e = Convert.ImplicitNumericConversion (left, r);
if (e != null)
left = e;
}
string op = oper_names [(int) oper];
MethodGroupExpr union;
- left_operators = MemberLookup (ec, l, op, MemberTypes.Method, AllBindingFlags, loc);
+ left_operators = MemberLookup (ec.ContainerType, l, op, MemberTypes.Method, AllBindingFlags, loc);
if (r != l){
right_operators = MemberLookup (
- ec, r, op, MemberTypes.Method, AllBindingFlags, loc);
+ ec.ContainerType, r, op, MemberTypes.Method, AllBindingFlags, loc);
union = Invocation.MakeUnionSet (left_operators, right_operators, loc);
} else
union = (MethodGroupExpr) left_operators;
// Simple constant folding
if (left is StringConstant && right is StringConstant)
return new StringConstant (((StringConstant) left).Value + ((StringConstant) right).Value, left.Location);
-
+
if (l == TypeManager.string_type || r == TypeManager.string_type) {
if (r == TypeManager.void_type || l == TypeManager.void_type) {
return left;
}
}
-
+
// Otherwise, start a new concat expression
return new StringConcat (ec, loc, left, right).Resolve (ec);
}
// Also, a standard conversion must exist from either one
//
bool left_to_right =
- Convert.ImplicitStandardConversionExists (ec, left, r);
+ Convert.ImplicitStandardConversionExists (left, r);
bool right_to_left = !left_to_right &&
- Convert.ImplicitStandardConversionExists (ec, right, l);
+ Convert.ImplicitStandardConversionExists (right, l);
if (!left_to_right && !right_to_left) {
Error_OperatorCannotBeApplied ();
// U operator - (E e, E f)
if (lie && rie){
if (oper == Operator.Subtraction){
- if (l == r){
- type = TypeManager.EnumToUnderlying (l);
- return this;
- }
- Error_OperatorCannotBeApplied ();
- return null;
- }
+ if (l == r){
+ type = TypeManager.EnumToUnderlying (l);
+ return this;
+ }
+ Error_OperatorCannotBeApplied ();
+ return null;
+ }
}
//
return e;
}
- if (TypeManager.IsNullableType (left.Type) || TypeManager.IsNullableType (right.Type))
+ Type ltype = left.Type, rtype = right.Type;
+ if (ltype.IsValueType && rtype.IsValueType &&
+ (TypeManager.IsNullableType (ltype) || TypeManager.IsNullableType (rtype)))
return new Nullable.LiftedBinaryOperator (oper, left, right, loc).Resolve (ec);
// Comparison warnings
return ResolveOperator (ec);
}
+ public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+ {
+ return null;
+ }
+
private void CheckUselessComparison (Constant c, Type type)
{
if (c == null || !IsTypeIntegral (type)
right = left;
left = swap;
}
-
+
if (((Constant) right).IsZeroInteger) {
left.Emit (ec);
if (my_on_true)
ig.Emit (OpCodes.Brfalse, target);
return;
- } else if (right is BoolConstant){
+ } else if (right is BoolConstant) {
left.Emit (ec);
if (my_on_true != ((BoolConstant) right).Value)
ig.Emit (OpCodes.Brtrue, target);
} else if (oper == Operator.LogicalAnd) {
if (onTrue) {
- Label tests_end = ig.DefineLabel ();
-
+ Label tests_end = ig.DefineLabel ();
+
left.EmitBranchable (ec, tests_end, false);
right.EmitBranchable (ec, target, true);
- ig.MarkLabel (tests_end);
- } else {
+ ig.MarkLabel (tests_end);
+ } else {
left.EmitBranchable (ec, target, false);
right.EmitBranchable (ec, target, false);
- }
-
+ }
+
return;
-
+
} else if (oper == Operator.LogicalOr){
if (onTrue) {
left.EmitBranchable (ec, target, true);
right.EmitBranchable (ec, target, true);
-
- } else {
- Label tests_end = ig.DefineLabel ();
+
+ } else {
+ Label tests_end = ig.DefineLabel ();
left.EmitBranchable (ec, tests_end, true);
right.EmitBranchable (ec, target, false);
ig.MarkLabel (tests_end);
}
-
+
return;
-
+
} else if (!(oper == Operator.LessThan || oper == Operator.GreaterThan ||
oper == Operator.LessThanOrEqual || oper == Operator.GreaterThanOrEqual ||
oper == Operator.Equality || oper == Operator.Inequality)) {
base.EmitBranchable (ec, target, onTrue);
return;
- }
-
+ }
+
left.Emit (ec);
right.Emit (ec);
Type t = left.Type;
bool isUnsigned = is_unsigned (t) || t == TypeManager.double_type || t == TypeManager.float_type;
-
+
switch (oper){
case Operator.Equality:
if (onTrue)
if (oper == Operator.LogicalAnd) {
Label load_zero = ig.DefineLabel ();
Label end = ig.DefineLabel ();
-
+
left.EmitBranchable (ec, load_zero, false);
- right.Emit (ec);
- ig.Emit (OpCodes.Br, end);
-
+ right.Emit (ec);
+ ig.Emit (OpCodes.Br, end);
+
ig.MarkLabel (load_zero);
ig.Emit (OpCodes.Ldc_I4_0);
ig.MarkLabel (end);
} else if (oper == Operator.LogicalOr) {
Label load_one = ig.DefineLabel ();
Label end = ig.DefineLabel ();
-
- left.EmitBranchable (ec, load_one, true);
- right.Emit (ec);
- ig.Emit (OpCodes.Br, end);
+ left.EmitBranchable (ec, load_one, true);
+ right.Emit (ec);
+ ig.Emit (OpCodes.Br, end);
+
ig.MarkLabel (load_one);
ig.Emit (OpCodes.Ldc_I4_1);
ig.MarkLabel (end);
ig.Emit (OpCodes.Call, (ConstructorInfo) method);
}
}
-
+
//
// Represents the operation a + b [+ c [+ d [+ ...]]], where a is a string
// b, c, d... may be strings or objects.
// This can get called multiple times, so we have to deal with that.
if (!emit_conv_done) {
emit_conv_done = true;
- for (int i = 0; i < operands.Count; i ++) {
- Expression e = (Expression) operands [i];
- is_strings_only &= e.Type == TypeManager.string_type;
- }
-
- for (int i = 0; i < operands.Count; i ++) {
- Expression e = (Expression) operands [i];
+ for (int i = 0; i < operands.Count; i ++) {
+ Expression e = (Expression) operands [i];
+ is_strings_only &= e.Type == TypeManager.string_type;
+ }
- if (! is_strings_only && e.Type == TypeManager.string_type) {
- // need to make sure this is an object, because the EmitParams
- // method might look at the type of this expression, see it is a
- // string and emit a string [] when we want an object [];
+ for (int i = 0; i < operands.Count; i ++) {
+ Expression e = (Expression) operands [i];
+ if (! is_strings_only && e.Type == TypeManager.string_type) {
+ // need to make sure this is an object, because the EmitParams
+ // method might look at the type of this expression, see it is a
+ // string and emit a string [] when we want an object [];
+
e = new EmptyCast (e, TypeManager.object_type);
+ }
+ operands [i] = new Argument (e, Argument.AType.Expression);
}
- operands [i] = new Argument (e, Argument.AType.Expression);
- }
}
//
if (expr == null)
return null;
- if (TypeManager.IsNullableType (expr.Type))
+ if (TypeManager.IsNullableValueType (expr.Type))
return new Nullable.LiftedConditional (expr, trueExpr, falseExpr, loc).Resolve (ec);
if (expr.Type != TypeManager.bool_type){
return this;
}
+ public override TypeExpr ResolveAsTypeTerminal (IResolveContext ec, bool silent)
+ {
+ return null;
+ }
+
public override void Emit (EmitContext ec)
{
ILGenerator ig = ec.ig;
Name, local_info.GetReadOnlyContext ());
return null;
}
-
+
if (variable_info != null)
variable_info.SetAssigned (ec);
}
ec.CaptureVariable (local_info);
}
}
-
+
return this;
}
-
+
public override Expression DoResolve (EmitContext ec)
{
return DoResolveBase (ec, null);
public void AddressOf (EmitContext ec, AddressOp mode)
{
ILGenerator ig = ec.ig;
-
+
if (local_info.FieldBuilder == null){
//
// A local variable on the local CLR stack
//
- ig.Emit (OpCodes.Ldloca, local_info.LocalBuilder);
+ ig.Emit (OpCodes.Ldloca, local_info.LocalBuilder);
} else {
//
// A local variable captured by anonymous methods or iterators
ec.CurrentBranching.SetFieldAssigned (vi, field_name);
}
- protected void DoResolveBase (EmitContext ec)
+ protected bool DoResolveBase (EmitContext ec)
{
if (!par.Resolve (ec)) {
//TODO:
if (is_ref && !block.Toplevel.IsLocalParameter (name)){
Report.Error (1628, Location, "Cannot use ref or out parameter `{0}' inside an anonymous method block",
par.Name);
- return;
+ return false;
}
//
ec.CaptureParameter (name, type, idx);
}
}
+
+ return true;
}
public override int GetHashCode()
//
public override Expression DoResolve (EmitContext ec)
{
- DoResolveBase (ec);
+ if (!DoResolveBase (ec))
+ return null;
if (is_out && ec.DoFlowAnalysis && (!ec.OmitStructFlowAnalysis || !vi.TypeInfo.IsStruct) && !IsAssigned (ec, loc))
return null;
override public Expression DoResolveLValue (EmitContext ec, Expression right_side)
{
- DoResolveBase (ec);
+ if (!DoResolveBase (ec))
+ return null;
SetAssigned (ec);
return null;
if (argument_expr is NullLiteral) {
- //
+ //
// If the argument is null and one of the types to compare is 'object' and
// the other is a reference type, we prefer the other.
- //
+ //
// This follows from the usual rules:
// * There is an implicit conversion from 'null' to type 'object'
// * There is an implicit conversion from 'null' to any reference type
if (!q.IsValueType && p == TypeManager.object_type)
return q;
}
-
+
if (argument_type == p)
return p;
Expression p_tmp = new EmptyExpression (p);
Expression q_tmp = new EmptyExpression (q);
-
+
bool p_to_q = Convert.ImplicitConversionExists (ec, p_tmp, q);
bool q_to_p = Convert.ImplicitConversionExists (ec, q_tmp, p);
if (q == TypeManager.ushort_type || q == TypeManager.uint32_type ||
q == TypeManager.uint64_type)
return p;
-
if (q == TypeManager.short_type)
if (p == TypeManager.ushort_type || p == TypeManager.uint32_type ||
p == TypeManager.uint64_type)
if (p == TypeManager.int32_type)
if (q == TypeManager.uint32_type || q == TypeManager.uint64_type)
return p;
-
if (q == TypeManager.int32_type)
if (p == TypeManager.uint32_type || p == TypeManager.uint64_type)
return q;
{
ParameterData candidate_pd = TypeManager.GetParameterData (candidate);
ParameterData best_pd = TypeManager.GetParameterData (best);
-
+
bool better_at_least_one = false;
bool same = true;
for (int j = 0; j < argument_count; ++j) {
same = false;
Type better = BetterConversion (ec, a, ct, bt, loc);
+
// for each argument, the conversion to 'ct' should be no worse than
// the conversion to 'bt'.
if (better == bt)
return false;
-
+
// for at least one argument, the conversion to 'ct' should be better than
// the conversion to 'bt'.
if (better == ct)
// Pick the "more specific" signature
//
- MethodBase orig_candidate = candidate.Mono_IsInflatedMethod ?
- candidate.GetGenericMethodDefinition () : candidate;
- MethodBase orig_best = best.Mono_IsInflatedMethod ?
- best.GetGenericMethodDefinition () : best;
+ MethodBase orig_candidate = TypeManager.DropGenericMethodArguments (candidate);
+ MethodBase orig_best = TypeManager.DropGenericMethodArguments (best);
ParameterData orig_candidate_pd = TypeManager.GetParameterData (orig_candidate);
ParameterData orig_best_pd = TypeManager.GetParameterData (orig_best);
bool do_varargs)
{
ParameterData pd = TypeManager.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;
} else {
if (!pd.HasParams)
- return false;
+ return false;
}
if (count > arg_count)
ref MethodBase candidate)
{
if (!me.HasTypeArguments &&
- !TypeManager.InferTypeArguments (ec, arguments, ref candidate))
+ !TypeManager.InferTypeArguments (arguments, ref candidate))
return false;
return IsApplicable (ec, arguments, arg_count, candidate);
return true;
}
-
+
static internal bool IsAncestralType (Type first_type, Type second_type)
{
return first_type != second_type &&
- (second_type.IsSubclassOf (first_type) ||
+ (TypeManager.IsSubclassOf (second_type, first_type) ||
TypeManager.ImplementsInterface (second_type, first_type));
}
if (Arguments != null)
arg_count = Arguments.Count;
-
+
if ((me.Name == "Invoke") &&
TypeManager.IsDelegateType (me.DeclaringType)) {
Error_InvokeOnDelegate (loc);
}
if (!is_applicable)
- continue;
+ continue;
candidates.Add (methods [i]);
if (pd.Count != arg_count)
continue;
- if (!TypeManager.InferTypeArguments (ec, Arguments, ref c))
+ if (!TypeManager.InferTypeArguments (Arguments, ref c))
continue;
VerifyArgumentsCompat (ec, Arguments, arg_count,
if (pd.Count != arg_count)
continue;
- if (TypeManager.InferTypeArguments (ec, Arguments, ref c))
+ if (TypeManager.InferTypeArguments (Arguments, ref c))
continue;
Report.Error (
bool cand_params = candidate_to_form != null && candidate_to_form.Contains (candidate);
if (!BetterFunction (ec, Arguments, arg_count,
- method, method_params,
- candidate, cand_params,
+ method, method_params,
+ candidate, cand_params,
loc)) {
Report.SymbolRelatedToPreviousError (candidate);
ambiguous = candidate;
if (method == null)
return null;
- MethodBase the_method = method;
- if (the_method.Mono_IsInflatedMethod) {
- the_method = the_method.GetGenericMethodDefinition ();
-
- if ((method is MethodInfo) &&
- !ConstraintChecker.CheckConstraints (ec, the_method, method, loc))
- return null;
- }
+ MethodBase the_method = TypeManager.DropGenericMethodArguments (method);
+ if (the_method.IsGenericMethodDefinition &&
+ !ConstraintChecker.CheckConstraints (ec, the_method, method, loc))
+ return null;
IMethodData data = TypeManager.GetMethod (the_method);
if (data != null)
/// <summary>
/// This checks the ConditionalAttribute on the method
/// </summary>
- static bool IsMethodExcluded (MethodBase method, EmitContext ec)
+ static bool IsMethodExcluded (MethodBase method)
{
if (method.IsConstructor)
return false;
IMethodData md = TypeManager.GetMethod (method);
if (md != null)
- return md.IsExcluded (ec);
+ return md.IsExcluded ();
// For some methods (generated by delegate class) GetMethod returns null
// because they are not included in builder_to_method table
method = TypeManager.void_array_copyto_array_int;
}
- if (ec.TestObsoleteMethodUsage) {
+ if (!ec.IsInObsoleteScope) {
//
// This checks ObsoleteAttribute on the method and on the declaring type
//
}
}
- if (IsMethodExcluded (method, ec))
+ if (IsMethodExcluded (method))
return;
if (!is_static){
//
// First try to resolve it as a cast.
//
- TypeExpr te = expr.ResolveAsTypeStep (ec) as TypeExpr;
+ TypeExpr te = expr.ResolveAsTypeTerminal (ec, true);
if ((te != null) && (te.eclass == ExprClass.Type)) {
Cast cast = new Cast (te, argument, loc);
return cast.Resolve (ec);
//
// First try to resolve it as a cast.
//
- TypeExpr te = expr.ResolveAsTypeStep (ec) as TypeExpr;
+ TypeExpr te = expr.ResolveAsTypeTerminal (ec, true);
if ((te != null) && (te.eclass == ExprClass.Type)) {
error201 ();
return null;
return this;
}
- TypeExpr texpr = RequestedType.ResolveAsTypeTerminal (ec);
+ TypeExpr texpr = RequestedType.ResolveAsTypeTerminal (ec, false);
if (texpr == null)
return null;
- type = texpr.ResolveType (ec);
+ type = texpr.Type;
if (Arguments == null) {
Expression c = Constantify (type);
if (is_struct && Arguments == null)
return this;
+ // For member-lookup, treat 'new Foo (bar)' as call to 'foo.ctor (bar)', where 'foo' is of type 'Foo'.
Expression ml = MemberLookupFinal (ec, type, type, ".ctor",
MemberTypes.Constructor, AllBindingFlags | BindingFlags.DeclaredOnly, loc);
MethodGroupExpr mg = ml as MethodGroupExpr;
if (mg == null) {
- ml.Error_UnexpectedKind (ec, "method group", loc);
+ ml.Error_UnexpectedKind (ec.DeclContainer, "method group", loc);
return null;
}
method = Invocation.OverloadResolve (ec, mg, Arguments, false, loc);
if (method == null) {
if (almostMatchedMembers.Count != 0)
- MemberLookupFailed (ec, type, type, ".ctor", null, true, loc);
+ MemberLookupFailed (ec.ContainerType, type, type, ".ctor", null, true, loc);
return null;
}
public bool ValidateInitializers (EmitContext ec, Type array_type)
{
if (initializers == null) {
- if (expect_initializers)
- return false;
- else
- return true;
+ return !expect_initializers;
}
if (underlying_type == null)
array_data = new ArrayList ();
bounds = new Hashtable ();
- bool ret;
-
if (arguments != null) {
- ret = CheckIndices (ec, initializers, 0, true);
- return ret;
+ return CheckIndices (ec, initializers, 0, true);
} else {
arguments = new ArrayList ();
- ret = CheckIndices (ec, initializers, 0, false);
-
- if (!ret)
+ if (!CheckIndices (ec, initializers, 0, false))
return false;
UpdateIndices (ec);
return false;
}
- return ret;
+ return true;
}
}
//
TypeExpr array_type_expr;
array_type_expr = new ComposedCast (requested_base_type, array_qualifier.ToString (), loc);
- array_type_expr = array_type_expr.ResolveAsTypeTerminal (ec);
+ array_type_expr = array_type_expr.ResolveAsTypeTerminal (ec, false);
if (array_type_expr == null)
return false;
- type = array_type_expr.ResolveType (ec);
+ type = array_type_expr.Type;
underlying_type = TypeManager.GetElementType (type);
dimensions = type.GetArrayRank ();
if (is_builtin_type) {
Expression ml;
- ml = MemberLookup (ec, type, ".ctor", MemberTypes.Constructor,
+ ml = MemberLookup (ec.ContainerType, type, ".ctor", MemberTypes.Constructor,
AllBindingFlags, loc);
if (!(ml is MethodGroupExpr)) {
- ml.Error_UnexpectedKind (ec, "method group", loc);
+ ml.Error_UnexpectedKind (ec.DeclContainer, "method group", loc);
return null;
}
// This will never be true for array types that cannot be statically
// initialized. num_automatic_initializers will always be zero. See
// CheckIndices.
- if (num_automatic_initializers > max_automatic_initializers)
- EmitStaticInitializers (ec);
+ if (num_automatic_initializers > max_automatic_initializers)
+ EmitStaticInitializers (ec);
if (dynamic_initializers)
EmitDynamicInitializers (ec);
}
}
-
- public object EncodeAsAttribute ()
+
+ public override bool GetAttributableValue (out object value)
{
if (!is_one_dimensional){
- Report.Error (-211, Location, "attribute can not encode multi-dimensional arrays");
- return null;
+// Report.Error (-211, Location, "attribute can not encode multi-dimensional arrays");
+ return base.GetAttributableValue (out value);
}
- if (array_data == null){
- Report.Error (-212, Location, "array should be initialized when passing it to an attribute");
- return null;
+ if (array_data == null) {
+ Constant c = (Constant)((Argument)arguments [0]).Expr;
+ if (c.IsDefaultValue) {
+ value = new object [0];
+ return true;
+ }
+// Report.Error (-212, Location, "array should be initialized when passing it to an attribute");
+ return base.GetAttributableValue (out value);
}
object [] ret = new object [array_data.Count];
- int i = 0;
- foreach (Expression e in array_data){
- object v;
-
- if (e is NullLiteral)
- v = null;
- else {
- if (!Attribute.GetAttributeArgumentExpression (e, Location, array_element_type, out v))
- return null;
+ for (int i = 0; i < ret.Length; ++i)
+ {
+ if (!((Expression)array_data [i]).GetAttributableValue (out ret [i])) {
+ value = null;
+ return false;
}
- ret [i++] = v;
}
- return ret;
+ value = ret;
+ return true;
}
}
/// Implements the typeof operator
/// </summary>
public class TypeOf : Expression {
- public Expression QueriedType;
+ readonly Expression QueriedType;
protected Type typearg;
public TypeOf (Expression queried_type, Location l)
public override Expression DoResolve (EmitContext ec)
{
- TypeExpr texpr = QueriedType.ResolveAsTypeTerminal (ec);
+ TypeExpr texpr = QueriedType.ResolveAsTypeTerminal (ec, false);
if (texpr == null)
return null;
- typearg = texpr.ResolveType (ec);
+ typearg = texpr.Type;
if (typearg == TypeManager.void_type) {
Error (673, "System.Void cannot be used from C#. Use typeof (void) to get the void type object");
ec.ig.Emit (OpCodes.Call, TypeManager.system_type_get_type_from_handle);
}
- public Type TypeArg {
- get { return typearg; }
+ public override bool GetAttributableValue (out object value)
+ {
+ value = typearg;
+ return true;
}
}
public override Expression DoResolve (EmitContext ec)
{
- TypeExpr texpr = QueriedType.ResolveAsTypeTerminal (ec);
+ TypeExpr texpr = QueriedType.ResolveAsTypeTerminal (ec, false);
if (texpr == null)
return null;
return null;
}
- type_queried = texpr.ResolveType (ec);
+ type_queried = texpr.Type;
int size_of = GetTypeSize (type_queried);
if (size_of > 0) {
loc = l;
}
- public override FullNamedExpression ResolveAsTypeStep (EmitContext ec, bool silent)
+ public override FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
{
if (alias == "global")
return new MemberAccess (RootNamespace.Global, identifier, loc).ResolveAsTypeStep (ec, silent);
int errors = Report.Errors;
- FullNamedExpression fne = ec.DeclSpace.NamespaceEntry.LookupAlias (alias);
+ FullNamedExpression fne = ec.DeclContainer.NamespaceEntry.LookupAlias (alias);
if (fne == null) {
if (errors == Report.Errors)
Report.Error (432, loc, "Alias `{0}' not found", alias);
fne = RootNamespace.Global;
} else {
int errors = Report.Errors;
- fne = ec.DeclSpace.NamespaceEntry.LookupAlias (alias);
+ fne = ec.DeclContainer.NamespaceEntry.LookupAlias (alias);
if (fne == null) {
if (errors == Report.Errors)
Report.Error (432, loc, "Alias `{0}' not found", alias);
if (new_expr is Namespace) {
Namespace ns = (Namespace) new_expr;
string lookup_id = MemberName.MakeName (Identifier, args);
- FullNamedExpression retval = ns.Lookup (ec.DeclSpace, lookup_id, loc);
+ FullNamedExpression retval = ns.Lookup (ec.DeclContainer, lookup_id, loc);
if ((retval != null) && (args != null))
- retval = new ConstructedType (retval, args, loc).ResolveAsTypeStep (ec);
+ retval = new ConstructedType (retval, args, loc).ResolveAsTypeStep (ec, false);
if (retval == null)
Report.Error (234, loc, "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
Identifier, ns.FullName);
Expression member_lookup;
member_lookup = MemberLookup (
- ec, expr_type, expr_type, Identifier, loc);
+ ec.ContainerType, expr_type, expr_type, Identifier, loc);
if ((member_lookup == null) && (args != null)) {
string lookup_id = MemberName.MakeName (Identifier, args);
member_lookup = MemberLookup (
- ec, expr_type, expr_type, lookup_id, loc);
+ ec.ContainerType, expr_type, expr_type, lookup_id, loc);
}
if (member_lookup == null) {
MemberLookupFailed (
- ec, expr_type, expr_type, Identifier, null, true, loc);
+ ec.ContainerType, expr_type, expr_type, Identifier, null, true, loc);
return null;
}
ct = new ConstructedType (
member_lookup.Type, ct.TypeArguments, loc);
- return ct.ResolveAsTypeStep (ec);
+ return ct.ResolveAsTypeStep (ec, false);
}
return member_lookup;
return DoResolve (ec, right_side);
}
- public override FullNamedExpression ResolveAsTypeStep (EmitContext ec, bool silent)
+ public override FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
{
return ResolveNamespaceOrType (ec, silent);
}
- public FullNamedExpression ResolveNamespaceOrType (EmitContext ec, bool silent)
+ public FullNamedExpression ResolveNamespaceOrType (IResolveContext rc, bool silent)
{
- FullNamedExpression new_expr = expr.ResolveAsTypeStep (ec, silent);
+ FullNamedExpression new_expr = expr.ResolveAsTypeStep (rc, silent);
if (new_expr == null)
return null;
if (new_expr is Namespace) {
Namespace ns = (Namespace) new_expr;
- FullNamedExpression retval = ns.Lookup (ec.DeclSpace, lookup_id, loc);
+ FullNamedExpression retval = ns.Lookup (rc.DeclContainer, lookup_id, loc);
if ((retval != null) && (args != null))
- retval = new ConstructedType (retval, args, loc).ResolveAsTypeStep (ec);
+ retval = new ConstructedType (retval, args, loc).ResolveAsTypeStep (rc, false);
if (!silent && retval == null)
Report.Error (234, loc, "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
Identifier, ns.FullName);
return retval;
}
- TypeExpr tnew_expr = new_expr.ResolveAsTypeTerminal (ec);
+ TypeExpr tnew_expr = new_expr.ResolveAsTypeTerminal (rc, false);
if (tnew_expr == null)
return null;
- Type expr_type = tnew_expr.ResolveType (ec);
+ Type expr_type = tnew_expr.Type;
if (expr_type.IsPointer){
Error (23, "The `.' operator can not be applied to pointer operands (" +
}
Expression member_lookup = MemberLookup (
- ec, ec.ContainerType, expr_type, expr_type, lookup_id,
+ rc.DeclContainer.TypeBuilder, expr_type, expr_type, lookup_id,
MemberTypes.NestedType, BindingFlags.Public | BindingFlags.NonPublic, loc);
if (member_lookup == null) {
int errors = Report.Errors;
- MemberLookupFailed (ec, expr_type, expr_type, lookup_id, null, false, loc);
+ MemberLookupFailed (rc.DeclContainer.TypeBuilder, expr_type, expr_type, lookup_id, null, false, loc);
if (!silent && errors == Report.Errors) {
Report.Error (426, loc, "The nested type `{0}' does not exist in the type `{1}'",
}
if (!(member_lookup is TypeExpr)) {
- new_expr.Error_UnexpectedKind (ec, "type", loc);
+ new_expr.Error_UnexpectedKind (rc.DeclContainer, "type", loc);
return null;
}
- TypeExpr texpr = member_lookup.ResolveAsTypeTerminal (ec);
+ TypeExpr texpr = member_lookup.ResolveAsTypeTerminal (rc, false);
if (texpr == null)
return null;
if (the_args != null) {
ConstructedType ctype = new ConstructedType (texpr.Type, the_args, loc);
- return ctype.ResolveAsTypeStep (ec);
+ return ctype.ResolveAsTypeStep (rc, false);
}
return texpr;
ig.Emit (OpCodes.Ldelema, type);
ig.Emit (OpCodes.Ldobj, type);
} else if (type.IsGenericParameter)
+#if MS_COMPATIBLE
+ ig.Emit (OpCodes.Ldelem, type);
+#else
ig.Emit (OpCodes.Ldelem_Any, type);
+#endif
else if (type.IsPointer)
ig.Emit (OpCodes.Ldelem_I);
else
return OpCodes.Stobj;
} else if (t.IsGenericParameter) {
has_type_arg = true;
+#if MS_COMPATIBLE
+ return OpCodes.Stelem;
+#else
return OpCodes.Stelem_Any;
+#endif
+
} else if (t.IsPointer)
return OpCodes.Stelem_I;
else
/// The base operator for method names
/// </summary>
public class BaseAccess : Expression {
- string member;
+ public readonly string Identifier;
+ TypeArguments args;
- public BaseAccess (string member, Location l)
+ public BaseAccess (string member, TypeArguments args, Location l)
{
- this.member = member;
+ this.Identifier = member;
+ this.args = args;
loc = l;
}
return null;
}
- member_lookup = MemberLookup (ec, ec.ContainerType, null, base_type,
- member, AllMemberTypes, AllBindingFlags,
- loc);
+ member_lookup = MemberLookup (ec.ContainerType, null, base_type, Identifier,
+ AllMemberTypes, AllBindingFlags, loc);
if (member_lookup == null) {
- MemberLookupFailed (ec, base_type, base_type, member, null, true, loc);
+ MemberLookupFailed (ec.ContainerType, base_type, base_type, Identifier, null, true, loc);
return null;
}
pe.IsBase = true;
}
- if (e is MethodGroupExpr)
- ((MethodGroupExpr) e).IsBase = true;
+ MethodGroupExpr mg = e as MethodGroupExpr;
+ if (mg != null)
+ mg.IsBase = true;
+
+ if (args != null) {
+ if (mg != null)
+ return mg.ResolveGeneric (ec, args);
+
+ Report.Error (307, loc, "`{0}' cannot be used with type arguments",
+ Identifier);
+ return null;
+ }
return e;
}
return this;
}
- protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
+ protected override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
{
- TypeExpr lexpr = left.ResolveAsTypeTerminal (ec);
+ TypeExpr lexpr = left.ResolveAsTypeTerminal (ec, false);
if (lexpr == null)
return null;
- bool old = ec.TestObsoleteMethodUsage;
- ec.TestObsoleteMethodUsage = false;
- Type ltype = lexpr.ResolveType (ec);
- ec.TestObsoleteMethodUsage = old;
-
+ Type ltype = lexpr.Type;
if ((ltype == TypeManager.void_type) && (dim != "*")) {
Report.Error (1547, Location,
"Keyword 'void' cannot be used in this context");
TypeExpr nullable = new NullableType (left, loc);
if (dim.Length > 1)
nullable = new ComposedCast (nullable, dim.Substring (1), loc);
- return nullable.ResolveAsTypeTerminal (ec);
+ return nullable.ResolveAsTypeTerminal (ec, false);
}
if (dim == "*" && !TypeManager.VerifyUnManaged (ltype, loc)) {
throw new InternalErrorException ("Couldn't create computed type " + ltype + dim);
}
- if (!ec.InUnsafe && type.IsPointer){
+ if (type.IsPointer && !ec.IsInUnsafeScope){
UnsafeError (loc);
return null;
}
return null;
}
- TypeExpr texpr = t.ResolveAsTypeTerminal (ec);
+ TypeExpr texpr = t.ResolveAsTypeTerminal (ec, false);
if (texpr == null)
return null;
- otype = texpr.ResolveType (ec);
+ otype = texpr.Type;
if (!TypeManager.VerifyUnManaged (otype, loc))
return null;