The API build script tokenizes enums declarations by first splitting on
whitespace. This is unhelpful as it means an enum
# define VIR_USE_CPU(cpumap, cpu) ((cpumap)[(cpu) / 8] |= (1 << ((cpu) % 8)))
Gets tokenized as
#define
VIR_USE_CPU(cpumap,
cpu)
((cpumap)[(cpu)
/
8]
|=
(1
<<
((cpu)
%
8)))
With this change, the set of parameters are all merged into the first
token:
#define
VIR_USE_CPU(cpumap,cpu)
((cpumap)[(cpu)
/
8]
|=
(1
<<
((cpu)
%
8)))
which is more convenient to process later on in the script.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
scripts/apibuild.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/scripts/apibuild.py b/scripts/apibuild.py
index b13b5db644..68c588d8b6 100755
--- a/scripts/apibuild.py
+++ b/scripts/apibuild.py
@@ -494,6 +494,28 @@ class CLexer:
if self.tokens[0][1] == "#":
self.tokens[0] = ('preproc', "#" +
self.tokens[1][1])
del self.tokens[1]
+
+ if self.tokens[0][1] == "#define" and "(" in
self.tokens[1][1]:
+ newtokens = [self.tokens[0]]
+
+ endArg = self.tokens[1][1].find(")")
+ if endArg != -1:
+ extra = self.tokens[1][1][endArg+1:]
+ name = self.tokens[1][1][0:endArg+1]
+ newtokens.append(('preproc', name))
+ if extra != "":
+ newtokens.append(('preproc', extra))
+ else:
+ name = self.tokens[1][1]
+ for token in self.tokens[2:]:
+ if name is not None:
+ name = name + token[1]
+ if ")" in token[1]:
+ newtokens.append(('preproc', name))
+ name = None
+ else:
+ newtokens.append(token)
+ self.tokens = newtokens
break
nline = len(line)
if line[0] == '"' or line[0] == "'":
--
2.26.2