[llvm-branch-commits] [cfe-branch] r155007 - in /cfe/branches/tooling: include/clang/ASTMatchers/ASTMatchFinder.h lib/ASTMatchers/ASTMatchFinder.cpp tools/fix-llvm-style/FixLLVMStyle.cpp tools/remove-cstr-calls/RemoveCStrCalls.cpp unittests/ASTMatchers/ASTMatchersTest.cpp
Manuel Klimek
klimek at google.com
Wed Apr 18 08:02:42 PDT 2012
Author: klimek
Date: Wed Apr 18 10:02:41 2012
New Revision: 155007
URL: http://llvm.org/viewvc/llvm-project?rev=155007&view=rev
Log:
Allow matchers to share a callback.
Modified:
cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchFinder.h
cfe/branches/tooling/lib/ASTMatchers/ASTMatchFinder.cpp
cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp
cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp
cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp
Modified: cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchFinder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchFinder.h?rev=155007&r1=155006&r2=155007&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchFinder.h (original)
+++ cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchFinder.h Wed Apr 18 10:02:41 2012
@@ -106,6 +106,8 @@
/// Calls 'Action' with the BoundNodes on every match.
/// Adding more than one 'NodeMatch' allows finding different matches in a
/// single pass over the AST.
+ ///
+ /// Does not take ownership of 'Action'.
/// @{
void addMatcher(const DeclarationMatcher &NodeMatch,
MatchCallback *Action);
Modified: cfe/branches/tooling/lib/ASTMatchers/ASTMatchFinder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/ASTMatchers/ASTMatchFinder.cpp?rev=155007&r1=155006&r2=155007&view=diff
==============================================================================
--- cfe/branches/tooling/lib/ASTMatchers/ASTMatchFinder.cpp (original)
+++ cfe/branches/tooling/lib/ASTMatchers/ASTMatchFinder.cpp Wed Apr 18 10:02:41 2012
@@ -559,7 +559,6 @@
It = Triggers.begin(), End = Triggers.end();
It != End; ++It) {
delete It->first;
- delete It->second;
}
}
Modified: cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp?rev=155007&r1=155006&r2=155007&view=diff
==============================================================================
--- cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp (original)
+++ cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp Wed Apr 18 10:02:41 2012
@@ -292,12 +292,13 @@
HasName("internal::PolymorphicMatcherWithParam1"),
HasName("internal::PolymorphicMatcherWithParam2")
)))));
-
+
+ FixLLVMStyle Callback(&Tool.GetReplacements());
Finder.addMatcher(StatementMatcher(AnyOf(
StatementMatcher(Id("ref", DeclarationReference(To(Id("declaration", FunctionMatch))))),
Call(Callee(Id("declaration", FunctionMatch)),
Callee(Id("callee", Expression()))))),
- new FixLLVMStyle(&Tool.GetReplacements()));
+ &Callback);
Finder.addMatcher(
DeclarationMatcher(AnyOf(
@@ -306,7 +307,7 @@
Id("declaration", FunctionMatch),
Not(Constructor())))
),
- new FixLLVMStyle(&Tool.GetReplacements()));
+ &Callback);
return Tool.Run(newFrontendActionFactory(&Finder));
}
Modified: cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp?rev=155007&r1=155006&r2=155007&view=diff
==============================================================================
--- cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp (original)
+++ cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp Wed Apr 18 10:02:41 2012
@@ -185,6 +185,7 @@
llvm::report_fatal_error(ErrorMessage);
tooling::RefactoringTool Tool(*Compilations, SourcePaths);
ast_matchers::MatchFinder Finder;
+ FixCStrCall Callback(&Tool.GetReplacements());
Finder.addMatcher(
ConstructorCall(
HasDeclaration(Method(HasName(StringConstructor))),
@@ -204,7 +205,7 @@
HasArgument(
1,
DefaultArgument())),
- new FixCStrCall(&Tool.GetReplacements()));
+ &Callback);
Finder.addMatcher(
ConstructorCall(
// Implicit constructors of these classes are overloaded
@@ -226,7 +227,7 @@
Callee(Id("member", MemberExpression())),
Callee(Method(HasName(StringCStrMethod))),
On(Id("arg", Expression())))))),
- new FixCStrCall(&Tool.GetReplacements()));
+ &Callback);
return Tool.Run(newFrontendActionFactory(&Finder));
}
Modified: cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=155007&r1=155006&r2=155007&view=diff
==============================================================================
--- cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp Wed Apr 18 10:02:41 2012
@@ -50,7 +50,8 @@
bool ExpectMatch) {
bool Found = false;
MatchFinder Finder;
- Finder.addMatcher(AMatcher, new VerifyMatch(0, &Found));
+ VerifyMatch Callback(0, &Found);
+ Finder.addMatcher(AMatcher, &Callback);
if (!runToolOnCode(Finder.newFrontendAction(), Code)) {
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
}
@@ -83,8 +84,8 @@
llvm::OwningPtr<BoundNodesCallback> ScopedVerifier(FindResultVerifier);
bool VerifiedResult = false;
MatchFinder Finder;
- Finder.addMatcher(
- AMatcher, new VerifyMatch(FindResultVerifier, &VerifiedResult));
+ VerifyMatch Callback(FindResultVerifier, &VerifiedResult);
+ Finder.addMatcher(AMatcher, &Callback);
if (!runToolOnCode(Finder.newFrontendAction(), Code)) {
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
}
More information about the llvm-branch-commits
mailing list