Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pycparserext/ext_c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def visit_TypeList(self, n):
def visit_RangeExpression(self, n):
return '%s ... %s' % (self.visit(n.first), self.visit(n.last))

def visit_CompoundExpression(self, n):
return "(%s)" % (self.visit(n.stmt))


class GNUCGenerator(GnuCGenerator):
def __init__(self):
Expand Down
31 changes: 18 additions & 13 deletions pycparserext/ext_c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@ def __iter__(self):
attr_names = ()


class CompoundExpression(c_ast.Node):
def __init__(self, stmt, coord=None):
self.stmt = stmt
self.coord = coord

def children(self):
nodelist = []
if self.stmt is not None: nodelist.append(("stmt", self.stmt))
return tuple(nodelist)

def __iter__(self):
if self.stmt is not None:
yield self.stmt

attr_names = ()


# These are the same as pycparser's, but it does *not* declare __slots__--
# so we can poke in attributes at our leisure.
class TypeDeclExt(c_ast.TypeDecl):
Expand Down Expand Up @@ -528,24 +545,12 @@ def p_postfix_expression_gnu_tcp(self, p):
def p_gnu_statement_expression(self, p):
""" gnu_statement_expression : LPAREN compound_statement RPAREN
"""
p[0] = p[2]
p[0] = CompoundExpression(p[2], coord=self._coord(p.lineno(1)))

def p_gnu_primary_expression_6(self, p):
""" primary_expression : gnu_statement_expression """
p[0] = p[1]

def p_statement(self, p):
""" statement : labeled_statement
| expression_statement
| compound_statement
| selection_statement
| iteration_statement
| jump_statement
| pppragma_directive
| gnu_statement_expression
"""
p[0] = p[1]

def p_attribute_const(self, p):
""" attribute : __CONST
"""
Expand Down