]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gengtype-lex.l
Update copyright years in gcc/
[thirdparty/gcc.git] / gcc / gengtype-lex.l
CommitLineData
e2500fed
GK
1/* -*- indented-text -*- */
2/* Process source files and output type information.
23a5b65a 3 Copyright (C) 2002-2014 Free Software Foundation, Inc.
e2500fed
GK
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
e2500fed
GK
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
e2500fed 20
e81f2ecf
BE
21%option noinput
22
e2500fed 23%{
f142b5bc 24#ifdef GENERATOR_FILE
4977bab6 25#include "bconfig.h"
f142b5bc
RG
26#else
27#include "config.h"
28#endif
4977bab6 29#include "system.h"
4da78214
JDA
30
31#define malloc xmalloc
32#define realloc xrealloc
33
e2500fed 34#include "gengtype.h"
01d419ae
ZW
35
36#define YY_DECL int yylex (const char **yylval)
37#define yyterminate() return EOF_TOKEN
e2500fed 38
e2500fed
GK
39struct fileloc lexer_line;
40int lexer_toplevel_done;
41
42static void
f55ade6e 43update_lineno (const char *l, size_t len)
e2500fed
GK
44{
45 while (len-- > 0)
46 if (*l++ == '\n')
47 lexer_line.line++;
48}
49
e2500fed
GK
50%}
51
313465bb 52CID [[:alpha:]_][[:alnum:]_]*
e2500fed 53WS [[:space:]]+
01d419ae 54HWS [ \t\r\v\f]*
b748fbd6 55IWORD short|long|(un)?signed|char|int|HOST_WIDE_INT|HOST_WIDEST_INT|bool|size_t|BOOL_BITFIELD|CPPCHAR_SIGNED_T|ino_t|dev_t|HARD_REG_SET
e2500fed 56ITYPE {IWORD}({WS}{IWORD})*
313465bb
DN
57 /* Include '::' in identifiers to capture C++ scope qualifiers. */
58ID {CID}({HWS}::{HWS}{CID})*
01d419ae 59EOID [^[:alnum:]_]
313465bb 60CXX_KEYWORD inline|public:|private:|protected:|template|operator|friend
e2500fed 61
cff4720f 62%x in_struct in_struct_comment in_comment
e2500fed
GK
63%option warn noyywrap nounput nodefault perf-report
64%option 8bit never-interactive
65%%
01d419ae
ZW
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 }
e2500fed 73
01d419ae
ZW
74 /* Things we look for in skipping mode: */
75<INITIAL>{
36f568c3 76^{HWS}typedef/{EOID} {
01d419ae
ZW
77 BEGIN(in_struct);
78 return TYPEDEF;
e2500fed 79}
36f568c3 80^{HWS}struct/{EOID} {
01d419ae
ZW
81 BEGIN(in_struct);
82 return STRUCT;
e2500fed 83}
36f568c3 84^{HWS}union/{EOID} {
01d419ae
ZW
85 BEGIN(in_struct);
86 return UNION;
790ca664 87}
313465bb
DN
88^{HWS}class/{EOID} {
89 BEGIN(in_struct);
90 return STRUCT;
91}
36f568c3 92^{HWS}extern/{EOID} {
01d419ae
ZW
93 BEGIN(in_struct);
94 return EXTERN;
790ca664 95}
36f568c3 96^{HWS}static/{EOID} {
e2500fed 97 BEGIN(in_struct);
01d419ae 98 return STATIC;
e2500fed 99}
ada55151
NS
100}
101
313465bb 102 /* Parsing inside a struct, union or class declaration. */
e2500fed 103<in_struct>{
e2500fed 104"/*" { BEGIN(in_struct_comment); }
313465bb 105"//".*\n { lexer_line.line++; }
e2500fed 106
e2500fed 107{WS} { update_lineno (yytext, yyleng); }
049e9ad9 108\\\n { lexer_line.line++; }
e2500fed 109
01d419ae 110"const"/{EOID} /* don't care */
313465bb
DN
111{CXX_KEYWORD}/{EOID} |
112"~" |
113"&" {
114 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng + 1);
115 return IGNORABLE_CXX_KEYWORD;
116}
01d419ae 117"GTY"/{EOID} { return GTY_TOKEN; }
01d419ae
ZW
118"union"/{EOID} { return UNION; }
119"struct"/{EOID} { return STRUCT; }
313465bb
DN
120"class"/{EOID} { return STRUCT; }
121"typedef"/{EOID} { return TYPEDEF; }
01d419ae
ZW
122"enum"/{EOID} { return ENUM; }
123"ptr_alias"/{EOID} { return PTR_ALIAS; }
124"nested_ptr"/{EOID} { return NESTED_PTR; }
0823efed 125"user"/{EOID} { return USER_GTY; }
e2500fed 126[0-9]+ { return NUM; }
01d419ae 127"param"[0-9]*"_is"/{EOID} {
7cbb2a85 128 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
36a5eadd
GK
129 return PARAM_IS;
130}
e2500fed 131
01d419ae 132{IWORD}({WS}{IWORD})*/{EOID} |
e2500fed
GK
133"ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
134 size_t len;
135
1f8e4682 136 for (len = yyleng; ISSPACE (yytext[len-1]); len--)
e2500fed
GK
137 ;
138
7cbb2a85 139 *yylval = XDUPVAR (const char, yytext, len, len+1);
e2500fed
GK
140 update_lineno (yytext, yyleng);
141 return SCALAR;
142}
143
01d419ae 144{ID}/{EOID} {
7cbb2a85 145 *yylval = XDUPVAR (const char, yytext, yyleng, yyleng+1);
e2500fed
GK
146 return ID;
147}
148
149\"([^"\\]|\\.)*\" {
7cbb2a85 150 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
e2500fed
GK
151 return STRING;
152}
01d419ae 153 /* This "terminal" avoids having to parse integer constant expressions. */
e2500fed 154"["[^\[\]]*"]" {
7cbb2a85 155 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng-1);
e2500fed
GK
156 return ARRAY;
157}
e2500fed 158"'"("\\".|[^\\])"'" {
7cbb2a85 159 *yylval = XDUPVAR (const char, yytext+1, yyleng-2, yyleng);
e2500fed
GK
160 return CHAR;
161}
162
01d419ae 163"..." { return ELLIPSIS; }
9771b263 164[(){},*:<>;=%|+\!\?\.-] { return yytext[0]; }
e2500fed 165
01d419ae
ZW
166 /* ignore pp-directives */
167^{HWS}"#"{HWS}[a-z_]+[^\n]*\n {lexer_line.line++;}
422d9921 168
e2500fed
GK
169. {
170 error_at_line (&lexer_line, "unexpected character `%s'", yytext);
171}
172}
173
174"/*" { BEGIN(in_comment); }
313465bb 175"//".*\n { lexer_line.line++; }
e2500fed
GK
176\n { lexer_line.line++; }
177{ID} |
8a5d66c4 178"'"("\\".|[^\\])"'" |
e2500fed
GK
179[^"/\n] /* do nothing */
180\"([^"\\]|\\.|\\\n)*\" { update_lineno (yytext, yyleng); }
181"/"/[^*] /* do nothing */
182
183<in_comment,in_struct_comment>{
184\n { lexer_line.line++; }
185[^*\n]{16} |
186[^*\n] /* do nothing */
187"*"/[^/] /* do nothing */
188}
313465bb 189
e2500fed
GK
190<in_comment>"*/" { BEGIN(INITIAL); }
191<in_struct_comment>"*/" { BEGIN(in_struct); }
192
e2500fed
GK
193["/] |
194<in_struct_comment,in_comment>"*" {
195 error_at_line (&lexer_line,
196 "unterminated comment or string; unexpected EOF");
197}
198
36f568c3 199^{HWS}"#"{HWS}"define"{WS}"GTY(" /* do nothing */
133f7a77 200
e2500fed
GK
201%%
202
203void
01d419ae 204yybegin (const char *fname)
e2500fed
GK
205{
206 yyin = fopen (fname, "r");
e2500fed
GK
207 if (yyin == NULL)
208 {
209 perror (fname);
210 exit (1);
211 }
14c4815e 212 lexer_line.file = input_file_by_name (fname);
01d419ae
ZW
213 lexer_line.line = 1;
214}
215
216void
217yyend (void)
218{
e2500fed
GK
219 fclose (yyin);
220}