diff options
author | Johan Dahlin <johan@gnome.org> | 2010-09-14 19:31:46 -0300 |
---|---|---|
committer | Johan Dahlin <johan@gnome.org> | 2010-09-14 19:37:52 -0300 |
commit | c31120dd00d2ea1513399832461ed4437c6940de (patch) | |
tree | 3a62e8ceb6509b80d34cf0cb8a33d519c6779130 /giscanner | |
parent | 839afcc48c492690e4d25ab763b081ce37cd1858 (diff) |
Add a parameter mismatch warning
https://bugzilla.gnome.org/show_bug.cgi?id=629708
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/annotationparser.py | 3 | ||||
-rw-r--r-- | giscanner/ast.py | 1 | ||||
-rw-r--r-- | giscanner/maintransformer.py | 25 |
3 files changed, 28 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) |