1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3 Copyright (C) 2002-2014 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/>. */
31 #define malloc xmalloc
32 #define realloc xrealloc
36 #define YY_DECL int yylex (const char **yylval)
37 #define yyterminate() return EOF_TOKEN
39 struct fileloc lexer_line;
40 int lexer_toplevel_done;
43 update_lineno (const char *l, size_t len)
52 CID [[:alpha:]_][[:alnum:]_]*
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})*
60 CXX_KEYWORD inline|public:|private:|protected:|template|operator|friend
62 %x in_struct in_struct_comment in_comment
63 %option warn noyywrap nounput nodefault perf-report
64 %option 8bit never-interactive
66 /* Do this on entry to yylex(): */
68 if (lexer_toplevel_done)
71 lexer_toplevel_done = 0;
74 /* Things we look for in skipping mode: */
76 ^{HWS}typedef/{EOID} {
102 /* Parsing inside a struct, union or class declaration. */
104 "/*" { BEGIN(in_struct_comment); }
105 "//".*\n { lexer_line.line++; }
107 {WS} { update_lineno (yytext, yyleng); }
108 \\\n { lexer_line.line++; }
110 "const"/{EOID} /* don't care */
111 {CXX_KEYWORD}/{EOID} |
114 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng + 1);
115 return IGNORABLE_CXX_KEYWORD;
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);
132 {IWORD}({WS}{IWORD})*/{EOID} |
133 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
136 for (len = yyleng; ISSPACE (yytext[len-1]); len--)
139 *yylval = XDUPVAR (const char, yytext, len, len+1);
140 update_lineno (yytext, yyleng);
145 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
150 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
153 /* This "terminal" avoids having to parse integer constant expressions. */
155 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
158 "'"("\\".|[^\\])"'" {
159 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng);
163 "..." { return ELLIPSIS; }
164 [(){},*:<>;=%|+\!\?\.-] { return yytext[0]; }
166 /* ignore pp-directives */
167 ^{HWS}"#"{HWS}[a-z_]+[^\n]*\n {lexer_line.line++;}
170 error_at_line (&lexer_line, "unexpected character `%s'", yytext);
174 "/*" { BEGIN(in_comment); }
175 "//".*\n { lexer_line.line++; }
176 \n { lexer_line.line++; }
178 "'"("\\".|[^\\])"'" |
179 [^"/\n] /* do nothing */
180 \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
181 "/"/[^*] /* do nothing */
183 <in_comment,in_struct_comment>{
184 \n { lexer_line.line++; }
186 [^*\n] /* do nothing */
187 "*"/[^/] /* do nothing */
190 <in_comment>"*/" { BEGIN(INITIAL); }
191 <in_struct_comment>"*/" { BEGIN(in_struct); }
194 <in_struct_comment,in_comment>"*" {
195 error_at_line (&lexer_line,
196 "unterminated comment or string; unexpected EOF");
199 ^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */
204 yybegin (const char *fname)
206 yyin = fopen (fname, "r");
212 lexer_line.file = input_file_by_name (fname);