annotate gcc/c/c-parser.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Declarations for the parser for C and Objective-C.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 Parser actions based on the old Bison parser; structure somewhat
kono
parents:
diff changeset
5 influenced by and fragments based on the C++ parser.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 This file is part of GCC.
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
10 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
11 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
12 version.
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
17 for more details.
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
20 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
21 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 #ifndef GCC_C_PARSER_H
kono
parents:
diff changeset
24 #define GCC_C_PARSER_H
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
kono
parents:
diff changeset
27 and the C parser. Unlike the C++ lexer, the parser structure
kono
parents:
diff changeset
28 stores the lexer information instead of using a separate structure.
kono
parents:
diff changeset
29 Identifiers are separated into ordinary identifiers, type names,
kono
parents:
diff changeset
30 keywords and some other Objective-C types of identifiers, and some
kono
parents:
diff changeset
31 look-ahead is maintained.
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 ??? It might be a good idea to lex the whole file up front (as for
kono
parents:
diff changeset
34 C++). It would then be possible to share more of the C and C++
kono
parents:
diff changeset
35 lexer code, if desired. */
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 /* More information about the type of a CPP_NAME token. */
kono
parents:
diff changeset
38 enum c_id_kind {
kono
parents:
diff changeset
39 /* An ordinary identifier. */
kono
parents:
diff changeset
40 C_ID_ID,
kono
parents:
diff changeset
41 /* An identifier declared as a typedef name. */
kono
parents:
diff changeset
42 C_ID_TYPENAME,
kono
parents:
diff changeset
43 /* An identifier declared as an Objective-C class name. */
kono
parents:
diff changeset
44 C_ID_CLASSNAME,
kono
parents:
diff changeset
45 /* An address space identifier. */
kono
parents:
diff changeset
46 C_ID_ADDRSPACE,
kono
parents:
diff changeset
47 /* Not an identifier. */
kono
parents:
diff changeset
48 C_ID_NONE
kono
parents:
diff changeset
49 };
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 /* A single C token after string literal concatenation and conversion
kono
parents:
diff changeset
52 of preprocessing tokens to tokens. */
kono
parents:
diff changeset
53 struct GTY (()) c_token {
kono
parents:
diff changeset
54 /* The kind of token. */
kono
parents:
diff changeset
55 ENUM_BITFIELD (cpp_ttype) type : 8;
kono
parents:
diff changeset
56 /* If this token is a CPP_NAME, this value indicates whether also
kono
parents:
diff changeset
57 declared as some kind of type. Otherwise, it is C_ID_NONE. */
kono
parents:
diff changeset
58 ENUM_BITFIELD (c_id_kind) id_kind : 8;
kono
parents:
diff changeset
59 /* If this token is a keyword, this value indicates which keyword.
kono
parents:
diff changeset
60 Otherwise, this value is RID_MAX. */
kono
parents:
diff changeset
61 ENUM_BITFIELD (rid) keyword : 8;
kono
parents:
diff changeset
62 /* If this token is a CPP_PRAGMA, this indicates the pragma that
kono
parents:
diff changeset
63 was seen. Otherwise it is PRAGMA_NONE. */
kono
parents:
diff changeset
64 ENUM_BITFIELD (pragma_kind) pragma_kind : 8;
kono
parents:
diff changeset
65 /* The location at which this token was found. */
kono
parents:
diff changeset
66 location_t location;
kono
parents:
diff changeset
67 /* The value associated with this token, if any. */
kono
parents:
diff changeset
68 tree value;
kono
parents:
diff changeset
69 /* Token flags. */
kono
parents:
diff changeset
70 unsigned char flags;
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 source_range get_range () const
kono
parents:
diff changeset
73 {
kono
parents:
diff changeset
74 return get_range_from_loc (line_table, location);
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 location_t get_finish () const
kono
parents:
diff changeset
78 {
kono
parents:
diff changeset
79 return get_range ().m_finish;
kono
parents:
diff changeset
80 }
kono
parents:
diff changeset
81 };
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 /* The parser. */
kono
parents:
diff changeset
84 struct c_parser;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 /* Possibly kinds of declarator to parse. */
kono
parents:
diff changeset
87 enum c_dtr_syn {
kono
parents:
diff changeset
88 /* A normal declarator with an identifier. */
kono
parents:
diff changeset
89 C_DTR_NORMAL,
kono
parents:
diff changeset
90 /* An abstract declarator (maybe empty). */
kono
parents:
diff changeset
91 C_DTR_ABSTRACT,
kono
parents:
diff changeset
92 /* A parameter declarator: may be either, but after a type name does
kono
parents:
diff changeset
93 not redeclare a typedef name as an identifier if it can
kono
parents:
diff changeset
94 alternatively be interpreted as a typedef name; see DR#009,
kono
parents:
diff changeset
95 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
kono
parents:
diff changeset
96 following DR#249. For example, given a typedef T, "int T" and
kono
parents:
diff changeset
97 "int *T" are valid parameter declarations redeclaring T, while
kono
parents:
diff changeset
98 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
kono
parents:
diff changeset
99 abstract declarators rather than involving redundant parentheses;
kono
parents:
diff changeset
100 the same applies with attributes inside the parentheses before
kono
parents:
diff changeset
101 "T". */
kono
parents:
diff changeset
102 C_DTR_PARM
kono
parents:
diff changeset
103 };
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 /* The binary operation precedence levels, where 0 is a dummy lowest level
kono
parents:
diff changeset
106 used for the bottom of the stack. */
kono
parents:
diff changeset
107 enum c_parser_prec {
kono
parents:
diff changeset
108 PREC_NONE,
kono
parents:
diff changeset
109 PREC_LOGOR,
kono
parents:
diff changeset
110 PREC_LOGAND,
kono
parents:
diff changeset
111 PREC_BITOR,
kono
parents:
diff changeset
112 PREC_BITXOR,
kono
parents:
diff changeset
113 PREC_BITAND,
kono
parents:
diff changeset
114 PREC_EQ,
kono
parents:
diff changeset
115 PREC_REL,
kono
parents:
diff changeset
116 PREC_SHIFT,
kono
parents:
diff changeset
117 PREC_ADD,
kono
parents:
diff changeset
118 PREC_MULT,
kono
parents:
diff changeset
119 NUM_PRECS
kono
parents:
diff changeset
120 };
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 enum c_lookahead_kind {
kono
parents:
diff changeset
123 /* Always treat unknown identifiers as typenames. */
kono
parents:
diff changeset
124 cla_prefer_type,
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 /* Could be parsing a nonabstract declarator. Only treat an identifier
kono
parents:
diff changeset
127 as a typename if followed by another identifier or a star. */
kono
parents:
diff changeset
128 cla_nonabstract_decl,
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 /* Never treat identifiers as typenames. */
kono
parents:
diff changeset
131 cla_prefer_id
kono
parents:
diff changeset
132 };
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 extern c_token * c_parser_peek_token (c_parser *parser);
kono
parents:
diff changeset
136 extern c_token * c_parser_peek_2nd_token (c_parser *parser);
kono
parents:
diff changeset
137 extern c_token * c_parser_peek_nth_token (c_parser *parser, unsigned int n);
kono
parents:
diff changeset
138 extern bool c_parser_require (c_parser *parser, enum cpp_ttype type,
kono
parents:
diff changeset
139 const char *msgid,
kono
parents:
diff changeset
140 location_t matching_location = UNKNOWN_LOCATION,
kono
parents:
diff changeset
141 bool type_is_unique=true);
kono
parents:
diff changeset
142 extern bool c_parser_error (c_parser *parser, const char *gmsgid);
kono
parents:
diff changeset
143 extern void c_parser_consume_token (c_parser *parser);
kono
parents:
diff changeset
144 extern void c_parser_skip_until_found (c_parser *parser, enum cpp_ttype type,
kono
parents:
diff changeset
145 const char *msgid,
kono
parents:
diff changeset
146 location_t = UNKNOWN_LOCATION);
kono
parents:
diff changeset
147 extern bool c_parser_next_token_starts_declspecs (c_parser *parser);
kono
parents:
diff changeset
148 bool c_parser_next_tokens_start_declaration (c_parser *parser);
kono
parents:
diff changeset
149 bool c_token_starts_typename (c_token *token);
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 /* Abstraction to avoid defining c_parser here which messes up gengtype
kono
parents:
diff changeset
152 output wrt ObjC due to vec<c_token> routines being put in gtype-c.h
kono
parents:
diff changeset
153 but not gtype-objc.h. */
kono
parents:
diff changeset
154 extern c_token * c_parser_tokens_buf (c_parser *parser, unsigned n);
kono
parents:
diff changeset
155 extern bool c_parser_error (c_parser *parser);
kono
parents:
diff changeset
156 extern void c_parser_set_error (c_parser *parser, bool);
kono
parents:
diff changeset
157
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
158 /* A bit of a hack to have this here. It would be better in a c-decl.h. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
159 extern bool old_style_parameter_scope (void);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
160
111
kono
parents:
diff changeset
161 /* Return true if the next token from PARSER has the indicated
kono
parents:
diff changeset
162 TYPE. */
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 static inline bool
kono
parents:
diff changeset
165 c_parser_next_token_is (c_parser *parser, enum cpp_ttype type)
kono
parents:
diff changeset
166 {
kono
parents:
diff changeset
167 return c_parser_peek_token (parser)->type == type;
kono
parents:
diff changeset
168 }
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 /* Return true if the next token from PARSER does not have the
kono
parents:
diff changeset
171 indicated TYPE. */
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 static inline bool
kono
parents:
diff changeset
174 c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type)
kono
parents:
diff changeset
175 {
kono
parents:
diff changeset
176 return !c_parser_next_token_is (parser, type);
kono
parents:
diff changeset
177 }
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 /* Return true if the next token from PARSER is the indicated
kono
parents:
diff changeset
180 KEYWORD. */
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 static inline bool
kono
parents:
diff changeset
183 c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword)
kono
parents:
diff changeset
184 {
kono
parents:
diff changeset
185 return c_parser_peek_token (parser)->keyword == keyword;
kono
parents:
diff changeset
186 }
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 extern struct c_declarator *
kono
parents:
diff changeset
189 c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
kono
parents:
diff changeset
190 bool *seen_id);
kono
parents:
diff changeset
191 extern void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool,
kono
parents:
diff changeset
192 bool, bool, bool, enum c_lookahead_kind);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
193 extern struct c_type_name *c_parser_type_name (c_parser *, bool = false);
111
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 #endif