]>
Commit | Line | Data |
---|---|---|
1f3233d1 | 1 | /* -*- indented-text -*- */ |
2 | /* Process source files and output type information. | |
1576dec7 | 3 | Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
1f3233d1 | 4 | |
5 | This file is part of GCC. | |
6 | ||
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 | |
10 | version. | |
11 | ||
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 | |
15 | for more details. | |
16 | ||
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 | |
67ce556b | 19 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA |
20 | 02110-1301, USA. */ | |
1f3233d1 | 21 | |
22 | %{ | |
805e22b2 | 23 | #include "bconfig.h" |
805e22b2 | 24 | #include "system.h" |
12a13e7a | 25 | |
26 | #define malloc xmalloc | |
27 | #define realloc xrealloc | |
28 | ||
1f3233d1 | 29 | #include "gengtype.h" |
1e837561 | 30 | |
31 | #define YY_DECL int yylex (const char **yylval) | |
32 | #define yyterminate() return EOF_TOKEN | |
1f3233d1 | 33 | |
1f3233d1 | 34 | struct fileloc lexer_line; |
35 | int lexer_toplevel_done; | |
36 | ||
37 | static void | |
5a2784f8 | 38 | update_lineno (const char *l, size_t len) |
1f3233d1 | 39 | { |
40 | while (len-- > 0) | |
41 | if (*l++ == '\n') | |
42 | lexer_line.line++; | |
43 | } | |
44 | ||
1f3233d1 | 45 | %} |
46 | ||
2f3d127e | 47 | ID [[:alpha:]_][[:alnum:]_]* |
1f3233d1 | 48 | WS [[:space:]]+ |
1e837561 | 49 | HWS [ \t\r\v\f]* |
50 | 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 | |
1f3233d1 | 51 | ITYPE {IWORD}({WS}{IWORD})* |
1e837561 | 52 | EOID [^[:alnum:]_] |
1f3233d1 | 53 | |
f8be92ce | 54 | %x in_struct in_struct_comment in_comment |
1f3233d1 | 55 | %option warn noyywrap nounput nodefault perf-report |
56 | %option 8bit never-interactive | |
57 | %% | |
1e837561 | 58 | /* Do this on entry to yylex(): */ |
59 | *yylval = 0; | |
60 | if (lexer_toplevel_done) | |
61 | { | |
62 | BEGIN(INITIAL); | |
63 | lexer_toplevel_done = 0; | |
64 | } | |
1f3233d1 | 65 | |
1e837561 | 66 | /* Things we look for in skipping mode: */ |
67 | <INITIAL>{ | |
30dfb8d1 | 68 | ^{HWS}typedef/{EOID} { |
1e837561 | 69 | BEGIN(in_struct); |
70 | return TYPEDEF; | |
1f3233d1 | 71 | } |
30dfb8d1 | 72 | ^{HWS}struct/{EOID} { |
1e837561 | 73 | BEGIN(in_struct); |
74 | return STRUCT; | |
1f3233d1 | 75 | } |
30dfb8d1 | 76 | ^{HWS}union/{EOID} { |
1e837561 | 77 | BEGIN(in_struct); |
78 | return UNION; | |
e8d74f41 | 79 | } |
30dfb8d1 | 80 | ^{HWS}extern/{EOID} { |
1e837561 | 81 | BEGIN(in_struct); |
82 | return EXTERN; | |
e8d74f41 | 83 | } |
30dfb8d1 | 84 | ^{HWS}static/{EOID} { |
1f3233d1 | 85 | BEGIN(in_struct); |
1e837561 | 86 | return STATIC; |
1f3233d1 | 87 | } |
88 | ||
30dfb8d1 | 89 | ^{HWS}DEF_VEC_[OP]/{EOID} { |
1f3233d1 | 90 | BEGIN(in_struct); |
1e837561 | 91 | return DEFVEC_OP; |
1f3233d1 | 92 | } |
30dfb8d1 | 93 | ^{HWS}DEF_VEC_I/{EOID} { |
1e837561 | 94 | BEGIN(in_struct); |
95 | return DEFVEC_I; | |
96 | } | |
30dfb8d1 | 97 | ^{HWS}DEF_VEC_ALLOC_[IOP]/{EOID} { |
1e837561 | 98 | BEGIN(in_struct); |
99 | return DEFVEC_ALLOC; | |
696e7773 | 100 | } |
190183c5 | 101 | } |
102 | ||
1f3233d1 | 103 | <in_struct>{ |
104 | ||
105 | "/*" { BEGIN(in_struct_comment); } | |
106 | ||
1f3233d1 | 107 | {WS} { update_lineno (yytext, yyleng); } |
108 | ||
1e837561 | 109 | "const"/{EOID} /* don't care */ |
110 | "GTY"/{EOID} { return GTY_TOKEN; } | |
111 | "VEC"/{EOID} { return VEC_TOKEN; } | |
112 | "union"/{EOID} { return UNION; } | |
113 | "struct"/{EOID} { return STRUCT; } | |
114 | "enum"/{EOID} { return ENUM; } | |
115 | "ptr_alias"/{EOID} { return PTR_ALIAS; } | |
116 | "nested_ptr"/{EOID} { return NESTED_PTR; } | |
1f3233d1 | 117 | [0-9]+ { return NUM; } |
1e837561 | 118 | "param"[0-9]*"_is"/{EOID} { |
119 | *yylval = xmemdup (yytext, yyleng, yyleng+1); | |
c849df63 | 120 | return PARAM_IS; |
121 | } | |
1f3233d1 | 122 | |
1e837561 | 123 | {IWORD}({WS}{IWORD})*/{EOID} | |
1f3233d1 | 124 | "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" { |
125 | size_t len; | |
126 | ||
74863452 | 127 | for (len = yyleng; ISSPACE (yytext[len-1]); len--) |
1f3233d1 | 128 | ; |
129 | ||
1e837561 | 130 | *yylval = xmemdup (yytext, len, len+1); |
1f3233d1 | 131 | update_lineno (yytext, yyleng); |
132 | return SCALAR; | |
133 | } | |
134 | ||
190183c5 | 135 | |
1e837561 | 136 | {ID}/{EOID} { |
137 | *yylval = xmemdup (yytext, yyleng, yyleng+1); | |
1f3233d1 | 138 | return ID; |
139 | } | |
140 | ||
141 | \"([^"\\]|\\.)*\" { | |
1e837561 | 142 | *yylval = xmemdup (yytext+1, yyleng-2, yyleng-1); |
1f3233d1 | 143 | return STRING; |
144 | } | |
1e837561 | 145 | /* This "terminal" avoids having to parse integer constant expressions. */ |
1f3233d1 | 146 | "["[^\[\]]*"]" { |
1e837561 | 147 | *yylval = xmemdup (yytext+1, yyleng-2, yyleng-1); |
1f3233d1 | 148 | return ARRAY; |
149 | } | |
1f3233d1 | 150 | "'"("\\".|[^\\])"'" { |
1e837561 | 151 | *yylval = xmemdup (yytext+1, yyleng-2, yyleng); |
1f3233d1 | 152 | return CHAR; |
153 | } | |
154 | ||
1e837561 | 155 | "..." { return ELLIPSIS; } |
156 | [(){},*:<>;=%|-] { return yytext[0]; } | |
1f3233d1 | 157 | |
1e837561 | 158 | /* ignore pp-directives */ |
159 | ^{HWS}"#"{HWS}[a-z_]+[^\n]*\n {lexer_line.line++;} | |
90a3c0eb | 160 | |
1f3233d1 | 161 | . { |
162 | error_at_line (&lexer_line, "unexpected character `%s'", yytext); | |
163 | } | |
164 | } | |
165 | ||
166 | "/*" { BEGIN(in_comment); } | |
167 | \n { lexer_line.line++; } | |
168 | {ID} | | |
2c2e43fb | 169 | "'"("\\".|[^\\])"'" | |
1f3233d1 | 170 | [^"/\n] /* do nothing */ |
171 | \"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); } | |
172 | "/"/[^*] /* do nothing */ | |
173 | ||
174 | <in_comment,in_struct_comment>{ | |
175 | \n { lexer_line.line++; } | |
176 | [^*\n]{16} | | |
177 | [^*\n] /* do nothing */ | |
178 | "*"/[^/] /* do nothing */ | |
179 | } | |
180 | <in_comment>"*/" { BEGIN(INITIAL); } | |
181 | <in_struct_comment>"*/" { BEGIN(in_struct); } | |
182 | ||
1f3233d1 | 183 | ["/] | |
184 | <in_struct_comment,in_comment>"*" { | |
185 | error_at_line (&lexer_line, | |
186 | "unterminated comment or string; unexpected EOF"); | |
187 | } | |
188 | ||
30dfb8d1 | 189 | ^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */ |
8ca71ef2 | 190 | {WS}"GTY"{WS}?"(" { |
191 | error_at_line (&lexer_line, "stray GTY marker"); | |
192 | } | |
193 | ||
1f3233d1 | 194 | %% |
195 | ||
196 | void | |
1e837561 | 197 | yybegin (const char *fname) |
1f3233d1 | 198 | { |
199 | yyin = fopen (fname, "r"); | |
1f3233d1 | 200 | if (yyin == NULL) |
201 | { | |
202 | perror (fname); | |
203 | exit (1); | |
204 | } | |
1e837561 | 205 | lexer_line.file = fname; |
206 | lexer_line.line = 1; | |
207 | } | |
208 | ||
209 | void | |
210 | yyend (void) | |
211 | { | |
1f3233d1 | 212 | fclose (yyin); |
213 | } |