OSDN Git Service

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