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
30 #define YY_DECL int yylex (const char **yylval)
31 #define yyterminate() return EOF_TOKEN
33 struct fileloc lexer_line;
34 int lexer_toplevel_done;
37 update_lineno (const char *l, size_t len)
46 ID [[:alpha:]_][[:alnum:]_]*
49 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
50 ITYPE {IWORD}({WS}{IWORD})*
53 %x in_struct in_struct_comment in_comment
54 %option warn noyywrap nounput nodefault perf-report
55 %option 8bit never-interactive
57 /* Do this on entry to yylex(): */
59 if (lexer_toplevel_done)
62 lexer_toplevel_done = 0;
65 /* Things we look for in skipping mode: */
67 ^{HWS}typedef/{EOID} {
88 ^{HWS}DEF_VEC_[OP]/{EOID} {
92 ^{HWS}DEF_VEC_I/{EOID} {
96 ^{HWS}DEF_VEC_ALLOC_[IOP]/{EOID} {
104 "/*" { BEGIN(in_struct_comment); }
106 {WS} { update_lineno (yytext, yyleng); }
107 \\\n { lexer_line.line++; }
109 "const"/{EOID} /* don't care */
110 "GTY"/{EOID} { return GTY_TOKEN; }
111 "VEC"/{EOID} { return VEC_TOKEN; }
112 "union"/{EOID} { return UNION; }
113 "struct"/{EOID} { return STRUCT; }
114 "enum"/{EOID} { return ENUM; }
115 "ptr_alias"/{EOID} { return PTR_ALIAS; }
116 "nested_ptr"/{EOID} { return NESTED_PTR; }
117 [0-9]+ { return NUM; }
118 "param"[0-9]*"_is"/{EOID} {
119 *yylval = xmemdup (yytext, yyleng, yyleng+1);
123 {IWORD}({WS}{IWORD})*/{EOID} |
124 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
127 for (len = yyleng; ISSPACE (yytext[len-1]); len--)
130 *yylval = xmemdup (yytext, len, len+1);
131 update_lineno (yytext, yyleng);
137 *yylval = xmemdup (yytext, yyleng, yyleng+1);
142 *yylval = xmemdup (yytext+1, yyleng-2, yyleng-1);
145 /* This "terminal" avoids having to parse integer constant expressions. */
147 *yylval = xmemdup (yytext+1, yyleng-2, yyleng-1);
150 "'"("\\".|[^\\])"'" {
151 *yylval = xmemdup (yytext+1, yyleng-2, yyleng);
155 "..." { return ELLIPSIS; }
156 [(){},*:<>;=%|-] { return yytext[0]; }
158 /* ignore pp-directives */
159 ^{HWS}"#"{HWS}[a-z_]+[^\n]*\n {lexer_line.line++;}
162 error_at_line (&lexer_line, "unexpected character `%s'", yytext);
166 "/*" { BEGIN(in_comment); }
167 \n { lexer_line.line++; }
169 "'"("\\".|[^\\])"'" |
170 [^"/\n] /* do nothing */
171 \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
172 "/"/[^*] /* do nothing */
174 <in_comment,in_struct_comment>{
175 \n { lexer_line.line++; }
177 [^*\n] /* do nothing */
178 "*"/[^/] /* do nothing */
180 <in_comment>"*/" { BEGIN(INITIAL); }
181 <in_struct_comment>"*/" { BEGIN(in_struct); }
184 <in_struct_comment,in_comment>"*" {
185 error_at_line (&lexer_line,
186 "unterminated comment or string; unexpected EOF");
189 ^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */
191 error_at_line (&lexer_line, "stray GTY marker");
197 yybegin (const char *fname)
199 yyin = fopen (fname, "r");
205 lexer_line.file = fname;