// caller already consumed '<' // scan header start or tag tail scanner::token_type scanner::scan_tag() { tag_name_length = 0; wchar c = get_char(); bool is_tail = c == '/'; if(is_tail) c = get_char(); while(c) { if(is_whitespace(c)) { c = skip_whitespace(); break; } if(c == '/' || c == '>') break; append_tag_name(c); switch(tag_name_length) { case 3: if(equal(tag_name,"!--",3)) { c_scan = &scanner::scan_comment; return TT_COMMENT_START; } break; case 8: if( equal(tag_name,"![CDATA[",8) ) { c_scan = &scanner::scan_cdata; return TT_CDATA_START; } break; case 7: if( equal(tag_name,"!ENTITY",8) ) { c_scan = &scanner::scan_entity_decl; return TT_ENTITY_START; } break; } c = get_char(); } if(c == 0) return TT_ERROR; if(is_tail) { if(c == '>') return TT_TAG_END; return TT_ERROR; } else push_back(c); c_scan = &scanner::scan_head; return TT_TAG_START; }
/* * See also it's preprocessor counterpart * add_long_preprocessor_conditional_block_comment * in defines.cpp */ void add_long_closebrace_comment(void) { LOG_FUNC_ENTRY(); chunk_t *br_close; chunk_t *fcn_pc = NULL; chunk_t *sw_pc = NULL; chunk_t *ns_pc = NULL; chunk_t *cl_pc = NULL; chunk_t *cl_semi_pc = NULL; unc_text xstr; for (chunk_t *pc = chunk_get_head(); pc; pc = chunk_get_next_ncnl(pc)) { if ((pc->type == CT_FUNC_DEF) || (pc->type == CT_OC_MSG_DECL)) { fcn_pc = pc; } else if (pc->type == CT_SWITCH) { /* kinda pointless, since it always has the text "switch" */ sw_pc = pc; } else if (pc->type == CT_NAMESPACE) { ns_pc = pc; } else if (pc->type == CT_CLASS) { cl_pc = pc; } if ((pc->type != CT_BRACE_OPEN) || (pc->flags & PCF_IN_PREPROC)) { continue; } chunk_t *br_open = pc; size_t nl_count = 0; chunk_t *tmp = pc; while ((tmp = chunk_get_next(tmp)) != NULL) { if (chunk_is_newline(tmp)) { nl_count += tmp->nl_count; } else if ((tmp->level == br_open->level) && (tmp->type == CT_BRACE_CLOSE)) { br_close = tmp; //LOG_FMT(LSYS, "found brace pair on lines %d and %d, nl_count=%d\n", // br_open->orig_line, br_close->orig_line, nl_count); /* Found the matching close brace - make sure a newline is next */ tmp = chunk_get_next(tmp); // Check for end of class if (tmp != NULL && tmp->parent_type == CT_CLASS && tmp->type == CT_SEMICOLON) { cl_semi_pc = tmp; tmp = chunk_get_next(tmp); if (tmp != NULL && !chunk_is_newline(tmp)) { tmp = cl_semi_pc; cl_semi_pc = NULL; } } if ((tmp == NULL) || chunk_is_newline(tmp)) { size_t nl_min = 0; chunk_t *tag_pc = NULL; if (br_open->parent_type == CT_SWITCH) { nl_min = cpd.settings[UO_mod_add_long_switch_closebrace_comment].u; tag_pc = sw_pc; xstr = sw_pc ? sw_pc->str : NULL; /* \todo NULL is no unc_text structure */ } else if ((br_open->parent_type == CT_FUNC_DEF) || (br_open->parent_type == CT_OC_MSG_DECL)) { nl_min = cpd.settings[UO_mod_add_long_function_closebrace_comment].u; // 76006 Explicit null dereferenced, 2016-03-17 tag_pc = fcn_pc; xstr.clear(); append_tag_name(xstr, tag_pc); } else if (br_open->parent_type == CT_NAMESPACE) { nl_min = cpd.settings[UO_mod_add_long_namespace_closebrace_comment].u; // 76007 Explicit null dereferenced, 2016-03-17 tag_pc = ns_pc; /* obtain the next chunck, normally this is the name of the namespace * and append it to generate "namespace xyz" */ xstr = ns_pc->str; xstr.append(" "); append_tag_name(xstr, chunk_get_next(ns_pc)); } else if (br_open->parent_type == CT_CLASS && cl_semi_pc && cl_pc) { nl_min = cpd.settings[UO_mod_add_long_class_closebrace_comment].u; tag_pc = cl_pc; xstr = tag_pc->str; xstr.append(" "); append_tag_name(xstr, chunk_get_next(cl_pc)); br_close = cl_semi_pc; cl_semi_pc = NULL; cl_pc = NULL; } if ((nl_min > 0) && (nl_count >= nl_min) && (tag_pc != NULL)) { /* determine the added comment style */ c_token_t style = (cpd.lang_flags & (LANG_CPP | LANG_CS)) ? CT_COMMENT_CPP : CT_COMMENT; /* Add a comment after the close brace */ insert_comment_after(br_close, style, xstr); } } break; } } } } // add_long_closebrace_comment