1.1 --- a/generator.py Sun Feb 12 23:24:42 2017 +0100
1.2 +++ b/generator.py Mon Feb 13 15:35:36 2017 +0100
1.3 @@ -533,7 +533,7 @@
1.4 # Define a macro for the constant.
1.5
1.6 attr_name = encode_path(const_path)
1.7 - print >>f_decls, "#define %s ((__attr) {{.context=&%s, .value=&%s}})" % (attr_name, structure_name, structure_name)
1.8 + print >>f_decls, "#define %s ((__attr) {.value=&%s})" % (attr_name, structure_name)
1.9
1.10 def make_parameter_table(self, f_decls, f_defs, parameters):
1.11
1.12 @@ -874,16 +874,10 @@
1.13
1.14 if kind == "<class>":
1.15 attr = encode_instantiator_pointer(attr)
1.16 - unbound_attr = attr
1.17 -
1.18 - # Provide bound method and unbound function pointers if
1.19 - # populating methods in a class.
1.20 -
1.21 else:
1.22 attr = encode_function_pointer(attr)
1.23 - unbound_attr = "__unbound_method"
1.24
1.25 - structure.append("{{.inv=%s, .fn=%s}}" % (unbound_attr, attr))
1.26 + structure.append("{.fn=%s}" % attr)
1.27 continue
1.28
1.29 # Special argument specification member.
1.30 @@ -892,7 +886,7 @@
1.31 signature = self.get_signature_for_callable(ref.get_origin())
1.32 ptable = encode_tablename("<function>", signature)
1.33
1.34 - structure.append("{{.min=%s, .ptable=&%s}}" % (attr, ptable))
1.35 + structure.append("{.min=%s, .ptable=&%s}" % (attr, ptable))
1.36 continue
1.37
1.38 # Special internal data member.
1.39 @@ -906,8 +900,8 @@
1.40 # Special internal key member.
1.41
1.42 elif attrname == "__key__":
1.43 - structure.append("{{.code=%s, .pos=%s}}" % (attr and encode_symbol("code", attr) or "0",
1.44 - attr and encode_symbol("pos", attr) or "0"))
1.45 + structure.append("{.code=%s, .pos=%s}" % (attr and encode_symbol("code", attr) or "0",
1.46 + attr and encode_symbol("pos", attr) or "0"))
1.47 continue
1.48
1.49 # Special cases.
1.50 @@ -950,13 +944,33 @@
1.51 # object paths.
1.52
1.53 value = path.rsplit(".", 1)[0]
1.54 - structure.append("{{.context=0, .value=&%s}}" % encode_path(value))
1.55 + structure.append("{.value=&%s}" % encode_path(value))
1.56 + continue
1.57 +
1.58 + # Special context member.
1.59 + # Set the context depending on the kind of attribute.
1.60 + # For methods: <parent>
1.61 + # For other attributes: __NULL
1.62 +
1.63 + elif attrname == "__context__":
1.64 + path = ref.get_origin()
1.65 +
1.66 + # Contexts of methods are derived from their object paths.
1.67 +
1.68 + context = "0"
1.69 +
1.70 + if ref.get_kind() == "<function>":
1.71 + parent = path.rsplit(".", 1)[0]
1.72 + if self.importer.classes.has_key(parent):
1.73 + context = "&%s" % encode_path(parent)
1.74 +
1.75 + structure.append("{.value=%s}" % context)
1.76 continue
1.77
1.78 # Special class relationship attributes.
1.79
1.80 elif is_type_attribute(attrname):
1.81 - structure.append("{{.context=0, .value=&%s}}" % encode_path(decode_type_attribute(attrname)))
1.82 + structure.append("{.value=&%s}" % encode_path(decode_type_attribute(attrname)))
1.83 continue
1.84
1.85 # All other kinds of members.
1.86 @@ -995,33 +1009,22 @@
1.87
1.88 if kind == "<instance>" and origin == self.none_type:
1.89 attr_path = encode_predefined_reference(self.none_value)
1.90 - return "{{.context=&%s, .value=&%s}} /* %s */" % (attr_path, attr_path, name)
1.91 + return "{.value=&%s} /* %s */" % (attr_path, name)
1.92
1.93 # Predefined constant members.
1.94
1.95 if (path, name) in self.predefined_constant_members:
1.96 attr_path = encode_predefined_reference("%s.%s" % (path, name))
1.97 - return "{{.context=&%s, .value=&%s}} /* %s */" % (attr_path, attr_path, name)
1.98 + return "{.value=&%s} /* %s */" % (attr_path, name)
1.99
1.100 # General undetermined members.
1.101
1.102 if kind in ("<var>", "<instance>"):
1.103 attr_path = encode_predefined_reference(self.none_value)
1.104 - return "{{.context=&%s, .value=&%s}} /* %s */" % (attr_path, attr_path, name)
1.105 -
1.106 - # Set the context depending on the kind of attribute.
1.107 - # For methods: {&<parent>, &<attr>}
1.108 - # For other attributes: {&<attr>, &<attr>}
1.109 + return "{.value=&%s} /* %s */" % (attr_path, name)
1.110
1.111 else:
1.112 - if kind == "<function>" and structure_type == "<class>":
1.113 - parent = origin.rsplit(".", 1)[0]
1.114 - context = "&%s" % encode_path(parent)
1.115 - elif kind == "<instance>":
1.116 - context = "&%s" % encode_path(origin)
1.117 - else:
1.118 - context = "0"
1.119 - return "{{.context=%s, .value=&%s}}" % (context, encode_path(origin))
1.120 + return "{.value=&%s}" % encode_path(origin)
1.121
1.122 def append_defaults(self, path, structure):
1.123
1.124 @@ -1129,7 +1132,7 @@
1.125 }
1.126 __Catch(__tmp_exc)
1.127 {
1.128 - if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {{.context=0, .value=&__builtins___exception_system_SystemExit}})))
1.129 + if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {.value=&__builtins___exception_system_SystemExit})))
1.130 return __load_via_object(
1.131 __load_via_object(__tmp_exc.arg.value, %s).value,
1.132 %s).intvalue;