1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3 Copyright (C) 2002, 2003 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 2, 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 COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
27 #define malloc xmalloc
28 #define realloc xrealloc
31 #include "gengtype-yacc.h"
34 #define YY_DECL int yylex ()
36 static void update_lineno (const char *l, size_t len);
38 struct fileloc lexer_line;
39 int lexer_toplevel_done;
42 update_lineno (const char *l, size_t len)
51 ID [[:alpha:]_][[:alnum:]_]*
53 IWORD short|long|(un)?signed|char|int|HOST_WIDE_INT|bool|size_t|CHAR_BITFIELD
54 ITYPE {IWORD}({WS}{IWORD})*
56 %x in_struct in_struct_comment in_comment in_yacc_escape
57 %option warn noyywrap nounput nodefault perf-report
58 %option 8bit never-interactive
61 [^[:alnum:]_]typedef{WS}(struct|union){WS}{ID}{WS}?[*[:space:]]{WS}?{ID}{WS}?";" {
70 tagstart = yytext + strlen (" typedef ");
71 while (ISSPACE (*tagstart))
73 union_p = tagstart[0] == 'u';
74 tagstart += strlen ("union ");
75 while (ISSPACE (*tagstart))
77 for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
79 for (namestart = tagstart + taglen;
80 ! ISIDNUM (*namestart);
82 if (*namestart == '*')
84 for (namelen = 1; ISIDNUM (namestart[namelen]); namelen++)
86 t = find_structure (xmemdup (tagstart, taglen, taglen+1), union_p);
88 t = create_pointer (t);
89 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
90 update_lineno (yytext, yyleng);
93 [^[:alnum:]_]typedef{WS}{ITYPE}{WS}{ID}{WS}?";" {
101 for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
103 for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
105 namestart -= namelen - 1;
106 for (typestart = yytext + strlen (" typedef ");
110 for (typelen = namestart - typestart;
111 ISSPACE(typestart[typelen-1]);
115 t = create_scalar_type (typestart, typelen);
116 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
117 update_lineno (yytext, yyleng);
120 [^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}PARAMS {
125 for (namestart = yytext + yyleng - 7; ISSPACE (*namestart); namestart--)
127 for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
129 namestart -= namelen - 1;
131 t = create_scalar_type ("function type", sizeof ("function type")-1);
132 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
133 update_lineno (yytext, yyleng);
136 [^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}"(" {
141 for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
143 for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
145 namestart -= namelen - 1;
147 t = create_scalar_type ("function type", sizeof ("function type")-1);
148 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
149 update_lineno (yytext, yyleng);
152 [^[:alnum:]_]typedef{WS}{ID}{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?PARAMS {
157 for (namestart = yytext + yyleng - 7; !ISIDNUM (*namestart); namestart--)
159 for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
161 namestart -= namelen - 1;
163 t = create_scalar_type ("function type", sizeof ("function type")-1);
164 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
165 update_lineno (yytext, yyleng);
168 [^[:alnum:]_]typedef{WS}{ID}{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?"(" {
173 for (namestart = yytext + yyleng - 2; !ISIDNUM (*namestart); namestart--)
175 for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
177 namestart -= namelen - 1;
179 t = create_scalar_type ("function type", sizeof ("function type")-1);
180 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
181 update_lineno (yytext, yyleng);
184 [^[:alnum:]_](typedef{WS})?(struct|union){WS}{ID}{WS}/"GTY" {
190 typedef_p = yytext[1] == 't';
192 for (tagstart = yytext + strlen (" typedef ");
197 tagstart = yytext + 1;
199 union_p = tagstart[0] == 'u';
200 tagstart += strlen ("union ");
201 while (ISSPACE (*tagstart))
203 for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
206 yylval.t = find_structure (xmemdup (tagstart, taglen, taglen + 1), union_p);
208 update_lineno (yytext, yyleng);
209 return typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT;
212 [^[:alnum:]_](extern|static){WS}/"GTY" {
214 update_lineno (yytext, yyleng);
215 return ENT_EXTERNSTATIC;
218 ^"%union"{WS}"{"{WS}/"GTY" {
220 update_lineno (yytext, yyleng);
221 return ENT_YACCUNION;
226 "/*" { BEGIN(in_struct_comment); }
228 ^"%{" { BEGIN(in_yacc_escape); }
230 ^"@@".* /* Used for c-parse.in C/ObjC demarcation. */
232 {WS} { update_lineno (yytext, yyleng); }
234 "const"/[^[:alnum:]_] /* don't care */
236 "GTY"/[^[:alnum:]_] { return GTY_TOKEN; }
237 "union"/[^[:alnum:]_] { return UNION; }
238 "struct"/[^[:alnum:]_] { return STRUCT; }
239 "enum"/[^[:alnum:]_] { return ENUM; }
240 "ptr_alias"/[^[:alnum:]_] { return ALIAS; }
241 [0-9]+ { return NUM; }
242 "param"[0-9]*"_is"/[^[:alnum:]_] {
243 yylval.s = xmemdup (yytext, yyleng, yyleng+1);
247 {IWORD}({WS}{IWORD})*/[^[:alnum:]_] |
248 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
251 for (len = yyleng; ISSPACE (yytext[len-1]); len--)
254 yylval.t = create_scalar_type (yytext, len);
255 update_lineno (yytext, yyleng);
260 yylval.s = xmemdup (yytext, yyleng, yyleng+1);
265 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng-1);
269 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng-1);
273 yylval.s = xmemdup (yytext+1, yyleng-1, yyleng);
276 "'"("\\".|[^\\])"'" {
277 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng);
281 [(){},*:<>] { return yytext[0]; }
284 if (lexer_toplevel_done)
287 lexer_toplevel_done = 0;
294 return PERCENTPERCENT;
298 error_at_line (&lexer_line, "unexpected character `%s'", yytext);
302 "/*" { BEGIN(in_comment); }
303 \n { lexer_line.line++; }
305 "'"("\\".|[^\\])"'" |
306 [^"/\n] /* do nothing */
307 \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
308 "/"/[^*] /* do nothing */
310 <in_comment,in_struct_comment>{
311 \n { lexer_line.line++; }
313 [^*\n] /* do nothing */
314 "*"/[^/] /* do nothing */
316 <in_comment>"*/" { BEGIN(INITIAL); }
317 <in_struct_comment>"*/" { BEGIN(in_struct); }
320 \n { lexer_line.line++; }
322 [^%] /* do nothing */
323 "%"/[^}] /* do nothing */
324 "%}" { BEGIN(in_struct); }
326 error_at_line (&lexer_line,
327 "unterminated %%{; unexpected EOF");
333 <in_struct_comment,in_comment>"*" {
334 error_at_line (&lexer_line,
335 "unterminated comment or string; unexpected EOF");
341 yyerror (const char *s)
343 error_at_line (&lexer_line, s);
347 parse_file (const char *fname)
349 yyin = fopen (fname, "r");
350 lexer_line.file = fname;