Fix bootstrap/PR63632
[official-gcc.git] / gcc / gengtype-lex.l
blob5e12885c63f063787eddc4c46257791d15012d9a
1 /* -*- indented-text -*- */
2 /* Process source files and output type information.
3    Copyright (C) 2002-2014 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 3, or (at your option) any later
10 version.
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.
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/>.  */
21 %option noinput
24 #ifdef GENERATOR_FILE
25 #include "bconfig.h"
26 #else
27 #include "config.h"
28 #endif
29 #include "system.h"
31 #define malloc xmalloc
32 #define realloc xrealloc
34 #include "gengtype.h"
36 #define YY_DECL int yylex (const char **yylval)
37 #define yyterminate() return EOF_TOKEN
39 struct fileloc lexer_line;
40 int lexer_toplevel_done;
42 static void 
43 update_lineno (const char *l, size_t len)
45   while (len-- > 0)
46     if (*l++ == '\n')
47       lexer_line.line++;
52 CID     [[:alpha:]_][[:alnum:]_]*
53 WS      [[:space:]]+
54 HWS     [ \t\r\v\f]*
55 IWORD   short|long|(un)?signed|char|int|HOST_WIDE_INT|uint64_t|int64_t|bool|size_t|BOOL_BITFIELD|CPPCHAR_SIGNED_T|ino_t|dev_t|HARD_REG_SET
56 ITYPE   {IWORD}({WS}{IWORD})*
57     /* Include '::' in identifiers to capture C++ scope qualifiers.  */
58 ID      {CID}({HWS}::{HWS}{CID})*
59 EOID    [^[:alnum:]_]
60 CXX_KEYWORD inline|public:|private:|protected:|template|operator|friend|static
62 %x in_struct in_struct_comment in_comment
63 %option warn noyywrap nounput nodefault perf-report
64 %option 8bit never-interactive
66   /* Do this on entry to yylex():  */
67   *yylval = 0;
68   if (lexer_toplevel_done)
69     {
70       BEGIN(INITIAL);
71       lexer_toplevel_done = 0;
72     }
74   /* Things we look for in skipping mode: */
75 <INITIAL>{
76 ^{HWS}typedef/{EOID} {
77   BEGIN(in_struct);
78   return TYPEDEF;
80 ^{HWS}struct/{EOID} {
81   BEGIN(in_struct);
82   return STRUCT;
84 ^{HWS}union/{EOID} {
85   BEGIN(in_struct);
86   return UNION;
88 ^{HWS}class/{EOID} {
89   BEGIN(in_struct);
90   return STRUCT;
92 ^{HWS}extern/{EOID} {
93   BEGIN(in_struct);
94   return EXTERN;
96 ^{HWS}static/{EOID} {
97   BEGIN(in_struct);
98   return STATIC;
102     /* Parsing inside a struct, union or class declaration.  */
103 <in_struct>{
104 "/*"                            { BEGIN(in_struct_comment); }
105 "//".*\n                        { lexer_line.line++; }
107 {WS}                            { update_lineno (yytext, yyleng); }
108 \\\n                            { lexer_line.line++; }
110 "const"/{EOID}                  /* don't care */
111 {CXX_KEYWORD}/{EOID}                    |
112 "~"                                     |
113 "^"                                     |
114 "&"                                     {
115     *yylval = XDUPVAR (const char, yytext, yyleng, yyleng + 1);
116     return IGNORABLE_CXX_KEYWORD;
118 "GTY"/{EOID}                    { return GTY_TOKEN; }
119 "union"/{EOID}                  { return UNION; }
120 "struct"/{EOID}                 { return STRUCT; }
121 "class"/{EOID}                  { return STRUCT; }
122 "typedef"/{EOID}                { return TYPEDEF; }
123 "enum"/{EOID}                   { return ENUM; }
124 "ptr_alias"/{EOID}              { return PTR_ALIAS; }
125 "nested_ptr"/{EOID}             { return NESTED_PTR; }
126 "user"/{EOID}                   { return USER_GTY; }
127 [0-9]+                          { return NUM; }
128 "param"[0-9]*"_is"/{EOID}               {
129   *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
130   return PARAM_IS;
133 {IWORD}({WS}{IWORD})*/{EOID}            |
134 "ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")"        {
135   size_t len;
137   for (len = yyleng; ISSPACE (yytext[len-1]); len--)
138     ;
140   *yylval = XDUPVAR (const char, yytext, len, len+1);
141   update_lineno (yytext, yyleng);
142   return SCALAR;
145 {ID}/{EOID}                     {
146   *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
147   return ID;
150 \"([^"\\]|\\.)*\"               {
151   *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
152   return STRING;
154   /* This "terminal" avoids having to parse integer constant expressions.  */
155 "["[^\[\]]*"]"                  {
156   *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
157   return ARRAY;
159 "'"("\\".|[^\\])"'"             {
160   *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng);
161   return CHAR;
164 "..."                           { return ELLIPSIS; }
165 [(){},*:<>;=%|+\!\?\.-]         { return yytext[0]; }
167    /* ignore pp-directives */
168 ^{HWS}"#"{HWS}[a-z_]+[^\n]*\n   {lexer_line.line++;}
170 .                               {
171   error_at_line (&lexer_line, "unexpected character `%s'", yytext);
175 "/*"                    { BEGIN(in_comment); }
176 "//".*\n                { lexer_line.line++; }
177 \n                      { lexer_line.line++; }
178 {ID}                    |
179 "'"("\\".|[^\\])"'"     |
180 [^"/\n]                 /* do nothing */
181 \"([^"\\]|\\.|\\\n)*\"  { update_lineno (yytext, yyleng); }
182 "/"/[^*]                /* do nothing */
184 <in_comment,in_struct_comment>{
185 \n              { lexer_line.line++; }
186 [^*\n]{16}      |
187 [^*\n]          /* do nothing */
188 "*"/[^/]        /* do nothing */
191 <in_comment>"*/"        { BEGIN(INITIAL); } 
192 <in_struct_comment>"*/" { BEGIN(in_struct); }
194 ["/]                    |
195 <in_struct_comment,in_comment>"*"       {
196   error_at_line (&lexer_line, 
197                  "unterminated comment or string; unexpected EOF");
200 ^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */
204 void
205 yybegin (const char *fname)
207   yyin = fopen (fname, "r");
208   if (yyin == NULL)
209     {
210       perror (fname);
211       exit (1);
212     }
213   lexer_line.file = input_file_by_name (fname);
214   lexer_line.line = 1;
217 void
218 yyend (void)
220   fclose (yyin);