1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3 Copyright (C) 2002, 2003, 2004 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"
33 static void update_lineno (const char *l, size_t len);
35 struct fileloc lexer_line;
36 int lexer_toplevel_done;
39 update_lineno (const char *l, size_t len)
48 ID [[:alpha:]_][[:alnum:]_]*
50 IWORD short|long|(un)?signed|char|int|HOST_WIDE_INT|HOST_WIDEST_INT|bool|size_t|BOOL_BITFIELD
51 ITYPE {IWORD}({WS}{IWORD})*
53 %x in_struct in_struct_comment in_comment in_yacc_escape
54 %option warn noyywrap nounput nodefault perf-report
55 %option 8bit never-interactive
58 [^[:alnum:]_]typedef{WS}(struct|union){WS}{ID}{WS}?[*[:space:]]{WS}?{ID}{WS}?";" {
67 tagstart = yytext + strlen (" typedef ");
68 while (ISSPACE (*tagstart))
70 union_p = tagstart[0] == 'u';
71 tagstart += strlen ("union ");
72 while (ISSPACE (*tagstart))
74 for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
76 for (namestart = tagstart + taglen;
77 ! ISIDNUM (*namestart);
79 if (*namestart == '*')
81 for (namelen = 1; ISIDNUM (namestart[namelen]); namelen++)
83 t = find_structure (xmemdup (tagstart, taglen, taglen+1), union_p);
85 t = create_pointer (t);
86 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
87 update_lineno (yytext, yyleng);
90 [^[:alnum:]_]typedef{WS}{ITYPE}{WS}{ID}{WS}?";" {
98 for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
100 for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
102 namestart -= namelen - 1;
103 for (typestart = yytext + strlen (" typedef ");
107 for (typelen = namestart - typestart;
108 ISSPACE(typestart[typelen-1]);
112 t = create_scalar_type (typestart, typelen);
113 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
114 update_lineno (yytext, yyleng);
117 [^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}PARAMS {
122 for (namestart = yytext + yyleng - 7; ISSPACE (*namestart); namestart--)
124 for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
126 namestart -= namelen - 1;
128 t = create_scalar_type ("function type", sizeof ("function type")-1);
129 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
130 update_lineno (yytext, yyleng);
133 [^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}"(" {
138 for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
140 for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
142 namestart -= namelen - 1;
144 t = create_scalar_type ("function type", sizeof ("function type")-1);
145 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
146 update_lineno (yytext, yyleng);
149 [^[:alnum:]_]typedef{WS}{ID}{WS}?"*"?{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?PARAMS {
154 for (namestart = yytext + yyleng - 7; !ISIDNUM (*namestart); namestart--)
156 for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
158 namestart -= namelen - 1;
160 t = create_scalar_type ("function type", sizeof ("function type")-1);
161 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
162 update_lineno (yytext, yyleng);
165 [^[:alnum:]_]typedef{WS}{ID}{WS}?"*"?{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?"(" {
170 for (namestart = yytext + yyleng - 2; !ISIDNUM (*namestart); namestart--)
172 for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
174 namestart -= namelen - 1;
176 t = create_scalar_type ("function type", sizeof ("function type")-1);
177 do_typedef (xmemdup (namestart, namelen, namelen+1), t, &lexer_line);
178 update_lineno (yytext, yyleng);
181 [^[:alnum:]_](typedef{WS})?(struct|union){WS}{ID}{WS}/"GTY" {
187 typedef_p = yytext[1] == 't';
189 for (tagstart = yytext + strlen (" typedef ");
194 tagstart = yytext + 1;
196 union_p = tagstart[0] == 'u';
197 tagstart += strlen ("union ");
198 while (ISSPACE (*tagstart))
200 for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
203 yylval.t = find_structure (xmemdup (tagstart, taglen, taglen + 1), union_p);
205 update_lineno (yytext, yyleng);
206 return typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT;
209 [^[:alnum:]_](extern|static){WS}/"GTY" {
211 update_lineno (yytext, yyleng);
212 return ENT_EXTERNSTATIC;
215 ^"%union"{WS}"{"{WS}/"GTY" {
217 update_lineno (yytext, yyleng);
218 return ENT_YACCUNION;
223 "/*" { BEGIN(in_struct_comment); }
225 ^"%{" { BEGIN(in_yacc_escape); }
227 ^"@@".* /* Used for c-parse.in C/ObjC demarcation. */
229 {WS} { update_lineno (yytext, yyleng); }
231 "const"/[^[:alnum:]_] /* don't care */
233 "GTY"/[^[:alnum:]_] { return GTY_TOKEN; }
234 "union"/[^[:alnum:]_] { return UNION; }
235 "struct"/[^[:alnum:]_] { return STRUCT; }
236 "enum"/[^[:alnum:]_] { return ENUM; }
237 "ptr_alias"/[^[:alnum:]_] { return ALIAS; }
238 "nested_ptr"/[^[:alnum:]_] { return NESTED_PTR; }
239 [0-9]+ { return NUM; }
240 "param"[0-9]*"_is"/[^[:alnum:]_] {
241 yylval.s = xmemdup (yytext, yyleng, yyleng+1);
245 {IWORD}({WS}{IWORD})*/[^[:alnum:]_] |
246 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
249 for (len = yyleng; ISSPACE (yytext[len-1]); len--)
252 yylval.t = create_scalar_type (yytext, len);
253 update_lineno (yytext, yyleng);
258 yylval.s = xmemdup (yytext, yyleng, yyleng+1);
263 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng-1);
267 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng-1);
271 yylval.s = xmemdup (yytext+1, yyleng-1, yyleng);
274 "'"("\\".|[^\\])"'" {
275 yylval.s = xmemdup (yytext+1, yyleng-2, yyleng);
279 [(){},*:<>] { return yytext[0]; }
282 if (lexer_toplevel_done)
285 lexer_toplevel_done = 0;
292 return PERCENTPERCENT;
296 error_at_line (&lexer_line, "unexpected character `%s'", yytext);
300 "/*" { BEGIN(in_comment); }
301 \n { lexer_line.line++; }
303 "'"("\\".|[^\\])"'" |
304 [^"/\n] /* do nothing */
305 \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
306 "/"/[^*] /* do nothing */
308 <in_comment,in_struct_comment>{
309 \n { lexer_line.line++; }
311 [^*\n] /* do nothing */
312 "*"/[^/] /* do nothing */
314 <in_comment>"*/" { BEGIN(INITIAL); }
315 <in_struct_comment>"*/" { BEGIN(in_struct); }
318 \n { lexer_line.line++; }
320 [^%] /* do nothing */
321 "%"/[^}] /* do nothing */
322 "%}" { BEGIN(in_struct); }
324 error_at_line (&lexer_line,
325 "unterminated %%{; unexpected EOF");
331 <in_struct_comment,in_comment>"*" {
332 error_at_line (&lexer_line,
333 "unterminated comment or string; unexpected EOF");
336 ^"#define"{WS}"GTY(" /* do nothing */
338 error_at_line (&lexer_line, "stray GTY marker");
344 yyerror (const char *s)
346 error_at_line (&lexer_line, s);
350 parse_file (const char *fname)
352 yyin = fopen (fname, "r");
353 lexer_line.file = fname;