diff options
| author | Manuel Klimek <klimek@google.com> | 2013-05-14 09:13:00 +0000 |
|---|---|---|
| committer | Manuel Klimek <klimek@google.com> | 2013-05-14 09:13:00 +0000 |
| commit | 24db0f0afd425fdb0854d3d6a6e04f87c76dd27f (patch) | |
| tree | c779aa13b2fe7edaf54839f2dc7f074e06818e70 /clang/unittests/ASTMatchers/ASTMatchersTest.h | |
| parent | 5ecb5fd7b229005695daa5a8cbfd72aa81838d5c (diff) | |
| download | bcm5719-llvm-24db0f0afd425fdb0854d3d6a6e04f87c76dd27f.tar.gz bcm5719-llvm-24db0f0afd425fdb0854d3d6a6e04f87c76dd27f.zip | |
First revision of the dynamic ASTMatcher library.
This library supports all the features of the compile-time based ASTMatcher
library, but allows the user to specify and construct the matchers at runtime.
It contains the following modules:
- A variant type, to be used by the matcher factory.
- A registry, where the matchers are indexed by name and have a factory method
with a generic signature.
- A simple matcher expression parser, that can be used to convert a matcher
expression string into actual matchers that can be used with the AST at
runtime.
Many features where omitted from this first revision to simplify this code
review. The main ideas are still represented in this change and it already has
support working use cases.
Things that are missing:
- Support for polymorphic matchers. These requires supporting code in the
registry, the marshallers and the variant type.
- Support for numbers, char and bool arguments to the matchers. This requires
supporting code in the parser and the variant type.
- A command line program putting everything together and providing an already
functional tool.
Patch by Samuel Benzaquen.
llvm-svn: 181768
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersTest.h')
| -rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h b/clang/unittests/ASTMatchers/ASTMatchersTest.h index 5fed85bb30b..05258f7fe2a 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.h +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h @@ -84,6 +84,41 @@ testing::AssertionResult notMatches(const std::string &Code, return matchesConditionally(Code, AMatcher, false, "-std=c++11"); } +inline testing::AssertionResult +matchesConditionallyDynamic(const std::string &Code, + const internal::DynTypedMatcher &AMatcher, + bool ExpectMatch, llvm::StringRef CompileArg) { + bool Found = false; + MatchFinder Finder; + Finder.addDynamicMatcher(AMatcher, new VerifyMatch(0, &Found)); + OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder)); + // Some tests use typeof, which is a gnu extension. + std::vector<std::string> Args(1, CompileArg); + if (!runToolOnCodeWithArgs(Factory->create(), Code, Args)) { + return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; + } + if (!Found && ExpectMatch) { + return testing::AssertionFailure() + << "Could not find match in \"" << Code << "\""; + } else if (Found && !ExpectMatch) { + return testing::AssertionFailure() + << "Found unexpected match in \"" << Code << "\""; + } + return testing::AssertionSuccess(); +} + +inline testing::AssertionResult +matchesDynamic(const std::string &Code, + const internal::DynTypedMatcher &AMatcher) { + return matchesConditionallyDynamic(Code, AMatcher, true, "-std=c++11"); +} + +inline testing::AssertionResult +notMatchesDynamic(const std::string &Code, + const internal::DynTypedMatcher &AMatcher) { + return matchesConditionallyDynamic(Code, AMatcher, false, "-std=c++11"); +} + template <typename T> testing::AssertionResult matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher, |

