Ignore:
Timestamp:
Sep 29, 2017, 9:59:40 AM (20 months ago)
Author:
cameron
Message:

Updates for Python 3; some refactoring

File:
1 edited

Legend:

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

    r5652 r5653  
    4747        self.property_data_headers = []
    4848        self.missing_specs = {}
     49        self.binary_properties = {}
    4950
    5051    def load_property_name_info(self):
     
    7879        #
    7980        for p in self.property_enum_name_list:
    80            if self.property_value_list.has_key(p):
     81           if p in self.property_value_list:
    8182              if not self.property_kind_map[p] == 'Binary':
    8283                  enum_text = cformat.multiline_fill(self.property_value_list[p], ',', 12)
     
    99100        cformat.close_header_file(f)
    100101
    101  
    102102    def generate_property_value_file(self, filename_root, property_code):
    103         canon_map = self.property_value_lookup_map[property_code]
    104         if self.missing_specs.has_key(property_code):
    105             default_value = canon_map[canonicalize(self.missing_specs[property_code])]
    106         else: default_value = None
    107103        vlist = self.property_value_list[property_code]
    108104        canon_map = self.property_value_lookup_map[property_code]
    109         (prop_values, value_map) = parse_UCD_enumerated_property_map(property_code, vlist, canon_map, filename_root + '.txt', default_value)
     105        (prop_values, value_map) = parse_UCD_enumerated_property_map(property_code, vlist, canon_map, filename_root + '.txt')
     106        canon_map = self.property_value_lookup_map[property_code]
     107        if property_code in self.missing_specs:
     108            default_value = canon_map[canonicalize(self.missing_specs[property_code])]
     109            value_map = add_Default_Values(value_map, 0, 0x10FFFF, default_value)
    110110        independent_prop_values = len(prop_values)
    111111        for v in vlist:
     
    116116        #
    117117        self.property_value_list[property_code] = prop_values
    118         basename = os.path.basename(filename_root)
    119         f = cformat.open_header_file_for_write(os.path.basename(filename_root))
    120         cformat.write_imports(f, ['"PropertyObjects.h"', '"PropertyValueAliases.h"', '"unicode_set.h"'])
    121         f.write("\nnamespace UCD {\n")
    122         f.write("  namespace %s_ns {\n" % property_code.upper())
    123         f.write("    const unsigned independent_prop_values = %s;\n" % independent_prop_values)
    124118        if property_code == 'gc':
    125119            # special logic for derived categories
     
    132126            value_map['Z'] = union_of_all([value_map[v] for v in ['Zs', 'Zl', 'Zp']])
    133127            value_map['C'] = union_of_all([value_map[v] for v in ['Cc', 'Cf', 'Cs', 'Co', 'Cn']])
     128        basename = os.path.basename(filename_root)
     129        f = cformat.open_header_file_for_write(os.path.basename(filename_root))
     130        cformat.write_imports(f, ['"PropertyObjects.h"', '"PropertyValueAliases.h"', '"unicode_set.h"'])
     131        f.write("\nnamespace UCD {\n")
     132        f.write("  namespace %s_ns {\n" % property_code.upper())
     133        f.write("    const unsigned independent_prop_values = %s;\n" % independent_prop_values)
    134134        for v in prop_values:
    135135            f.write("    /** Code Point Ranges for %s\n    " % v)
    136             f.write(cformat.multiline_fill(['[%s, %s]' % (lo, hi) for (lo, hi) in uset_to_range_list(value_map[v])], ',', 4))
     136            f.write(cformat.multiline_fill(['[%04x, %04x]' % (lo, hi) for (lo, hi) in uset_to_range_list(value_map[v])], ',', 4))
    137137            f.write("**/\n")
    138138            f.write("    const UnicodeSet %s_Set \n" % v.lower())
    139139            f.write(value_map[v].showC(8) + ";\n")
    140         print "%s: %s bytes" % (basename, sum([value_map[v].bytes() for v in value_map.keys()]))
     140        print("%s: %s bytes" % (basename, sum([value_map[v].bytes() for v in value_map.keys()])))
    141141        set_list = ['&%s_Set' % v.lower() for v in prop_values]
    142142        f.write("    static EnumeratedPropertyObject property_object\n")
     
    176176        f.write("\n        }};\n    }\n}\n")
    177177        cformat.close_header_file(f)
    178         print "%s: %s bytes" % (basename, sum([value_map[v].bytes() for v in value_map.keys()]))
     178        print("%s: %s bytes" % (basename, sum([value_map[v].bytes() for v in value_map.keys()])))
    179179        self.supported_props.append(property_code)
    180180        self.property_data_headers.append(basename)
     
    199199        f.write("}\n\n")
    200200        cformat.close_header_file(f)
    201         print "%s: %s bytes" % (basename, sum([prop_map[p].bytes() for p in prop_map.keys()]))
     201        print("%s: %s bytes" % (basename, sum([prop_map[p].bytes() for p in prop_map.keys()])))
    202202        self.supported_props += props
     203        for p in prop_map.keys(): self.binary_properties[p] = prop_map[p]
    203204        self.property_data_headers.append(basename)
    204205
     
    284285    ucd.generate_property_value_file('HangulSyllableType', 'hst')
    285286    #
    286     # Bidi_Class
    287     ucd.generate_property_value_file('extracted/DerivedBidiClass', 'bc')
    288     #
    289287    # Bidi Mirroroing from DerivedCoreProperties.txt
    290288    ucd.generate_binary_properties_file('extracted/DerivedBinaryProperties')
     
    306304    # Binary normalization properties.
    307305    ucd.generate_binary_properties_file('DerivedNormalizationProps')
     306    #
     307    # Bidi_Class
     308    ucd.generate_property_value_file('extracted/DerivedBidiClass', 'bc')
    308309
    309310    #
Note: See TracChangeset for help on using the changeset viewer.