gobject-introspection r271 - in trunk: giscanner tools



Author: johan
Date: Fri May  9 00:08:26 2008
New Revision: 271
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=271&view=rev

Log:
Move part of the namespace prefix parsing from glibtransformer->transformer

Modified:
   trunk/giscanner/ast.py
   trunk/giscanner/glibtransformer.py
   trunk/giscanner/transformer.py
   trunk/tools/g-ir-scanner

Modified: trunk/giscanner/ast.py
==============================================================================
--- trunk/giscanner/ast.py	(original)
+++ trunk/giscanner/ast.py	Fri May  9 00:08:26 2008
@@ -151,9 +151,9 @@
 
 
 class Return(Node):
-    def __init__(self, type_name):
+    def __init__(self, rtype):
         Node.__init__(self)
-        self.type = Type(type_name)
+        self.type = rtype
         self.transfer = False
 
     def __repr__(self):

Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py	(original)
+++ trunk/giscanner/glibtransformer.py	Fri May  9 00:08:26 2008
@@ -55,7 +55,8 @@
 
 
 class GLibTransformer(object):
-    def __init__(self):
+    def __init__(self, transformer):
+        self._transformer = transformer
         self._namespace_name = None
         self._output_ns = odict()
         self._library = None
@@ -68,8 +69,11 @@
             libname = resolve_libtool(libname)
         self._library = ctypes.cdll.LoadLibrary(libname)
 
-    def parse(self, namespace):
+    def parse(self):
+        namespace = self._transformer.parse()
         self._namespace_name = namespace.name
+        self._type_names = self._transformer.get_type_names()
+
         for node in namespace.nodes:
             self._parse_node(node)
 
@@ -83,19 +87,6 @@
         namespace.nodes = self._output_ns.values()
         return namespace
 
-    def register_include(self, filename):
-        if filename.endswith('.gir'):
-            from .girparser import GIRParser
-            parser = GIRParser(filename)
-        elif filename.endswith('.gidl'):
-            from .gidlparser import GIDLParser
-            parser = GIDLParser(filename)
-        else:
-            raise NotImplementedError(filename)
-        nsname = parser.get_namespace_name()
-        for node in parser.get_nodes():
-            self._type_names[node.type_name] = (nsname, node)
-
     # Private
 
     def _add_attribute(self, node, replace=False):
@@ -168,7 +159,6 @@
             return
 
         self._parse_parameters(func.parameters)
-        func.retval.type = self._resolve_param_type(func.retval.type)
 
         func.name = self._strip_namespace_func(func.name)
         self._add_attribute(func)
@@ -245,8 +235,7 @@
         return True
 
     def _parse_struct(self, struct):
-        type_name = self._resolve_type_name(struct.name)
-        node = self._output_ns.get(type_name)
+        node = self._output_ns.get(struct.name)
         if node is None:
             self._add_attribute(struct, replace=True)
             return
@@ -355,7 +344,8 @@
 
     def _introspect_signals(self, node, type_id):
         for signal_info in cgobject.signal_list(type_id):
-            return_ = Return(cgobject.type_name(signal_info.return_type))
+            rtype = Type(cgobject.type_name(signal_info.return_type))
+            return_ = Return(rtype)
             signal = GLibSignal(signal_info.signal_name, return_)
             for i, parameter in enumerate(signal_info.get_params()):
                 if i == 0:

Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py	(original)
+++ trunk/giscanner/transformer.py	Fri May  9 00:08:26 2008
@@ -32,9 +32,13 @@
         self.generator = generator
         self._namespace = Namespace(namespace_name)
         self._output_ns = {}
+        self._type_names = {}
         self._typedefs_ns = {}
         self._strip_prefix = ''
 
+    def get_type_names(self):
+        return self._type_names
+
     def set_strip_prefix(self, strip_prefix):
         self._strip_prefix = strip_prefix
 
@@ -50,6 +54,19 @@
             self._output_ns[node.name] = node
         return self._namespace
 
+    def register_include(self, filename):
+        if filename.endswith('.gir'):
+            from .girparser import GIRParser
+            parser = GIRParser(filename)
+        elif filename.endswith('.gidl'):
+            from .gidlparser import GIDLParser
+            parser = GIDLParser(filename)
+        else:
+            raise NotImplementedError(filename)
+        nsname = parser.get_namespace_name()
+        for node in parser.get_nodes():
+            self._type_names[node.type_name] = (nsname, node)
+
     def _remove_prefix(self, name):
         # when --strip-prefix=g:
         #   GHashTable -> HashTable
@@ -112,6 +129,7 @@
         return_ = self._create_return(symbol.base_type.base_type,
                                       directives.get('return', []))
         name = self._remove_prefix(symbol.ident)
+
         return Function(name, return_, parameters, symbol.ident)
 
     def _create_source_type(self, source_type):
@@ -161,15 +179,16 @@
     def _create_return(self, source_type, options=None):
         if not options:
             options = []
-        return_type = self._create_source_type(source_type)
-        return_ = Return(return_type)
+        rtype = Type(self._create_source_type(source_type))
+        rtype = self._resolve_param_type(rtype)
+        return_ = Return(rtype)
         for option in options:
             if option == 'caller-owns':
                 return_.transfer = True
             elif option.startswith('seq '):
                 value, element_options = option[3:].split(None, 2)
                 element_type = self._parse_type_annotation(value)
-                seq = Sequence(return_type, element_type)
+                seq = Sequence(rtype.name, element_type)
                 seq.transfer = True
                 return_.type = seq
             else:
@@ -187,12 +206,14 @@
         struct = self._typedefs_ns.get(symbol.ident, None)
         if struct is None:
             name = self._remove_prefix(symbol.ident)
+            name = self._resolve_type_name(name)
             struct = Struct(name, symbol.ident)
 
         for child in symbol.base_type.child_list:
             field = self._traverse_one(child, child.base_type.type)
             if field:
                 struct.fields.append(field)
+
         return struct
 
     def _create_callback(self, symbol):
@@ -205,3 +226,18 @@
             annotation[-1] == "]"):
             return Sequence(self._parse_type_annotation(annotation[1:-1]))
         return annotation
+
+    def _resolve_type_name(self, type_name):
+        item = self._type_names.get(type_name)
+        if item is not None:
+            nsname, item = item
+            if nsname is None:
+                return item.name
+            return '%s.%s' % (nsname, item.name)
+        return type_name
+
+    def _resolve_param_type(self, ptype):
+        type_name = ptype.name
+        ptype.name = self._resolve_type_name(type_name)
+        return ptype
+

Modified: trunk/tools/g-ir-scanner
==============================================================================
--- trunk/tools/g-ir-scanner	(original)
+++ trunk/tools/g-ir-scanner	Fri May  9 00:08:26 2008
@@ -119,17 +119,16 @@
     # Transform the C symbols into AST nodes
     transformer = Transformer(ss, options.namespace_name)
     transformer.set_strip_prefix(options.strip_prefix)
+    for include in options.includes:
+        transformer.register_include(include)
 
     # Transform the C AST nodes into higher level
     # GLib/GObject nodes
-    glibtransformer = GLibTransformer()
+    glibtransformer = GLibTransformer(transformer)
     if options.library:
         glibtransformer.load_library(options.library)
-    for include in options.includes:
-        glibtransformer.register_include(include)
 
-    namespace = transformer.parse()
-    namespace = glibtransformer.parse(namespace)
+    namespace = glibtransformer.parse()
 
     # Write out AST
     writer = Writer(namespace)



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