mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-24 06:03:52 +03:00
apibuild: Simplify conditional statements
Improve readability by reducing the complexity and length of conditional statements. Example: The following condition: if (o >= 97 and o <= 122) or (o >= 65 and o <= 90) or (o >= 48 and o <= 57) or (" \t(){}:;,+-*/%&!|[]=><".find(line[i]) == -1): Will be True for every character that is not in string: " \t(){}:;,+-*/%&!|[]=><" Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
This commit is contained in:
parent
e9476e1035
commit
e390bb1571
@ -386,14 +386,13 @@ class index:
|
|||||||
def merge_public(self, idx):
|
def merge_public(self, idx):
|
||||||
for id in idx.functions.keys():
|
for id in idx.functions.keys():
|
||||||
if id in self.functions:
|
if id in self.functions:
|
||||||
|
up = idx.functions[id]
|
||||||
# check that function condition agrees with header
|
# check that function condition agrees with header
|
||||||
if idx.functions[id].conditionals != \
|
if up.conditionals != self.functions[id].conditionals:
|
||||||
self.functions[id].conditionals:
|
|
||||||
self.warning("Header condition differs from Function for %s:" \
|
self.warning("Header condition differs from Function for %s:" \
|
||||||
% id)
|
% id)
|
||||||
self.warning(" H: %s" % self.functions[id].conditionals)
|
self.warning(" H: %s" % self.functions[id].conditionals)
|
||||||
self.warning(" C: %s" % idx.functions[id].conditionals)
|
self.warning(" C: %s" % up.conditionals)
|
||||||
up = idx.functions[id]
|
|
||||||
self.functions[id].update(None, up.module, up.type, up.info, up.extra)
|
self.functions[id].update(None, up.module, up.type, up.info, up.extra)
|
||||||
# else:
|
# else:
|
||||||
# print("Function %s from %s is not declared in headers" % (
|
# print("Function %s from %s is not declared in headers" % (
|
||||||
@ -515,7 +514,7 @@ class CLexer:
|
|||||||
self.last = ('string', tok)
|
self.last = ('string', tok)
|
||||||
return self.last
|
return self.last
|
||||||
|
|
||||||
if l >= 2 and line[0] == '/' and line[1] == '*':
|
if line.startswith("/*"):
|
||||||
line = line[2:]
|
line = line[2:]
|
||||||
found = 0
|
found = 0
|
||||||
tok = ""
|
tok = ""
|
||||||
@ -539,7 +538,7 @@ class CLexer:
|
|||||||
return None
|
return None
|
||||||
self.last = ('comment', tok)
|
self.last = ('comment', tok)
|
||||||
return self.last
|
return self.last
|
||||||
if l >= 2 and line[0] == '/' and line[1] == '/':
|
if line.startswith("//"):
|
||||||
line = line[2:]
|
line = line[2:]
|
||||||
self.last = ('comment', line)
|
self.last = ('comment', line)
|
||||||
return self.last
|
return self.last
|
||||||
@ -564,28 +563,23 @@ class CLexer:
|
|||||||
if line[i] == ' ' or line[i] == '\t':
|
if line[i] == ' ' or line[i] == '\t':
|
||||||
i = i + 1
|
i = i + 1
|
||||||
continue
|
continue
|
||||||
o = ord(line[i])
|
if line[i].isalnum():
|
||||||
if (o >= 97 and o <= 122) or (o >= 65 and o <= 90) or \
|
|
||||||
(o >= 48 and o <= 57):
|
|
||||||
s = i
|
s = i
|
||||||
while i < l:
|
while i < l:
|
||||||
o = ord(line[i])
|
if line[i] not in " \t(){}:;,+-*/%&!|[]=><":
|
||||||
if (o >= 97 and o <= 122) or (o >= 65 and o <= 90) or \
|
|
||||||
(o >= 48 and o <= 57) or \
|
|
||||||
(" \t(){}:;,+-*/%&!|[]=><".find(line[i]) == -1):
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
self.tokens.append(('name', line[s:i]))
|
self.tokens.append(('name', line[s:i]))
|
||||||
continue
|
continue
|
||||||
if "(){}:;,[]".find(line[i]) != -1:
|
if line[i] in "(){}:;,[]":
|
||||||
# if line[i] == '(' or line[i] == ')' or line[i] == '{' or \
|
# if line[i] == '(' or line[i] == ')' or line[i] == '{' or \
|
||||||
# line[i] == '}' or line[i] == ':' or line[i] == ';' or \
|
# line[i] == '}' or line[i] == ':' or line[i] == ';' or \
|
||||||
# line[i] == ',' or line[i] == '[' or line[i] == ']':
|
# line[i] == ',' or line[i] == '[' or line[i] == ']':
|
||||||
self.tokens.append(('sep', line[i]))
|
self.tokens.append(('sep', line[i]))
|
||||||
i = i + 1
|
i = i + 1
|
||||||
continue
|
continue
|
||||||
if "+-*><=/%&!|.".find(line[i]) != -1:
|
if line[i] in "+-*><=/%&!|.":
|
||||||
# if line[i] == '+' or line[i] == '-' or line[i] == '*' or \
|
# if line[i] == '+' or line[i] == '-' or line[i] == '*' or \
|
||||||
# line[i] == '>' or line[i] == '<' or line[i] == '=' or \
|
# line[i] == '>' or line[i] == '<' or line[i] == '=' or \
|
||||||
# line[i] == '/' or line[i] == '%' or line[i] == '&' or \
|
# line[i] == '/' or line[i] == '%' or line[i] == '&' or \
|
||||||
@ -597,8 +591,7 @@ class CLexer:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
j = i + 1
|
j = i + 1
|
||||||
if j < l and (
|
if j < l and line[j] in "+-*><=/%&!|":
|
||||||
"+-*><=/%&!|".find(line[j]) != -1):
|
|
||||||
# line[j] == '+' or line[j] == '-' or line[j] == '*' or \
|
# line[j] == '+' or line[j] == '-' or line[j] == '*' or \
|
||||||
# line[j] == '>' or line[j] == '<' or line[j] == '=' or \
|
# line[j] == '>' or line[j] == '<' or line[j] == '=' or \
|
||||||
# line[j] == '/' or line[j] == '%' or line[j] == '&' or \
|
# line[j] == '/' or line[j] == '%' or line[j] == '&' or \
|
||||||
@ -611,10 +604,7 @@ class CLexer:
|
|||||||
continue
|
continue
|
||||||
s = i
|
s = i
|
||||||
while i < l:
|
while i < l:
|
||||||
o = ord(line[i])
|
if line[i] not in " \t(){}:;,+-*/%&!|[]=><":
|
||||||
if (o >= 97 and o <= 122) or (o >= 65 and o <= 90) or \
|
|
||||||
(o >= 48 and o <= 57) or \
|
|
||||||
(" \t(){}:;,+-*/%&!|[]=><".find(line[i]) == -1):
|
|
||||||
# line[i] != ' ' and line[i] != '\t' and
|
# line[i] != ' ' and line[i] != '\t' and
|
||||||
# line[i] != '(' and line[i] != ')' and
|
# line[i] != '(' and line[i] != ')' and
|
||||||
# line[i] != '{' and line[i] != '}' and
|
# line[i] != '{' and line[i] != '}' and
|
||||||
@ -1555,10 +1545,8 @@ class CParser:
|
|||||||
if token is None:
|
if token is None:
|
||||||
return token
|
return token
|
||||||
|
|
||||||
while token[0] == "name" and (
|
while (token[0] == "name" and
|
||||||
token[1] == "const" or \
|
token[1] in ["const", "unsigned", "signed"]):
|
||||||
token[1] == "unsigned" or \
|
|
||||||
token[1] == "signed"):
|
|
||||||
if self.type == "":
|
if self.type == "":
|
||||||
self.type = token[1]
|
self.type = token[1]
|
||||||
else:
|
else:
|
||||||
@ -2402,8 +2390,7 @@ class docBuilder:
|
|||||||
pass
|
pass
|
||||||
typ = sorted(funcs.keys())
|
typ = sorted(funcs.keys())
|
||||||
for type in typ:
|
for type in typ:
|
||||||
if type == '' or type == 'void' or type == "int" or \
|
if type in ['', "void", "int", "char *", "const char *"]:
|
||||||
type == "char *" or type == "const char *":
|
|
||||||
continue
|
continue
|
||||||
output.write(" <type name='%s'>\n" % (type))
|
output.write(" <type name='%s'>\n" % (type))
|
||||||
ids = funcs[type]
|
ids = funcs[type]
|
||||||
@ -2431,8 +2418,7 @@ class docBuilder:
|
|||||||
pass
|
pass
|
||||||
typ = sorted(funcs.keys())
|
typ = sorted(funcs.keys())
|
||||||
for type in typ:
|
for type in typ:
|
||||||
if type == '' or type == 'void' or type == "int" or \
|
if type in ['', "void", "int", "char *", "const char *"]:
|
||||||
type == "char *" or type == "const char *":
|
|
||||||
continue
|
continue
|
||||||
output.write(" <type name='%s'>\n" % (type))
|
output.write(" <type name='%s'>\n" % (type))
|
||||||
ids = sorted(funcs[type])
|
ids = sorted(funcs[type])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user