aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-08-21 17:47:24 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-08-21 17:47:24 +0000
commit2e0b8d9c0b16c4f3e3bed992205ce43a0908915d (patch)
tree4a64ae994bcdee9f24319cd9782854d6f874c186
parentd1fc82efd53ffda30f4f16041399d78f3bf0705f (diff)
DeclPrinter, terse mode: don't print function bodies
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162294 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/DeclPrinter.cpp2
-rw-r--r--unittests/AST/DeclPrinterTest.cpp51
2 files changed, 35 insertions, 18 deletions
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
index d96b6e57c6..4cba2b0977 100644
--- a/lib/AST/DeclPrinter.cpp
+++ b/lib/AST/DeclPrinter.cpp
@@ -553,7 +553,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
Out << " = 0";
else if (D->isDeletedAsWritten())
Out << " = delete";
- else if (D->doesThisDeclarationHaveABody()) {
+ else if (D->doesThisDeclarationHaveABody() && !Policy.TerseOutput) {
if (!D->hasPrototype() && D->getNumParams()) {
// This is a K&R function definition, so we need to print the
// parameters.
diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp
index 0292499225..268d48e50f 100644
--- a/unittests/AST/DeclPrinterTest.cpp
+++ b/unittests/AST/DeclPrinterTest.cpp
@@ -296,13 +296,30 @@ TEST(DeclPrinter, TestFunctionDecl1) {
TEST(DeclPrinter, TestFunctionDecl2) {
ASSERT_TRUE(PrintedDeclMatches(
+ "void A() {}",
+ "A",
+ "void A()"));
+ // Should be: with semicolon
+}
+
+TEST(DeclPrinter, TestFunctionDecl3) {
+ ASSERT_TRUE(PrintedDeclMatches(
+ "void Z();"
+ "void A() { Z(); }",
+ "A",
+ "void A()"));
+ // Should be: with semicolon
+}
+
+TEST(DeclPrinter, TestFunctionDecl4) {
+ ASSERT_TRUE(PrintedDeclMatches(
"extern void A();",
"A",
"extern void A()"));
// Should be: with semicolon
}
-TEST(DeclPrinter, TestFunctionDecl3) {
+TEST(DeclPrinter, TestFunctionDecl5) {
ASSERT_TRUE(PrintedDeclMatches(
"static void A();",
"A",
@@ -310,7 +327,7 @@ TEST(DeclPrinter, TestFunctionDecl3) {
// Should be: with semicolon
}
-TEST(DeclPrinter, TestFunctionDecl4) {
+TEST(DeclPrinter, TestFunctionDecl6) {
ASSERT_TRUE(PrintedDeclMatches(
"inline void A();",
"A",
@@ -318,7 +335,7 @@ TEST(DeclPrinter, TestFunctionDecl4) {
// Should be: with semicolon
}
-TEST(DeclPrinter, TestFunctionDecl5) {
+TEST(DeclPrinter, TestFunctionDecl7) {
ASSERT_TRUE(PrintedDeclCXX11Matches(
"constexpr int A(int a);",
"A",
@@ -326,7 +343,7 @@ TEST(DeclPrinter, TestFunctionDecl5) {
// WRONG; Should be: "constexpr int A(int a);"
}
-TEST(DeclPrinter, TestFunctionDecl6) {
+TEST(DeclPrinter, TestFunctionDecl8) {
ASSERT_TRUE(PrintedDeclMatches(
"void A(int a);",
"A",
@@ -334,7 +351,7 @@ TEST(DeclPrinter, TestFunctionDecl6) {
// Should be: with semicolon
}
-TEST(DeclPrinter, TestFunctionDecl7) {
+TEST(DeclPrinter, TestFunctionDecl9) {
ASSERT_TRUE(PrintedDeclMatches(
"void A(...);",
"A",
@@ -342,7 +359,7 @@ TEST(DeclPrinter, TestFunctionDecl7) {
// Should be: with semicolon
}
-TEST(DeclPrinter, TestFunctionDecl8) {
+TEST(DeclPrinter, TestFunctionDecl10) {
ASSERT_TRUE(PrintedDeclMatches(
"void A(int a, ...);",
"A",
@@ -350,7 +367,7 @@ TEST(DeclPrinter, TestFunctionDecl8) {
// Should be: with semicolon
}
-TEST(DeclPrinter, TestFunctionDecl9) {
+TEST(DeclPrinter, TestFunctionDecl11) {
ASSERT_TRUE(PrintedDeclMatches(
"typedef long size_t;"
"typedef int *pInt;"
@@ -360,7 +377,7 @@ TEST(DeclPrinter, TestFunctionDecl9) {
// Should be: with semicolon
}
-TEST(DeclPrinter, TestFunctionDecl10) {
+TEST(DeclPrinter, TestFunctionDecl12) {
ASSERT_TRUE(PrintedDeclMatches(
"void A(int a, int b = 0);",
"A",
@@ -368,7 +385,7 @@ TEST(DeclPrinter, TestFunctionDecl10) {
// Should be: with semicolon
}
-TEST(DeclPrinter, TestFunctionDecl11) {
+TEST(DeclPrinter, TestFunctionDecl13) {
ASSERT_TRUE(PrintedDeclMatches(
"void (*A(int a))(int b);",
"A",
@@ -376,14 +393,14 @@ TEST(DeclPrinter, TestFunctionDecl11) {
// Should be: with semicolon, with parameter name (?)
}
-TEST(DeclPrinter, TestFunctionDecl12) {
+TEST(DeclPrinter, TestFunctionDecl14) {
ASSERT_TRUE(PrintedDeclMatches(
"template<typename T>"
"void A(T t) { }"
"template<>"
"void A(int N) { }",
function(hasName("A"), isExplicitTemplateSpecialization()).bind("id"),
- "void A(int N) {\n}\n\n"));
+ "void A(int N)"));
// WRONG; Should be: "template <> void A(int N);"));
}
@@ -1004,8 +1021,8 @@ TEST(DeclPrinter, TestFunctionTemplateDecl2) {
"template<typename T>"
"void A(T &t) { }",
functionTemplate(hasName("A")).bind("id"),
- "template <typename T> void A(T &t) {\n}\n\n"));
- // Should be: without body, with semicolon
+ "template <typename T> void A(T &t)"));
+ // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionTemplateDecl3) {
@@ -1031,8 +1048,8 @@ TEST(DeclPrinter, TestFunctionTemplateDecl5) {
ASSERT_TRUE(PrintedDeclMatches(
"struct Z { template<typename T> void A(T t) {} };",
functionTemplate(hasName("A")).bind("id"),
- "template <typename T> void A(T t) {\n}\n\n"));
- // Should be: without body, with semicolon
+ "template <typename T> void A(T t)"));
+ // Should be: with semicolon
}
TEST(DeclPrinter, TestFunctionTemplateDecl6) {
@@ -1041,8 +1058,8 @@ TEST(DeclPrinter, TestFunctionTemplateDecl6) {
" template<typename U> void A(U t) {}"
"};",
functionTemplate(hasName("A")).bind("id"),
- "template <typename U> void A(U t) {\n}\n\n"));
- // Should be: without body, with semicolon
+ "template <typename U> void A(U t)"));
+ // Should be: with semicolon
}
TEST(DeclPrinter, TestTemplateArgumentList1) {