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