aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/genksyms/lex.l
diff options
context:
space:
mode:
authorMichal Marek <mmarek@suse.cz>2011-03-17 10:15:18 -0400
committerMichal Marek <mmarek@suse.cz>2011-03-17 10:15:18 -0400
commita88bab9aeebe3118703e1532343d82688c12578e (patch)
treed6428e385b71d4bf8456ec8e919c7119a20505fb /scripts/genksyms/lex.l
parent00759c0ea0d3b4c918539ddd7cbbfbbb39a38fc7 (diff)
parent303fc01fb12d95cf9ab88c496df6651c887cef3c (diff)
Merge branch 'genksyms-enum' into kbuild/kbuild
Diffstat (limited to 'scripts/genksyms/lex.l')
-rw-r--r--scripts/genksyms/lex.l44
1 files changed, 31 insertions, 13 deletions
diff --git a/scripts/genksyms/lex.l b/scripts/genksyms/lex.l
index fe50ff9dacd0..e4ddd493fec3 100644
--- a/scripts/genksyms/lex.l
+++ b/scripts/genksyms/lex.l
@@ -55,10 +55,6 @@ CHAR L?\'([^\\\']*\\.)*[^\\\']*\'
55 55
56MC_TOKEN ([~%^&*+=|<>/-]=)|(&&)|("||")|(->)|(<<)|(>>) 56MC_TOKEN ([~%^&*+=|<>/-]=)|(&&)|("||")|(->)|(<<)|(>>)
57 57
58/* Version 2 checksumming does proper tokenization; version 1 wasn't
59 quite so pedantic. */
60%s V2_TOKENS
61
62/* We don't do multiple input files. */ 58/* We don't do multiple input files. */
63%option noyywrap 59%option noyywrap
64 60
@@ -84,9 +80,9 @@ MC_TOKEN ([~%^&*+=|<>/-]=)|(&&)|("||")|(->)|(<<)|(>>)
84 recognized as tokens. We don't actually use them since we don't 80 recognized as tokens. We don't actually use them since we don't
85 parse expressions, but we do want whitespace to be arranged 81 parse expressions, but we do want whitespace to be arranged
86 around them properly. */ 82 around them properly. */
87<V2_TOKENS>{MC_TOKEN} return OTHER; 83{MC_TOKEN} return OTHER;
88<V2_TOKENS>{INT} return INT; 84{INT} return INT;
89<V2_TOKENS>{REAL} return REAL; 85{REAL} return REAL;
90 86
91"..." return DOTS; 87"..." return DOTS;
92 88
@@ -103,12 +99,23 @@ MC_TOKEN ([~%^&*+=|<>/-]=)|(&&)|("||")|(->)|(<<)|(>>)
103 99
104/* Macros to append to our phrase collection list. */ 100/* Macros to append to our phrase collection list. */
105 101
102/*
103 * We mark any token, that that equals to a known enumerator, as
104 * SYM_ENUM_CONST. The parser will change this for struct and union tags later,
105 * the only problem is struct and union members:
106 * enum e { a, b }; struct s { int a, b; }
107 * but in this case, the only effect will be, that the ABI checksums become
108 * more volatile, which is acceptable. Also, such collisions are quite rare,
109 * so far it was only observed in include/linux/telephony.h.
110 */
106#define _APP(T,L) do { \ 111#define _APP(T,L) do { \
107 cur_node = next_node; \ 112 cur_node = next_node; \
108 next_node = xmalloc(sizeof(*next_node)); \ 113 next_node = xmalloc(sizeof(*next_node)); \
109 next_node->next = cur_node; \ 114 next_node->next = cur_node; \
110 cur_node->string = memcpy(xmalloc(L+1), T, L+1); \ 115 cur_node->string = memcpy(xmalloc(L+1), T, L+1); \
111 cur_node->tag = SYM_NORMAL; \ 116 cur_node->tag = \
117 find_symbol(cur_node->string, SYM_ENUM_CONST, 1)?\
118 SYM_ENUM_CONST : SYM_NORMAL ; \
112 } while (0) 119 } while (0)
113 120
114#define APP _APP(yytext, yyleng) 121#define APP _APP(yytext, yyleng)
@@ -134,7 +141,6 @@ yylex(void)
134 141
135 if (lexstate == ST_NOTSTARTED) 142 if (lexstate == ST_NOTSTARTED)
136 { 143 {
137 BEGIN(V2_TOKENS);
138 next_node = xmalloc(sizeof(*next_node)); 144 next_node = xmalloc(sizeof(*next_node));
139 next_node->next = NULL; 145 next_node->next = NULL;
140 lexstate = ST_NORMAL; 146 lexstate = ST_NORMAL;
@@ -187,8 +193,8 @@ repeat:
187 193
188 case STRUCT_KEYW: 194 case STRUCT_KEYW:
189 case UNION_KEYW: 195 case UNION_KEYW:
190 dont_want_brace_phrase = 3;
191 case ENUM_KEYW: 196 case ENUM_KEYW:
197 dont_want_brace_phrase = 3;
192 suppress_type_lookup = 2; 198 suppress_type_lookup = 2;
193 goto fini; 199 goto fini;
194 200
@@ -198,8 +204,7 @@ repeat:
198 } 204 }
199 if (!suppress_type_lookup) 205 if (!suppress_type_lookup)
200 { 206 {
201 struct symbol *sym = find_symbol(yytext, SYM_TYPEDEF); 207 if (find_symbol(yytext, SYM_TYPEDEF, 1))
202 if (sym && sym->type == SYM_TYPEDEF)
203 token = TYPE; 208 token = TYPE;
204 } 209 }
205 } 210 }
@@ -318,7 +323,20 @@ repeat:
318 ++count; 323 ++count;
319 APP; 324 APP;
320 goto repeat; 325 goto repeat;
321 case ')': case ']': case '}': 326 case '}':
327 /* is this the last line of an enum declaration? */
328 if (count == 0)
329 {
330 /* Put back the token we just read so's we can find it again
331 after registering the expression. */
332 unput(token);
333
334 lexstate = ST_NORMAL;
335 token = EXPRESSION_PHRASE;
336 break;
337 }
338 /* FALLTHRU */
339 case ')': case ']':
322 --count; 340 --count;
323 APP; 341 APP;
324 goto repeat; 342 goto repeat;