gobject-introspection r273 - trunk/giscanner



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

Log:
Clean up and refactor enum namespacing

Modified:
   trunk/giscanner/ast.py
   trunk/giscanner/girwriter.py
   trunk/giscanner/glibast.py
   trunk/giscanner/glibtransformer.py
   trunk/giscanner/transformer.py

Modified: trunk/giscanner/ast.py
==============================================================================
--- trunk/giscanner/ast.py	(original)
+++ trunk/giscanner/ast.py	Fri May  9 00:51:07 2008
@@ -125,10 +125,10 @@
 
 
 class Enum(Node):
-    def __init__(self, name, members):
+    def __init__(self, name, symbol, members):
         Node.__init__(self, name)
+        self.symbol = symbol
         self.members = members
-        self.ctype = name
 
     def __repr__(self):
         return 'Enum(%r, %r)' % (self.name, self.members)

Modified: trunk/giscanner/girwriter.py
==============================================================================
--- trunk/giscanner/girwriter.py	(original)
+++ trunk/giscanner/girwriter.py	Fri May  9 00:51:07 2008
@@ -128,7 +128,7 @@
 
     def _write_enum(self, enum):
         attrs = [('name', enum.name),
-                 ('c:type', enum.ctype)]
+                 ('c:type', enum.symbol)]
         tag_name = 'enumeration'
         if isinstance(enum, GLibEnum):
             attrs.extend([('glib:type-name', enum.type_name),

Modified: trunk/giscanner/glibast.py
==============================================================================
--- trunk/giscanner/glibast.py	(original)
+++ trunk/giscanner/glibast.py	Fri May  9 00:51:07 2008
@@ -23,7 +23,7 @@
 
 class GLibEnum(Enum):
     def __init__(self, name, members, type_name, get_type):
-        Enum.__init__(self, name, members)
+        Enum.__init__(self, name, type_name, members)
         self.ctype = type_name
         self.type_name = type_name
         self.get_type = get_type

Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py	(original)
+++ trunk/giscanner/glibtransformer.py	Fri May  9 00:51:07 2008
@@ -104,14 +104,6 @@
     def _register_internal_type(self, type_name, node):
         self._type_names[type_name] = (None, node)
 
-    def _strip_namespace_object(self, name):
-        orig_name = name
-        prefix = self._namespace_name.lower()
-        name = name.lower()
-        if name.startswith(prefix):
-            name = orig_name[len(prefix):]
-        return name
-
     def _resolve_type_name(self, type_name):
         item = self._type_names.get(type_name)
         if item is not None:
@@ -139,7 +131,6 @@
             print 'GOBJECT BUILDER: Unhandled node:', node
 
     def _parse_enum(self, enum):
-        enum.name = self._strip_namespace_object(enum.name)
         self._add_attribute(enum)
 
     def _parse_function(self, func):
@@ -283,15 +274,15 @@
 
         klass = (GLibFlags if ftype_id == cgobject.TYPE_FLAGS else GLibEnum)
         type_name = cgobject.type_name(type_id)
-        node = klass(self._strip_namespace_object(type_name),
-                      members, type_name, symbol)
+        node = klass(self._transformer.strip_namespace_object(type_name),
+                     members, type_name, symbol)
         self._add_attribute(node, replace=True)
         self._register_internal_type(type_name, node)
 
     def _introspect_object(self, type_id, symbol):
         type_name = cgobject.type_name(type_id)
         parent_type_name = cgobject.type_name(cgobject.type_parent(type_id))
-        node = GLibObject(self._strip_namespace_object(type_name),
+        node = GLibObject(self._transformer.strip_namespace_object(type_name),
                           self._resolve_type_name(parent_type_name),
                           type_name, symbol)
         self._introspect_properties(node, type_id)
@@ -302,8 +293,9 @@
 
     def _introspect_interface(self, type_id, symbol):
         type_name = cgobject.type_name(type_id)
-        node = GLibInterface(self._strip_namespace_object(type_name),
-                             type_name, symbol)
+        node = GLibInterface(
+            self._transformer.strip_namespace_object(type_name),
+            type_name, symbol)
         self._introspect_properties(node, type_id)
         self._introspect_signals(node, type_id)
         self._add_attribute(node)
@@ -311,7 +303,7 @@
 
     def _introspect_boxed(self, type_id, symbol):
         type_name = cgobject.type_name(type_id)
-        node = GLibBoxed(self._strip_namespace_object(type_name),
+        node = GLibBoxed(self._transformer.strip_namespace_object(type_name),
                          type_name, symbol)
         self._add_attribute(node)
         self._remove_attribute(type_name)

Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py	(original)
+++ trunk/giscanner/transformer.py	Fri May  9 00:51:07 2008
@@ -67,6 +67,16 @@
         for node in parser.get_nodes():
             self._type_names[node.type_name] = (nsname, node)
 
+    def strip_namespace_object(self, name):
+        orig_name = name
+        prefix = self._namespace.name.lower()
+        name = name.lower()
+        if name.startswith(prefix):
+            name = orig_name[len(prefix):]
+        return name
+
+    # Private
+
     def _strip_namespace_func(self, name):
         orig_name = name
         prefix = self._namespace.name.lower() + '_'
@@ -126,7 +136,8 @@
             members.append(Member(child.ident,
                                   child.const_int))
 
-        return Enum(symbol.ident, members)
+        name = self.strip_namespace_object(symbol.ident)
+        return Enum(name, symbol.ident, members)
 
     def _create_object(self, symbol):
         return Member(symbol.ident, symbol.base_type.name)



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