aboutsummaryrefslogtreecommitdiff
path: root/pycparser
diff options
context:
space:
mode:
authoreli.bendersky <devnull@localhost>2011-06-22 17:50:56 +0300
committereli.bendersky <devnull@localhost>2011-06-22 17:50:56 +0300
commit6b0117989691942c2d736a0a8950e55e1bdf9950 (patch)
tree4082e7612c8c4e85737350315c317782eb024594 /pycparser
parentd4a9975226825ff22fd70fdc57abc18313aa1a13 (diff)
downloadpycparser-6b0117989691942c2d736a0a8950e55e1bdf9950.tar.gz
Fix for Issue #39: allow anonymous struct fields not only of union/struct types. Although the C1X standard doesn't really allow it, some compilers (MSVC) do,
and Windows headers have typedefs there. Since pycparser shouldn't semantically follow typedefs, and it isn't about rejecting all invalid code, there's no harm in allowing this
Diffstat (limited to 'pycparser')
-rw-r--r--pycparser/c_parser.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py
index bde0c40..6379034 100644
--- a/pycparser/c_parser.py
+++ b/pycparser/c_parser.py
@@ -682,23 +682,23 @@ class CParser(PLYParser):
typename = spec['type']
decls.append(self._fix_decl_name_type(decl, typename))
-
- else: # anonymous struct/union, gcc extension, C1x feature
+ else:
+ # Anonymous struct/union, gcc extension, C1x feature.
+ # Although the standard only allows structs/unions here, I see no
+ # reason to disallow other types since some compilers have typedefs
+ # here, and pycparser isn't about rejecting all invalid code.
+ #
node = spec['type'][0]
- if isinstance(node, c_ast.Union) or isinstance(node, c_ast.Struct):
- decl = c_ast.Decl(
- name=None,
- quals=spec['qual'],
- funcspec=spec['function'],
- storage=spec['storage'],
- type=node,
- init=None,
- bitsize=None,
- coord=self._coord(p.lineno(3)))
- decls.append(decl)
- else:
- self._parse_error("Anonymous field of invalid type",
- self._coord(p.lineno(3)))
+ decl = c_ast.Decl(
+ name=None,
+ quals=spec['qual'],
+ funcspec=spec['function'],
+ storage=spec['storage'],
+ type=node,
+ init=None,
+ bitsize=None,
+ coord=self._coord(p.lineno(3)))
+ decls.append(decl)
p[0] = decls