OSDN Git Service

gcc/ChangeLog
[pf3gnuchains/gcc-fork.git] / gcc / gengtype-lex.l
1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3    Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 %option noinput
23
24 %{
25 #include "bconfig.h"
26 #include "system.h"
27
28 #define malloc xmalloc
29 #define realloc xrealloc
30
31 #include "gengtype.h"
32
33 #define YY_DECL int yylex (const char **yylval)
34 #define yyterminate() return EOF_TOKEN
35
36 struct fileloc lexer_line;
37 int lexer_toplevel_done;
38
39 static void 
40 update_lineno (const char *l, size_t len)
41 {
42   while (len-- > 0)
43     if (*l++ == '\n')
44       lexer_line.line++;
45 }
46
47 %}
48
49 ID      [[:alpha:]_][[:alnum:]_]*
50 WS      [[:space:]]+
51 HWS     [ \t\r\v\f]*
52 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
53 ITYPE   {IWORD}({WS}{IWORD})*
54 EOID    [^[:alnum:]_]
55
56 %x in_struct in_struct_comment in_comment
57 %option warn noyywrap nounput nodefault perf-report
58 %option 8bit never-interactive
59 %%
60   /* Do this on entry to yylex():  */
61   *yylval = 0;
62   if (lexer_toplevel_done)
63     {
64       BEGIN(INITIAL);
65       lexer_toplevel_done = 0;
66     }
67
68   /* Things we look for in skipping mode: */
69 <INITIAL>{
70 ^{HWS}typedef/{EOID} {
71   BEGIN(in_struct);
72   return TYPEDEF;
73 }
74 ^{HWS}struct/{EOID} {
75   BEGIN(in_struct);
76   return STRUCT;
77 }
78 ^{HWS}union/{EOID} {
79   BEGIN(in_struct);
80   return UNION;
81 }
82 ^{HWS}extern/{EOID} {
83   BEGIN(in_struct);
84   return EXTERN;
85 }
86 ^{HWS}static/{EOID} {
87   BEGIN(in_struct);
88   return STATIC;
89 }
90
91 ^{HWS}DEF_VEC_[OP]/{EOID} {
92   BEGIN(in_struct);
93   return DEFVEC_OP;
94 }
95 ^{HWS}DEF_VEC_I/{EOID} {
96   BEGIN(in_struct);
97   return DEFVEC_I;
98 }
99 ^{HWS}DEF_VEC_ALLOC_[IOP]/{EOID} {
100   BEGIN(in_struct);
101   return DEFVEC_ALLOC;
102 }
103 }
104
105 <in_struct>{
106
107 "/*"                            { BEGIN(in_struct_comment); }
108
109 {WS}                            { update_lineno (yytext, yyleng); }
110 \\\n                            { lexer_line.line++; }
111
112 "const"/{EOID}                  /* don't care */
113 "GTY"/{EOID}                    { return GTY_TOKEN; }
114 "VEC"/{EOID}                    { return VEC_TOKEN; }
115 "union"/{EOID}                  { return UNION; }
116 "struct"/{EOID}                 { return STRUCT; }
117 "enum"/{EOID}                   { return ENUM; }
118 "ptr_alias"/{EOID}              { return PTR_ALIAS; }
119 "nested_ptr"/{EOID}             { return NESTED_PTR; }
120 [0-9]+                          { return NUM; }
121 "param"[0-9]*"_is"/{EOID}               {
122   *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
123   return PARAM_IS;
124 }
125
126 {IWORD}({WS}{IWORD})*/{EOID}            |
127 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")"        {
128   size_t len;
129
130   for (len = yyleng; ISSPACE (yytext[len-1]); len--)
131     ;
132
133   *yylval = XDUPVAR (const char, yytext, len, len+1);
134   update_lineno (yytext, yyleng);
135   return SCALAR;
136 }
137
138
139 {ID}/{EOID}                     {
140   *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
141   return ID;
142 }
143
144 \"([^"\\]|\\.)*\"               {
145   *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
146   return STRING;
147 }
148   /* This "terminal" avoids having to parse integer constant expressions.  */
149 "["[^\[\]]*"]"                  {
150   *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
151   return ARRAY;
152 }
153 "'"("\\".|[^\\])"'"             {
154   *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng);
155   return CHAR;
156 }
157
158 "..."                           { return ELLIPSIS; }
159 [(){},*:<>;=%|-]                { return yytext[0]; }
160
161    /* ignore pp-directives */
162 ^{HWS}"#"{HWS}[a-z_]+[^\n]*\n   {lexer_line.line++;}
163
164 .                               {
165   error_at_line (&lexer_line, "unexpected character `%s'", yytext);
166 }
167 }
168
169 "/*"                    { BEGIN(in_comment); }
170 \n                      { lexer_line.line++; }
171 {ID}                    |
172 "'"("\\".|[^\\])"'"     |
173 [^"/\n]                 /* do nothing */
174 \"([^"\\]|\\.|\\\n)*\"  { update_lineno (yytext, yyleng); }
175 "/"/[^*]                /* do nothing */
176
177 <in_comment,in_struct_comment>{
178 \n              { lexer_line.line++; }
179 [^*\n]{16}      |
180 [^*\n]          /* do nothing */
181 "*"/[^/]        /* do nothing */
182 }
183 <in_comment>"*/"        { BEGIN(INITIAL); } 
184 <in_struct_comment>"*/" { BEGIN(in_struct); }
185
186 ["/]                    |
187 <in_struct_comment,in_comment>"*"       {
188   error_at_line (&lexer_line, 
189                  "unterminated comment or string; unexpected EOF");
190 }
191
192 ^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */
193
194 %%
195
196 void
197 yybegin (const char *fname)
198 {
199   yyin = fopen (fname, "r");
200   if (yyin == NULL)
201     {
202       perror (fname);
203       exit (1);
204     }
205   lexer_line.file = fname;
206   lexer_line.line = 1;
207 }
208
209 void
210 yyend (void)
211 {
212   fclose (yyin);
213 }