[cfe-dev] [PATCH] libclang interface for comments AST

Jacob Carlborg doob at me.com
Fri Jul 20 00:18:28 PDT 2012


On 2012-07-19 23:18, Dmitri Gribenko wrote:
> Hello,
>
> The attached patch adds libclang APIs to walk comments ASTs and an API
> to convert a comment to an HTML fragment.
>
> I implemented error handling as returning bogus-but-safe values.  I am
> still concerned about this, because if the programmer misuses the API,
> libclang will work around that silently.  It could be a good idea to
> add some opt-in debug output for libclang to scream in such cases.
>
> For testing I implemented an equivalent of Comment::dump() with these
> new APIs in c-index-test.

I think it still would be better to return an invalid value where 
possible. For example, for functions returning 
CXCommentParamPassDirection, return CXCommentParamPassDirection_Null 
where no legal value can be return instead of 
CXCommentParamPassDirection_In.

This is what I think the functions should be returning to indicate an 
invalid value, depending on their type:

* enum - Do as above
* string - Empty or null string
* integers - Negative number, if possible
* pointers - Null
* structs - Usually contains an enum and/or pointer

* floating point - Perhaps NaN? Don't really know how that works in C/C++

* char - This really depends on what encoding is assumed. For 7bit ASCII 
and UTF-8 you probably can return anything above 127. Although I can't 
remember I've seen a libclang function returning a char so it might not 
be a problem.

-- 
/Jacob Carlborg






More information about the cfe-dev mailing list