Base representation for members. This is used to keep track of Name, Location and Modifier flags, and handling Attributes.
Наследование: Mono.CSharp.Attributable, IResolveContext
Пример #1
0
		XmlNode GetDocCommentNode (MemberCore mc, string name)
		{
			// FIXME: It could be even optimizable as not
			// to use XmlDocument. But anyways the nodes
			// are not kept in memory.
			XmlDocument doc = XmlDocumentation;
			try {
				XmlElement el = doc.CreateElement ("member");
				el.SetAttribute ("name", name);
				string normalized = mc.DocComment;
				el.InnerXml = normalized;
				// csc keeps lines as written in the sources
				// and inserts formatting indentation (which 
				// is different from XmlTextWriter.Formatting
				// one), but when a start tag contains an 
				// endline, it joins the next line. We don't
				// have to follow such a hacky behavior.
				string [] split =
					normalized.Split ('\n');
				int j = 0;
				for (int i = 0; i < split.Length; i++) {
					string s = split [i].TrimEnd ();
					if (s.Length > 0)
						split [j++] = s;
				}
				el.InnerXml = line_head + String.Join (
					line_head, split, 0, j);
				return el;
			} catch (Exception ex) {
				Report.Warning (1570, 1, mc.Location, "XML documentation comment on `{0}' is not well-formed XML markup ({1})",
					mc.GetSignatureForError (), ex.Message);

				return doc.CreateComment (String.Format ("FIXME: Invalid documentation markup was found for member {0}", name));
			}
		}
Пример #2
0
		// TODO: merge method and mb
		public ReturnParameter (MemberCore method, MethodBuilder mb, Location location)
		{
			this.method = method;
			try {
				builder = mb.DefineParameter (0, ParameterAttributes.None, "");			
			}
			catch (ArgumentOutOfRangeException) {
				method.Compiler.Report.RuntimeMissingSupport (location, "custom attributes on the return type");
			}
		}
Пример #3
0
		XmlNode GetDocCommentNode (MemberCore mc, string name)
		{
			// FIXME: It could be even optimizable as not
			// to use XmlDocument. But anyways the nodes
			// are not kept in memory.
			XmlDocument doc = XmlDocumentation;
			try {
				XmlElement el = doc.CreateElement ("member");
				el.SetAttribute ("name", name);
				string normalized = mc.DocComment;
				el.InnerXml = normalized;

				string [] split = normalized.Split ('\n');
				el.InnerXml = line_head + String.Join (line_head, split);
				return el;
			} catch (Exception ex) {
				Report.Warning (1570, 1, mc.Location, "XML documentation comment on `{0}' is not well-formed XML markup ({1})",
					mc.GetSignatureForError (), ex.Message);

				return doc.CreateComment (String.Format ("FIXME: Invalid documentation markup was found for member {0}", name));
			}
		}
Пример #4
0
		public bool AddMember (MemberCore symbol)
		{
			return AddToContainer (symbol, symbol.MemberName.Basename);
		}
Пример #5
0
		public override bool EnableOverloadChecks (MemberCore overload)
		{
			if (overload is MethodCore) {
				caching_flags |= Flags.MethodOverloadsExist;
				return true;
			}

			// This can only happen with indexers and it will
			// be catched as indexer difference
			if (overload is AbstractPropertyEventMethod)
				return true;

			return false;
		}
Пример #6
0
        //
        // Processes "see" or "seealso" elements.
        // Checks cref attribute.
        //
        private static void HandleXrefCommon(MemberCore mc,
                                             DeclSpace ds, XmlElement xref, Report Report)
        {
            string cref = xref.GetAttribute("cref").Trim(wsChars);

            // when, XmlReader, "if (cref == null)"
            if (!xref.HasAttribute("cref"))
            {
                return;
            }
            if (cref.Length == 0)
            {
                Report.Warning(1001, 1, mc.Location, "Identifier expected");
            }
            // ... and continue until CS1584.
            else
            {
                // Additional symbols for < and > are allowed for easier XML typing
                cref = cref.Replace('{', '<').Replace('}', '>');
            }

            string signature;        // "x:" are stripped
            string name;             // method invokation "(...)" are removed
            string parameters;       // method parameter list

            // When it found '?:' ('T:' 'M:' 'F:' 'P:' 'E:' etc.),
            // MS ignores not only its member kind, but also
            // the entire syntax correctness. Nor it also does
            // type fullname resolution i.e. "T:List(int)" is kept
            // as T:List(int), not
            // T:System.Collections.Generic.List&lt;System.Int32&gt;
            if (cref.Length > 2 && cref [1] == ':')
            {
                return;
            }
            else
            {
                signature = cref;
            }

            // Also note that without "T:" any generic type
            // indication fails.

            int parens_pos = signature.IndexOf('(');
            int brace_pos  = parens_pos >= 0 ? -1 :
                             signature.IndexOf('[');

            if (parens_pos > 0 && signature [signature.Length - 1] == ')')
            {
                name       = signature.Substring(0, parens_pos).Trim(wsChars);
                parameters = signature.Substring(parens_pos + 1, signature.Length - parens_pos - 2).Trim(wsChars);
            }
            else if (brace_pos > 0 && signature [signature.Length - 1] == ']')
            {
                name       = signature.Substring(0, brace_pos).Trim(wsChars);
                parameters = signature.Substring(brace_pos + 1, signature.Length - brace_pos - 2).Trim(wsChars);
            }
            else
            {
                name       = signature;
                parameters = null;
            }
            Normalize(mc, ref name, Report);

            string identifier = GetBodyIdentifierFromName(name);

            // Check if identifier is valid.
            // This check is not necessary to mark as error, but
            // csc specially reports CS1584 for wrong identifiers.
            string [] name_elems = identifier.Split('.');
            for (int i = 0; i < name_elems.Length; i++)
            {
                string nameElem = GetBodyIdentifierFromName(name_elems [i]);
                if (i > 0)
                {
                    Normalize(mc, ref nameElem, Report);
                }
                if (!Tokenizer.IsValidIdentifier(nameElem) &&
                    nameElem.IndexOf("operator") < 0)
                {
                    Report.Warning(1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
                                   mc.GetSignatureForError(), cref);
                    xref.SetAttribute("cref", "!:" + signature);
                    return;
                }
            }

            // check if parameters are valid
            Type [] parameter_types;
            if (parameters == null)
            {
                parameter_types = null;
            }
            else if (parameters.Length == 0)
            {
                parameter_types = Type.EmptyTypes;
            }
            else
            {
                string [] param_list = parameters.Split(',');
                ArrayList plist      = new ArrayList();
                for (int i = 0; i < param_list.Length; i++)
                {
                    string param_type_name = param_list [i].Trim(wsChars);
                    Normalize(mc, ref param_type_name, Report);
                    Type param_type = FindDocumentedType(mc, param_type_name, ds, cref, Report);
                    if (param_type == null)
                    {
                        Report.Warning(1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'",
                                       (i + 1).ToString(), cref);
                        return;
                    }
                    plist.Add(param_type);
                }
                parameter_types = plist.ToArray(typeof(Type)) as Type [];
            }

            Type type = FindDocumentedType(mc, name, ds, cref, Report);

            if (type != null
                // delegate must not be referenced with args
                && (!TypeManager.IsDelegateType(type) ||
                    parameter_types == null))
            {
                string result = GetSignatureForDoc(type)
                                + (brace_pos < 0 ? String.Empty : signature.Substring(brace_pos));
                xref.SetAttribute("cref", "T:" + result);
                return;                 // a type
            }

            int period = name.LastIndexOf('.');

            if (period > 0)
            {
                string typeName    = name.Substring(0, period);
                string member_name = name.Substring(period + 1);
                Normalize(mc, ref member_name, Report);
                type = FindDocumentedType(mc, typeName, ds, cref, Report);
                int warn_result;
                if (type != null)
                {
                    FoundMember fm = FindDocumentedMember(mc, type, member_name, parameter_types, ds, out warn_result, cref, true, name, Report);
                    if (warn_result > 0)
                    {
                        return;
                    }
                    if (!fm.IsEmpty)
                    {
                        MemberInfo mi = fm.Member;
                        // we cannot use 'type' directly
                        // to get its name, since mi
                        // could be from DeclaringType
                        // for nested types.
                        xref.SetAttribute("cref", GetMemberDocHead(mi.MemberType) + GetSignatureForDoc(fm.Type) + "." + member_name + GetParametersFormatted(mi));
                        return;                         // a member of a type
                    }
                }
            }
            else
            {
                int         warn_result;
                FoundMember fm = FindDocumentedMember(mc, ds.TypeBuilder, name, parameter_types, ds, out warn_result, cref, true, name, Report);
                if (warn_result > 0)
                {
                    return;
                }
                if (!fm.IsEmpty)
                {
                    MemberInfo mi = fm.Member;
                    // we cannot use 'type' directly
                    // to get its name, since mi
                    // could be from DeclaringType
                    // for nested types.
                    xref.SetAttribute("cref", GetMemberDocHead(mi.MemberType) + GetSignatureForDoc(fm.Type) + "." + name + GetParametersFormatted(mi));
                    return;                     // local member name
                }
            }

            // It still might be part of namespace name.
            Namespace ns = ds.NamespaceEntry.NS.GetNamespace(name, false);

            if (ns != null)
            {
                xref.SetAttribute("cref", "N:" + ns.GetSignatureForError());
                return;                 // a namespace
            }
            if (GlobalRootNamespace.Instance.IsNamespace(name))
            {
                xref.SetAttribute("cref", "N:" + name);
                return;                 // a namespace
            }

            Report.Warning(1574, 1, mc.Location, "XML comment on `{0}' has cref attribute `{1}' that could not be resolved",
                           mc.GetSignatureForError(), cref);

            xref.SetAttribute("cref", "!:" + name);
        }
Пример #7
0
		public void ResolveDefaultValues (MemberCore m)
		{
			ResolveContext rc = null;
			for (int i = 0; i < parameters.Length; ++i) {
				Parameter p = (Parameter) parameters [i];

				//
				// Try not to enter default values resolution if there are is not any default value possible
				//
				if (p.HasDefaultValue || p.OptAttributes != null) {
					if (rc == null)
						rc = new ResolveContext (m);

					p.ResolveDefaultValue (rc);
				}
			}
		}
Пример #8
0
		private void AddMemberToList (MemberCore mc, List<MemberCore> alist, bool isexplicit)
		{
			if (ordered_explicit_member_list == null)  {
				ordered_explicit_member_list = new List<MemberCore> ();
				ordered_member_list = new List<MemberCore> ();
			}

			if (isexplicit) {
				if (Kind == MemberKind.Interface) {
					Report.Error (541, mc.Location,
						"`{0}': explicit interface declaration can only be declared in a class or struct",
						mc.GetSignatureForError ());
				}

				ordered_explicit_member_list.Add (mc);
				alist.Insert (0, mc);
			} else {
				ordered_member_list.Add (mc);
				alist.Add (mc);
			}

		}
Пример #9
0
		//
		// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
		//
		public virtual void AddNameToContainer (MemberCore symbol, string name)
		{
			if (((ModFlags | symbol.ModFlags) & Modifiers.COMPILER_GENERATED) != 0)
				return;

			MemberCore mc;
			if (!PartialContainer.defined_names.TryGetValue (name, out mc)) {
				PartialContainer.defined_names.Add (name, symbol);
				return;
			}

			if (symbol.EnableOverloadChecks (mc))
				return;

			InterfaceMemberBase im = mc as InterfaceMemberBase;
			if (im != null && im.IsExplicitImpl)
				return;

			Report.SymbolRelatedToPreviousError (mc);
			if ((mc.ModFlags & Modifiers.PARTIAL) != 0 && (symbol is ClassOrStruct || symbol is Interface)) {
				Error_MissingPartialModifier (symbol);
				return;
			}

			if (symbol is TypeParameter) {
				Report.Error (692, symbol.Location,
					"Duplicate type parameter `{0}'", symbol.GetSignatureForError ());
			} else {
				Report.Error (102, symbol.Location,
					"The type `{0}' already contains a definition for `{1}'",
					GetSignatureForError (), name);
			}

			return;
		}
Пример #10
0
		protected void Error_MissingPartialModifier (MemberCore type)
		{
			Report.Error (260, type.Location,
				"Missing partial modifier on declaration of type `{0}'. Another partial declaration of this type exists",
				type.GetSignatureForError ());
		}
Пример #11
0
 public virtual void Visit(MemberCore member)
 {
     Console.WriteLine("unknown member: " + member);
 }
Пример #12
0
 //
 // Handles <exception> elements.
 //
 void HandleException(MemberCore mc, DeclSpace ds, XmlElement seealso)
 {
     HandleXrefCommon(mc, ds, seealso);
 }
Пример #13
0
 //
 // Handles <see> elements.
 //
 void HandleSee(MemberCore mc, DeclSpace ds, XmlElement see)
 {
     HandleXrefCommon(mc, ds, see);
 }
Пример #14
0
 public static string GetMethodDocCommentName(MemberCore mc, ParametersCompiled p, DeclSpace ds)
 {
     return("");
 }
Пример #15
0
 internal static void GenerateDocComment(MemberCore mc, DeclSpace ds, Report r)
 {
 }
Пример #16
0
 public static void Error_CyclicDeclaration(MemberCore mc)
 {
     Report.Error(110, mc.Location, "The evaluation of the constant value for `{0}' involves a circular definition",
                  mc.GetSignatureForError());
 }
Пример #17
0
		//
		// Performs the validation on a Method's modifiers (properties have
		// the same properties).
		//
		// TODO: Why is it not done at parse stage, move to Modifiers::Check
		//
		public bool MethodModifiersValid (MemberCore mc)
		{
			const Modifiers vao = (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE);
			const Modifiers nv = (Modifiers.NEW | Modifiers.VIRTUAL);
			bool ok = true;
			var flags = mc.ModFlags;
			
			//
			// At most one of static, virtual or override
			//
			if ((flags & Modifiers.STATIC) != 0){
				if ((flags & vao) != 0){
					Report.Error (112, mc.Location, "A static member `{0}' cannot be marked as override, virtual or abstract",
						mc.GetSignatureForError ());
					ok = false;
				}
			}

			if ((flags & Modifiers.OVERRIDE) != 0 && (flags & nv) != 0){
				Report.Error (113, mc.Location, "A member `{0}' marked as override cannot be marked as new or virtual",
					mc.GetSignatureForError ());
				ok = false;
			}

			//
			// If the declaration includes the abstract modifier, then the
			// declaration does not include static, virtual or extern
			//
			if ((flags & Modifiers.ABSTRACT) != 0){
				if ((flags & Modifiers.EXTERN) != 0){
					Report.Error (
						180, mc.Location, "`{0}' cannot be both extern and abstract", mc.GetSignatureForError ());
					ok = false;
				}

				if ((flags & Modifiers.SEALED) != 0) {
					Report.Error (502, mc.Location, "`{0}' cannot be both abstract and sealed", mc.GetSignatureForError ());
					ok = false;
				}

				if ((flags & Modifiers.VIRTUAL) != 0){
					Report.Error (503, mc.Location, "The abstract method `{0}' cannot be marked virtual", mc.GetSignatureForError ());
					ok = false;
				}

				if ((ModFlags & Modifiers.ABSTRACT) == 0){
					Report.SymbolRelatedToPreviousError (this);
					Report.Error (513, mc.Location, "`{0}' is abstract but it is declared in the non-abstract class `{1}'",
						mc.GetSignatureForError (), GetSignatureForError ());
					ok = false;
				}
			}

			if ((flags & Modifiers.PRIVATE) != 0){
				if ((flags & vao) != 0){
					Report.Error (621, mc.Location, "`{0}': virtual or abstract members cannot be private", mc.GetSignatureForError ());
					ok = false;
				}
			}

			if ((flags & Modifiers.SEALED) != 0){
				if ((flags & Modifiers.OVERRIDE) == 0){
					Report.Error (238, mc.Location, "`{0}' cannot be sealed because it is not an override", mc.GetSignatureForError ());
					ok = false;
				}
			}

			return ok;
		}
Пример #18
0
		public override void RegisterFieldForInitialization (MemberCore field, FieldInitializer expression)
		{
			if ((field.ModFlags & Modifiers.STATIC) == 0) {
				Report.Error (573, field.Location, "`{0}': Structs cannot have instance field initializers",
					field.GetSignatureForError ());
				return;
			}
			base.RegisterFieldForInitialization (field, expression);
		}
Пример #19
0
 //
 // Generates xml doc comments (if any), and if required,
 // handle warning report.
 //
 internal void GenerateDocumentationForMember(MemberCore mc)
 {
 }
Пример #20
0
		protected void Error_CannotChangeAccessModifiers (MemberCore member, MemberSpec base_member)
		{
			var base_modifiers = base_member.Modifiers;

			// Remove internal modifier from types which are not internally accessible
			if ((base_modifiers & Modifiers.AccessibilityMask) == (Modifiers.PROTECTED | Modifiers.INTERNAL) &&
				!base_member.DeclaringType.MemberDefinition.IsInternalAsPublic (member.Module.DeclaringAssembly))
				base_modifiers = Modifiers.PROTECTED;

			Report.SymbolRelatedToPreviousError (base_member);
			Report.Error (507, member.Location,
				"`{0}': cannot change access modifiers when overriding `{1}' inherited member `{2}'",
				member.GetSignatureForError (),
				ModifiersExtensions.AccessibilityName (base_modifiers),
				base_member.GetSignatureForError ());
		}
Пример #21
0
        public Expression TryInline(ResolveContext rc)
        {
            if (!(Expr is Invocation))
            {
                return(Expr);
            }

            invocation = (Expr as Invocation);
            if (invocation.MethodGroup.BestCandidate == null)
            {
                return(Expr);
            }

            methodSpec = invocation.MethodGroup.BestCandidate;
            if (!(methodSpec.MemberDefinition is MethodCore))
            {
                return(Expr);
            }

            method     = methodSpec.MemberDefinition as MemberCore;
            methodData = method as IMethodData;

            if (methodData.IsInlinable)
            {
                return(Expr);
            }

            TypeSpec returnType = methodData.ReturnType;

            ToplevelBlock block = methodData.Block;

            if (block.Parameters.Count > 0 || block.TopBlock.NamesCount > 0 && block.TopBlock.LabelsCount > 0)
            {
                return(Expr);
            }

            if (returnType != rc.BuiltinTypes.Void &&
                block.Statements.Count == 1 && block.Statements [0] is Return)
            {
                inlineExpr = ((Return)block.Statements [0]).Expr.Clone(new CloneContext());
            }
            else if (returnType == rc.BuiltinTypes.Void)
            {
                Block newBlock = new Block(rc.CurrentBlock, block.StartLocation, block.EndLocation);
                foreach (var st in block.Statements)
                {
                    newBlock.AddStatement(st.Clone(new CloneContext()));
                }
//				inlineExpr = newBlock;
            }

            this.inlineFailed = false;

            Expression ret;

            inlineExpr.Accept(this);
            ret = inlineExpr;

            if (inlineFailed)
            {
                return(Expr);
            }

            return(ret);
        }
Пример #22
0
        private static Type FindDocumentedTypeNonArray(MemberCore mc,
                                                       string identifier, DeclSpace ds, string cref, Report r)
        {
            switch (identifier)
            {
            case "int":
                return(TypeManager.int32_type);

            case "uint":
                return(TypeManager.uint32_type);

            case "short":
                return(TypeManager.short_type);;

            case "ushort":
                return(TypeManager.ushort_type);

            case "long":
                return(TypeManager.int64_type);

            case "ulong":
                return(TypeManager.uint64_type);;

            case "float":
                return(TypeManager.float_type);;

            case "double":
                return(TypeManager.double_type);

            case "char":
                return(TypeManager.char_type);;

            case "decimal":
                return(TypeManager.decimal_type);;

            case "byte":
                return(TypeManager.byte_type);;

            case "sbyte":
                return(TypeManager.sbyte_type);;

            case "object":
                return(TypeManager.object_type);;

            case "bool":
                return(TypeManager.bool_type);;

            case "string":
                return(TypeManager.string_type);;

            case "void":
                return(TypeManager.void_type);;
            }
            FullNamedExpression e = ds.LookupNamespaceOrType(identifier, mc.Location, false);

            if (e != null)
            {
                if (!(e is TypeExpr))
                {
                    return(null);
                }
                return(e.Type);
            }
            int index = identifier.LastIndexOf('.');

            if (index < 0)
            {
                return(null);
            }
            int  warn;
            Type parent = FindDocumentedType(mc, identifier.Substring(0, index), ds, cref, r);

            if (parent == null)
            {
                return(null);
            }
            // no need to detect warning 419 here
            return(FindDocumentedMember(mc, parent,
                                        identifier.Substring(index + 1),
                                        null, ds, out warn, cref, false, null, r).Member as Type);
        }
Пример #23
0
 public InlinableValidator(MemberCore method)
 {
     this.method = method;
 }
Пример #24
0
		//
		// Parameters checks for members which don't have a block
		//
		public void CheckParameters (MemberCore member)
		{
			for (int i = 0; i < parameters.Length; ++i) {
				var name = parameters[i].Name;
				for (int ii = i + 1; ii < parameters.Length; ++ii) {
					if (parameters[ii].Name == name)
						this[ii].Error_DuplicateName (member.Compiler.Report);
				}
			}
		}
Пример #25
0
		public override bool EnableOverloadChecks (MemberCore overload)
		{
			if (overload is Indexer) {
				caching_flags |= Flags.MethodOverloadsExist;
				return true;
			}

			return base.EnableOverloadChecks (overload);
		}
Пример #26
0
		public override bool EnableOverloadChecks (MemberCore overload)
		{
			if (overload is Indexer)
				return false;

			return base.EnableOverloadChecks (overload);
		}
Пример #27
0
        private static MemberInfo FindDocumentedMemberNoNest(
            MemberCore mc, Type type, string member_name,
            Type [] param_list, DeclSpace ds, out int warning_type,
            string cref, bool warn419, string name_for_error, Report Report)
        {
            warning_type = 0;
            MemberInfo [] mis;

            if (param_list == null)
            {
                // search for fields/events etc.
                mis = TypeManager.MemberLookup(type, null,
                                               type, MemberTypes.All,
                                               BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance,
                                               member_name, null);
                mis = FilterOverridenMembersOut(mis);
                if (mis == null || mis.Length == 0)
                {
                    return(null);
                }
                if (warn419 && IsAmbiguous(mis))
                {
                    Report419(mc, name_for_error, mis, Report);
                }
                return(mis [0]);
            }

            MethodSignature msig = new MethodSignature(member_name, null, param_list);

            mis = FindMethodBase(type,
                                 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance,
                                 msig);

            if (warn419 && mis.Length > 0)
            {
                if (IsAmbiguous(mis))
                {
                    Report419(mc, name_for_error, mis, Report);
                }
                return(mis [0]);
            }

            // search for operators (whose parameters exactly
            // matches with the list) and possibly report CS1581.
            string oper             = null;
            string return_type_name = null;

            if (member_name.StartsWith("implicit operator "))
            {
                Operator.GetMetadataName(Operator.OpType.Implicit);
                return_type_name = member_name.Substring(18).Trim(wsChars);
            }
            else if (member_name.StartsWith("explicit operator "))
            {
                oper             = Operator.GetMetadataName(Operator.OpType.Explicit);
                return_type_name = member_name.Substring(18).Trim(wsChars);
            }
            else if (member_name.StartsWith("operator "))
            {
                oper = member_name.Substring(9).Trim(wsChars);
                switch (oper)
                {
                // either unary or binary
                case "+":
                    oper = param_list.Length == 2 ?
                           Operator.GetMetadataName(Operator.OpType.Addition) :
                           Operator.GetMetadataName(Operator.OpType.UnaryPlus);
                    break;

                case "-":
                    oper = param_list.Length == 2 ?
                           Operator.GetMetadataName(Operator.OpType.Subtraction) :
                           Operator.GetMetadataName(Operator.OpType.UnaryNegation);
                    break;

                default:
                    oper = Operator.GetMetadataName(oper);
                    if (oper != null)
                    {
                        break;
                    }

                    warning_type = 1584;
                    Report.Warning(1020, 1, mc.Location, "Overloadable {0} operator is expected", param_list.Length == 2 ? "binary" : "unary");
                    Report.Warning(1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
                                   mc.GetSignatureForError(), cref);
                    return(null);
                }
            }
            // here we still don't consider return type (to
            // detect CS1581 or CS1002+CS1584).
            msig = new MethodSignature(oper, null, param_list);

            mis = FindMethodBase(type,
                                 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance,
                                 msig);
            if (mis.Length == 0)
            {
                return(null);                // CS1574
            }
            MemberInfo mi       = mis [0];
            Type       expected = mi is MethodInfo ?
                                  ((MethodInfo)mi).ReturnType :
                                  mi is PropertyInfo ?
                                  ((PropertyInfo)mi).PropertyType :
                                  null;

            if (return_type_name != null)
            {
                Type returnType = FindDocumentedType(mc, return_type_name, ds, cref, Report);
                if (returnType == null || returnType != expected)
                {
                    warning_type = 1581;
                    Report.Warning(1581, 1, mc.Location, "Invalid return type in XML comment cref attribute `{0}'", cref);
                    return(null);
                }
            }
            return(mis [0]);
        }
Пример #28
0
			public override void Visit (MemberCore member)
			{
				Console.WriteLine ("Unknown member:");
				Console.WriteLine (member.GetType () + "-> Member {0}", member.GetSignatureForError ());
			}
Пример #29
0
 public virtual void Visit(MemberCore member)
 {
     Console.WriteLine("unknown member type: " + member.GetType());
 }
Пример #30
0
		public override bool EnableOverloadChecks (MemberCore overload)
		{
			if (overload is MethodCore) {
				caching_flags |= Flags.MethodOverloadsExist;
				return true;
			}

			if (overload is AbstractPropertyEventMethod)
				return true;

			return base.EnableOverloadChecks (overload);
		}
Пример #31
0
 public virtual void Visit(MemberCore member)
 {
     Debug.Fail("unknown member type: " + member.GetType());
 }
Пример #32
0
		public void RegisterFieldForInitialization (MemberCore field, FieldInitializer expression)
		{
			if (IsPartialPart)
				PartialContainer.RegisterFieldForInitialization (field, expression);

			if ((field.ModFlags & Modifiers.STATIC) != 0){
				if (initialized_static_fields == null) {
					HasStaticFieldInitializer = true;
					initialized_static_fields = new List<FieldInitializer> (4);
				}

				initialized_static_fields.Add (expression);
			} else {
				if (Kind == MemberKind.Struct) {
					if (Compiler.Settings.Version != LanguageVersion.Experimental) {
						Report.Error (573, expression.Location, "'{0}': Structs cannot have instance property or field initializers",
							GetSignatureForError ());
					}
				}

				if (initialized_fields == null)
					initialized_fields = new List<FieldInitializer> (4);

				initialized_fields.Add (expression);
			}
		}
Пример #33
0
		public override bool EnableOverloadChecks (MemberCore overload)
		{
			// TODO: It can be deleted when members will be defined in correct order
			if (overload is Operator)
				return overload.EnableOverloadChecks (this);

			if (overload is Indexer)
				return false;

			return base.EnableOverloadChecks (overload);
		}
Пример #34
0
		public bool AddMember (MemberCore symbol, string name)
		{
			return AddToContainer (symbol, name);
		}
Пример #35
0
		/// <summary>
		/// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
		/// </summary>
		protected virtual bool AddToContainer (MemberCore symbol, string name)
		{
			MemberCore mc;
			if (!defined_names.TryGetValue (name, out mc)) {
				defined_names.Add (name, symbol);
				return true;
			}

			if (((mc.ModFlags | symbol.ModFlags) & Modifiers.COMPILER_GENERATED) != 0)
				return true;

			if (symbol.EnableOverloadChecks (mc))
				return true;

			InterfaceMemberBase im = mc as InterfaceMemberBase;
			if (im != null && im.IsExplicitImpl)
				return true;

			Report.SymbolRelatedToPreviousError (mc);
			if ((mc.ModFlags & Modifiers.PARTIAL) != 0 && (symbol is ClassOrStruct || symbol is Interface)) {
				Error_MissingPartialModifier (symbol);
				return false;
			}

			if (this is ModuleContainer) {
				Report.Error (101, symbol.Location, 
					"The namespace `{0}' already contains a definition for `{1}'",
					((DeclSpace)symbol).NamespaceEntry.GetSignatureForError (), symbol.MemberName.Name);
			} else if (symbol is TypeParameter) {
				Report.Error (692, symbol.Location,
					"Duplicate type parameter `{0}'", symbol.GetSignatureForError ());
			} else {
				Report.Error (102, symbol.Location,
					      "The type `{0}' already contains a definition for `{1}'",
					      GetSignatureForError (), symbol.MemberName.Name);
			}

			return false;
		}
Пример #36
0
		public override void AddNameToContainer (MemberCore symbol, string name)
		{
			if (!(symbol is Constructor) && symbol.MemberName.Name == MemberName.Name) {
				if (symbol is TypeParameter) {
					Report.Error (694, symbol.Location,
						"Type parameter `{0}' has same name as containing type, or method",
						symbol.GetSignatureForError ());
					return;
				}
			
				InterfaceMemberBase imb = symbol as InterfaceMemberBase;
				if (imb == null || !imb.IsExplicitImpl) {
					Report.SymbolRelatedToPreviousError (this);
					Report.Error (542, symbol.Location, "`{0}': member names cannot be the same as their enclosing type",
						symbol.GetSignatureForError ());
					return;
				}
			}

			base.AddNameToContainer (symbol, name);
		}
Пример #37
0
		protected override bool AddToContainer (MemberCore symbol, string name)
		{
			MemberCore mc = GetDefinition (name);

			if (mc == null) {
				defined_names.Add (name, symbol);
				return true;
			}

			// A conflict between anonymous type members will be reported
			if (symbol is TypeParameter) {
				Report.SymbolRelatedToPreviousError (symbol);
				return false;
			}

			// Ignore other conflicts
			return true;
		}
Пример #38
0
		protected static bool CheckAccessModifiers (MemberCore this_member, MemberSpec base_member)
		{
			var thisp = this_member.ModFlags & Modifiers.AccessibilityMask;
			var base_classp = base_member.Modifiers & Modifiers.AccessibilityMask;

			if ((base_classp & (Modifiers.PROTECTED | Modifiers.INTERNAL)) == (Modifiers.PROTECTED | Modifiers.INTERNAL)) {
				//
				// It must be at least "protected"
				//
				if ((thisp & Modifiers.PROTECTED) == 0) {
					return false;
				}

				//
				// when overriding protected internal, the method can be declared
				// protected internal only within the same assembly or assembly
				// which has InternalsVisibleTo
				//
				if ((thisp & Modifiers.INTERNAL) != 0) {
					return base_member.DeclaringType.MemberDefinition.IsInternalAsPublic (this_member.Module.DeclaringAssembly);
				}

				//
				// protected overriding protected internal inside same assembly
				// requires internal modifier as well
				//
				if (base_member.DeclaringType.MemberDefinition.IsInternalAsPublic (this_member.Module.DeclaringAssembly)) {
					return false;
				}

				return true;
			}

			return thisp == base_classp;
		}
Пример #39
0
		/// <summary>
		/// Returns true when a member supports multiple overloads (methods, indexers, etc)
		/// </summary>
		public virtual bool EnableOverloadChecks (MemberCore overload)
		{
			return false;
		}
Пример #40
0
		public override bool EnableOverloadChecks (MemberCore overload)
		{
			//
			// Two members can differ in their explicit interface
			// type parameter only
			//
			InterfaceMemberBase imb = overload as InterfaceMemberBase;
			if (imb != null && imb.IsExplicitImpl) {
				if (IsExplicitImpl) {
					caching_flags |= Flags.MethodOverloadsExist;
				}
				return true;
			}

			return IsExplicitImpl;
		}
Пример #41
0
		public InternalErrorException (MemberCore mc, Exception e)
			: base (mc.Location + " " + mc.GetSignatureForError (), e)
		{
		}
Пример #42
0
		public void AddMember (MemberCore symbol)
		{
			if (symbol.MemberName.ExplicitInterface != null) {
				if (!(Kind == MemberKind.Class || Kind == MemberKind.Struct)) {
					Report.Error (541, symbol.Location,
						"`{0}': explicit interface declaration can only be declared in a class or struct",
						symbol.GetSignatureForError ());
				}
			}

			AddNameToContainer (symbol, symbol.MemberName.Basename);
			members.Add (symbol);
		}
Пример #43
0
		public void SymbolRelatedToPreviousError (MemberCore mc)
		{
			SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
		}
Пример #44
0
		public virtual void RegisterFieldForInitialization (MemberCore field, FieldInitializer expression)
		{
			if (IsPartialPart)
				PartialContainer.RegisterFieldForInitialization (field, expression);

			if ((field.ModFlags & Modifiers.STATIC) != 0){
				if (initialized_static_fields == null) {
					HasStaticFieldInitializer = true;
					initialized_static_fields = new List<FieldInitializer> (4);
				}

				initialized_static_fields.Add (expression);
			} else {
				if (initialized_fields == null)
					initialized_fields = new List<FieldInitializer> (4);

				initialized_fields.Add (expression);
			}
		}
Пример #45
0
 //
 // Handles <exception> elements.
 //
 private static void HandleException(MemberCore mc,
                                     DeclSpace ds, XmlElement seealso, Report r)
 {
     HandleXrefCommon(mc, ds, seealso, r);
 }