def parse_enum(self, xml_node): enum = self.parse_node(xml_node, Enumeration, "enums", name = xml_node.get("name")) enum.access = AccessSpecifier.from_string(xml_node.get('access', 'public')) for value in xml_node.findall('EnumValue'): enum.add_field(value.get('name'), int(value.get('init'))) return enum
def parse_struct(self, xml_node): ctx = xml_node.find('Context') struct = Struct(xml_node.get('name')) struct.context = self.parse_context(ctx) struct.location = self.parse_source_location(ctx) struct.access = AccessSpecifier.from_string(xml_node.get('access')) struct.members = [self.parse_member(i) for i in xml_node.findall('Field')] self.nodes[xml_node.get('id')] = struct self.structs.append(struct) return struct
def parse_struct(self, xml_node, node_type = Struct, registry = "structs"): name = xml_node.get('name', '') if not name or "<" in name: return if xml_node.get('incomplete') == '1': # TODO: Do something useful with incomplete types return struct = self.parse_node(xml_node, node_type, registry, name = name) struct.access = AccessSpecifier.from_string(xml_node.get('access', 'public')) struct.bases = [i.get('type') for i in xml_node.findall('Base')] struct.members = xml_node.get('members', '').split(" ") return struct
def parse_function_signature(self, xml_node): ctx = xml_node.find('Context') sig = FunctionSignature() sig.context = self.parse_context(ctx) sig.location = self.parse_source_location(ctx) sig.access = AccessSpecifier.from_string(xml_node.get('access')) sig.constructor = (xml_node.get('constructor') == '1') sig.destructor = (xml_node.get('destructor') == '1') sig.virtual = (xml_node.get('virtual') == '1') sig.pure = (xml_node.get('pure') == '1') sig.static = (xml_node.get('static') == '1') sig.const = (xml_node.get('const') == '1') sig.extern_c =(xml_node.get('extern_c') == '1') sig.args = [self.parse_argument(i, sig) for i in xml_node.findall('Argument')] returns = xml_node.findall('Returns') if returns: sig.returns = self.parse_type(returns[0].find('Type')) return sig
def parse_class(self, xml_node): ctx = xml_node.find('Context') cls = Class(xml_node.get('name')) cls.context = self.parse_context(ctx) cls.location = self.parse_source_location(ctx) cls.access = AccessSpecifier.from_string(xml_node.get('access')) cls.bases = [i.get('id') for i in xml_node.findall('Base')] cls.dynamic = xml_node.get('dynamic') == '1' cls.members = [self.parse_member(i) for i in xml_node.findall('Field')] methods = defaultdict(list) for i in xml_node.findall('Method'): sig = self.parse_function_signature(i) if sig.constructor: sig.context = cls cls.constructors.append(sig) elif sig.destructor: sig.context = cls cls.destructor = sig else: methods[i.get('name')].append(sig) cls.methods = [] for name, signatures in methods.items(): method = Method(name, signatures, cls) for sig in signatures: sig.context = method cls.methods.append(method) cls.determine_abstractness() for child_node in xml_node.findall('Class'): self.parse_class(child_node) for child_node in xml_node.findall('Enum'): self.parse_enumeration(child_node) self.nodes[xml_node.get('id')] = cls self.classes.append(cls) return cls
def parse_function_signature(self, xml_node, registry = None): name = xml_node.get('name', '') if not name or "<" in name: return sig = self.parse_node(xml_node, FunctionSignature, registry) sig.access = AccessSpecifier.from_string(xml_node.get('access', 'public')) sig.constructor = (xml_node.tag == 'Constructor') sig.destructor = (xml_node.tag == 'Destructor') sig.virtual = (xml_node.get('virtual') == '1') sig.pure = (xml_node.get('pure_virtual') == '1') sig.static = (xml_node.get('static') == '1') sig.const = (xml_node.get('const') == '1') sig.args = [self.parse_argument(arg_node, sig) for arg_node in xml_node.findall("Argument")] sig.returns = xml_node.get('returns') if sig.constructor: name = "+init" # Invalid method name so it won't class with normal methods elif sig.destructor: name = "+del" self.signatures[sig.context][name].append(sig) return sig
def parse_member(self, xml_node, context = None): member = Member(xml_node.get('name')) member.context = context member.access = AccessSpecifier.from_string(xml_node.get('access')) member.type = self.parse_type(xml_node.find('Type')) return member
def parse_field(self, xml_node): member = self.parse_node(xml_node, Member, name = xml_node.get('name')) member.access = AccessSpecifier.from_string(xml_node.get('access', 'public')) member.type = xml_node.get('type') return member