[llvm-branch-commits] [cfe-branch] r159551 - in /cfe/branches/tooling: examples/rename-method/RenameMethod.cpp include/clang/ASTMatchers/ASTMatchers.h lib/ASTMatchers/Dynamic/Registry.cpp tools/fix-llvm-style/FixLLVMStyle.cpp tools/remove-cstr-calls/RemoveCStrCalls.cpp unittests/ASTMatchers/ASTMatchersTest.cpp unittests/ASTMatchers/Dynamic/GenericMatcherTest.cpp unittests/ASTMatchers/Dynamic/GenericValueTest.cpp unittests/ASTMatchers/Dynamic/ParserTest.cpp unittests/ASTMatchers/Dynamic/RegistryTest.cpp
Manuel Klimek
klimek at google.com
Mon Jul 2 12:22:35 PDT 2012
Author: klimek
Date: Mon Jul 2 14:22:34 2012
New Revision: 159551
URL: http://llvm.org/viewvc/llvm-project?rev=159551&view=rev
Log:
The fix-style tool now supports seeing calls to variables of a type that
inherits VariadicFunctions as function style.
Fixed the dynamic matchers manually.
Modified:
cfe/branches/tooling/examples/rename-method/RenameMethod.cpp
cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchers.h
cfe/branches/tooling/lib/ASTMatchers/Dynamic/Registry.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
cfe/branches/tooling/unittests/ASTMatchers/Dynamic/GenericMatcherTest.cpp
cfe/branches/tooling/unittests/ASTMatchers/Dynamic/GenericValueTest.cpp
cfe/branches/tooling/unittests/ASTMatchers/Dynamic/ParserTest.cpp
cfe/branches/tooling/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
Modified: cfe/branches/tooling/examples/rename-method/RenameMethod.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/examples/rename-method/RenameMethod.cpp?rev=159551&r1=159550&r2=159551&view=diff
==============================================================================
--- cfe/branches/tooling/examples/rename-method/RenameMethod.cpp (original)
+++ cfe/branches/tooling/examples/rename-method/RenameMethod.cpp Mon Jul 2 14:22:34 2012
@@ -122,22 +122,22 @@
CallRenamer CallCallback(&Tool.getReplacements());
Finder.addMatcher(
// Match calls...
- Call(
+ call(
// Where the callee is a method called "Get"...
- callee(Method(hasName("Get"))),
+ callee(method(hasName("Get"))),
// ... and the class on which the method is called is derived
// from ElementsBase ...
- thisPointerType(Class(
+ thisPointerType(record(
isDerivedFrom("ElementsBase"))),
// ... and bind the member expression to the ID "member", under which
// it can later be found in the callback.
- callee(id("member", MemberExpression()))),
+ callee(id("member", memberExpression()))),
&CallCallback);
DeclRenamer DeclCallback(&Tool.getReplacements());
Finder.addMatcher(
// Match declarations...
- id("method", Method(hasName("Get"),
+ id("method", method(hasName("Get"),
ofClass(isDerivedFrom("ElementsBase")))),
&DeclCallback);
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=159551&r1=159550&r2=159551&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/branches/tooling/include/clang/ASTMatchers/ASTMatchers.h Mon Jul 2 14:22:34 2012
@@ -139,7 +139,7 @@
/// };
const internal::VariadicDynCastAllOfMatcher<
clang::Decl,
- clang::NamedDecl> NameableDeclaration;
+ clang::NamedDecl> nameableDeclaration;
/// \brief Matches C++ class declarations.
///
@@ -148,7 +148,7 @@
/// template<class T> class Z {};
const internal::VariadicDynCastAllOfMatcher<
clang::Decl,
- clang::CXXRecordDecl> Class;
+ clang::CXXRecordDecl> record;
/// \brief Matches C++ constructor declarations.
///
@@ -161,7 +161,7 @@
/// };
const internal::VariadicDynCastAllOfMatcher<
clang::Decl,
- clang::CXXConstructorDecl> Constructor;
+ clang::CXXConstructorDecl> constructor;
/// \brief Matches method declarations.
///
@@ -169,7 +169,7 @@
/// class X { void y() };
const internal::VariadicDynCastAllOfMatcher<
clang::Decl,
- clang::CXXMethodDecl> Method;
+ clang::CXXMethodDecl> method;
/// \brief Matches variable declarations.
///
@@ -180,7 +180,7 @@
/// int a;
const internal::VariadicDynCastAllOfMatcher<
clang::Decl,
- clang::VarDecl> Variable;
+ clang::VarDecl> variable;
/// \brief Matches field declarations.
///
@@ -190,7 +190,7 @@
/// matches 'm'.
const internal::VariadicDynCastAllOfMatcher<
clang::Decl,
- clang::FieldDecl> Field;
+ clang::FieldDecl> field;
/// \brief Matches function declarations.
///
@@ -198,7 +198,7 @@
/// void f();
const internal::VariadicDynCastAllOfMatcher<
clang::Decl,
- clang::FunctionDecl> Function;
+ clang::FunctionDecl> function;
/// \brief Matches statements.
@@ -207,7 +207,7 @@
/// { ++a; }
/// Statement()
/// matches both the compound statement '{ ++a; }' and '++a'.
-const internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::Stmt> Statement;
+const internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::Stmt> statement;
/// \brief Matches declaration statements.
///
@@ -217,7 +217,7 @@
/// matches 'int a'.
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::DeclStmt> DeclarationStatement;
+ clang::DeclStmt> declarationStatement;
/// \brief Matches member expressions.
///
@@ -230,14 +230,14 @@
/// matches this->x, x, y.x, a, this->b
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::MemberExpr> MemberExpression;
+ clang::MemberExpr> memberExpression;
/// \brief Matches call expressions.
///
/// Example matches x.y()
/// X x;
/// x.y();
-const internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::CallExpr> Call;
+const internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::CallExpr> call;
/// \brief Matches constructor call expressions (including implicit ones).
///
@@ -249,7 +249,7 @@
/// f(string(ptr, n), ptr);
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::CXXConstructExpr> ConstructorCall;
+ clang::CXXConstructExpr> constructorCall;
/// \brief Matches nodes where temporaries are created.
///
@@ -259,7 +259,7 @@
/// FunctionTakesStringByPointer(GetStringPointer());
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::CXXBindTemporaryExpr> BindTemporaryExpression;
+ clang::CXXBindTemporaryExpr> bindTemporaryExpression;
/// \brief Matches new expressions.
///
@@ -269,7 +269,7 @@
/// matches 'new X'.
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::CXXNewExpr> NewExpression;
+ clang::CXXNewExpr> newExpression;
/// \brief Matches the value of a default argument at the call site.
///
@@ -280,7 +280,7 @@
/// f(42);
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::CXXDefaultArgExpr> DefaultArgument;
+ clang::CXXDefaultArgExpr> defaultArgument;
/// \brief Matches overloaded operator calls.
///
@@ -296,7 +296,7 @@
/// o << b << c;
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::CXXOperatorCallExpr> OverloadedOperatorCall;
+ clang::CXXOperatorCallExpr> overloadedOperatorCall;
/// \brief Matches expressions.
///
@@ -304,7 +304,7 @@
/// void f() { x(); }
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::Expr> Expression;
+ clang::Expr> expression;
/// \brief Matches expressions that refer to declarations.
///
@@ -313,19 +313,19 @@
/// if (x) {}
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::DeclRefExpr> DeclarationReference;
+ clang::DeclRefExpr> declarationReference;
/// \brief Matches if statements.
///
/// Example matches 'if (x) {}'
/// if (x) {}
-const internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::IfStmt> If;
+const internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::IfStmt> ifStmt;
/// \brief Matches for statements.
///
/// Example matches 'for (;;) {}'
/// for (;;) {}
-const internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::ForStmt> For;
+const internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::ForStmt> forStmt;
/// \brief Matches while statements.
///
@@ -335,7 +335,7 @@
/// matches 'while (true) {}'.
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::WhileStmt> While;
+ clang::WhileStmt> whileStmt;
/// \brief Matches do statements.
///
@@ -343,7 +343,7 @@
/// do {} while (true);
/// Do()
/// matches 'do {} while(true)'
-const internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::DoStmt> Do;
+const internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::DoStmt> doStmt;
/// \brief Matches case and default statements inside switch statements.
///
@@ -353,7 +353,7 @@
/// matches 'case 42: break;' and 'default: break;'.
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::SwitchCase> SwitchCase;
+ clang::SwitchCase> switchCase;
/// \brief Matches compound statements.
///
@@ -361,7 +361,7 @@
/// for (;;) {{}}
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::CompoundStmt> CompoundStatement;
+ clang::CompoundStmt> compoundStatement;
/// \brief Matches bool literals.
///
@@ -369,7 +369,7 @@
/// true
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::CXXBoolLiteralExpr> BoolLiteral;
+ clang::CXXBoolLiteralExpr> boolLiteral;
/// \brief Matches string literals (also matches wide string literals).
///
@@ -377,7 +377,7 @@
/// char *s = "abcd"; wchar_t *ws = L"abcd"
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::StringLiteral> StringLiteral;
+ clang::StringLiteral> stringLiteral;
/// \brief Matches character literals (also matches wchar_t).
///
@@ -388,7 +388,7 @@
/// char ch = 'a'; wchar_t chw = L'a';
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::CharacterLiteral> CharacterLiteral;
+ clang::CharacterLiteral> characterLiteral;
/// \brief Matches integer literals of all sizes / encodings.
///
@@ -397,7 +397,7 @@
/// Example matches 1, 1L, 0x1, 1U
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::IntegerLiteral> IntegerLiteral;
+ clang::IntegerLiteral> integerLiteral;
/// \brief Matches binary operator expressions.
///
@@ -405,7 +405,7 @@
/// !(a || b)
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::BinaryOperator> BinaryOperator;
+ clang::BinaryOperator> binaryOperator;
/// \brief Matches unary operator expressions.
///
@@ -413,7 +413,7 @@
/// !a || b
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::UnaryOperator> UnaryOperator;
+ clang::UnaryOperator> unaryOperator;
/// \brief Matches conditional operator expressions.
///
@@ -421,7 +421,7 @@
/// (a ? b : c) + 42
const internal::VariadicDynCastAllOfMatcher<
clang::Stmt,
- clang::ConditionalOperator> ConditionalOperator;
+ clang::ConditionalOperator> conditionalOperator;
/// \brief Matches a reinterpret_cast expression.
///
@@ -433,7 +433,7 @@
/// void* p = reinterpret_cast<char*>(&p);
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::CXXReinterpretCastExpr> ReinterpretCast;
+ clang::CXXReinterpretCastExpr> reinterpretCast;
/// \brief Matches a C++ static_cast expression.
///
@@ -448,7 +448,7 @@
/// long eight(static_cast<long>(8));
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::CXXStaticCastExpr> StaticCast;
+ clang::CXXStaticCastExpr> staticCast;
/// \brief Matches a dynamic_cast expression.
///
@@ -462,7 +462,7 @@
/// D* p = dynamic_cast<D*>(&b);
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::CXXDynamicCastExpr> DynamicCast;
+ clang::CXXDynamicCastExpr> dynamicCast;
/// \brief Matches a const_cast expression.
///
@@ -472,7 +472,7 @@
/// int* p = const_cast<int*>(&r);
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::CXXConstCastExpr> ConstCast;
+ clang::CXXConstCastExpr> constCast;
/// \brief Matches explicit cast expressions.
///
@@ -493,7 +493,7 @@
/// long ell = 42;
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::ExplicitCastExpr> ExplicitCast;
+ clang::ExplicitCastExpr> explicitCast;
/// \brief Matches the implicit cast nodes of Clang's AST.
///
@@ -501,7 +501,7 @@
/// eliding, as well as any type conversions.
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::ImplicitCastExpr> ImplicitCast;
+ clang::ImplicitCastExpr> implicitCast;
/// \brief Matches functional cast expressions
///
@@ -511,7 +511,7 @@
/// Foo h = Foo(bar);
const internal::VariadicDynCastAllOfMatcher<
clang::Expr,
- clang::CXXFunctionalCastExpr> FunctionalCast;
+ clang::CXXFunctionalCastExpr> functionalCast;
/// \brief Various overloads for the AnyOf matcher.
/// @{
Modified: cfe/branches/tooling/lib/ASTMatchers/Dynamic/Registry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/ASTMatchers/Dynamic/Registry.cpp?rev=159551&r1=159550&r2=159551&view=diff
==============================================================================
--- cfe/branches/tooling/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/branches/tooling/lib/ASTMatchers/Dynamic/Registry.cpp Mon Jul 2 14:22:34 2012
@@ -144,29 +144,29 @@
RegistryMaps* registerMatchers() {
RegistryMaps* Data = new RegistryMaps();
- REGISTER_MATCHER_AUTO(BinaryOperator);
- REGISTER_MATCHER_AUTO(BindTemporaryExpression);
- REGISTER_MATCHER_AUTO(BoolLiteral);
- REGISTER_MATCHER_AUTO(Call);
- REGISTER_MATCHER_AUTO(CharacterLiteral);
- REGISTER_MATCHER_AUTO(Class);
- REGISTER_MATCHER_AUTO(CompoundStatement);
- REGISTER_MATCHER_AUTO(ConditionalOperator);
- REGISTER_MATCHER_AUTO(ConstCast);
- REGISTER_MATCHER_AUTO(Constructor);
- REGISTER_MATCHER_AUTO(ConstructorCall);
- REGISTER_MATCHER_AUTO(DeclarationReference);
- REGISTER_MATCHER_AUTO(DeclarationStatement);
- REGISTER_MATCHER_AUTO(DefaultArgument);
- REGISTER_MATCHER_AUTO(Do);
- REGISTER_MATCHER_AUTO(DynamicCast);
- REGISTER_MATCHER_AUTO(ExplicitCast);
- REGISTER_MATCHER_AUTO(Expression);
- REGISTER_MATCHER_AUTO(Field);
- REGISTER_MATCHER_AUTO(For);
+ REGISTER_MATCHER_AUTO(binaryOperator);
+ REGISTER_MATCHER_AUTO(bindTemporaryExpression);
+ REGISTER_MATCHER_AUTO(boolLiteral);
+ REGISTER_MATCHER_AUTO(call);
+ REGISTER_MATCHER_AUTO(characterLiteral);
+ REGISTER_MATCHER_AUTO(record);
+ REGISTER_MATCHER_AUTO(compoundStatement);
+ REGISTER_MATCHER_AUTO(conditionalOperator);
+ REGISTER_MATCHER_AUTO(constCast);
+ REGISTER_MATCHER_AUTO(constructor);
+ REGISTER_MATCHER_AUTO(constructorCall);
+ REGISTER_MATCHER_AUTO(declarationReference);
+ REGISTER_MATCHER_AUTO(declarationStatement);
+ REGISTER_MATCHER_AUTO(defaultArgument);
+ REGISTER_MATCHER_AUTO(doStmt);
+ REGISTER_MATCHER_AUTO(dynamicCast);
+ REGISTER_MATCHER_AUTO(explicitCast);
+ REGISTER_MATCHER_AUTO(expression);
+ REGISTER_MATCHER_AUTO(field);
+ REGISTER_MATCHER_AUTO(forStmt);
REGISTER_MATCHER_AUTO(forField);
- REGISTER_MATCHER_AUTO(Function);
- REGISTER_MATCHER_AUTO(FunctionalCast);
+ REGISTER_MATCHER_AUTO(function);
+ REGISTER_MATCHER_AUTO(functionalCast);
REGISTER_MATCHER_AUTO(hasAnyConstructorInitializer);
REGISTER_MATCHER_AUTO(hasAnyConstructorInitializer);
REGISTER_MATCHER_AUTO(hasAnyParameter);
@@ -187,33 +187,33 @@
REGISTER_MATCHER_AUTO(hasSourceExpression);
REGISTER_MATCHER_AUTO(hasTrueExpression);
REGISTER_MATCHER_AUTO(hasUnaryOperand);
- REGISTER_MATCHER_AUTO(If);
- REGISTER_MATCHER_AUTO(ImplicitCast);
- REGISTER_MATCHER_AUTO(IntegerLiteral);
+ REGISTER_MATCHER_AUTO(ifStmt);
+ REGISTER_MATCHER_AUTO(implicitCast);
+ REGISTER_MATCHER_AUTO(integerLiteral);
REGISTER_MATCHER_AUTO(isArrow);
REGISTER_MATCHER_AUTO(isConstQualified);
REGISTER_MATCHER_AUTO(isDerivedFrom);
REGISTER_MATCHER_AUTO(isImplicit);
REGISTER_MATCHER_AUTO(isWritten);
REGISTER_MATCHER_AUTO(member);
- REGISTER_MATCHER_AUTO(MemberExpression);
- REGISTER_MATCHER_AUTO(Method);
- REGISTER_MATCHER_AUTO(NameableDeclaration);
- REGISTER_MATCHER_AUTO(NewExpression);
+ REGISTER_MATCHER_AUTO(memberExpression);
+ REGISTER_MATCHER_AUTO(method);
+ REGISTER_MATCHER_AUTO(nameableDeclaration);
+ REGISTER_MATCHER_AUTO(newExpression);
REGISTER_MATCHER_AUTO(ofClass);
REGISTER_MATCHER_AUTO(on);
REGISTER_MATCHER_AUTO(onImplicitObjectArgument);
- REGISTER_MATCHER_AUTO(OverloadedOperatorCall);
- REGISTER_MATCHER_AUTO(ReinterpretCast);
- REGISTER_MATCHER_AUTO(Statement);
+ REGISTER_MATCHER_AUTO(overloadedOperatorCall);
+ REGISTER_MATCHER_AUTO(reinterpretCast);
+ REGISTER_MATCHER_AUTO(statement);
REGISTER_MATCHER_AUTO(statementCountIs);
- REGISTER_MATCHER_AUTO(StaticCast);
- REGISTER_MATCHER_AUTO(StringLiteral);
- REGISTER_MATCHER_AUTO(SwitchCase);
+ REGISTER_MATCHER_AUTO(staticCast);
+ REGISTER_MATCHER_AUTO(stringLiteral);
+ REGISTER_MATCHER_AUTO(switchCase);
REGISTER_MATCHER_AUTO(to);
- REGISTER_MATCHER_AUTO(UnaryOperator);
- REGISTER_MATCHER_AUTO(Variable);
- REGISTER_MATCHER_AUTO(While);
+ REGISTER_MATCHER_AUTO(unaryOperator);
+ REGISTER_MATCHER_AUTO(variable);
+ REGISTER_MATCHER_AUTO(whileStmt);
REGISTER_MATCHER_AUTO(withInitializer);
// HasType is very special. It is overloaded on parameter and return value.
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=159551&r1=159550&r2=159551&view=diff
==============================================================================
--- cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp (original)
+++ cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp Mon Jul 2 14:22:34 2012
@@ -51,44 +51,6 @@
return file_entry->getName();
}
-// 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,
- SourceLocation LocStart, SourceLocation LocEnd) {
- SourceLocation StartSpellingLocatino =
- SourceManager.getSpellingLoc(LocStart);
- SourceLocation EndSpellingLocation =
- SourceManager.getSpellingLoc(LocEnd);
- if (!StartSpellingLocatino.isValid() || !EndSpellingLocation.isValid()) {
- return std::string();
- }
- bool Invalid = true;
- const char *Text =
- SourceManager.getCharacterData(StartSpellingLocatino, &Invalid);
- if (Invalid) {
- return std::string();
- }
- std::pair<FileID, unsigned> Start =
- SourceManager.getDecomposedLoc(StartSpellingLocatino);
- std::pair<FileID, unsigned> End =
- SourceManager.getDecomposedLoc(Lexer::getLocForEndOfToken(
- EndSpellingLocation, 0, SourceManager, LangOptions()));
- if (Start.first != End.first) {
- // Start and end are in different files.
- return std::string();
- }
- if (End.second < Start.second) {
- // Shuffling text with macros may cause this.
- return std::string();
- }
- return std::string(Text, End.second - Start.second);
-}
-
-template <typename T>
-static std::string getText(const SourceManager &SourceManager, const T &Node) {
- return GetText(SourceManager, Node.getLocStart(), Node.getLocEnd());
-}
-
namespace {
bool hasMethod(const CXXRecordDecl &Decl, StringRef MethodName, ASTContext &Context) {
@@ -124,7 +86,7 @@
: Replace(Replace), EditFilesExpression(".*/ASTMatchers/.*") {}
virtual void run(const ast_matchers::MatchFinder::MatchResult &Result) {
- if (const CallExpr *Call = Result.Nodes.getStmtAs<CallExpr>("call")) {
+ if (Result.Nodes.getStmtAs<CallExpr>("call")) {
/* llvm::errs() << "Skipping: "
<< GetText(*Result.SourceManager, *Call) << "\n";*/
return;
@@ -152,6 +114,11 @@
if (Name == "new") Name = "create";
if (Name == "true") Name = "anything";
if (Name == "not") Name = "unless";
+ if (Name == "class") Name = "record";
+ if (Name == "do") Name = "doStmt";
+ if (Name == "for") Name = "forStmt";
+ if (Name == "if") Name = "ifStmt";
+ if (Name == "while") Name = "whileStmt";
if (const DeclRefExpr *Reference = Result.Nodes.getStmtAs<DeclRefExpr>("ref")) {
ReplaceText = Replacement(*Result.SourceManager, CharSourceRange::getTokenRange(SourceRange(Reference->getLocation(), Reference->getLocation())), Name);
@@ -172,6 +139,9 @@
// llvm::errs() << "*** " << GetFile(*Result.SourceManager, *Callee) << "\n";
//Callee->dump();
}
+ } else if (const VarDecl *Var = llvm::dyn_cast<VarDecl>(Declaration)) {
+ llvm::outs() << "Here " << Name << "\n";
+ ReplaceText = Replacement(*Result.SourceManager, CharSourceRange::getTokenRange(SourceRange(Var->getLocation(), Var->getLocation())), Name);
} else {
DeclarationNameInfo NameInfo;
if (const FunctionDecl *Function = llvm::dyn_cast<FunctionDecl>(Declaration)) {
@@ -189,7 +159,7 @@
//if (EditFilesExpression.match(ReplaceText.getFilePath())) {
//llvm::errs() << GetPosition(*Result.Nodes.GetDeclAs<NamedDecl>("declaration"), *Result.SourceManager) << "\n";
//llvm::errs
- llvm::outs() << ReplaceText.getFilePath() << ":" << ReplaceText.getOffset() << ", " << ReplaceText.getLength() << ": s/" << OldName << "/" << Name << "/g;\n";
+// llvm::outs() << ReplaceText.getFilePath() << ":" << ReplaceText.getOffset() << ", " << ReplaceText.getLength() << ": s/" << OldName << "/" << Name << "/g;\n";
Replace->insert(ReplaceText);
//} else {
// llvm::errs() << ReplaceText.GetFilePath() << ":" << ReplaceText.GetOffset() << ", " << ReplaceText.GetLength() << ": s/" << OldName << "/" << Name << "/g;\n";
@@ -290,17 +260,19 @@
FixLLVMStyle Callback(&Tool.getReplacements());
Finder.addMatcher(StatementMatcher(anyOf(
- StatementMatcher(id("ref", DeclarationReference(to(id("declaration", Function()))))),
- Call(callee(id("declaration", Function())),
- callee(id("callee", Expression()))))),
+ StatementMatcher(id("ref", declarationReference(to(id("declaration",
+ DeclarationMatcher(anyOf(function(), variable(
+ hasType(record(isDerivedFrom("VariadicFunction"))))))))))),
+ call(callee(id("declaration", function())),
+ callee(id("callee", expression()))))),
&Callback);
Finder.addMatcher(
DeclarationMatcher(anyOf(
- id("declaration", UsingDeclaration(hasAnyUsingShadowDeclaration(hasTargetDeclaration(Function())))),
+ id("declaration", UsingDeclaration(hasAnyUsingShadowDeclaration(hasTargetDeclaration(function())))),
allOf(
- id("declaration", Function()),
- unless(Constructor())))
+ id("declaration", DeclarationMatcher(anyOf(function(), variable(hasType(record(isDerivedFrom("VariadicFunction"))))))),
+ unless(constructor())))
),
&Callback);
return Tool.run(newFrontendActionFactory(&Finder));
Modified: cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp?rev=159551&r1=159550&r2=159551&view=diff
==============================================================================
--- cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp (original)
+++ cfe/branches/tooling/tools/remove-cstr-calls/RemoveCStrCalls.cpp Mon Jul 2 14:22:34 2012
@@ -187,8 +187,8 @@
ast_matchers::MatchFinder Finder;
FixCStrCall Callback(&Tool.getReplacements());
Finder.addMatcher(
- ConstructorCall(
- hasDeclaration(Method(hasName(StringConstructor))),
+ constructorCall(
+ hasDeclaration(method(hasName(StringConstructor))),
argumentCountIs(2),
// The first argument must have the form x.c_str() or p->c_str()
// where the method is string::c_str(). We can use the copy
@@ -196,23 +196,23 @@
// the string object).
hasArgument(
0,
- id("call", Call(
- callee(id("member", MemberExpression())),
- callee(Method(hasName(StringCStrMethod))),
- on(id("arg", Expression()))))),
+ id("call", call(
+ callee(id("member", memberExpression())),
+ callee(method(hasName(StringCStrMethod))),
+ on(id("arg", expression()))))),
// The second argument is the alloc object which must not be
// present explicitly.
hasArgument(
1,
- DefaultArgument())),
+ defaultArgument())),
&Callback);
Finder.addMatcher(
- ConstructorCall(
+ constructorCall(
// Implicit constructors of these classes are overloaded
// wrt. string types and they internally make a StringRef
// referring to the argument. Passing a string directly to
// them is preferred to passing a char pointer.
- hasDeclaration(Method(anyOf(
+ hasDeclaration(method(anyOf(
hasName("::llvm::StringRef::StringRef"),
hasName("::llvm::Twine::Twine")))),
argumentCountIs(1),
@@ -223,10 +223,10 @@
// directly.
hasArgument(
0,
- id("call", Call(
- callee(id("member", MemberExpression())),
- callee(Method(hasName(StringCStrMethod))),
- on(id("arg", Expression())))))),
+ id("call", call(
+ callee(id("member", memberExpression())),
+ callee(method(hasName(StringCStrMethod))),
+ on(id("arg", expression())))))),
&Callback);
return Tool.run(newFrontendActionFactory(&Finder));
}
Modified: cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=159551&r1=159550&r2=159551&view=diff
==============================================================================
--- cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/branches/tooling/unittests/ASTMatchers/ASTMatchersTest.cpp Mon Jul 2 14:22:34 2012
@@ -18,20 +18,20 @@
TEST(HasNameDeathTest, DiesOnEmptyName) {
ASSERT_DEBUG_DEATH({
- DeclarationMatcher HasEmptyName = Class(hasName(""));
+ DeclarationMatcher HasEmptyName = record(hasName(""));
EXPECT_TRUE(notMatches("class X {};", HasEmptyName));
}, "");
}
TEST(IsDerivedFromDeathTest, DiesOnEmptyBaseName) {
ASSERT_DEBUG_DEATH({
- DeclarationMatcher IsDerivedFromEmpty = Class(isDerivedFrom(""));
+ DeclarationMatcher IsDerivedFromEmpty = record(isDerivedFrom(""));
EXPECT_TRUE(notMatches("class X {};", IsDerivedFromEmpty));
}, "");
}
TEST(NameableDeclaration, MatchesVariousDecls) {
- DeclarationMatcher NamedX = NameableDeclaration(hasName("X"));
+ 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));
@@ -43,10 +43,10 @@
}
TEST(DeclarationMatcher, MatchClass) {
- DeclarationMatcher ClassMatcher(Class());
+ DeclarationMatcher ClassMatcher(record());
EXPECT_FALSE(matches("", ClassMatcher));
- DeclarationMatcher ClassX = Class(Class(hasName("X")));
+ DeclarationMatcher ClassX = record(record(hasName("X")));
EXPECT_TRUE(matches("class X;", ClassX));
EXPECT_TRUE(matches("class X {};", ClassX));
EXPECT_TRUE(matches("template<class T> class X {};", ClassX));
@@ -54,7 +54,7 @@
}
TEST(DeclarationMatcher, ClassIsDerived) {
- DeclarationMatcher IsDerivedFromX = Class(isDerivedFrom("X"));
+ DeclarationMatcher IsDerivedFromX = record(isDerivedFrom("X"));
EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsDerivedFromX));
EXPECT_TRUE(matches("class X {}; class Y : public X {};", IsDerivedFromX));
@@ -64,7 +64,7 @@
EXPECT_TRUE(notMatches("", IsDerivedFromX));
DeclarationMatcher ZIsDerivedFromX =
- Class(hasName("Z"), isDerivedFrom("X"));
+ record(hasName("Z"), isDerivedFrom("X"));
EXPECT_TRUE(
matches("class X {}; class Y : public X {}; class Z : public Y {};",
ZIsDerivedFromX));
@@ -195,18 +195,18 @@
"void f() { Z<float> z_float; Z<double> z_double; Z<char> z_char; }";
EXPECT_TRUE(matches(
RecursiveTemplateOneParameter,
- Variable(hasName("z_float"),
- hasInitializer(hasType(Class(isDerivedFrom("Base1")))))));
+ variable(hasName("z_float"),
+ hasInitializer(hasType(record(isDerivedFrom("Base1")))))));
EXPECT_TRUE(notMatches(
RecursiveTemplateOneParameter,
- Variable(
+ variable(
hasName("z_float"),
- hasInitializer(hasType(Class(isDerivedFrom("Base2")))))));
+ hasInitializer(hasType(record(isDerivedFrom("Base2")))))));
EXPECT_TRUE(matches(
RecursiveTemplateOneParameter,
- Variable(
+ variable(
hasName("z_char"),
- hasInitializer(hasType(Class(isDerivedFrom("Base1"),
+ hasInitializer(hasType(record(isDerivedFrom("Base1"),
isDerivedFrom("Base2")))))));
const char *RecursiveTemplateTwoParameters =
@@ -222,25 +222,25 @@
" Z<char, void> z_char; }";
EXPECT_TRUE(matches(
RecursiveTemplateTwoParameters,
- Variable(
+ variable(
hasName("z_float"),
- hasInitializer(hasType(Class(isDerivedFrom("Base1")))))));
+ hasInitializer(hasType(record(isDerivedFrom("Base1")))))));
EXPECT_TRUE(notMatches(
RecursiveTemplateTwoParameters,
- Variable(
+ variable(
hasName("z_float"),
- hasInitializer(hasType(Class(isDerivedFrom("Base2")))))));
+ hasInitializer(hasType(record(isDerivedFrom("Base2")))))));
EXPECT_TRUE(matches(
RecursiveTemplateTwoParameters,
- Variable(
+ variable(
hasName("z_char"),
- hasInitializer(hasType(Class(isDerivedFrom("Base1"),
+ hasInitializer(hasType(record(isDerivedFrom("Base1"),
isDerivedFrom("Base2")))))));
}
TEST(DeclarationMatcher, MatchAnyOf) {
DeclarationMatcher YOrZDerivedFromX =
- Class(anyOf(hasName("Y"), allOf(isDerivedFrom("X"), hasName("Z"))));
+ record(anyOf(hasName("Y"), allOf(isDerivedFrom("X"), hasName("Z"))));
EXPECT_TRUE(
matches("class X {}; class Z : public X {};", YOrZDerivedFromX));
@@ -250,7 +250,7 @@
EXPECT_TRUE(notMatches("class Z {};", YOrZDerivedFromX));
DeclarationMatcher XOrYOrZOrUOrV =
- Class(anyOf(hasName("X"), hasName("Y"), hasName("Z"), hasName("U"),
+ record(anyOf(hasName("X"), hasName("Y"), hasName("Z"), hasName("U"),
hasName("V")));
EXPECT_TRUE(matches("class X {};", XOrYOrZOrUOrV));
@@ -262,13 +262,13 @@
}
TEST(DeclarationMatcher, MatchHas) {
- DeclarationMatcher HasClassX = Class(has(Class(hasName("X"))));
+ DeclarationMatcher HasClassX = record(has(record(hasName("X"))));
EXPECT_TRUE(matches("class Y { class X {}; };", HasClassX));
EXPECT_TRUE(matches("class X {};", HasClassX));
DeclarationMatcher YHasClassX =
- Class(hasName("Y"), has(Class(hasName("X"))));
+ record(hasName("Y"), has(record(hasName("X"))));
EXPECT_TRUE(matches("class Y { class X {}; };", YHasClassX));
EXPECT_TRUE(notMatches("class X {};", YHasClassX));
EXPECT_TRUE(
@@ -277,14 +277,14 @@
TEST(DeclarationMatcher, MatchHasRecursiveAllOf) {
DeclarationMatcher Recursive =
- Class(
- has(Class(
- has(Class(hasName("X"))),
- has(Class(hasName("Y"))),
+ record(
+ has(record(
+ has(record(hasName("X"))),
+ has(record(hasName("Y"))),
hasName("Z"))),
- has(Class(
- has(Class(hasName("A"))),
- has(Class(hasName("B"))),
+ has(record(
+ has(record(hasName("A"))),
+ has(record(hasName("B"))),
hasName("C"))),
hasName("F"));
@@ -335,21 +335,21 @@
TEST(DeclarationMatcher, MatchHasRecursiveAnyOf) {
DeclarationMatcher Recursive =
- Class(
+ record(
anyOf(
- has(Class(
+ has(record(
anyOf(
- has(Class(
+ has(record(
hasName("X"))),
- has(Class(
+ has(record(
hasName("Y"))),
hasName("Z")))),
- has(Class(
+ has(record(
anyOf(
hasName("C"),
- has(Class(
+ has(record(
hasName("A"))),
- has(Class(
+ has(record(
hasName("B")))))),
hasName("F")));
@@ -366,7 +366,7 @@
TEST(DeclarationMatcher, MatchNot) {
DeclarationMatcher NotClassX =
- Class(
+ record(
isDerivedFrom("Y"),
unless(hasName("Y")),
unless(hasName("X")));
@@ -379,11 +379,11 @@
NotClassX));
DeclarationMatcher ClassXHasNotClassY =
- Class(
+ record(
hasName("X"),
- has(Class(hasName("Z"))),
+ has(record(hasName("Z"))),
unless(
- has(Class(hasName("Y")))));
+ has(record(hasName("Y")))));
EXPECT_TRUE(matches("class X { class Z {}; };", ClassXHasNotClassY));
EXPECT_TRUE(notMatches("class X { class Y {}; class Z {}; };",
ClassXHasNotClassY));
@@ -391,8 +391,8 @@
TEST(DeclarationMatcher, HasDescendant) {
DeclarationMatcher ZDescendantClassX =
- Class(
- hasDescendant(Class(hasName("X"))),
+ record(
+ hasDescendant(record(hasName("X"))),
hasName("Z"));
EXPECT_TRUE(matches("class Z { class X {}; };", ZDescendantClassX));
EXPECT_TRUE(
@@ -406,8 +406,8 @@
EXPECT_TRUE(notMatches("class Z {};", ZDescendantClassX));
DeclarationMatcher ZDescendantClassXHasClassY =
- Class(
- hasDescendant(Class(has(Class(hasName("Y"))),
+ record(
+ hasDescendant(record(has(record(hasName("Y"))),
hasName("X"))),
hasName("Z"));
EXPECT_TRUE(matches("class Z { class X { class Y {}; }; };",
@@ -429,8 +429,8 @@
"};", ZDescendantClassXHasClassY));
DeclarationMatcher ZDescendantClassXDescendantClassY =
- Class(
- hasDescendant(Class(hasDescendant(Class(hasName("Y"))),
+ record(
+ hasDescendant(record(hasDescendant(record(hasName("Y"))),
hasName("X"))),
hasName("Z"));
EXPECT_TRUE(
@@ -451,9 +451,9 @@
TEST(StatementMatcher, Has) {
StatementMatcher HasVariableI =
- Expression(
- hasType(pointsTo(Class(hasName("X")))),
- has(DeclarationReference(to(Variable(hasName("i"))))));
+ expression(
+ hasType(pointsTo(record(hasName("X")))),
+ has(declarationReference(to(variable(hasName("i"))))));
EXPECT_TRUE(matches(
"class X; X *x(int); void c() { int i; x(i); }", HasVariableI));
@@ -463,9 +463,9 @@
TEST(StatementMatcher, HasDescendant) {
StatementMatcher HasDescendantVariableI =
- Expression(
- hasType(pointsTo(Class(hasName("X")))),
- hasDescendant(DeclarationReference(to(Variable(hasName("i"))))));
+ expression(
+ hasType(pointsTo(record(hasName("X")))),
+ hasDescendant(declarationReference(to(variable(hasName("i"))))));
EXPECT_TRUE(matches(
"class X; X *x(bool); bool b(int); void c() { int i; x(b(i)); }",
@@ -476,19 +476,19 @@
}
TEST(TypeMatcher, MatchesClassType) {
- TypeMatcher TypeA = hasDeclaration(Class(hasName("A")));
+ TypeMatcher TypeA = hasDeclaration(record(hasName("A")));
EXPECT_TRUE(matches("class A { public: A *a; };", TypeA));
EXPECT_TRUE(notMatches("class A {};", TypeA));
- TypeMatcher TypeDerivedFromA = hasDeclaration(Class(isDerivedFrom("A")));
+ TypeMatcher TypeDerivedFromA = hasDeclaration(record(isDerivedFrom("A")));
EXPECT_TRUE(matches("class A {}; class B : public A { public: B *b; };",
TypeDerivedFromA));
EXPECT_TRUE(notMatches("class A {};", TypeA));
TypeMatcher TypeAHasClassB = hasDeclaration(
- Class(hasName("A"), has(Class(hasName("B")))));
+ record(hasName("A"), has(record(hasName("B")))));
EXPECT_TRUE(
matches("class A { public: A *a; class B {}; };", TypeAHasClassB));
@@ -542,7 +542,7 @@
};
TEST(Matcher, BindMatchedNodes) {
- DeclarationMatcher ClassX = has(id("x", Class(hasName("X"))));
+ DeclarationMatcher ClassX = has(id("x", record(hasName("X"))));
EXPECT_TRUE(matchAndVerifyResultTrue("class X {};",
ClassX, new VerifyIdIsBoundToDecl<clang::CXXRecordDecl>("x")));
@@ -551,13 +551,13 @@
ClassX, new VerifyIdIsBoundToDecl<clang::CXXRecordDecl>("other-id")));
TypeMatcher TypeAHasClassB = hasDeclaration(
- Class(hasName("A"), has(id("b", Class(hasName("B"))))));
+ record(hasName("A"), has(id("b", record(hasName("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")))));
+ StatementMatcher MethodX = id("x", call(callee(method(hasName("x")))));
EXPECT_TRUE(matchAndVerifyResultTrue("class A { void x() { x(); } };",
MethodX,
@@ -565,54 +565,54 @@
}
TEST(HasType, TakesQualTypeMatcherAndMatchesExpr) {
- TypeMatcher ClassX = hasDeclaration(Class(hasName("X")));
+ TypeMatcher ClassX = hasDeclaration(record(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; }",
- Expression(hasType(ClassX))));
+ expression(hasType(ClassX))));
EXPECT_TRUE(
matches("class X {}; void y(X *x) { x; }",
- Expression(hasType(pointsTo(ClassX)))));
+ expression(hasType(pointsTo(ClassX)))));
}
TEST(HasType, TakesQualTypeMatcherAndMatchesValueDecl) {
- TypeMatcher ClassX = hasDeclaration(Class(hasName("X")));
+ TypeMatcher ClassX = hasDeclaration(record(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; }",
- Variable(hasType(pointsTo(ClassX)))));
+ variable(hasType(pointsTo(ClassX)))));
}
TEST(HasType, TakesDeclMatcherAndMatchesExpr) {
- DeclarationMatcher ClassX = Class(hasName("X"));
+ DeclarationMatcher ClassX = record(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; }",
- Expression(hasType(ClassX))));
+ expression(hasType(ClassX))));
}
TEST(HasType, TakesDeclMatcherAndMatchesValueDecl) {
- DeclarationMatcher ClassX = Class(hasName("X"));
+ DeclarationMatcher ClassX = record(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) {
// FIXME: Do we want to overload Call() to directly take
// Matcher<clang::Decl>, too?
- StatementMatcher MethodX = Call(hasDeclaration(Method(hasName("x"))));
+ StatementMatcher MethodX = call(hasDeclaration(method(hasName("x"))));
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")))));
+ StatementMatcher MethodOnY = call(on(hasType(record(hasName("Y")))));
EXPECT_TRUE(
matches("class Y { public: void x(); }; void z() { Y y; y.x(); }",
@@ -631,7 +631,7 @@
MethodOnY));
StatementMatcher MethodOnYPointer =
- Call(on(hasType(pointsTo(Class(hasName("Y"))))));
+ call(on(hasType(pointsTo(record(hasName("Y"))))));
EXPECT_TRUE(
matches("class Y { public: void x(); }; void z() { Y *y; y->x(); }",
@@ -651,7 +651,7 @@
}
TEST(Matcher, OverloadedOperatorCall) {
- StatementMatcher OpCall = OverloadedOperatorCall();
+ StatementMatcher OpCall = overloadedOperatorCall();
// Unary operator
EXPECT_TRUE(matches("class Y { }; "
"bool operator!(Y x) { return false; }; "
@@ -678,12 +678,12 @@
TEST(Matcher, HasOperatorNameForOverloadedOperatorCall) {
StatementMatcher OpCallAndAnd =
- OverloadedOperatorCall(hasOverloadedOperatorName("&&"));
+ overloadedOperatorCall(hasOverloadedOperatorName("&&"));
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("<<"));
+ overloadedOperatorCall(hasOverloadedOperatorName("<<"));
EXPECT_TRUE(notMatches("class Y { }; "
"bool operator&&(Y x, Y y) { return true; }; "
"Y a; Y b; bool c = a && b;",
@@ -691,7 +691,7 @@
}
TEST(Matcher, ThisPointerType) {
- StatementMatcher MethodOnY = Call(thisPointerType(Class(hasName("Y"))));
+ StatementMatcher MethodOnY = call(thisPointerType(record(hasName("Y"))));
EXPECT_TRUE(
matches("class Y { public: void x(); }; void z() { Y y; y.x(); }",
@@ -721,9 +721,9 @@
TEST(Matcher, VariableUsage) {
StatementMatcher Reference =
- DeclarationReference(to(
- Variable(hasInitializer(
- Call(thisPointerType(Class(hasName("Y"))))))));
+ declarationReference(to(
+ variable(hasInitializer(
+ call(thisPointerType(record(hasName("Y"))))))));
EXPECT_TRUE(matches(
"class Y {"
@@ -746,8 +746,8 @@
}
TEST(Matcher, CalledVariable) {
- StatementMatcher CallOnVariableY = Expression(
- Call(on(DeclarationReference(to(Variable(hasName("y")))))));
+ StatementMatcher CallOnVariableY = expression(
+ call(on(declarationReference(to(variable(hasName("y")))))));
EXPECT_TRUE(matches(
"class Y { public: void x() { Y y; y.x(); } };", CallOnVariableY));
@@ -766,61 +766,61 @@
}
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; };",
- MemberExpression()));
+ memberExpression()));
}
TEST(MemberExpression, MatchesStaticVariable) {
EXPECT_TRUE(matches("class Y { void x() { this->y; } static int y; };",
- MemberExpression()));
+ memberExpression()));
EXPECT_TRUE(notMatches("class Y { void x() { y; } static int y; };",
- MemberExpression()));
+ memberExpression()));
EXPECT_TRUE(notMatches("class Y { void x() { Y::y; } static int y; };",
- MemberExpression()));
+ memberExpression()));
}
TEST(IsArrow, MatchesMemberVariablesViaArrow) {
EXPECT_TRUE(matches("class Y { void x() { this->y; } int y; };",
- MemberExpression(isArrow())));
+ memberExpression(isArrow())));
EXPECT_TRUE(matches("class Y { void x() { y; } int y; };",
- MemberExpression(isArrow())));
+ memberExpression(isArrow())));
EXPECT_TRUE(notMatches("class Y { void x() { (*this).y; } int y; };",
- MemberExpression(isArrow())));
+ memberExpression(isArrow())));
}
TEST(IsArrow, MatchesStaticMemberVariablesViaArrow) {
EXPECT_TRUE(matches("class Y { void x() { this->y; } static int y; };",
- MemberExpression(isArrow())));
+ memberExpression(isArrow())));
EXPECT_TRUE(notMatches("class Y { void x() { y; } static int y; };",
- MemberExpression(isArrow())));
+ memberExpression(isArrow())));
EXPECT_TRUE(notMatches("class Y { void x() { (*this).y; } static int y; };",
- MemberExpression(isArrow())));
+ memberExpression(isArrow())));
}
TEST(IsArrow, MatchesMemberCallsViaArrow) {
EXPECT_TRUE(matches("class Y { void x() { this->x(); } };",
- MemberExpression(isArrow())));
+ memberExpression(isArrow())));
EXPECT_TRUE(matches("class Y { void x() { x(); } };",
- MemberExpression(isArrow())));
+ memberExpression(isArrow())));
EXPECT_TRUE(notMatches("class Y { void x() { Y y; y.x(); } };",
- MemberExpression(isArrow())));
+ memberExpression(isArrow())));
}
TEST(Callee, MatchesDeclarations) {
- StatementMatcher CallMethodX = Call(callee(Method(hasName("x"))));
+ StatementMatcher CallMethodX = call(callee(method(hasName("x"))));
EXPECT_TRUE(matches("class Y { void x() { x(); } };", CallMethodX));
EXPECT_TRUE(notMatches("class Y { void x() {} };", CallMethodX));
@@ -828,13 +828,13 @@
TEST(Callee, MatchesMemberExpressions) {
EXPECT_TRUE(matches("class Y { void x() { this->x(); } };",
- Call(callee(MemberExpression()))));
+ 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"))));
+ StatementMatcher CallFunctionF = call(callee(function(hasName("f"))));
EXPECT_TRUE(matches("void f() { f(); }", CallFunctionF));
EXPECT_TRUE(notMatches("void f() { }", CallFunctionF));
@@ -857,29 +857,29 @@
}
TEST(Matcher, Argument) {
- StatementMatcher CallArgumentY = Expression(Call(
- hasArgument(0, DeclarationReference(to(Variable(hasName("y")))))));
+ 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("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")))))));
+ StatementMatcher WrongIndex = expression(call(
+ hasArgument(42, declarationReference(to(variable(hasName("y")))))));
EXPECT_TRUE(notMatches("void x(int) { int y; x(y); }", WrongIndex));
}
TEST(Matcher, AnyArgument) {
- StatementMatcher CallArgumentY = Expression(Call(
- hasAnyArgument(DeclarationReference(to(Variable(hasName("y")))))));
+ 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));
}
TEST(Matcher, ArgumentCount) {
- StatementMatcher Call1Arg = Expression(Call(argumentCountIs(1)));
+ 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));
@@ -887,8 +887,8 @@
}
TEST(Matcher, References) {
- DeclarationMatcher ReferenceClassX = Variable(
- hasType(references(Class(hasName("X")))));
+ DeclarationMatcher ReferenceClassX = variable(
+ hasType(references(record(hasName("X")))));
EXPECT_TRUE(matches("class X {}; void y(X y) { X &x = y; }",
ReferenceClassX));
EXPECT_TRUE(
@@ -901,53 +901,53 @@
TEST(HasParameter, CallsInnerMatcher) {
EXPECT_TRUE(matches("class X { void x(int) {} };",
- Method(hasParameter(0, Variable()))));
+ method(hasParameter(0, variable()))));
EXPECT_TRUE(notMatches("class X { void x(int) {} };",
- Method(hasParameter(0, hasName("x")))));
+ method(hasParameter(0, hasName("x")))));
}
TEST(HasParameter, DoesNotMatchIfIndexOutOfBounds) {
EXPECT_TRUE(notMatches("class X { void x(int) {} };",
- Method(hasParameter(42, Variable()))));
+ method(hasParameter(42, variable()))));
}
TEST(HasType, MatchesParameterVariableTypesStrictly) {
EXPECT_TRUE(matches("class X { void x(X x) {} };",
- Method(hasParameter(0, hasType(Class(hasName("X")))))));
+ method(hasParameter(0, hasType(record(hasName("X")))))));
EXPECT_TRUE(notMatches("class X { void x(const X &x) {} };",
- Method(hasParameter(0, hasType(Class(hasName("X")))))));
+ method(hasParameter(0, hasType(record(hasName("X")))))));
EXPECT_TRUE(matches("class X { void x(const X *x) {} };",
- Method(hasParameter(0, hasType(pointsTo(Class(hasName("X"))))))));
+ method(hasParameter(0, hasType(pointsTo(record(hasName("X"))))))));
EXPECT_TRUE(matches("class X { void x(const X &x) {} };",
- Method(hasParameter(0, hasType(references(Class(hasName("X"))))))));
+ method(hasParameter(0, hasType(references(record(hasName("X"))))))));
}
TEST(HasAnyParameter, MatchesIndependentlyOfPosition) {
EXPECT_TRUE(matches("class Y {}; class X { void x(X x, Y y) {} };",
- Method(hasAnyParameter(hasType(Class(hasName("X")))))));
+ method(hasAnyParameter(hasType(record(hasName("X")))))));
EXPECT_TRUE(matches("class Y {}; class X { void x(Y y, X x) {} };",
- Method(hasAnyParameter(hasType(Class(hasName("X")))))));
+ method(hasAnyParameter(hasType(record(hasName("X")))))));
}
TEST(HasAnyParameter, DoesntMatchIfInnerMatcherDoesntMatch) {
EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };",
- Method(hasAnyParameter(hasType(Class(hasName("X")))))));
+ method(hasAnyParameter(hasType(record(hasName("X")))))));
}
TEST(HasAnyParameter, DoesNotMatchThisPointer) {
EXPECT_TRUE(notMatches("class Y {}; class X { void x() {} };",
- Method(hasAnyParameter(hasType(pointsTo(Class(hasName("X"))))))));
+ method(hasAnyParameter(hasType(pointsTo(record(hasName("X"))))))));
}
TEST(HasName, MatchesParameterVariableDeclartions) {
EXPECT_TRUE(matches("class Y {}; class X { void x(int x) {} };",
- Method(hasAnyParameter(hasName("x")))));
+ method(hasAnyParameter(hasName("x")))));
EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };",
- Method(hasAnyParameter(hasName("x")))));
+ method(hasAnyParameter(hasName("x")))));
}
TEST(Matcher, ConstructorCall) {
- StatementMatcher Constructor = Expression(ConstructorCall());
+ StatementMatcher Constructor = expression(constructorCall());
EXPECT_TRUE(
matches("class X { public: X(); }; void x() { X x; }", Constructor));
@@ -961,8 +961,8 @@
}
TEST(Matcher, ConstructorArgument) {
- StatementMatcher Constructor = Expression(ConstructorCall(
- hasArgument(0, DeclarationReference(to(Variable(hasName("y")))))));
+ StatementMatcher Constructor = expression(constructorCall(
+ hasArgument(0, declarationReference(to(variable(hasName("y")))))));
EXPECT_TRUE(
matches("class X { public: X(int); }; void x() { int y; X x(y); }",
@@ -977,8 +977,8 @@
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")))))));
+ 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); }",
WrongIndex));
@@ -986,7 +986,7 @@
TEST(Matcher, ConstructorArgumentCount) {
StatementMatcher Constructor1Arg =
- Expression(ConstructorCall(argumentCountIs(1)));
+ expression(constructorCall(argumentCountIs(1)));
EXPECT_TRUE(
matches("class X { public: X(int); }; void x() { X x(0); }",
@@ -1003,7 +1003,7 @@
}
TEST(Matcher, BindTemporaryExpression) {
- StatementMatcher TempExpression = Expression(BindTemporaryExpression());
+ StatementMatcher TempExpression = expression(bindTemporaryExpression());
std::string ClassString = "class string { public: string(); ~string(); }; ";
@@ -1035,33 +1035,33 @@
TEST(ConstructorDeclaration, SimpleCase) {
EXPECT_TRUE(matches("class Foo { Foo(int i); };",
- Constructor(ofClass(hasName("Foo")))));
+ constructor(ofClass(hasName("Foo")))));
EXPECT_TRUE(notMatches("class Foo { Foo(int i); };",
- Constructor(ofClass(hasName("Bar")))));
+ 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 { };",
- Constructor(isImplicit())));
+ constructor(isImplicit())));
// The compiler added the implicit default constructor.
EXPECT_TRUE(matches("class Foo { }; Foo* f = new Foo();",
- Constructor(isImplicit())));
+ constructor(isImplicit())));
EXPECT_TRUE(matches("class Foo { Foo(){} };",
- Constructor(unless(isImplicit()))));
+ constructor(unless(isImplicit()))));
}
TEST(HasAnyConstructorInitializer, SimpleCase) {
EXPECT_TRUE(notMatches(
"class Foo { Foo() { } };",
- Constructor(hasAnyConstructorInitializer(anything()))));
+ constructor(hasAnyConstructorInitializer(anything()))));
EXPECT_TRUE(matches(
"class Foo {"
" Foo() : foo_() { }"
" int foo_;"
"};",
- Constructor(hasAnyConstructorInitializer(anything()))));
+ constructor(hasAnyConstructorInitializer(anything()))));
}
TEST(HasAnyConstructorInitializer, ForField) {
@@ -1072,12 +1072,12 @@
" Baz foo_;"
" Baz bar_;"
"};";
- EXPECT_TRUE(matches(Code, Constructor(hasAnyConstructorInitializer(
- forField(hasType(Class(hasName("Baz"))))))));
- EXPECT_TRUE(matches(Code, Constructor(hasAnyConstructorInitializer(
+ EXPECT_TRUE(matches(Code, constructor(hasAnyConstructorInitializer(
+ forField(hasType(record(hasName("Baz"))))))));
+ EXPECT_TRUE(matches(Code, constructor(hasAnyConstructorInitializer(
forField(hasName("foo_"))))));
- EXPECT_TRUE(notMatches(Code, Constructor(hasAnyConstructorInitializer(
- forField(hasType(Class(hasName("Bar"))))))));
+ EXPECT_TRUE(notMatches(Code, constructor(hasAnyConstructorInitializer(
+ forField(hasType(record(hasName("Bar"))))))));
}
TEST(HasAnyConstructorInitializer, WithInitializer) {
@@ -1086,10 +1086,10 @@
" Foo() : foo_(0) { }"
" int foo_;"
"};";
- EXPECT_TRUE(matches(Code, Constructor(hasAnyConstructorInitializer(
- withInitializer(IntegerLiteral(equals(0)))))));
- EXPECT_TRUE(notMatches(Code, Constructor(hasAnyConstructorInitializer(
- withInitializer(IntegerLiteral(equals(1)))))));
+ EXPECT_TRUE(matches(Code, constructor(hasAnyConstructorInitializer(
+ withInitializer(integerLiteral(equals(0)))))));
+ EXPECT_TRUE(notMatches(Code, constructor(hasAnyConstructorInitializer(
+ withInitializer(integerLiteral(equals(1)))))));
}
TEST(HasAnyConstructorInitializer, IsWritten) {
@@ -1100,16 +1100,16 @@
" 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_")), unless(isWritten()))))));
}
TEST(Matcher, NewExpression) {
- StatementMatcher New = Expression(NewExpression());
+ StatementMatcher New = expression(newExpression());
EXPECT_TRUE(matches("class X { public: X(); }; void x() { new X; }", New));
EXPECT_TRUE(
@@ -1120,9 +1120,9 @@
}
TEST(Matcher, NewExpressionArgument) {
- StatementMatcher New = Expression(ConstructorCall(
+ StatementMatcher New = expression(constructorCall(
hasArgument(
- 0, DeclarationReference(to(Variable(hasName("y")))))));
+ 0, declarationReference(to(variable(hasName("y")))))));
EXPECT_TRUE(
matches("class X { public: X(int); }; void x() { int y; new X(y); }",
@@ -1134,16 +1134,16 @@
notMatches("class X { public: X(int); }; void x() { int z; new X(z); }",
New));
- StatementMatcher WrongIndex = Expression(ConstructorCall(
+ StatementMatcher WrongIndex = expression(constructorCall(
hasArgument(
- 42, DeclarationReference(to(Variable(hasName("y")))))));
+ 42, declarationReference(to(variable(hasName("y")))))));
EXPECT_TRUE(
notMatches("class X { public: X(int); }; void x() { int y; new X(y); }",
WrongIndex));
}
TEST(Matcher, NewExpressionArgumentCount) {
- StatementMatcher New = ConstructorCall(argumentCountIs(1));
+ StatementMatcher New = constructorCall(argumentCountIs(1));
EXPECT_TRUE(
matches("class X { public: X(int); }; void x() { new X(0); }", New));
@@ -1153,7 +1153,7 @@
}
TEST(Matcher, DefaultArgument) {
- StatementMatcher Arg = DefaultArgument();
+ StatementMatcher Arg = defaultArgument();
EXPECT_TRUE(matches("void x(int, int = 0) { int y; x(y); }", Arg));
EXPECT_TRUE(
@@ -1162,7 +1162,7 @@
}
TEST(Matcher, StringLiterals) {
- StatementMatcher Literal = Expression(StringLiteral());
+ StatementMatcher Literal = expression(stringLiteral());
EXPECT_TRUE(matches("const char *s = \"string\";", Literal));
// wide string
EXPECT_TRUE(matches("const wchar_t *s = L\"string\";", Literal));
@@ -1173,7 +1173,7 @@
}
TEST(Matcher, CharacterLiterals) {
- StatementMatcher CharLiteral = Expression(CharacterLiteral());
+ StatementMatcher CharLiteral = expression(characterLiteral());
EXPECT_TRUE(matches("const char c = 'c';", CharLiteral));
// wide character
EXPECT_TRUE(matches("const char c = L'c';", CharLiteral));
@@ -1183,7 +1183,7 @@
}
TEST(Matcher, IntegerLiterals) {
- StatementMatcher HasIntLiteral = Expression(IntegerLiteral());
+ 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));
@@ -1199,7 +1199,7 @@
}
TEST(Matcher, Conditions) {
- StatementMatcher Condition = If(hasCondition(BoolLiteral(equals(true))));
+ StatementMatcher Condition = ifStmt(hasCondition(boolLiteral(equals(true))));
EXPECT_TRUE(matches("void x() { if (true) {} }", Condition));
EXPECT_TRUE(notMatches("void x() { if (false) {} }", Condition));
@@ -1209,7 +1209,7 @@
}
TEST(MatchBinaryOperator, HasOperatorName) {
- StatementMatcher OperatorOr = BinaryOperator(hasOperatorName("||"));
+ StatementMatcher OperatorOr = binaryOperator(hasOperatorName("||"));
EXPECT_TRUE(matches("void x() { true || false; }", OperatorOr));
EXPECT_TRUE(notMatches("void x() { true && false; }", OperatorOr));
@@ -1217,8 +1217,8 @@
TEST(MatchBinaryOperator, HasLHSAndHasRHS) {
StatementMatcher OperatorTrueFalse =
- BinaryOperator(hasLHS(BoolLiteral(equals(true))),
- hasRHS(BoolLiteral(equals(false))));
+ 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));
@@ -1227,7 +1227,7 @@
TEST(MatchBinaryOperator, HasEitherOperand) {
StatementMatcher HasOperand =
- BinaryOperator(hasEitherOperand(BoolLiteral(equals(false))));
+ binaryOperator(hasEitherOperand(boolLiteral(equals(false))));
EXPECT_TRUE(matches("void x() { true || false; }", HasOperand));
EXPECT_TRUE(matches("void x() { false && true; }", HasOperand));
@@ -1239,104 +1239,104 @@
// 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);",
- BinaryOperator(hasOperatorName("="))));
+ 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);",
- BinaryOperator(hasOperatorName("<<="))));
- EXPECT_TRUE(matches("bool b = 1 > 2;", BinaryOperator(hasOperatorName(">"))));
+ 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);",
- BinaryOperator(hasOperatorName(">>="))));
+ 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);",
- BinaryOperator(hasOperatorName("^="))));
+ 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);",
- BinaryOperator(hasOperatorName("%="))));
+ 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;",
- BinaryOperator(hasOperatorName("&&"))));
+ binaryOperator(hasOperatorName("&&"))));
EXPECT_TRUE(
matches("bool b = true; bool c = (b &= false);",
- BinaryOperator(hasOperatorName("&="))));
+ 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;",
- BinaryOperator(hasOperatorName("||"))));
+ binaryOperator(hasOperatorName("||"))));
EXPECT_TRUE(
matches("bool b = true; bool c = (b |= false);",
- BinaryOperator(hasOperatorName("|="))));
+ 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);",
- BinaryOperator(hasOperatorName("*="))));
+ 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);",
- BinaryOperator(hasOperatorName("/="))));
+ 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);",
- BinaryOperator(hasOperatorName("+="))));
+ 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);",
- BinaryOperator(hasOperatorName("-="))));
+ binaryOperator(hasOperatorName("-="))));
EXPECT_TRUE(
matches("struct A { void x() { void (A::*a)(); (this->*a)(); } };",
- BinaryOperator(hasOperatorName("->*"))));
+ binaryOperator(hasOperatorName("->*"))));
EXPECT_TRUE(
matches("struct A { void x() { void (A::*a)(); ((*this).*a)(); } };",
- BinaryOperator(hasOperatorName(".*"))));
+ binaryOperator(hasOperatorName(".*"))));
// Member expressions as operators are not supported in matches.
EXPECT_TRUE(
notMatches("struct A { void x(A *a) { a->x(this); } };",
- BinaryOperator(hasOperatorName("->"))));
+ 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(
"struct A { bool operator&&(const A &a) const { return false; } };"
"void x() { A a, b; a && b; }",
- BinaryOperator()));
+ binaryOperator()));
}
TEST(MatchUnaryOperator, HasOperatorName) {
- StatementMatcher OperatorNot = UnaryOperator(hasOperatorName("!"));
+ StatementMatcher OperatorNot = unaryOperator(hasOperatorName("!"));
EXPECT_TRUE(matches("void x() { !true; } ", OperatorNot));
EXPECT_TRUE(notMatches("void x() { true; } ", OperatorNot));
@@ -1344,7 +1344,7 @@
TEST(MatchUnaryOperator, HasUnaryOperand) {
StatementMatcher OperatorOnFalse =
- UnaryOperator(hasUnaryOperand(BoolLiteral(equals(false))));
+ unaryOperator(hasUnaryOperand(boolLiteral(equals(false))));
EXPECT_TRUE(matches("void x() { !false; }", OperatorOnFalse));
EXPECT_TRUE(notMatches("void x() { !true; }", OperatorOnFalse));
@@ -1353,49 +1353,49 @@
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(
"struct A { bool operator!() const { return false; } };"
- "void x() { A a; !a; }", UnaryOperator(hasOperatorName("!"))));
+ "void x() { A a; !a; }", unaryOperator(hasOperatorName("!"))));
}
TEST(Matcher, ConditionalOperator) {
- StatementMatcher Conditional = ConditionalOperator(
- hasCondition(BoolLiteral(equals(true))),
- hasTrueExpression(BoolLiteral(equals(false))));
+ StatementMatcher Conditional = conditionalOperator(
+ 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));
- StatementMatcher ConditionalFalse = ConditionalOperator(
- hasFalseExpression(BoolLiteral(equals(false))));
+ StatementMatcher ConditionalFalse = conditionalOperator(
+ hasFalseExpression(boolLiteral(equals(false))));
EXPECT_TRUE(matches("void x() { true ? true : false; }", ConditionalFalse));
EXPECT_TRUE(
@@ -1404,81 +1404,81 @@
TEST(Matcher, HasNameSupportsNamespaces) {
EXPECT_TRUE(matches("namespace a { namespace b { class C; } }",
- Class(hasName("a::b::C"))));
+ record(hasName("a::b::C"))));
EXPECT_TRUE(matches("namespace a { namespace b { class C; } }",
- Class(hasName("::a::b::C"))));
+ record(hasName("::a::b::C"))));
EXPECT_TRUE(matches("namespace a { namespace b { class C; } }",
- Class(hasName("b::C"))));
+ record(hasName("b::C"))));
EXPECT_TRUE(matches("namespace a { namespace b { class C; } }",
- Class(hasName("C"))));
+ record(hasName("C"))));
EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
- Class(hasName("c::b::C"))));
+ record(hasName("c::b::C"))));
EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
- Class(hasName("a::c::C"))));
+ record(hasName("a::c::C"))));
EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
- Class(hasName("a::b::A"))));
+ record(hasName("a::b::A"))));
EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
- Class(hasName("::C"))));
+ record(hasName("::C"))));
EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
- Class(hasName("::b::C"))));
+ record(hasName("::b::C"))));
EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
- Class(hasName("z::a::b::C"))));
+ record(hasName("z::a::b::C"))));
EXPECT_TRUE(notMatches("namespace a { namespace b { class C; } }",
- Class(hasName("a+b::C"))));
+ record(hasName("a+b::C"))));
EXPECT_TRUE(notMatches("namespace a { namespace b { class AC; } }",
- Class(hasName("C"))));
+ record(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; }; };", record(hasName("A::B::C"))));
EXPECT_TRUE(
matches("class A { class B { class C; }; };",
- Class(hasName("::A::B::C"))));
+ record(hasName("::A::B::C"))));
EXPECT_TRUE(
- matches("class A { class B { class C; }; };", Class(hasName("B::C"))));
+ matches("class A { class B { class C; }; };", record(hasName("B::C"))));
EXPECT_TRUE(
- matches("class A { class B { class C; }; };", Class(hasName("C"))));
+ matches("class A { class B { class C; }; };", record(hasName("C"))));
EXPECT_TRUE(
notMatches("class A { class B { class C; }; };",
- Class(hasName("c::B::C"))));
+ record(hasName("c::B::C"))));
EXPECT_TRUE(
notMatches("class A { class B { class C; }; };",
- Class(hasName("A::c::C"))));
+ record(hasName("A::c::C"))));
EXPECT_TRUE(
notMatches("class A { class B { class C; }; };",
- Class(hasName("A::B::A"))));
+ record(hasName("A::B::A"))));
EXPECT_TRUE(
- notMatches("class A { class B { class C; }; };", Class(hasName("::C"))));
+ notMatches("class A { class B { class C; }; };", record(hasName("::C"))));
EXPECT_TRUE(
notMatches("class A { class B { class C; }; };",
- Class(hasName("::B::C"))));
+ record(hasName("::B::C"))));
EXPECT_TRUE(notMatches("class A { class B { class C; }; };",
- Class(hasName("z::A::B::C"))));
+ record(hasName("z::A::B::C"))));
EXPECT_TRUE(
notMatches("class A { class B { class C; }; };",
- Class(hasName("A+B::C"))));
+ record(hasName("A+B::C"))));
}
TEST(Matcher, IsDefinition) {
DeclarationMatcher DefinitionOfClassA =
- Class(hasName("A"), isDefinition());
+ record(hasName("A"), isDefinition());
EXPECT_TRUE(matches("class A {};", DefinitionOfClassA));
EXPECT_TRUE(notMatches("class A;", DefinitionOfClassA));
DeclarationMatcher DefinitionOfVariableA =
- Variable(hasName("a"), isDefinition());
+ variable(hasName("a"), isDefinition());
EXPECT_TRUE(matches("int a;", DefinitionOfVariableA));
EXPECT_TRUE(notMatches("extern int a;", DefinitionOfVariableA));
DeclarationMatcher DefinitionOfMethodA =
- Method(hasName("a"), isDefinition());
+ method(hasName("a"), isDefinition());
EXPECT_TRUE(matches("class A { void a() {} };", DefinitionOfMethodA));
EXPECT_TRUE(notMatches("class A { void a(); };", DefinitionOfMethodA));
}
TEST(Matcher, OfClass) {
- StatementMatcher Constructor = ConstructorCall(hasDeclaration(Method(
+ StatementMatcher Constructor = constructorCall(hasDeclaration(method(
ofClass(hasName("X")))));
EXPECT_TRUE(
@@ -1495,7 +1495,7 @@
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"))))));
+ "void f() { B<A> b; b.y(); }", call(callee(method(hasName("x"))))));
EXPECT_TRUE(matches(
"class A { public: void x(); };"
@@ -1505,8 +1505,8 @@
"};"
"void f() {"
" C::B<A> b; b.y();"
- "}", Class(hasName("C"),
- hasDescendant(Call(callee(Method(hasName("x"))))))));
+ "}", record(hasName("C"),
+ hasDescendant(call(callee(method(hasName("x"))))))));
}
// For testing AST_MATCHER_P().
@@ -1517,7 +1517,7 @@
}
TEST(AstMatcherPMacro, Works) {
- DeclarationMatcher HasClassB = just(has(id("b", Class(hasName("B")))));
+ DeclarationMatcher HasClassB = just(has(id("b", record(hasName("B")))));
EXPECT_TRUE(matchAndVerifyResultTrue("class A { class B {}; };",
HasClassB, new VerifyIdIsBoundToDecl<clang::Decl>("b")));
@@ -1542,7 +1542,7 @@
}
TEST(AstPolymorphicMatcherPMacro, Works) {
- DeclarationMatcher HasClassB = polymorphicHas(id("b", Class(hasName("B"))));
+ DeclarationMatcher HasClassB = polymorphicHas(id("b", record(hasName("B"))));
EXPECT_TRUE(matchAndVerifyResultTrue("class A { class B {}; };",
HasClassB, new VerifyIdIsBoundToDecl<clang::Decl>("b")));
@@ -1554,39 +1554,39 @@
HasClassB, new VerifyIdIsBoundToDecl<clang::Decl>("b")));
StatementMatcher StatementHasClassB =
- polymorphicHas(Class(hasName("B")));
+ polymorphicHas(record(hasName("B")));
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(;;); }", forStmt()));
+ EXPECT_TRUE(matches("void f() { if(true) for(;;); }", forStmt()));
}
TEST(For, ReportsNoFalsePositives) {
- EXPECT_TRUE(notMatches("void f() { ; }", For()));
- EXPECT_TRUE(notMatches("void f() { if(true); }", For()));
+ EXPECT_TRUE(notMatches("void f() { ; }", forStmt()));
+ EXPECT_TRUE(notMatches("void f() { if(true); }", forStmt()));
}
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 {}; }",
- CompoundStatement()));
+ compoundStatement()));
EXPECT_TRUE(matches("namespace n { struct S { void f() {{}} }; }",
- CompoundStatement()));
+ compoundStatement()));
}
TEST(HasBody, FindsBodyOfForLoop) {
StatementMatcher HasCompoundStatementBody =
- For(hasBody(CompoundStatement()));
+ forStmt(hasBody(compoundStatement()));
EXPECT_TRUE(matches("void f() { for(;;) {} }",
HasCompoundStatementBody));
EXPECT_TRUE(notMatches("void f() { for(;;); }",
@@ -1598,67 +1598,67 @@
// definition, and the function body itself must be a compound
// statement.
EXPECT_TRUE(matches("void f() { for (;;); }",
- CompoundStatement(hasAnySubstatement(For()))));
+ compoundStatement(hasAnySubstatement(forStmt()))));
}
TEST(HasAnySubstatement, IsNotRecursive) {
// It's really "has any immediate substatement".
EXPECT_TRUE(notMatches("void f() { if (true) for (;;); }",
- CompoundStatement(hasAnySubstatement(For()))));
+ compoundStatement(hasAnySubstatement(forStmt()))));
}
TEST(HasAnySubstatement, MatchesInNestedCompoundStatements) {
EXPECT_TRUE(matches("void f() { if (true) { for (;;); } }",
- CompoundStatement(hasAnySubstatement(For()))));
+ compoundStatement(hasAnySubstatement(forStmt()))));
}
TEST(HasAnySubstatement, FindsSubstatementBetweenOthers) {
EXPECT_TRUE(matches("void f() { 1; 2; 3; for (;;); 4; 5; 6; }",
- CompoundStatement(hasAnySubstatement(For()))));
+ compoundStatement(hasAnySubstatement(forStmt()))));
}
TEST(StatementCountIs, FindsNoStatementsInAnEmptyCompoundStatement) {
EXPECT_TRUE(matches("void f() { }",
- CompoundStatement(statementCountIs(0))));
+ compoundStatement(statementCountIs(0))));
EXPECT_TRUE(notMatches("void f() {}",
- CompoundStatement(statementCountIs(1))));
+ compoundStatement(statementCountIs(1))));
}
TEST(StatementCountIs, AppearsToMatchOnlyOneCount) {
EXPECT_TRUE(matches("void f() { 1; }",
- CompoundStatement(statementCountIs(1))));
+ compoundStatement(statementCountIs(1))));
EXPECT_TRUE(notMatches("void f() { 1; }",
- CompoundStatement(statementCountIs(0))));
+ compoundStatement(statementCountIs(0))));
EXPECT_TRUE(notMatches("void f() { 1; }",
- CompoundStatement(statementCountIs(2))));
+ compoundStatement(statementCountIs(2))));
}
TEST(StatementCountIs, WorksWithMultipleStatements) {
EXPECT_TRUE(matches("void f() { 1; 2; 3; }",
- CompoundStatement(statementCountIs(3))));
+ compoundStatement(statementCountIs(3))));
}
TEST(StatementCountIs, WorksWithNestedCompoundStatements) {
EXPECT_TRUE(matches("void f() { { 1; } { 1; 2; 3; 4; } }",
- CompoundStatement(statementCountIs(1))));
+ compoundStatement(statementCountIs(1))));
EXPECT_TRUE(matches("void f() { { 1; } { 1; 2; 3; 4; } }",
- CompoundStatement(statementCountIs(2))));
+ compoundStatement(statementCountIs(2))));
EXPECT_TRUE(notMatches("void f() { { 1; } { 1; 2; 3; 4; } }",
- CompoundStatement(statementCountIs(3))));
+ compoundStatement(statementCountIs(3))));
EXPECT_TRUE(matches("void f() { { 1; } { 1; 2; 3; 4; } }",
- CompoundStatement(statementCountIs(4))));
+ compoundStatement(statementCountIs(4))));
}
TEST(Member, WorksInSimplestCase) {
EXPECT_TRUE(matches("struct { int first; } s; int i(s.first);",
- MemberExpression(member(hasName("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);",
- MemberExpression(member(hasName("first")))));
+ memberExpression(member(hasName("first")))));
}
TEST(Member, MatchesInMemberFunctionCall) {
@@ -1666,220 +1666,220 @@
" struct { void first() {}; } s;"
" s.first();"
"};",
- MemberExpression(member(hasName("first")))));
+ memberExpression(member(hasName("first")))));
}
TEST(HasObjectExpression, DoesNotMatchMember) {
EXPECT_TRUE(notMatches(
"class X {}; struct Z { X m; }; void f(Z z) { z.m; }",
- MemberExpression(hasObjectExpression(hasType(Class(hasName("X")))))));
+ memberExpression(hasObjectExpression(hasType(record(hasName("X")))))));
}
TEST(HasObjectExpression, MatchesBaseOfVariable) {
EXPECT_TRUE(matches(
"struct X { int m; }; void f(X x) { x.m; }",
- MemberExpression(hasObjectExpression(hasType(Class(hasName("X")))))));
+ memberExpression(hasObjectExpression(hasType(record(hasName("X")))))));
EXPECT_TRUE(matches(
"struct X { int m; }; void f(X* x) { x->m; }",
- MemberExpression(hasObjectExpression(
- hasType(pointsTo(Class(hasName("X"))))))));
+ memberExpression(hasObjectExpression(
+ hasType(pointsTo(record(hasName("X"))))))));
}
TEST(HasObjectExpression,
MatchesObjectExpressionOfImplicitlyFormedMemberExpression) {
EXPECT_TRUE(matches(
"class X {}; struct S { X m; void f() { this->m; } };",
- MemberExpression(hasObjectExpression(
- hasType(pointsTo(Class(hasName("S"))))))));
+ memberExpression(hasObjectExpression(
+ hasType(pointsTo(record(hasName("S"))))))));
EXPECT_TRUE(matches(
"class X {}; struct S { X m; void f() { m; } };",
- MemberExpression(hasObjectExpression(
- hasType(pointsTo(Class(hasName("S"))))))));
+ memberExpression(hasObjectExpression(
+ hasType(pointsTo(record(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;",
- Variable(hasType(isConstQualified()))));
+ variable(hasType(isConstQualified()))));
}
TEST(IsConstQualified, MatchesConstPointer) {
EXPECT_TRUE(matches("int i = 42; int* const p(&i);",
- Variable(hasType(isConstQualified()))));
+ variable(hasType(isConstQualified()))));
}
TEST(IsConstQualified, MatchesThroughTypedef) {
EXPECT_TRUE(matches("typedef const int const_int; const_int i = 42;",
- Variable(hasType(isConstQualified()))));
+ variable(hasType(isConstQualified()))));
EXPECT_TRUE(matches("typedef int* int_ptr; const int_ptr p(0);",
- Variable(hasType(isConstQualified()))));
+ variable(hasType(isConstQualified()))));
}
TEST(IsConstQualified, DoesNotMatchInappropriately) {
EXPECT_TRUE(notMatches("typedef int nonconst_int; nonconst_int i = 42;",
- Variable(hasType(isConstQualified()))));
+ variable(hasType(isConstQualified()))));
EXPECT_TRUE(notMatches("int const* p;",
- Variable(hasType(isConstQualified()))));
+ variable(hasType(isConstQualified()))));
}
TEST(ReinterpretCast, MatchesSimpleCase) {
EXPECT_TRUE(matches("char* p = reinterpret_cast<char*>(&p);",
- Expression(ReinterpretCast())));
+ expression(reinterpretCast())));
}
TEST(ReinterpretCast, DoesNotMatchOtherCasts) {
EXPECT_TRUE(notMatches("char* p = (char*)(&p);",
- Expression(ReinterpretCast())));
+ expression(reinterpretCast())));
EXPECT_TRUE(notMatches("char q, *p = const_cast<char*>(&q);",
- Expression(ReinterpretCast())));
+ expression(reinterpretCast())));
EXPECT_TRUE(notMatches("void* p = static_cast<void*>(&p);",
- Expression(ReinterpretCast())));
+ expression(reinterpretCast())));
EXPECT_TRUE(notMatches("struct B { virtual ~B() {} }; struct D : B {};"
"B b;"
"D* p = dynamic_cast<D*>(&b);",
- Expression(ReinterpretCast())));
+ expression(reinterpretCast())));
}
TEST(FunctionalCast, MatchesSimpleCase) {
std::string foo_class = "class Foo { public: Foo(char*); };";
EXPECT_TRUE(matches(foo_class + "void r() { Foo f = Foo(\"hello world\"); }",
- Expression(FunctionalCast())));
+ expression(functionalCast())));
}
TEST(FunctionalCast, DoesNotMatchOtherCasts) {
std::string FooClass = "class Foo { public: Foo(char*); };";
EXPECT_TRUE(
notMatches(FooClass + "void r() { Foo f = (Foo) \"hello world\"; }",
- Expression(FunctionalCast())));
+ expression(functionalCast())));
EXPECT_TRUE(
notMatches(FooClass + "void r() { Foo f = \"hello world\"; }",
- Expression(FunctionalCast())));
+ expression(functionalCast())));
}
TEST(DynamicCast, MatchesSimpleCase) {
EXPECT_TRUE(matches("struct B { virtual ~B() {} }; struct D : B {};"
"B b;"
"D* p = dynamic_cast<D*>(&b);",
- Expression(DynamicCast())));
+ expression(dynamicCast())));
}
TEST(StaticCast, MatchesSimpleCase) {
EXPECT_TRUE(matches("void* p(static_cast<void*>(&p));",
- Expression(StaticCast())));
+ expression(staticCast())));
}
TEST(StaticCast, DoesNotMatchOtherCasts) {
EXPECT_TRUE(notMatches("char* p = (char*)(&p);",
- Expression(StaticCast())));
+ expression(staticCast())));
EXPECT_TRUE(notMatches("char q, *p = const_cast<char*>(&q);",
- Expression(StaticCast())));
+ expression(staticCast())));
EXPECT_TRUE(notMatches("void* p = reinterpret_cast<char*>(&p);",
- Expression(StaticCast())));
+ expression(staticCast())));
EXPECT_TRUE(notMatches("struct B { virtual ~B() {} }; struct D : B {};"
"B b;"
"D* p = dynamic_cast<D*>(&b);",
- Expression(StaticCast())));
+ expression(staticCast())));
}
TEST(HasDestinationType, MatchesSimpleCase) {
EXPECT_TRUE(matches("char* p = static_cast<char*>(0);",
- Expression(
- StaticCast(hasDestinationType(
+ expression(
+ staticCast(hasDestinationType(
pointsTo(TypeMatcher(anything())))))));
}
TEST(HasSourceExpression, MatchesSimpleCase) {
EXPECT_TRUE(matches("class string {}; class URL { public: URL(string s); };"
"void r() {string a_string; URL url = a_string; }",
- Expression(ImplicitCast(
- hasSourceExpression(ConstructorCall())))));
+ 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() {}", whileStmt()));
+ EXPECT_TRUE(matches("void x() { while(true); }", whileStmt()));
+ EXPECT_TRUE(notMatches("void x() { do {} while(true); }", whileStmt()));
}
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); }", doStmt()));
+ EXPECT_TRUE(matches("void x() { do ; while(false); }", doStmt()));
}
TEST(Do, DoesNotMatchWhileLoops) {
- EXPECT_TRUE(notMatches("void x() { while(true) {} }", Do()));
+ EXPECT_TRUE(notMatches("void x() { while(true) {} }", doStmt()));
}
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(
"void x() { if(true) {} }",
- If(hasConditionVariableStatement(DeclarationStatement()))));
+ ifStmt(hasConditionVariableStatement(declarationStatement()))));
EXPECT_TRUE(notMatches(
"void x() { int x; if((x = 42)) {} }",
- If(hasConditionVariableStatement(DeclarationStatement()))));
+ ifStmt(hasConditionVariableStatement(declarationStatement()))));
}
TEST(HasConditionVariableStatement, MatchesConditionVariables) {
EXPECT_TRUE(matches(
"void x() { if(int* a = 0) {} }",
- If(hasConditionVariableStatement(DeclarationStatement()))));
+ ifStmt(hasConditionVariableStatement(declarationStatement()))));
}
TEST(ForEach, BindsOneNode) {
EXPECT_TRUE(matchAndVerifyResultTrue("class C { int x; };",
- Class(hasName("C"), forEach(id("x", Field(hasName("x"))))),
+ record(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()))),
+ record(hasName("C"), forEach(id("f", field()))),
new VerifyIdIsBoundToDecl<clang::FieldDecl>("f", 3)));
}
TEST(ForEach, BindsRecursiveCombinations) {
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()))))),
+ record(hasName("C"), forEach(record(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"))))),
+ record(hasName("C"), forEachDescendant(id("x", field(hasName("x"))))),
new VerifyIdIsBoundToDecl<clang::FieldDecl>("x", 1)));
}
@@ -1887,7 +1887,7 @@
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()))),
+ record(hasName("C"), forEachDescendant(id("f", field()))),
new VerifyIdIsBoundToDecl<clang::FieldDecl>("f", 4)));
}
@@ -1895,8 +1895,8 @@
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()))))),
+ record(hasName("C"), forEachDescendant(record(
+ forEachDescendant(id("f", field()))))),
new VerifyIdIsBoundToDecl<clang::FieldDecl>("f", 8)));
}
@@ -1907,18 +1907,18 @@
EXPECT_TRUE(matches(
"template <typename T> class X {}; class A {}; X<A> x;",
- Class(hasName("::X"), isTemplateInstantiation())));
+ record(hasName("::X"), isTemplateInstantiation())));
EXPECT_TRUE(matches(
"template <typename T> class X { T t; }; class A {}; X<A> x;",
- Class(isTemplateInstantiation(), hasDescendant(
- Field(hasType(Class(hasName("A"))))))));
+ record(isTemplateInstantiation(), hasDescendant(
+ field(hasType(record(hasName("A"))))))));
}
TEST(IsTemplateInstantiation, MatchesImplicitFunctionTemplateInstantiation) {
EXPECT_TRUE(matches(
"template <typename T> void f(T t) {} class A {}; void g() { f(A()); }",
- Function(hasParameter(0, hasType(Class(hasName("A")))),
+ function(hasParameter(0, hasType(record(hasName("A")))),
isTemplateInstantiation())));
}
@@ -1926,8 +1926,8 @@
EXPECT_TRUE(matches(
"template <typename T> class X { T t; }; class A {};"
"template class X<A>;",
- Class(isTemplateInstantiation(), hasDescendant(
- Field(hasType(Class(hasName("A"))))))));
+ record(isTemplateInstantiation(), hasDescendant(
+ field(hasType(record(hasName("A"))))))));
}
TEST(IsTemplateInstantiation,
@@ -1935,7 +1935,7 @@
EXPECT_TRUE(matches(
"template <typename T> class X {};"
"template <typename T> class X<T*> {}; class A {}; X<A*> x;",
- Class(hasName("::X"), isTemplateInstantiation())));
+ record(hasName("::X"), isTemplateInstantiation())));
}
TEST(IsTemplateInstantiation,
@@ -1946,7 +1946,7 @@
" template <typename U> class Y { U u; };"
" Y<A> y;"
"};",
- Class(hasName("::X::Y"), isTemplateInstantiation())));
+ record(hasName("::X::Y"), isTemplateInstantiation())));
}
TEST(IsTemplateInstantiation, DoesNotMatchInstantiationsInsideOfInstantiation) {
@@ -1959,20 +1959,20 @@
" template <typename U> class Y { U u; };"
" Y<T> y;"
"}; X<A> x;",
- Class(hasName("::X<A>::Y"), unless(isTemplateInstantiation()))));
+ record(hasName("::X<A>::Y"), unless(isTemplateInstantiation()))));
}
TEST(IsTemplateInstantiation, DoesNotMatchExplicitClassTemplateSpecialization) {
EXPECT_TRUE(notMatches(
"template <typename T> class X {}; class A {};"
"template <> class X<A> {}; X<A> x;",
- Class(hasName("::X"), isTemplateInstantiation())));
+ record(hasName("::X"), isTemplateInstantiation())));
}
TEST(IsTemplateInstantiation, DoesNotMatchNonTemplate) {
EXPECT_TRUE(notMatches(
"class A {}; class Y { A a; };",
- Class(isTemplateInstantiation())));
+ record(isTemplateInstantiation())));
}
} // end namespace ast_matchers
Modified: cfe/branches/tooling/unittests/ASTMatchers/Dynamic/GenericMatcherTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/unittests/ASTMatchers/Dynamic/GenericMatcherTest.cpp?rev=159551&r1=159550&r2=159551&view=diff
==============================================================================
--- cfe/branches/tooling/unittests/ASTMatchers/Dynamic/GenericMatcherTest.cpp (original)
+++ cfe/branches/tooling/unittests/ASTMatchers/Dynamic/GenericMatcherTest.cpp Mon Jul 2 14:22:34 2012
@@ -32,24 +32,24 @@
TEST(GeneicMatcherTest, SingleNode) {
EXPECT_TRUE(matchesGeneric("class X {};",
- GenericMatcher(Class(hasName("X")))));
- EXPECT_TRUE(matchesGeneric("int x;", GenericMatcher(Variable())));
+ GenericMatcher(record(hasName("X")))));
+ EXPECT_TRUE(matchesGeneric("int x;", GenericMatcher(variable())));
EXPECT_TRUE(matchesGeneric("int foo() { return 1 + 1; }",
- GenericMatcher(Function())));
+ GenericMatcher(function())));
- EXPECT_FALSE(matchesGeneric("int x;", GenericMatcher(Function())));
+ EXPECT_FALSE(matchesGeneric("int x;", GenericMatcher(function())));
EXPECT_FALSE(matchesGeneric("int foo() { return 1 + 1; }",
- GenericMatcher(DeclarationReference())));
+ GenericMatcher(declarationReference())));
}
TEST(GeneicMatcherTest, AnyOf) {
- GenericMatcher Generic(Class(hasName("X")));
+ GenericMatcher Generic(record(hasName("X")));
EXPECT_TRUE(matchesGeneric("class X {};", Generic));
EXPECT_FALSE(matchesGeneric("int x;", Generic));
EXPECT_FALSE(matchesGeneric("int foo() { return 1 + 1; }", Generic));
- Generic = GenericMatcher::anyOf(Generic, Variable());
+ Generic = GenericMatcher::anyOf(Generic, variable());
EXPECT_TRUE(matchesGeneric("class X {};", Generic));
EXPECT_TRUE(matchesGeneric("int x;", Generic));
@@ -57,7 +57,7 @@
// We can mix different types of matchers (statements and declarations)
Generic = GenericMatcher::anyOf(Generic,
- BinaryOperator(hasOperatorName("+")));
+ binaryOperator(hasOperatorName("+")));
EXPECT_TRUE(matchesGeneric("class X {};", Generic));
EXPECT_TRUE(matchesGeneric("int x;", Generic));
@@ -65,7 +65,7 @@
}
TEST(GeneicMatcherTest, AllOf) {
- GenericMatcher Generic(BinaryOperator(hasOperatorName("+")));
+ GenericMatcher Generic(binaryOperator(hasOperatorName("+")));
EXPECT_TRUE(matchesGeneric("int i = 1 + 1;", Generic));
EXPECT_TRUE(matchesGeneric("int i = 2 + 1;", Generic));
@@ -74,7 +74,7 @@
Generic = GenericMatcher::allOf(
Generic,
- BinaryOperator(hasLHS(IntegerLiteral(equals(1)))));
+ binaryOperator(hasLHS(integerLiteral(equals(1)))));
EXPECT_TRUE( matchesGeneric("int i = 1 + 1;", Generic));
EXPECT_FALSE(matchesGeneric("int i = 2 + 1;", Generic));
@@ -83,14 +83,14 @@
Generic = GenericMatcher::allOf(
Generic,
- BinaryOperator(hasRHS(IntegerLiteral(equals(3)))));
+ binaryOperator(hasRHS(integerLiteral(equals(3)))));
EXPECT_FALSE(matchesGeneric("int i = 1 + 1;", Generic));
EXPECT_FALSE(matchesGeneric("int i = 2 + 1;", Generic));
EXPECT_TRUE( matchesGeneric("int i = 1 + 3;", Generic));
EXPECT_FALSE(matchesGeneric("void foo() { }", Generic));
- Generic = GenericMatcher::allOf(Generic, Function());
+ Generic = GenericMatcher::allOf(Generic, function());
// Now nothing matches. Not even the function one because it is an AllOf().
EXPECT_FALSE(matchesGeneric("int i = 1 + 1;", Generic));
Modified: cfe/branches/tooling/unittests/ASTMatchers/Dynamic/GenericValueTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/unittests/ASTMatchers/Dynamic/GenericValueTest.cpp?rev=159551&r1=159550&r2=159551&view=diff
==============================================================================
--- cfe/branches/tooling/unittests/ASTMatchers/Dynamic/GenericValueTest.cpp (original)
+++ cfe/branches/tooling/unittests/ASTMatchers/Dynamic/GenericValueTest.cpp Mon Jul 2 14:22:34 2012
@@ -68,7 +68,7 @@
}
TEST(GenericValueTest, GenericMatcher) {
- GenericValue Value = Statement();
+ GenericValue Value = statement();
EXPECT_FALSE(Value.is< ::std::string>());
EXPECT_FALSE(Value.is<GenericError>());
@@ -85,12 +85,12 @@
// Conversion to any type of matcher works.
// If they are not compatible it would just return a matcher that matches
// nothing. That is tested in GenericMatcher's unittest.
- Value = GenericMatcher(Class());
+ Value = GenericMatcher(record());
EXPECT_TRUE(Value.is<GenericMatcher>());
EXPECT_TRUE(Value.is<Matcher<clang::Decl> >());
EXPECT_TRUE(Value.is<Matcher<clang::UnaryOperator> >());
- Value = GenericMatcher(UnaryOperator());
+ Value = GenericMatcher(unaryOperator());
EXPECT_TRUE(Value.is<GenericMatcher>());
EXPECT_TRUE(Value.is<Matcher<clang::Decl> >());
EXPECT_TRUE(Value.is<Matcher<clang::Stmt> >());
@@ -137,7 +137,7 @@
EXPECT_TRUE(Value.is<GenericError>());
EXPECT_EQ("foo", Value.get<GenericError>().Message);
- Value = GenericMatcher(Class());
+ Value = GenericMatcher(record());
EXPECT_FALSE(Value.is<bool>());
EXPECT_TRUE(Value.is<GenericMatcher>());
EXPECT_TRUE(Value.is<Matcher<clang::Decl> >());
Modified: cfe/branches/tooling/unittests/ASTMatchers/Dynamic/ParserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/unittests/ASTMatchers/Dynamic/ParserTest.cpp?rev=159551&r1=159550&r2=159551&view=diff
==============================================================================
--- cfe/branches/tooling/unittests/ASTMatchers/Dynamic/ParserTest.cpp (original)
+++ cfe/branches/tooling/unittests/ASTMatchers/Dynamic/ParserTest.cpp Mon Jul 2 14:22:34 2012
@@ -195,15 +195,15 @@
TEST(ParserTest, FullParserTest) {
RealProcessor Processor;
const GenericValue Value = Parser::parseMatcher(
- "BinaryOperator( hasOperatorName(\"+\"),\n"
- " hasLHS(IntegerLiteral(Equals(1))))", &Processor);
+ "binaryOperator( hasOperatorName(\"+\"),\n"
+ " hasLHS(integerLiteral(Equals(1))))", &Processor);
EXPECT_TRUE(matchesGeneric("int x = 1 + 1;", Value));
EXPECT_FALSE(matchesGeneric("int x = 2 + 1;", Value));
const GenericValue Error = Parser::parseMatcher(
- "BinaryOperator( hasOperatorName(6),\n"
- " hasLHS(IntegerLiteral(Equals(1))))", &Processor);
- EXPECT_EQ("Error parsing argument 0 for matcher BinaryOperator: "
+ "binaryOperator( hasOperatorName(6),\n"
+ " hasLHS(integerLiteral(Equals(1))))", &Processor);
+ EXPECT_EQ("Error parsing argument 0 for matcher binaryOperator: "
"Error building matcher hasOperatorName: "
"Incorrect type on function hasOperatorName for arg 0",
Error.get<GenericError>().Message);
Modified: cfe/branches/tooling/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/unittests/ASTMatchers/Dynamic/RegistryTest.cpp?rev=159551&r1=159550&r2=159551&view=diff
==============================================================================
--- cfe/branches/tooling/unittests/ASTMatchers/Dynamic/RegistryTest.cpp (original)
+++ cfe/branches/tooling/unittests/ASTMatchers/Dynamic/RegistryTest.cpp Mon Jul 2 14:22:34 2012
@@ -60,7 +60,7 @@
TEST(RegistryTest, CanConstructNoArgs) {
const GenericValue IsArrowValue = constructMatcher("isArrow");
- const GenericValue BoolValue = constructMatcher("BoolLiteral");
+ const GenericValue BoolValue = constructMatcher("boolLiteral");
const std::string ClassSnippet =
"struct Foo { int x; };\n"
@@ -80,24 +80,24 @@
EXPECT_FALSE(matchesGeneric("int x;", Value));
}
-TEST(RegistryTest, ContructWithMatcherArgs) {
+TEST(RegistryTest, ConstructWithMatcherArgs) {
const GenericValue OperatorPlus =
constructMatcher("hasOperatorName", std::string("+"));
const GenericValue OperatorMinus =
constructMatcher("hasOperatorName", std::string("-"));
const GenericValue One =
- constructMatcher("IntegerLiteral", constructMatcher("Equals", 1));
+ constructMatcher("integerLiteral", constructMatcher("Equals", 1));
const GenericValue HasLHSOne = constructMatcher("hasLHS", One);
const GenericValue OnePlus =
- constructMatcher("BinaryOperator", OperatorPlus, HasLHSOne);
+ constructMatcher("binaryOperator", OperatorPlus, HasLHSOne);
const GenericValue JustPlus =
- constructMatcher("BinaryOperator", OperatorPlus);
+ constructMatcher("binaryOperator", OperatorPlus);
const GenericValue OneMinus =
- constructMatcher("BinaryOperator", OperatorMinus, HasLHSOne);
+ constructMatcher("binaryOperator", OperatorMinus, HasLHSOne);
const GenericValue JustMinus =
- constructMatcher("BinaryOperator", OperatorMinus);
+ constructMatcher("binaryOperator", OperatorMinus);
EXPECT_TRUE( matchesGeneric("int i = 1 + 1;", OnePlus));
EXPECT_TRUE( matchesGeneric("int i = 1 + 1;", JustPlus));
@@ -130,8 +130,8 @@
GenericValue BadArgType = constructMatcher("ofClass", true);
EXPECT_EQ("Incorrect type on function ofClass for arg 0",
BadArgType.get<GenericError>().Message);
- BadArgType = constructMatcher("Class", Class(), 3);
- EXPECT_EQ("Incorrect type on function Class for arg 1",
+ BadArgType = constructMatcher("record", record(), 3);
+ EXPECT_EQ("Incorrect type on function record for arg 1",
BadArgType.get<GenericError>().Message);
}
More information about the llvm-branch-commits
mailing list