[cfe-commits] [PATCH] TableGen'ize documentation command lists (and break binary compatibility of CXComment)

Dmitri Gribenko gribozavr at gmail.com
Wed Sep 5 00:11:14 PDT 2012


Hello,

Doug: CCing you since this email is mostly about libclang CXComment
binary compatibility I need to break for a good reason.

The attached patch TableGen'izes all command lists in
CommentCommandTraits.cpp and 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 I added a CommandTraits object to ASTContext.

Also, in libclang CXComment has to be expanded to include a pointer to
ASTContext so that all functions working on comment AST nodes can get
a CommandTraits object.  This breaks binary compatibility of CXComment
APIs.

We can avoid breaking binary compatibility by storing CommandInfo* in
AST nodes instead of unsigned command IDs (that need to be resolved).
But with this approach we won't get that nice memory optimization.

The patch is long, but changes are mostly boring and just change the
code to use the new APIs to access command properties.  It is the
architecture and binary compatibility I want to get comments about.

Please review.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tablegen-command-info-v1.patch
Type: application/octet-stream
Size: 110463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120905/8ef7c5ed/attachment.obj>


More information about the cfe-commits mailing list