提交 34204f99 编写于 作者: D Daniel P. Berrangé

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: NMichal Privoznik <mprivozn@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 50eb22e3
......@@ -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] == "'":
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册