[gobject-introspection] Add a parameter mismatch warning
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] Add a parameter mismatch warning
- Date: Tue, 14 Sep 2010 22:38:31 +0000 (UTC)
commit c31120dd00d2ea1513399832461ed4437c6940de
Author: Johan Dahlin <johan gnome org>
Date: Tue Sep 14 19:31:46 2010 -0300
Add a parameter mismatch warning
https://bugzilla.gnome.org/show_bug.cgi?id=629708
giscanner/annotationparser.py | 3 +++
giscanner/ast.py | 1 +
giscanner/maintransformer.py | 25 ++++++++++++++++++++++++-
tests/warn/Makefile.am | 1 +
tests/warn/unknown-parameter.h | 28 ++++++++++++++++++++++++++++
tests/warn/warningtester.py | 2 ++
6 files changed, 59 insertions(+), 1 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index fedefcd..2aa198e 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -74,6 +74,7 @@ class DocBlock(object):
self.value = None
self.tags = odict()
self.comment = None
+ self.params = []
def __repr__(self):
return '<DocBlock %r %r>' % (self.name, self.options)
@@ -235,6 +236,8 @@ class AnnotationParser(object):
tag.comment = line[first_colonspace_index+2:].strip()
block.tags[argname] = tag
last_param_tag = tag
+ if is_parameter:
+ block.params.append(argname)
elif (not is_parameter) and parsing_parameters and last_param_tag:
# We need to handle continuation lines on parameters. The
# conditional above - if a line doesn't start with '@', we're
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 53ddad2..8ff61e1 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -523,6 +523,7 @@ class Callable(Node):
self.retval = retval
self.parameters = parameters
self.throws = not not throws
+ self.instance_parameter = None # Parameter
def get_parameter_index(self, name):
for i, parameter in enumerate(self.parameters):
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index a7f2b61..550023f 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -560,12 +560,34 @@ usage is void (*_gtk_reserved1)(void);"""
self._apply_annotations_param_ret_common(parent, return_, tag)
def _apply_annotations_params(self, parent, params, block):
+ allparams = []
+ if parent.instance_parameter:
+ allparams.append(parent.instance_parameter.argname)
for param in params:
if block:
tag = block.get(param.argname)
else:
tag = None
self._apply_annotations_param(parent, param, tag)
+ allparams.append(param.argname)
+
+ if not block:
+ return
+ docparams = block.params[:]
+ for doc_name in docparams:
+ if doc_name in allparams:
+ continue
+ if len(allparams) == 0:
+ text = ''
+ elif len(allparams) == 1:
+ text = ', should be %r' % (allparams[0], )
+ else:
+ text = ', should be one of %s' % (
+ ', '.join(repr(p) for p in allparams), )
+
+ message.warn(
+ '%s: unknown parameter %r in documentation comment%s' % (
+ block.name, doc_name, text))
def _apply_annotations_callable(self, node, chain, block):
self._apply_annotations_annotated(node, block)
@@ -822,7 +844,7 @@ method or constructor of some type."""
uscored = self._uscored_identifier_for_type(first.type)
if not subsymbol.startswith(uscored):
return False
- del func.parameters[0]
+ func.instance_parameter = func.parameters.pop(0)
subsym_idx = func.symbol.find(subsymbol)
self._namespace.float(func)
func.name = func.symbol[(subsym_idx + len(uscored) + 1):]
@@ -954,6 +976,7 @@ method or constructor of some type."""
if matched_signal:
continue
vfunc = ast.VFunction.from_callback(callback)
+ vfunc.instance_parameter = callback.parameters[0]
vfunc.inherit_file_positions(callback)
node.virtual_methods.append(vfunc)
diff --git a/tests/warn/Makefile.am b/tests/warn/Makefile.am
index 9e585bd..deece2f 100644
--- a/tests/warn/Makefile.am
+++ b/tests/warn/Makefile.am
@@ -4,6 +4,7 @@ TESTS = \
callback-invalid-scope.h \
callback-missing-scope.h \
return-gobject.h \
+ unknown-parameter.h \
unresolved-type.h
EXTRA_DIST = warningtester.py common.h $(TESTS)
diff --git a/tests/warn/unknown-parameter.h b/tests/warn/unknown-parameter.h
new file mode 100644
index 0000000..5b43c75
--- /dev/null
+++ b/tests/warn/unknown-parameter.h
@@ -0,0 +1,28 @@
+/* See https://bugzilla.gnome.org/show_bug.cgi?id=629708 */
+
+/**
+ * test_param_mismatch:
+ * @wrong_name: (out):
+ *
+ */
+void test_param_mismatch(int *out);
+
+// EXPECT:: Warning: Test: test_param_mismatch: unknown parameter 'wrong_name' in documentation comment, should be 'out'
+
+/**
+ * test_param_mismatch2:
+ * @wrong_name2: (out):
+ *
+ */
+void test_param_mismatch2(int a, int *out2);
+
+// EXPECT:: Warning: Test: test_param_mismatch2: unknown parameter 'wrong_name2' in documentation comment, should be one of 'a', 'out2'
+
+/**
+ * test_param_missing:
+ * @missing: (out):
+ *
+ */
+void test_param_missing(void);
+
+// EXPECT:: Warning: Test: test_param_missing: unknown parameter 'missing' in documentation comment
diff --git a/tests/warn/warningtester.py b/tests/warn/warningtester.py
index f30e3e0..a3de1e8 100644
--- a/tests/warn/warningtester.py
+++ b/tests/warn/warningtester.py
@@ -101,6 +101,8 @@ def check(args):
failed_tests = 0
expected_warnings = _extract_expected(filename)
+ if '' in warnings:
+ warnings.remove('')
if len(expected_warnings) != len(warnings):
raise SystemExit(
"ERROR: expected %d warnings, but got %d: %r\n" % (
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]