aboutsummaryrefslogtreecommitdiff
path: root/pycparser/c_parser.py
diff options
context:
space:
mode:
authorksero <ksero@users.noreply.github.com>2016-09-09 07:31:09 +0200
committerksero <ksero@users.noreply.github.com>2016-09-09 07:41:51 +0200
commit749650a2e24051cdd6a7bfa803c03e0a5fa77103 (patch)
tree30d05f3c50fe50e3832a63bcdbe2f9a6be5d0253 /pycparser/c_parser.py
parentf8718097468025958a024b62942b032807d01bb9 (diff)
downloadpycparser-749650a2e24051cdd6a7bfa803c03e0a5fa77103.tar.gz
Fix eliben/pycparser#87 : offsetof() support is incomplete
Diffstat (limited to 'pycparser/c_parser.py')
-rw-r--r--pycparser/c_parser.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py
index 53f445a..cf062fb 100644
--- a/pycparser/c_parser.py
+++ b/pycparser/c_parser.py
@@ -1608,13 +1608,28 @@ class CParser(PLYParser):
p[0] = p[2]
def p_primary_expression_5(self, p):
- """ primary_expression : OFFSETOF LPAREN type_name COMMA identifier RPAREN
+ """ primary_expression : OFFSETOF LPAREN type_name COMMA offsetof_member_designator 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_offsetof_member_designator(self, p):
+ """ offsetof_member_designator : identifier
+ | offsetof_member_designator PERIOD identifier
+ | offsetof_member_designator LBRACKET expression RBRACKET
+ """
+ if len(p) == 2:
+ p[0] = p[1]
+ elif len(p) == 4:
+ field = c_ast.ID(p[3], self._coord(p.lineno(3)))
+ p[0] = c_ast.StructRef(p[1], p[2], field, p[1].coord)
+ elif len(p) == 5:
+ p[0] = c_ast.ArrayRef(p[1], p[3], p[1].coord)
+ else:
+ raise NotImplementedError("Unexpected parsing state. len(p): %u" % len(p))
+
def p_argument_expression_list(self, p):
""" argument_expression_list : assignment_expression
| argument_expression_list COMMA assignment_expression