python-efl/efl/eolian/__init__.pyx

1223 lines
35 KiB
Cython

from libc.stdint cimport uintptr_t
from cpython cimport PyUnicode_AsUTF8String
from efl.eina cimport eina_inlist_count, EINA_LOG_DOM_DBG, \
EINA_LOG_DOM_INFO, EINA_LOG_DOM_WARN, EINA_LOG_DOM_ERR, \
EINA_LOG_DOM_CRIT, eina_iterator_next, eina_iterator_free
from efl.utils.conversions cimport _ctouni
from efl.utils.logger cimport add_logger
cdef int EOLIAN_DOM = add_logger("efl.eolian").eina_log_domain
from efl.utils.enum import IntEnum
class FunctionType(IntEnum):
"""Function Type"""
UNRESOLVED = EOLIAN_UNRESOLVED
PROPERTY = EOLIAN_PROPERTY
PROP_SET = EOLIAN_PROP_SET
PROP_GET = EOLIAN_PROP_GET
METHOD = EOLIAN_METHOD
CTOR = EOLIAN_CTOR
class ParameterDir(IntEnum):
"""Parameter Direction"""
IN = EOLIAN_IN_PARAM
OUT = EOLIAN_OUT_PARAM
INOUT = EOLIAN_INOUT_PARAM
class ClassType(IntEnum):
"""Class Type"""
UNKNOWN = EOLIAN_CLASS_UNKNOWN_TYPE
REGULAR = EOLIAN_CLASS_REGULAR
ABSTRACT = EOLIAN_CLASS_ABSTRACT
MIXIN = EOLIAN_CLASS_MIXIN
INTERFACE = EOLIAN_CLASS_INTERFACE
class FunctionScope(IntEnum):
"""Function Scope"""
PUBLIC = EOLIAN_SCOPE_PUBLIC
PROTECTED = EOLIAN_SCOPE_PROTECTED
class TypeType(IntEnum):
"""Type"""
UNKNOWN = EOLIAN_TYPE_UNKNOWN_TYPE
VOID = EOLIAN_TYPE_VOID
REGULAR = EOLIAN_TYPE_REGULAR
POINTER = EOLIAN_TYPE_POINTER
FUNCTION = EOLIAN_TYPE_FUNCTION
cdef class EinaIterator(object):
cdef:
Eina_Iterator *itr
type cls
def __init__(self, type cls):
self.cls = cls
cdef object _set_obj(self, Eina_Iterator *itr):
self.itr = itr
def __iter__(self):
return self
def __next__(self):
cdef:
void *data
bint itr_ret
if self.itr is NULL:
raise StopIteration
itr_ret = eina_iterator_next(self.itr, &data)
if not itr_ret:
EINA_LOG_DOM_ERR(
EOLIAN_DOM, "An error occurred during iteration", NULL
)
eina_iterator_free(self.itr)
raise StopIteration
return void_ptr_to_python_obj(data, self.cls)
cdef object void_ptr_to_python_obj(void *data, type cls):
if data == NULL:
EINA_LOG_DOM_DBG(
EOLIAN_DOM, "struct pointer is NULL", NULL
)
return None
if cls is Class:
return eolian_class_to_python_obj(<const Eolian_Class *>data)
elif cls is Function:
return eolian_func_to_python_obj(<const Eolian_Function *>data)
elif cls is FunctionParameter:
return eolian_func_param_to_python_obj(<const Eolian_Function_Parameter *>data)
elif cls is Type:
return eolian_type_to_python_obj(<const Eolian_Type *>data)
elif cls is Implement:
return eolian_implement_to_python_obj(<const Eolian_Implement *>data)
elif cls is Event:
return eolian_event_to_python_obj(<const Eolian_Event *>data)
elif cls is unicode:
return _ctouni(<const char *>data)
else:
EINA_LOG_DOM_WARN(
EOLIAN_DOM, "Unknown type for conversion", NULL
)
return
cdef Class eolian_class_to_python_obj(const Eolian_Class *o):
cdef Class ret = Class.__new__(Class)
ret._set_obj(o)
return ret
cdef Function eolian_func_to_python_obj(const Eolian_Function *o):
cdef Function ret = Function.__new__(Function)
ret._set_obj(o)
return ret
cdef FunctionParameter eolian_func_param_to_python_obj(const Eolian_Function_Parameter *o):
cdef FunctionParameter ret = FunctionParameter.__new__(FunctionParameter)
ret._set_obj(o)
return ret
cdef Type eolian_type_to_python_obj(const Eolian_Type *o):
cdef Type ret = Type.__new__(Type)
ret._set_obj(o)
return ret
cdef Implement eolian_implement_to_python_obj(const Eolian_Implement *o):
cdef Implement ret = Implement.__new__(Implement)
ret._set_obj(o)
return ret
cdef Event eolian_event_to_python_obj(const Eolian_Event *o):
cdef Event ret = Event.__new__(Event)
ret._set_obj(o)
return ret
def eo_file_parse(filename):
"""Parse a given .eo file and fill the database.
During parsing, the class described into the .eo file is created with
all the information related to this class.
:param filename: Name of the file to parse.
"""
if isinstance(filename, unicode): filename = PyUnicode_AsUTF8String(filename)
cdef bint ret = eolian_eo_file_parse(filename)
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in eo_file_parse()", NULL)
return ret
def eot_file_parse(filename):
"""Parse a given .eot file and fill the database.
:param filename: Name of the file to parse.
:see: :func:`eolian_eo_file_parse`
"""
if isinstance(filename, unicode): filename = PyUnicode_AsUTF8String(filename)
cdef bint ret = eolian_eot_file_parse(filename)
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in eot_file_parse()", NULL)
return ret
def init():
"""Init Eolian.
:rtype: int
"""
EINA_LOG_DOM_INFO(EOLIAN_DOM, "Initializing efl.eolian", NULL)
return eolian_init()
def shutdown():
"""Shutdown Eolian.
:rtype: int
"""
EINA_LOG_DOM_INFO(EOLIAN_DOM, "Shutting down efl.eolian", NULL)
return eolian_shutdown()
def directory_scan(directory):
"""Scan the given directory and search for .eo files.
The found files are just open to extract the class name.
:param dir: the directory to scan
:return: True on success, False otherwise.
"""
if isinstance(directory, unicode): directory = PyUnicode_AsUTF8String(directory)
cdef bint ret = eolian_directory_scan(directory)
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in directory_scan()", NULL)
return ret
def system_directory_scan():
"""Scan the system directory (recursively) and search for .eo and
.eot files.
:return: True on success, False otherwise.
"""
cdef bint ret = eolian_system_directory_scan()
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in system_directory_scan()", NULL)
return ret
def all_eo_files_parse():
"""Force parsing of all the files located in the directories
given in eolian_directory_scan.
:return: True on success, False otherwise.
:see: :py:func:`directory_scan`
"""
cdef bint ret = eolian_all_eo_files_parse()
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in all_eo_files_parse()", NULL)
return ret
def all_eot_files_parse():
"""Force parsing of all the .eot files located in the directories
given in eolian_directory_scan.
:return: True on success, False otherwise.
:see: :py:func:`directory_scan`
"""
cdef bint ret = eolian_all_eot_files_parse()
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in all_eot_files_parse()", NULL)
return ret
def show_class(Class klass=None):
"""Show information about a given class.
If ``klass`` is None, this function will print information of
all the classes stored into the database.
:param klass: the class to show
:return: True on success, False otherwise (when class is not found).
"""
cdef bint ret = eolian_show_class(
klass.klass if klass is not None else NULL
)
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in show_class()", NULL)
return ret
def show_typedef(alias):
"""Show information about a given typedef.
If ``alias`` is None, this function will print information of
all the typedefs.
:return: True on success, False otherwise (when typedef is not found).
"""
if isinstance(alias, unicode): alias = PyUnicode_AsUTF8String(alias)
cdef bint ret = eolian_show_typedef(
<const char *>alias if alias is not None else NULL
)
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in show_typedef()", NULL)
return ret
def show_struct(name):
"""Show information about a given struct.
If ``name`` is None, this function will print information of
all the named global structs.
:return: True on success, False otherwise (when struct is not found).
"""
if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
cdef bint ret = eolian_show_struct(
<const char *>name if name is not None else NULL
)
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in show_struct()", NULL)
return ret
def show_all():
"""Show information about everything.
This will print a complete dump of all information stored in the Eolian
database.
"""
eolian_show_all()
def all_classes_get():
"""Returns an iterator to all the classes stored into the database.
:return: the iterator
"""
cdef EinaIterator ret = EinaIterator(Class)
ret._set_obj(eolian_all_classes_get())
return ret
def type_aliases_get_by_file(file_name):
"""Get an iterator to all aliases contained in a file.
:param fname: the file name without full path
:return: the iterator or NULL
Thanks to internal caching, this is an O(1) operation.
"""
if isinstance(file_name, unicode):
file_name = PyUnicode_AsUTF8String(file_name)
cdef EinaIterator ret = EinaIterator(Type)
ret._set_obj(eolian_type_aliases_get_by_file(file_name))
return ret
def type_structs_get_by_file(file_name):
"""Get an iterator to all named structs contained in a file.
:param fname: the file name without full path
:return: the iterator or None
Thanks to internal caching, this is an O(1) operation.
"""
if isinstance(file_name, unicode):
file_name = PyUnicode_AsUTF8String(file_name)
cdef EinaIterator ret = EinaIterator(Type)
ret._set_obj(eolian_type_structs_get_by_file(file_name))
return ret
cdef class Class(object):
cdef const Eolian_Class *klass
cdef _set_obj(self, const Eolian_Class *obj):
self.klass = obj
def __init__(self):
pass
def __repr__(self):
return (
"<%s (full_name=%s, filename=%s, type=%s, inherits=%r, "
"description=%s)>" % (
self.name, self.full_name, self.filename,
self.type, self.inherits_list,
self.description.replace('\n', ' ') if self.description else \
None
))
@classmethod
def get_by_name(cls, class_name):
"""Gets a class by its name
:param class_name: name of the class to get.
:return: the class
"""
if isinstance(class_name, unicode): class_name = PyUnicode_AsUTF8String(class_name)
cdef const Eolian_Class *klass = eolian_class_get_by_name(class_name)
@classmethod
def get_by_file(cls, file_name):
"""Gets a class by its filename (name.eo)
:param file_name: the filename
:return: the class stored in the file
"""
if isinstance(file_name, unicode): file_name = PyUnicode_AsUTF8String(file_name)
cdef const Eolian_Class *klass = eolian_class_get_by_file(file_name)
property filename:
"""Returns the name of the file containing the given class.
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_file_get(self.klass))
property full_name:
"""Returns the full name of the given class.
:type: string
The full name and the name of a class will be different if namespaces
are used.
"""
def __get__(self):
return _ctouni(eolian_class_full_name_get(self.klass))
property name:
"""Returns the name of the given class.
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_name_get(self.klass))
property namespaces:
"""Returns an iterator to the namespaces of the given class.
:return: the iterator on success or None otherwise.
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(unicode)
ret._set_obj(eolian_class_namespaces_get(self.klass))
return ret
property type:
"""Returns the class type of the given class
:type: :class:`ClassType`
"""
def __get__(self):
return ClassType(eolian_class_type_get(self.klass))
def function_get_by_name(self, func_name, Eolian_Function_Type f_type):
"""Get a function in a class by its name and type
:param func_name: name of the function
:param f_type: type of the function
:return: the function id if found, None otherwise.
"""
if isinstance(func_name, unicode):
func_name = PyUnicode_AsUTF8String(func_name)
return eolian_func_to_python_obj(
eolian_class_function_get_by_name(self.klass, func_name, f_type)
)
property description:
"""Returns the description of a class.
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_description_get(self.klass))
property legacy_prefix:
"""Returns the legacy prefix of a class
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_legacy_prefix_get(self.klass))
property eo_prefix:
"""Returns the eo prefix of a class
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_eo_prefix_get(self.klass))
property data_type:
"""Returns the data type of a class
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_data_type_get(self.klass))
property inherits:
"""Returns an iterator to the names of inherit classes of a class
:return: the iterator
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(unicode)
ret._set_obj(eolian_class_inherits_get(self.klass))
return ret
def functions_get(self, Eolian_Function_Type func_type):
"""Returns an iterator to functions of a class.
:param func_type: type of the functions to insert into the list.
:return: the iterator
"""
cdef EinaIterator ret = EinaIterator(Function)
ret._set_obj(eolian_class_functions_get(self.klass, func_type))
return ret
property implements:
"""Get an iterator to the overriding functions defined in a class.
:return: the iterator
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(unicode)
ret._set_obj(eolian_class_implements_get(self.klass))
return ret
property events:
"""Get an iterator to the events defined in a class.
:return: the iterator
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(Event)
ret._set_obj(eolian_class_events_get(self.klass))
return ret
property constructor_enabled:
"""Indicates if the class constructor has to invoke
a non-generated class constructor function.
:type: bool
"""
def __get__(self):
return bool(eolian_class_ctor_enable_get(self.klass))
property destructor_enabled:
"""Indicates if the class destructor has to invoke
a non-generated class destructor function.
:type: bool
"""
def __get__(self):
return bool(eolian_class_dtor_enable_get(self.klass))
def function_get_by_name(self, func_name, Eolian_Function_Type f_type):
"""Find a function in a class by its name and type
:param func_name: name of the function
:type func_name: string
:param f_type: type of the function
:type ftype: :class:`FunctionType`
:return: the function id if found, None otherwise.
"""
if isinstance(func_name, unicode):
func_name = PyUnicode_AsUTF8String(func_name)
return eolian_func_to_python_obj(
eolian_class_function_get_by_name(
self.klass, func_name, f_type
)
)
cdef class Function(object):
cdef const Eolian_Function *function_id
cdef _set_obj(self, const Eolian_Function *obj):
self.function_id = obj
def __init__(self):
pass
def __repr__(self):
return (
"<%s (type=%s, scope=%s, is_const=%r)>" % (
self.name, self.type, self.scope, self.object_is_const,
))
property type:
"""Returns the type of a function
:type: :class:`FunctionType`
"""
def __get__(self):
return FunctionType(eolian_function_type_get(self.function_id))
property scope:
"""Returns the scope of a function
:type: :class:`FunctionScope`
"""
def __get__(self):
return FunctionScope(eolian_function_scope_get(self.function_id))
property name:
"""Returns the name of a function
:type: string
"""
def __get__(self):
return _ctouni(eolian_function_name_get(self.function_id))
def full_c_name_get(self, prefix):
"""Returns the full C name of a function (with prefix). It's here
because the C API names are deduplicated (prefix of function and suffix
of prefix merge if applicable) and this helps generators not write the
same code over and over.
:param prefix: function prefix
:type prefix: string
:return: the function name
:rtype: string
"""
if isinstance(prefix, unicode): prefix = PyUnicode_AsUTF8String(prefix)
return _ctouni(eolian_function_full_c_name_get(self.function_id, prefix))
def data_get(self, key):
"""Returns a specific data for a function.
:param key: key to access the data
:type key: string
:return: the data.
:rtype: string
"""
if isinstance(key, unicode): key = PyUnicode_AsUTF8String(key)
return _ctouni(eolian_function_data_get(self.function_id, key))
def is_virtual_pure_get(self, Eolian_Function_Type f_type):
"""Indicates if a function is virtual pure.
:param ftype: type of the function
:type ftype: :class:`FunctionType`
:return: True if virtual pure, False otherwise.
:rtype: bool
"""
return bool(eolian_function_is_virtual_pure(self.function_id, f_type))
property is_class:
"""Get whether a function is a class method/property.
:type: bool
"""
def __get__(self):
return bool(eolian_function_is_class(self.function_id))
def description_get(self, key):
"""Returns a specific description for a function.
:param key: key to access the description
:type key: string
:return: the description.
:rtype: string
"""
if isinstance(key, unicode): key = PyUnicode_AsUTF8String(key)
return _ctouni(eolian_function_data_get(self.function_id, key))
def parameter_get_by_name(self, param_name):
"""Returns a parameter of a function pointed by its id.
:param param_name: Name of the parameter
:type param_name: string
:return: a handle to this parameter.
:rtype: :class:`FunctionParameter`
"""
if isinstance(param_name, unicode):
param_name = PyUnicode_AsUTF8String(param_name)
return eolian_func_param_to_python_obj(
eolian_function_parameter_get_by_name(
self.function_id, param_name
)
)
property property_keys:
"""Returns an iterator to the keys params of a given function.
:type: list of :class:`FunctionParameter`
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(unicode)
ret._set_obj(eolian_property_keys_get(self.function_id))
return ret
property property_values:
"""Returns an iterator to the values params of a given function.
:type: list of :class:`FunctionParameter`
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(unicode)
ret._set_obj(eolian_property_values_get(self.function_id))
return ret
property parameters:
"""Returns an iterator to the parameter handles for a method/ctor/dtor.
:return: the iterator
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(FunctionParameter)
ret._set_obj(eolian_function_parameters_get(self.function_id))
return ret
def return_type_get(self, Eolian_Function_Type ftype):
"""Get the return type of a function.
:param ftype: Function Type
:type ftype: :class:`FunctionType`
:return: the types of the function return
:rtype: :class:`Type`
"""
return eolian_type_to_python_obj(
eolian_function_return_type_get(
self.function_id, ftype
)
)
def return_default_value_get(self, Eolian_Function_Type ftype):
"""Get the return default value of a function.
:param ftype: type of the function
:type ftype: :class:`FunctionType`
:return: the return default value of the function
:rtype: string
The return default value is needed to return an appropriate
value if an error occurs (eo_do failure...).
The default value is not mandatory, so None can be returned.
"""
return _ctouni(eolian_function_return_default_value_get(
self.function_id, ftype
))
def return_comment_get(self, Eolian_Function_Type ftype):
"""Get the return comment of a function.
:param ftype: type of the function
:type ftype: :class:`FunctionType`
:return: the return comment of the function
:rtype: string
The type of the function is needed because a given function can
represent a property, that can be set and get functions.
"""
return _ctouni(eolian_function_return_comment_get(
self.function_id, ftype
))
def return_is_warn_unused_get(self, Eolian_Function_Type ftype):
"""Indicates if a function return is warn-unused.
:param ftype: type of the function
:type ftype: :class:`FunctionType`
:return: True is warn-unused, False otherwise.
:rtype: bool
The type of the function is needed because a given function can
represent a property, that can be set and get functions.
"""
return bool(eolian_function_return_is_warn_unused(
self.function_id, ftype
))
property object_is_const:
"""Indicates if a function object is const.
:type: bool
"""
def __get__(self):
return bool(eolian_function_object_is_const(self.function_id))
cdef class FunctionParameter(object):
cdef const Eolian_Function_Parameter *param
cdef _set_obj(self, const Eolian_Function_Parameter *obj):
self.param = obj
def __init__(self):
pass
def __repr__(self):
info = self.information
return (
"<%s (type=%s, direction=%s, is_nonull=%r, description=%s)>" % (
info[2], info[1], info[0], self.is_nonull,
info[3].replace('\n', ' ') if info[3] else None
))
property information:
"""Get information about a function parameter
:type: :class:`ParameterDir` direction, string type, string name,
string description
"""
def __get__(self):
cdef:
Eolian_Parameter_Dir param_dir
const Eolian_Type *type
const char *name
const char *description
eolian_parameter_information_get(
self.param, &param_dir, &type, &name, &description
)
return (
ParameterDir(param_dir),
eolian_type_to_python_obj(type),
_ctouni(name),
_ctouni(description)
)
property type:
"""Get type of a parameter
:type: :py:class:`Type`
"""
def __get__(self):
return eolian_type_to_python_obj(
eolian_parameter_type_get(self.param)
)
property name:
"""Get name of a parameter
:type: string
"""
def __get__(self):
return _ctouni(eolian_parameter_name_get(self.param))
def const_attribute_get(self, bint is_get):
"""Indicates if a parameter has a const attribute.
This function is relevant for properties, to know if a parameter is a
const parameter in the get operation.
:param bool is_get: indicates if the information needed is for get or
set.
:return: True if const in get, False otherwise
"""
return bool(eolian_parameter_const_attribute_get(self.param, is_get))
property is_nonull:
"""Indicates if a parameter cannot be None.
:type: bool
"""
def __get__(self):
return bool(eolian_parameter_is_nonull(self.param))
cdef class Implement(object):
cdef const Eolian_Implement *impl
cdef _set_obj(self, const Eolian_Implement *obj):
self.impl = obj
def __init__(self):
pass
def __repr__(self):
info = self.information
if not info:
info = (None, None, None)
return (
"<%s (class=%r, function=%r, type=%r)>" % (
self.full_name, info[0], info[1], info[2],
))
property full_name:
"""Get full string of an overriding function (implement).
:type: string
"""
def __get__(self):
return _ctouni(eolian_implement_full_name_get(self.impl))
property information:
"""Get information about an overriding function (implement).
:type: overridden :py:class:`Class`, overridden :py:class:`Function`,
overridden :class:`FunctionType`
"""
def __get__(self):
cdef:
const Eolian_Class *klass
const Eolian_Function *function
Eolian_Function_Type type
if not eolian_implement_information_get(self.impl,
&klass,
&function,
&type
):
EINA_LOG_DOM_DBG(
EOLIAN_DOM, "Fetching info for Implement %s failed",
eolian_implement_full_name_get(self.impl)
)
return None
return (
eolian_class_to_python_obj(klass),
eolian_func_to_python_obj(function),
FunctionType(type)
)
cdef class Event(object):
cdef const Eolian_Event *event
cdef _set_obj(self, const Eolian_Event *obj):
self.event = obj
def __init__(self):
pass
def __repr__(self):
info = self.information
if info:
return (
"<%s (type=%s, description=%s)>" % (
info[0], info[1], info[2]
))
else:
return "<Event>"
property information:
"""Get information about an event.
:type: name of the event (string), type of the event (string),
description of the event (string)
"""
def __get__(self):
cdef:
const char *event_name
const Eolian_Type *event_type
const char *event_desc
if not eolian_class_event_information_get(
self.event, &event_name, &event_type, &event_desc
):
EINA_LOG_DOM_WARN(
EOLIAN_DOM, "Fetching info for an event failed", NULL
)
return None
return (
_ctouni(event_name),
eolian_type_to_python_obj(event_type),
_ctouni(event_desc)
)
cdef class Type(object):
"""Parameter/return type."""
cdef const Eolian_Type *tp
cdef _set_obj(self, const Eolian_Type *obj):
self.tp = obj
def __init__(self):
pass
@classmethod
def alias_get_by_name(cls, name):
"""Get an alias type by name. Supports namespaces.
:param name: the name of the alias
:return: the alias type or None
"""
cdef Type ret = cls.__new__(cls)
if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
ret._set_obj(eolian_type_alias_get_by_name(name))
return ret
@classmethod
def struct_get_by_name(cls, name):
"""Get a struct by name. Supports namespaces.
:param name: the name of the struct
:return: the struct or None
"""
cdef Type ret = cls.__new__(cls)
if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
ret._set_obj(eolian_type_struct_get_by_name(name))
return ret
property type:
"""Get the type of a type (regular, function, pointer)
:return: EOLIAN_TYPE_UNKNOWN_TYPE when ``tp`` is None, otherwise
EOLIAN_TYPE_REGULAR, EOLIAN_TYPE_POINTER or EOLIAN_TYPE_FUNCTION.
"""
def __get__(self):
return TypeType(eolian_type_type_get(self.tp))
property arguments:
"""Get an iterator to all arguments of a function type.
:return: the iterator when ``tp`` is an EOLIAN_TYPE_FUNCTION, None otherwise.
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(unicode)
ret._set_obj(eolian_type_arguments_get(self.tp))
return ret
property subtypes:
"""Get an iterator to all subtypes of a type.
:return: the iterator when ``tp`` is an EOLIAN_TYPE_REGULAR or
EOLIAN_TYPE_POINTER and has subtypes, None otherwise.
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(Type)
ret._set_obj(eolian_type_subtypes_get(self.tp))
return ret
property struct_field_names:
"""Get an iterator to all field names of a struct type.
:return: the iterator when ``tp`` is EOLIAN_TYPE_STRUCT, None otherwise.
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(unicode)
ret._set_obj(eolian_type_struct_field_names_get(self.tp))
return ret
def struct_field_get(self, field):
"""Get a field of a struct type.
:param field: the field name.
:return: the field when ``tp`` is EOLIAN_TYPE_STRUCT, ``field`` is not None
and the field exists, None otherwise.
"""
if isinstance(field, unicode): field = PyUnicode_AsUTF8String(field)
return eolian_type_to_python_obj(eolian_type_struct_field_get(self.tp, field))
def struct_field_description_get(self, field):
"""Get the description of a field of a struct type.
:param field: the field name.
:return: the description when ``tp`` is EOLIAN_TYPE_STRUCT, ``field`` is not None
and the field exists, None otherwise.
"""
if isinstance(field, unicode): field = PyUnicode_AsUTF8String(field)
return _ctouni(eolian_type_struct_field_description_get(self.tp, field))
property description:
"""Get the description of a struct/alias type.
:return: the description when ``tp`` is EOLIAN_TYPE_STRUCT, None otherwise.
"""
def __get__(self):
return _ctouni(eolian_type_description_get(self.tp))
property filename:
"""Get the filename of a struct/alias type.
:return: the filename when ``tp`` is EOLIAN_TYPE_STRUCT, None otherwise.
"""
def __get__(self):
return _ctouni(eolian_type_file_get(self.tp))
property return_type:
"""Get the return type of a function type.
:return: the return type when ``tp`` is an EOLIAN_TYPE_FUNCTION, None otherwise.
"""
def __get__(self):
return eolian_type_to_python_obj(eolian_type_return_type_get(self.tp))
property base_type:
"""Get the base type of a pointer or alias type.
:return: the base type when ``tp`` is a pointer or alias, None otherwise.
"""
def __get__(self):
return eolian_type_to_python_obj(eolian_type_base_type_get(self.tp))
property is_own:
"""Get whether the given type is @own.
:return: True when ``tp`` is a non-function type and not None,
False otherwise.
"""
def __get__(self):
return bool(eolian_type_is_own(self.tp))
property is_const:
"""Get whether the given type is const.
:return: True when ``tp`` is a non-function type and not None,
False otherwise.
"""
def __get__(self):
return bool(eolian_type_is_const(self.tp))
property is_extern:
"""Check if a struct or alias type is extern.
:return: True if it's extern, False otherwise.
"""
def __get__(self):
return bool(eolian_type_is_extern(self.tp))
def c_type_named_get(self, name):
"""Get the full C type name of the given type with a name.
:param name: the name.
:return: The C type name assuming ``tp`` is not None.
Providing the name is useful for function types, as in C a function
pointer type alone is not valid syntax. For non-function types, the
name is simply appended to the type (with a space). C type names do
not include subtypes as C doesn't support them. Name is ignored for
alias types. Alias types are turned into C typedefs.
Keep in mind that if ``name`` is None, the name won't be included.
@see eolian_type_c_type_get
"""
if isinstance(name, unicode): name = PyUnicode_AsUTF8String(name)
return _ctouni(eolian_type_c_type_named_get(self.tp, name))
property c_type:
"""Get the full C type name of the given type without a name.
:return: The C type name assuming ``tp`` is not None.
This behaves exactly like eolian_type_c_type_named_get when name is None.
Keep in mind that this is not useful for function types as a function
pointer type in C cannot be used without a name.
@see eolian_type_c_type_named_get
"""
def __get__(self):
return _ctouni(eolian_type_c_type_get(self.tp))
property name:
"""Get the name of the given type. You have to manually delete
the stringshare. For EOLIAN_TYPE_REGULAR and EOLIAN_TYPE_REGULAR_STRUCT,
this is for example "int". For EOLIAN_TYPE_STRUCT and EOLIAN_TYPE_ALIAS,
this is the name of the alias or of the struct. Keep in mind that the name
doesn't include namespaces for structs and aliases.
:return: the name.
"""
def __get__(self):
return _ctouni(eolian_type_name_get(self.tp))
property full_name:
"""Get the full (namespaced) name of a function. Only works on named
types (not pointers, not functions, not void).
:return: the name.
"""
def __get__(self):
return _ctouni(eolian_type_full_name_get(self.tp))
property namespaces:
"""Get an iterator to the list of namespaces of the given type. Only
works on named types (not pointers, not functions, not void).
:return: the iterator.
"""
def __get__(self):
cdef EinaIterator ret = EinaIterator(unicode)
ret._set_obj(eolian_type_namespaces_get(self.tp))
return ret