1.1 --- a/translator.py Sun Nov 27 20:54:08 2016 +0100
1.2 +++ b/translator.py Sun Nov 27 22:40:49 2016 +0100
1.3 @@ -754,10 +754,37 @@
1.4 class_name = self.get_namespace_path()
1.5 self.write_comment("Class: %s" % class_name)
1.6
1.7 + self.initialise_inherited_members(class_name)
1.8 +
1.9 self.process_structure(n)
1.10 + self.write_comment("End class: %s" % class_name)
1.11
1.12 self.exit_namespace()
1.13
1.14 + def initialise_inherited_members(self, class_name):
1.15 +
1.16 + "Initialise members of 'class_name' inherited from its ancestors."
1.17 +
1.18 + for name, path in self.importer.all_class_attrs[class_name].items():
1.19 + target = "%s.%s" % (class_name, name)
1.20 +
1.21 + # Ignore attributes with definitions.
1.22 +
1.23 + ref = self.importer.identify(target)
1.24 + if ref:
1.25 + continue
1.26 +
1.27 + # Reference inherited attributes.
1.28 +
1.29 + ref = self.importer.identify(path)
1.30 + if ref and not ref.static():
1.31 + parent, attrname = path.rsplit(".", 1)
1.32 +
1.33 + self.writestmt("__store_via_object(&%s, %s, __load_via_object(&%s, %s));" % (
1.34 + encode_path(class_name), encode_symbol("pos", name),
1.35 + encode_path(parent), encode_symbol("pos", attrname)
1.36 + ))
1.37 +
1.38 def process_function_body_node(self, n):
1.39
1.40 """
1.41 @@ -816,10 +843,18 @@
1.42 else:
1.43 return
1.44
1.45 + # Produce an appropriate access to an attribute's value.
1.46 +
1.47 + parameters = self.importer.function_parameters.get(self.get_namespace_path())
1.48 + if parameters and name in parameters:
1.49 + name_to_value = "%s->value" % name
1.50 + else:
1.51 + name_to_value = "%s.value" % name
1.52 +
1.53 # Write a test that raises a TypeError upon failure.
1.54
1.55 - self.writestmt("if (!__test_%s_%s(%s->value, %s)) __raise_type_error();" % (
1.56 - guard, guard_type, name, argstr))
1.57 + self.writestmt("if (!__test_%s_%s(%s, %s)) __raise_type_error();" % (
1.58 + guard, guard_type, name_to_value, argstr))
1.59
1.60 def process_function_node(self, n):
1.61