1 /* -*- indented-text -*- */ 2 /* Process source files and output type information. 3 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 4 Free Software Foundation, Inc. 5 6 This file is part of GCC. 7 8 GCC is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free 10 Software Foundation; either version 3, or (at your option) any later 11 version. 12 13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 14 WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with GCC; see the file COPYING3. If not see 20 <http://www.gnu.org/licenses/>. */ 21 22 %option noinput 23 24 %{ 25 #ifdef GENERATOR_FILE 26 #include "bconfig.h" 27 #else 28 #include "config.h" 29 #endif 30 #include "system.h" 31 32 #define malloc xmalloc 33 #define realloc xrealloc 34 35 #include "gengtype.h" 36 37 #define YY_DECL int yylex (const char **yylval) 38 #define yyterminate() return EOF_TOKEN 39 40 struct fileloc lexer_line; 41 int lexer_toplevel_done; 42 43 static void 44 update_lineno (const char *l, size_t len) 45 { 46 while (len-- > 0) 47 if (*l++ == '\n') 48 lexer_line.line++; 49 } 50 51 %} 52 53 ID [[:alpha:]_][[:alnum:]_]* 54 WS [[:space:]]+ 55 HWS [ \t\r\v\f]* 56 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 57 ITYPE {IWORD}({WS}{IWORD})* 58 EOID [^[:alnum:]_] 59 60 %x in_struct in_struct_comment in_comment 61 %option warn noyywrap nounput nodefault perf-report 62 %option 8bit never-interactive 63 %% 64 /* Do this on entry to yylex(): */ 65 *yylval = 0; 66 if (lexer_toplevel_done) 67 { 68 BEGIN(INITIAL); 69 lexer_toplevel_done = 0; 70 } 71 72 /* Things we look for in skipping mode: */ 73 <INITIAL>{ 74 ^{HWS}typedef/{EOID} { 75 BEGIN(in_struct); 76 return TYPEDEF; 77 } 78 ^{HWS}struct/{EOID} { 79 BEGIN(in_struct); 80 return STRUCT; 81 } 82 ^{HWS}union/{EOID} { 83 BEGIN(in_struct); 84 return UNION; 85 } 86 ^{HWS}extern/{EOID} { 87 BEGIN(in_struct); 88 return EXTERN; 89 } 90 ^{HWS}static/{EOID} { 91 BEGIN(in_struct); 92 return STATIC; 93 } 94 95 ^{HWS}DEF_VEC_[OP]/{EOID} { 96 BEGIN(in_struct); 97 return DEFVEC_OP; 98 } 99 ^{HWS}DEF_VEC_I/{EOID} { 100 BEGIN(in_struct); 101 return DEFVEC_I; 102 } 103 ^{HWS}DEF_VEC_ALLOC_[IOP]/{EOID} { 104 BEGIN(in_struct); 105 return DEFVEC_ALLOC; 106 } 107 } 108 109 <in_struct>{ 110 111 "/*" { BEGIN(in_struct_comment); } 112 113 {WS} { update_lineno (yytext, yyleng); } 114 \\\n { lexer_line.line++; } 115 116 "const"/{EOID} /* don't care */ 117 "GTY"/{EOID} { return GTY_TOKEN; } 118 "VEC"/{EOID} { return VEC_TOKEN; } 119 "union"/{EOID} { return UNION; } 120 "struct"/{EOID} { return STRUCT; } 121 "enum"/{EOID} { return ENUM; } 122 "ptr_alias"/{EOID} { return PTR_ALIAS; } 123 "nested_ptr"/{EOID} { return NESTED_PTR; } 124 [0-9]+ { return NUM; } 125 "param"[0-9]*"_is"/{EOID} { 126 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1); 127 return PARAM_IS; 128 } 129 130 {IWORD}({WS}{IWORD})*/{EOID} | 131 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" { 132 size_t len; 133 134 for (len = yyleng; ISSPACE (yytext[len-1]); len--) 135 ; 136 137 *yylval = XDUPVAR (const char, yytext, len, len+1); 138 update_lineno (yytext, yyleng); 139 return SCALAR; 140 } 141 142 143 {ID}/{EOID} { 144 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1); 145 return ID; 146 } 147 148 \"([^"\\]|\\.)*\" { 149 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1); 150 return STRING; 151 } 152 /* This "terminal" avoids having to parse integer constant expressions. */ 153 "["[^\[\]]*"]" { 154 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1); 155 return ARRAY; 156 } 157 "'"("\\".|[^\\])"'" { 158 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng); 159 return CHAR; 160 } 161 162 "..." { return ELLIPSIS; } 163 [(){},*:<>;=%|-] { return yytext[0]; } 164 165 /* ignore pp-directives */ 166 ^{HWS}"#"{HWS}[a-z_]+[^\n]*\n {lexer_line.line++;} 167 168 . { 169 error_at_line (&lexer_line, "unexpected character `%s'", yytext); 170 } 171 } 172 173 "/*" { BEGIN(in_comment); } 174 \n { lexer_line.line++; } 175 {ID} | 176 "'"("\\".|[^\\])"'" | 177 [^"/\n] /* do nothing */ 178 \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); } 179 "/"/[^*] /* do nothing */ 180 181 <in_comment,in_struct_comment>{ 182 \n { lexer_line.line++; } 183 [^*\n]{16} | 184 [^*\n] /* do nothing */ 185 "*"/[^/] /* do nothing */ 186 } 187 <in_comment>"*/" { BEGIN(INITIAL); } 188 <in_struct_comment>"*/" { BEGIN(in_struct); } 189 190 ["/] | 191 <in_struct_comment,in_comment>"*" { 192 error_at_line (&lexer_line, 193 "unterminated comment or string; unexpected EOF"); 194 } 195 196 ^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */ 197 198 %% 199 200 void 201 yybegin (const char *fname) 202 { 203 yyin = fopen (fname, "r"); 204 if (yyin == NULL) 205 { 206 perror (fname); 207 exit (1); 208 } 209 lexer_line.file = input_file_by_name (fname); 210 lexer_line.line = 1; 211 } 212 213 void 214 yyend (void) 215 { 216 fclose (yyin); 217 } 218