本文整理匯總了Python中wrapperbuilder.PyGccWrapperTypeObject.tp_repr方法的典型用法代碼示例。如果您正苦於以下問題:Python PyGccWrapperTypeObject.tp_repr方法的具體用法?Python PyGccWrapperTypeObject.tp_repr怎麽用?Python PyGccWrapperTypeObject.tp_repr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wrapperbuilder.PyGccWrapperTypeObject
的用法示例。
在下文中一共展示了PyGccWrapperTypeObject.tp_repr方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: generate_intermediate_tree_classes
# 需要導入模塊: from wrapperbuilder import PyGccWrapperTypeObject [as 別名]
# 或者: from wrapperbuilder.PyGccWrapperTypeObject import tp_repr [as 別名]
def generate_intermediate_tree_classes():
# Generate a "middle layer" of gcc.Tree subclasses, corresponding to most of the
# values of
# enum_tree_code_class
# from GCC's tree.h
global modinit_preinit
global modinit_postinit
for code_type in type_for_code_class.values():
# We've already built the base class:
if code_type == "PyGccTree_TypeObj":
continue
# Strip off the "PyGcc" prefix and "_TypeObj" suffix:
localname = code_type[5:-8]
getsettable = PyGetSetDefTable("gcc_%s_getset_table" % localname, [])
methods = PyMethodTable("gcc_%s_methods" % localname, [])
pytype = PyGccWrapperTypeObject(
identifier=code_type,
localname=localname,
tp_name="gcc.%s" % localname,
struct_name="PyGccTree",
tp_new="PyType_GenericNew",
tp_base="&PyGccTree_TypeObj",
tp_getset=getsettable.identifier,
tp_methods=methods.identifier,
)
def add_simple_getter(name, c_expression, doc):
getsettable.add_gsdef(
name, cu.add_simple_getter("PyGcc%s_get_%s" % (localname, name), "PyGccTree", c_expression), None, doc
)
if localname == "Declaration":
cu.add_defn(
"""
PyObject *
PyGccDeclaration_get_name(struct PyGccTree *self, void *closure)
{
if (DECL_NAME(self->t.inner)) {
return PyGccString_FromString(IDENTIFIER_POINTER (DECL_NAME (self->t.inner)));
}
Py_RETURN_NONE;
}
static PyObject *
PyGccDeclaration_get_location(struct PyGccTree *self, void *closure)
{
return PyGccLocation_New(gcc_decl_get_location(PyGccTree_as_gcc_decl(self)));
}
"""
)
getsettable.add_gsdef("name", "PyGccDeclaration_get_name", None, "The name of this declaration (string)")
getsettable.add_gsdef(
"location", "PyGccDeclaration_get_location", None, "The gcc.Location for this declaration"
)
add_simple_getter(
"is_artificial",
"PyBool_FromLong(gcc_decl_is_artificial(PyGccTree_as_gcc_decl(self)))",
"Is this a compiler-generated entity?",
)
add_simple_getter(
"is_builtin",
"PyBool_FromLong(gcc_decl_is_builtin(PyGccTree_as_gcc_decl(self)))",
"Is this declaration built in by the compiler?",
)
pytype.tp_repr = "(reprfunc)PyGccDeclaration_repr"
if localname == "Type":
add_simple_getter(
"name",
"PyGccTree_New(gcc_type_get_name(PyGccTree_as_gcc_type(self)))",
"The name of the type as a gcc.Tree, or None",
)
add_simple_getter(
"pointer",
"PyGccPointerType_New(gcc_type_get_pointer(PyGccTree_as_gcc_type(self)))",
"The gcc.PointerType representing '(this_type *)'",
)
getsettable.add_gsdef(
"attributes", "PyGccType_get_attributes", None, "The user-defined attributes on this type"
)
getsettable.add_gsdef("sizeof", "PyGccType_get_sizeof", None, "sizeof() this type, as a gcc.IntegerCst")
def add_type(c_expr_for_node, typename):
# Expose the given global type node within the gcc.Tree API
#
# The table is populated by tree.c:build_common_builtin_nodes
# but unfortunately this seems to be called after our plugin is
# initialized.
#
# Hence we add them as properties, so that they can be looked up on
# demand, rather than trying to look them up once when the module
# is set up
cu.add_defn(
"""
#.........這裏部分代碼省略.........
示例2: generate_intermediate_tree_classes
# 需要導入模塊: from wrapperbuilder import PyGccWrapperTypeObject [as 別名]
# 或者: from wrapperbuilder.PyGccWrapperTypeObject import tp_repr [as 別名]
def generate_intermediate_tree_classes():
# Generate a "middle layer" of gcc.Tree subclasses, corresponding to most of the
# values of
# enum_tree_code_class
# from GCC's tree.h
global modinit_preinit
global modinit_postinit
for code_type in type_for_code_class.values():
# We've already built the base class:
if code_type == 'gcc_TreeType':
continue
# Strip off the "gcc_" prefix and "Type" suffix:
localname = code_type[4:-4]
getsettable = PyGetSetDefTable('gcc_%s_getset_table' % localname, [])
methods = PyMethodTable('gcc_%s_methods' % localname, [])
pytype = PyGccWrapperTypeObject(identifier = code_type,
localname = localname,
tp_name = 'gcc.%s' % localname,
struct_name = 'PyGccTree',
tp_new = 'PyType_GenericNew',
tp_base = '&gcc_TreeType',
tp_getset = getsettable.identifier,
tp_methods = methods.identifier)
def add_simple_getter(name, c_expression, doc):
getsettable.add_gsdef(name,
cu.add_simple_getter('gcc_%s_get_%s' % (localname, name),
'PyGccTree',
c_expression),
None,
doc)
if localname == 'Declaration':
cu.add_defn("""
PyObject *
gcc_Declaration_get_name(struct PyGccTree *self, void *closure)
{
if (DECL_NAME(self->t)) {
return gcc_python_string_from_string(IDENTIFIER_POINTER (DECL_NAME (self->t)));
}
Py_RETURN_NONE;
}
static PyObject *
gcc_Declaration_get_location(struct PyGccTree *self, void *closure)
{
return gcc_python_make_wrapper_location(DECL_SOURCE_LOCATION(self->t));
}
""")
getsettable.add_gsdef('name',
'gcc_Declaration_get_name',
None,
'The name of this declaration (string)')
getsettable.add_gsdef('location',
'gcc_Declaration_get_location',
None,
'The gcc.Location for this declaration')
add_simple_getter('is_artificial',
'PyBool_FromLong(DECL_ARTIFICIAL(self->t))',
"Is this a compiler-generated entity?")
add_simple_getter('is_builtin',
'PyBool_FromLong(DECL_IS_BUILTIN(self->t))',
"Is this declaration built in by the compiler?")
pytype.tp_repr = '(reprfunc)gcc_Declaration_repr'
if localname == 'Type':
add_simple_getter('name',
'gcc_python_make_wrapper_tree(TYPE_NAME(self->t))',
"The name of the type as a gcc.Tree, or None")
add_simple_getter('pointer',
'gcc_python_make_wrapper_tree(build_pointer_type(self->t))',
"The gcc.PointerType representing '(this_type *)'")
getsettable.add_gsdef('attributes',
'gcc_Type_get_attributes',
None,
'The user-defined attributes on this type')
getsettable.add_gsdef('sizeof',
'gcc_Type_get_sizeof',
None,
'sizeof() this type, as a gcc.IntegerCst')
def add_type(c_expr_for_node, typename):
# Expose the given global type node within the gcc.Tree API
#
# The table is populated by tree.c:build_common_builtin_nodes
# but unfortunately this seems to be called after our plugin is
# initialized.
#
# Hence we add them as properties, so that they can be looked up on
# demand, rather than trying to look them up once when the module
# is set up
cu.add_defn("""
PyObject*
#.........這裏部分代碼省略.........