gobject-introspection r268 - in trunk: . giscanner tools
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: gobject-introspection r268 - in trunk: . giscanner tools
- Date: Fri, 9 May 2008 00:37:09 +0100 (BST)
Author: johan
Date: Thu May 8 23:37:09 2008
New Revision: 268
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=268&view=rev
Log:
2008-05-08 Johan Dahlin <johan gnome org>
* giscanner/ast.py:
* giscanner/girwriter.py:
* giscanner/glibtransformer.py:
* giscanner/transformer.py:
* tools/g-ir-scanner:
Introduce a namespace ast node
Modified:
trunk/ChangeLog
trunk/giscanner/ast.py
trunk/giscanner/girwriter.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 Thu May 8 23:37:09 2008
@@ -78,6 +78,12 @@
self.name = name
+class Namespace(Node):
+ def __init__(self, name):
+ Node.__init__(self, name)
+ self.nodes = []
+
+
class Function(Node):
def __init__(self, name, retval, parameters, symbol):
Node.__init__(self, name)
Modified: trunk/giscanner/girwriter.py
==============================================================================
--- trunk/giscanner/girwriter.py (original)
+++ trunk/giscanner/girwriter.py Thu May 8 23:37:09 2008
@@ -28,11 +28,11 @@
class GIRWriter(XMLWriter):
- def __init__(self, namespace, nodes):
+ def __init__(self, namespace):
super(GIRWriter, self).__init__()
- self._write_repository(namespace, nodes)
+ self._write_repository(namespace)
- def _write_repository(self, namespace, nodes):
+ def _write_repository(self, namespace):
attrs = [
('version', '1.0'),
('xmlns', 'http://www.gtk.org/introspection/core/1.0'),
@@ -40,11 +40,12 @@
('xmlns:glib', 'http://www.gtk.org/introspection/glib/1.0'),
]
with self.tagcontext('repository', attrs):
- self._write_namespace(namespace, nodes)
+ self._write_namespace(namespace)
- def _write_namespace(self, namespace, nodes):
- with self.tagcontext('namespace', [('name', namespace)]):
- for node in nodes:
+ def _write_namespace(self, namespace):
+ attrs = [('name', namespace.name)]
+ with self.tagcontext('namespace', attrs):
+ for node in namespace.nodes:
self._write_node(node)
def _write_node(self, node):
Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py (original)
+++ trunk/giscanner/glibtransformer.py Thu May 8 23:37:09 2008
@@ -24,8 +24,8 @@
from . import cgobject
from .odict import odict
-from .ast import (Callback, Enum, Function, Parameter, Property, Return,
- Sequence, Struct, Type)
+from .ast import (Callback, Enum, Function, Namespace, Parameter, Property,
+ Return, Sequence, Struct, Type)
from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember, GLibFlags,
GLibInterface, GLibObject, GLibSignal)
@@ -55,24 +55,22 @@
class GLibTransformer(object):
- def __init__(self, namespace_name):
- self._namespace_name = namespace_name
+ def __init__(self):
+ self._namespace_name = None
self._output_ns = odict()
self._library = None
self._type_names = {}
# Public API
- def get_nodes(self):
- return self._output_ns.values()
-
def load_library(self, libname):
if libname.endswith('.la'):
libname = resolve_libtool(libname)
self._library = ctypes.cdll.LoadLibrary(libname)
- def parse(self, nodes):
- for node in nodes:
+ def parse(self, namespace):
+ self._namespace_name = namespace.name
+ for node in namespace.nodes:
self._parse_node(node)
# Second round
@@ -81,6 +79,10 @@
if isinstance(node, Struct):
self._pair_class_struct(node)
+ namespace = Namespace(namespace.name)
+ namespace.nodes = self._output_ns.values()
+ return namespace
+
def register_include(self, filename):
if filename.endswith('.gir'):
from .girparser import GIRParser
Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py (original)
+++ trunk/giscanner/transformer.py Thu May 8 23:37:09 2008
@@ -18,8 +18,8 @@
# 02110-1301, USA.
#
-from giscanner.ast import (Callback, Enum, Function, Member, Parameter,
- Return, Sequence, Struct, Type)
+from giscanner.ast import (Callback, Enum, Function, Namespace, Member,
+ Parameter, Return, Sequence, Struct, Type)
from giscanner.sourcescanner import (
SourceSymbol, symbol_type_name, CTYPE_POINTER, CTYPE_TYPEDEF, CTYPE_VOID,
CTYPE_BASIC_TYPE, CTYPE_FUNCTION, CTYPE_STRUCT, CSYMBOL_TYPE_FUNCTION,
@@ -28,9 +28,9 @@
class Transformer(object):
- def __init__(self, generator):
+ def __init__(self, generator, namespace_name):
self.generator = generator
- self.nodes = []
+ self._namespace = Namespace(namespace_name)
self._output_ns = {}
self._typedefs_ns = {}
self._strip_prefix = ''
@@ -38,19 +38,17 @@
def set_strip_prefix(self, strip_prefix):
self._strip_prefix = strip_prefix
- def get_nodes(self):
- for node in self.nodes:
- yield node
-
def parse(self):
+ nodes = []
for symbol in self.generator.get_symbols():
node = self._traverse_one(symbol)
if node is None:
continue
if node.name.startswith('_'):
continue
- self.nodes.append(node)
+ self._namespace.nodes.append(node)
self._output_ns[node.name] = node
+ return self._namespace
def _remove_prefix(self, name):
# when --strip-prefix=g:
Modified: trunk/tools/g-ir-scanner
==============================================================================
--- trunk/tools/g-ir-scanner (original)
+++ trunk/tools/g-ir-scanner Thu May 8 23:37:09 2008
@@ -42,8 +42,8 @@
action="store", dest="library",
help="library of this unit")
parser.add_option("-n", "--namespace",
- action="store", dest="namespace",
- help="namespace of this unit")
+ action="store", dest="namespace_name",
+ help="name of namespace for this unit")
parser.add_option("", "--strip-prefix",
action="store", dest="strip_prefix", default="",
help="prefix to strip from functions, like g_")
@@ -82,8 +82,8 @@
if len(args) <= 1:
_error('Need at least one filename')
- if not options.namespace:
- _error('Namespace missing')
+ if not options.namespace_name:
+ _error('Namespace name missing')
if options.format == 'gir':
from giscanner.girwriter import GIRWriter as Writer
@@ -117,23 +117,22 @@
ss.parse_macros()
# Transform the C symbols into AST nodes
- transformer = Transformer(ss)
+ transformer = Transformer(ss, options.namespace_name)
transformer.set_strip_prefix(options.strip_prefix)
# Transform the C AST nodes into higher level
# GLib/GObject nodes
- glibtransformer = GLibTransformer(options.namespace)
+ glibtransformer = GLibTransformer()
if options.library:
glibtransformer.load_library(options.library)
for include in options.includes:
glibtransformer.register_include(include)
- transformer.parse()
- nodes = transformer.get_nodes()
- glibtransformer.parse(nodes)
+ namespace = transformer.parse()
+ namespace = glibtransformer.parse(namespace)
# Write out AST
- writer = Writer(options.namespace, glibtransformer.get_nodes())
+ writer = Writer(namespace)
data = writer.get_xml()
if options.output:
fd = open(options.output, "w")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]