Ignore:
Timestamp:
Nov 15, 2011, 1:19:24 AM (8 years ago)
Author:
vla24
Message:

SymbolTable?: updated templates implementation to use BitBlockForwardIterator?. Fixed block boundary case handling for div2 grouping strategy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/SymbolTable/symtab_hash_template.cpp

    r1666 r1684  
    2929HashSymbolTable symbol_table;
    3030
    31 /* StreamScan & Post Process Declarations */
    32 //      static inline int StreamScanToFirst(ScanBlock * stream, int blk_count, int ProcessPos(int), int * error_pos_in_block)
    33 static inline int StreamScan(ScanBlock * stream, int blk_count, int ProcessPos(int), int * error_pos_in_block);
    34 
    3531static inline int NameStrt_check(int pos);
    3632static inline int Name_check(int pos);
     
    4743static inline void s2p_do_final_block(BytePack U8[], Basis_bits & basis_bits, BitBlock EOF_mask);
    4844static inline void postprocess_do_block(Lex & lex, CtCDPI_Callouts & ctCDPI_Callouts, Ref_Callouts & ref_Callouts, Check_streams & check_streams, Tag_Callouts & tag_Callouts, int chars_avail);
     45void do_process(FILE *infile, FILE *outfile);
     46
     47static inline void validate_block(BitBlockForwardIterator & start, int block_base, int is_valid(int));
     48static inline void validate_block(BitBlockForwardIterator & start, int block_base, int is_valid(int,int));
     49
    4950static inline void do_symbol_table_lookup();
    5051
     
    113114}
    114115
    115 /* StreamScan & Post Process Definitions */
    116 static inline int StreamScan(ScanBlock * stream, int blk_count, int ProcessPos(int), int * error_pos_in_block) {
    117 
    118         int blk;
    119         int block_pos = 0;
    120         int pos;
    121 
    122         for (blk = 0; blk < blk_count; blk++) {
    123                 ScanBlock s = stream[blk];
    124                 while(s) {
    125                         pos = (cfzl(s) + block_pos);
    126                         int code = (ProcessPos(pos));
    127                         if (code) {
    128                                 *error_pos_in_block = pos;
    129                                 return code; // error code
    130                         }
    131                         s = s & (s-1);  // clear rightmost bit.
    132                 }
    133                 block_pos += 8 * sizeof(ScanBlock);
    134         }
    135         return 0;
    136 }
    137 
    138116static inline int ElemStrt_check(int pos) {
    139         int block_pos = block_base + pos;
    140         elem_starts_buf.push(buffer_base + block_pos);
     117        elem_starts_buf.push(buffer_base + pos);
    141118        return 0;
    142119}
    143120
    144121static inline int ElemEnd_check(int pos) {
    145         int block_pos = block_base + pos;
    146         elem_ends_buf.push(buffer_base + block_pos);
     122        elem_ends_buf.push(buffer_base + pos);
    147123        return 0;
    148124}
    149125
    150126static inline int NameStrt_check(int pos) {
    151         int block_pos = block_base + pos;
    152         if(XML_10_UTF8_NameStrt_bytes((unsigned char*)&source[block_pos]) == 0){
     127        if(XML_10_UTF8_NameStrt_bytes((unsigned char*)&source[pos]) == 0){
    153128              return XMLTestSuiteError::NAME_START;
    154129        }
     
    157132
    158133static inline int Name_check(int pos) {
    159         int block_pos = block_base + pos;
    160         if(XML_10_UTF8_NameChar_bytes((unsigned char*)&source[block_pos]) == 0){
     134        if(XML_10_UTF8_NameChar_bytes((unsigned char*)&source[pos]) == 0){
    161135                  return XMLTestSuiteError::NAME;
    162136        }
     
    164138}
    165139
    166 static inline int PIName_check(int pos) {
    167         int block_pos = block_base + pos;
    168         int file_pos = block_pos+buffer_base;
    169         if (at_XxMmLll<ASCII>((unsigned char*)&source[block_pos]) && (source[block_pos+3]=='?' || source[block_pos+3]<= ' ')) {
     140static inline int PIName_check(int pos, int file_pos) {
     141        if (at_XxMmLll<ASCII>((unsigned char*)&source[pos]) && (source[pos+3]=='?' || source[pos+3]<= ' ')) {
    170142              // "<?xml" legal at start of file.
    171143              if (!((file_pos == 2) && at_XmlDecl_start<ASCII>((unsigned char*)&source[0]))) {
     
    177149
    178150static inline int CD_check(int pos) {
    179         int block_pos = block_base + pos;
    180         if (!at_CDATA1<ASCII>((unsigned char*)&source[block_pos])){
     151        if (!at_CDATA1<ASCII>((unsigned char*)&source[pos])){
    181152                  return XMLTestSuiteError::CDATA;
    182153        }
     
    185156
    186157static inline int GenRef_check(int pos) {
    187         int block_pos = block_base + pos;
    188         unsigned char* s = (unsigned char*)&source[block_pos];
     158        unsigned char* s = (unsigned char*)&source[pos];
    189159        if (!(at_Ref_gt<ASCII>(s)||at_Ref_lt<ASCII>(s)||at_Ref_amp<ASCII>(s)||at_Ref_quot<ASCII>(s)||at_Ref_apos<ASCII>(s))){
    190160              return XMLTestSuiteError::UNDEFREF;
     
    194164
    195165static inline int HexRef_check(int pos) {
    196         int block_pos = block_base + pos;
    197         unsigned char* s = (unsigned char*)&source[block_pos];
     166        unsigned char* s = (unsigned char*)&source[pos];
    198167        int ch_val = 0;
    199168        while(at_HexDigit<ASCII>(s)){
     
    214183
    215184static inline int DecRef_check(int pos) {
    216         int block_pos = block_base + pos;
    217         unsigned char* s = (unsigned char*)&source[block_pos];
     185        unsigned char* s = (unsigned char*)&source[pos];
    218186        int ch_val = 0;
    219187        while(at_HexDigit<ASCII>(s)){
     
    234202
    235203static inline int AttRef_check(int pos) {
    236         int block_pos = block_base + pos;
    237         unsigned char* s = (unsigned char*)&source[block_pos];
     204        unsigned char* s = (unsigned char*)&source[pos];
    238205        int ch_val = 0;
    239206        if(s[0]=='#'){
     
    262229}
    263230
     231static inline void validate_block(BitBlockForwardIterator & start, int block_base, int is_valid(int)) {
     232
     233        BitBlockForwardIterator end;
     234        int pos, block_pos;
     235
     236        while(start != end) {
     237
     238                block_pos = block_base + *start;
     239                int rv = is_valid(block_pos);
     240
     241                if (rv) {
     242                        int error_line, error_column;
     243                        tracker.get_Line_and_Column(block_pos, error_line, error_column);
     244                        ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
     245                        exit(-1);
     246                }
     247                start++;
     248        }
     249}
     250
     251static inline void validate_block(BitBlockForwardIterator & start, int block_base, int buffer_base, int is_valid(int,int)) {
     252
     253        BitBlockForwardIterator end;
     254        int pos, block_pos, file_pos;
     255
     256        while(start != end) {
     257
     258                block_pos = block_base + *start;
     259                file_pos = block_pos+buffer_base;
     260
     261
     262                int rv = is_valid(block_pos, file_pos);
     263
     264                if (rv) {
     265                        int error_line, error_column;
     266                        tracker.get_Line_and_Column(block_pos, error_line, error_column);
     267                        ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
     268                        exit(-1);
     269                }
     270                start++;
     271        }
     272}
     273
    264274static inline void do_symbol_table_lookup()
    265275{
     
    290300
    291301    tracker.StoreNewlines(lex.LF);
    292     int rv, error_pos_in_block, error_line, error_column;
    293302
    294303    if ( bitblock_has_bit(tag_Callouts.ElemName_starts))
    295304    {
    296         StreamScan((ScanBlock *) &tag_Callouts.ElemName_starts, sizeof(BitBlock)/sizeof(ScanBlock), ElemStrt_check, &error_pos_in_block);
     305        BitBlockForwardIterator iter_length_grouping_starts(&tag_Callouts.ElemName_starts);
     306        validate_block(iter_length_grouping_starts, block_base, ElemStrt_check);
    297307    }
    298308
    299309    if ( bitblock_has_bit(tag_Callouts.ElemName_ends) )
    300310    {
    301         StreamScan((ScanBlock *) &tag_Callouts.ElemName_ends, sizeof(BitBlock)/sizeof(ScanBlock), ElemEnd_check, &error_pos_in_block);
     311        BitBlockForwardIterator iter_length_grouping_ends(&tag_Callouts.ElemName_ends);
     312        validate_block(iter_length_grouping_ends, block_base, ElemEnd_check);
    302313    }
    303314
     
    306317
    307318    if (bitblock_has_bit(simd_or(check_streams.non_ascii_name_starts, check_streams.non_ascii_names))) {
    308       rv = StreamScan((ScanBlock *) &check_streams.non_ascii_name_starts, sizeof(BitBlock)/sizeof(ScanBlock), NameStrt_check, &error_pos_in_block);
    309       if (rv) {
    310               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    311               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    312               exit(-1);
    313       }
    314 
    315       rv = StreamScan((ScanBlock *) &check_streams.non_ascii_names, sizeof(BitBlock)/sizeof(ScanBlock), Name_check, &error_pos_in_block);
    316       if (rv) {
    317               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    318               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    319               exit(-1);
    320       }
    321     }
    322 
     319        BitBlockForwardIterator iter_NameStrt_check(&check_streams.non_ascii_name_starts);
     320        validate_block(iter_NameStrt_check, block_base, NameStrt_check);
     321        BitBlockForwardIterator iter_Name_check(&check_streams.non_ascii_names);
     322        validate_block(iter_Name_check, block_base, Name_check);
     323    }
    323324    if (bitblock_has_bit(ctCDPI_Callouts.PI_name_starts)){
    324       rv = StreamScan((ScanBlock *) &ctCDPI_Callouts.PI_name_starts, sizeof(BitBlock)/sizeof(ScanBlock), PIName_check, &error_pos_in_block);
    325       if (rv) {
    326               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    327               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    328               exit(-1);
    329       }
    330     }
    331 
     325        BitBlockForwardIterator iter_PI_name_starts(&(ctCDPI_Callouts.PI_name_starts));
     326        validate_block(iter_PI_name_starts, block_base, buffer_base, PIName_check);
     327    }
    332328    if (bitblock_has_bit(ctCDPI_Callouts.CD_starts)){
    333       rv = StreamScan((ScanBlock *) &ctCDPI_Callouts.CD_starts, sizeof(BitBlock)/sizeof(ScanBlock), CD_check, &error_pos_in_block);
    334       if (rv) {
    335               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    336               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    337               exit(-1);
    338       }
    339     }
    340 
    341     if (bitblock_has_bit(ref_Callouts.GenRef_starts)){
    342       rv = StreamScan((ScanBlock *) &ref_Callouts.GenRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), GenRef_check, &error_pos_in_block);
    343       if (rv) {
    344               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    345               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    346               exit(-1);
    347       }
    348     }
    349 
    350     if (bitblock_has_bit(ref_Callouts.DecRef_starts)){
    351       rv = StreamScan((ScanBlock *) &ref_Callouts.DecRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), DecRef_check, &error_pos_in_block);
    352       if (rv) {
    353               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    354               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    355               exit(-1);
    356       }
    357     }
    358 
    359     if (bitblock_has_bit(ref_Callouts.HexRef_starts)){
    360       rv = StreamScan((ScanBlock *) &ref_Callouts.HexRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), HexRef_check, &error_pos_in_block);
    361       if (rv) {
    362               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    363               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    364               exit(-1);
    365       }
    366     }
    367 
    368     if (bitblock_has_bit(check_streams.att_refs)){
    369       rv = StreamScan((ScanBlock *) &check_streams.att_refs, sizeof(BitBlock)/sizeof(ScanBlock), AttRef_check, &error_pos_in_block);
    370       if (rv) {
    371               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    372               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    373               exit(-1);
    374       }
     329        BitBlockForwardIterator iter_CD_check(&ctCDPI_Callouts.CD_starts);
     330        validate_block(iter_CD_check, block_base, CD_check);
     331    }
     332    if(bitblock_has_bit(ref_Callouts.GenRef_starts)){
     333        BitBlockForwardIterator iter_GenRef_check(&ref_Callouts.GenRef_starts);
     334        validate_block(iter_GenRef_check, block_base, GenRef_check);
     335    }
     336    if(bitblock_has_bit(ref_Callouts.DecRef_starts)){
     337        BitBlockForwardIterator iter_DecRef_check(&ref_Callouts.DecRef_starts);
     338        validate_block(iter_DecRef_check, block_base, DecRef_check);
     339    }
     340    if(bitblock_has_bit(ref_Callouts.HexRef_starts)){
     341        BitBlockForwardIterator iter_HexRef_check(&ref_Callouts.HexRef_starts);
     342        validate_block(iter_HexRef_check, block_base, HexRef_check);
     343    }
     344    if(bitblock_has_bit(check_streams.att_refs)){
     345        BitBlockForwardIterator iter_AttRef_check(&check_streams.att_refs);
     346        validate_block(iter_AttRef_check, block_base, AttRef_check);
    375347    }
    376348
    377349    if(error_tracker.Has_Noted_Error()){
    378             tracker.get_Line_and_Column(error_tracker.Noted_Pos_In_Block(), error_line, error_column);
    379             ReportError(error_tracker.Noted_Error_Msg(), error_line, error_column);
    380             exit(-1);
     350        int error_line, error_column;
     351        tracker.get_Line_and_Column(error_tracker.Noted_Pos_In_Block(), error_line, error_column);
     352        ReportError(error_tracker.Noted_Error_Msg(), error_line, error_column);
     353        exit(-1);
    381354    }
    382355
Note: See TracChangeset for help on using the changeset viewer.