OSDN Git Service

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