+2009-07-10 Marek Safar <marek.safar@gmail.com>
+
+ * typemanager.cs, lambda.cs, parameter.cs, convert.cs, anonymous.cs,
+ expression.cs, literal.cs, ecore.cs, complete.cs: Moved internal
+ types to new class.
+
+ * support.cs: New dynamic type wrapper.
+
2009-07-08 Marek Safar <marek.safar@gmail.com>
* ecore.cs, cs-parser.jay: Better error reporting for implicitly
// anywhere', we depend on special conversion
// rules.
//
- type = TypeManager.anonymous_method_type;
+ type = InternalType.AnonymousMethod;
if ((Parameters != null) && !Parameters.Resolve (ec))
return null;
return null;
Type expr_type = expr_resolved.Type;
- if (expr_type.IsPointer || expr_type == TypeManager.void_type || expr_type == TypeManager.null_type || expr_type == TypeManager.anonymous_method_type) {
+ if (expr_type.IsPointer || expr_type == TypeManager.void_type || expr_type == TypeManager.null_type || expr_type == InternalType.AnonymousMethod) {
Unary.Error_OperatorCannotBeApplied (loc, ".", expr_type);
return null;
}
// from the null type to any reference-type.
if (expr_type == TypeManager.null_type)
- return target_type != TypeManager.anonymous_method_type;
+ return target_type != InternalType.AnonymousMethod;
if (TypeManager.IsGenericParameter (expr_type))
return ImplicitTypeParameterConversion (expr, target_type) != null;
if (ImplicitStandardConversionExists (expr, target_type))
return true;
- if (expr.Type == TypeManager.anonymous_method_type) {
+ if (expr.Type == InternalType.AnonymousMethod) {
if (!TypeManager.IsDelegateType (target_type) &&
TypeManager.DropGenericTypeArguments (target_type) != TypeManager.expression_type)
return false;
return true;
// Conversion from __arglist to System.ArgIterator
- if (expr_type == typeof (ArglistAccess))
+ if (expr_type == InternalType.Arglist)
return target_type == TypeManager.arg_iterator_type;
return false;
Expression e;
if (expr_type.Equals (target_type)) {
- if (expr_type != TypeManager.null_type && expr_type != TypeManager.anonymous_method_type)
+ if (expr_type != TypeManager.null_type && expr_type != InternalType.AnonymousMethod)
return expr;
return null;
}
return EmptyCast.Create (new NullPointer (loc), target_type);
}
- if (expr_type == TypeManager.anonymous_method_type){
+ if (expr_type == InternalType.AnonymousMethod){
AnonymousMethodExpression ame = (AnonymousMethodExpression) expr;
Expression am = ame.Compatible (ec, target_type);
if (am != null)
return am.DoResolve (ec);
}
- if (expr_type == typeof (ArglistAccess) && target_type == TypeManager.arg_iterator_type)
+ if (expr_type == InternalType.Arglist && target_type == TypeManager.arg_iterator_type)
return expr;
return null;
protected void Error_ValueCannotBeConvertedCore (EmitContext ec, Location loc, Type target, bool expl)
{
// The error was already reported as CS1660
- if (type == TypeManager.anonymous_method_type)
+ if (type == InternalType.AnonymousMethod)
return;
if (TypeManager.IsGenericParameter (Type) && TypeManager.IsGenericParameter (target) && type.Name == target.Name) {
{
this.loc = loc;
eclass = ExprClass.MethodGroup;
- this.type = typeof (MethodGroupExpr);
+ this.type = InternalType.MethodGroup;
queried_type = type;
}
static int BetterExpressionConversion (EmitContext ec, Argument a, Type p, Type q)
{
Type argument_type = TypeManager.TypeToCoreType (a.Type);
- if (argument_type == TypeManager.anonymous_method_type && RootContext.Version > LanguageVersion.ISO_2) {
+ if (argument_type == InternalType.AnonymousMethod && RootContext.Version > LanguageVersion.ISO_2) {
//
// Uwrap delegate from Expression<T>
//
/// Handles `var' contextual keyword; var becomes a keyword only
/// if no type called var exists in a variable scope
///
- public class VarExpr : SimpleName
+ class VarExpr : SimpleName
{
// Used for error reporting only
ArrayList initializer;
throw new InternalErrorException ("An implicitly typed local variable could not be redefined");
type = right_side.Type;
- if (type == TypeManager.null_type || type == TypeManager.void_type || type == TypeManager.anonymous_method_type) {
+ if (type == TypeManager.null_type || type == TypeManager.void_type || type == InternalType.AnonymousMethod) {
Report.Error (815, loc, "An implicitly typed local variable declaration cannot be initialized with `{0}'",
right_side.GetSignatureForError ());
return false;
protected override void Error_TypeOrNamespaceNotFound (IResolveContext ec)
{
- Report.Error (825, loc, "The contextual keyword `var' may only appear within a local variable declaration");
+ if (RootContext.Version < LanguageVersion.V_3)
+ base.Error_TypeOrNamespaceNotFound (ec);
+ else
+ Report.Error (825, loc, "The contextual keyword `var' may only appear within a local variable declaration");
}
public override TypeExpr ResolveAsContextualType (IResolveContext rc, bool silent)
return null;
}
- if (expr.Type == TypeManager.anonymous_method_type) {
+ if (expr.Type == InternalType.AnonymousMethod) {
Report.Error (837, loc, "The `{0}' operator cannot be applied to a lambda expression or anonymous method",
OperatorName);
return null;
bool is_equality = (oper & Operator.EqualityMask) != 0;
if (!TypeManager.IsEqual (l, r) && !TypeManager.IsVariantOf (r, l)) {
Expression tmp;
- if (right.eclass == ExprClass.MethodGroup || (r == TypeManager.anonymous_method_type && !is_equality)) {
+ if (right.eclass == ExprClass.MethodGroup || (r == InternalType.AnonymousMethod && !is_equality)) {
tmp = Convert.ImplicitConversionRequired (ec, right, l, loc);
if (tmp == null)
return null;
right = tmp;
r = right.Type;
- } else if (left.eclass == ExprClass.MethodGroup || (l == TypeManager.anonymous_method_type && !is_equality)) {
+ } else if (left.eclass == ExprClass.MethodGroup || (l == InternalType.AnonymousMethod && !is_equality)) {
tmp = Convert.ImplicitConversionRequired (ec, left, r, loc);
if (tmp == null)
return null;
return null;
}
- if (l == TypeManager.anonymous_method_type)
+ if (l == InternalType.AnonymousMethod)
return null;
if (TypeManager.IsValueType (l))
return null;
if (array_element_type == null || array_element_type == TypeManager.null_type ||
- array_element_type == TypeManager.void_type || array_element_type == TypeManager.anonymous_method_type ||
+ array_element_type == TypeManager.void_type || array_element_type == InternalType.AnonymousMethod ||
arguments.Count != dimensions) {
Error_NoBestType ();
return null;
public override Expression DoResolve (EmitContext ec)
{
eclass = ExprClass.Variable;
- type = typeof (ArglistAccess);
+ type = InternalType.Arglist;
if (Arguments != null)
Arguments.Resolve (ec);
Type expr_type = expr_resolved.Type;
if (expr_type.IsPointer || expr_type == TypeManager.void_type ||
- expr_type == TypeManager.null_type || expr_type == TypeManager.anonymous_method_type) {
+ expr_type == TypeManager.null_type || expr_type == InternalType.AnonymousMethod) {
Unary.Error_OperatorCannotBeApplied (loc, ".", expr_type);
return null;
}
type = e.Type;
if (type == TypeManager.void_type || type == TypeManager.null_type ||
- type == TypeManager.anonymous_method_type || type.IsPointer) {
+ type == InternalType.AnonymousMethod || type.IsPointer) {
Error_InvalidInitializer (e.GetSignatureForError ());
return null;
}
}
eclass = ExprClass.Value;
- type = TypeManager.anonymous_method_type;
+ type = InternalType.AnonymousMethod;
return this;
}
}
// Exlude internal compiler types
- if (targetType == TypeManager.anonymous_method_type)
+ if (targetType == InternalType.AnonymousMethod)
return null;
if (type != TypeManager.null_type && !Convert.ImplicitStandardConversionExists (this, targetType))
public override Type Resolve (IResolveContext ec)
{
- return typeof (ArglistAccess);
+ return InternalType.Arglist;
}
public override string GetSignatureForError ()
if (varargs != 0) {
par [par.Length - 1] = new ArglistParameter (Location.Null);
- types [types.Length - 1] = typeof (ArglistAccess);
+ types [types.Length - 1] = InternalType.Arglist;
}
return method != null ?
}
}
+ class DynamicType : Type
+ {
+ public override Assembly Assembly {
+ get { throw new NotImplementedException (); }
+ }
+
+ public override string AssemblyQualifiedName {
+ get { throw new NotImplementedException (); }
+ }
+
+ public override Type BaseType {
+ get { return null; }
+ }
+
+ public override string FullName {
+ get { return UnderlyingSystemType.FullName; }
+ }
+
+ public override Guid GUID {
+ get { throw new NotImplementedException (); }
+ }
+
+ protected override TypeAttributes GetAttributeFlagsImpl ()
+ {
+ return UnderlyingSystemType.Attributes;
+ }
+
+ protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override Type GetElementType ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override EventInfo[] GetEvents (BindingFlags bindingAttr)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override FieldInfo GetField (string name, BindingFlags bindingAttr)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override FieldInfo[] GetFields (BindingFlags bindingAttr)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override Type GetInterface (string name, bool ignoreCase)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override Type[] GetInterfaces ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
+ {
+ throw new NotImplementedException ();
+ }
+
+ protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override Type GetNestedType (string name, BindingFlags bindingAttr)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override Type[] GetNestedTypes (BindingFlags bindingAttr)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
+ {
+ throw new NotImplementedException ();
+ }
+
+ protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
+ {
+ throw new NotImplementedException ();
+ }
+
+ protected override bool HasElementTypeImpl ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] namedParameters)
+ {
+ throw new NotImplementedException ();
+ }
+
+ protected override bool IsArrayImpl ()
+ {
+ return false;
+ }
+
+ protected override bool IsByRefImpl ()
+ {
+ return false;
+ }
+
+ protected override bool IsCOMObjectImpl ()
+ {
+ return false;
+ }
+
+ protected override bool IsPointerImpl ()
+ {
+ return false;
+ }
+
+ protected override bool IsPrimitiveImpl ()
+ {
+ return false;
+ }
+
+ public override Module Module {
+ get { return UnderlyingSystemType.Module; }
+ }
+
+ public override string Namespace {
+ get { throw new NotImplementedException (); }
+ }
+
+ public override Type UnderlyingSystemType {
+ get { return TypeManager.object_type; }
+ }
+
+ public override object[] GetCustomAttributes (Type attributeType, bool inherit)
+ {
+ return new object [0];
+ }
+
+ public override object[] GetCustomAttributes (bool inherit)
+ {
+ return new object [0];
+ }
+
+ public override bool IsDefined (Type attributeType, bool inherit)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override string Name {
+ get { return UnderlyingSystemType.Name; }
+ }
+
+ public override string ToString ()
+ {
+ return GetType ().ToString ();
+ }
+
+ public override RuntimeTypeHandle TypeHandle {
+ get { return UnderlyingSystemType.TypeHandle; }
+ }
+ }
+
public class UnixUtils {
[System.Runtime.InteropServices.DllImport ("libc", EntryPoint="isatty")]
extern static int _isatty (int fd);
static public Type void_ptr_type;
static public Type exception_type;
- static public Type anonymous_method_type;
static public Type typed_reference_type;
static public Type arg_iterator_type;
static public Type mbr_type;
//
// These are only used for compare purposes
//
- anonymous_method_type = typeof (AnonymousMethodBody);
null_type = typeof (NullLiteral);
void_ptr_type = GetPointerType (void_type);
return a.FullName == b.FullName;
// Some types are never equal
- if (a == TypeManager.null_type || a == TypeManager.anonymous_method_type)
+ if (a == TypeManager.null_type || a == InternalType.AnonymousMethod)
return false;
return true;
}
+ class InternalType
+ {
+ public static readonly Type AnonymousMethod = typeof (AnonymousMethodBody);
+ public static readonly Type Arglist = typeof (ArglistAccess);
+ public static readonly Type Dynamic = new DynamicType ();
+ public static readonly Type MethodGroup = typeof (MethodGroupExpr);
+ }
+
/// <summary>
/// There is exactly one instance of this class per type.
/// </summary>