[PATCH] Adding 4 ASTMatchers: typedefDecl, isInMainFile, isInSystemFile, isInFileMatchingName

Samuel Benzaquen sbenza at google.com
Tue Jul 8 09:52:41 PDT 2014


================
Comment at: include/clang/ASTMatchers/ASTMatchers.h:155
@@ +154,3 @@
+/// \endcode
+/// typedefType(isInMainFile())
+///   matches "typedef int X"
----------------
s/typedefType/typedefDecl/

================
Comment at: include/clang/ASTMatchers/ASTMatchers.h:205
@@ +204,3 @@
+///
+/// Example matches Y but not X (matcher = recordDecl(isInSytemHeader())
+/// \code
----------------
Example is copy-pasted from above and not updated for isInFileMatchingName

================
Comment at: include/clang/Tooling/Tooling.h:157
@@ -157,1 +156,3 @@
+                           const Twine &FileName = "input.cc",
+                           const std::vector<std::pair<std::string, std::string>> &VirtualMappedFiles= {});
 
----------------
I believe we can't still use brace init in clang. More instances of this in other files.
See http://llvm.org/docs/CodingStandards.html#supported-c-11-language-and-library-features

================
Comment at: lib/ASTMatchers/Dynamic/Registry.cpp:315
@@ -314,1 +314,3 @@
   REGISTER_MATCHER(withInitializer);
+  REGISTER_MATCHER(typedefDecl);
+  REGISTER_MATCHER(isInMainFile);
----------------
sort lines.

================
Comment at: unittests/ASTMatchers/ASTMatchersTest.cpp:4406
@@ +4405,3 @@
+TEST(Matcher, IsInMainFileMatcher) {
+  EXPECT_TRUE(matchesConditionally(
+      "class X {};", recordDecl(hasName("X"), isInMainFile()), true, ""));
----------------
Use matches() or notMatches() instead.

================
Comment at: unittests/ASTMatchers/ASTMatchersTest.cpp:4440
@@ +4439,3 @@
+      {{"/foo", "class A {};"}, {"/bar", "class B {};"}}));
+  ASSERT_DEBUG_DEATH({
+                       EXPECT_TRUE(matchesConditionally(
----------------
Comment why this dies.

================
Comment at: unittests/ASTMatchers/ASTMatchersTest.cpp:4441
@@ +4440,3 @@
+  ASSERT_DEBUG_DEATH({
+                       EXPECT_TRUE(matchesConditionally(
+                           "#include <foo>\n"
----------------
You don't need the whole EXPECT_TRUE expression here.
Just the matcher is enough.

================
Comment at: unittests/ASTMatchers/ASTMatchersTest.h:65
@@ -65,1 +64,3 @@
+                                              llvm::StringRef CompileArg,
+                                              const std::vector<std::pair<std::string, std::string>> &VirtualMappedFiles= {}) {
   bool Found = false, DynamicFound = false;
----------------
over 80 chars. reflow the signature.

http://reviews.llvm.org/D4283






More information about the cfe-commits mailing list