pycparser 2.20__tar.gz → 2.22__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pycparser-2.20 → pycparser-2.22}/CHANGES +12 -0
- {pycparser-2.20 → pycparser-2.22}/LICENSE +2 -2
- pycparser-2.22/PKG-INFO +28 -0
- {pycparser-2.20 → pycparser-2.22}/README.rst +16 -44
- {pycparser-2.20 → pycparser-2.22}/examples/c-to-c.py +1 -32
- pycparser-2.22/examples/c_files/basic.c +6 -0
- {pycparser-2.20 → pycparser-2.22}/examples/c_files/memmgr.h +1 -1
- pycparser-2.22/examples/c_files/pragmas.c +15 -0
- {pycparser-2.20 → pycparser-2.22}/examples/c_files/year.c +2 -2
- {pycparser-2.20 → pycparser-2.22}/examples/c_json.py +0 -2
- pycparser-2.22/examples/construct_ast_from_scratch.py +53 -0
- {pycparser-2.20 → pycparser-2.22}/examples/dump_ast.py +5 -3
- {pycparser-2.20 → pycparser-2.22}/examples/explore_ast.py +1 -2
- {pycparser-2.20 → pycparser-2.22}/examples/func_calls.py +3 -5
- {pycparser-2.20 → pycparser-2.22}/examples/func_defs.py +1 -2
- pycparser-2.22/examples/func_defs_add_param.py +60 -0
- {pycparser-2.20 → pycparser-2.22}/examples/rewrite_ast.py +11 -10
- pycparser-2.22/examples/serialize_ast.py +34 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser/__init__.py +6 -3
- {pycparser-2.20 → pycparser-2.22}/pycparser/_ast_gen.py +5 -7
- {pycparser-2.20 → pycparser-2.22}/pycparser/_build_tables.py +3 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser/_c_ast.cfg +8 -4
- {pycparser-2.20 → pycparser-2.22}/pycparser/ast_transforms.py +58 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser/c_ast.py +55 -14
- {pycparser-2.20 → pycparser-2.22}/pycparser/c_generator.py +73 -15
- {pycparser-2.20 → pycparser-2.22}/pycparser/c_lexer.py +52 -11
- {pycparser-2.20 → pycparser-2.22}/pycparser/c_parser.py +141 -54
- pycparser-2.22/pycparser/lextab.py +10 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser/ply/lex.py +1 -1
- {pycparser-2.20 → pycparser-2.22}/pycparser/plyparser.py +2 -2
- pycparser-2.22/pycparser/yacctab.py +369 -0
- pycparser-2.22/pycparser.egg-info/PKG-INFO +28 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser.egg-info/SOURCES.txt +12 -1
- {pycparser-2.20 → pycparser-2.22}/setup.cfg +0 -3
- {pycparser-2.20 → pycparser-2.22}/setup.py +8 -8
- pycparser-2.22/tests/__init__.py +0 -0
- pycparser-2.22/tests/c_files/c11.c +56 -0
- {pycparser-2.20 → pycparser-2.22}/tests/c_files/memmgr.h +1 -1
- {pycparser-2.20 → pycparser-2.22}/tests/c_files/year.c +2 -2
- {pycparser-2.20 → pycparser-2.22}/tests/test_c_ast.py +0 -2
- {pycparser-2.20 → pycparser-2.22}/tests/test_c_generator.py +177 -23
- {pycparser-2.20 → pycparser-2.22}/tests/test_c_lexer.py +28 -6
- {pycparser-2.20 → pycparser-2.22}/tests/test_c_parser.py +249 -9
- pycparser-2.22/tests/test_examples.py +24 -0
- {pycparser-2.20 → pycparser-2.22}/tests/test_general.py +16 -16
- pycparser-2.22/tests/test_util.py +51 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/_fake_defines.h +44 -3
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/_fake_typedefs.h +50 -0
- pycparser-2.22/utils/fake_libc_include/wctype.h +2 -0
- pycparser-2.22/utils/fake_libc_include/wordexp.h +2 -0
- pycparser-2.22/utils/fake_libc_include/xcb/xcb.h +2 -0
- pycparser-2.22/utils/fake_libc_include/zlib.h +33 -0
- pycparser-2.20/PKG-INFO +0 -25
- pycparser-2.20/examples/serialize_ast.py +0 -36
- pycparser-2.20/pycparser/lextab.py +0 -10
- pycparser-2.20/pycparser/yacctab.py +0 -338
- pycparser-2.20/pycparser.egg-info/PKG-INFO +0 -25
- pycparser-2.20/tests/all_tests.py +0 -20
- {pycparser-2.20 → pycparser-2.22}/MANIFEST.in +0 -0
- {pycparser-2.20 → pycparser-2.22}/examples/c_files/funky.c +0 -0
- {pycparser-2.20 → pycparser-2.22}/examples/c_files/hash.c +0 -0
- {pycparser-2.20 → pycparser-2.22}/examples/c_files/memmgr.c +0 -0
- {pycparser-2.20 → pycparser-2.22}/examples/cdecl.py +0 -0
- {pycparser-2.20 → pycparser-2.22}/examples/using_cpp_libc.py +0 -0
- {pycparser-2.20 → pycparser-2.22}/examples/using_gcc_E_libc.py +0 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser/ply/__init__.py +0 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser/ply/cpp.py +0 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser/ply/ctokens.py +0 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser/ply/yacc.py +0 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser/ply/ygen.py +0 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser.egg-info/dependency_links.txt +0 -0
- {pycparser-2.20 → pycparser-2.22}/pycparser.egg-info/top_level.txt +0 -0
- {pycparser-2.20 → pycparser-2.22}/tests/c_files/cppd_with_stdio_h.c +0 -0
- {pycparser-2.20 → pycparser-2.22}/tests/c_files/empty.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/tests/c_files/example_c_file.c +0 -0
- {pycparser-2.20 → pycparser-2.22}/tests/c_files/hdir/9/inc.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/tests/c_files/memmgr.c +0 -0
- {pycparser-2.20 → pycparser-2.22}/tests/c_files/memmgr_with_h.c +0 -0
- {pycparser-2.20 → pycparser-2.22}/tests/c_files/simplemain.c +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/X11/Intrinsic.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/X11/Xlib.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/X11/_X11_fake_defines.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/X11/_X11_fake_typedefs.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/_ansi.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/_syslist.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/aio.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/alloca.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/ar.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/argz.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/arpa/inet.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/asm-generic/int-ll64.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/assert.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/complex.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/cpio.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/ctype.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/dirent.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/dlfcn.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/emmintrin.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/endian.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/envz.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/errno.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/fastmath.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/fcntl.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/features.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/fenv.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/float.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/fmtmsg.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/fnmatch.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/ftw.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/getopt.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/glob.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/grp.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/iconv.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/ieeefp.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/immintrin.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/inttypes.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/iso646.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/langinfo.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/libgen.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/libintl.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/limits.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/linux/socket.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/linux/version.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/locale.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/malloc.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/math.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/mir_toolkit/client_types.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/monetary.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/mqueue.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/ndbm.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/net/if.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/netdb.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/netinet/in.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/netinet/tcp.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/newlib.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/nl_types.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/openssl/err.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/openssl/evp.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/openssl/hmac.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/openssl/ssl.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/openssl/x509v3.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/paths.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/poll.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/process.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/pthread.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/pwd.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/reent.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/regdef.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/regex.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/sched.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/search.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/semaphore.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/setjmp.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/signal.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/smmintrin.h +0 -0
- {pycparser-2.20 → pycparser-2.22}/utils/fake_libc_include/spawn.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/stdarg.h → /pycparser-2.22/utils/fake_libc_include/stdalign.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/stdbool.h → /pycparser-2.22/utils/fake_libc_include/stdarg.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/stddef.h → /pycparser-2.22/utils/fake_libc_include/stdatomic.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/stdint.h → /pycparser-2.22/utils/fake_libc_include/stdbool.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/stdio.h → /pycparser-2.22/utils/fake_libc_include/stddef.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/stdlib.h → /pycparser-2.22/utils/fake_libc_include/stdint.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/string.h → /pycparser-2.22/utils/fake_libc_include/stdio.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/strings.h → /pycparser-2.22/utils/fake_libc_include/stdlib.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/stropts.h → /pycparser-2.22/utils/fake_libc_include/stdnoreturn.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/ioctl.h → /pycparser-2.22/utils/fake_libc_include/string.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/ipc.h → /pycparser-2.22/utils/fake_libc_include/strings.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/mman.h → /pycparser-2.22/utils/fake_libc_include/stropts.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/msg.h → /pycparser-2.22/utils/fake_libc_include/sys/ioctl.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/poll.h → /pycparser-2.22/utils/fake_libc_include/sys/ipc.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/resource.h → /pycparser-2.22/utils/fake_libc_include/sys/mman.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/select.h → /pycparser-2.22/utils/fake_libc_include/sys/msg.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/sem.h → /pycparser-2.22/utils/fake_libc_include/sys/poll.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/shm.h → /pycparser-2.22/utils/fake_libc_include/sys/resource.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/socket.h → /pycparser-2.22/utils/fake_libc_include/sys/select.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/stat.h → /pycparser-2.22/utils/fake_libc_include/sys/sem.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/statvfs.h → /pycparser-2.22/utils/fake_libc_include/sys/shm.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/sysctl.h → /pycparser-2.22/utils/fake_libc_include/sys/socket.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/time.h → /pycparser-2.22/utils/fake_libc_include/sys/stat.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/times.h → /pycparser-2.22/utils/fake_libc_include/sys/statvfs.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/types.h → /pycparser-2.22/utils/fake_libc_include/sys/sysctl.h +0 -0
- {pycparser-2.20/utils/fake_libc_include → pycparser-2.22/utils/fake_libc_include/sys}/time.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/uio.h → /pycparser-2.22/utils/fake_libc_include/sys/times.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/un.h → /pycparser-2.22/utils/fake_libc_include/sys/types.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/utsname.h → /pycparser-2.22/utils/fake_libc_include/sys/uio.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/sys/wait.h → /pycparser-2.22/utils/fake_libc_include/sys/un.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/syslog.h → /pycparser-2.22/utils/fake_libc_include/sys/utsname.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/tar.h → /pycparser-2.22/utils/fake_libc_include/sys/wait.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/termios.h → /pycparser-2.22/utils/fake_libc_include/syslog.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/tgmath.h → /pycparser-2.22/utils/fake_libc_include/tar.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/trace.h → /pycparser-2.22/utils/fake_libc_include/termios.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/ulimit.h → /pycparser-2.22/utils/fake_libc_include/tgmath.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/unctrl.h → /pycparser-2.22/utils/fake_libc_include/threads.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/unistd.h → /pycparser-2.22/utils/fake_libc_include/time.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/utime.h → /pycparser-2.22/utils/fake_libc_include/trace.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/utmp.h → /pycparser-2.22/utils/fake_libc_include/ulimit.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/utmpx.h → /pycparser-2.22/utils/fake_libc_include/unctrl.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/wchar.h → /pycparser-2.22/utils/fake_libc_include/unistd.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/wctype.h → /pycparser-2.22/utils/fake_libc_include/utime.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/wordexp.h → /pycparser-2.22/utils/fake_libc_include/utmp.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/xcb/xcb.h → /pycparser-2.22/utils/fake_libc_include/utmpx.h +0 -0
- /pycparser-2.20/utils/fake_libc_include/zlib.h → /pycparser-2.22/utils/fake_libc_include/wchar.h +0 -0
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
+ Starting with version 2.22, please use the GitHub UI
|
|
2
|
+
at https://github.com/eliben/pycparser/tags
|
|
3
|
+
to compare tags in order to find out what changed.
|
|
4
|
+
|
|
5
|
+
+ Version 2.21 (2021.11.06)
|
|
6
|
+
|
|
7
|
+
- Much improved support for C11 (multiple PRs)
|
|
8
|
+
- Support for parehthesized compount statements (#423)
|
|
9
|
+
- Support for modern Python versions (3.9 and 3.10)
|
|
10
|
+
- Fix support for structs with nested enums (#387)
|
|
11
|
+
- Multiple small bug fixes
|
|
12
|
+
|
|
1
13
|
+ Version 2.20 (2020.03.04)
|
|
2
14
|
|
|
3
15
|
- #61: Fix slow backtracking when parsing strings.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
pycparser -- A C parser in Python
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2008-
|
|
3
|
+
Copyright (c) 2008-2022, Eli Bendersky
|
|
4
4
|
All rights reserved.
|
|
5
5
|
|
|
6
6
|
Redistribution and use in source and binary forms, with or without modification,
|
|
@@ -11,7 +11,7 @@ are permitted provided that the following conditions are met:
|
|
|
11
11
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
12
12
|
this list of conditions and the following disclaimer in the documentation
|
|
13
13
|
and/or other materials provided with the distribution.
|
|
14
|
-
* Neither the name of
|
|
14
|
+
* Neither the name of the copyright holder nor the names of its contributors may
|
|
15
15
|
be used to endorse or promote products derived from this software without
|
|
16
16
|
specific prior written permission.
|
|
17
17
|
|
pycparser-2.22/PKG-INFO
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pycparser
|
|
3
|
+
Version: 2.22
|
|
4
|
+
Summary: C parser in Python
|
|
5
|
+
Home-page: https://github.com/eliben/pycparser
|
|
6
|
+
Author: Eli Bendersky
|
|
7
|
+
Author-email: eliben@gmail.com
|
|
8
|
+
Maintainer: Eli Bendersky
|
|
9
|
+
License: BSD-3-Clause
|
|
10
|
+
Platform: Cross Platform
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
pycparser is a complete parser of the C language, written in
|
|
24
|
+
pure Python using the PLY parsing library.
|
|
25
|
+
It parses C code into an AST and can serve as a front-end for
|
|
26
|
+
C compilers or analysis tools.
|
|
27
|
+
|
|
28
|
+
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
===============
|
|
2
|
-
pycparser v2.
|
|
2
|
+
pycparser v2.22
|
|
3
3
|
===============
|
|
4
4
|
|
|
5
|
-
:Author: `Eli Bendersky <https://eli.thegreenplace.net/>`_
|
|
6
5
|
|
|
6
|
+
.. image:: https://github.com/eliben/pycparser/workflows/pycparser-tests/badge.svg
|
|
7
|
+
:align: center
|
|
8
|
+
:target: https://github.com/eliben/pycparser/actions
|
|
9
|
+
|
|
10
|
+
----
|
|
7
11
|
|
|
8
12
|
.. contents::
|
|
9
13
|
:backlinks: none
|
|
@@ -79,9 +83,7 @@ Installing
|
|
|
79
83
|
Prerequisites
|
|
80
84
|
-------------
|
|
81
85
|
|
|
82
|
-
* **pycparser** was tested
|
|
83
|
-
Windows. It should work on any later version (in both the 2.x and 3.x lines)
|
|
84
|
-
as well.
|
|
86
|
+
* **pycparser** was tested with Python 3.8+ on Linux, macOS and Windows.
|
|
85
87
|
|
|
86
88
|
* **pycparser** has no external dependencies. The only non-stdlib library it
|
|
87
89
|
uses is PLY, which is bundled in ``pycparser/ply``. The current PLY version is
|
|
@@ -97,28 +99,10 @@ though.
|
|
|
97
99
|
Installation process
|
|
98
100
|
--------------------
|
|
99
101
|
|
|
100
|
-
|
|
101
|
-
package, you just have to execute the standard ``python setup.py install``. The
|
|
102
|
-
setup script will then place the ``pycparser`` module into ``site-packages`` in
|
|
103
|
-
your Python's installation library.
|
|
104
|
-
|
|
105
|
-
Alternatively, since **pycparser** is listed in the `Python Package Index
|
|
106
|
-
<https://pypi.org/project/pycparser/>`_ (PyPI), you can install it using your
|
|
107
|
-
favorite Python packaging/distribution tool, for example with::
|
|
102
|
+
The recommended way to install **pycparser** is with ``pip``::
|
|
108
103
|
|
|
109
104
|
> pip install pycparser
|
|
110
105
|
|
|
111
|
-
Known problems
|
|
112
|
-
--------------
|
|
113
|
-
|
|
114
|
-
* Some users who've installed a new version of **pycparser** over an existing
|
|
115
|
-
version ran into a problem using the newly installed library. This has to do
|
|
116
|
-
with parse tables staying around as ``.pyc`` files from the older version. If
|
|
117
|
-
you see unexplained errors from **pycparser** after an upgrade, remove it (by
|
|
118
|
-
deleting the ``pycparser`` directory in your Python's ``site-packages``, or
|
|
119
|
-
wherever you installed it) and install again.
|
|
120
|
-
|
|
121
|
-
|
|
122
106
|
Using
|
|
123
107
|
=====
|
|
124
108
|
|
|
@@ -147,10 +131,10 @@ What about the standard C library headers?
|
|
|
147
131
|
C code almost always ``#include``\s various header files from the standard C
|
|
148
132
|
library, like ``stdio.h``. While (with some effort) **pycparser** can be made to
|
|
149
133
|
parse the standard headers from any C compiler, it's much simpler to use the
|
|
150
|
-
provided "fake" standard
|
|
151
|
-
standard C header files that contain only the bare necessities to allow
|
|
152
|
-
parsing of the files that use them. As a bonus, since they're minimal, it
|
|
153
|
-
significantly improve the performance of parsing large C files.
|
|
134
|
+
provided "fake" standard includes for C11 in ``utils/fake_libc_include``. These
|
|
135
|
+
are standard C header files that contain only the bare necessities to allow
|
|
136
|
+
valid parsing of the files that use them. As a bonus, since they're minimal, it
|
|
137
|
+
can significantly improve the performance of parsing large C files.
|
|
154
138
|
|
|
155
139
|
The key point to understand here is that **pycparser** doesn't really care about
|
|
156
140
|
the semantics of types. It only needs to know whether some token encountered in
|
|
@@ -195,7 +179,8 @@ There are a few points to keep in mind when modifying **pycparser**:
|
|
|
195
179
|
|
|
196
180
|
* The code for **pycparser**'s AST nodes is automatically generated from a
|
|
197
181
|
configuration file - ``_c_ast.cfg``, by ``_ast_gen.py``. If you modify the AST
|
|
198
|
-
configuration, make sure to re-generate the code.
|
|
182
|
+
configuration, make sure to re-generate the code. This can be done by running
|
|
183
|
+
the ``_build_tables.py`` script from the ``pycparser`` directory.
|
|
199
184
|
* Make sure you understand the optimized mode of **pycparser** - for that you
|
|
200
185
|
must read the docstring in the constructor of the ``CParser`` class. For
|
|
201
186
|
development you should create the parser without optimizations, so that it
|
|
@@ -228,6 +213,8 @@ tests/:
|
|
|
228
213
|
|
|
229
214
|
utils/fake_libc_include:
|
|
230
215
|
Minimal standard C library include files that should allow to parse any C code.
|
|
216
|
+
Note that these headers now include C11 code, so they may not work when the
|
|
217
|
+
preprocessor is configured to an earlier C standard (like ``-std=c99``).
|
|
231
218
|
|
|
232
219
|
utils/internal/:
|
|
233
220
|
Internal utilities for my own use. You probably don't need them.
|
|
@@ -243,18 +230,3 @@ updating this list because Github does a much better job at tracking
|
|
|
243
230
|
contributions.
|
|
244
231
|
|
|
245
232
|
|
|
246
|
-
CI Status
|
|
247
|
-
=========
|
|
248
|
-
|
|
249
|
-
**pycparser** has automatic testing enabled through the convenient
|
|
250
|
-
`Travis CI project <https://travis-ci.org>`_. Here is the latest build status:
|
|
251
|
-
|
|
252
|
-
.. image:: https://travis-ci.org/eliben/pycparser.png?branch=master
|
|
253
|
-
:align: center
|
|
254
|
-
:target: https://travis-ci.org/eliben/pycparser
|
|
255
|
-
|
|
256
|
-
AppVeyor also helps run tests on Windows:
|
|
257
|
-
|
|
258
|
-
.. image:: https://ci.appveyor.com/api/projects/status/wrup68o5y8nuk1i9?svg=true
|
|
259
|
-
:align: center
|
|
260
|
-
:target: https://ci.appveyor.com/project/eliben/pycparser/
|
|
@@ -7,15 +7,13 @@
|
|
|
7
7
|
# Eli Bendersky [https://eli.thegreenplace.net/]
|
|
8
8
|
# License: BSD
|
|
9
9
|
#------------------------------------------------------------------------------
|
|
10
|
-
from __future__ import print_function
|
|
11
10
|
import sys
|
|
12
11
|
|
|
13
12
|
# This is not required if you've installed pycparser into
|
|
14
13
|
# your site-packages/ with setup.py
|
|
15
|
-
#
|
|
16
14
|
sys.path.extend(['.', '..'])
|
|
17
15
|
|
|
18
|
-
from pycparser import parse_file,
|
|
16
|
+
from pycparser import parse_file, c_generator
|
|
19
17
|
|
|
20
18
|
|
|
21
19
|
def translate_to_c(filename):
|
|
@@ -26,36 +24,7 @@ def translate_to_c(filename):
|
|
|
26
24
|
print(generator.visit(ast))
|
|
27
25
|
|
|
28
26
|
|
|
29
|
-
def _zz_test_translate():
|
|
30
|
-
# internal use
|
|
31
|
-
src = r'''
|
|
32
|
-
|
|
33
|
-
void f(char * restrict joe){}
|
|
34
|
-
|
|
35
|
-
int main(void)
|
|
36
|
-
{
|
|
37
|
-
unsigned int long k = 4;
|
|
38
|
-
int p = - - k;
|
|
39
|
-
return 0;
|
|
40
|
-
}
|
|
41
|
-
'''
|
|
42
|
-
parser = c_parser.CParser()
|
|
43
|
-
ast = parser.parse(src)
|
|
44
|
-
ast.show()
|
|
45
|
-
generator = c_generator.CGenerator()
|
|
46
|
-
|
|
47
|
-
print(generator.visit(ast))
|
|
48
|
-
|
|
49
|
-
# tracing the generator for debugging
|
|
50
|
-
#~ import trace
|
|
51
|
-
#~ tr = trace.Trace(countcallers=1)
|
|
52
|
-
#~ tr.runfunc(generator.visit, ast)
|
|
53
|
-
#~ tr.results().write_results()
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
#------------------------------------------------------------------------------
|
|
57
27
|
if __name__ == "__main__":
|
|
58
|
-
#_zz_test_translate()
|
|
59
28
|
if len(sys.argv) > 1:
|
|
60
29
|
translate_to_c(sys.argv[1])
|
|
61
30
|
else:
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
// minimize pool fragmentation in case of multiple allocations
|
|
50
50
|
// and deallocations, it is advisable to not allocate
|
|
51
51
|
// blocks that are too small.
|
|
52
|
-
// This flag sets the minimal
|
|
52
|
+
// This flag sets the minimal amount of quantas for
|
|
53
53
|
// an allocation. If the size of a ulong is 4 and you
|
|
54
54
|
// set this flag to 16, the minimal size of an allocation
|
|
55
55
|
// will be 4 * 2 * 16 = 128 bytes
|
|
@@ -7,8 +7,8 @@ void convert(int thousands, int hundreds, int tens, int ones)
|
|
|
7
7
|
char *num[] = {"", "One", "Two", "Three", "Four", "Five", "Six",
|
|
8
8
|
"Seven", "Eight", "Nine"};
|
|
9
9
|
|
|
10
|
-
char *for_ten[] = {"", "", "Twenty", "Thirty", "
|
|
11
|
-
"Seventy", "Eighty", "
|
|
10
|
+
char *for_ten[] = {"", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty",
|
|
11
|
+
"Seventy", "Eighty", "Ninety"};
|
|
12
12
|
|
|
13
13
|
char *af_ten[] = {"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
|
|
14
14
|
"Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen"};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# -----------------------------------------------------------------
|
|
2
|
+
# pycparser: construct_ast_from_scratch.py
|
|
3
|
+
#
|
|
4
|
+
# Tiny example of writing an AST from scratch to C code.
|
|
5
|
+
#
|
|
6
|
+
# Andre Ribeiro [https://github.com/Andree37]
|
|
7
|
+
# License: BSD
|
|
8
|
+
# -----------------------------------------------------------------
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
# This is not required if you've installed pycparser into
|
|
12
|
+
# your site-packages/ with setup.py
|
|
13
|
+
sys.path.extend(['.', '..'])
|
|
14
|
+
|
|
15
|
+
from pycparser import c_ast, c_generator
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# target C code:
|
|
19
|
+
# int main() {
|
|
20
|
+
# return 0;
|
|
21
|
+
# }
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def empty_main_function_ast():
|
|
25
|
+
constant_zero = c_ast.Constant(type='int', value='0')
|
|
26
|
+
return_node = c_ast.Return(expr=constant_zero)
|
|
27
|
+
compound_node = c_ast.Compound(block_items=[return_node])
|
|
28
|
+
type_decl_node = c_ast.TypeDecl(declname='main', quals=[],
|
|
29
|
+
type=c_ast.IdentifierType(names=['int']),
|
|
30
|
+
align=[])
|
|
31
|
+
func_decl_node = c_ast.FuncDecl(args=c_ast.ParamList([]),
|
|
32
|
+
type=type_decl_node)
|
|
33
|
+
func_def_node = c_ast.Decl(name='main', quals=[], storage=[], funcspec=[],
|
|
34
|
+
type=func_decl_node, init=None,
|
|
35
|
+
bitsize=None, align=[])
|
|
36
|
+
main_func_node = c_ast.FuncDef(decl=func_def_node, param_decls=None,
|
|
37
|
+
body=compound_node)
|
|
38
|
+
|
|
39
|
+
return main_func_node
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def generate_c_code(my_ast):
|
|
43
|
+
generator = c_generator.CGenerator()
|
|
44
|
+
return generator.visit(my_ast)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if __name__ == '__main__':
|
|
48
|
+
main_function_ast = empty_main_function_ast()
|
|
49
|
+
print("|----------------------------------------|")
|
|
50
|
+
main_function_ast.show(offset=2)
|
|
51
|
+
print("|----------------------------------------|")
|
|
52
|
+
main_c_code = generate_c_code(main_function_ast)
|
|
53
|
+
print("C code: \n%s" % main_c_code)
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
# Eli Bendersky [https://eli.thegreenplace.net/]
|
|
7
7
|
# License: BSD
|
|
8
8
|
#-----------------------------------------------------------------
|
|
9
|
-
from __future__ import print_function
|
|
10
9
|
import argparse
|
|
11
10
|
import sys
|
|
12
11
|
|
|
@@ -14,11 +13,14 @@ import sys
|
|
|
14
13
|
# your site-packages/ with setup.py
|
|
15
14
|
sys.path.extend(['.', '..'])
|
|
16
15
|
|
|
17
|
-
from pycparser import
|
|
16
|
+
from pycparser import parse_file
|
|
18
17
|
|
|
19
18
|
if __name__ == "__main__":
|
|
20
19
|
argparser = argparse.ArgumentParser('Dump AST')
|
|
21
|
-
argparser.add_argument('filename',
|
|
20
|
+
argparser.add_argument('filename',
|
|
21
|
+
default='examples/c_files/basic.c',
|
|
22
|
+
nargs='?',
|
|
23
|
+
help='name of file to parse')
|
|
22
24
|
argparser.add_argument('--coord', help='show coordinates in the dump',
|
|
23
25
|
action='store_true')
|
|
24
26
|
args = argparser.parse_args()
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
# Eli Bendersky [https://eli.thegreenplace.net/]
|
|
13
13
|
# License: BSD
|
|
14
14
|
#-----------------------------------------------------------------
|
|
15
|
-
from __future__ import print_function
|
|
16
15
|
import sys
|
|
17
16
|
|
|
18
17
|
# This is not required if you've installed pycparser into
|
|
@@ -20,7 +19,7 @@ import sys
|
|
|
20
19
|
#
|
|
21
20
|
sys.path.extend(['.', '..'])
|
|
22
21
|
|
|
23
|
-
from pycparser import c_parser
|
|
22
|
+
from pycparser import c_parser
|
|
24
23
|
|
|
25
24
|
# This is some C source to parse. Note that pycparser must begin
|
|
26
25
|
# at the top level of the C file, i.e. with either declarations
|
|
@@ -7,15 +7,13 @@
|
|
|
7
7
|
# Eli Bendersky [https://eli.thegreenplace.net/]
|
|
8
8
|
# License: BSD
|
|
9
9
|
#-----------------------------------------------------------------
|
|
10
|
-
from __future__ import print_function
|
|
11
10
|
import sys
|
|
12
11
|
|
|
13
12
|
# This is not required if you've installed pycparser into
|
|
14
13
|
# your site-packages/ with setup.py
|
|
15
14
|
sys.path.extend(['.', '..'])
|
|
16
15
|
|
|
17
|
-
from pycparser import
|
|
18
|
-
|
|
16
|
+
from pycparser import c_ast, parse_file
|
|
19
17
|
|
|
20
18
|
# A visitor with some state information (the funcname it's looking for)
|
|
21
19
|
class FuncCallVisitor(c_ast.NodeVisitor):
|
|
@@ -41,7 +39,7 @@ if __name__ == "__main__":
|
|
|
41
39
|
filename = sys.argv[1]
|
|
42
40
|
func = sys.argv[2]
|
|
43
41
|
else:
|
|
44
|
-
filename = 'examples/c_files/
|
|
45
|
-
func = '
|
|
42
|
+
filename = 'examples/c_files/basic.c'
|
|
43
|
+
func = 'foo'
|
|
46
44
|
|
|
47
45
|
show_func_calls(filename, func)
|
|
@@ -10,14 +10,13 @@
|
|
|
10
10
|
# Eli Bendersky [https://eli.thegreenplace.net/]
|
|
11
11
|
# License: BSD
|
|
12
12
|
#-----------------------------------------------------------------
|
|
13
|
-
from __future__ import print_function
|
|
14
13
|
import sys
|
|
15
14
|
|
|
16
15
|
# This is not required if you've installed pycparser into
|
|
17
16
|
# your site-packages/ with setup.py
|
|
18
17
|
sys.path.extend(['.', '..'])
|
|
19
18
|
|
|
20
|
-
from pycparser import
|
|
19
|
+
from pycparser import c_ast, parse_file
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
# A simple visitor for FuncDef nodes that prints the names and
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#-----------------------------------------------------------------
|
|
2
|
+
# pycparser: func_defs_add_param.py
|
|
3
|
+
#
|
|
4
|
+
# Example of rewriting AST nodes to add parameters to function
|
|
5
|
+
# definitions. Adds an "int _hidden" to every function.
|
|
6
|
+
#
|
|
7
|
+
# Eli Bendersky [https://eli.thegreenplace.net/]
|
|
8
|
+
# License: BSD
|
|
9
|
+
#-----------------------------------------------------------------
|
|
10
|
+
import sys
|
|
11
|
+
sys.path.extend(['.', '..'])
|
|
12
|
+
|
|
13
|
+
from pycparser import c_parser, c_ast, c_generator
|
|
14
|
+
|
|
15
|
+
text = r"""
|
|
16
|
+
void foo(int a, int b) {
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
void bar() {
|
|
20
|
+
}
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ParamAdder(c_ast.NodeVisitor):
|
|
25
|
+
def visit_FuncDecl(self, node):
|
|
26
|
+
ty = c_ast.TypeDecl(declname='_hidden',
|
|
27
|
+
quals=[],
|
|
28
|
+
align=[],
|
|
29
|
+
type=c_ast.IdentifierType(['int']))
|
|
30
|
+
newdecl = c_ast.Decl(
|
|
31
|
+
name='_hidden',
|
|
32
|
+
quals=[],
|
|
33
|
+
align=[],
|
|
34
|
+
storage=[],
|
|
35
|
+
funcspec=[],
|
|
36
|
+
type=ty,
|
|
37
|
+
init=None,
|
|
38
|
+
bitsize=None,
|
|
39
|
+
coord=node.coord)
|
|
40
|
+
if node.args:
|
|
41
|
+
node.args.params.append(newdecl)
|
|
42
|
+
else:
|
|
43
|
+
node.args = c_ast.ParamList(params=[newdecl])
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == '__main__':
|
|
47
|
+
parser = c_parser.CParser()
|
|
48
|
+
ast = parser.parse(text)
|
|
49
|
+
print("AST before change:")
|
|
50
|
+
ast.show(offset=2)
|
|
51
|
+
|
|
52
|
+
v = ParamAdder()
|
|
53
|
+
v.visit(ast)
|
|
54
|
+
|
|
55
|
+
print("\nAST after change:")
|
|
56
|
+
ast.show(offset=2)
|
|
57
|
+
|
|
58
|
+
print("\nCode after change:")
|
|
59
|
+
generator = c_generator.CGenerator()
|
|
60
|
+
print(generator.visit(ast))
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
# Eli Bendersky [https://eli.thegreenplace.net/]
|
|
7
7
|
# License: BSD
|
|
8
8
|
#-----------------------------------------------------------------
|
|
9
|
-
from __future__ import print_function
|
|
10
9
|
import sys
|
|
11
10
|
|
|
11
|
+
sys.path.extend(['.', '..'])
|
|
12
12
|
from pycparser import c_parser
|
|
13
13
|
|
|
14
14
|
text = r"""
|
|
@@ -18,14 +18,15 @@ void func(void)
|
|
|
18
18
|
}
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
if __name__ == '__main__':
|
|
22
|
+
parser = c_parser.CParser()
|
|
23
|
+
ast = parser.parse(text)
|
|
24
|
+
print("Before:")
|
|
25
|
+
ast.show(offset=2)
|
|
25
26
|
|
|
26
|
-
assign = ast.ext[0].body.block_items[0]
|
|
27
|
-
assign.lvalue.name = "y"
|
|
28
|
-
assign.rvalue.value = 2
|
|
27
|
+
assign = ast.ext[0].body.block_items[0]
|
|
28
|
+
assign.lvalue.name = "y"
|
|
29
|
+
assign.rvalue.value = 2
|
|
29
30
|
|
|
30
|
-
print("After:")
|
|
31
|
-
ast.show(offset=2)
|
|
31
|
+
print("After:")
|
|
32
|
+
ast.show(offset=2)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#-----------------------------------------------------------------
|
|
2
|
+
# pycparser: serialize_ast.py
|
|
3
|
+
#
|
|
4
|
+
# Simple example of serializing AST
|
|
5
|
+
#
|
|
6
|
+
# Hart Chu [https://github.com/CtheSky]
|
|
7
|
+
# Eli Bendersky [https://eli.thegreenplace.net/]
|
|
8
|
+
# License: BSD
|
|
9
|
+
#-----------------------------------------------------------------
|
|
10
|
+
import pickle
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
sys.path.extend(['.', '..'])
|
|
14
|
+
from pycparser import c_parser
|
|
15
|
+
|
|
16
|
+
text = r"""
|
|
17
|
+
void func(void)
|
|
18
|
+
{
|
|
19
|
+
x = 1;
|
|
20
|
+
}
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
if __name__ == '__main__':
|
|
24
|
+
parser = c_parser.CParser()
|
|
25
|
+
ast = parser.parse(text)
|
|
26
|
+
dump_filename = 'ast.pickle'
|
|
27
|
+
|
|
28
|
+
with open(dump_filename, 'wb') as f:
|
|
29
|
+
pickle.dump(ast, f, protocol=pickle.HIGHEST_PROTOCOL)
|
|
30
|
+
|
|
31
|
+
# Deserialize.
|
|
32
|
+
with open(dump_filename, 'rb') as f:
|
|
33
|
+
ast = pickle.load(f)
|
|
34
|
+
ast.show()
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
# License: BSD
|
|
9
9
|
#-----------------------------------------------------------------
|
|
10
10
|
__all__ = ['c_lexer', 'c_parser', 'c_ast']
|
|
11
|
-
__version__ = '2.
|
|
11
|
+
__version__ = '2.22'
|
|
12
12
|
|
|
13
13
|
import io
|
|
14
14
|
from subprocess import check_output
|
|
@@ -49,7 +49,7 @@ def preprocess_file(filename, cpp_path='cpp', cpp_args=''):
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='',
|
|
52
|
-
parser=None):
|
|
52
|
+
parser=None, encoding=None):
|
|
53
53
|
""" Parse a C file using pycparser.
|
|
54
54
|
|
|
55
55
|
filename:
|
|
@@ -71,6 +71,9 @@ def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='',
|
|
|
71
71
|
r'-I../utils/fake_libc_include'
|
|
72
72
|
If several arguments are required, pass a list of strings.
|
|
73
73
|
|
|
74
|
+
encoding:
|
|
75
|
+
Encoding to use for the file to parse
|
|
76
|
+
|
|
74
77
|
parser:
|
|
75
78
|
Optional parser object to be used instead of the default CParser
|
|
76
79
|
|
|
@@ -82,7 +85,7 @@ def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='',
|
|
|
82
85
|
if use_cpp:
|
|
83
86
|
text = preprocess_file(filename, cpp_path, cpp_args)
|
|
84
87
|
else:
|
|
85
|
-
with io.open(filename) as f:
|
|
88
|
+
with io.open(filename, encoding=encoding) as f:
|
|
86
89
|
text = f.read()
|
|
87
90
|
|
|
88
91
|
if parser is None:
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
# Eli Bendersky [https://eli.thegreenplace.net/]
|
|
11
11
|
# License: BSD
|
|
12
12
|
#-----------------------------------------------------------------
|
|
13
|
-
import pprint
|
|
14
13
|
from string import Template
|
|
15
14
|
|
|
16
15
|
|
|
@@ -86,7 +85,6 @@ class NodeCfg(object):
|
|
|
86
85
|
src = self._gen_init()
|
|
87
86
|
src += '\n' + self._gen_children()
|
|
88
87
|
src += '\n' + self._gen_iter()
|
|
89
|
-
|
|
90
88
|
src += '\n' + self._gen_attr_names()
|
|
91
89
|
return src
|
|
92
90
|
|
|
@@ -196,7 +194,7 @@ def _repr(obj):
|
|
|
196
194
|
if isinstance(obj, list):
|
|
197
195
|
return '[' + (',\n '.join((_repr(e).replace('\n', '\n ') for e in obj))) + '\n]'
|
|
198
196
|
else:
|
|
199
|
-
return repr(obj)
|
|
197
|
+
return repr(obj)
|
|
200
198
|
|
|
201
199
|
class Node(object):
|
|
202
200
|
__slots__ = ()
|
|
@@ -206,19 +204,19 @@ class Node(object):
|
|
|
206
204
|
""" Generates a python representation of the current node
|
|
207
205
|
"""
|
|
208
206
|
result = self.__class__.__name__ + '('
|
|
209
|
-
|
|
207
|
+
|
|
210
208
|
indent = ''
|
|
211
209
|
separator = ''
|
|
212
210
|
for name in self.__slots__[:-2]:
|
|
213
211
|
result += separator
|
|
214
212
|
result += indent
|
|
215
213
|
result += name + '=' + (_repr(getattr(self, name)).replace('\n', '\n ' + (' ' * (len(name) + len(self.__class__.__name__)))))
|
|
216
|
-
|
|
214
|
+
|
|
217
215
|
separator = ','
|
|
218
216
|
indent = '\n ' + (' ' * len(self.__class__.__name__))
|
|
219
|
-
|
|
217
|
+
|
|
220
218
|
result += indent + ')'
|
|
221
|
-
|
|
219
|
+
|
|
222
220
|
return result
|
|
223
221
|
|
|
224
222
|
def children(self):
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
# Insert '.' and '..' as first entries to the search path for modules.
|
|
14
14
|
# Restricted environments like embeddable python do not include the
|
|
15
15
|
# current working directory on startup.
|
|
16
|
+
import importlib
|
|
16
17
|
import sys
|
|
17
18
|
sys.path[0:0] = ['.', '..']
|
|
18
19
|
|
|
@@ -32,6 +33,8 @@ c_parser.CParser(
|
|
|
32
33
|
|
|
33
34
|
# Load to compile into .pyc
|
|
34
35
|
#
|
|
36
|
+
importlib.invalidate_caches()
|
|
37
|
+
|
|
35
38
|
import lextab
|
|
36
39
|
import yacctab
|
|
37
40
|
import c_ast
|