[gobject-introspection/wip/transformer: 14/16] [major] A few tweaks



commit 0fb1e9d2e47dd351ca49d76638089e0c613c6e9b
Author: Colin Walters <walters verbum org>
Date:   Thu Aug 12 08:05:57 2010 -0400

    [major] A few tweaks

 giscanner/ast.py                          |   21 ++++++++++++++++++---
 giscanner/primarytransformer.py           |   11 ++++++++++-
 tests/scanner/Annotation-1.0-expected.gir |   10 ++++------
 tests/scanner/annotation.c                |    7 ++++++-
 4 files changed, 38 insertions(+), 11 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 10bb41a..67af8db 100755
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -50,6 +50,10 @@ In this case, the ctype must be specified.
         elif target_fundamental:
             assert target_giname is None
             assert target_foreign is None
+        if block:
+            rename_to = block.get(TAG_RENAME_TO)
+            if rename_to:
+                for 
         elif target_giname:
             assert '.' in target_giname
             assert target_fundamental is None
@@ -272,6 +276,7 @@ class Namespace(object):
         self._aliases = {} # Maps from GIName -> GIName
         self._type_names = {} # Maps from GTName -> node
         self._ctypes = {} # Maps from CType -> node
+        self._symbols = {} # Maps from function symbols -> Function
 
     def type_from_name(self, name, ctype=None):
         """Backwards compatibility method for older .gir files, which
@@ -308,14 +313,14 @@ identifier string."""
             self._aliases[node.name] = node
         elif isinstance(node, (GLibBoxed, Interface, Class)):
             self._type_names[node.type_name] = node
+        elif isinstance(node, Function):
+            self._symbols[node.symbol] = node
         assert isinstance(node, Node)
         assert node.namespace is None
         node.namespace = self
         self._names[node.name] = node
         if hasattr(node, 'ctype'):
             self._ctypes[node.ctype] = node
-        elif hasattr(node, 'symbol'):
-            self._ctypes[node.symbol] = node
 
     def remove(self, node):
         from .glibast import GLibBoxed
@@ -329,11 +334,16 @@ identifier string."""
             del self._ctypes[node.ctype]
         if hasattr(node, 'symbol'):
             del self._ctypes[node.symbol]
+        if isinstance(node, Function):
+            del self._symbols[node.symbol]
 
     def float(self, node):
         """Like remove(), but doesn't unset the node's namespace
-back-reference."""
+back-reference, and it's still possible to look up functions via get_by_symbol()."""
+        if isinstance(node, Function):
+            symbol = node.symbol
         self.remove(node)
+        self._symbols[symbol] = node
         node.namespace = self
 
     def __iter__(self):
@@ -351,6 +361,9 @@ back-reference."""
     def get_by_ctype(self, ctype):
         return self._ctypes.get(ctype)
 
+    def get_by_symbol(self, symbol):
+        return self._symbols.get(symbol)
+
     def walk(self, callback):
         for node in self.itervalues():
             node.walk(callback, [])
@@ -477,6 +490,8 @@ class Function(Callable):
         self.symbol = symbol
         self.is_method = False
         self.is_constructor = False
+        self.shadowed_by = None # C symbol string
+        self.shadows = None # C symbol string
 
     def get_parameter_index(self, name):
         for i, parameter in enumerate(self.parameters):
diff --git a/giscanner/primarytransformer.py b/giscanner/primarytransformer.py
index 3872a8f..d7fd346 100644
--- a/giscanner/primarytransformer.py
+++ b/giscanner/primarytransformer.py
@@ -132,6 +132,15 @@ class PrimaryTransformer(object):
     def _apply_annotations_function(self, node, chain):
         block = self._blocks.get(node.symbol)
         self._apply_annotations_callable(node, chain, block)
+        if block:
+            rename_to = block.get(TAG_RENAME_TO)
+            if rename_to:
+                target = self._namespace.get_by_symbol(rename_to):
+                if not target:
+                    self._transformer.log_node_warning(node,
+                        "Can't find symbol %r referenced by Rename annotation" % (target, ))
+                else:
+                    
 
     def _pass_callable_defaults(self, node, chain):
         if isinstance(node, (Callable, GLibSignal)):
@@ -243,7 +252,7 @@ class PrimaryTransformer(object):
         element_type = options.get(OPT_ELEMENT_TYPE)
         if element_type is not None:
             element_type_node = self._resolve(element_type.one())
-        if isinstance(node.type, Array):
+        elif isinstance(node.type, Array):
             element_type_node = node.type.element_type
         else:
             # We're assuming here that Foo* with an (array) annotation
diff --git a/tests/scanner/Annotation-1.0-expected.gir b/tests/scanner/Annotation-1.0-expected.gir
index fc81134..b4501ce 100644
--- a/tests/scanner/Annotation-1.0-expected.gir
+++ b/tests/scanner/Annotation-1.0-expected.gir
@@ -216,7 +216,7 @@ and/or use gtk-doc annotations.  -->
           <parameter name="func"
                      transfer-ownership="none"
                      scope="call"
-                     closure="2">
+                     closure="1">
             <doc xml:whitespace="preserve">Callback to invoke</doc>
             <type name="ForeachFunc" c:type="AnnotationForeachFunc"/>
           </parameter>
@@ -449,9 +449,7 @@ type.</doc>
         </return-value>
         <parameters>
           <parameter name="bytes" transfer-ownership="none">
-            <array c:type="guchar*">
-              <type name="guint8"/>
-            </array>
+            <type name="guint8" c:type="guchar*"/>
           </parameter>
         </parameters>
       </method>
@@ -464,8 +462,8 @@ type.</doc>
           <parameter name="func"
                      transfer-ownership="none"
                      scope="notified"
-                     closure="2"
-                     destroy="3">
+                     closure="1"
+                     destroy="2">
             <doc xml:whitespace="preserve">The callback</doc>
             <type name="ForeachFunc" c:type="AnnotationForeachFunc"/>
           </parameter>
diff --git a/tests/scanner/annotation.c b/tests/scanner/annotation.c
index 8d39d85..397a1c5 100644
--- a/tests/scanner/annotation.c
+++ b/tests/scanner/annotation.c
@@ -382,6 +382,11 @@ annotation_object_create_object (AnnotationObject *object)
 	return g_object_ref (object);
 }
 
+/**
+ * annotation_object_use_buffer:
+ * @object: a #GObject
+ *
+ **/
 void
 annotation_object_use_buffer   (AnnotationObject *object,
 				guchar           *bytes)
@@ -504,7 +509,7 @@ annotation_object_set_data (AnnotationObject *object,
 /**
  * annotation_object_set_data2:
  * @object: a #AnnotationObject
- * @data: (array length=length): The data
+ * @data: (array length=length) (element-type gint8): The data
  * @length: Length of the data
  *
  * Test taking a gchar * with a length.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]