[cfe-dev] Issue using clang parsing in python

Moiz Ali moiz.ali at stonybrook.edu
Tue Jan 13 13:59:15 PST 2015


Hello,

I am trying to parse c file using clang. I have created python binding
using libclang.so and passing my .c file as and argument to my python
script.

I see that it is not able to parse header file, due to which file
linux/errno.h is also not parsed and hence it is not able to get values of
macro definition of all error codes.
Ex:
----
*file bcm63xx_wdt.c:*
#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/io.h>
...
...
static int bcm63xx_wdt_open(struct inode *inode, struct file *file)
{
if (test_and_set_bit(0, &bcm63xx_wdt_device.inuse))
return -EBUSY;                     *// not able to find value of
EBUSY,hence returns error when I try to print node.spelling()*
}

I try to parse same file using clang command directly in command prompt and
I see that

*:~$ clang -Xclang -ast-dump -fsyntax-only bcm63xx_wdt.c*
*O/P:*
|   | |-ReturnStmt 0x1c23858 <line:119:3,
/usr/include/asm-generic/errno-base.h:19:16>
|   | | `-UnaryOperator 0x1c23838 <bcm63xx_wdt.c:119:10,
/usr/include/asm-generic/errno-base.h:19:16> 'int' prefix '-'
|   | |   `-IntegerLiteral 0x1c23818 <col:16> *'int' 16*


Also if I include Macro definition in source file
#define EBUSY           16      /* Device or resource busy */

Then I get correct output

I am searching for issues in libclang but not able to find reason for
failiure, can you guide me some steps which can help.

Thanks,
Moiz Ali
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150113/6587fd11/attachment.html>


More information about the cfe-dev mailing list