pycparser-2.14/0000775000175000017500000000000012535724325014200 5ustar elibeneliben00000000000000pycparser-2.14/CHANGES0000644000175000017500000002042612535724066015177 0ustar elibeneliben00000000000000+ Version 2.14 (09.06.2015) - Added CParser parameter to specify output directory for generated parsing tables (#84). - Removed lcc's cpp and its license from the distribution. Using lcc's cpp is no longer recommended, now that Clang has binary builds available for Windows. + Version 2.13 (12.05.2015) - Added support for offsetof() the way gcc implements it (special builtin that takes a type as an argument). - Added faked va_* macros (these are expected to come from stdarg.h) - Added a bunch more fake headers and typedefs to support parsing C projects like Git and SQLite without modifications to pycparser. - Added support for empty initializer lists (#79). + Version 2.12 (21.04.2015) - This is a fix release for 2.11; the memory optimization with __slots__ on Coord and AST nodes didn't take weakrefs into account, which broke cffi and its many dependents (iseue #76). Fixed by adding __weakref__ to __slots__. + Version 2.11 (21.04.2015) - Add support for C99 6.5.3.7 p7 - qualifiers within array dimensions in function declarations. Started with issue #21 (reported with initial patch by Robin Martinjak). - Issue #27: bug in handling of unified wstring literals. - Issue #28: fix coord reporting for 'for' loops. - Added ``examples/using_gcc_E_libc.py`` to demonstrate how ``gcc -E`` can be used instead of ``cpp`` for preprocessing. - Pull request #64: support keywords like const, volatile, restrict and static in dimensions in array declarations. - Reduce memory usage of AST nodes (issue #72). - Parsing order of nested pointer declarations fixed (issue #68). + Version 2.10 (03.08.2013) - A number of improvements in the handling of typedef-name ambiguities, contributed by Sye van der Veen in GitHub issue #1: * Allow shadowing of types by identifiers in inner scopes. * Allow struct field names to reside in a separate namespace and have the same names as types. * Allow duplicate typedefs in some cases to mimic real compiler behavior. - c_generator error for ExprList in expression context. - Assume default int type for functions whose argument or return types were not specified. - Relax the lexer a bit w.r.t. some integer suffixes and $ in identifier names (which is supported by some other compilers). + Version 2.09.1 (29.12.2012) - No actual functionality changes. - The source distribution was re-packaged to contain the pre-generated Lex and Yacc tables of PLY. + Version 2.09 (27.12.2012) - The pycparser project has moved to Bitbucket. For this version, issue numbers still refer to the old Googlecode project, unless stated otherwise. Starting with the next version all issue numbers will refer to the new Bitbucket project. - pycparser now carries its PLY dependency along. The pycparser/ply directory contains the source of PLY for the currently supported version. This makes distribution and testing easier. - Issue #79: fix generation of new switch/case AST nodes. - Issue #83: fix parsing and C generation to distinguish between initializer lists in declarations and initializing variables with parenthesized comma-separated expressions. - Issue #84: fix C generation for some statements. - Issues #86 and #87: improve location reporting for parse errors. - Issue #89: fix C generation for K&R-style function definitions. + Version 2.08 (10.08.2012) - Issue 73: initial support for #pragma directives. Consume them without errors and ignore (no tokens are returned). Line numbers are preserved. - Issue 68: more correct handling of source files without any actual content. - Issue 69: running all tests will now set appropriate return code. - Better error reporting in case where multiple type specifiers are provided. Also fixes Issue 60. - Issue 63: line endings cleanup for consistent LF ending. - Issues 64 & 65: added some more headers and typedefs to fake includes. - Refactoring the cpp invocation in parse_file into a separate function, which can also be used as a utility. - Issue 74: some Windows include paths were handled incorrectly. + Version 2.07 (16.06.2012) - Issue 54: added an optional parser argument to parse_file - Issue 59: added some more fake headers for C99 - Issue 62: correct coord for Ellipsis nodes - Issue 57: support for C99 hexadecimal float constants - Made running tests that call on 'cpp' a bit more robust. + Version 2.06 (04.02.2012) - Issue 48: gracefully handle parsing of empty files - Issues 49 & 50: handle more escaped chars in paths to #line - "..\..\test.h". - Support for C99 _Complex type. - CGenerator moves from examples/ to pycparser/ as a first-class citizen, and added some fixes to it. examples/c-to-c.py still stays as a convenience wrapper. - Fix problem with parsing a file in which the first statement is just a semicolon. - Improved the AST created for switch statements, making it closer to the semantic meaning than to the grammar. + Version 2.05 (16.10.2011) - Added support for the C99 ``_Bool`` type and ``stdbool.h`` header file - Expanded ``examples/explore_ast.py`` with more details on working with the AST - Relaxed the rules on parsing unnamed struct members (helps parse ``windows.h``) - Bug fixes: * Fixed spacing issue for some type declarations * Issue 47: display empty statements (lone ';') correctly after parsing + Version 2.04 (21.05.2011) - License changed from LGPL to BSD - Bug fixes: * Issue 31: constraining the scope of typedef definitions * Issues 33, 35: fixes for the c-to-c.py example - Added C99 integer types to fake headers - Added unit tests for the c-to-c.py example + Version 2.03 (06.03.2011) - Bug fixes: * Issue 17: empty file-level declarations * Issue 18: empty statements and declarations in functions * Issue 19: anonymous structs & union fields * Issue 23: fix coordinates of Cast nodes - New example added (``examples/c-to-c.py``) for translating ASTs generated by ``pycparser`` back into C code. - ``pycparser`` is now on PyPI (Python Package Index) - Created `FAQ `_ on the ``pycparser`` project page - Removed support for Python 2.5. ``pycparser`` supports Python 2 from 2.6 and on, and Python 3. + Version 2.02 (10.12.2010) * The name of a ``NamedInitializer`` node was turned into a sequence of nodes instead of an attribute, to make it discoverable by the AST node visitor. * Documentation updates + Version 2.01 (04.12.2010) * Removed dependency on YAML. Parsing of the AST node configuration file is done with a simple parser. * Fixed issue 12: installation problems + Version 2.00 (31.10.2010) * Support for C99 (read `this wiki page `_ for more information). + Version 1.08 (09.10.2010) * Bug fixes: + Correct handling of ``do{} ... while`` statements in some cases + Issues 6 & 7: Concatenation of string literals + Issue 9: Support for unnamed bitfields in structs + Version 1.07 (18.05.2010) * Python 3.1 compatibility: ``pycparser`` was modified to run on Python 3.1 as well as 2.6 + Version 1.06 (10.04.2010) * Bug fixes: + coord not propagated to FuncCall nodes + lexing of the ^= token (XOREQUALS) + parsing failed on some abstract declarator rules * Linux compatibility: fixed end-of-line and ``cpp`` path issues to allow all tests and examples run on Linux + Version 1.05 (16.10.2009) * Fixed the ``parse_file`` auxiliary function to handle multiple arguments to ``cpp`` correctly + Version 1.04 (22.05.2009) * Added the ``fake_libc_include`` directory to allow parsing of C code that uses standard C library include files without dependency on a real C library. * Tested with Python 2.6 and PLY 3.2 + Version 1.03 (31.01.2009) * Accept enumeration lists with a comma after the last item (C99 feature). + Version 1.02 (16.01.2009) * Fixed problem of parsing struct/enum/union names that were named similarly to previously defined ``typedef`` types. + Version 1.01 (09.01.2009) * Fixed subprocess invocation in the helper function parse_file - now it's more portable + Version 1.0 (15.11.2008) * Initial release * Support for ANSI C89 pycparser-2.14/README.rst0000644000175000017500000001763412535724000015666 0ustar elibeneliben00000000000000=============== pycparser v2.14 =============== :Author: `Eli Bendersky `_ .. contents:: :backlinks: none .. sectnum:: Introduction ============ What is pycparser? ------------------ **pycparser** is a parser for the C language, written in pure Python. It is a module designed to be easily integrated into applications that need to parse C source code. What is it good for? -------------------- Anything that needs C code to be parsed. The following are some uses for **pycparser**, taken from real user reports: * C code obfuscator * Front-end for various specialized C compilers * Static code checker * Automatic unit-test discovery * Adding specialized extensions to the C language One of the most popular uses of **pycparser** is in the `cffi `_ library, which uses it to parse the declarations of C functions and types in order to auto-generate FFIs. **pycparser** is unique in the sense that it's written in pure Python - a very high level language that's easy to experiment with and tweak. To people familiar with Lex and Yacc, **pycparser**'s code will be simple to understand. It also has no external dependencies (except for a Python interpreter), making it very simple to install and deploy. Which version of C does pycparser support? ------------------------------------------ **pycparser** aims to support the full C99 language (according to the standard ISO/IEC 9899). Some features from C11 are also supported, and patches to support more are welcome. **pycparser** supports very few GCC extensions, but it's fairly easy to set things up so that it parses code with a lot of GCC-isms successfully. See the `FAQ `_ for more details. What grammar does pycparser follow? ----------------------------------- **pycparser** very closely follows the C grammar provided in the end of the C99 standard document How is pycparser licensed? -------------------------- BSD license. See the `LICENSE` file in the distribution. Contact details --------------- Drop me an email to eliben@gmail.com for any questions regarding **pycparser**. For reporting problems with **pycparser** or submitting feature requests, the best way is to open an `issue `_. Installing ========== Prerequisites ------------- * **pycparser** was tested on Python 2.7, 3.3 and 3.4, on both Linux and Windows. It should work on any later version (in both the 2.x and 3.x lines) as well. * **pycparser** has no external dependencies. The only non-stdlib library it uses is PLY, which is bundled in ``pycparser/ply``. The current PLY version is 3.4 Installation process -------------------- Installing **pycparser** is very simple. Once you download and unzip the package, you just have to execute the standard ``python setup.py install``. The setup script will then place the ``pycparser`` module into ``site-packages`` in your Python's installation library. Alternatively, since **pycparser** is listed in the `Python Package Index `_ (PyPI), you can install it using your favorite Python packaging/distribution tool, for example with:: > pip install pycparser Known problems -------------- * Some users who've installed a new version of **pycparser** over an existing version ran into a problem using the newly installed library. This has to do with parse tables staying around as ``.pyc`` files from the older version. If you see unexplained errors from **pycparser** after an upgrade, remove it (by deleting the ``pycparser`` directory in your Python's ``site-packages``, or wherever you installed it) and install again. Using ===== Interaction with the C preprocessor ----------------------------------- In order to be compilable, C code must be preprocessed by the C preprocessor - ``cpp``. ``cpp`` handles preprocessing directives like ``#include`` and ``#define``, removes comments, and does other minor tasks that prepare the C code for compilation. For all but the most trivial snippets of C code, **pycparser**, like a C compiler, must receive preprocessed C code in order to function correctly. If you import the top-level ``parse_file`` function from the **pycparser** package, it will interact with ``cpp`` for you, as long as it's in your PATH, or you provide a path to it. Note also that you can use ``gcc -E`` or ``clang -E`` instead of ``cpp``. See the ``using_gcc_E_libc.py`` example for more details. Windows users can download and install a binary build of Clang for Windows `from this website `_. What about the standard C library headers? ------------------------------------------ C code almost always includes various header files from the standard C library, like ``stdio.h``. While, with some effort, **pycparser** can be made to parse the standard headers from any C compiler, it's much simpler to use the provided "fake" standard includes in ``utils/fake_libc_include``. These are standard C header files that contain only the bare necessities to allow valid parsing of the files that use them. As a bonus, since they're minimal, it can significantly improve the performance of parsing large C files. The key point to understand here is that **pycparser** doesn't really care about the semantics of types. It only needs to know whether some token encountered in the source is a previously defined type. This is essential in order to be able to parse C correctly. See `this blog post `_ for more details. Basic usage ----------- Take a look at the ``examples`` directory of the distribution for a few examples of using **pycparser**. These should be enough to get you started. Advanced usage -------------- The public interface of **pycparser** is well documented with comments in ``pycparser/c_parser.py``. For a detailed overview of the various AST nodes created by the parser, see ``pycparser/_c_ast.cfg``. There's also a `FAQ available here `_. In any case, you can always drop me an `email `_ for help. Modifying ========= There are a few points to keep in mind when modifying **pycparser**: * The code for **pycparser**'s AST nodes is automatically generated from a configuration file - ``_c_ast.cfg``, by ``_ast_gen.py``. If you modify the AST configuration, make sure to re-generate the code. * Make sure you understand the optimized mode of **pycparser** - for that you must read the docstring in the constructor of the ``CParser`` class. For development you should create the parser without optimizations, so that it will regenerate the Yacc and Lex tables when you change the grammar. Package contents ================ Once you unzip the ``pycparser`` package, you'll see the following files and directories: README.rst: This README file. LICENSE: The pycparser license setup.py: Installation script examples/: A directory with some examples of using **pycparser** pycparser/: The **pycparser** module source code. tests/: Unit tests. utils/fake_libc_include: Minimal standard C library include files that should allow to parse any C code. utils/internal/: Internal utilities for my own use. You probably don't need them. Contributors ============ Some people have contributed to **pycparser** by opening issues on bugs they've found and/or submitting patches. The list of contributors is in the CONTRIBUTORS file in the source distribution. Once **pycparser** moved to Github, I stopped updating this list because Github does a much better job at tracking contributions. CI Status ========= **pycparser** has automatic testing enabled through the convenient `Travis CI project `_. Here is the latest build status: .. image:: https://travis-ci.org/eliben/pycparser.png?branch=master :align: center :target: https://travis-ci.org/eliben/pycparser pycparser-2.14/LICENSE0000644000175000017500000000273512523673432015211 0ustar elibeneliben00000000000000Copyright (c) 2008-2015, Eli Bendersky All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Eli Bendersky nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. pycparser-2.14/utils/0000775000175000017500000000000012535724325015340 5ustar elibeneliben00000000000000pycparser-2.14/utils/fake_libc_include/0000775000175000017500000000000012535724325020742 5ustar elibeneliben00000000000000pycparser-2.14/utils/fake_libc_include/getopt.h0000644000175000017500000000006712523504221022402 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/reent.h0000644000175000017500000000006712523504221022215 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/envz.h0000644000175000017500000000006712523504221022062 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/tgmath.h0000644000175000017500000000006712523504221022364 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/semaphore.h0000644000175000017500000000006712523504221023063 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/_syslist.h0000644000175000017500000000006712523504221022751 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/libgen.h0000644000175000017500000000006712523504221022340 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/dirent.h0000644000175000017500000000006712523504221022365 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/pwd.h0000644000175000017500000000006712523504221021672 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/limits.h0000644000175000017500000000006712523504221022401 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/utime.h0000644000175000017500000000006712523504221022223 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/stddef.h0000644000175000017500000000006712523504221022351 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/dlfcn.h0000644000175000017500000000006712523505605022175 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/stdio.h0000644000175000017500000000006712523504221022222 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/unctrl.h0000644000175000017500000000006712523504221022407 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/regex.h0000644000175000017500000000006712523657361022230 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/fastmath.h0000644000175000017500000000006712523504221022707 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/netdb.h0000644000175000017500000000006712523657422022210 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/zlib.h0000644000175000017500000000006712523657521022054 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/alloca.h0000644000175000017500000000006712523504221022333 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/string.h0000644000175000017500000000006712523504221022406 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/math.h0000644000175000017500000000006712523504221022031 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/malloc.h0000644000175000017500000000006712523504221022347 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/paths.h0000644000175000017500000000006712523504221022217 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/utmp.h0000644000175000017500000000006712523504221022065 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/_ansi.h0000644000175000017500000000006712523504221022171 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/tar.h0000644000175000017500000000006712523504221021666 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/_fake_defines.h0000644000175000017500000000167212523506134023652 0ustar elibeneliben00000000000000#ifndef _FAKE_DEFINES_H #define _FAKE_DEFINES_H #define NULL 0 #define BUFSIZ 1024 #define FOPEN_MAX 20 #define FILENAME_MAX 1024 #ifndef SEEK_SET #define SEEK_SET 0 /* set file offset to offset */ #endif #ifndef SEEK_CUR #define SEEK_CUR 1 /* set file offset to current plus offset */ #endif #ifndef SEEK_END #define SEEK_END 2 /* set file offset to EOF plus offset */ #endif #define __LITTLE_ENDIAN 1234 #define LITTLE_ENDIAN __LITTLE_ENDIAN #define __BIG_ENDIAN 4321 #define BIG_ENDIAN __BIG_ENDIAN #define __BYTE_ORDER __LITTLE_ENDIAN #define BYTE_ORDER __BYTE_ORDER #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 #define RAND_MAX 32767 #define INT_MAX 32767 /* C99 stdbool.h defines */ #define __bool_true_false_are_defined 1 #define false 0 #define true 1 /* va_arg macros and type*/ typedef int va_list; #define va_start(_ap, _type) __builtin_va_start((_ap)) #define va_arg(_ap, _type) __builtin_va_arg((_ap)) #define va_end(_list) #endif pycparser-2.14/utils/fake_libc_include/newlib.h0000644000175000017500000000006712523504221022360 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/unistd.h0000644000175000017500000000006712523504221022406 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/grp.h0000644000175000017500000000006712523504221021670 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/float.h0000644000175000017500000000006712523504221022205 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/regdef.h0000644000175000017500000000006712523504221022334 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/ar.h0000644000175000017500000000006712523504221021502 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/assert.h0000644000175000017500000000006712523504221022401 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/complex.h0000644000175000017500000000006712523504221022547 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/sched.h0000644000175000017500000000006712523504221022166 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/pthread.h0000644000175000017500000000006712523504221022527 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/stdarg.h0000644000175000017500000000006712523504221022364 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/time.h0000644000175000017500000000006712523504221022036 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/iconv.h0000644000175000017500000000006712523504221022216 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/argz.h0000644000175000017500000000006712523504221022043 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/wchar.h0000644000175000017500000000006712523504221022204 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/inttypes.h0000644000175000017500000000006712523504221022757 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/process.h0000644000175000017500000000006712523504221022556 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/termios.h0000644000175000017500000000006712523504221022562 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/endian.h0000644000175000017500000000006712523504221022336 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/locale.h0000644000175000017500000000006712523504221022337 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/ctype.h0000644000175000017500000000006712523504221022224 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/_fake_typedefs.h0000664000175000017500000000653512523660261024067 0ustar elibeneliben00000000000000#ifndef _FAKE_TYPEDEFS_H #define _FAKE_TYPEDEFS_H typedef int size_t; typedef int __builtin_va_list; typedef int __gnuc_va_list; typedef int __int8_t; typedef int __uint8_t; typedef int __int16_t; typedef int __uint16_t; typedef int __int_least16_t; typedef int __uint_least16_t; typedef int __int32_t; typedef int __uint32_t; typedef int __int64_t; typedef int __uint64_t; typedef int __int_least32_t; typedef int __uint_least32_t; typedef int _LOCK_T; typedef int _LOCK_RECURSIVE_T; typedef int _off_t; typedef int __dev_t; typedef int __uid_t; typedef int __gid_t; typedef int _off64_t; typedef int _fpos_t; typedef int _ssize_t; typedef int wint_t; typedef int _mbstate_t; typedef int _flock_t; typedef int _iconv_t; typedef int __ULong; typedef int __FILE; typedef int ptrdiff_t; typedef int wchar_t; typedef int __off_t; typedef int __pid_t; typedef int __loff_t; typedef int u_char; typedef int u_short; typedef int u_int; typedef int u_long; typedef int ushort; typedef int uint; typedef int clock_t; typedef int time_t; typedef int daddr_t; typedef int caddr_t; typedef int ino_t; typedef int off_t; typedef int dev_t; typedef int uid_t; typedef int gid_t; typedef int pid_t; typedef int key_t; typedef int ssize_t; typedef int mode_t; typedef int nlink_t; typedef int fd_mask; typedef int _types_fd_set; typedef int clockid_t; typedef int timer_t; typedef int useconds_t; typedef int suseconds_t; typedef int FILE; typedef int fpos_t; typedef int cookie_read_function_t; typedef int cookie_write_function_t; typedef int cookie_seek_function_t; typedef int cookie_close_function_t; typedef int cookie_io_functions_t; typedef int div_t; typedef int ldiv_t; typedef int lldiv_t; typedef int sigset_t; typedef int __sigset_t; typedef int _sig_func_ptr; typedef int sig_atomic_t; typedef int __tzrule_type; typedef int __tzinfo_type; typedef int mbstate_t; typedef int sem_t; typedef int pthread_t; typedef int pthread_attr_t; typedef int pthread_mutex_t; typedef int pthread_mutexattr_t; typedef int pthread_cond_t; typedef int pthread_condattr_t; typedef int pthread_key_t; typedef int pthread_once_t; typedef int pthread_rwlock_t; typedef int pthread_rwlockattr_t; typedef int pthread_spinlock_t; typedef int pthread_barrier_t; typedef int pthread_barrierattr_t; typedef int jmp_buf; typedef int rlim_t; typedef int sigjmp_buf; typedef int stack_t; typedef int siginfo_t; typedef int z_stream; /* C99 exact-width integer types */ typedef int int8_t; typedef int uint8_t; typedef int int16_t; typedef int uint16_t; typedef int int32_t; typedef int uint32_t; typedef int int64_t; typedef int uint64_t; /* C99 minimum-width integer types */ typedef int int_least8_t; typedef int uint_least8_t; typedef int int_least16_t; typedef int uint_least16_t; typedef int int_least32_t; typedef int uint_least32_t; typedef int int_least64_t; typedef int uint_least64_t; /* C99 fastest minimum-width integer types */ typedef int int_fast8_t; typedef int uint_fast8_t; typedef int int_fast16_t; typedef int uint_fast16_t; typedef int int_fast32_t; typedef int uint_fast32_t; typedef int int_fast64_t; typedef int uint_fast64_t; /* C99 integer types capable of holding object pointers */ typedef int intptr_t; typedef int uintptr_t; /* C99 greatest-width integer types */ typedef int intmax_t; typedef int uintmax_t; /* C99 stdbool.h bool type. _Bool is built-in in C99 */ typedef _Bool bool; typedef int va_list; #endif pycparser-2.14/utils/fake_libc_include/wctype.h0000644000175000017500000000006712523504221022413 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/stdlib.h0000644000175000017500000000006712523504221022361 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/search.h0000644000175000017500000000006712523504221022345 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/fenv.h0000644000175000017500000000006712523504221022036 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/stdbool.h0000644000175000017500000000006712523504221022546 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/langinfo.h0000644000175000017500000000006712523504221022675 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/errno.h0000644000175000017500000000006712523504221022225 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/fcntl.h0000644000175000017500000000006712523504221022206 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/signal.h0000644000175000017500000000006712523504221022355 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/setjmp.h0000644000175000017500000000006712523504221022402 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/iso646.h0000644000175000017500000000006712523504221022132 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/stdint.h0000644000175000017500000000006712523504221022405 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/features.h0000644000175000017500000000006712523504221022716 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/ieeefp.h0000644000175000017500000000006712523504221022335 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/syslog.h0000644000175000017500000000006712523504221022420 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/utils/fake_libc_include/libintl.h0000644000175000017500000000006712523657513022552 0ustar elibeneliben00000000000000#include "_fake_defines.h" #include "_fake_typedefs.h" pycparser-2.14/pycparser/0000775000175000017500000000000012535724325016210 5ustar elibeneliben00000000000000pycparser-2.14/pycparser/_build_tables.py0000644000175000017500000000152312523673260021347 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # pycparser: _build_tables.py # # A dummy for generating the lexing/parsing tables and and # compiling them into .pyc for faster execution in optimized mode. # Also generates AST code from the configuration file. # Should be called from the pycparser directory. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- # Generate c_ast.py from _ast_gen import ASTCodeGenerator ast_gen = ASTCodeGenerator('_c_ast.cfg') ast_gen.generate(open('c_ast.py', 'w')) import sys sys.path[0:0] = ['.', '..'] from pycparser import c_parser # Generates the tables # c_parser.CParser( lex_optimize=True, yacc_debug=False, yacc_optimize=True) # Load to compile into .pyc # import lextab import yacctab import c_ast pycparser-2.14/pycparser/c_ast.py0000644000175000017500000005545012535724325017662 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # ** ATTENTION ** # This code was automatically generated from the file: # _c_ast.cfg # # Do not modify it directly. Modify the configuration file and # run the generator again. # ** ** *** ** ** # # pycparser: c_ast.py # # AST Node classes. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- import sys class Node(object): __slots__ = () """ Abstract base class for AST nodes. """ def children(self): """ A sequence of all children that are Nodes """ pass def show(self, buf=sys.stdout, offset=0, attrnames=False, nodenames=False, showcoord=False, _my_node_name=None): """ Pretty print the Node and all its attributes and children (recursively) to a buffer. buf: Open IO buffer into which the Node is printed. offset: Initial offset (amount of leading spaces) attrnames: True if you want to see the attribute names in name=value pairs. False to only see the values. nodenames: True if you want to see the actual node names within their parents. showcoord: Do you want the coordinates of each Node to be displayed. """ lead = ' ' * offset if nodenames and _my_node_name is not None: buf.write(lead + self.__class__.__name__+ ' <' + _my_node_name + '>: ') else: buf.write(lead + self.__class__.__name__+ ': ') if self.attr_names: if attrnames: nvlist = [(n, getattr(self,n)) for n in self.attr_names] attrstr = ', '.join('%s=%s' % nv for nv in nvlist) else: vlist = [getattr(self, n) for n in self.attr_names] attrstr = ', '.join('%s' % v for v in vlist) buf.write(attrstr) if showcoord: buf.write(' (at %s)' % self.coord) buf.write('\n') for (child_name, child) in self.children(): child.show( buf, offset=offset + 2, attrnames=attrnames, nodenames=nodenames, showcoord=showcoord, _my_node_name=child_name) class NodeVisitor(object): """ A base NodeVisitor class for visiting c_ast nodes. Subclass it and define your own visit_XXX methods, where XXX is the class name you want to visit with these methods. For example: class ConstantVisitor(NodeVisitor): def __init__(self): self.values = [] def visit_Constant(self, node): self.values.append(node.value) Creates a list of values of all the constant nodes encountered below the given node. To use it: cv = ConstantVisitor() cv.visit(node) Notes: * generic_visit() will be called for AST nodes for which no visit_XXX method was defined. * The children of nodes for which a visit_XXX was defined will not be visited - if you need this, call generic_visit() on the node. You can use: NodeVisitor.generic_visit(self, node) * Modeled after Python's own AST visiting facilities (the ast module of Python 3.0) """ def visit(self, node): """ Visit a node. """ method = 'visit_' + node.__class__.__name__ visitor = getattr(self, method, self.generic_visit) return visitor(node) def generic_visit(self, node): """ Called if no explicit visitor function exists for a node. Implements preorder visiting of the node. """ for c_name, c in node.children(): self.visit(c) class ArrayDecl(Node): __slots__ = ('type', 'dim', 'dim_quals', 'coord', '__weakref__') def __init__(self, type, dim, dim_quals, coord=None): self.type = type self.dim = dim self.dim_quals = dim_quals self.coord = coord def children(self): nodelist = [] if self.type is not None: nodelist.append(("type", self.type)) if self.dim is not None: nodelist.append(("dim", self.dim)) return tuple(nodelist) attr_names = ('dim_quals', ) class ArrayRef(Node): __slots__ = ('name', 'subscript', 'coord', '__weakref__') def __init__(self, name, subscript, coord=None): self.name = name self.subscript = subscript self.coord = coord def children(self): nodelist = [] if self.name is not None: nodelist.append(("name", self.name)) if self.subscript is not None: nodelist.append(("subscript", self.subscript)) return tuple(nodelist) attr_names = () class Assignment(Node): __slots__ = ('op', 'lvalue', 'rvalue', 'coord', '__weakref__') def __init__(self, op, lvalue, rvalue, coord=None): self.op = op self.lvalue = lvalue self.rvalue = rvalue self.coord = coord def children(self): nodelist = [] if self.lvalue is not None: nodelist.append(("lvalue", self.lvalue)) if self.rvalue is not None: nodelist.append(("rvalue", self.rvalue)) return tuple(nodelist) attr_names = ('op', ) class BinaryOp(Node): __slots__ = ('op', 'left', 'right', 'coord', '__weakref__') def __init__(self, op, left, right, coord=None): self.op = op self.left = left self.right = right self.coord = coord def children(self): nodelist = [] if self.left is not None: nodelist.append(("left", self.left)) if self.right is not None: nodelist.append(("right", self.right)) return tuple(nodelist) attr_names = ('op', ) class Break(Node): __slots__ = ('coord', '__weakref__') def __init__(self, coord=None): self.coord = coord def children(self): return () attr_names = () class Case(Node): __slots__ = ('expr', 'stmts', 'coord', '__weakref__') def __init__(self, expr, stmts, coord=None): self.expr = expr self.stmts = stmts self.coord = coord def children(self): nodelist = [] if self.expr is not None: nodelist.append(("expr", self.expr)) for i, child in enumerate(self.stmts or []): nodelist.append(("stmts[%d]" % i, child)) return tuple(nodelist) attr_names = () class Cast(Node): __slots__ = ('to_type', 'expr', 'coord', '__weakref__') def __init__(self, to_type, expr, coord=None): self.to_type = to_type self.expr = expr self.coord = coord def children(self): nodelist = [] if self.to_type is not None: nodelist.append(("to_type", self.to_type)) if self.expr is not None: nodelist.append(("expr", self.expr)) return tuple(nodelist) attr_names = () class Compound(Node): __slots__ = ('block_items', 'coord', '__weakref__') def __init__(self, block_items, coord=None): self.block_items = block_items self.coord = coord def children(self): nodelist = [] for i, child in enumerate(self.block_items or []): nodelist.append(("block_items[%d]" % i, child)) return tuple(nodelist) attr_names = () class CompoundLiteral(Node): __slots__ = ('type', 'init', 'coord', '__weakref__') def __init__(self, type, init, coord=None): self.type = type self.init = init self.coord = coord def children(self): nodelist = [] if self.type is not None: nodelist.append(("type", self.type)) if self.init is not None: nodelist.append(("init", self.init)) return tuple(nodelist) attr_names = () class Constant(Node): __slots__ = ('type', 'value', 'coord', '__weakref__') def __init__(self, type, value, coord=None): self.type = type self.value = value self.coord = coord def children(self): nodelist = [] return tuple(nodelist) attr_names = ('type', 'value', ) class Continue(Node): __slots__ = ('coord', '__weakref__') def __init__(self, coord=None): self.coord = coord def children(self): return () attr_names = () class Decl(Node): __slots__ = ('name', 'quals', 'storage', 'funcspec', 'type', 'init', 'bitsize', 'coord', '__weakref__') def __init__(self, name, quals, storage, funcspec, type, init, bitsize, coord=None): self.name = name self.quals = quals self.storage = storage self.funcspec = funcspec self.type = type self.init = init self.bitsize = bitsize self.coord = coord def children(self): nodelist = [] if self.type is not None: nodelist.append(("type", self.type)) if self.init is not None: nodelist.append(("init", self.init)) if self.bitsize is not None: nodelist.append(("bitsize", self.bitsize)) return tuple(nodelist) attr_names = ('name', 'quals', 'storage', 'funcspec', ) class DeclList(Node): __slots__ = ('decls', 'coord', '__weakref__') def __init__(self, decls, coord=None): self.decls = decls self.coord = coord def children(self): nodelist = [] for i, child in enumerate(self.decls or []): nodelist.append(("decls[%d]" % i, child)) return tuple(nodelist) attr_names = () class Default(Node): __slots__ = ('stmts', 'coord', '__weakref__') def __init__(self, stmts, coord=None): self.stmts = stmts self.coord = coord def children(self): nodelist = [] for i, child in enumerate(self.stmts or []): nodelist.append(("stmts[%d]" % i, child)) return tuple(nodelist) attr_names = () class DoWhile(Node): __slots__ = ('cond', 'stmt', 'coord', '__weakref__') def __init__(self, cond, stmt, coord=None): self.cond = cond self.stmt = stmt self.coord = coord def children(self): nodelist = [] if self.cond is not None: nodelist.append(("cond", self.cond)) if self.stmt is not None: nodelist.append(("stmt", self.stmt)) return tuple(nodelist) attr_names = () class EllipsisParam(Node): __slots__ = ('coord', '__weakref__') def __init__(self, coord=None): self.coord = coord def children(self): return () attr_names = () class EmptyStatement(Node): __slots__ = ('coord', '__weakref__') def __init__(self, coord=None): self.coord = coord def children(self): return () attr_names = () class Enum(Node): __slots__ = ('name', 'values', 'coord', '__weakref__') def __init__(self, name, values, coord=None): self.name = name self.values = values self.coord = coord def children(self): nodelist = [] if self.values is not None: nodelist.append(("values", self.values)) return tuple(nodelist) attr_names = ('name', ) class Enumerator(Node): __slots__ = ('name', 'value', 'coord', '__weakref__') def __init__(self, name, value, coord=None): self.name = name self.value = value self.coord = coord def children(self): nodelist = [] if self.value is not None: nodelist.append(("value", self.value)) return tuple(nodelist) attr_names = ('name', ) class EnumeratorList(Node): __slots__ = ('enumerators', 'coord', '__weakref__') def __init__(self, enumerators, coord=None): self.enumerators = enumerators self.coord = coord def children(self): nodelist = [] for i, child in enumerate(self.enumerators or []): nodelist.append(("enumerators[%d]" % i, child)) return tuple(nodelist) attr_names = () class ExprList(Node): __slots__ = ('exprs', 'coord', '__weakref__') def __init__(self, exprs, coord=None): self.exprs = exprs self.coord = coord def children(self): nodelist = [] for i, child in enumerate(self.exprs or []): nodelist.append(("exprs[%d]" % i, child)) return tuple(nodelist) attr_names = () class FileAST(Node): __slots__ = ('ext', 'coord', '__weakref__') def __init__(self, ext, coord=None): self.ext = ext self.coord = coord def children(self): nodelist = [] for i, child in enumerate(self.ext or []): nodelist.append(("ext[%d]" % i, child)) return tuple(nodelist) attr_names = () class For(Node): __slots__ = ('init', 'cond', 'next', 'stmt', 'coord', '__weakref__') def __init__(self, init, cond, next, stmt, coord=None): self.init = init self.cond = cond self.next = next self.stmt = stmt self.coord = coord def children(self): nodelist = [] if self.init is not None: nodelist.append(("init", self.init)) if self.cond is not None: nodelist.append(("cond", self.cond)) if self.next is not None: nodelist.append(("next", self.next)) if self.stmt is not None: nodelist.append(("stmt", self.stmt)) return tuple(nodelist) attr_names = () class FuncCall(Node): __slots__ = ('name', 'args', 'coord', '__weakref__') def __init__(self, name, args, coord=None): self.name = name self.args = args self.coord = coord def children(self): nodelist = [] if self.name is not None: nodelist.append(("name", self.name)) if self.args is not None: nodelist.append(("args", self.args)) return tuple(nodelist) attr_names = () class FuncDecl(Node): __slots__ = ('args', 'type', 'coord', '__weakref__') def __init__(self, args, type, coord=None): self.args = args self.type = type self.coord = coord def children(self): nodelist = [] if self.args is not None: nodelist.append(("args", self.args)) if self.type is not None: nodelist.append(("type", self.type)) return tuple(nodelist) attr_names = () class FuncDef(Node): __slots__ = ('decl', 'param_decls', 'body', 'coord', '__weakref__') def __init__(self, decl, param_decls, body, coord=None): self.decl = decl self.param_decls = param_decls self.body = body self.coord = coord def children(self): nodelist = [] if self.decl is not None: nodelist.append(("decl", self.decl)) if self.body is not None: nodelist.append(("body", self.body)) for i, child in enumerate(self.param_decls or []): nodelist.append(("param_decls[%d]" % i, child)) return tuple(nodelist) attr_names = () class Goto(Node): __slots__ = ('name', 'coord', '__weakref__') def __init__(self, name, coord=None): self.name = name self.coord = coord def children(self): nodelist = [] return tuple(nodelist) attr_names = ('name', ) class ID(Node): __slots__ = ('name', 'coord', '__weakref__') def __init__(self, name, coord=None): self.name = name self.coord = coord def children(self): nodelist = [] return tuple(nodelist) attr_names = ('name', ) class IdentifierType(Node): __slots__ = ('names', 'coord', '__weakref__') def __init__(self, names, coord=None): self.names = names self.coord = coord def children(self): nodelist = [] return tuple(nodelist) attr_names = ('names', ) class If(Node): __slots__ = ('cond', 'iftrue', 'iffalse', 'coord', '__weakref__') def __init__(self, cond, iftrue, iffalse, coord=None): self.cond = cond self.iftrue = iftrue self.iffalse = iffalse self.coord = coord def children(self): nodelist = [] if self.cond is not None: nodelist.append(("cond", self.cond)) if self.iftrue is not None: nodelist.append(("iftrue", self.iftrue)) if self.iffalse is not None: nodelist.append(("iffalse", self.iffalse)) return tuple(nodelist) attr_names = () class InitList(Node): __slots__ = ('exprs', 'coord', '__weakref__') def __init__(self, exprs, coord=None): self.exprs = exprs self.coord = coord def children(self): nodelist = [] for i, child in enumerate(self.exprs or []): nodelist.append(("exprs[%d]" % i, child)) return tuple(nodelist) attr_names = () class Label(Node): __slots__ = ('name', 'stmt', 'coord', '__weakref__') def __init__(self, name, stmt, coord=None): self.name = name self.stmt = stmt self.coord = coord def children(self): nodelist = [] if self.stmt is not None: nodelist.append(("stmt", self.stmt)) return tuple(nodelist) attr_names = ('name', ) class NamedInitializer(Node): __slots__ = ('name', 'expr', 'coord', '__weakref__') def __init__(self, name, expr, coord=None): self.name = name self.expr = expr self.coord = coord def children(self): nodelist = [] if self.expr is not None: nodelist.append(("expr", self.expr)) for i, child in enumerate(self.name or []): nodelist.append(("name[%d]" % i, child)) return tuple(nodelist) attr_names = () class ParamList(Node): __slots__ = ('params', 'coord', '__weakref__') def __init__(self, params, coord=None): self.params = params self.coord = coord def children(self): nodelist = [] for i, child in enumerate(self.params or []): nodelist.append(("params[%d]" % i, child)) return tuple(nodelist) attr_names = () class PtrDecl(Node): __slots__ = ('quals', 'type', 'coord', '__weakref__') def __init__(self, quals, type, coord=None): self.quals = quals self.type = type self.coord = coord def children(self): nodelist = [] if self.type is not None: nodelist.append(("type", self.type)) return tuple(nodelist) attr_names = ('quals', ) class Return(Node): __slots__ = ('expr', 'coord', '__weakref__') def __init__(self, expr, coord=None): self.expr = expr self.coord = coord def children(self): nodelist = [] if self.expr is not None: nodelist.append(("expr", self.expr)) return tuple(nodelist) attr_names = () class Struct(Node): __slots__ = ('name', 'decls', 'coord', '__weakref__') def __init__(self, name, decls, coord=None): self.name = name self.decls = decls self.coord = coord def children(self): nodelist = [] for i, child in enumerate(self.decls or []): nodelist.append(("decls[%d]" % i, child)) return tuple(nodelist) attr_names = ('name', ) class StructRef(Node): __slots__ = ('name', 'type', 'field', 'coord', '__weakref__') def __init__(self, name, type, field, coord=None): self.name = name self.type = type self.field = field self.coord = coord def children(self): nodelist = [] if self.name is not None: nodelist.append(("name", self.name)) if self.field is not None: nodelist.append(("field", self.field)) return tuple(nodelist) attr_names = ('type', ) class Switch(Node): __slots__ = ('cond', 'stmt', 'coord', '__weakref__') def __init__(self, cond, stmt, coord=None): self.cond = cond self.stmt = stmt self.coord = coord def children(self): nodelist = [] if self.cond is not None: nodelist.append(("cond", self.cond)) if self.stmt is not None: nodelist.append(("stmt", self.stmt)) return tuple(nodelist) attr_names = () class TernaryOp(Node): __slots__ = ('cond', 'iftrue', 'iffalse', 'coord', '__weakref__') def __init__(self, cond, iftrue, iffalse, coord=None): self.cond = cond self.iftrue = iftrue self.iffalse = iffalse self.coord = coord def children(self): nodelist = [] if self.cond is not None: nodelist.append(("cond", self.cond)) if self.iftrue is not None: nodelist.append(("iftrue", self.iftrue)) if self.iffalse is not None: nodelist.append(("iffalse", self.iffalse)) return tuple(nodelist) attr_names = () class TypeDecl(Node): __slots__ = ('declname', 'quals', 'type', 'coord', '__weakref__') def __init__(self, declname, quals, type, coord=None): self.declname = declname self.quals = quals self.type = type self.coord = coord def children(self): nodelist = [] if self.type is not None: nodelist.append(("type", self.type)) return tuple(nodelist) attr_names = ('declname', 'quals', ) class Typedef(Node): __slots__ = ('name', 'quals', 'storage', 'type', 'coord', '__weakref__') def __init__(self, name, quals, storage, type, coord=None): self.name = name self.quals = quals self.storage = storage self.type = type self.coord = coord def children(self): nodelist = [] if self.type is not None: nodelist.append(("type", self.type)) return tuple(nodelist) attr_names = ('name', 'quals', 'storage', ) class Typename(Node): __slots__ = ('name', 'quals', 'type', 'coord', '__weakref__') def __init__(self, name, quals, type, coord=None): self.name = name self.quals = quals self.type = type self.coord = coord def children(self): nodelist = [] if self.type is not None: nodelist.append(("type", self.type)) return tuple(nodelist) attr_names = ('name', 'quals', ) class UnaryOp(Node): __slots__ = ('op', 'expr', 'coord', '__weakref__') def __init__(self, op, expr, coord=None): self.op = op self.expr = expr self.coord = coord def children(self): nodelist = [] if self.expr is not None: nodelist.append(("expr", self.expr)) return tuple(nodelist) attr_names = ('op', ) class Union(Node): __slots__ = ('name', 'decls', 'coord', '__weakref__') def __init__(self, name, decls, coord=None): self.name = name self.decls = decls self.coord = coord def children(self): nodelist = [] for i, child in enumerate(self.decls or []): nodelist.append(("decls[%d]" % i, child)) return tuple(nodelist) attr_names = ('name', ) class While(Node): __slots__ = ('cond', 'stmt', 'coord', '__weakref__') def __init__(self, cond, stmt, coord=None): self.cond = cond self.stmt = stmt self.coord = coord def children(self): nodelist = [] if self.cond is not None: nodelist.append(("cond", self.cond)) if self.stmt is not None: nodelist.append(("stmt", self.stmt)) return tuple(nodelist) attr_names = () pycparser-2.14/pycparser/lextab.py0000664000175000017500000001644112524375070020044 0ustar elibeneliben00000000000000# pycparser.lextab.py. This file automatically created by PLY (version 3.4). Don't edit! _tabversion = '3.4' _lextokens = {'VOID': 1, 'LBRACKET': 1, 'WCHAR_CONST': 1, 'FLOAT_CONST': 1, 'MINUS': 1, 'RPAREN': 1, 'LONG': 1, 'PLUS': 1, 'ELLIPSIS': 1, 'GT': 1, 'GOTO': 1, 'ENUM': 1, 'PERIOD': 1, 'GE': 1, 'INT_CONST_DEC': 1, 'ARROW': 1, 'HEX_FLOAT_CONST': 1, 'DOUBLE': 1, 'MINUSEQUAL': 1, 'INT_CONST_OCT': 1, 'TIMESEQUAL': 1, 'OR': 1, 'SHORT': 1, 'RETURN': 1, 'RSHIFTEQUAL': 1, 'RESTRICT': 1, 'STATIC': 1, 'SIZEOF': 1, 'UNSIGNED': 1, 'UNION': 1, 'COLON': 1, 'WSTRING_LITERAL': 1, 'DIVIDE': 1, 'FOR': 1, 'PLUSPLUS': 1, 'EQUALS': 1, 'ELSE': 1, 'INLINE': 1, 'EQ': 1, 'AND': 1, 'TYPEID': 1, 'LBRACE': 1, 'PPHASH': 1, 'INT': 1, 'SIGNED': 1, 'CONTINUE': 1, 'NOT': 1, 'OREQUAL': 1, 'MOD': 1, 'RSHIFT': 1, 'DEFAULT': 1, 'CHAR': 1, 'WHILE': 1, 'DIVEQUAL': 1, 'EXTERN': 1, 'CASE': 1, 'LAND': 1, 'REGISTER': 1, 'MODEQUAL': 1, 'NE': 1, 'SWITCH': 1, 'INT_CONST_HEX': 1, '_COMPLEX': 1, 'PLUSEQUAL': 1, 'STRUCT': 1, 'CONDOP': 1, 'BREAK': 1, 'VOLATILE': 1, 'ANDEQUAL': 1, 'INT_CONST_BIN': 1, 'DO': 1, 'LNOT': 1, 'CONST': 1, 'LOR': 1, 'CHAR_CONST': 1, 'LSHIFT': 1, 'RBRACE': 1, '_BOOL': 1, 'LE': 1, 'SEMI': 1, 'LT': 1, 'COMMA': 1, 'OFFSETOF': 1, 'TYPEDEF': 1, 'XOR': 1, 'AUTO': 1, 'TIMES': 1, 'LPAREN': 1, 'MINUSMINUS': 1, 'ID': 1, 'IF': 1, 'STRING_LITERAL': 1, 'FLOAT': 1, 'XOREQUAL': 1, 'LSHIFTEQUAL': 1, 'RBRACKET': 1} _lexreflags = 0 _lexliterals = '' _lexstateinfo = {'ppline': 'exclusive', 'pppragma': 'exclusive', 'INITIAL': 'inclusive'} _lexstatere = {'ppline': [('(?P"([^"\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))*")|(?P(0(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?)|([1-9][0-9]*(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?))|(?P\\n)|(?Pline)', [None, ('t_ppline_FILENAME', 'FILENAME'), None, None, None, None, None, None, ('t_ppline_LINE_NUMBER', 'LINE_NUMBER'), None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, ('t_ppline_NEWLINE', 'NEWLINE'), ('t_ppline_PPLINE', 'PPLINE')])], 'pppragma': [('(?P\\n)|(?Ppragma)|(?P"([^"\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))*")|(?P[a-zA-Z_$][0-9a-zA-Z_$]*)', [None, ('t_pppragma_NEWLINE', 'NEWLINE'), ('t_pppragma_PPPRAGMA', 'PPPRAGMA'), ('t_pppragma_STR', 'STR'), None, None, None, None, None, None, ('t_pppragma_ID', 'ID')])], 'INITIAL': [('(?P[ \\t]*\\#)|(?P\\n+)|(?P\\{)|(?P\\})|(?P((((([0-9]*\\.[0-9]+)|([0-9]+\\.))([eE][-+]?[0-9]+)?)|([0-9]+([eE][-+]?[0-9]+)))[FfLl]?))|(?P(0[xX]([0-9a-fA-F]+|((([0-9a-fA-F]+)?\\.[0-9a-fA-F]+)|([0-9a-fA-F]+\\.)))([pP][+-]?[0-9]+)[FfLl]?))|(?P0[xX][0-9a-fA-F]+(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?)', [None, ('t_PPHASH', 'PPHASH'), ('t_NEWLINE', 'NEWLINE'), ('t_LBRACE', 'LBRACE'), ('t_RBRACE', 'RBRACE'), ('t_FLOAT_CONST', 'FLOAT_CONST'), None, None, None, None, None, None, None, None, None, ('t_HEX_FLOAT_CONST', 'HEX_FLOAT_CONST'), None, None, None, None, None, None, None, ('t_INT_CONST_HEX', 'INT_CONST_HEX')]), ('(?P0[bB][01]+(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?)|(?P0[0-7]*[89])|(?P0[0-7]*(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?)|(?P(0(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?)|([1-9][0-9]*(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?))|(?P\'([^\'\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))\')|(?PL\'([^\'\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))\')|(?P(\'([^\'\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))*\\n)|(\'([^\'\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))*$))|(?P(\'([^\'\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))[^\'\n]+\')|(\'\')|(\'([\\\\][^a-zA-Z._~^!=&\\^\\-\\\\?\'"x0-7])[^\'\\n]*\'))', [None, ('t_INT_CONST_BIN', 'INT_CONST_BIN'), None, None, None, None, None, None, None, ('t_BAD_CONST_OCT', 'BAD_CONST_OCT'), ('t_INT_CONST_OCT', 'INT_CONST_OCT'), None, None, None, None, None, None, None, ('t_INT_CONST_DEC', 'INT_CONST_DEC'), None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, ('t_CHAR_CONST', 'CHAR_CONST'), None, None, None, None, None, None, ('t_WCHAR_CONST', 'WCHAR_CONST'), None, None, None, None, None, None, ('t_UNMATCHED_QUOTE', 'UNMATCHED_QUOTE'), None, None, None, None, None, None, None, None, None, None, None, None, None, None, ('t_BAD_CHAR_CONST', 'BAD_CHAR_CONST')]), ('(?PL"([^"\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))*")|(?P"([^"\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))*([\\\\][^a-zA-Z._~^!=&\\^\\-\\\\?\'"x0-7])([^"\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))*")|(?P[a-zA-Z_$][0-9a-zA-Z_$]*)|(?P"([^"\\\\\\n]|(\\\\(([a-zA-Z._~!=&\\^\\-\\\\?\'"])|(\\d+)|(x[0-9a-fA-F]+))))*")|(?P\\.\\.\\.)|(?P\\+\\+)|(?P\\|\\|)|(?P\\^=)|(?P\\|=)|(?P<<=)|(?P>>=)|(?P\\+=)|(?P\\*=)|(?P\\+)|(?P%=)|(?P/=)', [None, ('t_WSTRING_LITERAL', 'WSTRING_LITERAL'), None, None, None, None, None, None, ('t_BAD_STRING_LITERAL', 'BAD_STRING_LITERAL'), None, None, None, None, None, None, None, None, None, None, None, None, None, ('t_ID', 'ID'), (None, 'STRING_LITERAL'), None, None, None, None, None, None, (None, 'ELLIPSIS'), (None, 'PLUSPLUS'), (None, 'LOR'), (None, 'XOREQUAL'), (None, 'OREQUAL'), (None, 'LSHIFTEQUAL'), (None, 'RSHIFTEQUAL'), (None, 'PLUSEQUAL'), (None, 'TIMESEQUAL'), (None, 'PLUS'), (None, 'MODEQUAL'), (None, 'DIVEQUAL')]), ('(?P\\])|(?P\\?)|(?P\\^)|(?P<<)|(?P<=)|(?P\\()|(?P->)|(?P==)|(?P!=)|(?P--)|(?P\\|)|(?P\\*)|(?P\\[)|(?P>=)|(?P\\))|(?P&&)|(?P>>)|(?P-=)|(?P\\.)|(?P&=)|(?P=)|(?P<)|(?P,)|(?P/)|(?P&)|(?P%)|(?P;)|(?P-)|(?P>)|(?P:)|(?P~)|(?P!)', [None, (None, 'RBRACKET'), (None, 'CONDOP'), (None, 'XOR'), (None, 'LSHIFT'), (None, 'LE'), (None, 'LPAREN'), (None, 'ARROW'), (None, 'EQ'), (None, 'NE'), (None, 'MINUSMINUS'), (None, 'OR'), (None, 'TIMES'), (None, 'LBRACKET'), (None, 'GE'), (None, 'RPAREN'), (None, 'LAND'), (None, 'RSHIFT'), (None, 'MINUSEQUAL'), (None, 'PERIOD'), (None, 'ANDEQUAL'), (None, 'EQUALS'), (None, 'LT'), (None, 'COMMA'), (None, 'DIVIDE'), (None, 'AND'), (None, 'MOD'), (None, 'SEMI'), (None, 'MINUS'), (None, 'GT'), (None, 'COLON'), (None, 'NOT'), (None, 'LNOT')])]} _lexstateignore = {'ppline': ' \t', 'pppragma': ' \t<>.-{}();=+-*/$%@&^~!?:,0123456789', 'INITIAL': ' \t'} _lexstateerrorf = {'ppline': 't_ppline_error', 'pppragma': 't_pppragma_error', 'INITIAL': 't_error'} pycparser-2.14/pycparser/_c_ast.cfg0000644000175000017500000001012412523673271020115 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # pycparser: _c_ast.cfg # # Defines the AST Node classes used in pycparser. # # Each entry is a Node sub-class name, listing the attributes # and child nodes of the class: # * - a child node # ** - a sequence of child nodes # - an attribute # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- # ArrayDecl is a nested declaration of an array with the given type. # dim: the dimension (for example, constant 42) # dim_quals: list of dimension qualifiers, to support C99's allowing 'const' # and 'static' within the array dimension in function declarations. ArrayDecl: [type*, dim*, dim_quals] ArrayRef: [name*, subscript*] # op: =, +=, /= etc. # Assignment: [op, lvalue*, rvalue*] BinaryOp: [op, left*, right*] Break: [] Case: [expr*, stmts**] Cast: [to_type*, expr*] # Compound statement in C99 is a list of block items (declarations or # statements). # Compound: [block_items**] # Compound literal (anonymous aggregate) for C99. # (type-name) {initializer_list} # type: the typename # init: InitList for the initializer list # CompoundLiteral: [type*, init*] # type: int, char, float, etc. see CLexer for constant token types # Constant: [type, value] Continue: [] # name: the variable being declared # quals: list of qualifiers (const, volatile) # funcspec: list function specifiers (i.e. inline in C99) # storage: list of storage specifiers (extern, register, etc.) # type: declaration type (probably nested with all the modifiers) # init: initialization value, or None # bitsize: bit field size, or None # Decl: [name, quals, storage, funcspec, type*, init*, bitsize*] DeclList: [decls**] Default: [stmts**] DoWhile: [cond*, stmt*] # Represents the ellipsis (...) parameter in a function # declaration # EllipsisParam: [] # An empty statement (a semicolon ';' on its own) # EmptyStatement: [] # Enumeration type specifier # name: an optional ID # values: an EnumeratorList # Enum: [name, values*] # A name/value pair for enumeration values # Enumerator: [name, value*] # A list of enumerators # EnumeratorList: [enumerators**] # A list of expressions separated by the comma operator. # ExprList: [exprs**] # This is the top of the AST, representing a single C file (a # translation unit in K&R jargon). It contains a list of # "external-declaration"s, which is either declarations (Decl), # Typedef or function definitions (FuncDef). # FileAST: [ext**] # for (init; cond; next) stmt # For: [init*, cond*, next*, stmt*] # name: Id # args: ExprList # FuncCall: [name*, args*] # type (args) # FuncDecl: [args*, type*] # Function definition: a declarator for the function name and # a body, which is a compound statement. # There's an optional list of parameter declarations for old # K&R-style definitions # FuncDef: [decl*, param_decls**, body*] Goto: [name] ID: [name] # Holder for types that are a simple identifier (e.g. the built # ins void, char etc. and typedef-defined types) # IdentifierType: [names] If: [cond*, iftrue*, iffalse*] # An initialization list used for compound literals. # InitList: [exprs**] Label: [name, stmt*] # A named initializer for C99. # The name of a NamedInitializer is a sequence of Nodes, because # names can be hierarchical and contain constant expressions. # NamedInitializer: [name**, expr*] # a list of comma separated function parameter declarations # ParamList: [params**] PtrDecl: [quals, type*] Return: [expr*] # name: struct tag name # decls: declaration of members # Struct: [name, decls**] # type: . or -> # name.field or name->field # StructRef: [name*, type, field*] Switch: [cond*, stmt*] # cond ? iftrue : iffalse # TernaryOp: [cond*, iftrue*, iffalse*] # A base type declaration # TypeDecl: [declname, quals, type*] # A typedef declaration. # Very similar to Decl, but without some attributes # Typedef: [name, quals, storage, type*] Typename: [name, quals, type*] UnaryOp: [op, expr*] # name: union tag name # decls: declaration of members # Union: [name, decls**] While: [cond*, stmt*] pycparser-2.14/pycparser/c_parser.py0000664000175000017500000017140412535723564020373 0ustar elibeneliben00000000000000#------------------------------------------------------------------------------ # pycparser: c_parser.py # # CParser class: Parser and AST builder for the C language # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #------------------------------------------------------------------------------ import re from .ply import yacc from . import c_ast from .c_lexer import CLexer from .plyparser import PLYParser, Coord, ParseError from .ast_transforms import fix_switch_cases class CParser(PLYParser): def __init__( self, lex_optimize=True, lextab='pycparser.lextab', yacc_optimize=True, yacctab='pycparser.yacctab', yacc_debug=False, taboutputdir=''): """ Create a new CParser. Some arguments for controlling the debug/optimization level of the parser are provided. The defaults are tuned for release/performance mode. The simple rules for using them are: *) When tweaking CParser/CLexer, set these to False *) When releasing a stable parser, set to True lex_optimize: Set to False when you're modifying the lexer. Otherwise, changes in the lexer won't be used, if some lextab.py file exists. When releasing with a stable lexer, set to True to save the re-generation of the lexer table on each run. lextab: Points to the lex table that's used for optimized mode. Only if you're modifying the lexer and want some tests to avoid re-generating the table, make this point to a local lex table file (that's been earlier generated with lex_optimize=True) yacc_optimize: Set to False when you're modifying the parser. Otherwise, changes in the parser won't be used, if some parsetab.py file exists. When releasing with a stable parser, set to True to save the re-generation of the parser table on each run. yacctab: Points to the yacc table that's used for optimized mode. Only if you're modifying the parser, make this point to a local yacc table file yacc_debug: Generate a parser.out file that explains how yacc built the parsing table from the grammar. taboutputdir: Set this parameter to control the location of generated lextab and yacctab files. """ self.clex = CLexer( error_func=self._lex_error_func, on_lbrace_func=self._lex_on_lbrace_func, on_rbrace_func=self._lex_on_rbrace_func, type_lookup_func=self._lex_type_lookup_func) self.clex.build( optimize=lex_optimize, lextab=lextab, outputdir=taboutputdir) self.tokens = self.clex.tokens rules_with_opt = [ 'abstract_declarator', 'assignment_expression', 'declaration_list', 'declaration_specifiers', 'designation', 'expression', 'identifier_list', 'init_declarator_list', 'initializer_list', 'parameter_type_list', 'specifier_qualifier_list', 'block_item_list', 'type_qualifier_list', 'struct_declarator_list' ] for rule in rules_with_opt: self._create_opt_rule(rule) self.cparser = yacc.yacc( module=self, start='translation_unit_or_empty', debug=yacc_debug, optimize=yacc_optimize, tabmodule=yacctab, outputdir=taboutputdir) # Stack of scopes for keeping track of symbols. _scope_stack[-1] is # the current (topmost) scope. Each scope is a dictionary that # specifies whether a name is a type. If _scope_stack[n][name] is # True, 'name' is currently a type in the scope. If it's False, # 'name' is used in the scope but not as a type (for instance, if we # saw: int name; # If 'name' is not a key in _scope_stack[n] then 'name' was not defined # in this scope at all. self._scope_stack = [dict()] # Keeps track of the last token given to yacc (the lookahead token) self._last_yielded_token = None def parse(self, text, filename='', debuglevel=0): """ Parses C code and returns an AST. text: A string containing the C source code filename: Name of the file being parsed (for meaningful error messages) debuglevel: Debug level to yacc """ self.clex.filename = filename self.clex.reset_lineno() self._scope_stack = [dict()] self._last_yielded_token = None return self.cparser.parse( input=text, lexer=self.clex, debug=debuglevel) ######################-- PRIVATE --###################### def _push_scope(self): self._scope_stack.append(dict()) def _pop_scope(self): assert len(self._scope_stack) > 1 self._scope_stack.pop() def _add_typedef_name(self, name, coord): """ Add a new typedef name (ie a TYPEID) to the current scope """ if not self._scope_stack[-1].get(name, True): self._parse_error( "Typedef %r previously declared as non-typedef " "in this scope" % name, coord) self._scope_stack[-1][name] = True def _add_identifier(self, name, coord): """ Add a new object, function, or enum member name (ie an ID) to the current scope """ if self._scope_stack[-1].get(name, False): self._parse_error( "Non-typedef %r previously declared as typedef " "in this scope" % name, coord) self._scope_stack[-1][name] = False def _is_type_in_scope(self, name): """ Is *name* a typedef-name in the current scope? """ for scope in reversed(self._scope_stack): # If name is an identifier in this scope it shadows typedefs in # higher scopes. in_scope = scope.get(name) if in_scope is not None: return in_scope return False def _lex_error_func(self, msg, line, column): self._parse_error(msg, self._coord(line, column)) def _lex_on_lbrace_func(self): self._push_scope() def _lex_on_rbrace_func(self): self._pop_scope() def _lex_type_lookup_func(self, name): """ Looks up types that were previously defined with typedef. Passed to the lexer for recognizing identifiers that are types. """ is_type = self._is_type_in_scope(name) return is_type def _get_yacc_lookahead_token(self): """ We need access to yacc's lookahead token in certain cases. This is the last token yacc requested from the lexer, so we ask the lexer. """ return self.clex.last_token # To understand what's going on here, read sections A.8.5 and # A.8.6 of K&R2 very carefully. # # A C type consists of a basic type declaration, with a list # of modifiers. For example: # # int *c[5]; # # The basic declaration here is 'int c', and the pointer and # the array are the modifiers. # # Basic declarations are represented by TypeDecl (from module c_ast) and the # modifiers are FuncDecl, PtrDecl and ArrayDecl. # # The standard states that whenever a new modifier is parsed, it should be # added to the end of the list of modifiers. For example: # # K&R2 A.8.6.2: Array Declarators # # In a declaration T D where D has the form # D1 [constant-expression-opt] # and the type of the identifier in the declaration T D1 is # "type-modifier T", the type of the # identifier of D is "type-modifier array of T" # # This is what this method does. The declarator it receives # can be a list of declarators ending with TypeDecl. It # tacks the modifier to the end of this list, just before # the TypeDecl. # # Additionally, the modifier may be a list itself. This is # useful for pointers, that can come as a chain from the rule # p_pointer. In this case, the whole modifier list is spliced # into the new location. def _type_modify_decl(self, decl, modifier): """ Tacks a type modifier on a declarator, and returns the modified declarator. Note: the declarator and modifier may be modified """ #~ print '****' #~ decl.show(offset=3) #~ modifier.show(offset=3) #~ print '****' modifier_head = modifier modifier_tail = modifier # The modifier may be a nested list. Reach its tail. # while modifier_tail.type: modifier_tail = modifier_tail.type # If the decl is a basic type, just tack the modifier onto # it # if isinstance(decl, c_ast.TypeDecl): modifier_tail.type = decl return modifier else: # Otherwise, the decl is a list of modifiers. Reach # its tail and splice the modifier onto the tail, # pointing to the underlying basic type. # decl_tail = decl while not isinstance(decl_tail.type, c_ast.TypeDecl): decl_tail = decl_tail.type modifier_tail.type = decl_tail.type decl_tail.type = modifier_head return decl # Due to the order in which declarators are constructed, # they have to be fixed in order to look like a normal AST. # # When a declaration arrives from syntax construction, it has # these problems: # * The innermost TypeDecl has no type (because the basic # type is only known at the uppermost declaration level) # * The declaration has no variable name, since that is saved # in the innermost TypeDecl # * The typename of the declaration is a list of type # specifiers, and not a node. Here, basic identifier types # should be separated from more complex types like enums # and structs. # # This method fixes these problems. # def _fix_decl_name_type(self, decl, typename): """ Fixes a declaration. Modifies decl. """ # Reach the underlying basic type # type = decl while not isinstance(type, c_ast.TypeDecl): type = type.type decl.name = type.declname type.quals = decl.quals # The typename is a list of types. If any type in this # list isn't an IdentifierType, it must be the only # type in the list (it's illegal to declare "int enum ..") # If all the types are basic, they're collected in the # IdentifierType holder. # for tn in typename: if not isinstance(tn, c_ast.IdentifierType): if len(typename) > 1: self._parse_error( "Invalid multiple types specified", tn.coord) else: type.type = tn return decl if not typename: # Functions default to returning int # if not isinstance(decl.type, c_ast.FuncDecl): self._parse_error( "Missing type in declaration", decl.coord) type.type = c_ast.IdentifierType( ['int'], coord=decl.coord) else: # At this point, we know that typename is a list of IdentifierType # nodes. Concatenate all the names into a single list. # type.type = c_ast.IdentifierType( [name for id in typename for name in id.names], coord=typename[0].coord) return decl def _add_declaration_specifier(self, declspec, newspec, kind): """ Declaration specifiers are represented by a dictionary with the entries: * qual: a list of type qualifiers * storage: a list of storage type qualifiers * type: a list of type specifiers * function: a list of function specifiers This method is given a declaration specifier, and a new specifier of a given kind. Returns the declaration specifier, with the new specifier incorporated. """ spec = declspec or dict(qual=[], storage=[], type=[], function=[]) spec[kind].insert(0, newspec) return spec def _build_declarations(self, spec, decls, typedef_namespace=False): """ Builds a list of declarations all sharing the given specifiers. If typedef_namespace is true, each declared name is added to the "typedef namespace", which also includes objects, functions, and enum constants. """ is_typedef = 'typedef' in spec['storage'] declarations = [] # Bit-fields are allowed to be unnamed. # if decls[0].get('bitsize') is not None: pass # When redeclaring typedef names as identifiers in inner scopes, a # problem can occur where the identifier gets grouped into # spec['type'], leaving decl as None. This can only occur for the # first declarator. # elif decls[0]['decl'] is None: if len(spec['type']) < 2 or len(spec['type'][-1].names) != 1 or \ not self._is_type_in_scope(spec['type'][-1].names[0]): coord = '?' for t in spec['type']: if hasattr(t, 'coord'): coord = t.coord break self._parse_error('Invalid declaration', coord) # Make this look as if it came from "direct_declarator:ID" decls[0]['decl'] = c_ast.TypeDecl( declname=spec['type'][-1].names[0], type=None, quals=None, coord=spec['type'][-1].coord) # Remove the "new" type's name from the end of spec['type'] del spec['type'][-1] # A similar problem can occur where the declaration ends up looking # like an abstract declarator. Give it a name if this is the case. # elif not isinstance(decls[0]['decl'], (c_ast.Struct, c_ast.Union, c_ast.IdentifierType)): decls_0_tail = decls[0]['decl'] while not isinstance(decls_0_tail, c_ast.TypeDecl): decls_0_tail = decls_0_tail.type if decls_0_tail.declname is None: decls_0_tail.declname = spec['type'][-1].names[0] del spec['type'][-1] for decl in decls: assert decl['decl'] is not None if is_typedef: declaration = c_ast.Typedef( name=None, quals=spec['qual'], storage=spec['storage'], type=decl['decl'], coord=decl['decl'].coord) else: declaration = c_ast.Decl( name=None, quals=spec['qual'], storage=spec['storage'], funcspec=spec['function'], type=decl['decl'], init=decl.get('init'), bitsize=decl.get('bitsize'), coord=decl['decl'].coord) if isinstance(declaration.type, (c_ast.Struct, c_ast.Union, c_ast.IdentifierType)): fixed_decl = declaration else: fixed_decl = self._fix_decl_name_type(declaration, spec['type']) # Add the type name defined by typedef to a # symbol table (for usage in the lexer) # if typedef_namespace: if is_typedef: self._add_typedef_name(fixed_decl.name, fixed_decl.coord) else: self._add_identifier(fixed_decl.name, fixed_decl.coord) declarations.append(fixed_decl) return declarations def _build_function_definition(self, spec, decl, param_decls, body): """ Builds a function definition. """ assert 'typedef' not in spec['storage'] declaration = self._build_declarations( spec=spec, decls=[dict(decl=decl, init=None)], typedef_namespace=True)[0] return c_ast.FuncDef( decl=declaration, param_decls=param_decls, body=body, coord=decl.coord) def _select_struct_union_class(self, token): """ Given a token (either STRUCT or UNION), selects the appropriate AST class. """ if token == 'struct': return c_ast.Struct else: return c_ast.Union ## ## Precedence and associativity of operators ## precedence = ( ('left', 'LOR'), ('left', 'LAND'), ('left', 'OR'), ('left', 'XOR'), ('left', 'AND'), ('left', 'EQ', 'NE'), ('left', 'GT', 'GE', 'LT', 'LE'), ('left', 'RSHIFT', 'LSHIFT'), ('left', 'PLUS', 'MINUS'), ('left', 'TIMES', 'DIVIDE', 'MOD') ) ## ## Grammar productions ## Implementation of the BNF defined in K&R2 A.13 ## # Wrapper around a translation unit, to allow for empty input. # Not strictly part of the C99 Grammar, but useful in practice. # def p_translation_unit_or_empty(self, p): """ translation_unit_or_empty : translation_unit | empty """ if p[1] is None: p[0] = c_ast.FileAST([]) else: p[0] = c_ast.FileAST(p[1]) def p_translation_unit_1(self, p): """ translation_unit : external_declaration """ # Note: external_declaration is already a list # p[0] = p[1] def p_translation_unit_2(self, p): """ translation_unit : translation_unit external_declaration """ if p[2] is not None: p[1].extend(p[2]) p[0] = p[1] # Declarations always come as lists (because they can be # several in one line), so we wrap the function definition # into a list as well, to make the return value of # external_declaration homogenous. # def p_external_declaration_1(self, p): """ external_declaration : function_definition """ p[0] = [p[1]] def p_external_declaration_2(self, p): """ external_declaration : declaration """ p[0] = p[1] def p_external_declaration_3(self, p): """ external_declaration : pp_directive """ p[0] = p[1] def p_external_declaration_4(self, p): """ external_declaration : SEMI """ p[0] = None def p_pp_directive(self, p): """ pp_directive : PPHASH """ self._parse_error('Directives not supported yet', self._coord(p.lineno(1))) # In function definitions, the declarator can be followed by # a declaration list, for old "K&R style" function definitios. # def p_function_definition_1(self, p): """ function_definition : declarator declaration_list_opt compound_statement """ # no declaration specifiers - 'int' becomes the default type spec = dict( qual=[], storage=[], type=[c_ast.IdentifierType(['int'], coord=self._coord(p.lineno(1)))], function=[]) p[0] = self._build_function_definition( spec=spec, decl=p[1], param_decls=p[2], body=p[3]) def p_function_definition_2(self, p): """ function_definition : declaration_specifiers declarator declaration_list_opt compound_statement """ spec = p[1] p[0] = self._build_function_definition( spec=spec, decl=p[2], param_decls=p[3], body=p[4]) def p_statement(self, p): """ statement : labeled_statement | expression_statement | compound_statement | selection_statement | iteration_statement | jump_statement """ p[0] = p[1] # In C, declarations can come several in a line: # int x, *px, romulo = 5; # # However, for the AST, we will split them to separate Decl # nodes. # # This rule splits its declarations and always returns a list # of Decl nodes, even if it's one element long. # def p_decl_body(self, p): """ decl_body : declaration_specifiers init_declarator_list_opt """ spec = p[1] # p[2] (init_declarator_list_opt) is either a list or None # if p[2] is None: # By the standard, you must have at least one declarator unless # declaring a structure tag, a union tag, or the members of an # enumeration. # ty = spec['type'] s_u_or_e = (c_ast.Struct, c_ast.Union, c_ast.Enum) if len(ty) == 1 and isinstance(ty[0], s_u_or_e): decls = [c_ast.Decl( name=None, quals=spec['qual'], storage=spec['storage'], funcspec=spec['function'], type=ty[0], init=None, bitsize=None, coord=ty[0].coord)] # However, this case can also occur on redeclared identifiers in # an inner scope. The trouble is that the redeclared type's name # gets grouped into declaration_specifiers; _build_declarations # compensates for this. # else: decls = self._build_declarations( spec=spec, decls=[dict(decl=None, init=None)], typedef_namespace=True) else: decls = self._build_declarations( spec=spec, decls=p[2], typedef_namespace=True) p[0] = decls # The declaration has been split to a decl_body sub-rule and # SEMI, because having them in a single rule created a problem # for defining typedefs. # # If a typedef line was directly followed by a line using the # type defined with the typedef, the type would not be # recognized. This is because to reduce the declaration rule, # the parser's lookahead asked for the token after SEMI, which # was the type from the next line, and the lexer had no chance # to see the updated type symbol table. # # Splitting solves this problem, because after seeing SEMI, # the parser reduces decl_body, which actually adds the new # type into the table to be seen by the lexer before the next # line is reached. def p_declaration(self, p): """ declaration : decl_body SEMI """ p[0] = p[1] # Since each declaration is a list of declarations, this # rule will combine all the declarations and return a single # list # def p_declaration_list(self, p): """ declaration_list : declaration | declaration_list declaration """ p[0] = p[1] if len(p) == 2 else p[1] + p[2] def p_declaration_specifiers_1(self, p): """ declaration_specifiers : type_qualifier declaration_specifiers_opt """ p[0] = self._add_declaration_specifier(p[2], p[1], 'qual') def p_declaration_specifiers_2(self, p): """ declaration_specifiers : type_specifier declaration_specifiers_opt """ p[0] = self._add_declaration_specifier(p[2], p[1], 'type') def p_declaration_specifiers_3(self, p): """ declaration_specifiers : storage_class_specifier declaration_specifiers_opt """ p[0] = self._add_declaration_specifier(p[2], p[1], 'storage') def p_declaration_specifiers_4(self, p): """ declaration_specifiers : function_specifier declaration_specifiers_opt """ p[0] = self._add_declaration_specifier(p[2], p[1], 'function') def p_storage_class_specifier(self, p): """ storage_class_specifier : AUTO | REGISTER | STATIC | EXTERN | TYPEDEF """ p[0] = p[1] def p_function_specifier(self, p): """ function_specifier : INLINE """ p[0] = p[1] def p_type_specifier_1(self, p): """ type_specifier : VOID | _BOOL | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | _COMPLEX | SIGNED | UNSIGNED """ p[0] = c_ast.IdentifierType([p[1]], coord=self._coord(p.lineno(1))) def p_type_specifier_2(self, p): """ type_specifier : typedef_name | enum_specifier | struct_or_union_specifier """ p[0] = p[1] def p_type_qualifier(self, p): """ type_qualifier : CONST | RESTRICT | VOLATILE """ p[0] = p[1] def p_init_declarator_list_1(self, p): """ init_declarator_list : init_declarator | init_declarator_list COMMA init_declarator """ p[0] = p[1] + [p[3]] if len(p) == 4 else [p[1]] # If the code is declaring a variable that was declared a typedef in an # outer scope, yacc will think the name is part of declaration_specifiers, # not init_declarator, and will then get confused by EQUALS. Pass None # up in place of declarator, and handle this at a higher level. # def p_init_declarator_list_2(self, p): """ init_declarator_list : EQUALS initializer """ p[0] = [dict(decl=None, init=p[2])] # Similarly, if the code contains duplicate typedefs of, for example, # array types, the array portion will appear as an abstract declarator. # def p_init_declarator_list_3(self, p): """ init_declarator_list : abstract_declarator """ p[0] = [dict(decl=p[1], init=None)] # Returns a {decl= : init=} dictionary # If there's no initializer, uses None # def p_init_declarator(self, p): """ init_declarator : declarator | declarator EQUALS initializer """ p[0] = dict(decl=p[1], init=(p[3] if len(p) > 2 else None)) def p_specifier_qualifier_list_1(self, p): """ specifier_qualifier_list : type_qualifier specifier_qualifier_list_opt """ p[0] = self._add_declaration_specifier(p[2], p[1], 'qual') def p_specifier_qualifier_list_2(self, p): """ specifier_qualifier_list : type_specifier specifier_qualifier_list_opt """ p[0] = self._add_declaration_specifier(p[2], p[1], 'type') # TYPEID is allowed here (and in other struct/enum related tag names), because # struct/enum tags reside in their own namespace and can be named the same as types # def p_struct_or_union_specifier_1(self, p): """ struct_or_union_specifier : struct_or_union ID | struct_or_union TYPEID """ klass = self._select_struct_union_class(p[1]) p[0] = klass( name=p[2], decls=None, coord=self._coord(p.lineno(2))) def p_struct_or_union_specifier_2(self, p): """ struct_or_union_specifier : struct_or_union brace_open struct_declaration_list brace_close """ klass = self._select_struct_union_class(p[1]) p[0] = klass( name=None, decls=p[3], coord=self._coord(p.lineno(2))) def p_struct_or_union_specifier_3(self, p): """ struct_or_union_specifier : struct_or_union ID brace_open struct_declaration_list brace_close | struct_or_union TYPEID brace_open struct_declaration_list brace_close """ klass = self._select_struct_union_class(p[1]) p[0] = klass( name=p[2], decls=p[4], coord=self._coord(p.lineno(2))) def p_struct_or_union(self, p): """ struct_or_union : STRUCT | UNION """ p[0] = p[1] # Combine all declarations into a single list # def p_struct_declaration_list(self, p): """ struct_declaration_list : struct_declaration | struct_declaration_list struct_declaration """ p[0] = p[1] if len(p) == 2 else p[1] + p[2] def p_struct_declaration_1(self, p): """ struct_declaration : specifier_qualifier_list struct_declarator_list_opt SEMI """ spec = p[1] assert 'typedef' not in spec['storage'] if p[2] is not None: decls = self._build_declarations( spec=spec, decls=p[2]) elif len(spec['type']) == 1: # Anonymous struct/union, gcc extension, C1x feature. # Although the standard only allows structs/unions here, I see no # reason to disallow other types since some compilers have typedefs # here, and pycparser isn't about rejecting all invalid code. # node = spec['type'][0] if isinstance(node, c_ast.Node): decl_type = node else: decl_type = c_ast.IdentifierType(node) decls = self._build_declarations( spec=spec, decls=[dict(decl=decl_type)]) else: # Structure/union members can have the same names as typedefs. # The trouble is that the member's name gets grouped into # specifier_qualifier_list; _build_declarations compensates. # decls = self._build_declarations( spec=spec, decls=[dict(decl=None, init=None)]) p[0] = decls def p_struct_declaration_2(self, p): """ struct_declaration : specifier_qualifier_list abstract_declarator SEMI """ # "Abstract declarator?!", you ask? Structure members can have the # same names as typedefs. The trouble is that the member's name gets # grouped into specifier_qualifier_list, leaving any remainder to # appear as an abstract declarator, as in: # typedef int Foo; # struct { Foo Foo[3]; }; # p[0] = self._build_declarations( spec=p[1], decls=[dict(decl=p[2], init=None)]) def p_struct_declarator_list(self, p): """ struct_declarator_list : struct_declarator | struct_declarator_list COMMA struct_declarator """ p[0] = p[1] + [p[3]] if len(p) == 4 else [p[1]] # struct_declarator passes up a dict with the keys: decl (for # the underlying declarator) and bitsize (for the bitsize) # def p_struct_declarator_1(self, p): """ struct_declarator : declarator """ p[0] = {'decl': p[1], 'bitsize': None} def p_struct_declarator_2(self, p): """ struct_declarator : declarator COLON constant_expression | COLON constant_expression """ if len(p) > 3: p[0] = {'decl': p[1], 'bitsize': p[3]} else: p[0] = {'decl': c_ast.TypeDecl(None, None, None), 'bitsize': p[2]} def p_enum_specifier_1(self, p): """ enum_specifier : ENUM ID | ENUM TYPEID """ p[0] = c_ast.Enum(p[2], None, self._coord(p.lineno(1))) def p_enum_specifier_2(self, p): """ enum_specifier : ENUM brace_open enumerator_list brace_close """ p[0] = c_ast.Enum(None, p[3], self._coord(p.lineno(1))) def p_enum_specifier_3(self, p): """ enum_specifier : ENUM ID brace_open enumerator_list brace_close | ENUM TYPEID brace_open enumerator_list brace_close """ p[0] = c_ast.Enum(p[2], p[4], self._coord(p.lineno(1))) def p_enumerator_list(self, p): """ enumerator_list : enumerator | enumerator_list COMMA | enumerator_list COMMA enumerator """ if len(p) == 2: p[0] = c_ast.EnumeratorList([p[1]], p[1].coord) elif len(p) == 3: p[0] = p[1] else: p[1].enumerators.append(p[3]) p[0] = p[1] def p_enumerator(self, p): """ enumerator : ID | ID EQUALS constant_expression """ if len(p) == 2: enumerator = c_ast.Enumerator( p[1], None, self._coord(p.lineno(1))) else: enumerator = c_ast.Enumerator( p[1], p[3], self._coord(p.lineno(1))) self._add_identifier(enumerator.name, enumerator.coord) p[0] = enumerator def p_declarator_1(self, p): """ declarator : direct_declarator """ p[0] = p[1] def p_declarator_2(self, p): """ declarator : pointer direct_declarator """ p[0] = self._type_modify_decl(p[2], p[1]) # Since it's impossible for a type to be specified after a pointer, assume # it's intended to be the name for this declaration. _add_identifier will # raise an error if this TYPEID can't be redeclared. # def p_declarator_3(self, p): """ declarator : pointer TYPEID """ decl = c_ast.TypeDecl( declname=p[2], type=None, quals=None, coord=self._coord(p.lineno(2))) p[0] = self._type_modify_decl(decl, p[1]) def p_direct_declarator_1(self, p): """ direct_declarator : ID """ p[0] = c_ast.TypeDecl( declname=p[1], type=None, quals=None, coord=self._coord(p.lineno(1))) def p_direct_declarator_2(self, p): """ direct_declarator : LPAREN declarator RPAREN """ p[0] = p[2] def p_direct_declarator_3(self, p): """ direct_declarator : direct_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET """ quals = (p[3] if len(p) > 5 else []) or [] # Accept dimension qualifiers # Per C99 6.7.5.3 p7 arr = c_ast.ArrayDecl( type=None, dim=p[4] if len(p) > 5 else p[3], dim_quals=quals, coord=p[1].coord) p[0] = self._type_modify_decl(decl=p[1], modifier=arr) def p_direct_declarator_4(self, p): """ direct_declarator : direct_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET | direct_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET """ # Using slice notation for PLY objects doesn't work in Python 3 for the # version of PLY embedded with pycparser; see PLY Google Code issue 30. # Work around that here by listing the two elements separately. listed_quals = [item if isinstance(item, list) else [item] for item in [p[3],p[4]]] dim_quals = [qual for sublist in listed_quals for qual in sublist if qual is not None] arr = c_ast.ArrayDecl( type=None, dim=p[5], dim_quals=dim_quals, coord=p[1].coord) p[0] = self._type_modify_decl(decl=p[1], modifier=arr) # Special for VLAs # def p_direct_declarator_5(self, p): """ direct_declarator : direct_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET """ arr = c_ast.ArrayDecl( type=None, dim=c_ast.ID(p[4], self._coord(p.lineno(4))), dim_quals=p[3] if p[3] != None else [], coord=p[1].coord) p[0] = self._type_modify_decl(decl=p[1], modifier=arr) def p_direct_declarator_6(self, p): """ direct_declarator : direct_declarator LPAREN parameter_type_list RPAREN | direct_declarator LPAREN identifier_list_opt RPAREN """ func = c_ast.FuncDecl( args=p[3], type=None, coord=p[1].coord) # To see why _get_yacc_lookahead_token is needed, consider: # typedef char TT; # void foo(int TT) { TT = 10; } # Outside the function, TT is a typedef, but inside (starting and # ending with the braces) it's a parameter. The trouble begins with # yacc's lookahead token. We don't know if we're declaring or # defining a function until we see LBRACE, but if we wait for yacc to # trigger a rule on that token, then TT will have already been read # and incorrectly interpreted as TYPEID. We need to add the # parameters to the scope the moment the lexer sees LBRACE. # if self._get_yacc_lookahead_token().type == "LBRACE": if func.args is not None: for param in func.args.params: if isinstance(param, c_ast.EllipsisParam): break self._add_identifier(param.name, param.coord) p[0] = self._type_modify_decl(decl=p[1], modifier=func) def p_pointer(self, p): """ pointer : TIMES type_qualifier_list_opt | TIMES type_qualifier_list_opt pointer """ coord = self._coord(p.lineno(1)) # Pointer decls nest from inside out. This is important when different # levels have different qualifiers. For example: # # char * const * p; # # Means "pointer to const pointer to char" # # While: # # char ** const p; # # Means "const pointer to pointer to char" # # So when we construct PtrDecl nestings, the leftmost pointer goes in # as the most nested type. nested_type = c_ast.PtrDecl(quals=p[2] or [], type=None, coord=coord) if len(p) > 3: tail_type = p[3] while tail_type.type is not None: tail_type = tail_type.type tail_type.type = nested_type p[0] = p[3] else: p[0] = nested_type def p_type_qualifier_list(self, p): """ type_qualifier_list : type_qualifier | type_qualifier_list type_qualifier """ p[0] = [p[1]] if len(p) == 2 else p[1] + [p[2]] def p_parameter_type_list(self, p): """ parameter_type_list : parameter_list | parameter_list COMMA ELLIPSIS """ if len(p) > 2: p[1].params.append(c_ast.EllipsisParam(self._coord(p.lineno(3)))) p[0] = p[1] def p_parameter_list(self, p): """ parameter_list : parameter_declaration | parameter_list COMMA parameter_declaration """ if len(p) == 2: # single parameter p[0] = c_ast.ParamList([p[1]], p[1].coord) else: p[1].params.append(p[3]) p[0] = p[1] def p_parameter_declaration_1(self, p): """ parameter_declaration : declaration_specifiers declarator """ spec = p[1] if not spec['type']: spec['type'] = [c_ast.IdentifierType(['int'], coord=self._coord(p.lineno(1)))] p[0] = self._build_declarations( spec=spec, decls=[dict(decl=p[2])])[0] def p_parameter_declaration_2(self, p): """ parameter_declaration : declaration_specifiers abstract_declarator_opt """ spec = p[1] if not spec['type']: spec['type'] = [c_ast.IdentifierType(['int'], coord=self._coord(p.lineno(1)))] # Parameters can have the same names as typedefs. The trouble is that # the parameter's name gets grouped into declaration_specifiers, making # it look like an old-style declaration; compensate. # if len(spec['type']) > 1 and len(spec['type'][-1].names) == 1 and \ self._is_type_in_scope(spec['type'][-1].names[0]): decl = self._build_declarations( spec=spec, decls=[dict(decl=p[2], init=None)])[0] # This truly is an old-style parameter declaration # else: decl = c_ast.Typename( name='', quals=spec['qual'], type=p[2] or c_ast.TypeDecl(None, None, None), coord=self._coord(p.lineno(2))) typename = spec['type'] decl = self._fix_decl_name_type(decl, typename) p[0] = decl def p_identifier_list(self, p): """ identifier_list : identifier | identifier_list COMMA identifier """ if len(p) == 2: # single parameter p[0] = c_ast.ParamList([p[1]], p[1].coord) else: p[1].params.append(p[3]) p[0] = p[1] def p_initializer_1(self, p): """ initializer : assignment_expression """ p[0] = p[1] def p_initializer_2(self, p): """ initializer : brace_open initializer_list_opt brace_close | brace_open initializer_list COMMA brace_close """ if p[2] is None: p[0] = c_ast.InitList([], self._coord(p.lineno(1))) else: p[0] = p[2] def p_initializer_list(self, p): """ initializer_list : designation_opt initializer | initializer_list COMMA designation_opt initializer """ if len(p) == 3: # single initializer init = p[2] if p[1] is None else c_ast.NamedInitializer(p[1], p[2]) p[0] = c_ast.InitList([init], p[2].coord) else: init = p[4] if p[3] is None else c_ast.NamedInitializer(p[3], p[4]) p[1].exprs.append(init) p[0] = p[1] def p_designation(self, p): """ designation : designator_list EQUALS """ p[0] = p[1] # Designators are represented as a list of nodes, in the order in which # they're written in the code. # def p_designator_list(self, p): """ designator_list : designator | designator_list designator """ p[0] = [p[1]] if len(p) == 2 else p[1] + [p[2]] def p_designator(self, p): """ designator : LBRACKET constant_expression RBRACKET | PERIOD identifier """ p[0] = p[2] def p_type_name(self, p): """ type_name : specifier_qualifier_list abstract_declarator_opt """ #~ print '==========' #~ print p[1] #~ print p[2] #~ print p[2].children() #~ print '==========' typename = c_ast.Typename( name='', quals=p[1]['qual'], type=p[2] or c_ast.TypeDecl(None, None, None), coord=self._coord(p.lineno(2))) p[0] = self._fix_decl_name_type(typename, p[1]['type']) def p_abstract_declarator_1(self, p): """ abstract_declarator : pointer """ dummytype = c_ast.TypeDecl(None, None, None) p[0] = self._type_modify_decl( decl=dummytype, modifier=p[1]) def p_abstract_declarator_2(self, p): """ abstract_declarator : pointer direct_abstract_declarator """ p[0] = self._type_modify_decl(p[2], p[1]) def p_abstract_declarator_3(self, p): """ abstract_declarator : direct_abstract_declarator """ p[0] = p[1] # Creating and using direct_abstract_declarator_opt here # instead of listing both direct_abstract_declarator and the # lack of it in the beginning of _1 and _2 caused two # shift/reduce errors. # def p_direct_abstract_declarator_1(self, p): """ direct_abstract_declarator : LPAREN abstract_declarator RPAREN """ p[0] = p[2] def p_direct_abstract_declarator_2(self, p): """ direct_abstract_declarator : direct_abstract_declarator LBRACKET assignment_expression_opt RBRACKET """ arr = c_ast.ArrayDecl( type=None, dim=p[3], dim_quals=[], coord=p[1].coord) p[0] = self._type_modify_decl(decl=p[1], modifier=arr) def p_direct_abstract_declarator_3(self, p): """ direct_abstract_declarator : LBRACKET assignment_expression_opt RBRACKET """ p[0] = c_ast.ArrayDecl( type=c_ast.TypeDecl(None, None, None), dim=p[2], dim_quals=[], coord=self._coord(p.lineno(1))) def p_direct_abstract_declarator_4(self, p): """ direct_abstract_declarator : direct_abstract_declarator LBRACKET TIMES RBRACKET """ arr = c_ast.ArrayDecl( type=None, dim=c_ast.ID(p[3], self._coord(p.lineno(3))), dim_quals=[], coord=p[1].coord) p[0] = self._type_modify_decl(decl=p[1], modifier=arr) def p_direct_abstract_declarator_5(self, p): """ direct_abstract_declarator : LBRACKET TIMES RBRACKET """ p[0] = c_ast.ArrayDecl( type=c_ast.TypeDecl(None, None, None), dim=c_ast.ID(p[3], self._coord(p.lineno(3))), dim_quals=[], coord=self._coord(p.lineno(1))) def p_direct_abstract_declarator_6(self, p): """ direct_abstract_declarator : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN """ func = c_ast.FuncDecl( args=p[3], type=None, coord=p[1].coord) p[0] = self._type_modify_decl(decl=p[1], modifier=func) def p_direct_abstract_declarator_7(self, p): """ direct_abstract_declarator : LPAREN parameter_type_list_opt RPAREN """ p[0] = c_ast.FuncDecl( args=p[2], type=c_ast.TypeDecl(None, None, None), coord=self._coord(p.lineno(1))) # declaration is a list, statement isn't. To make it consistent, block_item # will always be a list # def p_block_item(self, p): """ block_item : declaration | statement """ p[0] = p[1] if isinstance(p[1], list) else [p[1]] # Since we made block_item a list, this just combines lists # def p_block_item_list(self, p): """ block_item_list : block_item | block_item_list block_item """ # Empty block items (plain ';') produce [None], so ignore them p[0] = p[1] if (len(p) == 2 or p[2] == [None]) else p[1] + p[2] def p_compound_statement_1(self, p): """ compound_statement : brace_open block_item_list_opt brace_close """ p[0] = c_ast.Compound( block_items=p[2], coord=self._coord(p.lineno(1))) def p_labeled_statement_1(self, p): """ labeled_statement : ID COLON statement """ p[0] = c_ast.Label(p[1], p[3], self._coord(p.lineno(1))) def p_labeled_statement_2(self, p): """ labeled_statement : CASE constant_expression COLON statement """ p[0] = c_ast.Case(p[2], [p[4]], self._coord(p.lineno(1))) def p_labeled_statement_3(self, p): """ labeled_statement : DEFAULT COLON statement """ p[0] = c_ast.Default([p[3]], self._coord(p.lineno(1))) def p_selection_statement_1(self, p): """ selection_statement : IF LPAREN expression RPAREN statement """ p[0] = c_ast.If(p[3], p[5], None, self._coord(p.lineno(1))) def p_selection_statement_2(self, p): """ selection_statement : IF LPAREN expression RPAREN statement ELSE statement """ p[0] = c_ast.If(p[3], p[5], p[7], self._coord(p.lineno(1))) def p_selection_statement_3(self, p): """ selection_statement : SWITCH LPAREN expression RPAREN statement """ p[0] = fix_switch_cases( c_ast.Switch(p[3], p[5], self._coord(p.lineno(1)))) def p_iteration_statement_1(self, p): """ iteration_statement : WHILE LPAREN expression RPAREN statement """ p[0] = c_ast.While(p[3], p[5], self._coord(p.lineno(1))) def p_iteration_statement_2(self, p): """ iteration_statement : DO statement WHILE LPAREN expression RPAREN SEMI """ p[0] = c_ast.DoWhile(p[5], p[2], self._coord(p.lineno(1))) def p_iteration_statement_3(self, p): """ iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement """ p[0] = c_ast.For(p[3], p[5], p[7], p[9], self._coord(p.lineno(1))) def p_iteration_statement_4(self, p): """ iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN statement """ p[0] = c_ast.For(c_ast.DeclList(p[3], self._coord(p.lineno(1))), p[4], p[6], p[8], self._coord(p.lineno(1))) def p_jump_statement_1(self, p): """ jump_statement : GOTO ID SEMI """ p[0] = c_ast.Goto(p[2], self._coord(p.lineno(1))) def p_jump_statement_2(self, p): """ jump_statement : BREAK SEMI """ p[0] = c_ast.Break(self._coord(p.lineno(1))) def p_jump_statement_3(self, p): """ jump_statement : CONTINUE SEMI """ p[0] = c_ast.Continue(self._coord(p.lineno(1))) def p_jump_statement_4(self, p): """ jump_statement : RETURN expression SEMI | RETURN SEMI """ p[0] = c_ast.Return(p[2] if len(p) == 4 else None, self._coord(p.lineno(1))) def p_expression_statement(self, p): """ expression_statement : expression_opt SEMI """ if p[1] is None: p[0] = c_ast.EmptyStatement(self._coord(p.lineno(1))) else: p[0] = p[1] def p_expression(self, p): """ expression : assignment_expression | expression COMMA assignment_expression """ if len(p) == 2: p[0] = p[1] else: if not isinstance(p[1], c_ast.ExprList): p[1] = c_ast.ExprList([p[1]], p[1].coord) p[1].exprs.append(p[3]) p[0] = p[1] def p_typedef_name(self, p): """ typedef_name : TYPEID """ p[0] = c_ast.IdentifierType([p[1]], coord=self._coord(p.lineno(1))) def p_assignment_expression(self, p): """ assignment_expression : conditional_expression | unary_expression assignment_operator assignment_expression """ if len(p) == 2: p[0] = p[1] else: p[0] = c_ast.Assignment(p[2], p[1], p[3], p[1].coord) # K&R2 defines these as many separate rules, to encode # precedence and associativity. Why work hard ? I'll just use # the built in precedence/associativity specification feature # of PLY. (see precedence declaration above) # def p_assignment_operator(self, p): """ assignment_operator : EQUALS | XOREQUAL | TIMESEQUAL | DIVEQUAL | MODEQUAL | PLUSEQUAL | MINUSEQUAL | LSHIFTEQUAL | RSHIFTEQUAL | ANDEQUAL | OREQUAL """ p[0] = p[1] def p_constant_expression(self, p): """ constant_expression : conditional_expression """ p[0] = p[1] def p_conditional_expression(self, p): """ conditional_expression : binary_expression | binary_expression CONDOP expression COLON conditional_expression """ if len(p) == 2: p[0] = p[1] else: p[0] = c_ast.TernaryOp(p[1], p[3], p[5], p[1].coord) def p_binary_expression(self, p): """ binary_expression : cast_expression | binary_expression TIMES binary_expression | binary_expression DIVIDE binary_expression | binary_expression MOD binary_expression | binary_expression PLUS binary_expression | binary_expression MINUS binary_expression | binary_expression RSHIFT binary_expression | binary_expression LSHIFT binary_expression | binary_expression LT binary_expression | binary_expression LE binary_expression | binary_expression GE binary_expression | binary_expression GT binary_expression | binary_expression EQ binary_expression | binary_expression NE binary_expression | binary_expression AND binary_expression | binary_expression OR binary_expression | binary_expression XOR binary_expression | binary_expression LAND binary_expression | binary_expression LOR binary_expression """ if len(p) == 2: p[0] = p[1] else: p[0] = c_ast.BinaryOp(p[2], p[1], p[3], p[1].coord) def p_cast_expression_1(self, p): """ cast_expression : unary_expression """ p[0] = p[1] def p_cast_expression_2(self, p): """ cast_expression : LPAREN type_name RPAREN cast_expression """ p[0] = c_ast.Cast(p[2], p[4], self._coord(p.lineno(1))) def p_unary_expression_1(self, p): """ unary_expression : postfix_expression """ p[0] = p[1] def p_unary_expression_2(self, p): """ unary_expression : PLUSPLUS unary_expression | MINUSMINUS unary_expression | unary_operator cast_expression """ p[0] = c_ast.UnaryOp(p[1], p[2], p[2].coord) def p_unary_expression_3(self, p): """ unary_expression : SIZEOF unary_expression | SIZEOF LPAREN type_name RPAREN """ p[0] = c_ast.UnaryOp( p[1], p[2] if len(p) == 3 else p[3], self._coord(p.lineno(1))) def p_unary_operator(self, p): """ unary_operator : AND | TIMES | PLUS | MINUS | NOT | LNOT """ p[0] = p[1] def p_postfix_expression_1(self, p): """ postfix_expression : primary_expression """ p[0] = p[1] def p_postfix_expression_2(self, p): """ postfix_expression : postfix_expression LBRACKET expression RBRACKET """ p[0] = c_ast.ArrayRef(p[1], p[3], p[1].coord) def p_postfix_expression_3(self, p): """ postfix_expression : postfix_expression LPAREN argument_expression_list RPAREN | postfix_expression LPAREN RPAREN """ p[0] = c_ast.FuncCall(p[1], p[3] if len(p) == 5 else None, p[1].coord) def p_postfix_expression_4(self, p): """ postfix_expression : postfix_expression PERIOD ID | postfix_expression PERIOD TYPEID | postfix_expression ARROW ID | postfix_expression ARROW TYPEID """ field = c_ast.ID(p[3], self._coord(p.lineno(3))) p[0] = c_ast.StructRef(p[1], p[2], field, p[1].coord) def p_postfix_expression_5(self, p): """ postfix_expression : postfix_expression PLUSPLUS | postfix_expression MINUSMINUS """ p[0] = c_ast.UnaryOp('p' + p[2], p[1], p[1].coord) def p_postfix_expression_6(self, p): """ postfix_expression : LPAREN type_name RPAREN brace_open initializer_list brace_close | LPAREN type_name RPAREN brace_open initializer_list COMMA brace_close """ p[0] = c_ast.CompoundLiteral(p[2], p[5]) def p_primary_expression_1(self, p): """ primary_expression : identifier """ p[0] = p[1] def p_primary_expression_2(self, p): """ primary_expression : constant """ p[0] = p[1] def p_primary_expression_3(self, p): """ primary_expression : unified_string_literal | unified_wstring_literal """ p[0] = p[1] def p_primary_expression_4(self, p): """ primary_expression : LPAREN expression RPAREN """ p[0] = p[2] def p_primary_expression_5(self, p): """ primary_expression : OFFSETOF LPAREN type_name COMMA identifier RPAREN """ coord = self._coord(p.lineno(1)) p[0] = c_ast.FuncCall(c_ast.ID(p[1], coord), c_ast.ExprList([p[3], p[5]], coord), coord) def p_argument_expression_list(self, p): """ argument_expression_list : assignment_expression | argument_expression_list COMMA assignment_expression """ if len(p) == 2: # single expr p[0] = c_ast.ExprList([p[1]], p[1].coord) else: p[1].exprs.append(p[3]) p[0] = p[1] def p_identifier(self, p): """ identifier : ID """ p[0] = c_ast.ID(p[1], self._coord(p.lineno(1))) def p_constant_1(self, p): """ constant : INT_CONST_DEC | INT_CONST_OCT | INT_CONST_HEX | INT_CONST_BIN """ p[0] = c_ast.Constant( 'int', p[1], self._coord(p.lineno(1))) def p_constant_2(self, p): """ constant : FLOAT_CONST | HEX_FLOAT_CONST """ p[0] = c_ast.Constant( 'float', p[1], self._coord(p.lineno(1))) def p_constant_3(self, p): """ constant : CHAR_CONST | WCHAR_CONST """ p[0] = c_ast.Constant( 'char', p[1], self._coord(p.lineno(1))) # The "unified" string and wstring literal rules are for supporting # concatenation of adjacent string literals. # I.e. "hello " "world" is seen by the C compiler as a single string literal # with the value "hello world" # def p_unified_string_literal(self, p): """ unified_string_literal : STRING_LITERAL | unified_string_literal STRING_LITERAL """ if len(p) == 2: # single literal p[0] = c_ast.Constant( 'string', p[1], self._coord(p.lineno(1))) else: p[1].value = p[1].value[:-1] + p[2][1:] p[0] = p[1] def p_unified_wstring_literal(self, p): """ unified_wstring_literal : WSTRING_LITERAL | unified_wstring_literal WSTRING_LITERAL """ if len(p) == 2: # single literal p[0] = c_ast.Constant( 'string', p[1], self._coord(p.lineno(1))) else: p[1].value = p[1].value.rstrip()[:-1] + p[2][2:] p[0] = p[1] def p_brace_open(self, p): """ brace_open : LBRACE """ p[0] = p[1] def p_brace_close(self, p): """ brace_close : RBRACE """ p[0] = p[1] def p_empty(self, p): 'empty : ' p[0] = None def p_error(self, p): # If error recovery is added here in the future, make sure # _get_yacc_lookahead_token still works! # if p: self._parse_error( 'before: %s' % p.value, self._coord(lineno=p.lineno, column=self.clex.find_tok_column(p))) else: self._parse_error('At end of input', '') #------------------------------------------------------------------------------ if __name__ == "__main__": import pprint import time, sys #t1 = time.time() #parser = CParser(lex_optimize=True, yacc_debug=True, yacc_optimize=False) #sys.write(time.time() - t1) #buf = ''' #int (*k)(int); #''' ## set debuglevel to 2 for debugging #t = parser.parse(buf, 'x.c', debuglevel=0) #t.show(showcoord=True) pycparser-2.14/pycparser/ast_transforms.py0000644000175000017500000000676012523673300021627 0ustar elibeneliben00000000000000#------------------------------------------------------------------------------ # pycparser: ast_transforms.py # # Some utilities used by the parser to create a friendlier AST. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #------------------------------------------------------------------------------ from . import c_ast def fix_switch_cases(switch_node): """ The 'case' statements in a 'switch' come out of parsing with one child node, so subsequent statements are just tucked to the parent Compound. Additionally, consecutive (fall-through) case statements come out messy. This is a peculiarity of the C grammar. The following: switch (myvar) { case 10: k = 10; p = k + 1; return 10; case 20: case 30: return 20; default: break; } Creates this tree (pseudo-dump): Switch ID: myvar Compound: Case 10: k = 10 p = k + 1 return 10 Case 20: Case 30: return 20 Default: break The goal of this transform it to fix this mess, turning it into the following: Switch ID: myvar Compound: Case 10: k = 10 p = k + 1 return 10 Case 20: Case 30: return 20 Default: break A fixed AST node is returned. The argument may be modified. """ assert isinstance(switch_node, c_ast.Switch) if not isinstance(switch_node.stmt, c_ast.Compound): return switch_node # The new Compound child for the Switch, which will collect children in the # correct order new_compound = c_ast.Compound([], switch_node.stmt.coord) # The last Case/Default node last_case = None # Goes over the children of the Compound below the Switch, adding them # either directly below new_compound or below the last Case as appropriate for child in switch_node.stmt.block_items: if isinstance(child, (c_ast.Case, c_ast.Default)): # If it's a Case/Default: # 1. Add it to the Compound and mark as "last case" # 2. If its immediate child is also a Case or Default, promote it # to a sibling. new_compound.block_items.append(child) _extract_nested_case(child, new_compound.block_items) last_case = new_compound.block_items[-1] else: # Other statements are added as children to the last case, if it # exists. if last_case is None: new_compound.block_items.append(child) else: last_case.stmts.append(child) switch_node.stmt = new_compound return switch_node def _extract_nested_case(case_node, stmts_list): """ Recursively extract consecutive Case statements that are made nested by the parser and add them to the stmts_list. """ if isinstance(case_node.stmts[0], (c_ast.Case, c_ast.Default)): stmts_list.append(case_node.stmts.pop()) _extract_nested_case(stmts_list[-1], stmts_list) pycparser-2.14/pycparser/_ast_gen.py0000644000175000017500000002072712523673365020353 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # _ast_gen.py # # Generates the AST Node classes from a specification given in # a configuration file # # The design of this module was inspired by astgen.py from the # Python 2.5 code-base. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- import pprint from string import Template class ASTCodeGenerator(object): def __init__(self, cfg_filename='_c_ast.cfg'): """ Initialize the code generator from a configuration file. """ self.cfg_filename = cfg_filename self.node_cfg = [NodeCfg(name, contents) for (name, contents) in self.parse_cfgfile(cfg_filename)] def generate(self, file=None): """ Generates the code into file, an open file buffer. """ src = Template(_PROLOGUE_COMMENT).substitute( cfg_filename=self.cfg_filename) src += _PROLOGUE_CODE for node_cfg in self.node_cfg: src += node_cfg.generate_source() + '\n\n' file.write(src) def parse_cfgfile(self, filename): """ Parse the configuration file and yield pairs of (name, contents) for each node. """ with open(filename, "r") as f: for line in f: line = line.strip() if not line or line.startswith('#'): continue colon_i = line.find(':') lbracket_i = line.find('[') rbracket_i = line.find(']') if colon_i < 1 or lbracket_i <= colon_i or rbracket_i <= lbracket_i: raise RuntimeError("Invalid line in %s:\n%s\n" % (filename, line)) name = line[:colon_i] val = line[lbracket_i + 1:rbracket_i] vallist = [v.strip() for v in val.split(',')] if val else [] yield name, vallist class NodeCfg(object): """ Node configuration. name: node name contents: a list of contents - attributes and child nodes See comment at the top of the configuration file for details. """ def __init__(self, name, contents): self.name = name self.all_entries = [] self.attr = [] self.child = [] self.seq_child = [] for entry in contents: clean_entry = entry.rstrip('*') self.all_entries.append(clean_entry) if entry.endswith('**'): self.seq_child.append(clean_entry) elif entry.endswith('*'): self.child.append(clean_entry) else: self.attr.append(entry) def generate_source(self): src = self._gen_init() src += '\n' + self._gen_children() src += '\n' + self._gen_attr_names() return src def _gen_init(self): src = "class %s(Node):\n" % self.name if self.all_entries: args = ', '.join(self.all_entries) slots = ', '.join("'{0}'".format(e) for e in self.all_entries) slots += ", 'coord', '__weakref__'" arglist = '(self, %s, coord=None)' % args else: slots = "'coord', '__weakref__'" arglist = '(self, coord=None)' src += " __slots__ = (%s)\n" % slots src += " def __init__%s:\n" % arglist for name in self.all_entries + ['coord']: src += " self.%s = %s\n" % (name, name) return src def _gen_children(self): src = ' def children(self):\n' if self.all_entries: src += ' nodelist = []\n' for child in self.child: src += ( ' if self.%(child)s is not None:' + ' nodelist.append(("%(child)s", self.%(child)s))\n') % ( dict(child=child)) for seq_child in self.seq_child: src += ( ' for i, child in enumerate(self.%(child)s or []):\n' ' nodelist.append(("%(child)s[%%d]" %% i, child))\n') % ( dict(child=seq_child)) src += ' return tuple(nodelist)\n' else: src += ' return ()\n' return src def _gen_attr_names(self): src = " attr_names = (" + ''.join("%r, " % nm for nm in self.attr) + ')' return src _PROLOGUE_COMMENT = \ r'''#----------------------------------------------------------------- # ** ATTENTION ** # This code was automatically generated from the file: # $cfg_filename # # Do not modify it directly. Modify the configuration file and # run the generator again. # ** ** *** ** ** # # pycparser: c_ast.py # # AST Node classes. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- ''' _PROLOGUE_CODE = r''' import sys class Node(object): __slots__ = () """ Abstract base class for AST nodes. """ def children(self): """ A sequence of all children that are Nodes """ pass def show(self, buf=sys.stdout, offset=0, attrnames=False, nodenames=False, showcoord=False, _my_node_name=None): """ Pretty print the Node and all its attributes and children (recursively) to a buffer. buf: Open IO buffer into which the Node is printed. offset: Initial offset (amount of leading spaces) attrnames: True if you want to see the attribute names in name=value pairs. False to only see the values. nodenames: True if you want to see the actual node names within their parents. showcoord: Do you want the coordinates of each Node to be displayed. """ lead = ' ' * offset if nodenames and _my_node_name is not None: buf.write(lead + self.__class__.__name__+ ' <' + _my_node_name + '>: ') else: buf.write(lead + self.__class__.__name__+ ': ') if self.attr_names: if attrnames: nvlist = [(n, getattr(self,n)) for n in self.attr_names] attrstr = ', '.join('%s=%s' % nv for nv in nvlist) else: vlist = [getattr(self, n) for n in self.attr_names] attrstr = ', '.join('%s' % v for v in vlist) buf.write(attrstr) if showcoord: buf.write(' (at %s)' % self.coord) buf.write('\n') for (child_name, child) in self.children(): child.show( buf, offset=offset + 2, attrnames=attrnames, nodenames=nodenames, showcoord=showcoord, _my_node_name=child_name) class NodeVisitor(object): """ A base NodeVisitor class for visiting c_ast nodes. Subclass it and define your own visit_XXX methods, where XXX is the class name you want to visit with these methods. For example: class ConstantVisitor(NodeVisitor): def __init__(self): self.values = [] def visit_Constant(self, node): self.values.append(node.value) Creates a list of values of all the constant nodes encountered below the given node. To use it: cv = ConstantVisitor() cv.visit(node) Notes: * generic_visit() will be called for AST nodes for which no visit_XXX method was defined. * The children of nodes for which a visit_XXX was defined will not be visited - if you need this, call generic_visit() on the node. You can use: NodeVisitor.generic_visit(self, node) * Modeled after Python's own AST visiting facilities (the ast module of Python 3.0) """ def visit(self, node): """ Visit a node. """ method = 'visit_' + node.__class__.__name__ visitor = getattr(self, method, self.generic_visit) return visitor(node) def generic_visit(self, node): """ Called if no explicit visitor function exists for a node. Implements preorder visiting of the node. """ for c_name, c in node.children(): self.visit(c) ''' if __name__ == "__main__": import sys ast_gen = ASTCodeGenerator('_c_ast.cfg') ast_gen.generate(open('c_ast.py', 'w')) pycparser-2.14/pycparser/c_generator.py0000664000175000017500000003240212523673310021045 0ustar elibeneliben00000000000000#------------------------------------------------------------------------------ # pycparser: c_generator.py # # C code generator from pycparser AST nodes. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #------------------------------------------------------------------------------ from . import c_ast class CGenerator(object): """ Uses the same visitor pattern as c_ast.NodeVisitor, but modified to return a value from each visit method, using string accumulation in generic_visit. """ def __init__(self): # Statements start with indentation of self.indent_level spaces, using # the _make_indent method # self.indent_level = 0 def _make_indent(self): return ' ' * self.indent_level def visit(self, node): method = 'visit_' + node.__class__.__name__ return getattr(self, method, self.generic_visit)(node) def generic_visit(self, node): #~ print('generic:', type(node)) if node is None: return '' else: return ''.join(self.visit(c) for c_name, c in node.children()) def visit_Constant(self, n): return n.value def visit_ID(self, n): return n.name def visit_ArrayRef(self, n): arrref = self._parenthesize_unless_simple(n.name) return arrref + '[' + self.visit(n.subscript) + ']' def visit_StructRef(self, n): sref = self._parenthesize_unless_simple(n.name) return sref + n.type + self.visit(n.field) def visit_FuncCall(self, n): fref = self._parenthesize_unless_simple(n.name) return fref + '(' + self.visit(n.args) + ')' def visit_UnaryOp(self, n): operand = self._parenthesize_unless_simple(n.expr) if n.op == 'p++': return '%s++' % operand elif n.op == 'p--': return '%s--' % operand elif n.op == 'sizeof': # Always parenthesize the argument of sizeof since it can be # a name. return 'sizeof(%s)' % self.visit(n.expr) else: return '%s%s' % (n.op, operand) def visit_BinaryOp(self, n): lval_str = self._parenthesize_if(n.left, lambda d: not self._is_simple_node(d)) rval_str = self._parenthesize_if(n.right, lambda d: not self._is_simple_node(d)) return '%s %s %s' % (lval_str, n.op, rval_str) def visit_Assignment(self, n): rval_str = self._parenthesize_if( n.rvalue, lambda n: isinstance(n, c_ast.Assignment)) return '%s %s %s' % (self.visit(n.lvalue), n.op, rval_str) def visit_IdentifierType(self, n): return ' '.join(n.names) def _visit_expr(self, n): if isinstance(n, c_ast.InitList): return '{' + self.visit(n) + '}' elif isinstance(n, c_ast.ExprList): return '(' + self.visit(n) + ')' else: return self.visit(n) def visit_Decl(self, n, no_type=False): # no_type is used when a Decl is part of a DeclList, where the type is # explicitly only for the first declaration in a list. # s = n.name if no_type else self._generate_decl(n) if n.bitsize: s += ' : ' + self.visit(n.bitsize) if n.init: s += ' = ' + self._visit_expr(n.init) return s def visit_DeclList(self, n): s = self.visit(n.decls[0]) if len(n.decls) > 1: s += ', ' + ', '.join(self.visit_Decl(decl, no_type=True) for decl in n.decls[1:]) return s def visit_Typedef(self, n): s = '' if n.storage: s += ' '.join(n.storage) + ' ' s += self._generate_type(n.type) return s def visit_Cast(self, n): s = '(' + self._generate_type(n.to_type) + ')' return s + ' ' + self._parenthesize_unless_simple(n.expr) def visit_ExprList(self, n): visited_subexprs = [] for expr in n.exprs: visited_subexprs.append(self._visit_expr(expr)) return ', '.join(visited_subexprs) def visit_InitList(self, n): visited_subexprs = [] for expr in n.exprs: visited_subexprs.append(self._visit_expr(expr)) return ', '.join(visited_subexprs) def visit_Enum(self, n): s = 'enum' if n.name: s += ' ' + n.name if n.values: s += ' {' for i, enumerator in enumerate(n.values.enumerators): s += enumerator.name if enumerator.value: s += ' = ' + self.visit(enumerator.value) if i != len(n.values.enumerators) - 1: s += ', ' s += '}' return s def visit_FuncDef(self, n): decl = self.visit(n.decl) self.indent_level = 0 body = self.visit(n.body) if n.param_decls: knrdecls = ';\n'.join(self.visit(p) for p in n.param_decls) return decl + '\n' + knrdecls + ';\n' + body + '\n' else: return decl + '\n' + body + '\n' def visit_FileAST(self, n): s = '' for ext in n.ext: if isinstance(ext, c_ast.FuncDef): s += self.visit(ext) else: s += self.visit(ext) + ';\n' return s def visit_Compound(self, n): s = self._make_indent() + '{\n' self.indent_level += 2 if n.block_items: s += ''.join(self._generate_stmt(stmt) for stmt in n.block_items) self.indent_level -= 2 s += self._make_indent() + '}\n' return s def visit_EmptyStatement(self, n): return ';' def visit_ParamList(self, n): return ', '.join(self.visit(param) for param in n.params) def visit_Return(self, n): s = 'return' if n.expr: s += ' ' + self.visit(n.expr) return s + ';' def visit_Break(self, n): return 'break;' def visit_Continue(self, n): return 'continue;' def visit_TernaryOp(self, n): s = self._visit_expr(n.cond) + ' ? ' s += self._visit_expr(n.iftrue) + ' : ' s += self._visit_expr(n.iffalse) return s def visit_If(self, n): s = 'if (' if n.cond: s += self.visit(n.cond) s += ')\n' s += self._generate_stmt(n.iftrue, add_indent=True) if n.iffalse: s += self._make_indent() + 'else\n' s += self._generate_stmt(n.iffalse, add_indent=True) return s def visit_For(self, n): s = 'for (' if n.init: s += self.visit(n.init) s += ';' if n.cond: s += ' ' + self.visit(n.cond) s += ';' if n.next: s += ' ' + self.visit(n.next) s += ')\n' s += self._generate_stmt(n.stmt, add_indent=True) return s def visit_While(self, n): s = 'while (' if n.cond: s += self.visit(n.cond) s += ')\n' s += self._generate_stmt(n.stmt, add_indent=True) return s def visit_DoWhile(self, n): s = 'do\n' s += self._generate_stmt(n.stmt, add_indent=True) s += self._make_indent() + 'while (' if n.cond: s += self.visit(n.cond) s += ');' return s def visit_Switch(self, n): s = 'switch (' + self.visit(n.cond) + ')\n' s += self._generate_stmt(n.stmt, add_indent=True) return s def visit_Case(self, n): s = 'case ' + self.visit(n.expr) + ':\n' for stmt in n.stmts: s += self._generate_stmt(stmt, add_indent=True) return s def visit_Default(self, n): s = 'default:\n' for stmt in n.stmts: s += self._generate_stmt(stmt, add_indent=True) return s def visit_Label(self, n): return n.name + ':\n' + self._generate_stmt(n.stmt) def visit_Goto(self, n): return 'goto ' + n.name + ';' def visit_EllipsisParam(self, n): return '...' def visit_Struct(self, n): return self._generate_struct_union(n, 'struct') def visit_Typename(self, n): return self._generate_type(n.type) def visit_Union(self, n): return self._generate_struct_union(n, 'union') def visit_NamedInitializer(self, n): s = '' for name in n.name: if isinstance(name, c_ast.ID): s += '.' + name.name elif isinstance(name, c_ast.Constant): s += '[' + name.value + ']' s += ' = ' + self.visit(n.expr) return s def visit_FuncDecl(self, n): return self._generate_type(n) def _generate_struct_union(self, n, name): """ Generates code for structs and unions. name should be either 'struct' or union. """ s = name + ' ' + (n.name or '') if n.decls: s += '\n' s += self._make_indent() self.indent_level += 2 s += '{\n' for decl in n.decls: s += self._generate_stmt(decl) self.indent_level -= 2 s += self._make_indent() + '}' return s def _generate_stmt(self, n, add_indent=False): """ Generation from a statement node. This method exists as a wrapper for individual visit_* methods to handle different treatment of some statements in this context. """ typ = type(n) if add_indent: self.indent_level += 2 indent = self._make_indent() if add_indent: self.indent_level -= 2 if typ in ( c_ast.Decl, c_ast.Assignment, c_ast.Cast, c_ast.UnaryOp, c_ast.BinaryOp, c_ast.TernaryOp, c_ast.FuncCall, c_ast.ArrayRef, c_ast.StructRef, c_ast.Constant, c_ast.ID, c_ast.Typedef, c_ast.ExprList): # These can also appear in an expression context so no semicolon # is added to them automatically # return indent + self.visit(n) + ';\n' elif typ in (c_ast.Compound,): # No extra indentation required before the opening brace of a # compound - because it consists of multiple lines it has to # compute its own indentation. # return self.visit(n) else: return indent + self.visit(n) + '\n' def _generate_decl(self, n): """ Generation from a Decl node. """ s = '' if n.funcspec: s = ' '.join(n.funcspec) + ' ' if n.storage: s += ' '.join(n.storage) + ' ' s += self._generate_type(n.type) return s def _generate_type(self, n, modifiers=[]): """ Recursive generation from a type node. n is the type node. modifiers collects the PtrDecl, ArrayDecl and FuncDecl modifiers encountered on the way down to a TypeDecl, to allow proper generation from it. """ typ = type(n) #~ print(n, modifiers) if typ == c_ast.TypeDecl: s = '' if n.quals: s += ' '.join(n.quals) + ' ' s += self.visit(n.type) nstr = n.declname if n.declname else '' # Resolve modifiers. # Wrap in parens to distinguish pointer to array and pointer to # function syntax. # for i, modifier in enumerate(modifiers): if isinstance(modifier, c_ast.ArrayDecl): if (i != 0 and isinstance(modifiers[i - 1], c_ast.PtrDecl)): nstr = '(' + nstr + ')' nstr += '[' + self.visit(modifier.dim) + ']' elif isinstance(modifier, c_ast.FuncDecl): if (i != 0 and isinstance(modifiers[i - 1], c_ast.PtrDecl)): nstr = '(' + nstr + ')' nstr += '(' + self.visit(modifier.args) + ')' elif isinstance(modifier, c_ast.PtrDecl): if modifier.quals: nstr = '* %s %s' % (' '.join(modifier.quals), nstr) else: nstr = '*' + nstr if nstr: s += ' ' + nstr return s elif typ == c_ast.Decl: return self._generate_decl(n.type) elif typ == c_ast.Typename: return self._generate_type(n.type) elif typ == c_ast.IdentifierType: return ' '.join(n.names) + ' ' elif typ in (c_ast.ArrayDecl, c_ast.PtrDecl, c_ast.FuncDecl): return self._generate_type(n.type, modifiers + [n]) else: return self.visit(n) def _parenthesize_if(self, n, condition): """ Visits 'n' and returns its string representation, parenthesized if the condition function applied to the node returns True. """ s = self._visit_expr(n) if condition(n): return '(' + s + ')' else: return s def _parenthesize_unless_simple(self, n): """ Common use case for _parenthesize_if """ return self._parenthesize_if(n, lambda d: not self._is_simple_node(d)) def _is_simple_node(self, n): """ Returns True for nodes that are "simple" - i.e. nodes that always have higher precedence than operators. """ return isinstance(n,( c_ast.Constant, c_ast.ID, c_ast.ArrayRef, c_ast.StructRef, c_ast.FuncCall)) pycparser-2.14/pycparser/c_lexer.py0000664000175000017500000003415712523673371020216 0ustar elibeneliben00000000000000#------------------------------------------------------------------------------ # pycparser: c_lexer.py # # CLexer class: lexer for the C language # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #------------------------------------------------------------------------------ import re import sys from .ply import lex from .ply.lex import TOKEN class CLexer(object): """ A lexer for the C language. After building it, set the input text with input(), and call token() to get new tokens. The public attribute filename can be set to an initial filaneme, but the lexer will update it upon #line directives. """ def __init__(self, error_func, on_lbrace_func, on_rbrace_func, type_lookup_func): """ Create a new Lexer. error_func: An error function. Will be called with an error message, line and column as arguments, in case of an error during lexing. on_lbrace_func, on_rbrace_func: Called when an LBRACE or RBRACE is encountered (likely to push/pop type_lookup_func's scope) type_lookup_func: A type lookup function. Given a string, it must return True IFF this string is a name of a type that was defined with a typedef earlier. """ self.error_func = error_func self.on_lbrace_func = on_lbrace_func self.on_rbrace_func = on_rbrace_func self.type_lookup_func = type_lookup_func self.filename = '' # Keeps track of the last token returned from self.token() self.last_token = None # Allow either "# line" or "# " to support GCC's # cpp output # self.line_pattern = re.compile('([ \t]*line\W)|([ \t]*\d+)') self.pragma_pattern = re.compile('[ \t]*pragma\W') def build(self, **kwargs): """ Builds the lexer from the specification. Must be called after the lexer object is created. This method exists separately, because the PLY manual warns against calling lex.lex inside __init__ """ self.lexer = lex.lex(object=self, **kwargs) def reset_lineno(self): """ Resets the internal line number counter of the lexer. """ self.lexer.lineno = 1 def input(self, text): self.lexer.input(text) def token(self): self.last_token = self.lexer.token() return self.last_token def find_tok_column(self, token): """ Find the column of the token in its line. """ last_cr = self.lexer.lexdata.rfind('\n', 0, token.lexpos) return token.lexpos - last_cr ######################-- PRIVATE --###################### ## ## Internal auxiliary methods ## def _error(self, msg, token): location = self._make_tok_location(token) self.error_func(msg, location[0], location[1]) self.lexer.skip(1) def _make_tok_location(self, token): return (token.lineno, self.find_tok_column(token)) ## ## Reserved keywords ## keywords = ( '_BOOL', '_COMPLEX', 'AUTO', 'BREAK', 'CASE', 'CHAR', 'CONST', 'CONTINUE', 'DEFAULT', 'DO', 'DOUBLE', 'ELSE', 'ENUM', 'EXTERN', 'FLOAT', 'FOR', 'GOTO', 'IF', 'INLINE', 'INT', 'LONG', 'REGISTER', 'OFFSETOF', 'RESTRICT', 'RETURN', 'SHORT', 'SIGNED', 'SIZEOF', 'STATIC', 'STRUCT', 'SWITCH', 'TYPEDEF', 'UNION', 'UNSIGNED', 'VOID', 'VOLATILE', 'WHILE', ) keyword_map = {} for keyword in keywords: if keyword == '_BOOL': keyword_map['_Bool'] = keyword elif keyword == '_COMPLEX': keyword_map['_Complex'] = keyword else: keyword_map[keyword.lower()] = keyword ## ## All the tokens recognized by the lexer ## tokens = keywords + ( # Identifiers 'ID', # Type identifiers (identifiers previously defined as # types with typedef) 'TYPEID', # constants 'INT_CONST_DEC', 'INT_CONST_OCT', 'INT_CONST_HEX', 'INT_CONST_BIN', 'FLOAT_CONST', 'HEX_FLOAT_CONST', 'CHAR_CONST', 'WCHAR_CONST', # String literals 'STRING_LITERAL', 'WSTRING_LITERAL', # Operators 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'MOD', 'OR', 'AND', 'NOT', 'XOR', 'LSHIFT', 'RSHIFT', 'LOR', 'LAND', 'LNOT', 'LT', 'LE', 'GT', 'GE', 'EQ', 'NE', # Assignment 'EQUALS', 'TIMESEQUAL', 'DIVEQUAL', 'MODEQUAL', 'PLUSEQUAL', 'MINUSEQUAL', 'LSHIFTEQUAL','RSHIFTEQUAL', 'ANDEQUAL', 'XOREQUAL', 'OREQUAL', # Increment/decrement 'PLUSPLUS', 'MINUSMINUS', # Structure dereference (->) 'ARROW', # Conditional operator (?) 'CONDOP', # Delimeters 'LPAREN', 'RPAREN', # ( ) 'LBRACKET', 'RBRACKET', # [ ] 'LBRACE', 'RBRACE', # { } 'COMMA', 'PERIOD', # . , 'SEMI', 'COLON', # ; : # Ellipsis (...) 'ELLIPSIS', # pre-processor 'PPHASH', # '#' ) ## ## Regexes for use in tokens ## ## # valid C identifiers (K&R2: A.2.3), plus '$' (supported by some compilers) identifier = r'[a-zA-Z_$][0-9a-zA-Z_$]*' hex_prefix = '0[xX]' hex_digits = '[0-9a-fA-F]+' bin_prefix = '0[bB]' bin_digits = '[01]+' # integer constants (K&R2: A.2.5.1) integer_suffix_opt = r'(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?' decimal_constant = '(0'+integer_suffix_opt+')|([1-9][0-9]*'+integer_suffix_opt+')' octal_constant = '0[0-7]*'+integer_suffix_opt hex_constant = hex_prefix+hex_digits+integer_suffix_opt bin_constant = bin_prefix+bin_digits+integer_suffix_opt bad_octal_constant = '0[0-7]*[89]' # character constants (K&R2: A.2.5.2) # Note: a-zA-Z and '.-~^_!=&;,' are allowed as escape chars to support #line # directives with Windows paths as filenames (..\..\dir\file) # For the same reason, decimal_escape allows all digit sequences. We want to # parse all correct code, even if it means to sometimes parse incorrect # code. # simple_escape = r"""([a-zA-Z._~!=&\^\-\\?'"])""" decimal_escape = r"""(\d+)""" hex_escape = r"""(x[0-9a-fA-F]+)""" bad_escape = r"""([\\][^a-zA-Z._~^!=&\^\-\\?'"x0-7])""" escape_sequence = r"""(\\("""+simple_escape+'|'+decimal_escape+'|'+hex_escape+'))' cconst_char = r"""([^'\\\n]|"""+escape_sequence+')' char_const = "'"+cconst_char+"'" wchar_const = 'L'+char_const unmatched_quote = "('"+cconst_char+"*\\n)|('"+cconst_char+"*$)" bad_char_const = r"""('"""+cconst_char+"""[^'\n]+')|('')|('"""+bad_escape+r"""[^'\n]*')""" # string literals (K&R2: A.2.6) string_char = r"""([^"\\\n]|"""+escape_sequence+')' string_literal = '"'+string_char+'*"' wstring_literal = 'L'+string_literal bad_string_literal = '"'+string_char+'*'+bad_escape+string_char+'*"' # floating constants (K&R2: A.2.5.3) exponent_part = r"""([eE][-+]?[0-9]+)""" fractional_constant = r"""([0-9]*\.[0-9]+)|([0-9]+\.)""" floating_constant = '(((('+fractional_constant+')'+exponent_part+'?)|([0-9]+'+exponent_part+'))[FfLl]?)' binary_exponent_part = r'''([pP][+-]?[0-9]+)''' hex_fractional_constant = '((('+hex_digits+r""")?\."""+hex_digits+')|('+hex_digits+r"""\.))""" hex_floating_constant = '('+hex_prefix+'('+hex_digits+'|'+hex_fractional_constant+')'+binary_exponent_part+'[FfLl]?)' ## ## Lexer states: used for preprocessor \n-terminated directives ## states = ( # ppline: preprocessor line directives # ('ppline', 'exclusive'), # pppragma: pragma # ('pppragma', 'exclusive'), ) def t_PPHASH(self, t): r'[ \t]*\#' if self.line_pattern.match(t.lexer.lexdata, pos=t.lexer.lexpos): t.lexer.begin('ppline') self.pp_line = self.pp_filename = None elif self.pragma_pattern.match(t.lexer.lexdata, pos=t.lexer.lexpos): t.lexer.begin('pppragma') else: t.type = 'PPHASH' return t ## ## Rules for the ppline state ## @TOKEN(string_literal) def t_ppline_FILENAME(self, t): if self.pp_line is None: self._error('filename before line number in #line', t) else: self.pp_filename = t.value.lstrip('"').rstrip('"') @TOKEN(decimal_constant) def t_ppline_LINE_NUMBER(self, t): if self.pp_line is None: self.pp_line = t.value else: # Ignore: GCC's cpp sometimes inserts a numeric flag # after the file name pass def t_ppline_NEWLINE(self, t): r'\n' if self.pp_line is None: self._error('line number missing in #line', t) else: self.lexer.lineno = int(self.pp_line) if self.pp_filename is not None: self.filename = self.pp_filename t.lexer.begin('INITIAL') def t_ppline_PPLINE(self, t): r'line' pass t_ppline_ignore = ' \t' def t_ppline_error(self, t): self._error('invalid #line directive', t) ## ## Rules for the pppragma state ## def t_pppragma_NEWLINE(self, t): r'\n' t.lexer.lineno += 1 t.lexer.begin('INITIAL') def t_pppragma_PPPRAGMA(self, t): r'pragma' pass t_pppragma_ignore = ' \t<>.-{}();=+-*/$%@&^~!?:,0123456789' @TOKEN(string_literal) def t_pppragma_STR(self, t): pass @TOKEN(identifier) def t_pppragma_ID(self, t): pass def t_pppragma_error(self, t): self._error('invalid #pragma directive', t) ## ## Rules for the normal state ## t_ignore = ' \t' # Newlines def t_NEWLINE(self, t): r'\n+' t.lexer.lineno += t.value.count("\n") # Operators t_PLUS = r'\+' t_MINUS = r'-' t_TIMES = r'\*' t_DIVIDE = r'/' t_MOD = r'%' t_OR = r'\|' t_AND = r'&' t_NOT = r'~' t_XOR = r'\^' t_LSHIFT = r'<<' t_RSHIFT = r'>>' t_LOR = r'\|\|' t_LAND = r'&&' t_LNOT = r'!' t_LT = r'<' t_GT = r'>' t_LE = r'<=' t_GE = r'>=' t_EQ = r'==' t_NE = r'!=' # Assignment operators t_EQUALS = r'=' t_TIMESEQUAL = r'\*=' t_DIVEQUAL = r'/=' t_MODEQUAL = r'%=' t_PLUSEQUAL = r'\+=' t_MINUSEQUAL = r'-=' t_LSHIFTEQUAL = r'<<=' t_RSHIFTEQUAL = r'>>=' t_ANDEQUAL = r'&=' t_OREQUAL = r'\|=' t_XOREQUAL = r'\^=' # Increment/decrement t_PLUSPLUS = r'\+\+' t_MINUSMINUS = r'--' # -> t_ARROW = r'->' # ? t_CONDOP = r'\?' # Delimeters t_LPAREN = r'\(' t_RPAREN = r'\)' t_LBRACKET = r'\[' t_RBRACKET = r'\]' t_COMMA = r',' t_PERIOD = r'\.' t_SEMI = r';' t_COLON = r':' t_ELLIPSIS = r'\.\.\.' # Scope delimiters # To see why on_lbrace_func is needed, consider: # typedef char TT; # void foo(int TT) { TT = 10; } # TT x = 5; # Outside the function, TT is a typedef, but inside (starting and ending # with the braces) it's a parameter. The trouble begins with yacc's # lookahead token. If we open a new scope in brace_open, then TT has # already been read and incorrectly interpreted as TYPEID. So, we need # to open and close scopes from within the lexer. # Similar for the TT immediately outside the end of the function. # @TOKEN(r'\{') def t_LBRACE(self, t): self.on_lbrace_func() return t @TOKEN(r'\}') def t_RBRACE(self, t): self.on_rbrace_func() return t t_STRING_LITERAL = string_literal # The following floating and integer constants are defined as # functions to impose a strict order (otherwise, decimal # is placed before the others because its regex is longer, # and this is bad) # @TOKEN(floating_constant) def t_FLOAT_CONST(self, t): return t @TOKEN(hex_floating_constant) def t_HEX_FLOAT_CONST(self, t): return t @TOKEN(hex_constant) def t_INT_CONST_HEX(self, t): return t @TOKEN(bin_constant) def t_INT_CONST_BIN(self, t): return t @TOKEN(bad_octal_constant) def t_BAD_CONST_OCT(self, t): msg = "Invalid octal constant" self._error(msg, t) @TOKEN(octal_constant) def t_INT_CONST_OCT(self, t): return t @TOKEN(decimal_constant) def t_INT_CONST_DEC(self, t): return t # Must come before bad_char_const, to prevent it from # catching valid char constants as invalid # @TOKEN(char_const) def t_CHAR_CONST(self, t): return t @TOKEN(wchar_const) def t_WCHAR_CONST(self, t): return t @TOKEN(unmatched_quote) def t_UNMATCHED_QUOTE(self, t): msg = "Unmatched '" self._error(msg, t) @TOKEN(bad_char_const) def t_BAD_CHAR_CONST(self, t): msg = "Invalid char constant %s" % t.value self._error(msg, t) @TOKEN(wstring_literal) def t_WSTRING_LITERAL(self, t): return t # unmatched string literals are caught by the preprocessor @TOKEN(bad_string_literal) def t_BAD_STRING_LITERAL(self, t): msg = "String contains invalid escape code" self._error(msg, t) @TOKEN(identifier) def t_ID(self, t): t.type = self.keyword_map.get(t.value, "ID") if t.type == 'ID' and self.type_lookup_func(t.value): t.type = "TYPEID" return t def t_error(self, t): msg = 'Illegal character %s' % repr(t.value[0]) self._error(msg, t) pycparser-2.14/pycparser/plyparser.py0000644000175000017500000000307212523673315020602 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # plyparser.py # # PLYParser class and other utilites for simplifying programming # parsers with PLY # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- class Coord(object): """ Coordinates of a syntactic element. Consists of: - File name - Line number - (optional) column number, for the Lexer """ __slots__ = ('file', 'line', 'column', '__weakref__') def __init__(self, file, line, column=None): self.file = file self.line = line self.column = column def __str__(self): str = "%s:%s" % (self.file, self.line) if self.column: str += ":%s" % self.column return str class ParseError(Exception): pass class PLYParser(object): def _create_opt_rule(self, rulename): """ Given a rule name, creates an optional ply.yacc rule for it. The name of the optional rule is _opt """ optname = rulename + '_opt' def optrule(self, p): p[0] = p[1] optrule.__doc__ = '%s : empty\n| %s' % (optname, rulename) optrule.__name__ = 'p_%s' % optname setattr(self.__class__, optrule.__name__, optrule) def _coord(self, lineno, column=None): return Coord( file=self.clex.filename, line=lineno, column=column) def _parse_error(self, msg, coord): raise ParseError("%s: %s" % (coord, msg)) pycparser-2.14/pycparser/yacctab.py0000664000175000017500000037504012524375070020176 0ustar elibeneliben00000000000000 # yacctab.py # This file is automatically generated. Do not edit. _tabversion = '3.2' _lr_method = 'LALR' _lr_signature = '\x11\x82\x05\xfb:\x10\xfeo5\xb4\x11N\xe7S\xb4b' _lr_action_items = {'VOID':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[6,6,-63,-74,-73,-60,-56,-57,-35,-31,-61,6,-36,-55,-70,-65,-54,6,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,6,-69,6,-72,-76,6,-59,-86,-261,-85,6,-113,-112,-32,-102,-101,6,6,6,-47,-48,6,-115,6,6,6,6,-92,6,6,6,6,-38,6,-49,6,6,-87,-93,-262,-103,-121,-120,6,6,6,6,6,-39,-41,-44,-40,-42,6,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,6,-175,-174,6,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'LBRACKET':([1,2,3,5,6,9,10,13,14,17,18,19,21,23,25,26,27,28,29,30,32,33,35,37,39,40,42,43,44,45,46,49,50,51,52,54,55,56,58,60,62,63,67,68,69,70,74,78,81,83,84,86,90,94,96,97,110,112,115,116,118,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,153,155,166,167,174,176,177,178,179,180,191,197,198,218,221,222,224,228,235,239,262,267,269,270,300,302,303,310,311,314,315,323,324,325,326,329,334,338,339,360,362,364,366,367,368,388,389,391,392,399,401,428,429,430,437,],[-263,-63,-74,-73,-60,-56,-57,-61,-263,-55,-70,-65,-54,-58,-178,65,-68,-263,-71,72,-75,-114,-66,-62,-64,-67,-263,-69,-263,-72,-76,-59,-52,-9,-10,-86,-261,-85,-51,65,-102,-101,-28,-122,-124,-27,72,72,164,-50,-53,72,-115,-263,-263,72,72,-248,-125,-123,-252,-243,-255,-259,-256,-253,-241,-242,226,-251,-228,-257,-249,-240,-254,-250,164,264,72,72,-87,-262,-23,-84,-24,-83,-103,-121,-120,-260,-258,-237,-236,-150,-152,72,-140,264,-154,-148,-248,-89,-88,-105,-104,-116,-119,-235,-234,-233,-232,-231,-244,72,72,-143,264,-141,-149,-151,-153,-118,-117,-229,-230,264,-142,-245,264,-238,-239,]),'WCHAR_CONST':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,124,124,-47,124,-28,-263,-125,-227,124,-225,124,-224,124,-223,124,124,-222,-226,-263,-223,124,124,124,-262,124,124,-223,124,124,-184,-187,-185,-181,-182,-186,-188,124,-190,-191,-183,-189,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,-12,124,124,-11,-223,-41,-44,-40,124,-42,124,124,-156,-155,-45,-157,124,-43,124,124,124,-263,-139,-175,-174,124,-172,124,124,-158,124,-171,-159,124,124,124,124,-263,124,124,-11,-170,-173,124,-162,124,-160,124,124,-161,124,124,124,-263,124,-166,-165,-163,124,124,124,-167,-164,124,-169,-168,]),'FLOAT_CONST':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,125,125,-47,125,-28,-263,-125,-227,125,-225,125,-224,125,-223,125,125,-222,-226,-263,-223,125,125,125,-262,125,125,-223,125,125,-184,-187,-185,-181,-182,-186,-188,125,-190,-191,-183,-189,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,-12,125,125,-11,-223,-41,-44,-40,125,-42,125,125,-156,-155,-45,-157,125,-43,125,125,125,-263,-139,-175,-174,125,-172,125,125,-158,125,-171,-159,125,125,125,125,-263,125,125,-11,-170,-173,125,-162,125,-160,125,125,-161,125,125,125,-263,125,-166,-165,-163,125,125,125,-167,-164,125,-169,-168,]),'MINUS':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,112,115,118,119,120,121,122,123,124,125,126,127,128,129,130,132,134,135,137,138,139,140,141,142,143,144,145,146,147,148,149,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,224,226,227,230,231,232,233,234,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,300,309,323,324,325,326,329,334,335,336,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,362,365,370,371,373,374,375,376,379,380,381,383,384,385,390,391,392,393,395,398,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,428,429,430,432,433,434,436,437,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,128,128,-47,128,-28,-263,-248,-125,-252,-227,-214,-243,-255,-259,-256,-253,-241,128,-225,-242,-216,-195,128,-224,128,-251,-223,-228,128,128,-257,-222,-249,-240,244,-254,-250,-226,-263,-223,128,128,128,-262,128,128,-223,128,128,-184,-187,-185,-181,-182,-186,-188,128,-190,-191,-183,-189,-260,128,-220,-258,-237,-236,128,128,128,-214,-219,128,-217,-218,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,-12,128,128,-11,-223,-41,-44,-40,128,-42,128,128,-156,-155,-45,-157,128,-43,-248,128,-235,-234,-233,-232,-231,-244,128,128,244,244,244,-200,244,244,244,-199,244,244,-197,-196,244,244,244,244,244,-198,-263,-139,-175,-174,128,-172,128,128,-158,128,-171,-159,128,128,-221,-229,-230,128,128,-215,-263,128,128,-11,-170,-173,128,-162,128,-160,128,128,-161,128,128,128,-245,-263,-238,128,-166,-165,-163,-239,128,128,128,-167,-164,128,-169,-168,]),'RPAREN':([1,2,3,5,6,9,10,13,14,17,18,19,21,23,25,26,27,28,29,32,33,35,37,39,40,42,43,44,45,46,49,50,51,52,53,54,56,58,59,60,62,63,66,67,68,69,70,74,78,81,83,84,90,94,96,106,107,108,109,110,111,112,113,114,115,116,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,151,153,158,159,160,161,165,166,167,174,176,177,178,179,180,191,197,198,199,200,201,202,218,220,221,222,224,227,228,231,232,234,235,236,237,238,239,240,269,270,275,285,302,303,310,311,314,315,318,319,320,321,322,323,324,325,326,328,329,330,332,333,334,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,366,367,368,378,388,389,390,391,392,397,398,410,412,415,416,417,419,428,430,432,435,437,438,439,442,],[-263,-63,-74,-73,-60,-56,-57,-61,-263,-55,-70,-65,-54,-58,-178,-111,-68,-263,-71,-75,-114,-66,-62,-64,-67,-263,-69,-263,-72,-76,-59,-52,-9,-10,90,-86,-85,-51,-113,-112,-102,-101,-263,-28,-122,-124,-27,-145,-263,-147,-50,-53,-115,-263,-263,197,-15,198,-128,-263,-16,-248,-126,-132,-125,-123,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,-193,-254,-250,-179,-146,-21,-22,269,270,-263,-145,-263,-87,-262,-23,-84,-24,-83,-103,-121,-120,-131,-1,-2,-130,-260,-220,-258,-237,-236,329,-150,-214,-219,-217,-152,334,336,-176,-263,-218,-154,-148,368,-14,-89,-88,-105,-104,-116,-119,-133,-127,-129,-180,390,-235,-234,-233,-232,-246,-231,392,395,396,-244,-144,-263,-145,-201,-213,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,-212,-207,-209,-210,-198,-149,-151,-153,-13,-118,-117,-221,-229,-230,-177,-215,423,425,427,-247,428,-194,-245,-238,-263,440,-239,-263,443,446,]),'LONG':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[19,19,-63,-74,-73,-60,-56,-57,-35,-31,-61,19,-36,-55,-70,-65,-54,19,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,19,-69,19,-72,-76,19,-59,-86,-261,-85,19,-113,-112,-32,-102,-101,19,19,19,-47,-48,19,-115,19,19,19,19,-92,19,19,19,19,-38,19,-49,19,19,-87,-93,-262,-103,-121,-120,19,19,19,19,19,-39,-41,-44,-40,-42,19,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,19,-175,-174,19,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'PLUS':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,112,115,118,119,120,121,122,123,124,125,126,127,128,129,130,132,134,135,137,138,139,140,141,142,143,144,145,146,147,148,149,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,224,226,227,230,231,232,233,234,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,300,309,323,324,325,326,329,334,335,336,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,362,365,370,371,373,374,375,376,379,380,381,383,384,385,390,391,392,393,395,398,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,428,429,430,432,433,434,436,437,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,135,135,-47,135,-28,-263,-248,-125,-252,-227,-214,-243,-255,-259,-256,-253,-241,135,-225,-242,-216,-195,135,-224,135,-251,-223,-228,135,135,-257,-222,-249,-240,248,-254,-250,-226,-263,-223,135,135,135,-262,135,135,-223,135,135,-184,-187,-185,-181,-182,-186,-188,135,-190,-191,-183,-189,-260,135,-220,-258,-237,-236,135,135,135,-214,-219,135,-217,-218,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,-12,135,135,-11,-223,-41,-44,-40,135,-42,135,135,-156,-155,-45,-157,135,-43,-248,135,-235,-234,-233,-232,-231,-244,135,135,248,248,248,-200,248,248,248,-199,248,248,-197,-196,248,248,248,248,248,-198,-263,-139,-175,-174,135,-172,135,135,-158,135,-171,-159,135,135,-221,-229,-230,135,135,-215,-263,135,135,-11,-170,-173,135,-162,135,-160,135,135,-161,135,135,135,-245,-263,-238,135,-166,-165,-163,-239,135,135,135,-167,-164,135,-169,-168,]),'ELLIPSIS':([204,],[319,]),'GT':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,249,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,249,-202,-200,-204,249,-203,-199,-206,249,-197,-196,-205,249,249,249,249,-198,-221,-229,-230,-215,-245,-238,-239,]),'GOTO':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,278,-262,-41,-44,-40,-42,278,-156,-155,-45,-157,278,-43,-175,-174,-172,278,-158,-171,-159,278,-170,-173,-162,278,-160,278,-161,278,278,-166,-165,-163,278,278,-167,-164,278,-169,-168,]),'ENUM':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[24,24,-63,-74,-73,-60,-56,-57,-35,-31,-61,24,-36,-55,-70,-65,-54,24,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,24,-69,24,-72,-76,24,-59,-86,-261,-85,24,-113,-112,-32,-102,-101,24,24,24,-47,-48,24,-115,24,24,24,24,-92,24,24,24,24,-38,24,-49,24,24,-87,-93,-262,-103,-121,-120,24,24,24,24,24,-39,-41,-44,-40,-42,24,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,24,-175,-174,24,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'PERIOD':([55,112,118,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,155,176,218,221,222,224,262,267,300,323,324,325,326,329,334,360,362,364,391,392,399,401,428,429,430,437,],[-261,-248,-252,-243,-255,-259,-256,-253,-241,-242,225,-251,-228,-257,-249,-240,-254,-250,263,-262,-260,-258,-237,-236,-140,263,-248,-235,-234,-233,-232,-231,-244,-143,263,-141,-229,-230,263,-142,-245,263,-238,-239,]),'GE':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,253,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,253,-202,-200,-204,253,-203,-199,-206,253,-197,-196,-205,253,253,253,253,-198,-221,-229,-230,-215,-245,-238,-239,]),'INT_CONST_DEC':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,145,145,-47,145,-28,-263,-125,-227,145,-225,145,-224,145,-223,145,145,-222,-226,-263,-223,145,145,145,-262,145,145,-223,145,145,-184,-187,-185,-181,-182,-186,-188,145,-190,-191,-183,-189,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,-12,145,145,-11,-223,-41,-44,-40,145,-42,145,145,-156,-155,-45,-157,145,-43,145,145,145,-263,-139,-175,-174,145,-172,145,145,-158,145,-171,-159,145,145,145,145,-263,145,145,-11,-170,-173,145,-162,145,-160,145,145,-161,145,145,145,-263,145,-166,-165,-163,145,145,145,-167,-164,145,-169,-168,]),'ARROW':([112,118,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,221,222,224,300,323,324,325,326,329,334,391,392,428,430,437,],[-248,-252,-243,-255,-259,-256,-253,-241,-242,223,-251,-228,-257,-249,-240,-254,-250,-262,-260,-258,-237,-236,-248,-235,-234,-233,-232,-231,-244,-229,-230,-245,-238,-239,]),'HEX_FLOAT_CONST':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,148,148,-47,148,-28,-263,-125,-227,148,-225,148,-224,148,-223,148,148,-222,-226,-263,-223,148,148,148,-262,148,148,-223,148,148,-184,-187,-185,-181,-182,-186,-188,148,-190,-191,-183,-189,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,-12,148,148,-11,-223,-41,-44,-40,148,-42,148,148,-156,-155,-45,-157,148,-43,148,148,148,-263,-139,-175,-174,148,-172,148,148,-158,148,-171,-159,148,148,148,148,-263,148,148,-11,-170,-173,148,-162,148,-160,148,148,-161,148,148,148,-263,148,-166,-165,-163,148,148,148,-167,-164,148,-169,-168,]),'DOUBLE':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[40,40,-63,-74,-73,-60,-56,-57,-35,-31,-61,40,-36,-55,-70,-65,-54,40,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,40,-69,40,-72,-76,40,-59,-86,-261,-85,40,-113,-112,-32,-102,-101,40,40,40,-47,-48,40,-115,40,40,40,40,-92,40,40,40,40,-38,40,-49,40,40,-87,-93,-262,-103,-121,-120,40,40,40,40,40,-39,-41,-44,-40,-42,40,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,40,-175,-174,40,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'MINUSEQUAL':([112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,390,391,392,398,428,430,437,],[-248,-252,207,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-221,-229,-230,-215,-245,-238,-239,]),'INT_CONST_OCT':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,149,149,-47,149,-28,-263,-125,-227,149,-225,149,-224,149,-223,149,149,-222,-226,-263,-223,149,149,149,-262,149,149,-223,149,149,-184,-187,-185,-181,-182,-186,-188,149,-190,-191,-183,-189,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,-12,149,149,-11,-223,-41,-44,-40,149,-42,149,149,-156,-155,-45,-157,149,-43,149,149,149,-263,-139,-175,-174,149,-172,149,149,-158,149,-171,-159,149,149,149,149,-263,149,149,-11,-170,-173,149,-162,149,-160,149,149,-161,149,149,149,-263,149,-166,-165,-163,149,149,149,-167,-164,149,-169,-168,]),'TIMESEQUAL':([112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,390,391,392,398,428,430,437,],[-248,-252,216,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-221,-229,-230,-215,-245,-238,-239,]),'OR':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,258,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,258,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,258,-207,-209,-210,-198,-221,-229,-230,-215,-245,-238,-239,]),'SHORT':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[2,2,-63,-74,-73,-60,-56,-57,-35,-31,-61,2,-36,-55,-70,-65,-54,2,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,2,-69,2,-72,-76,2,-59,-86,-261,-85,2,-113,-112,-32,-102,-101,2,2,2,-47,-48,2,-115,2,2,2,2,-92,2,2,2,2,-38,2,-49,2,2,-87,-93,-262,-103,-121,-120,2,2,2,2,2,-39,-41,-44,-40,-42,2,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,2,-175,-174,2,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'RETURN':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,281,-262,-41,-44,-40,-42,281,-156,-155,-45,-157,281,-43,-175,-174,-172,281,-158,-171,-159,281,-170,-173,-162,281,-160,281,-161,281,281,-166,-165,-163,281,281,-167,-164,281,-169,-168,]),'RSHIFTEQUAL':([112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,390,391,392,398,428,430,437,],[-248,-252,217,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-221,-229,-230,-215,-245,-238,-239,]),'RESTRICT':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,28,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,65,66,67,69,78,80,82,87,89,90,91,92,93,94,95,96,104,105,115,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[32,32,-63,-74,-73,-60,-56,-57,-35,-31,-61,32,-36,-55,-70,-65,-54,32,-58,-178,-111,-68,32,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,32,-69,32,-72,-76,32,-59,-86,-261,-85,32,-113,-112,-32,-102,-101,32,32,32,-124,32,32,-47,-48,32,-115,32,32,32,32,-92,32,32,32,-125,32,32,32,-38,32,-49,32,32,-87,-93,-262,-103,-121,-120,32,32,32,32,32,-39,-41,-44,-40,-42,32,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,32,-175,-174,32,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'STATIC':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,59,60,61,62,63,65,66,69,78,80,82,87,89,90,104,115,165,167,169,170,171,174,176,191,197,198,204,272,276,277,280,282,289,291,292,293,295,298,302,303,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[9,9,-63,-74,-73,-60,-56,-57,-35,-31,-61,9,-36,-55,-70,-65,-54,9,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,9,-69,9,-72,-76,9,-59,-86,-261,-85,-113,-112,-32,-102,-101,105,9,-124,9,9,-47,-48,9,-115,195,-125,9,9,-38,9,-49,-87,-262,-103,-121,-120,9,-39,-41,-44,-40,-42,9,-156,-155,-45,-157,-43,-89,-88,-105,-104,-116,-119,9,-175,-174,9,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'SIZEOF':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,127,127,-47,127,-28,-263,-125,-227,127,-225,127,-224,127,-223,127,127,-222,-226,-263,-223,127,127,127,-262,127,127,-223,127,127,-184,-187,-185,-181,-182,-186,-188,127,-190,-191,-183,-189,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,-12,127,127,-11,-223,-41,-44,-40,127,-42,127,127,-156,-155,-45,-157,127,-43,127,127,127,-263,-139,-175,-174,127,-172,127,127,-158,127,-171,-159,127,127,127,127,-263,127,127,-11,-170,-173,127,-162,127,-160,127,127,-161,127,127,127,-263,127,-166,-165,-163,127,127,127,-167,-164,127,-169,-168,]),'UNSIGNED':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[18,18,-63,-74,-73,-60,-56,-57,-35,-31,-61,18,-36,-55,-70,-65,-54,18,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,18,-69,18,-72,-76,18,-59,-86,-261,-85,18,-113,-112,-32,-102,-101,18,18,18,-47,-48,18,-115,18,18,18,18,-92,18,18,18,18,-38,18,-49,18,18,-87,-93,-262,-103,-121,-120,18,18,18,18,18,-39,-41,-44,-40,-42,18,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,18,-175,-174,18,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'UNION':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[20,20,-63,-74,-73,-60,-56,-57,-35,-31,-61,20,-36,-55,-70,-65,-54,20,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,20,-69,20,-72,-76,20,-59,-86,-261,-85,20,-113,-112,-32,-102,-101,20,20,20,-47,-48,20,-115,20,20,20,20,-92,20,20,20,20,-38,20,-49,20,20,-87,-93,-262,-103,-121,-120,20,20,20,20,20,-39,-41,-44,-40,-42,20,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,20,-175,-174,20,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'COLON':([2,3,5,6,13,18,19,25,26,27,29,32,33,35,37,39,40,43,45,46,54,56,59,60,62,63,90,94,96,97,112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,151,174,176,177,178,179,180,187,191,197,198,218,220,221,222,224,231,232,234,238,240,286,300,302,303,305,306,310,311,314,315,321,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,377,388,389,390,391,392,397,398,419,428,430,437,],[-63,-74,-73,-60,-61,-70,-65,-178,-111,-68,-71,-75,-114,-66,-62,-64,-67,-69,-72,-76,-86,-85,-113,-112,-102,-101,-115,-263,-263,181,-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,-193,-254,-250,-179,-87,-262,-23,-84,-24,-83,309,-103,-121,-120,-260,-220,-258,-237,-236,-214,-219,-217,-176,-218,375,384,-89,-88,-192,181,-105,-104,-116,-119,-180,-235,-234,-233,-232,-231,-244,-201,-213,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,-212,-207,-209,400,-210,-198,411,-118,-117,-221,-229,-230,-177,-215,-194,-245,-238,-239,]),'$end':([0,8,11,12,15,22,31,36,38,47,61,82,169,176,272,383,],[-263,0,-35,-31,-36,-29,-34,-33,-37,-30,-32,-47,-38,-262,-39,-159,]),'WSTRING_LITERAL':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,121,123,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,218,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,123,123,-47,123,-28,-263,-125,-227,218,-259,123,-225,123,-224,123,-223,123,123,-222,-226,-263,-223,123,123,123,-262,123,123,-223,123,123,-184,-187,-185,-181,-182,-186,-188,123,-190,-191,-183,-189,-260,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,-12,123,123,-11,-223,-41,-44,-40,123,-42,123,123,-156,-155,-45,-157,123,-43,123,123,123,-263,-139,-175,-174,123,-172,123,123,-158,123,-171,-159,123,123,123,123,-263,123,123,-11,-170,-173,123,-162,123,-160,123,123,-161,123,123,123,-263,123,-166,-165,-163,123,123,123,-167,-164,123,-169,-168,]),'DIVIDE':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,251,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,251,251,251,251,251,251,251,251,251,251,-197,-196,251,251,251,251,251,-198,-221,-229,-230,-215,-245,-238,-239,]),'FOR':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,283,-262,-41,-44,-40,-42,283,-156,-155,-45,-157,283,-43,-175,-174,-172,283,-158,-171,-159,283,-170,-173,-162,283,-160,283,-161,283,283,-166,-165,-163,283,283,-167,-164,283,-169,-168,]),'PLUSPLUS':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,112,115,118,119,121,122,123,124,125,126,127,128,129,130,134,135,137,138,139,140,141,142,143,144,145,146,148,149,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,218,219,221,222,224,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,300,309,323,324,325,326,329,334,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,391,392,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,428,429,430,432,433,434,436,437,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,137,137,-47,137,-28,-263,-248,-125,-252,-227,-243,-255,-259,-256,-253,-241,137,-225,-242,224,137,-224,137,-251,-223,-228,137,137,-257,-222,-249,-240,-254,-250,-226,-263,-223,137,137,137,-262,137,137,-223,137,137,-184,-187,-185,-181,-182,-186,-188,137,-190,-191,-183,-189,-260,137,-258,-237,-236,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,-12,137,137,-11,-223,-41,-44,-40,137,-42,137,137,-156,-155,-45,-157,137,-43,-248,137,-235,-234,-233,-232,-231,-244,137,137,-263,-139,-175,-174,137,-172,137,137,-158,137,-171,-159,137,137,-229,-230,137,137,-263,137,137,-11,-170,-173,137,-162,137,-160,137,137,-161,137,137,137,-245,-263,-238,137,-166,-165,-163,-239,137,137,137,-167,-164,137,-169,-168,]),'EQUALS':([1,2,3,5,6,9,10,13,14,17,18,19,21,23,25,26,27,29,30,32,33,35,37,39,40,42,43,44,45,46,49,50,51,52,54,56,58,59,60,62,63,80,83,84,86,90,102,112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,168,174,176,191,197,198,218,220,221,222,224,231,232,234,240,262,267,300,302,303,310,311,314,315,323,324,325,326,329,334,360,364,388,389,390,391,392,398,401,428,430,437,],[-263,-63,-74,-73,-60,-56,-57,-61,-263,-55,-70,-65,-54,-58,-178,-111,-68,-71,77,-75,-114,-66,-62,-64,-67,-263,-69,-263,-72,-76,-59,-52,-9,-10,-86,-85,-51,-113,-112,-102,-101,162,-50,-53,77,-115,192,-248,-252,209,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,162,-87,-262,-103,-121,-120,-260,-220,-258,-237,-236,-214,-219,-217,-218,-140,365,-248,-89,-88,-105,-104,-116,-119,-235,-234,-233,-232,-231,-244,-143,-141,-118,-117,-221,-229,-230,-215,-142,-245,-238,-239,]),'ELSE':([176,276,277,280,282,293,298,370,371,374,381,383,405,406,409,414,424,433,434,436,444,445,447,448,],[-262,-41,-44,-40,-42,-45,-43,-175,-174,-172,-171,-159,-170,-173,-162,-160,-161,-166,-165,441,-167,-164,-169,-168,]),'ANDEQUAL':([112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,390,391,392,398,428,430,437,],[-248,-252,214,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-221,-229,-230,-215,-245,-238,-239,]),'EQ':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,255,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,255,-202,-200,-204,-208,-203,-199,-206,255,-197,-196,-205,255,-207,255,255,-198,-221,-229,-230,-215,-245,-238,-239,]),'AND':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,112,115,118,119,120,121,122,123,124,125,126,127,128,129,130,132,134,135,137,138,139,140,141,142,143,144,145,146,147,148,149,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,224,226,227,230,231,232,233,234,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,300,309,323,324,325,326,329,334,335,336,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,362,365,370,371,373,374,375,376,379,380,381,383,384,385,390,391,392,393,395,398,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,428,429,430,432,433,434,436,437,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,144,144,-47,144,-28,-263,-248,-125,-252,-227,-214,-243,-255,-259,-256,-253,-241,144,-225,-242,-216,-195,144,-224,144,-251,-223,-228,144,144,-257,-222,-249,-240,256,-254,-250,-226,-263,-223,144,144,144,-262,144,144,-223,144,144,-184,-187,-185,-181,-182,-186,-188,144,-190,-191,-183,-189,-260,144,-220,-258,-237,-236,144,144,144,-214,-219,144,-217,-218,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,-12,144,144,-11,-223,-41,-44,-40,144,-42,144,144,-156,-155,-45,-157,144,-43,-248,144,-235,-234,-233,-232,-231,-244,144,144,-201,256,-202,-200,-204,-208,-203,-199,-206,256,-197,-196,-205,256,-207,-209,256,-198,-263,-139,-175,-174,144,-172,144,144,-158,144,-171,-159,144,144,-221,-229,-230,144,144,-215,-263,144,144,-11,-170,-173,144,-162,144,-160,144,144,-161,144,144,144,-245,-263,-238,144,-166,-165,-163,-239,144,144,144,-167,-164,144,-169,-168,]),'TYPEID':([0,1,2,3,5,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,31,32,33,34,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,67,68,69,70,74,78,80,82,87,89,90,91,92,93,94,95,96,115,116,141,165,166,167,169,170,171,172,173,174,175,176,191,197,198,204,219,223,225,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[25,25,-63,-74,-73,-60,54,-56,-57,-35,-31,-61,25,-36,59,-55,-70,-65,-91,-54,25,-58,62,-178,-111,-68,-263,-71,-34,-75,-114,-90,-66,-33,-62,-37,-64,-67,25,-69,25,-72,-76,25,-59,-86,-261,-85,25,-113,-112,-32,-102,-101,25,-28,-122,-124,-27,59,25,25,-47,-48,25,-115,25,25,25,25,-92,25,-125,-123,25,25,59,25,-38,25,-49,25,25,-87,-93,-262,-103,-121,-120,25,25,323,325,25,25,25,-39,-41,-44,-40,-42,25,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,25,-175,-174,25,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'LBRACE':([7,20,24,26,33,34,48,54,55,56,59,60,62,63,77,80,82,85,87,88,89,90,155,162,163,170,171,176,197,198,260,266,268,276,277,280,282,289,291,292,293,295,297,298,314,315,336,362,365,370,371,374,375,379,381,383,384,388,389,390,395,396,399,402,403,405,406,409,411,414,423,424,425,427,429,433,434,436,441,443,444,445,446,447,448,],[55,-91,55,-111,-114,-90,-263,55,-261,55,-113,-112,55,55,55,-263,-47,-7,-48,55,-8,-115,-263,55,55,55,-49,-262,-121,-120,-12,55,-11,-41,-44,-40,-42,55,-156,-155,-45,-157,55,-43,-116,-119,55,-263,-139,-175,-174,-172,55,-158,-171,-159,55,-118,-117,55,55,55,-263,55,-11,-170,-173,-162,55,-160,55,-161,55,55,-263,-166,-165,-163,55,55,-167,-164,55,-169,-168,]),'PPHASH':([0,11,12,15,22,31,36,38,61,82,169,176,272,383,],[38,-35,-31,-36,38,-34,-33,-37,-32,-47,-38,-262,-39,-159,]),'INT':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[39,39,-63,-74,-73,-60,-56,-57,-35,-31,-61,39,-36,-55,-70,-65,-54,39,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,39,-69,39,-72,-76,39,-59,-86,-261,-85,39,-113,-112,-32,-102,-101,39,39,39,-47,-48,39,-115,39,39,39,39,-92,39,39,39,39,-38,39,-49,39,39,-87,-93,-262,-103,-121,-120,39,39,39,39,39,-39,-41,-44,-40,-42,39,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,39,-175,-174,39,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'SIGNED':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[43,43,-63,-74,-73,-60,-56,-57,-35,-31,-61,43,-36,-55,-70,-65,-54,43,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,43,-69,43,-72,-76,43,-59,-86,-261,-85,43,-113,-112,-32,-102,-101,43,43,43,-47,-48,43,-115,43,43,43,43,-92,43,43,43,43,-38,43,-49,43,43,-87,-93,-262,-103,-121,-120,43,43,43,43,43,-39,-41,-44,-40,-42,43,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,43,-175,-174,43,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'CONTINUE':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,284,-262,-41,-44,-40,-42,284,-156,-155,-45,-157,284,-43,-175,-174,-172,284,-158,-171,-159,284,-170,-173,-162,284,-160,284,-161,284,284,-166,-165,-163,284,284,-167,-164,284,-169,-168,]),'NOT':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,152,152,-47,152,-28,-263,-125,-227,152,-225,152,-224,152,-223,152,152,-222,-226,-263,-223,152,152,152,-262,152,152,-223,152,152,-184,-187,-185,-181,-182,-186,-188,152,-190,-191,-183,-189,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,-12,152,152,-11,-223,-41,-44,-40,152,-42,152,152,-156,-155,-45,-157,152,-43,152,152,152,-263,-139,-175,-174,152,-172,152,152,-158,152,-171,-159,152,152,152,152,-263,152,152,-11,-170,-173,152,-162,152,-160,152,152,-161,152,152,152,-263,152,-166,-165,-163,152,152,152,-167,-164,152,-169,-168,]),'OREQUAL':([112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,390,391,392,398,428,430,437,],[-248,-252,215,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-221,-229,-230,-215,-245,-238,-239,]),'MOD':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,259,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,259,259,259,259,259,259,259,259,259,259,-197,-196,259,259,259,259,259,-198,-221,-229,-230,-215,-245,-238,-239,]),'RSHIFT':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,241,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,241,-202,-200,241,241,241,-199,241,241,-197,-196,241,241,241,241,241,-198,-221,-229,-230,-215,-245,-238,-239,]),'DEFAULT':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,286,-262,-41,-44,-40,-42,286,-156,-155,-45,-157,286,-43,-175,-174,-172,286,-158,-171,-159,286,-170,-173,-162,286,-160,286,-161,286,286,-166,-165,-163,286,286,-167,-164,286,-169,-168,]),'CHAR':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[37,37,-63,-74,-73,-60,-56,-57,-35,-31,-61,37,-36,-55,-70,-65,-54,37,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,37,-69,37,-72,-76,37,-59,-86,-261,-85,37,-113,-112,-32,-102,-101,37,37,37,-47,-48,37,-115,37,37,37,37,-92,37,37,37,37,-38,37,-49,37,37,-87,-93,-262,-103,-121,-120,37,37,37,37,37,-39,-41,-44,-40,-42,37,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,37,-175,-174,37,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'WHILE':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,382,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,287,-262,-41,-44,-40,-42,287,-156,-155,-45,-157,287,-43,-175,-174,-172,287,-158,-171,413,-159,287,-170,-173,-162,287,-160,287,-161,287,287,-166,-165,-163,287,287,-167,-164,287,-169,-168,]),'DIVEQUAL':([112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,390,391,392,398,428,430,437,],[-248,-252,206,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-221,-229,-230,-215,-245,-238,-239,]),'EXTERN':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,59,60,61,62,63,66,78,80,82,87,89,90,165,167,169,170,171,174,176,191,197,198,204,272,276,277,280,282,289,291,292,293,295,298,302,303,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[10,10,-63,-74,-73,-60,-56,-57,-35,-31,-61,10,-36,-55,-70,-65,-54,10,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,10,-69,10,-72,-76,10,-59,-86,-261,-85,-113,-112,-32,-102,-101,10,10,10,-47,-48,10,-115,10,10,-38,10,-49,-87,-262,-103,-121,-120,10,-39,-41,-44,-40,-42,10,-156,-155,-45,-157,-43,-89,-88,-105,-104,-116,-119,10,-175,-174,10,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'CASE':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,288,-262,-41,-44,-40,-42,288,-156,-155,-45,-157,288,-43,-175,-174,-172,288,-158,-171,-159,288,-170,-173,-162,288,-160,288,-161,288,288,-166,-165,-163,288,288,-167,-164,288,-169,-168,]),'LAND':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,254,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,254,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,-212,-207,-209,-210,-198,-221,-229,-230,-215,-245,-238,-239,]),'REGISTER':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,59,60,61,62,63,66,78,80,82,87,89,90,165,167,169,170,171,174,176,191,197,198,204,272,276,277,280,282,289,291,292,293,295,298,302,303,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[17,17,-63,-74,-73,-60,-56,-57,-35,-31,-61,17,-36,-55,-70,-65,-54,17,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,17,-69,17,-72,-76,17,-59,-86,-261,-85,-113,-112,-32,-102,-101,17,17,17,-47,-48,17,-115,17,17,-38,17,-49,-87,-262,-103,-121,-120,17,-39,-41,-44,-40,-42,17,-156,-155,-45,-157,-43,-89,-88,-105,-104,-116,-119,17,-175,-174,17,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'MODEQUAL':([112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,390,391,392,398,428,430,437,],[-248,-252,208,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-221,-229,-230,-215,-245,-238,-239,]),'NE':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,246,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,246,-202,-200,-204,-208,-203,-199,-206,246,-197,-196,-205,246,-207,246,246,-198,-221,-229,-230,-215,-245,-238,-239,]),'SWITCH':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,290,-262,-41,-44,-40,-42,290,-156,-155,-45,-157,290,-43,-175,-174,-172,290,-158,-171,-159,290,-170,-173,-162,290,-160,290,-161,290,290,-166,-165,-163,290,290,-167,-164,290,-169,-168,]),'INT_CONST_HEX':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,138,138,-47,138,-28,-263,-125,-227,138,-225,138,-224,138,-223,138,138,-222,-226,-263,-223,138,138,138,-262,138,138,-223,138,138,-184,-187,-185,-181,-182,-186,-188,138,-190,-191,-183,-189,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,-12,138,138,-11,-223,-41,-44,-40,138,-42,138,138,-156,-155,-45,-157,138,-43,138,138,138,-263,-139,-175,-174,138,-172,138,138,-158,138,-171,-159,138,138,138,138,-263,138,138,-11,-170,-173,138,-162,138,-160,138,138,-161,138,138,138,-263,138,-166,-165,-163,138,138,138,-167,-164,138,-169,-168,]),'_COMPLEX':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[27,27,-63,-74,-73,-60,-56,-57,-35,-31,-61,27,-36,-55,-70,-65,-54,27,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,27,-69,27,-72,-76,27,-59,-86,-261,-85,27,-113,-112,-32,-102,-101,27,27,27,-47,-48,27,-115,27,27,27,27,-92,27,27,27,27,-38,27,-49,27,27,-87,-93,-262,-103,-121,-120,27,27,27,27,27,-39,-41,-44,-40,-42,27,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,27,-175,-174,27,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'PLUSEQUAL':([112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,390,391,392,398,428,430,437,],[-248,-252,211,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-221,-229,-230,-215,-245,-238,-239,]),'STRUCT':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[34,34,-63,-74,-73,-60,-56,-57,-35,-31,-61,34,-36,-55,-70,-65,-54,34,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,34,-69,34,-72,-76,34,-59,-86,-261,-85,34,-113,-112,-32,-102,-101,34,34,34,-47,-48,34,-115,34,34,34,34,-92,34,34,34,34,-38,34,-49,34,34,-87,-93,-262,-103,-121,-120,34,34,34,34,34,-39,-41,-44,-40,-42,34,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,34,-175,-174,34,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'CONDOP':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,257,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,-213,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,-212,-207,-209,-210,-198,-221,-229,-230,-215,-245,-238,-239,]),'BREAK':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,294,-262,-41,-44,-40,-42,294,-156,-155,-45,-157,294,-43,-175,-174,-172,294,-158,-171,-159,294,-170,-173,-162,294,-160,294,-161,294,294,-166,-165,-163,294,294,-167,-164,294,-169,-168,]),'VOLATILE':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,28,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,65,66,67,69,78,80,82,87,89,90,91,92,93,94,95,96,104,105,115,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[46,46,-63,-74,-73,-60,-56,-57,-35,-31,-61,46,-36,-55,-70,-65,-54,46,-58,-178,-111,-68,46,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,46,-69,46,-72,-76,46,-59,-86,-261,-85,46,-113,-112,-32,-102,-101,46,46,46,-124,46,46,-47,-48,46,-115,46,46,46,46,-92,46,46,46,-125,46,46,46,-38,46,-49,46,46,-87,-93,-262,-103,-121,-120,46,46,46,46,46,-39,-41,-44,-40,-42,46,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,46,-175,-174,46,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'INLINE':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,59,60,61,62,63,66,78,80,82,87,89,90,165,167,169,170,171,174,176,191,197,198,204,272,276,277,280,282,289,291,292,293,295,298,302,303,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[49,49,-63,-74,-73,-60,-56,-57,-35,-31,-61,49,-36,-55,-70,-65,-54,49,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,49,-69,49,-72,-76,49,-59,-86,-261,-85,-113,-112,-32,-102,-101,49,49,49,-47,-48,49,-115,49,49,-38,49,-49,-87,-262,-103,-121,-120,49,-39,-41,-44,-40,-42,49,-156,-155,-45,-157,-43,-89,-88,-105,-104,-116,-119,49,-175,-174,49,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'INT_CONST_BIN':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,118,118,-47,118,-28,-263,-125,-227,118,-225,118,-224,118,-223,118,118,-222,-226,-263,-223,118,118,118,-262,118,118,-223,118,118,-184,-187,-185,-181,-182,-186,-188,118,-190,-191,-183,-189,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,-12,118,118,-11,-223,-41,-44,-40,118,-42,118,118,-156,-155,-45,-157,118,-43,118,118,118,-263,-139,-175,-174,118,-172,118,118,-158,118,-171,-159,118,118,118,118,-263,118,118,-11,-170,-173,118,-162,118,-160,118,118,-161,118,118,118,-263,118,-166,-165,-163,118,118,118,-167,-164,118,-169,-168,]),'DO':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,297,-262,-41,-44,-40,-42,297,-156,-155,-45,-157,297,-43,-175,-174,-172,297,-158,-171,-159,297,-170,-173,-162,297,-160,297,-161,297,297,-166,-165,-163,297,297,-167,-164,297,-169,-168,]),'LNOT':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,119,119,-47,119,-28,-263,-125,-227,119,-225,119,-224,119,-223,119,119,-222,-226,-263,-223,119,119,119,-262,119,119,-223,119,119,-184,-187,-185,-181,-182,-186,-188,119,-190,-191,-183,-189,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,-12,119,119,-11,-223,-41,-44,-40,119,-42,119,119,-156,-155,-45,-157,119,-43,119,119,119,-263,-139,-175,-174,119,-172,119,119,-158,119,-171,-159,119,119,119,119,-263,119,119,-11,-170,-173,119,-162,119,-160,119,119,-161,119,119,119,-263,119,-166,-165,-163,119,119,119,-167,-164,119,-169,-168,]),'CONST':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,28,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,65,66,67,69,78,80,82,87,89,90,91,92,93,94,95,96,104,105,115,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[3,3,-63,-74,-73,-60,-56,-57,-35,-31,-61,3,-36,-55,-70,-65,-54,3,-58,-178,-111,-68,3,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,3,-69,3,-72,-76,3,-59,-86,-261,-85,3,-113,-112,-32,-102,-101,3,3,3,-124,3,3,-47,-48,3,-115,3,3,3,3,-92,3,3,3,-125,3,3,3,-38,3,-49,3,3,-87,-93,-262,-103,-121,-120,3,3,3,3,3,-39,-41,-44,-40,-42,3,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,3,-175,-174,3,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'LOR':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,242,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,-213,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,-212,-207,-209,-210,-198,-221,-229,-230,-215,-245,-238,-239,]),'CHAR_CONST':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,122,122,-47,122,-28,-263,-125,-227,122,-225,122,-224,122,-223,122,122,-222,-226,-263,-223,122,122,122,-262,122,122,-223,122,122,-184,-187,-185,-181,-182,-186,-188,122,-190,-191,-183,-189,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,-12,122,122,-11,-223,-41,-44,-40,122,-42,122,122,-156,-155,-45,-157,122,-43,122,122,122,-263,-139,-175,-174,122,-172,122,122,-158,122,-171,-159,122,122,122,122,-263,122,122,-11,-170,-173,122,-162,122,-160,122,122,-161,122,122,122,-263,122,-166,-165,-163,122,122,122,-167,-164,122,-169,-168,]),'LSHIFT':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,243,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,243,-202,-200,243,243,243,-199,243,243,-197,-196,243,243,243,243,243,-198,-221,-229,-230,-215,-245,-238,-239,]),'RBRACE':([55,82,93,95,100,101,102,112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,151,155,156,170,172,173,175,176,188,189,190,218,220,221,222,224,231,232,234,240,261,265,268,276,277,280,282,289,291,292,293,295,296,298,299,305,307,308,312,313,321,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,359,362,363,370,371,374,379,381,383,390,391,392,398,404,405,406,409,414,418,419,420,424,428,429,430,433,434,436,437,444,445,447,448,],[-261,-47,176,-92,-106,176,-109,-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,-193,-254,-250,-179,-263,-134,-263,176,176,-93,-262,176,176,-107,-260,-220,-258,-237,-236,-214,-219,-217,-218,176,-20,-19,-41,-44,-40,-42,-6,-156,-155,-45,-157,-5,-43,176,-192,-94,-95,-108,-110,-180,-235,-234,-233,-232,-231,-244,-201,-213,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,-212,-207,-209,-210,-198,-135,176,-137,-175,-174,-172,-158,-171,-159,-221,-229,-230,-215,-136,-170,-173,-162,-160,176,-194,-138,-161,-245,176,-238,-166,-165,-163,-239,-167,-164,-169,-168,]),'_BOOL':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[13,13,-63,-74,-73,-60,-56,-57,-35,-31,-61,13,-36,-55,-70,-65,-54,13,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,13,-69,13,-72,-76,13,-59,-86,-261,-85,13,-113,-112,-32,-102,-101,13,13,13,-47,-48,13,-115,13,13,13,13,-92,13,13,13,13,-38,13,-49,13,13,-87,-93,-262,-103,-121,-120,13,13,13,13,13,-39,-41,-44,-40,-42,13,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,13,-175,-174,13,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'LE':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,245,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,245,-202,-200,-204,245,-203,-199,-206,245,-197,-196,-205,245,245,245,245,-198,-221,-229,-230,-215,-245,-238,-239,]),'SEMI':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,28,29,30,31,32,33,35,36,37,38,39,40,41,42,43,44,45,46,49,50,51,52,54,55,56,58,59,60,61,62,63,67,68,69,70,71,73,74,75,76,79,80,81,82,83,84,86,90,94,96,97,112,115,116,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,151,153,154,156,166,168,169,170,174,176,177,178,179,180,182,183,184,185,186,187,191,197,198,205,218,220,221,222,224,228,231,232,234,235,238,240,269,270,271,272,276,277,279,280,281,282,284,285,289,291,292,293,294,295,296,297,298,300,302,303,304,305,310,311,314,315,321,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,359,366,367,368,369,370,371,372,373,374,375,378,379,381,383,384,386,387,388,389,390,391,392,397,398,404,405,406,407,408,409,411,414,419,421,422,423,424,425,427,428,430,431,433,434,436,437,440,441,443,444,445,446,447,448,],[15,-263,-63,-74,-73,-60,-56,-57,-35,-31,-61,-263,-36,-55,-70,-65,-54,15,-58,-178,-111,-68,-263,-71,-263,-34,-75,-114,-66,-33,-62,-37,-64,-67,82,-263,-69,-263,-72,-76,-59,-52,-9,-10,-86,-261,-85,-51,-113,-112,-32,-102,-101,-28,-122,-124,-27,-18,-46,-145,-77,-17,-80,-81,-147,-47,-50,-53,-263,-115,-263,-263,-263,-248,-125,-123,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,-193,-254,-250,-179,-146,-79,-134,-145,-81,-38,-263,-87,-262,-23,-84,-24,-83,-26,307,-96,308,-25,-98,-103,-121,-120,-78,-260,-220,-258,-237,-236,-150,-214,-219,-217,-152,-176,-218,-154,-148,-82,-39,-41,-44,370,-40,371,-42,374,-14,-263,-156,-155,-45,381,-157,-13,-263,-43,-248,-89,-88,-100,-192,-105,-104,-116,-119,-180,-235,-234,-233,-232,-231,-244,-201,-213,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,-212,-207,-209,-210,-198,-135,-149,-151,-153,405,-175,-174,406,-263,-172,-263,-13,-158,-171,-159,-263,-97,-99,-118,-117,-221,-229,-230,-177,-215,-136,-170,-173,421,-263,-162,-263,-160,-194,-263,432,-263,-161,-263,-263,-245,-238,438,-166,-165,-163,-239,444,-263,-263,-167,-164,-263,-169,-168,]),'LT':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,247,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,247,-202,-200,-204,247,-203,-199,-206,247,-197,-196,-205,247,247,247,247,-198,-221,-229,-230,-215,-245,-238,-239,]),'COMMA':([1,2,3,5,6,9,10,13,14,17,18,19,21,23,25,26,27,28,29,32,33,35,37,39,40,42,43,44,45,46,49,50,51,52,54,56,58,59,60,62,63,67,68,69,70,71,74,75,79,80,81,83,84,90,94,96,100,101,102,109,110,111,112,113,114,115,116,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,151,153,154,156,166,168,174,176,177,178,179,180,182,184,187,188,189,190,191,197,198,199,200,201,202,205,218,220,221,222,224,228,231,232,234,235,236,238,239,240,265,269,270,271,285,300,302,303,304,305,310,311,312,313,314,315,318,320,321,323,324,325,326,327,328,329,330,331,334,337,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,363,366,367,368,372,386,387,388,389,390,391,392,397,398,404,410,412,415,416,418,419,420,428,430,435,437,],[-263,-63,-74,-73,-60,-56,-57,-61,-263,-55,-70,-65,-54,-58,-178,-111,-68,-263,-71,-75,-114,-66,-62,-64,-67,-263,-69,-263,-72,-76,-59,-52,-9,-10,-86,-85,-51,-113,-112,-102,-101,-28,-122,-124,-27,117,-145,-77,-80,-81,-147,-50,-53,-115,-263,-263,-106,190,-109,-128,-263,203,-248,204,-132,-125,-123,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,-193,-254,-250,-179,-146,-79,-134,-145,-81,-87,-262,-23,-84,-24,-83,306,-96,-98,190,190,-107,-103,-121,-120,-131,-1,-2,-130,-78,-260,-220,-258,-237,-236,-150,-214,-219,-217,-152,335,-176,-263,-218,362,-154,-148,-82,335,-248,-89,-88,-100,-192,-105,-104,-108,-110,-116,-119,-133,-129,-180,-235,-234,-233,-232,335,-246,-231,393,394,-244,-144,-145,-201,-213,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,-212,-207,-209,335,-210,-198,-135,-137,-149,-151,-153,335,-97,-99,-118,-117,-221,-229,-230,-177,-215,-136,335,335,335,-247,429,-194,-138,-245,-238,335,-239,]),'OFFSETOF':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,133,133,-47,133,-28,-263,-125,-227,133,-225,133,-224,133,-223,133,133,-222,-226,-263,-223,133,133,133,-262,133,133,-223,133,133,-184,-187,-185,-181,-182,-186,-188,133,-190,-191,-183,-189,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,-12,133,133,-11,-223,-41,-44,-40,133,-42,133,133,-156,-155,-45,-157,133,-43,133,133,133,-263,-139,-175,-174,133,-172,133,133,-158,133,-171,-159,133,133,133,133,-263,133,133,-11,-170,-173,133,-162,133,-160,133,133,-161,133,133,133,-263,133,-166,-165,-163,133,133,133,-167,-164,133,-169,-168,]),'TYPEDEF':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,59,60,61,62,63,66,78,80,82,87,89,90,165,167,169,170,171,174,176,191,197,198,204,272,276,277,280,282,289,291,292,293,295,298,302,303,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[23,23,-63,-74,-73,-60,-56,-57,-35,-31,-61,23,-36,-55,-70,-65,-54,23,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,23,-69,23,-72,-76,23,-59,-86,-261,-85,-113,-112,-32,-102,-101,23,23,23,-47,-48,23,-115,23,23,-38,23,-49,-87,-262,-103,-121,-120,23,-39,-41,-44,-40,-42,23,-156,-155,-45,-157,-43,-89,-88,-105,-104,-116,-119,23,-175,-174,23,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'XOR':([112,118,120,121,122,123,124,125,126,129,130,132,138,140,143,145,146,147,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,390,391,392,398,428,430,437,],[-248,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,-195,-251,-228,-257,-249,-240,250,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-201,250,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,250,-207,-209,250,-198,-221,-229,-230,-215,-245,-238,-239,]),'AUTO':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,59,60,61,62,63,66,78,80,82,87,89,90,165,167,169,170,171,174,176,191,197,198,204,272,276,277,280,282,289,291,292,293,295,298,302,303,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[21,21,-63,-74,-73,-60,-56,-57,-35,-31,-61,21,-36,-55,-70,-65,-54,21,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,21,-69,21,-72,-76,21,-59,-86,-261,-85,-113,-112,-32,-102,-101,21,21,21,-47,-48,21,-115,21,21,-38,21,-49,-87,-262,-103,-121,-120,21,-39,-41,-44,-40,-42,21,-156,-155,-45,-157,-43,-89,-88,-105,-104,-116,-119,21,-175,-174,21,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'TIMES':([0,1,2,3,4,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,27,28,29,30,31,32,35,36,37,38,39,40,42,43,44,45,46,49,50,51,52,54,55,56,58,61,62,63,65,67,68,69,70,72,77,78,82,83,84,86,94,96,97,103,104,105,110,112,115,117,118,119,120,121,122,123,124,125,126,127,128,129,130,132,134,135,137,138,139,140,141,142,143,144,145,146,147,148,149,152,155,157,162,164,167,169,170,174,176,177,178,179,180,181,191,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,224,226,227,230,231,232,233,234,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,272,274,276,277,280,281,282,288,289,291,292,293,295,297,298,300,302,303,306,309,310,311,323,324,325,326,329,334,335,336,338,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,362,365,370,371,373,374,375,376,379,380,381,383,384,385,390,391,392,393,395,398,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,428,429,430,432,433,434,436,437,438,441,443,444,445,446,447,448,],[28,-263,-63,-74,28,-73,-60,-56,-57,-35,-31,-61,-263,-36,-55,-70,-65,-54,28,-58,-178,-68,-263,-71,28,-34,-75,-66,-33,-62,-37,-64,-67,-263,-69,-263,-72,-76,-59,-52,-9,-10,-86,-261,-85,-51,-32,-102,-101,-263,-28,28,-124,-27,139,157,28,-47,-50,-53,28,-263,-263,28,194,-28,-263,28,-248,-125,28,-252,-227,-214,-243,-255,-259,-256,-253,-241,157,-225,-242,-216,-195,157,-224,157,-251,-223,-228,157,157,-257,-222,-249,-240,252,-254,-250,-226,-263,-223,157,274,28,-38,157,-87,-262,-23,-84,-24,-83,157,-103,157,-223,157,157,-184,-187,-185,-181,-182,-186,-188,157,-190,-191,-183,-189,-260,157,-220,-258,-237,-236,157,157,157,-214,-219,157,-217,28,-218,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,-12,157,157,-11,-39,-223,-41,-44,-40,157,-42,157,157,-156,-155,-45,-157,157,-43,-248,-89,-88,28,157,-105,-104,-235,-234,-233,-232,-231,-244,157,157,28,252,252,252,252,252,252,252,252,252,252,-197,-196,252,252,252,252,252,-198,-263,-139,-175,-174,157,-172,157,157,-158,157,-171,-159,157,157,-221,-229,-230,157,157,-215,-263,157,157,-11,-170,-173,157,-162,157,-160,157,157,-161,157,157,157,-245,-263,-238,157,-166,-165,-163,-239,157,157,157,-167,-164,157,-169,-168,]),'LPAREN':([0,1,2,3,4,5,6,9,10,11,12,13,14,15,16,17,18,19,21,22,23,25,26,27,28,29,30,31,32,33,35,36,37,38,39,40,42,43,44,45,46,49,50,51,52,54,55,56,58,60,61,62,63,65,67,68,69,70,72,74,77,78,81,82,83,84,86,90,94,96,97,103,104,105,110,112,115,116,117,118,119,121,122,123,124,125,126,127,128,129,130,133,134,135,137,138,139,140,141,142,143,144,145,146,148,149,152,153,155,157,162,164,166,167,169,170,174,176,177,178,179,180,181,191,192,194,195,196,197,198,206,207,208,209,210,211,212,213,214,215,216,217,218,219,221,222,224,226,227,228,230,233,235,239,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,269,270,272,274,276,277,280,281,282,283,287,288,289,290,291,292,293,295,297,298,300,301,302,303,306,309,310,311,314,315,323,324,325,326,329,334,335,336,338,339,362,365,366,367,368,370,371,373,374,375,376,379,380,381,383,384,385,388,389,391,392,393,395,399,400,402,403,405,406,408,409,411,413,414,421,423,424,425,426,427,428,429,430,432,433,434,436,437,438,441,443,444,445,446,447,448,],[4,-263,-63,-74,4,-73,-60,-56,-57,-35,-31,-61,-263,-36,4,-55,-70,-65,-54,4,-58,-178,66,-68,-263,-71,78,-34,-75,-114,-66,-33,-62,-37,-64,-67,-263,-69,-263,-72,-76,-59,-52,-9,-10,-86,-261,-85,-51,66,-32,-102,-101,-263,-28,-122,-124,-27,141,78,141,78,165,-47,-50,-53,167,-115,-263,-263,167,141,-28,-263,78,-248,-125,-123,4,-252,-227,-243,-255,-259,-256,-253,-241,219,-225,-242,227,229,230,-224,233,-251,-223,-228,141,233,-257,-222,-249,-240,-254,-250,-226,165,-263,-223,141,141,167,167,-38,141,-87,-262,-23,-84,-24,-83,230,-103,230,-223,141,141,-121,-120,-184,-187,-185,-181,-182,-186,-188,141,-190,-191,-183,-189,-260,141,-258,-237,-236,141,141,-150,141,141,-152,338,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,230,141,230,230,-12,230,141,-11,-154,-148,-39,-223,-41,-44,-40,141,-42,373,376,230,141,380,-156,-155,-45,-157,141,-43,-248,385,-89,-88,4,230,-105,-104,-116,-119,-235,-234,-233,-232,-231,-244,141,230,338,338,-263,-139,-149,-151,-153,-175,-174,141,-172,141,141,-158,141,-171,-159,141,141,-118,-117,-229,-230,141,230,-263,230,141,-11,-170,-173,141,-162,141,426,-160,141,141,-161,141,141,141,-245,-263,-238,141,-166,-165,-163,-239,141,141,141,-167,-164,141,-169,-168,]),'MINUSMINUS':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,112,115,118,119,121,122,123,124,125,126,127,128,129,130,134,135,137,138,139,140,141,142,143,144,145,146,148,149,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,218,219,221,222,224,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,300,309,323,324,325,326,329,334,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,391,392,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,428,429,430,432,433,434,436,437,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,142,142,-47,142,-28,-263,-248,-125,-252,-227,-243,-255,-259,-256,-253,-241,142,-225,-242,222,142,-224,142,-251,-223,-228,142,142,-257,-222,-249,-240,-254,-250,-226,-263,-223,142,142,142,-262,142,142,-223,142,142,-184,-187,-185,-181,-182,-186,-188,142,-190,-191,-183,-189,-260,142,-258,-237,-236,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,-12,142,142,-11,-223,-41,-44,-40,142,-42,142,142,-156,-155,-45,-157,142,-43,-248,142,-235,-234,-233,-232,-231,-244,142,142,-263,-139,-175,-174,142,-172,142,142,-158,142,-171,-159,142,142,-229,-230,142,142,-263,142,142,-11,-170,-173,142,-162,142,-160,142,142,-161,142,142,142,-245,-263,-238,142,-166,-165,-163,-239,142,142,142,-167,-164,142,-169,-168,]),'ID':([0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,34,35,36,37,38,39,40,42,43,44,45,46,49,50,51,52,54,55,56,58,61,62,63,64,65,66,67,68,69,70,72,74,77,78,82,83,84,86,94,96,97,98,99,103,104,105,110,115,116,117,119,127,128,134,135,137,139,141,142,144,152,155,157,162,164,166,167,169,170,174,176,177,178,179,180,181,190,191,192,194,195,196,203,206,207,208,209,210,211,212,213,214,215,216,217,219,223,225,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,263,264,266,268,272,274,276,277,278,280,281,282,288,289,291,292,293,295,297,298,302,303,306,309,310,311,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,394,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[33,-263,-63,-74,33,-73,-60,56,-56,-57,-35,-31,-61,-263,-36,33,-55,-70,-65,-91,-54,33,-58,63,-178,-68,-263,-71,33,-34,-75,-90,-66,-33,-62,-37,-64,-67,-263,-69,-263,-72,-76,-59,-52,-9,-10,-86,-261,-85,-51,-32,-102,-101,102,-263,112,-28,-122,-124,-27,112,33,112,33,-47,-50,-53,33,-263,-263,33,102,102,112,-28,-263,33,-125,-123,33,-227,112,-225,112,-224,112,-223,112,112,-222,-226,-263,-223,112,112,33,33,-38,300,-87,-262,-23,-84,-24,-83,112,102,-103,112,-223,112,112,112,-184,-187,-185,-181,-182,-186,-188,112,-190,-191,-183,-189,112,324,326,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,-12,112,112,112,-11,-39,-223,-41,-44,369,-40,112,-42,112,300,-156,-155,-45,-157,300,-43,-89,-88,33,112,-105,-104,112,112,-263,-139,-175,-174,112,-172,300,112,-158,112,-171,-159,300,112,112,112,112,-263,112,112,-11,-170,-173,112,-162,300,-160,112,300,-161,300,112,300,-263,112,-166,-165,-163,112,300,300,-167,-164,300,-169,-168,]),'IF':([55,82,170,176,276,277,280,282,289,291,292,293,295,297,298,370,371,374,375,379,381,383,384,405,406,409,411,414,423,424,425,427,433,434,436,441,443,444,445,446,447,448,],[-261,-47,301,-262,-41,-44,-40,-42,301,-156,-155,-45,-157,301,-43,-175,-174,-172,301,-158,-171,-159,301,-170,-173,-162,301,-160,301,-161,301,301,-166,-165,-163,301,301,-167,-164,301,-169,-168,]),'STRING_LITERAL':([3,32,46,55,65,67,69,70,72,77,82,103,104,105,115,119,127,128,129,134,135,137,139,141,142,143,144,152,155,157,162,164,170,176,181,192,194,195,196,206,207,208,209,210,211,212,213,214,215,216,217,219,221,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,264,266,268,274,276,277,280,281,282,288,289,291,292,293,295,297,298,309,335,336,362,365,370,371,373,374,375,376,379,380,381,383,384,385,393,395,399,400,402,403,405,406,408,409,411,414,421,423,424,425,426,427,429,432,433,434,436,438,441,443,444,445,446,447,448,],[-74,-75,-76,-261,-263,-28,-124,-27,143,143,-47,143,-28,-263,-125,-227,143,-225,221,143,-224,143,-223,143,143,-257,-222,-226,-263,-223,143,143,143,-262,143,143,-223,143,143,-184,-187,-185,-181,-182,-186,-188,143,-190,-191,-183,-189,143,-258,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,-12,143,143,-11,-223,-41,-44,-40,143,-42,143,143,-156,-155,-45,-157,143,-43,143,143,143,-263,-139,-175,-174,143,-172,143,143,-158,143,-171,-159,143,143,143,143,-263,143,143,-11,-170,-173,143,-162,143,-160,143,143,-161,143,143,143,-263,143,-166,-165,-163,143,143,143,-167,-164,143,-169,-168,]),'FLOAT':([0,1,2,3,5,6,9,10,11,12,13,14,15,17,18,19,21,22,23,25,26,27,29,31,32,33,35,36,37,38,39,40,42,43,44,45,46,48,49,54,55,56,57,59,60,61,62,63,66,78,80,82,87,89,90,91,92,93,94,95,96,141,165,167,169,170,171,172,173,174,175,176,191,197,198,204,219,229,230,233,272,276,277,280,282,289,291,292,293,295,298,302,303,307,308,310,311,314,315,338,370,371,373,374,379,381,383,388,389,405,406,409,414,424,433,434,436,444,445,447,448,],[35,35,-63,-74,-73,-60,-56,-57,-35,-31,-61,35,-36,-55,-70,-65,-54,35,-58,-178,-111,-68,-71,-34,-75,-114,-66,-33,-62,-37,-64,-67,35,-69,35,-72,-76,35,-59,-86,-261,-85,35,-113,-112,-32,-102,-101,35,35,35,-47,-48,35,-115,35,35,35,35,-92,35,35,35,35,-38,35,-49,35,35,-87,-93,-262,-103,-121,-120,35,35,35,35,35,-39,-41,-44,-40,-42,35,-156,-155,-45,-157,-43,-89,-88,-94,-95,-105,-104,-116,-119,35,-175,-174,35,-172,-158,-171,-159,-118,-117,-170,-173,-162,-160,-161,-166,-165,-163,-167,-164,-169,-168,]),'XOREQUAL':([112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,390,391,392,398,428,430,437,],[-248,-252,210,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-221,-229,-230,-215,-245,-238,-239,]),'LSHIFTEQUAL':([112,118,120,121,122,123,124,125,126,129,130,138,140,143,145,146,148,149,176,218,220,221,222,224,231,232,234,240,300,323,324,325,326,329,334,390,391,392,398,428,430,437,],[-248,-252,212,-243,-255,-259,-256,-253,-241,-242,-216,-251,-228,-257,-249,-240,-254,-250,-262,-260,-220,-258,-237,-236,-214,-219,-217,-218,-248,-235,-234,-233,-232,-231,-244,-221,-229,-230,-215,-245,-238,-239,]),'RBRACKET':([3,32,46,65,69,70,72,103,104,112,115,118,120,121,122,123,124,125,126,129,130,131,132,136,138,139,140,143,145,146,147,148,149,150,151,164,176,193,194,218,220,221,222,224,231,232,234,238,240,273,274,305,316,317,321,323,324,325,326,327,329,334,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,361,390,391,392,397,398,419,428,430,437,],[-74,-75,-76,-263,-124,-27,-263,-263,-28,-248,-125,-252,-214,-243,-255,-259,-256,-253,-241,-242,-216,228,-195,-4,-251,235,-228,-257,-249,-240,-193,-254,-250,-3,-179,-263,-262,314,315,-260,-220,-258,-237,-236,-214,-219,-217,-176,-218,366,367,-192,388,389,-180,-235,-234,-233,-232,391,-231,-244,-201,-213,-202,-200,-204,-208,-203,-199,-206,-211,-197,-196,-205,-212,-207,-209,-210,-198,401,-221,-229,-230,-177,-215,-194,-245,-238,-239,]),} _lr_action = { } for _k, _v in _lr_action_items.items(): for _x,_y in zip(_v[0],_v[1]): if not _x in _lr_action: _lr_action[_x] = { } _lr_action[_x][_k] = _y del _lr_action_items _lr_goto_items = {'storage_class_specifier':([0,1,14,22,42,44,48,66,78,80,89,165,167,170,204,289,338,373,],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,]),'identifier_list_opt':([66,],[106,]),'selection_statement':([170,289,297,375,384,411,423,425,427,441,443,446,],[298,298,298,298,298,298,298,298,298,298,298,298,]),'constant':([72,77,103,127,134,137,141,142,162,164,170,181,192,195,196,213,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,264,266,281,288,289,297,309,335,336,373,375,376,380,384,385,393,395,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,]),'unary_expression':([72,77,103,127,134,137,141,142,162,164,170,181,192,195,196,213,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,264,266,281,288,289,297,309,335,336,373,375,376,380,384,385,393,395,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[120,120,120,220,231,234,120,240,120,120,120,231,231,120,120,120,120,120,120,120,120,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,231,120,231,231,231,120,120,231,120,120,231,120,231,120,120,120,120,120,120,120,231,231,120,120,120,120,120,120,120,120,120,120,120,120,120,]),'conditional_expression':([72,77,103,141,162,164,170,181,192,195,196,213,219,226,227,230,233,257,264,266,281,288,289,297,309,335,373,375,376,380,384,385,393,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[151,151,151,151,151,151,151,305,305,151,151,151,151,151,151,151,151,151,305,151,151,305,151,151,305,151,151,151,151,151,151,151,151,419,151,151,151,151,151,151,151,151,151,151,151,151,151,]),'brace_close':([93,101,172,173,188,189,261,299,362,418,429,],[174,191,302,303,310,311,359,383,404,430,437,]),'struct_or_union_specifier':([0,1,14,22,42,44,48,57,66,78,80,89,91,92,93,94,96,141,165,167,170,172,173,204,219,229,230,233,289,338,373,],[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,]),'unified_wstring_literal':([72,77,103,127,134,137,141,142,162,164,170,181,192,195,196,213,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,264,266,281,288,289,297,309,335,336,373,375,376,380,384,385,393,395,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,]),'abstract_declarator_opt':([110,239,],[199,337,]),'iteration_statement':([170,289,297,375,384,411,423,425,427,441,443,446,],[277,277,277,277,277,277,277,277,277,277,277,277,]),'init_declarator_list':([30,86,],[71,71,]),'translation_unit_or_empty':([0,],[8,]),'struct_declaration_list':([57,91,92,],[93,172,173,]),'block_item_list_opt':([170,],[299,]),'enumerator':([64,98,99,190,],[100,100,100,312,]),'pp_directive':([0,22,],[11,11,]),'abstract_declarator':([30,78,86,97,110,167,239,338,],[79,161,79,185,201,161,201,161,]),'declaration_specifiers_opt':([1,14,42,44,],[50,58,83,84,]),'external_declaration':([0,22,],[12,61,]),'type_specifier':([0,1,14,22,42,44,48,57,66,78,80,89,91,92,93,94,96,141,165,167,170,172,173,204,219,229,230,233,289,338,373,],[14,14,14,14,14,14,14,94,14,14,14,14,94,94,94,94,94,94,14,14,14,94,94,14,94,94,94,94,14,14,14,]),'designation':([155,362,399,429,],[260,260,260,260,]),'compound_statement':([88,163,170,289,297,375,384,411,423,425,427,441,443,446,],[169,272,282,282,282,282,282,282,282,282,282,282,282,282,]),'pointer':([0,4,22,30,68,78,86,97,110,117,167,239,306,338,],[16,16,16,74,116,74,166,166,74,16,166,339,16,339,]),'type_name':([141,219,229,230,233,],[237,322,331,332,333,]),'unified_string_literal':([72,77,103,127,134,137,141,142,162,164,170,181,192,195,196,213,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,264,266,281,288,289,297,309,335,336,373,375,376,380,384,385,393,395,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,]),'postfix_expression':([72,77,103,127,134,137,141,142,162,164,170,181,192,195,196,213,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,264,266,281,288,289,297,309,335,336,373,375,376,380,384,385,393,395,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,]),'assignment_expression_opt':([72,103,164,],[131,193,273,]),'designation_opt':([155,362,399,429,],[266,402,266,402,]),'expression_statement':([170,289,297,375,384,411,423,425,427,441,443,446,],[276,276,276,276,276,276,276,276,276,276,276,276,]),'parameter_declaration':([66,78,165,167,204,338,],[109,109,109,109,320,109,]),'initializer_list_opt':([155,],[261,]),'cast_expression':([72,77,103,134,141,162,164,170,181,192,195,196,213,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,264,266,281,288,289,297,309,335,336,373,375,376,380,384,385,393,395,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[132,132,132,232,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,398,132,132,132,132,132,132,132,398,132,132,132,132,132,132,132,132,132,132,132,132,132,132,]),'init_declarator':([30,86,117,],[75,75,205,]),'struct_declarator_list':([97,],[182,]),'unary_operator':([72,77,103,127,134,137,141,142,162,164,170,181,192,195,196,213,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,264,266,281,288,289,297,309,335,336,373,375,376,380,384,385,393,395,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,]),'brace_open':([7,24,54,56,62,63,77,88,162,163,170,266,289,297,336,375,384,390,395,396,402,411,423,425,427,441,443,446,],[57,64,91,92,98,99,155,170,155,170,170,155,170,170,399,170,170,399,399,399,155,170,170,170,170,170,170,170,]),'assignment_operator':([120,],[213,]),'struct_or_union':([0,1,14,22,42,44,48,57,66,78,80,89,91,92,93,94,96,141,165,167,170,172,173,204,219,229,230,233,289,338,373,],[7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,]),'identifier':([66,72,77,103,127,134,137,141,142,162,164,170,181,192,195,196,203,213,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,263,264,266,281,288,289,297,309,335,336,373,375,376,380,384,385,393,394,395,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[114,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,318,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,360,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,417,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,]),'struct_declaration':([57,91,92,93,172,173,],[95,95,95,175,175,175,]),'assignment_expression':([72,77,103,141,162,164,170,195,196,213,219,226,227,230,233,257,266,281,289,297,335,373,375,376,380,384,385,393,402,408,411,421,423,425,426,427,432,438,441,443,446,],[136,156,136,238,156,136,238,316,317,321,238,238,328,238,238,238,156,238,238,238,397,238,238,238,238,238,238,416,156,238,238,238,238,238,238,238,238,238,238,238,238,]),'parameter_type_list':([66,78,165,167,338,],[108,159,159,159,159,]),'type_qualifier_list_opt':([28,65,105,],[68,103,196,]),'direct_declarator':([0,4,16,22,30,74,78,86,97,110,117,166,167,306,],[26,26,60,26,26,60,26,26,26,26,26,60,26,26,]),'type_qualifier_list':([28,65,105,],[67,104,67,]),'designator':([155,267,362,399,429,],[262,364,262,262,262,]),'argument_expression_list':([227,],[330,]),'initializer':([77,162,266,402,],[154,271,363,420,]),'specifier_qualifier_list_opt':([94,96,],[178,180,]),'constant_expression':([181,192,264,288,309,],[304,313,361,377,387,]),'expression_opt':([170,289,297,373,375,384,408,411,421,423,425,427,432,438,441,443,446,],[279,279,279,407,279,279,422,279,431,279,279,279,439,442,279,279,279,]),'primary_expression':([72,77,103,127,134,137,141,142,162,164,170,181,192,195,196,213,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,264,266,281,288,289,297,309,335,336,373,375,376,380,384,385,393,395,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,]),'declaration_specifiers':([0,1,14,22,42,44,48,66,78,80,89,165,167,170,204,289,338,373,],[30,52,52,30,52,52,86,110,110,86,86,110,110,86,110,86,110,86,]),'declaration':([0,22,48,80,89,170,289,373,],[31,31,87,87,171,292,292,408,]),'struct_declarator_list_opt':([97,],[183,]),'identifier_list':([66,],[111,]),'typedef_name':([0,1,14,22,42,44,48,57,66,78,80,89,91,92,93,94,96,141,165,167,170,172,173,204,219,229,230,233,289,338,373,],[29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,]),'parameter_type_list_opt':([78,165,167,338,],[160,275,160,160,]),'jump_statement':([170,289,297,375,384,411,423,425,427,441,443,446,],[293,293,293,293,293,293,293,293,293,293,293,293,]),'declaration_list_opt':([48,80,],[88,163,]),'struct_declarator':([97,306,],[184,386,]),'function_definition':([0,22,],[36,36,]),'binary_expression':([72,77,103,141,162,164,170,181,192,195,196,213,219,226,227,230,233,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,264,266,281,288,289,297,309,335,373,375,376,380,384,385,393,400,402,408,411,421,423,425,426,427,432,438,441,443,446,],[147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,147,357,358,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,]),'parameter_list':([66,78,165,167,338,],[113,113,113,113,113,]),'init_declarator_list_opt':([30,86,],[73,73,]),'enum_specifier':([0,1,14,22,42,44,48,57,66,78,80,89,91,92,93,94,96,141,165,167,170,172,173,204,219,229,230,233,289,338,373,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'decl_body':([0,22,48,80,89,170,289,373,],[41,41,41,41,41,41,41,41,]),'type_qualifier':([0,1,14,22,28,42,44,48,57,65,66,67,78,80,89,91,92,93,94,96,104,105,141,165,167,170,172,173,204,219,229,230,233,289,338,373,],[42,42,42,42,69,42,42,42,96,69,42,115,42,42,42,96,96,96,96,96,115,69,96,42,42,42,96,96,42,96,96,96,96,42,42,42,]),'statement':([170,289,297,375,384,411,423,425,427,441,443,446,],[291,291,382,409,414,424,433,434,436,445,447,448,]),'enumerator_list':([64,98,99,],[101,188,189,]),'labeled_statement':([170,289,297,375,384,411,423,425,427,441,443,446,],[280,280,280,280,280,280,280,280,280,280,280,280,]),'function_specifier':([0,1,14,22,42,44,48,66,78,80,89,165,167,170,204,289,338,373,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'specifier_qualifier_list':([57,91,92,93,94,96,141,172,173,219,229,230,233,],[97,97,97,97,179,179,239,97,97,239,239,239,239,]),'block_item':([170,289,],[295,379,]),'block_item_list':([170,],[289,]),'empty':([0,1,14,28,30,42,44,48,65,66,72,78,80,86,94,96,97,103,105,110,155,164,165,167,170,239,289,297,338,362,373,375,384,399,408,411,421,423,425,427,429,432,438,441,443,446,],[47,51,51,70,76,51,51,85,70,107,150,158,85,76,177,177,186,150,70,200,268,150,158,158,296,200,378,378,158,403,378,378,378,403,378,378,378,378,378,378,403,378,378,378,378,378,]),'translation_unit':([0,],[22,]),'initializer_list':([155,399,],[265,418,]),'declarator':([0,4,22,30,78,86,97,110,117,167,306,],[48,53,48,80,53,168,187,202,168,53,187,]),'direct_abstract_declarator':([30,74,78,86,97,110,166,167,239,338,339,],[81,153,81,81,81,81,153,81,81,81,153,]),'designator_list':([155,362,399,429,],[267,267,267,267,]),'declaration_list':([48,80,],[89,89,]),'expression':([141,170,219,226,230,233,257,281,289,297,373,375,376,380,384,385,408,411,421,423,425,426,427,432,438,441,443,446,],[236,285,236,327,236,236,356,372,285,285,285,285,410,412,285,415,285,285,285,285,285,435,285,285,285,285,285,285,]),} _lr_goto = { } for _k, _v in _lr_goto_items.items(): for _x,_y in zip(_v[0],_v[1]): if not _x in _lr_goto: _lr_goto[_x] = { } _lr_goto[_x][_k] = _y del _lr_goto_items _lr_productions = [ ("S' -> translation_unit_or_empty","S'",1,None,None,None), ('abstract_declarator_opt -> empty','abstract_declarator_opt',1,'p_abstract_declarator_opt','../pycparser/plyparser.py',42), ('abstract_declarator_opt -> abstract_declarator','abstract_declarator_opt',1,'p_abstract_declarator_opt','../pycparser/plyparser.py',43), ('assignment_expression_opt -> empty','assignment_expression_opt',1,'p_assignment_expression_opt','../pycparser/plyparser.py',42), ('assignment_expression_opt -> assignment_expression','assignment_expression_opt',1,'p_assignment_expression_opt','../pycparser/plyparser.py',43), ('block_item_list_opt -> empty','block_item_list_opt',1,'p_block_item_list_opt','../pycparser/plyparser.py',42), ('block_item_list_opt -> block_item_list','block_item_list_opt',1,'p_block_item_list_opt','../pycparser/plyparser.py',43), ('declaration_list_opt -> empty','declaration_list_opt',1,'p_declaration_list_opt','../pycparser/plyparser.py',42), ('declaration_list_opt -> declaration_list','declaration_list_opt',1,'p_declaration_list_opt','../pycparser/plyparser.py',43), ('declaration_specifiers_opt -> empty','declaration_specifiers_opt',1,'p_declaration_specifiers_opt','../pycparser/plyparser.py',42), ('declaration_specifiers_opt -> declaration_specifiers','declaration_specifiers_opt',1,'p_declaration_specifiers_opt','../pycparser/plyparser.py',43), ('designation_opt -> empty','designation_opt',1,'p_designation_opt','../pycparser/plyparser.py',42), ('designation_opt -> designation','designation_opt',1,'p_designation_opt','../pycparser/plyparser.py',43), ('expression_opt -> empty','expression_opt',1,'p_expression_opt','../pycparser/plyparser.py',42), ('expression_opt -> expression','expression_opt',1,'p_expression_opt','../pycparser/plyparser.py',43), ('identifier_list_opt -> empty','identifier_list_opt',1,'p_identifier_list_opt','../pycparser/plyparser.py',42), ('identifier_list_opt -> identifier_list','identifier_list_opt',1,'p_identifier_list_opt','../pycparser/plyparser.py',43), ('init_declarator_list_opt -> empty','init_declarator_list_opt',1,'p_init_declarator_list_opt','../pycparser/plyparser.py',42), ('init_declarator_list_opt -> init_declarator_list','init_declarator_list_opt',1,'p_init_declarator_list_opt','../pycparser/plyparser.py',43), ('initializer_list_opt -> empty','initializer_list_opt',1,'p_initializer_list_opt','../pycparser/plyparser.py',42), ('initializer_list_opt -> initializer_list','initializer_list_opt',1,'p_initializer_list_opt','../pycparser/plyparser.py',43), ('parameter_type_list_opt -> empty','parameter_type_list_opt',1,'p_parameter_type_list_opt','../pycparser/plyparser.py',42), ('parameter_type_list_opt -> parameter_type_list','parameter_type_list_opt',1,'p_parameter_type_list_opt','../pycparser/plyparser.py',43), ('specifier_qualifier_list_opt -> empty','specifier_qualifier_list_opt',1,'p_specifier_qualifier_list_opt','../pycparser/plyparser.py',42), ('specifier_qualifier_list_opt -> specifier_qualifier_list','specifier_qualifier_list_opt',1,'p_specifier_qualifier_list_opt','../pycparser/plyparser.py',43), ('struct_declarator_list_opt -> empty','struct_declarator_list_opt',1,'p_struct_declarator_list_opt','../pycparser/plyparser.py',42), ('struct_declarator_list_opt -> struct_declarator_list','struct_declarator_list_opt',1,'p_struct_declarator_list_opt','../pycparser/plyparser.py',43), ('type_qualifier_list_opt -> empty','type_qualifier_list_opt',1,'p_type_qualifier_list_opt','../pycparser/plyparser.py',42), ('type_qualifier_list_opt -> type_qualifier_list','type_qualifier_list_opt',1,'p_type_qualifier_list_opt','../pycparser/plyparser.py',43), ('translation_unit_or_empty -> translation_unit','translation_unit_or_empty',1,'p_translation_unit_or_empty','../pycparser/c_parser.py',494), ('translation_unit_or_empty -> empty','translation_unit_or_empty',1,'p_translation_unit_or_empty','../pycparser/c_parser.py',495), ('translation_unit -> external_declaration','translation_unit',1,'p_translation_unit_1','../pycparser/c_parser.py',503), ('translation_unit -> translation_unit external_declaration','translation_unit',2,'p_translation_unit_2','../pycparser/c_parser.py',510), ('external_declaration -> function_definition','external_declaration',1,'p_external_declaration_1','../pycparser/c_parser.py',522), ('external_declaration -> declaration','external_declaration',1,'p_external_declaration_2','../pycparser/c_parser.py',527), ('external_declaration -> pp_directive','external_declaration',1,'p_external_declaration_3','../pycparser/c_parser.py',532), ('external_declaration -> SEMI','external_declaration',1,'p_external_declaration_4','../pycparser/c_parser.py',537), ('pp_directive -> PPHASH','pp_directive',1,'p_pp_directive','../pycparser/c_parser.py',542), ('function_definition -> declarator declaration_list_opt compound_statement','function_definition',3,'p_function_definition_1','../pycparser/c_parser.py',551), ('function_definition -> declaration_specifiers declarator declaration_list_opt compound_statement','function_definition',4,'p_function_definition_2','../pycparser/c_parser.py',568), ('statement -> labeled_statement','statement',1,'p_statement','../pycparser/c_parser.py',579), ('statement -> expression_statement','statement',1,'p_statement','../pycparser/c_parser.py',580), ('statement -> compound_statement','statement',1,'p_statement','../pycparser/c_parser.py',581), ('statement -> selection_statement','statement',1,'p_statement','../pycparser/c_parser.py',582), ('statement -> iteration_statement','statement',1,'p_statement','../pycparser/c_parser.py',583), ('statement -> jump_statement','statement',1,'p_statement','../pycparser/c_parser.py',584), ('decl_body -> declaration_specifiers init_declarator_list_opt','decl_body',2,'p_decl_body','../pycparser/c_parser.py',598), ('declaration -> decl_body SEMI','declaration',2,'p_declaration','../pycparser/c_parser.py',657), ('declaration_list -> declaration','declaration_list',1,'p_declaration_list','../pycparser/c_parser.py',666), ('declaration_list -> declaration_list declaration','declaration_list',2,'p_declaration_list','../pycparser/c_parser.py',667), ('declaration_specifiers -> type_qualifier declaration_specifiers_opt','declaration_specifiers',2,'p_declaration_specifiers_1','../pycparser/c_parser.py',672), ('declaration_specifiers -> type_specifier declaration_specifiers_opt','declaration_specifiers',2,'p_declaration_specifiers_2','../pycparser/c_parser.py',677), ('declaration_specifiers -> storage_class_specifier declaration_specifiers_opt','declaration_specifiers',2,'p_declaration_specifiers_3','../pycparser/c_parser.py',682), ('declaration_specifiers -> function_specifier declaration_specifiers_opt','declaration_specifiers',2,'p_declaration_specifiers_4','../pycparser/c_parser.py',687), ('storage_class_specifier -> AUTO','storage_class_specifier',1,'p_storage_class_specifier','../pycparser/c_parser.py',692), ('storage_class_specifier -> REGISTER','storage_class_specifier',1,'p_storage_class_specifier','../pycparser/c_parser.py',693), ('storage_class_specifier -> STATIC','storage_class_specifier',1,'p_storage_class_specifier','../pycparser/c_parser.py',694), ('storage_class_specifier -> EXTERN','storage_class_specifier',1,'p_storage_class_specifier','../pycparser/c_parser.py',695), ('storage_class_specifier -> TYPEDEF','storage_class_specifier',1,'p_storage_class_specifier','../pycparser/c_parser.py',696), ('function_specifier -> INLINE','function_specifier',1,'p_function_specifier','../pycparser/c_parser.py',701), ('type_specifier -> VOID','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',706), ('type_specifier -> _BOOL','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',707), ('type_specifier -> CHAR','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',708), ('type_specifier -> SHORT','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',709), ('type_specifier -> INT','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',710), ('type_specifier -> LONG','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',711), ('type_specifier -> FLOAT','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',712), ('type_specifier -> DOUBLE','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',713), ('type_specifier -> _COMPLEX','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',714), ('type_specifier -> SIGNED','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',715), ('type_specifier -> UNSIGNED','type_specifier',1,'p_type_specifier_1','../pycparser/c_parser.py',716), ('type_specifier -> typedef_name','type_specifier',1,'p_type_specifier_2','../pycparser/c_parser.py',721), ('type_specifier -> enum_specifier','type_specifier',1,'p_type_specifier_2','../pycparser/c_parser.py',722), ('type_specifier -> struct_or_union_specifier','type_specifier',1,'p_type_specifier_2','../pycparser/c_parser.py',723), ('type_qualifier -> CONST','type_qualifier',1,'p_type_qualifier','../pycparser/c_parser.py',728), ('type_qualifier -> RESTRICT','type_qualifier',1,'p_type_qualifier','../pycparser/c_parser.py',729), ('type_qualifier -> VOLATILE','type_qualifier',1,'p_type_qualifier','../pycparser/c_parser.py',730), ('init_declarator_list -> init_declarator','init_declarator_list',1,'p_init_declarator_list_1','../pycparser/c_parser.py',735), ('init_declarator_list -> init_declarator_list COMMA init_declarator','init_declarator_list',3,'p_init_declarator_list_1','../pycparser/c_parser.py',736), ('init_declarator_list -> EQUALS initializer','init_declarator_list',2,'p_init_declarator_list_2','../pycparser/c_parser.py',746), ('init_declarator_list -> abstract_declarator','init_declarator_list',1,'p_init_declarator_list_3','../pycparser/c_parser.py',754), ('init_declarator -> declarator','init_declarator',1,'p_init_declarator','../pycparser/c_parser.py',762), ('init_declarator -> declarator EQUALS initializer','init_declarator',3,'p_init_declarator','../pycparser/c_parser.py',763), ('specifier_qualifier_list -> type_qualifier specifier_qualifier_list_opt','specifier_qualifier_list',2,'p_specifier_qualifier_list_1','../pycparser/c_parser.py',768), ('specifier_qualifier_list -> type_specifier specifier_qualifier_list_opt','specifier_qualifier_list',2,'p_specifier_qualifier_list_2','../pycparser/c_parser.py',773), ('struct_or_union_specifier -> struct_or_union ID','struct_or_union_specifier',2,'p_struct_or_union_specifier_1','../pycparser/c_parser.py',781), ('struct_or_union_specifier -> struct_or_union TYPEID','struct_or_union_specifier',2,'p_struct_or_union_specifier_1','../pycparser/c_parser.py',782), ('struct_or_union_specifier -> struct_or_union brace_open struct_declaration_list brace_close','struct_or_union_specifier',4,'p_struct_or_union_specifier_2','../pycparser/c_parser.py',791), ('struct_or_union_specifier -> struct_or_union ID brace_open struct_declaration_list brace_close','struct_or_union_specifier',5,'p_struct_or_union_specifier_3','../pycparser/c_parser.py',800), ('struct_or_union_specifier -> struct_or_union TYPEID brace_open struct_declaration_list brace_close','struct_or_union_specifier',5,'p_struct_or_union_specifier_3','../pycparser/c_parser.py',801), ('struct_or_union -> STRUCT','struct_or_union',1,'p_struct_or_union','../pycparser/c_parser.py',810), ('struct_or_union -> UNION','struct_or_union',1,'p_struct_or_union','../pycparser/c_parser.py',811), ('struct_declaration_list -> struct_declaration','struct_declaration_list',1,'p_struct_declaration_list','../pycparser/c_parser.py',818), ('struct_declaration_list -> struct_declaration_list struct_declaration','struct_declaration_list',2,'p_struct_declaration_list','../pycparser/c_parser.py',819), ('struct_declaration -> specifier_qualifier_list struct_declarator_list_opt SEMI','struct_declaration',3,'p_struct_declaration_1','../pycparser/c_parser.py',824), ('struct_declaration -> specifier_qualifier_list abstract_declarator SEMI','struct_declaration',3,'p_struct_declaration_2','../pycparser/c_parser.py',862), ('struct_declarator_list -> struct_declarator','struct_declarator_list',1,'p_struct_declarator_list','../pycparser/c_parser.py',876), ('struct_declarator_list -> struct_declarator_list COMMA struct_declarator','struct_declarator_list',3,'p_struct_declarator_list','../pycparser/c_parser.py',877), ('struct_declarator -> declarator','struct_declarator',1,'p_struct_declarator_1','../pycparser/c_parser.py',885), ('struct_declarator -> declarator COLON constant_expression','struct_declarator',3,'p_struct_declarator_2','../pycparser/c_parser.py',890), ('struct_declarator -> COLON constant_expression','struct_declarator',2,'p_struct_declarator_2','../pycparser/c_parser.py',891), ('enum_specifier -> ENUM ID','enum_specifier',2,'p_enum_specifier_1','../pycparser/c_parser.py',899), ('enum_specifier -> ENUM TYPEID','enum_specifier',2,'p_enum_specifier_1','../pycparser/c_parser.py',900), ('enum_specifier -> ENUM brace_open enumerator_list brace_close','enum_specifier',4,'p_enum_specifier_2','../pycparser/c_parser.py',905), ('enum_specifier -> ENUM ID brace_open enumerator_list brace_close','enum_specifier',5,'p_enum_specifier_3','../pycparser/c_parser.py',910), ('enum_specifier -> ENUM TYPEID brace_open enumerator_list brace_close','enum_specifier',5,'p_enum_specifier_3','../pycparser/c_parser.py',911), ('enumerator_list -> enumerator','enumerator_list',1,'p_enumerator_list','../pycparser/c_parser.py',916), ('enumerator_list -> enumerator_list COMMA','enumerator_list',2,'p_enumerator_list','../pycparser/c_parser.py',917), ('enumerator_list -> enumerator_list COMMA enumerator','enumerator_list',3,'p_enumerator_list','../pycparser/c_parser.py',918), ('enumerator -> ID','enumerator',1,'p_enumerator','../pycparser/c_parser.py',929), ('enumerator -> ID EQUALS constant_expression','enumerator',3,'p_enumerator','../pycparser/c_parser.py',930), ('declarator -> direct_declarator','declarator',1,'p_declarator_1','../pycparser/c_parser.py',945), ('declarator -> pointer direct_declarator','declarator',2,'p_declarator_2','../pycparser/c_parser.py',950), ('declarator -> pointer TYPEID','declarator',2,'p_declarator_3','../pycparser/c_parser.py',959), ('direct_declarator -> ID','direct_declarator',1,'p_direct_declarator_1','../pycparser/c_parser.py',970), ('direct_declarator -> LPAREN declarator RPAREN','direct_declarator',3,'p_direct_declarator_2','../pycparser/c_parser.py',979), ('direct_declarator -> direct_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET','direct_declarator',5,'p_direct_declarator_3','../pycparser/c_parser.py',984), ('direct_declarator -> direct_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET','direct_declarator',6,'p_direct_declarator_4','../pycparser/c_parser.py',998), ('direct_declarator -> direct_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET','direct_declarator',6,'p_direct_declarator_4','../pycparser/c_parser.py',999), ('direct_declarator -> direct_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET','direct_declarator',5,'p_direct_declarator_5','../pycparser/c_parser.py',1019), ('direct_declarator -> direct_declarator LPAREN parameter_type_list RPAREN','direct_declarator',4,'p_direct_declarator_6','../pycparser/c_parser.py',1030), ('direct_declarator -> direct_declarator LPAREN identifier_list_opt RPAREN','direct_declarator',4,'p_direct_declarator_6','../pycparser/c_parser.py',1031), ('pointer -> TIMES type_qualifier_list_opt','pointer',2,'p_pointer','../pycparser/c_parser.py',1058), ('pointer -> TIMES type_qualifier_list_opt pointer','pointer',3,'p_pointer','../pycparser/c_parser.py',1059), ('type_qualifier_list -> type_qualifier','type_qualifier_list',1,'p_type_qualifier_list','../pycparser/c_parser.py',1088), ('type_qualifier_list -> type_qualifier_list type_qualifier','type_qualifier_list',2,'p_type_qualifier_list','../pycparser/c_parser.py',1089), ('parameter_type_list -> parameter_list','parameter_type_list',1,'p_parameter_type_list','../pycparser/c_parser.py',1094), ('parameter_type_list -> parameter_list COMMA ELLIPSIS','parameter_type_list',3,'p_parameter_type_list','../pycparser/c_parser.py',1095), ('parameter_list -> parameter_declaration','parameter_list',1,'p_parameter_list','../pycparser/c_parser.py',1103), ('parameter_list -> parameter_list COMMA parameter_declaration','parameter_list',3,'p_parameter_list','../pycparser/c_parser.py',1104), ('parameter_declaration -> declaration_specifiers declarator','parameter_declaration',2,'p_parameter_declaration_1','../pycparser/c_parser.py',1113), ('parameter_declaration -> declaration_specifiers abstract_declarator_opt','parameter_declaration',2,'p_parameter_declaration_2','../pycparser/c_parser.py',1124), ('identifier_list -> identifier','identifier_list',1,'p_identifier_list','../pycparser/c_parser.py',1155), ('identifier_list -> identifier_list COMMA identifier','identifier_list',3,'p_identifier_list','../pycparser/c_parser.py',1156), ('initializer -> assignment_expression','initializer',1,'p_initializer_1','../pycparser/c_parser.py',1165), ('initializer -> brace_open initializer_list_opt brace_close','initializer',3,'p_initializer_2','../pycparser/c_parser.py',1170), ('initializer -> brace_open initializer_list COMMA brace_close','initializer',4,'p_initializer_2','../pycparser/c_parser.py',1171), ('initializer_list -> designation_opt initializer','initializer_list',2,'p_initializer_list','../pycparser/c_parser.py',1179), ('initializer_list -> initializer_list COMMA designation_opt initializer','initializer_list',4,'p_initializer_list','../pycparser/c_parser.py',1180), ('designation -> designator_list EQUALS','designation',2,'p_designation','../pycparser/c_parser.py',1191), ('designator_list -> designator','designator_list',1,'p_designator_list','../pycparser/c_parser.py',1199), ('designator_list -> designator_list designator','designator_list',2,'p_designator_list','../pycparser/c_parser.py',1200), ('designator -> LBRACKET constant_expression RBRACKET','designator',3,'p_designator','../pycparser/c_parser.py',1205), ('designator -> PERIOD identifier','designator',2,'p_designator','../pycparser/c_parser.py',1206), ('type_name -> specifier_qualifier_list abstract_declarator_opt','type_name',2,'p_type_name','../pycparser/c_parser.py',1211), ('abstract_declarator -> pointer','abstract_declarator',1,'p_abstract_declarator_1','../pycparser/c_parser.py',1228), ('abstract_declarator -> pointer direct_abstract_declarator','abstract_declarator',2,'p_abstract_declarator_2','../pycparser/c_parser.py',1236), ('abstract_declarator -> direct_abstract_declarator','abstract_declarator',1,'p_abstract_declarator_3','../pycparser/c_parser.py',1241), ('direct_abstract_declarator -> LPAREN abstract_declarator RPAREN','direct_abstract_declarator',3,'p_direct_abstract_declarator_1','../pycparser/c_parser.py',1251), ('direct_abstract_declarator -> direct_abstract_declarator LBRACKET assignment_expression_opt RBRACKET','direct_abstract_declarator',4,'p_direct_abstract_declarator_2','../pycparser/c_parser.py',1255), ('direct_abstract_declarator -> LBRACKET assignment_expression_opt RBRACKET','direct_abstract_declarator',3,'p_direct_abstract_declarator_3','../pycparser/c_parser.py',1266), ('direct_abstract_declarator -> direct_abstract_declarator LBRACKET TIMES RBRACKET','direct_abstract_declarator',4,'p_direct_abstract_declarator_4','../pycparser/c_parser.py',1275), ('direct_abstract_declarator -> LBRACKET TIMES RBRACKET','direct_abstract_declarator',3,'p_direct_abstract_declarator_5','../pycparser/c_parser.py',1286), ('direct_abstract_declarator -> direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN','direct_abstract_declarator',4,'p_direct_abstract_declarator_6','../pycparser/c_parser.py',1295), ('direct_abstract_declarator -> LPAREN parameter_type_list_opt RPAREN','direct_abstract_declarator',3,'p_direct_abstract_declarator_7','../pycparser/c_parser.py',1305), ('block_item -> declaration','block_item',1,'p_block_item','../pycparser/c_parser.py',1316), ('block_item -> statement','block_item',1,'p_block_item','../pycparser/c_parser.py',1317), ('block_item_list -> block_item','block_item_list',1,'p_block_item_list','../pycparser/c_parser.py',1324), ('block_item_list -> block_item_list block_item','block_item_list',2,'p_block_item_list','../pycparser/c_parser.py',1325), ('compound_statement -> brace_open block_item_list_opt brace_close','compound_statement',3,'p_compound_statement_1','../pycparser/c_parser.py',1331), ('labeled_statement -> ID COLON statement','labeled_statement',3,'p_labeled_statement_1','../pycparser/c_parser.py',1337), ('labeled_statement -> CASE constant_expression COLON statement','labeled_statement',4,'p_labeled_statement_2','../pycparser/c_parser.py',1341), ('labeled_statement -> DEFAULT COLON statement','labeled_statement',3,'p_labeled_statement_3','../pycparser/c_parser.py',1345), ('selection_statement -> IF LPAREN expression RPAREN statement','selection_statement',5,'p_selection_statement_1','../pycparser/c_parser.py',1349), ('selection_statement -> IF LPAREN expression RPAREN statement ELSE statement','selection_statement',7,'p_selection_statement_2','../pycparser/c_parser.py',1353), ('selection_statement -> SWITCH LPAREN expression RPAREN statement','selection_statement',5,'p_selection_statement_3','../pycparser/c_parser.py',1357), ('iteration_statement -> WHILE LPAREN expression RPAREN statement','iteration_statement',5,'p_iteration_statement_1','../pycparser/c_parser.py',1362), ('iteration_statement -> DO statement WHILE LPAREN expression RPAREN SEMI','iteration_statement',7,'p_iteration_statement_2','../pycparser/c_parser.py',1366), ('iteration_statement -> FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement','iteration_statement',9,'p_iteration_statement_3','../pycparser/c_parser.py',1370), ('iteration_statement -> FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN statement','iteration_statement',8,'p_iteration_statement_4','../pycparser/c_parser.py',1374), ('jump_statement -> GOTO ID SEMI','jump_statement',3,'p_jump_statement_1','../pycparser/c_parser.py',1379), ('jump_statement -> BREAK SEMI','jump_statement',2,'p_jump_statement_2','../pycparser/c_parser.py',1383), ('jump_statement -> CONTINUE SEMI','jump_statement',2,'p_jump_statement_3','../pycparser/c_parser.py',1387), ('jump_statement -> RETURN expression SEMI','jump_statement',3,'p_jump_statement_4','../pycparser/c_parser.py',1391), ('jump_statement -> RETURN SEMI','jump_statement',2,'p_jump_statement_4','../pycparser/c_parser.py',1392), ('expression_statement -> expression_opt SEMI','expression_statement',2,'p_expression_statement','../pycparser/c_parser.py',1397), ('expression -> assignment_expression','expression',1,'p_expression','../pycparser/c_parser.py',1404), ('expression -> expression COMMA assignment_expression','expression',3,'p_expression','../pycparser/c_parser.py',1405), ('typedef_name -> TYPEID','typedef_name',1,'p_typedef_name','../pycparser/c_parser.py',1417), ('assignment_expression -> conditional_expression','assignment_expression',1,'p_assignment_expression','../pycparser/c_parser.py',1421), ('assignment_expression -> unary_expression assignment_operator assignment_expression','assignment_expression',3,'p_assignment_expression','../pycparser/c_parser.py',1422), ('assignment_operator -> EQUALS','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1435), ('assignment_operator -> XOREQUAL','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1436), ('assignment_operator -> TIMESEQUAL','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1437), ('assignment_operator -> DIVEQUAL','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1438), ('assignment_operator -> MODEQUAL','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1439), ('assignment_operator -> PLUSEQUAL','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1440), ('assignment_operator -> MINUSEQUAL','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1441), ('assignment_operator -> LSHIFTEQUAL','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1442), ('assignment_operator -> RSHIFTEQUAL','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1443), ('assignment_operator -> ANDEQUAL','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1444), ('assignment_operator -> OREQUAL','assignment_operator',1,'p_assignment_operator','../pycparser/c_parser.py',1445), ('constant_expression -> conditional_expression','constant_expression',1,'p_constant_expression','../pycparser/c_parser.py',1450), ('conditional_expression -> binary_expression','conditional_expression',1,'p_conditional_expression','../pycparser/c_parser.py',1454), ('conditional_expression -> binary_expression CONDOP expression COLON conditional_expression','conditional_expression',5,'p_conditional_expression','../pycparser/c_parser.py',1455), ('binary_expression -> cast_expression','binary_expression',1,'p_binary_expression','../pycparser/c_parser.py',1463), ('binary_expression -> binary_expression TIMES binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1464), ('binary_expression -> binary_expression DIVIDE binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1465), ('binary_expression -> binary_expression MOD binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1466), ('binary_expression -> binary_expression PLUS binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1467), ('binary_expression -> binary_expression MINUS binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1468), ('binary_expression -> binary_expression RSHIFT binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1469), ('binary_expression -> binary_expression LSHIFT binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1470), ('binary_expression -> binary_expression LT binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1471), ('binary_expression -> binary_expression LE binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1472), ('binary_expression -> binary_expression GE binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1473), ('binary_expression -> binary_expression GT binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1474), ('binary_expression -> binary_expression EQ binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1475), ('binary_expression -> binary_expression NE binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1476), ('binary_expression -> binary_expression AND binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1477), ('binary_expression -> binary_expression OR binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1478), ('binary_expression -> binary_expression XOR binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1479), ('binary_expression -> binary_expression LAND binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1480), ('binary_expression -> binary_expression LOR binary_expression','binary_expression',3,'p_binary_expression','../pycparser/c_parser.py',1481), ('cast_expression -> unary_expression','cast_expression',1,'p_cast_expression_1','../pycparser/c_parser.py',1489), ('cast_expression -> LPAREN type_name RPAREN cast_expression','cast_expression',4,'p_cast_expression_2','../pycparser/c_parser.py',1493), ('unary_expression -> postfix_expression','unary_expression',1,'p_unary_expression_1','../pycparser/c_parser.py',1497), ('unary_expression -> PLUSPLUS unary_expression','unary_expression',2,'p_unary_expression_2','../pycparser/c_parser.py',1501), ('unary_expression -> MINUSMINUS unary_expression','unary_expression',2,'p_unary_expression_2','../pycparser/c_parser.py',1502), ('unary_expression -> unary_operator cast_expression','unary_expression',2,'p_unary_expression_2','../pycparser/c_parser.py',1503), ('unary_expression -> SIZEOF unary_expression','unary_expression',2,'p_unary_expression_3','../pycparser/c_parser.py',1508), ('unary_expression -> SIZEOF LPAREN type_name RPAREN','unary_expression',4,'p_unary_expression_3','../pycparser/c_parser.py',1509), ('unary_operator -> AND','unary_operator',1,'p_unary_operator','../pycparser/c_parser.py',1517), ('unary_operator -> TIMES','unary_operator',1,'p_unary_operator','../pycparser/c_parser.py',1518), ('unary_operator -> PLUS','unary_operator',1,'p_unary_operator','../pycparser/c_parser.py',1519), ('unary_operator -> MINUS','unary_operator',1,'p_unary_operator','../pycparser/c_parser.py',1520), ('unary_operator -> NOT','unary_operator',1,'p_unary_operator','../pycparser/c_parser.py',1521), ('unary_operator -> LNOT','unary_operator',1,'p_unary_operator','../pycparser/c_parser.py',1522), ('postfix_expression -> primary_expression','postfix_expression',1,'p_postfix_expression_1','../pycparser/c_parser.py',1527), ('postfix_expression -> postfix_expression LBRACKET expression RBRACKET','postfix_expression',4,'p_postfix_expression_2','../pycparser/c_parser.py',1531), ('postfix_expression -> postfix_expression LPAREN argument_expression_list RPAREN','postfix_expression',4,'p_postfix_expression_3','../pycparser/c_parser.py',1535), ('postfix_expression -> postfix_expression LPAREN RPAREN','postfix_expression',3,'p_postfix_expression_3','../pycparser/c_parser.py',1536), ('postfix_expression -> postfix_expression PERIOD ID','postfix_expression',3,'p_postfix_expression_4','../pycparser/c_parser.py',1541), ('postfix_expression -> postfix_expression PERIOD TYPEID','postfix_expression',3,'p_postfix_expression_4','../pycparser/c_parser.py',1542), ('postfix_expression -> postfix_expression ARROW ID','postfix_expression',3,'p_postfix_expression_4','../pycparser/c_parser.py',1543), ('postfix_expression -> postfix_expression ARROW TYPEID','postfix_expression',3,'p_postfix_expression_4','../pycparser/c_parser.py',1544), ('postfix_expression -> postfix_expression PLUSPLUS','postfix_expression',2,'p_postfix_expression_5','../pycparser/c_parser.py',1550), ('postfix_expression -> postfix_expression MINUSMINUS','postfix_expression',2,'p_postfix_expression_5','../pycparser/c_parser.py',1551), ('postfix_expression -> LPAREN type_name RPAREN brace_open initializer_list brace_close','postfix_expression',6,'p_postfix_expression_6','../pycparser/c_parser.py',1556), ('postfix_expression -> LPAREN type_name RPAREN brace_open initializer_list COMMA brace_close','postfix_expression',7,'p_postfix_expression_6','../pycparser/c_parser.py',1557), ('primary_expression -> identifier','primary_expression',1,'p_primary_expression_1','../pycparser/c_parser.py',1562), ('primary_expression -> constant','primary_expression',1,'p_primary_expression_2','../pycparser/c_parser.py',1566), ('primary_expression -> unified_string_literal','primary_expression',1,'p_primary_expression_3','../pycparser/c_parser.py',1570), ('primary_expression -> unified_wstring_literal','primary_expression',1,'p_primary_expression_3','../pycparser/c_parser.py',1571), ('primary_expression -> LPAREN expression RPAREN','primary_expression',3,'p_primary_expression_4','../pycparser/c_parser.py',1576), ('primary_expression -> OFFSETOF LPAREN type_name COMMA identifier RPAREN','primary_expression',6,'p_primary_expression_5','../pycparser/c_parser.py',1580), ('argument_expression_list -> assignment_expression','argument_expression_list',1,'p_argument_expression_list','../pycparser/c_parser.py',1588), ('argument_expression_list -> argument_expression_list COMMA assignment_expression','argument_expression_list',3,'p_argument_expression_list','../pycparser/c_parser.py',1589), ('identifier -> ID','identifier',1,'p_identifier','../pycparser/c_parser.py',1598), ('constant -> INT_CONST_DEC','constant',1,'p_constant_1','../pycparser/c_parser.py',1602), ('constant -> INT_CONST_OCT','constant',1,'p_constant_1','../pycparser/c_parser.py',1603), ('constant -> INT_CONST_HEX','constant',1,'p_constant_1','../pycparser/c_parser.py',1604), ('constant -> INT_CONST_BIN','constant',1,'p_constant_1','../pycparser/c_parser.py',1605), ('constant -> FLOAT_CONST','constant',1,'p_constant_2','../pycparser/c_parser.py',1611), ('constant -> HEX_FLOAT_CONST','constant',1,'p_constant_2','../pycparser/c_parser.py',1612), ('constant -> CHAR_CONST','constant',1,'p_constant_3','../pycparser/c_parser.py',1618), ('constant -> WCHAR_CONST','constant',1,'p_constant_3','../pycparser/c_parser.py',1619), ('unified_string_literal -> STRING_LITERAL','unified_string_literal',1,'p_unified_string_literal','../pycparser/c_parser.py',1630), ('unified_string_literal -> unified_string_literal STRING_LITERAL','unified_string_literal',2,'p_unified_string_literal','../pycparser/c_parser.py',1631), ('unified_wstring_literal -> WSTRING_LITERAL','unified_wstring_literal',1,'p_unified_wstring_literal','../pycparser/c_parser.py',1641), ('unified_wstring_literal -> unified_wstring_literal WSTRING_LITERAL','unified_wstring_literal',2,'p_unified_wstring_literal','../pycparser/c_parser.py',1642), ('brace_open -> LBRACE','brace_open',1,'p_brace_open','../pycparser/c_parser.py',1652), ('brace_close -> RBRACE','brace_close',1,'p_brace_close','../pycparser/c_parser.py',1657), ('empty -> ','empty',0,'p_empty','../pycparser/c_parser.py',1662), ] pycparser-2.14/pycparser/__init__.py0000644000175000017500000000552712535723772020335 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # pycparser: __init__.py # # This package file exports some convenience functions for # interacting with pycparser # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- __all__ = ['c_lexer', 'c_parser', 'c_ast'] __version__ = '2.14' from subprocess import Popen, PIPE from .c_parser import CParser def preprocess_file(filename, cpp_path='cpp', cpp_args=''): """ Preprocess a file using cpp. filename: Name of the file you want to preprocess. cpp_path: cpp_args: Refer to the documentation of parse_file for the meaning of these arguments. When successful, returns the preprocessed file's contents. Errors from cpp will be printed out. """ path_list = [cpp_path] if isinstance(cpp_args, list): path_list += cpp_args elif cpp_args != '': path_list += [cpp_args] path_list += [filename] try: # Note the use of universal_newlines to treat all newlines # as \n for Python's purpose # pipe = Popen( path_list, stdout=PIPE, universal_newlines=True) text = pipe.communicate()[0] except OSError as e: raise RuntimeError("Unable to invoke 'cpp'. " + 'Make sure its path was passed correctly\n' + ('Original error: %s' % e)) return text def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='', parser=None): """ Parse a C file using pycparser. filename: Name of the file you want to parse. use_cpp: Set to True if you want to execute the C pre-processor on the file prior to parsing it. cpp_path: If use_cpp is True, this is the path to 'cpp' on your system. If no path is provided, it attempts to just execute 'cpp', so it must be in your PATH. cpp_args: If use_cpp is True, set this to the command line arguments strings to cpp. Be careful with quotes - it's best to pass a raw string (r'') here. For example: r'-I../utils/fake_libc_include' If several arguments are required, pass a list of strings. parser: Optional parser object to be used instead of the default CParser When successful, an AST is returned. ParseError can be thrown if the file doesn't parse successfully. Errors from cpp will be printed out. """ if use_cpp: text = preprocess_file(filename, cpp_path, cpp_args) else: with open(filename, 'rU') as f: text = f.read() if parser is None: parser = CParser() return parser.parse(text, filename) pycparser-2.14/PKG-INFO0000664000175000017500000000113212535724325015272 0ustar elibeneliben00000000000000Metadata-Version: 1.1 Name: pycparser Version: 2.14 Summary: C parser in Python Home-page: https://github.com/eliben/pycparser Author: Eli Bendersky Author-email: eliben@gmail.com License: BSD Description: pycparser is a complete parser of the C language, written in pure Python using the PLY parsing library. It parses C code into an AST and can serve as a front-end for C compilers or analysis tools. Platform: Cross Platform Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 3 pycparser-2.14/setup.cfg0000664000175000017500000000007312535724325016021 0ustar elibeneliben00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 pycparser-2.14/examples/0000775000175000017500000000000012535724325016016 5ustar elibeneliben00000000000000pycparser-2.14/examples/func_defs.py0000644000175000017500000000231612515542015020314 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # pycparser: func_defs.py # # Using pycparser for printing out all the functions defined in a # C file. # # This is a simple example of traversing the AST generated by # pycparser. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- from __future__ import print_function import sys # This is not required if you've installed pycparser into # your site-packages/ with setup.py sys.path.extend(['.', '..']) from pycparser import c_parser, c_ast, parse_file # A simple visitor for FuncDef nodes that prints the names and # locations of function definitions. class FuncDefVisitor(c_ast.NodeVisitor): def visit_FuncDef(self, node): print('%s at %s' % (node.decl.name, node.decl.coord)) def show_func_defs(filename): # Note that cpp is used. Provide a path to your own cpp or # make sure one exists in PATH. ast = parse_file(filename, use_cpp=True) v = FuncDefVisitor() v.visit(ast) if __name__ == "__main__": if len(sys.argv) > 1: filename = sys.argv[1] else: filename = 'examples/c_files/memmgr.c' show_func_defs(filename) pycparser-2.14/examples/using_gcc_E_libc.py0000644000175000017500000000163212515542117021561 0ustar elibeneliben00000000000000#------------------------------------------------------------------------------- # pycparser: using_gcc_E_libc.py # # Similar to the using_cpp_libc.py example, but uses 'gcc -E' instead # of 'cpp'. The same can be achieved with Clang instead of gcc. If you have # Clang installed, simply replace 'gcc' with 'clang' here. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #------------------------------------------------------------------------------- import sys # This is not required if you've installed pycparser into # your site-packages/ with setup.py # sys.path.extend(['.', '..']) from pycparser import parse_file if __name__ == "__main__": if len(sys.argv) > 1: filename = sys.argv[1] else: filename = 'examples/c_files/year.c' ast = parse_file(filename, use_cpp=True, cpp_path='gcc', cpp_args=['-E', r'-Iutils/fake_libc_include']) ast.show() pycparser-2.14/examples/c_files/0000775000175000017500000000000012535724325017422 5ustar elibeneliben00000000000000pycparser-2.14/examples/c_files/memmgr.c0000644000175000017500000001241712257601020021040 0ustar elibeneliben00000000000000//---------------------------------------------------------------- // Statically-allocated memory manager // // by Eli Bendersky (eliben@gmail.com) // // This code is in the public domain. //---------------------------------------------------------------- #include "memmgr.h" typedef ulong Align; union mem_header_union { struct { // Pointer to the next block in the free list // union mem_header_union* next; // Size of the block (in quantas of sizeof(mem_header_t)) // ulong size; } s; // Used to align headers in memory to a boundary // Align align_dummy; }; typedef union mem_header_union mem_header_t; // Initial empty list // static mem_header_t base; // Start of free list // static mem_header_t* freep = 0; // Static pool for new allocations // static byte pool[POOL_SIZE] = {0}; static ulong pool_free_pos = 0; void memmgr_init() { base.s.next = 0; base.s.size = 0; freep = 0; pool_free_pos = 0; } static mem_header_t* get_mem_from_pool(ulong nquantas) { ulong total_req_size; mem_header_t* h; if (nquantas < MIN_POOL_ALLOC_QUANTAS) nquantas = MIN_POOL_ALLOC_QUANTAS; total_req_size = nquantas * sizeof(mem_header_t); if (pool_free_pos + total_req_size <= POOL_SIZE) { h = (mem_header_t*) (pool + pool_free_pos); h->s.size = nquantas; memmgr_free((void*) (h + 1)); pool_free_pos += total_req_size; } else { return 0; } return freep; } // Allocations are done in 'quantas' of header size. // The search for a free block of adequate size begins at the point 'freep' // where the last block was found. // If a too-big block is found, it is split and the tail is returned (this // way the header of the original needs only to have its size adjusted). // The pointer returned to the user points to the free space within the block, // which begins one quanta after the header. // void* memmgr_alloc(ulong nbytes) { mem_header_t* p; mem_header_t* prevp; // Calculate how many quantas are required: we need enough to house all // the requested bytes, plus the header. The -1 and +1 are there to make sure // that if nbytes is a multiple of nquantas, we don't allocate too much // ulong nquantas = (nbytes + sizeof(mem_header_t) - 1) / sizeof(mem_header_t) + 1; // First alloc call, and no free list yet ? Use 'base' for an initial // denegerate block of size 0, which points to itself // if ((prevp = freep) == 0) { base.s.next = freep = prevp = &base; base.s.size = 0; } for (p = prevp->s.next; ; prevp = p, p = p->s.next) { // big enough ? if (p->s.size >= nquantas) { // exactly ? if (p->s.size == nquantas) { // just eliminate this block from the free list by pointing // its prev's next to its next // prevp->s.next = p->s.next; } else // too big { p->s.size -= nquantas; p += p->s.size; p->s.size = nquantas; } freep = prevp; return (void*) (p + 1); } // Reached end of free list ? // Try to allocate the block from the pool. If that succeeds, // get_mem_from_pool adds the new block to the free list and // it will be found in the following iterations. If the call // to get_mem_from_pool doesn't succeed, we've run out of // memory // else if (p == freep) { if ((p = get_mem_from_pool(nquantas)) == 0) { #ifdef DEBUG_MEMMGR_FATAL printf("!! Memory allocation failed !!\n"); #endif return 0; } } } } // Scans the free list, starting at freep, looking the the place to insert the // free block. This is either between two existing blocks or at the end of the // list. In any case, if the block being freed is adjacent to either neighbor, // the adjacent blocks are combined. // void memmgr_free(void* ap) { mem_header_t* block; mem_header_t* p; // acquire pointer to block header block = ((mem_header_t*) ap) - 1; // Find the correct place to place the block in (the free list is sorted by // address, increasing order) // for (p = freep; !(block > p && block < p->s.next); p = p->s.next) { // Since the free list is circular, there is one link where a // higher-addressed block points to a lower-addressed block. // This condition checks if the block should be actually // inserted between them // if (p >= p->s.next && (block > p || block < p->s.next)) break; } // Try to combine with the higher neighbor // if (block + block->s.size == p->s.next) { block->s.size += p->s.next->s.size; block->s.next = p->s.next->s.next; } else { block->s.next = p->s.next; } // Try to combine with the lower neighbor // if (p + p->s.size == block) { p->s.size += block->s.size; p->s.next = block->s.next; } else { p->s.next = block; } freep = p; } pycparser-2.14/examples/c_files/hash.c0000644000175000017500000000731612257601020020501 0ustar elibeneliben00000000000000/* ** C implementation of a hash table ADT */ typedef enum tagReturnCode {SUCCESS, FAIL} ReturnCode; typedef struct tagEntry { char* key; char* value; } Entry; typedef struct tagNode { Entry* entry; struct tagNode* next; } Node; typedef struct tagHash { unsigned int table_size; Node** heads; } Hash; static unsigned int hash_func(const char* str, unsigned int table_size) { unsigned int hash_value; unsigned int a = 127; for (hash_value = 0; *str != 0; ++str) hash_value = (a*hash_value + *str) % table_size; return hash_value; } ReturnCode HashCreate(Hash** hash, unsigned int table_size) { unsigned int i; if (table_size < 1) return FAIL; // // Allocate space for the Hash // if (((*hash) = malloc(sizeof(**hash))) == NULL) return FAIL; // // Allocate space for the array of list heads // if (((*hash)->heads = malloc(table_size*sizeof(*((*hash)->heads)))) == NULL) return FAIL; // // Initialize Hash info // for (i = 0; i < table_size; ++i) { (*hash)->heads[i] = NULL; } (*hash)->table_size = table_size; return SUCCESS; } ReturnCode HashInsert(Hash* hash, const Entry* entry) { unsigned int index = hash_func(entry->key, hash->table_size); Node* temp = hash->heads[index]; HashRemove(hash, entry->key); if ((hash->heads[index] = malloc(sizeof(Node))) == NULL) return FAIL; hash->heads[index]->entry = malloc(sizeof(Entry)); hash->heads[index]->entry->key = malloc(strlen(entry->key)+1); hash->heads[index]->entry->value = malloc(strlen(entry->value)+1); strcpy(hash->heads[index]->entry->key, entry->key); strcpy(hash->heads[index]->entry->value, entry->value); hash->heads[index]->next = temp; return SUCCESS; } const Entry* HashFind(const Hash* hash, const char* key) { unsigned int index = hash_func(key, hash->table_size); Node* temp = hash->heads[index]; while (temp != NULL) { if (!strcmp(key, temp->entry->key)) return temp->entry; temp = temp->next; } return NULL; } ReturnCode HashRemove(Hash* hash, const char* key) { unsigned int index = hash_func(key, hash->table_size); Node* temp1 = hash->heads[index]; Node* temp2 = temp1; while (temp1 != NULL) { if (!strcmp(key, temp1->entry->key)) { if (temp1 == hash->heads[index]) hash->heads[index] = hash->heads[index]->next; else temp2->next = temp1->next; free(temp1->entry->key); free(temp1->entry->value); free(temp1->entry); free(temp1); temp1 = NULL; return SUCCESS; } temp2 = temp1; temp1 = temp1->next; } return FAIL; } void HashPrint(Hash* hash, void (*PrintFunc)(char*, char*)) { unsigned int i; if (hash == NULL || hash->heads == NULL) return; for (i = 0; i < hash->table_size; ++i) { Node* temp = hash->heads[i]; while (temp != NULL) { PrintFunc(temp->entry->key, temp->entry->value); temp = temp->next; } } } void HashDestroy(Hash* hash) { unsigned int i; if (hash == NULL) return; for (i = 0; i < hash->table_size; ++i) { Node* temp = hash->heads[i]; while (temp != NULL) { Node* temp2 = temp; free(temp->entry->key); free(temp->entry->value); free(temp->entry); temp = temp->next; free(temp2); } } free(hash->heads); hash->heads = NULL; free(hash); } pycparser-2.14/examples/c_files/year.c0000644000175000017500000000212512326051027020512 0ustar elibeneliben00000000000000#include #include #include void convert(int thousands, int hundreds, int tens, int ones) { char *num[] = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}; char *for_ten[] = {"", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninty"}; char *af_ten[] = {"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen"}; printf("\nThe year in words is:\n"); printf("%s thousand", num[thousands]); if (hundreds != 0) printf(" %s hundred", num[hundreds]); if (tens != 1) printf(" %s %s", for_ten[tens], num[ones]); else printf(" %s", af_ten[ones]); } int main() { int year; int n1000, n100, n10, n1; printf("\nEnter the year (4 digits): "); scanf("%d", &year); if (year > 9999 || year < 1000) { printf("\nError !! The year must contain 4 digits."); exit(EXIT_FAILURE); } n1000 = year/1000; n100 = ((year)%1000)/100; n10 = (year%100)/10; n1 = ((year%10)%10); convert(n1000, n100, n10, n1); return 0; } pycparser-2.14/examples/c_files/memmgr.h0000644000175000017500000000552712257601020021051 0ustar elibeneliben00000000000000//---------------------------------------------------------------- // Statically-allocated memory manager // // by Eli Bendersky (eliben@gmail.com) // // This code is in the public domain. //---------------------------------------------------------------- #ifndef MEMMGR_H #define MEMMGR_H // // Memory manager: dynamically allocates memory from // a fixed pool that is allocated statically at link-time. // // Usage: after calling memmgr_init() in your // initialization routine, just use memmgr_alloc() instead // of malloc() and memmgr_free() instead of free(). // Naturally, you can use the preprocessor to define // malloc() and free() as aliases to memmgr_alloc() and // memmgr_free(). This way the manager will be a drop-in // replacement for the standard C library allocators, and can // be useful for debugging memory allocation problems and // leaks. // // Preprocessor flags you can define to customize the // memory manager: // // DEBUG_MEMMGR_FATAL // Allow printing out a message when allocations fail // // DEBUG_MEMMGR_SUPPORT_STATS // Allow printing out of stats in function // memmgr_print_stats When this is disabled, // memmgr_print_stats does nothing. // // Note that in production code on an embedded system // you'll probably want to keep those undefined, because // they cause printf to be called. // // POOL_SIZE // Size of the pool for new allocations. This is // effectively the heap size of the application, and can // be changed in accordance with the available memory // resources. // // MIN_POOL_ALLOC_QUANTAS // Internally, the memory manager allocates memory in // quantas roughly the size of two ulong objects. To // minimize pool fragmentation in case of multiple allocations // and deallocations, it is advisable to not allocate // blocks that are too small. // This flag sets the minimal ammount of quantas for // an allocation. If the size of a ulong is 4 and you // set this flag to 16, the minimal size of an allocation // will be 4 * 2 * 16 = 128 bytes // If you have a lot of small allocations, keep this value // low to conserve memory. If you have mostly large // allocations, it is best to make it higher, to avoid // fragmentation. // // Notes: // 1. This memory manager is *not thread safe*. Use it only // for single thread/task applications. // #define DEBUG_MEMMGR_SUPPORT_STATS 1 #define POOL_SIZE 8 * 1024 #define MIN_POOL_ALLOC_QUANTAS 16 typedef unsigned char byte; typedef unsigned long ulong; // Initialize the memory manager. This function should be called // only once in the beginning of the program. // void memmgr_init(); // 'malloc' clone // void* memmgr_alloc(ulong nbytes); // 'free' clone // void memmgr_free(void* ap); // Prints statistics about the current state of the memory // manager // void memmgr_print_stats(); #endif // MEMMGR_H pycparser-2.14/examples/c_files/funky.c0000644000175000017500000000031612257601020020703 0ustar elibeneliben00000000000000char foo(void) { return '1'; } int maxout_in(int paste, char** matrix) { char o = foo(); return (int) matrix[1][2] * 5 - paste; } int main() { auto char* multi = "a multi"; } pycparser-2.14/examples/using_cpp_libc.py0000644000175000017500000000154512526364602021351 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # pycparser: using_cpp_libc.py # # Shows how to use the provided 'cpp' (on Windows, substitute for # the 'real' cpp if you're on Linux/Unix) and "fake" libc includes # to parse a file that includes standard C headers. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- import sys # This is not required if you've installed pycparser into # your site-packages/ with setup.py # sys.path.extend(['.', '..']) from pycparser import parse_file if __name__ == "__main__": if len(sys.argv) > 1: filename = sys.argv[1] else: filename = 'examples/c_files/year.c' ast = parse_file(filename, use_cpp=True, cpp_path='cpp', cpp_args=r'-Iutils/fake_libc_include') ast.show() pycparser-2.14/examples/rewrite_ast.py0000664000175000017500000000112712515541763020722 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # pycparser: func_write.py # # Tiny example of rewriting a AST node # # Copyright (C) 2014, Akira Hayakawa # License: BSD #----------------------------------------------------------------- from __future__ import print_function import sys from pycparser import c_parser text = r""" void func(void) { x = 1; } """ parser = c_parser.CParser() ast = parser.parse(text) print("Before:") ast.show(offset=2) assign = ast.ext[0].body.block_items[0] assign.lvalue.name = "y" assign.rvalue.value = 2 print("After:") ast.show(offset=2) pycparser-2.14/examples/cdecl.py0000644000175000017500000000625612515541763017452 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # pycparser: cdecl.py # # Example of the CDECL tool using pycparser. CDECL "explains" C type # declarations in plain English. # # The AST generated by pycparser from the given declaration is traversed # recursively to build the explanation. Note that the declaration must be a # valid external declaration in C. All the types used in it must be defined with # typedef, or parsing will fail. The definition can be arbitrary - pycparser # doesn't really care what the type is defined to be, only that it's a type. # # For example: # # 'typedef int Node; const Node* (*ar)[10];' # => # ar is a pointer to array[10] of pointer to const Node # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- import sys # This is not required if you've installed pycparser into # your site-packages/ with setup.py # sys.path.extend(['.', '..']) from pycparser import c_parser, c_ast def explain_c_declaration(c_decl): """ Parses the declaration in c_decl and returns a text explanation as a string. The last external node of the string is used, to allow earlier typedefs for used types. """ parser = c_parser.CParser() try: node = parser.parse(c_decl, filename='') except c_parser.ParseError: e = sys.exc_info()[1] return "Parse error:" + str(e) if (not isinstance(node, c_ast.FileAST) or not isinstance(node.ext[-1], c_ast.Decl) ): return "Not a valid declaration" return _explain_decl_node(node.ext[-1]) def _explain_decl_node(decl_node): """ Receives a c_ast.Decl note and returns its explanation in English. """ storage = ' '.join(decl_node.storage) + ' ' if decl_node.storage else '' return (decl_node.name + " is a " + storage + _explain_type(decl_node.type)) def _explain_type(decl): """ Recursively explains a type decl node """ typ = type(decl) if typ == c_ast.TypeDecl: quals = ' '.join(decl.quals) + ' ' if decl.quals else '' return quals + _explain_type(decl.type) elif typ == c_ast.Typename or typ == c_ast.Decl: return _explain_type(decl.type) elif typ == c_ast.IdentifierType: return ' '.join(decl.names) elif typ == c_ast.PtrDecl: quals = ' '.join(decl.quals) + ' ' if decl.quals else '' return quals + 'pointer to ' + _explain_type(decl.type) elif typ == c_ast.ArrayDecl: arr = 'array' if decl.dim: arr += '[%s]' % decl.dim.value return arr + " of " + _explain_type(decl.type) elif typ == c_ast.FuncDecl: if decl.args: params = [_explain_type(param) for param in decl.args.params] args = ', '.join(params) else: args = '' return ('function(%s) returning ' % (args) + _explain_type(decl.type)) if __name__ == "__main__": if len(sys.argv) > 1: c_decl = sys.argv[1] else: c_decl = "char *(*(**foo[][8])())[];" print("Explaining the declaration: " + c_decl + "\n") print(explain_c_declaration(c_decl) + "\n") pycparser-2.14/examples/func_calls.py0000644000175000017500000000232112515542013020463 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # pycparser: func_defs.py # # Using pycparser for printing out all the calls of some function # in a C file. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- from __future__ import print_function import sys # This is not required if you've installed pycparser into # your site-packages/ with setup.py sys.path.extend(['.', '..']) from pycparser import c_parser, c_ast, parse_file # A visitor with some state information (the funcname it's # looking for) # class FuncCallVisitor(c_ast.NodeVisitor): def __init__(self, funcname): self.funcname = funcname def visit_FuncCall(self, node): if node.name.name == self.funcname: print('%s called at %s' % (self.funcname, node.name.coord)) def show_func_calls(filename, funcname): ast = parse_file(filename, use_cpp=True) v = FuncCallVisitor(funcname) v.visit(ast) if __name__ == "__main__": if len(sys.argv) > 2: filename = sys.argv[1] func = sys.argv[2] else: filename = 'examples/c_files/hash.c' func = 'malloc' show_func_calls(filename, func) pycparser-2.14/examples/c-to-c.py0000644000175000017500000000305212523673374017454 0ustar elibeneliben00000000000000#------------------------------------------------------------------------------ # pycparser: c-to-c.py # # Example of using pycparser.c_generator, serving as a simplistic translator # from C to AST and back to C. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #------------------------------------------------------------------------------ from __future__ import print_function import sys # This is not required if you've installed pycparser into # your site-packages/ with setup.py # sys.path.extend(['.', '..']) from pycparser import parse_file, c_parser, c_generator def translate_to_c(filename): """ Simply use the c_generator module to emit a parsed AST. """ ast = parse_file(filename, use_cpp=True) generator = c_generator.CGenerator() print(generator.visit(ast)) def _zz_test_translate(): # internal use src = r''' void f(char * restrict joe){} int main(void) { unsigned int long k = 4; int p = - - k; return 0; } ''' parser = c_parser.CParser() ast = parser.parse(src) ast.show() generator = c_generator.CGenerator() print(generator.visit(ast)) # tracing the generator for debugging #~ import trace #~ tr = trace.Trace(countcallers=1) #~ tr.runfunc(generator.visit, ast) #~ tr.results().write_results() #------------------------------------------------------------------------------ if __name__ == "__main__": #_zz_test_translate() if len(sys.argv) > 1: translate_to_c(sys.argv[1]) else: print("Please provide a filename as argument") pycparser-2.14/examples/explore_ast.py0000664000175000017500000001262112523673400020711 0ustar elibeneliben00000000000000#----------------------------------------------------------------- # pycparser: explore_ast.py # # This example demonstrates how to "explore" the AST created by # pycparser to understand its structure. The AST is a n-nary tree # of nodes, each node having several children, each with a name. # Just read the code, and let the comments guide you. The lines # beginning with #~ can be uncommented to print out useful # information from the AST. # It helps to have the pycparser/_c_ast.cfg file in front of you. # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- from __future__ import print_function import sys # This is not required if you've installed pycparser into # your site-packages/ with setup.py # sys.path.extend(['.', '..']) from pycparser import c_parser, c_ast # This is some C source to parse. Note that pycparser must begin # at the top level of the C file, i.e. with either declarations # or function definitions (this is called "external declarations" # in C grammar lingo) # # Also, a C parser must have all the types declared in order to # build the correct AST. It doesn't matter what they're declared # to, so I've inserted the dummy typedef in the code to let the # parser know Hash and Node are types. You don't need to do it # when parsing real, correct C code. # text = r""" typedef int Node, Hash; void HashPrint(Hash* hash, void (*PrintFunc)(char*, char*)) { unsigned int i; if (hash == NULL || hash->heads == NULL) return; for (i = 0; i < hash->table_size; ++i) { Node* temp = hash->heads[i]; while (temp != NULL) { PrintFunc(temp->entry->key, temp->entry->value); temp = temp->next; } } } """ # Create the parser and ask to parse the text. parse() will throw # a ParseError if there's an error in the code # parser = c_parser.CParser() ast = parser.parse(text, filename='') # Uncomment the following line to see the AST in a nice, human # readable way. show() is the most useful tool in exploring ASTs # created by pycparser. See the c_ast.py file for the options you # can pass it. # #~ ast.show() # OK, we've seen that the top node is FileAST. This is always the # top node of the AST. Its children are "external declarations", # and are stored in a list called ext[] (see _c_ast.cfg for the # names and types of Nodes and their children). # As you see from the printout, our AST has two Typedef children # and one FuncDef child. # Let's explore FuncDef more closely. As I've mentioned, the list # ext[] holds the children of FileAST. Since the function # definition is the third child, it's ext[2]. Uncomment the # following line to show it: # #~ ast.ext[2].show() # A FuncDef consists of a declaration, a list of parameter # declarations (for K&R style function definitions), and a body. # First, let's examine the declaration. # function_decl = ast.ext[2].decl # function_decl, like any other declaration, is a Decl. Its type child # is a FuncDecl, which has a return type and arguments stored in a # ParamList node #~ function_decl.type.show() #~ function_decl.type.args.show() # The following displays the name and type of each argument: # #~ for param_decl in function_decl.type.args.params: #~ print('Arg name: %s' % param_decl.name) #~ print('Type:') #~ param_decl.type.show(offset=6) # The body is of FuncDef is a Compound, which is a placeholder for a block # surrounded by {} (You should be reading _c_ast.cfg parallel to this # explanation and seeing these things with your own eyes). # Let's see the block's declarations: # function_body = ast.ext[2].body # The following displays the declarations and statements in the function # body # #~ for decl in function_body.block_items: #~ decl.show() # We can see a single variable declaration, i, declared to be a simple type # declaration of type 'unsigned int', followed by statements. # block_items is a list, so the third element is the For statement: # for_stmt = function_body.block_items[2] #~ for_stmt.show() # As you can see in _c_ast.cfg, For's children are 'init, cond, # next' for the respective parts of the 'for' loop specifier, # and stmt, which is either a single stmt or a Compound if there's # a block. # # Let's dig deeper, to the while statement inside the for loop: # while_stmt = for_stmt.stmt.block_items[1] #~ while_stmt.show() # While is simpler, it only has a condition node and a stmt node. # The condition: # while_cond = while_stmt.cond #~ while_cond.show() # Note that it's a BinaryOp node - the basic constituent of # expressions in our AST. BinaryOp is the expression tree, with # left and right nodes as children. It also has the op attribute, # which is just the string representation of the operator. # #~ print(while_cond.op) #~ while_cond.left.show() #~ while_cond.right.show() # # That's it for the example. I hope you now see how easy it is to explore the # AST created by pycparser. Although on the surface it is quite complex and has # a lot of node types, this is the inherent complexity of the C language every # parser/compiler designer has to cope with. # Using the tools provided by the c_ast package it's easy to explore the # structure of AST nodes and write code that processes them. # Specifically, see the cdecl.py example for a non-trivial demonstration of what # you can do by recursively going through the AST. # pycparser-2.14/MANIFEST.in0000644000175000017500000000046312526364714015741 0ustar elibeneliben00000000000000recursive-include examples *.c *.h *.py recursive-include tests *.c *.h *.py recursive-include pycparser *.py *.cfg include utils/fake_libc_include/*.h include README.* include LICENSE include CHANGES include setup.* recursive-exclude tests yacctab.* lextab.* recursive-exclude examples yacctab.* lextab.* pycparser-2.14/setup.py0000644000175000017500000000333212535723761015714 0ustar elibeneliben00000000000000import os, sys try: from setuptools import setup from setuptools.command.install import install as _install from setuptools.command.sdist import sdist as _sdist except ImportError: from distutils.core import setup from distutils.command.install import install as _install from distutils.command.sdist import sdist as _sdist def _run_build_tables(dir): from subprocess import call call([sys.executable, '_build_tables.py'], cwd=os.path.join(dir, 'pycparser')) class install(_install): def run(self): _install.run(self) self.execute(_run_build_tables, (self.install_lib,), msg="Build the lexing/parsing tables") class sdist(_sdist): def make_release_tree(self, basedir, files): _sdist.make_release_tree(self, basedir, files) self.execute(_run_build_tables, (basedir,), msg="Build the lexing/parsing tables") setup( # metadata name='pycparser', description='C parser in Python', long_description=""" pycparser is a complete parser of the C language, written in pure Python using the PLY parsing library. It parses C code into an AST and can serve as a front-end for C compilers or analysis tools. """, license='BSD', version='2.14', author='Eli Bendersky', maintainer='Eli Bendersky', author_email='eliben@gmail.com', url='https://github.com/eliben/pycparser', platforms='Cross Platform', classifiers = [ 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3',], packages=['pycparser', 'pycparser.ply'], package_data={'pycparser': ['*.cfg']}, cmdclass={'install': install, 'sdist': sdist}, ) pycparser-2.14/tests/0000775000175000017500000000000012535724325015342 5ustar elibeneliben00000000000000pycparser-2.14/tests/test_c_lexer.py0000664000175000017500000003307212523502326020371 0ustar elibeneliben00000000000000import re import sys import unittest sys.path.insert(0, '..') from pycparser.c_lexer import CLexer def token_list(clex): return list(iter(clex.token, None)) def token_types(clex): return [i.type for i in token_list(clex)] class TestCLexerNoErrors(unittest.TestCase): """ Test lexing of strings that are not supposed to cause errors. Therefore, the error_func passed to the lexer raises an exception. """ def error_func(self, msg, line, column): self.fail(msg) def on_lbrace_func(self): pass def on_rbrace_func(self): pass def type_lookup_func(self, typ): if typ.startswith('mytype'): return True else: return False def setUp(self): self.clex = CLexer(self.error_func, lambda: None, lambda: None, self.type_lookup_func) self.clex.build(optimize=False) def assertTokensTypes(self, str, types): self.clex.input(str) self.assertEqual(token_types(self.clex), types) def test_trivial_tokens(self): self.assertTokensTypes('1', ['INT_CONST_DEC']) self.assertTokensTypes('-', ['MINUS']) self.assertTokensTypes('volatile', ['VOLATILE']) self.assertTokensTypes('...', ['ELLIPSIS']) self.assertTokensTypes('++', ['PLUSPLUS']) self.assertTokensTypes('case int', ['CASE', 'INT']) self.assertTokensTypes('caseint', ['ID']) self.assertTokensTypes('$dollar cent$', ['ID', 'ID']) self.assertTokensTypes('i ^= 1;', ['ID', 'XOREQUAL', 'INT_CONST_DEC', 'SEMI']) def test_id_typeid(self): self.assertTokensTypes('myt', ['ID']) self.assertTokensTypes('mytype', ['TYPEID']) self.assertTokensTypes('mytype6 var', ['TYPEID', 'ID']) def test_integer_constants(self): self.assertTokensTypes('12', ['INT_CONST_DEC']) self.assertTokensTypes('12u', ['INT_CONST_DEC']) self.assertTokensTypes('12l', ['INT_CONST_DEC']) self.assertTokensTypes('199872Ul', ['INT_CONST_DEC']) self.assertTokensTypes('199872lU', ['INT_CONST_DEC']) self.assertTokensTypes('199872LL', ['INT_CONST_DEC']) self.assertTokensTypes('199872ull', ['INT_CONST_DEC']) self.assertTokensTypes('199872llu', ['INT_CONST_DEC']) self.assertTokensTypes('1009843200000uLL', ['INT_CONST_DEC']) self.assertTokensTypes('1009843200000LLu', ['INT_CONST_DEC']) self.assertTokensTypes('077', ['INT_CONST_OCT']) self.assertTokensTypes('0123456L', ['INT_CONST_OCT']) self.assertTokensTypes('0xf7', ['INT_CONST_HEX']) self.assertTokensTypes('0b110', ['INT_CONST_BIN']) self.assertTokensTypes('0x01202AAbbf7Ul', ['INT_CONST_HEX']) # no 0 before x, so ID catches it self.assertTokensTypes('xf7', ['ID']) # - is MINUS, the rest a constnant self.assertTokensTypes('-1', ['MINUS', 'INT_CONST_DEC']) def test_special_names(self): self.assertTokensTypes('sizeof offsetof', ['SIZEOF', 'OFFSETOF']) def test_floating_constants(self): self.assertTokensTypes('1.5f', ['FLOAT_CONST']) self.assertTokensTypes('01.5', ['FLOAT_CONST']) self.assertTokensTypes('.15L', ['FLOAT_CONST']) self.assertTokensTypes('0.', ['FLOAT_CONST']) # but just a period is a period self.assertTokensTypes('.', ['PERIOD']) self.assertTokensTypes('3.3e-3', ['FLOAT_CONST']) self.assertTokensTypes('.7e25L', ['FLOAT_CONST']) self.assertTokensTypes('6.e+125f', ['FLOAT_CONST']) self.assertTokensTypes('666e666', ['FLOAT_CONST']) self.assertTokensTypes('00666e+3', ['FLOAT_CONST']) # but this is a hex integer + 3 self.assertTokensTypes('0x0666e+3', ['INT_CONST_HEX', 'PLUS', 'INT_CONST_DEC']) def test_hexadecimal_floating_constants(self): self.assertTokensTypes('0xDE.488641p0', ['HEX_FLOAT_CONST']) self.assertTokensTypes('0x.488641p0', ['HEX_FLOAT_CONST']) self.assertTokensTypes('0X12.P0', ['HEX_FLOAT_CONST']) def test_char_constants(self): self.assertTokensTypes(r"""'x'""", ['CHAR_CONST']) self.assertTokensTypes(r"""L'x'""", ['WCHAR_CONST']) self.assertTokensTypes(r"""'\t'""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\''""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\?'""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\012'""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\x2f'""", ['CHAR_CONST']) self.assertTokensTypes(r"""'\x2f12'""", ['CHAR_CONST']) self.assertTokensTypes(r"""L'\xaf'""", ['WCHAR_CONST']) def test_on_rbrace_lbrace(self): braces = [] def on_lbrace(): braces.append('{') def on_rbrace(): braces.append('}') clex = CLexer(self.error_func, on_lbrace, on_rbrace, self.type_lookup_func) clex.build(optimize=False) clex.input('hello { there } } and again }}{') token_list(clex) self.assertEqual(braces, ['{', '}', '}', '}', '}', '{']) def test_string_literal(self): self.assertTokensTypes('"a string"', ['STRING_LITERAL']) self.assertTokensTypes('L"ing"', ['WSTRING_LITERAL']) self.assertTokensTypes( '"i am a string too \t"', ['STRING_LITERAL']) self.assertTokensTypes( r'''"esc\ape \"\'\? \0234 chars \rule"''', ['STRING_LITERAL']) self.assertTokensTypes( r'''"hello 'joe' wanna give it a \"go\"?"''', ['STRING_LITERAL']) def test_mess(self): self.assertTokensTypes( r'[{}]()', ['LBRACKET', 'LBRACE', 'RBRACE', 'RBRACKET', 'LPAREN', 'RPAREN']) self.assertTokensTypes( r'()||!C&~Z?J', ['LPAREN', 'RPAREN', 'LOR', 'LNOT', 'ID', 'AND', 'NOT', 'ID', 'CONDOP', 'ID']) self.assertTokensTypes( r'+-*/%|||&&&^><>=<===!=', ['PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'MOD', 'LOR', 'OR', 'LAND', 'AND', 'XOR', 'GT', 'LT', 'GE', 'LE', 'EQ', 'NE']) self.assertTokensTypes( r'++--->?.,;:', ['PLUSPLUS', 'MINUSMINUS', 'ARROW', 'CONDOP', 'PERIOD', 'COMMA', 'SEMI', 'COLON']) def test_exprs(self): self.assertTokensTypes( 'bb-cc', ['ID', 'MINUS', 'ID']) self.assertTokensTypes( 'foo & 0xFF', ['ID', 'AND', 'INT_CONST_HEX']) self.assertTokensTypes( '(2+k) * 62', ['LPAREN', 'INT_CONST_DEC', 'PLUS', 'ID', 'RPAREN', 'TIMES', 'INT_CONST_DEC'],) self.assertTokensTypes( 'x | y >> z', ['ID', 'OR', 'ID', 'RSHIFT', 'ID']) self.assertTokensTypes( 'x <<= z << 5', ['ID', 'LSHIFTEQUAL', 'ID', 'LSHIFT', 'INT_CONST_DEC']) self.assertTokensTypes( 'x = y > 0 ? y : -6', ['ID', 'EQUALS', 'ID', 'GT', 'INT_CONST_OCT', 'CONDOP', 'ID', 'COLON', 'MINUS', 'INT_CONST_DEC']) self.assertTokensTypes( 'a+++b', ['ID', 'PLUSPLUS', 'PLUS', 'ID']) def test_statements(self): self.assertTokensTypes( 'for (int i = 0; i < n; ++i)', ['FOR', 'LPAREN', 'INT', 'ID', 'EQUALS', 'INT_CONST_OCT', 'SEMI', 'ID', 'LT', 'ID', 'SEMI', 'PLUSPLUS', 'ID', 'RPAREN']) self.assertTokensTypes( 'self: goto self;', ['ID', 'COLON', 'GOTO', 'ID', 'SEMI']) self.assertTokensTypes( """ switch (typ) { case TYPE_ID: m = 5; break; default: m = 8; }""", ['SWITCH', 'LPAREN', 'ID', 'RPAREN', 'LBRACE', 'CASE', 'ID', 'COLON', 'ID', 'EQUALS', 'INT_CONST_DEC', 'SEMI', 'BREAK', 'SEMI', 'DEFAULT', 'COLON', 'ID', 'EQUALS', 'INT_CONST_DEC', 'SEMI', 'RBRACE']) def test_preprocessor_line(self): self.assertTokensTypes('#abracadabra', ['PPHASH', 'ID']) str = r""" 546 #line 66 "kwas\df.h" id 4 dsf # 9 armo #line 10 "..\~..\test.h" tok1 #line 99999 "include/me.h" tok2 """ #~ self.clex.filename self.clex.input(str) self.clex.reset_lineno() t1 = self.clex.token() self.assertEqual(t1.type, 'INT_CONST_DEC') self.assertEqual(t1.lineno, 2) t2 = self.clex.token() self.assertEqual(t2.type, 'ID') self.assertEqual(t2.value, 'id') self.assertEqual(t2.lineno, 66) self.assertEqual(self.clex.filename, r'kwas\df.h') for i in range(3): t = self.clex.token() self.assertEqual(t.type, 'ID') self.assertEqual(t.value, 'armo') self.assertEqual(t.lineno, 9) self.assertEqual(self.clex.filename, r'kwas\df.h') t4 = self.clex.token() self.assertEqual(t4.type, 'ID') self.assertEqual(t4.value, 'tok1') self.assertEqual(t4.lineno, 10) self.assertEqual(self.clex.filename, r'..\~..\test.h') t5 = self.clex.token() self.assertEqual(t5.type, 'ID') self.assertEqual(t5.value, 'tok2') self.assertEqual(t5.lineno, 99999) self.assertEqual(self.clex.filename, r'include/me.h') def test_preprocessor_line_funny(self): str = r''' #line 10 "..\6\joe.h" 10 ''' self.clex.input(str) self.clex.reset_lineno() t1 = self.clex.token() self.assertEqual(t1.type, 'INT_CONST_DEC') self.assertEqual(t1.lineno, 10) self.assertEqual(self.clex.filename, r'..\6\joe.h') def test_preprocessor_pragma(self): str = r''' 42 #pragma helo me #pragma once # pragma omp parallel private(th_id) #pragma {pack: 2, smack: 3} #pragma "nowit.h" #pragma "string" #pragma somestring="some_other_string" #pragma id 124124 and numbers 0235495 59 ''' # Check that pragmas are ignored but the line number advances self.clex.input(str) self.clex.reset_lineno() t1 = self.clex.token() self.assertEqual(t1.type, 'INT_CONST_DEC') t2 = self.clex.token() self.assertEqual(t2.type, 'INT_CONST_DEC') self.assertEqual(t2.lineno, 11) # Keeps all the errors the lexer spits in one place, to allow # easier modification if the error syntax changes. # ERR_ILLEGAL_CHAR = 'Illegal character' ERR_OCTAL = 'Invalid octal constant' ERR_UNMATCHED_QUOTE = 'Unmatched \'' ERR_INVALID_CCONST = 'Invalid char constant' ERR_STRING_ESCAPE = 'String contains invalid escape' ERR_FILENAME_BEFORE_LINE = 'filename before line' ERR_LINENUM_MISSING = 'line number missing' ERR_INVALID_LINE_DIRECTIVE = 'invalid #line directive' class TestCLexerErrors(unittest.TestCase): """ Test lexing of erroneous strings. Works by passing an error functions that saves the error in an attribute for later perusal. """ def error_func(self, msg, line, column): self.error = msg def on_lbrace_func(self): pass def on_rbrace_func(self): pass def type_lookup_func(self, typ): return False def setUp(self): self.clex = CLexer(self.error_func, self.on_lbrace_func, self.on_rbrace_func, self.type_lookup_func) self.clex.build(optimize=False) self.error = "" def assertLexerError(self, str, error_like): # feed the string to the lexer self.clex.input(str) # Pulls all tokens from the string. Errors will # be written into self.error by the error_func # callback # token_types(self.clex) # compare the error to the expected self.assertTrue(re.search(error_like, self.error), "\nExpected error matching: %s\nGot: %s" % (error_like, self.error)) # clear last error, for the sake of subsequent invocations self.error = "" def test_trivial_tokens(self): self.assertLexerError('@', ERR_ILLEGAL_CHAR) self.assertLexerError('`', ERR_ILLEGAL_CHAR) self.assertLexerError('\\', ERR_ILLEGAL_CHAR) def test_integer_constants(self): self.assertLexerError('029', ERR_OCTAL) self.assertLexerError('012345678', ERR_OCTAL) def test_char_constants(self): self.assertLexerError("'", ERR_UNMATCHED_QUOTE) self.assertLexerError("'b\n", ERR_UNMATCHED_QUOTE) self.assertLexerError("'jx'", ERR_INVALID_CCONST) self.assertLexerError("'\*'", ERR_INVALID_CCONST) def test_string_literals(self): self.assertLexerError('"jx\9"', ERR_STRING_ESCAPE) self.assertLexerError('"hekllo\* on ix"', ERR_STRING_ESCAPE) self.assertLexerError('L"hekllo\* on ix"', ERR_STRING_ESCAPE) def test_preprocessor(self): self.assertLexerError('#line "ka"', ERR_FILENAME_BEFORE_LINE) self.assertLexerError('#line df', ERR_INVALID_LINE_DIRECTIVE) self.assertLexerError('#line \n', ERR_LINENUM_MISSING) if __name__ == '__main__': unittest.main() pycparser-2.14/tests/test_c_ast.py0000644000175000017500000000503312515563360020041 0ustar elibeneliben00000000000000import pprint import re import sys import unittest import weakref sys.path.insert(0, '..') import pycparser.c_ast as c_ast import pycparser.plyparser as plyparser class Test_c_ast(unittest.TestCase): def test_BinaryOp(self): b1 = c_ast.BinaryOp( op='+', left=c_ast.Constant(type='int', value='6'), right=c_ast.ID(name='joe')) self.failUnless(isinstance(b1.left, c_ast.Constant)) self.assertEqual(b1.left.type, 'int') self.assertEqual(b1.left.value, '6') self.failUnless(isinstance(b1.right, c_ast.ID)) self.assertEqual(b1.right.name, 'joe') def test_weakref_works_on_nodes(self): c1 = c_ast.Constant(type='float', value='3.14') wr = weakref.ref(c1) cref = wr() self.assertEqual(cref.type, 'float') self.assertEqual(weakref.getweakrefcount(c1), 1) def test_weakref_works_on_coord(self): coord = plyparser.Coord(file='a', line=2) wr = weakref.ref(coord) cref = wr() self.assertEqual(cref.line, 2) self.assertEqual(weakref.getweakrefcount(coord), 1) class TestNodeVisitor(unittest.TestCase): class ConstantVisitor(c_ast.NodeVisitor): def __init__(self): self.values = [] def visit_Constant(self, node): self.values.append(node.value) def test_scalar_children(self): b1 = c_ast.BinaryOp( op='+', left=c_ast.Constant(type='int', value='6'), right=c_ast.ID(name='joe')) cv = self.ConstantVisitor() cv.visit(b1) self.assertEqual(cv.values, ['6']) b2 = c_ast.BinaryOp( op='*', left=c_ast.Constant(type='int', value='111'), right=b1) b3 = c_ast.BinaryOp( op='^', left=b2, right=b1) cv = self.ConstantVisitor() cv.visit(b3) self.assertEqual(cv.values, ['111', '6', '6']) def tests_list_children(self): c1 = c_ast.Constant(type='float', value='5.6') c2 = c_ast.Constant(type='char', value='t') b1 = c_ast.BinaryOp( op='+', left=c1, right=c2) b2 = c_ast.BinaryOp( op='-', left=b1, right=c2) comp = c_ast.Compound( block_items=[b1, b2, c1, c2]) cv = self.ConstantVisitor() cv.visit(comp) self.assertEqual(cv.values, ['5.6', 't', '5.6', 't', 't', '5.6', 't']) if __name__ == '__main__': unittest.main() pycparser-2.14/tests/test_general.py0000644000175000017500000000361312526364772020377 0ustar elibeneliben00000000000000import sys, os import unittest sys.path.insert(0, '..') from pycparser import parse_file, c_ast CPPPATH = 'cpp' # Test successful parsing # class TestParsing(unittest.TestCase): def _find_file(self, name): """ Find a c file by name, taking into account the current dir can be in a couple of typical places """ testdir = os.path.dirname(__file__) name = os.path.join(testdir, 'c_files', name) assert os.path.exists(name) return name def test_without_cpp(self): ast = parse_file(self._find_file('example_c_file.c')) self.assertTrue(isinstance(ast, c_ast.FileAST)) def test_with_cpp(self): memmgr_path = self._find_file('memmgr.c') c_files_path = os.path.dirname(memmgr_path) ast = parse_file(memmgr_path, use_cpp=True, cpp_path=CPPPATH, cpp_args='-I%s' % c_files_path) self.assertTrue(isinstance(ast, c_ast.FileAST)) fake_libc = os.path.join(c_files_path, '..', '..', 'utils', 'fake_libc_include') ast2 = parse_file(self._find_file('year.c'), use_cpp=True, cpp_path=CPPPATH, cpp_args=[r'-I%s' % fake_libc]) self.assertTrue(isinstance(ast2, c_ast.FileAST)) def test_cpp_funkydir(self): # This test contains Windows specific path escapes if sys.platform != 'win32': return c_files_path = os.path.join('tests', 'c_files') ast = parse_file(self._find_file('simplemain.c'), use_cpp=True, cpp_path=CPPPATH, cpp_args='-I%s' % c_files_path) self.assertTrue(isinstance(ast, c_ast.FileAST)) def test_no_real_content_after_cpp(self): ast = parse_file(self._find_file('empty.h'), use_cpp=True, cpp_path=CPPPATH) self.assertTrue(isinstance(ast, c_ast.FileAST)) if __name__ == '__main__': unittest.main() pycparser-2.14/tests/test_c_parser.py0000775000175000017500000017151012523670566020565 0ustar elibeneliben00000000000000#!/usr/bin/env python import pprint import re import os, sys import unittest sys.path[0:0] = ['.', '..'] from pycparser import c_parser from pycparser.c_ast import * from pycparser.c_parser import CParser, Coord, ParseError _c_parser = c_parser.CParser( lex_optimize=False, yacc_debug=True, yacc_optimize=False, yacctab='yacctab') def expand_decl(decl): """ Converts the declaration into a nested list. """ typ = type(decl) if typ == TypeDecl: return ['TypeDecl', expand_decl(decl.type)] elif typ == IdentifierType: return ['IdentifierType', decl.names] elif typ == ID: return ['ID', decl.name] elif typ in [Struct, Union]: decls = [expand_decl(d) for d in decl.decls or []] return [typ.__name__, decl.name, decls] else: nested = expand_decl(decl.type) if typ == Decl: if decl.quals: return ['Decl', decl.quals, decl.name, nested] else: return ['Decl', decl.name, nested] elif typ == Typename: # for function parameters if decl.quals: return ['Typename', decl.quals, nested] else: return ['Typename', nested] elif typ == ArrayDecl: dimval = decl.dim.value if decl.dim else '' return ['ArrayDecl', dimval, decl.dim_quals, nested] elif typ == PtrDecl: if decl.quals: return ['PtrDecl', decl.quals, nested] else: return ['PtrDecl', nested] elif typ == Typedef: return ['Typedef', decl.name, nested] elif typ == FuncDecl: if decl.args: params = [expand_decl(param) for param in decl.args.params] else: params = [] return ['FuncDecl', params, nested] def expand_init(init): """ Converts an initialization into a nested list """ typ = type(init) if typ == NamedInitializer: des = [expand_init(dp) for dp in init.name] return (des, expand_init(init.expr)) elif typ in (InitList, ExprList): return [expand_init(expr) for expr in init.exprs] elif typ == Constant: return ['Constant', init.type, init.value] elif typ == ID: return ['ID', init.name] class TestCParser_base(unittest.TestCase): def parse(self, txt, filename=''): return self.cparser.parse(txt, filename) def setUp(self): self.cparser = _c_parser class TestCParser_fundamentals(TestCParser_base): def get_decl(self, txt, index=0): """ Given a source and an index returns the expanded declaration at that index. FileAST holds a list of 'external declarations'. index is the offset of the desired declaration in that list. """ t = self.parse(txt).ext[index] return expand_decl(t) def get_decl_init(self, txt, index=0): """ Returns the expanded initializer of the declaration at index. """ t = self.parse(txt).ext[index] return expand_init(t.init) def test_FileAST(self): t = self.parse('int a; char c;') self.assertTrue(isinstance(t, FileAST)) self.assertEqual(len(t.ext), 2) # empty file t2 = self.parse('') self.assertTrue(isinstance(t2, FileAST)) self.assertEqual(len(t2.ext), 0) def test_empty_toplevel_decl(self): code = 'int foo;;' t = self.parse(code) self.assertTrue(isinstance(t, FileAST)) self.assertEqual(len(t.ext), 1) self.assertEqual(self.get_decl(code), ['Decl', 'foo', ['TypeDecl', ['IdentifierType', ['int']]]]) def assert_coord(self, node, line, file=None): self.assertEqual(node.coord.line, line) if file: self.assertEqual(node.coord.file, file) def test_coords(self): """ Tests the "coordinates" of parsed elements - file name and line numbers, with modification insterted by #line directives. """ self.assert_coord(self.parse('int a;').ext[0], 1) t1 = """ int a; int b;\n\n int c; """ f1 = self.parse(t1, filename='test.c') self.assert_coord(f1.ext[0], 2, 'test.c') self.assert_coord(f1.ext[1], 3, 'test.c') self.assert_coord(f1.ext[2], 6, 'test.c') t1_1 = ''' int main() { k = p; printf("%d", b); return 0; }''' f1_1 = self.parse(t1_1, filename='test.c') self.assert_coord(f1_1.ext[0].body.block_items[0], 3, 'test.c') self.assert_coord(f1_1.ext[0].body.block_items[1], 4, 'test.c') t1_2 = ''' int main () { int p = (int) k; }''' f1_2 = self.parse(t1_2, filename='test.c') # make sure that the Cast has a coord (issue 23) self.assert_coord(f1_2.ext[0].body.block_items[0].init, 3, 'test.c') t2 = """ #line 99 int c; """ self.assert_coord(self.parse(t2).ext[0], 99) t3 = """ int dsf; char p; #line 3000 "in.h" char d; """ f3 = self.parse(t3, filename='test.c') self.assert_coord(f3.ext[0], 2, 'test.c') self.assert_coord(f3.ext[1], 3, 'test.c') self.assert_coord(f3.ext[2], 3000, 'in.h') t4 = """ #line 20 "restore.h" int maydler(char); #line 30 "includes/daween.ph" long j, k; #line 50000 char* ro; """ f4 = self.parse(t4, filename='myb.c') self.assert_coord(f4.ext[0], 20, 'restore.h') self.assert_coord(f4.ext[1], 30, 'includes/daween.ph') self.assert_coord(f4.ext[2], 30, 'includes/daween.ph') self.assert_coord(f4.ext[3], 50000, 'includes/daween.ph') t5 = """ int #line 99 c; """ self.assert_coord(self.parse(t5).ext[0], 99) # coord for ellipsis t6 = """ int foo(int j, ...) { }""" f6 = self.parse(t6, filename='z.c') self.assert_coord(self.parse(t6).ext[0].decl.type.args.params[1], 3) def test_forloop_coord(self): t = '''\ void foo() { for(int z=0; z<4; z++){} } ''' s = self.parse(t, filename='f.c') forloop = s.ext[0].body.block_items[0] self.assert_coord(forloop.init, 2, 'f.c') self.assert_coord(forloop.cond, 2, 'f.c') self.assert_coord(forloop.next, 3, 'f.c') def test_simple_decls(self): self.assertEqual(self.get_decl('int a;'), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(self.get_decl('unsigned int a;'), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['unsigned', 'int']]]]) self.assertEqual(self.get_decl('_Bool a;'), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['_Bool']]]]) self.assertEqual(self.get_decl('float _Complex fcc;'), ['Decl', 'fcc', ['TypeDecl', ['IdentifierType', ['float', '_Complex']]]]) self.assertEqual(self.get_decl('char* string;'), ['Decl', 'string', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]) self.assertEqual(self.get_decl('long ar[15];'), ['Decl', 'ar', ['ArrayDecl', '15', [], ['TypeDecl', ['IdentifierType', ['long']]]]]) self.assertEqual(self.get_decl('long long ar[15];'), ['Decl', 'ar', ['ArrayDecl', '15', [], ['TypeDecl', ['IdentifierType', ['long', 'long']]]]]) self.assertEqual(self.get_decl('unsigned ar[];'), ['Decl', 'ar', ['ArrayDecl', '', [], ['TypeDecl', ['IdentifierType', ['unsigned']]]]]) self.assertEqual(self.get_decl('int strlen(char* s);'), ['Decl', 'strlen', ['FuncDecl', [['Decl', 's', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl('int strcmp(char* s1, char* s2);'), ['Decl', 'strcmp', ['FuncDecl', [ ['Decl', 's1', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]], ['Decl', 's2', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]] ], ['TypeDecl', ['IdentifierType', ['int']]]]]) # function return values and parameters may not have type information self.assertEqual(self.get_decl('extern foobar(foo, bar);'), ['Decl', 'foobar', ['FuncDecl', [ ['ID', 'foo'], ['ID', 'bar'] ], ['TypeDecl', ['IdentifierType', ['int']]]]]) def test_nested_decls(self): # the fun begins self.assertEqual(self.get_decl('char** ar2D;'), ['Decl', 'ar2D', ['PtrDecl', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]) self.assertEqual(self.get_decl('int (*a)[1][2];'), ['Decl', 'a', ['PtrDecl', ['ArrayDecl', '1', [], ['ArrayDecl', '2', [], ['TypeDecl', ['IdentifierType', ['int']]]]]]]) self.assertEqual(self.get_decl('int *a[1][2];'), ['Decl', 'a', ['ArrayDecl', '1', [], ['ArrayDecl', '2', [], ['PtrDecl', ['TypeDecl', ['IdentifierType', ['int']]]]]]]) self.assertEqual(self.get_decl('char* const* p;'), ['Decl', 'p', ['PtrDecl', ['PtrDecl', ['const'], ['TypeDecl', ['IdentifierType', ['char']]]]]]) self.assertEqual(self.get_decl('char* * const p;'), ['Decl', 'p', ['PtrDecl', ['const'], ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]) self.assertEqual(self.get_decl('char ***ar3D[40];'), ['Decl', 'ar3D', ['ArrayDecl', '40', [], ['PtrDecl', ['PtrDecl', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]) self.assertEqual(self.get_decl('char (***ar3D)[40];'), ['Decl', 'ar3D', ['PtrDecl', ['PtrDecl', ['PtrDecl', ['ArrayDecl', '40', [], ['TypeDecl', ['IdentifierType', ['char']]]]]]]]) self.assertEqual(self.get_decl('int (*x[4])(char, int);'), ['Decl', 'x', ['ArrayDecl', '4', [], ['PtrDecl', ['FuncDecl', [ ['Typename', ['TypeDecl', ['IdentifierType', ['char']]]], ['Typename', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]]) self.assertEqual(self.get_decl('char *(*(**foo [][8])())[];'), ['Decl', 'foo', ['ArrayDecl', '', [], ['ArrayDecl', '8', [], ['PtrDecl', ['PtrDecl', ['FuncDecl', [], ['PtrDecl', ['ArrayDecl', '', [], ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]]]]]) # explore named and unnamed function pointer parameters, # with and without qualifiers # unnamed w/o quals self.assertEqual(self.get_decl('int (*k)(int);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Typename', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) # unnamed w/ quals self.assertEqual(self.get_decl('int (*k)(const int);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Typename', ['const'], ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) # named w/o quals self.assertEqual(self.get_decl('int (*k)(int q);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Decl', 'q', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) # named w/ quals self.assertEqual(self.get_decl('int (*k)(const volatile int q);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Decl', ['const', 'volatile'], 'q', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) # restrict qualifier self.assertEqual(self.get_decl('int (*k)(restrict int* q);'), ['Decl', 'k', ['PtrDecl', ['FuncDecl', [['Decl', ['restrict'], 'q', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['int']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) def test_func_decls_with_array_dim_qualifiers(self): self.assertEqual(self.get_decl('int zz(int p[static 10]);'), ['Decl', 'zz', ['FuncDecl', [['Decl', 'p', ['ArrayDecl', '10', ['static'], ['TypeDecl', ['IdentifierType', ['int']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl('int zz(int p[const 10]);'), ['Decl', 'zz', ['FuncDecl', [['Decl', 'p', ['ArrayDecl', '10', ['const'], ['TypeDecl', ['IdentifierType', ['int']]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl('int zz(int p[restrict][5]);'), ['Decl', 'zz', ['FuncDecl', [['Decl', 'p', ['ArrayDecl', '', ['restrict'], ['ArrayDecl', '5', [], ['TypeDecl', ['IdentifierType', ['int']]]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl('int zz(int p[const restrict static 10][5]);'), ['Decl', 'zz', ['FuncDecl', [['Decl', 'p', ['ArrayDecl', '10', ['const', 'restrict', 'static'], ['ArrayDecl', '5', [], ['TypeDecl', ['IdentifierType', ['int']]]]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) def test_qualifiers_storage_specifiers(self): def assert_qs(txt, index, quals, storage): d = self.parse(txt).ext[index] self.assertEqual(d.quals, quals) self.assertEqual(d.storage, storage) assert_qs("extern int p;", 0, [], ['extern']) assert_qs("const long p = 6;", 0, ['const'], []) d1 = "static const int p, q, r;" for i in range(3): assert_qs(d1, i, ['const'], ['static']) d2 = "static char * const p;" assert_qs(d2, 0, [], ['static']) pdecl = self.parse(d2).ext[0].type self.assertTrue(isinstance(pdecl, PtrDecl)) self.assertEqual(pdecl.quals, ['const']) def test_sizeof(self): e = """ void foo() { int a = sizeof k; int b = sizeof(int); int c = sizeof(int**);; char* p = "just to make sure this parses w/o error..."; int d = sizeof(int()); } """ compound = self.parse(e).ext[0].body s1 = compound.block_items[0].init self.assertTrue(isinstance(s1, UnaryOp)) self.assertEqual(s1.op, 'sizeof') self.assertTrue(isinstance(s1.expr, ID)) self.assertEqual(s1.expr.name, 'k') s2 = compound.block_items[1].init self.assertEqual(expand_decl(s2.expr), ['Typename', ['TypeDecl', ['IdentifierType', ['int']]]]) s3 = compound.block_items[2].init self.assertEqual(expand_decl(s3.expr), ['Typename', ['PtrDecl', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['int']]]]]]) def test_offsetof(self): e = """ void foo() { int a = offsetof(struct S, p); a.b = offsetof(struct sockaddr, sp) + strlen(bar); } """ compound = self.parse(e).ext[0].body s1 = compound.block_items[0].init self.assertTrue(isinstance(s1, FuncCall)) self.assertTrue(isinstance(s1.name, ID)) self.assertEqual(s1.name.name, 'offsetof') self.assertTrue(isinstance(s1.args.exprs[0], Typename)) self.assertTrue(isinstance(s1.args.exprs[1], ID)) # The C99 compound literal feature # def test_compound_literals(self): ps1 = self.parse(r''' void foo() { p = (long long){k}; tc = (struct jk){.a = {1, 2}, .b[0] = t}; }''') compound = ps1.ext[0].body.block_items[0].rvalue self.assertEqual(expand_decl(compound.type), ['Typename', ['TypeDecl', ['IdentifierType', ['long', 'long']]]]) self.assertEqual(expand_init(compound.init), [['ID', 'k']]) compound = ps1.ext[0].body.block_items[1].rvalue self.assertEqual(expand_decl(compound.type), ['Typename', ['TypeDecl', ['Struct', 'jk', []]]]) self.assertEqual(expand_init(compound.init), [ ([['ID', 'a']], [['Constant', 'int', '1'], ['Constant', 'int', '2']]), ([['ID', 'b'], ['Constant', 'int', '0']], ['ID', 't'])]) def test_enums(self): e1 = "enum mycolor op;" e1_type = self.parse(e1).ext[0].type.type self.assertTrue(isinstance(e1_type, Enum)) self.assertEqual(e1_type.name, 'mycolor') self.assertEqual(e1_type.values, None) e2 = "enum mysize {large=20, small, medium} shoes;" e2_type = self.parse(e2).ext[0].type.type self.assertTrue(isinstance(e2_type, Enum)) self.assertEqual(e2_type.name, 'mysize') e2_elist = e2_type.values self.assertTrue(isinstance(e2_elist, EnumeratorList)) for e2_eval in e2_elist.enumerators: self.assertTrue(isinstance(e2_eval, Enumerator)) self.assertEqual(e2_elist.enumerators[0].name, 'large') self.assertEqual(e2_elist.enumerators[0].value.value, '20') self.assertEqual(e2_elist.enumerators[2].name, 'medium') self.assertEqual(e2_elist.enumerators[2].value, None) # enum with trailing comma (C99 feature) e3 = """ enum { red, blue, green, } color; """ e3_type = self.parse(e3).ext[0].type.type self.assertTrue(isinstance(e3_type, Enum)) e3_elist = e3_type.values self.assertTrue(isinstance(e3_elist, EnumeratorList)) for e3_eval in e3_elist.enumerators: self.assertTrue(isinstance(e3_eval, Enumerator)) self.assertEqual(e3_elist.enumerators[0].name, 'red') self.assertEqual(e3_elist.enumerators[0].value, None) self.assertEqual(e3_elist.enumerators[1].name, 'blue') self.assertEqual(e3_elist.enumerators[2].name, 'green') def test_typedef(self): # without typedef, error s1 = """ node k; """ self.assertRaises(ParseError, self.parse, s1) # now with typedef, works s2 = """ typedef void* node; node k; """ ps2 = self.parse(s2) self.assertEqual(expand_decl(ps2.ext[0]), ['Typedef', 'node', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['void']]]]]) self.assertEqual(expand_decl(ps2.ext[1]), ['Decl', 'k', ['TypeDecl', ['IdentifierType', ['node']]]]) s3 = """ typedef int T; typedef T *pT; pT aa, bb; """ ps3 = self.parse(s3) self.assertEqual(expand_decl(ps3.ext[3]), ['Decl', 'bb', ['TypeDecl', ['IdentifierType', ['pT']]]]) s4 = ''' typedef char* __builtin_va_list; typedef __builtin_va_list __gnuc_va_list; ''' ps4 = self.parse(s4) self.assertEqual(expand_decl(ps4.ext[1]), ['Typedef', '__gnuc_va_list', ['TypeDecl', ['IdentifierType', ['__builtin_va_list']]]]) s5 = '''typedef struct tagHash Hash;''' ps5 = self.parse(s5) self.assertEqual(expand_decl(ps5.ext[0]), ['Typedef', 'Hash', ['TypeDecl', ['Struct', 'tagHash', []]]]) def test_struct_union(self): s1 = """ struct { int id; char* name; } joe; """ self.assertEqual(expand_decl(self.parse(s1).ext[0]), ['Decl', 'joe', ['TypeDecl', ['Struct', None, [ ['Decl', 'id', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'name', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]]) s2 = """ struct node p; """ self.assertEqual(expand_decl(self.parse(s2).ext[0]), ['Decl', 'p', ['TypeDecl', ['Struct', 'node', []]]]) s21 = """ union pri ra; """ self.assertEqual(expand_decl(self.parse(s21).ext[0]), ['Decl', 'ra', ['TypeDecl', ['Union', 'pri', []]]]) s3 = """ struct node* p; """ self.assertEqual(expand_decl(self.parse(s3).ext[0]), ['Decl', 'p', ['PtrDecl', ['TypeDecl', ['Struct', 'node', []]]]]) s4 = """ struct node; """ self.assertEqual(expand_decl(self.parse(s4).ext[0]), ['Decl', None, ['Struct', 'node', []]]) s5 = """ union { struct { int type; } n; struct { int type; int intnode; } ni; } u; """ self.assertEqual(expand_decl(self.parse(s5).ext[0]), ['Decl', 'u', ['TypeDecl', ['Union', None, [['Decl', 'n', ['TypeDecl', ['Struct', None, [['Decl', 'type', ['TypeDecl', ['IdentifierType', ['int']]]]]]]], ['Decl', 'ni', ['TypeDecl', ['Struct', None, [['Decl', 'type', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'intnode', ['TypeDecl', ['IdentifierType', ['int']]]]]]]]]]]]) s6 = """ typedef struct foo_tag { void* data; } foo, *pfoo; """ s6_ast = self.parse(s6) self.assertEqual(expand_decl(s6_ast.ext[0]), ['Typedef', 'foo', ['TypeDecl', ['Struct', 'foo_tag', [['Decl', 'data', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['void']]]]]]]]]) self.assertEqual(expand_decl(s6_ast.ext[1]), ['Typedef', 'pfoo', ['PtrDecl', ['TypeDecl', ['Struct', 'foo_tag', [['Decl', 'data', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['void']]]]]]]]]]) s7 = r""" struct _on_exit_args { void * _fnargs[32]; void * _dso_handle[32]; long _fntypes; #line 77 "D:\eli\cpp_stuff\libc_include/sys/reent.h" long _is_cxa; }; """ s7_ast = self.parse(s7, filename='test.c') self.assert_coord(s7_ast.ext[0].type.decls[2], 6, 'test.c') self.assert_coord(s7_ast.ext[0].type.decls[3], 78, r'D:\eli\cpp_stuff\libc_include/sys/reent.h') s8 = """ typedef enum tagReturnCode {SUCCESS, FAIL} ReturnCode; typedef struct tagEntry { char* key; char* value; } Entry; typedef struct tagNode { Entry* entry; struct tagNode* next; } Node; typedef struct tagHash { unsigned int table_size; Node** heads; } Hash; """ s8_ast = self.parse(s8) self.assertEqual(expand_decl(s8_ast.ext[3]), ['Typedef', 'Hash', ['TypeDecl', ['Struct', 'tagHash', [['Decl', 'table_size', ['TypeDecl', ['IdentifierType', ['unsigned', 'int']]]], ['Decl', 'heads', ['PtrDecl', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['Node']]]]]]]]]]) def test_anonymous_struct_union(self): s1 = """ union { union { int i; long l; }; struct { int type; int intnode; }; } u; """ self.assertEqual(expand_decl(self.parse(s1).ext[0]), ['Decl', 'u', ['TypeDecl', ['Union', None, [['Decl', None, ['Union', None, [['Decl', 'i', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'l', ['TypeDecl', ['IdentifierType', ['long']]]]]]], ['Decl', None, ['Struct', None, [['Decl', 'type', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'intnode', ['TypeDecl', ['IdentifierType', ['int']]]]]]]]]]]) s2 = """ struct { int i; union { int id; char* name; }; float f; } joe; """ self.assertEqual(expand_decl(self.parse(s2).ext[0]), ['Decl', 'joe', ['TypeDecl', ['Struct', None, [['Decl', 'i', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', None, ['Union', None, [['Decl', 'id', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'name', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]], ['Decl', 'f', ['TypeDecl', ['IdentifierType', ['float']]]]]]]]) # ISO/IEC 9899:201x Commitee Draft 2010-11-16, N1539 # section 6.7.2.1, par. 19, example 1 s3 = """ struct v { union { struct { int i, j; }; struct { long k, l; } w; }; int m; } v1; """ self.assertEqual(expand_decl(self.parse(s3).ext[0]), ['Decl', 'v1', ['TypeDecl', ['Struct', 'v', [['Decl', None, ['Union', None, [['Decl', None, ['Struct', None, [['Decl', 'i', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'j', ['TypeDecl', ['IdentifierType', ['int']]]]]]], ['Decl', 'w', ['TypeDecl', ['Struct', None, [['Decl', 'k', ['TypeDecl', ['IdentifierType', ['long']]]], ['Decl', 'l', ['TypeDecl', ['IdentifierType', ['long']]]]]]]]]]], ['Decl', 'm', ['TypeDecl', ['IdentifierType', ['int']]]]]]]]) s4 = """ struct v { int i; float; } v2;""" # just make sure this doesn't raise ParseError self.parse(s4) def test_struct_members_namespace(self): """ Tests that structure/union member names reside in a separate namespace and can be named after existing types. """ s1 = """ typedef int Name; typedef Name NameArray[10]; struct { Name Name; Name NameArray[3]; } sye; void main(void) { sye.Name = 1; } """ s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[2]), ['Decl', 'sye', ['TypeDecl', ['Struct', None, [ ['Decl', 'Name', ['TypeDecl', ['IdentifierType', ['Name']]]], ['Decl', 'NameArray', ['ArrayDecl', '3', [], ['TypeDecl', ['IdentifierType', ['Name']]]]]]]]]) self.assertEqual(s1_ast.ext[3].body.block_items[0].lvalue.field.name, 'Name') def test_struct_bitfields(self): # a struct with two bitfields, one unnamed s1 = """ struct { int k:6; int :2; } joe; """ parsed_struct = self.parse(s1).ext[0] # We can see here the name of the decl for the unnamed bitfield is # None, but expand_decl doesn't show bitfield widths # ... self.assertEqual(expand_decl(parsed_struct), ['Decl', 'joe', ['TypeDecl', ['Struct', None, [ ['Decl', 'k', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', None, ['TypeDecl', ['IdentifierType', ['int']]]]]]]]) # ... # so we test them manually self.assertEqual(parsed_struct.type.type.decls[0].bitsize.value, '6') self.assertEqual(parsed_struct.type.type.decls[1].bitsize.value, '2') def test_tags_namespace(self): """ Tests that the tags of structs/unions/enums reside in a separate namespace and can be named after existing types. """ s1 = """ typedef int tagEntry; struct tagEntry { char* key; char* value; } Entry; """ s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[1]), ['Decl', 'Entry', ['TypeDecl', ['Struct', 'tagEntry', [['Decl', 'key', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]], ['Decl', 'value', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]]) s2 = """ struct tagEntry; typedef struct tagEntry tagEntry; struct tagEntry { char* key; char* value; } Entry; """ s2_ast = self.parse(s2) self.assertEqual(expand_decl(s2_ast.ext[2]), ['Decl', 'Entry', ['TypeDecl', ['Struct', 'tagEntry', [['Decl', 'key', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]], ['Decl', 'value', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]]]]) s3 = """ typedef int mytag; enum mytag {ABC, CDE}; enum mytag joe; """ s3_type = self.parse(s3).ext[1].type self.assertTrue(isinstance(s3_type, Enum)) self.assertEqual(s3_type.name, 'mytag') def test_multi_decls(self): d1 = 'int a, b;' self.assertEqual(self.get_decl(d1, 0), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(self.get_decl(d1, 1), ['Decl', 'b', ['TypeDecl', ['IdentifierType', ['int']]]]) d2 = 'char* p, notp, ar[4];' self.assertEqual(self.get_decl(d2, 0), ['Decl', 'p', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]) self.assertEqual(self.get_decl(d2, 1), ['Decl', 'notp', ['TypeDecl', ['IdentifierType', ['char']]]]) self.assertEqual(self.get_decl(d2, 2), ['Decl', 'ar', ['ArrayDecl', '4', [], ['TypeDecl', ['IdentifierType', ['char']]]]]) def test_invalid_multiple_types_error(self): bad = [ 'int enum {ab, cd} fubr;', 'enum kid char brbr;'] for b in bad: self.assertRaises(ParseError, self.parse, b) def test_duplicate_typedef(self): """ Tests that redeclarations of existing types are parsed correctly. This is non-standard, but allowed by many compilers. """ d1 = ''' typedef int numbertype; typedef int numbertype; ''' self.assertEqual(self.get_decl(d1, 0), ['Typedef', 'numbertype', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(self.get_decl(d1, 1), ['Typedef', 'numbertype', ['TypeDecl', ['IdentifierType', ['int']]]]) d2 = ''' typedef int (*funcptr)(int x); typedef int (*funcptr)(int x); ''' self.assertEqual(self.get_decl(d2, 0), ['Typedef', 'funcptr', ['PtrDecl', ['FuncDecl', [['Decl', 'x', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) self.assertEqual(self.get_decl(d2, 1), ['Typedef', 'funcptr', ['PtrDecl', ['FuncDecl', [['Decl', 'x', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]]) d3 = ''' typedef int numberarray[5]; typedef int numberarray[5]; ''' self.assertEqual(self.get_decl(d3, 0), ['Typedef', 'numberarray', ['ArrayDecl', '5', [], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(self.get_decl(d3, 1), ['Typedef', 'numberarray', ['ArrayDecl', '5', [], ['TypeDecl', ['IdentifierType', ['int']]]]]) def test_decl_inits(self): d1 = 'int a = 16;' #~ self.parse(d1).show() self.assertEqual(self.get_decl(d1), ['Decl', 'a', ['TypeDecl', ['IdentifierType', ['int']]]]) self.assertEqual(self.get_decl_init(d1), ['Constant', 'int', '16']) d1_1 = 'float f = 0xEF.56p1;' self.assertEqual(self.get_decl_init(d1_1), ['Constant', 'float', '0xEF.56p1']) d1_2 = 'int bitmask = 0b1001010;' self.assertEqual(self.get_decl_init(d1_2), ['Constant', 'int', '0b1001010']) d2 = 'long ar[] = {7, 8, 9};' self.assertEqual(self.get_decl(d2), ['Decl', 'ar', ['ArrayDecl', '', [], ['TypeDecl', ['IdentifierType', ['long']]]]]) self.assertEqual(self.get_decl_init(d2), [ ['Constant', 'int', '7'], ['Constant', 'int', '8'], ['Constant', 'int', '9']]) d21 = 'long ar[4] = {};' self.assertEqual(self.get_decl_init(d21), []) d3 = 'char p = j;' self.assertEqual(self.get_decl(d3), ['Decl', 'p', ['TypeDecl', ['IdentifierType', ['char']]]]) self.assertEqual(self.get_decl_init(d3), ['ID', 'j']) d4 = "char x = 'c', *p = {0, 1, 2, {4, 5}, 6};" self.assertEqual(self.get_decl(d4, 0), ['Decl', 'x', ['TypeDecl', ['IdentifierType', ['char']]]]) self.assertEqual(self.get_decl_init(d4, 0), ['Constant', 'char', "'c'"]) self.assertEqual(self.get_decl(d4, 1), ['Decl', 'p', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]) self.assertEqual(self.get_decl_init(d4, 1), [ ['Constant', 'int', '0'], ['Constant', 'int', '1'], ['Constant', 'int', '2'], [['Constant', 'int', '4'], ['Constant', 'int', '5']], ['Constant', 'int', '6']]) def test_decl_named_inits(self): d1 = 'int a = {.k = 16};' self.assertEqual(self.get_decl_init(d1), [( [['ID', 'k']], ['Constant', 'int', '16'])]) d2 = 'int a = { [0].a = {1}, [1].a[0] = 2 };' self.assertEqual(self.get_decl_init(d2), [ ([['Constant', 'int', '0'], ['ID', 'a']], [['Constant', 'int', '1']]), ([['Constant', 'int', '1'], ['ID', 'a'], ['Constant', 'int', '0']], ['Constant', 'int', '2'])]) d3 = 'int a = { .a = 1, .c = 3, 4, .b = 5};' self.assertEqual(self.get_decl_init(d3), [ ([['ID', 'a']], ['Constant', 'int', '1']), ([['ID', 'c']], ['Constant', 'int', '3']), ['Constant', 'int', '4'], ([['ID', 'b']], ['Constant', 'int', '5'])]) def test_function_definitions(self): def parse_fdef(str): return self.parse(str).ext[0] def fdef_decl(fdef): return expand_decl(fdef.decl) f1 = parse_fdef(''' int factorial(int p) { return 3; } ''') self.assertEqual(fdef_decl(f1), ['Decl', 'factorial', ['FuncDecl', [['Decl', 'p', ['TypeDecl', ['IdentifierType', ['int']]]]], ['TypeDecl', ['IdentifierType', ['int']]]]]) self.assertEqual(type(f1.body.block_items[0]), Return) f2 = parse_fdef(''' char* zzz(int p, char* c) { int a; char b; a = b + 2; return 3; } ''') self.assertEqual(fdef_decl(f2), ['Decl', 'zzz', ['FuncDecl', [ ['Decl', 'p', ['TypeDecl', ['IdentifierType', ['int']]]], ['Decl', 'c', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]], ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]) self.assertEqual(list(map(type, f2.body.block_items)), [Decl, Decl, Assignment, Return]) f3 = parse_fdef(''' char* zzz(p, c) long p, *c; { int a; char b; a = b + 2; return 3; } ''') self.assertEqual(fdef_decl(f3), ['Decl', 'zzz', ['FuncDecl', [ ['ID', 'p'], ['ID', 'c']], ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]]) self.assertEqual(list(map(type, f3.body.block_items)), [Decl, Decl, Assignment, Return]) self.assertEqual(expand_decl(f3.param_decls[0]), ['Decl', 'p', ['TypeDecl', ['IdentifierType', ['long']]]]) self.assertEqual(expand_decl(f3.param_decls[1]), ['Decl', 'c', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['long']]]]]) # function return values and parameters may not have type information f4 = parse_fdef(''' que(p) { return 3; } ''') self.assertEqual(fdef_decl(f4), ['Decl', 'que', ['FuncDecl', [['ID', 'p']], ['TypeDecl', ['IdentifierType', ['int']]]]]) def test_unified_string_literals(self): # simple string, for reference d1 = self.get_decl_init('char* s = "hello";') self.assertEqual(d1, ['Constant', 'string', '"hello"']) d2 = self.get_decl_init('char* s = "hello" " world";') self.assertEqual(d2, ['Constant', 'string', '"hello world"']) # the test case from issue 6 d3 = self.parse(r''' int main() { fprintf(stderr, "Wrong Params?\n" "Usage:\n" "%s \n", argv[0] ); } ''') self.assertEqual( d3.ext[0].body.block_items[0].args.exprs[1].value, r'"Wrong Params?\nUsage:\n%s \n"') d4 = self.get_decl_init('char* s = "" "foobar";') self.assertEqual(d4, ['Constant', 'string', '"foobar"']) d5 = self.get_decl_init(r'char* s = "foo\"" "bar";') self.assertEqual(d5, ['Constant', 'string', r'"foo\"bar"']) def test_unified_wstring_literals(self): d1 = self.get_decl_init('char* s = L"hello" L"world";') self.assertEqual(d1, ['Constant', 'string', 'L"helloworld"']) d2 = self.get_decl_init('char* s = L"hello " L"world" L" and I";') self.assertEqual(d2, ['Constant', 'string', 'L"hello world and I"']) def test_inline_specifier(self): ps2 = self.parse('static inline void inlinefoo(void);') self.assertEqual(ps2.ext[0].funcspec, ['inline']) # variable length array def test_vla(self): ps2 = self.parse(r''' int main() { int size; int var[size = 5]; int var2[*]; } ''') self.assertTrue(isinstance(ps2.ext[0].body.block_items[1].type.dim, Assignment)) self.assertTrue(isinstance(ps2.ext[0].body.block_items[2].type.dim, ID)) class TestCParser_whole_code(TestCParser_base): """ Testing of parsing whole chunks of code. Since I don't want to rely on the structure of ASTs too much, most of these tests are implemented with visitors. """ # A simple helper visitor that lists the values of all the # Constant nodes it sees. # class ConstantVisitor(NodeVisitor): def __init__(self): self.values = [] def visit_Constant(self, node): self.values.append(node.value) # This visitor counts the amount of references to the ID # with the name provided to it in the constructor. # class IDNameCounter(NodeVisitor): def __init__(self, name): self.name = name self.nrefs = 0 def visit_ID(self, node): if node.name == self.name: self.nrefs += 1 # Counts the amount of nodes of a given class # class NodeKlassCounter(NodeVisitor): def __init__(self, node_klass): self.klass = node_klass self.n = 0 def generic_visit(self, node): if node.__class__ == self.klass: self.n += 1 NodeVisitor.generic_visit(self, node) def assert_all_Constants(self, code, constants): """ Asserts that the list of all Constant values (by 'preorder' appearance) in the chunk of code is as given. """ if isinstance(code, str): parsed = self.parse(code) else: parsed = code cv = self.ConstantVisitor() cv.visit(parsed) self.assertEqual(cv.values, constants) def assert_num_ID_refs(self, code, name, num): """ Asserts the number of references to the ID with the given name. """ if isinstance(code, str): parsed = self.parse(code) else: parsed = code iv = self.IDNameCounter(name) iv.visit(parsed) self.assertEqual(iv.nrefs, num) def assert_num_klass_nodes(self, code, klass, num): """ Asserts the amount of klass nodes in the code. """ if isinstance(code, str): parsed = self.parse(code) else: parsed = code cv = self.NodeKlassCounter(klass) cv.visit(parsed) self.assertEqual(cv.n, num) def test_expressions(self): e1 = '''int k = (r + 10.0) >> 6 + 8 << (3 & 0x14);''' self.assert_all_Constants(e1, ['10.0', '6', '8', '3', '0x14']) e2 = r'''char n = '\n', *prefix = "st_";''' self.assert_all_Constants(e2, [r"'\n'", '"st_"']) s1 = r'''int main() { int i = 5, j = 6, k = 1; if ((i=j && k == 1) || k > j) printf("Hello, world\n"); return 0; }''' ps1 = self.parse(s1) self.assert_all_Constants(ps1, ['5', '6', '1', '1', '"Hello, world\\n"', '0']) self.assert_num_ID_refs(ps1, 'i', 1) self.assert_num_ID_refs(ps1, 'j', 2) def test_statements(self): s1 = r''' void foo(){ if (sp == 1) if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') return -1; else if (strcmp(argv[optind], "--") == 0) { optind++; return -1; } } ''' self.assert_all_Constants(s1, ['1', '0', r"'-'", '1', r"'\0'", '1', r'"--"', '0', '1']) ps1 = self.parse(s1) self.assert_num_ID_refs(ps1, 'argv', 3) self.assert_num_ID_refs(ps1, 'optind', 5) self.assert_num_klass_nodes(ps1, If, 3) self.assert_num_klass_nodes(ps1, Return, 2) self.assert_num_klass_nodes(ps1, FuncCall, 1) # strcmp self.assert_num_klass_nodes(ps1, BinaryOp, 7) # In the following code, Hash and Node were defined as # int to pacify the parser that sees they're used as # types # s2 = r''' typedef int Hash, Node; void HashDestroy(Hash* hash) { unsigned int i; if (hash == NULL) return; for (i = 0; i < hash->table_size; ++i) { Node* temp = hash->heads[i]; while (temp != NULL) { Node* temp2 = temp; free(temp->entry->key); free(temp->entry->value); free(temp->entry); temp = temp->next; free(temp2); } } free(hash->heads); hash->heads = NULL; free(hash); } ''' ps2 = self.parse(s2) self.assert_num_klass_nodes(ps2, FuncCall, 6) self.assert_num_klass_nodes(ps2, FuncDef, 1) self.assert_num_klass_nodes(ps2, For, 1) self.assert_num_klass_nodes(ps2, While, 1) self.assert_num_klass_nodes(ps2, StructRef, 10) # declarations don't count self.assert_num_ID_refs(ps2, 'hash', 6) self.assert_num_ID_refs(ps2, 'i', 4) s3 = r''' void x(void) { int a, b; if (a < b) do { a = 0; } while (0); else if (a == b) { a = 1; } } ''' ps3 = self.parse(s3) self.assert_num_klass_nodes(ps3, DoWhile, 1) self.assert_num_ID_refs(ps3, 'a', 4) self.assert_all_Constants(ps3, ['0', '0', '1']) def test_empty_statement(self): s1 = r''' void foo(void){ ; return; } ''' ps1 = self.parse(s1) self.assert_num_klass_nodes(ps1, EmptyStatement, 1) self.assert_num_klass_nodes(ps1, Return, 1) def test_switch_statement(self): def assert_case_node(node, const_value): self.assertTrue(isinstance(node, Case)) self.assertTrue(isinstance(node.expr, Constant)) self.assertEqual(node.expr.value, const_value) def assert_default_node(node): self.assertTrue(isinstance(node, Default)) s1 = r''' int foo(void) { switch (myvar) { case 10: k = 10; p = k + 1; return 10; case 20: case 30: return 20; default: break; } return 0; } ''' ps1 = self.parse(s1) switch = ps1.ext[0].body.block_items[0] block = switch.stmt.block_items assert_case_node(block[0], '10') self.assertEqual(len(block[0].stmts), 3) assert_case_node(block[1], '20') self.assertEqual(len(block[1].stmts), 0) assert_case_node(block[2], '30') self.assertEqual(len(block[2].stmts), 1) assert_default_node(block[3]) s2 = r''' int foo(void) { switch (myvar) { default: joe = moe; return 10; case 10: case 20: case 30: case 40: break; } return 0; } ''' ps2 = self.parse(s2) switch = ps2.ext[0].body.block_items[0] block = switch.stmt.block_items assert_default_node(block[0]) self.assertEqual(len(block[0].stmts), 2) assert_case_node(block[1], '10') self.assertEqual(len(block[1].stmts), 0) assert_case_node(block[2], '20') self.assertEqual(len(block[1].stmts), 0) assert_case_node(block[3], '30') self.assertEqual(len(block[1].stmts), 0) assert_case_node(block[4], '40') self.assertEqual(len(block[4].stmts), 1) def test_for_statement(self): s2 = r''' void x(void) { int i; for (i = 0; i < 5; ++i) { x = 50; } } ''' ps2 = self.parse(s2) self.assert_num_klass_nodes(ps2, For, 1) # here there are 3 refs to 'i' since the declaration doesn't count as # a ref in the visitor # self.assert_num_ID_refs(ps2, 'i', 3) s3 = r''' void x(void) { for (int i = 0; i < 5; ++i) { x = 50; } } ''' ps3 = self.parse(s3) self.assert_num_klass_nodes(ps3, For, 1) # here there are 2 refs to 'i' since the declaration doesn't count as # a ref in the visitor # self.assert_num_ID_refs(ps3, 'i', 2) s4 = r''' void x(void) { for (int i = 0;;) i; } ''' ps4 = self.parse(s4) self.assert_num_ID_refs(ps4, 'i', 1) def _open_c_file(self, name): """ Find a c file by name, taking into account the current dir can be in a couple of typical places """ testdir = os.path.dirname(__file__) name = os.path.join(testdir, 'c_files', name) assert os.path.exists(name) return open(name, 'rU') def test_whole_file(self): # See how pycparser handles a whole, real C file. # with self._open_c_file('memmgr_with_h.c') as f: code = f.read() p = self.parse(code) self.assert_num_klass_nodes(p, FuncDef, 5) # each FuncDef also has a FuncDecl. 4 declarations # + 5 definitions, overall 9 self.assert_num_klass_nodes(p, FuncDecl, 9) self.assert_num_klass_nodes(p, Typedef, 4) self.assertEqual(p.ext[4].coord.line, 88) self.assertEqual(p.ext[4].coord.file, "./memmgr.h") self.assertEqual(p.ext[6].coord.line, 10) self.assertEqual(p.ext[6].coord.file, "memmgr.c") def test_whole_file_with_stdio(self): # Parse a whole file with stdio.h included by cpp # with self._open_c_file('cppd_with_stdio_h.c') as f: code = f.read() p = self.parse(code) self.assertTrue(isinstance(p.ext[0], Typedef)) self.assertEqual(p.ext[0].coord.line, 213) self.assertEqual(p.ext[0].coord.file, "D:\eli\cpp_stuff\libc_include/stddef.h") self.assertTrue(isinstance(p.ext[-1], FuncDef)) self.assertEqual(p.ext[-1].coord.line, 15) self.assertEqual(p.ext[-1].coord.file, "example_c_file.c") self.assertTrue(isinstance(p.ext[-8], Typedef)) self.assertTrue(isinstance(p.ext[-8].type, TypeDecl)) self.assertEqual(p.ext[-8].name, 'cookie_io_functions_t') class TestCParser_typenames(TestCParser_base): """ Test issues related to the typedef-name problem. """ def test_innerscope_typedef(self): # should fail since TT is not a type in bar s1 = r''' void foo() { typedef char TT; TT x; } void bar() { TT y; } ''' self.assertRaises(ParseError, self.parse, s1) # should succeed since TT is not a type in bar s2 = r''' void foo() { typedef char TT; TT x; } void bar() { unsigned TT; } ''' self.assertTrue(isinstance(self.parse(s2), FileAST)) def test_innerscope_reuse_typedef_name(self): # identifiers can be reused in inner scopes; the original should be # restored at the end of the block s1 = r''' typedef char TT; void foo(void) { unsigned TT; TT = 10; } TT x = 5; ''' s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[1].body.block_items[0]), ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]]) self.assertEqual(expand_decl(s1_ast.ext[2]), ['Decl', 'x', ['TypeDecl', ['IdentifierType', ['TT']]]]) # this should be recognized even with an initializer s2 = r''' typedef char TT; void foo(void) { unsigned TT = 10; } ''' s2_ast = self.parse(s2) self.assertEqual(expand_decl(s2_ast.ext[1].body.block_items[0]), ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]]) # before the second local variable, TT is a type; after, it's a # variable s3 = r''' typedef char TT; void foo(void) { TT tt = sizeof(TT); unsigned TT = 10; } ''' s3_ast = self.parse(s3) self.assertEqual(expand_decl(s3_ast.ext[1].body.block_items[0]), ['Decl', 'tt', ['TypeDecl', ['IdentifierType', ['TT']]]]) self.assertEqual(expand_decl(s3_ast.ext[1].body.block_items[1]), ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]]) # a variable and its type can even share the same name s4 = r''' typedef char TT; void foo(void) { TT TT = sizeof(TT); unsigned uu = TT * 2; } ''' s4_ast = self.parse(s4) self.assertEqual(expand_decl(s4_ast.ext[1].body.block_items[0]), ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['TT']]]]) self.assertEqual(expand_decl(s4_ast.ext[1].body.block_items[1]), ['Decl', 'uu', ['TypeDecl', ['IdentifierType', ['unsigned']]]]) # ensure an error is raised if a type, redeclared as a variable, is # used as a type s5 = r''' typedef char TT; void foo(void) { unsigned TT = 10; TT erroneous = 20; } ''' self.assertRaises(ParseError, self.parse, s5) def test_parameter_reuse_typedef_name(self): # identifiers can be reused as parameter names; parameter name scope # begins and ends with the function body; it's important that TT is # used immediately before the LBRACE or after the RBRACE, to test # a corner case s1 = r''' typedef char TT; void foo(unsigned TT, TT bar) { TT = 10; } TT x = 5; ''' s1_ast = self.parse(s1) self.assertEqual(expand_decl(s1_ast.ext[1].decl), ['Decl', 'foo', ['FuncDecl', [ ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]], ['Decl', 'bar', ['TypeDecl', ['IdentifierType', ['TT']]]]], ['TypeDecl', ['IdentifierType', ['void']]]]]) # the scope of a parameter name in a function declaration ends at the # end of the declaration...so it is effectively never used; it's # important that TT is used immediately after the declaration, to # test a corner case s2 = r''' typedef char TT; void foo(unsigned TT, TT bar); TT x = 5; ''' s2_ast = self.parse(s2) self.assertEqual(expand_decl(s2_ast.ext[1]), ['Decl', 'foo', ['FuncDecl', [ ['Decl', 'TT', ['TypeDecl', ['IdentifierType', ['unsigned']]]], ['Decl', 'bar', ['TypeDecl', ['IdentifierType', ['TT']]]]], ['TypeDecl', ['IdentifierType', ['void']]]]]) # ensure an error is raised if a type, redeclared as a parameter, is # used as a type s3 = r''' typedef char TT; void foo(unsigned TT, TT bar) { TT erroneous = 20; } ''' self.assertRaises(ParseError, self.parse, s3) def test_nested_function_decls(self): # parameter names of nested function declarations must not escape into # the top-level function _definition's_ scope; the following must # succeed because TT is still a typedef inside foo's body s1 = r''' typedef char TT; void foo(unsigned bar(int TT)) { TT x = 10; } ''' self.assertTrue(isinstance(self.parse(s1), FileAST)) def test_samescope_reuse_name(self): # a typedef name cannot be reused as an object name in the same scope s1 = r''' typedef char TT; char TT = 5; ''' self.assertRaises(ParseError, self.parse, s1) # ...and vice-versa s2 = r''' char TT = 5; typedef char TT; ''' self.assertRaises(ParseError, self.parse, s2) if __name__ == '__main__': #~ suite = unittest.TestLoader().loadTestsFromNames( #~ ['test_c_parser.TestCParser_fundamentals.test_typedef']) #~ unittest.TextTestRunner(verbosity=2).run(suite) unittest.main() pycparser-2.14/tests/all_tests.py0000755000175000017500000000057312514761152017710 0ustar elibeneliben00000000000000#!/usr/bin/env python import sys sys.path[0:0] = ['.', '..'] import unittest suite = unittest.TestLoader().loadTestsFromNames( [ 'test_c_lexer', 'test_c_ast', 'test_general', 'test_c_parser', 'test_c_generator', ] ) testresult = unittest.TextTestRunner(verbosity=1).run(suite) sys.exit(0 if testresult.wasSuccessful() else 1) pycparser-2.14/tests/c_files/0000775000175000017500000000000012535724325016746 5ustar elibeneliben00000000000000pycparser-2.14/tests/c_files/memmgr.c0000644000175000017500000001273512257601020020367 0ustar elibeneliben00000000000000//---------------------------------------------------------------- // Statically-allocated memory manager // // by Eli Bendersky (eliben@gmail.com) // // This code is in the public domain. //---------------------------------------------------------------- #include "memmgr.h" typedef ulong Align; union mem_header_union { struct { // Pointer to the next block in the free list // union mem_header_union* next; // Size of the block (in quantas of sizeof(mem_header_t)) // ulong size; } s; // Used to align headers in memory to a boundary // Align align_dummy; }; typedef union mem_header_union mem_header_t; // Initial empty list // static mem_header_t base; // Start of free list // static mem_header_t* freep = 0; // Static pool for new allocations // static byte pool[POOL_SIZE] = {0}; static ulong pool_free_pos = 0; void memmgr_init() { base.s.next = 0; base.s.size = 0; freep = 0; pool_free_pos = 0; } static mem_header_t* get_mem_from_pool(ulong nquantas) { ulong total_req_size; mem_header_t* h; if (nquantas < MIN_POOL_ALLOC_QUANTAS) nquantas = MIN_POOL_ALLOC_QUANTAS; total_req_size = nquantas * sizeof(mem_header_t); if (pool_free_pos + total_req_size <= POOL_SIZE) { h = (mem_header_t*) (pool + pool_free_pos); h->s.size = nquantas; memmgr_free((void*) (h + 1)); pool_free_pos += total_req_size; } else { return 0; } return freep; } // Allocations are done in 'quantas' of header size. // The search for a free block of adequate size begins at the point 'freep' // where the last block was found. // If a too-big block is found, it is split and the tail is returned (this // way the header of the original needs only to have its size adjusted). // The pointer returned to the user points to the free space within the block, // which begins one quanta after the header. // void* memmgr_alloc(ulong nbytes) { mem_header_t* p; mem_header_t* prevp; // Calculate how many quantas are required: we need enough to house all // the requested bytes, plus the header. The -1 and +1 are there to make sure // that if nbytes is a multiple of nquantas, we don't allocate too much // ulong nquantas = (nbytes + sizeof(mem_header_t) - 1) / sizeof(mem_header_t) + 1; // First alloc call, and no free list yet ? Use 'base' for an initial // denegerate block of size 0, which points to itself // if ((prevp = freep) == 0) { base.s.next = freep = prevp = &base; base.s.size = 0; } for (p = prevp->s.next; ; prevp = p, p = p->s.next) { // big enough ? if (p->s.size >= nquantas) { // exactly ? if (p->s.size == nquantas) { // just eliminate this block from the free list by pointing // its prev's next to its next // prevp->s.next = p->s.next; } else // too big { p->s.size -= nquantas; p += p->s.size; p->s.size = nquantas; } freep = prevp; return (void*) (p + 1); } // Reached end of free list ? // Try to allocate the block from the pool. If that succeeds, // get_mem_from_pool adds the new block to the free list and // it will be found in the following iterations. If the call // to get_mem_from_pool doesn't succeed, we've run out of // memory // else if (p == freep) { if ((p = get_mem_from_pool(nquantas)) == 0) { #ifdef DEBUG_MEMMGR_FATAL printf("!! Memory allocation failed !!\n"); #endif return 0; } } } } // Scans the free list, starting at freep, looking the the place to insert the // free block. This is either between two existing blocks or at the end of the // list. In any case, if the block being freed is adjacent to either neighbor, // the adjacent blocks are combined. // void memmgr_free(void* ap) { mem_header_t* block; mem_header_t* p; // acquire pointer to block header block = ((mem_header_t*) ap) - 1; // Find the correct place to place the block in (the free list is sorted by // address, increasing order) // for (p = freep; !(block > p && block < p->s.next); p = p->s.next) { // Since the free list is circular, there is one link where a // higher-addressed block points to a lower-addressed block. // This condition checks if the block should be actually // inserted between them // if (p >= p->s.next && (block > p || block < p->s.next)) break; } // Try to combine with the higher neighbor // if (block + block->s.size == p->s.next) { block->s.size += p->s.next->s.size; block->s.next = p->s.next->s.next; } else { block->s.next = p->s.next; } // Try to combine with the lower neighbor // if (p + p->s.size == block) { p->s.size += block->s.size; p->s.next = block->s.next; } else { p->s.next = block; } freep = p; } pycparser-2.14/tests/c_files/memmgr_with_h.c0000644000175000017500000000770612257601020021733 0ustar elibeneliben00000000000000#line 1 "memmgr.c" #line 1 "./memmgr.h" typedef unsigned char byte; typedef unsigned long ulong; void memmgr_init(); void* memmgr_alloc(ulong nbytes); void memmgr_free(void* ap); void memmgr_print_stats(); #line 9 "memmgr.c" typedef ulong Align; union mem_header_union { struct { union mem_header_union* next; ulong size; } s; Align align_dummy; }; typedef union mem_header_union mem_header_t; static mem_header_t base; static mem_header_t* freep = 0; static byte pool[8 * 1024] = {0}; static ulong pool_free_pos = 0; void memmgr_init() { base.s.next = 0; base.s.size = 0; freep = 0; pool_free_pos = 0; } void memmgr_print_stats() { mem_header_t* p; printf("------ Memory manager stats ------\n\n"); printf( "Pool: free_pos = %lu (%lu bytes left)\n\n", pool_free_pos,8 * 1024 - pool_free_pos); p = (mem_header_t*) pool; while (p < (mem_header_t*) (pool + pool_free_pos)) { printf( " * Addr: 0x%8lu; Size: %8lu\n", p, p->s.size); p += p->s.size; } printf("\nFree list:\n\n"); if (freep) { p = freep; while (1) { printf( " * Addr: 0x%8lu; Size: %8lu; Next: 0x%8lu\n", p, p->s.size, p->s.next); p = p->s.next; if (p == freep) break; } } else { printf("Empty\n"); } printf("\n"); } static mem_header_t* get_mem_from_pool(ulong nquantas) { ulong total_req_size; mem_header_t* h; if (nquantas < 16) nquantas = 16; total_req_size = nquantas * sizeof(mem_header_t); if (pool_free_pos + total_req_size <= 8 * 1024) { h = (mem_header_t*) (pool + pool_free_pos); h->s.size = nquantas; memmgr_free((void*) (h + 1)); pool_free_pos += total_req_size; } else { return 0; } return freep; } void* memmgr_alloc(ulong nbytes) { mem_header_t* p; mem_header_t* prevp; ulong nquantas = (nbytes + sizeof(mem_header_t) - 1) / sizeof(mem_header_t) + 1; if ((prevp = freep) == 0) { base.s.next = freep = prevp = &base; base.s.size = 0; } for (p = prevp->s.next; ; prevp = p, p = p->s.next) { if (p->s.size >= nquantas) { if (p->s.size == nquantas) { prevp->s.next = p->s.next; } else { p->s.size -= nquantas; p += p->s.size; p->s.size = nquantas; } freep = prevp; return (void*) (p + 1); } else if (p == freep) { if ((p = get_mem_from_pool(nquantas)) == 0) { return 0; } } } } void memmgr_free(void* ap) { mem_header_t* block; mem_header_t* p; block = ((mem_header_t*) ap) - 1; for (p = freep; !(block > p && block < p->s.next); p = p->s.next) { if (p >= p->s.next && (block > p || block < p->s.next)) break; } if (block + block->s.size == p->s.next) { block->s.size += p->s.next->s.size; block->s.next = p->s.next->s.next; } else { block->s.next = p->s.next; } if (p + p->s.size == block) { p->s.size += block->s.size; p->s.next = block->s.next; } else { p->s.next = block; } freep = p; } pycparser-2.14/tests/c_files/simplemain.c0000644000175000017500000000010012257601020021220 0ustar elibeneliben00000000000000#include "hdir\emptydir\..\9\inc.h" int main() { return 0; } pycparser-2.14/tests/c_files/cppd_with_stdio_h.c0000644000175000017500000010602312257601020022567 0ustar elibeneliben00000000000000#line 1 "example_c_file.c" #line 1 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 19 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 25 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 11 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 1 "D:\eli\cpp_stuff\libc_include/newlib.h" #line 3 "D:\eli\cpp_stuff\libc_include/newlib.h" #line 16 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 1 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 52 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 58 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 83 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 86 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 89 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 95 "D:\eli\cpp_stuff\libc_include/machine/ieeefp.h" #line 5 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 11 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 143 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 157 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 195 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 207 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 17 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 21 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 30 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 19 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 26 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 30 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 35 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 39 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 42 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 53 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 56 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 67 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 76 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 98 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 108 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 126 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 131 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 170 "D:\eli\cpp_stuff\libc_include/stddef.h" typedef long unsigned int size_t; #line 243 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 246 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 290 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 302 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 310 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 361 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 365 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 418 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 422 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 427 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 35 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 19 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 26 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 30 "D:\eli\cpp_stuff\libc_include/stdarg.h" typedef char* __builtin_va_list; typedef __builtin_va_list __gnuc_va_list; #line 50 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 66 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 80 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 98 "D:\eli\cpp_stuff\libc_include/stdarg.h" #line 38 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 44 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 6 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 1 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 11 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 21 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 14 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 8 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 1 "D:\eli\cpp_stuff\libc_include/machine/_types.h" #line 4 "D:\eli\cpp_stuff\libc_include/machine/_types.h" #line 1 "D:\eli\cpp_stuff\libc_include/machine/_default_types.h" #line 4 "D:\eli\cpp_stuff\libc_include/machine/_default_types.h" #line 15 "D:\eli\cpp_stuff\libc_include/machine/_default_types.h" #line 17 "D:\eli\cpp_stuff\libc_include/machine/_default_types.h" #line 1 "D:\eli\cpp_stuff\libc_include/limits.h" #line 1 "D:\eli\cpp_stuff\libc_include/newlib.h" #line 3 "D:\eli\cpp_stuff\libc_include/newlib.h" #line 5 "D:\eli\cpp_stuff\libc_include/limits.h" #line 19 "D:\eli\cpp_stuff\libc_include/limits.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 11 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 143 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 157 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 195 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 207 "D:\eli\cpp_stuff\libc_include/sys/config.h" #line 25 "D:\eli\cpp_stuff\libc_include/limits.h" #line 79 "D:\eli\cpp_stuff\libc_include/limits.h" #line 23 "D:\eli\cpp_stuff\libc_include/machine/_default_types.h" typedef signed char __int8_t ; typedef unsigned char __uint8_t ; typedef signed short __int16_t; typedef unsigned short __uint16_t; typedef __int16_t __int_least16_t; typedef __uint16_t __uint_least16_t; typedef signed int __int32_t; typedef unsigned int __uint32_t; typedef __int32_t __int_least32_t; typedef __uint32_t __uint_least32_t; #line 8 "D:\eli\cpp_stuff\libc_include/machine/_types.h" #line 13 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/lock.h" typedef int _LOCK_T; typedef int _LOCK_RECURSIVE_T; #line 14 "D:\eli\cpp_stuff\libc_include/sys/_types.h" typedef long _off_t; typedef short __dev_t; typedef unsigned short __uid_t; typedef unsigned short __gid_t; typedef long long _off64_t; #line 43 "D:\eli\cpp_stuff\libc_include/sys/_types.h" typedef long _fpos_t; typedef int _ssize_t; #line 1 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 19 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 26 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 30 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 35 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 39 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 42 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 53 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 56 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 67 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 76 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 98 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 108 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 126 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 131 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 170 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 243 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 246 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 290 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 302 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 310 "D:\eli\cpp_stuff\libc_include/stddef.h" typedef unsigned int wint_t; #line 361 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 365 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 418 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 422 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 427 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 64 "D:\eli\cpp_stuff\libc_include/sys/_types.h" typedef struct { int __count; union { wint_t __wch; unsigned char __wchb[4]; } __value; } _mbstate_t; typedef _LOCK_RECURSIVE_T _flock_t; typedef void *_iconv_t; #line 15 "D:\eli\cpp_stuff\libc_include/sys/reent.h" typedef unsigned long __ULong; struct _reent; #line 43 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct _Bigint { struct _Bigint *_next; int _k, _maxwds, _sign, _wds; __ULong _x[1]; }; struct __tm { int __tm_sec; int __tm_min; int __tm_hour; int __tm_mday; int __tm_mon; int __tm_year; int __tm_wday; int __tm_yday; int __tm_isdst; }; #line 68 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct _on_exit_args { void * _fnargs[32]; void * _dso_handle[32]; __ULong _fntypes; #line 77 "D:\eli\cpp_stuff\libc_include/sys/reent.h" __ULong _is_cxa; }; struct _atexit { struct _atexit *_next; int _ind; void (*_fns[32])(void); struct _on_exit_args _on_exit_args; }; #line 104 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct __sbuf { unsigned char *_base; int _size; }; #line 134 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 141 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct __sFILE { unsigned char *_p; int _r; int _w; short _flags; short _file; struct __sbuf _bf; int _lbfsize; char * _cookie; int(*_read)(); #line 176 "D:\eli\cpp_stuff\libc_include/sys/reent.h" int(*_write)(); #line 178 "D:\eli\cpp_stuff\libc_include/sys/reent.h" _fpos_t(*_seek)(); int(*_close)(); struct __sbuf _ub; unsigned char *_up; int _ur; unsigned char _ubuf[3]; unsigned char _nbuf[1]; struct __sbuf _lb; int _blksize; int _offset; struct _reent *_data; _flock_t _lock; }; typedef struct __sFILE __FILE; struct _glue { struct _glue *_next; int _niobs; __FILE *_iobs; }; #line 284 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct _rand48 { unsigned short _seed[3]; unsigned short _mult[3]; unsigned short _add; }; #line 313 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 344 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 350 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 420 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 452 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 474 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 478 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 482 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 494 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 496 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 503 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 505 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 508 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 531 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 533 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 536 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct _reent { int _errno; #line 571 "D:\eli\cpp_stuff\libc_include/sys/reent.h" __FILE *_stdin, *_stdout, *_stderr; int _inc; char _emergency[25]; int _current_category; char *_current_locale; int __sdidinit; void(*__cleanup)(); struct _Bigint *_result; int _result_k; struct _Bigint *_p5s; struct _Bigint **_freelist; int _cvtlen; char *_cvtbuf; union { struct { unsigned int _unused_rand; char * _strtok_last; char _asctime_buf[26]; struct __tm _localtime_buf; int _gamma_signgam; unsigned long long _rand_next; struct _rand48 _r48; _mbstate_t _mblen_state; _mbstate_t _mbtowc_state; _mbstate_t _wctomb_state; char _l64a_buf[8]; char _signal_buf[24]; int _getdate_err; _mbstate_t _mbrlen_state; _mbstate_t _mbrtowc_state; _mbstate_t _mbsrtowcs_state; _mbstate_t _wcrtomb_state; _mbstate_t _wcsrtombs_state; } _reent; #line 619 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct { unsigned char * _nextf[30]; unsigned int _nmalloc[30]; } _unused; } _new; struct _atexit *_atexit; struct _atexit _atexit0; void (**(_sig_func))(int); #line 637 "D:\eli\cpp_stuff\libc_include/sys/reent.h" struct _glue __sglue; __FILE __sf[3]; }; #line 689 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 751 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 791 "D:\eli\cpp_stuff\libc_include/sys/reent.h" extern struct _reent *_impure_ptr; extern struct _reent * _global_impure_ptr; void _reclaim_reent(); #line 46 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 17 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 1 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 11 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 21 "D:\eli\cpp_stuff\libc_include/_ansi.h" #line 21 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 1 "D:\eli\cpp_stuff\libc_include/machine/_types.h" #line 4 "D:\eli\cpp_stuff\libc_include/machine/_types.h" #line 26 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 33 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 8 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 43 "D:\eli\cpp_stuff\libc_include/sys/_types.h" #line 62 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 1 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 19 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 26 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 30 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 35 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 39 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 42 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 53 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 56 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 67 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 76 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 98 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 108 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 126 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 131 "D:\eli\cpp_stuff\libc_include/stddef.h" typedef long int ptrdiff_t; #line 170 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 243 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 246 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 290 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 302 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 310 "D:\eli\cpp_stuff\libc_include/stddef.h" typedef int wchar_t; #line 361 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 365 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 418 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 422 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 427 "D:\eli\cpp_stuff\libc_include/stddef.h" #line 70 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 1 "D:\eli\cpp_stuff\libc_include/machine/types.h" #line 9 "D:\eli\cpp_stuff\libc_include/machine/types.h" typedef long int __off_t; typedef int __pid_t; typedef long int __loff_t; #line 71 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 79 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned int u_int; typedef unsigned long u_long; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long clock_t; typedef long time_t; struct timespec { time_t tv_sec; long tv_nsec; }; struct itimerspec { struct timespec it_interval; struct timespec it_value; }; typedef long daddr_t; typedef char * caddr_t; #line 131 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef unsigned short ino_t; #line 160 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef _off_t off_t; typedef __dev_t dev_t; typedef __uid_t uid_t; typedef __gid_t gid_t; typedef int pid_t; typedef long key_t; typedef _ssize_t ssize_t; typedef unsigned int mode_t; typedef unsigned short nlink_t; #line 200 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 209 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef long fd_mask; #line 221 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef struct _types_fd_set { fd_mask fds_bits[(((64)+(((sizeof (fd_mask) * 8))-1))/((sizeof (fd_mask) * 8)))]; } _types_fd_set; #line 236 "D:\eli\cpp_stuff\libc_include/sys/types.h" typedef unsigned long clockid_t; typedef unsigned long timer_t; typedef unsigned long useconds_t; typedef long suseconds_t; #line 1 "D:\eli\cpp_stuff\libc_include/sys/features.h" #line 20 "D:\eli\cpp_stuff\libc_include/sys/features.h" #line 257 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 266 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 273 "D:\eli\cpp_stuff\libc_include/sys/types.h" #line 47 "D:\eli\cpp_stuff\libc_include/stdio.h" typedef __FILE FILE; typedef _fpos_t fpos_t; #line 1 "D:\eli\cpp_stuff\libc_include/sys/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/lock.h" #line 5 "D:\eli\cpp_stuff\libc_include/sys/stdio.h" #line 1 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 6 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 43 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 68 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 77 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 104 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 134 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 141 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 284 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 313 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 344 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 350 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 420 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 452 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 474 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 478 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 482 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 494 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 496 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 503 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 505 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 508 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 531 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 533 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 536 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 571 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 619 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 637 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 689 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 751 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 791 "D:\eli\cpp_stuff\libc_include/sys/reent.h" #line 6 "D:\eli\cpp_stuff\libc_include/sys/stdio.h" #line 11 "D:\eli\cpp_stuff\libc_include/sys/stdio.h" #line 66 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 96 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 163 "D:\eli\cpp_stuff\libc_include/stdio.h" FILE * tmpfile(); char * tmpnam(); int fclose(); int fflush(); FILE * freopen(); void setbuf(); int setvbuf(); int fprintf(); #line 179 "D:\eli\cpp_stuff\libc_include/stdio.h" int fscanf(); #line 181 "D:\eli\cpp_stuff\libc_include/stdio.h" int printf(); #line 183 "D:\eli\cpp_stuff\libc_include/stdio.h" int scanf(); #line 185 "D:\eli\cpp_stuff\libc_include/stdio.h" int sscanf(); #line 187 "D:\eli\cpp_stuff\libc_include/stdio.h" int vfprintf(); #line 189 "D:\eli\cpp_stuff\libc_include/stdio.h" int vprintf(); #line 191 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsprintf(); #line 193 "D:\eli\cpp_stuff\libc_include/stdio.h" int fgetc(); char * fgets(); int fputc(); int fputs(); int getc(); int getchar(); char * gets(); int putc(); int putchar(); int puts(); int ungetc(); size_t fread(); size_t fwrite(); int fgetpos(); int fseek(); int fsetpos(); long ftell(); void rewind(); void clearerr(); int feof(); int ferror(); void perror(); FILE * fopen(); int sprintf(); #line 227 "D:\eli\cpp_stuff\libc_include/stdio.h" int remove(); int rename(); int fseeko(); off_t ftello(); int asiprintf(); #line 241 "D:\eli\cpp_stuff\libc_include/stdio.h" char * asniprintf(); #line 243 "D:\eli\cpp_stuff\libc_include/stdio.h" char * asnprintf(); #line 245 "D:\eli\cpp_stuff\libc_include/stdio.h" int asprintf(); #line 247 "D:\eli\cpp_stuff\libc_include/stdio.h" int diprintf(); #line 250 "D:\eli\cpp_stuff\libc_include/stdio.h" int fcloseall(); int fiprintf(); #line 254 "D:\eli\cpp_stuff\libc_include/stdio.h" int fiscanf(); #line 256 "D:\eli\cpp_stuff\libc_include/stdio.h" int iprintf(); #line 258 "D:\eli\cpp_stuff\libc_include/stdio.h" int iscanf(); #line 260 "D:\eli\cpp_stuff\libc_include/stdio.h" int siprintf(); #line 262 "D:\eli\cpp_stuff\libc_include/stdio.h" int siscanf(); #line 264 "D:\eli\cpp_stuff\libc_include/stdio.h" int snprintf(); #line 266 "D:\eli\cpp_stuff\libc_include/stdio.h" int sniprintf(); #line 268 "D:\eli\cpp_stuff\libc_include/stdio.h" char * tempnam(); int vasiprintf(); #line 271 "D:\eli\cpp_stuff\libc_include/stdio.h" char * vasniprintf(); #line 273 "D:\eli\cpp_stuff\libc_include/stdio.h" char * vasnprintf(); #line 275 "D:\eli\cpp_stuff\libc_include/stdio.h" int vasprintf(); #line 277 "D:\eli\cpp_stuff\libc_include/stdio.h" int vdiprintf(); #line 279 "D:\eli\cpp_stuff\libc_include/stdio.h" int vfiprintf(); #line 281 "D:\eli\cpp_stuff\libc_include/stdio.h" int vfiscanf(); #line 283 "D:\eli\cpp_stuff\libc_include/stdio.h" int vfscanf(); #line 285 "D:\eli\cpp_stuff\libc_include/stdio.h" int viprintf(); #line 287 "D:\eli\cpp_stuff\libc_include/stdio.h" int viscanf(); #line 289 "D:\eli\cpp_stuff\libc_include/stdio.h" int vscanf(); #line 291 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsiprintf(); #line 293 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsiscanf(); #line 295 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsniprintf(); #line 297 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsnprintf(); #line 299 "D:\eli\cpp_stuff\libc_include/stdio.h" int vsscanf(); #line 301 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 307 "D:\eli\cpp_stuff\libc_include/stdio.h" FILE * fdopen(); int fileno(); int getw(); int pclose(); FILE * popen(); int putw(); void setbuffer(); int setlinebuf(); int getc_unlocked(); int getchar_unlocked(); void flockfile(); int ftrylockfile(); void funlockfile(); int putc_unlocked(); int putchar_unlocked(); #line 331 "D:\eli\cpp_stuff\libc_include/stdio.h" int dprintf(); #line 337 "D:\eli\cpp_stuff\libc_include/stdio.h" FILE * fmemopen(); FILE * open_memstream(); int vdprintf(); #line 345 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 351 "D:\eli\cpp_stuff\libc_include/stdio.h" int _asiprintf_r(); #line 354 "D:\eli\cpp_stuff\libc_include/stdio.h" char * _asniprintf_r(); #line 356 "D:\eli\cpp_stuff\libc_include/stdio.h" char * _asnprintf_r(); #line 358 "D:\eli\cpp_stuff\libc_include/stdio.h" int _asprintf_r(); #line 360 "D:\eli\cpp_stuff\libc_include/stdio.h" int _diprintf_r(); #line 362 "D:\eli\cpp_stuff\libc_include/stdio.h" int _dprintf_r(); #line 364 "D:\eli\cpp_stuff\libc_include/stdio.h" int _fclose_r(); int _fcloseall_r(); FILE * _fdopen_r(); int _fflush_r(); char * _fgets_r(); int _fiprintf_r(); #line 371 "D:\eli\cpp_stuff\libc_include/stdio.h" int _fiscanf_r(); #line 373 "D:\eli\cpp_stuff\libc_include/stdio.h" FILE * _fmemopen_r(); FILE * _fopen_r(); int _fprintf_r(); #line 377 "D:\eli\cpp_stuff\libc_include/stdio.h" int _fputc_r(); int _fputs_r(); size_t _fread_r(); int _fscanf_r(); #line 382 "D:\eli\cpp_stuff\libc_include/stdio.h" int _fseek_r(); long _ftell_r(); size_t _fwrite_r(); int _getc_r(); int _getc_unlocked_r(); int _getchar_r(); int _getchar_unlocked_r(); char * _gets_r(); int _iprintf_r(); #line 392 "D:\eli\cpp_stuff\libc_include/stdio.h" int _iscanf_r(); #line 394 "D:\eli\cpp_stuff\libc_include/stdio.h" int _mkstemp_r(); char * _mktemp_r(); FILE * _open_memstream_r(); void _perror_r(); int _printf_r(); #line 400 "D:\eli\cpp_stuff\libc_include/stdio.h" int _putc_r(); int _putc_unlocked_r(); int _putchar_unlocked_r(); int _putchar_r(); int _puts_r(); int _remove_r(); int _rename_r(); #line 408 "D:\eli\cpp_stuff\libc_include/stdio.h" int _scanf_r(); #line 410 "D:\eli\cpp_stuff\libc_include/stdio.h" int _siprintf_r(); #line 412 "D:\eli\cpp_stuff\libc_include/stdio.h" int _siscanf_r(); #line 414 "D:\eli\cpp_stuff\libc_include/stdio.h" int _sniprintf_r(); #line 416 "D:\eli\cpp_stuff\libc_include/stdio.h" int _snprintf_r(); #line 418 "D:\eli\cpp_stuff\libc_include/stdio.h" int _sprintf_r(); #line 420 "D:\eli\cpp_stuff\libc_include/stdio.h" int _sscanf_r(); #line 422 "D:\eli\cpp_stuff\libc_include/stdio.h" char * _tempnam_r(); FILE * _tmpfile_r(); char * _tmpnam_r(); int _ungetc_r(); int _vasiprintf_r(); #line 428 "D:\eli\cpp_stuff\libc_include/stdio.h" char * _vasniprintf_r(); #line 430 "D:\eli\cpp_stuff\libc_include/stdio.h" char * _vasnprintf_r(); #line 432 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vasprintf_r(); #line 434 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vdiprintf_r(); #line 436 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vdprintf_r(); #line 438 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vfiprintf_r(); #line 440 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vfiscanf_r(); #line 442 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vfprintf_r(); #line 444 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vfscanf_r(); #line 446 "D:\eli\cpp_stuff\libc_include/stdio.h" int _viprintf_r(); #line 448 "D:\eli\cpp_stuff\libc_include/stdio.h" int _viscanf_r(); #line 450 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vprintf_r(); #line 452 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vscanf_r(); #line 454 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsiprintf_r(); #line 456 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsiscanf_r(); #line 458 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsniprintf_r(); #line 460 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsnprintf_r(); #line 462 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsprintf_r(); #line 464 "D:\eli\cpp_stuff\libc_include/stdio.h" int _vsscanf_r(); #line 466 "D:\eli\cpp_stuff\libc_include/stdio.h" ssize_t __getdelim(); ssize_t __getline(); #line 493 "D:\eli\cpp_stuff\libc_include/stdio.h" int __srget_r(); int __swbuf_r(); #line 500 "D:\eli\cpp_stuff\libc_include/stdio.h" FILE * funopen(); #line 514 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 518 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 520 "D:\eli\cpp_stuff\libc_include/stdio.h" typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n); typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf, size_t __n); typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence); typedef int cookie_close_function_t(void *__cookie); typedef struct { #line 535 "D:\eli\cpp_stuff\libc_include/stdio.h" cookie_read_function_t *read; cookie_write_function_t *write; cookie_seek_function_t *seek; cookie_close_function_t *close; } cookie_io_functions_t; FILE * fopencookie(); #line 542 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 549 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 574 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 580 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 603 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 613 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 621 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 626 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 657 "D:\eli\cpp_stuff\libc_include/stdio.h" #line 4 "example_c_file.c" #line 8 "example_c_file.c" char tav = 'b'; char maav = L"'guruguru\n"; char* moral = "ain't I \\\"\\\t\" a nice string?\"\""; char* comment_inside = "but you will /* see it */!!!!"; char* i_have_newlines = "line one\nline two\nline three"; int main() { auto char* multi = "a multi"; } pycparser-2.14/tests/c_files/example_c_file.c0000644000175000017500000000037212257601020022031 0ustar elibeneliben00000000000000char tav = 'b'; char* moral = "ain't I \\\"\\\t\" a nice string?\"\""; char* comment_inside = "but you will /* see it */!!!!"; char* i_have_newlines = "line one\nline two\nline three"; int main() { auto char* multi = "a multi"; } pycparser-2.14/tests/c_files/year.c0000644000175000017500000000240112257601020020030 0ustar elibeneliben00000000000000#include #include #include #include /* C99 bools */ _Bool just_a_flag = false; bool another_flag = true; void convert(int thousands, int hundreds, int tens, int ones) { char *num[] = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}; char *for_ten[] = {"", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninty"}; char *af_ten[] = {"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen"}; printf("\nThe year in words is:\n"); printf("%s thousand", num[thousands]); if (hundreds != 0) printf(" %s hundred", num[hundreds]); if (tens != 1) printf(" %s %s", for_ten[tens], num[ones]); else printf(" %s", af_ten[ones]); va_list jajaja; } int main() { int year; int n1000, n100, n10, n1; printf("\nEnter the year (4 digits): "); scanf("%d", &year); if (year > 9999 || year < 1000) { printf("\nError !! The year must contain 4 digits."); exit(EXIT_FAILURE); } n1000 = year/1000; n100 = ((year)%1000)/100; n10 = (year%100)/10; n1 = ((year%10)%10); convert(n1000, n100, n10, n1); return 0; } pycparser-2.14/tests/c_files/memmgr.h0000644000175000017500000000566712257601020020402 0ustar elibeneliben00000000000000//---------------------------------------------------------------- // Statically-allocated memory manager // // by Eli Bendersky (eliben@gmail.com) // // This code is in the public domain. //---------------------------------------------------------------- #ifndef MEMMGR_H #define MEMMGR_H // // Memory manager: dynamically allocates memory from // a fixed pool that is allocated statically at link-time. // // Usage: after calling memmgr_init() in your // initialization routine, just use memmgr_alloc() instead // of malloc() and memmgr_free() instead of free(). // Naturally, you can use the preprocessor to define // malloc() and free() as aliases to memmgr_alloc() and // memmgr_free(). This way the manager will be a drop-in // replacement for the standard C library allocators, and can // be useful for debugging memory allocation problems and // leaks. // // Preprocessor flags you can define to customize the // memory manager: // // DEBUG_MEMMGR_FATAL // Allow printing out a message when allocations fail // // DEBUG_MEMMGR_SUPPORT_STATS // Allow printing out of stats in function // memmgr_print_stats When this is disabled, // memmgr_print_stats does nothing. // // Note that in production code on an embedded system // you'll probably want to keep those undefined, because // they cause printf to be called. // // POOL_SIZE // Size of the pool for new allocations. This is // effectively the heap size of the application, and can // be changed in accordance with the available memory // resources. // // MIN_POOL_ALLOC_QUANTAS // Internally, the memory manager allocates memory in // quantas roughly the size of two ulong objects. To // minimize pool fragmentation in case of multiple allocations // and deallocations, it is advisable to not allocate // blocks that are too small. // This flag sets the minimal ammount of quantas for // an allocation. If the size of a ulong is 4 and you // set this flag to 16, the minimal size of an allocation // will be 4 * 2 * 16 = 128 bytes // If you have a lot of small allocations, keep this value // low to conserve memory. If you have mostly large // allocations, it is best to make it higher, to avoid // fragmentation. // // Notes: // 1. This memory manager is *not thread safe*. Use it only // for single thread/task applications. // #define DEBUG_MEMMGR_SUPPORT_STATS 1 #define POOL_SIZE 8 * 1024 #define MIN_POOL_ALLOC_QUANTAS 16 typedef unsigned char byte; typedef unsigned long ulong; // Initialize the memory manager. This function should be called // only once in the beginning of the program. // void memmgr_init(); // 'malloc' clone // void* memmgr_alloc(ulong nbytes); // 'free' clone // void memmgr_free(void* ap); // Prints statistics about the current state of the memory // manager // void memmgr_print_stats(); #endif // MEMMGR_H pycparser-2.14/tests/c_files/empty.h0000644000175000017500000000016212257601020020235 0ustar elibeneliben00000000000000#define PERFECTLY #define NORMAL #define TO #define HAVE #define HEADER #define WITH #define ONLY #define DEFINES pycparser-2.14/tests/c_files/hdir/0000775000175000017500000000000012535724325017674 5ustar elibeneliben00000000000000pycparser-2.14/tests/c_files/hdir/9/0000775000175000017500000000000012535724325020044 5ustar elibeneliben00000000000000pycparser-2.14/tests/c_files/hdir/9/inc.h0000644000175000017500000000001712257601020020745 0ustar elibeneliben00000000000000extern int ie; pycparser-2.14/tests/test_c_generator.py0000664000175000017500000001504012515205056021234 0ustar elibeneliben00000000000000import sys import unittest # Run from the root dir sys.path.insert(0, '.') from pycparser import c_parser, c_generator, c_ast _c_parser = c_parser.CParser( lex_optimize=False, yacc_debug=True, yacc_optimize=False, yacctab='yacctab') def compare_asts(ast1, ast2): if type(ast1) != type(ast2): return False if isinstance(ast1, tuple) and isinstance(ast2, tuple): if ast1[0] != ast2[0]: return False ast1 = ast1[1] ast2 = ast2[1] return compare_asts(ast1, ast2) for attr in ast1.attr_names: if getattr(ast1, attr) != getattr(ast2, attr): return False for i, c1 in enumerate(ast1.children()): if compare_asts(c1, ast2.children()[i]) == False: return False return True def parse_to_ast(src): return _c_parser.parse(src) class TestFunctionDeclGeneration(unittest.TestCase): class _FuncDeclVisitor(c_ast.NodeVisitor): def __init__(self): self.stubs = [] def visit_FuncDecl(self, node): gen = c_generator.CGenerator() self.stubs.append(gen.visit(node)) def test_partial_funcdecl_generation(self): src = r''' void noop(void); void *something(void *thing); int add(int x, int y);''' ast = parse_to_ast(src) v = TestFunctionDeclGeneration._FuncDeclVisitor() v.visit(ast) self.assertEqual(len(v.stubs), 3) self.assertTrue(r'void noop(void)' in v.stubs) self.assertTrue(r'void *something(void *thing)' in v.stubs) self.assertTrue(r'int add(int x, int y)' in v.stubs) class TestCtoC(unittest.TestCase): def _run_c_to_c(self, src): ast = parse_to_ast(src) generator = c_generator.CGenerator() return generator.visit(ast) def _assert_ctoc_correct(self, src): """ Checks that the c2c translation was correct by parsing the code generated by c2c for src and comparing the AST with the original AST. """ src2 = self._run_c_to_c(src) self.assertTrue(compare_asts(parse_to_ast(src), parse_to_ast(src2)), src2) def test_trivial_decls(self): self._assert_ctoc_correct('int a;') self._assert_ctoc_correct('int b, a;') self._assert_ctoc_correct('int c, b, a;') def test_complex_decls(self): self._assert_ctoc_correct('int** (*a)(void);') self._assert_ctoc_correct('int** (*a)(void*, int);') self._assert_ctoc_correct('int (*b)(char * restrict k, float);') self._assert_ctoc_correct('int test(const char* const* arg);') self._assert_ctoc_correct('int test(const char** const arg);') #s = 'int test(const char* const* arg);' #parse_to_ast(s).show() def test_casts(self): self._assert_ctoc_correct(r''' int main() { int b = (int) f; int c = (int*) f; }''') def test_initlist(self): self._assert_ctoc_correct('int arr[] = {1, 2, 3};') def test_exprs(self): self._assert_ctoc_correct(''' int main(void) { int a; int b = a++; int c = ++a; int d = a--; int e = --a; }''') def test_statements(self): # note two minuses here self._assert_ctoc_correct(r''' int main() { int a; a = 5; ; b = - - a; return a; }''') def test_casts(self): self._assert_ctoc_correct(r''' int main() { int a = (int) b + 8; int t = (int) c; } ''') def test_struct_decl(self): self._assert_ctoc_correct(r''' typedef struct node_t { struct node_t* next; int data; } node; ''') def test_krstyle(self): self._assert_ctoc_correct(r''' int main(argc, argv) int argc; char** argv; { return 0; } ''') def test_switchcase(self): self._assert_ctoc_correct(r''' int main() { switch (myvar) { case 10: { k = 10; p = k + 1; break; } case 20: case 30: return 20; default: break; } } ''') def test_nest_initializer_list(self): self._assert_ctoc_correct(r''' int main() { int i[1][1] = { { 1 } }; }''') def test_expr_list_in_initializer_list(self): self._assert_ctoc_correct(r''' int main() { int i[1] = { (1, 2) }; }''') def test_issue36(self): self._assert_ctoc_correct(r''' int main() { }''') def test_issue37(self): self._assert_ctoc_correct(r''' int main(void) { unsigned size; size = sizeof(size); return 0; }''') def test_issue83(self): self._assert_ctoc_correct(r''' void x(void) { int i = (9, k); } ''') def test_issue84(self): self._assert_ctoc_correct(r''' void x(void) { for (int i = 0;;) i; } ''') def test_exprlist_with_semi(self): self._assert_ctoc_correct(r''' void x() { if (i < j) tmp = C[i], C[i] = C[j], C[j] = tmp; if (i <= j) i++, j--; } ''') def test_exprlist_with_subexprlist(self): self._assert_ctoc_correct(r''' void x() { (a = b, (b = c, c = a)); } ''') def test_comma_operator_funcarg(self): self._assert_ctoc_correct(r''' void f(int x) { return x; } int main(void) { f((1, 2)); return 0; } ''') def test_comma_op_in_ternary(self): self._assert_ctoc_correct(r''' void f() { (0, 0) ? (0, 0) : (0, 0); } ''') def test_comma_op_assignment(self): self._assert_ctoc_correct(r''' void f() { i = (a, b, c); } ''') if __name__ == "__main__": unittest.main() pycparser-2.14/pycparser.egg-info/0000775000175000017500000000000012535724325017702 5ustar elibeneliben00000000000000pycparser-2.14/pycparser.egg-info/PKG-INFO0000644000175000017500000000113212535724325020772 0ustar elibeneliben00000000000000Metadata-Version: 1.1 Name: pycparser Version: 2.14 Summary: C parser in Python Home-page: https://github.com/eliben/pycparser Author: Eli Bendersky Author-email: eliben@gmail.com License: BSD Description: pycparser is a complete parser of the C language, written in pure Python using the PLY parsing library. It parses C code into an AST and can serve as a front-end for C compilers or analysis tools. Platform: Cross Platform Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 3 pycparser-2.14/pycparser.egg-info/top_level.txt0000644000175000017500000000001212535724325022423 0ustar elibeneliben00000000000000pycparser pycparser-2.14/pycparser.egg-info/SOURCES.txt0000644000175000017500000000653012535724325021570 0ustar elibeneliben00000000000000CHANGES LICENSE MANIFEST.in README.rst setup.py examples/c-to-c.py examples/cdecl.py examples/explore_ast.py examples/func_calls.py examples/func_defs.py examples/rewrite_ast.py examples/using_cpp_libc.py examples/using_gcc_E_libc.py examples/c_files/funky.c examples/c_files/hash.c examples/c_files/memmgr.c examples/c_files/memmgr.h examples/c_files/year.c pycparser/__init__.py pycparser/_ast_gen.py pycparser/_build_tables.py pycparser/_c_ast.cfg pycparser/ast_transforms.py pycparser/c_ast.py pycparser/c_generator.py pycparser/c_lexer.py pycparser/c_parser.py pycparser/lextab.py pycparser/plyparser.py pycparser/yacctab.py pycparser.egg-info/PKG-INFO pycparser.egg-info/SOURCES.txt pycparser.egg-info/dependency_links.txt pycparser.egg-info/top_level.txt pycparser/ply/__init__.py pycparser/ply/cpp.py pycparser/ply/ctokens.py pycparser/ply/lex.py pycparser/ply/yacc.py tests/all_tests.py tests/test_c_ast.py tests/test_c_generator.py tests/test_c_lexer.py tests/test_c_parser.py tests/test_general.py tests/c_files/cppd_with_stdio_h.c tests/c_files/empty.h tests/c_files/example_c_file.c tests/c_files/memmgr.c tests/c_files/memmgr.h tests/c_files/memmgr_with_h.c tests/c_files/simplemain.c tests/c_files/year.c tests/c_files/hdir/9/inc.h utils/fake_libc_include/_ansi.h utils/fake_libc_include/_fake_defines.h utils/fake_libc_include/_fake_typedefs.h utils/fake_libc_include/_syslist.h utils/fake_libc_include/alloca.h utils/fake_libc_include/ar.h utils/fake_libc_include/argz.h utils/fake_libc_include/assert.h utils/fake_libc_include/complex.h utils/fake_libc_include/ctype.h utils/fake_libc_include/dirent.h utils/fake_libc_include/dlfcn.h utils/fake_libc_include/endian.h utils/fake_libc_include/envz.h utils/fake_libc_include/errno.h utils/fake_libc_include/fastmath.h utils/fake_libc_include/fcntl.h utils/fake_libc_include/features.h utils/fake_libc_include/fenv.h utils/fake_libc_include/float.h utils/fake_libc_include/getopt.h utils/fake_libc_include/grp.h utils/fake_libc_include/iconv.h utils/fake_libc_include/ieeefp.h utils/fake_libc_include/inttypes.h utils/fake_libc_include/iso646.h utils/fake_libc_include/langinfo.h utils/fake_libc_include/libgen.h utils/fake_libc_include/libintl.h utils/fake_libc_include/limits.h utils/fake_libc_include/locale.h utils/fake_libc_include/malloc.h utils/fake_libc_include/math.h utils/fake_libc_include/netdb.h utils/fake_libc_include/newlib.h utils/fake_libc_include/paths.h utils/fake_libc_include/process.h utils/fake_libc_include/pthread.h utils/fake_libc_include/pwd.h utils/fake_libc_include/reent.h utils/fake_libc_include/regdef.h utils/fake_libc_include/regex.h utils/fake_libc_include/sched.h utils/fake_libc_include/search.h utils/fake_libc_include/semaphore.h utils/fake_libc_include/setjmp.h utils/fake_libc_include/signal.h utils/fake_libc_include/stdarg.h utils/fake_libc_include/stdbool.h utils/fake_libc_include/stddef.h utils/fake_libc_include/stdint.h utils/fake_libc_include/stdio.h utils/fake_libc_include/stdlib.h utils/fake_libc_include/string.h utils/fake_libc_include/syslog.h utils/fake_libc_include/tar.h utils/fake_libc_include/termios.h utils/fake_libc_include/tgmath.h utils/fake_libc_include/time.h utils/fake_libc_include/unctrl.h utils/fake_libc_include/unistd.h utils/fake_libc_include/utime.h utils/fake_libc_include/utmp.h utils/fake_libc_include/wchar.h utils/fake_libc_include/wctype.h utils/fake_libc_include/zlib.hpycparser-2.14/pycparser.egg-info/dependency_links.txt0000644000175000017500000000000112535724325023746 0ustar elibeneliben00000000000000