[cfe-dev] Issue using clang parsing in python

Moiz Ali moiz.ali at stonybrook.edu
Wed Jan 14 12:24:12 PST 2015


Hi,

Thanks for your help,

I am passing header files in args option of parse function.

tu = index.parse(sys.argv[1],list_arg)
where list_arg = ['-I/usr/include',....]  --all libraries which i will
require.

When I parse .c source file to read all return values of a function using
"node2.get_tokens().next().spelling" , it is not able to find correct value
of macro which is defined in library included in .c file and passed in args
during index.parse().

For Example
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()*
}                                                          // EBUSY is
defined in linux/errno.h which is included in my .c file and also passed in
list_arg.


Thanks again for all your help,
Moiz Ali



On Wed, Jan 14, 2015 at 3:47 AM, mats petersson <mats at planetcatfish.com>
wrote:

> Not able to parse header files, or not able to FIND (the correct!)
> header files? There is a distinct difference... Maybe you could output
> the preprocessed data from libclang (using the -E option)
>
> --
> Mats
>
> On 13 January 2015 at 21:59, Moiz Ali <moiz.ali at stonybrook.edu> wrote:
> > 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
> >
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150114/c69e224c/attachment.html>


More information about the cfe-dev mailing list