diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/python/pycparser | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/pycparser')
-rw-r--r-- | contrib/python/pycparser/.dist-info/METADATA | 52 | ||||
-rw-r--r-- | contrib/python/pycparser/.dist-info/top_level.txt | 2 | ||||
-rw-r--r-- | contrib/python/pycparser/LICENSE | 52 | ||||
-rw-r--r-- | contrib/python/pycparser/README.rst | 476 | ||||
-rw-r--r-- | contrib/python/pycparser/pycparser/_build_tables.py | 12 | ||||
-rw-r--r-- | contrib/python/pycparser/pycparser/ast_transforms.py | 4 | ||||
-rw-r--r-- | contrib/python/pycparser/pycparser/c_generator.py | 54 | ||||
-rw-r--r-- | contrib/python/pycparser/pycparser/c_lexer.py | 78 | ||||
-rw-r--r-- | contrib/python/pycparser/pycparser/c_parser.py | 46 | ||||
-rw-r--r-- | contrib/python/pycparser/ya.make | 36 |
10 files changed, 406 insertions, 406 deletions
diff --git a/contrib/python/pycparser/.dist-info/METADATA b/contrib/python/pycparser/.dist-info/METADATA index 1d0fbd6514..520a9640d2 100644 --- a/contrib/python/pycparser/.dist-info/METADATA +++ b/contrib/python/pycparser/.dist-info/METADATA @@ -1,31 +1,31 @@ -Metadata-Version: 2.1 -Name: pycparser +Metadata-Version: 2.1 +Name: pycparser Version: 2.21 -Summary: C parser in Python -Home-page: https://github.com/eliben/pycparser -Author: Eli Bendersky -Author-email: eliben@gmail.com -Maintainer: Eli Bendersky -License: BSD -Platform: Cross Platform -Classifier: Development Status :: 5 - Production/Stable -Classifier: License :: OSI Approved :: BSD License -Classifier: Programming Language :: Python :: 2 -Classifier: Programming Language :: Python :: 2.7 -Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.4 -Classifier: Programming Language :: Python :: 3.5 -Classifier: Programming Language :: Python :: 3.6 +Summary: C parser in Python +Home-page: https://github.com/eliben/pycparser +Author: Eli Bendersky +Author-email: eliben@gmail.com +Maintainer: Eli Bendersky +License: BSD +Platform: Cross Platform +Classifier: Development Status :: 5 - Production/Stable +Classifier: License :: OSI Approved :: BSD License +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 -Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* - - -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. - - +Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* + + +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. + + diff --git a/contrib/python/pycparser/.dist-info/top_level.txt b/contrib/python/pycparser/.dist-info/top_level.txt index dc1c9e101a..925b216b4b 100644 --- a/contrib/python/pycparser/.dist-info/top_level.txt +++ b/contrib/python/pycparser/.dist-info/top_level.txt @@ -1 +1 @@ -pycparser +pycparser diff --git a/contrib/python/pycparser/LICENSE b/contrib/python/pycparser/LICENSE index ea215f2dbb..fdb1f4da02 100644 --- a/contrib/python/pycparser/LICENSE +++ b/contrib/python/pycparser/LICENSE @@ -1,27 +1,27 @@ -pycparser -- A C parser in Python - +pycparser -- A C parser in Python + Copyright (c) 2008-2020, 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. +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. diff --git a/contrib/python/pycparser/README.rst b/contrib/python/pycparser/README.rst index e8ae8c1555..107b3a21d1 100644 --- a/contrib/python/pycparser/README.rst +++ b/contrib/python/pycparser/README.rst @@ -1,252 +1,252 @@ -=============== +=============== pycparser v2.21 -=============== - - +=============== + + .. image:: https://github.com/eliben/pycparser/workflows/pycparser-tests/badge.svg :align: center :target: https://github.com/eliben/pycparser/actions - + ---- -.. 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 -<https://cffi.readthedocs.io/en/latest/>`_ 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 <https://github.com/eliben/pycparser/wiki/FAQ>`_ for more details. - -What grammar does pycparser follow? ------------------------------------ - -**pycparser** very closely follows the C grammar provided in Annex A of the C99 -standard (ISO/IEC 9899). - -How is pycparser licensed? --------------------------- - -`BSD license <https://github.com/eliben/pycparser/blob/master/LICENSE>`_. - -Contact details ---------------- - -For reporting problems with **pycparser** or submitting feature requests, please -open an `issue <https://github.com/eliben/pycparser/issues>`_, or submit a -pull request. - - -Installing -========== - -Prerequisites -------------- - -* **pycparser** was tested on Python 2.7, 3.4-3.6, 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.10, retrieved from `<http://www.dabeaz.com/ply/>`_ - -Note that **pycparser** (and PLY) uses docstrings for grammar specifications. -Python installations that strip docstrings (such as when using the Python -``-OO`` option) will fail to instantiate and use **pycparser**. You can try to -work around this problem by making sure the PLY parsing tables are pre-generated -in normal mode; this isn't an officially supported/tested mode of operation, -though. - -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 -<https://pypi.org/project/pycparser/>`_ (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 performs 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 -<http://llvm.org/releases/download.html>`_. - -What about the standard C library headers? ------------------------------------------- - -C code almost always ``#include``\s 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 +.. 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 +<https://cffi.readthedocs.io/en/latest/>`_ 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 <https://github.com/eliben/pycparser/wiki/FAQ>`_ for more details. + +What grammar does pycparser follow? +----------------------------------- + +**pycparser** very closely follows the C grammar provided in Annex A of the C99 +standard (ISO/IEC 9899). + +How is pycparser licensed? +-------------------------- + +`BSD license <https://github.com/eliben/pycparser/blob/master/LICENSE>`_. + +Contact details +--------------- + +For reporting problems with **pycparser** or submitting feature requests, please +open an `issue <https://github.com/eliben/pycparser/issues>`_, or submit a +pull request. + + +Installing +========== + +Prerequisites +------------- + +* **pycparser** was tested on Python 2.7, 3.4-3.6, 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.10, retrieved from `<http://www.dabeaz.com/ply/>`_ + +Note that **pycparser** (and PLY) uses docstrings for grammar specifications. +Python installations that strip docstrings (such as when using the Python +``-OO`` option) will fail to instantiate and use **pycparser**. You can try to +work around this problem by making sure the PLY parsing tables are pre-generated +in normal mode; this isn't an officially supported/tested mode of operation, +though. + +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 +<https://pypi.org/project/pycparser/>`_ (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 performs 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 +<http://llvm.org/releases/download.html>`_. + +What about the standard C library headers? +------------------------------------------ + +C code almost always ``#include``\s 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 for C11 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 -<https://eli.thegreenplace.net/2015/on-parsing-c-type-declarations-and-fake-headers>`_ -for more details. - -Note that the fake headers are not included in the ``pip`` package nor installed -via ``setup.py`` (`#224 <https://github.com/eliben/pycparser/issues/224>`_). - -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. Please note -that most realistic C code samples would require running the C preprocessor -before passing the code to **pycparser**; see the previous sections for more -details. - -.. |examples| replace:: ``examples`` -.. _examples: examples - - -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 <https://github.com/eliben/pycparser/wiki/FAQ>`_. -In any case, you can always drop me an `email <eliben@gmail.com>`_ 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 + +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 +<https://eli.thegreenplace.net/2015/on-parsing-c-type-declarations-and-fake-headers>`_ +for more details. + +Note that the fake headers are not included in the ``pip`` package nor installed +via ``setup.py`` (`#224 <https://github.com/eliben/pycparser/issues/224>`_). + +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. Please note +that most realistic C code samples would require running the C preprocessor +before passing the code to **pycparser**; see the previous sections for more +details. + +.. |examples| replace:: ``examples`` +.. _examples: examples + + +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 <https://github.com/eliben/pycparser/wiki/FAQ>`_. +In any case, you can always drop me an `email <eliben@gmail.com>`_ 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. This can be done by running the ``_build_tables.py`` script from the ``pycparser`` directory. -* 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. +* 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. Note that these headers now include C11 code, so they may not work when the preprocessor is configured to an earlier C standard (like ``-std=c99``). - -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. After **pycparser** moved to Github I stopped -updating this list because Github does a much better job at tracking -contributions. - - + +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. After **pycparser** moved to Github I stopped +updating this list because Github does a much better job at tracking +contributions. + + diff --git a/contrib/python/pycparser/pycparser/_build_tables.py b/contrib/python/pycparser/pycparser/_build_tables.py index 958381ad0f..2ed20afe70 100644 --- a/contrib/python/pycparser/pycparser/_build_tables.py +++ b/contrib/python/pycparser/pycparser/_build_tables.py @@ -10,12 +10,12 @@ # License: BSD #----------------------------------------------------------------- -# Insert '.' and '..' as first entries to the search path for modules. -# Restricted environments like embeddable python do not include the -# current working directory on startup. -import sys -sys.path[0:0] = ['.', '..'] - +# Insert '.' and '..' as first entries to the search path for modules. +# Restricted environments like embeddable python do not include the +# current working directory on startup. +import sys +sys.path[0:0] = ['.', '..'] + # Generate c_ast.py from _ast_gen import ASTCodeGenerator ast_gen = ASTCodeGenerator('_c_ast.cfg') diff --git a/contrib/python/pycparser/pycparser/ast_transforms.py b/contrib/python/pycparser/pycparser/ast_transforms.py index 367dcf54c5..221a0b73b4 100644 --- a/contrib/python/pycparser/pycparser/ast_transforms.py +++ b/contrib/python/pycparser/pycparser/ast_transforms.py @@ -74,8 +74,8 @@ def fix_switch_cases(switch_node): # 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 `switch(cond) {}`, block_items would have been None) - for child in (switch_node.stmt.block_items or []): + # (for `switch(cond) {}`, block_items would have been None) + for child in (switch_node.stmt.block_items or []): 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" diff --git a/contrib/python/pycparser/pycparser/c_generator.py b/contrib/python/pycparser/pycparser/c_generator.py index 1057b2c62e..85bea1a18e 100644 --- a/contrib/python/pycparser/pycparser/c_generator.py +++ b/contrib/python/pycparser/pycparser/c_generator.py @@ -162,7 +162,7 @@ class CGenerator(object): return s def visit_Cast(self, n): - s = '(' + self._generate_type(n.to_type, emit_declname=False) + ')' + s = '(' + self._generate_type(n.to_type, emit_declname=False) + ')' return s + ' ' + self._parenthesize_unless_simple(n.expr) def visit_ExprList(self, n): @@ -346,15 +346,15 @@ class CGenerator(object): def visit_FuncDecl(self, n): return self._generate_type(n) - def visit_ArrayDecl(self, n): - return self._generate_type(n, emit_declname=False) - - def visit_TypeDecl(self, n): - return self._generate_type(n, emit_declname=False) - - def visit_PtrDecl(self, n): - return self._generate_type(n, emit_declname=False) - + def visit_ArrayDecl(self, n): + return self._generate_type(n, emit_declname=False) + + def visit_TypeDecl(self, n): + return self._generate_type(n, emit_declname=False) + + def visit_PtrDecl(self, n): + return self._generate_type(n, emit_declname=False) + def _generate_struct_union_enum(self, n, name): """ Generates code for structs, unions, and enums. name should be 'struct', 'union', or 'enum'. @@ -426,7 +426,7 @@ class CGenerator(object): s += self._generate_type(n.type) return s - def _generate_type(self, n, modifiers=[], emit_declname = True): + def _generate_type(self, n, modifiers=[], emit_declname = True): """ 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 @@ -440,29 +440,29 @@ class CGenerator(object): if n.quals: s += ' '.join(n.quals) + ' ' s += self.visit(n.type) - nstr = n.declname if n.declname and emit_declname else '' + nstr = n.declname if n.declname and emit_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 += '[' - if modifier.dim_quals: - nstr += ' '.join(modifier.dim_quals) + ' ' - nstr += self.visit(modifier.dim) + ']' + if (i != 0 and + isinstance(modifiers[i - 1], c_ast.PtrDecl)): + nstr = '(' + nstr + ')' + nstr += '[' + if modifier.dim_quals: + nstr += ' '.join(modifier.dim_quals) + ' ' + nstr += self.visit(modifier.dim) + ']' elif isinstance(modifier, c_ast.FuncDecl): - if (i != 0 and - isinstance(modifiers[i - 1], c_ast.PtrDecl)): - nstr = '(' + nstr + ')' + 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 if nstr else '') + nstr = '* %s%s' % (' '.join(modifier.quals), + ' ' + nstr if nstr else '') else: nstr = '*' + nstr if nstr: s += ' ' + nstr @@ -470,12 +470,12 @@ class CGenerator(object): elif typ == c_ast.Decl: return self._generate_decl(n.type) elif typ == c_ast.Typename: - return self._generate_type(n.type, emit_declname = emit_declname) + return self._generate_type(n.type, emit_declname = emit_declname) 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], - emit_declname = emit_declname) + return self._generate_type(n.type, modifiers + [n], + emit_declname = emit_declname) else: return self.visit(n) diff --git a/contrib/python/pycparser/pycparser/c_lexer.py b/contrib/python/pycparser/pycparser/c_lexer.py index d68d8ebfa3..16c6abe855 100644 --- a/contrib/python/pycparser/pycparser/c_lexer.py +++ b/contrib/python/pycparser/pycparser/c_lexer.py @@ -18,7 +18,7 @@ class CLexer(object): tokens. The public attribute filename can be set to an initial - filename, but the lexer will update it upon #line + filename, but the lexer will update it upon #line directives. """ def __init__(self, error_func, on_lbrace_func, on_rbrace_func, @@ -134,7 +134,7 @@ class CLexer(object): 'TYPEID', # constants - 'INT_CONST_DEC', 'INT_CONST_OCT', 'INT_CONST_HEX', 'INT_CONST_BIN', 'INT_CONST_CHAR', + 'INT_CONST_DEC', 'INT_CONST_OCT', 'INT_CONST_HEX', 'INT_CONST_BIN', 'INT_CONST_CHAR', 'FLOAT_CONST', 'HEX_FLOAT_CONST', 'CHAR_CONST', 'WCHAR_CONST', @@ -215,55 +215,55 @@ class CLexer(object): # parse all correct code, even if it means to sometimes parse incorrect # code. # - # The original regexes were taken verbatim from the C syntax definition, - # and were later modified to avoid worst-case exponential running time. - # - # 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])""" - # - # The following modifications were made to avoid the ambiguity that allowed backtracking: - # (https://github.com/eliben/pycparser/issues/61) - # - # - \x was removed from simple_escape, unless it was not followed by a hex digit, to avoid ambiguity with hex_escape. - # - hex_escape allows one or more hex characters, but requires that the next character(if any) is not hex - # - decimal_escape allows one or more decimal characters, but requires that the next character(if any) is not a decimal - # - bad_escape does not allow any decimals (8-9), to avoid conflicting with the permissive decimal_escape. - # - # Without this change, python's `re` module would recursively try parsing each ambiguous escape sequence in multiple ways. - # e.g. `\123` could be parsed as `\1`+`23`, `\12`+`3`, and `\123`. - - simple_escape = r"""([a-wyzA-Z._~!=&\^\-\\?'"]|x(?![0-9a-fA-F]))""" - decimal_escape = r"""(\d+)(?!\d)""" - hex_escape = r"""(x[0-9a-fA-F]+)(?![0-9a-fA-F])""" - bad_escape = r"""([\\][^a-zA-Z._~^!=&\^\-\\?'"x0-9])""" - + # The original regexes were taken verbatim from the C syntax definition, + # and were later modified to avoid worst-case exponential running time. + # + # 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])""" + # + # The following modifications were made to avoid the ambiguity that allowed backtracking: + # (https://github.com/eliben/pycparser/issues/61) + # + # - \x was removed from simple_escape, unless it was not followed by a hex digit, to avoid ambiguity with hex_escape. + # - hex_escape allows one or more hex characters, but requires that the next character(if any) is not hex + # - decimal_escape allows one or more decimal characters, but requires that the next character(if any) is not a decimal + # - bad_escape does not allow any decimals (8-9), to avoid conflicting with the permissive decimal_escape. + # + # Without this change, python's `re` module would recursively try parsing each ambiguous escape sequence in multiple ways. + # e.g. `\123` could be parsed as `\1`+`23`, `\12`+`3`, and `\123`. + + simple_escape = r"""([a-wyzA-Z._~!=&\^\-\\?'"]|x(?![0-9a-fA-F]))""" + decimal_escape = r"""(\d+)(?!\d)""" + hex_escape = r"""(x[0-9a-fA-F]+)(?![0-9a-fA-F])""" + bad_escape = r"""([\\][^a-zA-Z._~^!=&\^\-\\?'"x0-9])""" + escape_sequence = r"""(\\("""+simple_escape+'|'+decimal_escape+'|'+hex_escape+'))' - - # This complicated regex with lookahead might be slow for strings, so because all of the valid escapes (including \x) allowed - # 0 or more non-escaped characters after the first character, simple_escape+decimal_escape+hex_escape got simplified to - - escape_sequence_start_in_string = r"""(\\[0-9a-zA-Z._~!=&\^\-\\?'"])""" - + + # This complicated regex with lookahead might be slow for strings, so because all of the valid escapes (including \x) allowed + # 0 or more non-escaped characters after the first character, simple_escape+decimal_escape+hex_escape got simplified to + + escape_sequence_start_in_string = r"""(\\[0-9a-zA-Z._~!=&\^\-\\?'"])""" + cconst_char = r"""([^'\\\n]|"""+escape_sequence+')' char_const = "'"+cconst_char+"'" wchar_const = 'L'+char_const u8char_const = 'u8'+char_const u16char_const = 'u'+char_const u32char_const = 'U'+char_const - multicharacter_constant = "'"+cconst_char+"{2,4}'" + multicharacter_constant = "'"+cconst_char+"{2,4}'" 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_start_in_string+')' + string_char = r"""([^"\\\n]|"""+escape_sequence_start_in_string+')' string_literal = '"'+string_char+'*"' wstring_literal = 'L'+string_literal u8string_literal = 'u8'+string_literal u16string_literal = 'u'+string_literal u32string_literal = 'U'+string_literal - bad_string_literal = '"'+string_char+'*'+bad_escape+string_char+'*"' + bad_string_literal = '"'+string_char+'*'+bad_escape+string_char+'*"' # floating constants (K&R2: A.2.5.3) exponent_part = r"""([eE][-+]?[0-9]+)""" @@ -485,10 +485,10 @@ class CLexer(object): # Must come before bad_char_const, to prevent it from # catching valid char constants as invalid # - @TOKEN(multicharacter_constant) - def t_INT_CONST_CHAR(self, t): - return t - + @TOKEN(multicharacter_constant) + def t_INT_CONST_CHAR(self, t): + return t + @TOKEN(char_const) def t_CHAR_CONST(self, t): return t diff --git a/contrib/python/pycparser/pycparser/c_parser.py b/contrib/python/pycparser/pycparser/c_parser.py index 640a759406..c57b6110fd 100644 --- a/contrib/python/pycparser/pycparser/c_parser.py +++ b/contrib/python/pycparser/pycparser/c_parser.py @@ -523,7 +523,7 @@ class CParser(PLYParser): def p_translation_unit_2(self, p): """ translation_unit : translation_unit external_declaration """ - p[1].extend(p[2]) + p[1].extend(p[2]) p[0] = p[1] # Declarations always come as lists (because they can be @@ -549,7 +549,7 @@ class CParser(PLYParser): def p_external_declaration_4(self, p): """ external_declaration : SEMI """ - p[0] = [] + p[0] = [] def p_external_declaration_5(self, p): """ external_declaration : static_assert @@ -1469,13 +1469,13 @@ class CParser(PLYParser): p[0] = self._type_modify_decl(decl=p[1], modifier=arr) def p_direct_abstract_declarator_3(self, p): - """ direct_abstract_declarator : LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET + """ direct_abstract_declarator : LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET """ - quals = (p[2] if len(p) > 4 else []) or [] + quals = (p[2] if len(p) > 4 else []) or [] p[0] = c_ast.ArrayDecl( type=c_ast.TypeDecl(None, None, None, None), - dim=p[3] if len(p) > 4 else p[2], - dim_quals=quals, + dim=p[3] if len(p) > 4 else p[2], + dim_quals=quals, coord=self._token_coord(p, 1)) def p_direct_abstract_declarator_4(self, p): @@ -1804,7 +1804,7 @@ class CParser(PLYParser): if len(p) == 2: p[0] = p[1] elif len(p) == 4: - p[0] = c_ast.StructRef(p[1], p[2], p[3], p[1].coord) + p[0] = c_ast.StructRef(p[1], p[2], p[3], p[1].coord) elif len(p) == 5: p[0] = c_ast.ArrayRef(p[1], p[3], p[1].coord) else: @@ -1829,23 +1829,23 @@ class CParser(PLYParser): | INT_CONST_OCT | INT_CONST_HEX | INT_CONST_BIN - | INT_CONST_CHAR - """ - uCount = 0 - lCount = 0 - for x in p[1][-3:]: - if x in ('l', 'L'): - lCount += 1 - elif x in ('u', 'U'): - uCount += 1 - t = '' - if uCount > 1: - raise ValueError('Constant cannot have more than one u/U suffix.') - elif lCount > 2: - raise ValueError('Constant cannot have more than two l/L suffix.') - prefix = 'unsigned ' * uCount + 'long ' * lCount + | INT_CONST_CHAR + """ + uCount = 0 + lCount = 0 + for x in p[1][-3:]: + if x in ('l', 'L'): + lCount += 1 + elif x in ('u', 'U'): + uCount += 1 + t = '' + if uCount > 1: + raise ValueError('Constant cannot have more than one u/U suffix.') + elif lCount > 2: + raise ValueError('Constant cannot have more than two l/L suffix.') + prefix = 'unsigned ' * uCount + 'long ' * lCount p[0] = c_ast.Constant( - prefix + 'int', p[1], self._token_coord(p, 1)) + prefix + 'int', p[1], self._token_coord(p, 1)) def p_constant_2(self, p): """ constant : FLOAT_CONST diff --git a/contrib/python/pycparser/ya.make b/contrib/python/pycparser/ya.make index 1eb209b7b6..f6d0593ea4 100644 --- a/contrib/python/pycparser/ya.make +++ b/contrib/python/pycparser/ya.make @@ -1,25 +1,25 @@ -# Generated by devtools/yamaker (pypi). - +# Generated by devtools/yamaker (pypi). + PY23_LIBRARY() OWNER(g:python-contrib) VERSION(2.21) -LICENSE(BSD-3-Clause) - +LICENSE(BSD-3-Clause) + NO_LINT() -NO_CHECK_IMPORTS( - pycparser._ast_gen - pycparser._build_tables -) - +NO_CHECK_IMPORTS( + pycparser._ast_gen + pycparser._build_tables +) + PY_SRCS( TOP_LEVEL pycparser/__init__.py - pycparser/_ast_gen.py - pycparser/_build_tables.py + pycparser/_ast_gen.py + pycparser/_build_tables.py pycparser/ast_transforms.py pycparser/c_ast.py pycparser/c_generator.py @@ -36,11 +36,11 @@ PY_SRCS( pycparser/yacctab.py ) -RESOURCE_FILES( - PREFIX contrib/python/pycparser/ - .dist-info/METADATA - .dist-info/top_level.txt - pycparser/_c_ast.cfg -) - +RESOURCE_FILES( + PREFIX contrib/python/pycparser/ + .dist-info/METADATA + .dist-info/top_level.txt + pycparser/_c_ast.cfg +) + END() |