📄 lexi.c
字号:
} else { p = is_reserved (token, token_end - token); } if ((p == NULL) && (user_specials != 0)) { for (p = &user_specials[0]; p < &user_specials[0] + user_specials_idx; p++) { char *q = token; char *r = p->rwd; /* This string compare is a little nonstandard because token * ends at the character before token_end and p->rwd is * null-terminated. */ while (1) { /* If we have come to the end of both the keyword in * user_specials and the keyword in token they are equal. */ if (q >= token_end && !*r) { goto found_keyword; } /* If we have come to the end of just one, they are not * equal. */ if (q >= token_end || !*r) { break; } /* If the characters in corresponding characters are not * equal, the strings are not equal. */ if (*q++ != *r++) { break; } } } /* Didn't find anything in user_specials. */ p = NULL; } found_keyword: if (p) { /* we have a keyword */ codes_ty value; value = ident; parser_state_tos->its_a_keyword = true; parser_state_tos->last_u_d = true; parser_state_tos->last_rw = p->rwcode; parser_state_tos->last_rw_depth = parser_state_tos->paren_depth; switch (p->rwcode) { case rw_operator: /* C++ operator overloading. */ value = cpp_operator; parser_state_tos->in_parameter_declaration = 1; break; case rw_switch: /* it is a switch */ value = (swstmt); break; case rw_case: /* a case or default */ value = (casestmt); break; case rw_enum: l_enum = true; /* reset on '(' ')' '{' '}' or ';' */ /* fall through */ case rw_struct_like: /* a "struct" */ if (parser_state_tos->p_l_follow && !(parser_state_tos->noncast_mask & 1 << parser_state_tos->p_l_follow)) /* inside parens: cast */ { parser_state_tos->cast_mask |= 1 << parser_state_tos->p_l_follow; break; } l_struct = true; /* Next time around, we will want to know that we have had a 'struct' */ case rw_decl: /* one of the declaration keywords */ if (parser_state_tos->p_l_follow && !(parser_state_tos->noncast_mask & 1 << parser_state_tos->p_l_follow)) /* inside parens: cast */ { parser_state_tos->cast_mask |= 1 << parser_state_tos->p_l_follow; break; } last_code = decl; value = (decl); break; case rw_sp_paren: /* if, while, for */ value = (sp_paren); if (*token == 'i' && parser_state_tos->last_token == sp_else) { parser_state_tos->i_l_follow -= settings.ind_size; } break; case rw_sp_nparen: /* do */ value = (sp_nparen); break; case rw_sp_else: /* else */ value = (sp_else); break; case rw_sizeof: parser_state_tos->sizeof_keyword = true; value = (ident); break; case rw_return: case rw_break: default: /* all others are treated like any other identifier */ value = (ident); } /* end of switch */ if (parser_state_tos->last_token == cpp_operator) { return overloaded; } return value; } /* end of if (found_it) */ else if ((*buf_ptr == '(') && (parser_state_tos->tos <= 1) && (parser_state_tos->ind_level == 0) && (parser_state_tos->paren_depth == 0)) { /* We have found something which might be the name in a function * definition. */ char *tp; int paren_count = 1; /* If the return type of this function definition was not defined * with a -T commandline option, then the output of indent would * alternate on subsequent calls. In order to avoid that we try * to detect that case here and make a minimal change to cause * the correct behaviour. */ if (parser_state_tos->last_token == ident && parser_state_tos->last_saw_nl) { parser_state_tos->in_decl = true; } /* Skip to the matching ')'. */ for (tp = buf_ptr + 1; (paren_count > 0) && (tp < in_prog + in_prog_size); tp++) { if (*tp == '(') { paren_count++; } if (*tp == ')') { paren_count--; } /* Can't occur in parameter list; this way we don't search the * whole file in the case of unbalanced parens. */ if (*tp == ';') { goto not_proc; } } if (paren_count == 0) { parser_state_tos->procname = token; parser_state_tos->procname_end = token_end; while (isspace (*tp)) { tp++; } if ((*tp == '_') && (in_prog + in_prog_size - tp >= 13) && !strncmp (tp, "__attribute__", 13)) { /* Found an __attribute__ after a function declaration */ /* Must be a declaration */ } else { /* If the next char is ';' or ',' or '(' we have a function * declaration, not a definition. * * I've added '=' to this list to keep from breaking * a non-valid C macro from libc. -jla */ if (*tp != ';' && *tp != ',' && *tp != '(' && *tp != '=') { parser_state_tos->in_parameter_declaration = 1; } } } not_proc:; } else if ((*buf_ptr == ':') && (*(buf_ptr + 1) == ':') && (parser_state_tos->tos <= 1) && (parser_state_tos->ind_level == 0) && (parser_state_tos->paren_depth == 0)) { parser_state_tos->classname = token; parser_state_tos->classname_end = token_end; } /* The following hack attempts to guess whether or not the * current token is in fact a declaration keyword -- one that * has been typedef'd */ else if ( ( ((*buf_ptr == '*') && (buf_ptr[1] != '=')) || isalpha (*buf_ptr) || (*buf_ptr == '_')) && !parser_state_tos->p_l_follow && !parser_state_tos->block_init && ( (parser_state_tos->last_token == rparen) || (parser_state_tos->last_token == semicolon) || (parser_state_tos->last_token == rbrace) || (parser_state_tos->last_token == decl) || (parser_state_tos->last_token == lbrace) || (parser_state_tos->last_token == start_token))) { parser_state_tos->its_a_keyword = true; parser_state_tos->last_u_d = true; last_code = decl; if (parser_state_tos->last_token == cpp_operator) { return overloaded; } return decl; } if (last_code == decl) { /* if this is a declared variable, then following sign is unary */ parser_state_tos->last_u_d = true; /* will make "int a -1" work */ } last_code = ident; if (parser_state_tos->last_token == cpp_operator) { return overloaded; } return (ident); /* the ident is not in the list */ } /* end of procesing for alpanum character */ /* Scan a non-alphanumeric token */ /* If it is not a one character token, token_end will get changed later. */ token_end = buf_ptr + 1; /* THIS MAY KILL YOU!!! * * Note that it may be possible for this to kill us--if `fill_buffer' * at any time switches `buf_ptr' to the other input buffer, `token' * and `token_end' will point to different storage areas!!! */ if (++buf_ptr >= buf_end) { fill_buffer (); } /* If it is a backslash new-line, just eat the backslash */ if ((*token == '\\') && (buf_ptr[0] == EOL)) { token = buf_ptr; if (++buf_ptr >= buf_end) { fill_buffer (); } } switch (*token) { case '\0': code = code_eof; break; case EOL: parser_state_tos->matching_brace_on_same_line = -1; unary_delim = parser_state_tos->last_u_d; parser_state_tos->last_nl = true; code = newline; break; /* Handle wide strings and chars. */ case 'L': if (buf_ptr[0] != '"' && buf_ptr[0] != '\'') { token_end = buf_ptr; code = ident; break; } qchar = buf_ptr[0]; buf_ptr++; goto handle_string; case '\'': /* start of quoted character */ case '"': /* start of string */ qchar = *token; handle_string: /* Find out how big the literal is so we can set token_end. */ /* Invariant: before loop test buf_ptr points to the next * character that we have not yet checked. */ while ((*buf_ptr != qchar) && (*buf_ptr != 0)) /* && *buf_ptr != EOL) */ { if (*buf_ptr == EOL) { ++line_no; } if (*buf_ptr == '\\') { buf_ptr++; if (buf_ptr >= buf_end) { fill_buffer (); } if (*buf_ptr == EOL) { ++line_no; } if (*buf_ptr == 0) { break; } } buf_ptr++; if (buf_ptr >= buf_end) { fill_buffer (); } } if (*buf_ptr == EOL || *buf_ptr == 0) { WARNING ((qchar == '\'' ? _("Unterminated character constant") : _("Unterminated string constant")), 0, 0); } else { /* Advance over end quote char. */ buf_ptr++; if (buf_ptr >= buf_end) { fill_buffer (); } } token_end = buf_ptr; code = ident; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -