diff options
author | Anna Zaks <ganna@apple.com> | 2012-01-20 00:11:12 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-01-20 00:11:12 +0000 |
commit | 461af1e502c9bd88330bbf17d449a7593fc0d624 (patch) | |
tree | ac561fae795df42d51defa69e5ddc74e90ff2b1e /lib/StaticAnalyzer/Core/CheckerContext.cpp | |
parent | 3352ea914644edb2b56e999c94319ce915d68707 (diff) |
[analyzer] Add a utility method that allows to find the macro name used
at the given location.
This could be useful when checkers' logic depends on whether a function
is called with a given macro argument.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148516 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core/CheckerContext.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Core/CheckerContext.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/StaticAnalyzer/Core/CheckerContext.cpp b/lib/StaticAnalyzer/Core/CheckerContext.cpp index cb272fb1c3..6aaa377325 100644 --- a/lib/StaticAnalyzer/Core/CheckerContext.cpp +++ b/lib/StaticAnalyzer/Core/CheckerContext.cpp @@ -14,6 +14,7 @@ #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" #include "clang/Basic/Builtins.h" +#include "clang/Lex/Lexer.h" using namespace clang; using namespace ento; @@ -53,3 +54,15 @@ bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD, return false; } + +StringRef CheckerContext::getMacroNameOrSpelling(SourceLocation &Loc) { + if (!Loc.isMacroID()) { + SmallVector<char, 16> buf; + return Lexer::getSpelling(Loc, buf, getSourceManager(), getLangOptions()); + } else { + return Lexer::getImmediateMacroName(Loc, getSourceManager(), + getLangOptions()); + } + return StringRef(); +} + |