How to use the pycparserext.ext_c_generator.CGeneratorBase function in pycparserext

To help you get started, we’ve selected a few pycparserext 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 inducer / pycparserext / pycparserext / ext_c_generator.py View on Github external
return self.visit(i)
            else:
                return i

        if n.funcspec:
            s = ' '.join(funcspec_to_str(i) for i in n.funcspec) + ' '
        if n.storage:
            s += ' '.join(n.storage) + ' '
        s += self._generate_type(n.type)
        return s

    def visit_AttributeSpecifier(self, n):
        return ' __attribute__((' + self.visit(n.exprlist) + '))'


class GnuCGenerator(AsmAndAttributesMixin, CGeneratorBase):
    def visit_TypeOfDeclaration(self, n):
        return "__typeof__(%s)" % self.visit(n.declaration)

    def visit_TypeOfExpression(self, n):
        return "__typeof__(%s)" % self.visit(n.expr)

    def visit_TypeList(self, n):
        return ', '.join(self.visit(ch) for ch in n.types)


class GNUCGenerator(GnuCGenerator):
    def __init__(self):
        from warnings import warn
        warn("GNUCGenerator is now called GnuCGenerator",
                DeprecationWarning, stacklevel=2)
github inducer / pycparserext / pycparserext / ext_c_generator.py View on Github external
def visit_TypeOfExpression(self, n):
        return "__typeof__(%s)" % self.visit(n.expr)

    def visit_TypeList(self, n):
        return ', '.join(self.visit(ch) for ch in n.types)


class GNUCGenerator(GnuCGenerator):
    def __init__(self):
        from warnings import warn
        warn("GNUCGenerator is now called GnuCGenerator",
                DeprecationWarning, stacklevel=2)


class OpenCLCGenerator(AsmAndAttributesMixin, CGeneratorBase):
    def visit_FileAST(self, n):
        s = ''
        from pycparserext.ext_c_parser import PreprocessorLine
        for ext in n.ext:
            if isinstance(ext, (c_ast.FuncDef, PreprocessorLine)):
                s += self.visit(ext)
            else:
                s += self.visit(ext) + ';\n'
        return s

    def visit_PreprocessorLine(self, n):
        return n.contents