gobject-introspection r255 - in trunk: . giscanner tools



Author: johan
Date: Mon Apr 28 22:14:43 2008
New Revision: 255
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=255&view=rev

Log:
2008-04-28  Johan Dahlin  <jdahlin async com br>

    * giscanner/ast.py:
    * giscanner/glibast.py:
    * giscanner/glibtransformer.py:
    * giscanner/transformer.py:
    * tools/g-ir-scanner:
    Add a --strip-prefix and sort out confusion between names and symbols
    for functions and struct + derivaties.
    Refactor bootstrap of g-ir-scanner, so we can set options on
    Transformer() before parsing everything.



Modified:
   trunk/ChangeLog
   trunk/giscanner/ast.py
   trunk/giscanner/glibast.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	Mon Apr 28 22:14:43 2008
@@ -81,9 +81,10 @@
 
 
 class Struct(Node):
-    def __init__(self, name):
+    def __init__(self, name, symbol):
         Node.__init__(self, name)
         self.fields = []
+        self.symbol = symbol
 
     def __repr__(self):
         return 'Struct(%r)' % (self.name,)

Modified: trunk/giscanner/glibast.py
==============================================================================
--- trunk/giscanner/glibast.py	(original)
+++ trunk/giscanner/glibast.py	Mon Apr 28 22:14:43 2008
@@ -56,11 +56,12 @@
 
 class GLibBoxed(Struct):
     def __init__(self, name, type_name, get_type):
-        Struct.__init__(self, name)
+        Struct.__init__(self, name, get_type)
         self.ctype = name
         self.constructors = []
         self.methods = []
         self.type_name = type_name
+        self.symbol = type_name
         self.get_type = get_type
 
 

Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py	(original)
+++ trunk/giscanner/glibtransformer.py	Mon Apr 28 22:14:43 2008
@@ -178,7 +178,7 @@
 
     def _parse_get_type_function(self, func):
         # GType *_get_type(void)
-        symbol = func.name
+        symbol = func.symbol
         if not symbol.endswith('_get_type'):
             return False
         if func.retval.type.name != 'GType':

Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py	(original)
+++ trunk/giscanner/transformer.py	Mon Apr 28 22:14:43 2008
@@ -29,13 +29,16 @@
         self.nodes = []
         self._output_ns = {}
         self._typedefs_ns = {}
-        self._traverse()
+        self._strip_prefix = ''
+
+    def set_strip_prefix(self, strip_prefix):
+        self._strip_prefix = strip_prefix
 
     def get_nodes(self):
         for node in self.nodes:
             yield node
 
-    def _traverse(self):
+    def parse(self):
         for symbol in self.generator.get_symbols():
             node = self._traverse_one(symbol)
             if node is None:
@@ -45,6 +48,17 @@
             self.nodes.append(node)
             self._output_ns[node.name] = node
 
+    def _remove_prefix(self, name):
+        # when --strip-prefix=g:
+        #   GHashTable -> HashTable
+        #   g_hash_table_new -> hash_table_new
+        if name.lower().startswith(self._strip_prefix.lower()):
+            name = name[len(self._strip_prefix):]
+
+        while name.startswith('_'):
+            name = name[1:]
+        return name
+
     def _traverse_one(self, symbol, stype=None):
         if stype is None:
             stype = symbol.type
@@ -67,6 +81,9 @@
             return self._create_struct(symbol)
         elif stype == giscanner.CSYMBOL_TYPE_ENUM:
             return self._create_enum(symbol)
+        elif stype == giscanner.CSYMBOL_TYPE_UNION:
+            # Unions are not supported
+            pass
         else:
             print 'BUILDER: unhandled symbol', symbol.type
 
@@ -83,7 +100,8 @@
         parameters = list(self._create_parameters(symbol.base_type, directives))
         return_ = self._create_return(symbol.base_type.base_type,
                                       directives.get('return', []))
-        return Function(symbol.ident, return_, parameters, symbol.ident)
+        name = self._remove_prefix(symbol.ident)
+        return Function(name, return_, parameters, symbol.ident)
 
     def _create_source_type(self, source_type):
         if source_type is None:
@@ -148,8 +166,10 @@
         self._typedefs_ns[symbol.base_type.name] = symbol.ident
 
     def _create_struct(self, symbol):
-        name = self._typedefs_ns.get(symbol.ident, symbol.ident)
-        struct = Struct(name)
+        name = self._typedefs_ns.get(symbol.ident, None)
+        if name is None:
+            name = self._remove_prefix(symbol.ident)
+        struct = Struct(name, symbol.ident)
         for child in symbol.base_type.child_list:
             struct.fields.append(self._traverse_one(child,
                                                     child.base_type.type))

Modified: trunk/tools/g-ir-scanner
==============================================================================
--- trunk/tools/g-ir-scanner	(original)
+++ trunk/tools/g-ir-scanner	Mon Apr 28 22:14:43 2008
@@ -44,6 +44,9 @@
     parser.add_option("-n", "--namespace",
                       action="store", dest="namespace",
                       help="namespace of this unit")
+    parser.add_option("", "--strip-prefix",
+                      action="store", dest="strip_prefix", default="",
+                      help="prefix to strip from functions, like g_")
     parser.add_option("-o", "--output",
                       action="store", dest="output",
                       help="output to writeout, defaults to stdout")
@@ -93,19 +96,25 @@
     ss.parse_files(filenames)
     ss.parse_macros()
 
-    builder = GLibTransformer(options.namespace)
+    transformer = Transformer(ss)
+    transformer.set_strip_prefix(options.strip_prefix)
+
+    glibtransformer = GLibTransformer(options.namespace)
     if options.library:
-        builder.load_library(options.library)
+        glibtransformer.load_library(options.library)
     for include in options.includes:
-        builder.register_include(include)
-    builder.parse(Transformer(ss).get_nodes())
+        glibtransformer.register_include(include)
+
+    transformer.parse()
+    nodes = transformer.get_nodes()
+    glibtransformer.parse(nodes)
 
     if options.format == 'gir':
         from giscanner.girwriter import GIRWriter
-        writer = GIRWriter(options.namespace, builder.get_nodes())
+        writer = GIRWriter(options.namespace, glibtransformer.get_nodes())
     elif options.format == 'gidl':
         from giscanner.gidlwriter import GIDLWriter
-        writer = GIDLWriter(options.namespace, builder.get_nodes())
+        writer = GIDLWriter(options.namespace, glibtransformer.get_nodes())
     else:
         raise SystemExit("Unknown format: %s" % (options.format,))
 



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