diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-06-20 00:34:58 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-06-20 00:34:58 +0000 |
commit | aa0cd85838f2a024e589ea4e8c2094130065af21 (patch) | |
tree | b4e013c1268210fa0769c263d702c637395b59ae /tools | |
parent | ed36b2a80878c29603bdc89a7969253fb6446174 (diff) |
Structured comment parsing, first step.
* Retain comments in the AST
* Serialize/deserialize comments
* Find comments attached to a certain Decl
* Expose raw comment text and SourceRange via libclang
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158771 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/arcmt-test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/arcmt-test/Makefile | 3 | ||||
-rw-r--r-- | tools/c-index-test/Makefile | 3 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 20 | ||||
-rw-r--r-- | tools/clang-check/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/clang-check/Makefile | 2 | ||||
-rw-r--r-- | tools/diagtool/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/diagtool/Makefile | 2 | ||||
-rw-r--r-- | tools/driver/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/driver/Makefile | 2 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 30 | ||||
-rw-r--r-- | tools/libclang/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/libclang/Makefile | 2 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 2 |
14 files changed, 63 insertions, 9 deletions
diff --git a/tools/arcmt-test/CMakeLists.txt b/tools/arcmt-test/CMakeLists.txt index a0029b416f..7950ee2a46 100644 --- a/tools/arcmt-test/CMakeLists.txt +++ b/tools/arcmt-test/CMakeLists.txt @@ -1,5 +1,6 @@ set(LLVM_USED_LIBS clangARCMigrate + clangComments clangEdit clangRewrite ) diff --git a/tools/arcmt-test/Makefile b/tools/arcmt-test/Makefile index 57cd57482b..81f27c2b11 100644 --- a/tools/arcmt-test/Makefile +++ b/tools/arcmt-test/Makefile @@ -19,6 +19,7 @@ NO_INSTALL = 1 LINK_COMPONENTS := support mc USEDLIBS = clangARCMigrate.a clangRewrite.a \ clangFrontend.a clangDriver.a clangSerialization.a clangParse.a \ - clangSema.a clangEdit.a clangAnalysis.a clangAST.a clangLex.a clangBasic.a + clangSema.a clangEdit.a clangAnalysis.a clangAST.a clangLex.a clangComments.a \ + clangBasic.a include $(CLANG_LEVEL)/Makefile diff --git a/tools/c-index-test/Makefile b/tools/c-index-test/Makefile index 03519b3823..b061492caf 100644 --- a/tools/c-index-test/Makefile +++ b/tools/c-index-test/Makefile @@ -20,6 +20,7 @@ TOOL_NO_EXPORTS = 1 LINK_COMPONENTS := support mc USEDLIBS = clang.a clangFrontend.a clangDriver.a \ clangSerialization.a clangParse.a clangSema.a \ - clangAnalysis.a clangEdit.a clangAST.a clangLex.a clangBasic.a + clangAnalysis.a clangEdit.a clangAST.a clangLex.a clangComments.a \ + clangBasic.a include $(CLANG_LEVEL)/Makefile diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 497c9ee6af..4c9723da01 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -218,7 +218,9 @@ static void PrintCursor(CXCursor Cursor) { CXPlatformAvailability PlatformAvailability[2]; int NumPlatformAvailability; int I; - + CXString Comment; + const char *CommentCString; + ks = clang_getCursorKindSpelling(Cursor.kind); string = want_display_name? clang_getCursorDisplayName(Cursor) : clang_getCursorSpelling(Cursor); @@ -398,6 +400,22 @@ static void PrintCursor(CXCursor Cursor) { if (!clang_equalRanges(CursorExtent, RefNameRange)) PrintRange(RefNameRange, "RefName"); } + + Comment = clang_Cursor_getRawCommentText(Cursor); + CommentCString = clang_getCString(Comment); + if (CommentCString != NULL && CommentCString[0] != '\0') { + printf(" Comment=["); + for ( ; *CommentCString; ++CommentCString) { + if (*CommentCString != '\n') + putchar(*CommentCString); + else + printf("\\n"); + } + printf("]"); + + PrintRange(clang_Cursor_getCommentRange(Cursor), "CommentRange"); + } + clang_disposeString(Comment); } } diff --git a/tools/clang-check/CMakeLists.txt b/tools/clang-check/CMakeLists.txt index 851d6cdd16..83fe10f80e 100644 --- a/tools/clang-check/CMakeLists.txt +++ b/tools/clang-check/CMakeLists.txt @@ -1,4 +1,4 @@ -set(LLVM_USED_LIBS clangTooling clangBasic) +set(LLVM_USED_LIBS clangTooling clangBasic clangComments) add_clang_executable(clang-check ClangCheck.cpp diff --git a/tools/clang-check/Makefile b/tools/clang-check/Makefile index 49b1ada95b..5c54a6b332 100644 --- a/tools/clang-check/Makefile +++ b/tools/clang-check/Makefile @@ -18,7 +18,7 @@ TOOL_NO_EXPORTS = 1 LINK_COMPONENTS := support mc USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a \ clangTooling.a clangParse.a clangSema.a clangAnalysis.a \ - clangEdit.a clangAST.a clangLex.a clangBasic.a + clangEdit.a clangAST.a clangLex.a clangComments.a clangBasic.a include $(CLANG_LEVEL)/Makefile diff --git a/tools/diagtool/CMakeLists.txt b/tools/diagtool/CMakeLists.txt index d2ad735337..05b896975c 100644 --- a/tools/diagtool/CMakeLists.txt +++ b/tools/diagtool/CMakeLists.txt @@ -4,6 +4,7 @@ set( LLVM_LINK_COMPONENTS set( LLVM_USED_LIBS clangBasic + clangComments clangLex clangSema clangFrontend diff --git a/tools/diagtool/Makefile b/tools/diagtool/Makefile index 8af4cef643..5f5fb2ae36 100644 --- a/tools/diagtool/Makefile +++ b/tools/diagtool/Makefile @@ -20,7 +20,7 @@ LINK_COMPONENTS := support mc USEDLIBS = clangFrontend.a clangDriver.a clangSerialization.a clangParse.a \ clangSema.a clangAnalysis.a clangEdit.a clangAST.a clangLex.a \ - clangBasic.a + clangComments.a clangBasic.a include $(CLANG_LEVEL)/Makefile diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt index ae49ac1eeb..5413546e28 100644 --- a/tools/driver/CMakeLists.txt +++ b/tools/driver/CMakeLists.txt @@ -4,6 +4,7 @@ set( LLVM_USED_LIBS clangAnalysis clangBasic clangCodeGen + clangComments clangDriver clangEdit clangFrontend diff --git a/tools/driver/Makefile b/tools/driver/Makefile index 270d4fdda8..4105cb6d94 100644 --- a/tools/driver/Makefile +++ b/tools/driver/Makefile @@ -36,7 +36,7 @@ USEDLIBS = clangFrontendTool.a clangFrontend.a clangDriver.a \ clangStaticAnalyzerFrontend.a clangStaticAnalyzerCheckers.a \ clangStaticAnalyzerCore.a \ clangAnalysis.a clangARCMigrate.a clangRewrite.a \ - clangEdit.a clangAST.a clangLex.a clangBasic.a + clangEdit.a clangAST.a clangLex.a clangComments.a clangBasic.a include $(CLANG_LEVEL)/Makefile diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 7fb944ddd3..df8adb419e 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -5676,7 +5676,35 @@ CXFile clang_getIncludedFile(CXCursor cursor) { InclusionDirective *ID = getCursorInclusionDirective(cursor); return (void *)ID->getFile(); } - + +CXSourceRange clang_Cursor_getCommentRange(CXCursor C) { + if (!clang_isDeclaration(C.kind)) + return clang_getNullRange(); + + const Decl *D = getCursorDecl(C); + ASTContext &Context = getCursorContext(C); + const RawComment *RC = Context.getRawCommentForDecl(D); + if (!RC) + return clang_getNullRange(); + + return cxloc::translateSourceRange(Context, RC->getSourceRange()); +} + +CXString clang_Cursor_getRawCommentText(CXCursor C) { + if (!clang_isDeclaration(C.kind)) + return createCXString((const char *) NULL); + + const Decl *D = getCursorDecl(C); + ASTContext &Context = getCursorContext(C); + const RawComment *RC = Context.getRawCommentForDecl(D); + StringRef RawText = RC ? RC->getRawText(Context.getSourceManager()) : + StringRef(); + + // Don't duplicate the string because RawText points directly into source + // code. + return createCXString(RawText, false); +} + } // end: extern "C" diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt index 293dfa3ff9..7a6732a77a 100644 --- a/tools/libclang/CMakeLists.txt +++ b/tools/libclang/CMakeLists.txt @@ -6,6 +6,7 @@ set(LLVM_USED_LIBS clangSerialization clangSema clangEdit + clangComments clangAST clangLex clangBasic) diff --git a/tools/libclang/Makefile b/tools/libclang/Makefile index 8d0a614403..78da0675dc 100644 --- a/tools/libclang/Makefile +++ b/tools/libclang/Makefile @@ -19,7 +19,7 @@ LINK_COMPONENTS := support mc USEDLIBS = clangARCMigrate.a clangRewrite.a clangFrontend.a clangDriver.a \ clangSerialization.a \ clangParse.a clangSema.a clangEdit.a clangAnalysis.a \ - clangAST.a clangLex.a clangBasic.a + clangAST.a clangLex.a clangComments.a clangBasic.a include $(CLANG_LEVEL)/Makefile diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index 594a7969e3..d24960b297 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -5,6 +5,8 @@ clang_CXIndex_setGlobalOptions clang_CXXMethod_isStatic clang_CXXMethod_isVirtual clang_Cursor_getArgument +clang_Cursor_getCommentRange +clang_Cursor_getRawCommentText clang_Cursor_getNumArguments clang_Cursor_getObjCSelectorIndex clang_Cursor_getSpellingNameRange |