From d893890d1098953d6740d5c8114d278b6d9875fc Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Tue, 28 Aug 2012 00:11:40 +0200 Subject: Add documentation for enumeration members Enum members were Annotated in the AST, and most code already assumed they could have docs. What was missing was reading the docs from the comment blocks and writing them in the XML. https://bugzilla.gnome.org/show_bug.cgi?id=683046 --- giscanner/maintransformer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index d4163fae..bf276c06 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -215,6 +215,8 @@ usage is void (*_gtk_reserved1)(void);""" if isinstance(node, (ast.Class, ast.Interface, ast.Union, ast.Enum, ast.Bitfield, ast.Callback)): self._apply_annotations_annotated(node, self._get_block(node)) + if isinstance(node, (ast.Enum, ast.Bitfield)): + self._apply_annotations_enum_members(node, self._get_block(node)) if isinstance(node, (ast.Class, ast.Interface, ast.Record, ast.Union)): block = self._get_block(node) for field in node.fields: @@ -820,6 +822,15 @@ usage is void (*_gtk_reserved1)(void);""" if tag: node.value = tag.value + def _apply_annotations_enum_members(self, node, block): + if block is None: + return + + for m in node.members: + tag = block.params.get(m.symbol, None) + if tag is not None: + m.doc = tag.comment + def _pass_read_annotations2(self, node, chain): if isinstance(node, ast.Function): self._apply_annotations2_function(node, chain) -- cgit v1.2.1 From 4959599c423af9648d8d4e3f02b4117d11ab9a0b Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Tue, 17 Jul 2012 17:04:36 +0200 Subject: giscanner: improve wording of inline documentation https://bugzilla.gnome.org/show_bug.cgi?id=688897 --- giscanner/maintransformer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index bf276c06..037cb265 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -791,7 +791,7 @@ usage is void (*_gtk_reserved1)(void);""" block = self._blocks.get('%s::%s' % (prefix, signal.name)) self._apply_annotations_annotated(signal, block) # We're only attempting to name the signal parameters if - # the number of parameter tags (@foo) is the same or greater + # the number of parameters (@foo) is the same or greater # than the number of signal parameters if block and len(block.params) > len(signal.parameters): names = block.params.items() -- cgit v1.2.1 From a867ab49295f5f6f1f72042c237625905e43953f Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Wed, 28 Nov 2012 19:05:07 +0100 Subject: giscanner: use dict.items()... ... in favor of "for key in dict: value=dict[key]" and "dict.iteritems()". This makes it possible to run the upcoming annotationparser.py tests with both Python 2 and Python 3. https://bugzilla.gnome.org/show_bug.cgi?id=688897 --- giscanner/maintransformer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 037cb265..4ad800d4 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -631,7 +631,7 @@ usage is void (*_gtk_reserved1)(void);""" annos_tag = block.get_tag(TAG_ATTRIBUTES) if annos_tag is not None: - for key, value in annos_tag.options.iteritems(): + for key, value in annos_tag.options.items(): if value: node.attributes.append((key, value.one())) -- cgit v1.2.1 From bdb479f3663d284e1a785f603f17670a754d0bbf Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Fri, 29 Jun 2012 14:43:33 +0200 Subject: giscanner: remove unused variables https://bugzilla.gnome.org/show_bug.cgi?id=688897 --- giscanner/maintransformer.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 4ad800d4..34d153be 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -125,7 +125,7 @@ usage is void (*_gtk_reserved1)(void);""" def _get_validate_parameter_name(self, parent, param_name, origin): try: param = parent.get_parameter(param_name) - except ValueError, e: + except ValueError: param = None if param is None: if isinstance(origin, ast.Parameter): @@ -888,11 +888,10 @@ the ones that failed to resolve removed.""" else: self._transformer.resolve_type(field.type) if isinstance(node, (ast.Class, ast.Interface)): - resolved_parent = None for parent in node.parent_chain: try: self._transformer.resolve_type(parent) - except ValueError, e: + except ValueError: continue target = self._transformer.lookup_typenode(parent) if target: @@ -1293,7 +1292,7 @@ method or constructor of some type.""" params = node.parameters # First, do defaults for well-known callback types - for i, param in enumerate(params): + for param in params: argnode = self._transformer.lookup_typenode(param.type) if isinstance(argnode, ast.Callback): if param.type.target_giname in ('Gio.AsyncReadyCallback', @@ -1302,7 +1301,7 @@ method or constructor of some type.""" param.transfer = ast.PARAM_TRANSFER_NONE callback_param = None - for i, param in enumerate(params): + for param in params: argnode = self._transformer.lookup_typenode(param.type) is_destroynotify = False if isinstance(argnode, ast.Callback): -- cgit v1.2.1 From c291bce772a09af1e884a064ceaa736712fe36a4 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Mon, 29 Oct 2012 08:32:08 +0100 Subject: giscanner: fix DocBlock().comment If there is no comment block description, DocBlock().comment should be None. This results in the removal of unneeded blank lines in the output of DocBlock().to_gtk_doc and hence the .c files generated by misc/update-glib-annotations.py https://bugzilla.gnome.org/show_bug.cgi?id=688897 --- giscanner/maintransformer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 34d153be..67168d6b 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -225,7 +225,7 @@ usage is void (*_gtk_reserved1)(void);""" section_name = 'SECTION:' + name.lower() block = self._blocks.get(section_name) if block: - node.doc = block.comment + node.doc = block.comment if block.comment else '' if isinstance(node, (ast.Class, ast.Interface)): for prop in node.properties: self._apply_annotations_property(node, prop) @@ -600,7 +600,7 @@ usage is void (*_gtk_reserved1)(void);""" if block is None: return - node.doc = block.comment + node.doc = block.comment if block.comment else '' since_tag = block.get_tag(TAG_SINCE) if since_tag is not None: -- cgit v1.2.1 From 0f5f94ed8a86355003533452a2d6cc8077d27535 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 31 Jan 2013 21:42:32 -0500 Subject: giscanner: Apply standard annotations to constant values While there's no particular reason I need to do this, there really isn't any reason to not do this, and it helps with doctool or whatever in the future if we want to document when a constant showed up. g-ir-compiler also keeps track of constant deprecations, so this fixes constants not ever being deprecated. https://bugzilla.gnome.org/show_bug.cgi?id=693040 --- giscanner/maintransformer.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 67168d6b..d149f30a 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -192,7 +192,7 @@ usage is void (*_gtk_reserved1)(void);""" def _get_annotation_name(self, node): if isinstance(node, (ast.Class, ast.Interface, ast.Record, ast.Union, ast.Enum, ast.Bitfield, - ast.Callback, ast.Alias)): + ast.Callback, ast.Alias, ast.Constant)): if node.ctype is not None: return node.ctype elif isinstance(node, ast.Registered) and node.gtype_name is not None: @@ -815,9 +815,12 @@ usage is void (*_gtk_reserved1)(void);""" self._apply_annotations_return(signal, signal.retval, block) def _apply_annotations_constant(self, node): - block = self._blocks.get(node.ctype) - if not block: + block = self._get_block(node) + if block is None: return + + self._apply_annotations_annotated(node, block) + tag = block.get_tag(TAG_VALUE) if tag: node.value = tag.value -- cgit v1.2.1 From 7bdc0b75872dcff2e154d05121568de54996a947 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 3 Feb 2013 08:54:16 -0500 Subject: transformer: Ensure that types aren't resolved if we can't find them This ensures that things can't try to reference undefined/invalid types without emitting warnings, and that users need to include other GIRs at build time if they want to reference another type. https://bugzilla.gnome.org/show_bug.cgi?id=693098 --- giscanner/maintransformer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index d149f30a..4eaf6401 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -306,7 +306,7 @@ usage is void (*_gtk_reserved1)(void);""" else: text = type_str message.warn_node(parent, "%s: Unknown type: %r" % - (text, result.ctype), positions=position) + (text, type_str), positions=position) return result def _resolve_toplevel(self, type_str, type_node=None, node=None, parent=None): -- cgit v1.2.1 From 5ac33d8399b14b631971071f47c9973c9f462d95 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 15 Feb 2013 06:19:00 -0500 Subject: ast: Rename Class.parent to parent_type The eventual model I want to have is that .parent is the "container" of the node. In all the cases where we don't explicitly set the parent, this is the namespace, but having this under one field name would be a big cleanup for the docwriter. https://bugzilla.gnome.org/show_bug.cgi?id=693876 --- giscanner/maintransformer.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 4eaf6401..049ba9ba 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -479,8 +479,8 @@ usage is void (*_gtk_reserved1)(void);""" assert supercls if cls is supercls: return True - if cls.parent and cls.parent.target_giname != 'GObject.Object': - return self._is_gi_subclass(cls.parent, supercls_type) + if cls.parent_type and cls.parent_type.target_giname != 'GObject.Object': + return self._is_gi_subclass(cls.parent_type, supercls_type) return False def _get_transfer_default_return(self, parent, node): @@ -898,11 +898,11 @@ the ones that failed to resolve removed.""" continue target = self._transformer.lookup_typenode(parent) if target: - node.parent = parent + node.parent_type = parent break else: if isinstance(node, ast.Interface): - node.parent = ast.Type(target_giname='GObject.Object') + node.parent_type = ast.Type(target_giname='GObject.Object') for prop in node.properties: self._transformer.resolve_type(prop.type) for sig in node.signals: @@ -1197,8 +1197,8 @@ method or constructor of some type.""" while parent and (not parent.gi_name == 'GObject.Object'): if parent == target: break - if parent.parent: - parent = self._transformer.lookup_typenode(parent.parent) + if parent.parent_type: + parent = self._transformer.lookup_typenode(parent.parent_type) else: parent = None if parent is None: -- cgit v1.2.1 From 93ea709aa40f84e9c5677a7faab345a30072a968 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Fri, 15 Feb 2013 07:06:18 +0100 Subject: giscanner: remove unused variables and imports https://bugzilla.gnome.org/show_bug.cgi?id=697615 --- giscanner/maintransformer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 049ba9ba..8cfb80f8 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -35,9 +35,7 @@ from .annotationparser import (OPT_ALLOW_NONE, OPT_ARRAY, OPT_ATTRIBUTE, OPT_ARRAY_LENGTH, OPT_ARRAY_ZERO_TERMINATED, OPT_CONSTRUCTOR, OPT_METHOD, OPT_TRANSFER_NONE, OPT_TRANSFER_FLOATING) -from .annotationparser import AnnotationParser -from .transformer import TransformerException -from .utils import to_underscores, to_underscores_noprefix +from .utils import to_underscores_noprefix class MainTransformer(object): -- cgit v1.2.1 From e40d509f8247164ff8f893f516c6a7b37ce0a30f Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Fri, 15 Feb 2013 07:18:33 +0100 Subject: giscanner: make _pass_fixup_hidden_fields() more readable https://bugzilla.gnome.org/show_bug.cgi?id=697621 --- giscanner/maintransformer.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 8cfb80f8..fb199861 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -108,16 +108,13 @@ class MainTransformer(object): def _pass_fixup_hidden_fields(self, node, chain): """Hide all callbacks starting with _; the typical usage is void (*_gtk_reserved1)(void);""" - if not isinstance(node, (ast.Class, ast.Interface, - ast.Record, ast.Union)): - return True - for field in node.fields: - if field is None: - continue - if (field.name.startswith('_') + if isinstance(node, (ast.Class, ast.Interface, ast.Record, ast.Union)): + for field in node.fields: + if (field + and field.name.startswith('_') and field.anonymous_node is not None and isinstance(field.anonymous_node, ast.Callback)): - field.introspectable = False + field.introspectable = False return True def _get_validate_parameter_name(self, parent, param_name, origin): -- cgit v1.2.1 From beadfeff33302a3012fb5df1a7197cb4fac8f6f6 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Tue, 9 Apr 2013 12:04:08 +0200 Subject: giscanner: make _pass_read_annotations2() more readable _apply_annotations2_function() is only ever called by _pass_read_annotations2() so there's no need to go and hide what's being done behind an extra method call. Also change the 'if not something; return' into a more readable 'if something: do something'... https://bugzilla.gnome.org/show_bug.cgi?id=697622 --- giscanner/maintransformer.py | 48 ++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 26 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index fb199861..6cf5a006 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -831,34 +831,30 @@ usage is void (*_gtk_reserved1)(void);""" def _pass_read_annotations2(self, node, chain): if isinstance(node, ast.Function): - self._apply_annotations2_function(node, chain) + block = self._blocks.get(node.symbol) + + self._apply_annotation_rename_to(node, chain, block) + + # Handle virtual invokers + parent = chain[-1] if chain else None + if (block and parent): + virtual_annotation = block.get_tag(TAG_VFUNC) + if virtual_annotation: + invoker_name = virtual_annotation.value + matched = False + for vfunc in parent.virtual_methods: + if vfunc.name == invoker_name: + matched = True + vfunc.invoker = node.name + # Also merge in annotations + self._apply_annotations_callable(vfunc, [parent], block) + break + if not matched: + message.warn_node(node, + "Virtual slot %r not found for %r annotation" % (invoker_name, + TAG_VFUNC)) return True - def _apply_annotations2_function(self, node, chain): - block = self._blocks.get(node.symbol) - - self._apply_annotation_rename_to(node, chain, block) - - # Handle virtual invokers - parent = chain[-1] if chain else None - if not (block and parent): - return - virtual = block.get_tag(TAG_VFUNC) - if not virtual: - return - invoker_name = virtual.value - matched = False - for vfunc in parent.virtual_methods: - if vfunc.name == invoker_name: - matched = True - vfunc.invoker = node.name - # Also merge in annotations - self._apply_annotations_callable(vfunc, [parent], block) - break - if not matched: - message.warn_node(node, - "Virtual slot %r not found for %r annotation" % (invoker_name, TAG_VFUNC)) - def _resolve_and_filter_type_list(self, typelist): """Given a list of Type instances, return a new list of types with the ones that failed to resolve removed.""" -- cgit v1.2.1 From 0dbd46680a7fac7ac74c2945e23b95dd04ff79dc Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Thu, 25 Apr 2013 17:08:56 +0200 Subject: giscanner: simplify the MainTransformer().transform() method The ast.Namespace.names instance attribute is an OrderedDict which itself is a specialised dict() subclass. There are any number of ways to test if a dict() is empty or not. Creating a copy of it's keys by iterating over them just to count the number of items in the copy is not the most elegant way though. https://bugzilla.gnome.org/show_bug.cgi?id=699533 --- giscanner/maintransformer.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 6cf5a006..d2a8be7b 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -48,12 +48,10 @@ class MainTransformer(object): # Public API def transform(self): - contents = list(self._namespace.itervalues()) - if len(contents) == 0: - message.fatal("""Namespace is empty; likely causes are: -* Not including .h files to be scanned -* Broken --identifier-prefix -""") + if not self._namespace.names: + message.fatal('Namespace is empty; likely causes are:\n' + '* Not including .h files to be scanned\n' + '* Broken --identifier-prefix') # Some initial namespace surgery self._namespace.walk(self._pass_fixup_hidden_fields) -- cgit v1.2.1 From a0185528a17378b6e6e7bc458f34b1f3719cc420 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 27 Mar 2013 17:33:52 -0400 Subject: annotationparser: Remove get_tag/get_param They're useless if we can just access the dict directly. https://bugzilla.gnome.org/show_bug.cgi?id=688897 --- giscanner/maintransformer.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index d2a8be7b..28ffed36 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -135,7 +135,7 @@ usage is void (*_gtk_reserved1)(void);""" def _apply_annotation_rename_to(self, node, chain, block): if not block: return - rename_to = block.get_tag(TAG_RENAME_TO) + rename_to = block.tags.get(TAG_RENAME_TO) if not rename_to: return rename_to = rename_to.value @@ -227,13 +227,13 @@ usage is void (*_gtk_reserved1)(void);""" if isinstance(node, ast.Class): block = self._get_block(node) if block: - tag = block.get_tag(TAG_UNREF_FUNC) + tag = block.tags.get(TAG_UNREF_FUNC) node.unref_func = tag.value if tag else None - tag = block.get_tag(TAG_REF_FUNC) + tag = block.tags.get(TAG_REF_FUNC) node.ref_func = tag.value if tag else None - tag = block.get_tag(TAG_SET_VALUE_FUNC) + tag = block.tags.get(TAG_SET_VALUE_FUNC) node.set_value_func = tag.value if tag else None - tag = block.get_tag(TAG_GET_VALUE_FUNC) + tag = block.tags.get(TAG_GET_VALUE_FUNC) node.get_value_func = tag.value if tag else None if isinstance(node, ast.Constant): self._apply_annotations_constant(node) @@ -595,11 +595,11 @@ usage is void (*_gtk_reserved1)(void);""" node.doc = block.comment if block.comment else '' - since_tag = block.get_tag(TAG_SINCE) + since_tag = block.tags.get(TAG_SINCE) if since_tag is not None: node.version = since_tag.value - deprecated_tag = block.get_tag(TAG_DEPRECATED) + deprecated_tag = block.tags.get(TAG_DEPRECATED) if deprecated_tag is not None: value = deprecated_tag.value if ': ' in value: @@ -613,7 +613,7 @@ usage is void (*_gtk_reserved1)(void);""" if version is not None: node.deprecated_version = version - stability_tag = block.get_tag(TAG_STABILITY) + stability_tag = block.tags.get(TAG_STABILITY) if stability_tag is not None: stability = stability_tag.value.capitalize() if stability in ["Stable", "Unstable", "Private", "Internal"]: @@ -622,7 +622,7 @@ usage is void (*_gtk_reserved1)(void);""" message.warn('unknown value "%s" for Stability tag' % ( stability_tag.value), stability_tag.position) - annos_tag = block.get_tag(TAG_ATTRIBUTES) + annos_tag = block.tags.get(TAG_ATTRIBUTES) if annos_tag is not None: for key, value in annos_tag.options.items(): if value: @@ -684,7 +684,7 @@ usage is void (*_gtk_reserved1)(void);""" def _apply_annotations_return(self, parent, return_, block): if block: - tag = block.get_tag(TAG_RETURNS) + tag = block.tags.get(TAG_RETURNS) else: tag = None self._apply_annotations_param_ret_common(parent, return_, tag) @@ -695,7 +695,7 @@ usage is void (*_gtk_reserved1)(void);""" declparams.add(parent.instance_parameter.argname) for param in params: if block: - tag = block.get_param(param.argname) + tag = block.params.get(param.argname) else: tag = None self._apply_annotations_param(parent, param, tag) @@ -721,7 +721,7 @@ usage is void (*_gtk_reserved1)(void);""" text = ', should be one of %s' % ( ', '.join(repr(p) for p in unused), ) - tag = block.get_param(doc_name) + tag = block.params.get(doc_name) message.warn( '%s: unknown parameter %r in documentation comment%s' % ( block.name, doc_name, text), @@ -749,7 +749,7 @@ usage is void (*_gtk_reserved1)(void);""" def _apply_annotations_field(self, parent, block, field): if not block: return - tag = block.get_param(field.name) + tag = block.params.get(field.name) if not tag: return t = tag.options.get(OPT_TYPE) @@ -767,7 +767,7 @@ usage is void (*_gtk_reserved1)(void);""" self._apply_annotations_annotated(prop, block) if not block: return - transfer_tag = block.get_tag(TAG_TRANSFER) + transfer_tag = block.tags.get(TAG_TRANSFER) if transfer_tag is not None: transfer = transfer_tag.value if transfer == OPT_TRANSFER_FLOATING: @@ -775,7 +775,7 @@ usage is void (*_gtk_reserved1)(void);""" prop.transfer = transfer else: prop.transfer = self._get_transfer_default(parent, prop) - type_tag = block.get_tag(TAG_TYPE) + type_tag = block.tags.get(TAG_TYPE) if type_tag: prop.type = self._resolve_toplevel(type_tag.value, prop.type, prop, parent) @@ -814,7 +814,7 @@ usage is void (*_gtk_reserved1)(void);""" self._apply_annotations_annotated(node, block) - tag = block.get_tag(TAG_VALUE) + tag = block.tags.get(TAG_VALUE) if tag: node.value = tag.value @@ -836,7 +836,7 @@ usage is void (*_gtk_reserved1)(void);""" # Handle virtual invokers parent = chain[-1] if chain else None if (block and parent): - virtual_annotation = block.get_tag(TAG_VFUNC) + virtual_annotation = block.tags.get(TAG_VFUNC) if virtual_annotation: invoker_name = virtual_annotation.value matched = False -- cgit v1.2.1 From a031129d8ab28e2f51e95e7266f1274bdc592557 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Wed, 9 Jan 2013 17:20:11 +0100 Subject: giscanner: emit 'incorrect number of parameters in comment block' warning instead of silently ignoring parameter names on signals when the number of parameters doesn't match our expectations. https://bugzilla.gnome.org/show_bug.cgi?id=697623 --- giscanner/maintransformer.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 28ffed36..8292f8eb 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -780,20 +780,26 @@ usage is void (*_gtk_reserved1)(void);""" prop.type = self._resolve_toplevel(type_tag.value, prop.type, prop, parent) def _apply_annotations_signal(self, parent, signal): + names = [] prefix = self._get_annotation_name(parent) block = self._blocks.get('%s::%s' % (prefix, signal.name)) - self._apply_annotations_annotated(signal, block) - # We're only attempting to name the signal parameters if - # the number of parameters (@foo) is the same or greater - # than the number of signal parameters - if block and len(block.params) > len(signal.parameters): - names = block.params.items() - # Resolve real parameter names early, so that in later - # phase we can refer to them while resolving annotations. - for i, param in enumerate(signal.parameters): - param.argname, tag = names[i+1] - else: - names = [] + + if block: + self._apply_annotations_annotated(signal, block) + + # We're only attempting to name the signal parameters if + # the number of parameters (@foo) is the same or greater + # than the number of signal parameters + if len(block.params) > len(signal.parameters): + names = block.params.items() + # Resolve real parameter names early, so that in later + # phase we can refer to them while resolving annotations. + for i, param in enumerate(signal.parameters): + param.argname, tag = names[i+1] + else: + message.warn("incorrect number of parameters in comment block, " + "parameter annotations will be ignored.", block.position) + for i, param in enumerate(signal.parameters): if names: name, tag = names[i+1] -- cgit v1.2.1 From c9e2d880011c530ff1454fe31a2d40d189860be5 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Wed, 24 Apr 2013 14:06:18 +0200 Subject: tests: Update misc/pep8.py to 1.4.5 Version in our tree is a wee bit outdated. For example, later work will introduce an utf8 encoded python source file which our old pep8.py does not yet understand (yeah, it really was *that* ancient)... Updated from: https://raw.github.com/jcrocholl/pep8/1.4.5/pep8.py Takes 552c1f1525e37a30376790151c1ba437776682c5, f941537d1c0a40f0906490ed160db6c79af572d3, 5a4afe2a77d0ff7d9fea13dd93c3304a6ca993de and a17f157e19bd6792c00321c8020dca5e5a281f45 into account... https://bugzilla.gnome.org/show_bug.cgi?id=699535 --- giscanner/maintransformer.py | 61 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 8292f8eb..6acc5947 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -37,6 +37,7 @@ from .annotationparser import (OPT_ALLOW_NONE, OPT_ARRAY, OPT_ATTRIBUTE, OPT_TRANSFER_NONE, OPT_TRANSFER_FLOATING) from .utils import to_underscores_noprefix + class MainTransformer(object): def __init__(self, transformer, blocks): @@ -105,7 +106,7 @@ class MainTransformer(object): def _pass_fixup_hidden_fields(self, node, chain): """Hide all callbacks starting with _; the typical -usage is void (*_gtk_reserved1)(void);""" + usage is void (*_gtk_reserved1)(void);""" if isinstance(node, (ast.Class, ast.Interface, ast.Record, ast.Union)): for field in node.fields: if (field @@ -204,7 +205,7 @@ usage is void (*_gtk_reserved1)(void);""" if isinstance(node, ast.Function): self._apply_annotations_function(node, chain) if isinstance(node, ast.Callback): - self._apply_annotations_callable(node, chain, block = self._get_block(node)) + self._apply_annotations_callable(node, chain, block=self._get_block(node)) if isinstance(node, (ast.Class, ast.Interface, ast.Union, ast.Enum, ast.Bitfield, ast.Callback)): self._apply_annotations_annotated(node, self._get_block(node)) @@ -257,7 +258,7 @@ usage is void (*_gtk_reserved1)(void);""" Use resolver() on each identifier, and combiner() on the parts of each complete type. (top_combiner is used on the top-most type.)""" bits = re.split(r'([,<>()])', type_str, 1) - first, sep, rest = [bits[0], '', ''] if (len(bits)==1) else bits + first, sep, rest = [bits[0], '', ''] if (len(bits) == 1) else bits args = [resolver(first)] if sep == '<' or sep == '(': lastsep = '>' if (sep == '<') else ')' @@ -268,9 +269,11 @@ usage is void (*_gtk_reserved1)(void);""" else: rest = sep + rest return top_combiner(*args), rest + def resolver(ident): res = self._transformer.create_type_from_user_string(ident) return res + def combiner(base, *rest): if not rest: return base @@ -281,6 +284,7 @@ usage is void (*_gtk_reserved1)(void);""" message.warn( "Too many parameters in type specification %r" % (type_str, )) return base + def top_combiner(base, *rest): if type_node is not None and isinstance(type_node, ast.Type): base.is_const = type_node.is_const @@ -327,24 +331,23 @@ usage is void (*_gtk_reserved1)(void);""" return block.position def _check_array_element_type(self, array, options): + array_type = array.array_type + element_type = array.element_type + # GPtrArrays are allowed to contain non basic types # (except enums and flags) or basic types that are # as big as a gpointer - if array.array_type == ast.Array.GLIB_PTRARRAY and \ - ((array.element_type in ast.BASIC_GIR_TYPES - and not array.element_type in ast.POINTER_TYPES) or - isinstance(array.element_type, ast.Enum) or - isinstance(array.element_type, ast.Bitfield)): - message.warn("invalid (element-type) for a GPtrArray, " - "must be a pointer", options.position) + if array_type == ast.Array.GLIB_PTRARRAY: + if ((element_type in ast.BASIC_GIR_TYPES and not element_type in ast.POINTER_TYPES) + or isinstance(element_type, (ast.Enum, ast.Bitfield))): + message.warn("invalid (element-type) for a GPtrArray, " + "must be a pointer", options.position) # GByteArrays have (element-type) guint8 by default - if array.array_type == ast.Array.GLIB_BYTEARRAY: - if array.element_type == ast.TYPE_ANY: + if array_type == ast.Array.GLIB_BYTEARRAY: + if element_type == ast.TYPE_ANY: array.element_type = ast.TYPE_UINT8 - elif not array.element_type in [ast.TYPE_UINT8, - ast.TYPE_INT8, - ast.TYPE_CHAR]: + elif not element_type in [ast.TYPE_UINT8, ast.TYPE_INT8, ast.TYPE_CHAR]: message.warn("invalid (element-type) for a GByteArray, " "must be one of guint8, gint8 or gchar", options.position) @@ -454,8 +457,8 @@ usage is void (*_gtk_reserved1)(void);""" def _get_transfer_default_returntype_basic(self, typeval): if (typeval.is_equiv(ast.BASIC_GIR_TYPES) - or typeval.is_const - or typeval.is_equiv(ast.TYPE_NONE)): + or typeval.is_const + or typeval.is_equiv(ast.TYPE_NONE)): return ast.PARAM_TRANSFER_NONE elif typeval.is_equiv(ast.TYPE_STRING): # Non-const strings default to FULL @@ -535,8 +538,7 @@ usage is void (*_gtk_reserved1)(void);""" caller_allocates = False annotated_direction = None - if (OPT_INOUT in options or - OPT_INOUT_ALT in options): + if (OPT_INOUT in options or OPT_INOUT_ALT in options): annotated_direction = ast.PARAM_DIRECTION_INOUT elif OPT_OUT in options: subtype = options[OPT_OUT] @@ -574,9 +576,9 @@ usage is void (*_gtk_reserved1)(void);""" self._adjust_container_type(parent, node, options) - if (OPT_ALLOW_NONE in options or - node.type.target_giname == 'Gio.AsyncReadyCallback' or - node.type.target_giname == 'Gio.Cancellable'): + if (OPT_ALLOW_NONE in options + or node.type.target_giname == 'Gio.AsyncReadyCallback' + or node.type.target_giname == 'Gio.Cancellable'): node.allow_none = True if tag is not None and tag.comment is not None: @@ -605,7 +607,7 @@ usage is void (*_gtk_reserved1)(void);""" if ': ' in value: colon = value.find(': ') version = value[:colon] - desc = value[colon+2:] + desc = value[colon + 2:] else: desc = value version = None @@ -718,8 +720,7 @@ usage is void (*_gtk_reserved1)(void);""" (param, ) = unused text = ', should be %r' % (param, ) else: - text = ', should be one of %s' % ( - ', '.join(repr(p) for p in unused), ) + text = ', should be one of %s' % (', '.join(repr(p) for p in unused), ) tag = block.params.get(doc_name) message.warn( @@ -795,14 +796,14 @@ usage is void (*_gtk_reserved1)(void);""" # Resolve real parameter names early, so that in later # phase we can refer to them while resolving annotations. for i, param in enumerate(signal.parameters): - param.argname, tag = names[i+1] + param.argname, tag = names[i + 1] else: message.warn("incorrect number of parameters in comment block, " "parameter annotations will be ignored.", block.position) for i, param in enumerate(signal.parameters): if names: - name, tag = names[i+1] + name, tag = names[i + 1] options = getattr(tag, 'options', {}) param_type = options.get(OPT_TYPE) if param_type: @@ -1164,9 +1165,9 @@ method or constructor of some type.""" origin_node = self._get_constructor_class(func, subsymbol) if origin_node is None: if func.is_constructor: - message.warn_node(func, - "Can't find matching type for constructor; symbol=%r" \ - % (func.symbol, )) + message.warn_node( + func, + "Can't find matching type for constructor; symbol=%r" % (func.symbol, )) return False # Some sanity checks; only objects and boxeds can have ctors -- cgit v1.2.1 From 4613390bcfd6a814685a5862925b11338b797e48 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 7 May 2013 18:41:48 -0400 Subject: scanner: Only warn about signal parameters if there are some We don't want to emit a warning if there are actually no parameters. --- giscanner/maintransformer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'giscanner/maintransformer.py') diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 6acc5947..11bfb4cb 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -797,7 +797,9 @@ class MainTransformer(object): # phase we can refer to them while resolving annotations. for i, param in enumerate(signal.parameters): param.argname, tag = names[i + 1] - else: + elif len(signal.parameters) != 0: + # Only warn about missing params if there are actually parameters + # besides implicit self. message.warn("incorrect number of parameters in comment block, " "parameter annotations will be ignored.", block.position) -- cgit v1.2.1