[cfe-dev] Libclang and Objective-C headers

jahanian fjahanian at apple.com
Mon Jan 3 09:29:46 PST 2011


On Dec 31, 2010, at 9:47 AM, David Chisnall wrote:

> Hi,
> 
> I'm trying to use libclang to gather information about Objective-C headers.  Unfortunately, clang appears to default to C for .h files (probably sensible) and to refer to ignore -x options passed in to clang_createTranslationUnitFromSourceFile() and clang_parseTranslationUnit().  

At least for clang proper, it seems to work as expected:

% cat t.h
@interface I
- m;
@end

% cat t.c
#include "t.h"

@implementation I
- m { return 0; }
@end

% clang -x objective-c -fsyntax-only t.c
% 

If it does not happen  in the context of libclang use, it is probably a bug (not knowing if it is intentional for some reasons).

- fariborz


> 
> Is there an existing way of overriding the default language choice when parsing headers (I assume that the XCode people needed this for editing Objective-C headers?), and if so what is it?  
> 
> Alternatively, would it be possible for libclang to automatically detect the language of header files?  It's relatively easy to tell C[++] and Objective-C[++] apart (spot an #import or an @-keyword anywhere), but telling C and C++ apart is probably a bit harder.
> 
> David
> 
> -- Sent from my STANTEC-ZEBRA
> 
> 
> _______________________________________________
> 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