xref: /dflybsd-src/contrib/gcc-8.0/gcc/input.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* Declarations for variables relating to reading the source file.
2*38fd1498Szrj    Used by parsers, lexical analyzers, and error message routines.
3*38fd1498Szrj    Copyright (C) 1993-2018 Free Software Foundation, Inc.
4*38fd1498Szrj 
5*38fd1498Szrj This file is part of GCC.
6*38fd1498Szrj 
7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
8*38fd1498Szrj the terms of the GNU General Public License as published by the Free
9*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
10*38fd1498Szrj version.
11*38fd1498Szrj 
12*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15*38fd1498Szrj for more details.
16*38fd1498Szrj 
17*38fd1498Szrj You should have received a copy of the GNU General Public License
18*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
19*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
20*38fd1498Szrj 
21*38fd1498Szrj #ifndef GCC_INPUT_H
22*38fd1498Szrj #define GCC_INPUT_H
23*38fd1498Szrj 
24*38fd1498Szrj #include "line-map.h"
25*38fd1498Szrj 
26*38fd1498Szrj extern GTY(()) struct line_maps *line_table;
27*38fd1498Szrj extern GTY(()) struct line_maps *saved_line_table;
28*38fd1498Szrj 
29*38fd1498Szrj /* A value which will never be used to represent a real location.  */
30*38fd1498Szrj #define UNKNOWN_LOCATION ((source_location) 0)
31*38fd1498Szrj 
32*38fd1498Szrj /* The location for declarations in "<built-in>" */
33*38fd1498Szrj #define BUILTINS_LOCATION ((source_location) 1)
34*38fd1498Szrj 
35*38fd1498Szrj /* line-map.c reserves RESERVED_LOCATION_COUNT to the user.  Ensure
36*38fd1498Szrj    both UNKNOWN_LOCATION and BUILTINS_LOCATION fit into that.  */
37*38fd1498Szrj extern char builtins_location_check[(BUILTINS_LOCATION
38*38fd1498Szrj 				     < RESERVED_LOCATION_COUNT) ? 1 : -1];
39*38fd1498Szrj 
40*38fd1498Szrj extern bool is_location_from_builtin_token (source_location);
41*38fd1498Szrj extern expanded_location expand_location (source_location);
42*38fd1498Szrj extern const char *location_get_source_line (const char *file_path, int line,
43*38fd1498Szrj 					     int *line_size);
44*38fd1498Szrj extern bool location_missing_trailing_newline (const char *file_path);
45*38fd1498Szrj extern expanded_location expand_location_to_spelling_point (source_location);
46*38fd1498Szrj extern source_location expansion_point_location_if_in_system_header (source_location);
47*38fd1498Szrj extern source_location expansion_point_location (source_location);
48*38fd1498Szrj 
49*38fd1498Szrj /* Historically GCC used location_t, while cpp used source_location.
50*38fd1498Szrj    This could be removed but it hardly seems worth the effort.  */
51*38fd1498Szrj typedef source_location location_t;
52*38fd1498Szrj 
53*38fd1498Szrj extern location_t input_location;
54*38fd1498Szrj 
55*38fd1498Szrj #define LOCATION_FILE(LOC) ((expand_location (LOC)).file)
56*38fd1498Szrj #define LOCATION_LINE(LOC) ((expand_location (LOC)).line)
57*38fd1498Szrj #define LOCATION_COLUMN(LOC)((expand_location (LOC)).column)
58*38fd1498Szrj #define LOCATION_LOCUS(LOC) \
59*38fd1498Szrj   ((IS_ADHOC_LOC (LOC)) ? get_location_from_adhoc_loc (line_table, LOC) \
60*38fd1498Szrj    : (LOC))
61*38fd1498Szrj #define LOCATION_BLOCK(LOC) \
62*38fd1498Szrj   ((tree) ((IS_ADHOC_LOC (LOC)) ? get_data_from_adhoc_loc (line_table, (LOC)) \
63*38fd1498Szrj    : NULL))
64*38fd1498Szrj #define RESERVED_LOCATION_P(LOC) \
65*38fd1498Szrj   (LOCATION_LOCUS (LOC) < RESERVED_LOCATION_COUNT)
66*38fd1498Szrj 
67*38fd1498Szrj /* Return a positive value if LOCATION is the locus of a token that is
68*38fd1498Szrj    located in a system header, O otherwise. It returns 1 if LOCATION
69*38fd1498Szrj    is the locus of a token that is located in a system header, and 2
70*38fd1498Szrj    if LOCATION is the locus of a token located in a C system header
71*38fd1498Szrj    that therefore needs to be extern "C" protected in C++.
72*38fd1498Szrj 
73*38fd1498Szrj    Note that this function returns 1 if LOCATION belongs to a token
74*38fd1498Szrj    that is part of a macro replacement-list defined in a system
75*38fd1498Szrj    header, but expanded in a non-system file.  */
76*38fd1498Szrj #define in_system_header_at(LOC) \
77*38fd1498Szrj   (linemap_location_in_system_header_p (line_table, LOC))
78*38fd1498Szrj /* Return a positive value if LOCATION is the locus of a token that
79*38fd1498Szrj    comes from a macro expansion, O otherwise.  */
80*38fd1498Szrj #define from_macro_expansion_at(LOC) \
81*38fd1498Szrj   ((linemap_location_from_macro_expansion_p (line_table, LOC)))
82*38fd1498Szrj /* Return a positive value if LOCATION is the locus of a token that comes from
83*38fd1498Szrj    a macro definition, O otherwise.  This differs from from_macro_expansion_at
84*38fd1498Szrj    in its treatment of macro arguments, for which this returns false.  */
85*38fd1498Szrj #define from_macro_definition_at(LOC) \
86*38fd1498Szrj   ((linemap_location_from_macro_definition_p (line_table, LOC)))
87*38fd1498Szrj 
88*38fd1498Szrj static inline location_t
get_pure_location(location_t loc)89*38fd1498Szrj get_pure_location (location_t loc)
90*38fd1498Szrj {
91*38fd1498Szrj   return get_pure_location (line_table, loc);
92*38fd1498Szrj }
93*38fd1498Szrj 
94*38fd1498Szrj /* Get the start of any range encoded within location LOC.  */
95*38fd1498Szrj 
96*38fd1498Szrj static inline location_t
get_start(location_t loc)97*38fd1498Szrj get_start (location_t loc)
98*38fd1498Szrj {
99*38fd1498Szrj   return get_range_from_loc (line_table, loc).m_start;
100*38fd1498Szrj }
101*38fd1498Szrj 
102*38fd1498Szrj /* Get the endpoint of any range encoded within location LOC.  */
103*38fd1498Szrj 
104*38fd1498Szrj static inline location_t
get_finish(location_t loc)105*38fd1498Szrj get_finish (location_t loc)
106*38fd1498Szrj {
107*38fd1498Szrj   return get_range_from_loc (line_table, loc).m_finish;
108*38fd1498Szrj }
109*38fd1498Szrj 
110*38fd1498Szrj extern location_t make_location (location_t caret,
111*38fd1498Szrj 				 location_t start, location_t finish);
112*38fd1498Szrj extern location_t make_location (location_t caret, source_range src_range);
113*38fd1498Szrj 
114*38fd1498Szrj void dump_line_table_statistics (void);
115*38fd1498Szrj 
116*38fd1498Szrj void dump_location_info (FILE *stream);
117*38fd1498Szrj 
118*38fd1498Szrj void diagnostics_file_cache_fini (void);
119*38fd1498Szrj 
120*38fd1498Szrj void diagnostics_file_cache_forcibly_evict_file (const char *file_path);
121*38fd1498Szrj 
122*38fd1498Szrj struct GTY(()) string_concat
123*38fd1498Szrj {
124*38fd1498Szrj   string_concat (int num, location_t *locs);
125*38fd1498Szrj 
126*38fd1498Szrj   int m_num;
127*38fd1498Szrj   location_t * GTY ((atomic)) m_locs;
128*38fd1498Szrj };
129*38fd1498Szrj 
130*38fd1498Szrj struct location_hash : int_hash <location_t, UNKNOWN_LOCATION> { };
131*38fd1498Szrj 
class()132*38fd1498Szrj class GTY(()) string_concat_db
133*38fd1498Szrj {
134*38fd1498Szrj  public:
135*38fd1498Szrj   string_concat_db ();
136*38fd1498Szrj   void record_string_concatenation (int num, location_t *locs);
137*38fd1498Szrj 
138*38fd1498Szrj   bool get_string_concatenation (location_t loc,
139*38fd1498Szrj 				 int *out_num,
140*38fd1498Szrj 				 location_t **out_locs);
141*38fd1498Szrj 
142*38fd1498Szrj  private:
143*38fd1498Szrj   static location_t get_key_loc (location_t loc);
144*38fd1498Szrj 
145*38fd1498Szrj   /* For the fields to be private, we must grant access to the
146*38fd1498Szrj      generated code in gtype-desc.c.  */
147*38fd1498Szrj 
148*38fd1498Szrj   friend void ::gt_ggc_mx_string_concat_db (void *x_p);
149*38fd1498Szrj   friend void ::gt_pch_nx_string_concat_db (void *x_p);
150*38fd1498Szrj   friend void ::gt_pch_p_16string_concat_db (void *this_obj, void *x_p,
151*38fd1498Szrj 					     gt_pointer_operator op,
152*38fd1498Szrj 					     void *cookie);
153*38fd1498Szrj 
154*38fd1498Szrj   hash_map <location_hash, string_concat *> *m_table;
155*38fd1498Szrj };
156*38fd1498Szrj 
157*38fd1498Szrj #endif
158