How to use the pygccxml.declarations.templates.is_instantiation 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 gccxml / pygccxml / unittests / templates_tester.py View on Github external
def __test_is_template_impl(self, decl_string):
        self.assertTrue(declarations.templates.is_instantiation(decl_string))
github gjcarneiro / pybindgen / pybindgen / gccxmlparser.py View on Github external
ok = False
                    break
            else:
                ok = True
            if not ok:
                postpone_class(cls, ("waiting for implicit conversion target class %s to be registered first"
                                     % (operator.return_type.partial_decl_string,)))
                continue

            is_exception = self._apply_class_annotations(cls, global_annotations, kwargs)

            custom_template_class_name = None
            template_parameters = ()
            if typedef is None:
                alias = None
                if templates.is_instantiation(cls.decl_string):
                    cls_name, template_parameters = templates.split(cls.name)
                    assert template_parameters
                    if '::' in cls_name:
                        cls_name = cls_name.split('::')[-1]
                    template_instance_names = global_annotations.get('template_instance_names', '')
                    if template_instance_names:
                        for mapping in template_instance_names.split('|'):
                            type_names, name = mapping.split('=>')
                            instance_types = type_names.split(',')
                            if instance_types == template_parameters:
                                custom_template_class_name = name
                                break
                else:
                    cls_name = cls.name
            else:
                cls_name = typedef.name
github gccxml / pygccxml / pygccxml / declarations / declarations_matchers.py View on Github external
def name(self, name):
        self.__name = name
        if not self.__name:
            self.__opt_is_tmpl_inst = None
            self.__opt_tmpl_name = None
            self.__opt_is_full_name = None
            self.__decl_name_only = None
        else:
            self.__opt_is_tmpl_inst = templates.is_instantiation(self.__name)
            self.__opt_tmpl_name = templates.name(self.__name)
            if self.__opt_is_tmpl_inst:
                if '::' in self.__opt_tmpl_name:
                    self.__opt_is_full_name = True
                    self.__decl_name_only = \
                        self.__opt_tmpl_name.split('::')[-1]
                else:
                    self.__opt_is_full_name = False
                    self.__decl_name_only = self.__opt_tmpl_name
                self.__name = templates.normalize(name)
            else:
                if '::' in self.__name:
                    self.__opt_is_full_name = True
                    self.__decl_name_only = self.__name.split('::')[-1]
                else:
                    self.__opt_is_full_name = False
github gjcarneiro / pybindgen / pybindgen / gccxmlparser.py View on Github external
for hook in self._pre_scan_hooks:
                hook(self, member, global_annotations, parameter_annotations)

            if 'ignore' in global_annotations:
                continue

            ## ------------ method --------------------
            if isinstance(member, (calldef.member_function_t, calldef.member_operator_t)):
                is_virtual = (member.virtuality != calldef.VIRTUALITY_TYPES.NOT_VIRTUAL)
                pure_virtual = (member.virtuality == calldef.VIRTUALITY_TYPES.PURE_VIRTUAL)

                kwargs = {} # kwargs passed into the add_method call

                for key, val in global_annotations.items():
                    if key == 'template_instance_names' \
                            and templates.is_instantiation(member.demangled_name):
                        pass
                    elif key == 'pygen_comment':
                        pass
                    elif key == 'unblock_threads':
                        kwargs['unblock_threads'] = annotations_scanner.parse_boolean(val)
                    elif key == 'name':
                        kwargs['custom_name'] = val
                    elif key == 'throw':
                        kwargs['throw'] = self._get_annotation_exceptions(val)
                    else:
                        warnings.warn_explicit("Annotation '%s=%s' not used (used in %s)"
                                               % (key, val, member),
                                               AnnotationsWarning, member.location.file_name, member.location.line)
                if isinstance(member, calldef.member_operator_t):
                    if member.symbol == '()':
                        kwargs['custom_name'] = '__call__'
github Gabrielcarvfer / NS3 / bindings / python / ns3modulescan-modular.py View on Github external
def scan_callback_classes(module_parser, callback_classes_file):
    callback_classes_file.write("callback_classes = [\n")
    for cls in module_parser.module_namespace.classes(function=module_parser.location_filter,
                                                      recursive=False):
        if not cls.name.startswith("Callback<"):
            continue
        assert templates.is_instantiation(cls.decl_string), "%s is not a template instantiation" % cls
        dummy_cls_name, template_parameters = templates.split(cls.decl_string)
        callback_classes_file.write("    %r,\n" % template_parameters)
    callback_classes_file.write("]\n")
github fetchai / ledger / to-sort / python / pybindgen / gccxmlparser.py View on Github external
return_type_spec = self.type_registry.lookup_return(member.return_type,
                                                                    parameter_annotations.get('return', {}))
                argument_specs = []
                for arg in member.arguments:
                    argument_specs.append(self.type_registry.lookup_parameter(arg.type, arg.name,
                                                                              parameter_annotations.get(arg.name, {}),
                                                                              arg.default_value))
                    
                

                if pure_virtual and not class_wrapper.allow_subclassing:
                    class_wrapper.set_cannot_be_constructed("pure virtual method and subclassing disabled")
                    #self.pygen_sink.writeln('cls.set_cannot_be_constructed("pure virtual method not wrapped")')

                custom_template_method_name = None
                if templates.is_instantiation(member.demangled_name):
                    template_parameters = templates.args(member.demangled_name)
                    template_instance_names = global_annotations.get('template_instance_names', '')
                    if template_instance_names:
                        for mapping in template_instance_names.split('|'):
                            type_names, name = mapping.split('=>')
                            instance_types = type_names.split(',')
                            if instance_types == template_parameters:
                                custom_template_method_name = name
                                break
                else:
                    template_parameters = ()

                if member.has_const:
                    kwargs['is_const'] = True
                if member.has_static:
                    kwargs['is_static'] = True
github samueljero / snake / ns-3-dev / bindings / python / ns3modulescan-modular.py View on Github external
def scan_callback_classes(module_parser, callback_classes_file):
    callback_classes_file.write("callback_classes = [\n")
    for cls in module_parser.module_namespace.classes(function=module_parser.location_filter,
                                                      recursive=False):
        if not cls.name.startswith("Callback<"):
            continue
        assert templates.is_instantiation(cls.decl_string), "%s is not a template instantiation" % cls
        dummy_cls_name, template_parameters = templates.split(cls.decl_string)
        callback_classes_file.write("    %r,\n" % template_parameters)
    callback_classes_file.write("]\n")
github siconos / siconos / io / tools / builder.py View on Github external
if isinstance(type_, declarations.class_t):
            class_names[declarations.full_name(type_)] = type_
            class_ = type_
        elif isinstance(type_, declarations.typedef_t):
            try:
                is_typedef = True
                class_ = class_names['::' + str(type_.type)]
            except:
                class_ = None
        # with the serializable tag
        # (could not find friend functions with pygccxml)
        if class_ is not None and \
            is_serializable(class_) and \
            (is_typedef or not
             declarations.templates.is_instantiation(class_.name)):
            if not unwanted(class_.name):

                if not class_.is_abstract:
                    with_base.append((class_.name, get_priority(type_, class_.name)))

                # print registration macros depending on inheritance
                if class_.bases == []:
                    dest_file.write(
                        'SICONOS_IO_REGISTER({0},\n'.format(name(type_)))
                else:
                    serializable_bases = \
                        reduce(lambda r, b:
                               r + [b.related_class]
                               if is_serializable(b.related_class)
                               and
                               b.related_class.parent.name == siconos_namespace
github cpc / tce / tce / Python-bindings / tools / pygccxml / pyplusplus / code_creators / calldef.py View on Github external
def _create_impl( self ):
        if self.declaration.already_exposed:
            return ''

        result = []

        if not self.works_on_instance:
            exported_class_alias = None
            if declarations.templates.is_instantiation( self.declaration.parent.name ):
                exported_class_alias = self.exported_class_alias
                result.append( 'typedef %s %s;' % ( self.parent.decl_identifier, exported_class_alias ) )
                result.append( os.linesep )
            result.append( self.create_function_type_alias_code(exported_class_alias) )
            result.append( os.linesep * 2 )

        result.append( self.create_def_code() + '( ' )
        result.append( os.linesep + self.indent( '"%s"' % self.alias ) )

        result.append( self.param_sep() )
        result.append( self.create_function_ref_code( not self.works_on_instance ) )

        if self.declaration.use_keywords:
            keywd_args = self.create_keywords_args()
            if keywd_args:
                result.append( self.param_sep() )
github gjcarneiro / pybindgen / pybindgen / gccxmlparser.py View on Github external
type_from_name = normalize_name(str(alias.type))
                type_to_name = normalize_name(utils.ascii('::'.join([module.cpp_namespace_prefix, alias.name])))

                for sym in '', '*', '&':
                    typehandlers.base.add_type_alias(type_from_name+sym, type_to_name+sym)
                    pygen_sink = self._get_pygen_sink_for_definition(alias)
                    if pygen_sink:
                        pygen_sink.writeln("typehandlers.add_type_alias(%r, %r)" % (type_from_name+sym, type_to_name+sym))

                ## Look for forward declarations of class/structs like
                ## "typedef struct _Foo Foo"; these are represented in
                ## pygccxml by a typedef whose .type.declaration is a
                ## class_declaration_t instead of class_t.
                if isinstance(alias.type, cpptypes.declarated_t):
                    cls = alias.type.declaration
                    if templates.is_instantiation(cls.decl_string):
                        continue # typedef to template instantiations, must be fully defined
                    if isinstance(cls, class_declaration_t):

                        global_annotations, param_annotations = annotations_scanner.get_annotations(cls)
                        for hook in self._pre_scan_hooks:
                            hook(self, cls, global_annotations, param_annotations)
                        if 'ignore' in global_annotations:
                            continue

                        kwargs = dict()
                        self._apply_class_annotations(cls, global_annotations, kwargs)
                        kwargs.setdefault("incomplete_type", True)
                        kwargs.setdefault("automatic_type_narrowing", False)
                        kwargs.setdefault("allow_subclassing", False)

                        pygen_sink = self._get_pygen_sink_for_definition(cls)