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_ls_template.cpp

    r1648 r1684  
    2929LSSymbolTable ls_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));
    4949static inline void do_symbol_table_lookup();
    50 
    51 void do_process(FILE *infile, FILE *outfile);
    5250
    5351int main(int argc, char * argv[]) {
     
    113111}
    114112
    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 
    138113static inline int ElemStrt_check(int pos) {
    139         int block_pos = block_base + pos;
    140         elem_starts_buf.push(buffer_base + block_pos);
     114        elem_starts_buf.push(buffer_base + pos);
    141115        return 0;
    142116}
    143117
    144118static inline int ElemEnd_check(int pos) {
    145         int block_pos = block_base + pos;
    146         elem_ends_buf.push(buffer_base + block_pos);
     119        elem_ends_buf.push(buffer_base + pos);
    147120        return 0;
    148121}
    149122
    150123static 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){
     124        if(XML_10_UTF8_NameStrt_bytes((unsigned char*)&source[pos]) == 0){
    153125              return XMLTestSuiteError::NAME_START;
    154126        }
     
    157129
    158130static 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){
     131        if(XML_10_UTF8_NameChar_bytes((unsigned char*)&source[pos]) == 0){
    161132                  return XMLTestSuiteError::NAME;
    162133        }
     
    164135}
    165136
    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]<= ' ')) {
     137static inline int PIName_check(int pos, int file_pos) {
     138        if (at_XxMmLll<ASCII>((unsigned char*)&source[pos]) && (source[pos+3]=='?' || source[pos+3]<= ' ')) {
    170139              // "<?xml" legal at start of file.
    171140              if (!((file_pos == 2) && at_XmlDecl_start<ASCII>((unsigned char*)&source[0]))) {
     
    177146
    178147static inline int CD_check(int pos) {
    179         int block_pos = block_base + pos;
    180         if (!at_CDATA1<ASCII>((unsigned char*)&source[block_pos])){
     148        if (!at_CDATA1<ASCII>((unsigned char*)&source[pos])){
    181149                  return XMLTestSuiteError::CDATA;
    182150        }
     
    185153
    186154static inline int GenRef_check(int pos) {
    187         int block_pos = block_base + pos;
    188         unsigned char* s = (unsigned char*)&source[block_pos];
     155        unsigned char* s = (unsigned char*)&source[pos];
    189156        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))){
    190157              return XMLTestSuiteError::UNDEFREF;
     
    194161
    195162static inline int HexRef_check(int pos) {
    196         int block_pos = block_base + pos;
    197         unsigned char* s = (unsigned char*)&source[block_pos];
     163        unsigned char* s = (unsigned char*)&source[pos];
    198164        int ch_val = 0;
    199165        while(at_HexDigit<ASCII>(s)){
     
    214180
    215181static inline int DecRef_check(int pos) {
    216         int block_pos = block_base + pos;
    217         unsigned char* s = (unsigned char*)&source[block_pos];
     182        unsigned char* s = (unsigned char*)&source[pos];
    218183        int ch_val = 0;
    219184        while(at_HexDigit<ASCII>(s)){
     
    234199
    235200static inline int AttRef_check(int pos) {
    236         int block_pos = block_base + pos;
    237         unsigned char* s = (unsigned char*)&source[block_pos];
     201        unsigned char* s = (unsigned char*)&source[pos];
    238202        int ch_val = 0;
    239203        if(s[0]=='#'){
     
    262226}
    263227
     228static inline void validate_block(BitBlockForwardIterator & start, int block_base, int is_valid(int)) {
     229
     230        BitBlockForwardIterator end;
     231        int pos, block_pos;
     232
     233        while(start != end) {
     234
     235                block_pos = block_base + *start;
     236                int rv = is_valid(block_pos);
     237
     238                if (rv) {
     239                        int error_line, error_column;
     240                        tracker.get_Line_and_Column(block_pos, error_line, error_column);
     241                        ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
     242                        exit(-1);
     243                }
     244                start++;
     245        }
     246}
     247
     248static inline void validate_block(BitBlockForwardIterator & start, int block_base, int buffer_base, int is_valid(int,int)) {
     249
     250        BitBlockForwardIterator end;
     251        int pos, block_pos, file_pos;
     252
     253        while(start != end) {
     254
     255                block_pos = block_base + *start;
     256                file_pos = block_pos+buffer_base;
     257
     258
     259                int rv = is_valid(block_pos, file_pos);
     260
     261                if (rv) {
     262                        int error_line, error_column;
     263                        tracker.get_Line_and_Column(block_pos, error_line, error_column);
     264                        ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
     265                        exit(-1);
     266                }
     267                start++;
     268        }
     269}
     270
     271
    264272static inline void do_symbol_table_lookup()
    265273{
     
    290298
    291299    tracker.StoreNewlines(lex.LF);
    292     int rv, error_pos_in_block, error_line, error_column;
    293300
    294301    if ( bitblock_has_bit(tag_Callouts.ElemName_starts))
    295302    {
    296         StreamScan((ScanBlock *) &tag_Callouts.ElemName_starts, sizeof(BitBlock)/sizeof(ScanBlock), ElemStrt_check, &error_pos_in_block);
     303        BitBlockForwardIterator iter_length_grouping_starts(&tag_Callouts.ElemName_starts);
     304        validate_block(iter_length_grouping_starts, block_base, ElemStrt_check);
    297305    }
    298306
    299307    if ( bitblock_has_bit(tag_Callouts.ElemName_ends) )
    300308    {
    301         StreamScan((ScanBlock *) &tag_Callouts.ElemName_ends, sizeof(BitBlock)/sizeof(ScanBlock), ElemEnd_check, &error_pos_in_block);
     309        BitBlockForwardIterator iter_length_grouping_ends(&tag_Callouts.ElemName_ends);
     310        validate_block(iter_length_grouping_ends, block_base, ElemEnd_check);
    302311    }
    303312
    304313    do_symbol_table_lookup();
    305314
     315
    306316    if (bitblock_has_bit(simd_or(check_streams.non_ascii_name_starts, check_streams.non_ascii_names))) {
    307       rv = StreamScan((ScanBlock *) &check_streams.non_ascii_name_starts, sizeof(BitBlock)/sizeof(ScanBlock), NameStrt_check, &error_pos_in_block);
    308       if (rv) {
    309               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    310               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    311               exit(-1);
    312       }
    313 
    314       rv = StreamScan((ScanBlock *) &check_streams.non_ascii_names, sizeof(BitBlock)/sizeof(ScanBlock), Name_check, &error_pos_in_block);
    315       if (rv) {
    316               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    317               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    318               exit(-1);
    319       }
    320     }
    321 
     317        BitBlockForwardIterator iter_NameStrt_check(&check_streams.non_ascii_name_starts);
     318        validate_block(iter_NameStrt_check, block_base, NameStrt_check);
     319        BitBlockForwardIterator iter_Name_check(&check_streams.non_ascii_names);
     320        validate_block(iter_Name_check, block_base, Name_check);
     321    }
    322322    if (bitblock_has_bit(ctCDPI_Callouts.PI_name_starts)){
    323       rv = StreamScan((ScanBlock *) &ctCDPI_Callouts.PI_name_starts, sizeof(BitBlock)/sizeof(ScanBlock), PIName_check, &error_pos_in_block);
    324       if (rv) {
    325               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    326               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    327               exit(-1);
    328       }
    329     }
    330 
     323        BitBlockForwardIterator iter_PI_name_starts(&(ctCDPI_Callouts.PI_name_starts));
     324        validate_block(iter_PI_name_starts, block_base, buffer_base, PIName_check);
     325    }
    331326    if (bitblock_has_bit(ctCDPI_Callouts.CD_starts)){
    332       rv = StreamScan((ScanBlock *) &ctCDPI_Callouts.CD_starts, sizeof(BitBlock)/sizeof(ScanBlock), CD_check, &error_pos_in_block);
    333       if (rv) {
    334               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    335               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    336               exit(-1);
    337       }
    338     }
    339 
    340     if (bitblock_has_bit(ref_Callouts.GenRef_starts)){
    341       rv = StreamScan((ScanBlock *) &ref_Callouts.GenRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), GenRef_check, &error_pos_in_block);
    342       if (rv) {
    343               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    344               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    345               exit(-1);
    346       }
    347     }
    348 
    349     if (bitblock_has_bit(ref_Callouts.DecRef_starts)){
    350       rv = StreamScan((ScanBlock *) &ref_Callouts.DecRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), DecRef_check, &error_pos_in_block);
    351       if (rv) {
    352               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    353               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    354               exit(-1);
    355       }
    356     }
    357 
    358     if (bitblock_has_bit(ref_Callouts.HexRef_starts)){
    359       rv = StreamScan((ScanBlock *) &ref_Callouts.HexRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), HexRef_check, &error_pos_in_block);
    360       if (rv) {
    361               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    362               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    363               exit(-1);
    364       }
    365     }
    366 
    367     if (bitblock_has_bit(check_streams.att_refs)){
    368       rv = StreamScan((ScanBlock *) &check_streams.att_refs, sizeof(BitBlock)/sizeof(ScanBlock), AttRef_check, &error_pos_in_block);
    369       if (rv) {
    370               tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    371               ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column);
    372               exit(-1);
    373       }
     327        BitBlockForwardIterator iter_CD_check(&ctCDPI_Callouts.CD_starts);
     328        validate_block(iter_CD_check, block_base, CD_check);
     329    }
     330    if(bitblock_has_bit(ref_Callouts.GenRef_starts)){
     331        BitBlockForwardIterator iter_GenRef_check(&ref_Callouts.GenRef_starts);
     332        validate_block(iter_GenRef_check, block_base, GenRef_check);
     333    }
     334    if(bitblock_has_bit(ref_Callouts.DecRef_starts)){
     335        BitBlockForwardIterator iter_DecRef_check(&ref_Callouts.DecRef_starts);
     336        validate_block(iter_DecRef_check, block_base, DecRef_check);
     337    }
     338    if(bitblock_has_bit(ref_Callouts.HexRef_starts)){
     339        BitBlockForwardIterator iter_HexRef_check(&ref_Callouts.HexRef_starts);
     340        validate_block(iter_HexRef_check, block_base, HexRef_check);
     341    }
     342    if(bitblock_has_bit(check_streams.att_refs)){
     343        BitBlockForwardIterator iter_AttRef_check(&check_streams.att_refs);
     344        validate_block(iter_AttRef_check, block_base, AttRef_check);
    374345    }
    375346
    376347    if(error_tracker.Has_Noted_Error()){
    377             tracker.get_Line_and_Column(error_tracker.Noted_Pos_In_Block(), error_line, error_column);
    378             ReportError(error_tracker.Noted_Error_Msg(), error_line, error_column);
    379             exit(-1);
     348        int error_line, error_column;
     349        tracker.get_Line_and_Column(error_tracker.Noted_Pos_In_Block(), error_line, error_column);
     350        ReportError(error_tracker.Noted_Error_Msg(), error_line, error_column);
     351        exit(-1);
    380352    }
    381353
Note: See TracChangeset for help on using the changeset viewer.