Changeset 3928 for proto/charsetcompiler


Ignore:
Timestamp:
Jul 25, 2014, 11:36:50 AM (5 years ago)
Author:
daled
Message:

Implements the new algorithm to reduce the number of character class equations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/charset_compiler.py

    r3413 r3928  
    404404def charset_expr(chardef):
    405405    if chardef.items == []: return FalseLiteral()
     406    if len(chardef.items) > 1:
     407        combine = True
     408        #If all of the charset items are single codepoints
     409        #such that X0 == Y0, X1 == Y1 etc.
     410        for i in range(1, len(chardef.items)):
     411            if len(chardef.items[i]) == 3:
     412                combine = False
     413                break
     414        if combine == True:
     415            #If charset items are all of the form X1 = X0 + 2.
     416            for i in range(1 , len(chardef.items) - 1):
     417                curr_item = chardef.items[i]
     418                next_item = chardef.items[i+1]
     419                if ord(curr_item) != ord(next_item) - 2:
     420                    combine = False
     421                    break
     422        if combine == True:
     423            first_item = ord(chardef.items[0])
     424            last_item = ord(chardef.items[len(chardef.items)-1])
     425            utf_temp = UTF_encoding.Encoding.mask - 1
     426            first_item &= utf_temp
     427            last_item |= (UTF_encoding.Encoding.mask ^ utf_temp)
     428            return char_or_range_expr(chr(first_item) + '-' + chr(last_item))
    406429    e1 = char_or_range_expr(chardef.items[0])
    407430    for i in range(1, len(chardef.items)):   
     
    676699              print '\tprint_register<BitBlock>("%s",%s);\n' % (d.name, d.name)
    677700          print "\ndef main():\n\tDo_defs(%s)\n" % params
    678         else: print stmts 
     701        else:
     702           print stmts
     703           #fo = open("icgrep_dev/Z_equations.txt", "wb")
     704           #fo.write(stmts);
     705
     706           # Close opend file
     707           #fo.close()
    679708    else:
    680709        option_parser.print_usage()
Note: See TracChangeset for help on using the changeset viewer.