Closed h4ck3rm1k3 closed 2 years ago
Did you try this with the git version? @vijunag contributed code recently that might do what you want. At any rate, I've gone ahead and released 2016.1. Let me know if that fixes your issue.
this is git master latest .
On Sat, Apr 2, 2016 at 11:49 AM, Andreas Klöckner notifications@github.com wrote:
Did you try this with the git version? @vijunag https://github.com/vijunag contributed code recently that might do what you want. At any rate, I've gone ahead and released 2016.1. Let me know if that fixes your issue.
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/inducer/pycparserext/issues/17#issuecomment-204741820
James Michael DuPont Kansas Linux Fest http://kansaslinuxfest.us Free/Libre Open Source and Open Knowledge Association of Kansas http://openkansas.us Member of Free Libre Open Source Software Kosova http://www.flossk.org Saving Wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com
Thanks for the report. I'd be happy to consider a patch.
Python 2.7.10 (default, Jul 5 2015, 14:15:43)
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pycparserext.ext_c_parser import GnuCParser
>>> p = GnuCParser()
>>> src="""
... typedef int wchar_t;
... extern wchar_t *wcscpy (wchar_t *restrict __dest,
... const wchar_t *__restrict __src) __attribute ((nothrow , leaf));
...
... """
>>> p.parse(src).show()
FileAST:
Typedef: wchar_t, [], ['typedef']
TypeDecl: wchar_t, []
IdentifierType: ['int']
Decl: wcscpy, [], ['extern'], []
FuncDecl:
ParamList:
Decl: __dest, [], [], []
TypeDeclExt: __dest, []
IdentifierType: ['wchar_t']
Decl: __src, ['const'], [], []
TypeDeclExt: __src, ['const']
IdentifierType: ['wchar_t']
PtrDecl: []
TypeDeclExt: wcscpy, []
IdentifierType: ['wchar_t']
>>> exit()
localhost:~/clone3/pycparserext]$ git log
commit a5d7ef695aed6400fb1cacdfb40faea809d084e5
Author: Vijay Nag <vijay@localhost.localdomain>
Date: Thu Mar 24 17:09:58 2016 +0530
Added support for empty GNU structures
The latest master seems to be working fine for me.
@inducer He doesn't seem to be having my patch looks like since the code at the backtrace is at a different line.
File "/home/jamesmikedupont/py/pycparserext/pycparserext/ext_c_parser.py", line 282, in p_declarator_2 % type(p[1])) NotImplementedError: cannot attach attributes to nodes of type '<class 'pycparser.c_ast.PtrDecl'>'
I just checked all the versions. my branch is up to date with my tests. But look, I am on the latest version of ply and of the pycparser maybe that causes a problem.
it says WARNING: /usr/lib/python2.7/dist-packages/pycparser/plyparser.py:41: Rule 'initializer_list_opt' defined, but not used WARNING: There is 1 unused rule WARNING: Symbol 'initializer_list_opt' is unreachable
ply$ git log -1 commit d776a2ece6c12bf8f8b6a0e65b48546ac6078765 Author: David Beazley dave@dabeaz.com Date: Fri Oct 2 13:07:25 2015 -0500
Bumped version number
pycparser$ git log -1 commit 843362984323854f2ee81b529faa20e148915481 Author: Eli Bendersky eliben@gmail.com Date: Sat Mar 19 05:48:10 2016 -0700
jamesmikedupont@instance-3:~/py/pycparserext$ python test.py
WARNING: /usr/lib/python2.7/dist-packages/pycparser/plyparser.py:41: Rule 'initializer_list_opt' defined, but not used
WARNING: There is 1 unused rule
WARNING: Symbol 'initializer_list_opt' is unreachable
Traceback (most recent call last):
File "test.py", line 9, in <module>
p.parse(src).show()
File "/home/jamesmikedupont/py/pycparserext/pycparserext/ext_c_parser.py", line 64, in parse
return self.cparser.parse(text, lexer=self.clex, debug=debuglevel)
File "/usr/lib/python2.7/dist-packages/ply/yacc.py", line 269, in parse
return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
File "/usr/lib/python2.7/dist-packages/ply/yacc.py", line 975, in parseopt_notrack
p.callable(pslice)
File "/home/jamesmikedupont/py/pycparserext/pycparserext/ext_c_parser.py", line 279, in p_declarator_2
% type(p[1]))
NotImplementedError: cannot attach attributes to nodes of type '<class 'pycparser.c_ast.PtrDecl'>'
Interesting. I just did a clone of latest pycparser and below are the yacc_debug logs and I didn't notice any "unreachable production error"
p = GnuCParser(yacc_debug=1) Generating LALR tables WARNING: 87 shift/reduce conflicts WARNING: 88 reduce/reduce conflicts WARNING: reduce/reduce conflict in state 295 resolved using rule (direct_declarator -> direct_declarator LPAREN identifier_list_opt RPAREN) WARNING: rejected rule (empty ->
) in state 295 WARNING: reduce/reduce conflict in state 296 resolved using rule (direct_declarator -> direct_declarator LPAREN parameter_type_list RPAREN) WARNING: rejected rule (empty -> ) in state 296 WARNING: reduce/reduce conflict in state 341 resolved using rule (primary_expression -> gnu_statement_expression) WARNING: rejected rule (statement -> gnu_statement_expression) in state 341
Also, I suggest you to use the ply/lex tha came along with cparser.
cat pycparserext/ext_c_parser.py
from __future__ import division
import pycparser.c_parser
import pycparser.c_ast as c_ast
try:
import pycparser.ply.yacc as yacc # use this version of ply
except ImportError:
import ply.yacc as yacc
On Sun, Apr 3, 2016 at 1:35 AM, vijunag notifications@github.com wrote:
from future import division import pycparser.c_parser import pycparser.c_ast as c_ast try: import pycparser.ply.yacc as yacc # use this version of ply except ImportError: import ply.yacc as yacc
Hi, I dont need this right now, I am reporting what I found. Please give it a try. I will circle back to this in a while.
James Michael DuPont Kansas Linux Fest http://kansaslinuxfest.us Free/Libre Open Source and Open Knowledge Association of Kansas http://openkansas.us Member of Free Libre Open Source Software Kosova http://www.flossk.org Saving Wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com
Cool. Thanks much for the report anyway.
On Sun, Apr 3, 2016 at 1:35 AM, vijunag notifications@github.com wrote:
from future import division import pycparser.c_parser import pycparser.c_ast as c_ast try: import pycparser.ply.yacc as yacc # use this version of ply except ImportError: import ply.yacc as yacc
Hi, I dont need this right now, I am reporting what I found. Please give it a try. I will circle back to this in a while.
James Michael DuPont Kansas Linux Fest http://kansaslinuxfest.us Free/Libre Open Source and Open Knowledge Association of Kansas http://openkansas.us Member of Free Libre Open Source Software Kosova http://www.flossk.org Saving Wikipedia(tm) articles from deletion http://SpeedyDeletion.wikia.com
May I know how you solve this problem? thank u
typedef int wchar_t; extern wchar_t *wcscpy (wchar_t restrict __dest, const wchar_t restrict src) __attribute ((nothrow , leaf));