clang 8.0.0

Functions
DiagnosticRenderer.cpp File Reference
`#include "clang/Frontend/DiagnosticRenderer.h"`
`#include "clang/Basic/Diagnostic.h"`
`#include "clang/Basic/DiagnosticOptions.h"`
`#include "clang/Basic/LLVM.h"`
`#include "clang/Basic/SourceLocation.h"`
`#include "clang/Basic/SourceManager.h"`
`#include "clang/Edit/Commit.h"`
`#include "clang/Edit/EditedSource.h"`
`#include "clang/Edit/EditsReceiver.h"`
`#include "clang/Lex/Lexer.h"`
`#include "llvm/ADT/ArrayRef.h"`
`#include "llvm/ADT/DenseMap.h"`
`#include "llvm/ADT/None.h"`
`#include "llvm/ADT/SmallString.h"`
`#include "llvm/ADT/SmallVector.h"`
`#include "llvm/ADT/StringRef.h"`
`#include "llvm/Support/raw_ostream.h"`
`#include <algorithm>`
`#include <cassert>`
`#include <iterator>`
`#include <utility>`
Include dependency graph for DiagnosticRenderer.cpp:

Go to the source code of this file.

## Functions
static void | mergeFixits (ArrayRef< FixItHint > FixItHints, const SourceManager &SM, const LangOptions &LangOpts, SmallVectorImpl< FixItHint > &MergedFixits)
static SourceLocation | retrieveMacroLocation (SourceLocation Loc, FileID MacroFileID, FileID CaretFileID, const SmallVectorImpl< FileID > &CommonArgExpansions, bool IsBegin, const SourceManager *SM, bool &IsTokenRange)
| A recursive function to trace all possible backtrace locations to match the `CaretLocFileID`. More...
static void | getMacroArgExpansionFileIDs (SourceLocation Loc, SmallVectorImpl< FileID > &IDs, bool IsBegin, const SourceManager *SM)
| Walk up the chain of macro expansions and collect the FileIDs identifying the expansions. More...
static void | computeCommonMacroArgExpansionFileIDs (SourceLocation Begin, SourceLocation End, const SourceManager *SM, SmallVectorImpl< FileID > &CommonArgExpansions)
| Collect the expansions of the begin and end locations and compute the set intersection. More...
static void | mapDiagnosticRanges (FullSourceLoc CaretLoc, ArrayRef< CharSourceRange > Ranges, SmallVectorImpl< CharSourceRange > &SpellingRanges)
static bool | checkLocForMacroArgExpansion (SourceLocation Loc, const SourceManager &SM, SourceLocation ArgumentLoc)
| Check that the macro argument location of Loc starts with ArgumentLoc. More...
static bool | checkRangeForMacroArgExpansion (CharSourceRange Range, const SourceManager &SM, SourceLocation ArgumentLoc)
| Check if all the locations in the range have the same macro argument expansion, and that the expansion starts with ArgumentLoc. More...
static bool | checkRangesForMacroArgExpansion (FullSourceLoc Loc, ArrayRef< CharSourceRange > Ranges)
| A helper function to check if the current ranges are all inside the same macro argument expansion as Loc. More...

## Function Documentation

## ◆ checkLocForMacroArgExpansion()

static bool checkLocForMacroArgExpansion | ( | SourceLocation | Loc,
|  | const SourceManager & | SM,
|  | SourceLocation | ArgumentLoc
| ) |  |
| static

Check that the macro argument location of Loc starts with ArgumentLoc.

The starting location of the macro expansions is used to differeniate different macro expansions.

Definition at line 456 of file DiagnosticRenderer.cpp.

References clang::SourceManager::isMacroArgExpansion().

Referenced by checkRangeForMacroArgExpansion().

## ◆ checkRangeForMacroArgExpansion()

static bool checkRangeForMacroArgExpansion | ( | CharSourceRange | Range,
|  | const SourceManager & | SM,
|  | SourceLocation | ArgumentLoc
| ) |  |
| static

Check if all the locations in the range have the same macro argument expansion, and that the expansion starts with ArgumentLoc.

Definition at line 469 of file DiagnosticRenderer.cpp.

References checkLocForMacroArgExpansion(), clang::CharSourceRange::getBegin(), clang::CharSourceRange::getEnd(), and clang::SourceLocation::getLocWithOffset().

Referenced by checkRangesForMacroArgExpansion().

## ◆ checkRangesForMacroArgExpansion()

static bool checkRangesForMacroArgExpansion | ( | FullSourceLoc | Loc,
|  | ArrayRef< CharSourceRange > | Ranges
| ) |  |
| static

A helper function to check if the current ranges are all inside the same macro argument expansion as Loc.

Count all valid ranges.

To store the source location of the argument location.

Set the ArgumentLoc to the beginning location of the expansion of Loc so to check if the ranges expands to the same beginning location.

Definition at line 484 of file DiagnosticRenderer.cpp.

References checkRangeForMacroArgExpansion(), clang::DiagnosticRenderer::DiagOpts, clang::FullSourceLoc::getManager(), clang::SourceLocation::isFileID(), clang::FullSourceLoc::isMacroArgExpansion(), clang::SourceLocation::isMacroID(), clang::SourceLocation::isValid(), mapDiagnosticRanges(), and clang::DiagnosticNoteRenderer::~DiagnosticNoteRenderer().

## ◆ computeCommonMacroArgExpansionFileIDs()

static void computeCommonMacroArgExpansionFileIDs | ( | SourceLocation | Begin,
|  | SourceLocation | End,
|  | const SourceManager * | SM,
|  | SmallVectorImpl< FileID > & | CommonArgExpansions
| ) |  |
| static

Collect the expansions of the begin and end locations and compute the set intersection.

Produces a sorted vector of FileIDs in CommonArgExpansions.

Definition at line 333 of file DiagnosticRenderer.cpp.

References getMacroArgExpansionFileIDs().

Referenced by mapDiagnosticRanges().

## ◆ getMacroArgExpansionFileIDs()

static void getMacroArgExpansionFileIDs | ( | SourceLocation | Loc,
|  | SmallVectorImpl< FileID > & | IDs,
|  | bool | IsBegin,
|  | const SourceManager * | SM
| ) |  |
| static

Walk up the chain of macro expansions and collect the FileIDs identifying the expansions.

Definition at line 317 of file DiagnosticRenderer.cpp.

References clang::SourceManager::getFileID(), clang::SourceManager::getImmediateExpansionRange(), clang::SourceManager::getImmediateSpellingLoc(), clang::SourceManager::isMacroArgExpansion(), and clang::SourceLocation::isMacroID().

Referenced by computeCommonMacroArgExpansionFileIDs().

## ◆ mapDiagnosticRanges()

static void mapDiagnosticRanges | ( | FullSourceLoc | CaretLoc,
|  | ArrayRef< CharSourceRange > | Ranges,
|  | SmallVectorImpl< CharSourceRange > & | SpellingRanges
| ) |  |
| static

Definition at line 358 of file DiagnosticRenderer.cpp.

References Begin, computeCommonMacroArgExpansionFileIDs(), clang::DiagnosticRenderer::emitCodeContext(), clang::DiagnosticRenderer::emitDiagnostic(), End, clang::CharSourceRange::getBegin(), clang::FullSourceLoc::getFileID(), clang::SourceManager::getFileID(), clang::SourceManager::getImmediateExpansionRange(), clang::Lexer::getImmediateMacroNameForDiagnostics(), clang::FullSourceLoc::getManager(), clang::FullSourceLoc::getSpellingLoc(), clang::SourceManager::getSpellingLoc(), clang::SourceLocation::isInvalid(), clang::SourceLocation::isMacroID(), clang::CharSourceRange::isTokenRange(), clang::DiagnosticRenderer::LangOpts, clang::None, clang::DiagnosticsEngine::Note, and retrieveMacroLocation().

Referenced by checkRangesForMacroArgExpansion().

## ◆ mergeFixits()

static void mergeFixits | ( | ArrayRef< FixItHint > | FixItHints,
|  | const SourceManager & | SM,
|  | const LangOptions & | LangOpts,
|  | SmallVectorImpl< FixItHint > & | MergedFixits
| ) |  |
| static

Definition at line 60 of file DiagnosticRenderer.cpp.

References clang::edit::EditedSource::applyRewrites(), clang::edit::EditedSource::commit(), clang::edit::Commit::insert(), clang::edit::Commit::insertFromRange(), clang::edit::Commit::remove(), and clang::edit::Commit::replace().

Referenced by clang::DiagnosticRenderer::emitDiagnostic().

## ◆ retrieveMacroLocation()

static SourceLocation retrieveMacroLocation | ( | SourceLocation | Loc,
|  | FileID | MacroFileID,
|  | FileID | CaretFileID,
|  | const SmallVectorImpl< FileID > & | CommonArgExpansions,
|  | bool | IsBegin,
|  | const SourceManager * | SM,
|  | bool & | IsTokenRange
| ) |  |
| static

A recursive function to trace all possible backtrace locations to match the `CaretLocFileID`.

Definition at line 262 of file DiagnosticRenderer.cpp.

References clang::CharSourceRange::getBegin(), clang::CharSourceRange::getEnd(), clang::SourceManager::getFileID(), clang::SourceManager::getImmediateExpansionRange(), clang::SourceManager::getImmediateSpellingLoc(), clang::SourceManager::isMacroArgExpansion(), clang::SourceLocation::isMacroID(), and clang::CharSourceRange::isTokenRange().

Referenced by mapDiagnosticRanges().