summaryrefslogtreecommitdiffstats
path: root/clang/unittests
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2019-09-25 14:50:12 +0000
committerIlya Biryukov <ibiryukov@google.com>2019-09-25 14:50:12 +0000
commit71472a3eeceb9ea513a1d3c672fc2e47d77cc741 (patch)
tree6008a87735cf52c6cffd3eb416a998b90044745e /clang/unittests
parenta1639b9bba7cc6ef32a6a0c4db4f98301b91f6be (diff)
downloadbcm5719-llvm-71472a3eeceb9ea513a1d3c672fc2e47d77cc741.tar.gz
bcm5719-llvm-71472a3eeceb9ea513a1d3c672fc2e47d77cc741.zip
Revert r372863: [AST] Extract Decl::printNestedNameSpecifier helper from Decl::printQualifiedName
Reason: causes a test failure, will investigate and re-land with a fix. llvm-svn: 372880
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/AST/NamedDeclPrinterTest.cpp70
1 files changed, 12 insertions, 58 deletions
diff --git a/clang/unittests/AST/NamedDeclPrinterTest.cpp b/clang/unittests/AST/NamedDeclPrinterTest.cpp
index a5c3e19055f..a50626517f6 100644
--- a/clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ b/clang/unittests/AST/NamedDeclPrinterTest.cpp
@@ -16,12 +16,9 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/ASTContext.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/PrettyPrinter.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/SmallString.h"
-#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
using namespace clang;
@@ -33,12 +30,11 @@ namespace {
class PrintMatch : public MatchFinder::MatchCallback {
SmallString<1024> Printed;
unsigned NumFoundDecls;
- std::function<void(llvm::raw_ostream &OS, const NamedDecl *)> Printer;
+ bool SuppressUnwrittenScope;
public:
- explicit PrintMatch(
- std::function<void(llvm::raw_ostream &OS, const NamedDecl *)> Printer)
- : NumFoundDecls(0), Printer(std::move(Printer)) {}
+ explicit PrintMatch(bool suppressUnwrittenScope)
+ : NumFoundDecls(0), SuppressUnwrittenScope(suppressUnwrittenScope) {}
void run(const MatchFinder::MatchResult &Result) override {
const NamedDecl *ND = Result.Nodes.getNodeAs<NamedDecl>("id");
@@ -49,7 +45,9 @@ public:
return;
llvm::raw_svector_ostream Out(Printed);
- Printer(Out, ND);
+ PrintingPolicy Policy = Result.Context->getPrintingPolicy();
+ Policy.SuppressUnwrittenScope = SuppressUnwrittenScope;
+ ND->printQualifiedName(Out, Policy);
}
StringRef getPrinted() const {
@@ -61,12 +59,12 @@ public:
}
};
-::testing::AssertionResult PrintedDeclMatches(
- StringRef Code, const std::vector<std::string> &Args,
- const DeclarationMatcher &NodeMatch, StringRef ExpectedPrinted,
- StringRef FileName,
- std::function<void(llvm::raw_ostream &, const NamedDecl *)> Print) {
- PrintMatch Printer(std::move(Print));
+::testing::AssertionResult
+PrintedNamedDeclMatches(StringRef Code, const std::vector<std::string> &Args,
+ bool SuppressUnwrittenScope,
+ const DeclarationMatcher &NodeMatch,
+ StringRef ExpectedPrinted, StringRef FileName) {
+ PrintMatch Printer(SuppressUnwrittenScope);
MatchFinder Finder;
Finder.addMatcher(NodeMatch, &Printer);
std::unique_ptr<FrontendActionFactory> Factory =
@@ -94,21 +92,6 @@ public:
}
::testing::AssertionResult
-PrintedNamedDeclMatches(StringRef Code, const std::vector<std::string> &Args,
- bool SuppressUnwrittenScope,
- const DeclarationMatcher &NodeMatch,
- StringRef ExpectedPrinted, StringRef FileName) {
- return PrintedDeclMatches(Code, Args, NodeMatch, ExpectedPrinted, FileName,
- [=](llvm::raw_ostream &Out, const NamedDecl *ND) {
- auto Policy =
- ND->getASTContext().getPrintingPolicy();
- Policy.SuppressUnwrittenScope =
- SuppressUnwrittenScope;
- ND->printQualifiedName(Out, Policy);
- });
-}
-
-::testing::AssertionResult
PrintedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
StringRef ExpectedPrinted) {
std::vector<std::string> Args(1, "-std=c++98");
@@ -144,17 +127,6 @@ PrintedWrittenPropertyDeclObjCMatches(StringRef Code, StringRef DeclName,
"input.m");
}
-::testing::AssertionResult
-PrintedNestedNameSpecifierMatches(StringRef Code, StringRef DeclName,
- StringRef ExpectedPrinted) {
- std::vector<std::string> Args{"-std=c++11"};
- return PrintedDeclMatches(Code, Args, namedDecl(hasName(DeclName)).bind("id"),
- ExpectedPrinted, "input.cc",
- [](llvm::raw_ostream &Out, const NamedDecl *D) {
- D->printNestedNameSpecifier(Out);
- });
-}
-
} // unnamed namespace
TEST(NamedDeclPrinter, TestNamespace1) {
@@ -251,21 +223,3 @@ R"(
"property",
"Obj::property"));
}
-
-TEST(NamedDeclPrinter, NestedNameSpecifierSimple) {
- const char *Code =
- R"(
- namespace foo { namespace bar { void func(); } }
-)";
- ASSERT_TRUE(PrintedNestedNameSpecifierMatches(Code, "func", "foo::bar::"));
-}
-
-TEST(NamedDeclPrinter, NestedNameSpecifierTemplateArgs) {
- const char *Code =
- R"(
- template <class T> struct vector;
- template <> struct vector<int> { int method(); };
-)";
- ASSERT_TRUE(
- PrintedNestedNameSpecifierMatches(Code, "method", "vector<int>::"));
-}
OpenPOWER on IntegriCloud