Beispiel #1
0
def get_struct(tagname):
    for u in gcc.get_translation_units():
        for v in u.block.vars:
            if isinstance(v, gcc.TypeDecl):
                if isinstance(v.type, gcc.RecordType):
                    if isinstance(v.type.name, gcc.IdentifierNode):
                        if v.type.name.name == tagname:
                            return v.type
Beispiel #2
0
def gccPassHook(passname, _):
    if passname.name == '*free_lang_data':
        for i in gcc.get_translation_units():
            gns = gcc.get_global_namespace()
            for decl in gns.declarations:
                if decl.is_builtin is False:
                    pp = pprint.PrettyPrinter(indent=4)
                    pp.pprint(str(decl.type))
                    pp.pprint(decl.type.fields)
                    pp.pprint(decl.type.methods)
Beispiel #3
0
def gccPassHook(passname, _):
    if passname.name == '*free_lang_data':
        for i in gcc.get_translation_units ():
            gns = gcc.get_global_namespace ()
            for decl in gns.declarations:
                if decl.is_builtin is False:
                    pp = pprint.PrettyPrinter(indent=4)
                    pp.pprint (str (decl.type))
                    pp.pprint (decl.type.fields)
                    pp.pprint (decl.type.methods)
def get_global_vardecl_by_name(name):
    # Look up a variable in global scope by name, returning a gcc.VarDecl,
    # or None if not found
    for u in gcc.get_translation_units():
        if u.language == 'GNU C++':
            gns = gcc.get_global_namespace()
            return gns.lookup(name)
        for v in u.block.vars:
            if isinstance(v, gcc.VarDecl):
                if v.name == name:
                    return v
Beispiel #5
0
def on_pass_execution(p, fn):
    if p.name == '*warn_function_return':
        assert isinstance(fn, gcc.Function)

        for u in gcc.get_translation_units():
            for v in u.block.vars:
                if v.name == 'arr':
                    print('arr-range-min:%s' % v.type.range.min_value)
                    print('arr-range-max:%s' % v.type.range.max_value)
                if v.name == 'arr2':
                    print('arr2-range:%s' % v.type.range)
Beispiel #6
0
def on_pass_execution(p, fn):
    if p.name == '*warn_function_return':
        assert isinstance(fn, gcc.Function)

        for u in gcc.get_translation_units():
            for v in u.block.vars:
                if v.name == 'arr':
                    print('arr-range-min:%s' % v.type.range.min_value)
                    print('arr-range-max:%s' % v.type.range.max_value)
                if v.name == 'arr2':
                    print('arr2-range:%s' % v.type.range)
def get_global_vardecl_by_name(name):
    # Look up a variable in global scope by name, returning a gcc.VarDecl,
    # or None if not found
    for u in gcc.get_translation_units():
        if u.language == 'GNU C++':
            gns = gcc.get_global_namespace()
            return gns.lookup(name)
        for v in u.block.vars:
            if isinstance(v, gcc.VarDecl):
                if v.name == name:
                    return v
def get_global_typedef(name):
    # Look up a typedef in global scope by name, returning a gcc.TypeDecl,
    # or None if not found
    for u in gcc.get_translation_units():
        if u.language.startswith('GNU C++'):
            gns = gcc.get_global_namespace()
            return gns.lookup(name)
        if u.block:
            for v in u.block.vars:
                if isinstance(v, gcc.TypeDecl):
                    if v.name == name:
                        return v
def get_global_typedef(name):
    # Look up a typedef in global scope by name, returning a gcc.TypeDecl,
    # or None if not found
    for u in gcc.get_translation_units():
        if u.language == 'GNU C++':
            gns = gcc.get_global_namespace()
            return gns.lookup(name)
        if u.block:
            for v in u.block.vars:
                if isinstance(v, gcc.TypeDecl):
                    if v.name == name:
                        return v
Beispiel #10
0
def on_pass_execution(p, data):
    if p.name == 'visibility':
        print('len(gcc.get_translation_units()): %i' % len(gcc.get_translation_units()))
        u = gcc.get_translation_units()[0]
        print('type(u): %s' % type(u))
        print('u.language: %r' % u.language)
        print('type(u.block): %s' % type(u.block))
        for v in u.block.vars:
            if v.name == 'test_typedef':
                print('v.name: %r' % v.name)
                print('type(v): %r' % v)

            if v.name == 'test_var':
                print('v.name: %r' % v.name)
                print('type(v): %r' % v)
        #print 'u.block: %s' % u.block
        #u.block.debug()

        td = get_global_typedef('test_typedef')
        print('td: %r' % td)
        print('td.name: %r' % td.name)
        print('type(td.type): %s' % type(td.type))
Beispiel #11
0
def on_pass_execution(p, data):
    if p.name == 'visibility':
        print('len(gcc.get_translation_units()): %i' %
              len(gcc.get_translation_units()))
        u = gcc.get_translation_units()[0]
        print('type(u): %s' % type(u))
        print('u.language: %r' % u.language)
        print('type(u.block): %s' % type(u.block))
        for v in u.block.vars:
            if v.name == 'test_typedef':
                print('v.name: %r' % v.name)
                print('type(v): %r' % v)

            if v.name == 'test_var':
                print('v.name: %r' % v.name)
                print('type(v): %r' % v)
        #print 'u.block: %s' % u.block
        #u.block.debug()

        td = get_global_typedef('test_typedef')
        print('td: %r' % td)
        print('td.name: %r' % td.name)
        print('type(td.type): %s' % type(td.type))
Beispiel #12
0
 def execute(self, fn):
     print('fn: %r' % fn)
     for u in gcc.get_translation_units():
         for decl in u.block.vars:
             if isinstance(decl, gcc.TypeDecl):
                 # "decl" is a gcc.TypeDecl
                 # "decl.type" is a gcc.RecordType:
                 print('  type(decl): %s' % type(decl))
                 print('  type(decl.type): %s' % type(decl.type))
                 print('  decl.type.name: %r' % decl.type.name)
                 for f in decl.type.fields:
                     print('    type(f): %s' % type(f))
                     print('      f.name: %r' % f.name)
                     print('      f.type: %s' % f.type)
                     print('      type(f.type): %s' % type(f.type))
Beispiel #13
0
 def execute(self, fn):
     print('fn: %r' % fn)
     for u in gcc.get_translation_units():
         for decl in u.block.vars:
             if isinstance(decl, gcc.TypeDecl):
                 # "decl" is a gcc.TypeDecl
                 # "decl.type" is a gcc.RecordType:
                 print('  type(decl): %s' % type(decl))
                 print('  type(decl.type): %s' % type(decl.type))
                 print('  decl.type.name: %r' % decl.type.name)
                 for f in decl.type.fields:
                     print('    type(f): %s' % type(f))
                     print('      f.name: %r' % f.name)
                     print('      f.type: %s' % f.type)
                     print('      type(f.type): %s' % type(f.type))
Beispiel #14
0
def gccPassHook ():
    global TranslationUnit
    for i in gcc.get_variables ():
        TranslationUnit.append (i.decl)
    for i in gcc.get_translation_units ():
        if i.language == 'GNU C++':
            TranslationUnit = []
            gns = gcc.get_global_namespace ()
            for decl in gns.namespaces:
                if decl.is_builtin is False:
                    TranslationUnit.append (decl)
            for decl in gns.declarations:
                if decl.is_builtin is False:
                    TranslationUnit.append (decl)
        else:
            for y in i.block.vars:
                if type (y) is not gcc.VarDecl:
                    TranslationUnit.append (y)
    pxdutil.pxdcompile (TranslationUnit)