diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-07-03 12:34:38 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-07-03 12:34:38 +0200 |
commit | 65d6c642590bd5f51c04228d941608322a85f1ac (patch) | |
tree | b0eec098731abbc9e89ae7b33e52dc3450cffffc /compilerplugins/clang/compat.hxx | |
parent | e6391dde04044147a1ac13acdccf797f3872fc6b (diff) |
loplugin:casttovoid
Change-Id: I427b15b35ef6e7c803cb8a00c961d35175ae8cb2
Diffstat (limited to 'compilerplugins/clang/compat.hxx')
-rw-r--r-- | compilerplugins/clang/compat.hxx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index a493cdc7b209..060bf4cf2317 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -214,6 +214,40 @@ inline bool isMacroArgExpansion( #endif } +inline llvm::StringRef getImmediateMacroNameForDiagnostics( + clang::SourceLocation Loc, clang::SourceManager const & SM, + clang::LangOptions const &LangOpts) +{ +#if CLANG_VERSION >= 30900 + return clang::Lexer::getImmediateMacroNameForDiagnostics(Loc, SM, LangOpts); +#else + using namespace clang; + // Verbatim copy from Clang's lib/Lex/Lexer.cpp: + + assert(Loc.isMacroID() && "Only reasonble to call this on macros"); + // Walk past macro argument expanions. + while (SM.isMacroArgExpansion(Loc)) + Loc = SM.getImmediateExpansionRange(Loc).first; + + // If the macro's spelling has no FileID, then it's actually a token paste + // or stringization (or similar) and not a macro at all. + if (!SM.getFileEntryForID(SM.getFileID(SM.getSpellingLoc(Loc)))) + return StringRef(); + + // Find the spelling location of the start of the non-argument expansion + // range. This is where the macro name was spelled in order to begin + // expanding this macro. + Loc = SM.getSpellingLoc(SM.getImmediateExpansionRange(Loc).first); + + // Dig out the buffer where the macro name was spelled and the extents of + // the name so that we can render it into the expansion note. + std::pair<FileID, unsigned> ExpansionInfo = SM.getDecomposedLoc(Loc); + unsigned MacroTokenLength = Lexer::MeasureTokenLength(Loc, SM, LangOpts); + StringRef ExpansionBuffer = SM.getBufferData(ExpansionInfo.first); + return ExpansionBuffer.substr(ExpansionInfo.second, MacroTokenLength); +#endif +} + inline auto getAsTagDecl(clang::Type const& t) -> clang::TagDecl * { #if CLANG_VERSION >= 30500 |