Example #1
0
#!/usr/bin/env python
# encoding: utf-8

import sys
from clang import cindex
from utils import get_clang_args, get_clang_analyzer_diagnostics

if __name__ == '__main__':

    filename = sys.argv[1]

    clang_args = get_clang_args()

    clang_args = filter(lambda a: '-W' not in a, clang_args)

    print clang_args

    index = cindex.Index.create()
    tu = index.parse(filename, clang_args)
    tu.reparse()

    for d in tu.diagnostics:
        if d.location.file:
            print(d.location.file.name + ':' + str(d.location.line)
                    + ' ' + d.spelling)
        else:
            print('???:' + str(d.location.line) + ' ' + d.spelling)

    for d in get_clang_analyzer_diagnostics(filename, clang_args):
        print(d.filename + ':' + str(d.line_number) + ' ' + d.message)
Example #2
0
#!/usr/bin/env python
# encoding: utf-8

import sys
from clang import cindex
from utils import get_clang_args, get_clang_analyzer_diagnostics

if __name__ == '__main__':

    filenames = sys.argv[1:]

    clang_args = get_clang_args()

    clang_args = filter(lambda a: '-W' not in a, clang_args)

    # print clang_args

    for filename in filenames:
        index = cindex.Index.create()
        tu = index.parse(filename, clang_args)
        if not tu:
            print filename + " parsing failed"
            continue
        tu.reparse()

        for d in tu.diagnostics:
            if d.location.file and 'Developer/SDK' not in d.location.file.name:
                print(d.location.file.name + ':' + str(d.location.line) + ' ' +
                      d.spelling)
            else:
                # print('???:' + str(d.location.line) + ' ' + d.spelling)
Example #3
0
import clang.cindex as cindex
from utils import full_text_for_cursor, get_clang_args


def print_cursor_recursive(cur, depth=0):

    token_text = full_text_for_cursor(cur)
    # token_text = cur.displayname
    # token_text = cur.spelling

    if '--all' not in sys.argv\
            and cur.location.file\
            and cur.location.file.name == sys.argv[1]:
        print('{0} {1} | {2}'.format('->' * depth, cur.kind, token_text))

    for child in cur.get_children():
        print_cursor_recursive(child, depth + 1)


if __name__ == '__main__':

    filename = sys.argv[-1]

    index = cindex.Index.create()
    tu = index.parse(filename, get_clang_args())

    with open(filename) as fi:
        blob = fi.read()

    print_cursor_recursive(tu.cursor)