Esempio n. 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'))
Esempio n. 2
0
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)
Esempio n. 3
0
def is_py3k():
    """
    Is the Python.h we're compiling against python 3?
    """
    if get_global_typedef('PyStringObject'):
        return False
    else:
        return True
Esempio n. 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)
Esempio n. 5
0
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')
Esempio n. 6
0
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')
Esempio n. 7
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)
Esempio n. 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)
Esempio n. 9
0
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)
Esempio n. 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))
Esempio n. 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))
Esempio n. 12
0
def get_PyTypeObject():
    return get_global_typedef('PyTypeObject')
Esempio n. 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))
Esempio n. 14
0
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'
Esempio n. 15
0
def get_Py_ssize_t():
    return get_global_typedef('Py_ssize_t')
Esempio n. 16
0
def get_Py_buffer():
    return get_global_typedef('Py_buffer')
Esempio n. 17
0
def Py_UNICODE():
    return get_global_typedef('Py_UNICODE')
Esempio n. 18
0
def get_PyBytesObject():
    return get_global_typedef('PyBytesObject')
Esempio n. 19
0
def get_Py_complex():
    return get_global_typedef('Py_complex')
Esempio n. 20
0
def get_PyUnicodeObject():
    return get_global_typedef('PyUnicodeObject')
Esempio n. 21
0
def get_PyStringObject():
    return get_global_typedef('PyStringObject')
Esempio n. 22
0
def get_PyObjectPtr():
    return get_global_typedef('PyObject').pointer