summaryrefslogtreecommitdiff
path: root/pycparser
Commit message (Collapse)AuthorAgeFilesLines
* _build_tables: Invalidate cache before importing generated modules (#494)Michał Górny2023-02-251-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make sure to invalidate finder caches before trying to import generated modules. This is necessary according to the Python documentation: https://docs.python.org/3/library/importlib.html#importlib.invalidate_caches This fixes a hard-to-reproduce bug that Python would be unable to find just-generated `lextab.py` if mtime of the current directory did not change from the moment the script was started. This could e.g. be the case if one has second-precision timestamps and removes the generated file just before starting the build, e.g.: $ rm pycparser/lextab.py; python -m build -nw It could also be reproduced easier by doing something like: $ cd pycparser $ touch .; python -B _build_tables.py Traceback (most recent call last): File "/var/tmp/pycparser/pycparser/_build_tables.py", line 38, in <module> import lextab ModuleNotFoundError: No module named 'lextab' This is because the first command (`rm` or `touch`) updates the mtime of the directory to the current time. If the script is run fast enough, it manages to scan the directory and then write the new `lextab.py` within the same second. As a result, mtime of the directory after writing the new file is the same as when the script was started, finder does not invalidate the cache and assumes that `lextab.py` does not exist since it did not exist when the directory was scanned earlier. This potentially fixes #493. It was originally reported on https://bugs.gentoo.org/701878. Thanks to Gary E. Miller for patience in reproducing the problem and proxy-debugging it for me, as well as testing the final patch before submission.
* Feature/add pragma support (#487)Jordy Ruiz2023-01-082-1/+10
| | | | | | | | | * Support _Pragma, a C99 alternative to #pragma See https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html * Test cases for _Pragma * Add explanatory comment for _PRAGMA and PPPRAGMA
* Add encoding param to parse_file (#486)Jordy Ruiz2023-01-071-2/+5
|
* Fix #479 (multi-pragma/single statement blocks) (#480)ldore2022-11-101-3/+9
|
* Preparation for releasing 2.21Eli Bendersky2021-11-061-1/+1
| | | | updates #438
* Fix typos (#443)Kian Meng Ang2021-10-184-12/+12
| | | | | * Fix typos * Revert changes in vendor module
* Fix Flake8 Errors (#442)Eisuke Kawashima2021-10-153-6/+2
| | | | | | | | | * Fix PEP8 [E101](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes) * Fix PEP8 [E711](https://github.com/PyCQA/pycodestyle/blob/2.8.0/docs/intro.rst#error-codes) * Fix E999 (python2) * Fix PEP8 [F401](https://flake8.pycqa.org/en/4.0.1/user/error-codes.html)
* Implement C23 _Static_assert without message (#440)Vitaly Cheptsov2021-10-052-3/+8
| | | Co-authored-by: vit9696 <vit9696@users.noreply.github.com>
* Implement u8, u, and U strings from C11 (#439)Vitaly Cheptsov2021-10-052-0/+45
| | | | | | | * Implement u8, u, and U strings from C11 * Also add u8, u, and U chars from C11 and C23 Co-authored-by: vit9696 <vit9696@users.noreply.github.com>
* Implement _Alignas and _Alignof support with tests (#435)Vitaly Cheptsov2021-10-046-23/+84
| | | | | | | | | | | | | | | * Implement _Alignas and _Alignof support with tests * Improve testing and avoid unnecessary alignas for typedef * Add more tests * Drop legacy artifact * Remove extra _add_declaration_specifier call * Drop custom equality comparators for now Co-authored-by: vit9696 <vit9696@users.noreply.github.com>
* Simplify usage of _add_declaration_specifierEli Bendersky2021-09-251-2/+1
|
* Clean up some commentsEli Bendersky2021-09-201-2/+2
|
* Improve _Atomic support and add more tests (#431)Vitaly Cheptsov2021-09-201-3/+11
| | | | | | | | | * Improve _Atomic support with more tests and fix typedef handling * Remove duplicated tests and check the generated code for typedefs * Add typedef testing to parser as well Co-authored-by: vit9696 <vit9696@users.noreply.github.com>
* Rename debuglevel->debug flag to the parserEli Bendersky2021-09-161-4/+4
| | | | Now it matches the yacc flag name
* Fix declname for _Atomic specifiers, and add c-to-c testsEli Bendersky2021-09-141-2/+5
| | | | Updates #430
* A different, more robust appoach to fix _Atomic specifiers.Eli Bendersky2021-09-132-33/+62
| | | | | Now the ASTs produced are more correct, and more complex cases work like nested _Atomic(...) specifiers.
* Implement atomic specifiers like _Atomic(int*).Eli Bendersky2021-09-131-6/+34
| | | | | Based on #431 by vit9696 Updates #430
* Support _Atomic as a qualifierEli Bendersky2021-09-132-2/+3
| | | | | | | This adds initial implementation for the _Atomic keyword in C11, only focusing on the use as qualifier (spec section 6.7.3) Based on #431 by vit9696. Updates #430
* Introduce partial C11 support (#429)Vitaly Cheptsov2021-08-315-7/+59
| | | | | | | | | | * Introduce partial C11 support Implemented _Noreturn, _Static_assert, _Thread_local. Also fixed tests with preprocessor on macOS. * Add more tests Co-authored-by: vit9696 <vit9696@users.noreply.github.com>
* Add a tricky test, and reformat some commentsEli Bendersky2021-08-281-19/+12
|
* c_parser: support parenthesized compounds (#423)Jordan Yates2021-07-071-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * c_parser: support parenthesized compounds Support parenthesized compound statements as described here: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au> * test_c_parser: support additional initializers Add support to `expand_init` for additional `c_ast` types. If a type is not explicitly handled, return the type name instead of `None`. Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au> * test_c_parser: test parenthesized compounds Add parsing tests for various situations of parenthesized compound statements. The complete tree generated by the test string is: ``` FileAST: FuncDef: Decl: foo, [], [], [] FuncDecl: TypeDecl: foo, [] IdentifierType: ['void'] Compound: Decl: a, [], [], [] TypeDecl: a, [] IdentifierType: ['int'] Compound: Compound: Constant: int, 1 Compound: Constant: int, 1 Constant: int, 2 Decl: b, [], [], [] TypeDecl: b, [] IdentifierType: ['int'] Compound: Constant: int, 1 Decl: c, [], [], [] TypeDecl: c, [] IdentifierType: ['int'] Decl: d, [], [], [] TypeDecl: d, [] IdentifierType: ['int'] Compound: Decl: x, [], [], [] TypeDecl: x, [] IdentifierType: ['int'] Constant: int, 1 BinaryOp: + ID: x Constant: int, 2 Assignment: = ID: a Compound: Decl: x, [], [], [] TypeDecl: x, [] IdentifierType: ['int'] Constant: int, 1 BinaryOp: * Constant: int, 2 ID: x ``` Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
* Extra line breaks when c_ast.If are chained (#401)Patricio Inzaghi2020-12-091-0/+2
|
* Clean up commentsEli Bendersky2020-10-051-4/+2
|
* Added flattening of abundant parenthesis in CGenerator (#394)Julian2020-10-052-5/+50
|
* Remove confusing/stale reference in commentEli Bendersky2020-09-301-1/+1
|
* Fix issues #378, #379, #385 (#387)Zecong Hu2020-07-182-12/+15
| | | | | | | | | | | | * Fix #385: generate code with nested sizeofs * Fix #378: replace assertion with check Only the assertion inside `_build_function_definition` is replaced. The assertion is not appropriate because there are possible inputs that would trigger the assertion, they're just grammatically incorrect. Thus, it is replaced with a check that raises `ParseError` on failure. * Fix #379: parse struct with nested enum
* Clean up whitespace in generated AST codeEli Bendersky2020-04-152-10/+10
|
* Update version 2.19 --> 2.20Eli Bendersky2020-03-041-1/+1
|
* Fix #363 incorrect AST when parsing offsetof (#364)Zecong Hu2020-03-031-2/+1
|
* Recognize integer multicharacter constants like 'ABCD' (#350)yaroslav-o2019-09-252-1/+7
| | | | | | | | | | | | | Recognize integer multicharacter constants like 'ABCD' The feature I am adding is defined here - 5th case. https://en.cppreference.com/w/c/language/character_constant Also here: 6.4.4.4.10 of C99. Put simply, pycparser thought a statement like this is an error: int a = 'ABCD'; However it is not. It is likely possible to just modify char_const regular expression in c_lexer.py:240 to allow longer characters, but the way it is done in this PR - multicharacter constants are clearly separated. I am also limiting the length of multicharacter const integers to 4 characters - this matches VS compiler behavior (gcc allows any length with a warning) and lets pycparser NOT consider lengthy single-quoted strings as integers - these would be nonsensical anyway.
* Fix slow backtracking when parsing strings (no external deps) (#347)Tyson Andre2019-08-261-7/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix slow backtracking when parsing strings (no external deps) Fixes #61 This uses negative lookaheads to avoid ambiguity in how string should be parsed by the regex. - https://docs.python.org/2/library/re.html#regular-expression-syntax - Previously, if it didn't immediately succeed at parsing an escape sequence such as `\123`, it would have to try `\1`+`23`, `\12` + `3`, and `\123`, which multiplied the time taken by 3 per additional escape sequence. This solves that by only allowing `\123` - The same fix was added for hex escapes. Also fix a test that relied on the incorrect handling of regexes. The implementation documentation says that it intends to allow **decimal** escapes permissively. * WIP debug * Fix ambiguity caused by allowing #path directives Solve this by allowing "\x" when not followed by hex, in the regular string literal. In the previous commits, `\x12` could be parsed both as `\x`+`12` and `\x12`, which caused exponential options for backtracking. * Document changes to lexer, remove debug code * Optimize this for strings
* Fix error transforming an empty switch (#346)Tyson Andre2019-08-211-1/+2
| | | | | | | | | | | | | * Fix error transforming an empty switch The parser would crash on that line for `switch(1) {}` because NoneType is not iterable. Fixes #345 * Add a test of empty switch statements * Address review comments
* Fix issue #99: parser for FuncDecl incorrectly sets declname attribute on ↵Saullo Carvalho Castelo Branco2019-06-271-6/+6
| | | | return type (#329)
* Fix issue #314: Failed parsing unnamed function parameters with array dim ↵Saullo Carvalho Castelo Branco2019-06-011-3/+4
| | | | | qualifiers (#327) Fixes #314
* Followup on #326 - simplify building up type stringEli Bendersky2019-05-091-9/+2
|
* Fix issue #324: u/l constant integer suffix (#326)Kevin2019-05-091-1/+21
|
* Insert '.' and '..' to sys.path before import statements (#321)Thomas Krennwallner2019-04-131-2/+6
| | | | Restricted environments like embeddable python do not include the current working directory on startup.
* Generate pointer types correctly (#315)Amir Gonnen2019-03-271-21/+21
| | | | | | | | | | | | * Add visit_PtrDecl to generate ptr types correctly Also removed code duplication from visit_ArrayDecl and visit_TypeDecl by calling _generate_type instead, without emitting the declname. Added tests for ptr type generation * Truncate lines longer than 80 characters per https://github.com/eliben/pycparser/pull/315/files#r269553083
* Fix array type generation (#312) (#313)Amir Gonnen2019-03-261-1/+17
| | | | | | | | | | | | | | | * Fix array type generation (#312) Also added dim_quals handling to _generate_type Exmaple: >>> ast = parser.parse('int g(const int a[const 20]){}') >>> gen.visit(ast.ext[0].decl.type.args.params[0]) 'const int a[const 20]' >>> gen.visit(ast.ext[0].decl.type.args.params[0].type) 'int[const 20]' * Added TypeDecl generation. Added tests
* Fix crash when file starts with a semicolon (#310)Simon Lindholm2019-03-061-3/+2
|
* Revert "Fix encoding problem by adding `encoding` parameter to parse_file ↵Eli Bendersky2018-12-061-10/+4
| | | | | | | | | | function. (#295)" This reverts commit 1083b55c64d6235b00f40070e452b9b2605b23da. encoding is not portable across the list of supported Python versions See #296
* Fix encoding problem by adding `encoding` parameter to parse_file function. ↵ilovexyz2018-12-041-4/+10
| | | | | | (#295) Description: For some Chinese Unicode c files, parse_file may fail if not providing proper `encoding` information. Adding `encoding` parameter will give users the option of providing correct file encoding.
* Bump versions to 2.19release_v2.19Eli Bendersky2018-09-191-1/+1
|
* Correct Parsing of Floating Point Literals, issue #253 (#277)Robbert Harms2018-08-311-1/+11
| | | | | | * Corrects the type attribute of a constant node when parsing doubles. This sets the type attribute to either 'float', 'long double' or 'double' depending on if 'f|F', 'l|L' or '' is specified at the end of the constant definition. * Add tests for previous changes.
* Merge branch 'master' of github.com:eliben/pycparserEli Bendersky2018-07-2512-15/+14
|\
| * Remove unnecessary __future__ import (#266)Jon Dufresne2018-06-261-2/+0
| | | | | | | | | | | | | | | | Generators have been available since 2.3. The feature is automatically included in all supported Pythons. For additional details, see: https://docs.python.org/3/library/__future__.html
| * Use https:// for all project links where available (#267)Jon Dufresne2018-06-2611-12/+12
| |
| * Avoid opening files with deprecated 'U' mode (#269)Jon Dufresne2018-06-261-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Opening files with 'U' mode is deprecated. When running tests with Python warnings enabled, the warnings of the following form are emitted: DeprecationWarning: 'U' mode is deprecated return open(name, 'rU') To open files with universal newlines on both Ptyhon 2 & 3, use the io module. It defaults to opening with universal newlines and doesn't emit a warning. https://docs.python.org/3/library/io.html > When reading input from the stream, if newline is None, universal > newlines mode is enabled.
* | Add tests for empty struct/union typedeclsEli Bendersky2018-07-251-1/+1
|/
* Small cosmetic comment fixEli Bendersky2018-05-211-1/+0
|