diff options
author | Colin Walters <walters@src.gnome.org> | 2008-10-25 15:20:54 +0000 |
---|---|---|
committer | Colin Walters <walters@src.gnome.org> | 2008-10-25 15:20:54 +0000 |
commit | d15f8cde47100a77189d5febb8704c0e4d736594 (patch) | |
tree | 651b1c0990dbf5ec99c77139e1a648aca63d5ec5 /giscanner | |
parent | c7d2a0712f6301aa670f87a98e8f217bf3c54a7a (diff) | |
download | gobject-introspection-d15f8cde47100a77189d5febb8704c0e4d736594.tar.gz |
Bug 557786 - support fixed size arrays
svn path=/trunk/; revision=814
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/ast.py | 1 | ||||
-rw-r--r-- | giscanner/girwriter.py | 2 | ||||
-rw-r--r-- | giscanner/scannerparser.y | 12 | ||||
-rw-r--r-- | giscanner/sourcescanner.c | 4 | ||||
-rw-r--r-- | giscanner/sourcescanner.h | 3 | ||||
-rw-r--r-- | giscanner/transformer.py | 22 |
6 files changed, 29 insertions, 15 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py index 6ee98c1f..3d802df9 100644 --- a/giscanner/ast.py +++ b/giscanner/ast.py @@ -227,6 +227,7 @@ class Array(Type): self.zeroterminated = True self.length_param_index = -1 self.length_param_name = None + self.size = None def __repr__(self): return 'Array(%r of %r)' % (self.name, self.element_type, ) diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py index 5c8aa12b..3de71bcd 100644 --- a/giscanner/girwriter.py +++ b/giscanner/girwriter.py @@ -176,6 +176,8 @@ class GIRWriter(XMLWriter): if ntype.length_param_index >= 0: attrs.append(('length', '%d' % (ntype.length_param_index, ))) attrs.append(('c:type', ntype.ctype)) + if ntype.size is not None: + attrs.append(('fixed-size', ntype.size)) with self.tagcontext('array', attrs): self._write_type(ntype.element_type) return diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y index e3ca20e2..64cf11b3 100644 --- a/giscanner/scannerparser.y +++ b/giscanner/scannerparser.y @@ -923,12 +923,12 @@ direct_declarator | direct_declarator '[' assignment_expression ']' { $$ = $1; - gi_source_symbol_merge_type ($$, gi_source_array_new ()); + gi_source_symbol_merge_type ($$, gi_source_array_new ($3)); } | direct_declarator '[' ']' { $$ = $1; - gi_source_symbol_merge_type ($$, gi_source_array_new ()); + gi_source_symbol_merge_type ($$, gi_source_array_new (NULL)); } | direct_declarator '(' parameter_list ')' { @@ -1059,22 +1059,22 @@ direct_abstract_declarator | '[' ']' { $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID); - gi_source_symbol_merge_type ($$, gi_source_array_new ()); + gi_source_symbol_merge_type ($$, gi_source_array_new (NULL)); } | '[' assignment_expression ']' { $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID); - gi_source_symbol_merge_type ($$, gi_source_array_new ()); + gi_source_symbol_merge_type ($$, gi_source_array_new ($2)); } | direct_abstract_declarator '[' ']' { $$ = $1; - gi_source_symbol_merge_type ($$, gi_source_array_new ()); + gi_source_symbol_merge_type ($$, gi_source_array_new (NULL)); } | direct_abstract_declarator '[' assignment_expression ']' { $$ = $1; - gi_source_symbol_merge_type ($$, gi_source_array_new ()); + gi_source_symbol_merge_type ($$, gi_source_array_new ($3)); } | '(' ')' { diff --git a/giscanner/sourcescanner.c b/giscanner/sourcescanner.c index ebdcf0d5..c7bb57e0 100644 --- a/giscanner/sourcescanner.c +++ b/giscanner/sourcescanner.c @@ -163,9 +163,11 @@ gi_source_pointer_new (GISourceType * base_type) } GISourceType * -gi_source_array_new (void) +gi_source_array_new (GISourceSymbol *size) { GISourceType *array = gi_source_type_new (CTYPE_ARRAY); + if (size != NULL && size->type == CSYMBOL_TYPE_CONST && size->const_int_set) + array->child_list = g_list_append (array->child_list, size); return array; } diff --git a/giscanner/sourcescanner.h b/giscanner/sourcescanner.h index 9ba8c520..02d2facd 100644 --- a/giscanner/sourcescanner.h +++ b/giscanner/sourcescanner.h @@ -163,7 +163,6 @@ GISourceDirective * gi_source_directive_new (const gchar *name, void gi_source_directive_free (GISourceDirective *directive); /* Private */ -GISourceType * gi_source_array_new (void); void gi_source_scanner_add_symbol (GISourceScanner *scanner, GISourceSymbol *symbol); gboolean gi_source_scanner_is_typedef (GISourceScanner *scanner, @@ -178,7 +177,7 @@ GISourceType * gi_source_struct_new (const char *name); GISourceType * gi_source_union_new (const char *name); GISourceType * gi_source_enum_new (const char *name); GISourceType * gi_source_pointer_new (GISourceType *base_type); -GISourceType * gi_source_array_new (void); +GISourceType * gi_source_array_new (GISourceSymbol *size); GISourceType * gi_source_function_new (void); G_END_DECLS diff --git a/giscanner/transformer.py b/giscanner/transformer.py index 925010a5..c6c5bfa7 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -309,7 +309,14 @@ class Transformer(object): symbol.base_type.base_type.type == CTYPE_FUNCTION): node = self._create_callback(symbol) else: - ftype = self._create_type(symbol.base_type, {}, True) + opts = {} + if ctype == CTYPE_ARRAY: + opts['array'] = [] + child_list = list(symbol.base_type.child_list) + if child_list: + size_opt = 'fixed-size=%d' % (child_list[0].const_int, ) + opts['array'].append(size_opt) + ftype = self._create_type(symbol.base_type, opts, True) # Fields are assumed to be read-write # (except for Objects, see also glibtransformer.py) node = Field(symbol.ident, ftype, symbol.ident, @@ -392,13 +399,16 @@ class Transformer(object): ctype, key_type, value_type) elif (ctype in default_array_types) or ('array' in options): - derefed_name = ctype[:-1] # strip the * + derefed_name = ctype[:-1] if ctype[-1] == '*' else ctype rettype = Array(ctype, self._parse_ctype(derefed_name)) - array_opts = options.get('array') - if array_opts: - (_, len_name) = array_opts[0].split('=') - rettype.length_param_name = len_name + array_opts = dict([opt.split('=') + for opt in options.get('array', [])]) + if 'length' in array_opts: + rettype.length_param_name = array_opts['length'] + if 'fixed-size' in array_opts: + rettype.size = array_opts['fixed-size'] + rettype.zeroterminated = False else: derefed_name = self._parse_ctype(ctype) rettype = Type(derefed_name, ctype) |