aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/libclang/LibclangTest.cpp
diff options
context:
space:
mode:
authorJonathan Coe <jbcoe@me.com>2018-01-16 10:19:56 +0000
committerJonathan Coe <jbcoe@me.com>2018-01-16 10:19:56 +0000
commit45ef5036c929b73e180d0c959c05b1a6bda07162 (patch)
tree1ee6f220fd2c97888dd264eacda749d8fe157a38 /clang/unittests/libclang/LibclangTest.cpp
parent639a3980986d65c620c3ebbc3fddba7d3103b58a (diff)
downloadllvm-45ef5036c929b73e180d0c959c05b1a6bda07162.zip
llvm-45ef5036c929b73e180d0c959c05b1a6bda07162.tar.gz
llvm-45ef5036c929b73e180d0c959c05b1a6bda07162.tar.bz2
[libclang] Add PrintingPolicy for pretty printing declarations
Summary: Introduce clang_getCursorPrettyPrinted() for pretty printing declarations. Expose also PrintingPolicy, so the user gets more fine-grained control of the entities being printed. The already existing clang_getCursorDisplayName() is pretty limited - for example, it does not handle return types, parameter names or default arguments for function declarations. Addressing these issues in clang_getCursorDisplayName() would mean to duplicate existing code (e.g. clang::DeclPrinter), so rather expose new API to access the existing functionality. Reviewed By: jbcoe Subscribers: cfe-commits Tags: #clang Patch by nik (Nikolai Kosjar) Differential Revision: https://reviews.llvm.org/D39903 llvm-svn: 322540
Diffstat (limited to 'clang/unittests/libclang/LibclangTest.cpp')
-rw-r--r--clang/unittests/libclang/LibclangTest.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp
index 34bc98f..c44095d 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -573,6 +573,36 @@ TEST_F(LibclangReparseTest, clang_parseTranslationUnit2FullArgv) {
DisplayDiagnostics();
}
+class LibclangPrintingPolicyTest : public LibclangParseTest {
+public:
+ CXPrintingPolicy Policy = nullptr;
+
+ void SetUp() override {
+ LibclangParseTest::SetUp();
+ std::string File = "file.cpp";
+ WriteFile(File, "int i;\n");
+ ClangTU = clang_parseTranslationUnit(Index, File.c_str(), nullptr, 0,
+ nullptr, 0, TUFlags);
+ CXCursor TUCursor = clang_getTranslationUnitCursor(ClangTU);
+ Policy = clang_getCursorPrintingPolicy(TUCursor);
+ }
+ void TearDown() override {
+ clang_PrintingPolicy_dispose(Policy);
+ LibclangParseTest::TearDown();
+ }
+};
+
+TEST_F(LibclangPrintingPolicyTest, SetAndGetProperties) {
+ for (unsigned Value = 0; Value < 2; ++Value) {
+ for (int I = 0; I < CXPrintingPolicy_LastProperty; ++I) {
+ auto Property = static_cast<enum CXPrintingPolicyProperty>(I);
+
+ clang_PrintingPolicy_setProperty(Policy, Property, Value);
+ EXPECT_EQ(Value, clang_PrintingPolicy_getProperty(Policy, Property));
+ }
+ }
+}
+
TEST_F(LibclangReparseTest, PreprocessorSkippedRanges) {
std::string Header = "header.h", Main = "main.cpp";
WriteFile(Header,