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 /lib/AST/CommentDumper.cpp | |
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 'lib/AST/CommentDumper.cpp')
-rw-r--r-- | lib/AST/CommentDumper.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/AST/CommentDumper.cpp b/lib/AST/CommentDumper.cpp index dffc8233a0..f6fb3b1baa 100644 --- a/lib/AST/CommentDumper.cpp +++ b/lib/AST/CommentDumper.cpp @@ -16,12 +16,15 @@ namespace comments { namespace { class CommentDumper: public comments::ConstCommentVisitor<CommentDumper> { raw_ostream &OS; - SourceManager *SM; + const CommandTraits *Traits; + const SourceManager *SM; unsigned IndentLevel; public: - CommentDumper(raw_ostream &OS, SourceManager *SM) : - OS(OS), SM(SM), IndentLevel(0) + CommentDumper(raw_ostream &OS, + const CommandTraits *Traits, + const SourceManager *SM) : + OS(OS), Traits(Traits), SM(SM), IndentLevel(0) { } void dumpIndent() const { @@ -56,6 +59,15 @@ public: void visitVerbatimLineComment(const VerbatimLineComment *C); void visitFullComment(const FullComment *C); + + const char *getCommandName(unsigned CommandID) { + if (Traits) + return Traits->getCommandInfo(CommandID)->Name; + const CommandInfo *Info = CommandTraits::getBuiltinCommandInfo(CommandID); + if (Info) + return Info->Name; + return "<not a builtin command>"; + } }; void CommentDumper::dumpSourceRange(const Comment *C) { @@ -107,7 +119,7 @@ void CommentDumper::visitTextComment(const TextComment *C) { void CommentDumper::visitInlineCommandComment(const InlineCommandComment *C) { dumpComment(C); - OS << " Name=\"" << C->getCommandName() << "\""; + OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""; switch (C->getRenderKind()) { case InlineCommandComment::RenderNormal: OS << " RenderNormal"; @@ -155,7 +167,7 @@ void CommentDumper::visitParagraphComment(const ParagraphComment *C) { void CommentDumper::visitBlockCommandComment(const BlockCommandComment *C) { dumpComment(C); - OS << " Name=\"" << C->getCommandName() << "\""; + OS << " Name=\"" << getCommandName(C->getCommandID()) << "\""; for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) OS << " Arg[" << i << "]=\"" << C->getArgText(i) << "\""; } @@ -198,7 +210,7 @@ void CommentDumper::visitTParamCommandComment(const TParamCommandComment *C) { void CommentDumper::visitVerbatimBlockComment(const VerbatimBlockComment *C) { dumpComment(C); - OS << " Name=\"" << C->getCommandName() << "\"" + OS << " Name=\"" << getCommandName(C->getCommandID()) << "\"" " CloseName=\"" << C->getCloseName() << "\""; } @@ -220,8 +232,9 @@ void CommentDumper::visitFullComment(const FullComment *C) { } // unnamed namespace -void Comment::dump(llvm::raw_ostream &OS, SourceManager *SM) const { - CommentDumper D(llvm::errs(), SM); +void Comment::dump(llvm::raw_ostream &OS, const CommandTraits *Traits, + const SourceManager *SM) const { + CommentDumper D(llvm::errs(), Traits, SM); D.dumpSubtree(this); llvm::errs() << '\n'; } |