Ejemplo n.º 1
0
    def _process_functions(self, objects: ObjectManager):
        wrapper_classes = [
            CFunctionCallbackWrapper, StringArrayWrapper, InoutArgumentWrapper
        ]
        wrappers: List[BaseFunctionWrapper] = [
            i(self.type_manager) for i in wrapper_classes
        ]

        # get all function from objects
        fs: List[GeneratorFunction] = []
        for f in objects.values():
            if isinstance(f, GeneratorFunction):
                fs.append(f)

        # apply user supplied wrappers first
        if self.options.output_arg_pattern:
            self._apply_user_wrapper_by_pattern(
                fs, self.options.output_arg_pattern, OutputArgumentWrapper)
        if self.options.inout_arg_pattern:
            self._apply_user_wrapper_by_pattern(fs,
                                                self.options.inout_arg_pattern,
                                                InoutArgumentWrapper)

        for of in fs:
            # keep apply wrapper until no wrapper can be applied
            wrapped = True
            while wrapped:
                wrapped = self._apply_wrappers_one_round(of, wrappers)

        self._process_functions_with_virtual_arguments_(objects)
Ejemplo n.º 2
0
 def apply_filter(objects: ObjectManager, pattern: str,
                  callback: Callable[["GeneratorSymbol"], None]):
     if pattern:
         r = re.compile(pattern)
         for f in objects.values():  # type: GeneratorSymbol
             m = r.match(f.full_name)
             if m:
                 callback(f)
Ejemplo n.º 3
0
    def process(self) -> PreProcessorResult:
        options = self.options
        objects = ObjectManager()
        result = PreProcessorResult(
            to_generator_type(self.parser_result.g, None, objects))
        result.objects = objects
        self.type_manager = TypeManager(result.g, objects)

        # classes
        self._process_namespace(result.g)

        # constant macros
        result.const_macros = self._process_constant_macros()

        # optional conversion process:
        # const macros -> variables
        if options.treat_const_macros_as_variable:
            for name, v in result.const_macros.items():
                var = GeneratorVariableFromMacro(
                    name=name,
                    generate=v.generate,
                    location=v.location,
                    parent=None,
                    type=v.type,
                    const=True,
                    static=True,
                    value=v.value,
                    literal=v.literal,
                )
                result.g.variables[var.name] = var
                result.objects[var.full_name] = var

        # ignore global variables starts with _
        if options.ignore_global_variables_starts_with_underline:
            result.g.variables = {
                k: v
                for k, v in result.g.variables.items() if not k.startswith("_")
            }

        self._process_functions(result.objects)

        # seeks unsupported functions
        for s in result.objects.values():
            if not self._should_output_symbol(s):
                s.generate = False
                continue

            if isinstance(s, GeneratorFunction):
                if not self._function_supported(s):
                    result.unsupported_functions[s.full_name].append(s)
                    if self.options.ignore_unsupported_functions:
                        s.generate = False

        result.parser_result = self.parser_result
        return result
Ejemplo n.º 4
0
    def _process_functions_with_virtual_arguments_(self,
                                                   objects: ObjectManager):
        """
        default implementation of async call will copy any pointer.
        But it is impossible to copy a polymorphic(has virtual method) class
        """
        def is_virtual_type(obj: GeneratorVariable):
            t = self.type_manager.remove_decorations(obj.type)
            try:
                obj = objects.resolve_all_typedef(t)
                if isinstance(obj, GeneratorClass):
                    return obj.is_polymorphic
            except KeyError:
                pass
            return False

        for f in objects.values():
            if isinstance(f, GeneratorFunction):
                if any(map(is_virtual_type, f.args)):
                    f.calling_type = CallingType.Sync
Ejemplo n.º 5
0
    def _process_functions(self, objects: ObjectManager):
        wrapper_classes = [
            CFunctionCallbackWrapper, StringArrayWrapper, InoutArgumentWrapper
        ]
        wrappers: List[BaseFunctionWrapper] = [
            i(self.type_manager) for i in wrapper_classes
        ]
        for f in objects.values():
            if isinstance(f, GeneratorFunction):
                wrapped = True
                while wrapped:
                    wrapped = False
                    f = f.resolve_wrappers()
                    for w in wrappers:
                        for i, a in enumerate(f.args):
                            if w.can_wrap_arg(f, i):
                                if w.match(f, i, a):
                                    f.wrappers.append(
                                        WrapperInfo(wrapper=w, index=i))
                                    wrapped = True

        self._process_functions_with_virtual_arguments_(objects)