Mercurial > hg > CbC > CbC_gcc
comparison gcc/read-md.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* MD reader for GCC. | 1 /* MD reader for GCC. |
2 Copyright (C) 1987-2018 Free Software Foundation, Inc. | 2 Copyright (C) 1987-2020 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify it under | 6 GCC is free software; you can redistribute it and/or modify it under |
7 the terms of the GNU General Public License as published by the Free | 7 the terms of the GNU General Public License as published by the Free |
41 int have_error = 0; | 41 int have_error = 0; |
42 | 42 |
43 #endif /* #ifndef GENERATOR_FILE */ | 43 #endif /* #ifndef GENERATOR_FILE */ |
44 | 44 |
45 | 45 |
46 /* Associates PTR (which can be a string, etc.) with the file location | |
47 specified by FILENAME and LINENO. */ | |
48 struct ptr_loc { | |
49 const void *ptr; | |
50 const char *filename; | |
51 int lineno; | |
52 }; | |
53 | |
54 /* This callback will be invoked whenever an md include directive is | 46 /* This callback will be invoked whenever an md include directive is |
55 processed. To be used for creation of the dependency file. */ | 47 processed. To be used for creation of the dependency file. */ |
56 void (*include_callback) (const char *); | 48 void (*include_callback) (const char *); |
57 | 49 |
58 /* Global singleton. */ | 50 /* Global singleton. */ |
92 leading_ptr_eq_p (const void *def1, const void *def2) | 84 leading_ptr_eq_p (const void *def1, const void *def2) |
93 { | 85 { |
94 return *(const void *const *) def1 == *(const void *const *) def2; | 86 return *(const void *const *) def1 == *(const void *const *) def2; |
95 } | 87 } |
96 | 88 |
97 /* Associate PTR with the file position given by FILENAME and LINENO. */ | 89 /* Associate PTR with the file position given by FILE_LOC. */ |
98 | 90 |
99 void | 91 void |
100 md_reader::set_md_ptr_loc (const void *ptr, const char *filename, int lineno) | 92 md_reader::set_md_ptr_loc (const void *ptr, file_location file_loc) |
101 { | 93 { |
102 struct ptr_loc *loc; | 94 struct ptr_loc *loc; |
103 | 95 |
104 loc = (struct ptr_loc *) obstack_alloc (&m_ptr_loc_obstack, | 96 loc = (struct ptr_loc *) obstack_alloc (&m_ptr_loc_obstack, |
105 sizeof (struct ptr_loc)); | 97 sizeof (struct ptr_loc)); |
106 loc->ptr = ptr; | 98 loc->ptr = ptr; |
107 loc->filename = filename; | 99 loc->loc = file_loc; |
108 loc->lineno = lineno; | |
109 *htab_find_slot (m_ptr_locs, loc, INSERT) = loc; | 100 *htab_find_slot (m_ptr_locs, loc, INSERT) = loc; |
110 } | 101 } |
111 | 102 |
112 /* Return the position associated with pointer PTR. Return null if no | 103 /* Return the position associated with pointer PTR. Return null if no |
113 position was set. */ | 104 position was set. */ |
114 | 105 |
115 const struct ptr_loc * | 106 const md_reader::ptr_loc * |
116 md_reader::get_md_ptr_loc (const void *ptr) | 107 md_reader::get_md_ptr_loc (const void *ptr) |
117 { | 108 { |
118 return (const struct ptr_loc *) htab_find (m_ptr_locs, &ptr); | 109 return (const struct ptr_loc *) htab_find (m_ptr_locs, &ptr); |
119 } | 110 } |
120 | 111 |
123 void | 114 void |
124 md_reader::copy_md_ptr_loc (const void *new_ptr, const void *old_ptr) | 115 md_reader::copy_md_ptr_loc (const void *new_ptr, const void *old_ptr) |
125 { | 116 { |
126 const struct ptr_loc *loc = get_md_ptr_loc (old_ptr); | 117 const struct ptr_loc *loc = get_md_ptr_loc (old_ptr); |
127 if (loc != 0) | 118 if (loc != 0) |
128 set_md_ptr_loc (new_ptr, loc->filename, loc->lineno); | 119 set_md_ptr_loc (new_ptr, loc->loc); |
129 } | 120 } |
130 | 121 |
131 /* If PTR is associated with a known file position, print a #line | 122 /* If PTR is associated with a known file position, print a #line |
132 directive for it to OUTF. */ | 123 directive for it to OUTF. */ |
133 | 124 |
134 void | 125 void |
135 md_reader::fprint_md_ptr_loc (FILE *outf, const void *ptr) | 126 md_reader::fprint_md_ptr_loc (FILE *outf, const void *ptr) |
136 { | 127 { |
137 const struct ptr_loc *loc = get_md_ptr_loc (ptr); | 128 const struct ptr_loc *loc = get_md_ptr_loc (ptr); |
138 if (loc != 0) | 129 if (loc != 0) |
139 fprintf (outf, "#line %d \"%s\"\n", loc->lineno, loc->filename); | 130 fprintf (outf, "#line %d \"%s\"\n", loc->loc.lineno, loc->loc.filename); |
140 } | 131 } |
141 | 132 |
142 /* Special fprint_md_ptr_loc for writing to STDOUT. */ | 133 /* Special fprint_md_ptr_loc for writing to STDOUT. */ |
143 void | 134 void |
144 md_reader::print_md_ptr_loc (const void *ptr) | 135 md_reader::print_md_ptr_loc (const void *ptr) |
670 char * | 661 char * |
671 md_reader::read_string (int star_if_braced) | 662 md_reader::read_string (int star_if_braced) |
672 { | 663 { |
673 char *stringbuf; | 664 char *stringbuf; |
674 int saw_paren = 0; | 665 int saw_paren = 0; |
675 int c, old_lineno; | 666 int c; |
676 | 667 |
677 c = read_skip_spaces (); | 668 c = read_skip_spaces (); |
678 if (c == '(') | 669 if (c == '(') |
679 { | 670 { |
680 saw_paren = 1; | 671 saw_paren = 1; |
681 c = read_skip_spaces (); | 672 c = read_skip_spaces (); |
682 } | 673 } |
683 | 674 |
684 old_lineno = get_lineno (); | 675 file_location loc = get_current_location (); |
685 if (c == '"') | 676 if (c == '"') |
686 stringbuf = read_quoted_string (); | 677 stringbuf = read_quoted_string (); |
687 else if (c == '{') | 678 else if (c == '{') |
688 { | 679 { |
689 if (star_if_braced) | 680 if (star_if_braced) |
702 fatal_with_file_and_line ("expected `\"' or `{', found `%c'", c); | 693 fatal_with_file_and_line ("expected `\"' or `{', found `%c'", c); |
703 | 694 |
704 if (saw_paren) | 695 if (saw_paren) |
705 require_char_ws (')'); | 696 require_char_ws (')'); |
706 | 697 |
707 set_md_ptr_loc (stringbuf, get_filename (), old_lineno); | 698 set_md_ptr_loc (stringbuf, loc); |
708 return stringbuf; | 699 return stringbuf; |
709 } | 700 } |
710 | 701 |
711 /* Skip the rest of a construct that started at line LINENO and that | 702 /* Skip the rest of a construct that started at line LINENO and that |
712 is currently nested by DEPTH levels of parentheses. */ | 703 is currently nested by DEPTH levels of parentheses. */ |