Newer
Older
# This script takes the output of get-project-params.sh on stdin
# and transforms it into a tabular representation for further
# processing.
import sys
import re
import os.path
def debug(msg):
sys.stderr.write(msg+"\n")
def write_out(*args):
print_("@@@".join(str(a) for a in args))
comment = re.compile(r"//! \\ogs_file_(param|attr)\{([A-Za-z_0-9]+)\}( \\todo .*)?$")
comment_special = re.compile(r"//! \\ogs_file(_param|_attr)?_special(\{[A-Za-z_0-9]+\})?( \\todo .*)?$")
# capture #5 is the parameter name
getter = re.compile(r'(get|check|ignore|peek)Config(Parameter|Attribute|Subtree)(List|Optional|All)?'
+r'\s*(<.*>)?'
+r'\s*\(\s*"([a-zA-Z_0-9:]+)"\s*[,)]')
getter_special = re.compile(r'(get|check|ignore|peek)Config(Parameter|Attribute|Subtree)(List|Optional|All)?'
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
+r'\s*(<.*>)?\(')
# merge lines belonging together from grep -A 2 output.
def merge_lines(it):
buf = ""
buf_fn = ""
buf_lno = 0
for l in it:
l = l.strip()
if (not l) or l == "--":
# separator line
if buf_fn:
yield buf_fn, buf_lno, buf
buf = ""
buf_fn = ""
buf_lno = 0
else:
m = re.match("(.*)([:-])([0-9]+)([:-])(.*)$", l)
assert m
assert m.group(2) == m.group(4)
fn = m.group(1)
lno = int(m.group(3))
line = m.group(5)
msg = fn + m.group(2) + str(lno) + m.group(4) + line
# remove non-doxygen comments
line = re.sub('/\*[^!*].*\*/|/\*\*/', '', line)
line = re.sub("//[^!*].*|//$", "", line, 1)
if buf_fn:
if m.group(2) == ":":
# new location started, yield the old one
yield buf_fn, buf_lno, buf
buf = line
buf_fn = fn
buf_lno = lno
else:
# continuation line
assert buf_fn == fn
buf += " " + line
elif m.group(2) == ":":
buf = line
buf_fn = fn
buf_lno = lno
else:
# continuation line and empty buffer
pass
if buf_fn and (comment.search(line) or comment_special.search(line)):
# make sure nothing can be appended to doxygen comment lines
yield buf_fn, buf_lno, buf
buf = ""
buf_lno = 0
buf_fn = ""
if buf_fn:
yield buf_fn, buf_lno, buf
return
yield
state = "getter"
path = ""
lineno = 0
line = ""
tag_path_comment = ""
param_or_attr_comment = ""
for inline in merge_lines(sys.stdin):
oldpath = path; oldlineno = lineno; oldline = line
path, lineno, line = inline
if path != oldpath: debug(path)
if m:
if state != "getter":
write_out("UNNEEDED", oldpath, oldlineno, oldline)
state = "comment"
param_or_attr_comment = m.group(1)
tag_path_comment = m.group(2).replace("__", ".")
debug(" {0:>5} //! {1}".format(lineno, tag_path_comment))
tag_name_comment = tag_path_comment.split(".")[-1]
continue
if m:
if state != "getter":
write_out("UNNEEDED", oldpath, oldlineno, oldline)
state = "comment"
param_or_attr_comment = "special"
if m.group(1): # param|attr matched
# second group must not be empty!
tag_path_comment = m.group(2).strip("{}").replace("__", ".")
param = tag_path_comment.split(".")[-1]
paramtype = ""
method = ""
write_out("OK", path, lineno, tag_path_comment, param, paramtype, method)
state = "getter" # reset state s.t. next time a comment is accepted
continue
if m:
param = m.group(5)
paramtype = m.group(4)[1:-1] if m.group(4) else ""
method = m.group(1) + "Config" + m.group(2) + (m.group(3) or "")
if state != "comment" or oldpath != path:
write_out("NODOC", path, lineno, "NONE", param, paramtype, method)
else:
debug(" {0:>5} {1} {2} ".format(lineno, param, paramtype))
if param != tag_name_comment:
debug("error: parameter name from comment and code do not match: "
+ tag_name_comment + " vs. " + param)
write_out("NODOC", path, lineno, tag_path_comment, param, paramtype, method)
elif lineno != oldlineno+1:
debug("error: the associated comment is not on the line preceding this one."
+ " line numbers {0} vs. {1}".format(oldlineno, lineno))
write_out("NODOC", path, lineno, tag_path_comment, param, paramtype, method)
elif param_or_attr_comment == "param" and m.group(2) != "Parameter" and m.group(2) != "Subtree":
debug("error: comment says param but code says different.")
write_out("NODOC", path, lineno, tag_path_comment, param, paramtype, method)
elif param_or_attr_comment == "attr" and m.group(2) != "Attribute":
debug("error: comment says attr but code says different.")
write_out("NODOC", path, lineno, tag_path_comment, param, paramtype, method)
elif param_or_attr_comment == "special":
debug("error: comment comments a special line.")
write_out("NODOC", path, lineno, "UNKNOWN", "UNKNOWN", paramtype, method)
else:
write_out("OK", path, lineno, tag_path_comment, param, paramtype, method)
state = "getter"
continue
if m:
paramtype = m.group(4)[1:-1] if m.group(4) else ""
method = m.group(1) + "Config" + m.group(2) + (m.group(3) or "")
if state != "comment" or oldpath != path:
write_out("NODOC", path, lineno, "NONE", "UNKNOWN", paramtype, method)
else:
if lineno != oldlineno+1:
debug("error: the associated comment is not on the line preceding this one."
+ " line numbers {0} vs. {1}".format(oldlineno, lineno))
write_out("NODOC", path, lineno, "UNKNOWN", "UNKNOWN", paramtype, method)
elif param_or_attr_comment != "special":
debug("error: comment does not comment a special line.")
write_out("NODOC", path, lineno, "UNKNOWN", "UNKNOWN", paramtype, method)
else:
write_out("SPECIAL", path, lineno, paramtype, method)
state = "getter"
continue
write_out("WRONGIN", path, lineno, line.strip())
state = "getter" # reset state in order to avoid warnings