|
@@ -14,7 +14,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
SKIP_FILES = [ "OpenBSD_malloc_Linux.c",
|
|
|
"eventdns.c",
|
|
|
"eventdns.h",
|
|
@@ -23,8 +40,11 @@ SKIP_FILES = [ "OpenBSD_malloc_Linux.c",
|
|
|
"aes.c",
|
|
|
"aes.h" ]
|
|
|
|
|
|
+
|
|
|
SKIP_NAME_PATTERNS = [ r'^.*_c_id$' ]
|
|
|
|
|
|
+
|
|
|
+
|
|
|
ADD_DOCDOCS_TO_TYPES = [ 'function', 'type', 'typedef' ]
|
|
|
|
|
|
|
|
@@ -43,6 +63,9 @@ THING_RE = re.compile(r'^Member ([a-zA-Z0-9_]+).*\((typedef|define|function|vari
|
|
|
SKIP_NAMES = [re.compile(s) for s in SKIP_NAME_PATTERNS]
|
|
|
|
|
|
def parsething(thing):
|
|
|
+ """I figure out what 'foobar baz in quux quum is not documented' means,
|
|
|
+ and return: the name of the foobar, and the kind of the foobar.
|
|
|
+ """
|
|
|
if thing.startswith("Compound "):
|
|
|
tp, name = "type", thing.split()[1]
|
|
|
else:
|
|
@@ -59,6 +82,10 @@ def parsething(thing):
|
|
|
return name, tp
|
|
|
|
|
|
def read():
|
|
|
+ """I snarf doxygen stderr from stdin, and parse all the "foo has no
|
|
|
+ documentation messages. I return a map from filename to lists
|
|
|
+ of tuples of (alleged line number, name of thing, kind of thing)
|
|
|
+ """
|
|
|
errs = {}
|
|
|
for line in sys.stdin:
|
|
|
m = NODOC_LINE_RE.match(line)
|
|
@@ -71,6 +98,9 @@ def read():
|
|
|
return errs
|
|
|
|
|
|
def findline(lines, lineno, ident):
|
|
|
+ """Given a list of all the lines in the file (adjusted so 1-indexing works),
|
|
|
+ a line number that ident is alledgedly on, and ident, I figure out
|
|
|
+ the line where ident was really declared."""
|
|
|
for lineno in xrange(lineno, 0, -1):
|
|
|
if ident in lines[lineno]:
|
|
|
return lineno
|
|
@@ -80,6 +110,8 @@ def findline(lines, lineno, ident):
|
|
|
FUNC_PAT = re.compile(r"^[A-Za-z0-9_]+\(")
|
|
|
|
|
|
def hascomment(lines, lineno, kind):
|
|
|
+ """I return true if it looks like there's already a good comment about
|
|
|
+ the thing on lineno of lines of type kind. """
|
|
|
if "*/" in lines[lineno-1]:
|
|
|
return True
|
|
|
if kind == 'function' and FUNC_PAT.match(lines[lineno]):
|
|
@@ -88,6 +120,8 @@ def hascomment(lines, lineno, kind):
|
|
|
return False
|
|
|
|
|
|
def hasdocdoc(lines, lineno, kind):
|
|
|
+ """I return true if it looks like there's already a docdoc comment about
|
|
|
+ the thing on lineno of lines of type kind."""
|
|
|
if "DOCDOC" in lines[lineno] or "DOCDOC" in lines[lineno-1]:
|
|
|
return True
|
|
|
if kind == 'function' and FUNC_PAT.match(lines[lineno]):
|
|
@@ -95,13 +129,17 @@ def hasdocdoc(lines, lineno, kind):
|
|
|
return True
|
|
|
return False
|
|
|
|
|
|
-def checkf(fn, errs, comments):
|
|
|
-
|
|
|
+def checkf(fn, errs):
|
|
|
+ """I go through the output of read() for a single file, and build a list
|
|
|
+ of tuples of things that want DOCDOC comments. Each tuple has:
|
|
|
+ the line number where the comment goes; the kind of thing; its name.
|
|
|
+ """
|
|
|
for skip in SKIP_FILES:
|
|
|
if fn.endswith(skip):
|
|
|
print "Skipping",fn
|
|
|
return
|
|
|
|
|
|
+ comments = []
|
|
|
lines = [ None ]
|
|
|
try:
|
|
|
lines.extend( open(fn, 'r').readlines() )
|
|
@@ -132,9 +170,11 @@ def checkf(fn, errs, comments):
|
|
|
if kind == 'function' and FUNC_PAT.match(lines[ln]):
|
|
|
ln = ln - 1
|
|
|
|
|
|
- comments.setdefault(fn, []).append((ln, kind, name))
|
|
|
+ comments.append((ln, kind, name))
|
|
|
|
|
|
def applyComments(fn, entries):
|
|
|
+ """I apply lots of comments to the file in fn, making a new .newdoc file.
|
|
|
+ """
|
|
|
N = 0
|
|
|
|
|
|
lines = [ None ]
|
|
@@ -143,6 +183,9 @@ def applyComments(fn, entries):
|
|
|
except IOError:
|
|
|
return
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
entries.sort()
|
|
|
entries.reverse()
|
|
|
|
|
@@ -159,10 +202,8 @@ def applyComments(fn, entries):
|
|
|
print "Added %s DOCDOCs to %s" %(N, fn)
|
|
|
|
|
|
e = read()
|
|
|
-comments = {}
|
|
|
|
|
|
for fn, errs in e.iteritems():
|
|
|
- checkf(fn, errs, comments)
|
|
|
-
|
|
|
-for fn, entries in comments.iteritems():
|
|
|
- applyComments(fn, entries)
|
|
|
+ comments = checkf(fn, errs)
|
|
|
+ if comments:
|
|
|
+ applyComments(fn, comments)
|