Implement "rename to" annotation for records
authorJon Nordby <jononor@gmail.com>
Sat, 23 Jun 2012 11:59:12 +0000 (13:59 +0200)
committerJon Nordby <jononor@gmail.com>
Fri, 27 Jul 2012 19:36:36 +0000 (21:36 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=675985
Moving the early annotation pass is needed to avoid
the first type resolve pass to resolve to the not-renamed type.

giscanner/maintransformer.py

index 77a66d21fdd1b3730e74547efe3312cc34d3d72f..eb6b8b3878a22d07a7deb388c6e5b83d98de7925 100644 (file)
@@ -60,14 +60,14 @@ class MainTransformer(object):
         # Some initial namespace surgery
         self._namespace.walk(self._pass_fixup_hidden_fields)
 
+        # Read in annotations needed early
+        self._namespace.walk(self._pass_read_annotations_early)
+
         # We have a rough tree which should have most of of the types
         # we know about.  Let's attempt closure; walk over all of the
         # Type() types and see if they match up with something.
         self._namespace.walk(self._pass_type_resolution)
 
-        # Read in annotations needed early
-        self._namespace.walk(self._pass_read_annotations_early)
-
         # Determine some default values for transfer etc.
         # based on the current tree.
         self._namespace.walk(self._pass_callable_defaults)
@@ -139,7 +139,16 @@ usage is void (*_gtk_reserved1)(void);"""
 
         return param.argname
 
-    def _apply_annotation_rename_to(self, node, chain, block):
+    def _apply_annotation_rename_to_record(self, node, chain, block):
+        if not block:
+            return
+        rename_to = block.get_tag(TAG_RENAME_TO)
+        if not rename_to:
+            return
+
+        node.name = rename_to.value
+
+    def _apply_annotation_rename_to_function(self, node, chain, block):
         if not block:
             return
         rename_to = block.get_tag(TAG_RENAME_TO)
@@ -177,6 +186,7 @@ usage is void (*_gtk_reserved1)(void);"""
                 block = self._blocks.get(node.ctype)
             else:
                 block = self._blocks.get(node.c_name)
+            self._apply_annotation_rename_to_record(node, chain, block)
             self._apply_annotations_annotated(node, block)
         return True
 
@@ -828,7 +838,7 @@ usage is void (*_gtk_reserved1)(void);"""
     def _apply_annotations2_function(self, node, chain):
         block = self._blocks.get(node.symbol)
 
-        self._apply_annotation_rename_to(node, chain, block)
+        self._apply_annotation_rename_to_function(node, chain, block)
 
         # Handle virtual invokers
         parent = chain[-1] if chain else None