Commit 2a259fa7 authored by Matti Picus's avatar Matti Picus
Browse files

update pycparser

parent 28187446337e
Pipeline #61657 passed with stage
in 5 minutes and 28 seconds
......@@ -14,4 +14,4 @@ class CParser(PLYParser):
When updating the version of this in-place, you must regenerate the and files. They will be regenerated on import if they
are not found, so they should be removed, then regenrated, then the new
versions committed.
versions committed. Note that they may be generated in a different directory.
......@@ -49,7 +49,7 @@ def preprocess_file(filename, cpp_path='cpp', cpp_args=''):
def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='',
parser=None, encoding=None):
""" Parse a C file using pycparser.
......@@ -71,6 +71,9 @@ def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='',
If several arguments are required, pass a list of strings.
Encoding to use for the file to parse
Optional parser object to be used instead of the default CParser
......@@ -82,7 +85,7 @@ def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='',
if use_cpp:
text = preprocess_file(filename, cpp_path, cpp_args)
with as f:
with, encoding=encoding) as f:
text =
if parser is None:
......@@ -112,6 +112,7 @@ class CLexer(object):
keyword_map = {}
......@@ -571,15 +571,29 @@ class CParser(PLYParser):
self._parse_error('Directives not supported yet',
self._token_coord(p, 1))
# This encompasses two types of C99-compatible pragmas:
# - The #pragma directive:
# # pragma character_sequence
# - The _Pragma unary operator:
# _Pragma ( " string_literal " )
def p_pppragma_directive(self, p):
""" pppragma_directive : PPPRAGMA
| _PRAGMA LPAREN unified_string_literal RPAREN
if len(p) == 3:
if len(p) == 5:
p[0] = c_ast.Pragma(p[3], self._token_coord(p, 2))
elif len(p) == 3:
p[0] = c_ast.Pragma(p[2], self._token_coord(p, 2))
p[0] = c_ast.Pragma("", self._token_coord(p, 1))
def p_pppragma_directive_list(self, p):
""" pppragma_directive_list : pppragma_directive
| pppragma_directive_list pppragma_directive
p[0] = [p[1]] if len(p) == 2 else p[1] + [p[2]]
# 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):
......@@ -671,12 +685,12 @@ class CParser(PLYParser):
# sum += 1;
# }
def p_pragmacomp_or_statement(self, p):
""" pragmacomp_or_statement : pppragma_directive statement
""" pragmacomp_or_statement : pppragma_directive_list statement
| statement
if isinstance(p[1], c_ast.Pragma) and len(p) == 3:
if len(p) == 3:
p[0] = c_ast.Compound(
block_items=[p[1], p[2]],
coord=self._token_coord(p, 1))
p[0] = p[1]
# This file automatically created by PLY (version 3.10). Don't edit!
_tabversion = '3.10'
_lexreflags = 64
_lexliterals = ''
_lexstateinfo = {'INITIAL': 'inclusive', 'ppline': 'exclusive', 'pppragma': 'exclusive'}
This source diff could not be displayed because it is too large. You can view the blob instead.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment