diff options
author | Neil Booth <neilb@earthling.net> | 2000-11-27 08:00:04 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2000-11-27 08:00:04 +0000 |
commit | 27e2564ac886bee1a7552df98dcab17a4bf06e26 (patch) | |
tree | 6ecb94c4e9edb0c2004142e389531669ea20c416 /gcc/cpplib.c | |
parent | 9ccb25d582aba15db6bb27944085c7478d532ade (diff) | |
download | gcc-27e2564ac886bee1a7552df98dcab17a4bf06e26.zip gcc-27e2564ac886bee1a7552df98dcab17a4bf06e26.tar.gz gcc-27e2564ac886bee1a7552df98dcab17a4bf06e26.tar.bz2 |
c-lex.c (cb_enter_file, [...]): Combine into the new function cb_change_file.
* c-lex.c (cb_enter_file, cb_leave_file, cb_rename_file):
Combine into the new function cb_change_file.
(init_c_lex): Update.
* cppfiles.c (stack_include_file): Use _cpp_do_file_change.
(cpp_syshdr_flags): Delete.
* cpphash.h (_cpp_do_file_change): New prototype.
Move struct cpp_buffer here from...
* cpplib.h (struct cpp_buffer): ... here.
(enum cpp_fc_reason, struct cpp_file_loc,
struct_cpp_file_change, change_file): New.
(enter_file, leave_file, rename_file, cpp_syshdr_flags): Delete.
* cpplib.c (do_line): Update for new cb_change_file callback.
(_cpp_do_file_change): New function.
(_cpp_pop_buffer): Update to use it.
* cppmain.c (move_printer): Delete.
(main): Set up single callback cb_change_file.
(cb_enter_file, cb_leave_file, cb_rename_file): Delete.
(cb_change_file): New.
* fix-header.c (cur_file, cb_change_file): New.
(recognized_function, read_scan_file): Update.
* scan-decls.c (scan_decls): Update.
* scan.h (recognized_function): Update prototype.
From-SVN: r37784
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r-- | gcc/cpplib.c | 96 |
1 files changed, 60 insertions, 36 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 48a8bf6..de72e98 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -718,13 +718,17 @@ static void do_line (pfile) cpp_reader *pfile; { - cpp_buffer *ip = CPP_BUFFER (pfile); + cpp_buffer *buffer = pfile->buffer; + const char *filename = buffer->nominal_fname; + unsigned int lineno = buffer->lineno; + enum cpp_fc_reason reason = (enum cpp_fc_reason) -1; unsigned long new_lineno; - /* C99 raised the minimum limit on #line numbers. */ - unsigned int cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767; - int enter = 0, leave = 0, rename = 0; + unsigned int cap; cpp_token token; + /* C99 raised the minimum limit on #line numbers. */ + cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767; + /* #line commands expand macros. */ cpp_get_token (pfile, &token); if (token.type != CPP_NUMBER @@ -739,32 +743,24 @@ do_line (pfile) cpp_pedwarn (pfile, "line number out of range"); cpp_get_token (pfile, &token); - - if (token.type != CPP_EOF) + if (token.type == CPP_STRING) { char *fname; unsigned int len; int action_number = 0; - if (token.type != CPP_STRING) - { - cpp_error (pfile, "\"%s\" is not a valid filename", - cpp_token_as_text (pfile, &token)); - return; - } - len = token.val.str.len; fname = alloca (len + 1); memcpy (fname, token.val.str.text, len); fname[len] = '\0'; - if (strcmp (fname, ip->nominal_fname)) + if (strcmp (fname, buffer->nominal_fname)) { - rename = 1; - if (!strcmp (fname, ip->inc->name)) - ip->nominal_fname = ip->inc->name; + reason = FC_RENAME; + if (!strcmp (fname, buffer->inc->name)) + buffer->nominal_fname = buffer->inc->name; else - ip->nominal_fname = _cpp_fake_include (pfile, fname); + buffer->nominal_fname = _cpp_fake_include (pfile, fname); } if (read_line_number (pfile, &action_number) != 0) @@ -774,39 +770,66 @@ do_line (pfile) if (action_number == 1) { - enter = 1; - cpp_make_system_header (pfile, ip, 0); + reason = FC_ENTER; + cpp_make_system_header (pfile, buffer, 0); read_line_number (pfile, &action_number); } else if (action_number == 2) { - leave = 1; - cpp_make_system_header (pfile, ip, 0); + reason = FC_LEAVE; + cpp_make_system_header (pfile, buffer, 0); read_line_number (pfile, &action_number); } if (action_number == 3) { - cpp_make_system_header (pfile, ip, 1); + cpp_make_system_header (pfile, buffer, 1); read_line_number (pfile, &action_number); } if (action_number == 4) { - cpp_make_system_header (pfile, ip, 2); + cpp_make_system_header (pfile, buffer, 2); read_line_number (pfile, &action_number); } } + check_eol (pfile); } + else if (token.type != CPP_EOF) + { + cpp_error (pfile, "\"%s\" is not a valid filename", + cpp_token_as_text (pfile, &token)); + return; + } /* Our line number is incremented after the directive is processed. */ - ip->lineno = new_lineno - 1; - pfile->lexer_pos.output_line = ip->lineno; - if (enter && pfile->cb.enter_file) - (*pfile->cb.enter_file) (pfile); - if (leave && pfile->cb.leave_file) - (*pfile->cb.leave_file) (pfile); - if (rename && pfile->cb.rename_file) - (*pfile->cb.rename_file) (pfile); + buffer->lineno = new_lineno - 1; + if (reason != (enum cpp_fc_reason) -1) + _cpp_do_file_change (pfile, reason, filename, lineno); +} + +/* Arrange the file_change callback. The assumption is that the + current buffer's lineno is one less than the next line. */ +void +_cpp_do_file_change (pfile, reason, from_file, from_lineno) + cpp_reader *pfile; + enum cpp_fc_reason reason; + const char *from_file; + unsigned int from_lineno; +{ + if (pfile->cb.change_file) + { + cpp_file_change fc; + cpp_buffer *buffer = pfile->buffer; + + fc.reason = reason; + fc.from.filename = from_file; + fc.from.lineno = from_lineno; + fc.to.filename = buffer->nominal_fname; + fc.to.lineno = buffer->lineno + 1; + fc.sysp = buffer->inc->sysp; + fc.externc = CPP_OPTION (pfile, cplusplus) && buffer->inc->sysp == 2; + pfile->cb.change_file (pfile, &fc); + } } /* @@ -1745,8 +1768,10 @@ cpp_pop_buffer (pfile) cpp_reader *pfile; { cpp_buffer *buffer = pfile->buffer; + const char *filename = buffer->nominal_fname; + unsigned int lineno = buffer->lineno; struct if_stack *ifs = buffer->if_stack; - int wfb; + int wfb = (buffer->inc != 0); /* Walk back up the conditional stack till we reach its level at entry to this file, issuing error messages. */ @@ -1754,7 +1779,6 @@ cpp_pop_buffer (pfile) cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col, "unterminated #%s", dtable[ifs->type].name); - wfb = (buffer->inc != 0); if (wfb) _cpp_pop_file_buffer (pfile, buffer); @@ -1762,8 +1786,8 @@ cpp_pop_buffer (pfile) obstack_free (pfile->buffer_ob, buffer); pfile->buffer_stack_depth--; - if (pfile->buffer && wfb && pfile->cb.leave_file) - (*pfile->cb.leave_file) (pfile); + if (pfile->buffer && wfb) + _cpp_do_file_change (pfile, FC_LEAVE, filename, lineno); return pfile->buffer; } |