Changeset 4379


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

Incremental step towards general property support

Location:
proto/charsetcompiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/Makefile

    r4375 r4379  
    1717
    1818gc:
    19         python $(PABLO_COMPILER) DerivedGeneralCategory.pablo -Z -t $(PABLO_TEMPLATE) -o src/gc.h
     19        python $(PABLO_COMPILER) DerivedGeneralCategory.pablo -Z -t gc.h -o src/gc.h
    2020
    2121sc:
    22         python $(PABLO_COMPILER) Scripts.pablo -Z -t $(PABLO_TEMPLATE) -o src/sc.h
     22        python $(PABLO_COMPILER) Scripts.pablo -Z -t sc.h -o src/sc.h
    2323
    2424scx:
    25         python $(PABLO_COMPILER) ScriptExtensions.pablo -Z -t $(PABLO_TEMPLATE) -o src/scx.h
     25        python $(PABLO_COMPILER) ScriptExtensions.pablo -Z -t scx.h -o src/scx.h
    2626
  • proto/charsetcompiler/generate_UCD_property_functions.py

    r4375 r4379  
    1313from UCD.UCD_parser import *
    1414from if_hierarchy import *
     15from string import Template
     16
     17Unicode_property_fn_template = Template(r"""
     18Property_${property}_${value} * f${property}_${value} = nullptr;
     19
     20extern "C" {
     21    BitBlock __get_${property}_${value} (Basis_bits & basis_bits) {
     22        if (f${property}_${value} == nullptr) f${property}_${value} = new Property_${property}_${value}();
     23        Struct_${property}_${value} output;
     24        f${property}_${value} -> do_block(basis_bits, output);
     25        return output.cc;
     26    }
     27}
     28""")
     29
     30Unicode_pablo_template = r"""
     31
     32#include "icgrep.h"
     33
     34#define LocalCarryDeclare(name, count)\
     35CarryArray<count, 0> name;\
    1536
    1637
     38@global
    1739
    1840
    19 Unicode_CC_struct = "class struct_%s_%s:\n\tcc = 0\n\n"
     41"""
    2042
    21 Unicode_CC_header = "def %s_%s(basis_bits, struct_%s):\n"
     43Unicode_CC_struct = Template("class Struct_${property}_${value}:\n\tcc = 0\n\n")
     44
     45Unicode_CC_header = Template("def property_${property}_${value}(basis_bits, struct_${property}_${value}):\n")
    2246
    2347Unicode_dummy_main = "\n\ndef Main(basis_bits):\n    pass\n"
    2448
    25 Unicode_template_var = "struct_%s.cc"
    26 
    27 
    28 
    29 
    30 
     49Unicode_template_var = Template("struct_${property}_%s.cc")
    3150
    3251
     
    4160       (self.property_value_list, self.property_value_enum_integer, self.property_value_full_name_map, self.property_value_lookup_map, self.missing_specs) = parse_PropertyValueAlias_txt(self.property_lookup_map)
    4261
    43 
    44 
    45     def generate_property_file(self, filename_root, property_code, default_value = None):
     62    def generate_enumerated_property_template(self, filename_root, property_code):
     63       f = cformat.open_header_file_for_write(os.path.basename(property_code))
     64       f.write(Unicode_pablo_template)
     65       vlist = self.property_value_list[property_code]
     66       for v in vlist:
     67          f.write(Unicode_property_fn_template.substitute({'property': property_code.lower(), 'value': v}))
     68       cformat.close_header_file(f)
     69       
     70    def generate_enumerated_property_file(self, filename_root, property_code, default_value = None):
    4671       vlist = self.property_value_list[property_code]
    4772       canon_map = self.property_value_lookup_map[property_code]
     
    5075       f = open(basename + ".pablo", "wb")
    5176       for k in value_map.keys():
    52          f.write(Unicode_CC_struct % (property_code, k))
    53          f.write(Unicode_CC_header % (property_code, k, k))
    54          template_var = "struct_%s_%%s.cc" % property_code
     77         parms = {'property' : property_code.lower(), 'value' : k}
     78         f.write(Unicode_CC_struct.substitute(parms))
     79         f.write(Unicode_CC_header.substitute(parms))
     80         template_var = Unicode_template_var.substitute(parms)
    5581         f.write(generateCharClassDefs(defaultIfRangeList, {k: uset_to_range_list(value_map[k])},  template_var))
    5682       f.write(Unicode_dummy_main)
     
    6490       f = open(basename + ".pablo", "wb")
    6591       for k in value_map.keys():
    66          f.write(Unicode_CC_struct % (property_code, k))
    67          f.write(Unicode_CC_header % (property_code, k, k))
    68          template_var = "struct_%s_%%s.cc" % property_code
     92         parms = {'property' : 'scx', 'value' : k}
     93         f.write(Unicode_CC_struct.substitute(parms))
     94         f.write(Unicode_CC_header.substitute(parms))
     95         template_var = Unicode_template_var.substitute(parms)
    6996         f.write(generateCharClassDefs(defaultIfRangeList, {k: uset_to_range_list(value_map[k])},  template_var))
    7097       f.write(Unicode_dummy_main)
     
    83110   #
    84111   # The Block property
    85    #ucd.generate_property_file('Blocks', 'blk')
     112   #ucd.generate_enumerated_property_file('Blocks', 'blk')
    86113   #
    87114   # Scripts
    88    ucd.generate_property_file('Scripts', 'sc')
     115   ucd.generate_enumerated_property_template('Scripts', 'sc')
     116   ucd.generate_enumerated_property_file('Scripts', 'sc')
    89117   #
    90118   # Script Extensions
     119   #ucd.generate_enumerated_property_template('ScriptExtensions', 'scx')
    91120   ucd.generate_ScriptExtensions_pablo()
    92121   #
    93122   # General Category
    94    ucd.generate_property_file('extracted/DerivedGeneralCategory', 'gc')
     123   ucd.generate_enumerated_property_template('GeneralCategory', 'gc')
     124   ucd.generate_enumerated_property_file('extracted/DerivedGeneralCategory', 'gc')
    95125   #
    96126
Note: See TracChangeset for help on using the changeset viewer.