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;
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);
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 {
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;
}
// 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 ();
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)
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;
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);
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 (
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 (texpr == null)
return null;
- type = texpr.ResolveType (ec);
+ type = texpr.Type;
if (Arguments == null) {
Expression c = Constantify (type);
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;
}
}
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 ();
}
}
- 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)
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;
}
}
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);
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.DeclContainer, 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, false);
+ 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, false);
+ 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.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.ContainerType, 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.DeclContainer, "type", loc);
+ new_expr.Error_UnexpectedKind (rc.DeclContainer, "type", loc);
return null;
}
- TypeExpr texpr = member_lookup.ResolveAsTypeTerminal (ec, false);
+ 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, false);
+ return ctype.ResolveAsTypeStep (rc, false);
}
return texpr;
return this;
}
- protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
+ protected override TypeExpr DoResolveAsTypeStep (IResolveContext 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");
throw new InternalErrorException ("Couldn't create computed type " + ltype + dim);
}
- if (!ec.InUnsafe && type.IsPointer){
+ if (type.IsPointer && !ec.IsInUnsafeScope){
UnsafeError (loc);
return null;
}
if (texpr == null)
return null;
- otype = texpr.ResolveType (ec);
+ otype = texpr.Type;
if (!TypeManager.VerifyUnManaged (otype, loc))
return null;