diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-09-10 20:32:42 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-09-10 20:32:42 +0000 |
commit | e4330a302ac20b41b9800267ebd4b5b01f8553f8 (patch) | |
tree | 2a0fe1a83b27fd60a74bbdf5ea4026c0fd1b380e /tools/libclang/CXComment.h | |
parent | db133151fc405573634877f13da7bcc2e9f2a1cd (diff) |
Comment AST: TableGen'ize all command lists in CommentCommandTraits.cpp.
Now we have a list of all commands. This is a good thing in itself, but it
also enables us to easily implement typo correction for command names.
With this change we have objects that contain information about each command,
so it makes sense to resolve command name just once during lexing (currently we
store command names as strings and do a linear search every time some property
value is needed). Thus comment token and AST nodes were changed to contain a
command ID -- index into a tables of builtin and registered commands. Unknown
commands are registered during parsing and thus are also uniformly assigned an
ID. Using an ID instead of a StringRef is also a nice memory optimization
since ID is a small integer that fits into a common bitfield in Comment class.
This change implies that to get any information about a command (even a command
name) we need a CommandTraits object to resolve the command ID to CommandInfo*.
Currently a fresh temporary CommandTraits object is created whenever it is
needed since it does not have any state. But with this change it has state --
new commands can be registered, so a CommandTraits object was added to
ASTContext.
Also, in libclang CXComment has to be expanded to include a CXTranslationUnit
so that all functions working on comment AST nodes can get a CommandTraits
object. This breaks binary compatibility of CXComment APIs.
Now clang_FullComment_getAsXML(CXTranslationUnit TU, CXComment CXC) doesn't
need TU parameter anymore, so it was removed. This is a source-incompatible
change for this C API.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163540 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang/CXComment.h')
-rw-r--r-- | tools/libclang/CXComment.h | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/tools/libclang/CXComment.h b/tools/libclang/CXComment.h index 753877e6c7..513431709f 100644 --- a/tools/libclang/CXComment.h +++ b/tools/libclang/CXComment.h @@ -15,20 +15,29 @@ #define LLVM_CLANG_CXCOMMENT_H #include "clang-c/Index.h" +#include "CXTranslationUnit.h" #include "clang/AST/Comment.h" +#include "clang/AST/ASTContext.h" +#include "clang/Frontend/ASTUnit.h" namespace clang { +namespace comments { + class CommandTraits; +} + namespace cxcomment { -inline CXComment createCXComment(const comments::Comment *C) { +inline CXComment createCXComment(const comments::Comment *C, + CXTranslationUnit TU) { CXComment Result; - Result.Data = C; + Result.ASTNode = C; + Result.TranslationUnit = TU; return Result; } inline const comments::Comment *getASTNode(CXComment CXC) { - return static_cast<const comments::Comment *>(CXC.Data); + return static_cast<const comments::Comment *>(CXC.ASTNode); } template<typename T> @@ -40,6 +49,14 @@ inline const T *getASTNodeAs(CXComment CXC) { return dyn_cast<T>(C); } +inline ASTContext &getASTContext(CXComment CXC) { + return static_cast<ASTUnit *>(CXC.TranslationUnit->TUData)->getASTContext(); +} + +inline comments::CommandTraits &getCommandTraits(CXComment CXC) { + return getASTContext(CXC).getCommentCommandTraits(); +} + } // end namespace cxcomment } // end namespace clang |