summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-09-08 15:08:19 -0400
committerColin Walters <walters@verbum.org>2010-09-09 09:55:03 -0400
commit303c9d64032819d55420d3c1be1583d2cc582ccf (patch)
treef6e0fb5846b1623df4fe9714984a022cf97cd420
parent26395037d049fd119156052643505b224aa07d35 (diff)
scanner: Unify parsing of compounds
Avoids duplicate code.
-rw-r--r--giscanner/girparser.py61
1 files changed, 23 insertions, 38 deletions
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index 5c54dbe..ab2b29d 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -330,56 +330,41 @@ class GIRParser(object):
res.append(fieldobj)
return res
- def _parse_record(self, node, anonymous=False):
- struct = ast.Record(node.attrib.get('name'),
- node.attrib.get(_cns('type')),
- disguised=node.attrib.get('disguised') == '1',
- gtype_name=node.attrib.get(_glibns('type-name')),
- get_type=node.attrib.get(_glibns('get-type')),
- c_symbol_prefix=node.attrib.get(_cns('symbol-prefix')))
- is_gtype_struct_for = node.attrib.get(_glibns('is-gtype-struct-for'))
- if is_gtype_struct_for is not None:
- struct.is_gtype_struct_for = self._namespace.type_from_name(is_gtype_struct_for)
+ def _parse_compound(self, cls, node):
+ compound = cls(node.attrib.get('name'),
+ ctype=node.attrib.get(_cns('type')),
+ disguised=node.attrib.get('disguised') == '1',
+ gtype_name=node.attrib.get(_glibns('type-name')),
+ get_type=node.attrib.get(_glibns('get-type')),
+ c_symbol_prefix=node.attrib.get(_cns('symbol-prefix')))
if node.attrib.get('foreign') == '1':
- struct.foreign = True
- self._parse_generic_attribs(node, struct)
- if not anonymous:
- self._namespace.append(struct)
-
- struct.fields.extend(self._parse_fields(node))
+ compound.foreign = True
+ self._parse_generic_attribs(node, compound)
+ compound.fields.extend(self._parse_fields(node))
for method in self._find_children(node, _corens('method')):
- struct.methods.append(
+ compound.methods.append(
self._parse_function_common(method, ast.Function))
for func in self._find_children(node, _corens('function')):
- struct.static_methods.append(
+ compound.static_methods.append(
self._parse_function_common(func, ast.Function))
for ctor in self._find_children(node, _corens('constructor')):
- struct.constructors.append(
+ compound.constructors.append(
self._parse_function_common(ctor, ast.Function))
+ return compound
+
+ def _parse_record(self, node, anonymous=False):
+ struct = self._parse_compound(ast.Record, node)
+ is_gtype_struct_for = node.attrib.get(_glibns('is-gtype-struct-for'))
+ if is_gtype_struct_for is not None:
+ struct.is_gtype_struct_for = self._namespace.type_from_name(is_gtype_struct_for)
+ if not anonymous:
+ self._namespace.append(struct)
return struct
def _parse_union(self, node, anonymous=False):
- union = ast.Union(node.attrib.get('name'),
- node.attrib.get(_cns('type')),
- gtype_name=node.attrib.get(_glibns('type-name')),
- get_type=node.attrib.get(_glibns('get-type')),
- c_symbol_prefix=node.attrib.get(_cns('symbol-prefix')))
+ union = self._parse_compound(ast.Union, node)
if not anonymous:
self._namespace.append(union)
-
- for callback in self._find_children(node, _corens('callback')):
- union.fields.append(
- self._parse_function_common(callback, ast.Callback))
- union.fields.extend(self._parse_fields(node))
- for method in self._find_children(node, _corens('method')):
- union.methods.append(
- self._parse_function_common(method, ast.Function))
- for func in self._find_children(node, _corens('function')):
- union.static_methods.append(
- self._parse_function_common(func, ast.Function))
- for ctor in self._find_children(node, _corens('constructor')):
- union.constructors.append(
- self._parse_function_common(ctor, ast.Function))
return union
def _parse_type_simple(self, typenode):