Exemplo n.º 1
0
 internal void HandleErrors(object sender, Microsoft.Cci.ErrorEventArgs args)
 {
     foreach (IErrorMessage error in args.Errors)
     {
         ISourceLocation /*?*/ sourceLocation = error.Location as ISourceLocation;
         if (sourceLocation == null)
         {
             continue;
         }
         if (!error.IsWarning)
         {
             hasError = true;
         }
         CompositeSourceDocument /*?*/ compositeDocument = sourceLocation.SourceDocument as CompositeSourceDocument;
         if (compositeDocument != null)
         {
             foreach (ISourceLocation sl in compositeDocument.GetFragmentLocationsFor(sourceLocation))
             {
                 sourceLocation = sl;
                 break;
             }
         }
         IPrimarySourceLocation /*?*/ primarySourceLocation = sourceLocation as IPrimarySourceLocation;
         if (primarySourceLocation == null)
         {
             Console.Out.WriteLine(error.Message);
             continue;
         }
         string docName     = primarySourceLocation.SourceDocument.Name.Value;
         int    startLine   = primarySourceLocation.StartLine;
         int    startColumn = primarySourceLocation.StartColumn;
         int    endLine     = primarySourceLocation.EndLine;
         int    endColumn   = primarySourceLocation.EndColumn;
         IncludedSourceLocation /*?*/ includedSourceLocation = primarySourceLocation as IncludedSourceLocation;
         if (includedSourceLocation != null)
         {
             docName   = includedSourceLocation.OriginalSourceDocumentName;
             startLine = includedSourceLocation.OriginalStartLine;
             endLine   = includedSourceLocation.OriginalEndLine;
         }
         if (!displayFileName)
         {
             docName = "";
         }
         Console.Out.WriteLine("{6}({0},{1})-({2},{3}): {4}: {5}", startLine, startColumn, endLine, endColumn,
                               error.IsWarning ? "warning" : "error", error.Message, docName);
         foreach (ILocation relatedLocation in error.RelatedLocations)
         {
             ISourceLocation /*?*/ sloc = relatedLocation as ISourceLocation;
             if (sloc != null)
             {
                 compositeDocument = sloc.SourceDocument as CompositeSourceDocument;
                 if (compositeDocument != null)
                 {
                     foreach (ISourceLocation sl in compositeDocument.GetFragmentLocationsFor(sloc))
                     {
                         sloc = sl;
                         break;
                     }
                 }
                 primarySourceLocation = sloc as IPrimarySourceLocation;
                 if (primarySourceLocation == null)
                 {
                     continue;
                 }
                 docName                = primarySourceLocation.SourceDocument.Name.Value;
                 startLine              = primarySourceLocation.StartLine;
                 startColumn            = primarySourceLocation.StartColumn;
                 endLine                = primarySourceLocation.EndLine;
                 endColumn              = primarySourceLocation.EndColumn;
                 includedSourceLocation = primarySourceLocation as IncludedSourceLocation;
                 if (includedSourceLocation != null)
                 {
                     docName   = includedSourceLocation.OriginalSourceDocumentName;
                     startLine = includedSourceLocation.OriginalStartLine;
                     endLine   = includedSourceLocation.OriginalEndLine;
                 }
                 Console.Out.WriteLine("({0},{1})-({2},{3}): (Location of symbol related to previous {4}.)", startLine, startColumn, endLine, endColumn, error.IsWarning ? "warning" : "error");
             }
             //TODO: deal with non source locations
         }
     }
 }
Exemplo n.º 2
0
        public void HandleErrors(object sender, Microsoft.Cci.ErrorEventArgs args)
        {
            foreach (IErrorMessage error in args.Errors)
            {
                ISourceLocation /*?*/ sourceLocation = error.Location as ISourceLocation;
                if (sourceLocation == null)
                {
                    continue;
                }
                if (this.DebugOnWarningOrError)
                {
                    System.Diagnostics.Debugger.Launch();
                }
                bool isError = !error.IsWarning || WarningsAsErrors;
                if (!isError && GetWarningLevel(error.Code) > WarningLevel)
                {
                    continue;
                }
                if (isError)
                {
                    VccCommandLineHost.IncreaseErrorCount();
                }
                CompositeSourceDocument /*?*/ compositeDocument = sourceLocation.SourceDocument as CompositeSourceDocument;
                if (compositeDocument != null)
                {
                    foreach (ISourceLocation sl in compositeDocument.GetFragmentLocationsFor(sourceLocation))
                    {
                        sourceLocation = sl;
                        break;
                    }
                }
                IPrimarySourceLocation /*?*/ primarySourceLocation = sourceLocation as IPrimarySourceLocation;
                if (primarySourceLocation == null)
                {
                    Logger.Instance.Error(error.Message);
                    continue;
                }
                string docName     = primarySourceLocation.SourceDocument.Location ?? primarySourceLocation.SourceDocument.Name.Value;
                int    startLine   = primarySourceLocation.StartLine;
                int    startColumn = primarySourceLocation.StartColumn;
                IncludedSourceLocation /*?*/ includedSourceLocation = primarySourceLocation as IncludedSourceLocation;
                if (includedSourceLocation != null)
                {
                    docName = includedSourceLocation.OriginalSourceDocumentName;
                    if (docName != null)
                    {
                        docName = docName.Replace("\\\\", "\\");
                    }
                    startLine = includedSourceLocation.OriginalStartLine;
                }
                long id = error.IsWarning ? ErrorToId(error.Code) : error.Code;
                if (WarningIsDisabled(id))
                {
                    return;
                }

                Logger.Instance.LogWithLocation(String.Format("VC{0:0000}", id), error.Message, new Location(docName, startLine, startColumn), isError ? LogKind.Error : LogKind.Warning, false);

                string firstErrFile = docName;
                int    firstErrLine = startLine;

                foreach (ILocation relatedLocation in error.RelatedLocations)
                {
                    ISourceLocation /*?*/ sloc = relatedLocation as ISourceLocation;
                    if (sloc != null)
                    {
                        compositeDocument = sloc.SourceDocument as CompositeSourceDocument;
                        if (compositeDocument != null)
                        {
                            foreach (ISourceLocation sl in compositeDocument.GetFragmentLocationsFor(sloc))
                            {
                                sloc = sl;
                                break;
                            }
                        }
                        primarySourceLocation = sloc as IPrimarySourceLocation;
                        if (primarySourceLocation == null)
                        {
                            continue;
                        }
                        docName                = primarySourceLocation.SourceDocument.Location ?? primarySourceLocation.SourceDocument.Name.Value;
                        startLine              = primarySourceLocation.StartLine;
                        startColumn            = primarySourceLocation.StartColumn;
                        includedSourceLocation = primarySourceLocation as IncludedSourceLocation;
                        if (includedSourceLocation != null)
                        {
                            docName = includedSourceLocation.OriginalSourceDocumentName;
                            if (docName != null)
                            {
                                docName = docName.Replace("\\\\", "\\");
                            }
                            startLine = includedSourceLocation.OriginalStartLine;
                        }
                        if (docName != firstErrFile || firstErrLine != startLine)
                        {
                            Logger.Instance.LogWithLocation(
                                null,
                                String.Format("(Location of symbol related to previous {0}.)", isError ? "error" : "warning"),
                                new Location(docName, startLine, startColumn),
                                isError ? LogKind.Error : LogKind.Warning,
                                true);
                        }
                    }
                    //TODO: deal with non source locations
                }
            }
        }