mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
apibuild: Simplify parseTypeComment()
Improve readability and reduce complexity the method parseTypeComment(). Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
This commit is contained in:
committed by
Daniel P. Berrangé
parent
c57b56756a
commit
06462d7927
@@ -756,48 +756,38 @@ class CParser:
|
|||||||
#
|
#
|
||||||
# Parse a comment block associate to a typedef
|
# Parse a comment block associate to a typedef
|
||||||
#
|
#
|
||||||
def parseTypeComment(self, name, quiet=0):
|
def parseTypeComment(self, name, quiet=False):
|
||||||
if name[0:2] == '__':
|
if name[0:2] == '__':
|
||||||
quiet = 1
|
quiet = True
|
||||||
|
|
||||||
args = []
|
|
||||||
desc = ""
|
|
||||||
|
|
||||||
if self.comment is None:
|
if self.comment is None:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
self.warning("Missing comment for type %s" % (name))
|
self.warning("Missing comment for type %s" % (name))
|
||||||
return((args, desc))
|
return None
|
||||||
if self.comment[0] != '*':
|
if not self.comment.startswith('*'):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
self.warning("Missing * in type comment for %s" % (name))
|
self.warning("Missing * in type comment for %s" % (name))
|
||||||
return((args, desc))
|
return None
|
||||||
|
|
||||||
lines = self.comment.split('\n')
|
lines = self.comment.split('\n')
|
||||||
if lines[0] == '*':
|
# Remove lines that contain only single asterisk
|
||||||
del lines[0]
|
lines[:] = [line for line in lines if line.strip() != '*']
|
||||||
|
|
||||||
if lines[0] != "* %s:" % (name):
|
if lines[0] != "* %s:" % (name):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
self.warning("Misformatted type comment for %s" % (name))
|
self.warning("Misformatted type comment for %s" % (name))
|
||||||
self.warning(" Expecting '* %s:' got '%s'" % (name, lines[0]))
|
self.warning(" Expecting '* %s:' got '%s'" % (name, lines[0]))
|
||||||
return((args, desc))
|
return None
|
||||||
del lines[0]
|
del lines[0]
|
||||||
while len(lines) > 0 and lines[0] == '*':
|
|
||||||
del lines[0]
|
|
||||||
desc = ""
|
|
||||||
while len(lines) > 0:
|
|
||||||
l = lines[0]
|
|
||||||
while len(l) > 0 and l[0] == '*':
|
|
||||||
l = l[1:]
|
|
||||||
l = l.strip()
|
|
||||||
desc = desc + " " + l
|
|
||||||
del lines[0]
|
|
||||||
|
|
||||||
desc = desc.strip()
|
# Concatenate all remaining lines by striping leading asterisks
|
||||||
|
desc = " ".join([line.lstrip("*").strip() for line in lines]).strip()
|
||||||
|
|
||||||
if quiet == 0:
|
if not (quiet or desc):
|
||||||
if desc == "":
|
self.warning("Type comment for %s lack description of the macro"
|
||||||
self.warning("Type comment for %s lack description of the macro" % (name))
|
% (name))
|
||||||
|
|
||||||
return(desc)
|
return desc
|
||||||
#
|
#
|
||||||
# Parse a comment block associate to a macro
|
# Parse a comment block associate to a macro
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user