summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-05-08 23:37:09 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-05-08 23:37:09 +0000
commit870afacec8ba104daef3c1a23e42a3646d547633 (patch)
tree5b3f99b930fcc72fc5aa65c9ae5f26b0ff841fd2
parentb22b5bfb007c4bc6202b7fd901a38869af1d234b (diff)
downloadgobject-introspection-870afacec8ba104daef3c1a23e42a3646d547633.tar.gz
Introduce a namespace ast node
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 svn path=/trunk/; revision=268
-rw-r--r--ChangeLog9
-rw-r--r--giscanner/ast.py6
-rw-r--r--giscanner/girwriter.py15
-rw-r--r--giscanner/glibtransformer.py20
-rw-r--r--giscanner/transformer.py16
-rwxr-xr-xtools/g-ir-scanner19
6 files changed, 50 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index e46e7492..08b707b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+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
+
2008-05-05 Johan Dahlin <johan@gnome.org>
* giscanner/__init__.py:
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 9ce964b0..2bd5f27c 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -78,6 +78,12 @@ class Node(object):
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)
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 911b76f9..16c9a112 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -28,11 +28,11 @@ from .xmlwriter import XMLWriter
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 @@ class GIRWriter(XMLWriter):
('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):
diff --git a/giscanner/glibtransformer.py b/giscanner/glibtransformer.py
index bebae5f5..b79a018c 100644
--- a/giscanner/glibtransformer.py
+++ b/giscanner/glibtransformer.py
@@ -24,8 +24,8 @@ import os
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 @@ def resolve_libtool(libname):
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 @@ class GLibTransformer(object):
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
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index c5b48ebe..656b4e2f 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -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 @@ from giscanner.sourcescanner import (
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 @@ class Transformer(object):
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:
diff --git a/tools/g-ir-scanner b/tools/g-ir-scanner
index 56615b09..22abf403 100755
--- a/tools/g-ir-scanner
+++ b/tools/g-ir-scanner
@@ -42,8 +42,8 @@ def _get_option_parser():
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 @@ def main(args):
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 @@ def main(args):
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")