diff options
author | Stef Walter <stefw@gnome.org> | 2013-10-28 22:13:47 +0100 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-10-28 17:32:27 -0400 |
commit | 288b339edf262f1dba4e87a9faef46cc79749bd5 (patch) | |
tree | 665063f59d802db644f8496f8295d2478443ab08 | |
parent | 95cd591fb7e855d280505168444894e729bb39f8 (diff) | |
download | gobject-introspection-288b339edf262f1dba4e87a9faef46cc79749bd5.tar.gz |
giscanner: Test fixups for field annotations and documentation
Related to: https://bugzilla.gnome.org/show_bug.cgi?id=710561
-rw-r--r-- | giscanner/girparser.py | 19 | ||||
-rw-r--r-- | tests/scanner/Regress-1.0-Gjs-expected/Regress.AnnotationFields.page | 25 | ||||
-rw-r--r-- | tests/scanner/Regress-1.0-Python-expected/Regress.AnnotationFields.page | 25 | ||||
-rw-r--r-- | tests/scanner/Utility-1.0-expected.gir | 1 |
4 files changed, 63 insertions, 7 deletions
diff --git a/giscanner/girparser.py b/giscanner/girparser.py index d01e753c..25e9035d 100644 --- a/giscanner/girparser.py +++ b/giscanner/girparser.py @@ -331,7 +331,7 @@ class GIRParser(object): for i, paramnode in enumerate(self._find_children(parameters_node, _corens('parameter'))): param = parameters[i] - self._parse_type_second_pass(func, paramnode, param.type) + self._parse_type_array_length(parameters, paramnode, param.type) closure = paramnode.attrib.get('closure') if closure: idx = int(closure) @@ -343,7 +343,7 @@ class GIRParser(object): assert idx < len(parameters), "%d >= %d" % (idx, len(parameters)) param.destroy_name = parameters[idx].argname - self._parse_type_second_pass(func, returnnode, retval.type) + self._parse_type_array_length(parameters, returnnode, retval.type) self._parse_generic_attribs(node, func) @@ -375,6 +375,9 @@ class GIRParser(object): func = self._parse_function_common(method, ast.Function, compound) func.is_method = True compound.methods.append(func) + for i, fieldnode in enumerate(self._find_children(node, _corens('field'))): + field = compound.fields[i] + self._parse_type_array_length(compound.fields, fieldnode, field.type) for func in self._find_children(node, _corens('function')): compound.static_methods.append( self._parse_function_common(func, ast.Function, compound)) @@ -456,8 +459,8 @@ class GIRParser(object): return self._parse_type_simple(typenode) assert False, "Failed to parse toplevel type" - def _parse_type_second_pass(self, parent, node, typeval): - """A hack necessary to handle the integer parameter indexes on + def _parse_type_array_length(self, siblings, node, typeval): + """A hack necessary to handle the integer parameter/field indexes on array types.""" typenode = node.find(_corens('array')) if typenode is None: @@ -465,9 +468,11 @@ class GIRParser(object): lenidx = typenode.attrib.get('length') if lenidx is not None: idx = int(lenidx) - assert idx < len(parent.parameters), "%r %d >= %d" % (parent, idx, - len(parent.parameters)) - typeval.length_param_name = parent.parameters[idx].argname + assert idx < len(siblings), "%r %d >= %d" % (parent, idx, len(siblings)) + if isinstance(siblings[idx], ast.Field): + typeval.length_param_name = siblings[idx].name + else: + typeval.length_param_name = siblings[idx].argname def _parse_boxed(self, node): obj = ast.Boxed(node.attrib[_glibns('name')], diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnnotationFields.page b/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnnotationFields.page new file mode 100644 index 00000000..53234545 --- /dev/null +++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.AnnotationFields.page @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<page id="Regress.AnnotationFields" + type="guide" + style="record" + xmlns="http://projectmallard.org/1.0/" + xmlns:api="http://projectmallard.org/experimental/api/" + xmlns:ui="http://projectmallard.org/1.0/ui/"> + <info> + + <link xref="index" group="record" type="guide"/> + + </info> + <title>Regress.AnnotationFields</title> + + + + <p>This is a struct for testing field documentation and annotations</p> + + + + + + + +</page> diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.AnnotationFields.page b/tests/scanner/Regress-1.0-Python-expected/Regress.AnnotationFields.page new file mode 100644 index 00000000..53234545 --- /dev/null +++ b/tests/scanner/Regress-1.0-Python-expected/Regress.AnnotationFields.page @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<page id="Regress.AnnotationFields" + type="guide" + style="record" + xmlns="http://projectmallard.org/1.0/" + xmlns:api="http://projectmallard.org/experimental/api/" + xmlns:ui="http://projectmallard.org/1.0/ui/"> + <info> + + <link xref="index" group="record" type="guide"/> + + </info> + <title>Regress.AnnotationFields</title> + + + + <p>This is a struct for testing field documentation and annotations</p> + + + + + + + +</page> diff --git a/tests/scanner/Utility-1.0-expected.gir b/tests/scanner/Utility-1.0-expected.gir index 1936fd2b..0bd38297 100644 --- a/tests/scanner/Utility-1.0-expected.gir +++ b/tests/scanner/Utility-1.0-expected.gir @@ -19,6 +19,7 @@ and/or use gtk-doc annotations. --> </alias> <record name="Buffer" c:type="UtilityBuffer"> <field name="data" writable="1"> + <doc xml:space="preserve">the data</doc> <type name="gpointer"/> </field> <field name="length" writable="1"> |