How to use the pygccxml.declarations.type_traits.is_const function in pygccxml

To help you get started, we’ve selected a few pygccxml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Gabrielcarvfer / NS3 / 3rd-party / pybindgen / pybindgen / gccxmlparser.py View on Github external
pygen_sink.writeln("cls.add_instance_attribute(%r, %s, is_const=%r)" %
                                       (member.name, _pygen_retval(*return_type_spec),
                                        type_traits.is_const(member.type)))

                ## convert the return value
                try:
                    return_type = ReturnValue.new(*return_type_spec[0], **return_type_spec[1])
                except (TypeLookupError, TypeConfigurationError) as ex:
                    warnings.warn_explicit("Return value '%s' error (used in %s): %r"
                                           % (member.type.partial_decl_string, member, ex),
                                           WrapperWarning, member.location.file_name, member.location.line)
                    continue

                if member.type_qualifiers.has_static:
                    class_wrapper.add_static_attribute(member.name, return_type,
                                                       is_const=type_traits.is_const(member.type))
                else:
                    class_wrapper.add_instance_attribute(member.name, return_type,
                                                         is_const=type_traits.is_const(member.type))
                ## TODO: invoke post_scan_hooks
            elif isinstance(member, calldef.destructor_t):
                pass

        ## gccxml 0.9, unlike 0.7, does not explicitly report inheritted trivial constructors
        ## thankfully pygccxml comes to the rescue!
        if not have_trivial_constructor:
            if type_traits.has_trivial_constructor(cls):
                class_wrapper.add_constructor([])
                pygen_sink.writeln("cls.add_constructor([])")

        if not have_copy_constructor:
            try: # pygccxml > 0.9
github Gabrielcarvfer / NS3 / 3rd-party / pybindgen / pybindgen / gccxmlparser.py View on Github external
warnings.warn_explicit("Member variable %s of class %s will not be wrapped, "
                                           "because wrapping member variables of anonymous types "
                                           "is not yet supported by pybindgen"
                                           % (member.name, cls.partial_decl_string),
                                           NotSupportedWarning, member.location.file_name, member.location.line)
                    continue

                return_type_spec = self.type_registry.lookup_return(member.type, global_annotations)

                ## pygen...
                if 'pygen_comment' in global_annotations:
                    pygen_sink.writeln('## ' + global_annotations['pygen_comment'])
                if member.type_qualifiers.has_static:
                    pygen_sink.writeln("cls.add_static_attribute(%r, %s, is_const=%r)" %
                                       (member.name, _pygen_retval(*return_type_spec),
                                        type_traits.is_const(member.type)))
                else:
                    pygen_sink.writeln("cls.add_instance_attribute(%r, %s, is_const=%r)" %
                                       (member.name, _pygen_retval(*return_type_spec),
                                        type_traits.is_const(member.type)))

                ## convert the return value
                try:
                    return_type = ReturnValue.new(*return_type_spec[0], **return_type_spec[1])
                except (TypeLookupError, TypeConfigurationError) as ex:
                    warnings.warn_explicit("Return value '%s' error (used in %s): %r"
                                           % (member.type.partial_decl_string, member, ex),
                                           WrapperWarning, member.location.file_name, member.location.line)
                    continue

                if member.type_qualifiers.has_static:
                    class_wrapper.add_static_attribute(member.name, return_type,
github gjcarneiro / pybindgen / pybindgen / castxmlparser.py View on Github external
pygen_sink.writeln("cls.add_instance_attribute(%r, %s, is_const=%r)" %
                                       (member.name, _pygen_retval(*return_type_spec),
                                        type_traits.is_const(member.decl_type)))

                ## convert the return value
                try:
                    return_type = ReturnValue.new(*return_type_spec[0], **return_type_spec[1])
                except (TypeLookupError, TypeConfigurationError) as ex:
                    warnings.warn_explicit("Return value '%s' error (used in %s): %r"
                                           % (member.decl_type.partial_decl_string, member, ex),
                                           WrapperWarning, member.location.file_name, member.location.line)
                    continue

                if member.type_qualifiers.has_static:
                    class_wrapper.add_static_attribute(member.name, return_type,
                                                       is_const=type_traits.is_const(member.decl_type))
                else:
                    class_wrapper.add_instance_attribute(member.name, return_type,
                                                         is_const=type_traits.is_const(member.decl_type))
                ## TODO: invoke post_scan_hooks
            elif isinstance(member, calldef_members.destructor_t):
                pass

        ## gccxml 0.9, unlike 0.7, does not explicitly report inheritted trivial constructors
        ## thankfully pygccxml comes to the rescue!
        if not have_trivial_constructor:
            if type_traits_classes.has_trivial_constructor(cls):
                class_wrapper.add_constructor([])
                pygen_sink.writeln("cls.add_constructor([])")

        if not have_copy_constructor:
            try: # pygccxml > 0.9
github gjcarneiro / pybindgen / pybindgen / castxmlparser.py View on Github external
def remove_const(type):
    """removes const from the type definition

    If type is not const type, it will be returned as is
    """

    #nake_type = remove_alias( type )
    nake_type = type
    if not type_traits.is_const( nake_type ):
        return type
    else:
        if isinstance(nake_type, cpptypes.compound_t):
            return nake_type.base
        else:
            return nake_type
###
github gccxml / pygccxml / pygccxml / declarations / type_traits_classes.py View on Github external
recursive=False,
        allow_empty=True)
    noncopyable_vars = []

    if already_visited_cls_vars is None:
        already_visited_cls_vars = []

    message = (
        "__contains_noncopyable_mem_var - %s - TRUE - " +
        "contains const member variable")

    for mvar in mvars:

        var_type = type_traits.remove_reference(mvar.decl_type)

        if type_traits.is_const(var_type):
            no_const = type_traits.remove_const(var_type)
            if type_traits.is_fundamental(no_const) or is_enum(no_const):
                logger.debug(
                    (message + "- fundamental or enum"),
                    var_type.decl_string)
                noncopyable_vars.append(mvar)
            if is_class(no_const):
                logger.debug((message + " - class"), var_type.decl_string)
                noncopyable_vars.append(mvar)
            if type_traits.is_array(no_const):
                logger.debug((message + " - array"), var_type.decl_string)
                noncopyable_vars.append(mvar)

        if type_traits.is_pointer(var_type):
            continue
github Gabrielcarvfer / NS3 / 3rd-party / pybindgen / pybindgen / gccxmlparser.py View on Github external
def remove_const(type):
    """removes const from the type definition

    If type is not const type, it will be returned as is
    """

    #nake_type = remove_alias( type )
    nake_type = type
    if not type_traits.is_const( nake_type ):
        return type
    else:
        if isinstance(nake_type, cpptypes.compound_t):
            return nake_type.base
        else:
            return nake_type
###
github gccxml / pygccxml / pygccxml / declarations / function_traits.py View on Github external
if f1.virtuality == calldef_types.VIRTUALITY_TYPES.NOT_VIRTUAL \
       or f2.virtuality == calldef_types.VIRTUALITY_TYPES.NOT_VIRTUAL:
        # for non-virtual member functions we compare types as usual
        return type_traits.is_same(f1.return_type, f2.return_type)
    rt1 = f1.return_type
    rt2 = f2.return_type
    if type_traits.is_pointer(rt1) and type_traits.is_pointer(rt2):
        rt1 = type_traits.remove_pointer(rt1)
        rt2 = type_traits.remove_pointer(rt2)
    elif type_traits.is_reference(rt1) and type_traits.is_reference(rt2):
        rt1 = type_traits.remove_reference(rt1)
        rt2 = type_traits.remove_reference(rt2)
    else:
        return type_traits.is_same(f1.return_type, f2.return_type)
    if (type_traits.is_const(rt1) and type_traits.is_const(rt2)) \
       or (not type_traits.is_const(rt1) and not type_traits.is_const(rt2)):
        rt1 = type_traits.remove_const(rt1)
        rt2 = type_traits.remove_const(rt2)
    else:
        return False
    if not type_traits_classes.is_class(rt1) or not \
            type_traits_classes.is_class(rt2):
        return type_traits.is_same(rt1, rt2)

    if type_traits_classes.is_union(rt1) or \
            type_traits_classes.is_union(rt2):
        return type_traits.is_same(rt1, rt2)

    c1 = type_traits_classes.class_traits.get_declaration(rt1)
    c2 = type_traits_classes.class_traits.get_declaration(rt2)
    return type_traits.is_same(c1, c2) \
        or type_traits_classes.is_base_and_derived(c1, c2) \
github fetchai / ledger / to-sort / python / pybindgen / gccxmlparser.py View on Github external
else:
                    pygen_sink.writeln("module.add_class(%s)" %
                                       ", ".join([repr(cls_name)] + _pygen_kwargs(kwargs)))

            ## detect use of unregistered container types: need to look at
            ## all parameters and return values of all functions in this namespace...
            for member in cls.get_members(access='public'):
                if member.name.startswith('__'):
                    continue
                for dependency in member.i_depend_on_them(recursive=True):
                    type_info = dependency.depend_on_it
                    if type_traits.is_pointer(type_info):
                        type_info = type_traits.remove_pointer(type_info)
                    elif type_traits.is_reference(type_info):
                        type_info = type_traits.remove_reference(type_info)
                    if type_traits.is_const(type_info):
                        type_info = type_traits.remove_const(type_info)
                    traits = container_traits.find_container_traits(type_info)
                    if traits is None:
                        continue
                    name = normalize_name(type_info.partial_decl_string)
                    # now postpone container registration until after
                    # all classes are registered, because we may
                    # depend on one of those classes for the element
                    # type.
                    self._containers_to_register.append((traits, type_info, None, name))

            if is_exception:
                class_wrapper = module.add_exception(cls_name, **kwargs)
            else:
                class_wrapper = module.add_class(cls_name, **kwargs)
            #print >> sys.stderr, "<<<<>>>> ", cls_name
github gjcarneiro / pybindgen / pybindgen / castxmlparser.py View on Github external
pygen_sink.writeln("root_module.end_section(%r)" % section.name)

        ## detect use of unregistered container types: need to look at
        ## all parameters and return values of all functions in this namespace...
        for fun in module_namespace.free_functions(function=self.location_filter,
                                                   allow_empty=True, recursive=False):
            # logger.debug("Saw free function: %s", fun)
            if fun.name.startswith('__'):
                continue
            for dependency in fun.i_depend_on_them(recursive=True):
                type_info = dependency.depend_on_it
                if type_traits.is_pointer(type_info):
                    type_info = type_traits.remove_pointer(type_info)
                elif type_traits.is_reference(type_info):
                    type_info = type_traits.remove_reference(type_info)
                if type_traits.is_const(type_info):
                    type_info = type_traits.remove_const(type_info)
                traits = container_traits.find_container_traits(type_info)
                if traits is None:
                    continue
                name = normalize_name(type_info.partial_decl_string)
                #print >> sys.stderr, "** type: %s; ---> partial_decl_string: %r; name: %r" %\
                #    (type_info, type_info.partial_decl_string, name)
                self._containers_to_register.append((traits, type_info, None, name))

        ## scan enumerations
        if outer_class is None:
            enums = module_namespace.enumerations(function=self.location_filter,
                                           recursive=False, allow_empty=True)
        else:
            enums = []
            for enum in outer_class.castxml_definition.enumerations(function=self.location_filter,
github gccxml / pygccxml / pygccxml / declarations / type_traits_classes.py View on Github external
if not type_traits.is_fundamental(
                type_traits.base_type(source)) or not \
                type_traits.is_fundamental(
                    type_traits.base_type(target)):
            return False
        if type_traits.is_void(type_traits.base_type(source)) or \
                type_traits.is_void(type_traits.base_type(target)):
            return False
        if type_traits.is_fundamental(source) and \
                type_traits.is_fundamental(target):
            return True
        if not type_traits.is_pointer(source) and \
                type_traits.is_fundamental(target):
            return True
        if not type_traits.is_pointer(source) and \
                type_traits.is_const(target) and \
                type_traits.is_fundamental(target.base):
            return True
        if type_traits.is_fundamental(source) \
           and type_traits.is_reference(target) \
           and type_traits.is_const(target.base) \
           and type_traits.is_fundamental(target.base.base):
            return True  # X => const Y&
        return False