1.1 --- a/generator.py Thu Jul 05 23:40:53 2018 +0200
1.2 +++ b/generator.py Wed Jul 11 18:33:51 2018 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Generate C code from object layouts and other deduced information.
1.6
1.7 -Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -204,14 +204,12 @@
1.13 # Generate table and structure data.
1.14
1.15 function_instance_attrs = None
1.16 - objects = self.optimiser.attr_table.items()
1.17 + objects = self.optimiser.all_attrs.items()
1.18 objects.sort()
1.19
1.20 self.callables = {}
1.21
1.22 - for ref, indexes in objects:
1.23 - attrnames = self.get_attribute_names(indexes)
1.24 -
1.25 + for ref, attrnames in objects:
1.26 kind = ref.get_kind()
1.27 path = ref.get_origin()
1.28 table_name = encode_tablename(kind, path)
1.29 @@ -613,8 +611,7 @@
1.30 # Obtain the attributes.
1.31
1.32 cls = ref.get_origin()
1.33 - indexes = self.optimiser.attr_table[ref]
1.34 - attrnames = self.get_attribute_names(indexes)
1.35 + attrnames = self.optimiser.all_attrs[ref]
1.36 attrs = self.get_instance_attributes(cls, attrnames)
1.37
1.38 # Set the data, if provided.
1.39 @@ -867,22 +864,6 @@
1.40 num_parameters = len(parameters) + 1
1.41 return num_parameters - (defaults and len(defaults) or 0), num_parameters
1.42
1.43 - def get_attribute_names(self, indexes):
1.44 -
1.45 - """
1.46 - Given a list of attribute table 'indexes', return a list of attribute
1.47 - names.
1.48 - """
1.49 -
1.50 - all_attrnames = self.optimiser.all_attrnames
1.51 - attrnames = []
1.52 - for i in indexes:
1.53 - if i is None:
1.54 - attrnames.append(None)
1.55 - else:
1.56 - attrnames.append(all_attrnames[i])
1.57 - return attrnames
1.58 -
1.59 def get_static_attributes(self, kind, name, attrnames):
1.60
1.61 """
1.62 @@ -987,17 +968,8 @@
1.63 structure of the given 'kind', adding entries to the object 'structure'.
1.64 """
1.65
1.66 - # Populate function instance structures for functions.
1.67 -
1.68 - if ref.has_kind("<function>"):
1.69 - origin = self.function_type
1.70 - structure_ref = Reference("<instance>", self.function_type)
1.71 -
1.72 - # Otherwise, just populate the appropriate structures.
1.73 -
1.74 - else:
1.75 - origin = ref.get_origin()
1.76 - structure_ref = ref
1.77 + structure_ref = self.get_target_structure(ref)
1.78 + origin = structure_ref.get_origin()
1.79
1.80 for attrname in self.optimiser.structures[structure_ref]:
1.81
1.82 @@ -1129,6 +1101,20 @@
1.83
1.84 structure.append(self.encode_member(origin, attrname, attr, kind))
1.85
1.86 + def get_target_structure(self, ref):
1.87 +
1.88 + "Return the target structure type and reference for 'ref'."
1.89 +
1.90 + # Populate function instance structures for functions.
1.91 +
1.92 + if ref.has_kind("<function>"):
1.93 + return Reference("<instance>", self.function_type)
1.94 +
1.95 + # Otherwise, just populate the appropriate structures.
1.96 +
1.97 + else:
1.98 + return ref
1.99 +
1.100 def encode_member(self, path, name, ref, structure_type):
1.101
1.102 """