summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-07-21 21:06:17 -0400
committerColin Walters <walters@verbum.org>2010-08-31 16:05:56 -0400
commite66d50732c8ce5cf3ef198e114d94e102a1c4911 (patch)
tree11136782cda96b23479e388197bcf58736842e2d /giscanner
parentabc4e514ff46ed77159b19f56dea54eeef8bc909 (diff)
downloadgobject-introspection-e66d50732c8ce5cf3ef198e114d94e102a1c4911.tar.gz
Use GLib types consistently
Rather than have the scanner/parser handle both e.g. "glong" and "long", simply use the GLib types everywhere. This commit adds TYPE_LONG_LONG and TYPE_LONG_DOUBLE to the scanner types; however, rather than add them to the typelib, they're just marked as not-introspectable.
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/annotationparser.py2
-rw-r--r--giscanner/ast.py154
-rw-r--r--giscanner/girwriter.py36
-rw-r--r--giscanner/glibast.py50
-rw-r--r--giscanner/glibtransformer.py16
-rw-r--r--giscanner/transformer.py15
6 files changed, 124 insertions, 149 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index c642d56e..9e4340fa 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -783,7 +783,7 @@ class AnnotationApplier(object):
self._guess_direction(node) == PARAM_DIRECTION_IN and
element_type is None):
# FIXME: unsigned char/guchar should be uint8
- container_type.element_type = Type('int8')
+ container_type.element_type = Type('gint8')
container_type.size = array_values.get(OPT_ARRAY_FIXED_SIZE)
return container_type
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 3678e8ce..8c7ea093 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -27,74 +27,58 @@ These can later on be extended (eg subclassed) with additional information
which is language/library/domain specific.
"""
-##
-## Basic types, modeled on GITypeTag but not equivalent
-##
-
-TYPE_NONE = 'none' # We differ from repository on these first two
-TYPE_ANY = 'any'
-TYPE_BOOLEAN = 'boolean'
-TYPE_INT8 = 'int8'
-TYPE_UINT8 = 'uint8'
-TYPE_SHORT = 'short'
-TYPE_USHORT = 'ushort'
-TYPE_INT16 = 'int16'
-TYPE_UINT16 = 'uint16'
-TYPE_INT = 'int'
-TYPE_UINT = 'uint'
-TYPE_INT32 = 'int32'
-TYPE_UINT32 = 'uint32'
-TYPE_INT64 = 'int64'
-TYPE_UINT64 = 'uint64'
-TYPE_LONG = 'long'
-TYPE_ULONG = 'ulong'
-TYPE_SIZET = 'gsize'
-TYPE_SSIZET = 'gssize'
+######
+## Fundamental types
+######
+# Two special ones
+TYPE_NONE = 'none'
+TYPE_ANY = 'gpointer'
+# "Basic" types
+TYPE_BOOLEAN = 'gboolean'
+TYPE_INT8 = 'gint8'
+TYPE_UINT8 = 'guint8'
+TYPE_INT16 = 'gint16'
+TYPE_UINT16 = 'guint16'
+TYPE_INT32 = 'gint32'
+TYPE_UINT32 = 'guint32'
+TYPE_INT64 = 'gint64'
+TYPE_UINT64 = 'guint64'
+TYPE_CHAR = 'gchar'
+TYPE_SHORT = 'gshort'
+TYPE_USHORT = 'gushort'
+TYPE_INT = 'gint'
+TYPE_UINT = 'guint'
+TYPE_LONG = 'glong'
+TYPE_ULONG = 'gulong'
+# C99 types
+TYPE_LONG_LONG = 'long long'
+TYPE_LONG_ULONG = 'unsigned long long'
+TYPE_FLOAT = 'gfloat'
+TYPE_DOUBLE = 'gdouble'
+# ?
+TYPE_LONG_DOUBLE = 'long double'
+
+# C types with semantics overlaid
TYPE_GTYPE = 'GType'
-TYPE_FLOAT = 'float'
-TYPE_DOUBLE = 'double'
-TYPE_STRING = 'utf8' # requires zero-terminated
+TYPE_STRING = 'utf8'
TYPE_FILENAME = 'filename'
BASIC_GIR_TYPES = [TYPE_BOOLEAN, TYPE_INT8, TYPE_UINT8, TYPE_INT16,
TYPE_UINT16, TYPE_INT32, TYPE_UINT32, TYPE_INT64,
- TYPE_UINT64, TYPE_SHORT, TYPE_USHORT, TYPE_INT,
- TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_SSIZET,
- TYPE_SIZET, TYPE_FLOAT, TYPE_DOUBLE,
- TYPE_GTYPE]
+ TYPE_UINT64, TYPE_CHAR, TYPE_SHORT, TYPE_USHORT, TYPE_INT,
+ TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_LONG_LONG,
+ TYPE_LONG_ULONG, TYPE_FLOAT, TYPE_DOUBLE,
+ TYPE_LONG_DOUBLE, TYPE_GTYPE]
GIR_TYPES = [TYPE_NONE, TYPE_ANY]
GIR_TYPES.extend(BASIC_GIR_TYPES)
GIR_TYPES.extend([TYPE_STRING, TYPE_FILENAME])
-# Higher-level data types
-TYPE_SEQUENCE = 'sequence' # Sequence of something
-
-# Wide/Unicode
-TYPE_UCHAR = 'uchar'
-TYPE_USTRING = 'ustring'
-
-##
-## Parameters
-##
-
-PARAM_DIRECTION_IN = 'in'
-PARAM_DIRECTION_OUT = 'out'
-PARAM_DIRECTION_INOUT = 'inout'
-
-PARAM_SCOPE_CALL = 'call'
-PARAM_SCOPE_ASYNC = 'async'
-PARAM_SCOPE_NOTIFIED = 'notified'
-
-PARAM_TRANSFER_NONE = 'none'
-PARAM_TRANSFER_CONTAINER = 'container'
-PARAM_TRANSFER_FULL = 'full'
-
type_names = {}
-for name in GIR_TYPES:
- type_names[name] = name
+for typeval in GIR_TYPES:
+ type_names[typeval] = typeval
# C builtin
-type_names['char'] = TYPE_INT8
+type_names['char'] = TYPE_CHAR
type_names['signed char'] = TYPE_INT8
type_names['unsigned char'] = TYPE_UINT8
type_names['short'] = TYPE_SHORT
@@ -115,8 +99,25 @@ type_names['double'] = TYPE_DOUBLE
type_names['char*'] = TYPE_STRING
type_names['void*'] = TYPE_ANY
type_names['void'] = TYPE_NONE
+# Also alias the signed one here
+type_names['signed long long'] = TYPE_LONG_LONG
-# Random C unix type definitions; note some of these may be GNU Libc
+# A few additional GLib type aliases
+type_names['guchar'] = TYPE_UINT8
+type_names['gchararray'] = TYPE_STRING
+type_names['gchar*'] = TYPE_STRING
+type_names['gsize'] = TYPE_ULONG
+type_names['gssize'] = TYPE_LONG
+type_names['gconstpointer'] = TYPE_ANY
+
+# Some special C types that aren't scriptable, and we just squash
+type_names['va_list'] = TYPE_ANY
+
+# C stdio, used in GLib public headers; squash this for now here
+# until we move scanning into GLib and can (skip)
+type_names['FILE*'] = TYPE_ANY
+
+# One off C unix type definitions; note some of these may be GNU Libc
# specific. If someone is actually bitten by this, feel free to do
# the required configure goop to determine their size and replace
# here.
@@ -127,39 +128,48 @@ type_names['void'] = TYPE_NONE
# methods are added under #ifdefs inside GLib itself. We could just (skip)
# the relevant methods, but on the other hand, since these types are just
# integers it's easy enough to expand them.
-type_names['size_t'] = TYPE_SIZET
+type_names['size_t'] = type_names['gsize']
type_names['time_t'] = TYPE_LONG
-type_names['off_t'] = TYPE_SIZET
+type_names['off_t'] = type_names['gsize']
type_names['pid_t'] = TYPE_INT
type_names['uid_t'] = TYPE_UINT
type_names['gid_t'] = TYPE_UINT
type_names['dev_t'] = TYPE_INT
type_names['socklen_t'] = TYPE_INT32
+type_names['size_t'] = TYPE_ULONG
+type_names['ssize_t'] = TYPE_LONG
# Obj-C
type_names['id'] = TYPE_ANY
-# Suppress some GLib names
-type_names['uchar'] = TYPE_UINT8
-type_names['ushort'] = TYPE_USHORT
-type_names['size'] = TYPE_SIZET
-type_names['ssize'] = TYPE_SSIZET
-type_names['pointer'] = TYPE_ANY
-type_names['constpointer'] = TYPE_ANY
-
-
# These types, when seen by reference, are converted into an Array()
# by default
-# If you add/change these, be sure to update glibast.py too
default_array_types = {}
-default_array_types['uint8*'] = TYPE_UINT8
+default_array_types['guint8*'] = TYPE_UINT8
+default_array_types['guchar*'] = TYPE_UINT8
default_array_types['utf8*'] = TYPE_STRING
+default_array_types['char**'] = TYPE_STRING
+default_array_types['gchar**'] = TYPE_STRING
# These types, when seen by reference, are interpreted as out parameters
default_out_types = (TYPE_SHORT, TYPE_USHORT, TYPE_INT, TYPE_UINT,
- TYPE_LONG, TYPE_ULONG, TYPE_FLOAT, TYPE_DOUBLE,
- TYPE_SIZET, TYPE_SSIZET)
+ TYPE_LONG, TYPE_ULONG, TYPE_FLOAT, TYPE_DOUBLE)
+
+##
+## Parameters
+##
+
+PARAM_DIRECTION_IN = 'in'
+PARAM_DIRECTION_OUT = 'out'
+PARAM_DIRECTION_INOUT = 'inout'
+
+PARAM_SCOPE_CALL = 'call'
+PARAM_SCOPE_ASYNC = 'async'
+PARAM_SCOPE_NOTIFIED = 'notified'
+PARAM_TRANSFER_NONE = 'none'
+PARAM_TRANSFER_CONTAINER = 'container'
+PARAM_TRANSFER_FULL = 'full'
def type_name_from_ctype(ctype):
return type_names.get(ctype, ctype)
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 0f621251..c8103494 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -23,7 +23,7 @@ from __future__ import with_statement
from .ast import (Alias, Array, Bitfield, Callback, Class, Constant, Enum,
Function, Interface, List, Map, Member, Struct, Union,
- Varargs, Type)
+ Varargs, Type, TYPE_ANY)
from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember,
GLibFlags, GLibObject, GLibInterface,
GLibRecord)
@@ -258,7 +258,7 @@ and/or use gtk-doc annotations. ''')
if ntype.element_type is not None:
self._write_type(ntype.element_type)
else:
- self._write_type(Type('any', ctype='gpointer'))
+ self._write_type(Type(TYPE_ANY, ctype='gpointer'))
return
attrs = [('name', self._type_to_string(ntype))]
# FIXME: figure out if type references a basic type
@@ -273,7 +273,7 @@ and/or use gtk-doc annotations. ''')
if isinstance(ntype, List) and ntype.element_type:
self._write_type(ntype.element_type)
else:
- self._write_type(Type('any', ctype='gpointer'))
+ self._write_type(Type(TYPE_ANY, ctype='gpointer'))
return
if isinstance(ntype, Map) and ntype.key_type:
with self.tagcontext('type', attrs):
@@ -363,25 +363,25 @@ and/or use gtk-doc annotations. ''')
with self.tagcontext(tag_name, attrs):
self._write_generic(node)
if isinstance(node, GLibObject):
- for iface in node.interfaces:
+ for iface in sorted(node.interfaces):
self.write_tag('implements', [('name', iface)])
if isinstance(node, Interface):
- for iface in node.prerequisites:
+ for iface in sorted(node.prerequisites):
self.write_tag('prerequisite', [('name', iface)])
if isinstance(node, Class):
- for method in node.constructors:
+ for method in sorted(node.constructors):
self._write_constructor(method)
- for method in node.static_methods:
+ for method in sorted(node.static_methods):
self._write_static_method(method)
- for vfunc in node.virtual_methods:
+ for vfunc in sorted(node.virtual_methods):
self._write_vfunc(vfunc)
- for method in node.methods:
+ for method in sorted(node.methods):
self._write_method(method)
- for prop in node.properties:
+ for prop in sorted(node.properties):
self._write_property(prop)
for field in node.fields:
self._write_field(field)
- for signal in node.signals:
+ for signal in sorted(node.signals):
self._write_signal(signal)
def _write_boxed(self, boxed):
@@ -390,9 +390,9 @@ and/or use gtk-doc annotations. ''')
attrs.extend(self._boxed_attrs(boxed))
with self.tagcontext('glib:boxed', attrs):
self._write_generic(boxed)
- for method in boxed.constructors:
+ for method in sorted(boxed.constructors):
self._write_constructor(method)
- for method in boxed.methods:
+ for method in sorted(boxed.methods):
self._write_method(method)
def _write_property(self, prop):
@@ -452,9 +452,9 @@ and/or use gtk-doc annotations. ''')
if record.fields:
for field in record.fields:
self._write_field(field, is_gtype_struct)
- for method in record.constructors:
+ for method in sorted(record.constructors):
self._write_constructor(method)
- for method in record.methods:
+ for method in sorted(record.methods):
self._write_method(method)
def _write_union(self, union):
@@ -472,9 +472,9 @@ and/or use gtk-doc annotations. ''')
if union.fields:
for field in union.fields:
self._write_field(field)
- for method in union.constructors:
+ for method in sorted(union.constructors):
self._write_constructor(method)
- for method in union.methods:
+ for method in sorted(union.methods):
self._write_method(method)
def _write_field(self, field, is_gtype_struct=False):
@@ -489,7 +489,7 @@ and/or use gtk-doc annotations. ''')
if is_gtype_struct:
self._write_callback(field)
else:
- attrs = [('name', 'any'), ('c:type', 'pointer')]
+ attrs = [('name', TYPE_ANY), ('c:type', 'pointer')]
self.write_tag('type', attrs)
elif isinstance(field, Struct):
self._write_record(field)
diff --git a/giscanner/glibast.py b/giscanner/glibast.py
index c7129883..ad87926f 100644
--- a/giscanner/glibast.py
+++ b/giscanner/glibast.py
@@ -19,48 +19,7 @@
#
from .ast import (Bitfield, Class, Enum, Interface, Member, Node,
- Property, Struct, Union, Record)
-from .ast import (
- type_names, default_array_types,
- TYPE_STRING, TYPE_INT8, TYPE_UINT8, TYPE_SHORT, TYPE_USHORT,
- TYPE_INT16, TYPE_UINT16, TYPE_INT, TYPE_UINT, TYPE_UINT32,
- TYPE_INT32, TYPE_LONG, TYPE_ULONG, TYPE_INT64, TYPE_UINT64,
- TYPE_FLOAT, TYPE_DOUBLE, TYPE_BOOLEAN, TYPE_ANY, TYPE_SSIZET,
- TYPE_SIZET)
-
-
-# Glib type names
-type_names['gchararray'] = TYPE_STRING
-type_names['gint8'] = TYPE_INT8
-type_names['guint8'] = TYPE_UINT8
-type_names['gint16'] = TYPE_INT16
-type_names['guint16'] = TYPE_UINT16
-type_names['gint'] = TYPE_INT
-type_names['guint'] = TYPE_UINT
-type_names['gint32'] = TYPE_INT32
-type_names['guint32'] = TYPE_UINT32
-type_names['glong'] = TYPE_LONG
-type_names['gulong'] = TYPE_ULONG
-type_names['gint64'] = TYPE_INT64
-type_names['guint64'] = TYPE_UINT64
-type_names['gfloat'] = TYPE_FLOAT
-type_names['gdouble'] = TYPE_DOUBLE
-type_names['gchar*'] = TYPE_STRING
-type_names['gboolean'] = TYPE_BOOLEAN
-type_names['gpointer'] = TYPE_ANY
-type_names['gconstpointer'] = TYPE_ANY
-type_names['gsize'] = TYPE_SIZET
-type_names['gssize'] = TYPE_SSIZET
-type_names['gchar'] = TYPE_INT8
-type_names['guchar'] = TYPE_UINT8
-type_names['gshort'] = TYPE_SHORT
-type_names['gushort'] = TYPE_USHORT
-
-# It's not very nice to duplicate the array types from ast.py,
-# but a clean fix is hard without essentially hardcoding
-# char * again inside transformer.py
-default_array_types['guint8*'] = TYPE_UINT8
-default_array_types['gchar**'] = TYPE_STRING
+ Property, Union, Record)
class GLibRecord(Record):
def __init__(self, *args, **kwargs):
@@ -136,10 +95,12 @@ class GLibBoxed:
self.get_type = get_type
-class GLibBoxedStruct(Struct, GLibBoxed):
+
+
+class GLibBoxedStruct(Record, GLibBoxed):
def __init__(self, name, type_name, get_type, ctype=None):
- Struct.__init__(self, name, ctype or type_name)
+ Record.__init__(self, name, ctype or type_name)
GLibBoxed.__init__(self, type_name, get_type)
@@ -160,6 +121,7 @@ class GLibBoxedOther(Node, GLibBoxed):
self.ctype = type_name
self.doc = None
+
class GLibInterface(Interface):
def __init__(self, name, parent, type_name, get_type,
diff --git a/giscanner/glibtransformer.py b/giscanner/glibtransformer.py
index 391042d5..560be915 100644
--- a/giscanner/glibtransformer.py
+++ b/giscanner/glibtransformer.py
@@ -30,12 +30,12 @@ from .ast import (Alias, Bitfield, Callable, Callback, Class, Constant, Enum,
Property, Record, Return, Type, TypeContainer, Union,
Field, VFunction, type_name_from_ctype, default_array_types,
TYPE_UINT8, PARAM_TRANSFER_FULL, Array, List,
- Map, Varargs)
+ TYPE_LONG_LONG, TYPE_LONG_DOUBLE,
+ Map, Varargs, type_names)
from .transformer import Names
from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember, GLibFlags,
GLibInterface, GLibObject, GLibSignal, GLibBoxedStruct,
- GLibBoxedUnion, GLibBoxedOther, GLibRecord,
- type_names)
+ GLibBoxedUnion, GLibBoxedOther, GLibRecord)
from .utils import to_underscores, to_underscores_noprefix
default_array_types['guchar*'] = TYPE_UINT8
@@ -772,7 +772,7 @@ class GLibTransformer(object):
for interface in xmlnode.findall('implements'):
gitype = self._resolve_gtypename(interface.attrib['name'])
gt_interfaces.append(gitype)
- node.interfaces = sorted(gt_interfaces)
+ node.interfaces = gt_interfaces
def _introspect_properties(self, node, xmlnode):
for pspec in xmlnode.findall('property'):
@@ -788,7 +788,7 @@ class GLibTransformer(object):
readable, writable, construct, construct_only,
ctype,
))
- node.properties = sorted(node.properties)
+ node.properties = node.properties
def _introspect_signals(self, node, xmlnode):
for signal_info in xmlnode.findall('signal'):
@@ -808,7 +808,7 @@ class GLibTransformer(object):
param.transfer = 'none'
signal.parameters.append(param)
node.signals.append(signal)
- node.signals = sorted(node.signals)
+ node.signals = node.signals
def _introspect_fundamental(self, xmlnode):
# We only care about types that can be instantiatable, other
@@ -1160,7 +1160,9 @@ class GLibTransformer(object):
def _introspectable_analysis(self, node, stack):
if isinstance(node, TypeContainer):
parent = stack[-1]
- if isinstance(node.type, Varargs):
+ if node.type.name in [TYPE_LONG_LONG, TYPE_LONG_DOUBLE]:
+ parent.introspectable = False
+ elif isinstance(node.type, Varargs):
parent.introspectable = False
elif self._is_unannotated_list(node):
if isinstance(node, Parameter):
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 2f255211..e2a22049 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -25,7 +25,8 @@ from .ast import (Bitfield, Callback, Enum, Function, Namespace, Member,
Parameter, Return, Struct, Field,
Type, Array, Alias, Interface, Class, Node, Union,
Varargs, Constant, type_name_from_ctype,
- type_names, TYPE_STRING, BASIC_GIR_TYPES)
+ type_names, TYPE_ANY, TYPE_STRING,
+ BASIC_GIR_TYPES)
from .config import DATADIR, GIR_DIR, GIR_SUFFIX
from .glibast import GLibBoxed
from .girparser import GIRParser
@@ -345,7 +346,7 @@ context will be used."""
return False
def _handle_closure(self, param, closure_idx, closure_param):
- if (closure_param.type.name == 'any' and
+ if (closure_param.type.name == TYPE_ANY and
closure_param.name.endswith('data')):
param.closure_name = closure_param.name
param.closure_index = closure_idx
@@ -412,7 +413,7 @@ context will be used."""
elif source_type.type == CTYPE_POINTER:
value = self._create_source_type(source_type.base_type) + '*'
else:
- value = 'any'
+ value = TYPE_ANY
return value
def _create_parameters(self, base_type):
@@ -527,7 +528,7 @@ context will be used."""
# Preserve "pointerness" of struct/union members
if (is_member and canonical.endswith('*') and
derefed_typename in BASIC_GIR_TYPES):
- return 'any'
+ return TYPE_ANY
else:
return derefed_typename
@@ -584,10 +585,10 @@ context will be used."""
type_name = 'utf8'
value = symbol.const_string
elif symbol.const_int is not None:
- type_name = 'int'
+ type_name = 'gint'
value = symbol.const_int
elif symbol.const_double is not None:
- type_name = 'double'
+ type_name = 'gdouble'
value = symbol.const_double
else:
raise AssertionError()
@@ -658,7 +659,7 @@ context will be used."""
# Mark the 'user_data' arguments
for i, param in enumerate(parameters):
- if (param.type.name == 'any' and
+ if (param.type.name == TYPE_ANY and
param.name == 'user_data'):
param.closure_index = i