Ignore:
Timestamp:
Oct 5, 2017, 1:21:22 PM (21 months ago)
Author:
cameron
Message:

Numeric Property Support and missing SpecialCasing?.h file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/UCD-scripts/UCD_properties.py

    r5669 r5670  
    8181    reflexive_set_ranges = cformat.multiline_fill(['[%04x, %04x]' % (lo, hi) for (lo, hi) in uset_to_range_list(reflexive_set)], ',', 8),
    8282    reflexive_set_value = reflexive_set.showC(12),
     83    explicitly_defined_cp_count = len(cps),
     84    explicitly_defined_cps = cformat.multiline_fill(['0x%04x' % cp for cp in cps], ',', 8)
     85    ))
     86
     87def emit_numeric_property(f, property_code, NaN_set, cp_value_map):
     88    s = string.Template(r"""    namespace ${prop_enum_up}_ns {
     89        /** Code Point Ranges for ${prop_enum} mapping to NaN
     90        ${NaN_set_ranges}**/
     91
     92        const UnicodeSet NaN_set
     93        ${NaN_set_value};
     94
     95       const unsigned buffer_length = ${buffer_length};
     96        const static char __attribute__ ((aligned (32))) string_buffer[${allocation_length}] = u8R"__(${string_buffer})__";
     97
     98        const static std::vector<codepoint_t> defined_cps = {
     99        ${explicitly_defined_cps}};
     100        static NumericPropertyObject property_object(${prop_enum},
     101                                                    NaN_set,
     102                                                    static_cast<const char *>(string_buffer),
     103                                                    buffer_length,
     104                                                    defined_cps);
     105    }
     106""")
     107    cps = sorted(cp_value_map.keys())
     108    string_buffer = ""
     109    for cp in cps:
     110        string_buffer += cp_value_map[cp] + "\n"
     111    buffer_length = len(string_buffer.encode("utf-8"))
     112    f.write(s.substitute(prop_enum = property_code,
     113    prop_enum_up = property_code.upper(),
     114    string_buffer = string_buffer,
     115    buffer_length = buffer_length,
     116    allocation_length = (buffer_length + 255) & -256,
     117    NaN_set_ranges = cformat.multiline_fill(['[%04x, %04x]' % (lo, hi) for (lo, hi) in uset_to_range_list(NaN_set)], ',', 8),
     118    NaN_set_value = NaN_set.showC(12),
    83119    explicitly_defined_cp_count = len(cps),
    84120    explicitly_defined_cps = cformat.multiline_fill(['0x%04x' % cp for cp in cps], ',', 8)
     
    203239        elif isinstance(property_object, StringPropertyObject):
    204240            emit_string_property(f, property_code, property_object.null_str_set, property_object.reflexive_set, property_object.cp_value_map)
     241        elif isinstance(property_object, NumericPropertyObject):
     242            emit_numeric_property(f, property_code, property_object.NaN_set, property_object.cp_value_map)
    205243        elif isinstance(property_object, ObsoletePropertyObject):
    206244            emit_Obsolete_property(f, property_code)
    207         else: return
     245        else:
     246            print("%s: unsupported property.")
     247            return
    208248        self.supported_props.append(property_code)
    209249
     
    253293        f = cformat.open_header_file_for_write(basename)
    254294        cformat.write_imports(f, ['"PropertyAliases.h"', '"PropertyObjects.h"', '"PropertyValueAliases.h"', '"unicode_set.h"'])
    255         prop_code_list = ['na', 'dm', 'suc', 'slc', 'stc', 'na1', 'isc']
     295        prop_code_list = ['na', 'dm', 'suc', 'slc', 'stc', 'na1', 'isc', 'nv']
    256296        f.write("\nnamespace UCD {\n")
    257297        for p in prop_code_list:
Note: See TracChangeset for help on using the changeset viewer.