# HG changeset patch # User Paul Boddie # Date 1481668089 -3600 # Node ID 9e1d8b186e5c7710895ba1e9b0b02f26b8c0f0b0 # Parent e545439a787cdb3ce30430ea12ae363175fdc7cc Initialise the encoding of Unicode constants to None, also introducing generic support for initialising None members. diff -r e545439a787c -r 9e1d8b186e5c generator.py --- a/generator.py Tue Dec 13 23:26:33 2016 +0100 +++ b/generator.py Tue Dec 13 23:28:09 2016 +0100 @@ -56,8 +56,12 @@ # NOTE: These must be synchronised with the library. function_type = "__builtins__.core.function" + none_type = "__builtins__.none.NoneType" string_type = "__builtins__.str.string" type_type = "__builtins__.core.type" + unicode_type = "__builtins__.unicode.utf8string" + + none_value = "__builtins__.none.None" predefined_constant_members = ( ("__builtins__.boolean", "False"), @@ -494,6 +498,11 @@ else: attrs["__key__"] = None + # Define Unicode constant encoding details. + + if cls == self.unicode_type: + attrs["encoding"] = Reference("", self.none_type) + # Define the structure details. An object is created for the constant, # but an attribute is provided, referring to the object, for access to # the constant in the program. @@ -933,7 +942,13 @@ constant_value = "__const%d" % constant_number return "%s /* %s */" % (constant_value, name) - # Predefined constant references. + # Usage of predefined constants, currently only None supported. + + if kind == "" and origin == self.none_type: + attr_path = encode_predefined_reference(self.none_value) + return "{&%s, &%s} /* %s */" % (attr_path, attr_path, name) + + # Predefined constant members. if (path, name) in self.predefined_constant_members: attr_path = encode_predefined_reference("%s.%s" % (path, name))