Skip to content

Commit cff5bd3

Browse files
More accurate parsing of #define directives
Support continuation lines and remove comments.
1 parent 3f076dd commit cff5bd3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

scripts/generate_psa_constants.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,14 @@ def __init__(self):
182182
# and the expansion in group 3.
183183
_define_directive_re = re.compile(r'\s*#\s*define\s+(\w+)' +
184184
r'(?:\s+|\((\w+)\)\s*)' +
185-
r'(.+)(?:/[*/])?')
185+
r'(.+)')
186186

187187
def read_line(self, line):
188188
m = re.match(self._define_directive_re, line)
189189
if not m:
190190
return
191191
name, parameter, expansion = m.groups()
192+
expansion = re.sub(r'/\*.*?\*/|//.*', r' ', expansion)
192193
if name.endswith('_FLAG') or name.endswith('MASK'):
193194
# Macro only to build actual values
194195
return
@@ -238,6 +239,9 @@ def read_line(self, line):
238239

239240
def read_file(self, header_file):
240241
for line in header_file:
242+
while line.endswith('\\\n'):
243+
cont = header_file.next()
244+
line = line[:-2] + cont
241245
self.read_line(line)
242246

243247
def make_return_case(self, name):

0 commit comments

Comments
 (0)