scripts: fix tokenizing of enum parameters in API builder

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.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2020-05-19 12:27:15 +01:00
parent 50eb22e343
commit 34204f9923
1 changed files with 22 additions and 0 deletions

View File

@ -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] == "'":