📄 lex.c
字号:
if (c == EOF) { /* Known end of constant, just append this character. */ ffelex_append_to_token_ (code); if (ffelex_raw_mode_ > 0) --ffelex_raw_mode_; return EOF; } /* Have two characters to handle. Do the first, then leave it to the caller to detect anything special about the second. */ ffelex_append_to_token_ (code); if (ffelex_raw_mode_ > 0) --ffelex_raw_mode_; ffelex_backslash_reconsider_ = TRUE; return c;}/* ffelex_bad_1_ -- Issue diagnostic with one source point ffelex_bad_1_(FFEBAD_SOME_ERROR,ffelex_linecount_current_,column + 1); Creates ffewhere line and column objects for the source point, sends them along with the error code to ffebad, then kills the line and column objects before returning. */static voidffelex_bad_1_ (ffebad errnum, ffewhereLineNumber ln0, ffewhereColumnNumber cn0){ ffewhereLine wl0; ffewhereColumn wc0; wl0 = ffewhere_line_new (ln0); wc0 = ffewhere_column_new (cn0); ffebad_start_lex (errnum); ffebad_here (0, wl0, wc0); ffebad_finish (); ffewhere_line_kill (wl0); ffewhere_column_kill (wc0);}/* ffelex_bad_2_ -- Issue diagnostic with two source points ffelex_bad_2_(FFEBAD_SOME_ERROR,ffelex_linecount_current_,column + 1, otherline,othercolumn); Creates ffewhere line and column objects for the source points, sends them along with the error code to ffebad, then kills the line and column objects before returning. */static voidffelex_bad_2_ (ffebad errnum, ffewhereLineNumber ln0, ffewhereColumnNumber cn0, ffewhereLineNumber ln1, ffewhereColumnNumber cn1){ ffewhereLine wl0, wl1; ffewhereColumn wc0, wc1; wl0 = ffewhere_line_new (ln0); wc0 = ffewhere_column_new (cn0); wl1 = ffewhere_line_new (ln1); wc1 = ffewhere_column_new (cn1); ffebad_start_lex (errnum); ffebad_here (0, wl0, wc0); ffebad_here (1, wl1, wc1); ffebad_finish (); ffewhere_line_kill (wl0); ffewhere_column_kill (wc0); ffewhere_line_kill (wl1); ffewhere_column_kill (wc1);}static voidffelex_bad_here_ (int n, ffewhereLineNumber ln0, ffewhereColumnNumber cn0){ ffewhereLine wl0; ffewhereColumn wc0; wl0 = ffewhere_line_new (ln0); wc0 = ffewhere_column_new (cn0); ffebad_here (n, wl0, wc0); ffewhere_line_kill (wl0); ffewhere_column_kill (wc0);}#if FFECOM_targetCURRENT == FFECOM_targetGCCstatic intffelex_getc_ (FILE *finput){ int c; if (ffelex_kludge_chars_ == NULL) return getc (finput); c = *ffelex_kludge_chars_++; if (c != 0) return c; ffelex_kludge_chars_ = NULL; return getc (finput);}#endif#if FFECOM_targetCURRENT == FFECOM_targetGCCstatic intffelex_cfebackslash_ (int *use_d, int *d, FILE *finput){ register int c = getc (finput); register int code; register unsigned count; unsigned firstdig = 0; int nonnull; *use_d = 0; switch (c) { case 'x': if (warn_traditional) warning ("the meaning of `\\x' varies with -traditional"); if (flag_traditional) return c; code = 0; count = 0; nonnull = 0; while (1) { c = getc (finput); if (!(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F') && !(c >= '0' && c <= '9')) { *use_d = 1; *d = c; break; } code *= 16; if (c >= 'a' && c <= 'f') code += c - 'a' + 10; if (c >= 'A' && c <= 'F') code += c - 'A' + 10; if (c >= '0' && c <= '9') code += c - '0'; if (code != 0 || count != 0) { if (count == 0) firstdig = code; count++; } nonnull = 1; } if (! nonnull) error ("\\x used with no following hex digits"); else if (count == 0) /* Digits are all 0's. Ok. */ ; else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node) || (count > 1 && (((unsigned) 1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4)) <= firstdig))) pedwarn ("hex escape out of range"); return code; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': code = 0; count = 0; while ((c <= '7') && (c >= '0') && (count++ < 3)) { code = (code * 8) + (c - '0'); c = getc (finput); } *use_d = 1; *d = c; return code; case '\\': case '\'': case '"': return c; case '\n': ffelex_next_line_ (); *use_d = 2; return 0; case EOF: *use_d = 1; *d = EOF; return EOF; case 'n': return TARGET_NEWLINE; case 't': return TARGET_TAB; case 'r': return TARGET_CR; case 'f': return TARGET_FF; case 'b': return TARGET_BS; case 'a': if (warn_traditional) warning ("the meaning of `\\a' varies with -traditional"); if (flag_traditional) return c; return TARGET_BELL; case 'v':#if 0 /* Vertical tab is present in common usage compilers. */ if (flag_traditional) return c;#endif return TARGET_VT; case 'e': case 'E': if (pedantic) pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c); return 033; case '?': return c; /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */ case '(': case '{': case '[': /* `\%' is used to prevent SCCS from getting confused. */ case '%': if (pedantic) pedwarn ("non-ANSI escape sequence `\\%c'", c); return c; } if (c >= 040 && c < 0177) pedwarn ("unknown escape sequence `\\%c'", c); else pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c); return c;}#endif/* A miniature version of the C front-end lexer. */#if FFECOM_targetCURRENT == FFECOM_targetGCCstatic intffelex_cfelex_ (ffelexToken *xtoken, FILE *finput, int c){ ffelexToken token; char buff[129]; char *p; char *q; char *r; register unsigned buffer_length; if ((*xtoken != NULL) && !ffelex_kludge_flag_) ffelex_token_kill (*xtoken); switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': buffer_length = ARRAY_SIZE (buff); p = &buff[0]; q = p; r = &buff[buffer_length]; for (;;) { *p++ = c; if (p >= r) { register unsigned bytes_used = (p - q); buffer_length *= 2; q = (char *)xrealloc (q, buffer_length); p = &q[bytes_used]; r = &q[buffer_length]; } c = ffelex_getc_ (finput); if (! ISDIGIT (c)) break; } *p = '\0'; token = ffelex_token_new_number (q, ffewhere_line_unknown (), ffewhere_column_unknown ()); if (q != &buff[0]) free (q); break; case '\"': buffer_length = ARRAY_SIZE (buff); p = &buff[0]; q = p; r = &buff[buffer_length]; c = ffelex_getc_ (finput); for (;;) { bool done = FALSE; int use_d = 0; int d; switch (c) { case '\"': c = getc (finput); done = TRUE; break; case '\\': /* ~~~~~ */ c = ffelex_cfebackslash_ (&use_d, &d, finput); break; case EOF: case '\n': fatal ("Badly formed directive -- no closing quote"); done = TRUE; break; default: break; } if (done) break; if (use_d != 2) /* 0=>c, 1=>cd, 2=>nil. */ { *p++ = c; if (p >= r) { register unsigned bytes_used = (p - q); buffer_length = bytes_used * 2; q = (char *)xrealloc (q, buffer_length); p = &q[bytes_used]; r = &q[buffer_length]; } } if (use_d == 1) c = d; else c = getc (finput); } *p = '\0'; token = ffelex_token_new_character (q, ffewhere_line_unknown (), ffewhere_column_unknown ()); if (q != &buff[0]) free (q); break; default: token = NULL; break; } *xtoken = token; return c;}#endif#if FFECOM_targetCURRENT == FFECOM_targetGCCstatic voidffelex_file_pop_ (char *input_filename){ if (input_file_stack->next) { struct file_stack *p = input_file_stack; input_file_stack = p->next; free (p); input_file_stack_tick++;#ifdef DWARF_DEBUGGING_INFO if (debug_info_level == DINFO_LEVEL_VERBOSE && write_symbols == DWARF_DEBUG) dwarfout_resume_previous_source_file (input_file_stack->line);#endif /* DWARF_DEBUGGING_INFO */ } else error ("#-lines for entering and leaving files don't match"); /* Now that we've pushed or popped the input stack, update the name in the top element. */ if (input_file_stack) input_file_stack->name = input_filename;}#endif#if FFECOM_targetCURRENT == FFECOM_targetGCCstatic voidffelex_file_push_ (int old_lineno, char *input_filename){ struct file_stack *p = (struct file_stack *) xmalloc (sizeof (struct file_stack)); input_file_stack->line = old_lineno; p->next = input_file_stack; p->name = input_filename; input_file_stack = p; input_file_stack_tick++;#ifdef DWARF_DEBUGGING_INFO if (debug_info_level == DINFO_LEVEL_VERBOSE && write_symbols == DWARF_DEBUG) dwarfout_start_new_source_file (input_filename);#endif /* DWARF_DEBUGGING_INFO */ /* Now that we've pushed or popped the input stack, update the name in the top element. */ if (input_file_stack) input_file_stack->name = input_filename;}#endif/* Prepare to finish a statement-in-progress by sending the current token, if any, then setting up EOS as the current token with the appropriate current pointer. The caller can then move the current pointer before actually sending EOS, if desired, as it is in typical fixed-form cases. */static voidffelex_prepare_eos_ (){ if (ffelex_token_->type != FFELEX_typeNONE) { ffelex_backslash_ (EOF, 0); switch (ffelex_raw_mode_) { case -2: break; case -1: ffebad_start_lex ((ffelex_raw_char_ == '\'') ? FFEBAD_NO_CLOSING_APOSTROPHE : FFEBAD_NO_CLOSING_QUOTE); ffebad_here (0, ffelex_token_->where_line, ffelex_token_->where_col); ffebad_here (1, ffelex_current_wl_, ffelex_current_wc_); ffebad_finish (); break; case 0: break; default: { char num[20]; ffebad_start_lex (FFEBAD_NOT_ENOUGH_HOLLERITH_CHARS); ffebad_here (0, ffelex_token_->where_line, ffelex_token_->where_col); ffebad_here (1, ffelex_current_wl_, ffelex_current_wc_); sprintf (num, "%lu", (unsigned long) ffelex_raw_mode_); ffebad_string (num); ffebad_finish (); /* Make sure the token has some text, might as well fill up with spaces. */ do { ffelex_append_to_token_ (' '); } while (--ffelex_raw_mode_ > 0); break; } } ffelex_raw_mode_ = 0; ffelex_send_token_ (); } ffelex_token_->type = FFELEX_typeEOS; ffelex_token_->where_line = ffewhere_line_use (ffelex_current_wl_); ffelex_token_->where_col = ffewhere_column_use (ffelex_current_wc_);}static voidffelex_finish_statement_ (){ if ((ffelex_number_of_tokens_ == 0) && (ffelex_token_->type == FFELEX_typeNONE))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -