Changeset 4381


Ignore:
Timestamp:
Dec 31, 2014, 9:48:05 PM (4 years ago)
Author:
cameron
Message:

Various fixes to UCD property data system

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/UCD/UCD_properties.py

    r4375 r4381  
    4545
    4646EnumeratedProperty_template = r"""
    47   namespace %s {
     47  namespace %s_ns {
    4848    enum value_t {
     49      %s};
     50    const std::vector<std::string> enum_names = {
    4951      %s};
    5052    const std::vector<std::string> value_names = {
     
    8688       #  Generate the aliases for all Binary properties.
    8789       enum_text = cformat.multiline_fill(['N', 'Y'], ',', 6)
     90       enum_names = cformat.multiline_fill(['"N"', '"Y"'], ',', 6)
    8891       full_name_text = cformat.multiline_fill(['"No"', '"Yes"'], ',', 6)
    8992       binary_map_text = cformat.multiline_fill(['{"n", N}', '{"y", Y}', '{"no", N}', '{"yes", Y}', '{"f", N}', '{"t", Y}', '{"false", N}', '{"true", Y}'], ',', 6)
    90        f.write(EnumeratedProperty_template % ('Binary', enum_text, full_name_text, binary_map_text))
     93       f.write(EnumeratedProperty_template % ('Binary', enum_text, enum_names, full_name_text, binary_map_text))
    9194       #
    9295       for p in self.property_enum_name_list:
     
    9497           if not self.property_kind_map[p] == 'Binary':
    9598             enum_text = cformat.multiline_fill(self.property_value_list[p], ',', 6)
     99             enum_names = cformat.multiline_fill(['"%s"' % s for s in self.property_value_list[p]], ',', 6)
    96100             if p == 'ccc': # Special case: add numeric value information for ccc.
    97101               enum_text += r"""
     
    103107             full_name_text = cformat.multiline_fill(['"%s"' % name for name in full_names], ',', 6)
    104108             canon_full_names = [canonicalize(name) for name in full_names]
    105              aliases_only = [k for k in self.property_value_lookup_map[p].keys() if not canonicalize(k) in canon_full_names and k == canonicalize(k)]
    106              map_text = cformat.multiline_fill(['{"%s", %s::%s}' % (k, p.upper(), self.property_value_lookup_map[p][k]) for k in sorted(aliases_only)], ',', 6)
    107              f.write(EnumeratedProperty_template % (p.upper(), enum_text, full_name_text, map_text))
     109             canon_enums = [canonicalize(e) for e in self.property_value_list[p]]
     110             canon_keys = [canonicalize(k) for k in self.property_value_lookup_map[p].keys()]
     111             aliases_only = [k for k in canon_keys if not k in canon_enums + canon_full_names]
     112             map_text = cformat.multiline_fill(['{"%s", %s_ns::%s}' % (k, p.upper(), self.property_value_lookup_map[p][k]) for k in sorted(aliases_only)], ',', 6)
     113             f.write(EnumeratedProperty_template % (p.upper(), enum_text, enum_names, full_name_text, map_text))
    108114       f.write("}\n")
    109115       cformat.close_header_file(f)
     
    118124       cformat.write_imports(f, ["<vector>", '"unicode_set.h"', '"PropertyAliases.h"', '"PropertyValueAliases.h"'])
    119125       f.write("\nnamespace UCD {\n")
    120        f.write("  namespace %s {\n" % property_code.upper())
     126       f.write("  namespace %s_ns {\n" % property_code.upper())
    121127       for v in self.property_value_list[property_code]:
    122128         f.write("    const UnicodeSet %s_Set \n" % v.lower())
     
    124130       print "%s: %s bytes" % (basename, sum([value_map[v].bytes() for v in value_map.keys()]))
    125131       set_list = ['%s_Set' % v.lower() for v in self.property_value_list[property_code]]
    126        f.write("    const EnumeratedPropertyObject property_object\n")
     132       f.write("    EnumeratedPropertyObject property_object\n")
    127133       f.write("      {%s,\n" % property_code)
    128        f.write("       %s::value_names,\n" % property_code.upper())
    129        f.write("       %s::aliases_only_map,\n" % property_code.upper())
     134       f.write("       %s_ns::enum_names,\n" % property_code.upper())
     135       f.write("       %s_ns::value_names,\n" % property_code.upper())
     136       f.write("       %s_ns::aliases_only_map,\n" % property_code.upper())
    130137       f.write("       {")
    131138       f.write(cformat.multiline_fill(set_list, ',', 8))
     
    142149       f = cformat.open_header_file_for_write(basename)
    143150       cformat.write_imports(f, ["<vector>", '"PropertyAliases.h"', '"PropertyValueAliases.h"', '"unicode_set.h"'])
    144        f.write("\nusing namespace UCD;\n\n")
     151       f.write("\nnamespace UCD {\n")
     152       f.write("  namespace SCX_ns {\n")
    145153       for v in self.property_value_list['sc']:
    146154         f.write("    const UnicodeSet %s_Ext \n" % v.lower())
     
    148156       print "%s: %s bytes" % (basename, sum([value_map[v].bytes() for v in value_map.keys()]))
    149157       set_list = ['%s_Ext' % v.lower() for v in self.property_value_list['sc']]
    150        f.write("    const EnumeratedPropertyObject property_object\n")
     158       f.write("    EnumeratedPropertyObject property_object\n")
    151159       f.write("      {%s,\n" % property_code)
    152        f.write("       SC::value_names,\n")
    153        f.write("       SC:aliases_only_map,\n")
     160       f.write("       SC_ns::enum_names,\n")
     161       f.write("       SC_ns::value_names,\n")
     162       f.write("       SC_ns::aliases_only_map,\n")
    154163       f.write("       {")
    155164       f.write(cformat.multiline_fill(set_list, ',', 8))
     
    168177       print "%s: %s bytes" % (basename, sum([prop_map[p].bytes() for p in prop_map.keys()]))
    169178       for p in sorted(props):
    170          f.write("  namespace %s {\n    const UnicodeSet codepoint_set \n" % p.upper())
     179         f.write("  namespace %s_ns {\n    const UnicodeSet codepoint_set \n" % p.upper())
    171180         f.write(prop_map[p].showC(6) + ";\n")
    172          f.write("    const BinaryPropertyObject property_object{%s, codepoint_set};\n  }\n" % p)
     181         f.write("    BinaryPropertyObject property_object{%s, codepoint_set};\n  }\n" % p)
    173182       f.write("}\n\n")
    174183       cformat.close_header_file(f)
     
    185194         k = self.property_kind_map[p]
    186195         if (k == 'Enumerated' or k == 'Catalog') and p in self.supported_props:
    187             objlist.append("&%s::property_object" % p.upper())
     196            objlist.append("&%s_ns::property_object" % p.upper())
    188197         elif k == 'String':
    189198            if p in CodepointProperties:
     
    192201              objlist.append("new UnsupportedPropertyObject(%s, StringProperty)" % p)
    193202         elif k == 'Binary' and p in self.supported_props:
    194             objlist.append("&%s::property_object" % p.upper())
     203            objlist.append("&%s_ns::property_object" % p.upper())
    195204         else:
    196205            objlist.append("new UnsupportedPropertyObject(%s, %sProperty)" % (p, k))
    197        f.write("\n  const PropertyObject* property_object_table[] = {\n    ")
     206       f.write("\n  PropertyObject* property_object_table[] = {\n    ")
    198207       f.write(",\n    ".join(objlist) + '  };\n}\n')
    199208       cformat.close_header_file(f)
Note: See TracChangeset for help on using the changeset viewer.