clang  3.8.0
Functions
DiagnosticRenderer.cpp File Reference
#include "clang/Frontend/DiagnosticRenderer.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.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/SmallSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
Include dependency graph for DiagnosticRenderer.cpp:

Go to the source code of this file.

Functions

static StringRef getImmediateMacroName (SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
 Retrieve the name of the immediate macro expansion. More...
 
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)
 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 (SourceLocation CaretLoc, ArrayRef< CharSourceRange > Ranges, SmallVectorImpl< CharSourceRange > &SpellingRanges, const SourceManager *SM)
 
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 that expansion starts with ArgumentLoc. More...
 
static bool checkRangesForMacroArgExpansion (SourceLocation Loc, ArrayRef< CharSourceRange > Ranges, const SourceManager &SM)
 A helper function to check if the current ranges are all inside the same macro argument expansion as Loc. More...
 

Function Documentation

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 490 of file DiagnosticRenderer.cpp.

References clang::SourceManager::isMacroArgExpansion().

Referenced by 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 that expansion starts with ArgumentLoc.

Definition at line 503 of file DiagnosticRenderer.cpp.

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

Referenced by checkRangesForMacroArgExpansion().

static bool checkRangesForMacroArgExpansion ( SourceLocation  Loc,
ArrayRef< CharSourceRange Ranges,
const SourceManager SM 
)
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 518 of file DiagnosticRenderer.cpp.

References checkRangeForMacroArgExpansion(), E, I, clang::SourceManager::isMacroArgExpansion(), clang::SourceLocation::isMacroID(), and mapDiagnosticRanges().

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 370 of file DiagnosticRenderer.cpp.

References getMacroArgExpansionFileIDs().

Referenced by mapDiagnosticRanges().

static StringRef getImmediateMacroName ( SourceLocation  Loc,
const SourceManager SM,
const LangOptions LangOpts 
)
static

Retrieve the name of the immediate macro expansion.

This routine starts from a source location, and finds the name of the macro responsible for its immediate expansion. It looks through any intervening macro argument expansions to compute this. It returns a StringRef which refers to the SourceManager-owned buffer of the source where that macro name is spelled. Thus, the result shouldn't out-live that SourceManager.

This differs from Lexer::getImmediateMacroName in that any macro argument location will result in the topmost function macro that accepted it. e.g.

MAC1( MAC2(foo) )

for location of 'foo' token, this function will return "MAC1" while Lexer::getImmediateMacroName will return "MAC2".

Definition at line 42 of file DiagnosticRenderer.cpp.

References clang::SourceManager::getBufferData(), clang::SourceManager::getDecomposedLoc(), clang::SourceManager::getFileEntryForID(), clang::SourceManager::getFileID(), clang::SourceManager::getImmediateExpansionRange(), clang::SourceManager::getSpellingLoc(), clang::SourceManager::isMacroArgExpansion(), clang::SourceLocation::isMacroID(), and clang::Lexer::MeasureTokenLength().

static void getMacroArgExpansionFileIDs ( SourceLocation  Loc,
SmallVectorImpl< FileID > &  IDs,
bool  IsBegin,
const SourceManager SM 
)
static
static void mapDiagnosticRanges ( SourceLocation  CaretLoc,
ArrayRef< CharSourceRange Ranges,
SmallVectorImpl< CharSourceRange > &  SpellingRanges,
const SourceManager SM 
)
static
static void mergeFixits ( ArrayRef< FixItHint FixItHints,
const SourceManager SM,
const LangOptions LangOpts,
SmallVectorImpl< FixItHint > &  MergedFixits 
)
static
static SourceLocation retrieveMacroLocation ( SourceLocation  Loc,
FileID  MacroFileID,
FileID  CaretFileID,
const SmallVectorImpl< FileID > &  CommonArgExpansions,
bool  IsBegin,
const SourceManager SM 
)
static