Пример #1
0
		FullNamedExpression ResolveMemberName (IMemberContext context, MemberName mn)
		{
			if (mn.Left == null)
				return context.LookupNamespaceOrType (mn.Name, mn.Arity, LookupMode.Probing, Location.Null);

			var left = ResolveMemberName (context, mn.Left);
			var ns = left as Namespace;
			if (ns != null)
				return ns.LookupTypeOrNamespace (context, mn.Name, mn.Arity, LookupMode.Probing, Location.Null);

			TypeExpr texpr = left as TypeExpr;
			if (texpr != null) {
				var found = MemberCache.FindNestedType (texpr.Type, ParsedName.Name, ParsedName.Arity);
				if (found != null)
					return new TypeExpression (found, Location.Null);

				return null;
			}

			return left;
		}
Пример #2
0
        public override FullNamedExpression ResolveAsTypeStep(IMemberContext ec, bool silent)
        {
            int errors = ec.Compiler.Report.Errors;
            FullNamedExpression fne = ec.LookupNamespaceOrType (Name, Arity, loc, /*ignore_cs0104=*/ false);

            if (fne != null) {
                if (HasTypeArguments && fne.Type != null && TypeManager.IsGenericType (fne.Type)) {
                    GenericTypeExpr ct = new GenericTypeExpr (fne.Type, targs, loc);
                    return ct.ResolveAsTypeStep (ec, false);
                }

                return fne;
            }

            if (!HasTypeArguments && Name == "dynamic" &&
                RootContext.Version > LanguageVersion.V_3 &&
                RootContext.MetadataCompatibilityVersion > MetadataVersion.v2) {

                if (!PredefinedAttributes.Get.Dynamic.IsDefined) {
                    ec.Compiler.Report.Error (1980, Location,
                        "Dynamic keyword requires `{0}' to be defined. Are you missing System.Core.dll assembly reference?",
                        PredefinedAttributes.Get.Dynamic.GetSignatureForError ());
                }

                return new DynamicTypeExpr (loc);
            }

            if (silent || errors != ec.Compiler.Report.Errors)
                return null;

            Error_TypeOrNamespaceNotFound (ec);
            return null;
        }
Пример #3
0
        protected virtual void Error_TypeOrNamespaceNotFound(IMemberContext ec)
        {
            if (ec.CurrentType != null) {
                if (ec.CurrentMemberDefinition != null) {
                    MemberCore mc = ec.CurrentMemberDefinition.Parent.GetDefinition (Name);
                    if (mc != null) {
                        Error_UnexpectedKind (ec.Compiler.Report, mc, "type", GetMemberType (mc), loc);
                        return;
                    }
                }

                /*
                                // TODO MemberCache: Implement

                                string ns = ec.CurrentType.Namespace;
                                string fullname = (ns.Length > 0) ? ns + "." + Name : Name;
                                foreach (Assembly a in GlobalRootNamespace.Instance.Assemblies) {
                                    var type = a.GetType (fullname);
                                    if (type != null) {
                                        ec.Compiler.Report.SymbolRelatedToPreviousError (type);
                                        Expression.ErrorIsInaccesible (loc, TypeManager.CSharpName (type), ec.Compiler.Report);
                                        return;
                                    }
                                }

                                if (ec.CurrentTypeDefinition != null) {
                                    TypeSpec t = ec.CurrentTypeDefinition.LookupAnyGeneric (Name);
                                    if (t != null) {
                                        Namespace.Error_InvalidNumberOfTypeArguments (ec.Compiler.Report, t, loc);
                                        return;
                                    }
                                }
                */
            }

            FullNamedExpression retval = ec.LookupNamespaceOrType (Name, -System.Math.Max (1, Arity), loc, true);
            if (retval != null) {
                Error_TypeArgumentsCannotBeUsed (ec.Compiler.Report, loc, retval.Type, Arity);
            /*
                var te = retval as TypeExpr;
                if (HasTypeArguments && te != null && !te.Type.IsGeneric)
                    retval.Error_TypeArgumentsCannotBeUsed (ec.Compiler.Report, loc);
                else
                    Namespace.Error_InvalidNumberOfTypeArguments (ec.Compiler.Report, retval.Type, loc);
            */
                return;
            }

            NamespaceEntry.Error_NamespaceNotFound (loc, Name, ec.Compiler.Report);
        }
Пример #4
0
		FullNamedExpression ResolveMemberName (IMemberContext context, MemberName mn)
		{
			// FIXME: Default namespace lookups to C# resolution semantics (for now).  Need a way to determine if PlayScript absolute
			// namespace lookups should be used here.
			bool absolute_ns = false;

			if (mn.Left == null)
				return context.LookupNamespaceOrType (mn.Name, mn.Arity, LookupMode.Probing, absolute_ns, Location.Null);

			var left = ResolveMemberName (context, mn.Left);
			var ns = left as Namespace;
			if (ns != null)
				return ns.LookupTypeOrNamespace (context, mn.Name, mn.Arity, LookupMode.Probing, Location.Null);

			TypeExpr texpr = left as TypeExpr;
			if (texpr != null) {
				var found = MemberCache.FindNestedType (texpr.Type, ParsedName.Name, ParsedName.Arity);
				if (found != null)
					return new TypeExpression (found, Location.Null);

				return null;
			}

			return left;
		}
Пример #5
0
        public bool IdenticalNameAndTypeName(IMemberContext mc, Expression resolved_to, Location loc)
        {
            if (resolved_to == null || resolved_to.Type == null)
                return false;

            if (resolved_to.Type is ElementTypeSpec || resolved_to.Type is InternalType)
                return false;

            return resolved_to.Type.Name == Name &&
                (mc.LookupNamespaceOrType (Name, Arity, loc, /* ignore_cs0104 = */ true) != null);
        }
Пример #6
0
		protected virtual void Error_TypeOrNamespaceNotFound (IMemberContext ec)
		{
			if (ec.CurrentType != null) {
				if (ec.CurrentTypeDefinition != null) {
					MemberCore mc = ec.CurrentTypeDefinition.GetDefinition (Name);
					if (mc != null) {
						Error_UnexpectedKind (ec.Compiler.Report, mc, "type", GetMemberType (mc), loc);
						return;
					}
				}

				string ns = ec.CurrentType.Namespace;
				string fullname = (ns.Length > 0) ? ns + "." + Name : Name;
				foreach (Assembly a in GlobalRootNamespace.Instance.Assemblies) {
					Type type = a.GetType (fullname);
					if (type != null) {
						ec.Compiler.Report.SymbolRelatedToPreviousError (type);
						Expression.ErrorIsInaccesible (loc, TypeManager.CSharpName (type), ec.Compiler.Report);
						return;
					}
				}

				if (ec.CurrentTypeDefinition != null) {
					Type t = ec.CurrentTypeDefinition.LookupAnyGeneric (Name);
					if (t != null) {
						Namespace.Error_InvalidNumberOfTypeArguments (t, loc);
						return;
					}
				}
			}

			if (targs != null) {
				FullNamedExpression retval = ec.LookupNamespaceOrType (SimpleName.RemoveGenericArity (Name), loc, true);
				if (retval != null) {
					Namespace.Error_TypeArgumentsCannotBeUsed (retval, loc);
					return;
				}
			}
						
			NamespaceEntry.Error_NamespaceNotFound (loc, Name, ec.Compiler.Report);
		}
Пример #7
0
		public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent)
		{
			int errors = ec.Compiler.Report.Errors;
			FullNamedExpression fne = ec.LookupNamespaceOrType (Name, loc, /*ignore_cs0104=*/ false);

			if (fne != null) {
				if (fne.Type == null)
					return fne;

				FullNamedExpression nested = ResolveNested (fne.Type);
				if (nested != null)
					return nested.ResolveAsTypeStep (ec, false);

				if (targs != null) {
					if (TypeManager.IsGenericType (fne.Type)) {
						GenericTypeExpr ct = new GenericTypeExpr (fne.Type, targs, loc);
						return ct.ResolveAsTypeStep (ec, false);
					}

					Namespace.Error_TypeArgumentsCannotBeUsed (fne, loc);
				}

				return fne;
			}

			if (!HasTypeArguments && Name == "dynamic" && RootContext.Version > LanguageVersion.V_3)
				return new DynamicTypeExpr (loc);

			if (silent || errors != ec.Compiler.Report.Errors)
				return null;

			Error_TypeOrNamespaceNotFound (ec);
			return null;
		}
Пример #8
0
		public bool IdenticalNameAndTypeName (IMemberContext mc, Expression resolved_to, Location loc)
		{
			return resolved_to != null && resolved_to.Type != null && 
				resolved_to.Type.Name == Name &&
				(mc.LookupNamespaceOrType (Name, loc, /* ignore_cs0104 = */ true) != null);
		}
Пример #9
0
 public FullNamedExpression LookupNamespaceOrType(string name, int arity, LookupMode mode, Location loc)
 {
     return(MemberContext.LookupNamespaceOrType(name, arity, mode, loc));
 }
Пример #10
0
 public FullNamedExpression LookupNamespaceOrType(string name, int arity, Location loc, bool ignore_cs0104)
 {
     return(MemberContext.LookupNamespaceOrType(name, arity, loc, ignore_cs0104));
 }