]>
Commit | Line | Data |
---|---|---|
e2500fed GK |
1 | /* -*- indented-text -*- */ |
2 | /* Process source files and output type information. | |
8d9254fc | 3 | Copyright (C) 2002-2020 Free Software Foundation, Inc. |
e2500fed GK |
4 | |
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
e2500fed GK |
10 | version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
e2500fed | 20 | |
e81f2ecf BE |
21 | %option noinput |
22 | ||
e2500fed | 23 | %{ |
d6d34aa9 | 24 | #ifdef HOST_GENERATOR_FILE |
f142b5bc | 25 | #include "config.h" |
d6d34aa9 JJ |
26 | #define GENERATOR_FILE 1 |
27 | #else | |
28 | #include "bconfig.h" | |
f142b5bc | 29 | #endif |
4977bab6 | 30 | #include "system.h" |
4da78214 JDA |
31 | |
32 | #define malloc xmalloc | |
33 | #define realloc xrealloc | |
34 | ||
e2500fed | 35 | #include "gengtype.h" |
01d419ae ZW |
36 | |
37 | #define YY_DECL int yylex (const char **yylval) | |
38 | #define yyterminate() return EOF_TOKEN | |
e2500fed | 39 | |
e2500fed GK |
40 | struct fileloc lexer_line; |
41 | int lexer_toplevel_done; | |
42 | ||
43 | static void | |
f55ade6e | 44 | update_lineno (const char *l, size_t len) |
e2500fed GK |
45 | { |
46 | while (len-- > 0) | |
47 | if (*l++ == '\n') | |
48 | lexer_line.line++; | |
49 | } | |
50 | ||
e2500fed GK |
51 | %} |
52 | ||
313465bb | 53 | CID [[:alpha:]_][[:alnum:]_]* |
e2500fed | 54 | WS [[:space:]]+ |
01d419ae | 55 | HWS [ \t\r\v\f]* |
a9243bfc | 56 | IWORD short|long|(un)?signed|char|int|HOST_WIDE_INT|uint64_t|int64_t|bool|size_t|BOOL_BITFIELD|CPPCHAR_SIGNED_T|ino_t|dev_t|HARD_REG_SET |
e2500fed | 57 | ITYPE {IWORD}({WS}{IWORD})* |
313465bb DN |
58 | /* Include '::' in identifiers to capture C++ scope qualifiers. */ |
59 | ID {CID}({HWS}::{HWS}{CID})* | |
01d419ae | 60 | EOID [^[:alnum:]_] |
ad671098 | 61 | CXX_KEYWORD inline|public:|private:|protected:|template|operator|friend|static|mutable |
e2500fed | 62 | |
cff4720f | 63 | %x in_struct in_struct_comment in_comment |
e2500fed GK |
64 | %option warn noyywrap nounput nodefault perf-report |
65 | %option 8bit never-interactive | |
66 | %% | |
01d419ae ZW |
67 | /* Do this on entry to yylex(): */ |
68 | *yylval = 0; | |
69 | if (lexer_toplevel_done) | |
70 | { | |
71 | BEGIN(INITIAL); | |
72 | lexer_toplevel_done = 0; | |
73 | } | |
e2500fed | 74 | |
01d419ae ZW |
75 | /* Things we look for in skipping mode: */ |
76 | <INITIAL>{ | |
36f568c3 | 77 | ^{HWS}typedef/{EOID} { |
01d419ae ZW |
78 | BEGIN(in_struct); |
79 | return TYPEDEF; | |
e2500fed | 80 | } |
36f568c3 | 81 | ^{HWS}struct/{EOID} { |
01d419ae ZW |
82 | BEGIN(in_struct); |
83 | return STRUCT; | |
e2500fed | 84 | } |
36f568c3 | 85 | ^{HWS}union/{EOID} { |
01d419ae ZW |
86 | BEGIN(in_struct); |
87 | return UNION; | |
790ca664 | 88 | } |
313465bb DN |
89 | ^{HWS}class/{EOID} { |
90 | BEGIN(in_struct); | |
91 | return STRUCT; | |
92 | } | |
36f568c3 | 93 | ^{HWS}extern/{EOID} { |
01d419ae ZW |
94 | BEGIN(in_struct); |
95 | return EXTERN; | |
790ca664 | 96 | } |
36f568c3 | 97 | ^{HWS}static/{EOID} { |
e2500fed | 98 | BEGIN(in_struct); |
01d419ae | 99 | return STATIC; |
e2500fed | 100 | } |
ada55151 NS |
101 | } |
102 | ||
313465bb | 103 | /* Parsing inside a struct, union or class declaration. */ |
e2500fed | 104 | <in_struct>{ |
e2500fed | 105 | "/*" { BEGIN(in_struct_comment); } |
313465bb | 106 | "//".*\n { lexer_line.line++; } |
e2500fed | 107 | |
e2500fed | 108 | {WS} { update_lineno (yytext, yyleng); } |
049e9ad9 | 109 | \\\n { lexer_line.line++; } |
e2500fed | 110 | |
01d419ae | 111 | "const"/{EOID} /* don't care */ |
313465bb DN |
112 | {CXX_KEYWORD}/{EOID} | |
113 | "~" | | |
807e902e | 114 | "^" | |
313465bb DN |
115 | "&" { |
116 | *yylval = XDUPVAR (const char, yytext, yyleng, yyleng + 1); | |
117 | return IGNORABLE_CXX_KEYWORD; | |
118 | } | |
01d419ae | 119 | "GTY"/{EOID} { return GTY_TOKEN; } |
01d419ae ZW |
120 | "union"/{EOID} { return UNION; } |
121 | "struct"/{EOID} { return STRUCT; } | |
313465bb DN |
122 | "class"/{EOID} { return STRUCT; } |
123 | "typedef"/{EOID} { return TYPEDEF; } | |
01d419ae ZW |
124 | "enum"/{EOID} { return ENUM; } |
125 | "ptr_alias"/{EOID} { return PTR_ALIAS; } | |
126 | "nested_ptr"/{EOID} { return NESTED_PTR; } | |
0823efed | 127 | "user"/{EOID} { return USER_GTY; } |
e2500fed GK |
128 | [0-9]+ { return NUM; } |
129 | ||
01d419ae | 130 | {IWORD}({WS}{IWORD})*/{EOID} | |
e2500fed GK |
131 | "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" { |
132 | size_t len; | |
133 | ||
1f8e4682 | 134 | for (len = yyleng; ISSPACE (yytext[len-1]); len--) |
e2500fed GK |
135 | ; |
136 | ||
7cbb2a85 | 137 | *yylval = XDUPVAR (const char, yytext, len, len+1); |
e2500fed GK |
138 | update_lineno (yytext, yyleng); |
139 | return SCALAR; | |
140 | } | |
141 | ||
01d419ae | 142 | {ID}/{EOID} { |
7cbb2a85 | 143 | *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1); |
e2500fed GK |
144 | return ID; |
145 | } | |
146 | ||
147 | \"([^"\\]|\\.)*\" { | |
7cbb2a85 | 148 | *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1); |
e2500fed GK |
149 | return STRING; |
150 | } | |
01d419ae | 151 | /* This "terminal" avoids having to parse integer constant expressions. */ |
e2500fed | 152 | "["[^\[\]]*"]" { |
7cbb2a85 | 153 | *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1); |
e2500fed GK |
154 | return ARRAY; |
155 | } | |
e2500fed | 156 | "'"("\\".|[^\\])"'" { |
7cbb2a85 | 157 | *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng); |
e2500fed GK |
158 | return CHAR; |
159 | } | |
160 | ||
01d419ae | 161 | "..." { return ELLIPSIS; } |
0e9d2c4f | 162 | [(){},*:<>;=%/|+\!\?\.-] { return yytext[0]; } |
e2500fed | 163 | |
01d419ae ZW |
164 | /* ignore pp-directives */ |
165 | ^{HWS}"#"{HWS}[a-z_]+[^\n]*\n {lexer_line.line++;} | |
422d9921 | 166 | |
e2500fed GK |
167 | . { |
168 | error_at_line (&lexer_line, "unexpected character `%s'", yytext); | |
169 | } | |
170 | } | |
171 | ||
172 | "/*" { BEGIN(in_comment); } | |
313465bb | 173 | "//".*\n { lexer_line.line++; } |
e2500fed GK |
174 | \n { lexer_line.line++; } |
175 | {ID} | | |
8a5d66c4 | 176 | "'"("\\".|[^\\])"'" | |
e2500fed GK |
177 | [^"/\n] /* do nothing */ |
178 | \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); } | |
179 | "/"/[^*] /* do nothing */ | |
180 | ||
181 | <in_comment,in_struct_comment>{ | |
182 | \n { lexer_line.line++; } | |
183 | [^*\n]{16} | | |
184 | [^*\n] /* do nothing */ | |
185 | "*"/[^/] /* do nothing */ | |
186 | } | |
313465bb | 187 | |
e2500fed GK |
188 | <in_comment>"*/" { BEGIN(INITIAL); } |
189 | <in_struct_comment>"*/" { BEGIN(in_struct); } | |
190 | ||
e2500fed GK |
191 | ["/] | |
192 | <in_struct_comment,in_comment>"*" { | |
193 | error_at_line (&lexer_line, | |
194 | "unterminated comment or string; unexpected EOF"); | |
195 | } | |
196 | ||
36f568c3 | 197 | ^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */ |
133f7a77 | 198 | |
e2500fed GK |
199 | %% |
200 | ||
201 | void | |
01d419ae | 202 | yybegin (const char *fname) |
e2500fed GK |
203 | { |
204 | yyin = fopen (fname, "r"); | |
e2500fed GK |
205 | if (yyin == NULL) |
206 | { | |
207 | perror (fname); | |
208 | exit (1); | |
209 | } | |
14c4815e | 210 | lexer_line.file = input_file_by_name (fname); |
01d419ae ZW |
211 | lexer_line.line = 1; |
212 | } | |
213 | ||
214 | void | |
215 | yyend (void) | |
216 | { | |
e2500fed GK |
217 | fclose (yyin); |
218 | } |