Add support for overloaded matchers. ie different matcher function signatures with the same name.

Summary:
Add support for overloaded matchers.
This composes with other features, like supporting polymorphic matchers.

Reviewers: klimek

CC: cfe-commits, revane

Differential Revision: http://llvm-reviews.chandlerc.com/D1188

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186836 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/unittests/ASTMatchers/Dynamic/ParserTest.cpp
index 9ccd3dc..d9b2d3c 100644
--- a/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ b/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -256,6 +256,15 @@
             ParseMatcherWithError("hasBody(stmt())"));
 }
 
+TEST(ParserTest, OverloadErrors) {
+  EXPECT_EQ("1:1: Error building matcher callee.\n"
+            "1:8: Candidate 1: Incorrect type for arg 1. "
+            "(Expected = Matcher<Stmt>) != (Actual = String)\n"
+            "1:8: Candidate 2: Incorrect type for arg 1. "
+            "(Expected = Matcher<Decl>) != (Actual = String)",
+            ParseWithError("callee(\"A\")"));
+}
+
 }  // end anonymous namespace
 }  // end namespace dynamic
 }  // end namespace ast_matchers
diff --git a/unittests/ASTMatchers/Dynamic/RegistryTest.cpp b/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
index 178a64a..e69017e 100644
--- a/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ b/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -124,6 +124,30 @@
   EXPECT_FALSE(matches("void f(int x, int a);", HasParameter));
 }
 
+TEST_F(RegistryTest, OverloadedMatchers) {
+  Matcher<Stmt> CallExpr0 = constructMatcher(
+      "callExpr",
+      constructMatcher("callee", constructMatcher("memberExpr",
+                                                  constructMatcher("isArrow"))))
+      .getTypedMatcher<Stmt>();
+
+  Matcher<Stmt> CallExpr1 = constructMatcher(
+      "callExpr",
+      constructMatcher(
+          "callee",
+          constructMatcher("methodDecl",
+                           constructMatcher("hasName", std::string("x")))))
+      .getTypedMatcher<Stmt>();
+
+  std::string Code = "class Y { public: void x(); }; void z() { Y y; y.x(); }";
+  EXPECT_FALSE(matches(Code, CallExpr0));
+  EXPECT_TRUE(matches(Code, CallExpr1));
+
+  Code = "class Z { public: void z() { this->z(); } };";
+  EXPECT_TRUE(matches(Code, CallExpr0));
+  EXPECT_FALSE(matches(Code, CallExpr1));
+}
+
 TEST_F(RegistryTest, PolymorphicMatchers) {
   const MatcherList IsDefinition = constructMatcher("isDefinition");
   Matcher<Decl> Var =