GithubHelp home page GithubHelp logo

Comments (3)

eliben avatar eliben commented on May 27, 2024

Thanks for the report. Can you provide a full test case using the pycparser API? I assume you're using the C code generator as well?

from pycparser.

schachmat avatar schachmat commented on May 27, 2024

Here you go:

bla.c: int test(const char* const* arg);

test.py:

#!/bin/env python

import sys
from pycparser import parse_file, c_generator, c_ast

sys.path.extend(['.', '..'])

class FuncDeclVisitor(c_ast.NodeVisitor):
    def visit_FuncDecl(self, node):
        decl = c_ast.Decl("hui", None, None, None, node, None, None)
        print(c_generator.CGenerator().visit(decl))

ast = parse_file("bla.c", use_cpp=True, cpp_args=[r'-Ifake', r'-I.'])
FuncDeclVisitor().visit(ast)

output when running test.py is: int test(const char ** const arg)
expected output is: int test(const char * const * arg)

from pycparser.

eliben avatar eliben commented on May 27, 2024

Hmm, curiously pycparser's cdecl also gets this wrong:

$python examples/cdecl.py "const char* const* arg;"
Explaining the declaration: const char* const* arg;

arg is a const pointer to pointer to const char

And:

$ python examples/cdecl.py "const char** const arg;"
Explaining the declaration: const char** const arg;

arg is a pointer to const pointer to const char

Those should be reversed (the first explanation suits the second decl, and vice versa).

The problem may even begin at AST parsing:

    const char ** const arg;
    const char * const * arg2;

FileAST: 
  Decl <ext[0]>: name=arg, quals=['const'], storage=[], funcspec=[]
    PtrDecl <type>: quals=[]
      PtrDecl <type>: quals=['const']
        TypeDecl <type>: declname=arg, quals=['const']
          IdentifierType <type>: names=['char']
  Decl <ext[1]>: name=arg2, quals=['const'], storage=[], funcspec=[]
    PtrDecl <type>: quals=['const']
      PtrDecl <type>: quals=[]
        TypeDecl <type>: declname=arg2, quals=['const']
          IdentifierType <type>: names=['char']

from pycparser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.