]>
Commit | Line | Data |
---|---|---|
1f3233d1 | 1 | /* -*- indented-text -*- */ |
2 | /* Process source files and output type information. | |
8e8f6434 | 3 | Copyright (C) 2002-2018 Free Software Foundation, Inc. |
1f3233d1 | 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 | |
8c4c00c1 | 9 | Software Foundation; either version 3, or (at your option) any later |
1f3233d1 | 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 | |
8c4c00c1 | 18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
1f3233d1 | 20 | |
e8f6c3dc | 21 | %option noinput |
22 | ||
1f3233d1 | 23 | %{ |
ed89620f | 24 | #ifdef HOST_GENERATOR_FILE |
6d70c713 | 25 | #include "config.h" |
ed89620f | 26 | #define GENERATOR_FILE 1 |
27 | #else | |
28 | #include "bconfig.h" | |
6d70c713 | 29 | #endif |
805e22b2 | 30 | #include "system.h" |
12a13e7a | 31 | |
32 | #define malloc xmalloc | |
33 | #define realloc xrealloc | |
34 | ||
1f3233d1 | 35 | #include "gengtype.h" |
1e837561 | 36 | |
37 | #define YY_DECL int yylex (const char **yylval) | |
38 | #define yyterminate() return EOF_TOKEN | |
1f3233d1 | 39 | |
1f3233d1 | 40 | struct fileloc lexer_line; |
41 | int lexer_toplevel_done; | |
42 | ||
43 | static void | |
5a2784f8 | 44 | update_lineno (const char *l, size_t len) |
1f3233d1 | 45 | { |
46 | while (len-- > 0) | |
47 | if (*l++ == '\n') | |
48 | lexer_line.line++; | |
49 | } | |
50 | ||
1f3233d1 | 51 | %} |
52 | ||
25d34a34 | 53 | CID [[:alpha:]_][[:alnum:]_]* |
1f3233d1 | 54 | WS [[:space:]]+ |
1e837561 | 55 | HWS [ \t\r\v\f]* |
3a4303e7 | 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 |
1f3233d1 | 57 | ITYPE {IWORD}({WS}{IWORD})* |
25d34a34 | 58 | /* Include '::' in identifiers to capture C++ scope qualifiers. */ |
59 | ID {CID}({HWS}::{HWS}{CID})* | |
1e837561 | 60 | EOID [^[:alnum:]_] |
e913b5cd | 61 | CXX_KEYWORD inline|public:|private:|protected:|template|operator|friend|static |
1f3233d1 | 62 | |
f8be92ce | 63 | %x in_struct in_struct_comment in_comment |
1f3233d1 | 64 | %option warn noyywrap nounput nodefault perf-report |
65 | %option 8bit never-interactive | |
66 | %% | |
1e837561 | 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 | } | |
1f3233d1 | 74 | |
1e837561 | 75 | /* Things we look for in skipping mode: */ |
76 | <INITIAL>{ | |
30dfb8d1 | 77 | ^{HWS}typedef/{EOID} { |
1e837561 | 78 | BEGIN(in_struct); |
79 | return TYPEDEF; | |
1f3233d1 | 80 | } |
30dfb8d1 | 81 | ^{HWS}struct/{EOID} { |
1e837561 | 82 | BEGIN(in_struct); |
83 | return STRUCT; | |
1f3233d1 | 84 | } |
30dfb8d1 | 85 | ^{HWS}union/{EOID} { |
1e837561 | 86 | BEGIN(in_struct); |
87 | return UNION; | |
e8d74f41 | 88 | } |
25d34a34 | 89 | ^{HWS}class/{EOID} { |
90 | BEGIN(in_struct); | |
91 | return STRUCT; | |
92 | } | |
30dfb8d1 | 93 | ^{HWS}extern/{EOID} { |
1e837561 | 94 | BEGIN(in_struct); |
95 | return EXTERN; | |
e8d74f41 | 96 | } |
30dfb8d1 | 97 | ^{HWS}static/{EOID} { |
1f3233d1 | 98 | BEGIN(in_struct); |
1e837561 | 99 | return STATIC; |
1f3233d1 | 100 | } |
190183c5 | 101 | } |
102 | ||
25d34a34 | 103 | /* Parsing inside a struct, union or class declaration. */ |
1f3233d1 | 104 | <in_struct>{ |
1f3233d1 | 105 | "/*" { BEGIN(in_struct_comment); } |
25d34a34 | 106 | "//".*\n { lexer_line.line++; } |
1f3233d1 | 107 | |
1f3233d1 | 108 | {WS} { update_lineno (yytext, yyleng); } |
046553d4 | 109 | \\\n { lexer_line.line++; } |
1f3233d1 | 110 | |
1e837561 | 111 | "const"/{EOID} /* don't care */ |
25d34a34 | 112 | {CXX_KEYWORD}/{EOID} | |
113 | "~" | | |
e913b5cd | 114 | "^" | |
25d34a34 | 115 | "&" { |
116 | *yylval = XDUPVAR (const char, yytext, yyleng, yyleng + 1); | |
117 | return IGNORABLE_CXX_KEYWORD; | |
118 | } | |
1e837561 | 119 | "GTY"/{EOID} { return GTY_TOKEN; } |
1e837561 | 120 | "union"/{EOID} { return UNION; } |
121 | "struct"/{EOID} { return STRUCT; } | |
25d34a34 | 122 | "class"/{EOID} { return STRUCT; } |
123 | "typedef"/{EOID} { return TYPEDEF; } | |
1e837561 | 124 | "enum"/{EOID} { return ENUM; } |
125 | "ptr_alias"/{EOID} { return PTR_ALIAS; } | |
126 | "nested_ptr"/{EOID} { return NESTED_PTR; } | |
2b15d2ba | 127 | "user"/{EOID} { return USER_GTY; } |
1f3233d1 | 128 | [0-9]+ { return NUM; } |
129 | ||
1e837561 | 130 | {IWORD}({WS}{IWORD})*/{EOID} | |
1f3233d1 | 131 | "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" { |
132 | size_t len; | |
133 | ||
74863452 | 134 | for (len = yyleng; ISSPACE (yytext[len-1]); len--) |
1f3233d1 | 135 | ; |
136 | ||
65b198c2 | 137 | *yylval = XDUPVAR (const char, yytext, len, len+1); |
1f3233d1 | 138 | update_lineno (yytext, yyleng); |
139 | return SCALAR; | |
140 | } | |
141 | ||
1e837561 | 142 | {ID}/{EOID} { |
65b198c2 | 143 | *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1); |
1f3233d1 | 144 | return ID; |
145 | } | |
146 | ||
147 | \"([^"\\]|\\.)*\" { | |
65b198c2 | 148 | *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1); |
1f3233d1 | 149 | return STRING; |
150 | } | |
1e837561 | 151 | /* This "terminal" avoids having to parse integer constant expressions. */ |
1f3233d1 | 152 | "["[^\[\]]*"]" { |
65b198c2 | 153 | *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1); |
1f3233d1 | 154 | return ARRAY; |
155 | } | |
1f3233d1 | 156 | "'"("\\".|[^\\])"'" { |
65b198c2 | 157 | *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng); |
1f3233d1 | 158 | return CHAR; |
159 | } | |
160 | ||
1e837561 | 161 | "..." { return ELLIPSIS; } |
7aa67720 | 162 | [(){},*:<>;=%/|+\!\?\.-] { return yytext[0]; } |
1f3233d1 | 163 | |
1e837561 | 164 | /* ignore pp-directives */ |
165 | ^{HWS}"#"{HWS}[a-z_]+[^\n]*\n {lexer_line.line++;} | |
90a3c0eb | 166 | |
1f3233d1 | 167 | . { |
168 | error_at_line (&lexer_line, "unexpected character `%s'", yytext); | |
169 | } | |
170 | } | |
171 | ||
172 | "/*" { BEGIN(in_comment); } | |
25d34a34 | 173 | "//".*\n { lexer_line.line++; } |
1f3233d1 | 174 | \n { lexer_line.line++; } |
175 | {ID} | | |
2c2e43fb | 176 | "'"("\\".|[^\\])"'" | |
1f3233d1 | 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 | } | |
25d34a34 | 187 | |
1f3233d1 | 188 | <in_comment>"*/" { BEGIN(INITIAL); } |
189 | <in_struct_comment>"*/" { BEGIN(in_struct); } | |
190 | ||
1f3233d1 | 191 | ["/] | |
192 | <in_struct_comment,in_comment>"*" { | |
193 | error_at_line (&lexer_line, | |
194 | "unterminated comment or string; unexpected EOF"); | |
195 | } | |
196 | ||
30dfb8d1 | 197 | ^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */ |
8ca71ef2 | 198 | |
1f3233d1 | 199 | %% |
200 | ||
201 | void | |
1e837561 | 202 | yybegin (const char *fname) |
1f3233d1 | 203 | { |
204 | yyin = fopen (fname, "r"); | |
1f3233d1 | 205 | if (yyin == NULL) |
206 | { | |
207 | perror (fname); | |
208 | exit (1); | |
209 | } | |
dc8a8bf5 | 210 | lexer_line.file = input_file_by_name (fname); |
1e837561 | 211 | lexer_line.line = 1; |
212 | } | |
213 | ||
214 | void | |
215 | yyend (void) | |
216 | { | |
1f3233d1 | 217 | fclose (yyin); |
218 | } |