[cfe-dev] libclang and handling of # directives

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Sep 6 09:21:38 PDT 2011


On Sep 5, 2011, at 2:13 PM, Vinay Sajip wrote:

> I'm using libclang to parse some Objective-C code which has been produced using
> gcc -E, and so the input file has #line directives of the form
> 
> # 45 "/System/Library/Frameworks/WebKit.framework/Headers/WebUIDelegate.h" 3
> 
> I can parse the file without any errors, but the source locations don't seem to
> reflect the line directives. When parsing a simple file "somefile.c" with a
> similar directive 
> 
> # 123 "dummy.c" 2
> 
> static int func()
> {
>    return 0;
> }
> 
> and iterating over the definitions, I get source location results like
> 
> Typedef, __builtin_va_list, NULL, 99, 15
> FunctionNoProto, func, somefile.c, 3, 12
> 
> whereas I would have hoped that the func definition had a source location at the
> appropriate line in "dummy.c". Using a #line directive makes no difference.
> 
> Is there any way one can get clang to take # line directives into account? None
> of the CXTranslationUnit_XXX flags seem to be applicable here.

There is not currently a way to expose that info from libclang. There should be a new function (like clang_getPresumedLocation) similar to clang_getExpansionLocation that will call SourceManager::getPresumedLoc internally.
Please file a bugzilla report so that we can track it.

> 
> Thanks,
> 
> Vinay Sajip
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list