[gobject-introspection/wip/transformer: 18/18] scanner: Better handling of empty namespace prefix for X



commit 432b86c63efcb43eb91e47ee44656cfb5fb6eb78
Author: Colin Walters <walters verbum org>
Date:   Wed Aug 25 14:19:29 2010 -0400

    scanner: Better handling of empty namespace prefix for X
    
    Add namespacing prefixes to the static .gir files.  Support the empty
    prefix, as is needed for xlib.

 gir/DBus-1.0.gir                |    4 ++-
 gir/DBusGLib-1.0.gir            |    4 ++-
 gir/GL-1.0.gir                  |    4 ++-
 gir/cairo-1.0.gir               |    3 +-
 gir/fontconfig-2.0.gir          |    4 ++-
 gir/freetype2-2.0.gir           |    4 ++-
 gir/libxml2-2.0.gir             |    4 ++-
 gir/xfixes-4.0.gir              |    4 ++-
 gir/xft-2.0.gir                 |    5 +++-
 gir/xlib-2.0.gir                |    4 ++-
 gir/xrandr-1.3.gir              |    4 ++-
 giscanner/ast.py                |    4 +-
 giscanner/primarytransformer.py |   23 +++++++++++--------
 giscanner/scannermain.py        |   16 ++++++++++++-
 giscanner/transformer.py        |   45 +++++++++++++++++++++++---------------
 15 files changed, 89 insertions(+), 43 deletions(-)
---
diff --git a/gir/DBus-1.0.gir b/gir/DBus-1.0.gir
index 5eab4ce..4ce0309 100644
--- a/gir/DBus-1.0.gir
+++ b/gir/DBus-1.0.gir
@@ -2,7 +2,9 @@
 <repository version="1.2"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";
-            xmlns:glib="http://www.gtk.org/introspection/glib/1.0";>
+            xmlns:glib="http://www.gtk.org/introspection/glib/1.0";
+	    c:identifier-prefixes="DBus"
+	    c:symbol-prefixes="DBus">
   <package name="dbus-1"/>
   <namespace name="DBus"
              version="1.0"
diff --git a/gir/DBusGLib-1.0.gir b/gir/DBusGLib-1.0.gir
index b9ba132..ff61931 100644
--- a/gir/DBusGLib-1.0.gir
+++ b/gir/DBusGLib-1.0.gir
@@ -2,7 +2,9 @@
 <repository version="1.2"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";
-	    xmlns:glib="http://www.gtk.org/introspection/glib/1.0";>
+	    xmlns:glib="http://www.gtk.org/introspection/glib/1.0";
+	    c:identifier-prefixes="DBus"
+	    c:symbol-prefixes="DBus">
   <include name="GObject" version="2.0"/>
   <package name="dbus-glib-1"/>
   <namespace name="DBusGLib" version="1.0" c:prefix="DBusG">
diff --git a/gir/GL-1.0.gir b/gir/GL-1.0.gir
index cf07454..f93100a 100644
--- a/gir/GL-1.0.gir
+++ b/gir/GL-1.0.gir
@@ -2,7 +2,9 @@
 <repository version="1.2"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";>
-  <namespace name="GL" version="1.0">
+  <namespace name="GL" version="1.0"
+	     c:identifier-prefixes="GL"
+	     c:symbol-prefixes="gl">
     <record name="bitfield" c:type="GLbitfield"/>
     <record name="charARB" c:type="GLcharARB"/>
     <record name="clampf" c:type="GLclampf"/>
diff --git a/gir/cairo-1.0.gir b/gir/cairo-1.0.gir
index 05f1a78..dbec19d 100644
--- a/gir/cairo-1.0.gir
+++ b/gir/cairo-1.0.gir
@@ -4,7 +4,8 @@
             xmlns:c="http://www.gtk.org/introspection/c/1.0";
             xmlns:glib="http://www.gtk.org/introspection/glib/1.0";>
   <namespace name="cairo" version="1.0"
-	     c:prefix="cairo">
+	     c:identifier-prefixes="cairo"
+	     c:symbol-prefixes="cairo">
     <record name="Context" c:type="cairo_t" foreign="1"/>
     <record name="Surface" c:type="cairo_surface_t" foreign="1"/>
     <record name="Matrix" c:type="cairo_matrix_t" foreign="1"/>
diff --git a/gir/fontconfig-2.0.gir b/gir/fontconfig-2.0.gir
index 192d720..e7ecd51 100644
--- a/gir/fontconfig-2.0.gir
+++ b/gir/fontconfig-2.0.gir
@@ -2,7 +2,9 @@
 <repository version="1.2"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";>
-  <namespace name="fontconfig" version="2.0">
+  <namespace name="fontconfig" version="2.0"
+	     c:identifier-prefixes="Fc"
+	     c:symbol-prefixes="fc">
     <record name="Pattern" c:type="FcPattern"/>
     <record name="CharSet" c:type="FcCharSet"/>
     <function name="init" c:identifier="FcInit">
diff --git a/gir/freetype2-2.0.gir b/gir/freetype2-2.0.gir
index 495726a..ac74dc8 100644
--- a/gir/freetype2-2.0.gir
+++ b/gir/freetype2-2.0.gir
@@ -2,7 +2,9 @@
 <repository version="1.2"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";>
-  <namespace name="freetype2" version="2.0">
+  <namespace name="freetype2" version="2.0"
+	     c:identifier-prefixes="FT"
+	     c:symbol-prefixes="FT">
     <record name="Bitmap" c:type="FT_Bitmap"/>
     <record name="Face" c:type="FT_Face"/>
     <record name="Library" c:type="FT_Library"/>
diff --git a/gir/libxml2-2.0.gir b/gir/libxml2-2.0.gir
index cd962d0..34aeadc 100644
--- a/gir/libxml2-2.0.gir
+++ b/gir/libxml2-2.0.gir
@@ -2,7 +2,9 @@
 <repository version="1.2"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";>
-  <namespace name="libxml2" version="2.0">
+  <namespace name="libxml2" version="2.0"
+	     c:identifier-prefixes="xml"
+	     c:symbol-prefixes="xml">
     <record name="Node" c:type="xmlNode"/>
     <record name="NodePtr" c:type="xmlNodePtr"/>
     <record name="Doc" c:type="xmlDoc"/>
diff --git a/gir/xfixes-4.0.gir b/gir/xfixes-4.0.gir
index 7a0fa18..2ffe968 100644
--- a/gir/xfixes-4.0.gir
+++ b/gir/xfixes-4.0.gir
@@ -2,7 +2,9 @@
 <repository version="1.2"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";>
-  <namespace name="xfixes" version="4.0">
+  <namespace name="xfixes" version="4.0"
+	     c:identifier-prefixes="X"
+	     c:symbol-prefixes="X">
     <record name="XserverRegion" c:type="XserverRegion"/>
   </namespace>
 </repository>
diff --git a/gir/xft-2.0.gir b/gir/xft-2.0.gir
index 1117847..83e1e84 100644
--- a/gir/xft-2.0.gir
+++ b/gir/xft-2.0.gir
@@ -2,7 +2,10 @@
 <repository version="1.2"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";>
-  <namespace name="xft" version="2.0">
+  <include name="xlib" version="2.0"/>
+  <namespace name="xft" version="2.0"
+	     c:identifier-prefixes="Xft"
+	     c:symbol-prefixes="Xft">
     <record name="Color" c:type="XftColor"/>
     <record name="Draw" c:type="XftDraw"/>
     <record name="Font" c:type="XftFont"/>
diff --git a/gir/xlib-2.0.gir b/gir/xlib-2.0.gir
index 1081652..95cdc74 100644
--- a/gir/xlib-2.0.gir
+++ b/gir/xlib-2.0.gir
@@ -2,7 +2,9 @@
 <repository version="1.2"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";>
-  <namespace name="xlib" version="2.0">
+  <namespace name="xlib" version="2.0"
+	     c:identifier-prefixes=""
+	     c:symbol-prefixes="X">
     <record name="Atom" c:type="Atom"/>
     <record name="Colormap" c:type="Colormap"/>
     <record name="Cursor" c:type="Cursor"/>
diff --git a/gir/xrandr-1.3.gir b/gir/xrandr-1.3.gir
index d8844da..2e62e98 100644
--- a/gir/xrandr-1.3.gir
+++ b/gir/xrandr-1.3.gir
@@ -2,7 +2,9 @@
 <repository version="1.2"
             xmlns="http://www.gtk.org/introspection/core/1.0";
             xmlns:c="http://www.gtk.org/introspection/c/1.0";>
-  <namespace name="xrandr" version="1.3">
+  <namespace name="xrandr" version="1.3"
+	     c:identifier-prefixes="XRR"
+	     c:symbol-prefixes="XRR">
     <record name="ScreenSize" c:type="XRRScreenSize"/>
     <record name="ScreenChangeNotifyEvent" c:type="XRRScreenChangeNotifyEvent"/>
     <record name="NotifyEvent" c:type="XRRNotifyEvent"/>
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 501b439..ac60e44 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -270,11 +270,11 @@ class Namespace(object):
                  symbol_prefixes=None):
         self.name = name
         self.version = version
-        if identifier_prefixes:
+        if identifier_prefixes is not None:
             self.identifier_prefixes = identifier_prefixes
         else:
             self.identifier_prefixes = [name]
-        if symbol_prefixes:
+        if symbol_prefixes is not None:
             self.symbol_prefixes = symbol_prefixes
         else:
             ps = self.identifier_prefixes
diff --git a/giscanner/primarytransformer.py b/giscanner/primarytransformer.py
index d26851d..d542ef6 100644
--- a/giscanner/primarytransformer.py
+++ b/giscanner/primarytransformer.py
@@ -96,7 +96,7 @@ class PrimaryTransformer(object):
         assert supercls
         if cls is supercls:
             return True
-        if cls.parent:
+        if cls.parent and (not cls.parent.target_giname == 'GObject.Object'):
             return self._is_gi_subclass(cls.parent, supercls_type)
         return False
 
@@ -624,15 +624,18 @@ class PrimaryTransformer(object):
                     self._transformer.resolve_type(field.type)
         if isinstance(node, (ast.Class, ast.Interface)):
             resolved_parent = None
-            for parent in node.parent_chain:
-                try:
-                    self._transformer.resolve_type(parent)
-                except ValueError, e:
-                    continue
-                target = self._transformer.lookup_typenode(parent)
-                if target:
-                    node.parent = parent
-                    break
+            if node.parent_chain:
+                for parent in node.parent_chain:
+                    try:
+                        self._transformer.resolve_type(parent)
+                    except ValueError, e:
+                        continue
+                    target = self._transformer.lookup_typenode(parent)
+                    if target:
+                        node.parent = parent
+                        break
+            else:
+                node.parent = ast.Type(target_giname='GObject.Object')
             for prop in node.properties:
                 self._transformer.resolve_type(prop.type)
             for sig in node.signals:
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index daa5a9a..975fa7f 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -260,12 +260,24 @@ def scanner_main(args):
             # against the absolute path that cpp will give us
             filenames.append(os.path.abspath(arg))
 
+    # We do this dance because the empty list has different semantics from
+    # None; if the user didn't specify the options, we want to use None so
+    # the Namespace constructor picks the defaults.
+    if len(options.identifier_prefixes) == 0:
+        identifier_prefixes = None
+    else:
+        identifier_prefixes = options.identifier_prefixes
+    if len(options.symbol_prefixes) == 0:
+        symbol_prefixes = None
+    else:
+        symbol_prefixes = options.symbol_prefixes
+
     cachestore = CacheStore()
     transformer = Transformer(cachestore,
                               options.namespace_name,
                               options.namespace_version,
-                              options.identifier_prefixes,
-                              options.symbol_prefixes)
+                              identifier_prefixes,
+                              symbol_prefixes)
     if options.warn_all:
         transformer.enable_warnings(True)
     transformer.set_include_paths(options.include_paths)
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index f6639a6..90c9b18 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -280,10 +280,14 @@ or raise ValueError.  As a special case, if the current namespace matches,
 it is always biggest (i.e. last)."""
         matches = []
         for ns in self._iter_namespaces():
-            for prefix in ns.identifier_prefixes:
-                if ident.startswith(prefix):
-                    matches.append((ns, ident[len(prefix):], len(prefix)))
-                    break
+            if ns.identifier_prefixes:
+                for prefix in ns.identifier_prefixes:
+                    if ident.startswith(prefix):
+                        matches.append((ns, ident[len(prefix):], len(prefix)))
+                        break
+            else:
+                # A special case for namespaces without a prefix, such as X
+                matches.append((ns, ident, 0))
         if matches:
             matches.sort(self._sort_matches)
             return map(lambda x: (x[0], x[1]), matches)
@@ -767,6 +771,21 @@ both GI type string (utf8, Foo.Bar) style, as well as C (char *, FooBar) style."
         typeval.ctype = None
         return typeval
 
+    def _resolve_type_from_ctype(self, typeval):
+        pointer_stripped = typeval.ctype.replace('*', '')
+        try:
+            matches = self.split_ctype_namespaces(pointer_stripped)
+        except ValueError, e:
+            raise TypeResolutionException(e)
+        target_giname=None
+        for namespace, name in matches:
+            target = namespace.get(name)
+            if not target:
+                target = namespace.get_by_ctype(pointer_stripped)
+            if target:
+                typeval.target_giname='%s.%s' % (namespace.name, target.name)
+                return
+
     def resolve_type(self, typeval):
         if isinstance(typeval, (ast.Array, ast.List)):
             self.resolve_type(typeval.element_type)
@@ -775,20 +794,10 @@ both GI type string (utf8, Foo.Bar) style, as well as C (char *, FooBar) style."
             self.resolve_type(typeval.key_type)
             self.resolve_type(typeval.value_type)
             return
-        elif not typeval.resolved and typeval.ctype:
-            pointer_stripped = typeval.ctype.replace('*', '')
-            try:
-                matches = self.split_ctype_namespaces(pointer_stripped)
-            except ValueError, e:
-                raise TypeResolutionException(e)
-            target_giname=None
-            for namespace, name in matches:
-                target = namespace.get(name)
-                if not target:
-                    target = namespace.get_by_ctype(pointer_stripped)
-                if target:
-                    typeval.target_giname='%s.%s' % (namespace.name, target.name)
-                    return
+        elif typeval.resolved:
+            return
+        elif typeval.ctype:
+            return self._resolve_type_from_ctype(typeval)
 
     def _typepair_to_str(self, item):
         nsname, item = item



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