[llvm-branch-commits] [cfe-branch] r153950 - in /cfe/branches/tooling: include/clang/ASTMatchers/ASTMatchFinder.h include/clang/ASTMatchers/ASTMatchers.h include/clang/ASTMatchers/ASTMatchersInternal.h include/clang/ASTMatchers/ASTMatchersMacros.h include/clang/Tooling/Tooling.h lib/ASTMatchers/ASTMatchFinder.cpp lib/ASTMatchers/ASTMatchersInternal.cpp tools/fix-llvm-style/FixLLVMStyle.cpp tools/remove-cstr-calls/RemoveCStrCalls.cpp unittests/ASTMatchers/ASTMatchersTest.cpp
Manuel Klimek
klimek at google.com
Tue Apr 3 04:12:13 PDT 2012
Author: klimek
Date: Tue Apr 3 06:12:12 2012
New Revision: 153950
URL: http://llvm.org/viewvc/llvm-project?rev=153950&view=rev
Log:
Updating naming convention with automated fix-it script.
Modified:
cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchFinder.h
cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchers.h
cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchersMacros.h
cfe/branches/tooling/include/clang/Tooling/Tooling.h
cfe/branches/tooling/lib/ASTMatchers/ASTMatchFinder.cpp
cfe/branches/tooling/lib/ASTMatchers/ASTMatchersInternal.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=153950&r1=153949&r2=153950&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchFinder.h (original)
+++ cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchFinder.h Tue Apr 3 06:12:12 2012
@@ -88,14 +88,14 @@
class MatchCallback {
public:
virtual ~MatchCallback();
- virtual void Run(const MatchResult &Result) = 0;
+ virtual void run(const MatchResult &Result) = 0;
};
/// \brief Called when parsing is finished. Intended for testing only.
class ParsingDoneTestCallback {
public:
virtual ~ParsingDoneTestCallback();
- virtual void Run() = 0;
+ virtual void run() = 0;
};
MatchFinder();
@@ -107,23 +107,23 @@
/// Adding more than one 'NodeMatch' allows finding different matches in a
/// single pass over the AST.
/// @{
- void AddMatcher(const DeclarationMatcher &NodeMatch,
+ void addMatcher(const DeclarationMatcher &NodeMatch,
MatchCallback *Action);
- void AddMatcher(const TypeMatcher &NodeMatch,
+ void addMatcher(const TypeMatcher &NodeMatch,
MatchCallback *Action);
- void AddMatcher(const StatementMatcher &NodeMatch,
+ void addMatcher(const StatementMatcher &NodeMatch,
MatchCallback *Action);
/// @}
/// \brief Creates a clang FrontendAction that finds all matches.
- FrontendAction *NewFrontendAction();
+ FrontendAction *newFrontendAction();
/// \brief Registers a callback to notify the end of parsing.
///
/// The provided closure is called after parsing is done, before the AST is
/// traversed. Useful for benchmarking.
/// Each call to FindAll(...) will call the closure once.
- void RegisterTestCallbackAfterParsing(ParsingDoneTestCallback *ParsingDone);
+ void registerTestCallbackAfterParsing(ParsingDoneTestCallback *ParsingDone);
private:
/// \brief The MatchCallback*'s will be called every time the
Modified: cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchers.h?rev=153950&r1=153949&r2=153950&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchers.h Tue Apr 3 06:12:12 2012
@@ -67,12 +67,12 @@
/// FIXME: We'll need one of those for every base type.
/// @{
template <typename T>
- const T *GetDeclAs(const std::string &ID) const {
- return GetNodeAs<T>(DeclBindings, ID);
+ const T *getDeclAs(const std::string &ID) const {
+ return getNodeAs<T>(DeclBindings, ID);
}
template <typename T>
- const T *GetStmtAs(const std::string &ID) const {
- return GetNodeAs<T>(StmtBindings, ID);
+ const T *getStmtAs(const std::string &ID) const {
+ return getNodeAs<T>(StmtBindings, ID);
}
/// @}
@@ -83,7 +83,7 @@
: DeclBindings(DeclBindings), StmtBindings(StmtBindings) {}
template <typename T, typename MapT>
- const T *GetNodeAs(const MapT &Bindings, const std::string &ID) const {
+ const T *getNodeAs(const MapT &Bindings, const std::string &ID) const {
typename MapT::const_iterator It = Bindings.find(ID);
if (It == Bindings.end()) {
return NULL;
@@ -622,7 +622,7 @@
/// class Bar : public Foo {}; // derived from a type that X is a typedef of
AST_MATCHER_P(clang::CXXRecordDecl, IsDerivedFrom, std::string, Base) {
assert(!Base.empty());
- return Finder->ClassIsDerivedFrom(&Node, Base);
+ return Finder->classIsDerivedFrom(&Node, Base);
}
/// \brief Matches AST nodes that have child AST nodes that match the
@@ -635,7 +635,7 @@
///
/// ChildT must be an AST base type.
template <typename ChildT>
-internal::ArgumentAdaptingMatcher<internal::HasMatcher, ChildT> Has(
+internal::ArgumentAdaptingMatcher<internal::HasMatcher, ChildT> has(
const internal::Matcher<ChildT> &ChildMatcher) {
return internal::ArgumentAdaptingMatcher<internal::HasMatcher,
ChildT>(ChildMatcher);
@@ -653,7 +653,7 @@
/// DescendantT must be an AST base type.
template <typename DescendantT>
internal::ArgumentAdaptingMatcher<internal::HasDescendantMatcher, DescendantT>
-HasDescendant(const internal::Matcher<DescendantT> &DescendantMatcher) {
+hasDescendant(const internal::Matcher<DescendantT> &DescendantMatcher) {
return internal::ArgumentAdaptingMatcher<
internal::HasDescendantMatcher,
DescendantT>(DescendantMatcher);
@@ -673,7 +673,7 @@
/// As opposed to 'Has', 'ForEach' will cause a match for each result that
/// matches instead of only on the first one.
template <typename ChildT>
-internal::ArgumentAdaptingMatcher<internal::ForEachMatcher, ChildT> ForEach(
+internal::ArgumentAdaptingMatcher<internal::ForEachMatcher, ChildT> forEach(
const internal::Matcher<ChildT>& ChildMatcher) {
return internal::ArgumentAdaptingMatcher<
internal::ForEachMatcher,
@@ -700,7 +700,7 @@
/// class A { class B { class C { class D { class E {}; }; }; }; };
template <typename DescendantT>
internal::ArgumentAdaptingMatcher<internal::ForEachDescendantMatcher, DescendantT>
-ForEachDescendant(
+forEachDescendant(
const internal::Matcher<DescendantT>& DescendantMatcher) {
return internal::ArgumentAdaptingMatcher<
internal::ForEachDescendantMatcher,
@@ -741,7 +741,7 @@
.getImplicitObjectArgument()
->IgnoreParenImpCasts();
return (ExprNode != NULL &&
- InnerMatcher.Matches(*ExprNode, Finder, Builder));
+ InnerMatcher.matches(*ExprNode, Finder, Builder));
}
/// \brief Matches if the call expression's callee expression matches.
@@ -762,7 +762,7 @@
InnerMatcher) {
const clang::Expr *ExprNode = Node.getCallee();
return (ExprNode != NULL &&
- InnerMatcher.Matches(*ExprNode, Finder, Builder));
+ InnerMatcher.matches(*ExprNode, Finder, Builder));
}
/// \brief Matches if the call expression's callee's declaration matches the
@@ -790,7 +790,7 @@
TOOLING_COMPILE_ASSERT((llvm::is_base_of<clang::Expr, NodeType>::value ||
llvm::is_base_of<clang::ValueDecl, NodeType>::value),
instantiated_with_wrong_types);
- return InnerMatcher.Matches(Node.getType(), Finder, Builder);
+ return InnerMatcher.matches(Node.getType(), Finder, Builder);
}
/// \brief Overloaded to match the declaration of the expression's or value
@@ -825,7 +825,7 @@
clang::QualType, PointsTo, internal::Matcher<clang::QualType>,
InnerMatcher) {
return (Node->isPointerType() &&
- InnerMatcher.Matches(Node->getPointeeType(), Finder, Builder));
+ InnerMatcher.matches(Node->getPointeeType(), Finder, Builder));
}
/// \brief Overloaded to match the pointee type's declaration.
@@ -848,7 +848,7 @@
AST_MATCHER_P(clang::QualType, References, internal::Matcher<clang::QualType>,
InnerMatcher) {
return (Node->isReferenceType() &&
- InnerMatcher.Matches(Node->getPointeeType(), Finder, Builder));
+ InnerMatcher.matches(Node->getPointeeType(), Finder, Builder));
}
/// \brief Overloaded to match the referenced type's declaration.
@@ -863,7 +863,7 @@
const clang::Expr *ExprNode =
const_cast<clang::CXXMemberCallExpr&>(Node).getImplicitObjectArgument();
return (ExprNode != NULL &&
- InnerMatcher.Matches(*ExprNode, Finder, Builder));
+ InnerMatcher.matches(*ExprNode, Finder, Builder));
}
/// \brief Matches if the expression's type either matches the specified
@@ -892,7 +892,7 @@
InnerMatcher) {
const clang::Decl *DeclNode = Node.getDecl();
return (DeclNode != NULL &&
- InnerMatcher.Matches(*DeclNode, Finder, Builder));
+ InnerMatcher.matches(*DeclNode, Finder, Builder));
}
/// \brief Matches a variable declaration that has an initializer expression
@@ -906,7 +906,7 @@
InnerMatcher) {
const clang::Expr *Initializer = Node.getAnyInitializer();
return (Initializer != NULL &&
- InnerMatcher.Matches(*Initializer, Finder, Builder));
+ InnerMatcher.matches(*Initializer, Finder, Builder));
}
/// \brief Checks that a call expression or a constructor call expression has
@@ -936,7 +936,7 @@
NodeType>::value),
instantiated_with_wrong_types);
return (N < Node.getNumArgs() &&
- InnerMatcher.Matches(
+ InnerMatcher.matches(
*Node.getArg(N)->IgnoreParenImpCasts(), Finder, Builder));
}
@@ -953,7 +953,7 @@
internal::Matcher<clang::CXXCtorInitializer>, InnerMatcher) {
for (clang::CXXConstructorDecl::init_const_iterator I = Node.init_begin();
I != Node.init_end(); ++I) {
- if (InnerMatcher.Matches(**I, Finder, Builder)) {
+ if (InnerMatcher.matches(**I, Finder, Builder)) {
return true;
}
}
@@ -975,7 +975,7 @@
internal::Matcher<clang::FieldDecl>, InnerMatcher) {
const clang::FieldDecl *NodeAsDecl = Node.getMember();
return (NodeAsDecl != NULL &&
- InnerMatcher.Matches(*NodeAsDecl, Finder, Builder));
+ InnerMatcher.matches(*NodeAsDecl, Finder, Builder));
}
/// \brief Matches the initializer expression of a constructor initializer.
@@ -993,7 +993,7 @@
internal::Matcher<clang::Expr>, InnerMatcher) {
const clang::Expr* NodeAsExpr = Node.getInit();
return (NodeAsExpr != NULL &&
- InnerMatcher.Matches(*NodeAsExpr, Finder, Builder));
+ InnerMatcher.matches(*NodeAsExpr, Finder, Builder));
}
/// \brief Matches a contructor initializer if it is explicitly written in
@@ -1033,7 +1033,7 @@
NodeType>::value),
instantiated_with_wrong_types);
for (unsigned I = 0; I < Node.getNumArgs(); ++I) {
- if (InnerMatcher.Matches(*Node.getArg(I)->IgnoreParenImpCasts(),
+ if (InnerMatcher.matches(*Node.getArg(I)->IgnoreParenImpCasts(),
Finder, Builder)) {
return true;
}
@@ -1053,7 +1053,7 @@
unsigned, N, internal::Matcher<clang::ParmVarDecl>,
InnerMatcher) {
return (N < Node.getNumParams() &&
- InnerMatcher.Matches(
+ InnerMatcher.matches(
*Node.getParamDecl(N), Finder, Builder));
}
@@ -1070,7 +1070,7 @@
AST_MATCHER_P(clang::FunctionDecl, HasAnyParameter,
internal::Matcher<clang::ParmVarDecl>, InnerMatcher) {
for (unsigned I = 0; I < Node.getNumParams(); ++I) {
- if (InnerMatcher.Matches(*Node.getParamDecl(I), Finder, Builder)) {
+ if (InnerMatcher.matches(*Node.getParamDecl(I), Finder, Builder)) {
return true;
}
}
@@ -1090,7 +1090,7 @@
has_condition_requires_if_statement_or_conditional_operator);
const clang::Expr *const Condition = Node.getCond();
return (Condition != NULL &&
- InnerMatcher.Matches(*Condition, Finder, Builder));
+ InnerMatcher.matches(*Condition, Finder, Builder));
}
/// \brief Matches the condition variable statement in an if statement.
@@ -1104,7 +1104,7 @@
const clang::DeclStmt* const DeclarationStatement =
Node.getConditionVariableDeclStmt();
return DeclarationStatement != NULL &&
- InnerMatcher.Matches(*DeclarationStatement, Finder, Builder);
+ InnerMatcher.matches(*DeclarationStatement, Finder, Builder);
}
/// \brief Matches a 'for' statement that has a given body.
@@ -1119,7 +1119,7 @@
InnerMatcher) {
const clang::Stmt *const Statement = Node.getBody();
return (Statement != NULL &&
- InnerMatcher.Matches(*Statement, Finder, Builder));
+ InnerMatcher.matches(*Statement, Finder, Builder));
}
/// \brief Matches compound statements where at least one substatement matches
@@ -1136,7 +1136,7 @@
for (clang::CompoundStmt::const_body_iterator It = Node.body_begin();
It != Node.body_end();
++It) {
- if (InnerMatcher.Matches(**It, Finder, Builder)) return true;
+ if (InnerMatcher.matches(**It, Finder, Builder)) return true;
}
return false;
}
@@ -1186,7 +1186,7 @@
internal::Matcher<clang::Expr>, InnerMatcher) {
clang::Expr *LeftHandSide = Node.getLHS();
return (LeftHandSide != NULL &&
- InnerMatcher.Matches(*LeftHandSide, Finder, Builder));
+ InnerMatcher.matches(*LeftHandSide, Finder, Builder));
}
/// \brief Matches the right hand side of binary operator expressions.
@@ -1197,7 +1197,7 @@
internal::Matcher<clang::Expr>, InnerMatcher) {
clang::Expr *RightHandSide = Node.getRHS();
return (RightHandSide != NULL &&
- InnerMatcher.Matches(*RightHandSide, Finder, Builder));
+ InnerMatcher.matches(*RightHandSide, Finder, Builder));
}
/// \brief Matches if either the left hand side or the right hand side of a
@@ -1215,7 +1215,7 @@
internal::Matcher<clang::Expr>, InnerMatcher) {
const clang::Expr * const Operand = Node.getSubExpr();
return (Operand != NULL &&
- InnerMatcher.Matches(*Operand, Finder, Builder));
+ InnerMatcher.matches(*Operand, Finder, Builder));
}
/// Matches if the implicit cast's source expression matches the given matcher.
@@ -1229,7 +1229,7 @@
internal::Matcher<clang::Expr>, InnerMatcher) {
const clang::Expr* const SubExpression = Node.getSubExpr();
return (SubExpression != NULL &&
- InnerMatcher.Matches(*SubExpression, Finder, Builder));
+ InnerMatcher.matches(*SubExpression, Finder, Builder));
}
/// \brief Matches casts whose destination type matches a given matcher.
@@ -1239,7 +1239,7 @@
AST_MATCHER_P(clang::ExplicitCastExpr, HasDestinationType,
internal::Matcher<clang::QualType>, InnerMatcher) {
const clang::QualType NodeType = Node.getTypeAsWritten();
- return InnerMatcher.Matches(NodeType, Finder, Builder);
+ return InnerMatcher.matches(NodeType, Finder, Builder);
}
/// \brief Matches implicit casts whose destination type matches a given
@@ -1248,7 +1248,7 @@
/// FIXME: Unit test this matcher
AST_MATCHER_P(clang::ImplicitCastExpr, HasImplicitDestinationType,
internal::Matcher<clang::QualType>, InnerMatcher) {
- return InnerMatcher.Matches(Node.getType(), Finder, Builder);
+ return InnerMatcher.matches(Node.getType(), Finder, Builder);
}
/// \brief Matches the true branch expression of a conditional operator.
@@ -1259,7 +1259,7 @@
internal::Matcher<clang::Expr>, InnerMatcher) {
clang::Expr *Expression = Node.getTrueExpr();
return (Expression != NULL &&
- InnerMatcher.Matches(*Expression, Finder, Builder));
+ InnerMatcher.matches(*Expression, Finder, Builder));
}
/// \brief Matches the false branch expression of a conditional operator.
@@ -1270,7 +1270,7 @@
internal::Matcher<clang::Expr>, InnerMatcher) {
clang::Expr *Expression = Node.getFalseExpr();
return (Expression != NULL &&
- InnerMatcher.Matches(*Expression, Finder, Builder));
+ InnerMatcher.matches(*Expression, Finder, Builder));
}
/// \brief Matches if a declaration has a body attached.
@@ -1307,7 +1307,7 @@
internal::Matcher<clang::CXXRecordDecl>, InnerMatcher) {
const clang::CXXRecordDecl *Parent = Node.getParent();
return (Parent != NULL &&
- InnerMatcher.Matches(*Parent, Finder, Builder));
+ InnerMatcher.matches(*Parent, Finder, Builder));
}
/// \brief Matches member expressions that are called with '->' as opposed
@@ -1356,7 +1356,7 @@
/// but not first.second (because the member name there is "second").
AST_MATCHER_P(clang::MemberExpr, Member,
internal::Matcher<clang::ValueDecl>, InnerMatcher) {
- return InnerMatcher.Matches(*Node.getMemberDecl(), Finder, Builder);
+ return InnerMatcher.matches(*Node.getMemberDecl(), Finder, Builder);
}
/// \brief Matches a member expression where the object expression is
@@ -1371,7 +1371,7 @@
/// matching "x" and the implicit object expression of "m" which has type X*.
AST_MATCHER_P(clang::MemberExpr, HasObjectExpression,
internal::Matcher<clang::Expr>, InnerMatcher) {
- return InnerMatcher.Matches(*Node.getBase(), Finder, Builder);
+ return InnerMatcher.matches(*Node.getBase(), Finder, Builder);
}
/// \brief Matches template instantiations of function, class, or static
Modified: cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=153950&r1=153949&r2=153950&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchersInternal.h Tue Apr 3 06:12:12 2012
@@ -78,7 +78,7 @@
/// \brief Called multiple times during a single call to VisitMatches(...).
///
/// 'BoundNodesView' contains the bound nodes for a single match.
- virtual void VisitMatch(const BoundNodes& BoundNodesView) = 0;
+ virtual void visitMatch(const BoundNodes& BoundNodesView) = 0;
};
BoundNodesTree();
@@ -89,21 +89,21 @@
const std::vector<BoundNodesTree> RecursiveBindings);
/// \brief Adds all bound nodes to bound_nodes_builder.
- void CopyTo(BoundNodesTreeBuilder* Builder) const;
+ void copyTo(BoundNodesTreeBuilder* Builder) const;
/// \brief Visits all matches that this BoundNodesTree represents.
///
/// The ownership of 'visitor' remains at the caller.
- void VisitMatches(Visitor* ResultVisitor);
+ void visitMatches(Visitor* ResultVisitor);
private:
- void VisitMatchesRecursively(
+ void visitMatchesRecursively(
Visitor* ResultVistior,
std::map<std::string, const clang::Decl*> DeclBindings,
std::map<std::string, const clang::Stmt*> StmtBindings);
template <typename T>
- void CopyBindingsTo(const T& bindings, BoundNodesTreeBuilder* Builder) const;
+ void copyBindingsTo(const T& bindings, BoundNodesTreeBuilder* Builder) const;
// FIXME: Find out whether we want to use different data structures here -
// first benchmarks indicate that it doesn't matter though.
@@ -126,17 +126,17 @@
///
/// FIXME: Add overloads for all AST base types.
/// @{
- void SetBinding(const std::pair<const std::string,
+ void setBinding(const std::pair<const std::string,
const clang::Decl*>& binding);
- void SetBinding(const std::pair<const std::string,
+ void setBinding(const std::pair<const std::string,
const clang::Stmt*>& binding);
/// @}
/// \brief Adds a branch in the tree.
- void AddMatch(const BoundNodesTree& Bindings);
+ void addMatch(const BoundNodesTree& Bindings);
/// \brief Returns a BoundNodes object containing all current bindings.
- BoundNodesTree Build() const;
+ BoundNodesTree build() const;
private:
BoundNodesTreeBuilder(const BoundNodesTreeBuilder&); // DO NOT IMPLEMENT
@@ -166,7 +166,7 @@
///
/// May bind 'Node' to an ID via 'Builder', or recurse into
/// the AST via 'Finder'.
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const = 0;
};
@@ -178,14 +178,14 @@
/// \brief Returns true if the matcher matches the provided node.
///
/// A subclass must implement this instead of Matches().
- virtual bool MatchesNode(const T &Node) const = 0;
+ virtual bool matchesNode(const T &Node) const = 0;
private:
/// Implements MatcherInterface::Matches.
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder * /* Finder */,
BoundNodesTreeBuilder * /* Builder */) const {
- return MatchesNode(Node);
+ return matchesNode(Node);
}
};
@@ -205,10 +205,10 @@
: Implementation(Implementation) {}
/// \brief Forwards the call to the underlying MatcherInterface<T> pointer.
- bool Matches(const T &Node,
+ bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- return Implementation->Matches(Node, Finder, Builder);
+ return Implementation->matches(Node, Finder, Builder);
}
/// \brief Implicitly converts this object to a Matcher<Derived>.
@@ -220,7 +220,7 @@
}
/// \brief Returns an ID that uniquely identifies the matcher.
- uint64_t GetID() const {
+ uint64_t getID() const {
/// FIXME: Document the requirements this imposes on matcher
/// implementations (no new() implementation_ during a Matches()).
return reinterpret_cast<uint64_t>(Implementation.getPtr());
@@ -235,10 +235,10 @@
explicit ImplicitCastMatcher(const Matcher<T> &From)
: From(From) {}
- virtual bool Matches(const Derived &Node,
+ virtual bool matches(const Derived &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- return From.Matches(Node, Finder, Builder);
+ return From.matches(Node, Finder, Builder);
}
private:
@@ -268,40 +268,40 @@
explicit HasDeclarationMatcher(const Matcher<clang::Decl> &InnerMatcher)
: InnerMatcher(InnerMatcher) {}
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- return MatchesSpecialized(Node, Finder, Builder);
+ return matchesSpecialized(Node, Finder, Builder);
}
private:
/// \brief Extracts the CXXRecordDecl of a QualType and returns whether the
/// inner matcher matches on it.
- bool MatchesSpecialized(const clang::QualType &Node, ASTMatchFinder *Finder,
+ bool matchesSpecialized(const clang::QualType &Node, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
/// FIXME: Add other ways to convert...
clang::CXXRecordDecl *NodeAsRecordDecl = Node->getAsCXXRecordDecl();
return NodeAsRecordDecl != NULL &&
- InnerMatcher.Matches(*NodeAsRecordDecl, Finder, Builder);
+ InnerMatcher.matches(*NodeAsRecordDecl, Finder, Builder);
}
/// \brief Extracts the Decl of the callee of a CallExpr and returns whether
/// the inner matcher matches on it.
- bool MatchesSpecialized(const clang::CallExpr &Node, ASTMatchFinder *Finder,
+ bool matchesSpecialized(const clang::CallExpr &Node, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
const clang::Decl *NodeAsDecl = Node.getCalleeDecl();
return NodeAsDecl != NULL &&
- InnerMatcher.Matches(*NodeAsDecl, Finder, Builder);
+ InnerMatcher.matches(*NodeAsDecl, Finder, Builder);
}
/// \brief Extracts the Decl of the constructor call and returns whether the
/// inner matcher matches on it.
- bool MatchesSpecialized(const clang::CXXConstructExpr &Node,
+ bool matchesSpecialized(const clang::CXXConstructExpr &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
const clang::Decl *NodeAsDecl = Node.getConstructor();
return NodeAsDecl != NULL &&
- InnerMatcher.Matches(*NodeAsDecl, Finder, Builder);
+ InnerMatcher.matches(*NodeAsDecl, Finder, Builder);
}
const Matcher<clang::Decl> InnerMatcher;
@@ -324,21 +324,21 @@
public:
virtual ~UntypedBaseMatcher() {}
- virtual bool Matches(const clang::Decl &DeclNode, ASTMatchFinder *Finder,
+ virtual bool matches(const clang::Decl &DeclNode, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
return false;
}
- virtual bool Matches(const clang::QualType &TypeNode, ASTMatchFinder *Finder,
+ virtual bool matches(const clang::QualType &TypeNode, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
return false;
}
- virtual bool Matches(const clang::Stmt &StmtNode, ASTMatchFinder *Finder,
+ virtual bool matches(const clang::Stmt &StmtNode, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
return false;
}
/// \brief Returns a unique ID for the matcher.
- virtual uint64_t GetID() const = 0;
+ virtual uint64_t getID() const = 0;
};
/// \brief An UntypedBaseMatcher that overwrites the Matches(...) method for
@@ -351,21 +351,21 @@
explicit TypedBaseMatcher(const Matcher<T> &InnerMatcher)
: InnerMatcher(InnerMatcher) {}
- using UntypedBaseMatcher::Matches;
+ using UntypedBaseMatcher::matches;
/// \brief Implements UntypedBaseMatcher::Matches.
///
/// Since T is guaranteed to be a "base" AST node type, this method is
/// guaranteed to override one of the Matches() methods from
/// UntypedBaseMatcher.
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- return InnerMatcher.Matches(Node, Finder, Builder);
+ return InnerMatcher.matches(Node, Finder, Builder);
}
/// \brief Implements UntypedBaseMatcher::GetID.
- virtual uint64_t GetID() const {
- return InnerMatcher.GetID();
+ virtual uint64_t getID() const {
+ return InnerMatcher.getID();
}
private:
@@ -407,26 +407,26 @@
/// from a base type with the given name.
///
/// A class is considered to be also derived from itself.
- virtual bool ClassIsDerivedFrom(const clang::CXXRecordDecl *Declaration,
+ virtual bool classIsDerivedFrom(const clang::CXXRecordDecl *Declaration,
const std::string &BaseName) const = 0;
// FIXME: Implement for other base nodes.
- virtual bool MatchesChildOf(const clang::Decl &DeclNode,
+ virtual bool matchesChildOf(const clang::Decl &DeclNode,
const UntypedBaseMatcher &BaseMatcher,
BoundNodesTreeBuilder *Builder,
TraversalKind Traverse,
BindKind Bind) = 0;
- virtual bool MatchesChildOf(const clang::Stmt &StmtNode,
+ virtual bool matchesChildOf(const clang::Stmt &StmtNode,
const UntypedBaseMatcher &BaseMatcher,
BoundNodesTreeBuilder *Builder,
TraversalKind Traverse,
BindKind Bind) = 0;
- virtual bool MatchesDescendantOf(const clang::Decl &DeclNode,
+ virtual bool matchesDescendantOf(const clang::Decl &DeclNode,
const UntypedBaseMatcher &BaseMatcher,
BoundNodesTreeBuilder *Builder,
BindKind Bind) = 0;
- virtual bool MatchesDescendantOf(const clang::Stmt &StmtNode,
+ virtual bool matchesDescendantOf(const clang::Stmt &StmtNode,
const UntypedBaseMatcher &BaseMatcher,
BoundNodesTreeBuilder *Builder,
BindKind Bind) = 0;
@@ -533,7 +533,7 @@
template <typename T>
class TrueMatcher : public SingleNodeMatcherInterface<T> {
public:
- virtual bool MatchesNode(const T &Node) const {
+ virtual bool matchesNode(const T &Node) const {
return true;
}
};
@@ -547,12 +547,12 @@
explicit DynCastMatcher(const Matcher<To> &InnerMatcher)
: InnerMatcher(InnerMatcher) {}
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
const To *InnerMatchValue = llvm::dyn_cast<To>(&Node);
return InnerMatchValue != NULL &&
- InnerMatcher.Matches(*InnerMatchValue, Finder, Builder);
+ InnerMatcher.matches(*InnerMatchValue, Finder, Builder);
}
private:
@@ -582,12 +582,12 @@
IdMatcher(const std::string &ID, const Matcher<T> &InnerMatcher)
: ID(ID), InnerMatcher(InnerMatcher) {}
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- bool Result = InnerMatcher.Matches(Node, Finder, Builder);
+ bool Result = InnerMatcher.matches(Node, Finder, Builder);
if (Result) {
- Builder->SetBinding(std::pair<const std::string, const T*>(ID, &Node));
+ Builder->setBinding(std::pair<const std::string, const T*>(ID, &Node));
}
return Result;
}
@@ -609,10 +609,10 @@
explicit HasMatcher(const Matcher<ChildT> &ChildMatcher)
: ChildMatcher(ChildMatcher) {}
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- return Finder->MatchesChildOf(
+ return Finder->matchesChildOf(
Node, ChildMatcher, Builder,
ASTMatchFinder::TK_IgnoreImplicitCastsAndParentheses,
ASTMatchFinder::BK_First);
@@ -635,10 +635,10 @@
explicit ForEachMatcher(const Matcher<ChildT> &ChildMatcher)
: ChildMatcher(ChildMatcher) {}
- virtual bool Matches(const T& Node,
+ virtual bool matches(const T& Node,
ASTMatchFinder* Finder,
BoundNodesTreeBuilder* Builder) const {
- return Finder->MatchesChildOf(
+ return Finder->matchesChildOf(
Node, ChildMatcher, Builder,
ASTMatchFinder::TK_IgnoreImplicitCastsAndParentheses,
ASTMatchFinder::BK_All);
@@ -659,10 +659,10 @@
explicit NotMatcher(const Matcher<T> &InnerMatcher)
: InnerMatcher(InnerMatcher) {}
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- return !InnerMatcher.Matches(Node, Finder, Builder);
+ return !InnerMatcher.matches(Node, Finder, Builder);
}
private:
@@ -680,11 +680,11 @@
AllOfMatcher(const Matcher<T> &InnerMatcher1, const Matcher<T> &InnerMatcher2)
: InnerMatcher1(InnerMatcher1), InnerMatcher2(InnerMatcher2) {}
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- return InnerMatcher1.Matches(Node, Finder, Builder) &&
- InnerMatcher2.Matches(Node, Finder, Builder);
+ return InnerMatcher1.matches(Node, Finder, Builder) &&
+ InnerMatcher2.matches(Node, Finder, Builder);
}
private:
@@ -705,11 +705,11 @@
AnyOfMatcher(const Matcher<T> &InnerMatcher1, const Matcher<T> &InnerMatcher2)
: InnerMatcher1(InnerMatcher1), InnertMatcher2(InnerMatcher2) {}
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- return InnerMatcher1.Matches(Node, Finder, Builder) ||
- InnertMatcher2.Matches(Node, Finder, Builder);
+ return InnerMatcher1.matches(Node, Finder, Builder) ||
+ InnertMatcher2.matches(Node, Finder, Builder);
}
private:
@@ -747,10 +747,10 @@
explicit HasDescendantMatcher(const Matcher<DescendantT> &DescendantMatcher)
: DescendantMatcher(DescendantMatcher) {}
- virtual bool Matches(const T &Node,
+ virtual bool matches(const T &Node,
ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- return Finder->MatchesDescendantOf(
+ return Finder->matchesDescendantOf(
Node, DescendantMatcher, Builder, ASTMatchFinder::BK_First);
}
@@ -773,10 +773,10 @@
const Matcher<DescendantT>& DescendantMatcher)
: DescendantMatcher(DescendantMatcher) {}
- virtual bool Matches(const T& Node,
+ virtual bool matches(const T& Node,
ASTMatchFinder* Finder,
BoundNodesTreeBuilder* Builder) const {
- return Finder->MatchesDescendantOf(Node, DescendantMatcher, Builder,
+ return Finder->matchesDescendantOf(Node, DescendantMatcher, Builder,
ASTMatchFinder::BK_All);
}
@@ -798,7 +798,7 @@
explicit ValueEqualsMatcher(const ValueT &ExpectedValue)
: ExpectedValue(ExpectedValue) {}
- virtual bool MatchesNode(const T &Node) const {
+ virtual bool matchesNode(const T &Node) const {
return Node.getValue() == ExpectedValue;
}
@@ -814,7 +814,7 @@
(llvm::is_base_of<clang::FunctionDecl, T>::value),
is_definition_requires_isThisDeclarationADefinition_method);
public:
- virtual bool MatchesNode(const T &Node) const {
+ virtual bool matchesNode(const T &Node) const {
return Node.isThisDeclarationADefinition();
}
};
@@ -828,7 +828,7 @@
(llvm::is_base_of<clang::CXXRecordDecl, T>::value),
requires_getTemplateSpecializationKind_method);
public:
- virtual bool Matches(const T& Node,
+ virtual bool matches(const T& Node,
ASTMatchFinder* Finder,
BoundNodesTreeBuilder* Builder) const {
return (Node.getTemplateSpecializationKind() ==
@@ -840,7 +840,7 @@
class IsArrowMatcher : public SingleNodeMatcherInterface<clang::MemberExpr> {
public:
- virtual bool MatchesNode(const clang::MemberExpr &Node) const {
+ virtual bool matchesNode(const clang::MemberExpr &Node) const {
return Node.isArrow();
}
};
@@ -848,7 +848,7 @@
class IsConstQualifiedMatcher
: public SingleNodeMatcherInterface<clang::QualType> {
public:
- virtual bool MatchesNode(const clang::QualType& Node) const {
+ virtual bool matchesNode(const clang::QualType& Node) const {
return Node.isConstQualified();
}
};
Modified: cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchersMacros.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchersMacros.h?rev=153950&r1=153949&r2=153950&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchersMacros.h (original)
+++ cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchersMacros.h Tue Apr 3 06:12:12 2012
@@ -42,7 +42,7 @@
: public MatcherInterface<Type> { \
public: \
explicit matcher_##DefineMatcher##Matcher() {} \
- virtual bool Matches( \
+ virtual bool matches( \
const Type &Node, ASTMatchFinder *Finder, \
BoundNodesTreeBuilder *Builder) const; \
}; \
@@ -51,7 +51,7 @@
return internal::MakeMatcher( \
new internal::matcher_##DefineMatcher##Matcher()); \
} \
- inline bool internal::matcher_##DefineMatcher##Matcher::Matches( \
+ inline bool internal::matcher_##DefineMatcher##Matcher::matches( \
const Type &Node, ASTMatchFinder *Finder, \
BoundNodesTreeBuilder *Builder) const
@@ -75,7 +75,7 @@
public: \
explicit matcher_##DefineMatcher##Matcher( \
const ParamType &A##Param) : Param(A##Param) {} \
- virtual bool Matches( \
+ virtual bool matches( \
const Type &Node, ASTMatchFinder *Finder, \
BoundNodesTreeBuilder *Builder) const; \
private: \
@@ -86,7 +86,7 @@
return internal::MakeMatcher( \
new internal::matcher_##DefineMatcher##Matcher(Param)); \
} \
- inline bool internal::matcher_##DefineMatcher##Matcher::Matches( \
+ inline bool internal::matcher_##DefineMatcher##Matcher::matches( \
const Type &Node, ASTMatchFinder *Finder, \
BoundNodesTreeBuilder *Builder) const
@@ -113,7 +113,7 @@
matcher_##DefineMatcher##Matcher( \
const ParamType1 &A##Param1, const ParamType2 &A##Param2) \
: Param1(A##Param1), Param2(A##Param2) {} \
- virtual bool Matches( \
+ virtual bool matches( \
const Type &Node, ASTMatchFinder *Finder, \
BoundNodesTreeBuilder *Builder) const; \
private: \
@@ -127,7 +127,7 @@
new internal::matcher_##DefineMatcher##Matcher( \
Param1, Param2)); \
} \
- inline bool internal::matcher_##DefineMatcher##Matcher::Matches( \
+ inline bool internal::matcher_##DefineMatcher##Matcher::matches( \
const Type &Node, ASTMatchFinder *Finder, \
BoundNodesTreeBuilder *Builder) const
@@ -148,7 +148,7 @@
public: \
explicit matcher_##DefineMatcher##Matcher( \
const ParamType &A##Param) : Param(A##Param) {} \
- virtual bool Matches( \
+ virtual bool matches( \
const NodeType &Node, ASTMatchFinder *Finder, \
BoundNodesTreeBuilder *Builder) const; \
private: \
@@ -164,7 +164,7 @@
ParamType >(Param); \
} \
template <typename NodeType, typename ParamT> \
- bool internal::matcher_##DefineMatcher##Matcher<NodeType, ParamT>::Matches( \
+ bool internal::matcher_##DefineMatcher##Matcher<NodeType, ParamT>::matches( \
const NodeType &Node, ASTMatchFinder *Finder, \
BoundNodesTreeBuilder *Builder) const
@@ -186,7 +186,7 @@
matcher_##DefineMatcher##Matcher( \
const ParamType1 &A##Param1, const ParamType2 &A##Param2) \
: Param1(A##Param1), Param2(A##Param2) {} \
- virtual bool Matches( \
+ virtual bool matches( \
const NodeType &Node, ASTMatchFinder *Finder, \
BoundNodesTreeBuilder *Builder) const; \
private: \
@@ -205,7 +205,7 @@
} \
template <typename NodeType, typename ParamT1, typename ParamT2> \
bool internal::matcher_##DefineMatcher##Matcher< \
- NodeType, ParamT1, ParamT2>::Matches( \
+ NodeType, ParamT1, ParamT2>::matches( \
const NodeType &Node, ASTMatchFinder *Finder, \
BoundNodesTreeBuilder *Builder) const
Modified: cfe/branches/tooling/include/clang/Tooling/Tooling.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Tooling/Tooling.h?rev=153950&r1=153949&r2=153950&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Tooling/Tooling.h (original)
+++ cfe/branches/tooling/include/clang/Tooling/Tooling.h Tue Apr 3 06:12:12 2012
@@ -260,7 +260,7 @@
: ActionFactory(ActionFactory) {}
virtual clang::FrontendAction *New() {
- return ActionFactory->NewFrontendAction();
+ return ActionFactory->newFrontendAction();
}
private:
Modified: cfe/branches/tooling/lib/ASTMatchers/ASTMatchFinder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/ASTMatchers/ASTMatchFinder.cpp?rev=153950&r1=153949&r2=153950&view=diff
==============================================================================
--- cfe/branches/tooling/lib/ASTMatchers/ASTMatchFinder.cpp (original)
+++ cfe/branches/tooling/lib/ASTMatchers/ASTMatchFinder.cpp Tue Apr 3 06:12:12 2012
@@ -32,7 +32,7 @@
// not in 'AMap'.
template <typename Map>
static const typename Map::mapped_type *
-Find(const Map &AMap, const typename Map::key_type &Key) {
+find(const Map &AMap, const typename Map::key_type &Key) {
typename Map::const_iterator It = AMap.find(Key);
return It == AMap.end() ? NULL : &It->second;
}
@@ -87,9 +87,9 @@
// - Traverse*(c) in turn calls Traverse(c), completing the
// recursion.
template <typename T>
- bool FindMatch(const T &Node) {
- Reset();
- Traverse(Node);
+ bool findMatch(const T &Node) {
+ reset();
+ traverse(Node);
return Matches;
}
@@ -97,7 +97,7 @@
// They are public only to allow CRTP to work. They are *not *part
// of the public API of this class.
bool TraverseDecl(clang::Decl *DeclNode) {
- return (DeclNode == NULL) || Traverse(*DeclNode);
+ return (DeclNode == NULL) || traverse(*DeclNode);
}
bool TraverseStmt(clang::Stmt *StmtNode) {
const clang::Stmt *StmtToTraverse = StmtNode;
@@ -108,10 +108,10 @@
StmtToTraverse = ExprNode->IgnoreParenImpCasts();
}
}
- return (StmtToTraverse == NULL) || Traverse(*StmtToTraverse);
+ return (StmtToTraverse == NULL) || traverse(*StmtToTraverse);
}
bool TraverseType(clang::QualType TypeNode) {
- return Traverse(TypeNode);
+ return traverse(TypeNode);
}
bool shouldVisitTemplateInstantiations() const { return true; }
@@ -127,20 +127,20 @@
};
// Resets the state of this object.
- void Reset() {
+ void reset() {
Matches = false;
CurrentDepth = -1;
}
// Forwards the call to the corresponding Traverse*() method in the
// base visitor class.
- bool BaseTraverse(const clang::Decl &DeclNode) {
+ bool baseTraverse(const clang::Decl &DeclNode) {
return VisitorBase::TraverseDecl(const_cast<clang::Decl*>(&DeclNode));
}
- bool BaseTraverse(const clang::Stmt &StmtNode) {
+ bool baseTraverse(const clang::Stmt &StmtNode) {
return VisitorBase::TraverseStmt(const_cast<clang::Stmt*>(&StmtNode));
}
- bool BaseTraverse(clang::QualType TypeNode) {
+ bool baseTraverse(clang::QualType TypeNode) {
return VisitorBase::TraverseType(TypeNode);
}
@@ -148,23 +148,23 @@
// traversal should continue after this function returns; also sets
// matched_ to true if a match is found during the traversal.
template <typename T>
- bool Traverse(const T &Node) {
+ bool traverse(const T &Node) {
TOOLING_COMPILE_ASSERT(IsBaseType<T>::value,
traverse_can_only_be_instantiated_with_base_type);
ScopedIncrement ScopedDepth(&CurrentDepth);
if (CurrentDepth == 0) {
// We don't want to match the root node, so just recurse.
- return BaseTraverse(Node);
+ return baseTraverse(Node);
}
if (Bind != ASTMatchFinder::BK_All) {
- if (BaseMatcher->Matches(Node, Finder, Builder)) {
+ if (BaseMatcher->matches(Node, Finder, Builder)) {
Matches = true;
return false; // Abort as soon as a match is found.
}
if (CurrentDepth < MaxDepth) {
// The current node doesn't match, and we haven't reached the
// maximum depth yet, so recurse.
- return BaseTraverse(Node);
+ return baseTraverse(Node);
}
// The current node doesn't match, and we have reached the
// maximum depth, so don't recurse (but continue the traversal
@@ -172,13 +172,13 @@
return true;
} else {
BoundNodesTreeBuilder RecursiveBuilder;
- if (BaseMatcher->Matches(Node, Finder, &RecursiveBuilder)) {
+ if (BaseMatcher->matches(Node, Finder, &RecursiveBuilder)) {
// After the first match the matcher succeeds.
Matches = true;
- Builder->AddMatch(RecursiveBuilder.Build());
+ Builder->addMatch(RecursiveBuilder.build());
}
if (CurrentDepth < MaxDepth) {
- BaseTraverse(Node);
+ baseTraverse(Node);
}
// In kBindAll mode we always search for more matches.
return true;
@@ -263,72 +263,72 @@
// Matches children or descendants of 'Node' with 'BaseMatcher'.
template <typename T>
- bool MemoizedMatchesRecursively(const T &Node,
+ bool memoizedMatchesRecursively(const T &Node,
const UntypedBaseMatcher &BaseMatcher,
BoundNodesTreeBuilder *Builder, int MaxDepth,
TraversalKind Traversal, BindKind Bind) {
TOOLING_COMPILE_ASSERT((llvm::is_same<T, clang::Decl>::value) ||
(llvm::is_same<T, clang::Stmt>::value),
type_does_not_support_memoization);
- const UntypedMatchInput input(BaseMatcher.GetID(), &Node);
+ const UntypedMatchInput input(BaseMatcher.getID(), &Node);
std::pair<MemoizationMap::iterator, bool> InsertResult
= ResultCache.insert(std::make_pair(input, MemoizedMatchResult()));
if (InsertResult.second) {
BoundNodesTreeBuilder DescendantBoundNodesBuilder;
InsertResult.first->second.ResultOfMatch =
- MatchesRecursively(Node, BaseMatcher, &DescendantBoundNodesBuilder,
+ matchesRecursively(Node, BaseMatcher, &DescendantBoundNodesBuilder,
MaxDepth, Traversal, Bind);
InsertResult.first->second.Nodes =
- DescendantBoundNodesBuilder.Build();
+ DescendantBoundNodesBuilder.build();
}
- InsertResult.first->second.Nodes.CopyTo(Builder);
+ InsertResult.first->second.Nodes.copyTo(Builder);
return InsertResult.first->second.ResultOfMatch;
}
// Matches children or descendants of 'Node' with 'BaseMatcher'.
template <typename T>
- bool MatchesRecursively(const T &Node, const UntypedBaseMatcher &BaseMatcher,
+ bool matchesRecursively(const T &Node, const UntypedBaseMatcher &BaseMatcher,
BoundNodesTreeBuilder *Builder, int MaxDepth,
TraversalKind Traversal, BindKind Bind) {
MatchChildASTVisitor Visitor(
&BaseMatcher, this, Builder, MaxDepth, Traversal, Bind);
- return Visitor.FindMatch(Node);
+ return Visitor.findMatch(Node);
}
- virtual bool ClassIsDerivedFrom(const clang::CXXRecordDecl *Declaration,
+ virtual bool classIsDerivedFrom(const clang::CXXRecordDecl *Declaration,
const std::string &BaseName) const;
// Implements ASTMatchFinder::MatchesChildOf.
- virtual bool MatchesChildOf(const clang::Decl &DeclNode,
+ virtual bool matchesChildOf(const clang::Decl &DeclNode,
const UntypedBaseMatcher &BaseMatcher,
BoundNodesTreeBuilder *Builder,
TraversalKind Traversal,
BindKind Bind) {
- return MatchesRecursively(DeclNode, BaseMatcher, Builder, 1, Traversal,
+ return matchesRecursively(DeclNode, BaseMatcher, Builder, 1, Traversal,
Bind);
}
- virtual bool MatchesChildOf(const clang::Stmt &StmtNode,
+ virtual bool matchesChildOf(const clang::Stmt &StmtNode,
const UntypedBaseMatcher &BaseMatcher,
BoundNodesTreeBuilder *Builder,
TraversalKind Traversal,
BindKind Bind) {
- return MatchesRecursively(StmtNode, BaseMatcher, Builder, 1, Traversal,
+ return matchesRecursively(StmtNode, BaseMatcher, Builder, 1, Traversal,
Bind);
}
// Implements ASTMatchFinder::MatchesDescendantOf.
- virtual bool MatchesDescendantOf(const clang::Decl &DeclNode,
+ virtual bool matchesDescendantOf(const clang::Decl &DeclNode,
const UntypedBaseMatcher &BaseMatcher,
BoundNodesTreeBuilder *Builder,
BindKind Bind) {
- return MemoizedMatchesRecursively(DeclNode, BaseMatcher, Builder, INT_MAX,
+ return memoizedMatchesRecursively(DeclNode, BaseMatcher, Builder, INT_MAX,
TK_AsIs, Bind);
}
- virtual bool MatchesDescendantOf(const clang::Stmt &StmtNode,
+ virtual bool matchesDescendantOf(const clang::Stmt &StmtNode,
const UntypedBaseMatcher &BaseMatcher,
BoundNodesTreeBuilder *Builder,
BindKind Bind) {
- return MemoizedMatchesRecursively(StmtNode, BaseMatcher, Builder, INT_MAX,
+ return memoizedMatchesRecursively(StmtNode, BaseMatcher, Builder, INT_MAX,
TK_AsIs, Bind);
}
@@ -345,8 +345,8 @@
: Context(Context), Sources(Sources),
Callback(Callback) {}
- virtual void VisitMatch(const BoundNodes& BoundNodesView) {
- Callback->Run(MatchFinder::MatchResult(BoundNodesView, Context, Sources));
+ virtual void visitMatch(const BoundNodes& BoundNodesView) {
+ Callback->run(MatchFinder::MatchResult(BoundNodesView, Context, Sources));
}
private:
@@ -358,29 +358,29 @@
// Returns true if 'TypeNode' is also known by the name 'Name'. In other
// words, there is a type (including typedef) with the name 'Name'
// that is equal to 'TypeNode'.
- bool TypeHasAlias(const clang::Type *TypeNode,
+ bool typeHasAlias(const clang::Type *TypeNode,
const std::string &Name) const {
const clang::Type *const CanonicalType =
ActiveASTContext->getCanonicalType(TypeNode);
const std::set<std::string> *UnqualifiedAlias =
- Find(TypeToUnqualifiedAliases, CanonicalType);
+ find(TypeToUnqualifiedAliases, CanonicalType);
return UnqualifiedAlias != NULL && UnqualifiedAlias->count(Name) > 0;
}
// Matches all registered matchers on the given node and calls the
// result callback for every node that matches.
template <typename T>
- void Match(const T &node) {
+ void match(const T &node) {
for (std::vector< std::pair<const UntypedBaseMatcher*,
MatchFinder::MatchCallback*> >::const_iterator
It = Triggers->begin(), End = Triggers->end();
It != End; ++It) {
BoundNodesTreeBuilder Builder;
- if (It->first->Matches(node, this, &Builder)) {
- BoundNodesTree BoundNodes = Builder.Build();
+ if (It->first->matches(node, this, &Builder)) {
+ BoundNodesTree BoundNodes = Builder.build();
MatchVisitor Visitor(ActiveASTContext, VisitorSourceManager,
It->second);
- BoundNodes.VisitMatches(&Visitor);
+ BoundNodes.visitMatches(&Visitor);
}
}
}
@@ -404,7 +404,7 @@
// from a base type with the given name. A class is considered to be
// also derived from itself.
bool
-MatchASTVisitor::ClassIsDerivedFrom(const clang::CXXRecordDecl *Declaration,
+MatchASTVisitor::classIsDerivedFrom(const clang::CXXRecordDecl *Declaration,
const std::string &BaseName) const {
if (std::string(Declaration->getName()) == BaseName) {
return true;
@@ -417,7 +417,7 @@
End = Declaration->bases_end(); It != End; ++It) {
const clang::Type *TypeNode = It->getType().getTypePtr();
- if (TypeHasAlias(TypeNode, BaseName))
+ if (typeHasAlias(TypeNode, BaseName))
return true;
// clang::Type::getAs<...>() drills through typedefs.
@@ -459,7 +459,7 @@
}
assert(ClassDecl != NULL);
assert(ClassDecl != Declaration);
- if (ClassIsDerivedFrom(ClassDecl, BaseName)) {
+ if (classIsDerivedFrom(ClassDecl, BaseName)) {
return true;
}
}
@@ -470,7 +470,7 @@
if (DeclNode == NULL) {
return true;
}
- Match(*DeclNode);
+ match(*DeclNode);
return clang::RecursiveASTVisitor<MatchASTVisitor>::TraverseDecl(DeclNode);
}
@@ -478,12 +478,12 @@
if (StmtNode == NULL) {
return true;
}
- Match(*StmtNode);
+ match(*StmtNode);
return clang::RecursiveASTVisitor<MatchASTVisitor>::TraverseStmt(StmtNode);
}
bool MatchASTVisitor::TraverseType(clang::QualType TypeNode) {
- Match(TypeNode);
+ match(TypeNode);
return clang::RecursiveASTVisitor<MatchASTVisitor>::TraverseType(TypeNode);
}
@@ -505,7 +505,7 @@
private:
virtual void HandleTranslationUnit(clang::ASTContext &Context) {
if (ParsingDone != NULL) {
- ParsingDone->Run();
+ ParsingDone->run();
}
Visitor.set_active_ast_context(&Context);
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
@@ -563,29 +563,29 @@
}
}
-void MatchFinder::AddMatcher(const DeclarationMatcher &NodeMatch,
+void MatchFinder::addMatcher(const DeclarationMatcher &NodeMatch,
MatchCallback *Action) {
Triggers.push_back(std::make_pair(
new internal::TypedBaseMatcher<clang::Decl>(NodeMatch), Action));
}
-void MatchFinder::AddMatcher(const TypeMatcher &NodeMatch,
+void MatchFinder::addMatcher(const TypeMatcher &NodeMatch,
MatchCallback *Action) {
Triggers.push_back(std::make_pair(
new internal::TypedBaseMatcher<clang::QualType>(NodeMatch), Action));
}
-void MatchFinder::AddMatcher(const StatementMatcher &NodeMatch,
+void MatchFinder::addMatcher(const StatementMatcher &NodeMatch,
MatchCallback *Action) {
Triggers.push_back(std::make_pair(
new internal::TypedBaseMatcher<clang::Stmt>(NodeMatch), Action));
}
-clang::FrontendAction *MatchFinder::NewFrontendAction() {
+clang::FrontendAction *MatchFinder::newFrontendAction() {
return new internal::MatchASTAction(&Triggers, ParsingDone);
}
-void MatchFinder::RegisterTestCallbackAfterParsing(
+void MatchFinder::registerTestCallbackAfterParsing(
MatchFinder::ParsingDoneTestCallback *NewParsingDone) {
ParsingDone = NewParsingDone;
}
Modified: cfe/branches/tooling/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=153950&r1=153949&r2=153950&view=diff
==============================================================================
--- cfe/branches/tooling/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/branches/tooling/lib/ASTMatchers/ASTMatchersInternal.cpp Tue Apr 3 06:12:12 2012
@@ -27,36 +27,36 @@
: DeclBindings(DeclBindings), StmtBindings(StmtBindings),
RecursiveBindings(RecursiveBindings) {}
-void BoundNodesTree::CopyTo(BoundNodesTreeBuilder* Builder) const {
- CopyBindingsTo(DeclBindings, Builder);
- CopyBindingsTo(StmtBindings, Builder);
+void BoundNodesTree::copyTo(BoundNodesTreeBuilder* Builder) const {
+ copyBindingsTo(DeclBindings, Builder);
+ copyBindingsTo(StmtBindings, Builder);
for (std::vector<BoundNodesTree>::const_iterator
I = RecursiveBindings.begin(),
E = RecursiveBindings.end();
I != E; ++I) {
- Builder->AddMatch(*I);
+ Builder->addMatch(*I);
}
}
template <typename T>
-void BoundNodesTree::CopyBindingsTo(
+void BoundNodesTree::copyBindingsTo(
const T& Bindings, BoundNodesTreeBuilder* Builder) const {
for (typename T::const_iterator I = Bindings.begin(),
E = Bindings.end();
I != E; ++I) {
- Builder->SetBinding(*I);
+ Builder->setBinding(*I);
}
}
-void BoundNodesTree::VisitMatches(Visitor* ResultVisitor) {
+void BoundNodesTree::visitMatches(Visitor* ResultVisitor) {
std::map<std::string, const clang::Decl*> AggregatedDeclBindings;
std::map<std::string, const clang::Stmt*> AggregatedStmtBindings;
- VisitMatchesRecursively(ResultVisitor, AggregatedDeclBindings,
+ visitMatchesRecursively(ResultVisitor, AggregatedDeclBindings,
AggregatedStmtBindings);
}
void BoundNodesTree::
-VisitMatchesRecursively(Visitor* ResultVisitor,
+visitMatchesRecursively(Visitor* ResultVisitor,
std::map<std::string, const clang::Decl*>
AggregatedDeclBindings,
std::map<std::string, const clang::Stmt*>
@@ -66,11 +66,11 @@
copy(StmtBindings.begin(), StmtBindings.end(),
inserter(AggregatedStmtBindings, AggregatedStmtBindings.begin()));
if (RecursiveBindings.empty()) {
- ResultVisitor->VisitMatch(BoundNodes(AggregatedDeclBindings,
+ ResultVisitor->visitMatch(BoundNodes(AggregatedDeclBindings,
AggregatedStmtBindings));
} else {
for (unsigned I = 0; I < RecursiveBindings.size(); ++I) {
- RecursiveBindings[I].VisitMatchesRecursively(ResultVisitor,
+ RecursiveBindings[I].visitMatchesRecursively(ResultVisitor,
AggregatedDeclBindings,
AggregatedStmtBindings);
}
@@ -80,20 +80,20 @@
BoundNodesTreeBuilder::BoundNodesTreeBuilder() {}
void BoundNodesTreeBuilder::
-SetBinding(const std::pair<const std::string, const clang::Decl*>& Binding) {
+setBinding(const std::pair<const std::string, const clang::Decl*>& Binding) {
DeclBindings.insert(Binding);
}
void BoundNodesTreeBuilder::
-SetBinding(const std::pair<const std::string, const clang::Stmt*>& Binding) {
+setBinding(const std::pair<const std::string, const clang::Stmt*>& Binding) {
StmtBindings.insert(Binding);
}
-void BoundNodesTreeBuilder::AddMatch(const BoundNodesTree& Bindings) {
+void BoundNodesTreeBuilder::addMatch(const BoundNodesTree& Bindings) {
RecursiveBindings.push_back(Bindings);
}
-BoundNodesTree BoundNodesTreeBuilder::Build() const {
+BoundNodesTree BoundNodesTreeBuilder::build() const {
return BoundNodesTree(DeclBindings, StmtBindings, RecursiveBindings);
}
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=153950&r1=153949&r2=153950&view=diff
==============================================================================
--- cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp (original)
+++ cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp Tue Apr 3 06:12:12 2012
@@ -26,6 +26,8 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/system_error.h"
+#include "clang/AST/DeclTemplate.h"
+
using namespace clang;
using namespace clang::ast_matchers;
using clang::tooling::NewFrontendActionFactory;
@@ -34,7 +36,7 @@
// FIXME: Pull out helper methods in here into more fitting places.
template <typename T>
-std::string GetFile(const clang::SourceManager& source_manager, const T& node) {
+std::string getFile(const clang::SourceManager& source_manager, const T& node) {
clang::SourceLocation start_spelling_location =
source_manager.getSpellingLoc(node.getLocStart());
if (!start_spelling_location.isValid()) return std::string();
@@ -47,7 +49,7 @@
// Returns the text that makes up 'node' in the source.
// Returns an empty string if the text cannot be found.
-static std::string GetText(const SourceManager &SourceManager,
+static std::string getText(const SourceManager &SourceManager,
SourceLocation LocStart, SourceLocation LocEnd) {
SourceLocation StartSpellingLocatino =
SourceManager.getSpellingLoc(LocStart);
@@ -79,14 +81,24 @@
}
template <typename T>
-static std::string GetText(const SourceManager &SourceManager, const T &Node) {
+static std::string getText(const SourceManager &SourceManager, const T &Node) {
return GetText(SourceManager, Node.getLocStart(), Node.getLocEnd());
}
namespace {
-bool AllParentsMatch(SourceManager *SM, const CXXRecordDecl *Decl, llvm::Regex &EditFilesExpression) {
- if (!EditFilesExpression.match(GetFile(*SM, *Decl))) {
+bool hasMethod(const CXXRecordDecl &Decl, StringRef MethodName, ASTContext &Context) {
+ clang::IdentifierInfo& Identifier = Context.Idents.get(MethodName);
+ clang::DeclContext::lookup_const_result Result = Decl.lookup(&Identifier);
+ return Result.first != Result.second;
+}
+
+bool allParentsMatch(SourceManager *SM, ASTContext &Context, const CXXRecordDecl *Decl, StringRef MethodName, llvm::Regex &EditFilesExpression) {
+ if (Decl == NULL)
+ return true;
+ if (!EditFilesExpression.match(getFile(*SM, *Decl)) &&
+ hasMethod(*Decl, MethodName, Context)) {
+ //llvm::outs() << GetFile(*SM, *Decl) << "\n";
return false;
}
typedef clang::CXXRecordDecl::base_class_const_iterator BaseIterator;
@@ -95,7 +107,7 @@
const clang::Type *TypeNode = It->getType().getTypePtr();
clang::CXXRecordDecl *
ClassDecl = TypeNode->getAsCXXRecordDecl();
- if (!AllParentsMatch(SM, ClassDecl, EditFilesExpression)) {
+ if (!allParentsMatch(SM, Context, ClassDecl, MethodName, EditFilesExpression)) {
return false;
}
}
@@ -105,12 +117,12 @@
class FixLLVMStyle: public ast_matchers::MatchFinder::MatchCallback {
public:
FixLLVMStyle(tooling::Replacements *Replace)
- : Replace(Replace), EditFilesExpression(".*ASTMatchers/.*") {}
+ : Replace(Replace), EditFilesExpression(".*ASTMatchers/.*|.*tools/clang/tools/.*") {}
- virtual void Run(const ast_matchers::MatchFinder::MatchResult &Result) {
- if (const CallExpr *Call = Result.Nodes.GetStmtAs<CallExpr>("call")) {
- llvm::errs() << "Skipping: "
- << GetText(*Result.SourceManager, *Call) << "\n";
+ virtual void run(const ast_matchers::MatchFinder::MatchResult &Result) {
+ if (const CallExpr *Call = Result.Nodes.getStmtAs<CallExpr>("call")) {
+ /* llvm::errs() << "Skipping: "
+ << GetText(*Result.SourceManager, *Call) << "\n";*/
return;
}
Replacement ReplaceText;
@@ -118,14 +130,16 @@
std::string OldName;
std::string SedCommand;
if (const NamedDecl *Declaration =
- Result.Nodes.GetDeclAs<NamedDecl>("declaration")) {
+ Result.Nodes.getDeclAs<NamedDecl>("declaration")) {
+ if (!EditFilesExpression.match(getFile(*Result.SourceManager, *Declaration)))
+ return;
Name = Declaration->getNameAsString();
OldName = Name;
if (const CXXMethodDecl *Method =
llvm::dyn_cast<CXXMethodDecl>(Declaration)) {
- if (Method->size_overridden_methods() > 0 &&
- !AllParentsMatch(Result.SourceManager, Method->getParent(), EditFilesExpression)) {
- llvm::errs() << "NotAllParentsMatch: " << OldName << "\n";
+ if (//Method->size_overridden_methods() > 0 &&
+ !allParentsMatch(Result.SourceManager, *Result.Context, Method->getParent(), OldName, EditFilesExpression)) {
+ // llvm::errs() << "NotAllParentsMatch: " << OldName << "\n";
return;
}
}
@@ -133,11 +147,11 @@
Name[0] = tolower(Name[0]);
if (Name == "new") Name = "create";
- if (const DeclRefExpr *Reference = Result.Nodes.GetStmtAs<DeclRefExpr>("ref")) {
+ if (const DeclRefExpr *Reference = Result.Nodes.getStmtAs<DeclRefExpr>("ref")) {
ReplaceText = Replacement(*Result.SourceManager, Reference, Name);
- } else if (const Expr *Callee = Result.Nodes.GetStmtAs<Expr>("callee")) {
+ } else if (const Expr *Callee = Result.Nodes.getStmtAs<Expr>("callee")) {
if (const MemberExpr *Member = dyn_cast<MemberExpr>(Callee)) {
- llvm::errs() << OldName << "\n";
+ // llvm::errs() << OldName << "\n";
assert(Member != NULL);
// std::string CalleeText = GetText(*Result.SourceManager, *Callee);
// llvm::outs() << "Callee: " << CalleeText << "\n";
@@ -147,10 +161,10 @@
Name);
} else if (const DeclRefExpr *Ref = dyn_cast<DeclRefExpr>(Callee)) {
(void)Ref;
- llvm::errs() << "XXX " << GetFile(*Result.SourceManager, *Callee) << "\n";
+ // llvm::errs() << "XXX " << GetFile(*Result.SourceManager, *Callee) << "\n";
} else {
- llvm::errs() << "*** " << GetFile(*Result.SourceManager, *Callee) << "\n";
- Callee->dump();
+ // llvm::errs() << "*** " << GetFile(*Result.SourceManager, *Callee) << "\n";
+ //Callee->dump();
}
} else {
DeclarationNameInfo NameInfo;
@@ -161,14 +175,18 @@
}
ReplaceText = Replacement(*Result.SourceManager, &NameInfo, Name);
if (!ReplaceText.IsApplicable()) {
- llvm::errs() << "Not applicable: " << Name << "\n";
+ // llvm::errs() << "Not applicable: " << Name << "\n";
}
}
}
}
if (EditFilesExpression.match(ReplaceText.GetFilePath())) {
+ //llvm::errs() << GetPosition(*Result.Nodes.GetDeclAs<NamedDecl>("declaration"), *Result.SourceManager) << "\n";
+ //llvm::errs
llvm::errs() << ReplaceText.GetFilePath() << ":" << ReplaceText.GetOffset() << ", " << ReplaceText.GetLength() << ": s/" << OldName << "/" << Name << "/g;\n";
-// Replace->insert(ReplaceText);
+ Replace->insert(ReplaceText);
+ } else {
+// llvm::errs() << ReplaceText.GetFilePath() << ":" << ReplaceText.GetOffset() << ", " << ReplaceText.GetLength() << ": s/" << OldName << "/" << Name << "/g;\n";
}
}
@@ -184,7 +202,7 @@
internal::Matcher<clang::UsingShadowDecl>, InnerMatcher) {
for (clang::UsingDecl::shadow_iterator I = Node.shadow_begin();
I != Node.shadow_end(); ++I) {
- if (InnerMatcher.Matches(**I, Finder, Builder)) {
+ if (InnerMatcher.matches(**I, Finder, Builder)) {
return true;
}
}
@@ -192,7 +210,55 @@
}
AST_MATCHER_P(clang::UsingShadowDecl, HasTargetDeclaration,
internal::Matcher<clang::NamedDecl>, InnerMatcher) {
- return InnerMatcher.Matches(*Node.getTargetDecl(), Finder, Builder);
+ return InnerMatcher.matches(*Node.getTargetDecl(), Finder, Builder);
+}
+AST_MATCHER_P(clang::QualType, HasClassDeclaration,
+ internal::Matcher<clang::CXXRecordDecl>, InnerMatcher) {
+ if (const clang::CXXRecordDecl *Decl = Node->getAsCXXRecordDecl()) {
+ return InnerMatcher.matches(*Decl, Finder, Builder);
+ }
+ if (const clang::TemplateSpecializationType *T = Node->getAs<clang::TemplateSpecializationType>()) {
+ if (const clang::NamedDecl *N = T->getTemplateName().getAsTemplateDecl()->getTemplatedDecl()) {
+ if (const clang::CXXRecordDecl *Decl = dyn_cast<CXXRecordDecl>(N)) {
+ return InnerMatcher.matches(*Decl, Finder, Builder);
+ }
+ }
+ }
+ return false;
+}
+AST_MATCHER_P(clang::FunctionDecl, HasReturnType,
+ internal::Matcher<clang::QualType>, InnerMatcher) {
+ llvm::errs() << Node.getNameAsString() << "\n";
+ Node.getResultType().dump();
+ llvm::errs() << "\n";
+ const clang::TemplateSpecializationType* T = Node.getResultType()->getAs<clang::TemplateSpecializationType>();
+ if (T != NULL) {
+ const NamedDecl *N = T->getTemplateName().getAsTemplateDecl()->getTemplatedDecl();
+
+ if (N != NULL) {
+ llvm::errs() << dyn_cast<CXXRecordDecl>(N) << "\n";
+ }
+/* T->desugar().dump();
+ llvm::errs() << T->desugar()->getTypeClass() << "\n";
+ const clang::TemplateSpecializationType* T2 = T->desugar()->getAs<clang::TemplateSpecializationType>();
+ if (T2 != NULL) {
+ T2->desugar().dump();
+ }*/
+
+ }
+ return InnerMatcher.matches(Node.getResultType(), Finder, Builder);
+}
+AST_MATCHER_P(clang::NamedDecl, HasName2, std::string, name) {
+ assert(!name.empty());
+ const std::string full_name_string = "::" + Node.getQualifiedNameAsString();
+ const llvm::StringRef full_name = full_name_string;
+ llvm::errs() << full_name << "\n";
+ const llvm::StringRef pattern = name;
+ if (pattern.startswith("::")) {
+ return full_name == pattern;
+ } else {
+ return full_name.endswith(("::" + pattern).str());
+ }
}
} }
@@ -200,18 +266,25 @@
int main(int argc, char **argv) {
tooling::RefactoringTool Tool(argc, argv);
ast_matchers::MatchFinder Finder;
+
+ DeclarationMatcher FunctionMatch = Function(Not(HasReturnType(HasClassDeclaration(
+ AnyOf(HasName2("internal::Matcher"),
+ HasName("internal::PolymorphicMatcherWithParam0"),
+ HasName("internal::PolymorphicMatcherWithParam1"),
+ HasName("internal::PolymorphicMatcherWithParam2")
+ )))));
- Finder.AddMatcher(StatementMatcher(AnyOf(
- StatementMatcher(Id("ref", DeclarationReference(To(Id("declaration", Function()))))),
- Call(Callee(Id("declaration", Function())),
+ 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()));
- Finder.AddMatcher(
+ Finder.addMatcher(
DeclarationMatcher(AnyOf(
- Id("declaration", UsingDeclaration(HasAnyUsingShadowDeclaration(HasTargetDeclaration(Function())))),
+ Id("declaration", UsingDeclaration(HasAnyUsingShadowDeclaration(HasTargetDeclaration(FunctionMatch)))),
AllOf(
- Id("declaration", Function()),
+ Id("declaration", FunctionMatch),
Not(Constructor())))
),
new FixLLVMStyle(&Tool.GetReplacements()));
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=153950&r1=153949&r2=153950&view=diff
==============================================================================
--- cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp (original)
+++ cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp Tue Apr 3 06:12:12 2012
@@ -58,7 +58,7 @@
// Returns the text that makes up 'node' in the source.
// Returns an empty string if the text cannot be found.
template <typename T>
-static std::string GetText(const SourceManager &SourceManager, const T &Node) {
+static std::string getText(const SourceManager &SourceManager, const T &Node) {
SourceLocation StartSpellingLocatino =
SourceManager.getSpellingLoc(Node.getLocStart());
SourceLocation EndSpellingLocation =
@@ -91,7 +91,7 @@
// Return true if expr needs to be put in parens when it is an
// argument of a prefix unary operator, e.g. when it is a binary or
// ternary operator syntactically.
-static bool NeedParensAfterUnaryOperator(const Expr &ExprNode) {
+static bool needParensAfterUnaryOperator(const Expr &ExprNode) {
if (dyn_cast<clang::BinaryOperator>(&ExprNode) ||
dyn_cast<clang::ConditionalOperator>(&ExprNode)) {
return true;
@@ -109,19 +109,19 @@
// Format a pointer to an expression: prefix with '*' but simplify
// when it already begins with '&'. Return empty string on failure.
-static std::string FormatDereference(const SourceManager &SourceManager,
+static std::string formatDereference(const SourceManager &SourceManager,
const Expr &ExprNode) {
if (const clang::UnaryOperator *Op =
dyn_cast<clang::UnaryOperator>(&ExprNode)) {
if (Op->getOpcode() == UO_AddrOf) {
// Strip leading '&'.
- return GetText(SourceManager, *Op->getSubExpr()->IgnoreParens());
+ return getText(SourceManager, *Op->getSubExpr()->IgnoreParens());
}
}
- const std::string Text = GetText(SourceManager, ExprNode);
+ const std::string Text = getText(SourceManager, ExprNode);
if (Text.empty()) return std::string();
// Add leading '*'.
- if (NeedParensAfterUnaryOperator(ExprNode)) {
+ if (needParensAfterUnaryOperator(ExprNode)) {
return std::string("*(") + Text + ")";
}
return std::string("*") + Text;
@@ -133,18 +133,18 @@
FixCStrCall(tooling::Replacements *Replace)
: Replace(Replace) {}
- virtual void Run(const ast_matchers::MatchFinder::MatchResult &Result) {
+ virtual void run(const ast_matchers::MatchFinder::MatchResult &Result) {
const CallExpr *Call =
- Result.Nodes.GetStmtAs<CallExpr>("call");
+ Result.Nodes.getStmtAs<CallExpr>("call");
const Expr *Arg =
- Result.Nodes.GetStmtAs<Expr>("arg");
+ Result.Nodes.getStmtAs<Expr>("arg");
const bool Arrow =
- Result.Nodes.GetStmtAs<MemberExpr>("member")->isArrow();
+ Result.Nodes.getStmtAs<MemberExpr>("member")->isArrow();
// Replace the "call" node with the "arg" node, prefixed with '*'
// if the call was using '->' rather than '.'.
const std::string ArgText = Arrow ?
- FormatDereference(*Result.SourceManager, *Arg) :
- GetText(*Result.SourceManager, *Arg);
+ formatDereference(*Result.SourceManager, *Arg) :
+ getText(*Result.SourceManager, *Arg);
if (ArgText.empty()) return;
Replace->insert(Replacement(*Result.SourceManager, Call, ArgText));
@@ -166,7 +166,7 @@
int main(int argc, char **argv) {
tooling::RefactoringTool Tool(argc, argv);
ast_matchers::MatchFinder Finder;
- Finder.AddMatcher(
+ Finder.addMatcher(
ConstructorCall(
HasDeclaration(Method(HasName(StringConstructor))),
ArgumentCountIs(2),
@@ -186,7 +186,7 @@
1,
DefaultArgument())),
new FixCStrCall(&Tool.GetReplacements()));
- Finder.AddMatcher(
+ Finder.addMatcher(
ConstructorCall(
// Implicit constructors of these classes are overloaded
// wrt. string types and they internally make a StringRef
Modified: cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=153950&r1=153949&r2=153950&view=diff
==============================================================================
--- cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp Tue Apr 3 06:12:12 2012
@@ -20,7 +20,7 @@
class BoundNodesCallback {
public:
virtual ~BoundNodesCallback() {}
- virtual bool Run(const BoundNodes *BoundNodes) = 0;
+ virtual bool run(const BoundNodes *BoundNodes) = 0;
};
// If 'FindResultVerifier' is not NULL, sets *Verified to the result of
@@ -31,9 +31,9 @@
VerifyMatch(BoundNodesCallback *FindResultVerifier, bool *Verified)
: Verified(Verified), FindResultReviewer(FindResultVerifier) {}
- virtual void Run(const MatchFinder::MatchResult &Result) {
+ virtual void run(const MatchFinder::MatchResult &Result) {
if (FindResultReviewer != NULL) {
- *Verified = FindResultReviewer->Run(&Result.Nodes);
+ *Verified = FindResultReviewer->run(&Result.Nodes);
} else {
*Verified = true;
}
@@ -45,13 +45,13 @@
};
template <typename T>
-testing::AssertionResult MatchesConditionally(const std::string &Code,
+testing::AssertionResult matchesConditionally(const std::string &Code,
const T &AMatcher,
bool ExpectMatch) {
bool Found = false;
MatchFinder Finder;
- Finder.AddMatcher(AMatcher, new VerifyMatch(0, &Found));
- if (!RunSyntaxOnlyToolOnCode(Finder.NewFrontendAction(), Code)) {
+ Finder.addMatcher(AMatcher, new VerifyMatch(0, &Found));
+ if (!RunSyntaxOnlyToolOnCode(Finder.newFrontendAction(), Code)) {
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
}
if (!Found && ExpectMatch) {
@@ -65,27 +65,27 @@
}
template <typename T>
-testing::AssertionResult Matches(const std::string &Code, const T &AMatcher) {
- return MatchesConditionally(Code, AMatcher, true);
+testing::AssertionResult matches(const std::string &Code, const T &AMatcher) {
+ return matchesConditionally(Code, AMatcher, true);
}
template <typename T>
-testing::AssertionResult NotMatches(const std::string &Code,
+testing::AssertionResult notMatches(const std::string &Code,
const T &AMatcher) {
- return MatchesConditionally(Code, AMatcher, false);
+ return matchesConditionally(Code, AMatcher, false);
}
template <typename T>
testing::AssertionResult
-MatchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher,
+matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher,
BoundNodesCallback *FindResultVerifier,
bool ExpectResult) {
llvm::OwningPtr<BoundNodesCallback> ScopedVerifier(FindResultVerifier);
bool VerifiedResult = false;
MatchFinder Finder;
- Finder.AddMatcher(
+ Finder.addMatcher(
AMatcher, new VerifyMatch(FindResultVerifier, &VerifiedResult));
- if (!RunSyntaxOnlyToolOnCode(Finder.NewFrontendAction(), Code)) {
+ if (!RunSyntaxOnlyToolOnCode(Finder.newFrontendAction(), Code)) {
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
}
if (!VerifiedResult && ExpectResult) {
@@ -102,180 +102,180 @@
// do more precisely).
template <typename T>
testing::AssertionResult
-MatchAndVerifyResultTrue(const std::string &Code, const T &AMatcher,
+matchAndVerifyResultTrue(const std::string &Code, const T &AMatcher,
BoundNodesCallback *FindResultVerifier) {
- return MatchAndVerifyResultConditionally(
+ return matchAndVerifyResultConditionally(
Code, AMatcher, FindResultVerifier, true);
}
template <typename T>
testing::AssertionResult
-MatchAndVerifyResultFalse(const std::string &Code, const T &AMatcher,
+matchAndVerifyResultFalse(const std::string &Code, const T &AMatcher,
BoundNodesCallback *FindResultVerifier) {
- return MatchAndVerifyResultConditionally(
+ return matchAndVerifyResultConditionally(
Code, AMatcher, FindResultVerifier, false);
}
TEST(HasNameDeathTest, DiesOnEmptyName) {
ASSERT_DEBUG_DEATH({
DeclarationMatcher HasEmptyName = Class(HasName(""));
- EXPECT_TRUE(NotMatches("class X {};", HasEmptyName));
+ EXPECT_TRUE(notMatches("class X {};", HasEmptyName));
}, "");
}
TEST(IsDerivedFromDeathTest, DiesOnEmptyBaseName) {
ASSERT_DEBUG_DEATH({
DeclarationMatcher IsDerivedFromEmpty = Class(IsDerivedFrom(""));
- EXPECT_TRUE(NotMatches("class X {};", IsDerivedFromEmpty));
+ EXPECT_TRUE(notMatches("class X {};", IsDerivedFromEmpty));
}, "");
}
TEST(NameableDeclaration, MatchesVariousDecls) {
DeclarationMatcher NamedX = NameableDeclaration(HasName("X"));
- EXPECT_TRUE(Matches("typedef int X;", NamedX));
- EXPECT_TRUE(Matches("int X;", NamedX));
- EXPECT_TRUE(Matches("class foo { virtual void X(); };", NamedX));
- EXPECT_TRUE(Matches("void foo() try { } catch(int X) { }", NamedX));
- EXPECT_TRUE(Matches("void foo() { int X; }", NamedX));
- EXPECT_TRUE(Matches("namespace X { }", NamedX));
+ EXPECT_TRUE(matches("typedef int X;", NamedX));
+ EXPECT_TRUE(matches("int X;", NamedX));
+ EXPECT_TRUE(matches("class foo { virtual void X(); };", NamedX));
+ EXPECT_TRUE(matches("void foo() try { } catch(int X) { }", NamedX));
+ EXPECT_TRUE(matches("void foo() { int X; }", NamedX));
+ EXPECT_TRUE(matches("namespace X { }", NamedX));
- EXPECT_TRUE(NotMatches("#define X 1", NamedX));
+ EXPECT_TRUE(notMatches("#define X 1", NamedX));
}
TEST(DeclarationMatcher, MatchClass) {
DeclarationMatcher ClassMatcher(Class());
// Even for an empty string there are classes in the AST.
- EXPECT_TRUE(Matches("", ClassMatcher));
+ EXPECT_TRUE(matches("", ClassMatcher));
DeclarationMatcher ClassX = Class(Class(HasName("X")));
- EXPECT_TRUE(Matches("class X;", ClassX));
- EXPECT_TRUE(Matches("class X {};", ClassX));
- EXPECT_TRUE(Matches("template<class T> class X {};", ClassX));
- EXPECT_TRUE(NotMatches("", ClassX));
+ EXPECT_TRUE(matches("class X;", ClassX));
+ EXPECT_TRUE(matches("class X {};", ClassX));
+ EXPECT_TRUE(matches("template<class T> class X {};", ClassX));
+ EXPECT_TRUE(notMatches("", ClassX));
}
TEST(DeclarationMatcher, ClassIsDerived) {
DeclarationMatcher IsDerivedFromX = Class(IsDerivedFrom("X"));
- EXPECT_TRUE(Matches("class X {}; class Y : public X {};", IsDerivedFromX));
- EXPECT_TRUE(Matches("class X {}; class Y : public X {};", IsDerivedFromX));
- EXPECT_TRUE(Matches("class X {};", IsDerivedFromX));
- EXPECT_TRUE(Matches("class X;", IsDerivedFromX));
- EXPECT_TRUE(NotMatches("class Y;", IsDerivedFromX));
- EXPECT_TRUE(NotMatches("", IsDerivedFromX));
+ EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsDerivedFromX));
+ EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsDerivedFromX));
+ EXPECT_TRUE(matches("class X {};", IsDerivedFromX));
+ EXPECT_TRUE(matches("class X;", IsDerivedFromX));
+ EXPECT_TRUE(notMatches("class Y;", IsDerivedFromX));
+ EXPECT_TRUE(notMatches("", IsDerivedFromX));
DeclarationMatcher ZIsDerivedFromX =
Class(HasName("Z"), IsDerivedFrom("X"));
EXPECT_TRUE(
- Matches("class X {}; class Y : public X {}; class Z : public Y {};",
+ matches("class X {}; class Y : public X {}; class Z : public Y {};",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("class X {};"
+ matches("class X {};"
"template<class T> class Y : public X {};"
"class Z : public Y<int> {};", ZIsDerivedFromX));
- EXPECT_TRUE(Matches("class X {}; template<class T> class Z : public X {};",
+ EXPECT_TRUE(matches("class X {}; template<class T> class Z : public X {};",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("template<class T> class X {}; "
+ matches("template<class T> class X {}; "
"template<class T> class Z : public X<T> {};",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("template<class T, class U=T> class X {}; "
+ matches("template<class T, class U=T> class X {}; "
"template<class T> class Z : public X<T> {};",
ZIsDerivedFromX));
EXPECT_TRUE(
- NotMatches("template<class X> class A { class Z : public X {}; };",
+ notMatches("template<class X> class A { class Z : public X {}; };",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("template<class X> class A { public: class Z : public X {}; }; "
+ matches("template<class X> class A { public: class Z : public X {}; }; "
"class X{}; void y() { A<X>::Z z; }", ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("template <class T> class X {}; "
+ matches("template <class T> class X {}; "
"template<class Y> class A { class Z : public X<Y> {}; };",
ZIsDerivedFromX));
EXPECT_TRUE(
- NotMatches("template<template<class T> class X> class A { "
+ notMatches("template<template<class T> class X> class A { "
" class Z : public X<int> {}; };", ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("template<template<class T> class X> class A { "
+ matches("template<template<class T> class X> class A { "
" public: class Z : public X<int> {}; }; "
"template<class T> class X {}; void y() { A<X>::Z z; }",
ZIsDerivedFromX));
EXPECT_TRUE(
- NotMatches("template<class X> class A { class Z : public X::D {}; };",
+ notMatches("template<class X> class A { class Z : public X::D {}; };",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("template<class X> class A { public: "
+ matches("template<class X> class A { public: "
" class Z : public X::D {}; }; "
"class Y { public: class X {}; typedef X D; }; "
"void y() { A<Y>::Z z; }", ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("class X {}; typedef X Y; class Z : public Y {};",
+ matches("class X {}; typedef X Y; class Z : public Y {};",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("template<class T> class Y { typedef typename T::U X; "
+ matches("template<class T> class Y { typedef typename T::U X; "
" class Z : public X {}; };", ZIsDerivedFromX));
- EXPECT_TRUE(Matches("class X {}; class Z : public ::X {};",
+ EXPECT_TRUE(matches("class X {}; class Z : public ::X {};",
ZIsDerivedFromX));
EXPECT_TRUE(
- NotMatches("template<class T> class X {}; "
+ notMatches("template<class T> class X {}; "
"template<class T> class A { class Z : public X<T>::D {}; };",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("template<class T> class X { public: typedef X<T> D; }; "
+ matches("template<class T> class X { public: typedef X<T> D; }; "
"template<class T> class A { public: "
" class Z : public X<T>::D {}; }; void y() { A<int>::Z z; }",
ZIsDerivedFromX));
EXPECT_TRUE(
- NotMatches("template<class X> class A { class Z : public X::D::E {}; };",
+ notMatches("template<class X> class A { class Z : public X::D::E {}; };",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("class X {}; typedef X V; typedef V W; class Z : public W {};",
+ matches("class X {}; typedef X V; typedef V W; class Z : public W {};",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("class X {}; class Y : public X {}; "
+ matches("class X {}; class Y : public X {}; "
"typedef Y V; typedef V W; class Z : public W {};",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("template<class T, class U> class X {}; "
+ matches("template<class T, class U> class X {}; "
"template<class T> class A { class Z : public X<T, int> {}; };",
ZIsDerivedFromX));
EXPECT_TRUE(
- NotMatches("template<class X> class D { typedef X A; typedef A B; "
+ notMatches("template<class X> class D { typedef X A; typedef A B; "
" typedef B C; class Z : public C {}; };",
ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("class X {}; typedef X A; typedef A B; "
+ matches("class X {}; typedef X A; typedef A B; "
"class Z : public B {};", ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("class X {}; typedef X A; typedef A B; typedef B C; "
+ matches("class X {}; typedef X A; typedef A B; typedef B C; "
"class Z : public C {};", ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("class U {}; typedef U X; typedef X V; "
+ matches("class U {}; typedef U X; typedef X V; "
"class Z : public V {};", ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("class Base {}; typedef Base X; "
+ matches("class Base {}; typedef Base X; "
"class Z : public Base {};", ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("class Base {}; typedef Base Base2; typedef Base2 X; "
+ matches("class Base {}; typedef Base Base2; typedef Base2 X; "
"class Z : public Base {};", ZIsDerivedFromX));
EXPECT_TRUE(
- NotMatches("class Base {}; class Base2 {}; typedef Base2 X; "
+ notMatches("class Base {}; class Base2 {}; typedef Base2 X; "
"class Z : public Base {};", ZIsDerivedFromX));
EXPECT_TRUE(
- Matches("class A {}; typedef A X; typedef A Y; "
+ matches("class A {}; typedef A X; typedef A Y; "
"class Z : public Y {};", ZIsDerivedFromX));
EXPECT_TRUE(
- NotMatches("template <typename T> class Z;"
+ notMatches("template <typename T> class Z;"
"template <> class Z<void> {};"
"template <typename T> class Z : public Z<void> {};",
IsDerivedFromX));
EXPECT_TRUE(
- Matches("template <typename T> class X;"
+ matches("template <typename T> class X;"
"template <> class X<void> {};"
"template <typename T> class X : public X<void> {};",
IsDerivedFromX));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class X {};"
"template <typename T> class Z;"
"template <> class Z<void> {};"
@@ -294,16 +294,16 @@
"template <> class Z<double> : public Z<int> {};"
"template <typename T> class Z : public Z<float>, public Z<double> {};"
"void f() { Z<float> z_float; Z<double> z_double; Z<char> z_char; }";
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
RecursiveTemplateOneParameter,
Variable(HasName("z_float"),
HasInitializer(HasType(Class(IsDerivedFrom("Base1")))))));
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
RecursiveTemplateOneParameter,
Variable(
HasName("z_float"),
HasInitializer(HasType(Class(IsDerivedFrom("Base2")))))));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
RecursiveTemplateOneParameter,
Variable(
HasName("z_char"),
@@ -321,17 +321,17 @@
" public Z<float, T2>, public Z<double, T2> {};"
"void f() { Z<float, void> z_float; Z<double, void> z_double; "
" Z<char, void> z_char; }";
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
RecursiveTemplateTwoParameters,
Variable(
HasName("z_float"),
HasInitializer(HasType(Class(IsDerivedFrom("Base1")))))));
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
RecursiveTemplateTwoParameters,
Variable(
HasName("z_float"),
HasInitializer(HasType(Class(IsDerivedFrom("Base2")))))));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
RecursiveTemplateTwoParameters,
Variable(
HasName("z_char"),
@@ -344,52 +344,52 @@
Class(AnyOf(HasName("Y"), AllOf(IsDerivedFrom("X"), HasName("Z"))));
EXPECT_TRUE(
- Matches("class X {}; class Z : public X {};", YOrZDerivedFromX));
- EXPECT_TRUE(Matches("class Y {};", YOrZDerivedFromX));
+ matches("class X {}; class Z : public X {};", YOrZDerivedFromX));
+ EXPECT_TRUE(matches("class Y {};", YOrZDerivedFromX));
EXPECT_TRUE(
- NotMatches("class X {}; class W : public X {};", YOrZDerivedFromX));
- EXPECT_TRUE(NotMatches("class Z {};", YOrZDerivedFromX));
+ notMatches("class X {}; class W : public X {};", YOrZDerivedFromX));
+ EXPECT_TRUE(notMatches("class Z {};", YOrZDerivedFromX));
DeclarationMatcher XOrYOrZOrUOrV =
Class(AnyOf(HasName("X"), HasName("Y"), HasName("Z"), HasName("U"),
HasName("V")));
- EXPECT_TRUE(Matches("class X {};", XOrYOrZOrUOrV));
- EXPECT_TRUE(Matches("class Y {};", XOrYOrZOrUOrV));
- EXPECT_TRUE(Matches("class Z {};", XOrYOrZOrUOrV));
- EXPECT_TRUE(Matches("class U {};", XOrYOrZOrUOrV));
- EXPECT_TRUE(Matches("class V {};", XOrYOrZOrUOrV));
- EXPECT_TRUE(NotMatches("class A {};", XOrYOrZOrUOrV));
+ EXPECT_TRUE(matches("class X {};", XOrYOrZOrUOrV));
+ EXPECT_TRUE(matches("class Y {};", XOrYOrZOrUOrV));
+ EXPECT_TRUE(matches("class Z {};", XOrYOrZOrUOrV));
+ EXPECT_TRUE(matches("class U {};", XOrYOrZOrUOrV));
+ EXPECT_TRUE(matches("class V {};", XOrYOrZOrUOrV));
+ EXPECT_TRUE(notMatches("class A {};", XOrYOrZOrUOrV));
}
TEST(DeclarationMatcher, MatchHas) {
- DeclarationMatcher HasClassX = Class(Has(Class(HasName("X"))));
+ DeclarationMatcher HasClassX = Class(has(Class(HasName("X"))));
- EXPECT_TRUE(Matches("class Y { class X {}; };", HasClassX));
- EXPECT_TRUE(Matches("class X {};", HasClassX));
+ EXPECT_TRUE(matches("class Y { class X {}; };", HasClassX));
+ EXPECT_TRUE(matches("class X {};", HasClassX));
DeclarationMatcher YHasClassX =
- Class(HasName("Y"), Has(Class(HasName("X"))));
- EXPECT_TRUE(Matches("class Y { class X {}; };", YHasClassX));
- EXPECT_TRUE(NotMatches("class X {};", YHasClassX));
+ Class(HasName("Y"), has(Class(HasName("X"))));
+ EXPECT_TRUE(matches("class Y { class X {}; };", YHasClassX));
+ EXPECT_TRUE(notMatches("class X {};", YHasClassX));
EXPECT_TRUE(
- NotMatches("class Y { class Z { class X {}; }; };", YHasClassX));
+ notMatches("class Y { class Z { class X {}; }; };", YHasClassX));
}
TEST(DeclarationMatcher, MatchHasRecursiveAllOf) {
DeclarationMatcher Recursive =
Class(
- Has(Class(
- Has(Class(HasName("X"))),
- Has(Class(HasName("Y"))),
+ has(Class(
+ has(Class(HasName("X"))),
+ has(Class(HasName("Y"))),
HasName("Z"))),
- Has(Class(
- Has(Class(HasName("A"))),
- Has(Class(HasName("B"))),
+ has(Class(
+ has(Class(HasName("A"))),
+ has(Class(HasName("B"))),
HasName("C"))),
HasName("F"));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class F {"
" class Z {"
" class X {};"
@@ -401,7 +401,7 @@
" };"
"};", Recursive));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class F {"
" class Z {"
" class A {};"
@@ -415,7 +415,7 @@
" };"
"};", Recursive));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class O1 {"
" class O2 {"
" class F {"
@@ -438,29 +438,29 @@
DeclarationMatcher Recursive =
Class(
AnyOf(
- Has(Class(
+ has(Class(
AnyOf(
- Has(Class(
+ has(Class(
HasName("X"))),
- Has(Class(
+ has(Class(
HasName("Y"))),
HasName("Z")))),
- Has(Class(
+ has(Class(
AnyOf(
HasName("C"),
- Has(Class(
+ has(Class(
HasName("A"))),
- Has(Class(
+ has(Class(
HasName("B")))))),
HasName("F")));
- EXPECT_TRUE(Matches("class F {};", Recursive));
- EXPECT_TRUE(Matches("class Z {};", Recursive));
- EXPECT_TRUE(Matches("class C {};", Recursive));
- EXPECT_TRUE(Matches("class M { class N { class X {}; }; };", Recursive));
- EXPECT_TRUE(Matches("class M { class N { class B {}; }; };", Recursive));
+ EXPECT_TRUE(matches("class F {};", Recursive));
+ EXPECT_TRUE(matches("class Z {};", Recursive));
+ EXPECT_TRUE(matches("class C {};", Recursive));
+ EXPECT_TRUE(matches("class M { class N { class X {}; }; };", Recursive));
+ EXPECT_TRUE(matches("class M { class N { class B {}; }; };", Recursive));
EXPECT_TRUE(
- Matches("class O1 { class O2 {"
+ matches("class O1 { class O2 {"
" class M { class N { class B {}; }; }; "
"}; };", Recursive));
}
@@ -471,52 +471,52 @@
IsDerivedFrom("Y"),
Not(HasName("Y")),
Not(HasName("X")));
- EXPECT_TRUE(NotMatches("", NotClassX));
- EXPECT_TRUE(NotMatches("class Y {};", NotClassX));
- EXPECT_TRUE(Matches("class Y {}; class Z : public Y {};", NotClassX));
- EXPECT_TRUE(NotMatches("class Y {}; class X : public Y {};", NotClassX));
+ EXPECT_TRUE(notMatches("", NotClassX));
+ EXPECT_TRUE(notMatches("class Y {};", NotClassX));
+ EXPECT_TRUE(matches("class Y {}; class Z : public Y {};", NotClassX));
+ EXPECT_TRUE(notMatches("class Y {}; class X : public Y {};", NotClassX));
EXPECT_TRUE(
- NotMatches("class Y {}; class Z {}; class X : public Y {};",
+ notMatches("class Y {}; class Z {}; class X : public Y {};",
NotClassX));
DeclarationMatcher ClassXHasNotClassY =
Class(
HasName("X"),
- Has(Class(HasName("Z"))),
+ has(Class(HasName("Z"))),
Not(
- Has(Class(HasName("Y")))));
- EXPECT_TRUE(Matches("class X { class Z {}; };", ClassXHasNotClassY));
- EXPECT_TRUE(NotMatches("class X { class Y {}; class Z {}; };",
+ has(Class(HasName("Y")))));
+ EXPECT_TRUE(matches("class X { class Z {}; };", ClassXHasNotClassY));
+ EXPECT_TRUE(notMatches("class X { class Y {}; class Z {}; };",
ClassXHasNotClassY));
}
TEST(DeclarationMatcher, HasDescendant) {
DeclarationMatcher ZDescendantClassX =
Class(
- HasDescendant(Class(HasName("X"))),
+ hasDescendant(Class(HasName("X"))),
HasName("Z"));
- EXPECT_TRUE(Matches("class Z { class X {}; };", ZDescendantClassX));
+ EXPECT_TRUE(matches("class Z { class X {}; };", ZDescendantClassX));
EXPECT_TRUE(
- Matches("class Z { class Y { class X {}; }; };", ZDescendantClassX));
+ matches("class Z { class Y { class X {}; }; };", ZDescendantClassX));
EXPECT_TRUE(
- Matches("class Z { class A { class Y { class X {}; }; }; };",
+ matches("class Z { class A { class Y { class X {}; }; }; };",
ZDescendantClassX));
EXPECT_TRUE(
- Matches("class Z { class A { class B { class Y { class X {}; }; }; }; };",
+ matches("class Z { class A { class B { class Y { class X {}; }; }; }; };",
ZDescendantClassX));
- EXPECT_TRUE(NotMatches("class Z {};", ZDescendantClassX));
+ EXPECT_TRUE(notMatches("class Z {};", ZDescendantClassX));
DeclarationMatcher ZDescendantClassXHasClassY =
Class(
- HasDescendant(Class(Has(Class(HasName("Y"))),
+ hasDescendant(Class(has(Class(HasName("Y"))),
HasName("X"))),
HasName("Z"));
- EXPECT_TRUE(Matches("class Z { class X { class Y {}; }; };",
+ EXPECT_TRUE(matches("class Z { class X { class Y {}; }; };",
ZDescendantClassXHasClassY));
EXPECT_TRUE(
- Matches("class Z { class A { class B { class X { class Y {}; }; }; }; };",
+ matches("class Z { class A { class B { class X { class Y {}; }; }; }; };",
ZDescendantClassXHasClassY));
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"class Z {"
" class A {"
" class B {"
@@ -531,13 +531,13 @@
DeclarationMatcher ZDescendantClassXDescendantClassY =
Class(
- HasDescendant(Class(HasDescendant(Class(HasName("Y"))),
+ hasDescendant(Class(hasDescendant(Class(HasName("Y"))),
HasName("X"))),
HasName("Z"));
EXPECT_TRUE(
- Matches("class Z { class A { class X { class B { class Y {}; }; }; }; };",
+ matches("class Z { class A { class X { class B { class Y {}; }; }; }; };",
ZDescendantClassXDescendantClassY));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class Z {"
" class A {"
" class X {"
@@ -554,11 +554,11 @@
StatementMatcher HasVariableI =
Expression(
HasType(PointsTo(Class(HasName("X")))),
- Has(DeclarationReference(To(Variable(HasName("i"))))));
+ has(DeclarationReference(To(Variable(HasName("i"))))));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class X; X *x(int); void c() { int i; x(i); }", HasVariableI));
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"class X; X *x(int); void c() { int i; x(42); }", HasVariableI));
}
@@ -566,12 +566,12 @@
StatementMatcher HasDescendantVariableI =
Expression(
HasType(PointsTo(Class(HasName("X")))),
- HasDescendant(DeclarationReference(To(Variable(HasName("i"))))));
+ hasDescendant(DeclarationReference(To(Variable(HasName("i"))))));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class X; X *x(bool); bool b(int); void c() { int i; x(b(i)); }",
HasDescendantVariableI));
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"class X; X *x(bool); bool b(int); void c() { int i; x(b(42)); }",
HasDescendantVariableI));
}
@@ -579,20 +579,20 @@
TEST(TypeMatcher, MatchesClassType) {
TypeMatcher TypeA = HasDeclaration(Class(HasName("A")));
- EXPECT_TRUE(Matches("class A { public: A *a; };", TypeA));
- EXPECT_TRUE(NotMatches("class A {};", TypeA));
+ EXPECT_TRUE(matches("class A { public: A *a; };", TypeA));
+ EXPECT_TRUE(notMatches("class A {};", TypeA));
TypeMatcher TypeDerivedFromA = HasDeclaration(Class(IsDerivedFrom("A")));
- EXPECT_TRUE(Matches("class A {}; class B : public A { public: B *b; };",
+ EXPECT_TRUE(matches("class A {}; class B : public A { public: B *b; };",
TypeDerivedFromA));
- EXPECT_TRUE(NotMatches("class A {};", TypeA));
+ EXPECT_TRUE(notMatches("class A {};", TypeA));
TypeMatcher TypeAHasClassB = HasDeclaration(
- Class(HasName("A"), Has(Class(HasName("B")))));
+ Class(HasName("A"), has(Class(HasName("B")))));
EXPECT_TRUE(
- Matches("class A { public: A *a; class B {}; };", TypeAHasClassB));
+ matches("class A { public: A *a; class B {}; };", TypeAHasClassB));
}
// Returns from Run whether 'bound_nodes' contain a Decl bound to 'Id', which
@@ -617,8 +617,8 @@
}
}
- virtual bool Run(const BoundNodes *Nodes) {
- if (Nodes->GetDeclAs<T>(Id) != NULL) {
+ virtual bool run(const BoundNodes *Nodes) {
+ if (Nodes->getDeclAs<T>(Id) != NULL) {
++Count;
return true;
}
@@ -634,8 +634,8 @@
class VerifyIdIsBoundToStmt : public BoundNodesCallback {
public:
explicit VerifyIdIsBoundToStmt(const std::string &Id) : Id(Id) {}
- virtual bool Run(const BoundNodes *Nodes) {
- const T *Node = Nodes->GetStmtAs<T>(Id);
+ virtual bool run(const BoundNodes *Nodes) {
+ const T *Node = Nodes->getStmtAs<T>(Id);
return Node != NULL;
}
private:
@@ -643,24 +643,24 @@
};
TEST(Matcher, BindMatchedNodes) {
- DeclarationMatcher ClassX = Has(Id("x", Class(HasName("X"))));
+ DeclarationMatcher ClassX = has(Id("x", Class(HasName("X"))));
- EXPECT_TRUE(MatchAndVerifyResultTrue("class X {};",
+ EXPECT_TRUE(matchAndVerifyResultTrue("class X {};",
ClassX, new VerifyIdIsBoundToDecl<clang::CXXRecordDecl>("x")));
- EXPECT_TRUE(MatchAndVerifyResultFalse("class X {};",
+ EXPECT_TRUE(matchAndVerifyResultFalse("class X {};",
ClassX, new VerifyIdIsBoundToDecl<clang::CXXRecordDecl>("other-id")));
TypeMatcher TypeAHasClassB = HasDeclaration(
- Class(HasName("A"), Has(Id("b", Class(HasName("B"))))));
+ Class(HasName("A"), has(Id("b", Class(HasName("B"))))));
- EXPECT_TRUE(MatchAndVerifyResultTrue("class A { public: A *a; class B {}; };",
+ EXPECT_TRUE(matchAndVerifyResultTrue("class A { public: A *a; class B {}; };",
TypeAHasClassB,
new VerifyIdIsBoundToDecl<clang::Decl>("b")));
StatementMatcher MethodX = Id("x", Call(Callee(Method(HasName("x")))));
- EXPECT_TRUE(MatchAndVerifyResultTrue("class A { void x() { x(); } };",
+ EXPECT_TRUE(matchAndVerifyResultTrue("class A { void x() { x(); } };",
MethodX,
new VerifyIdIsBoundToStmt<clang::CXXMemberCallExpr>("x")));
}
@@ -668,41 +668,41 @@
TEST(HasType, TakesQualTypeMatcherAndMatchesExpr) {
TypeMatcher ClassX = HasDeclaration(Class(HasName("X")));
EXPECT_TRUE(
- Matches("class X {}; void y(X &x) { x; }", Expression(HasType(ClassX))));
+ matches("class X {}; void y(X &x) { x; }", Expression(HasType(ClassX))));
EXPECT_TRUE(
- NotMatches("class X {}; void y(X *x) { x; }",
+ notMatches("class X {}; void y(X *x) { x; }",
Expression(HasType(ClassX))));
EXPECT_TRUE(
- Matches("class X {}; void y(X *x) { x; }",
+ matches("class X {}; void y(X *x) { x; }",
Expression(HasType(PointsTo(ClassX)))));
}
TEST(HasType, TakesQualTypeMatcherAndMatchesValueDecl) {
TypeMatcher ClassX = HasDeclaration(Class(HasName("X")));
EXPECT_TRUE(
- Matches("class X {}; void y() { X x; }", Variable(HasType(ClassX))));
+ matches("class X {}; void y() { X x; }", Variable(HasType(ClassX))));
EXPECT_TRUE(
- NotMatches("class X {}; void y() { X *x; }", Variable(HasType(ClassX))));
+ notMatches("class X {}; void y() { X *x; }", Variable(HasType(ClassX))));
EXPECT_TRUE(
- Matches("class X {}; void y() { X *x; }",
+ matches("class X {}; void y() { X *x; }",
Variable(HasType(PointsTo(ClassX)))));
}
TEST(HasType, TakesDeclMatcherAndMatchesExpr) {
DeclarationMatcher ClassX = Class(HasName("X"));
EXPECT_TRUE(
- Matches("class X {}; void y(X &x) { x; }", Expression(HasType(ClassX))));
+ matches("class X {}; void y(X &x) { x; }", Expression(HasType(ClassX))));
EXPECT_TRUE(
- NotMatches("class X {}; void y(X *x) { x; }",
+ notMatches("class X {}; void y(X *x) { x; }",
Expression(HasType(ClassX))));
}
TEST(HasType, TakesDeclMatcherAndMatchesValueDecl) {
DeclarationMatcher ClassX = Class(HasName("X"));
EXPECT_TRUE(
- Matches("class X {}; void y() { X x; }", Variable(HasType(ClassX))));
+ matches("class X {}; void y() { X x; }", Variable(HasType(ClassX))));
EXPECT_TRUE(
- NotMatches("class X {}; void y() { X *x; }", Variable(HasType(ClassX))));
+ notMatches("class X {}; void y() { X *x; }", Variable(HasType(ClassX))));
}
TEST(Matcher, Call) {
@@ -710,51 +710,51 @@
// Matcher<clang::Decl>, too?
StatementMatcher MethodX = Call(HasDeclaration(Method(HasName("x"))));
- EXPECT_TRUE(Matches("class Y { void x() { x(); } };", MethodX));
- EXPECT_TRUE(NotMatches("class Y { void x() {} };", MethodX));
+ EXPECT_TRUE(matches("class Y { void x() { x(); } };", MethodX));
+ EXPECT_TRUE(notMatches("class Y { void x() {} };", MethodX));
StatementMatcher MethodOnY = Call(On(HasType(Class(HasName("Y")))));
EXPECT_TRUE(
- Matches("class Y { public: void x(); }; void z() { Y y; y.x(); }",
+ matches("class Y { public: void x(); }; void z() { Y y; y.x(); }",
MethodOnY));
EXPECT_TRUE(
- Matches("class Y { public: void x(); }; void z(Y &y) { y.x(); }",
+ matches("class Y { public: void x(); }; void z(Y &y) { y.x(); }",
MethodOnY));
EXPECT_TRUE(
- NotMatches("class Y { public: void x(); }; void z(Y *&y) { y->x(); }",
+ notMatches("class Y { public: void x(); }; void z(Y *&y) { y->x(); }",
MethodOnY));
EXPECT_TRUE(
- NotMatches("class Y { public: void x(); }; void z(Y y[]) { y->x(); }",
+ notMatches("class Y { public: void x(); }; void z(Y y[]) { y->x(); }",
MethodOnY));
EXPECT_TRUE(
- NotMatches("class Y { public: void x(); }; void z() { Y *y; y->x(); }",
+ notMatches("class Y { public: void x(); }; void z() { Y *y; y->x(); }",
MethodOnY));
StatementMatcher MethodOnYPointer =
Call(On(HasType(PointsTo(Class(HasName("Y"))))));
EXPECT_TRUE(
- Matches("class Y { public: void x(); }; void z() { Y *y; y->x(); }",
+ matches("class Y { public: void x(); }; void z() { Y *y; y->x(); }",
MethodOnYPointer));
EXPECT_TRUE(
- Matches("class Y { public: void x(); }; void z(Y *&y) { y->x(); }",
+ matches("class Y { public: void x(); }; void z(Y *&y) { y->x(); }",
MethodOnYPointer));
EXPECT_TRUE(
- Matches("class Y { public: void x(); }; void z(Y y[]) { y->x(); }",
+ matches("class Y { public: void x(); }; void z(Y y[]) { y->x(); }",
MethodOnYPointer));
EXPECT_TRUE(
- NotMatches("class Y { public: void x(); }; void z() { Y y; y.x(); }",
+ notMatches("class Y { public: void x(); }; void z() { Y y; y.x(); }",
MethodOnYPointer));
EXPECT_TRUE(
- NotMatches("class Y { public: void x(); }; void z(Y &y) { y.x(); }",
+ notMatches("class Y { public: void x(); }; void z(Y &y) { y.x(); }",
MethodOnYPointer));
}
TEST(Matcher, OverloadedOperatorCall) {
StatementMatcher OpCall = OverloadedOperatorCall();
// Unary operator
- EXPECT_TRUE(Matches("class Y { }; "
+ EXPECT_TRUE(matches("class Y { }; "
"bool operator!(Y x) { return false; }; "
"Y y; bool c = !y;", OpCall));
// No match -- special operators like "new", "delete"
@@ -764,28 +764,28 @@
// "class Y { }; "
// "void *operator new(size_t size) { return 0; } "
// "Y *y = new Y;", OpCall));
- EXPECT_TRUE(NotMatches("class Y { }; "
+ EXPECT_TRUE(notMatches("class Y { }; "
"void operator delete(void *p) { } "
"void a() {Y *y = new Y; delete y;}", OpCall));
// Binary operator
- EXPECT_TRUE(Matches("class Y { }; "
+ EXPECT_TRUE(matches("class Y { }; "
"bool operator&&(Y x, Y y) { return true; }; "
"Y a; Y b; bool c = a && b;",
OpCall));
// No match -- normal operator, not an overloaded one.
- EXPECT_TRUE(NotMatches("bool x = true, y = true; bool t = x && y;", OpCall));
- EXPECT_TRUE(NotMatches("int t = 5 << 2;", OpCall));
+ EXPECT_TRUE(notMatches("bool x = true, y = true; bool t = x && y;", OpCall));
+ EXPECT_TRUE(notMatches("int t = 5 << 2;", OpCall));
}
TEST(Matcher, HasOperatorNameForOverloadedOperatorCall) {
StatementMatcher OpCallAndAnd =
OverloadedOperatorCall(HasOverloadedOperatorName("&&"));
- EXPECT_TRUE(Matches("class Y { }; "
+ EXPECT_TRUE(matches("class Y { }; "
"bool operator&&(Y x, Y y) { return true; }; "
"Y a; Y b; bool c = a && b;", OpCallAndAnd));
StatementMatcher OpCallLessLess =
OverloadedOperatorCall(HasOverloadedOperatorName("<<"));
- EXPECT_TRUE(NotMatches("class Y { }; "
+ EXPECT_TRUE(notMatches("class Y { }; "
"bool operator&&(Y x, Y y) { return true; }; "
"Y a; Y b; bool c = a && b;",
OpCallLessLess));
@@ -795,22 +795,22 @@
StatementMatcher MethodOnY = Call(ThisPointerType(Class(HasName("Y"))));
EXPECT_TRUE(
- Matches("class Y { public: void x(); }; void z() { Y y; y.x(); }",
+ matches("class Y { public: void x(); }; void z() { Y y; y.x(); }",
MethodOnY));
EXPECT_TRUE(
- Matches("class Y { public: void x(); }; void z(Y &y) { y.x(); }",
+ matches("class Y { public: void x(); }; void z(Y &y) { y.x(); }",
MethodOnY));
EXPECT_TRUE(
- Matches("class Y { public: void x(); }; void z(Y *&y) { y->x(); }",
+ matches("class Y { public: void x(); }; void z(Y *&y) { y->x(); }",
MethodOnY));
EXPECT_TRUE(
- Matches("class Y { public: void x(); }; void z(Y y[]) { y->x(); }",
+ matches("class Y { public: void x(); }; void z(Y y[]) { y->x(); }",
MethodOnY));
EXPECT_TRUE(
- Matches("class Y { public: void x(); }; void z() { Y *y; y->x(); }",
+ matches("class Y { public: void x(); }; void z() { Y *y; y->x(); }",
MethodOnY));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class Y {"
" public: virtual void x();"
"};"
@@ -826,7 +826,7 @@
Variable(HasInitializer(
Call(ThisPointerType(Class(HasName("Y"))))))));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class Y {"
" public:"
" bool x() const;"
@@ -836,7 +836,7 @@
" if (b) {}"
"}", Reference));
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"class Y {"
" public:"
" bool x() const;"
@@ -850,109 +850,109 @@
StatementMatcher CallOnVariableY = Expression(
Call(On(DeclarationReference(To(Variable(HasName("y")))))));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class Y { public: void x() { Y y; y.x(); } };", CallOnVariableY));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class Y { public: void x() const { Y y; y.x(); } };", CallOnVariableY));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class Y { public: void x(); };"
"class X : public Y { void z() { X y; y.x(); } };", CallOnVariableY));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class Y { public: void x(); };"
"class X : public Y { void z() { X *y; y->x(); } };", CallOnVariableY));
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"class Y { public: void x(); };"
"class X : public Y { void z() { unsigned long y; ((X*)y)->x(); } };",
CallOnVariableY));
}
TEST(MemberExpression, DoesNotMatchClasses) {
- EXPECT_TRUE(NotMatches("class Y { void x() {} };", MemberExpression()));
+ EXPECT_TRUE(notMatches("class Y { void x() {} };", MemberExpression()));
}
TEST(MemberExpression, MatchesMemberFunctionCall) {
- EXPECT_TRUE(Matches("class Y { void x() { x(); } };", MemberExpression()));
+ EXPECT_TRUE(matches("class Y { void x() { x(); } };", MemberExpression()));
}
TEST(MemberExpression, MatchesVariable) {
EXPECT_TRUE(
- Matches("class Y { void x() { this->y; } int y; };", MemberExpression()));
+ matches("class Y { void x() { this->y; } int y; };", MemberExpression()));
EXPECT_TRUE(
- Matches("class Y { void x() { y; } int y; };", MemberExpression()));
+ matches("class Y { void x() { y; } int y; };", MemberExpression()));
EXPECT_TRUE(
- Matches("class Y { void x() { Y y; y.y; } int y; };",
+ matches("class Y { void x() { Y y; y.y; } int y; };",
MemberExpression()));
}
TEST(MemberExpression, MatchesStaticVariable) {
- EXPECT_TRUE(Matches("class Y { void x() { this->y; } static int y; };",
+ EXPECT_TRUE(matches("class Y { void x() { this->y; } static int y; };",
MemberExpression()));
- EXPECT_TRUE(NotMatches("class Y { void x() { y; } static int y; };",
+ EXPECT_TRUE(notMatches("class Y { void x() { y; } static int y; };",
MemberExpression()));
- EXPECT_TRUE(NotMatches("class Y { void x() { Y::y; } static int y; };",
+ EXPECT_TRUE(notMatches("class Y { void x() { Y::y; } static int y; };",
MemberExpression()));
}
TEST(IsArrow, MatchesMemberVariablesViaArrow) {
- EXPECT_TRUE(Matches("class Y { void x() { this->y; } int y; };",
+ EXPECT_TRUE(matches("class Y { void x() { this->y; } int y; };",
MemberExpression(IsArrow())));
- EXPECT_TRUE(Matches("class Y { void x() { y; } int y; };",
+ EXPECT_TRUE(matches("class Y { void x() { y; } int y; };",
MemberExpression(IsArrow())));
- EXPECT_TRUE(NotMatches("class Y { void x() { (*this).y; } int y; };",
+ EXPECT_TRUE(notMatches("class Y { void x() { (*this).y; } int y; };",
MemberExpression(IsArrow())));
}
TEST(IsArrow, MatchesStaticMemberVariablesViaArrow) {
- EXPECT_TRUE(Matches("class Y { void x() { this->y; } static int y; };",
+ EXPECT_TRUE(matches("class Y { void x() { this->y; } static int y; };",
MemberExpression(IsArrow())));
- EXPECT_TRUE(NotMatches("class Y { void x() { y; } static int y; };",
+ EXPECT_TRUE(notMatches("class Y { void x() { y; } static int y; };",
MemberExpression(IsArrow())));
- EXPECT_TRUE(NotMatches("class Y { void x() { (*this).y; } static int y; };",
+ EXPECT_TRUE(notMatches("class Y { void x() { (*this).y; } static int y; };",
MemberExpression(IsArrow())));
}
TEST(IsArrow, MatchesMemberCallsViaArrow) {
- EXPECT_TRUE(Matches("class Y { void x() { this->x(); } };",
+ EXPECT_TRUE(matches("class Y { void x() { this->x(); } };",
MemberExpression(IsArrow())));
- EXPECT_TRUE(Matches("class Y { void x() { x(); } };",
+ EXPECT_TRUE(matches("class Y { void x() { x(); } };",
MemberExpression(IsArrow())));
- EXPECT_TRUE(NotMatches("class Y { void x() { Y y; y.x(); } };",
+ EXPECT_TRUE(notMatches("class Y { void x() { Y y; y.x(); } };",
MemberExpression(IsArrow())));
}
TEST(Callee, MatchesDeclarations) {
StatementMatcher CallMethodX = Call(Callee(Method(HasName("x"))));
- EXPECT_TRUE(Matches("class Y { void x() { x(); } };", CallMethodX));
- EXPECT_TRUE(NotMatches("class Y { void x() {} };", CallMethodX));
+ EXPECT_TRUE(matches("class Y { void x() { x(); } };", CallMethodX));
+ EXPECT_TRUE(notMatches("class Y { void x() {} };", CallMethodX));
}
TEST(Callee, MatchesMemberExpressions) {
- EXPECT_TRUE(Matches("class Y { void x() { this->x(); } };",
+ EXPECT_TRUE(matches("class Y { void x() { this->x(); } };",
Call(Callee(MemberExpression()))));
EXPECT_TRUE(
- NotMatches("class Y { void x() { this->x(); } };", Call(Callee(Call()))));
+ notMatches("class Y { void x() { this->x(); } };", Call(Callee(Call()))));
}
TEST(Function, MatchesFunctionDeclarations) {
StatementMatcher CallFunctionF = Call(Callee(Function(HasName("f"))));
- EXPECT_TRUE(Matches("void f() { f(); }", CallFunctionF));
- EXPECT_TRUE(NotMatches("void f() { }", CallFunctionF));
+ EXPECT_TRUE(matches("void f() { f(); }", CallFunctionF));
+ EXPECT_TRUE(notMatches("void f() { }", CallFunctionF));
// Dependent contexts, but a non-dependent call.
- EXPECT_TRUE(Matches("void f(); template <int N> void g() { f(); }",
+ EXPECT_TRUE(matches("void f(); template <int N> void g() { f(); }",
CallFunctionF));
EXPECT_TRUE(
- Matches("void f(); template <int N> struct S { void g() { f(); } };",
+ matches("void f(); template <int N> struct S { void g() { f(); } };",
CallFunctionF));
// Depedent calls don't match.
EXPECT_TRUE(
- NotMatches("void f(int); template <typename T> void g(T t) { f(t); }",
+ notMatches("void f(int); template <typename T> void g(T t) { f(t); }",
CallFunctionF));
EXPECT_TRUE(
- NotMatches("void f(int);"
+ notMatches("void f(int);"
"template <typename T> struct S { void g(T t) { f(t); } };",
CallFunctionF));
}
@@ -961,89 +961,89 @@
StatementMatcher CallArgumentY = Expression(Call(
HasArgument(0, DeclarationReference(To(Variable(HasName("y")))))));
- EXPECT_TRUE(Matches("void x(int) { int y; x(y); }", CallArgumentY));
+ EXPECT_TRUE(matches("void x(int) { int y; x(y); }", CallArgumentY));
EXPECT_TRUE(
- Matches("class X { void x(int) { int y; x(y); } };", CallArgumentY));
- EXPECT_TRUE(NotMatches("void x(int) { int z; x(z); }", CallArgumentY));
+ matches("class X { void x(int) { int y; x(y); } };", CallArgumentY));
+ EXPECT_TRUE(notMatches("void x(int) { int z; x(z); }", CallArgumentY));
StatementMatcher WrongIndex = Expression(Call(
HasArgument(42, DeclarationReference(To(Variable(HasName("y")))))));
- EXPECT_TRUE(NotMatches("void x(int) { int y; x(y); }", WrongIndex));
+ EXPECT_TRUE(notMatches("void x(int) { int y; x(y); }", WrongIndex));
}
TEST(Matcher, AnyArgument) {
StatementMatcher CallArgumentY = Expression(Call(
HasAnyArgument(DeclarationReference(To(Variable(HasName("y")))))));
- EXPECT_TRUE(Matches("void x(int, int) { int y; x(1, y); }", CallArgumentY));
- EXPECT_TRUE(Matches("void x(int, int) { int y; x(y, 42); }", CallArgumentY));
- EXPECT_TRUE(NotMatches("void x(int, int) { x(1, 2); }", CallArgumentY));
+ EXPECT_TRUE(matches("void x(int, int) { int y; x(1, y); }", CallArgumentY));
+ EXPECT_TRUE(matches("void x(int, int) { int y; x(y, 42); }", CallArgumentY));
+ EXPECT_TRUE(notMatches("void x(int, int) { x(1, 2); }", CallArgumentY));
}
TEST(Matcher, ArgumentCount) {
StatementMatcher Call1Arg = Expression(Call(ArgumentCountIs(1)));
- EXPECT_TRUE(Matches("void x(int) { x(0); }", Call1Arg));
- EXPECT_TRUE(Matches("class X { void x(int) { x(0); } };", Call1Arg));
- EXPECT_TRUE(NotMatches("void x(int, int) { x(0, 0); }", Call1Arg));
+ EXPECT_TRUE(matches("void x(int) { x(0); }", Call1Arg));
+ EXPECT_TRUE(matches("class X { void x(int) { x(0); } };", Call1Arg));
+ EXPECT_TRUE(notMatches("void x(int, int) { x(0, 0); }", Call1Arg));
}
TEST(Matcher, References) {
DeclarationMatcher ReferenceClassX = Variable(
HasType(References(Class(HasName("X")))));
- EXPECT_TRUE(Matches("class X {}; void y(X y) { X &x = y; }",
+ EXPECT_TRUE(matches("class X {}; void y(X y) { X &x = y; }",
ReferenceClassX));
EXPECT_TRUE(
- Matches("class X {}; void y(X y) { const X &x = y; }", ReferenceClassX));
+ matches("class X {}; void y(X y) { const X &x = y; }", ReferenceClassX));
EXPECT_TRUE(
- NotMatches("class X {}; void y(X y) { X x = y; }", ReferenceClassX));
+ notMatches("class X {}; void y(X y) { X x = y; }", ReferenceClassX));
EXPECT_TRUE(
- NotMatches("class X {}; void y(X *y) { X *&x = y; }", ReferenceClassX));
+ notMatches("class X {}; void y(X *y) { X *&x = y; }", ReferenceClassX));
}
TEST(HasParameter, CallsInnerMatcher) {
- EXPECT_TRUE(Matches("class X { void x(int) {} };",
+ EXPECT_TRUE(matches("class X { void x(int) {} };",
Method(HasParameter(0, Variable()))));
- EXPECT_TRUE(NotMatches("class X { void x(int) {} };",
+ EXPECT_TRUE(notMatches("class X { void x(int) {} };",
Method(HasParameter(0, HasName("x")))));
}
TEST(HasParameter, DoesNotMatchIfIndexOutOfBounds) {
- EXPECT_TRUE(NotMatches("class X { void x(int) {} };",
+ EXPECT_TRUE(notMatches("class X { void x(int) {} };",
Method(HasParameter(42, Variable()))));
}
TEST(HasType, MatchesParameterVariableTypesStrictly) {
- EXPECT_TRUE(Matches("class X { void x(X x) {} };",
+ EXPECT_TRUE(matches("class X { void x(X x) {} };",
Method(HasParameter(0, HasType(Class(HasName("X")))))));
- EXPECT_TRUE(NotMatches("class X { void x(const X &x) {} };",
+ EXPECT_TRUE(notMatches("class X { void x(const X &x) {} };",
Method(HasParameter(0, HasType(Class(HasName("X")))))));
- EXPECT_TRUE(Matches("class X { void x(const X *x) {} };",
+ EXPECT_TRUE(matches("class X { void x(const X *x) {} };",
Method(HasParameter(0, HasType(PointsTo(Class(HasName("X"))))))));
- EXPECT_TRUE(Matches("class X { void x(const X &x) {} };",
+ EXPECT_TRUE(matches("class X { void x(const X &x) {} };",
Method(HasParameter(0, HasType(References(Class(HasName("X"))))))));
}
TEST(HasAnyParameter, MatchesIndependentlyOfPosition) {
- EXPECT_TRUE(Matches("class Y {}; class X { void x(X x, Y y) {} };",
+ EXPECT_TRUE(matches("class Y {}; class X { void x(X x, Y y) {} };",
Method(HasAnyParameter(HasType(Class(HasName("X")))))));
- EXPECT_TRUE(Matches("class Y {}; class X { void x(Y y, X x) {} };",
+ EXPECT_TRUE(matches("class Y {}; class X { void x(Y y, X x) {} };",
Method(HasAnyParameter(HasType(Class(HasName("X")))))));
}
TEST(HasAnyParameter, DoesntMatchIfInnerMatcherDoesntMatch) {
- EXPECT_TRUE(NotMatches("class Y {}; class X { void x(int) {} };",
+ EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };",
Method(HasAnyParameter(HasType(Class(HasName("X")))))));
}
TEST(HasAnyParameter, DoesNotMatchThisPointer) {
- EXPECT_TRUE(NotMatches("class Y {}; class X { void x() {} };",
+ EXPECT_TRUE(notMatches("class Y {}; class X { void x() {} };",
Method(HasAnyParameter(HasType(PointsTo(Class(HasName("X"))))))));
}
TEST(HasName, MatchesParameterVariableDeclartions) {
- EXPECT_TRUE(Matches("class Y {}; class X { void x(int x) {} };",
+ EXPECT_TRUE(matches("class Y {}; class X { void x(int x) {} };",
Method(HasAnyParameter(HasName("x")))));
- EXPECT_TRUE(NotMatches("class Y {}; class X { void x(int) {} };",
+ EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };",
Method(HasAnyParameter(HasName("x")))));
}
@@ -1051,14 +1051,14 @@
StatementMatcher Constructor = Expression(ConstructorCall());
EXPECT_TRUE(
- Matches("class X { public: X(); }; void x() { X x; }", Constructor));
+ matches("class X { public: X(); }; void x() { X x; }", Constructor));
EXPECT_TRUE(
- Matches("class X { public: X(); }; void x() { X x = X(); }",
+ matches("class X { public: X(); }; void x() { X x = X(); }",
Constructor));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { X x = 0; }",
+ matches("class X { public: X(int); }; void x() { X x = 0; }",
Constructor));
- EXPECT_TRUE(Matches("class X {}; void x(int) { X x; }", Constructor));
+ EXPECT_TRUE(matches("class X {}; void x(int) { X x; }", Constructor));
}
TEST(Matcher, ConstructorArgument) {
@@ -1066,22 +1066,22 @@
HasArgument(0, DeclarationReference(To(Variable(HasName("y")))))));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { int y; X x(y); }",
+ matches("class X { public: X(int); }; void x() { int y; X x(y); }",
Constructor));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { int y; X x = X(y); }",
+ matches("class X { public: X(int); }; void x() { int y; X x = X(y); }",
Constructor));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { int y; X x = y; }",
+ matches("class X { public: X(int); }; void x() { int y; X x = y; }",
Constructor));
EXPECT_TRUE(
- NotMatches("class X { public: X(int); }; void x() { int z; X x(z); }",
+ notMatches("class X { public: X(int); }; void x() { int z; X x(z); }",
Constructor));
StatementMatcher WrongIndex = Expression(ConstructorCall(
HasArgument(42, DeclarationReference(To(Variable(HasName("y")))))));
EXPECT_TRUE(
- NotMatches("class X { public: X(int); }; void x() { int y; X x(y); }",
+ notMatches("class X { public: X(int); }; void x() { int y; X x(y); }",
WrongIndex));
}
@@ -1090,16 +1090,16 @@
Expression(ConstructorCall(ArgumentCountIs(1)));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { X x(0); }",
+ matches("class X { public: X(int); }; void x() { X x(0); }",
Constructor1Arg));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { X x = X(0); }",
+ matches("class X { public: X(int); }; void x() { X x = X(0); }",
Constructor1Arg));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { X x = 0; }",
+ matches("class X { public: X(int); }; void x() { X x = 0; }",
Constructor1Arg));
EXPECT_TRUE(
- NotMatches("class X { public: X(int, int); }; void x() { X x(0, 0); }",
+ notMatches("class X { public: X(int, int); }; void x() { X x(0, 0); }",
Constructor1Arg));
}
@@ -1109,14 +1109,14 @@
std::string ClassString = "class string { public: string(); ~string(); }; ";
EXPECT_TRUE(
- Matches(ClassString +
+ matches(ClassString +
"string GetStringByValue();"
"void FunctionTakesString(string s);"
"void run() { FunctionTakesString(GetStringByValue()); }",
TempExpression));
EXPECT_TRUE(
- NotMatches(ClassString +
+ notMatches(ClassString +
"string* GetStringPointer(); "
"void FunctionTakesStringPtr(string* s);"
"void run() {"
@@ -1127,7 +1127,7 @@
TempExpression));
EXPECT_TRUE(
- NotMatches("class no_dtor {};"
+ notMatches("class no_dtor {};"
"no_dtor GetObjByValue();"
"void ConsumeObj(no_dtor param);"
"void run() { ConsumeObj(GetObjByValue()); }",
@@ -1135,29 +1135,29 @@
}
TEST(ConstructorDeclaration, SimpleCase) {
- EXPECT_TRUE(Matches("class Foo { Foo(int i); };",
+ EXPECT_TRUE(matches("class Foo { Foo(int i); };",
Constructor(OfClass(HasName("Foo")))));
- EXPECT_TRUE(NotMatches("class Foo { Foo(int i); };",
+ EXPECT_TRUE(notMatches("class Foo { Foo(int i); };",
Constructor(OfClass(HasName("Bar")))));
}
TEST(ConstructorDeclaration, IsImplicit) {
// This one doesn't match because the constructor is not added by the
// compiler (it is not needed).
- EXPECT_TRUE(NotMatches("class Foo { };",
+ EXPECT_TRUE(notMatches("class Foo { };",
Constructor(IsImplicit())));
// The compiler added the implicit default constructor.
- EXPECT_TRUE(Matches("class Foo { }; Foo* f = new Foo();",
+ EXPECT_TRUE(matches("class Foo { }; Foo* f = new Foo();",
Constructor(IsImplicit())));
- EXPECT_TRUE(Matches("class Foo { Foo(){} };",
+ EXPECT_TRUE(matches("class Foo { Foo(){} };",
Constructor(Not(IsImplicit()))));
}
TEST(HasAnyConstructorInitializer, SimpleCase) {
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"class Foo { Foo() { } };",
Constructor(HasAnyConstructorInitializer(True()))));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class Foo {"
" Foo() : foo_() { }"
" int foo_;"
@@ -1173,11 +1173,11 @@
" Baz foo_;"
" Baz bar_;"
"};";
- EXPECT_TRUE(Matches(Code, Constructor(HasAnyConstructorInitializer(
+ EXPECT_TRUE(matches(Code, Constructor(HasAnyConstructorInitializer(
ForField(HasType(Class(HasName("Baz"))))))));
- EXPECT_TRUE(Matches(Code, Constructor(HasAnyConstructorInitializer(
+ EXPECT_TRUE(matches(Code, Constructor(HasAnyConstructorInitializer(
ForField(HasName("foo_"))))));
- EXPECT_TRUE(NotMatches(Code, Constructor(HasAnyConstructorInitializer(
+ EXPECT_TRUE(notMatches(Code, Constructor(HasAnyConstructorInitializer(
ForField(HasType(Class(HasName("Bar"))))))));
}
@@ -1187,9 +1187,9 @@
" Foo() : foo_(0) { }"
" int foo_;"
"};";
- EXPECT_TRUE(Matches(Code, Constructor(HasAnyConstructorInitializer(
+ EXPECT_TRUE(matches(Code, Constructor(HasAnyConstructorInitializer(
WithInitializer(IntegerLiteral(Equals(0)))))));
- EXPECT_TRUE(NotMatches(Code, Constructor(HasAnyConstructorInitializer(
+ EXPECT_TRUE(notMatches(Code, Constructor(HasAnyConstructorInitializer(
WithInitializer(IntegerLiteral(Equals(1)))))));
}
@@ -1201,23 +1201,23 @@
" Bar foo_;"
" Bar bar_;"
"};";
- EXPECT_TRUE(Matches(Code, Constructor(HasAnyConstructorInitializer(
+ EXPECT_TRUE(matches(Code, Constructor(HasAnyConstructorInitializer(
AllOf(ForField(HasName("foo_")), IsWritten())))));
- EXPECT_TRUE(NotMatches(Code, Constructor(HasAnyConstructorInitializer(
+ EXPECT_TRUE(notMatches(Code, Constructor(HasAnyConstructorInitializer(
AllOf(ForField(HasName("bar_")), IsWritten())))));
- EXPECT_TRUE(Matches(Code, Constructor(HasAnyConstructorInitializer(
+ EXPECT_TRUE(matches(Code, Constructor(HasAnyConstructorInitializer(
AllOf(ForField(HasName("bar_")), Not(IsWritten()))))));
}
TEST(Matcher, NewExpression) {
StatementMatcher New = Expression(NewExpression());
- EXPECT_TRUE(Matches("class X { public: X(); }; void x() { new X; }", New));
+ EXPECT_TRUE(matches("class X { public: X(); }; void x() { new X; }", New));
EXPECT_TRUE(
- Matches("class X { public: X(); }; void x() { new X(); }", New));
+ matches("class X { public: X(); }; void x() { new X(); }", New));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { new X(0); }", New));
- EXPECT_TRUE(Matches("class X {}; void x(int) { new X; }", New));
+ matches("class X { public: X(int); }; void x() { new X(0); }", New));
+ EXPECT_TRUE(matches("class X {}; void x(int) { new X; }", New));
}
TEST(Matcher, NewExpressionArgument) {
@@ -1226,20 +1226,20 @@
0, DeclarationReference(To(Variable(HasName("y")))))));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { int y; new X(y); }",
+ matches("class X { public: X(int); }; void x() { int y; new X(y); }",
New));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { int y; new X(y); }",
+ matches("class X { public: X(int); }; void x() { int y; new X(y); }",
New));
EXPECT_TRUE(
- NotMatches("class X { public: X(int); }; void x() { int z; new X(z); }",
+ notMatches("class X { public: X(int); }; void x() { int z; new X(z); }",
New));
StatementMatcher WrongIndex = Expression(ConstructorCall(
HasArgument(
42, DeclarationReference(To(Variable(HasName("y")))))));
EXPECT_TRUE(
- NotMatches("class X { public: X(int); }; void x() { int y; new X(y); }",
+ notMatches("class X { public: X(int); }; void x() { int y; new X(y); }",
WrongIndex));
}
@@ -1247,73 +1247,73 @@
StatementMatcher New = ConstructorCall(ArgumentCountIs(1));
EXPECT_TRUE(
- Matches("class X { public: X(int); }; void x() { new X(0); }", New));
+ matches("class X { public: X(int); }; void x() { new X(0); }", New));
EXPECT_TRUE(
- NotMatches("class X { public: X(int, int); }; void x() { new X(0, 0); }",
+ notMatches("class X { public: X(int, int); }; void x() { new X(0, 0); }",
New));
}
TEST(Matcher, DefaultArgument) {
StatementMatcher Arg = DefaultArgument();
- EXPECT_TRUE(Matches("void x(int, int = 0) { int y; x(y); }", Arg));
+ EXPECT_TRUE(matches("void x(int, int = 0) { int y; x(y); }", Arg));
EXPECT_TRUE(
- Matches("class X { void x(int, int = 0) { int y; x(y); } };", Arg));
- EXPECT_TRUE(NotMatches("void x(int, int = 0) { int y; x(y, 0); }", Arg));
+ matches("class X { void x(int, int = 0) { int y; x(y); } };", Arg));
+ EXPECT_TRUE(notMatches("void x(int, int = 0) { int y; x(y, 0); }", Arg));
}
TEST(Matcher, StringLiterals) {
StatementMatcher Literal = Expression(StringLiteral());
- EXPECT_TRUE(Matches("const char *s = \"string\";", Literal));
+ EXPECT_TRUE(matches("const char *s = \"string\";", Literal));
// wide string
- EXPECT_TRUE(Matches("const wchar_t *s = L\"string\";", Literal));
+ EXPECT_TRUE(matches("const wchar_t *s = L\"string\";", Literal));
// with escaped characters
- EXPECT_TRUE(Matches("const char *s = \"\x05five\";", Literal));
+ EXPECT_TRUE(matches("const char *s = \"\x05five\";", Literal));
// no matching -- though the data type is the same, there is no string literal
- EXPECT_TRUE(NotMatches("const char s[1] = {'a'};", Literal));
+ EXPECT_TRUE(notMatches("const char s[1] = {'a'};", Literal));
}
TEST(Matcher, CharacterLiterals) {
StatementMatcher CharLiteral = Expression(CharacterLiteral());
- EXPECT_TRUE(Matches("const char c = 'c';", CharLiteral));
+ EXPECT_TRUE(matches("const char c = 'c';", CharLiteral));
// wide character
- EXPECT_TRUE(Matches("const char c = L'c';", CharLiteral));
+ EXPECT_TRUE(matches("const char c = L'c';", CharLiteral));
// wide character, Hex encoded, NOT MATCHED!
- EXPECT_TRUE(NotMatches("const wchar_t c = 0x2126;", CharLiteral));
- EXPECT_TRUE(NotMatches("const char c = 0x1;", CharLiteral));
+ EXPECT_TRUE(notMatches("const wchar_t c = 0x2126;", CharLiteral));
+ EXPECT_TRUE(notMatches("const char c = 0x1;", CharLiteral));
}
TEST(Matcher, IntegerLiterals) {
StatementMatcher HasIntLiteral = Expression(IntegerLiteral());
- EXPECT_TRUE(Matches("int i = 10;", HasIntLiteral));
- EXPECT_TRUE(Matches("int i = 0x1AB;", HasIntLiteral));
- EXPECT_TRUE(Matches("int i = 10L;", HasIntLiteral));
- EXPECT_TRUE(Matches("int i = 10U;", HasIntLiteral));
+ EXPECT_TRUE(matches("int i = 10;", HasIntLiteral));
+ EXPECT_TRUE(matches("int i = 0x1AB;", HasIntLiteral));
+ EXPECT_TRUE(matches("int i = 10L;", HasIntLiteral));
+ EXPECT_TRUE(matches("int i = 10U;", HasIntLiteral));
// Non-matching cases (character literals, float and double)
- EXPECT_TRUE(NotMatches("int i = L'a';",
+ EXPECT_TRUE(notMatches("int i = L'a';",
HasIntLiteral)); // this is actually a character
// literal cast to int
- EXPECT_TRUE(NotMatches("int i = 'a';", HasIntLiteral));
- EXPECT_TRUE(NotMatches("int i = 1e10;", HasIntLiteral));
- EXPECT_TRUE(NotMatches("int i = 10.0;", HasIntLiteral));
+ EXPECT_TRUE(notMatches("int i = 'a';", HasIntLiteral));
+ EXPECT_TRUE(notMatches("int i = 1e10;", HasIntLiteral));
+ EXPECT_TRUE(notMatches("int i = 10.0;", HasIntLiteral));
}
TEST(Matcher, Conditions) {
StatementMatcher Condition = If(HasCondition(BoolLiteral(Equals(true))));
- EXPECT_TRUE(Matches("void x() { if (true) {} }", Condition));
- EXPECT_TRUE(NotMatches("void x() { if (false) {} }", Condition));
- EXPECT_TRUE(NotMatches("void x() { bool a = true; if (a) {} }", Condition));
- EXPECT_TRUE(NotMatches("void x() { if (true || false) {} }", Condition));
- EXPECT_TRUE(NotMatches("void x() { if (1) {} }", Condition));
+ EXPECT_TRUE(matches("void x() { if (true) {} }", Condition));
+ EXPECT_TRUE(notMatches("void x() { if (false) {} }", Condition));
+ EXPECT_TRUE(notMatches("void x() { bool a = true; if (a) {} }", Condition));
+ EXPECT_TRUE(notMatches("void x() { if (true || false) {} }", Condition));
+ EXPECT_TRUE(notMatches("void x() { if (1) {} }", Condition));
}
TEST(MatchBinaryOperator, HasOperatorName) {
StatementMatcher OperatorOr = BinaryOperator(HasOperatorName("||"));
- EXPECT_TRUE(Matches("void x() { true || false; }", OperatorOr));
- EXPECT_TRUE(NotMatches("void x() { true && false; }", OperatorOr));
+ EXPECT_TRUE(matches("void x() { true || false; }", OperatorOr));
+ EXPECT_TRUE(notMatches("void x() { true && false; }", OperatorOr));
}
TEST(MatchBinaryOperator, HasLHSAndHasRHS) {
@@ -1321,18 +1321,18 @@
BinaryOperator(HasLHS(BoolLiteral(Equals(true))),
HasRHS(BoolLiteral(Equals(false))));
- EXPECT_TRUE(Matches("void x() { true || false; }", OperatorTrueFalse));
- EXPECT_TRUE(Matches("void x() { true && false; }", OperatorTrueFalse));
- EXPECT_TRUE(NotMatches("void x() { false || true; }", OperatorTrueFalse));
+ EXPECT_TRUE(matches("void x() { true || false; }", OperatorTrueFalse));
+ EXPECT_TRUE(matches("void x() { true && false; }", OperatorTrueFalse));
+ EXPECT_TRUE(notMatches("void x() { false || true; }", OperatorTrueFalse));
}
TEST(MatchBinaryOperator, HasEitherOperand) {
StatementMatcher HasOperand =
BinaryOperator(HasEitherOperand(BoolLiteral(Equals(false))));
- EXPECT_TRUE(Matches("void x() { true || false; }", HasOperand));
- EXPECT_TRUE(Matches("void x() { false && true; }", HasOperand));
- EXPECT_TRUE(NotMatches("void x() { true || true; }", HasOperand));
+ EXPECT_TRUE(matches("void x() { true || false; }", HasOperand));
+ EXPECT_TRUE(matches("void x() { false && true; }", HasOperand));
+ EXPECT_TRUE(notMatches("void x() { true || true; }", HasOperand));
}
TEST(Matcher, BinaryOperatorTypes) {
@@ -1340,97 +1340,97 @@
// a way we expect.
// FIXME: Operator ','
EXPECT_TRUE(
- Matches("void x() { 3, 4; }", BinaryOperator(HasOperatorName(","))));
+ matches("void x() { 3, 4; }", BinaryOperator(HasOperatorName(","))));
EXPECT_TRUE(
- Matches("bool b; bool c = (b = true);",
+ matches("bool b; bool c = (b = true);",
BinaryOperator(HasOperatorName("="))));
EXPECT_TRUE(
- Matches("bool b = 1 != 2;", BinaryOperator(HasOperatorName("!="))));
+ matches("bool b = 1 != 2;", BinaryOperator(HasOperatorName("!="))));
EXPECT_TRUE(
- Matches("bool b = 1 == 2;", BinaryOperator(HasOperatorName("=="))));
- EXPECT_TRUE(Matches("bool b = 1 < 2;", BinaryOperator(HasOperatorName("<"))));
+ matches("bool b = 1 == 2;", BinaryOperator(HasOperatorName("=="))));
+ EXPECT_TRUE(matches("bool b = 1 < 2;", BinaryOperator(HasOperatorName("<"))));
EXPECT_TRUE(
- Matches("bool b = 1 <= 2;", BinaryOperator(HasOperatorName("<="))));
+ matches("bool b = 1 <= 2;", BinaryOperator(HasOperatorName("<="))));
EXPECT_TRUE(
- Matches("int i = 1 << 2;", BinaryOperator(HasOperatorName("<<"))));
+ matches("int i = 1 << 2;", BinaryOperator(HasOperatorName("<<"))));
EXPECT_TRUE(
- Matches("int i = 1; int j = (i <<= 2);",
+ matches("int i = 1; int j = (i <<= 2);",
BinaryOperator(HasOperatorName("<<="))));
- EXPECT_TRUE(Matches("bool b = 1 > 2;", BinaryOperator(HasOperatorName(">"))));
+ EXPECT_TRUE(matches("bool b = 1 > 2;", BinaryOperator(HasOperatorName(">"))));
EXPECT_TRUE(
- Matches("bool b = 1 >= 2;", BinaryOperator(HasOperatorName(">="))));
+ matches("bool b = 1 >= 2;", BinaryOperator(HasOperatorName(">="))));
EXPECT_TRUE(
- Matches("int i = 1 >> 2;", BinaryOperator(HasOperatorName(">>"))));
+ matches("int i = 1 >> 2;", BinaryOperator(HasOperatorName(">>"))));
EXPECT_TRUE(
- Matches("int i = 1; int j = (i >>= 2);",
+ matches("int i = 1; int j = (i >>= 2);",
BinaryOperator(HasOperatorName(">>="))));
EXPECT_TRUE(
- Matches("int i = 42 ^ 23;", BinaryOperator(HasOperatorName("^"))));
+ matches("int i = 42 ^ 23;", BinaryOperator(HasOperatorName("^"))));
EXPECT_TRUE(
- Matches("int i = 42; int j = (i ^= 42);",
+ matches("int i = 42; int j = (i ^= 42);",
BinaryOperator(HasOperatorName("^="))));
EXPECT_TRUE(
- Matches("int i = 42 % 23;", BinaryOperator(HasOperatorName("%"))));
+ matches("int i = 42 % 23;", BinaryOperator(HasOperatorName("%"))));
EXPECT_TRUE(
- Matches("int i = 42; int j = (i %= 42);",
+ matches("int i = 42; int j = (i %= 42);",
BinaryOperator(HasOperatorName("%="))));
EXPECT_TRUE(
- Matches("bool b = 42 &23;", BinaryOperator(HasOperatorName("&"))));
+ matches("bool b = 42 &23;", BinaryOperator(HasOperatorName("&"))));
EXPECT_TRUE(
- Matches("bool b = true && false;",
+ matches("bool b = true && false;",
BinaryOperator(HasOperatorName("&&"))));
EXPECT_TRUE(
- Matches("bool b = true; bool c = (b &= false);",
+ matches("bool b = true; bool c = (b &= false);",
BinaryOperator(HasOperatorName("&="))));
EXPECT_TRUE(
- Matches("bool b = 42 | 23;", BinaryOperator(HasOperatorName("|"))));
+ matches("bool b = 42 | 23;", BinaryOperator(HasOperatorName("|"))));
EXPECT_TRUE(
- Matches("bool b = true || false;",
+ matches("bool b = true || false;",
BinaryOperator(HasOperatorName("||"))));
EXPECT_TRUE(
- Matches("bool b = true; bool c = (b |= false);",
+ matches("bool b = true; bool c = (b |= false);",
BinaryOperator(HasOperatorName("|="))));
EXPECT_TRUE(
- Matches("int i = 42 *23;", BinaryOperator(HasOperatorName("*"))));
+ matches("int i = 42 *23;", BinaryOperator(HasOperatorName("*"))));
EXPECT_TRUE(
- Matches("int i = 42; int j = (i *= 23);",
+ matches("int i = 42; int j = (i *= 23);",
BinaryOperator(HasOperatorName("*="))));
EXPECT_TRUE(
- Matches("int i = 42 / 23;", BinaryOperator(HasOperatorName("/"))));
+ matches("int i = 42 / 23;", BinaryOperator(HasOperatorName("/"))));
EXPECT_TRUE(
- Matches("int i = 42; int j = (i /= 23);",
+ matches("int i = 42; int j = (i /= 23);",
BinaryOperator(HasOperatorName("/="))));
EXPECT_TRUE(
- Matches("int i = 42 + 23;", BinaryOperator(HasOperatorName("+"))));
+ matches("int i = 42 + 23;", BinaryOperator(HasOperatorName("+"))));
EXPECT_TRUE(
- Matches("int i = 42; int j = (i += 23);",
+ matches("int i = 42; int j = (i += 23);",
BinaryOperator(HasOperatorName("+="))));
EXPECT_TRUE(
- Matches("int i = 42 - 23;", BinaryOperator(HasOperatorName("-"))));
+ matches("int i = 42 - 23;", BinaryOperator(HasOperatorName("-"))));
EXPECT_TRUE(
- Matches("int i = 42; int j = (i -= 23);",
+ matches("int i = 42; int j = (i -= 23);",
BinaryOperator(HasOperatorName("-="))));
EXPECT_TRUE(
- Matches("struct A { void x() { void (A::*a)(); (this->*a)(); } };",
+ matches("struct A { void x() { void (A::*a)(); (this->*a)(); } };",
BinaryOperator(HasOperatorName("->*"))));
EXPECT_TRUE(
- Matches("struct A { void x() { void (A::*a)(); ((*this).*a)(); } };",
+ matches("struct A { void x() { void (A::*a)(); ((*this).*a)(); } };",
BinaryOperator(HasOperatorName(".*"))));
// Member expressions as operators are not supported in matches.
EXPECT_TRUE(
- NotMatches("struct A { void x(A *a) { a->x(this); } };",
+ notMatches("struct A { void x(A *a) { a->x(this); } };",
BinaryOperator(HasOperatorName("->"))));
// Initializer assignments are not represented as operator equals.
EXPECT_TRUE(
- NotMatches("bool b = true;", BinaryOperator(HasOperatorName("="))));
+ notMatches("bool b = true;", BinaryOperator(HasOperatorName("="))));
// Array indexing is not represented as operator.
- EXPECT_TRUE(NotMatches("int a[42]; void x() { a[23]; }", UnaryOperator()));
+ EXPECT_TRUE(notMatches("int a[42]; void x() { a[23]; }", UnaryOperator()));
// Overloaded operators do not match at all.
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"struct A { bool operator&&(const A &a) const { return false; } };"
"void x() { A a, b; a && b; }",
BinaryOperator()));
@@ -1439,49 +1439,49 @@
TEST(MatchUnaryOperator, HasOperatorName) {
StatementMatcher OperatorNot = UnaryOperator(HasOperatorName("!"));
- EXPECT_TRUE(Matches("void x() { !true; } ", OperatorNot));
- EXPECT_TRUE(NotMatches("void x() { true; } ", OperatorNot));
+ EXPECT_TRUE(matches("void x() { !true; } ", OperatorNot));
+ EXPECT_TRUE(notMatches("void x() { true; } ", OperatorNot));
}
TEST(MatchUnaryOperator, HasUnaryOperand) {
StatementMatcher OperatorOnFalse =
UnaryOperator(HasUnaryOperand(BoolLiteral(Equals(false))));
- EXPECT_TRUE(Matches("void x() { !false; }", OperatorOnFalse));
- EXPECT_TRUE(NotMatches("void x() { !true; }", OperatorOnFalse));
+ EXPECT_TRUE(matches("void x() { !false; }", OperatorOnFalse));
+ EXPECT_TRUE(notMatches("void x() { !true; }", OperatorOnFalse));
}
TEST(Matcher, UnaryOperatorTypes) {
// Integration test that verifies the AST provides all unary operators in
// a way we expect.
- EXPECT_TRUE(Matches("bool b = !true;", UnaryOperator(HasOperatorName("!"))));
+ EXPECT_TRUE(matches("bool b = !true;", UnaryOperator(HasOperatorName("!"))));
EXPECT_TRUE(
- Matches("bool b; bool *p = &b;", UnaryOperator(HasOperatorName("&"))));
- EXPECT_TRUE(Matches("int i = ~ 1;", UnaryOperator(HasOperatorName("~"))));
+ matches("bool b; bool *p = &b;", UnaryOperator(HasOperatorName("&"))));
+ EXPECT_TRUE(matches("int i = ~ 1;", UnaryOperator(HasOperatorName("~"))));
EXPECT_TRUE(
- Matches("bool *p; bool b = *p;", UnaryOperator(HasOperatorName("*"))));
+ matches("bool *p; bool b = *p;", UnaryOperator(HasOperatorName("*"))));
EXPECT_TRUE(
- Matches("int i; int j = +i;", UnaryOperator(HasOperatorName("+"))));
+ matches("int i; int j = +i;", UnaryOperator(HasOperatorName("+"))));
EXPECT_TRUE(
- Matches("int i; int j = -i;", UnaryOperator(HasOperatorName("-"))));
+ matches("int i; int j = -i;", UnaryOperator(HasOperatorName("-"))));
EXPECT_TRUE(
- Matches("int i; int j = ++i;", UnaryOperator(HasOperatorName("++"))));
+ matches("int i; int j = ++i;", UnaryOperator(HasOperatorName("++"))));
EXPECT_TRUE(
- Matches("int i; int j = i++;", UnaryOperator(HasOperatorName("++"))));
+ matches("int i; int j = i++;", UnaryOperator(HasOperatorName("++"))));
EXPECT_TRUE(
- Matches("int i; int j = --i;", UnaryOperator(HasOperatorName("--"))));
+ matches("int i; int j = --i;", UnaryOperator(HasOperatorName("--"))));
EXPECT_TRUE(
- Matches("int i; int j = i--;", UnaryOperator(HasOperatorName("--"))));
+ matches("int i; int j = i--;", UnaryOperator(HasOperatorName("--"))));
// We don't match conversion operators.
- EXPECT_TRUE(NotMatches("int i; double d = (double)i;", UnaryOperator()));
+ EXPECT_TRUE(notMatches("int i; double d = (double)i;", UnaryOperator()));
// Function calls are not represented as operator.
- EXPECT_TRUE(NotMatches("void f(); void x() { f(); }", UnaryOperator()));
+ EXPECT_TRUE(notMatches("void f(); void x() { f(); }", UnaryOperator()));
// Overloaded operators do not match at all.
// FIXME: We probably want to add that.
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"struct A { bool operator!() const { return false; } };"
"void x() { A a; !a; }", UnaryOperator(HasOperatorName("!"))));
}
@@ -1491,91 +1491,91 @@
HasCondition(BoolLiteral(Equals(true))),
HasTrueExpression(BoolLiteral(Equals(false))));
- EXPECT_TRUE(Matches("void x() { true ? false : true; }", Conditional));
- EXPECT_TRUE(NotMatches("void x() { false ? false : true; }", Conditional));
- EXPECT_TRUE(NotMatches("void x() { true ? true : false; }", Conditional));
+ EXPECT_TRUE(matches("void x() { true ? false : true; }", Conditional));
+ EXPECT_TRUE(notMatches("void x() { false ? false : true; }", Conditional));
+ EXPECT_TRUE(notMatches("void x() { true ? true : false; }", Conditional));
StatementMatcher ConditionalFalse = ConditionalOperator(
HasFalseExpression(BoolLiteral(Equals(false))));
- EXPECT_TRUE(Matches("void x() { true ? true : false; }", ConditionalFalse));
+ EXPECT_TRUE(matches("void x() { true ? true : false; }", ConditionalFalse));
EXPECT_TRUE(
- NotMatches("void x() { true ? false : true; }", ConditionalFalse));
+ notMatches("void x() { true ? false : true; }", ConditionalFalse));
}
TEST(Matcher, HasNameSupportsNamespaces) {
- EXPECT_TRUE(Matches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(matches("namespace a { namespace b { class C; } }",
Class(HasName("a::b::C"))));
- EXPECT_TRUE(Matches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(matches("namespace a { namespace b { class C; } }",
Class(HasName("::a::b::C"))));
- EXPECT_TRUE(Matches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(matches("namespace a { namespace b { class C; } }",
Class(HasName("b::C"))));
- EXPECT_TRUE(Matches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(matches("namespace a { namespace b { class C; } }",
Class(HasName("C"))));
- EXPECT_TRUE(NotMatches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
Class(HasName("c::b::C"))));
- EXPECT_TRUE(NotMatches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
Class(HasName("a::c::C"))));
- EXPECT_TRUE(NotMatches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
Class(HasName("a::b::A"))));
- EXPECT_TRUE(NotMatches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
Class(HasName("::C"))));
- EXPECT_TRUE(NotMatches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
Class(HasName("::b::C"))));
- EXPECT_TRUE(NotMatches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
Class(HasName("z::a::b::C"))));
- EXPECT_TRUE(NotMatches("namespace a { namespace b { class C; } }",
+ EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
Class(HasName("a+b::C"))));
- EXPECT_TRUE(NotMatches("namespace a { namespace b { class AC; } }",
+ EXPECT_TRUE(notMatches("namespace a { namespace b { class AC; } }",
Class(HasName("C"))));
}
TEST(Matcher, HasNameSupportsOuterClasses) {
EXPECT_TRUE(
- Matches("class A { class B { class C; }; };", Class(HasName("A::B::C"))));
+ matches("class A { class B { class C; }; };", Class(HasName("A::B::C"))));
EXPECT_TRUE(
- Matches("class A { class B { class C; }; };",
+ matches("class A { class B { class C; }; };",
Class(HasName("::A::B::C"))));
EXPECT_TRUE(
- Matches("class A { class B { class C; }; };", Class(HasName("B::C"))));
+ matches("class A { class B { class C; }; };", Class(HasName("B::C"))));
EXPECT_TRUE(
- Matches("class A { class B { class C; }; };", Class(HasName("C"))));
+ matches("class A { class B { class C; }; };", Class(HasName("C"))));
EXPECT_TRUE(
- NotMatches("class A { class B { class C; }; };",
+ notMatches("class A { class B { class C; }; };",
Class(HasName("c::B::C"))));
EXPECT_TRUE(
- NotMatches("class A { class B { class C; }; };",
+ notMatches("class A { class B { class C; }; };",
Class(HasName("A::c::C"))));
EXPECT_TRUE(
- NotMatches("class A { class B { class C; }; };",
+ notMatches("class A { class B { class C; }; };",
Class(HasName("A::B::A"))));
EXPECT_TRUE(
- NotMatches("class A { class B { class C; }; };", Class(HasName("::C"))));
+ notMatches("class A { class B { class C; }; };", Class(HasName("::C"))));
EXPECT_TRUE(
- NotMatches("class A { class B { class C; }; };",
+ notMatches("class A { class B { class C; }; };",
Class(HasName("::B::C"))));
- EXPECT_TRUE(NotMatches("class A { class B { class C; }; };",
+ EXPECT_TRUE(notMatches("class A { class B { class C; }; };",
Class(HasName("z::A::B::C"))));
EXPECT_TRUE(
- NotMatches("class A { class B { class C; }; };",
+ notMatches("class A { class B { class C; }; };",
Class(HasName("A+B::C"))));
}
TEST(Matcher, IsDefinition) {
DeclarationMatcher DefinitionOfClassA =
Class(HasName("A"), IsDefinition());
- EXPECT_TRUE(Matches("class A {};", DefinitionOfClassA));
- EXPECT_TRUE(NotMatches("class A;", DefinitionOfClassA));
+ EXPECT_TRUE(matches("class A {};", DefinitionOfClassA));
+ EXPECT_TRUE(notMatches("class A;", DefinitionOfClassA));
DeclarationMatcher DefinitionOfVariableA =
Variable(HasName("a"), IsDefinition());
- EXPECT_TRUE(Matches("int a;", DefinitionOfVariableA));
- EXPECT_TRUE(NotMatches("extern int a;", DefinitionOfVariableA));
+ EXPECT_TRUE(matches("int a;", DefinitionOfVariableA));
+ EXPECT_TRUE(notMatches("extern int a;", DefinitionOfVariableA));
DeclarationMatcher DefinitionOfMethodA =
Method(HasName("a"), IsDefinition());
- EXPECT_TRUE(Matches("class A { void a() {} };", DefinitionOfMethodA));
- EXPECT_TRUE(NotMatches("class A { void a(); };", DefinitionOfMethodA));
+ EXPECT_TRUE(matches("class A { void a() {} };", DefinitionOfMethodA));
+ EXPECT_TRUE(notMatches("class A { void a(); };", DefinitionOfMethodA));
}
TEST(Matcher, OfClass) {
@@ -1583,22 +1583,22 @@
OfClass(HasName("X")))));
EXPECT_TRUE(
- Matches("class X { public: X(); }; void x(int) { X x; }", Constructor));
+ matches("class X { public: X(); }; void x(int) { X x; }", Constructor));
EXPECT_TRUE(
- Matches("class X { public: X(); }; void x(int) { X x = X(); }",
+ matches("class X { public: X(); }; void x(int) { X x = X(); }",
Constructor));
EXPECT_TRUE(
- NotMatches("class Y { public: Y(); }; void x(int) { Y y; }",
+ notMatches("class Y { public: Y(); }; void x(int) { Y y; }",
Constructor));
}
TEST(Matcher, VisitsTemplateInstantiations) {
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class A { public: void x(); };"
"template <typename T> class B { public: void y() { T t; t.x(); } };"
"void f() { B<A> b; b.y(); }", Call(Callee(Method(HasName("x"))))));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class A { public: void x(); };"
"class C {"
" public:"
@@ -1607,26 +1607,26 @@
"void f() {"
" C::B<A> b; b.y();"
"}", Class(HasName("C"),
- HasDescendant(Call(Callee(Method(HasName("x"))))))));
+ hasDescendant(Call(Callee(Method(HasName("x"))))))));
}
// For testing AST_MATCHER_P().
AST_MATCHER_P(clang::Decl, Just, internal::Matcher<clang::Decl>, AMatcher) {
// Make sure all special variables are used: node, match_finder,
// bound_nodes_builder, and the parameter named 'AMatcher'.
- return AMatcher.Matches(Node, Finder, Builder);
+ return AMatcher.matches(Node, Finder, Builder);
}
TEST(AstMatcherPMacro, Works) {
- DeclarationMatcher HasClassB = Just(Has(Id("b", Class(HasName("B")))));
+ DeclarationMatcher HasClassB = Just(has(Id("b", Class(HasName("B")))));
- EXPECT_TRUE(MatchAndVerifyResultTrue("class A { class B {}; };",
+ EXPECT_TRUE(matchAndVerifyResultTrue("class A { class B {}; };",
HasClassB, new VerifyIdIsBoundToDecl<clang::Decl>("b")));
- EXPECT_TRUE(MatchAndVerifyResultFalse("class A { class B {}; };",
+ EXPECT_TRUE(matchAndVerifyResultFalse("class A { class B {}; };",
HasClassB, new VerifyIdIsBoundToDecl<clang::Decl>("a")));
- EXPECT_TRUE(MatchAndVerifyResultFalse("class A { class C {}; };",
+ EXPECT_TRUE(matchAndVerifyResultFalse("class A { class C {}; };",
HasClassB, new VerifyIdIsBoundToDecl<clang::Decl>("b")));
}
@@ -1636,7 +1636,7 @@
(llvm::is_same<NodeType, clang::Stmt>::value),
assert_node_type_is_accessible);
internal::TypedBaseMatcher<clang::Decl> ChildMatcher(AMatcher);
- return Finder->MatchesChildOf(
+ return Finder->matchesChildOf(
Node, ChildMatcher, Builder,
ASTMatchFinder::TK_IgnoreImplicitCastsAndParentheses,
ASTMatchFinder::BK_First);
@@ -1645,52 +1645,52 @@
TEST(AstPolymorphicMatcherPMacro, Works) {
DeclarationMatcher HasClassB = PolymorphicHas(Id("b", Class(HasName("B"))));
- EXPECT_TRUE(MatchAndVerifyResultTrue("class A { class B {}; };",
+ EXPECT_TRUE(matchAndVerifyResultTrue("class A { class B {}; };",
HasClassB, new VerifyIdIsBoundToDecl<clang::Decl>("b")));
- EXPECT_TRUE(MatchAndVerifyResultFalse("class A { class B {}; };",
+ EXPECT_TRUE(matchAndVerifyResultFalse("class A { class B {}; };",
HasClassB, new VerifyIdIsBoundToDecl<clang::Decl>("a")));
- EXPECT_TRUE(MatchAndVerifyResultFalse("class A { class C {}; };",
+ EXPECT_TRUE(matchAndVerifyResultFalse("class A { class C {}; };",
HasClassB, new VerifyIdIsBoundToDecl<clang::Decl>("b")));
StatementMatcher StatementHasClassB =
PolymorphicHas(Class(HasName("B")));
- EXPECT_TRUE(Matches("void x() { class B {}; }", StatementHasClassB));
+ EXPECT_TRUE(matches("void x() { class B {}; }", StatementHasClassB));
}
TEST(For, FindsForLoops) {
- EXPECT_TRUE(Matches("void f() { for(;;); }", For()));
- EXPECT_TRUE(Matches("void f() { if(true) for(;;); }", For()));
+ EXPECT_TRUE(matches("void f() { for(;;); }", For()));
+ EXPECT_TRUE(matches("void f() { if(true) for(;;); }", For()));
}
TEST(For, ReportsNoFalsePositives) {
- EXPECT_TRUE(NotMatches("void f() { ; }", For()));
- EXPECT_TRUE(NotMatches("void f() { if(true); }", For()));
+ EXPECT_TRUE(notMatches("void f() { ; }", For()));
+ EXPECT_TRUE(notMatches("void f() { if(true); }", For()));
}
TEST(CompoundStatement, HandlesSimpleCases) {
- EXPECT_TRUE(NotMatches("void f();", CompoundStatement()));
- EXPECT_TRUE(Matches("void f() {}", CompoundStatement()));
- EXPECT_TRUE(Matches("void f() {{}}", CompoundStatement()));
+ EXPECT_TRUE(notMatches("void f();", CompoundStatement()));
+ EXPECT_TRUE(matches("void f() {}", CompoundStatement()));
+ EXPECT_TRUE(matches("void f() {{}}", CompoundStatement()));
}
TEST(CompoundStatement, DoesNotMatchEmptyStruct) {
// It's not a compound statement just because there's "{}" in the source
// text. This is an AST search, not grep.
- EXPECT_TRUE(NotMatches("namespace n { struct S {}; }",
+ EXPECT_TRUE(notMatches("namespace n { struct S {}; }",
CompoundStatement()));
- EXPECT_TRUE(Matches("namespace n { struct S { void f() {{}} }; }",
+ EXPECT_TRUE(matches("namespace n { struct S { void f() {{}} }; }",
CompoundStatement()));
}
TEST(HasBody, FindsBodyOfForLoop) {
StatementMatcher HasCompoundStatementBody =
For(HasBody(CompoundStatement()));
- EXPECT_TRUE(Matches("void f() { for(;;) {} }",
+ EXPECT_TRUE(matches("void f() { for(;;) {} }",
HasCompoundStatementBody));
- EXPECT_TRUE(NotMatches("void f() { for(;;); }",
+ EXPECT_TRUE(notMatches("void f() { for(;;); }",
HasCompoundStatementBody));
}
@@ -1698,72 +1698,72 @@
// The simplest case: every compound statement is in a function
// definition, and the function body itself must be a compound
// statement.
- EXPECT_TRUE(Matches("void f() { for (;;); }",
+ EXPECT_TRUE(matches("void f() { for (;;); }",
CompoundStatement(HasAnySubstatement(For()))));
}
TEST(HasAnySubstatement, IsNotRecursive) {
// It's really "has any immediate substatement".
- EXPECT_TRUE(NotMatches("void f() { if (true) for (;;); }",
+ EXPECT_TRUE(notMatches("void f() { if (true) for (;;); }",
CompoundStatement(HasAnySubstatement(For()))));
}
TEST(HasAnySubstatement, MatchesInNestedCompoundStatements) {
- EXPECT_TRUE(Matches("void f() { if (true) { for (;;); } }",
+ EXPECT_TRUE(matches("void f() { if (true) { for (;;); } }",
CompoundStatement(HasAnySubstatement(For()))));
}
TEST(HasAnySubstatement, FindsSubstatementBetweenOthers) {
- EXPECT_TRUE(Matches("void f() { 1; 2; 3; for (;;); 4; 5; 6; }",
+ EXPECT_TRUE(matches("void f() { 1; 2; 3; for (;;); 4; 5; 6; }",
CompoundStatement(HasAnySubstatement(For()))));
}
TEST(StatementCountIs, FindsNoStatementsInAnEmptyCompoundStatement) {
- EXPECT_TRUE(Matches("void f() { }",
+ EXPECT_TRUE(matches("void f() { }",
CompoundStatement(StatementCountIs(0))));
- EXPECT_TRUE(NotMatches("void f() {}",
+ EXPECT_TRUE(notMatches("void f() {}",
CompoundStatement(StatementCountIs(1))));
}
TEST(StatementCountIs, AppearsToMatchOnlyOneCount) {
- EXPECT_TRUE(Matches("void f() { 1; }",
+ EXPECT_TRUE(matches("void f() { 1; }",
CompoundStatement(StatementCountIs(1))));
- EXPECT_TRUE(NotMatches("void f() { 1; }",
+ EXPECT_TRUE(notMatches("void f() { 1; }",
CompoundStatement(StatementCountIs(0))));
- EXPECT_TRUE(NotMatches("void f() { 1; }",
+ EXPECT_TRUE(notMatches("void f() { 1; }",
CompoundStatement(StatementCountIs(2))));
}
TEST(StatementCountIs, WorksWithMultipleStatements) {
- EXPECT_TRUE(Matches("void f() { 1; 2; 3; }",
+ EXPECT_TRUE(matches("void f() { 1; 2; 3; }",
CompoundStatement(StatementCountIs(3))));
}
TEST(StatementCountIs, WorksWithNestedCompoundStatements) {
- EXPECT_TRUE(Matches("void f() { { 1; } { 1; 2; 3; 4; } }",
+ EXPECT_TRUE(matches("void f() { { 1; } { 1; 2; 3; 4; } }",
CompoundStatement(StatementCountIs(1))));
- EXPECT_TRUE(Matches("void f() { { 1; } { 1; 2; 3; 4; } }",
+ EXPECT_TRUE(matches("void f() { { 1; } { 1; 2; 3; 4; } }",
CompoundStatement(StatementCountIs(2))));
- EXPECT_TRUE(NotMatches("void f() { { 1; } { 1; 2; 3; 4; } }",
+ EXPECT_TRUE(notMatches("void f() { { 1; } { 1; 2; 3; 4; } }",
CompoundStatement(StatementCountIs(3))));
- EXPECT_TRUE(Matches("void f() { { 1; } { 1; 2; 3; 4; } }",
+ EXPECT_TRUE(matches("void f() { { 1; } { 1; 2; 3; 4; } }",
CompoundStatement(StatementCountIs(4))));
}
TEST(Member, WorksInSimplestCase) {
- EXPECT_TRUE(Matches("struct { int first; } s; int i(s.first);",
+ EXPECT_TRUE(matches("struct { int first; } s; int i(s.first);",
MemberExpression(Member(HasName("first")))));
}
TEST(Member, DoesNotMatchTheBaseExpression) {
// Don't pick out the wrong part of the member expression, this should
// be checking the member (name) only.
- EXPECT_TRUE(NotMatches("struct { int i; } first; int i(first.i);",
+ EXPECT_TRUE(notMatches("struct { int i; } first; int i(first.i);",
MemberExpression(Member(HasName("first")))));
}
TEST(Member, MatchesInMemberFunctionCall) {
- EXPECT_TRUE(Matches("void f() {"
+ EXPECT_TRUE(matches("void f() {"
" struct { void first() {}; } s;"
" s.first();"
"};",
@@ -1771,16 +1771,16 @@
}
TEST(HasObjectExpression, DoesNotMatchMember) {
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"class X {}; struct Z { X m; }; void f(Z z) { z.m; }",
MemberExpression(HasObjectExpression(HasType(Class(HasName("X")))))));
}
TEST(HasObjectExpression, MatchesBaseOfVariable) {
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"struct X { int m; }; void f(X x) { x.m; }",
MemberExpression(HasObjectExpression(HasType(Class(HasName("X")))))));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"struct X { int m; }; void f(X* x) { x->m; }",
MemberExpression(HasObjectExpression(
HasType(PointsTo(Class(HasName("X"))))))));
@@ -1788,64 +1788,64 @@
TEST(HasObjectExpression,
MatchesObjectExpressionOfImplicitlyFormedMemberExpression) {
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class X {}; struct S { X m; void f() { this->m; } };",
MemberExpression(HasObjectExpression(
HasType(PointsTo(Class(HasName("S"))))))));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class X {}; struct S { X m; void f() { m; } };",
MemberExpression(HasObjectExpression(
HasType(PointsTo(Class(HasName("S"))))))));
}
TEST(Field, DoesNotMatchNonFieldMembers) {
- EXPECT_TRUE(NotMatches("class X { void m(); };", Field(HasName("m"))));
- EXPECT_TRUE(NotMatches("class X { class m {}; };", Field(HasName("m"))));
- EXPECT_TRUE(NotMatches("class X { enum { m }; };", Field(HasName("m"))));
- EXPECT_TRUE(NotMatches("class X { enum m {}; };", Field(HasName("m"))));
+ EXPECT_TRUE(notMatches("class X { void m(); };", Field(HasName("m"))));
+ EXPECT_TRUE(notMatches("class X { class m {}; };", Field(HasName("m"))));
+ EXPECT_TRUE(notMatches("class X { enum { m }; };", Field(HasName("m"))));
+ EXPECT_TRUE(notMatches("class X { enum m {}; };", Field(HasName("m"))));
}
TEST(Field, MatchesField) {
- EXPECT_TRUE(Matches("class X { int m; };", Field(HasName("m"))));
+ EXPECT_TRUE(matches("class X { int m; };", Field(HasName("m"))));
}
TEST(IsConstQualified, MatchesConstInt) {
- EXPECT_TRUE(Matches("const int i = 42;",
+ EXPECT_TRUE(matches("const int i = 42;",
Variable(HasType(IsConstQualified()))));
}
TEST(IsConstQualified, MatchesConstPointer) {
- EXPECT_TRUE(Matches("int i = 42; int* const p(&i);",
+ EXPECT_TRUE(matches("int i = 42; int* const p(&i);",
Variable(HasType(IsConstQualified()))));
}
TEST(IsConstQualified, MatchesThroughTypedef) {
- EXPECT_TRUE(Matches("typedef const int const_int; const_int i = 42;",
+ EXPECT_TRUE(matches("typedef const int const_int; const_int i = 42;",
Variable(HasType(IsConstQualified()))));
- EXPECT_TRUE(Matches("typedef int* int_ptr; const int_ptr p(0);",
+ EXPECT_TRUE(matches("typedef int* int_ptr; const int_ptr p(0);",
Variable(HasType(IsConstQualified()))));
}
TEST(IsConstQualified, DoesNotMatchInappropriately) {
- EXPECT_TRUE(NotMatches("typedef int nonconst_int; nonconst_int i = 42;",
+ EXPECT_TRUE(notMatches("typedef int nonconst_int; nonconst_int i = 42;",
Variable(HasType(IsConstQualified()))));
- EXPECT_TRUE(NotMatches("int const* p;",
+ EXPECT_TRUE(notMatches("int const* p;",
Variable(HasType(IsConstQualified()))));
}
TEST(ReinterpretCast, MatchesSimpleCase) {
- EXPECT_TRUE(Matches("char* p = reinterpret_cast<char*>(&p);",
+ EXPECT_TRUE(matches("char* p = reinterpret_cast<char*>(&p);",
Expression(ReinterpretCast())));
}
TEST(ReinterpretCast, DoesNotMatchOtherCasts) {
- EXPECT_TRUE(NotMatches("char* p = (char*)(&p);",
+ EXPECT_TRUE(notMatches("char* p = (char*)(&p);",
Expression(ReinterpretCast())));
- EXPECT_TRUE(NotMatches("char q, *p = const_cast<char*>(&q);",
+ EXPECT_TRUE(notMatches("char q, *p = const_cast<char*>(&q);",
Expression(ReinterpretCast())));
- EXPECT_TRUE(NotMatches("void* p = static_cast<void*>(&p);",
+ EXPECT_TRUE(notMatches("void* p = static_cast<void*>(&p);",
Expression(ReinterpretCast())));
- EXPECT_TRUE(NotMatches("struct B { virtual ~B() {} }; struct D : B {};"
+ EXPECT_TRUE(notMatches("struct B { virtual ~B() {} }; struct D : B {};"
"B b;"
"D* p = dynamic_cast<D*>(&b);",
Expression(ReinterpretCast())));
@@ -1853,151 +1853,151 @@
TEST(FunctionalCast, MatchesSimpleCase) {
std::string foo_class = "class Foo { public: Foo(char*); };";
- EXPECT_TRUE(Matches(foo_class + "void r() { Foo f = Foo(\"hello world\"); }",
+ EXPECT_TRUE(matches(foo_class + "void r() { Foo f = Foo(\"hello world\"); }",
Expression(FunctionalCast())));
}
TEST(FunctionalCast, DoesNotMatchOtherCasts) {
std::string FooClass = "class Foo { public: Foo(char*); };";
EXPECT_TRUE(
- NotMatches(FooClass + "void r() { Foo f = (Foo) \"hello world\"; }",
+ notMatches(FooClass + "void r() { Foo f = (Foo) \"hello world\"; }",
Expression(FunctionalCast())));
EXPECT_TRUE(
- NotMatches(FooClass + "void r() { Foo f = \"hello world\"; }",
+ notMatches(FooClass + "void r() { Foo f = \"hello world\"; }",
Expression(FunctionalCast())));
}
TEST(DynamicCast, MatchesSimpleCase) {
- EXPECT_TRUE(Matches("struct B { virtual ~B() {} }; struct D : B {};"
+ EXPECT_TRUE(matches("struct B { virtual ~B() {} }; struct D : B {};"
"B b;"
"D* p = dynamic_cast<D*>(&b);",
Expression(DynamicCast())));
}
TEST(StaticCast, MatchesSimpleCase) {
- EXPECT_TRUE(Matches("void* p(static_cast<void*>(&p));",
+ EXPECT_TRUE(matches("void* p(static_cast<void*>(&p));",
Expression(StaticCast())));
}
TEST(StaticCast, DoesNotMatchOtherCasts) {
- EXPECT_TRUE(NotMatches("char* p = (char*)(&p);",
+ EXPECT_TRUE(notMatches("char* p = (char*)(&p);",
Expression(StaticCast())));
- EXPECT_TRUE(NotMatches("char q, *p = const_cast<char*>(&q);",
+ EXPECT_TRUE(notMatches("char q, *p = const_cast<char*>(&q);",
Expression(StaticCast())));
- EXPECT_TRUE(NotMatches("void* p = reinterpret_cast<char*>(&p);",
+ EXPECT_TRUE(notMatches("void* p = reinterpret_cast<char*>(&p);",
Expression(StaticCast())));
- EXPECT_TRUE(NotMatches("struct B { virtual ~B() {} }; struct D : B {};"
+ EXPECT_TRUE(notMatches("struct B { virtual ~B() {} }; struct D : B {};"
"B b;"
"D* p = dynamic_cast<D*>(&b);",
Expression(StaticCast())));
}
TEST(HasDestinationType, MatchesSimpleCase) {
- EXPECT_TRUE(Matches("char* p = static_cast<char*>(0);",
+ EXPECT_TRUE(matches("char* p = static_cast<char*>(0);",
Expression(
StaticCast(HasDestinationType(
PointsTo(TypeMatcher(True())))))));
}
TEST(HasSourceExpression, MatchesSimpleCase) {
- EXPECT_TRUE(Matches("class string {}; class URL { public: URL(string s); };"
+ EXPECT_TRUE(matches("class string {}; class URL { public: URL(string s); };"
"void r() {string a_string; URL url = a_string; }",
Expression(ImplicitCast(
HasSourceExpression(ConstructorCall())))));
}
TEST(Statement, DoesNotMatchDeclarations) {
- EXPECT_TRUE(NotMatches("class X {};", Statement()));
+ EXPECT_TRUE(notMatches("class X {};", Statement()));
}
TEST(Statement, MatchesCompoundStatments) {
- EXPECT_TRUE(Matches("void x() {}", Statement()));
+ EXPECT_TRUE(matches("void x() {}", Statement()));
}
TEST(DeclarationStatement, DoesNotMatchCompoundStatements) {
- EXPECT_TRUE(NotMatches("void x() {}", DeclarationStatement()));
+ EXPECT_TRUE(notMatches("void x() {}", DeclarationStatement()));
}
TEST(DeclarationStatement, MatchesVariableDeclarationStatements) {
- EXPECT_TRUE(Matches("void x() { int a; }", DeclarationStatement()));
+ EXPECT_TRUE(matches("void x() { int a; }", DeclarationStatement()));
}
TEST(While, MatchesWhileLoops) {
- EXPECT_TRUE(NotMatches("void x() {}", While()));
- EXPECT_TRUE(Matches("void x() { while(true); }", While()));
- EXPECT_TRUE(NotMatches("void x() { do {} while(true); }", While()));
+ EXPECT_TRUE(notMatches("void x() {}", While()));
+ EXPECT_TRUE(matches("void x() { while(true); }", While()));
+ EXPECT_TRUE(notMatches("void x() { do {} while(true); }", While()));
}
TEST(Do, MatchesDoLoops) {
- EXPECT_TRUE(Matches("void x() { do {} while(true); }", Do()));
- EXPECT_TRUE(Matches("void x() { do ; while(false); }", Do()));
+ EXPECT_TRUE(matches("void x() { do {} while(true); }", Do()));
+ EXPECT_TRUE(matches("void x() { do ; while(false); }", Do()));
}
TEST(Do, DoesNotMatchWhileLoops) {
- EXPECT_TRUE(NotMatches("void x() { while(true) {} }", Do()));
+ EXPECT_TRUE(notMatches("void x() { while(true) {} }", Do()));
}
TEST(SwitchCase, MatchesCase) {
- EXPECT_TRUE(Matches("void x() { switch(42) { case 42:; } }", SwitchCase()));
- EXPECT_TRUE(Matches("void x() { switch(42) { default:; } }", SwitchCase()));
- EXPECT_TRUE(Matches("void x() { switch(42) default:; }", SwitchCase()));
- EXPECT_TRUE(NotMatches("void x() { switch(42) {} }", SwitchCase()));
+ EXPECT_TRUE(matches("void x() { switch(42) { case 42:; } }", SwitchCase()));
+ EXPECT_TRUE(matches("void x() { switch(42) { default:; } }", SwitchCase()));
+ EXPECT_TRUE(matches("void x() { switch(42) default:; }", SwitchCase()));
+ EXPECT_TRUE(notMatches("void x() { switch(42) {} }", SwitchCase()));
}
TEST(HasConditionVariableStatement, DoesNotMatchCondition) {
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"void x() { if(true) {} }",
If(HasConditionVariableStatement(DeclarationStatement()))));
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"void x() { int x; if((x = 42)) {} }",
If(HasConditionVariableStatement(DeclarationStatement()))));
}
TEST(HasConditionVariableStatement, MatchesConditionVariables) {
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"void x() { if(int* a = 0) {} }",
If(HasConditionVariableStatement(DeclarationStatement()))));
}
TEST(ForEach, BindsOneNode) {
- EXPECT_TRUE(MatchAndVerifyResultTrue("class C { int x; };",
- Class(HasName("C"), ForEach(Id("x", Field(HasName("x"))))),
+ EXPECT_TRUE(matchAndVerifyResultTrue("class C { int x; };",
+ Class(HasName("C"), forEach(Id("x", Field(HasName("x"))))),
new VerifyIdIsBoundToDecl<clang::FieldDecl>("x", 1)));
}
TEST(ForEach, BindsMultipleNodes) {
- EXPECT_TRUE(MatchAndVerifyResultTrue("class C { int x; int y; int z; };",
- Class(HasName("C"), ForEach(Id("f", Field()))),
+ EXPECT_TRUE(matchAndVerifyResultTrue("class C { int x; int y; int z; };",
+ Class(HasName("C"), forEach(Id("f", Field()))),
new VerifyIdIsBoundToDecl<clang::FieldDecl>("f", 3)));
}
TEST(ForEach, BindsRecursiveCombinations) {
- EXPECT_TRUE(MatchAndVerifyResultTrue(
+ EXPECT_TRUE(matchAndVerifyResultTrue(
"class C { class D { int x; int y; }; class E { int y; int z; }; };",
- Class(HasName("C"), ForEach(Class(ForEach(Id("f", Field()))))),
+ Class(HasName("C"), forEach(Class(forEach(Id("f", Field()))))),
new VerifyIdIsBoundToDecl<clang::FieldDecl>("f", 4)));
}
TEST(ForEachDescendant, BindsOneNode) {
- EXPECT_TRUE(MatchAndVerifyResultTrue("class C { class D { int x; }; };",
- Class(HasName("C"), ForEachDescendant(Id("x", Field(HasName("x"))))),
+ EXPECT_TRUE(matchAndVerifyResultTrue("class C { class D { int x; }; };",
+ Class(HasName("C"), forEachDescendant(Id("x", Field(HasName("x"))))),
new VerifyIdIsBoundToDecl<clang::FieldDecl>("x", 1)));
}
TEST(ForEachDescendant, BindsMultipleNodes) {
- EXPECT_TRUE(MatchAndVerifyResultTrue(
+ EXPECT_TRUE(matchAndVerifyResultTrue(
"class C { class D { int x; int y; }; "
" class E { class F { int y; int z; }; }; };",
- Class(HasName("C"), ForEachDescendant(Id("f", Field()))),
+ Class(HasName("C"), forEachDescendant(Id("f", Field()))),
new VerifyIdIsBoundToDecl<clang::FieldDecl>("f", 4)));
}
TEST(ForEachDescendant, BindsRecursiveCombinations) {
- EXPECT_TRUE(MatchAndVerifyResultTrue(
+ EXPECT_TRUE(matchAndVerifyResultTrue(
"class C { class D { "
" class E { class F { class G { int y; int z; }; }; }; }; };",
- Class(HasName("C"), ForEachDescendant(Class(
- ForEachDescendant(Id("f", Field()))))),
+ Class(HasName("C"), forEachDescendant(Class(
+ forEachDescendant(Id("f", Field()))))),
new VerifyIdIsBoundToDecl<clang::FieldDecl>("f", 8)));
}
@@ -2006,34 +2006,34 @@
// Make sure that we can both match the class by name (::X) and by the type
// the template was instantiated with (via a field).
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"template <typename T> class X {}; class A {}; X<A> x;",
Class(HasName("::X"), IsTemplateInstantiation())));
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"template <typename T> class X { T t; }; class A {}; X<A> x;",
- Class(IsTemplateInstantiation(), HasDescendant(
+ Class(IsTemplateInstantiation(), hasDescendant(
Field(HasType(Class(HasName("A"))))))));
}
TEST(IsTemplateInstantiation, MatchesImplicitFunctionTemplateInstantiation) {
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"template <typename T> void f(T t) {} class A {}; void g() { f(A()); }",
Function(HasParameter(0, HasType(Class(HasName("A")))),
IsTemplateInstantiation())));
}
TEST(IsTemplateInstantiation, MatchesExplicitClassTemplateInstantiation) {
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"template <typename T> class X { T t; }; class A {};"
"template class X<A>;",
- Class(IsTemplateInstantiation(), HasDescendant(
+ Class(IsTemplateInstantiation(), hasDescendant(
Field(HasType(Class(HasName("A"))))))));
}
TEST(IsTemplateInstantiation,
MatchesInstantiationOfPartiallySpecializedClassTemplate) {
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"template <typename T> class X {};"
"template <typename T> class X<T*> {}; class A {}; X<A*> x;",
Class(HasName("::X"), IsTemplateInstantiation())));
@@ -2041,7 +2041,7 @@
TEST(IsTemplateInstantiation,
MatchesInstantiationOfClassTemplateNestedInNonTemplate) {
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class A {};"
"class X {"
" template <typename U> class Y { U u; };"
@@ -2054,7 +2054,7 @@
// FIXME: Figure out whether this makes sense. It doesn't affect the
// normal use case as long as the uppermost instantiation always is marked
// as template instantiation, but it might be confusing as a predicate.
- EXPECT_TRUE(Matches(
+ EXPECT_TRUE(matches(
"class A {};"
"template <typename T> class X {"
" template <typename U> class Y { U u; };"
@@ -2064,14 +2064,14 @@
}
TEST(IsTemplateInstantiation, DoesNotMatchExplicitClassTemplateSpecialization) {
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"template <typename T> class X {}; class A {};"
"template <> class X<A> {}; X<A> x;",
Class(HasName("::X"), IsTemplateInstantiation())));
}
TEST(IsTemplateInstantiation, DoesNotMatchNonTemplate) {
- EXPECT_TRUE(NotMatches(
+ EXPECT_TRUE(notMatches(
"class A {}; class Y { A a; };",
Class(IsTemplateInstantiation())));
}
More information about the llvm-branch-commits
mailing list