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
23 #define malloc xmalloc
24 #define realloc xrealloc
30 #include "gengtype-yacc.h"
32 static void update_lineno PARAMS ((const char *l, size_t len));
34 struct fileloc lexer_line;
35 int lexer_toplevel_done;
38 update_lineno (l, len)
47 #define IDchar(c) (isalnum(c) || (c) == '_')
50 ID [[:alpha:]][[:alnum:]_]*
52 IWORD short|long|(un)?signed|char|int|HOST_WIDE_INT|bool|size_t
53 ITYPE {IWORD}({WS}{IWORD})*
55 %x in_struct in_struct_comment in_comment in_yacc_escape
56 %option warn noyywrap nounput nodefault perf-report
57 %option 8bit never-interactive
60 [^[:alnum:]_]typedef{WS}(struct|union){WS}{ID}{WS}?[*[:space:]]{WS}?{ID}{WS}?";" {
69 tagstart = yytext + strlen (" typedef ");
70 while (isspace (*tagstart))
72 union_p = tagstart[0] == 'u';
73 tagstart += strlen ("union ");
74 while (isspace (*tagstart))
76 for (taglen = 1; IDchar (tagstart[taglen]); taglen++)
78 for (namestart = tagstart + taglen;
79 ! IDchar (*namestart);
81 if (*namestart == '*')
83 for (namelen = 1; IDchar (namestart[namelen]); namelen++)
85 t = find_structure (xmemdup (tagstart, taglen, taglen+1), union_p);
87 t = create_pointer (t);
88 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
89 update_lineno (yytext, yyleng);
92 [^[:alnum:]_]typedef{WS}{ITYPE}{WS}{ID}{WS}?";" {
100 for (namestart = yytext + yyleng - 2; isspace (*namestart); namestart--)
102 for (namelen = 1; !isspace (namestart[-namelen]); namelen++)
104 namestart -= namelen - 1;
105 for (typestart = yytext + strlen (" typedef ");
109 for (typelen = namestart - typestart;
110 isspace(typestart[typelen-1]);
114 t = create_scalar_type (typestart, typelen);
115 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
116 update_lineno (yytext, yyleng);
119 [^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}PARAMS {
124 for (namestart = yytext + yyleng - 7; isspace (*namestart); namestart--)
126 for (namelen = 1; !isspace (namestart[-namelen]); namelen++)
128 namestart -= namelen - 1;
130 t = create_scalar_type ("function type", sizeof ("function type")-1);
131 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
132 update_lineno (yytext, yyleng);
134 [^[:alnum:]_]typedef{WS}{ID}{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?PARAMS {
139 for (namestart = yytext + yyleng - 7; !IDchar (*namestart); namestart--)
141 for (namelen = 1; IDchar (namestart[-namelen]); namelen++)
143 namestart -= namelen - 1;
145 t = create_scalar_type ("function type", sizeof ("function type")-1);
146 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
147 update_lineno (yytext, yyleng);
150 [^[:alnum:]_](typedef{WS})?(struct|union){WS}{ID}{WS}/"GTY" {
156 typedef_p = yytext[1] == 't';
158 for (tagstart = yytext + strlen (" typedef ");
163 tagstart = yytext + 1;
165 union_p = tagstart[0] == 'u';
166 tagstart += strlen ("union ");
167 while (isspace (*tagstart))
169 for (taglen = 1; IDchar (tagstart[taglen]); taglen++)
172 yylval.t = find_structure (xmemdup (tagstart, taglen, taglen + 1), union_p);
174 update_lineno (yytext, yyleng);
175 return typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT;
178 [^[:alnum:]_](extern|static){WS}/"GTY" {
180 update_lineno (yytext, yyleng);
181 return ENT_EXTERNSTATIC;
184 ^"%union"{WS}"{"{WS}/"GTY" {
186 update_lineno (yytext, yyleng);
187 return ENT_YACCUNION;
192 "/*" { BEGIN(in_struct_comment); }
194 ^"%{" { BEGIN(in_yacc_escape); }
196 {WS} { update_lineno (yytext, yyleng); }
198 "const"/[^[:alnum:]_] /* don't care */
200 "GTY"/[^[:alnum:]_] { return GTY_TOKEN; }
201 "union"/[^[:alnum:]_] { return UNION; }
202 "struct"/[^[:alnum:]_] { return STRUCT; }
203 "enum"/[^[:alnum:]_] { return ENUM; }
204 "ptr_alias"/[^[:alnum:]_] { return ALIAS; }
205 "param_is"/[^[:alnum:]_] { return PARAM_IS; }
206 [0-9]+ { return NUM; }
208 {IWORD}({WS}{IWORD})*/[^[:alnum:]_] |
209 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
212 for (len = yyleng; isspace (yytext[len-1]); len--)
215 yylval.t = create_scalar_type (yytext, len);
216 update_lineno (yytext, yyleng);
221 yylval.s = xmemdup (yytext, yyleng, yyleng+1);
226 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng-1);
230 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng-1);
234 yylval.s = xmemdup (yytext+1, yyleng-1, yyleng);
237 "'"("\\".|[^\\])"'" {
238 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng);
242 [(){},*:<>] { return yytext[0]; }
245 if (lexer_toplevel_done)
248 lexer_toplevel_done = 0;
255 return PERCENTPERCENT;
259 error_at_line (&lexer_line, "unexpected character `%s'", yytext);
263 "/*" { BEGIN(in_comment); }
264 \n { lexer_line.line++; }
266 [^"/\n] /* do nothing */
267 \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
268 "/"/[^*] /* do nothing */
270 <in_comment,in_struct_comment>{
271 \n { lexer_line.line++; }
273 [^*\n] /* do nothing */
274 "*"/[^/] /* do nothing */
276 <in_comment>"*/" { BEGIN(INITIAL); }
277 <in_struct_comment>"*/" { BEGIN(in_struct); }
280 \n { lexer_line.line++; }
282 [^%] /* do nothing */
283 "%"/[^}] /* do nothing */
284 "%}" { BEGIN(in_struct); }
286 error_at_line (&lexer_line,
287 "unterminated %{; unexpected EOF");
293 <in_struct_comment,in_comment>"*" {
294 error_at_line (&lexer_line,
295 "unterminated comment or string; unexpected EOF");
304 error_at_line (&lexer_line, s);
311 yyin = fopen (fname, "r");
312 lexer_line.file = fname;