Example #1
0
        //------------------------------------------------------------
        // CController.CheckDisplayWarning
        //
        /// <summary>
        /// <para>This function determines whether a warning should be displayed or suppressed,
        /// taking into account the warning level and "no warn" list.</para>
        /// </summary>
        /// <param name="errorId"></param>
        /// <param name="warnLevel"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal bool CheckDisplayWarning(CSCERRID errorId, int warnLevel)
        {
            // this must be a warning.
            DebugUtil.Assert(warnLevel > 0);
            int errNo;
            int level;

            // Get error level by errorId.
            if (!CSCErrorInfo.Manager.GetInfo(errorId, out errNo, out level))
            {
                return(false);
            }

            // Error level 99 means that it is obsolete.
            if (level == 99)
            {
                return(false);
            }

            // Not show errors whose level are lower than warnLevel.
            if (warnLevel > OptionManager.WarningLevel)
            {
                return(false);
            }

            if (OptionManager.IsNoWarnNumber(errNo))
            {
                return(false);
            }
            return(true);
        }
Example #2
0
        //------------------------------------------------------------
        // OptionUtil.IsVaildWarningID (2)
        //
        /// <summary></summary>
        /// <param name="errNo"></param>
        /// <param name="errId"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal static bool IsValidWarningNumber(int errNo, out CSCERRID errId, out int index)
        {
            DebugUtil.Assert(OptionUtil.WarningNumbers != null);

            errId = CSCErrorInfo.Manager.GetIDfromNumber(errNo);
            index = Array.BinarySearch(WarningNumbers, errNo);
            return(index >= 0 && index < WarningNumbers.Length);
        }
Example #3
0
        //------------------------------------------------------------
        // ConsoleOutput.PrintString (2)
        //
        /// <summary>
        /// Load a string from a resource and print it, followed by an optional newline.
        /// </summary>
        /// <param name="eid"></param>
        /// <param name="newline"></param>
        /// <param name="prettyprint"></param>
        /// <remarks>
        /// ALink's PrintHelp() function will just iterate through a range of ids,
        /// and only print the ones which exist.
        /// Thus, the string may not exist for ALink, but it should for CSC.
        /// </remarks>
        //------------------------------------------------------------
        internal void PrintString(
            CSCERRID errorId,
            bool newLine,       // = true,
            bool prettyPrint    // = false
            )
        {
            ResNo resNo;

            if (!CSCErrorInfo.Manager.GetResourceNumber(errorId, out resNo))
            {
                return;
            }
            PrintString(resNo, newLine, prettyPrint);
        }
Example #4
0
        //------------------------------------------------------------
        // CController.ReportError (2a)
        //
        /// <summary>
        /// <para>(ConsoleOutput::ShowErrorIdString in sscli.)</para>
        /// </summary>
        /// <param name="errorID"></param>
        /// <param name="kind"></param>
        /// <param name="args"></param>
        //------------------------------------------------------------
        internal void ReportError(CSCERRID errorID, ERRORKIND kind, params Object[] args)
        {
            string    msg  = null;
            Exception excp = null;

            msg = CSCErrorInfo.Manager.FormatErrorMessage(
                out excp,
                kind,
                errorID,
                args);

            if (msg != null && excp == null)
            {
                CountReportedError(kind);
                WriteLine(msg);
                return;
            }

            if (excp != null)
            {
                OnCatastrophicError(excp.Message);
            }
        }
Example #5
0
        // The following methods comprise the error handling/COMPILER-to-CController hosting

        //------------------------------------------------------------
        // CController.CreateError (1)
        //
        /// <summary>
        /// <para>This function creates a CError object from the given information.
        /// The CError object is created with no location information.
        /// The CError object is returned with a ref count of 0.</para>
        /// </summary>
        /// <param name="errorId">Error ID.</param>
        /// <param name="args">Arguments for error message.</param>
        /// <param name="error">A created CError instance will be set.</param>
        /// <param name="warnOverride">if true, treats a error as a warning.</param>
        /// <returns>if failed to create a instance, return false.</returns>
        /// <remarks>
        /// <para>If "warnOverride" is true (defaults to false), and this error is usually
        /// an error (not warning or fatal), then the error is wrapped with warning WRN_ErrorOverride</para>
        /// </remarks>
        //------------------------------------------------------------
        internal bool CreateError(
            CSCERRID errorId,
            ErrArg[] args,
            out CError error,
            bool warnOverride)  // = false);
        {
            error = null;
            // Make some assertions...
            DebugUtil.Assert(errorId > 0 && errorId < CSCERRID.ERR_COUNT);
            DebugUtil.Assert(errorId != CSCERRID.WRN_ErrorOverride);

            CError errorObject = null;
            int    errNo;
            int    level1, level2;

            // when errorId is invalid, or has no level, return false;
            if (!CSCErrorInfo.Manager.GetInfo(errorId, out errNo, out level1))
            {
                goto LERROR;
            }

            if (level1 == 0 && warnOverride)
            {
                // If errorId is of ERROR and should treat it as WARNING,
                // and if CSCERRID.WRN_ErrorOverride is lower than optionData.WarnLevel,
                // return false.
                if (CSCErrorInfo.Manager.GetWarningLevel(CSCERRID.WRN_ErrorOverride, out level2))
                {
                    if (!CheckDisplayWarning(CSCERRID.WRN_ErrorOverride, level2))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                // Clear this bit (since we clearly aren't overriding an error to a warning)
                warnOverride = false;

                // If it's a warning, does it meet the warning level criteria?
                if (level1 > 0 && !CheckDisplayWarning(errorId, level1))
                {
                    return(true);
                }
            }

            // Create a CError instance and initialize it.
            errorObject = new CError();
            if (errorObject == null || !errorObject.Initialize((CSCERRID)errorId, args))
            {
                goto LERROR;
            }

            // Do we need to wrap this Error in a warning?
            if (warnOverride == true)
            {
                DebugUtil.Assert(errorObject.Kind == ERRORKIND.ERROR);
                if (!errorObject.Initialize(
                        CSCERRID.WRN_ErrorOverride,
                        new ErrArg(errorObject.Text),
                        new ErrArg(errorObject.ErrorID)))
                {
                    goto LERROR;
                }
            }

            // Now check to see if we need to promote this warning to an error
            if (errorObject.Kind == ERRORKIND.WARNING &&
                this.OptionManager.IsWarnAsError(errorObject.ErrorID) &&
                !errorObject.WarnAsError())
            {
                goto LERROR;
            }
            error = errorObject;
            return(true);

LERROR:
            if (errorObject != null &&
                !String.IsNullOrEmpty(errorObject.Text))
            {
                OnCatastrophicError(errorObject.Text);
            }
            else
            {
                OnCatastrophicError("CController.CreateError");
            }
            error = null;
            return(false);
        }