1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3 Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
5 This file is part of GCC.
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
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
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/>. */
25 #define malloc xmalloc
26 #define realloc xrealloc
31 #define YY_DECL int yylex (const char **yylval)
32 #define yyterminate() return EOF_TOKEN
34 struct fileloc lexer_line;
35 int lexer_toplevel_done;
38 update_lineno (const char *l, size_t len)
47 ID [[:alpha:]_][[:alnum:]_]*
50 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
51 ITYPE {IWORD}({WS}{IWORD})*
54 %x in_struct in_struct_comment in_comment
55 %option warn noyywrap nounput nodefault perf-report
56 %option 8bit never-interactive
58 /* Do this on entry to yylex(): */
60 if (lexer_toplevel_done)
63 lexer_toplevel_done = 0;
66 /* Things we look for in skipping mode: */
68 ^{HWS}typedef/{EOID} {
89 ^{HWS}DEF_VEC_[OP]/{EOID} {
93 ^{HWS}DEF_VEC_I/{EOID} {
97 ^{HWS}DEF_VEC_ALLOC_[IOP]/{EOID} {
105 "/*" { BEGIN(in_struct_comment); }
107 {WS} { update_lineno (yytext, yyleng); }
108 \\\n { lexer_line.line++; }
110 "const"/{EOID} /* don't care */
111 "GTY"/{EOID} { return GTY_TOKEN; }
112 "VEC"/{EOID} { return VEC_TOKEN; }
113 "union"/{EOID} { return UNION; }
114 "struct"/{EOID} { return STRUCT; }
115 "enum"/{EOID} { return ENUM; }
116 "ptr_alias"/{EOID} { return PTR_ALIAS; }
117 "nested_ptr"/{EOID} { return NESTED_PTR; }
118 [0-9]+ { return NUM; }
119 "param"[0-9]*"_is"/{EOID} {
120 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
124 {IWORD}({WS}{IWORD})*/{EOID} |
125 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
128 for (len = yyleng; ISSPACE (yytext[len-1]); len--)
131 *yylval = XDUPVAR (const char, yytext, len, len+1);
132 update_lineno (yytext, yyleng);
138 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
143 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
146 /* This "terminal" avoids having to parse integer constant expressions. */
148 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
151 "'"("\\".|[^\\])"'" {
152 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng);
156 "..." { return ELLIPSIS; }
157 [(){},*:<>;=%|-] { return yytext[0]; }
159 /* ignore pp-directives */
160 ^{HWS}"#"{HWS}[a-z_]+[^\n]*\n {lexer_line.line++;}
163 error_at_line (&lexer_line, "unexpected character `%s'", yytext);
167 "/*" { BEGIN(in_comment); }
168 \n { lexer_line.line++; }
170 "'"("\\".|[^\\])"'" |
171 [^"/\n] /* do nothing */
172 \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
173 "/"/[^*] /* do nothing */
175 <in_comment,in_struct_comment>{
176 \n { lexer_line.line++; }
178 [^*\n] /* do nothing */
179 "*"/[^/] /* do nothing */
181 <in_comment>"*/" { BEGIN(INITIAL); }
182 <in_struct_comment>"*/" { BEGIN(in_struct); }
185 <in_struct_comment,in_comment>"*" {
186 error_at_line (&lexer_line,
187 "unterminated comment or string; unexpected EOF");
190 ^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */
192 error_at_line (&lexer_line, "stray GTY marker");
198 yybegin (const char *fname)
200 yyin = fopen (fname, "r");
206 lexer_line.file = fname;