diff options
author | Johan Dahlin <johan@gnome.org> | 2008-05-08 23:37:09 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-05-08 23:37:09 +0000 |
commit | 870afacec8ba104daef3c1a23e42a3646d547633 (patch) | |
tree | 5b3f99b930fcc72fc5aa65c9ae5f26b0ff841fd2 /giscanner | |
parent | b22b5bfb007c4bc6202b7fd901a38869af1d234b (diff) | |
download | gobject-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
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/ast.py | 6 | ||||
-rw-r--r-- | giscanner/girwriter.py | 15 | ||||
-rw-r--r-- | giscanner/glibtransformer.py | 20 | ||||
-rw-r--r-- | giscanner/transformer.py | 16 |
4 files changed, 32 insertions, 25 deletions
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: |