1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3 Copyright (C) 2002 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 PARAMS ((const char *l, size_t len));
38 struct fileloc lexer_line;
39 int lexer_toplevel_done;
42 update_lineno (l, len)
53 ID [[:alpha:]_][[:alnum:]_]*
55 IWORD short|long|(un)?signed|char|int|HOST_WIDE_INT|bool|size_t|CHAR_BITFIELD
56 ITYPE {IWORD}({WS}{IWORD})*
58 %x in_struct in_struct_comment in_comment in_yacc_escape
59 %option warn noyywrap nounput nodefault perf-report
60 %option 8bit never-interactive
63 [^[:alnum:]_]typedef{WS}(struct|union){WS}{ID}{WS}?[*[:space:]]{WS}?{ID}{WS}?";" {
72 tagstart = yytext + strlen (" typedef ");
73 while (ISSPACE (*tagstart))
75 union_p = tagstart[0] == 'u';
76 tagstart += strlen ("union ");
77 while (ISSPACE (*tagstart))
79 for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
81 for (namestart = tagstart + taglen;
82 ! ISIDNUM (*namestart);
84 if (*namestart == '*')
86 for (namelen = 1; ISIDNUM (namestart[namelen]); namelen++)
88 t = find_structure (xmemdup (tagstart, taglen, taglen+1), union_p);
90 t = create_pointer (t);
91 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
92 update_lineno (yytext, yyleng);
95 [^[:alnum:]_]typedef{WS}{ITYPE}{WS}{ID}{WS}?";" {
103 for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
105 for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
107 namestart -= namelen - 1;
108 for (typestart = yytext + strlen (" typedef ");
112 for (typelen = namestart - typestart;
113 ISSPACE(typestart[typelen-1]);
117 t = create_scalar_type (typestart, typelen);
118 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
119 update_lineno (yytext, yyleng);
122 [^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}PARAMS {
127 for (namestart = yytext + yyleng - 7; ISSPACE (*namestart); namestart--)
129 for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
131 namestart -= namelen - 1;
133 t = create_scalar_type ("function type", sizeof ("function type")-1);
134 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
135 update_lineno (yytext, yyleng);
137 [^[:alnum:]_]typedef{WS}{ID}{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?PARAMS {
142 for (namestart = yytext + yyleng - 7; !ISIDNUM (*namestart); namestart--)
144 for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
146 namestart -= namelen - 1;
148 t = create_scalar_type ("function type", sizeof ("function type")-1);
149 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
150 update_lineno (yytext, yyleng);
153 [^[:alnum:]_](typedef{WS})?(struct|union){WS}{ID}{WS}/"GTY" {
159 typedef_p = yytext[1] == 't';
161 for (tagstart = yytext + strlen (" typedef ");
166 tagstart = yytext + 1;
168 union_p = tagstart[0] == 'u';
169 tagstart += strlen ("union ");
170 while (ISSPACE (*tagstart))
172 for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
175 yylval.t = find_structure (xmemdup (tagstart, taglen, taglen + 1), union_p);
177 update_lineno (yytext, yyleng);
178 return typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT;
181 [^[:alnum:]_](extern|static){WS}/"GTY" {
183 update_lineno (yytext, yyleng);
184 return ENT_EXTERNSTATIC;
187 ^"%union"{WS}"{"{WS}/"GTY" {
189 update_lineno (yytext, yyleng);
190 return ENT_YACCUNION;
195 "/*" { BEGIN(in_struct_comment); }
197 ^"%{" { BEGIN(in_yacc_escape); }
199 {WS} { update_lineno (yytext, yyleng); }
201 "const"/[^[:alnum:]_] /* don't care */
203 "GTY"/[^[:alnum:]_] { return GTY_TOKEN; }
204 "union"/[^[:alnum:]_] { return UNION; }
205 "struct"/[^[:alnum:]_] { return STRUCT; }
206 "enum"/[^[:alnum:]_] { return ENUM; }
207 "ptr_alias"/[^[:alnum:]_] { return ALIAS; }
208 [0-9]+ { return NUM; }
209 "param"[0-9]*"_is"/[^[:alnum:]_] {
210 yylval.s = xmemdup (yytext, yyleng, yyleng+1);
214 {IWORD}({WS}{IWORD})*/[^[:alnum:]_] |
215 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
218 for (len = yyleng; ISSPACE (yytext[len-1]); len--)
221 yylval.t = create_scalar_type (yytext, len);
222 update_lineno (yytext, yyleng);
227 yylval.s = xmemdup (yytext, yyleng, yyleng+1);
232 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng-1);
236 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng-1);
240 yylval.s = xmemdup (yytext+1, yyleng-1, yyleng);
243 "'"("\\".|[^\\])"'" {
244 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng);
248 [(){},*:<>] { return yytext[0]; }
251 if (lexer_toplevel_done)
254 lexer_toplevel_done = 0;
261 return PERCENTPERCENT;
265 error_at_line (&lexer_line, "unexpected character `%s'", yytext);
269 "/*" { BEGIN(in_comment); }
270 \n { lexer_line.line++; }
272 "'"("\\".|[^\\])"'" |
273 [^"/\n] /* do nothing */
274 \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
275 "/"/[^*] /* do nothing */
277 <in_comment,in_struct_comment>{
278 \n { lexer_line.line++; }
280 [^*\n] /* do nothing */
281 "*"/[^/] /* do nothing */
283 <in_comment>"*/" { BEGIN(INITIAL); }
284 <in_struct_comment>"*/" { BEGIN(in_struct); }
287 \n { lexer_line.line++; }
289 [^%] /* do nothing */
290 "%"/[^}] /* do nothing */
291 "%}" { BEGIN(in_struct); }
293 error_at_line (&lexer_line,
294 "unterminated %%{; unexpected EOF");
300 <in_struct_comment,in_comment>"*" {
301 error_at_line (&lexer_line,
302 "unterminated comment or string; unexpected EOF");
311 error_at_line (&lexer_line, s);
318 yyin = fopen (fname, "r");
319 lexer_line.file = fname;