aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Tools/c-analyzer/c_parser
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/c-analyzer/c_parser')
-rw-r--r--Tools/c-analyzer/c_parser/info.py4
-rw-r--r--Tools/c-analyzer/c_parser/parser/_compound_decl_body.py2
-rw-r--r--Tools/c-analyzer/c_parser/parser/_regexes.py7
3 files changed, 11 insertions, 2 deletions
diff --git a/Tools/c-analyzer/c_parser/info.py b/Tools/c-analyzer/c_parser/info.py
index 697b1f26dc2..bbfbff7e62d 100644
--- a/Tools/c-analyzer/c_parser/info.py
+++ b/Tools/c-analyzer/c_parser/info.py
@@ -1161,7 +1161,9 @@ class Member(namedtuple('Member', 'name vartype size')):
vartype = dict(raw.data)
del vartype['storage']
if 'size' in vartype:
- size = int(vartype.pop('size'))
+ size = vartype.pop('size')
+ if isinstance(size, str) and size.isdigit():
+ size = int(size)
vartype = VarType(**vartype)
return cls(name, vartype, size)
diff --git a/Tools/c-analyzer/c_parser/parser/_compound_decl_body.py b/Tools/c-analyzer/c_parser/parser/_compound_decl_body.py
index eb5bc67607b..67528d22798 100644
--- a/Tools/c-analyzer/c_parser/parser/_compound_decl_body.py
+++ b/Tools/c-analyzer/c_parser/parser/_compound_decl_body.py
@@ -99,7 +99,7 @@ def _parse_struct_next(m, srcinfo, anon_name, parent):
name = anon_name('struct-field-')
if size:
# data = (data, size)
- data['size'] = int(size)
+ data['size'] = int(size) if size.isdigit() else size
else:
# This shouldn't happen (we expect each field to have a name).
raise NotImplementedError
diff --git a/Tools/c-analyzer/c_parser/parser/_regexes.py b/Tools/c-analyzer/c_parser/parser/_regexes.py
index cb85a59aaa1..b7f22b186f4 100644
--- a/Tools/c-analyzer/c_parser/parser/_regexes.py
+++ b/Tools/c-analyzer/c_parser/parser/_regexes.py
@@ -176,6 +176,7 @@ DECLARATOR = textwrap.dedent(rf'''
(?: # <IDENTIFIER>
{STRICT_IDENTIFIER}
)
+ # Inside the brackets is actually a "constant expression".
(?: \s* \[ (?: \s* [^\]]+ \s* )? [\]] )* # arrays
)
|
@@ -184,6 +185,7 @@ DECLARATOR = textwrap.dedent(rf'''
(?: # <WRAPPED_IDENTIFIER>
{STRICT_IDENTIFIER}
)
+ # Inside the brackets is actually a "constant expression".
(?: \s* \[ (?: \s* [^\]]+ \s* )? [\]] )* # arrays
\s* [)]
)
@@ -194,6 +196,7 @@ DECLARATOR = textwrap.dedent(rf'''
(?: # <FUNC_IDENTIFIER>
{STRICT_IDENTIFIER}
)
+ # Inside the brackets is actually a "constant expression".
(?: \s* \[ (?: \s* [^\]]+ \s* )? [\]] )* # arrays
\s* [)]
# We allow for a single level of paren nesting in parameters.
@@ -322,7 +325,10 @@ STRUCT_MEMBER_DECL = textwrap.dedent(rf'''
(?:
\s* [:] \s*
(?: # <SIZE>
+ # This is actually a "constant expression".
\d+
+ |
+ [^'",}}]+
)
)?
\s*
@@ -357,6 +363,7 @@ ENUM_MEMBER_DECL = textwrap.dedent(rf'''
(?:
\s* = \s*
(?: # <INIT>
+ # This is actually a "constant expression".
{_ind(STRING_LITERAL, 4)}
|
[^'",}}]+