Changeset 4185


Ignore:
Timestamp:
Sep 22, 2014, 7:21:22 AM (5 years ago)
Author:
cameron
Message:

CodepointPropertyObjects?, aliases-only maps

File:
1 edited

Legend:

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

    r4184 r4185  
    169169"""
    170170
    171 
     171EnumeratedProperty_template = r"""
     172  namespace %s {
     173    enum value_t {
     174%s};
     175    const std::string value_names[] = {
     176%s};
     177    const std::unordered_map<std::string, int> aliases_only_map[] = {
     178%s};
     179  }
     180"""
    172181
    173182PropertyValues_template = r"""
     
    185194def generate_PropertyValueAliases_h(property_enum_name_list, property_value_list, property_value_enum_integer, property_value_full_name_map, property_value_lookup_map):
    186195   f = cformat.open_header_file_for_write('PropertyValueAliases')
    187    cformat.write_imports(f, ["<string>", "<unordered_map>", '"unicode_set.h"', '"PropertyAliases.h"'])
     196   cformat.write_imports(f, ["<string>", "<unordered_map>", '"PropertyAliases.h"'])
    188197   #  Generate the aliases for all Binary properties.
    189198   full_name_text = cformat.multiline_fill(['"No"', '"Yes"'], ',', 6)
    190199   binary_map_text = cformat.multiline_fill(['{"n", N}', '{"y", Y}', '{"no", N}', '{"yes", Y}', '{"f", N}', '{"t", Y}', '{"false", N}', '{"true", Y}'], ',', 6)
    191200   #
    192    enum_text = ""
    193    name_vectors = []
    194    alias_maps = []
    195201   for p in property_enum_name_list:
    196202     if property_value_list.has_key(p):
    197        if property_value_list[p] == ['N', 'Y']:
    198          name_vectors.append('    {"No", "Yes"}')
    199          alias_maps.append("    {%s}" % binary_map_text)
    200        else:
    201          enum_text += "  namespace %s {\n    enum value_t {\n" % p.upper()
    202          #enum_text += multiline_join(property_value_list[p], 4, ',','', 6)
    203          enum_text += cformat.multiline_fill(property_value_list[p], ',', 6)
     203       if not property_value_list[p] == ['N', 'Y']:
     204         enum_text = cformat.multiline_fill(property_value_list[p], ',', 6)
    204205         if p == 'ccc': # Special case: add numeric value information for ccc.
    205206           enum_text += r"""
     
    207208    const uint8_t enum_val[] = {
    208209"""
    209            #enum_text += multiline_join(["%s" % (property_value_enum_integer[p][e]) for e in property_value_list['ccc']], 4, ',', '', 6)
    210210           enum_text += cformat.multiline_fill(["%s" % (property_value_enum_integer[p][e]) for e in property_value_list['ccc']], ',', 6)
    211          enum_text += "};\n  }\n"
    212          #full_name_text = multiline_join(['"%s"' % (property_value_full_name_map[p][e]) for e in property_value_list[p]], 4, ',',  '', 6)
    213          full_name_text = cformat.multiline_fill(['"%s"' % (property_value_full_name_map[p][e]) for e in property_value_list[p]], ',', 6)
    214          name_vectors.append("    {%s}" % full_name_text)
    215          #map_text = multiline_join(['{"%s", %s::%s}' % (k, p.upper(), property_value_lookup_map[p][k]) for k in sorted(property_value_lookup_map[p].keys())], 4, ',', '', 6)
    216          map_text = cformat.multiline_fill(['{"%s", %s::%s}' % (k, p.upper(), property_value_lookup_map[p][k]) for k in sorted(property_value_lookup_map[p].keys())], ',', 6)
    217          alias_maps.append("    {%s}" % map_text)
    218      else:
    219        name_vectors.append("    {}")
    220        alias_maps.append("    {}")
    221    f.write(PropertyValueAliases_template % (enum_text, ",\n".join(name_vectors), ",\n".join(alias_maps)))
     211         full_names = [property_value_full_name_map[p][e] for e in property_value_list[p]]
     212         full_name_text = cformat.multiline_fill(['"%s"' % name for name in full_names], ',', 6)
     213         canon_full_names = [canonicalize(name) for name in full_names]
     214         aliases_only = [k for k in property_value_lookup_map[p].keys() if not canonicalize(k) in canon_full_names]
     215         map_text = cformat.multiline_fill(['{"%s", %s::%s}' % (k, p.upper(), property_value_lookup_map[p][k]) for k in sorted(aliases_only)], ',', 6)
     216         f.write(EnumeratedProperty_template % (p.upper(), enum_text, full_name_text, map_text))
    222217   cformat.close_header_file(f)
    223218
     
    293288   cformat.close_header_file(f)
    294289     
     290CodepointProperties = ['scf', 'slc', 'suc', 'stc']
     291
    295292def generate_PropertyObjectArray_h(property_enum_name_list, property_kind_map):
    296293   f = cformat.open_header_file_for_write('PropertyObjectArray')
    297    cformat.write_imports(f, ['"PropertyObjects.h"', '"PropertyAliases.h"', '"PropertyValueAliases.h"'])
     294   cformat.write_imports(f, ['"PropertyObjects.h"', '"PropertyAliases.h"'])
    298295   objlist = []
    299296   for p in property_enum_name_list:
    300297     k = property_kind_map[p]
    301298     if k == 'Enumerated' or k == 'Catalog':
    302         objlist.append("EnumeratedPropertyObject(UCD::%s, UCD::%s::full_name, UCD::%s::alias_map)" % (p, p.upper(), p.upper()))
     299        objlist.append("EnumeratedPropertyObject(UCD::%s, UCD::%s::value_names, UCD::%s::aliases_only_map)" % (p, p.upper(), p.upper()))
     300     elif k == 'String':
     301        if p in CodepointProperties:
     302          objlist.append("CodepointPropertyObject(UCD::%s)" % p)
     303        else:
     304          objlist.append("StringPropertyObject(UCD::%s)" % p)
    303305     else:
    304306        objlist.append("%sPropertyObject(UCD::%s)" % (k, p))
    305    f.write("\nPropertyObject property_object_array[] = {\n    ")
     307   f.write("\nUnicodePropertyObject property_object_array[] = {\n    ")
    306308   f.write(",\n    ".join(objlist) + '};\n')
    307309   cformat.close_header_file(f)
Note: See TracChangeset for help on using the changeset viewer.