[PATCH] D15506: [ASTMatchers] Allow hasName() to look through inline namespaces

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 14 13:59:54 PST 2015


aaron.ballman added inline comments.

================
Comment at: lib/ASTMatchers/ASTMatchersInternal.cpp:320-331
@@ -323,4 +319,14 @@
 
-  if (Pattern.startswith("::"))
-    return FullName == Pattern;
+  const bool SkipUnwrittenCases[] = {false, true};
+  for (bool SkipUnwritten : SkipUnwrittenCases) {
+    llvm::SmallString<128> NodeName = StringRef("::");
+    llvm::raw_svector_ostream OS(NodeName);
+
+    if (SkipUnwritten) {
+      PrintingPolicy Policy = Node.getASTContext().getPrintingPolicy();
+      Policy.SuppressUnwrittenScope = true;
+      Node.printQualifiedName(OS, Policy);
+    } else {
+      Node.printQualifiedName(OS);
+    }
 
----------------
> Extracted the array into a variable.

Good solution to be on the safe side. Range-for isn't the issue with MSVC 2013, it's initializer lists (which really didn't get enough love until 2015).

================
Comment at: lib/ASTMatchers/ASTMatchersInternal.cpp:335
@@ +334,3 @@
+
+    if (Pattern.startswith("::")) {
+      if (FullName == Pattern)
----------------
> Which braces do you want to remove?
> I need these to make the else bind with the outer if().

Good point; I think they're fine as-is then.



http://reviews.llvm.org/D15506





More information about the cfe-commits mailing list