How to use the pycparserext.ext_c_parser 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 / test / test_pycparserext.py View on Github external
def test_no_added_attr():
    src = """
    char* foo() {
        return "";
    }

    int main() {
        return 0;
    }
    """
    import pycparserext.ext_c_parser as ext_c_parser
    import pycparserext.ext_c_generator as ext_c_generator

    parser = ext_c_parser.GnuCParser()
    ast = parser.parse(src)
    gen = ext_c_generator.GnuCGenerator()
    print(gen.visit(ast))
    assert "attr" not in gen.visit(ast)
github inducer / pycparserext / test / test_pycparserext.py View on Github external
def test_pointer_reproduction():
    src = """
    struct foo {
        const char                      *bar;
        const char                      *baz;
    };

    int main () {
        return 0;
    }
    """
    import pycparserext.ext_c_parser as ext_c_parser
    import pycparserext.ext_c_generator as ext_c_generator

    parser = ext_c_parser.GnuCParser()
    ast = parser.parse(src)
    gen = ext_c_generator.GnuCGenerator()
    print(gen.visit(ast))
github pinterest / ptracer / tools / extract_ptrace_constants.py View on Github external
def read_user_h(path, include_path):
    text = get_header_text(path, include_path)
    parser = ext_c_parser.GnuCParser()
    fileast = parser.parse(text, path)

    if not isinstance(fileast, c_ast.FileAST):
        die('could not parse user.h')

    typedefs = parse_typedefs(fileast)
    structs = {'user_regs_struct', 'user_fpregs_struct'}
    return parse_structs(fileast, structs, typedefs)
github pinterest / ptracer / tools / extract_ptrace_constants.py View on Github external
def read_signal_h(path, include_path):
    text = get_header_text(path, include_path)
    parser = ext_c_parser.GnuCParser()
    fileast = parser.parse(text, path)

    if not isinstance(fileast, c_ast.FileAST):
        die('could not parse signal.h')

    typedefs = parse_typedefs(fileast)
    structs = {'siginfo_t'}
    return parse_structs(fileast, structs, typedefs)
github pinterest / ptracer / tools / extract_ptrace_constants.py View on Github external
def read_ptrace_h(path, include_path):
    text = get_header_text(path, include_path)
    parser = ext_c_parser.GnuCParser()
    fileast = parser.parse(text, path)

    if not isinstance(fileast, c_ast.FileAST):
        die('could not parse user.h')

    output = ['\n']

    for decl in fileast.ext:
        if (not isinstance(decl, c_ast.Decl) or
                not isinstance(decl.type, c_ast.Enum)):
            continue

        for item in decl.type.values.enumerators:
            if item.name.startswith('PTRACE_'):
                output.append('{} = {}'.format(
                    item.name, render_const(item.value)))