コード例 #1
0
def on_finish_unit():
    def dump_integer_type(t):
        print('gcc.Type: %r' % str(t))
        print('  t.const: %r' % t.const)
        print('  t.unsigned: %r' % t.unsigned)
        print('  t.precision: %r' % t.precision)
        assert isinstance(t.min_value, gcc.IntegerCst)
        assert isinstance(t.max_value, gcc.IntegerCst)
        print('  t.min_value.constant: %r' % t.min_value.constant)
        print('  t.max_value.constant: %r' % t.max_value.constant)
        assert isinstance(t.sizeof, int)
        print('  t.sizeof: %r' % t.sizeof)
        # gccutils.pprint(t)

    # Pick some types that ought to be arch-independent and thus suitable
    # for a unit test
    dump_integer_type(gcc.Type.unsigned_char())
    dump_integer_type(gcc.Type.signed_char())

    print(gcc.Type.char().const)
    print(gcc.Type.char().const_equivalent.const)
    print(gcc.Type.char().const_equivalent.restrict_equivalent.const)
    print(gcc.Type.char().const_equivalent.volatile_equivalent.const)
    print(gcc.Type.char().const_equivalent.volatile_equivalent.
          unqualified_equivalent.const)

    def dump_real_type(t):
        print('gcc.Type: %r' % str(t))
        print('  t.const: %r' % t.const)
        print('  t.precision: %r' % t.precision)
        assert isinstance(t.sizeof, int)
        print('  t.sizeof: %r' % t.sizeof)

    dump_real_type(gcc.Type.float())
    dump_real_type(gcc.Type.double())

    def dump_typedef(td):
        t = td.type
        print('gcc.TypeDecl: %r' % str(td))
        print('  td.original_type: %r' % td.original_type)
        print('  td.original_type is gcc.Type.int(): %r' %
              (td.original_type is gcc.Type.int()))
        mytype = gccutils.get_global_typedef('mytype')
        print('  td.original_type.name: %r' % td.original_type.name)
        print('  td.original_type.name is mytype: %r' %
              (td.original_type.name is mytype))
        dump_integer_type(t)

    dump_typedef(gccutils.get_global_typedef('mytype'))
    dump_typedef(gccutils.get_global_typedef('nestedtype'))
コード例 #2
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def get_type_for_typeobject(typeobject):
    check_isinstance(typeobject, gcc.VarDecl)
    if typeobject.name not in type_dict:
        return None

    type_name = type_dict[typeobject.name]
    return get_global_typedef(type_name)
コード例 #3
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def is_py3k():
    """
    Is the Python.h we're compiling against python 3?
    """
    if get_global_typedef('PyStringObject'):
        return False
    else:
        return True
コード例 #4
0
 def dump_typedef(td):
     t = td.type
     print('gcc.TypeDecl: %r' % str(td))
     print('  td.original_type: %r' % td.original_type)
     print('  td.original_type is gcc.Type.int(): %r' %
           (td.original_type is gcc.Type.int()))
     mytype = gccutils.get_global_typedef('mytype')
     print('  td.original_type.name: %r' % td.original_type.name)
     print('  td.original_type.name is mytype: %r' %
           (td.original_type.name is mytype))
     dump_integer_type(t)
コード例 #5
0
ファイル: script.py プロジェクト: B-Rich/gcc-python-plugin
def on_finish_unit():
    for i in range(0, 4):
        fn_type_decl = gccutils.get_global_typedef('example%i' % i)
        assert isinstance(fn_type_decl, gcc.TypeDecl)
        print('fn_type_decl.name: %r' % fn_type_decl.name)
        fn_type = fn_type_decl.type
        assert isinstance(fn_type, gcc.FunctionType)
        print('str(fn_type): %r' % str(fn_type))
        print('str(fn_type.type): %r' % str(fn_type.type))
        assert isinstance(fn_type.argument_types, tuple)
        print('argument_types: %r' % [str(t) for t in fn_type.argument_types])
        print('fn_type.attributes: %r' % fn_type.attributes)
        print('gccutils.get_nonnull_arguments(fn_type): %r' % gccutils.get_nonnull_arguments(fn_type))
        print('-----------------------------------------------------\n')
コード例 #6
0
ファイル: script.py プロジェクト: yinglang/gcc-python-plugin
def on_finish_unit():
    for i in range(0, 4):
        fn_type_decl = gccutils.get_global_typedef('example%i' % i)
        assert isinstance(fn_type_decl, gcc.TypeDecl)
        print('fn_type_decl.name: %r' % fn_type_decl.name)
        fn_type = fn_type_decl.type
        assert isinstance(fn_type, gcc.FunctionType)
        print('str(fn_type): %r' % str(fn_type))
        print('str(fn_type.type): %r' % str(fn_type.type))
        assert isinstance(fn_type.argument_types, tuple)
        print('argument_types: %r' % [str(t) for t in fn_type.argument_types])
        print('fn_type.attributes: %r' % fn_type.attributes)
        print('gccutils.get_nonnull_arguments(fn_type): %r' %
              gccutils.get_nonnull_arguments(fn_type))
        print('-----------------------------------------------------\n')
コード例 #7
0
ファイル: script.py プロジェクト: B-Rich/gcc-python-plugin
def on_finish_unit():
    fn_type_decl = gccutils.get_global_typedef('example_fn_type')
    assert isinstance(fn_type_decl, gcc.TypeDecl)

    print('fn_type_decl.name: %r' % fn_type_decl.name)

    fn_type = fn_type_decl.type
    assert isinstance(fn_type, gcc.FunctionType)
    print('str(fn_type): %r' % str(fn_type))
    print('str(fn_type.type): %r' % str(fn_type.type))
    assert isinstance(fn_type.argument_types, tuple)
    print('argument_types: %r' % [str(t) for t in fn_type.argument_types])
    try:
        fn_type.sizeof
        assert 0 # an exception should have been raised
    except:
        err = sys.exc_info()[1]
        print('err: %s' % err)
コード例 #8
0
def on_finish_unit():
    fn_type_decl = gccutils.get_global_typedef('example_fn_type')
    assert isinstance(fn_type_decl, gcc.TypeDecl)

    print('fn_type_decl.name: %r' % fn_type_decl.name)

    fn_type = fn_type_decl.type
    assert isinstance(fn_type, gcc.FunctionType)
    print('str(fn_type): %r' % str(fn_type))
    print('str(fn_type.type): %r' % str(fn_type.type))
    assert isinstance(fn_type.argument_types, tuple)
    print('argument_types: %r' % [str(t) for t in fn_type.argument_types])
    try:
        fn_type.sizeof
        assert 0  # an exception should have been raised
    except:
        err = sys.exc_info()[1]
        print('err: %s' % err)
コード例 #9
0
ファイル: script.py プロジェクト: HackLinux/gcc-python-plugin
def check_fn_type(name):
    fn_type_decl = gccutils.get_global_typedef(name)
    assert isinstance(fn_type_decl, gcc.TypeDecl)

    print("fn_type_decl.name: %r" % fn_type_decl.name)

    fn_type = fn_type_decl.type
    assert isinstance(fn_type, gcc.FunctionType)
    print("str(fn_type): %r" % str(fn_type))
    print("str(fn_type.type): %r" % str(fn_type.type))
    assert isinstance(fn_type.argument_types, tuple)
    print("argument_types: %r" % [str(t) for t in fn_type.argument_types])
    print("is_variadic: %r" % fn_type.is_variadic)
    try:
        fn_type.sizeof
        assert 0  # an exception should have been raised
    except:
        err = sys.exc_info()[1]
        print("err: %s" % err)
コード例 #10
0
ファイル: script.py プロジェクト: B-Rich/gcc-python-plugin
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))
コード例 #11
0
ファイル: script.py プロジェクト: yinglang/gcc-python-plugin
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))
コード例 #12
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def get_PyTypeObject():
    return get_global_typedef('PyTypeObject')
コード例 #13
0
def check_typedef(typedef):
    print('typedef: %r' % typedef)
    decl = get_global_typedef(typedef)
    ptr_type = decl.type.pointer
    print('  ptr_type: %s' % ptr_type)
    print('  is PyObject* subclass?: %s\n' % type_is_pyobjptr_subclass(ptr_type))
コード例 #14
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def is_debug_build():
    """
    Is the Python.h we're compiling against configured --with-pydebug ?
    """
    obj = get_global_typedef('PyObject')
    return obj.type.fields[0].name == '_ob_next'
コード例 #15
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def get_Py_ssize_t():
    return get_global_typedef('Py_ssize_t')
コード例 #16
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def get_Py_buffer():
    return get_global_typedef('Py_buffer')
コード例 #17
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def Py_UNICODE():
    return get_global_typedef('Py_UNICODE')
コード例 #18
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def get_PyBytesObject():
    return get_global_typedef('PyBytesObject')
コード例 #19
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def get_Py_complex():
    return get_global_typedef('Py_complex')
コード例 #20
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def get_PyUnicodeObject():
    return get_global_typedef('PyUnicodeObject')
コード例 #21
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def get_PyStringObject():
    return get_global_typedef('PyStringObject')
コード例 #22
0
ファイル: types.py プロジェクト: yinglang/gcc-python-plugin
def get_PyObjectPtr():
    return get_global_typedef('PyObject').pointer