Go to the documentation of this file.
14 #include "clang/Basic/SourceLocation.h"
15 #include "llvm/Support/ScopedPrinter.h"
16 #include "gmock/gmock.h"
17 #include "gtest/gtest.h"
23 using testing::UnorderedElementsAreArray;
25 TEST(CollectMainFileMacros, SelectedMacros) {
30 const char *Tests[] = {
31 R
"cpp(// Macros: Cursor on definition.
32 #define $1[[FOO]](x,y) (x + y)
33 int main() { int x = $1[[FOO]]($1[[FOO]](3, 4), $1[[FOO]](5, 6)); }
38 int s = $1[[M]]($2[[abc]]);
52 #ifdef $Unknown[[UNDEFINED]]
56 #ifndef $Unknown[[abc]]
63 // Macros from token concatenations not included.
64 #define $1[[CONCAT]](X) X##A()
65 #define $2[[PREPEND]](X) MACRO##X()
66 #define $3[[MACROA]]() 123
67 int B = $1[[CONCAT]](MACRO);
68 int D = $2[[PREPEND]](A);
71 // FIXME: Macro names in a definition are not detected.
72 #define $1[[MACRO_ARGS2]](X, Y) X Y
77 for (
const char *Test : Tests) {
85 for (
int I = 1;; I++) {
86 const auto ExpectedRefs = T.ranges(llvm::to_string(I));
87 if (ExpectedRefs.empty())
91 ASSERT_TRUE(
bool(
Loc));
92 const auto *Id = syntax::spelledIdentifierTouching(*
Loc, AST.
getTokens());
98 EXPECT_THAT(ExpectedRefs,
99 UnorderedElementsAreArray(ActualMacroRefs.MacroRefs[*SID]))
100 <<
"Annotation=" << I <<
", MacroName=" <<
Macro->Name
101 <<
", Test = " << Test;
105 UnorderedElementsAreArray(T.ranges(
"Unknown")))
106 <<
"Unknown macros doesn't match in " << Test;
TEST(BackgroundQueueTest, Priority)
llvm::Optional< DefinedMacro > locateMacroAt(const syntax::Token &SpelledTok, Preprocessor &PP)
Gets the macro referenced by SpelledTok.
static TestTU withCode(llvm::StringRef Code)
Preprocessor & getPreprocessor()
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
const syntax::TokenBuffer & getTokens() const
Tokens recorded while parsing the main file.
llvm::Optional< SymbolID > getSymbolID(const Decl *D)
Gets the symbol ID for a declaration, if possible.
SourceLocation Loc
'#' location in the include directive
SourceManager & getSourceManager()
std::vector< Range > UnknownMacros
llvm::Expected< SourceLocation > sourceLocationInMainFile(const SourceManager &SM, Position P)
Return the file location, corresponding to P.
const MainFileMacros & getMacros() const
Gets all macro references (definition, expansions) present in the main file, including those in the p...