Beispiel #1
0
        private static MessageContainer CreateWarningMessageContainer(LinkContext context, MessageOrigin origin, DiagnosticId id, WarnVersion version, string subcategory, params string[] args)
        {
            if (!(version >= WarnVersion.ILLink0 && version <= WarnVersion.Latest))
            {
                throw new ArgumentException($"The provided warning version '{version}' is invalid.");
            }

            if (context.IsWarningSuppressed((int)id, origin))
            {
                return(Empty);
            }

            if (version > context.WarnVersion)
            {
                return(Empty);
            }

            if (TryLogSingleWarning(context, (int)id, origin, subcategory))
            {
                return(Empty);
            }

            if (context.IsWarningAsError((int)id))
            {
                return(new MessageContainer(MessageCategory.WarningAsError, id, subcategory, origin, args));
            }

            return(new MessageContainer(MessageCategory.Warning, id, subcategory, origin, args));
        }
Beispiel #2
0
        private static MessageContainer CreateWarningMessageContainer(LinkContext context, string text, int code, MessageOrigin origin, WarnVersion version, string subcategory = MessageSubCategory.None)
        {
            if (!(version >= WarnVersion.ILLink0 && version <= WarnVersion.Latest))
            {
                throw new ArgumentException($"The provided warning version '{version}' is invalid.");
            }

            if (context.IsWarningSuppressed(code, origin))
            {
                return(Empty);
            }

            if (version > context.WarnVersion)
            {
                return(Empty);
            }

            if (TryLogSingleWarning(context, code, origin, subcategory))
            {
                return(Empty);
            }

            if (context.IsWarningAsError(code))
            {
                return(new MessageContainer(MessageCategory.WarningAsError, text, code, subcategory, origin));
            }

            return(new MessageContainer(MessageCategory.Warning, text, code, subcategory, origin));
        }
Beispiel #3
0
        /// <summary>
        /// Create a warning message.
        /// </summary>
        /// <param name="context">Context with the relevant warning suppression info.</param>
        /// <param name="text">Humanly readable message describing the warning</param>
        /// <param name="code">Unique warning ID. Please see https://github.com/mono/linker/blob/master/doc/error-codes.md
        /// for the list of warnings and possibly add a new one</param>
        /// /// <param name="origin">Filename or member where the warning is coming from</param>
        /// <param name="subcategory">Optionally, further categorize this warning</param>
        /// <param name="version">Optional warning version number. Versioned warnings can be controlled with the
        /// warning wave option --warn VERSION. Unversioned warnings are unaffected by this option. </param>
        /// <returns>New MessageContainer of 'Warning' category</returns>
        public static MessageContainer CreateWarningMessage(LinkContext context, string text, int code, MessageOrigin origin, WarnVersion version, string subcategory = MessageSubCategory.None)
        {
            if (!(code > 2000 && code <= 6000))
            {
                throw new ArgumentException($"The provided code '{code}' does not fall into the warning category, which is in the range of 2001 to 6000 (inclusive).");
            }

            if (!(version >= WarnVersion.ILLink0 && version <= WarnVersion.Latest))
            {
                throw new ArgumentException($"The provided warning version '{version}' is invalid.");
            }

            if (context.IsWarningSuppressed(code, origin))
            {
                return(Empty);
            }

            if (version > context.WarnVersion)
            {
                return(Empty);
            }

            if (context.IsWarningAsError(code))
            {
                return(new MessageContainer(MessageCategory.WarningAsError, text, code, subcategory, origin));
            }

            return(new MessageContainer(MessageCategory.Warning, text, code, subcategory, origin));
        }
Beispiel #4
0
        private static MessageContainer CreateWarningMessageContainer(LinkContext context, string text, int code, MessageOrigin origin, WarnVersion version, string subcategory = MessageSubCategory.None)
        {
            if (!(version >= WarnVersion.ILLink0 && version <= WarnVersion.Latest))
            {
                throw new ArgumentException($"The provided warning version '{version}' is invalid.");
            }

            if (context.IsWarningSuppressed(code, origin))
            {
                return(Empty);
            }

            if (version > context.WarnVersion)
            {
                return(Empty);
            }

            if (subcategory == MessageSubCategory.TrimAnalysis)
            {
                Debug.Assert(origin.MemberDefinition != null);
                var declaringType = origin.MemberDefinition?.DeclaringType ?? (origin.MemberDefinition as TypeDefinition);
                var assembly      = declaringType.Module.Assembly;
                var assemblyName  = assembly?.Name.Name;
                if (assemblyName != null && context.IsSingleWarn(assemblyName))
                {
                    if (context.AssembliesWithGeneratedSingleWarning.Add(assemblyName))
                    {
                        context.LogWarning($"Assembly '{assemblyName}' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries", 2104, context.GetAssemblyLocation(assembly));
                    }
                    return(Empty);
                }
            }

            if (context.IsWarningAsError(code))
            {
                return(new MessageContainer(MessageCategory.WarningAsError, text, code, subcategory, origin));
            }

            return(new MessageContainer(MessageCategory.Warning, text, code, subcategory, origin));
        }