#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
-#include "clang/Lex/Lexer.h"
#include "llvm/Support/raw_ostream.h"
namespace clang {
}
inline void EmitLocation(raw_ostream &o, const SourceManager &SM,
- const LangOptions &LangOpts, SourceLocation L,
- const FIDMap &FM, unsigned indent,
- bool extend = false) {
- FullSourceLoc Loc(SM.getExpansionLoc(L), const_cast<SourceManager &>(SM));
+ SourceLocation L, const FIDMap &FM, unsigned indent) {
+ if (L.isInvalid()) return;
- // Add in the length of the token, so that we cover multi-char tokens.
- unsigned offset =
- extend ? Lexer::MeasureTokenLength(Loc, SM, LangOpts) - 1 : 0;
+ FullSourceLoc Loc(SM.getExpansionLoc(L), const_cast<SourceManager &>(SM));
Indent(o, indent) << "<dict>\n";
Indent(o, indent) << " <key>line</key>";
EmitInteger(o, Loc.getExpansionLineNumber()) << '\n';
Indent(o, indent) << " <key>col</key>";
- EmitInteger(o, Loc.getExpansionColumnNumber() + offset) << '\n';
+ EmitInteger(o, Loc.getExpansionColumnNumber()) << '\n';
Indent(o, indent) << " <key>file</key>";
EmitInteger(o, GetFID(FM, SM, Loc)) << '\n';
Indent(o, indent) << "</dict>\n";
}
inline void EmitRange(raw_ostream &o, const SourceManager &SM,
- const LangOptions &LangOpts, CharSourceRange R,
- const FIDMap &FM, unsigned indent) {
+ CharSourceRange R, const FIDMap &FM, unsigned indent) {
+ if (R.isInvalid()) return;
+
+ assert(R.isCharRange() && "cannot handle a token range");
Indent(o, indent) << "<array>\n";
- EmitLocation(o, SM, LangOpts, R.getBegin(), FM, indent + 1);
- EmitLocation(o, SM, LangOpts, R.getEnd(), FM, indent + 1, R.isTokenRange());
+ EmitLocation(o, SM, R.getBegin(), FM, indent + 1);
+ EmitLocation(o, SM, R.getEnd(), FM, indent + 1);
Indent(o, indent) << "</array>\n";
}
}
getImmediateExpansionRange(SourceLocation Loc) const;
/// \brief Given a SourceLocation object, return the range of
- /// tokens covered by the expansion the ultimate file.
+ /// tokens covered by the expansion in the ultimate file.
std::pair<SourceLocation,SourceLocation>
getExpansionRange(SourceLocation Loc) const;
+ /// \brief Given a SourceRange object, return the range of
+ /// tokens covered by the expansion in the ultimate file.
+ SourceRange getExpansionRange(SourceRange Range) const {
+ return SourceRange(getExpansionRange(Range.getBegin()).first,
+ getExpansionRange(Range.getEnd()).second);
+ }
/// \brief Given a SourceLocation object, return the spelling
/// location referenced by the ID.
const SourceManager &SM,
const LangOptions &LangOpts);
+ /// \brief Given a token range, produce a corresponding CharSourceRange that
+ /// is not a token range. This allows the source range to be used by
+ /// components that don't have access to the lexer and thus can't find the
+ /// end of the range for themselves.
+ static CharSourceRange getAsCharRange(SourceRange Range,
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
+ SourceLocation End = getLocForEndOfToken(Range.getEnd(), 0, SM, LangOpts);
+ return End.isInvalid() ? CharSourceRange()
+ : CharSourceRange::getCharRange(
+ Range.getBegin(), End.getLocWithOffset(-1));
+ }
+ static CharSourceRange getAsCharRange(CharSourceRange Range,
+ const SourceManager &SM,
+ const LangOptions &LangOpts) {
+ return Range.isTokenRange()
+ ? getAsCharRange(Range.getAsRange(), SM, LangOpts)
+ : Range;
+ }
+
/// \brief Returns true if the given MacroID location points at the first
/// token of the macro expansion.
///
requires cplusplus
umbrella "Analysis"
- // This file is intended for repeated textual inclusion.
- exclude header "Analysis/Analyses/ThreadSafetyOps.def"
+ textual header "Analysis/Analyses/ThreadSafetyOps.def"
module * { export * }
}
requires cplusplus
umbrella "AST"
- // These files are intended for repeated textual inclusion.
- exclude header "AST/BuiltinTypes.def"
- exclude header "AST/TypeLocNodes.def"
- exclude header "AST/TypeNodes.def"
+ textual header "AST/BuiltinTypes.def"
+ textual header "AST/TypeLocNodes.def"
+ textual header "AST/TypeNodes.def"
module * { export * }
}
requires cplusplus
umbrella "Basic"
- // These files are intended for repeated textual inclusion.
- exclude header "Basic/BuiltinsAArch64.def"
- exclude header "Basic/BuiltinsARM64.def"
- exclude header "Basic/BuiltinsARM.def"
- exclude header "Basic/Builtins.def"
- exclude header "Basic/BuiltinsHexagon.def"
- exclude header "Basic/BuiltinsMips.def"
- exclude header "Basic/BuiltinsNEON.def"
- exclude header "Basic/BuiltinsNVPTX.def"
- exclude header "Basic/BuiltinsPPC.def"
- exclude header "Basic/BuiltinsR600.def"
- exclude header "Basic/BuiltinsX86.def"
- exclude header "Basic/BuiltinsXCore.def"
- exclude header "Basic/BuiltinsLe64.def"
- exclude header "Basic/DiagnosticOptions.def"
- exclude header "Basic/LangOptions.def"
- exclude header "Basic/OpenCLExtensions.def"
- exclude header "Basic/OpenMPKinds.def"
- exclude header "Basic/OperatorKinds.def"
- exclude header "Basic/Sanitizers.def"
- exclude header "Basic/TokenKinds.def"
-
- // This file includes a header from Lex.
- exclude header "Basic/PlistSupport.h"
-
- // FIXME: This is logically a part of Basic, but has been put in the wrong place.
- header "StaticAnalyzer/Core/AnalyzerOptions.h"
+ textual header "Basic/BuiltinsAArch64.def"
+ textual header "Basic/BuiltinsARM64.def"
+ textual header "Basic/BuiltinsARM.def"
+ textual header "Basic/Builtins.def"
+ textual header "Basic/BuiltinsHexagon.def"
+ textual header "Basic/BuiltinsMips.def"
+ textual header "Basic/BuiltinsNEON.def"
+ textual header "Basic/BuiltinsNVPTX.def"
+ textual header "Basic/BuiltinsPPC.def"
+ textual header "Basic/BuiltinsR600.def"
+ textual header "Basic/BuiltinsX86.def"
+ textual header "Basic/BuiltinsXCore.def"
+ textual header "Basic/BuiltinsLe64.def"
+ textual header "Basic/DiagnosticOptions.def"
+ textual header "Basic/LangOptions.def"
+ textual header "Basic/OpenCLExtensions.def"
+ textual header "Basic/OpenMPKinds.def"
+ textual header "Basic/OperatorKinds.def"
+ textual header "Basic/Sanitizers.def"
+ textual header "Basic/TokenKinds.def"
module * { export * }
}
requires cplusplus
umbrella "Driver"
- // This file is intended for repeated textual inclusion.
- exclude header "Driver/Types.def"
+ textual header "Driver/Types.def"
module * { export * }
}
requires cplusplus
umbrella "Frontend"
- // These files are intended for repeated textual inclusion.
- exclude header "Frontend/CodeGenOptions.def"
- exclude header "Frontend/LangStandards.def"
+ textual header "Frontend/CodeGenOptions.def"
+ textual header "Frontend/LangStandards.def"
module * { export * }
}
requires cplusplus
umbrella "StaticAnalyzer"
- // This file is intended for repeated textual inclusion.
- exclude header "StaticAnalyzer/Core/Analyses.def"
+ textual header "StaticAnalyzer/Core/Analyses.def"
module * { export * }
}
// Output the location of the bug.
o << " <key>location</key>\n";
- EmitLocation(o, SM, LangOpts, D.getLocation(), FM, 2);
+ EmitLocation(o, SM, D.getLocation(), FM, 2);
// Output the ranges (if any).
- StoredDiagnostic::range_iterator RI = D.range_begin(), RE = D.range_end();
-
- if (RI != RE) {
+ if (!D.getRanges().empty()) {
o << " <key>ranges</key>\n";
o << " <array>\n";
- for (; RI != RE; ++RI)
- EmitRange(o, SM, LangOpts, *RI, FM, 4);
+ for (auto &R : D.getRanges()) {
+ CharSourceRange ExpansionRange(SM.getExpansionRange(R.getAsRange()),
+ R.isTokenRange());
+ EmitRange(o, SM, Lexer::getAsCharRange(ExpansionRange, SM, LangOpts),
+ FM, 4);
+ }
o << " </array>\n";
}
// by forcing to use only the beginning of the range. This simplifies the layout
// logic for clients.
Indent(o, indent) << "<key>start</key>\n";
- SourceLocation StartEdge = I->getStart().asRange().getBegin();
- EmitRange(o, SM, LangOpts, CharSourceRange::getTokenRange(StartEdge), FM,
+ SourceRange StartEdge(
+ SM.getExpansionLoc(I->getStart().asRange().getBegin()));
+ EmitRange(o, SM, Lexer::getAsCharRange(StartEdge, SM, LangOpts), FM,
indent + 1);
Indent(o, indent) << "<key>end</key>\n";
- SourceLocation EndEdge = I->getEnd().asRange().getBegin();
- EmitRange(o, SM, LangOpts, CharSourceRange::getTokenRange(EndEdge), FM,
+ SourceRange EndEdge(SM.getExpansionLoc(I->getEnd().asRange().getBegin()));
+ EmitRange(o, SM, Lexer::getAsCharRange(EndEdge, SM, LangOpts), FM,
indent + 1);
--indent;
FullSourceLoc L = P.getLocation().asLocation();
Indent(o, indent) << "<key>location</key>\n";
- EmitLocation(o, SM, LangOpts, L, FM, indent);
+ EmitLocation(o, SM, L, FM, indent);
// Output the ranges (if any).
ArrayRef<SourceRange> Ranges = P.getRanges();
Indent(o, indent) << "<key>ranges</key>\n";
Indent(o, indent) << "<array>\n";
++indent;
- for (ArrayRef<SourceRange>::iterator I = Ranges.begin(), E = Ranges.end();
- I != E; ++I) {
- EmitRange(o, SM, LangOpts, CharSourceRange::getTokenRange(*I), FM,
- indent + 1);
- }
+ for (auto &R : Ranges)
+ EmitRange(o, SM,
+ Lexer::getAsCharRange(SM.getExpansionRange(R), SM, LangOpts),
+ FM, indent + 1);
--indent;
Indent(o, indent) << "</array>\n";
}
// Output the location of the bug.
o << " <key>location</key>\n";
- EmitLocation(o, *SM, LangOpts, D->getLocation().asLocation(), FM, 2);
+ EmitLocation(o, *SM, D->getLocation().asLocation(), FM, 2);
// Output the diagnostic to the sub-diagnostic client, if any.
if (!filesMade->empty()) {
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>69</integer>
-// CHECK-NEXT: <key>col</key><integer>18</integer>
+// CHECK-NEXT: <key>col</key><integer>51</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>45</integer>
-// CHECK-NEXT: <key>col</key><integer>18</integer>
+// CHECK-NEXT: <key>col</key><integer>21</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>82</integer>
-// CHECK-NEXT: <key>col</key><integer>9</integer>
+// CHECK-NEXT: <key>col</key><integer>12</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>
// CHECK-NEXT: </dict>
// CHECK-NEXT: <dict>
// CHECK-NEXT: <key>line</key><integer>82</integer>
-// CHECK-NEXT: <key>col</key><integer>9</integer>
+// CHECK-NEXT: <key>col</key><integer>12</integer>
// CHECK-NEXT: <key>file</key><integer>0</integer>
// CHECK-NEXT: </dict>
// CHECK-NEXT: </array>