More accurate parsing of #define directives
Support continuation lines and remove comments.
This commit is contained in:
parent
5c196fb599
commit
f30d4d9b34
@ -210,7 +210,7 @@ class MacroCollector:
|
|||||||
# and the expansion in group 3.
|
# and the expansion in group 3.
|
||||||
_define_directive_re = re.compile(r'\s*#\s*define\s+(\w+)' +
|
_define_directive_re = re.compile(r'\s*#\s*define\s+(\w+)' +
|
||||||
r'(?:\s+|\((\w+)\)\s*)' +
|
r'(?:\s+|\((\w+)\)\s*)' +
|
||||||
r'(.+)(?:/[*/])?')
|
r'(.+)')
|
||||||
|
|
||||||
def read_line(self, line):
|
def read_line(self, line):
|
||||||
"""Parse a C header line and record the PSA identifier it defines if any.
|
"""Parse a C header line and record the PSA identifier it defines if any.
|
||||||
@ -222,6 +222,7 @@ class MacroCollector:
|
|||||||
if not m:
|
if not m:
|
||||||
return
|
return
|
||||||
name, parameter, expansion = m.groups()
|
name, parameter, expansion = m.groups()
|
||||||
|
expansion = re.sub(r'/\*.*?\*/|//.*', r' ', expansion)
|
||||||
if name.endswith('_FLAG') or name.endswith('MASK'):
|
if name.endswith('_FLAG') or name.endswith('MASK'):
|
||||||
# Macro only to build actual values
|
# Macro only to build actual values
|
||||||
return
|
return
|
||||||
@ -274,6 +275,9 @@ class MacroCollector:
|
|||||||
|
|
||||||
def read_file(self, header_file):
|
def read_file(self, header_file):
|
||||||
for line in header_file:
|
for line in header_file:
|
||||||
|
while line.endswith('\\\n'):
|
||||||
|
cont = next(header_file)
|
||||||
|
line = line[:-2] + cont
|
||||||
self.read_line(line)
|
self.read_line(line)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user