void emitImportStackRecursively(SourceLocation Loc, StringRef ModuleName,
const SourceManager &SM);
void emitModuleBuildStack(const SourceManager &SM);
- void emitMacroExpansionsAndCarets(SourceLocation Loc,
- DiagnosticsEngine::Level Level,
- SmallVectorImpl<CharSourceRange>& Ranges,
- ArrayRef<FixItHint> Hints,
- const SourceManager &SM,
- unsigned &MacroDepth,
- unsigned OnMacroInst = 0);
+ void emitCaret(SourceLocation Loc, DiagnosticsEngine::Level Level,
+ ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> Hints,
+ const SourceManager &SM);
+ void emitMacroExpansions(SourceLocation Loc,
+ DiagnosticsEngine::Level Level,
+ ArrayRef<CharSourceRange> Ranges,
+ ArrayRef<FixItHint> Hints,
+ const SourceManager &SM,
+ unsigned &MacroDepth,
+ unsigned OnMacroInst = 0);
public:
/// \brief Emit a diagnostic.
///
beginDiagnostic(D, Level);
+ SourceLocation ExpandedLoc = Loc;
PresumedLoc PLoc;
if (Loc.isValid()) {
- PLoc = SM->getPresumedLocForDisplay(Loc, DiagOpts->ShowPresumedLoc);
+ // Perform the same walk as emitMacroExpansions, to find the ultimate
+ // expansion location for the diagnostic.
+ while (ExpandedLoc.isMacroID())
+ ExpandedLoc = SM->getImmediateMacroCallerLoc(ExpandedLoc);
+ PLoc = SM->getPresumedLoc(ExpandedLoc, DiagOpts->ShowPresumedLoc);
// First, if this diagnostic is not in the main file, print out the
// "included from" lines.
- emitIncludeStack(Loc, PLoc, Level, *SM);
+ emitIncludeStack(ExpandedLoc, PLoc, Level, *SM);
}
// Next, emit the actual diagnostic message.
- emitDiagnosticMessage(Loc, PLoc, Level, Message, Ranges, SM, D);
+ emitDiagnosticMessage(ExpandedLoc, PLoc, Level, Message, Ranges, SM, D);
// Only recurse if we have a valid location.
if (Loc.isValid()) {
I != E; ++I)
if (I->RemoveRange.isValid())
MutableRanges.push_back(I->RemoveRange);
-
- unsigned MacroDepth = 0;
- emitMacroExpansionsAndCarets(Loc, Level, MutableRanges, FixItHints, *SM,
- MacroDepth);
+
+ emitCaret(ExpandedLoc, Level, MutableRanges, FixItHints, *SM);
+
+ // If this location is within a macro, walk from the unexpanded location
+ // up to ExpandedLoc and produce a macro backtrace.
+ if (Loc.isMacroID()) {
+ unsigned MacroDepth = 0;
+ emitMacroExpansions(Loc, Level, MutableRanges, FixItHints, *SM,
+ MacroDepth);
+ }
}
LastLoc = Loc;
// iff the FileID is the same.
static void mapDiagnosticRanges(
SourceLocation CaretLoc,
- const SmallVectorImpl<CharSourceRange>& Ranges,
+ ArrayRef<CharSourceRange> Ranges,
SmallVectorImpl<CharSourceRange>& SpellingRanges,
const SourceManager *SM) {
FileID CaretLocFileID = SM->getFileID(CaretLoc);
- for (SmallVectorImpl<CharSourceRange>::const_iterator I = Ranges.begin(),
+ for (ArrayRef<CharSourceRange>::const_iterator I = Ranges.begin(),
E = Ranges.end();
I != E; ++I) {
SourceLocation Begin = I->getBegin(), End = I->getEnd();
}
}
+void DiagnosticRenderer::emitCaret(SourceLocation Loc,
+ DiagnosticsEngine::Level Level,
+ ArrayRef<CharSourceRange> Ranges,
+ ArrayRef<FixItHint> Hints,
+ const SourceManager &SM) {
+ SmallVector<CharSourceRange, 4> SpellingRanges;
+ mapDiagnosticRanges(Loc, Ranges, SpellingRanges, &SM);
+ emitCodeContext(Loc, Level, SpellingRanges, Hints, SM);
+}
+
/// \brief Recursively emit notes for each macro expansion and caret
/// diagnostics where appropriate.
///
/// \param Hints The FixIt hints active for this diagnostic.
/// \param MacroSkipEnd The depth to stop skipping macro expansions.
/// \param OnMacroInst The current depth of the macro expansion stack.
-void DiagnosticRenderer::emitMacroExpansionsAndCarets(
- SourceLocation Loc,
- DiagnosticsEngine::Level Level,
- SmallVectorImpl<CharSourceRange>& Ranges,
- ArrayRef<FixItHint> Hints,
- const SourceManager &SM,
- unsigned &MacroDepth,
- unsigned OnMacroInst)
-{
+void DiagnosticRenderer::emitMacroExpansions(SourceLocation Loc,
+ DiagnosticsEngine::Level Level,
+ ArrayRef<CharSourceRange> Ranges,
+ ArrayRef<FixItHint> Hints,
+ const SourceManager &SM,
+ unsigned &MacroDepth,
+ unsigned OnMacroInst) {
assert(!Loc.isInvalid() && "must have a valid source location here");
- // If this is a file source location, directly emit the source snippet and
- // caret line. Also record the macro depth reached.
- if (Loc.isFileID()) {
- // Map the ranges.
- SmallVector<CharSourceRange, 4> SpellingRanges;
- mapDiagnosticRanges(Loc, Ranges, SpellingRanges, &SM);
-
- assert(MacroDepth == 0 && "We shouldn't hit a leaf node twice!");
- MacroDepth = OnMacroInst;
- emitCodeContext(Loc, Level, SpellingRanges, Hints, SM);
- return;
- }
- // Otherwise recurse through each macro expansion layer.
-
// Walk up to the caller of this macro, and produce a backtrace down to there.
SourceLocation OneLevelUp = SM.getImmediateMacroCallerLoc(Loc);
- emitMacroExpansionsAndCarets(OneLevelUp, Level, Ranges, Hints, SM, MacroDepth,
- OnMacroInst + 1);
+ if (OneLevelUp.isMacroID())
+ emitMacroExpansions(OneLevelUp, Level, Ranges, Hints, SM,
+ MacroDepth, OnMacroInst + 1);
+ else
+ MacroDepth = OnMacroInst + 1;
unsigned MacroSkipStart = 0, MacroSkipEnd = 0;
if (MacroDepth > DiagOpts->MacroBacktraceLimit &&