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/>. */
24 #ifdef HOST_GENERATOR_FILE
26 #define GENERATOR_FILE 1
32 #define malloc xmalloc
33 #define realloc xrealloc
37 #define YY_DECL int yylex (const char **yylval)
38 #define yyterminate() return EOF_TOKEN
40 struct fileloc lexer_line;
41 int lexer_toplevel_done;
44 update_lineno (const char *l, size_t len)
53 CID [[:alpha:]_][[:alnum:]_]*
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
57 ITYPE {IWORD}({WS}{IWORD})*
58 /* Include '::' in identifiers to capture C++ scope qualifiers. */
59 ID {CID}({HWS}::{HWS}{CID})*
61 CXX_KEYWORD inline|public:|private:|protected:|template|operator|friend|static
63 %x in_struct in_struct_comment in_comment
64 %option warn noyywrap nounput nodefault perf-report
65 %option 8bit never-interactive
67 /* Do this on entry to yylex(): */
69 if (lexer_toplevel_done)
72 lexer_toplevel_done = 0;
75 /* Things we look for in skipping mode: */
77 ^{HWS}typedef/{EOID} {
103 /* Parsing inside a struct, union or class declaration. */
105 "/*" { BEGIN(in_struct_comment); }
106 "//".*\n { lexer_line.line++; }
108 {WS} { update_lineno (yytext, yyleng); }
109 \\\n { lexer_line.line++; }
111 "const"/{EOID} /* don't care */
112 {CXX_KEYWORD}/{EOID} |
116 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng + 1);
117 return IGNORABLE_CXX_KEYWORD;
119 "GTY"/{EOID} { return GTY_TOKEN; }
120 "union"/{EOID} { return UNION; }
121 "struct"/{EOID} { return STRUCT; }
122 "class"/{EOID} { return STRUCT; }
123 "typedef"/{EOID} { return TYPEDEF; }
124 "enum"/{EOID} { return ENUM; }
125 "ptr_alias"/{EOID} { return PTR_ALIAS; }
126 "nested_ptr"/{EOID} { return NESTED_PTR; }
127 "user"/{EOID} { return USER_GTY; }
128 [0-9]+ { return NUM; }
129 "param"[0-9]*"_is"/{EOID} {
130 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
134 {IWORD}({WS}{IWORD})*/{EOID} |
135 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
138 for (len = yyleng; ISSPACE (yytext[len-1]); len--)
141 *yylval = XDUPVAR (const char, yytext, len, len+1);
142 update_lineno (yytext, yyleng);
147 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
152 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
155 /* This "terminal" avoids having to parse integer constant expressions. */
157 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
160 "'"("\\".|[^\\])"'" {
161 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng);
165 "..." { return ELLIPSIS; }
166 [(){},*:<>;=%|+\!\?\.-] { return yytext[0]; }
168 /* ignore pp-directives */
169 ^{HWS}"#"{HWS}[a-z_]+[^\n]*\n {lexer_line.line++;}
172 error_at_line (&lexer_line, "unexpected character `%s'", yytext);
176 "/*" { BEGIN(in_comment); }
177 "//".*\n { lexer_line.line++; }
178 \n { lexer_line.line++; }
180 "'"("\\".|[^\\])"'" |
181 [^"/\n] /* do nothing */
182 \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
183 "/"/[^*] /* do nothing */
185 <in_comment,in_struct_comment>{
186 \n { lexer_line.line++; }
188 [^*\n] /* do nothing */
189 "*"/[^/] /* do nothing */
192 <in_comment>"*/" { BEGIN(INITIAL); }
193 <in_struct_comment>"*/" { BEGIN(in_struct); }
196 <in_struct_comment,in_comment>"*" {
197 error_at_line (&lexer_line,
198 "unterminated comment or string; unexpected EOF");
201 ^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */
206 yybegin (const char *fname)
208 yyin = fopen (fname, "r");
214 lexer_line.file = input_file_by_name (fname);