diff options
author | Jason Merrill <jason@yorick.cygnus.com> | 1999-08-14 00:42:07 +0000 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 1999-08-13 20:42:07 -0400 |
commit | d3a34a0a7e041f823c4163e646f6755d85bacb25 (patch) | |
tree | d29784eb7e378d505b67f37e44240c8db48326ff /gcc/cpplib.c | |
parent | 8dd3f57a9eb02313b4d87ba14c26f5d004d61833 (diff) | |
download | gcc-d3a34a0a7e041f823c4163e646f6755d85bacb25.zip gcc-d3a34a0a7e041f823c4163e646f6755d85bacb25.tar.gz gcc-d3a34a0a7e041f823c4163e646f6755d85bacb25.tar.bz2 |
cpplib.c (read_line_number): New fn, split out of...
* cpplib.c (read_line_number): New fn, split out of...
(do_line): Here.
From-SVN: r28707
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r-- | gcc/cpplib.c | 69 |
1 files changed, 44 insertions, 25 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c index f2fadf2..06b1717 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -1208,6 +1208,34 @@ do_include (pfile, keyword) return 0; } +/* Subroutine of do_line. Read next token from PFILE without adding it to + the output buffer. If it is a number between 1 and 4, store it in *NUM + and return 1; otherwise, return 0 and complain if we aren't at the end + of the directive. */ + +static int +read_line_number (pfile, num) + cpp_reader *pfile; + int *num; +{ + long save_written = CPP_WRITTEN (pfile); + U_CHAR *p = pfile->token_buffer + save_written; + enum cpp_token token = get_directive_token (pfile); + CPP_SET_WRITTEN (pfile, save_written); + + if (token == CPP_NUMBER && *p >= '1' && *p <= '4' && p[1] == '\0') + { + *num = p[0] - '0'; + return 1; + } + else + { + if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) + cpp_error (pfile, "invalid format `#line' command"); + return 0; + } +} + /* Interpret #line command. Note that the filename string (if any) is treated as if it were an include filename. That means no escape handling. */ @@ -1249,41 +1277,32 @@ do_line (pfile, keyword) { U_CHAR *fname = pfile->token_buffer + old_written + 1; U_CHAR *end_name = CPP_PWRITTEN (pfile) - 1; - long num_start = CPP_WRITTEN (pfile); + int action_number = 0; - token = get_directive_token (pfile); - if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) + if (read_line_number (pfile, &action_number)) { - U_CHAR *p = pfile->token_buffer + num_start; if (CPP_PEDANTIC (pfile)) cpp_pedwarn (pfile, "garbage at end of `#line' command"); - if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0') + if (action_number == 1) + { + file_change = enter_file; + read_line_number (pfile, &action_number); + } + else if (action_number == 2) { - cpp_error (pfile, "invalid format `#line' command"); - goto bad_line_directive; + file_change = leave_file; + read_line_number (pfile, &action_number); } - if (*p == '1') - file_change = enter_file; - else if (*p == '2') - file_change = leave_file; - else if (*p == '3') - ip->system_header_p = 1; - else /* if (*p == '4') */ - ip->system_header_p = 2; - - CPP_SET_WRITTEN (pfile, num_start); - token = get_directive_token (pfile); - p = pfile->token_buffer + num_start; - if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4')) + if (action_number == 3) { - ip->system_header_p = *p == '3' ? 1 : 2; - token = get_directive_token (pfile); + ip->system_header_p = 1; + read_line_number (pfile, &action_number); } - if (token != CPP_VSPACE) + if (action_number == 4) { - cpp_error (pfile, "invalid format `#line' command"); - goto bad_line_directive; + ip->system_header_p = 2; + read_line_number (pfile, &action_number); } } |