[gobject-introspection/wip/transformer] scanner: remove * imports, use less than 100 char lines
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/wip/transformer] scanner: remove * imports, use less than 100 char lines
- Date: Thu, 19 Aug 2010 16:46:11 +0000 (UTC)
commit 578ab9cae3416394eac58d707ea40c65b204416c
Author: Colin Walters <walters verbum org>
Date: Thu Aug 19 11:45:05 2010 -0400
scanner: remove * imports, use less than 100 char lines
giscanner/annotationparser.py | 19 ---
giscanner/ast.py | 6 -
giscanner/codegen.py | 22 ++--
giscanner/finaltransformer.py | 53 ++++-----
giscanner/girparser.py | 114 +++++++++---------
giscanner/glibast.py | 45 ++++----
giscanner/glibtransformer.py | 99 ++++++++--------
giscanner/primarytransformer.py | 250 ++++++++++++++++++++-------------------
giscanner/scannermain.py | 9 +-
giscanner/sourcescanner.py | 2 +-
giscanner/testcodegen.py | 60 +++++-----
giscanner/transformer.py | 110 ++++++++---------
misc/pep8.py | 2 +-
13 files changed, 376 insertions(+), 415 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index 68aebf9..48c4cd7 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -22,23 +22,7 @@
import re
-from .ast import (Array, Bitfield, Callback, Class, Enum, Field, Function,
- Interface, List, Map, Parameter, Property, Record, Return,
- Type, Union, Varargs,
- BASIC_GIR_TYPES,
- PARAM_DIRECTION_INOUT,
- PARAM_DIRECTION_IN,
- PARAM_DIRECTION_OUT,
- PARAM_SCOPE_CALL,
- PARAM_SCOPE_ASYNC,
- PARAM_SCOPE_NOTIFIED,
- PARAM_TRANSFER_NONE,
- PARAM_TRANSFER_CONTAINER,
- PARAM_TRANSFER_FULL,
- TYPE_ANY, TYPE_NONE, TYPE_STRING)
-from .transformer import TypeResolutionException
from .odict import odict
-from .glibast import GLibBoxed
# All gtk-doc comments needs to start with this:
_COMMENT_HEADER = '*\n '
@@ -73,9 +57,6 @@ OPT_DESTROY = 'destroy'
OPT_SKIP = 'skip'
OPT_FOREIGN = 'foreign'
-# Specific option values
-OPT_VAL_BITFIELD = 'bitfield'
-
# Array options - array specific annotations
OPT_ARRAY_FIXED_SIZE = 'fixed-size'
OPT_ARRAY_LENGTH = 'length'
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 722bf42..a76931e 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -378,12 +378,6 @@ functions via get_by_symbol()."""
for node in self.itervalues():
node.walk(callback, [])
- def iter_recursive(self):
- """Recursively iterate over all Node instances."""
- def doyield(node, chain):
- yield node
- self.walk(test)
-
class Include(object):
def __init__(self, name, version):
diff --git a/giscanner/codegen.py b/giscanner/codegen.py
index 55f1383..0c0c559 100644
--- a/giscanner/codegen.py
+++ b/giscanner/codegen.py
@@ -18,10 +18,8 @@
# Boston, MA 02111-1307, USA.
#
-import os, sys
from contextlib import contextmanager
-from .ast import *
-from .glibast import *
+from . import ast
class CCodeGenerator(object):
def __init__(self, namespace, out_h_filename, out_c_filename):
@@ -35,14 +33,14 @@ class CCodeGenerator(object):
return '%s_%s' % (self.namespace.symbol_prefixes[0], name)
def _typecontainer_to_ctype(self, param):
- if (isinstance(param, Parameter) and
- param.direction in (PARAM_DIRECTION_OUT,
- PARAM_DIRECTION_INOUT)):
+ if (isinstance(param, ast.Parameter) and
+ param.direction in (ast.PARAM_DIRECTION_OUT,
+ ast.PARAM_DIRECTION_INOUT)):
suffix = '*'
else:
suffix = ''
- if (param.type.is_equiv((TYPE_STRING, TYPE_FILENAME)) and
- param.transfer == PARAM_TRANSFER_NONE):
+ if (param.type.is_equiv((ast.TYPE_STRING, ast.TYPE_FILENAME)) and
+ param.transfer == ast.PARAM_TRANSFER_NONE):
return "const gchar*" + suffix
return param.type.ctype + suffix
@@ -72,8 +70,8 @@ class CCodeGenerator(object):
self.out_c.write("/**\n * %s:\n" % (func.symbol, ))
for param in func.parameters:
self.out_c.write(" * @%s: " % (param.argname, ))
- if param.direction in (PARAM_DIRECTION_OUT,
- PARAM_DIRECTION_INOUT):
+ if param.direction in (ast.PARAM_DIRECTION_OUT,
+ ast.PARAM_DIRECTION_INOUT):
if param.caller_allocates:
allocate_string = ' caller-allocates'
else:
@@ -119,7 +117,7 @@ class CCodeGenerator(object):
self.out_c.close()
def set_function_body(self, node, body):
- assert isinstance(node, Function)
+ assert isinstance(node, ast.Function)
self._function_bodies[node] = body
def codegen(self):
@@ -129,7 +127,7 @@ class CCodeGenerator(object):
self._codegen_start()
for node in self.namespace.itervalues():
- if isinstance(node, Function):
+ if isinstance(node, ast.Function):
with self._function(node):
body = self._function_bodies.get(node)
if not body:
diff --git a/giscanner/finaltransformer.py b/giscanner/finaltransformer.py
index 87dc0bc..16a00b3 100644
--- a/giscanner/finaltransformer.py
+++ b/giscanner/finaltransformer.py
@@ -17,16 +17,8 @@
# Boston, MA 02111-1307, USA.
#
-import os
-import sys
-import re
-import tempfile
-import shutil
-import subprocess
-
-from .ast import *
-from .glibast import *
-from .utils import to_underscores, to_underscores_noprefix
+from . import ast
+from . import glibast
class FinalTransformer(object):
@@ -43,7 +35,7 @@ class FinalTransformer(object):
self._namespace.walk(self._introspectable_pass3)
def _interface_vfunc_check(self, node, stack):
- if isinstance(node, GLibInterface):
+ if isinstance(node, glibast.GLibInterface):
for vfunc in node.virtual_methods:
if not vfunc.invoker:
self._transformer.log_node_warning(vfunc,
@@ -55,7 +47,7 @@ class FinalTransformer(object):
prefix = '%s: ' % (parent.symbol, )
else:
prefix = ''
- if isinstance(param, Parameter):
+ if isinstance(param, ast.Parameter):
context = "argument %s: " % (param.argname, )
else:
context = "return value: "
@@ -65,9 +57,9 @@ class FinalTransformer(object):
if not node.type.resolved:
self._parameter_warning(parent, node, "Unresolved ctype: %r" % (node.type.ctype, ))
parent.introspectable = False
- elif isinstance(node.type, Varargs):
+ elif isinstance(node.type, ast.Varargs):
parent.introspectable = False
- elif not isinstance(node.type, List) and \
+ elif not isinstance(node.type, ast.List) and \
(node.type.target_giname == 'GLib.List'):
self._parameter_warning(parent, node, "Missing (element-type) annotation")
parent.introspectable = False
@@ -75,37 +67,40 @@ class FinalTransformer(object):
self._parameter_warning(parent, node, "Missing (transfer) annotation")
parent.introspectable = False
- if isinstance(node, Parameter) and node.type.target_giname:
+ if isinstance(node, ast.Parameter) and node.type.target_giname:
target = self._transformer.lookup_typenode(node.type)
- if (isinstance(target, Callback)
- and not target.create_type().target_giname in ('GLib.DestroyNotify', 'Gio.AsyncReadyCallback')
+ if (isinstance(target, ast.Callback)
+ and not target.create_type().target_giname in ('GLib.DestroyNotify',
+ 'Gio.AsyncReadyCallback')
and node.scope is None):
self._parameter_warning(parent, node,
- "Missing (scope) annotation for callback without GDestroyNotify (valid: %s, %s)" % (PARAM_SCOPE_CALL, PARAM_SCOPE_ASYNC))
+ ("Missing (scope) annotation for callback" +
+ " without GDestroyNotify (valid: %s, %s)")
+ % (ast.PARAM_SCOPE_CALL, ast.PARAM_SCOPE_ASYNC))
parent.introspectable = False
def _type_is_introspectable(self, typeval, warn=False):
if not typeval.resolved:
return False
- if isinstance(typeval, (Array, List)):
+ if isinstance(typeval, (ast.Array, ast.List)):
return self._type_is_introspectable(typeval.element_type)
- elif isinstance(typeval, Map):
+ elif isinstance(typeval, ast.Map):
return (self._type_is_introspectable(typeval.key_type)
and self._type_is_introspectable(typeval.value_type))
if typeval.target_foreign:
return True
if typeval.target_fundamental:
- if typeval.is_equiv(TYPE_VALIST):
+ if typeval.is_equiv(ast.TYPE_VALIST):
return False
# Mark UCHAR as not introspectable temporarily until
# we're ready to land the typelib changes
- if typeval.is_equiv(TYPE_UNICHAR):
+ if typeval.is_equiv(ast.TYPE_UNICHAR):
return False
# These are not introspectable pending us adding
# larger type tags to the typelib (in theory these could
# be 128 bit or larger)
- if typeval.is_equiv((TYPE_LONG_LONG, TYPE_LONG_ULONG,
- TYPE_LONG_DOUBLE)):
+ if typeval.is_equiv((ast.TYPE_LONG_LONG, ast.TYPE_LONG_ULONG,
+ ast.TYPE_LONG_DOUBLE)):
return False
return True
target = self._transformer.lookup_typenode(typeval)
@@ -119,11 +114,11 @@ class FinalTransformer(object):
# Combine one-pass checks here
self._interface_vfunc_check(obj, stack)
# Our first pass for scriptability
- if isinstance(obj, Callable):
+ if isinstance(obj, ast.Callable):
for param in obj.parameters:
self._introspectable_param_analysis(obj, param)
self._introspectable_param_analysis(obj, obj.retval)
- if isinstance(obj, (Class, Interface, Record, Union)):
+ if isinstance(obj, (ast.Class, ast.Interface, ast.Record, ast.Union)):
for field in obj.fields:
if field.type:
if not self._type_is_introspectable(field.type):
@@ -134,7 +129,7 @@ class FinalTransformer(object):
if obj.skip:
return True
# Propagate introspectability of parameters to entire functions
- if isinstance(obj, Callable):
+ if isinstance(obj, ast.Callable):
for param in obj.parameters:
if not self._type_is_introspectable(param.type):
obj.introspectable = False
@@ -148,7 +143,7 @@ class FinalTransformer(object):
if obj.skip:
return True
# Propagate introspectability for fields
- if isinstance(obj, (Class, Interface, Record, Union)):
+ if isinstance(obj, (ast.Class, ast.Interface, ast.Record, ast.Union)):
for field in obj.fields:
if field.anonymous_node:
if not field.anonymous_node.introspectable:
@@ -157,7 +152,7 @@ class FinalTransformer(object):
if not self._type_is_introspectable(field.type):
field.introspectable = False
# Propagate introspectability for properties
- if isinstance(obj, (Class, Interface)):
+ if isinstance(obj, (ast.Class, ast.Interface)):
for prop in obj.properties:
if not self._type_is_introspectable(prop.type):
prop.introspectable = False
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index 1924a59..f5c3ecf 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -22,8 +22,8 @@ import os
from xml.etree.cElementTree import parse
-from .ast import *
-from .glibast import *
+from . import ast
+from . import glibast
from .girwriter import COMPATIBLE_GIR_VERSION
CORE_NS = "http://www.gtk.org/introspection/core/1.0"
@@ -141,7 +141,7 @@ class GIRParser(object):
symbol_prefixes = ns.attrib.get(_cns('symbol-prefixes'))
if symbol_prefixes:
symbol_prefixes = symbol_prefixes.split(',')
- self._namespace = Namespace(ns.attrib['name'],
+ self._namespace = ast.Namespace(ns.attrib['name'],
ns.attrib['version'],
identifier_prefixes=identifier_prefixes,
symbol_prefixes=symbol_prefixes)
@@ -169,7 +169,7 @@ class GIRParser(object):
method(node)
def _parse_include(self, node):
- include = Include(node.attrib['name'],
+ include = ast.Include(node.attrib['name'],
node.attrib['version'])
self._includes.add(include)
@@ -181,13 +181,13 @@ class GIRParser(object):
def _parse_alias(self, node):
typeval = self._parse_type(node)
- alias = Alias(node.attrib['name'],
+ alias = ast.Alias(node.attrib['name'],
typeval,
node.attrib.get(_cns('type')))
self._namespace.append(alias)
def _parse_generic_attribs(self, node, obj):
- assert isinstance(obj, Annotated)
+ assert isinstance(obj, ast.Annotated)
doc = node.find(_corens('doc'))
if doc is not None:
obj.doc = doc.text
@@ -214,9 +214,9 @@ class GIRParser(object):
node.attrib[_glibns('get-type')],
node.attrib.get(_cns('symbol-prefix'))]
if node.tag == _corens('interface'):
- klass = GLibInterface
+ klass = glibast.GLibInterface
elif node.tag == _corens('class'):
- klass = GLibObject
+ klass = glibast.GLibObject
is_abstract = node.attrib.get('abstract')
is_abstract = is_abstract and is_abstract != '0'
ctor_args.append(is_abstract)
@@ -236,34 +236,34 @@ class GIRParser(object):
for iface in self._find_children(node, _corens('prerequisite')):
obj.prerequisites.append(self._namespace.type_from_name(iface.attrib['name']))
for func_node in self._find_children(node, _corens('function')):
- func = self._parse_function_common(func_node, Function)
+ func = self._parse_function_common(func_node, ast.Function)
obj.static_methods.append(func)
for method in self._find_children(node, _corens('method')):
- func = self._parse_function_common(method, Function)
+ func = self._parse_function_common(method, ast.Function)
func.is_method = True
obj.methods.append(func)
for method in self._find_children(node, _corens('virtual-method')):
- func = self._parse_function_common(method, VFunction)
+ func = self._parse_function_common(method, ast.VFunction)
self._parse_generic_attribs(method, func)
func.is_method = True
func.invoker = method.get('invoker')
obj.virtual_methods.append(func)
for ctor in self._find_children(node, _corens('constructor')):
- func = self._parse_function_common(ctor, Function)
+ func = self._parse_function_common(ctor, ast.Function)
func.is_constructor = True
obj.constructors.append(func)
obj.fields.extend(self._parse_fields(node))
for prop in self._find_children(node, _corens('property')):
obj.properties.append(self._parse_property(prop))
for signal in self._find_children(node, _glibns('signal')):
- obj.signals.append(self._parse_function_common(signal, Function))
+ obj.signals.append(self._parse_function_common(signal, ast.Function))
def _parse_callback(self, node):
- callback = self._parse_function_common(node, Callback)
+ callback = self._parse_function_common(node, ast.Callback)
self._namespace.append(callback)
def _parse_function(self, node):
- function = self._parse_function_common(node, Function)
+ function = self._parse_function_common(node, ast.Function)
function.shadows = node.attrib.get('shadows', None)
function.shadowed_by = node.attrib.get('shadowed-by', None)
self._namespace.append(function)
@@ -274,19 +274,19 @@ class GIRParser(object):
if not returnnode:
raise ValueError('node %r has no return-value' % (name, ))
transfer = returnnode.attrib.get('transfer-ownership')
- retval = Return(self._parse_type(returnnode), transfer)
+ retval = ast.Return(self._parse_type(returnnode), transfer)
self._parse_generic_attribs(returnnode, retval)
parameters = []
throws = (node.attrib.get('throws') == '1')
- if klass is Callback:
+ if klass is ast.Callback:
func = klass(name, retval, parameters, throws,
node.attrib.get(_cns('type')))
- elif klass is Function:
+ elif klass is ast.Function:
identifier = node.attrib.get(_cns('identifier'))
- func = klass (name, retval, parameters, throws, identifier)
- elif klass is VFunction:
+ func = klass(name, retval, parameters, throws, identifier)
+ elif klass is ast.VFunction:
func = klass(name, retval, parameters, throws)
else:
assert False
@@ -294,9 +294,9 @@ class GIRParser(object):
parameters_node = node.find(_corens('parameters'))
if (parameters_node is not None):
for paramnode in self._find_children(parameters_node, _corens('parameter')):
- param = Parameter(paramnode.attrib.get('name'),
+ param = ast.Parameter(paramnode.attrib.get('name'),
self._parse_type(paramnode),
- paramnode.attrib.get('direction') or PARAM_DIRECTION_IN,
+ paramnode.attrib.get('direction') or ast.PARAM_DIRECTION_IN,
paramnode.attrib.get('transfer-ownership'),
paramnode.attrib.get('allow-none') == '1',
paramnode.attrib.get('scope'),
@@ -325,19 +325,19 @@ class GIRParser(object):
def _parse_record(self, node, anonymous=False):
if _glibns('type-name') in node.attrib:
- struct = GLibBoxedStruct(node.attrib['name'],
+ struct = glibast.GLibBoxedStruct(node.attrib['name'],
node.attrib[_glibns('type-name')],
node.attrib[_glibns('get-type')],
node.attrib.get(_cns('symbol-prefix')),
node.attrib.get(_cns('type')))
elif _glibns('is-gtype-struct-for') in node.attrib:
- struct = GLibRecord(node.attrib['name'],
+ struct = glibast.GLibRecord(node.attrib['name'],
node.attrib.get(_cns('type')),
disguised=node.attrib.get('disguised') == '1')
is_gtype_struct_for = node.attrib[_glibns('is-gtype-struct-for')]
struct.is_gtype_struct_for = self._namespace.type_from_name(is_gtype_struct_for)
else:
- struct = Record(node.attrib.get('name'),
+ struct = ast.Record(node.attrib.get('name'),
node.attrib.get(_cns('type')),
disguised=node.attrib.get('disguised') == '1')
if node.attrib.get('foreign') == '1':
@@ -349,55 +349,55 @@ class GIRParser(object):
struct.fields.extend(self._parse_fields(node))
for method in self._find_children(node, _corens('method')):
struct.methods.append(
- self._parse_function_common(method, Function))
+ self._parse_function_common(method, ast.Function))
for func in self._find_children(node, _corens('function')):
struct.static_methods.append(
- self._parse_function_common(func, Function))
+ self._parse_function_common(func, ast.Function))
for ctor in self._find_children(node, _corens('constructor')):
struct.constructors.append(
- self._parse_function_common(ctor, Function))
+ self._parse_function_common(ctor, ast.Function))
return struct
def _parse_union(self, node, anonymous=False):
if _glibns('type-name') in node.attrib:
- union = GLibBoxedUnion(node.attrib['name'],
+ union = glibast.GLibBoxedUnion(node.attrib['name'],
node.attrib[_glibns('type-name')],
node.attrib[_glibns('get-type')],
node.attrib.get(_cns('symbol-prefix')),
node.attrib.get(_cns('type')))
else:
- union = Union(node.attrib.get('name'),
+ union = ast.Union(node.attrib.get('name'),
node.attrib.get(_cns('type')))
if not anonymous:
self._namespace.append(union)
for callback in self._find_children(node, _corens('callback')):
union.fields.append(
- self._parse_function_common(callback, Callback))
+ self._parse_function_common(callback, ast.Callback))
union.fields.extend(self._parse_fields(node))
for method in self._find_children(node, _corens('method')):
union.fields.append(
- self._parse_function_common(method, Function))
+ self._parse_function_common(method, ast.Function))
for ctor in self._find_children(node, _corens('constructor')):
union.constructors.append(
- self._parse_function_common(ctor, Function))
+ self._parse_function_common(ctor, ast.Function))
return union
def _parse_type(self, node):
- # Fields can contain inline callbacks
+ # ast.Fields can contain inline callbacks
typenode = node.find(_corens('callback'))
if typenode is not None:
typeval = self._namespace.type_from_name(typenode.attrib['name'])
typeval.ctype = typenode.attrib.get(_cns('type'))
return typeval
- # Arrays have their own toplevel XML
+ # ast.Arrays have their own toplevel XML
typenode = node.find(_corens('array'))
if typenode is not None:
array_type = typenode.attrib.get('name')
element_type = self._parse_type(typenode)
array_ctype = typenode.attrib.get(_cns('type'))
- ret = Array(array_type, element_type, ctype=array_ctype)
+ ret = ast.Array(array_type, element_type, ctype=array_ctype)
# zero-terminated defaults to true...
zero = typenode.attrib.get('zero-terminated')
if zero and zero == '0':
@@ -414,7 +414,7 @@ class GIRParser(object):
# Dispsense with varargs
typenode = node.find(_corens('varargs'))
if typenode is not None:
- return Varargs()
+ return ast.Varargs()
# Okay now...could be a list, let's see.
typenode = self._find_first_child(node, _corens('type'))
@@ -423,20 +423,20 @@ class GIRParser(object):
ctype = typenode.attrib.get(_cns('type'))
if name is None:
if ctype is None:
- return TypeUnknown()
- return Type(ctype=ctype)
+ return ast.TypeUnknown()
+ return ast.Type(ctype=ctype)
if name in ['GLib.List', 'GLib.SList']:
subchild = self._find_first_child(typenode, _corens('type'))
if subchild is not None:
element_type = self._parse_type(typenode)
else:
- element_type = TYPE_ANY
- return List(name, element_type, ctype=ctype)
+ element_type = ast.TYPE_ANY
+ return ast.List(name, element_type, ctype=ctype)
if name == 'GLib.HashTable':
subchildren = map(self._parse_type, self._find_children(node, _corens('type')))
while len(subchildren) < 2:
- subchildren.append(TYPE_ANY)
- return Map(subchildren[0],
+ subchildren.append(ast.TYPE_ANY)
+ return ast.Map(subchildren[0],
subchildren[1],
ctype=ctype)
else:
@@ -446,22 +446,22 @@ class GIRParser(object):
node, list(node))
def _parse_boxed(self, node):
- obj = GLibBoxedOther(node.attrib[_glibns('name')],
+ obj = glibast.GLibBoxedOther(node.attrib[_glibns('name')],
node.attrib[_glibns('type-name')],
node.attrib[_glibns('get-type')],
node.attrib.get(_cns('symbol-prefix')))
self._parse_generic_attribs(node, obj)
self._namespace.append(obj)
for method in self._find_children(node, _corens('method')):
- func = self._parse_function_common(method, Function)
+ func = self._parse_function_common(method, ast.Function)
func.is_method = True
obj.methods.append(func)
for ctor in self._find_children(node, _corens('constructor')):
obj.constructors.append(
- self._parse_function_common(ctor, Function))
+ self._parse_function_common(ctor, ast.Function))
for callback in self._find_children(node, _corens('callback')):
obj.fields.append(
- self._parse_function_common(callback, Callback))
+ self._parse_function_common(callback, ast.Callback))
def _parse_field(self, node):
type_node = None
@@ -472,7 +472,7 @@ class GIRParser(object):
anonymous_elt = self._find_first_child(node, _corens('callback'))
if anonymous_elt is not None:
if anonymous_elt.tag == _corens('callback'):
- anonymous_node = self._parse_function_common(anonymous_elt, Callback)
+ anonymous_node = self._parse_function_common(anonymous_elt, ast.Callback)
elif anonymous_elt.tag == _corens('record'):
anonymous_node = self._parse_record(anonymous_elt, anonymous=True)
elif anonymous_elt.tag == _corens('union'):
@@ -482,7 +482,7 @@ class GIRParser(object):
else:
assert node.tag == _corens('field'), node.tag
type_node = self._parse_type(node)
- field = Field(node.attrib.get('name'),
+ field = ast.Field(node.attrib.get('name'),
type_node,
node.attrib.get('readable') != '0',
node.attrib.get('writable') == '1',
@@ -492,7 +492,7 @@ class GIRParser(object):
return field
def _parse_property(self, node):
- prop = Property(node.attrib['name'],
+ prop = ast.Property(node.attrib['name'],
self._parse_type(node),
node.attrib.get('readable') != '0',
node.attrib.get('writable') == '1',
@@ -502,7 +502,7 @@ class GIRParser(object):
return prop
def _parse_member(self, node):
- member = GLibEnumMember(node.attrib['name'],
+ member = glibast.GLibEnumMember(node.attrib['name'],
node.attrib['value'],
node.attrib.get(_cns('identifier')),
node.attrib.get(_glibns('nick')))
@@ -511,7 +511,7 @@ class GIRParser(object):
def _parse_constant(self, node):
type_node = self._parse_type(node)
- constant = Constant(node.attrib['name'],
+ constant = ast.Constant(node.attrib['name'],
type_node,
node.attrib['value'])
self._parse_generic_attribs(node, constant)
@@ -525,17 +525,17 @@ class GIRParser(object):
glib_error_quark = node.attrib.get(_glibns('error-quark'))
if get_type or glib_error_quark:
if node.tag == _corens('bitfield'):
- klass = GLibFlags
+ klass = glibast.GLibFlags
else:
- klass = GLibEnum
+ klass = glibast.GLibEnum
else:
if node.tag == _corens('bitfield'):
- klass = Bitfield
+ klass = ast.Bitfield
else:
- klass = Enum
+ klass = ast.Enum
type_name = ctype
members = []
- if klass in (Enum, Bitfield):
+ if klass in (ast.Enum, ast.Bitfield):
obj = klass(name, type_name, members)
else:
obj = klass(name, type_name, members, get_type)
diff --git a/giscanner/glibast.py b/giscanner/glibast.py
index 1fd5bd5..85092b8 100644
--- a/giscanner/glibast.py
+++ b/giscanner/glibast.py
@@ -18,12 +18,11 @@
# Boston, MA 02111-1307, USA.
#
-from .ast import (Bitfield, Class, Enum, Interface, Member, Node,
- Property, Union, Record, Annotated, Callable)
+from . import ast
-class GLibRecord(Record):
+class GLibRecord(ast.Record):
def __init__(self, *args, **kwargs):
- Record.__init__(self, *args, **kwargs)
+ ast.Record.__init__(self, *args, **kwargs)
@classmethod
def from_record(cls, record):
@@ -38,10 +37,10 @@ class GLibRecord(Record):
obj.is_gtype_struct_for = False
return obj
-class GLibEnum(Enum):
+class GLibEnum(ast.Enum):
def __init__(self, name, type_name, members, get_type):
- Enum.__init__(self, name, type_name, members)
+ ast.Enum.__init__(self, name, type_name, members)
self.ctype = type_name
self.type_name = type_name
self.get_type = get_type
@@ -52,10 +51,10 @@ class GLibEnum(Enum):
self.get_type)
-class GLibFlags(Bitfield):
+class GLibFlags(ast.Bitfield):
def __init__(self, name, type_name, members, get_type):
- Bitfield.__init__(self, name, type_name, members)
+ ast.Bitfield.__init__(self, name, type_name, members)
self.ctype = type_name
self.type_name = type_name
self.get_type = get_type
@@ -65,18 +64,18 @@ class GLibFlags(Bitfield):
self.get_type)
-class GLibEnumMember(Member):
+class GLibEnumMember(ast.Member):
def __init__(self, name, value, symbol, nick):
- Member.__init__(self, name, value, symbol)
+ ast.Member.__init__(self, name, value, symbol)
self.nick = nick
-class GLibObject(Class):
+class GLibObject(ast.Class):
def __init__(self, name, parent, type_name, get_type,
c_symbol_prefix, is_abstract, ctype=None):
- Class.__init__(self, name, parent, is_abstract)
+ ast.Class.__init__(self, name, parent, is_abstract)
self.type_name = type_name
self.get_type = get_type
self.c_symbol_prefix = c_symbol_prefix
@@ -102,24 +101,24 @@ class GLibBoxed:
self.c_symbol_prefix = c_symbol_prefix
-class GLibBoxedStruct(Record, GLibBoxed):
+class GLibBoxedStruct(ast.Record, GLibBoxed):
def __init__(self, name, type_name, get_type, c_symbol_prefix, ctype=None):
- Record.__init__(self, name, ctype or type_name)
+ ast.Record.__init__(self, name, ctype or type_name)
GLibBoxed.__init__(self, type_name, get_type, c_symbol_prefix)
-class GLibBoxedUnion(Union, GLibBoxed):
+class GLibBoxedUnion(ast.Union, GLibBoxed):
def __init__(self, name, type_name, get_type, c_symbol_prefix, ctype=None):
- Union.__init__(self, name, ctype or type_name)
+ ast.Union.__init__(self, name, ctype or type_name)
GLibBoxed.__init__(self, type_name, get_type, c_symbol_prefix)
-class GLibBoxedOther(Node, GLibBoxed):
+class GLibBoxedOther(ast.Node, GLibBoxed):
def __init__(self, name, type_name, get_type, c_symbol_prefix):
- Node.__init__(self, name)
+ ast.Node.__init__(self, name)
GLibBoxed.__init__(self, type_name, get_type, c_symbol_prefix)
self.constructors = []
self.methods = []
@@ -136,11 +135,11 @@ class GLibBoxedOther(Node, GLibBoxed):
meth.walk(callback, chain)
-class GLibInterface(Interface):
+class GLibInterface(ast.Interface):
def __init__(self, name, parent, type_name, get_type,
c_symbol_prefix, ctype=None):
- Interface.__init__(self, name, parent)
+ ast.Interface.__init__(self, name, parent)
self.type_name = type_name
self.get_type = get_type
self.c_symbol_prefix = c_symbol_prefix
@@ -152,11 +151,11 @@ class GLibInterface(Interface):
for sig in self.signals:
sig.walk(callback, chain)
-class GLibProperty(Property):
+class GLibProperty(ast.Property):
pass
-class GLibSignal(Callable):
+class GLibSignal(ast.Callable):
def __init__(self, name, retval, parameters):
- Callable.__init__(self, name, retval, parameters, False)
+ ast.Callable.__init__(self, name, retval, parameters, False)
diff --git a/giscanner/glibtransformer.py b/giscanner/glibtransformer.py
index bff6415..b5bfe35 100644
--- a/giscanner/glibtransformer.py
+++ b/giscanner/glibtransformer.py
@@ -20,22 +20,12 @@
import os
import sys
-import re
import tempfile
import shutil
import subprocess
-from .ast import (Alias, Bitfield, Callable, Callback, Class, Constant, Enum,
- Function, Interface, Member, Namespace, Node, Parameter,
- Property, Record, Return, Type, TypeContainer, Union,
- Class, Field, VFunction,
- TYPE_ANY, TYPE_GTYPE, TYPE_UINT8, PARAM_TRANSFER_FULL, Array, List,
- PARAM_TRANSFER_NONE,
- Map, Varargs, type_names)
-from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember, GLibFlags,
- GLibInterface, GLibObject, GLibSignal, GLibBoxedStruct,
- GLibBoxedUnion, GLibBoxedOther, GLibRecord)
-from .utils import to_underscores, to_underscores_noprefix
+from . import ast
+from . import glibast
# GParamFlags
G_PARAM_READABLE = 1 << 0
@@ -92,11 +82,11 @@ class GLibTransformer(object):
# First pass: parsing
for node in self._namespace.itervalues():
- if isinstance(node, Function):
+ if isinstance(node, ast.Function):
self._initparse_function(node)
if self._namespace.name == 'GObject':
for node in self._namespace.itervalues():
- if isinstance(node, Record):
+ if isinstance(node, ast.Record):
self._initparse_gobject_record(node)
def get_get_type_functions(self):
@@ -118,17 +108,18 @@ class GLibTransformer(object):
self._introspect_type(child)
# Pair up boxed types and class records
- for name,boxed in self._boxed_types.iteritems():
+ for name, boxed in self._boxed_types.iteritems():
self._pair_boxed_type(boxed)
for node in self._namespace.itervalues():
- if isinstance(node, (Class, Interface)):
+ if isinstance(node, (ast.Class, ast.Interface)):
self._find_class_record(node)
# Clear the _get_type functions out of the namespace;
- # Anyone who wants them can get them from the Class/Interface/Boxed
+ # Anyone who wants them can get them from the ast.Class/Interface/Boxed
to_remove = []
- for name,node in self._namespace.iteritems():
- if isinstance(node, (Class, Interface, GLibBoxed, GLibEnum, GLibFlags)):
+ for name, node in self._namespace.iteritems():
+ if isinstance(node, (ast.Class, ast.Interface, glibast.GLibBoxed,
+ glibast.GLibEnum, glibast.GLibFlags)):
get_type_name = node.get_type
if get_type_name == 'intern':
continue
@@ -178,11 +169,11 @@ blob containing data gleaned from GObject's primitive introspection."""
parent_gitype = None
symbol = 'intern'
elif type_name == 'GInitiallyUnowned':
- parent_gitype = Type(target_giname='GLib.Object')
+ parent_gitype = ast.Type(target_giname='GLib.Object')
symbol = 'g_initially_unowned_get_type'
else:
assert False
- gnode = GLibObject(node.name, parent_gitype, type_name, symbol, 'object', True)
+ gnode = glibast.GLibObject(node.name, parent_gitype, type_name, symbol, 'object', True)
if type_name == 'GObject':
gnode.fields.extend(node.fields)
else:
@@ -217,9 +208,10 @@ blob containing data gleaned from GObject's primitive introspection."""
return False
# GType *_get_type(void)
rettype = func.retval.type
- if not (rettype.is_equiv(TYPE_GTYPE)
+ if not (rettype.is_equiv(ast.TYPE_GTYPE)
or rettype.target_giname == 'Gtk.Type'):
- self._transformer.log_warning("function returns '%r', not a GType") % (func.retval.type, )
+ self._transformer.log_warning("function returns '%r', not a GType"
+ % (func.retval.type, ))
return False
self._get_type_functions.append(func.symbol)
@@ -258,12 +250,12 @@ blob containing data gleaned from GObject's primitive introspection."""
# Keep the name closer to what we'd take from C by default;
# see http://bugzilla.gnome.org/show_bug.cgi?id=575613
name = member.attrib['nick'].replace('-', '_')
- members.append(GLibEnumMember(name,
+ members.append(glibast.GLibEnumMember(name,
member.attrib['value'],
member.attrib['name'],
member.attrib['nick']))
- klass = (GLibFlags if node.tag == 'flags' else GLibEnum)
+ klass = (glibast.GLibFlags if node.tag == 'flags' else glibast.GLibEnum)
type_name = node.attrib['name']
enum_name = self._transformer.strip_identifier_or_warn(type_name, fatal=True)
node = klass(enum_name, type_name, members, node.attrib['get-type'])
@@ -286,10 +278,11 @@ blob containing data gleaned from GObject's primitive introspection."""
return
is_abstract = bool(xmlnode.attrib.get('abstract', False))
(get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
- node = GLibObject(self._transformer.strip_identifier_or_warn(type_name, fatal=True),
- None,
- type_name,
- get_type, c_symbol_prefix, is_abstract)
+ node = glibast.GLibObject(
+ self._transformer.strip_identifier_or_warn(type_name, fatal=True),
+ None,
+ type_name,
+ get_type, c_symbol_prefix, is_abstract)
self._parse_parents(xmlnode, node)
self._introspect_properties(node, xmlnode)
self._introspect_signals(node, xmlnode)
@@ -301,9 +294,10 @@ blob containing data gleaned from GObject's primitive introspection."""
def _introspect_interface(self, xmlnode):
type_name = xmlnode.attrib['name']
(get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
- node = GLibInterface(self._transformer.strip_identifier_or_warn(type_name, fatal=True),
- None,
- type_name, get_type, c_symbol_prefix)
+ node = glibast.GLibInterface(
+ self._transformer.strip_identifier_or_warn(type_name, fatal=True),
+ None,
+ type_name, get_type, c_symbol_prefix)
self._introspect_properties(node, xmlnode)
self._introspect_signals(node, xmlnode)
for child in xmlnode.findall('prerequisite'):
@@ -322,7 +316,7 @@ blob containing data gleaned from GObject's primitive introspection."""
# This one doesn't go in the main namespace; we associate it with
# the struct or union
(get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
- node = GLibBoxed(type_name, get_type, c_symbol_prefix)
+ node = glibast.GLibBoxed(type_name, get_type, c_symbol_prefix)
self._boxed_types[node.type_name] = node
def _introspect_implemented_interfaces(self, node, xmlnode):
@@ -340,7 +334,7 @@ blob containing data gleaned from GObject's primitive introspection."""
writable = (flags & G_PARAM_WRITABLE) != 0
construct = (flags & G_PARAM_CONSTRUCT) != 0
construct_only = (flags & G_PARAM_CONSTRUCT_ONLY) != 0
- node.properties.append(Property(
+ node.properties.append(ast.Property(
pspec.attrib['name'],
self._transformer.create_type_from_user_string(ctype),
readable, writable, construct, construct_only,
@@ -352,7 +346,7 @@ blob containing data gleaned from GObject's primitive introspection."""
for signal_info in xmlnode.findall('signal'):
rctype = signal_info.attrib['return']
rtype = self._transformer.create_type_from_user_string(rctype)
- return_ = Return(rtype)
+ return_ = ast.Return(rtype)
parameters = []
for i, parameter in enumerate(signal_info.findall('param')):
if i == 0:
@@ -361,10 +355,10 @@ blob containing data gleaned from GObject's primitive introspection."""
argname = 'p%s' % (i-1, )
pctype = parameter.attrib['type']
ptype = self._transformer.create_type_from_user_string(pctype)
- param = Parameter(argname, ptype)
- param.transfer = PARAM_TRANSFER_NONE
+ param = ast.Parameter(argname, ptype)
+ param.transfer = ast.PARAM_TRANSFER_NONE
parameters.append(param)
- signal = GLibSignal(signal_info.attrib['name'], return_, parameters)
+ signal = glibast.GLibSignal(signal_info.attrib['name'], return_, parameters)
node.signals.append(signal)
node.signals = node.signals
@@ -387,10 +381,11 @@ blob containing data gleaned from GObject's primitive introspection."""
type_name = xmlnode.attrib['name']
is_abstract = bool(xmlnode.attrib.get('abstract', False))
(get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
- node = GLibObject(self._transformer.strip_identifier_or_warn(type_name, fatal=True),
- None,
- type_name,
- get_type, c_symbol_prefix, is_abstract)
+ node = glibast.GLibObject(
+ self._transformer.strip_identifier_or_warn(type_name, fatal=True),
+ None,
+ type_name,
+ get_type, c_symbol_prefix, is_abstract)
self._parse_parents(xmlnode, node)
node.fundamental = True
self._introspect_implemented_interfaces(node, xmlnode)
@@ -401,11 +396,11 @@ blob containing data gleaned from GObject's primitive introspection."""
def _add_record_fields(self, node):
# add record fields
record = self._namespace.get(node.name)
- if not isinstance(record, Record):
+ if not isinstance(record, ast.Record):
return
node.fields = record.fields
for field in node.fields:
- if isinstance(field, Field):
+ if isinstance(field, ast.Field):
# Object instance fields are assumed to be read-only
# (see also _find_class_record and transformer.py)
field.writable = False
@@ -414,17 +409,17 @@ blob containing data gleaned from GObject's primitive introspection."""
name = self._transformer.strip_identifier_or_warn(boxed.type_name, fatal=True)
pair_node = self._namespace.get(name)
if not pair_node:
- boxed_item = GLibBoxedOther(name, boxed.type_name,
+ boxed_item = glibast.GLibBoxedOther(name, boxed.type_name,
boxed.get_type,
boxed.c_symbol_prefix)
- elif isinstance(pair_node, Record):
- boxed_item = GLibBoxedStruct(pair_node.name, boxed.type_name,
+ elif isinstance(pair_node, ast.Record):
+ boxed_item = glibast.GLibBoxedStruct(pair_node.name, boxed.type_name,
boxed.get_type,
boxed.c_symbol_prefix)
boxed_item.inherit_file_positions(pair_node)
boxed_item.fields = pair_node.fields
- elif isinstance(pair_node, Union):
- boxed_item = GLibBoxedUnion(pair_node.name, boxed.type_name,
+ elif isinstance(pair_node, ast.Union):
+ boxed_item = glibast.GLibBoxedUnion(pair_node.name, boxed.type_name,
boxed.get_type,
boxed.c_symbol_prefix)
boxed_item.inherit_file_positions(pair_node)
@@ -444,17 +439,17 @@ blob containing data gleaned from GObject's primitive introspection."""
def _find_class_record(self, cls):
pair_record = None
- if isinstance(cls, Class):
+ if isinstance(cls, ast.Class):
pair_record = self._namespace.get(cls.name + 'Class')
else:
for suffix in ('Iface', 'Interface'):
pair_record = self._namespace.get(cls.name + suffix)
if pair_record:
break
- if not (pair_record and isinstance(pair_record, Record)):
+ if not (pair_record and isinstance(pair_record, ast.Record)):
return
- gclass_struct = GLibRecord.from_record(pair_record)
+ gclass_struct = glibast.GLibRecord.from_record(pair_record)
self._namespace.append(gclass_struct, replace=True)
cls.glib_type_struct = gclass_struct.create_type()
cls.inherit_file_positions(pair_record)
diff --git a/giscanner/primarytransformer.py b/giscanner/primarytransformer.py
index 4248690..1dda3c4 100644
--- a/giscanner/primarytransformer.py
+++ b/giscanner/primarytransformer.py
@@ -17,29 +17,21 @@
# Boston, MA 02111-1307, USA.
#
-import os
-import sys
import re
-import tempfile
-import shutil
-import subprocess
-from .ast import *
+from . import ast
+from . import glibast
from .annotationparser import (TAG_VFUNC, TAG_SINCE, TAG_DEPRECATED, TAG_RETURNS,
TAG_ATTRIBUTES, TAG_RENAME_TO, TAG_TYPE, TAG_TRANSFER,
TAG_UNREF_FUNC, TAG_REF_FUNC, TAG_SET_VALUE_FUNC,
TAG_GET_VALUE_FUNC)
from .annotationparser import (OPT_ALLOW_NONE,
OPT_ARRAY, OPT_ELEMENT_TYPE, OPT_IN, OPT_INOUT,
- OPT_INOUT_ALT, OPT_OUT, OPT_SCOPE, OPT_TRANSFER,
+ OPT_INOUT_ALT, OPT_OUT, OPT_SCOPE,
OPT_TYPE, OPT_CLOSURE, OPT_DESTROY, OPT_SKIP,
- OPT_FOREIGN, OPT_VAL_BITFIELD, OPT_ARRAY_FIXED_SIZE,
- OPT_ARRAY_LENGTH, OPT_ARRAY_ZERO_TERMINATED,
- OPT_SCOPE_ASYNC, OPT_SCOPE_CALL, OPT_SCOPE_NOTIFIED)
-from .annotationparser import Option, AnnotationParser
-from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember, GLibFlags,
- GLibInterface, GLibObject, GLibSignal, GLibBoxedStruct,
- GLibBoxedUnion, GLibBoxedOther, GLibRecord)
+ OPT_FOREIGN, OPT_ARRAY_FIXED_SIZE,
+ OPT_ARRAY_LENGTH, OPT_ARRAY_ZERO_TERMINATED)
+from .annotationparser import AnnotationParser
from .utils import to_underscores, to_underscores_noprefix
class PrimaryTransformer(object):
@@ -71,17 +63,17 @@ class PrimaryTransformer(object):
# Generate a reverse mapping "bar_baz" -> BarBaz
for node in self._namespace.itervalues():
- if isinstance(node, (Class, Interface, GLibBoxed)):
+ if isinstance(node, (ast.Class, ast.Interface, glibast.GLibBoxed)):
self._uscore_type_names[node.c_symbol_prefix] = node
- elif isinstance(node, (Record, Union)):
+ elif isinstance(node, (ast.Record, ast.Union)):
uscored = to_underscores_noprefix(node.name).lower()
self._uscore_type_names[uscored] = node
for node in list(self._namespace.itervalues()):
- if isinstance(node, Function):
+ if isinstance(node, ast.Function):
# Discover which toplevel functions are actually methods
self._pair_function(node)
- if isinstance(node, (Class, Interface)):
+ if isinstance(node, (ast.Class, ast.Interface)):
self._pair_class_virtuals(node)
# Some annotations need to be post function pairing
@@ -111,7 +103,7 @@ class PrimaryTransformer(object):
def _get_parameter_index(self, parent, param_name, origin):
index = parent.get_parameter_index(param_name)
if index is None:
- if isinstance(origin, Parameter):
+ if isinstance(origin, ast.Parameter):
origin_name = 'parameter %s' % (origin.argname, )
else:
origin_name = 'return value'
@@ -131,23 +123,23 @@ class PrimaryTransformer(object):
target = self._namespace.get_by_symbol(rename_to)
if not target:
self._transformer.log_node_warning(node,
- "Can't find symbol %r referenced by Rename annotation" % (rename_to, ))
+"Can't find symbol %r referenced by Rename annotation" % (rename_to, ))
elif target.shadowed_by:
self._transformer.log_node_warning(node,
- "Function %r already shadowed by %r, can't overwrite with %r" % (target.symbol,
- target.shadowed_by,
- rename_to))
+"Function %r already shadowed by %r, can't overwrite with %r" % (target.symbol,
+ target.shadowed_by,
+ rename_to))
elif target.shadows:
self._transformer.log_node_warning(node,
- "Function %r already shadows %r, can't multiply shadow with %r" % (target.symbol,
- target.shadows,
- rename_to))
+"Function %r already shadows %r, can't multiply shadow with %r" % (target.symbol,
+ target.shadows,
+ rename_to))
else:
target.shadows = node.symbol
node.shadowed_by = target.symbol
def _pass_callable_defaults(self, node, chain):
- if isinstance(node, (Callable, GLibSignal)):
+ if isinstance(node, (ast.Callable, glibast.GLibSignal)):
for param in node.parameters:
if param.transfer is None:
param.transfer = self._get_transfer_default(node, param)
@@ -158,25 +150,26 @@ class PrimaryTransformer(object):
def _pass_read_annotations(self, node, chain):
if not node.namespace:
return False
- if isinstance(node, Function):
+ if isinstance(node, ast.Function):
self._apply_annotations_function(node, chain)
- if isinstance(node, Callback):
+ if isinstance(node, ast.Callback):
block = self._blocks.get(node.c_name)
self._apply_annotations_callable(node, chain, block)
- if isinstance(node, (Class, Interface, Record, Union, Enum, Bitfield,
- Callback)):
+ if isinstance(node, (ast.Class, ast.Interface, ast.Record,
+ ast.Union, ast.Enum, ast.Bitfield,
+ ast.Callback)):
block = self._blocks.get(node.c_name)
self._apply_annotations_annotated(node, block)
- if isinstance(node, (Class, Interface, Record, Union)):
+ if isinstance(node, (ast.Class, ast.Interface, ast.Record, ast.Union)):
for field in node.fields:
self._blocks.get('%s::%s' % (node.c_name, field.name))
self._apply_annotations_field(node, block, field)
- if isinstance(node, (Class, Interface)):
+ if isinstance(node, (ast.Class, ast.Interface)):
for prop in node.properties:
self._apply_annotations_property(node, prop)
for sig in node.signals:
self._apply_annotations_signal(node, sig)
- if isinstance(node, Class):
+ if isinstance(node, ast.Class):
block = self._blocks.get(node.c_name)
if block:
tag = block.get(TAG_UNREF_FUNC)
@@ -230,11 +223,12 @@ class PrimaryTransformer(object):
def combiner(base, *rest):
if not rest:
return base
- if isinstance(base, List) and len(rest) == 1:
- return List(base.name, *rest)
- if isinstance(base, Map) and len(rest) == 2:
- return Map(*rest)
- self._transformer.log_warning("Too many parameters in type specification %r" % (type_str, ))
+ if isinstance(base, ast.List) and len(rest) == 1:
+ return ast.List(base.name, *rest)
+ if isinstance(base, ast.Map) and len(rest) == 2:
+ return ast.Map(*rest)
+ self._transformer.log_warning(
+"Too many parameters in type specification %r" % (type_str, ))
return base
def top_combiner(base, *rest):
if orig_node is not None:
@@ -243,7 +237,8 @@ class PrimaryTransformer(object):
result, rest = grab_one(type_str, resolver, top_combiner, combiner)
if rest:
- self._transformer.log_warning("Trailing components in type specification %r" % (type_str, ))
+ self._transformer.log_warning(
+"Trailing components in type specification %r" % (type_str, ))
return result
def _apply_annotations_array(self, parent, node, options):
@@ -256,7 +251,7 @@ class PrimaryTransformer(object):
element_type = options.get(OPT_ELEMENT_TYPE)
if element_type is not None:
element_type_node = self._resolve(element_type.one())
- elif isinstance(node.type, Array):
+ elif isinstance(node.type, ast.Array):
element_type_node = node.type.element_type
else:
# We're assuming here that Foo* with an (array) annotation
@@ -265,11 +260,11 @@ class PrimaryTransformer(object):
# Explicitly erase ctype since it's no longer valid
element_type_node.ctype = None
- if isinstance(node.type, Array):
+ if isinstance(node.type, ast.Array):
array_type = node.type.array_type
else:
array_type = None
- container_type = Array(array_type, element_type_node,
+ container_type = ast.Array(array_type, element_type_node,
ctype=node.type.ctype,
is_const=node.type.is_const)
if OPT_ARRAY_ZERO_TERMINATED in array_values:
@@ -280,8 +275,8 @@ class PrimaryTransformer(object):
param_index = self._get_parameter_index(parent, length, node)
param = parent.parameters[param_index]
param.direction = node.direction
- if param.direction == PARAM_DIRECTION_OUT:
- param.transfer = PARAM_TRANSFER_FULL
+ if param.direction == ast.PARAM_DIRECTION_OUT:
+ param.transfer = ast.PARAM_TRANSFER_FULL
container_type.length_param_index = param_index
fixed = array_values.get(OPT_ARRAY_FIXED_SIZE)
if fixed:
@@ -291,35 +286,35 @@ class PrimaryTransformer(object):
def _apply_annotations_element_type(self, parent, node, options):
element_type_opt = options.get(OPT_ELEMENT_TYPE)
element_type = element_type_opt.flat()
- if isinstance(node.type, List):
+ if isinstance(node.type, ast.List):
assert len(element_type) == 1
node.type.element_type = self._resolve(element_type[0])
- elif isinstance(node.type, Map):
+ elif isinstance(node.type, ast.Map):
assert len(element_type) == 2
node.type.key_type = self._resolve(element_type[0])
node.type.value_type = self._resolve(element_type[1])
- elif isinstance(node.type, Array):
+ elif isinstance(node.type, ast.Array):
node.type.element_type = self._resolve(element_type[0])
else:
self._transformer.log_node_warning(parent,
"Unknown container %r for element-type annotation" % (node.type, ))
def _get_transfer_default_param(self, parent, node):
- if node.direction in [PARAM_DIRECTION_INOUT,
- PARAM_DIRECTION_OUT]:
+ if node.direction in [ast.PARAM_DIRECTION_INOUT,
+ ast.PARAM_DIRECTION_OUT]:
if node.caller_allocates:
- return PARAM_TRANSFER_NONE
- return PARAM_TRANSFER_FULL
- return PARAM_TRANSFER_NONE
+ return ast.PARAM_TRANSFER_NONE
+ return ast.PARAM_TRANSFER_FULL
+ return ast.PARAM_TRANSFER_NONE
def _get_transfer_default_returntype_basic(self, typeval):
- if (typeval.is_equiv(BASIC_GIR_TYPES)
+ if (typeval.is_equiv(ast.BASIC_GIR_TYPES)
or typeval.is_const
- or typeval.is_equiv(TYPE_NONE)):
- return PARAM_TRANSFER_NONE
- elif typeval.is_equiv(TYPE_STRING):
+ or typeval.is_equiv(ast.TYPE_NONE)):
+ return ast.PARAM_TRANSFER_NONE
+ elif typeval.is_equiv(ast.TYPE_STRING):
# Non-const strings default to FULL
- return PARAM_TRANSFER_FULL
+ return ast.PARAM_TRANSFER_FULL
elif typeval.target_fundamental:
# This looks like just GType right now
return None
@@ -332,26 +327,26 @@ class PrimaryTransformer(object):
return basic
if typeval.target_giname:
target = self._transformer.lookup_typenode(typeval)
- if isinstance(target, Alias):
+ if isinstance(target, ast.Alias):
return self._get_transfer_default_returntype_basic(target.target)
- elif isinstance(target, GLibBoxed):
- return PARAM_TRANSFER_FULL
- elif isinstance(target, (Enum, Bitfield)):
- return PARAM_TRANSFER_NONE
+ elif isinstance(target, glibast.GLibBoxed):
+ return ast.PARAM_TRANSFER_FULL
+ elif isinstance(target, (ast.Enum, ast.Bitfield)):
+ return ast.PARAM_TRANSFER_NONE
# Handle constructors specially here
- elif isinstance(parent, Function) and parent.is_constructor:
- if isinstance(target, Class):
- initially_unowned_type = Type(target_giname='GObject.InitiallyUnowned')
+ elif isinstance(parent, ast.Function) and parent.is_constructor:
+ if isinstance(target, ast.Class):
+ initially_unowned_type = ast.Type(target_giname='GObject.InitiallyUnowned')
initially_unowned = self._transformer.lookup_typenode(initially_unowned_type)
if initially_unowned and self._is_gi_subclass(typeval, initially_unowned_type):
- return PARAM_TRANSFER_NONE
+ return ast.PARAM_TRANSFER_NONE
else:
- return PARAM_TRANSFER_FULL
- elif isinstance(target, (Record, Union)):
- return PARAM_TRANSFER_FULL
+ return ast.PARAM_TRANSFER_FULL
+ elif isinstance(target, (ast.Record, ast.Union)):
+ return ast.PARAM_TRANSFER_FULL
else:
assert False, "Invalid constructor"
- elif isinstance(target, (Class, Record, Union)):
+ elif isinstance(target, (ast.Class, ast.Record, ast.Union)):
# Explicitly no default for these
return None
else:
@@ -359,16 +354,16 @@ class PrimaryTransformer(object):
return None
def _get_transfer_default(self, parent, node):
- if node.type.is_equiv(TYPE_NONE) or isinstance(node.type, Varargs):
- return PARAM_TRANSFER_NONE
- elif isinstance(node, Parameter):
+ if node.type.is_equiv(ast.TYPE_NONE) or isinstance(node.type, ast.Varargs):
+ return ast.PARAM_TRANSFER_NONE
+ elif isinstance(node, ast.Parameter):
return self._get_transfer_default_param(parent, node)
- elif isinstance(node, Return):
+ elif isinstance(node, ast.Return):
return self._get_transfer_default_return(parent, node)
- elif isinstance(node, Field):
- return PARAM_TRANSFER_NONE
- elif isinstance(node, Property):
- return PARAM_TRANSFER_NONE
+ elif isinstance(node, ast.Field):
+ return ast.PARAM_TRANSFER_NONE
+ elif isinstance(node, ast.Property):
+ return ast.PARAM_TRANSFER_NONE
else:
raise AssertionError(node)
@@ -383,12 +378,12 @@ class PrimaryTransformer(object):
annotated_direction = None
if (OPT_INOUT in options or
OPT_INOUT_ALT in options):
- annotated_direction = PARAM_DIRECTION_INOUT
+ annotated_direction = ast.PARAM_DIRECTION_INOUT
elif OPT_OUT in options:
subtype = options[OPT_OUT]
if subtype is not None:
subtype = subtype.one()
- annotated_direction = PARAM_DIRECTION_OUT
+ annotated_direction = ast.PARAM_DIRECTION_OUT
if subtype in (None, ''):
if node.type.target_giname and node.type.ctype:
caller_allocates = '**' not in node.type.ctype
@@ -399,10 +394,10 @@ class PrimaryTransformer(object):
elif subtype == 'callee-allocates':
caller_allocates = False
else:
- raise InvalidAnnotationError(
- "out allocation for %s is invalid (%r)" % (node, subtype))
+ self._transformer.log_warning(
+"out allocation for %s is invalid (%r)" % (node, subtype), fatal=True)
elif OPT_IN in options:
- annotated_direction = PARAM_DIRECTION_IN
+ annotated_direction = ast.PARAM_DIRECTION_IN
if (annotated_direction is not None) and (annotated_direction != node.direction):
node.direction = annotated_direction
@@ -469,17 +464,18 @@ class PrimaryTransformer(object):
options = tag.options
else:
options = {}
- if isinstance(parent, Function):
+ if isinstance(parent, ast.Function):
scope = options.get(OPT_SCOPE)
if scope:
scope = scope.one()
- if scope not in [PARAM_SCOPE_CALL,
- PARAM_SCOPE_ASYNC,
- PARAM_SCOPE_NOTIFIED]:
- self._transformer.log_warning(parent, "Invalid scope %r for parameter %r" % (scope, param.name))
+ if scope not in [ast.PARAM_SCOPE_CALL,
+ ast.PARAM_SCOPE_ASYNC,
+ ast.PARAM_SCOPE_NOTIFIED]:
+ self._transformer.log_warning(parent,
+"Invalid scope %r for parameter %r" % (scope, param.name))
else:
param.scope = scope
- param.transfer = PARAM_TRANSFER_NONE
+ param.transfer = ast.PARAM_TRANSFER_NONE
destroy = options.get(OPT_DESTROY)
if destroy:
@@ -487,13 +483,13 @@ class PrimaryTransformer(object):
param.destroy_index = self._get_parameter_index(parent,
destroy_name,
param)
- param.scope = PARAM_SCOPE_NOTIFIED
+ param.scope = ast.PARAM_SCOPE_NOTIFIED
if param.destroy_index >= 0:
destroy_param = parent.parameters[param.destroy_index]
# This is technically bogus; we're setting the scope on the destroy
# itself. But this helps avoid tripping a warning from finaltransformer,
# since we don't have a way right now to flag this callback a destroy.
- destroy_param.scope = PARAM_SCOPE_NOTIFIED
+ destroy_param.scope = ast.PARAM_SCOPE_NOTIFIED
self._fixup_param_destroy(parent, param)
closure = options.get(OPT_CLOSURE)
if closure:
@@ -501,7 +497,7 @@ class PrimaryTransformer(object):
closure.one(),
param)
self._fixup_param_closure(parent, param)
- elif isinstance(parent, Callback):
+ elif isinstance(parent, ast.Callback):
if OPT_CLOSURE in options:
# For callbacks, (closure) appears without an
# argument, and tags a parameter that is a closure. We
@@ -542,8 +538,9 @@ class PrimaryTransformer(object):
if param.argname == tag:
break
else:
- self._transformer.log_warning("""Annotation for '%s' refers to unknown argument '%s'"""
- % (parent.name, tag))
+ self._transformer.log_warning(
+"Annotation for '%s' refers to unknown argument '%s'"
+% (parent.name, tag))
def _apply_annotations_field(self, parent, block, field):
if not block:
@@ -594,7 +591,7 @@ class PrimaryTransformer(object):
self._apply_annotations_return(signal, signal.retval, block)
def _pass_read_annotations2(self, node, chain):
- if isinstance(node, Function):
+ if isinstance(node, ast.Function):
self._apply_annotations2_function(node, chain)
return True
@@ -617,25 +614,25 @@ class PrimaryTransformer(object):
self._apply_annotations_callable(vfunc, [parent], block)
break
if not matched:
- self._transformer.log_symbol_warning(meth.symbol,
+ self._transformer.log_symbol_warning(node.symbol,
"Virtual slot %r not found for %r annotation" % (invoker_name, TAG_VFUNC))
def _pass_type_resolution(self, node, chain):
- if isinstance(node, Alias):
+ if isinstance(node, ast.Alias):
self._transformer.resolve_type(node.target)
- if isinstance(node, Callable):
+ if isinstance(node, ast.Callable):
for parameter in node.parameters:
self._transformer.resolve_type(parameter.type)
self._transformer.resolve_type(node.retval.type)
- if isinstance(node, Constant):
+ if isinstance(node, ast.Constant):
self._transformer.resolve_type(node.value_type)
- if isinstance(node, (Class, Interface, Record, Union)):
+ if isinstance(node, (ast.Class, ast.Interface, ast.Record, ast.Union)):
for field in node.fields:
if field.anonymous_node:
pass
else:
self._transformer.resolve_type(field.type)
- if isinstance(node, (Class, Interface)):
+ if isinstance(node, (ast.Class, ast.Interface)):
resolved_parent = None
for parent in node.parent_chain:
try:
@@ -651,10 +648,10 @@ class PrimaryTransformer(object):
for sig in node.signals:
for param in sig.parameters:
self._transformer.resolve_type(param.type)
- if isinstance(node, Class):
+ if isinstance(node, ast.Class):
for iface in node.interfaces:
self._transformer.resolve_type(iface)
- if isinstance(node, Interface):
+ if isinstance(node, ast.Interface):
for iface in node.prerequisites:
self._transformer.resolve_type(iface)
return True
@@ -666,7 +663,7 @@ class PrimaryTransformer(object):
# Create a fallback mapping based on all known enums in this module.
uscore_enums = {}
for enum in self._namespace.itervalues():
- if not isinstance(enum, Enum):
+ if not isinstance(enum, ast.Enum):
continue
type_name = enum.symbol
uscored = to_underscores(type_name).lower()
@@ -678,7 +675,7 @@ class PrimaryTransformer(object):
uscore_enums[no_uscore_prefixed] = enum
for node in self._namespace.itervalues():
- if not isinstance(node, Function):
+ if not isinstance(node, ast.Function):
continue
if node.retval.type.target_giname != 'GLib.Quark':
continue
@@ -703,7 +700,7 @@ function searches through the namespace for the longest type which
prefixes uscored, and returns (type, suffix). Example, assuming
namespace Gtk, type is TextBuffer:
-_split_uscored_by_type(text_buffer_try_new) -> (Class(TextBuffer), 'try_new')"""
+_split_uscored_by_type(text_buffer_try_new) -> (ast.Class(TextBuffer), 'try_new')"""
node = None
count = 0
prev_split_count = -1
@@ -742,7 +739,9 @@ method or constructor of some type."""
return False
first = func.parameters[0]
target = self._transformer.lookup_typenode(first.type)
- if not isinstance(target, (Class, Interface, Record, Union, GLibBoxedOther)):
+ if not isinstance(target, (ast.Class, ast.Interface,
+ ast.Record, ast.Union,
+ glibast.GLibBoxedOther)):
return False
uscored = self._uscored_identifier_for_type(first.type)
if not subsymbol.startswith(uscored):
@@ -760,7 +759,8 @@ method or constructor of some type."""
if split is None:
return False
(node, funcname) = split
- if not isinstance(node, (Class, Interface, Record, Union, GLibBoxedOther)):
+ if not isinstance(node, (ast.Class, ast.Interface,
+ ast.Record, ast.Union, glibast.GLibBoxedOther)):
return False
self._namespace.float(func)
func.name = funcname
@@ -770,7 +770,7 @@ method or constructor of some type."""
if not (func.symbol.find('_new_') >= 0 or func.symbol.endswith('_new')):
return False
target = self._transformer.lookup_typenode(func.retval.type)
- if not isinstance(target, (Class, Record, Union, GLibBoxedOther)):
+ if not isinstance(target, (ast.Class, ast.Record, ast.Union, glibast.GLibBoxedOther)):
return False
new_idx = func.symbol.rfind('_new')
assert (new_idx >= 0)
@@ -782,7 +782,7 @@ method or constructor of some type."""
"Can't find matching type for constructor; symbol=%r" % (func.symbol, ))
return False
(origin_node, funcname) = split
- if isinstance(target, Class):
+ if isinstance(target, ast.Class):
parent = origin_node
while parent:
if parent == target:
@@ -793,12 +793,14 @@ method or constructor of some type."""
parent = None
if parent is None:
self._transformer.log_node_warning(func,
- "Return value is not superclass for constructor; symbol=%r constructed=%r return=%r" % (func.symbol, str(origin_node.create_type()), str(func.retval.type)))
+"Return value is not superclass for constructor; symbol=%r constructed=%r return=%r"
+% (func.symbol, str(origin_node.create_type()), str(func.retval.type)))
return False
else:
if origin_node != target:
self._transformer.log_node_warning(func,
- "Constructor return type mismatch symbol=%r constructed=%r return=%r" % (func.symbol, str(origin_node.create_type()), str(func.retval.type)))
+"Constructor return type mismatch symbol=%r constructed=%r return=%r"
+% (func.symbol, str(origin_node.create_type()), str(func.retval.type)))
return False
self._namespace.float(func)
func.name = funcname
@@ -822,7 +824,7 @@ method or constructor of some type."""
# Object class fields are assumed to be read-only
# (see also _introspect_object and transformer.py)
for field in class_struct.fields:
- if isinstance(field, Field):
+ if isinstance(field, ast.Field):
field.writable = False
# Loop through fields to determine which are virtual
@@ -830,7 +832,7 @@ method or constructor of some type."""
# assuming everything that doesn't share a name
# with a known signal is a virtual slot.
for field in class_struct.fields:
- if not isinstance(field.anonymous_node, Callback):
+ if not isinstance(field.anonymous_node, ast.Callback):
continue
callback = field.anonymous_node
# Check the first parameter is the object
@@ -848,7 +850,7 @@ method or constructor of some type."""
break
if matched_signal:
continue
- vfunc = VFunction.from_callback(callback)
+ vfunc = ast.VFunction.from_callback(callback)
vfunc.inherit_file_positions(callback)
node.virtual_methods.append(vfunc)
@@ -877,7 +879,7 @@ method or constructor of some type."""
def _pass3(self, node, chain):
"""Pass 3 is after we've loaded GType data and performed type
closure."""
- if isinstance(node, Callable):
+ if isinstance(node, ast.Callable):
self._pass3_callable_callbacks(node)
self._pass3_callable_throws(node)
return True
@@ -891,17 +893,17 @@ method or constructor of some type."""
# First, do defaults for well-known callback types
for i, param in enumerate(params):
argnode = self._transformer.lookup_typenode(param.type)
- if isinstance(argnode, Callback):
+ if isinstance(argnode, ast.Callback):
if param.type.target_giname in ('Gio.AsyncReadyCallback',
'GLib.DestroyNotify'):
- param.scope = PARAM_SCOPE_ASYNC
- param.transfer = PARAM_TRANSFER_NONE
+ param.scope = ast.PARAM_SCOPE_ASYNC
+ param.transfer = ast.PARAM_TRANSFER_NONE
callback_param = None
for i, param in enumerate(params):
argnode = self._transformer.lookup_typenode(param.type)
is_destroynotify = False
- if isinstance(argnode, Callback):
+ if isinstance(argnode, ast.Callback):
if param.type.target_giname == 'GLib.DestroyNotify':
is_destroynotify = True
else:
@@ -911,9 +913,9 @@ method or constructor of some type."""
continue
if is_destroynotify:
callback_param.destroy_index = i
- callback_param.scope = PARAM_SCOPE_NOTIFIED
- callback_param.transfer = PARAM_TRANSFER_NONE
- elif (param.type.is_equiv(TYPE_ANY) and
+ callback_param.scope = ast.PARAM_SCOPE_NOTIFIED
+ callback_param.transfer = ast.PARAM_TRANSFER_NONE
+ elif (param.type.is_equiv(ast.TYPE_ANY) and
param.argname.endswith('data')):
callback_param.closure_index = i
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index 9cd1003..daa5a9a 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -31,7 +31,7 @@ from giscanner.ast import Include
from giscanner.cachestore import CacheStore
from giscanner.dumper import compile_introspection_binary
from giscanner.glibtransformer import GLibTransformer, IntrospectionBinary
-from giscanner.minixpath import myxpath, xpath_assert
+from giscanner.minixpath import xpath_assert
from giscanner.sourcescanner import SourceScanner
from giscanner.shlibs import resolve_shlibs
from giscanner.transformer import Transformer
@@ -94,7 +94,9 @@ def _get_option_parser():
help="version of namespace for this unit")
parser.add_option("", "--identifier-prefix",
action="append", dest="identifier_prefixes", default=[],
- help="Remove this prefix from C identifiers (structure typedefs, etc.). May be specified multiple times. This is also used as the default for --symbol-prefix if the latter is not specified.")
+ help="""Remove this prefix from C identifiers (structure typedefs, etc.).
+May be specified multiple times. This is also used as the default for --symbol-prefix if
+the latter is not specified.""")
parser.add_option("", "--symbol-prefix",
action="append", dest="symbol_prefixes", default=[],
help="Remove this prefix from C symbols (function names)")
@@ -349,7 +351,8 @@ def scanner_main(args):
passthrough_gir(main_temppath, temp_f)
temp_f.close()
if not files_are_identical(main_temppath, tempgir_path):
- raise SystemExit("Failed to re-parse .gir file; scanned=%r passthrough=%r" % (main_temppath, tempgir_path))
+ raise SystemExit(
+"Failed to re-parse .gir file; scanned=%r passthrough=%r" % (main_temppath, tempgir_path))
os.unlink(tempgir_path)
os.rename(main_temppath, options.output)
else:
diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py
index 49bbe78..a2db2e7 100644
--- a/giscanner/sourcescanner.py
+++ b/giscanner/sourcescanner.py
@@ -158,7 +158,7 @@ class SourceSymbol(object):
if src:
line = self.line
if line:
- src += ':%r' % (line,)
+ src += ':%r' % (line, )
return '<%s type=%r ident=%r src=%r>' % (
self.__class__.__name__,
symbol_type_name(self.type),
diff --git a/giscanner/testcodegen.py b/giscanner/testcodegen.py
index 7fee6ee..9155c4c 100644
--- a/giscanner/testcodegen.py
+++ b/giscanner/testcodegen.py
@@ -18,21 +18,19 @@
# Boston, MA 02111-1307, USA.
#
-import os, sys
from StringIO import StringIO
-from contextlib import contextmanager
-from .ast import *
-from .glibast import *
+from . import ast
from .codegen import CCodeGenerator
-INTROSPECTABLE_BASIC = filter(lambda x: x not in (TYPE_NONE, TYPE_ANY,
- TYPE_LONG_LONG, TYPE_LONG_ULONG,
- TYPE_LONG_DOUBLE, TYPE_VALIST), GIR_TYPES)
+INTROSPECTABLE_BASIC = filter(lambda x: x not in (
+ ast.TYPE_NONE, ast.TYPE_ANY,
+ ast.TYPE_LONG_LONG, ast.TYPE_LONG_ULONG,
+ ast.TYPE_LONG_DOUBLE, ast.TYPE_VALIST), ast.GIR_TYPES)
-DEFAULT_C_VALUES = {TYPE_ANY: 'NULL',
- TYPE_STRING: '""',
- TYPE_FILENAME: '""',
- TYPE_GTYPE: 'g_object_get_type ()'}
+DEFAULT_C_VALUES = {ast.TYPE_ANY: 'NULL',
+ ast.TYPE_STRING: '""',
+ ast.TYPE_FILENAME: '""',
+ ast.TYPE_GTYPE: 'g_object_get_type ()'}
def get_default_for_typeval(typeval):
default = DEFAULT_C_VALUES.get(typeval)
@@ -51,13 +49,13 @@ def uscore_from_type(typeval):
class EverythingCodeGenerator(object):
def __init__(self, out_h_filename, out_c_filename):
- self.namespace = Namespace('Everything', '1.0')
+ self.namespace = ast.Namespace('Everything', '1.0')
self.gen = CCodeGenerator(self.namespace, out_h_filename, out_c_filename)
def write(self):
-
- func = Function('nullfunc', Return(TYPE_NONE, transfer=PARAM_TRANSFER_NONE),
- [], False, self.gen.gen_symbol('nullfunc'))
+ func = ast.Function('nullfunc',
+ ast.Return(ast.TYPE_NONE, transfer=ast.PARAM_TRANSFER_NONE),
+ [], False, self.gen.gen_symbol('nullfunc'))
self.namespace.append(func)
body = " return;\n"
self.gen.set_function_body(func, body)
@@ -67,8 +65,9 @@ class EverythingCodeGenerator(object):
for typeval in INTROSPECTABLE_BASIC:
name = prefix + uscore_from_type(typeval)
sym = self.gen.gen_symbol(name)
- func = Function(name, Return(typeval, transfer=PARAM_TRANSFER_NONE),
- [], False, sym)
+ func = ast.Function(name,
+ ast.Return(typeval, transfer=ast.PARAM_TRANSFER_NONE),
+ [], False, sym)
self.namespace.append(func)
default = get_default_for_typeval(typeval)
body = " return %s;\n" % (default, )
@@ -77,26 +76,28 @@ class EverythingCodeGenerator(object):
# Void return, one parameter
prefix = 'oneparam '
for typeval in INTROSPECTABLE_BASIC:
- if typeval is TYPE_NONE:
+ if typeval is ast.TYPE_NONE:
continue
name = prefix + uscore_from_type(typeval)
sym = self.gen.gen_symbol(name)
- func = Function(name, Return(TYPE_NONE, transfer=PARAM_TRANSFER_NONE),
- [Parameter('arg0', typeval, transfer=PARAM_TRANSFER_NONE,
- direction=PARAM_DIRECTION_IN)], False, sym)
+ func = ast.Function(name,
+ ast.Return(ast.TYPE_NONE, transfer=ast.PARAM_TRANSFER_NONE),
+ [ast.Parameter('arg0', typeval, transfer=ast.PARAM_TRANSFER_NONE,
+ direction=ast.PARAM_DIRECTION_IN)], False, sym)
self.namespace.append(func)
self.gen.set_function_body(func, " return;\n")
# Void return, one (out) parameter
prefix = 'one_outparam '
for typeval in INTROSPECTABLE_BASIC:
- if typeval is TYPE_NONE:
+ if typeval is ast.TYPE_NONE:
continue
name = prefix + uscore_from_type(typeval)
sym = self.gen.gen_symbol(name)
- func = Function(name, Return(TYPE_NONE, transfer=PARAM_TRANSFER_NONE),
- [Parameter('arg0', typeval, transfer=PARAM_TRANSFER_NONE,
- direction=PARAM_DIRECTION_OUT)], False, sym)
+ func = ast.Function(name,
+ ast.Return(ast.TYPE_NONE, transfer=ast.PARAM_TRANSFER_NONE),
+ [ast.Parameter('arg0', typeval, transfer=ast.PARAM_TRANSFER_NONE,
+ direction=ast.PARAM_DIRECTION_OUT)], False, sym)
self.namespace.append(func)
body = StringIO('w')
default = get_default_for_typeval(func.retval)
@@ -107,13 +108,13 @@ class EverythingCodeGenerator(object):
# Passthrough one parameter
prefix = 'passthrough_one '
for typeval in INTROSPECTABLE_BASIC:
- if typeval is TYPE_NONE:
+ if typeval is ast.TYPE_NONE:
continue
name = prefix + uscore_from_type(typeval)
sym = self.gen.gen_symbol(name)
- func = Function(name, Return(typeval, transfer=PARAM_TRANSFER_NONE),
- [Parameter('arg0', typeval, transfer=PARAM_TRANSFER_NONE,
- direction=PARAM_DIRECTION_IN)], False, sym)
+ func = ast.Function(name, ast.Return(typeval, transfer=ast.PARAM_TRANSFER_NONE),
+ [ast.Parameter('arg0', typeval, transfer=ast.PARAM_TRANSFER_NONE,
+ direction=ast.PARAM_DIRECTION_IN)], False, sym)
self.namespace.append(func)
body = StringIO('w')
default = get_default_for_typeval(func.retval)
@@ -121,4 +122,3 @@ class EverythingCodeGenerator(object):
self.gen.set_function_body(func, body.getvalue())
self.gen.codegen()
-
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 1596ca1..7f5fa12 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -22,14 +22,9 @@ import os
import sys
import re
-from .ast import (Bitfield, Callback, Enum, Function, Namespace, Member,
- Parameter, Return, Record, Field,
- Type, Array, List, Map, Alias, Interface, Class, Node, Union,
- Varargs, Constant, type_names, basic_type_names,
- TYPE_STRING, TYPE_ANY, TYPE_INT, TYPE_DOUBLE)
+from . import ast
from .config import DATADIR, GIR_DIR, GIR_SUFFIX
from .girparser import GIRParser
-from .odict import odict
from .sourcescanner import (
SourceSymbol, ctype_name, CTYPE_POINTER,
CTYPE_BASIC_TYPE, CTYPE_UNION, CTYPE_ARRAY, CTYPE_TYPEDEF,
@@ -38,7 +33,6 @@ from .sourcescanner import (
CSYMBOL_TYPE_ENUM, CSYMBOL_TYPE_UNION, CSYMBOL_TYPE_OBJECT,
CSYMBOL_TYPE_MEMBER, CSYMBOL_TYPE_ELLIPSIS, CSYMBOL_TYPE_CONST,
TYPE_QUALIFIER_CONST)
-from .utils import to_underscores
class TypeResolutionException(Exception):
pass
@@ -56,7 +50,7 @@ class Transformer(object):
self._cwd = os.getcwd() + os.sep
self._cachestore = cachestore
self.generator = None
- self._namespace = Namespace(namespace_name, namespace_version,
+ self._namespace = ast.Namespace(namespace_name, namespace_version,
identifier_prefixes=identifier_prefixes,
symbol_prefixes=symbol_prefixes)
self._pkg_config_packages = set()
@@ -88,7 +82,7 @@ class Transformer(object):
# handle #ifdef. But this introduces an arch-dependency in the .gir
# file. So far this has only come up scanning glib - in theory, other
# modules will just depend on that.
- if isinstance(original, Constant) and isinstance(node, Constant):
+ if isinstance(original, ast.Constant) and isinstance(node, ast.Constant):
pass
elif original:
positions = set()
@@ -110,17 +104,17 @@ class Transformer(object):
# where we've never seen the struct _Foo. Just create
# an empty structure for these as "disguised"
# If we do have a class/interface, merge fields
- for typedef,compound in self._typedefs_ns.iteritems():
+ for typedef, compound in self._typedefs_ns.iteritems():
ns_compound = self._namespace.get(compound.name)
if not ns_compound:
ns_compound = self._namespace.get('_' + compound.name)
- if (not ns_compound and isinstance(compound, (Record, Union))
+ if (not ns_compound and isinstance(compound, (ast.Record, ast.Union))
and len(compound.fields) == 0):
- disguised = Record(compound.name, typedef, disguised=True)
+ disguised = ast.Record(compound.name, typedef, disguised=True)
self._namespace.append(disguised)
elif not ns_compound:
self._namespace.append(compound)
- elif isinstance(ns_compound, (Record, Union)) and len(ns_compound.fields) == 0:
+ elif isinstance(ns_compound, (ast.Record, ast.Union)) and len(ns_compound.fields) == 0:
ns_compound.fields = compound.fields
self._typedefs_ns = None
@@ -136,7 +130,7 @@ class Transformer(object):
def lookup_giname(self, name):
"""Given a name of the form Foo or Bar.Foo,
-return the corresponding Node, or None if none
+return the corresponding ast.Node, or None if none
available. Will throw KeyError however for unknown
namespaces."""
if '.' not in name:
@@ -161,13 +155,11 @@ None."""
def log_warning(self, text, file_positions=None, prefix=None,
fatal=False):
"""Log a warning, using optional file positioning information.
-If the warning is related to a Node type, see log_node_warning()."""
+If the warning is related to a ast.Node type, see log_node_warning()."""
if not fatal and not self._enable_warnings:
return
self._warned = True
- if 'GI_SCANNER_DEBUG_WARNINGS' in os.environ:
- import pdb; pdb.set_trace()
if file_positions is None or len(file_positions) == 0:
target_file_positions = [('<unknown>', -1, -1)]
@@ -212,7 +204,7 @@ If the warning is related to a Node type, see log_node_warning()."""
def log_node_warning(self, node, text, context=None, fatal=False):
"""Log a warning, using information about file positions from
the given node. The optional context argument, if given, should be
-another Node type which will also be displayed. If no file position
+another ast.Node type which will also be displayed. If no file position
information is available from the node, the position data from the
context will be used."""
if hasattr(node, 'file_positions'):
@@ -227,7 +219,7 @@ context will be used."""
text = "context=%r %s" % (node, text)
if context:
- if isinstance(context, Function):
+ if isinstance(context, ast.Function):
name = context.symbol
else:
name = context.name
@@ -346,7 +338,8 @@ it is always biggest (i.e. last)."""
self.log_symbol_warning(symbol, "Unknown namespace", fatal=fatal)
return None
if ns != self._namespace:
- self.log_symbol_warning(symbol, "Skipping foreign symbol from namespace %s" % (ns.name, ),
+ self.log_symbol_warning(symbol,
+"Skipping foreign symbol from namespace %s" % (ns.name, ),
fatal=fatal)
return None
if is_constant:
@@ -419,7 +412,7 @@ it is always biggest (i.e. last)."""
name = self._strip_symbol_or_warn(child, is_constant=True)
if name is None:
return None
- members.append(Member(name.lower(),
+ members.append(ast.Member(name.lower(),
child.const_int,
child.ident))
@@ -427,9 +420,9 @@ it is always biggest (i.e. last)."""
if not enum_name:
return None
if symbol.base_type.is_bitfield:
- klass = Bitfield
+ klass = ast.Bitfield
else:
- klass = Enum
+ klass = ast.Enum
node = klass(enum_name, symbol.ident, members)
node.add_symbol_reference(symbol)
return node
@@ -440,7 +433,7 @@ it is always biggest (i.e. last)."""
name = self._strip_symbol_or_warn(symbol)
if not name:
return None
- func = Function(name, return_, parameters, False, symbol.ident)
+ func = ast.Function(name, return_, parameters, False, symbol.ident)
func.add_symbol_reference(symbol)
return func
@@ -486,16 +479,17 @@ it is always biggest (i.e. last)."""
derefed_name = canonical_ctype[:-1]
else:
derefed_name = canonical_ctype
- ftype = Array(None, self.create_type_from_ctype_string(ctype), ctype=derefed_name)
+ ftype = ast.Array(None, self.create_type_from_ctype_string(ctype),
+ ctype=derefed_name)
child_list = list(symbol.base_type.child_list)
ftype.zeroterminated = False
if child_list:
ftype.size = child_list[0].const_int
else:
ftype = self._create_type_from_base(symbol.base_type)
- # Fields are assumed to be read-write
+ # ast.Fields are assumed to be read-write
# (except for Objects, see also glibtransformer.py)
- node = Field(symbol.ident, ftype,
+ node = ast.Field(symbol.ident, ftype,
readable=True, writable=True, bits=symbol.const_int)
return node
@@ -523,10 +517,10 @@ it is always biggest (i.e. last)."""
if symbol.base_type.name:
target = self.create_type_from_ctype_string(symbol.base_type.name)
else:
- target = TYPE_ANY
- if name in type_names:
+ target = ast.TYPE_ANY
+ if name in ast.type_names:
return None
- return Alias(name, target, ctype=symbol.ident)
+ return ast.Alias(name, target, ctype=symbol.ident)
else:
raise NotImplementedError(
"symbol %r of type %s" % (symbol.ident, ctype_name(ctype)))
@@ -536,7 +530,7 @@ it is always biggest (i.e. last)."""
# First look up the ctype including any pointers;
# a few type names like 'char*' have their own aliases
# and we need pointer information for those.
- firstpass = type_names.get(ctype)
+ firstpass = ast.type_names.get(ctype)
# If we have a particular alias for this, skip deep
# canonicalization to prevent changing
@@ -567,7 +561,7 @@ it is always biggest (i.e. last)."""
# Preserve "pointerness" of struct/union members
if (is_member and canonical.endswith('*') and
- derefed_typename in basic_type_names):
+ derefed_typename in ast.basic_type_names):
return 'gpointer'
else:
return derefed_typename
@@ -586,7 +580,7 @@ it is always biggest (i.e. last)."""
name = 'GLib.' + base[1:]
else:
name = base
- return List(name, TYPE_ANY, ctype=ctype,
+ return ast.List(name, ast.TYPE_ANY, ctype=ctype,
is_const=is_const)
elif base in ('GArray', 'GPtrArray', 'GByteArray',
'GLib.Array', 'GLib.PtrArray', 'GLib.ByteArray'):
@@ -594,44 +588,44 @@ it is always biggest (i.e. last)."""
name = 'GLib.' + base[1:]
else:
name = base
- return Array(name, TYPE_ANY, ctype=ctype,
+ return ast.Array(name, ast.TYPE_ANY, ctype=ctype,
is_const=is_const)
elif base in ('GHashTable', 'GLib.HashTable'):
- return Map(TYPE_ANY, TYPE_ANY, ctype=ctype, is_const=is_const)
+ return ast.Map(ast.TYPE_ANY, ast.TYPE_ANY, ctype=ctype, is_const=is_const)
return None
def create_type_from_ctype_string(self, ctype, is_const=False,
is_parameter=False, is_return=False):
canonical = self._canonicalize_ctype(ctype)
- # Special default: char ** -> Array
+ # Special default: char ** -> ast.Array
if is_return and canonical == 'utf8*':
- element_type = Type(target_fundamental='utf8')
- return Array(None, element_type, ctype=ctype,
+ element_type = ast.Type(target_fundamental='utf8')
+ return ast.Array(None, element_type, ctype=ctype,
is_const=is_const)
base = canonical.replace('*', '')
- fundamental = type_names.get(base)
+ fundamental = ast.type_names.get(base)
if fundamental is not None:
- return Type(target_fundamental=fundamental.target_fundamental,
+ return ast.Type(target_fundamental=fundamental.target_fundamental,
ctype=ctype,
is_const=is_const)
container = self._create_bare_container_type(base, ctype=ctype, is_const=is_const)
if container:
return container
- return Type(ctype=ctype, is_const=is_const)
+ return ast.Type(ctype=ctype, is_const=is_const)
def _create_parameter(self, symbol):
if symbol.type == CSYMBOL_TYPE_ELLIPSIS:
- ptype = Varargs()
+ ptype = ast.Varargs()
else:
ptype = self._create_type_from_base(symbol.base_type, is_parameter=True)
- return Parameter(symbol.ident, ptype)
+ return ast.Parameter(symbol.ident, ptype)
def _create_return(self, source_type):
typeval = self._create_type_from_base(source_type, is_return=True)
- return Return(typeval)
+ return ast.Return(typeval)
def _create_const(self, symbol):
# Don't create constants for non-public things
@@ -646,18 +640,18 @@ it is always biggest (i.e. last)."""
if not name:
return None
if symbol.const_string is not None:
- typeval = TYPE_STRING
+ typeval = ast.TYPE_STRING
value = symbol.const_string
elif symbol.const_int is not None:
- typeval = TYPE_INT
+ typeval = ast.TYPE_INT
value = '%d' % (symbol.const_int, )
elif symbol.const_double is not None:
- typeval = TYPE_DOUBLE
+ typeval = ast.TYPE_DOUBLE
value = '%f' % (symbol.const_double, )
else:
raise AssertionError()
- const = Constant(name, typeval, value)
+ const = ast.Constant(name, typeval, value)
const.add_symbol_reference(symbol)
return const
@@ -665,7 +659,7 @@ it is always biggest (i.e. last)."""
name = self.strip_identifier_or_warn(symbol.ident)
if not name:
return None
- struct = Record(name, symbol.ident, disguised)
+ struct = ast.Record(name, symbol.ident, disguised)
self._parse_fields(symbol, struct)
struct.add_symbol_reference(symbol)
self._typedefs_ns[symbol.ident] = struct
@@ -675,7 +669,7 @@ it is always biggest (i.e. last)."""
name = self.strip_identifier_or_warn(symbol.ident)
if not name:
return None
- union = Union(name, symbol.ident)
+ union = ast.Union(name, symbol.ident)
self._parse_fields(symbol, union)
union.add_symbol_reference(symbol)
self._typedefs_ns[symbol.ident] = union
@@ -693,10 +687,10 @@ it is always biggest (i.e. last)."""
child_node = self._traverse_one(child)
if not child_node:
continue
- if isinstance(child_node, Field):
+ if isinstance(child_node, ast.Field):
field = child_node
else:
- field = Field(child.ident, None, True, False,
+ field = ast.Field(child.ident, None, True, False,
anonymous_node=child_node)
compound.fields.append(field)
@@ -728,10 +722,10 @@ it is always biggest (i.e. last)."""
return compound
def _create_struct(self, symbol, anonymous=False):
- return self._create_compound(Record, symbol, anonymous)
+ return self._create_compound(ast.Record, symbol, anonymous)
def _create_union(self, symbol, anonymous=False):
- return self._create_compound(Union, symbol, anonymous)
+ return self._create_compound(ast.Union, symbol, anonymous)
def _create_callback(self, symbol, member=False):
parameters = list(self._create_parameters(symbol.base_type.base_type))
@@ -753,7 +747,7 @@ it is always biggest (i.e. last)."""
name = self.strip_identifier_or_warn(symbol.ident)
if not name:
return None
- callback = Callback(name, retval, parameters, False)
+ callback = ast.Callback(name, retval, parameters, False)
callback.add_symbol_reference(symbol)
return callback
@@ -774,10 +768,10 @@ both GI type string (utf8, Foo.Bar) style, as well as C (char *, FooBar) style."
return typeval
def resolve_type(self, typeval):
- if isinstance(typeval, (Array, List)):
+ if isinstance(typeval, (ast.Array, ast.List)):
self.resolve_type(typeval.element_type)
return
- elif isinstance(typeval, Map):
+ elif isinstance(typeval, ast.Map):
self.resolve_type(typeval.key_type)
self.resolve_type(typeval.value_type)
return
@@ -788,7 +782,7 @@ both GI type string (utf8, Foo.Bar) style, as well as C (char *, FooBar) style."
except ValueError, e:
raise TypeResolutionException(e)
target_giname=None
- for namespace,name in matches:
+ for namespace, name in matches:
target = namespace.get(name)
if not target:
target = namespace.get_by_ctype(pointer_stripped)
diff --git a/misc/pep8.py b/misc/pep8.py
index fef8a54..1a50efc 100644
--- a/misc/pep8.py
+++ b/misc/pep8.py
@@ -183,7 +183,7 @@ def maximum_line_length(physical_line):
length to 72 characters is recommended.
"""
length = len(physical_line.rstrip())
- if length > 79:
+ if length > 99:
return 79, "E501 line too long (%d characters)" % length
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]