Finding pointer arguments with GnuCParser?
<p>I'm trying to parse this fragment of C code:</p>

<pre><code>void foo(const int *bar, int * const baz);
</code></pre>

<p>using <code>GnuCParser</code>, part of <a href="https://github.com/inducer/pycparserext" rel="nofollow">pycparserext</a>.</p>

<p>Based on <a href="http://stackoverflow.com/a/21872138/28169">this answer</a> I expected to see some <code>PtrDecl</code>s, but here's what I get from <code>ast.show()</code> on the resulting parse tree:</p>

<pre><code>FileAST:
  Decl: foo, [], [], []
    FuncDecl:
      ParamList:
        Decl: bar, ['const'], [], []
          TypeDeclExt: bar, ['const']
            IdentifierType: ['int']
        Decl: baz, [], [], []
          TypeDeclExt: baz, []
            IdentifierType: ['int']
      TypeDecl: foo, []
        IdentifierType: ['void']
</code></pre>

<p>Notice how <code>baz</code>, a "const pointer to <code>int</code>", doesn't have a trace of <code>const</code> (or "pointeryness") in the data printed by <code>ast.show()</code>. Is this difference because of <code>GnuCParser</code>?</p>

<p>How do I figure out the type of <code>baz</code> from the AST? My actual C code needs the GNU parser. I'm using pycparserext version 2016.1.</p>

<p><em>UPDATE</em>: I've created a <a href="https://github.com/inducer/pycparserext/issues/21" rel="nofollow">pycparserext issue on GitHub</a>.</p>

<p>This was due to a bug in pycparserext, it has been fixed now by the maintainer and the issue mentioned in the question has been closed. The fix is in release 2016.2.</p>

<p>The output is now:</p>

<pre><code>&gt;&gt;&gt; from pycparserext.ext_c_parser import GnuCParser
&gt;&gt;&gt; p=GnuCParser()
&gt;&gt;&gt; ast=p.parse("void foo(const int *bar, int * const baz);")
&gt;&gt;&gt; ast.show()
FileAST:
  Decl: foo, [], [], []
    FuncDecl:
      ParamList:
        Decl: bar, ['const'], [], []
          PtrDecl: []
            TypeDecl: bar, ['const']
              IdentifierType: ['int']
        Decl: baz, [], [], []
          PtrDecl: ['const']
            TypeDecl: baz, []
              IdentifierType: ['int']
      TypeDecl: foo, []
        IdentifierType: ['void']
</code></pre>

<p>Clearly this contains more <code>Ptr</code> nodes, which is a very good sign. The pycparserext code has also had a test added to catch this in the future.</p>

<p>Very impressive. :)</p>

python gcc pycparser