diff options
Diffstat (limited to 'giscanner/maintransformer.py')
-rw-r--r-- | giscanner/maintransformer.py | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 9468751d..9077a1d0 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -69,6 +69,10 @@ class MainTransformer(object): # Read in most annotations now. self._namespace.walk(self._pass_read_annotations) + # Now that we have associated doc SECTIONs to classes, + # add the unused section blocks as standalone nodes. + self._add_standalone_doc_sections() + # Now that we've possibly seen more types from annotations, # do another type resolution pass. self._namespace.walk(self._pass_type_resolution) @@ -101,6 +105,14 @@ class MainTransformer(object): # Private + def _add_standalone_doc_sections(self): + for block_name, block in self._blocks.items(): + if block_name.startswith("SECTION:") and block.description: + node = ast.DocSection(block_name[8:]) + node.doc = block.description + node.doc_position = block.position + self._namespace.append(node) + def _pass_fixup_hidden_fields(self, node, chain): """Hide all callbacks starting with _; the typical usage is void (*_gtk_reserved1)(void);""" @@ -240,7 +252,9 @@ class MainTransformer(object): self._apply_annotations_field(node, block, field) name = self._get_annotation_name(node) section_name = 'SECTION:%s' % (name.lower(), ) - block = self._blocks.get(section_name) + # We pop it from our blocks so that we can serialize leftover + # SECTIONs as standalone nodes + block = self._blocks.pop(section_name, None) self._apply_annotations_annotated(node, block) if isinstance(node, (ast.Class, ast.Interface)): for prop in node.properties: @@ -858,19 +872,28 @@ class MainTransformer(object): self._apply_annotations_params(node, node.parameters, block) self._apply_annotations_return(node, node.retval, block) - def _apply_annotations_field(self, parent, block, field): - if not block: - return - tag = block.params.get(field.name) - if not tag: + def _apply_annotations_field(self, parent, parent_block, field): + block = self._blocks.get('%s.%s' % (self._get_annotation_name(parent), field.name)) + + # Prioritize block level documentation + if block: + self._apply_annotations_annotated(field, block) + annotations = block.annotations + elif not parent_block: return - type_annotation = tag.annotations.get(ANN_TYPE) + else: + tag = parent_block.params.get(field.name) + if not tag: + return + annotations = tag.annotations + field.doc = tag.description + field.doc_position = tag.position + + type_annotation = annotations.get(ANN_TYPE) if type_annotation: field.type = self._transformer.create_type_from_user_string(type_annotation[0]) - field.doc = tag.description - field.doc_position = tag.position try: - self._adjust_container_type(parent, field, tag.annotations) + self._adjust_container_type(parent, field, annotations) except AttributeError as ex: print(ex) @@ -938,15 +961,21 @@ class MainTransformer(object): if value_annotation: node.value = value_annotation[0] - def _apply_annotations_enum_members(self, node, block): - if block is None: - return - + def _apply_annotations_enum_members(self, node, parent_block): for m in node.members: - param = block.params.get(m.symbol, None) - if param and param.description: - m.doc = param.description - m.doc_position = param.position + block = self._blocks.get(m.symbol) + # Prioritize block-level documentation + if block: + self._apply_annotations_annotated(m, block) + elif parent_block: + param = parent_block.params.get(m.symbol) + + if not param: + continue + + if param.description: + m.doc = param.description + m.doc_position = param.position def _pass_read_annotations2(self, node, chain): if isinstance(node, ast.Function): |