Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 1 | %{ |
| 2 | /* |
| 3 | * Copyright © 2010 Intel Corporation |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 27 | #include <assert.h> |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 28 | #include <inttypes.h> |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 29 | |
Carl Worth | a1e32bc | 2010-05-10 13:17:25 -0700 | [diff] [blame] | 30 | #include "glcpp.h" |
| 31 | |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 32 | #define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str) |
| 33 | #define glcpp_printf(stream, fmt, args...) \ |
| 34 | stream = talloc_asprintf_append(stream, fmt, args) |
| 35 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 36 | static void |
Kenneth Graunke | 465e03e | 2010-06-16 16:35:57 -0700 | [diff] [blame] | 37 | yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error); |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 38 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 39 | static void |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 40 | _define_object_macro (glcpp_parser_t *parser, |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 41 | YYLTYPE *loc, |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 42 | const char *macro, |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 43 | token_list_t *replacements); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 44 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 45 | static void |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 46 | _define_function_macro (glcpp_parser_t *parser, |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 47 | YYLTYPE *loc, |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 48 | const char *macro, |
Carl Worth | c5e9855 | 2010-05-14 10:12:21 -0700 | [diff] [blame] | 49 | string_list_t *parameters, |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 50 | token_list_t *replacements); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 51 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 52 | static string_list_t * |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 53 | _string_list_create (void *ctx); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 54 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 55 | static void |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 56 | _string_list_append_item (string_list_t *list, const char *str); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 57 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 58 | static void |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 59 | _string_list_append_list (string_list_t *list, string_list_t *tail); |
Carl Worth | c6d5af3 | 2010-05-11 12:30:09 -0700 | [diff] [blame] | 60 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 61 | static int |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 62 | _string_list_contains (string_list_t *list, const char *member, int *index); |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 63 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 64 | static int |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 65 | _string_list_length (string_list_t *list); |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 66 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 67 | static argument_list_t * |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 68 | _argument_list_create (void *ctx); |
| 69 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 70 | static void |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 71 | _argument_list_append (argument_list_t *list, token_list_t *argument); |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 72 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 73 | static int |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 74 | _argument_list_length (argument_list_t *list); |
| 75 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 76 | static token_list_t * |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 77 | _argument_list_member_at (argument_list_t *list, int index); |
| 78 | |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 79 | /* Note: This function talloc_steal()s the str pointer. */ |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 80 | static token_t * |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 81 | _token_create_str (void *ctx, int type, char *str); |
| 82 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 83 | static token_t * |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 84 | _token_create_ival (void *ctx, int type, int ival); |
| 85 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 86 | static token_list_t * |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 87 | _token_list_create (void *ctx); |
| 88 | |
Carl Worth | b1ae61a | 2010-05-26 08:10:38 -0700 | [diff] [blame] | 89 | /* Note: This function adds a talloc_reference() to token. |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 90 | * |
| 91 | * You may want to talloc_unlink any current reference if you no |
| 92 | * longer need it. */ |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 93 | static void |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 94 | _token_list_append (token_list_t *list, token_t *token); |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 95 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 96 | static void |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 97 | _token_list_append_list (token_list_t *list, token_list_t *tail); |
| 98 | |
Carl Worth | 22b3ace | 2010-06-02 15:32:03 -0700 | [diff] [blame] | 99 | static int |
| 100 | _token_list_length (token_list_t *list); |
| 101 | |
| 102 | static active_list_t * |
| 103 | _active_list_push (active_list_t *list, |
| 104 | const char *identifier, |
| 105 | token_node_t *marker); |
| 106 | |
| 107 | static active_list_t * |
| 108 | _active_list_pop (active_list_t *list); |
| 109 | |
| 110 | int |
| 111 | _active_list_contains (active_list_t *list, const char *identifier); |
| 112 | |
Carl Worth | 5aa7ea0 | 2010-05-25 18:39:43 -0700 | [diff] [blame] | 113 | static void |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 114 | _glcpp_parser_evaluate_defined (glcpp_parser_t *parser, |
| 115 | token_list_t *list); |
| 116 | |
| 117 | static void |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 118 | _glcpp_parser_expand_token_list (glcpp_parser_t *parser, |
| 119 | token_list_t *list); |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 120 | |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 121 | static void |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 122 | _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser, |
| 123 | token_list_t *list); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 124 | |
| 125 | static void |
Kenneth Graunke | 0774523 | 2010-06-17 12:41:46 -0700 | [diff] [blame] | 126 | _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc, |
| 127 | int condition); |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 128 | |
| 129 | static void |
Kenneth Graunke | 8a132aa | 2010-06-17 12:30:57 -0700 | [diff] [blame] | 130 | _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc, |
| 131 | const char *type, int condition); |
Carl Worth | 80dc60b | 2010-05-25 14:42:00 -0700 | [diff] [blame] | 132 | |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 133 | static void |
Kenneth Graunke | 8a132aa | 2010-06-17 12:30:57 -0700 | [diff] [blame] | 134 | _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc); |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 135 | |
Carl Worth | 0293b2e | 2010-05-19 10:05:40 -0700 | [diff] [blame] | 136 | #define yylex glcpp_parser_lex |
| 137 | |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 138 | static int |
Kenneth Graunke | 465e03e | 2010-06-16 16:35:57 -0700 | [diff] [blame] | 139 | glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser); |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 140 | |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 141 | static void |
| 142 | glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list); |
| 143 | |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 144 | %} |
| 145 | |
Kenneth Graunke | e0e429f | 2010-06-16 16:26:28 -0700 | [diff] [blame] | 146 | %pure-parser |
Kenneth Graunke | f70f607 | 2010-06-17 13:07:13 -0700 | [diff] [blame] | 147 | %error-verbose |
Kenneth Graunke | 465e03e | 2010-06-16 16:35:57 -0700 | [diff] [blame] | 148 | %locations |
Kenneth Graunke | e0e429f | 2010-06-16 16:26:28 -0700 | [diff] [blame] | 149 | |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 150 | %parse-param {glcpp_parser_t *parser} |
Carl Worth | 0293b2e | 2010-05-19 10:05:40 -0700 | [diff] [blame] | 151 | %lex-param {glcpp_parser_t *parser} |
Carl Worth | 38aa835 | 2010-05-10 11:52:29 -0700 | [diff] [blame] | 152 | |
Carl Worth | 050e3de | 2010-05-27 14:36:29 -0700 | [diff] [blame] | 153 | %token COMMA_FINAL DEFINED ELIF_EXPANDED HASH HASH_DEFINE_FUNC HASH_DEFINE_OBJ HASH_ELIF HASH_ELSE HASH_ENDIF HASH_IF HASH_IFDEF HASH_IFNDEF HASH_UNDEF IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING NEWLINE OTHER PLACEHOLDER SPACE |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 154 | %token PASTE |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 155 | %type <ival> expression INTEGER operator SPACE |
Carl Worth | 050e3de | 2010-05-27 14:36:29 -0700 | [diff] [blame] | 156 | %type <str> IDENTIFIER INTEGER_STRING OTHER |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 157 | %type <string_list> identifier_list |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 158 | %type <token> preprocessing_token |
| 159 | %type <token_list> pp_tokens replacement_list text_line |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 160 | %left OR |
| 161 | %left AND |
| 162 | %left '|' |
| 163 | %left '^' |
| 164 | %left '&' |
| 165 | %left EQUAL NOT_EQUAL |
| 166 | %left '<' '>' LESS_OR_EQUAL GREATER_OR_EQUAL |
| 167 | %left LEFT_SHIFT RIGHT_SHIFT |
| 168 | %left '+' '-' |
| 169 | %left '*' '/' '%' |
| 170 | %right UNARY |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 171 | |
| 172 | %% |
| 173 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 174 | input: |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 175 | /* empty */ |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 176 | | input line |
| 177 | ; |
| 178 | |
| 179 | line: |
| 180 | control_line { |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 181 | glcpp_print(parser->output, "\n"); |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 182 | } |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 183 | | text_line { |
Carl Worth | a771a40 | 2010-06-01 11:20:18 -0700 | [diff] [blame] | 184 | _glcpp_parser_print_expanded_token_list (parser, $1); |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 185 | glcpp_print(parser->output, "\n"); |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 186 | talloc_free ($1); |
| 187 | } |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 188 | | expanded_line |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 189 | | HASH non_directive |
Carl Worth | cd27e64 | 2010-05-12 13:11:50 -0700 | [diff] [blame] | 190 | ; |
| 191 | |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 192 | expanded_line: |
| 193 | IF_EXPANDED expression NEWLINE { |
Kenneth Graunke | 0774523 | 2010-06-17 12:41:46 -0700 | [diff] [blame] | 194 | _glcpp_parser_skip_stack_push_if (parser, & @1, $2); |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 195 | } |
| 196 | | ELIF_EXPANDED expression NEWLINE { |
Kenneth Graunke | 8a132aa | 2010-06-17 12:30:57 -0700 | [diff] [blame] | 197 | _glcpp_parser_skip_stack_change_if (parser, & @1, "elif", $2); |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 198 | } |
| 199 | ; |
| 200 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 201 | control_line: |
Carl Worth | f34a000 | 2010-05-25 16:59:02 -0700 | [diff] [blame] | 202 | HASH_DEFINE_OBJ IDENTIFIER replacement_list NEWLINE { |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 203 | _define_object_macro (parser, & @2, $2, $3); |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 204 | } |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 205 | | HASH_DEFINE_FUNC IDENTIFIER '(' ')' replacement_list NEWLINE { |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 206 | _define_function_macro (parser, & @2, $2, NULL, $5); |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 207 | } |
| 208 | | HASH_DEFINE_FUNC IDENTIFIER '(' identifier_list ')' replacement_list NEWLINE { |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 209 | _define_function_macro (parser, & @2, $2, $4, $6); |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 210 | } |
Carl Worth | e6fb782 | 2010-05-25 15:28:58 -0700 | [diff] [blame] | 211 | | HASH_UNDEF IDENTIFIER NEWLINE { |
Carl Worth | 0324cad | 2010-05-26 15:53:05 -0700 | [diff] [blame] | 212 | macro_t *macro = hash_table_find (parser->defines, $2); |
Carl Worth | e6fb782 | 2010-05-25 15:28:58 -0700 | [diff] [blame] | 213 | if (macro) { |
| 214 | /* XXX: Need hash table to support a real way |
| 215 | * to remove an element rather than prefixing |
| 216 | * a new node with data of NULL like this. */ |
| 217 | hash_table_insert (parser->defines, NULL, $2); |
| 218 | talloc_free (macro); |
| 219 | } |
| 220 | talloc_free ($2); |
| 221 | } |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 222 | | HASH_IF pp_tokens NEWLINE { |
| 223 | token_list_t *expanded; |
| 224 | token_t *token; |
| 225 | |
| 226 | expanded = _token_list_create (parser); |
| 227 | token = _token_create_ival (parser, IF_EXPANDED, IF_EXPANDED); |
| 228 | _token_list_append (expanded, token); |
| 229 | talloc_unlink (parser, token); |
| 230 | _glcpp_parser_evaluate_defined (parser, $2); |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 231 | _glcpp_parser_expand_token_list (parser, $2); |
| 232 | _token_list_append_list (expanded, $2); |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 233 | glcpp_parser_lex_from (parser, expanded); |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 234 | } |
Kenneth Graunke | 6587574 | 2010-06-18 20:08:15 -0700 | [diff] [blame] | 235 | | HASH_IFDEF IDENTIFIER junk NEWLINE { |
Carl Worth | 0324cad | 2010-05-26 15:53:05 -0700 | [diff] [blame] | 236 | macro_t *macro = hash_table_find (parser->defines, $2); |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 237 | talloc_free ($2); |
Kenneth Graunke | 0774523 | 2010-06-17 12:41:46 -0700 | [diff] [blame] | 238 | _glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL); |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 239 | } |
Kenneth Graunke | 6587574 | 2010-06-18 20:08:15 -0700 | [diff] [blame] | 240 | | HASH_IFNDEF IDENTIFIER junk NEWLINE { |
Carl Worth | 0324cad | 2010-05-26 15:53:05 -0700 | [diff] [blame] | 241 | macro_t *macro = hash_table_find (parser->defines, $2); |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 242 | talloc_free ($2); |
Kenneth Graunke | 0774523 | 2010-06-17 12:41:46 -0700 | [diff] [blame] | 243 | _glcpp_parser_skip_stack_push_if (parser, & @1, macro == NULL); |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 244 | } |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 245 | | HASH_ELIF pp_tokens NEWLINE { |
| 246 | token_list_t *expanded; |
| 247 | token_t *token; |
| 248 | |
| 249 | expanded = _token_list_create (parser); |
| 250 | token = _token_create_ival (parser, ELIF_EXPANDED, ELIF_EXPANDED); |
| 251 | _token_list_append (expanded, token); |
| 252 | talloc_unlink (parser, token); |
| 253 | _glcpp_parser_evaluate_defined (parser, $2); |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 254 | _glcpp_parser_expand_token_list (parser, $2); |
| 255 | _token_list_append_list (expanded, $2); |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 256 | glcpp_parser_lex_from (parser, expanded); |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 257 | } |
| 258 | | HASH_ELSE NEWLINE { |
Kenneth Graunke | 8a132aa | 2010-06-17 12:30:57 -0700 | [diff] [blame] | 259 | _glcpp_parser_skip_stack_change_if (parser, & @1, "else", 1); |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 260 | } |
| 261 | | HASH_ENDIF NEWLINE { |
Kenneth Graunke | 8a132aa | 2010-06-17 12:30:57 -0700 | [diff] [blame] | 262 | _glcpp_parser_skip_stack_pop (parser, & @1); |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 263 | } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 264 | | HASH NEWLINE |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 265 | ; |
| 266 | |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 267 | expression: |
Carl Worth | 050e3de | 2010-05-27 14:36:29 -0700 | [diff] [blame] | 268 | INTEGER_STRING { |
| 269 | if (strlen ($1) >= 3 && strncmp ($1, "0x", 2) == 0) { |
| 270 | $$ = strtoll ($1 + 2, NULL, 16); |
| 271 | } else if ($1[0] == '0') { |
| 272 | $$ = strtoll ($1, NULL, 8); |
| 273 | } else { |
| 274 | $$ = strtoll ($1, NULL, 10); |
| 275 | } |
| 276 | } |
| 277 | | INTEGER { |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 278 | $$ = $1; |
| 279 | } |
| 280 | | expression OR expression { |
| 281 | $$ = $1 || $3; |
| 282 | } |
| 283 | | expression AND expression { |
| 284 | $$ = $1 && $3; |
| 285 | } |
| 286 | | expression '|' expression { |
| 287 | $$ = $1 | $3; |
| 288 | } |
| 289 | | expression '^' expression { |
| 290 | $$ = $1 ^ $3; |
| 291 | } |
| 292 | | expression '&' expression { |
| 293 | $$ = $1 & $3; |
| 294 | } |
| 295 | | expression NOT_EQUAL expression { |
| 296 | $$ = $1 != $3; |
| 297 | } |
| 298 | | expression EQUAL expression { |
| 299 | $$ = $1 == $3; |
| 300 | } |
| 301 | | expression GREATER_OR_EQUAL expression { |
| 302 | $$ = $1 >= $3; |
| 303 | } |
| 304 | | expression LESS_OR_EQUAL expression { |
| 305 | $$ = $1 <= $3; |
| 306 | } |
| 307 | | expression '>' expression { |
| 308 | $$ = $1 > $3; |
| 309 | } |
| 310 | | expression '<' expression { |
| 311 | $$ = $1 < $3; |
| 312 | } |
| 313 | | expression RIGHT_SHIFT expression { |
| 314 | $$ = $1 >> $3; |
| 315 | } |
| 316 | | expression LEFT_SHIFT expression { |
| 317 | $$ = $1 << $3; |
| 318 | } |
| 319 | | expression '-' expression { |
| 320 | $$ = $1 - $3; |
| 321 | } |
| 322 | | expression '+' expression { |
| 323 | $$ = $1 + $3; |
| 324 | } |
| 325 | | expression '%' expression { |
| 326 | $$ = $1 % $3; |
| 327 | } |
| 328 | | expression '/' expression { |
| 329 | $$ = $1 / $3; |
| 330 | } |
| 331 | | expression '*' expression { |
| 332 | $$ = $1 * $3; |
| 333 | } |
| 334 | | '!' expression %prec UNARY { |
| 335 | $$ = ! $2; |
| 336 | } |
| 337 | | '~' expression %prec UNARY { |
| 338 | $$ = ~ $2; |
| 339 | } |
| 340 | | '-' expression %prec UNARY { |
| 341 | $$ = - $2; |
| 342 | } |
| 343 | | '+' expression %prec UNARY { |
| 344 | $$ = + $2; |
| 345 | } |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 346 | | '(' expression ')' { |
| 347 | $$ = $2; |
| 348 | } |
| 349 | ; |
| 350 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 351 | identifier_list: |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 352 | IDENTIFIER { |
| 353 | $$ = _string_list_create (parser); |
| 354 | _string_list_append_item ($$, $1); |
| 355 | talloc_steal ($$, $1); |
| 356 | } |
| 357 | | identifier_list ',' IDENTIFIER { |
| 358 | $$ = $1; |
| 359 | _string_list_append_item ($$, $3); |
| 360 | talloc_steal ($$, $3); |
| 361 | } |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 362 | ; |
| 363 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 364 | text_line: |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 365 | NEWLINE { $$ = NULL; } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 366 | | pp_tokens NEWLINE |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 367 | ; |
| 368 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 369 | non_directive: |
Kenneth Graunke | 739ba06 | 2010-06-16 12:41:37 -0700 | [diff] [blame] | 370 | pp_tokens NEWLINE { |
Kenneth Graunke | 465e03e | 2010-06-16 16:35:57 -0700 | [diff] [blame] | 371 | yyerror (& @1, parser, "Invalid tokens after #"); |
Kenneth Graunke | 739ba06 | 2010-06-16 12:41:37 -0700 | [diff] [blame] | 372 | } |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 373 | ; |
| 374 | |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 375 | replacement_list: |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 376 | /* empty */ { $$ = NULL; } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 377 | | pp_tokens |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 378 | ; |
| 379 | |
Kenneth Graunke | 6587574 | 2010-06-18 20:08:15 -0700 | [diff] [blame] | 380 | junk: |
| 381 | /* empty */ |
| 382 | | pp_tokens { |
| 383 | glcpp_warning(&@1, parser, "extra tokens at end of directive"); |
| 384 | } |
| 385 | |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 386 | pp_tokens: |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 387 | preprocessing_token { |
Carl Worth | f34a000 | 2010-05-25 16:59:02 -0700 | [diff] [blame] | 388 | parser->space_tokens = 1; |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 389 | $$ = _token_list_create (parser); |
| 390 | _token_list_append ($$, $1); |
| 391 | talloc_unlink (parser, $1); |
| 392 | } |
| 393 | | pp_tokens preprocessing_token { |
| 394 | $$ = $1; |
| 395 | _token_list_append ($$, $2); |
| 396 | talloc_unlink (parser, $2); |
| 397 | } |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 398 | ; |
| 399 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 400 | preprocessing_token: |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 401 | IDENTIFIER { |
| 402 | $$ = _token_create_str (parser, IDENTIFIER, $1); |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 403 | $$->location = yylloc; |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 404 | } |
Carl Worth | 050e3de | 2010-05-27 14:36:29 -0700 | [diff] [blame] | 405 | | INTEGER_STRING { |
| 406 | $$ = _token_create_str (parser, INTEGER_STRING, $1); |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 407 | $$->location = yylloc; |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 408 | } |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 409 | | operator { |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 410 | $$ = _token_create_ival (parser, $1, $1); |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 411 | $$->location = yylloc; |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 412 | } |
| 413 | | OTHER { |
| 414 | $$ = _token_create_str (parser, OTHER, $1); |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 415 | $$->location = yylloc; |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 416 | } |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 417 | | SPACE { |
Carl Worth | e939786 | 2010-05-25 17:08:07 -0700 | [diff] [blame] | 418 | $$ = _token_create_ival (parser, SPACE, SPACE); |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 419 | $$->location = yylloc; |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 420 | } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 421 | ; |
| 422 | |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 423 | operator: |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 424 | '[' { $$ = '['; } |
| 425 | | ']' { $$ = ']'; } |
| 426 | | '(' { $$ = '('; } |
| 427 | | ')' { $$ = ')'; } |
| 428 | | '{' { $$ = '{'; } |
| 429 | | '}' { $$ = '}'; } |
| 430 | | '.' { $$ = '.'; } |
| 431 | | '&' { $$ = '&'; } |
| 432 | | '*' { $$ = '*'; } |
| 433 | | '+' { $$ = '+'; } |
| 434 | | '-' { $$ = '-'; } |
| 435 | | '~' { $$ = '~'; } |
| 436 | | '!' { $$ = '!'; } |
| 437 | | '/' { $$ = '/'; } |
| 438 | | '%' { $$ = '%'; } |
| 439 | | LEFT_SHIFT { $$ = LEFT_SHIFT; } |
| 440 | | RIGHT_SHIFT { $$ = RIGHT_SHIFT; } |
| 441 | | '<' { $$ = '<'; } |
| 442 | | '>' { $$ = '>'; } |
| 443 | | LESS_OR_EQUAL { $$ = LESS_OR_EQUAL; } |
| 444 | | GREATER_OR_EQUAL { $$ = GREATER_OR_EQUAL; } |
| 445 | | EQUAL { $$ = EQUAL; } |
| 446 | | NOT_EQUAL { $$ = NOT_EQUAL; } |
| 447 | | '^' { $$ = '^'; } |
| 448 | | '|' { $$ = '|'; } |
| 449 | | AND { $$ = AND; } |
| 450 | | OR { $$ = OR; } |
| 451 | | ';' { $$ = ';'; } |
| 452 | | ',' { $$ = ','; } |
Carl Worth | 6310169 | 2010-05-29 05:07:24 -0700 | [diff] [blame] | 453 | | '=' { $$ = '='; } |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 454 | | PASTE { $$ = PASTE; } |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 455 | | DEFINED { $$ = DEFINED; } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 456 | ; |
| 457 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 458 | %% |
| 459 | |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 460 | string_list_t * |
| 461 | _string_list_create (void *ctx) |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 462 | { |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 463 | string_list_t *list; |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 464 | |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 465 | list = xtalloc (ctx, string_list_t); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 466 | list->head = NULL; |
| 467 | list->tail = NULL; |
| 468 | |
| 469 | return list; |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 470 | } |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 471 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 472 | void |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 473 | _string_list_append_list (string_list_t *list, string_list_t *tail) |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 474 | { |
| 475 | if (list->head == NULL) { |
| 476 | list->head = tail->head; |
| 477 | } else { |
| 478 | list->tail->next = tail->head; |
| 479 | } |
| 480 | |
| 481 | list->tail = tail->tail; |
| 482 | } |
| 483 | |
| 484 | void |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 485 | _string_list_append_item (string_list_t *list, const char *str) |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 486 | { |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 487 | string_node_t *node; |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 488 | |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 489 | node = xtalloc (list, string_node_t); |
Carl Worth | 5070a20 | 2010-05-12 12:45:33 -0700 | [diff] [blame] | 490 | node->str = xtalloc_strdup (node, str); |
Carl Worth | 80dc60b | 2010-05-25 14:42:00 -0700 | [diff] [blame] | 491 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 492 | node->next = NULL; |
| 493 | |
| 494 | if (list->head == NULL) { |
| 495 | list->head = node; |
| 496 | } else { |
| 497 | list->tail->next = node; |
| 498 | } |
| 499 | |
| 500 | list->tail = node; |
| 501 | } |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 502 | |
| 503 | int |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 504 | _string_list_contains (string_list_t *list, const char *member, int *index) |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 505 | { |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 506 | string_node_t *node; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 507 | int i; |
| 508 | |
| 509 | if (list == NULL) |
| 510 | return 0; |
| 511 | |
| 512 | for (i = 0, node = list->head; node; i++, node = node->next) { |
| 513 | if (strcmp (node->str, member) == 0) { |
Carl Worth | 420d05a | 2010-05-17 10:15:23 -0700 | [diff] [blame] | 514 | if (index) |
| 515 | *index = i; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 516 | return 1; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | int |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 524 | _string_list_length (string_list_t *list) |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 525 | { |
| 526 | int length = 0; |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 527 | string_node_t *node; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 528 | |
| 529 | if (list == NULL) |
| 530 | return 0; |
| 531 | |
| 532 | for (node = list->head; node; node = node->next) |
| 533 | length++; |
| 534 | |
| 535 | return length; |
| 536 | } |
| 537 | |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 538 | argument_list_t * |
| 539 | _argument_list_create (void *ctx) |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 540 | { |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 541 | argument_list_t *list; |
| 542 | |
| 543 | list = xtalloc (ctx, argument_list_t); |
| 544 | list->head = NULL; |
| 545 | list->tail = NULL; |
| 546 | |
| 547 | return list; |
| 548 | } |
| 549 | |
| 550 | void |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 551 | _argument_list_append (argument_list_t *list, token_list_t *argument) |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 552 | { |
| 553 | argument_node_t *node; |
| 554 | |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 555 | node = xtalloc (list, argument_node_t); |
| 556 | node->argument = argument; |
| 557 | |
| 558 | node->next = NULL; |
| 559 | |
| 560 | if (list->head == NULL) { |
| 561 | list->head = node; |
| 562 | } else { |
| 563 | list->tail->next = node; |
| 564 | } |
| 565 | |
| 566 | list->tail = node; |
| 567 | } |
| 568 | |
| 569 | int |
| 570 | _argument_list_length (argument_list_t *list) |
| 571 | { |
| 572 | int length = 0; |
| 573 | argument_node_t *node; |
| 574 | |
| 575 | if (list == NULL) |
| 576 | return 0; |
| 577 | |
| 578 | for (node = list->head; node; node = node->next) |
| 579 | length++; |
| 580 | |
| 581 | return length; |
| 582 | } |
| 583 | |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 584 | token_list_t * |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 585 | _argument_list_member_at (argument_list_t *list, int index) |
| 586 | { |
| 587 | argument_node_t *node; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 588 | int i; |
| 589 | |
| 590 | if (list == NULL) |
| 591 | return NULL; |
| 592 | |
| 593 | node = list->head; |
| 594 | for (i = 0; i < index; i++) { |
| 595 | node = node->next; |
| 596 | if (node == NULL) |
| 597 | break; |
| 598 | } |
| 599 | |
| 600 | if (node) |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 601 | return node->argument; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 602 | |
| 603 | return NULL; |
| 604 | } |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 605 | |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 606 | /* Note: This function talloc_steal()s the str pointer. */ |
| 607 | token_t * |
| 608 | _token_create_str (void *ctx, int type, char *str) |
| 609 | { |
| 610 | token_t *token; |
| 611 | |
| 612 | token = xtalloc (ctx, token_t); |
| 613 | token->type = type; |
| 614 | token->value.str = talloc_steal (token, str); |
| 615 | |
| 616 | return token; |
| 617 | } |
| 618 | |
| 619 | token_t * |
| 620 | _token_create_ival (void *ctx, int type, int ival) |
| 621 | { |
| 622 | token_t *token; |
| 623 | |
| 624 | token = xtalloc (ctx, token_t); |
| 625 | token->type = type; |
| 626 | token->value.ival = ival; |
| 627 | |
| 628 | return token; |
| 629 | } |
| 630 | |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 631 | token_list_t * |
| 632 | _token_list_create (void *ctx) |
| 633 | { |
| 634 | token_list_t *list; |
| 635 | |
| 636 | list = xtalloc (ctx, token_list_t); |
| 637 | list->head = NULL; |
| 638 | list->tail = NULL; |
Carl Worth | 10ae438 | 2010-05-25 20:35:01 -0700 | [diff] [blame] | 639 | list->non_space_tail = NULL; |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 640 | |
| 641 | return list; |
| 642 | } |
| 643 | |
| 644 | void |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 645 | _token_list_append (token_list_t *list, token_t *token) |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 646 | { |
| 647 | token_node_t *node; |
| 648 | |
| 649 | node = xtalloc (list, token_node_t); |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 650 | node->token = xtalloc_reference (list, token); |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 651 | |
| 652 | node->next = NULL; |
| 653 | |
| 654 | if (list->head == NULL) { |
| 655 | list->head = node; |
| 656 | } else { |
| 657 | list->tail->next = node; |
| 658 | } |
| 659 | |
| 660 | list->tail = node; |
Carl Worth | 10ae438 | 2010-05-25 20:35:01 -0700 | [diff] [blame] | 661 | if (token->type != SPACE) |
| 662 | list->non_space_tail = node; |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | void |
| 666 | _token_list_append_list (token_list_t *list, token_list_t *tail) |
| 667 | { |
Carl Worth | a65cf7b | 2010-05-27 11:55:36 -0700 | [diff] [blame] | 668 | if (tail == NULL || tail->head == NULL) |
| 669 | return; |
| 670 | |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 671 | if (list->head == NULL) { |
| 672 | list->head = tail->head; |
| 673 | } else { |
| 674 | list->tail->next = tail->head; |
| 675 | } |
| 676 | |
| 677 | list->tail = tail->tail; |
Carl Worth | 10ae438 | 2010-05-25 20:35:01 -0700 | [diff] [blame] | 678 | list->non_space_tail = tail->non_space_tail; |
| 679 | } |
| 680 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 681 | token_list_t * |
| 682 | _token_list_copy (void *ctx, token_list_t *other) |
| 683 | { |
| 684 | token_list_t *copy; |
| 685 | token_node_t *node; |
| 686 | |
| 687 | if (other == NULL) |
| 688 | return NULL; |
| 689 | |
| 690 | copy = _token_list_create (ctx); |
| 691 | for (node = other->head; node; node = node->next) |
| 692 | _token_list_append (copy, node->token); |
| 693 | |
| 694 | return copy; |
| 695 | } |
| 696 | |
Carl Worth | 10ae438 | 2010-05-25 20:35:01 -0700 | [diff] [blame] | 697 | void |
| 698 | _token_list_trim_trailing_space (token_list_t *list) |
| 699 | { |
| 700 | token_node_t *tail, *next; |
| 701 | |
| 702 | if (list->non_space_tail) { |
| 703 | tail = list->non_space_tail->next; |
| 704 | list->non_space_tail->next = NULL; |
| 705 | list->tail = list->non_space_tail; |
| 706 | |
| 707 | while (tail) { |
| 708 | next = tail->next; |
| 709 | talloc_free (tail); |
| 710 | tail = next; |
| 711 | } |
| 712 | } |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 713 | } |
Carl Worth | 80dc60b | 2010-05-25 14:42:00 -0700 | [diff] [blame] | 714 | |
Carl Worth | 22b3ace | 2010-06-02 15:32:03 -0700 | [diff] [blame] | 715 | static int |
| 716 | _token_list_length (token_list_t *list) |
| 717 | { |
| 718 | int length = 0; |
| 719 | token_node_t *node; |
| 720 | |
| 721 | if (list == NULL) |
| 722 | return 0; |
| 723 | |
| 724 | for (node = list->head; node; node = node->next) |
| 725 | length++; |
| 726 | |
| 727 | return length; |
| 728 | } |
| 729 | |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 730 | static void |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 731 | _token_print (char **out, token_t *token) |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 732 | { |
| 733 | if (token->type < 256) { |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 734 | glcpp_printf (*out, "%c", token->type); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 735 | return; |
| 736 | } |
| 737 | |
| 738 | switch (token->type) { |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 739 | case INTEGER: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 740 | glcpp_printf (*out, "%" PRIxMAX, token->value.ival); |
Carl Worth | 8fed1cd | 2010-05-26 09:32:12 -0700 | [diff] [blame] | 741 | break; |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 742 | case IDENTIFIER: |
Carl Worth | 050e3de | 2010-05-27 14:36:29 -0700 | [diff] [blame] | 743 | case INTEGER_STRING: |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 744 | case OTHER: |
Kenneth Graunke | ca9e5fc | 2010-06-16 17:31:50 -0700 | [diff] [blame] | 745 | glcpp_print (*out, token->value.str); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 746 | break; |
| 747 | case SPACE: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 748 | glcpp_print (*out, " "); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 749 | break; |
| 750 | case LEFT_SHIFT: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 751 | glcpp_print (*out, "<<"); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 752 | break; |
| 753 | case RIGHT_SHIFT: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 754 | glcpp_print (*out, ">>"); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 755 | break; |
| 756 | case LESS_OR_EQUAL: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 757 | glcpp_print (*out, "<="); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 758 | break; |
| 759 | case GREATER_OR_EQUAL: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 760 | glcpp_print (*out, ">="); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 761 | break; |
| 762 | case EQUAL: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 763 | glcpp_print (*out, "=="); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 764 | break; |
| 765 | case NOT_EQUAL: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 766 | glcpp_print (*out, "!="); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 767 | break; |
| 768 | case AND: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 769 | glcpp_print (*out, "&&"); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 770 | break; |
| 771 | case OR: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 772 | glcpp_print (*out, "||"); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 773 | break; |
| 774 | case PASTE: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 775 | glcpp_print (*out, "##"); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 776 | break; |
Carl Worth | dd74900 | 2010-05-27 10:12:33 -0700 | [diff] [blame] | 777 | case COMMA_FINAL: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 778 | glcpp_print (*out, ","); |
Carl Worth | dd74900 | 2010-05-27 10:12:33 -0700 | [diff] [blame] | 779 | break; |
Carl Worth | 85b50e8 | 2010-05-27 14:01:18 -0700 | [diff] [blame] | 780 | case PLACEHOLDER: |
| 781 | /* Nothing to print. */ |
| 782 | break; |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 783 | default: |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 784 | assert(!"Error: Don't know how to print token."); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 785 | break; |
| 786 | } |
| 787 | } |
| 788 | |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 789 | /* Return a new token (talloc()ed off of 'token') formed by pasting |
| 790 | * 'token' and 'other'. Note that this function may return 'token' or |
| 791 | * 'other' directly rather than allocating anything new. |
| 792 | * |
| 793 | * Caution: Only very cursory error-checking is performed to see if |
| 794 | * the final result is a valid single token. */ |
| 795 | static token_t * |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 796 | _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other) |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 797 | { |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 798 | token_t *combined = NULL; |
| 799 | |
Carl Worth | 85b50e8 | 2010-05-27 14:01:18 -0700 | [diff] [blame] | 800 | /* Pasting a placeholder onto anything makes no change. */ |
| 801 | if (other->type == PLACEHOLDER) |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 802 | return token; |
Carl Worth | 85b50e8 | 2010-05-27 14:01:18 -0700 | [diff] [blame] | 803 | |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 804 | /* When 'token' is a placeholder, just return 'other'. */ |
| 805 | if (token->type == PLACEHOLDER) |
| 806 | return other; |
Carl Worth | 85b50e8 | 2010-05-27 14:01:18 -0700 | [diff] [blame] | 807 | |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 808 | /* A very few single-character punctuators can be combined |
| 809 | * with another to form a multi-character punctuator. */ |
| 810 | switch (token->type) { |
| 811 | case '<': |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 812 | if (other->type == '<') |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 813 | combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT); |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 814 | else if (other->type == '=') |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 815 | combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL); |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 816 | break; |
| 817 | case '>': |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 818 | if (other->type == '>') |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 819 | combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT); |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 820 | else if (other->type == '=') |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 821 | combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL); |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 822 | break; |
| 823 | case '=': |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 824 | if (other->type == '=') |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 825 | combined = _token_create_ival (token, EQUAL, EQUAL); |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 826 | break; |
| 827 | case '!': |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 828 | if (other->type == '=') |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 829 | combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL); |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 830 | break; |
| 831 | case '&': |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 832 | if (other->type == '&') |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 833 | combined = _token_create_ival (token, AND, AND); |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 834 | break; |
| 835 | case '|': |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 836 | if (other->type == '|') |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 837 | combined = _token_create_ival (token, OR, OR); |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 838 | break; |
| 839 | } |
| 840 | |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 841 | if (combined != NULL) { |
| 842 | /* Inherit the location from the first token */ |
| 843 | combined->location = token->location; |
| 844 | return combined; |
| 845 | } |
| 846 | |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 847 | /* Two string-valued tokens can usually just be mashed |
| 848 | * together. |
| 849 | * |
Carl Worth | 050e3de | 2010-05-27 14:36:29 -0700 | [diff] [blame] | 850 | * XXX: This isn't actually legitimate. Several things here |
| 851 | * should result in a diagnostic since the result cannot be a |
| 852 | * valid, single pre-processing token. For example, pasting |
| 853 | * "123" and "abc" is not legal, but we don't catch that |
| 854 | * here. */ |
| 855 | if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING) && |
| 856 | (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING)) |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 857 | { |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 858 | char *str; |
| 859 | |
| 860 | str = xtalloc_asprintf (token, "%s%s", |
| 861 | token->value.str, other->value.str); |
Kenneth Graunke | b78c9dd | 2010-06-16 16:58:31 -0700 | [diff] [blame] | 862 | combined = _token_create_str (token, token->type, str); |
| 863 | combined->location = token->location; |
| 864 | return combined; |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Kenneth Graunke | ca9e5fc | 2010-06-16 17:31:50 -0700 | [diff] [blame] | 867 | glcpp_error (&token->location, parser, ""); |
Kenneth Graunke | 33eaa3e | 2010-06-18 19:52:36 -0700 | [diff] [blame] | 868 | glcpp_print (parser->info_log, "Pasting \""); |
| 869 | _token_print (&parser->info_log, token); |
| 870 | glcpp_print (parser->info_log, "\" and \""); |
| 871 | _token_print (&parser->info_log, other); |
| 872 | glcpp_print (parser->info_log, "\" does not give a valid preprocessing token.\n"); |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 873 | |
| 874 | return token; |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 877 | static void |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 878 | _token_list_print (glcpp_parser_t *parser, token_list_t *list) |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 879 | { |
| 880 | token_node_t *node; |
| 881 | |
| 882 | if (list == NULL) |
| 883 | return; |
| 884 | |
| 885 | for (node = list->head; node; node = node->next) |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 886 | _token_print (&parser->output, node->token); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 889 | void |
Kenneth Graunke | 465e03e | 2010-06-16 16:35:57 -0700 | [diff] [blame] | 890 | yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error) |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 891 | { |
Kenneth Graunke | f1e6c06 | 2010-06-17 12:03:25 -0700 | [diff] [blame] | 892 | glcpp_error(locp, parser, "%s", error); |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 893 | } |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 894 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 895 | glcpp_parser_t * |
| 896 | glcpp_parser_create (void) |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 897 | { |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 898 | glcpp_parser_t *parser; |
| 899 | |
Carl Worth | 5070a20 | 2010-05-12 12:45:33 -0700 | [diff] [blame] | 900 | parser = xtalloc (NULL, glcpp_parser_t); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 901 | |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 902 | glcpp_lex_init_extra (parser, &parser->scanner); |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 903 | parser->defines = hash_table_ctor (32, hash_table_string_hash, |
| 904 | hash_table_string_compare); |
Carl Worth | 22b3ace | 2010-06-02 15:32:03 -0700 | [diff] [blame] | 905 | parser->active = NULL; |
Carl Worth | a771a40 | 2010-06-01 11:20:18 -0700 | [diff] [blame] | 906 | parser->lexing_if = 0; |
Carl Worth | f34a000 | 2010-05-25 16:59:02 -0700 | [diff] [blame] | 907 | parser->space_tokens = 1; |
Carl Worth | 95951ea | 2010-05-26 15:57:10 -0700 | [diff] [blame] | 908 | parser->newline_as_space = 0; |
| 909 | parser->in_control_line = 0; |
| 910 | parser->paren_count = 0; |
Carl Worth | 5a6b9a2 | 2010-05-20 14:29:43 -0700 | [diff] [blame] | 911 | |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 912 | parser->skip_stack = NULL; |
| 913 | |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 914 | parser->lex_from_list = NULL; |
| 915 | parser->lex_from_node = NULL; |
| 916 | |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 917 | parser->output = talloc_strdup(parser, ""); |
Kenneth Graunke | 33eaa3e | 2010-06-18 19:52:36 -0700 | [diff] [blame] | 918 | parser->info_log = talloc_strdup(parser, ""); |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 919 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 920 | return parser; |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | int |
| 924 | glcpp_parser_parse (glcpp_parser_t *parser) |
| 925 | { |
| 926 | return yyparse (parser); |
| 927 | } |
| 928 | |
| 929 | void |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 930 | glcpp_parser_destroy (glcpp_parser_t *parser) |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 931 | { |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 932 | if (parser->skip_stack) |
Kenneth Graunke | 0774523 | 2010-06-17 12:41:46 -0700 | [diff] [blame] | 933 | glcpp_error (&parser->skip_stack->loc, parser, "Unterminated #if\n"); |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 934 | glcpp_lex_destroy (parser->scanner); |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 935 | hash_table_dtor (parser->defines); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 936 | talloc_free (parser); |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 937 | } |
Carl Worth | c6d5af3 | 2010-05-11 12:30:09 -0700 | [diff] [blame] | 938 | |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 939 | /* Replace any occurences of DEFINED tokens in 'list' with either a |
| 940 | * '0' or '1' INTEGER token depending on whether the next token in the |
| 941 | * list is defined or not. */ |
| 942 | static void |
| 943 | _glcpp_parser_evaluate_defined (glcpp_parser_t *parser, |
| 944 | token_list_t *list) |
| 945 | { |
| 946 | token_node_t *node, *next; |
Carl Worth | 0324cad | 2010-05-26 15:53:05 -0700 | [diff] [blame] | 947 | macro_t *macro; |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 948 | |
| 949 | if (list == NULL) |
| 950 | return; |
| 951 | |
| 952 | for (node = list->head; node; node = node->next) { |
| 953 | if (node->token->type != DEFINED) |
| 954 | continue; |
| 955 | next = node->next; |
| 956 | while (next && next->token->type == SPACE) |
| 957 | next = next->next; |
| 958 | if (next == NULL || next->token->type != IDENTIFIER) { |
Kenneth Graunke | ca9e5fc | 2010-06-16 17:31:50 -0700 | [diff] [blame] | 959 | yyerror (&node->token->location, parser, "operator \"defined\" requires an identifier\n"); |
Kenneth Graunke | e8e93a4 | 2010-06-17 12:58:54 -0700 | [diff] [blame] | 960 | /* Already flagged an error; fake it. */ |
| 961 | node->token->type = INTEGER; |
| 962 | node->token->value.ival = 0; |
| 963 | return; |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 964 | } |
| 965 | macro = hash_table_find (parser->defines, |
| 966 | next->token->value.str); |
| 967 | |
| 968 | node->token->type = INTEGER; |
| 969 | node->token->value.ival = (macro != NULL); |
| 970 | node->next = next->next; |
| 971 | } |
| 972 | } |
| 973 | |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 974 | typedef enum function_status |
| 975 | { |
| 976 | FUNCTION_STATUS_SUCCESS, |
| 977 | FUNCTION_NOT_A_FUNCTION, |
| 978 | FUNCTION_UNBALANCED_PARENTHESES |
| 979 | } function_status_t; |
| 980 | |
| 981 | /* Find a set of function-like macro arguments by looking for a |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 982 | * balanced set of parentheses. |
| 983 | * |
| 984 | * When called, 'node' should be the opening-parenthesis token, (or |
| 985 | * perhaps preceeding SPACE tokens). Upon successful return *last will |
| 986 | * be the last consumed node, (corresponding to the closing right |
| 987 | * parenthesis). |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 988 | * |
| 989 | * Return values: |
| 990 | * |
| 991 | * FUNCTION_STATUS_SUCCESS: |
| 992 | * |
| 993 | * Successfully parsed a set of function arguments. |
| 994 | * |
| 995 | * FUNCTION_NOT_A_FUNCTION: |
| 996 | * |
| 997 | * Macro name not followed by a '('. This is not an error, but |
| 998 | * simply that the macro name should be treated as a non-macro. |
| 999 | * |
Carl Worth | 14c98a5 | 2010-06-02 15:49:54 -0700 | [diff] [blame] | 1000 | * FUNCTION_UNBALANCED_PARENTHESES |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1001 | * |
| 1002 | * Macro name is not followed by a balanced set of parentheses. |
| 1003 | */ |
| 1004 | static function_status_t |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1005 | _arguments_parse (argument_list_t *arguments, |
| 1006 | token_node_t *node, |
| 1007 | token_node_t **last) |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1008 | { |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1009 | token_list_t *argument; |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1010 | int paren_count; |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1011 | |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1012 | node = node->next; |
| 1013 | |
| 1014 | /* Ignore whitespace before first parenthesis. */ |
| 1015 | while (node && node->token->type == SPACE) |
| 1016 | node = node->next; |
| 1017 | |
| 1018 | if (node == NULL || node->token->type != '(') |
| 1019 | return FUNCTION_NOT_A_FUNCTION; |
| 1020 | |
Carl Worth | 652fa27 | 2010-05-25 17:45:22 -0700 | [diff] [blame] | 1021 | node = node->next; |
| 1022 | |
Carl Worth | a19297b | 2010-05-27 13:29:19 -0700 | [diff] [blame] | 1023 | argument = _token_list_create (arguments); |
| 1024 | _argument_list_append (arguments, argument); |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1025 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1026 | for (paren_count = 1; node; node = node->next) { |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1027 | if (node->token->type == '(') |
| 1028 | { |
| 1029 | paren_count++; |
| 1030 | } |
| 1031 | else if (node->token->type == ')') |
| 1032 | { |
| 1033 | paren_count--; |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1034 | if (paren_count == 0) |
Carl Worth | c7581c2 | 2010-05-25 17:41:07 -0700 | [diff] [blame] | 1035 | break; |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1036 | } |
Carl Worth | 652fa27 | 2010-05-25 17:45:22 -0700 | [diff] [blame] | 1037 | |
| 1038 | if (node->token->type == ',' && |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1039 | paren_count == 1) |
| 1040 | { |
Carl Worth | a19297b | 2010-05-27 13:29:19 -0700 | [diff] [blame] | 1041 | _token_list_trim_trailing_space (argument); |
| 1042 | argument = _token_list_create (arguments); |
| 1043 | _argument_list_append (arguments, argument); |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1044 | } |
| 1045 | else { |
Carl Worth | a19297b | 2010-05-27 13:29:19 -0700 | [diff] [blame] | 1046 | if (argument->head == NULL) { |
Carl Worth | c7581c2 | 2010-05-25 17:41:07 -0700 | [diff] [blame] | 1047 | /* Don't treat initial whitespace as |
| 1048 | * part of the arguement. */ |
| 1049 | if (node->token->type == SPACE) |
| 1050 | continue; |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1051 | } |
| 1052 | _token_list_append (argument, node->token); |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1053 | } |
Carl Worth | c7581c2 | 2010-05-25 17:41:07 -0700 | [diff] [blame] | 1054 | } |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1055 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1056 | if (paren_count) |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1057 | return FUNCTION_UNBALANCED_PARENTHESES; |
| 1058 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1059 | *last = node; |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1060 | |
| 1061 | return FUNCTION_STATUS_SUCCESS; |
| 1062 | } |
| 1063 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1064 | /* This is a helper function that's essentially part of the |
| 1065 | * implementation of _glcpp_parser_expand_node. It shouldn't be called |
| 1066 | * except for by that function. |
| 1067 | * |
| 1068 | * Returns NULL if node is a simple token with no expansion, (that is, |
| 1069 | * although 'node' corresponds to an identifier defined as a |
| 1070 | * function-like macro, it is not followed with a parenthesized |
| 1071 | * argument list). |
| 1072 | * |
| 1073 | * Compute the complete expansion of node (which is a function-like |
| 1074 | * macro) and subsequent nodes which are arguments. |
| 1075 | * |
| 1076 | * Returns the token list that results from the expansion and sets |
| 1077 | * *last to the last node in the list that was consumed by the |
| 1078 | * expansion. Specificallty, *last will be set as follows: as the |
| 1079 | * token of the closing right parenthesis. |
| 1080 | */ |
| 1081 | static token_list_t * |
| 1082 | _glcpp_parser_expand_function (glcpp_parser_t *parser, |
| 1083 | token_node_t *node, |
| 1084 | token_node_t **last) |
| 1085 | |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1086 | { |
| 1087 | macro_t *macro; |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1088 | const char *identifier; |
| 1089 | argument_list_t *arguments; |
| 1090 | function_status_t status; |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 1091 | token_list_t *substituted; |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1092 | int parameter_index; |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1093 | |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1094 | identifier = node->token->value.str; |
| 1095 | |
| 1096 | macro = hash_table_find (parser->defines, identifier); |
| 1097 | |
| 1098 | assert (macro->is_function); |
| 1099 | |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1100 | arguments = _argument_list_create (parser); |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1101 | status = _arguments_parse (arguments, node, last); |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1102 | |
| 1103 | switch (status) { |
| 1104 | case FUNCTION_STATUS_SUCCESS: |
| 1105 | break; |
| 1106 | case FUNCTION_NOT_A_FUNCTION: |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1107 | return NULL; |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 1108 | case FUNCTION_UNBALANCED_PARENTHESES: |
Kenneth Graunke | ca9e5fc | 2010-06-16 17:31:50 -0700 | [diff] [blame] | 1109 | glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier); |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1110 | return NULL; |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1113 | if (macro->replacements == NULL) { |
| 1114 | talloc_free (arguments); |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1115 | return _token_list_create (parser); |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
Carl Worth | a19297b | 2010-05-27 13:29:19 -0700 | [diff] [blame] | 1118 | if (! ((_argument_list_length (arguments) == |
| 1119 | _string_list_length (macro->parameters)) || |
| 1120 | (_string_list_length (macro->parameters) == 0 && |
| 1121 | _argument_list_length (arguments) == 1 && |
| 1122 | arguments->head->argument->head == NULL))) |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1123 | { |
Kenneth Graunke | ca9e5fc | 2010-06-16 17:31:50 -0700 | [diff] [blame] | 1124 | glcpp_error (&node->token->location, parser, |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 1125 | "Error: macro %s invoked with %d arguments (expected %d)\n", |
| 1126 | identifier, |
| 1127 | _argument_list_length (arguments), |
| 1128 | _string_list_length (macro->parameters)); |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1129 | return NULL; |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 1132 | /* Perform argument substitution on the replacement list. */ |
| 1133 | substituted = _token_list_create (arguments); |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1134 | |
Carl Worth | ce540f2 | 2010-05-26 08:25:44 -0700 | [diff] [blame] | 1135 | for (node = macro->replacements->head; node; node = node->next) |
| 1136 | { |
| 1137 | if (node->token->type == IDENTIFIER && |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1138 | _string_list_contains (macro->parameters, |
Carl Worth | ce540f2 | 2010-05-26 08:25:44 -0700 | [diff] [blame] | 1139 | node->token->value.str, |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1140 | ¶meter_index)) |
| 1141 | { |
| 1142 | token_list_t *argument; |
| 1143 | argument = _argument_list_member_at (arguments, |
| 1144 | parameter_index); |
Carl Worth | d5cd403 | 2010-05-26 08:09:29 -0700 | [diff] [blame] | 1145 | /* Before substituting, we expand the argument |
Carl Worth | 85b50e8 | 2010-05-27 14:01:18 -0700 | [diff] [blame] | 1146 | * tokens, or append a placeholder token for |
| 1147 | * an empty argument. */ |
| 1148 | if (argument->head) { |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1149 | _glcpp_parser_expand_token_list (parser, |
| 1150 | argument); |
| 1151 | _token_list_append_list (substituted, argument); |
Carl Worth | 85b50e8 | 2010-05-27 14:01:18 -0700 | [diff] [blame] | 1152 | } else { |
| 1153 | token_t *new_token; |
| 1154 | |
| 1155 | new_token = _token_create_ival (substituted, |
| 1156 | PLACEHOLDER, |
| 1157 | PLACEHOLDER); |
| 1158 | _token_list_append (substituted, new_token); |
| 1159 | } |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1160 | } else { |
Carl Worth | ce540f2 | 2010-05-26 08:25:44 -0700 | [diff] [blame] | 1161 | _token_list_append (substituted, node->token); |
Carl Worth | 9ce18cf | 2010-05-25 17:32:21 -0700 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 1165 | /* After argument substitution, and before further expansion |
| 1166 | * below, implement token pasting. */ |
| 1167 | |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 1168 | _token_list_trim_trailing_space (substituted); |
| 1169 | |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 1170 | node = substituted->head; |
| 1171 | while (node) |
| 1172 | { |
| 1173 | token_node_t *next_non_space; |
| 1174 | |
| 1175 | /* Look ahead for a PASTE token, skipping space. */ |
| 1176 | next_non_space = node->next; |
| 1177 | while (next_non_space && next_non_space->token->type == SPACE) |
| 1178 | next_non_space = next_non_space->next; |
| 1179 | |
| 1180 | if (next_non_space == NULL) |
| 1181 | break; |
| 1182 | |
| 1183 | if (next_non_space->token->type != PASTE) { |
| 1184 | node = next_non_space; |
| 1185 | continue; |
| 1186 | } |
| 1187 | |
| 1188 | /* Now find the next non-space token after the PASTE. */ |
| 1189 | next_non_space = next_non_space->next; |
| 1190 | while (next_non_space && next_non_space->token->type == SPACE) |
| 1191 | next_non_space = next_non_space->next; |
| 1192 | |
| 1193 | if (next_non_space == NULL) { |
Kenneth Graunke | ca9e5fc | 2010-06-16 17:31:50 -0700 | [diff] [blame] | 1194 | yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n"); |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1195 | return NULL; |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 1198 | node->token = _token_paste (parser, node->token, next_non_space->token); |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 1199 | node->next = next_non_space->next; |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 1200 | if (next_non_space == substituted->tail) |
| 1201 | substituted->tail = node; |
Carl Worth | ad0dee6 | 2010-05-26 09:04:50 -0700 | [diff] [blame] | 1202 | |
| 1203 | node = node->next; |
| 1204 | } |
| 1205 | |
Carl Worth | b06096e | 2010-05-29 05:54:19 -0700 | [diff] [blame] | 1206 | substituted->non_space_tail = substituted->tail; |
| 1207 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1208 | return substituted; |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1211 | /* Compute the complete expansion of node, (and subsequent nodes after |
| 1212 | * 'node' in the case that 'node' is a function-like macro and |
| 1213 | * subsequent nodes are arguments). |
| 1214 | * |
| 1215 | * Returns NULL if node is a simple token with no expansion. |
| 1216 | * |
| 1217 | * Otherwise, returns the token list that results from the expansion |
| 1218 | * and sets *last to the last node in the list that was consumed by |
| 1219 | * the expansion. Specificallty, *last will be set as follows: |
| 1220 | * |
| 1221 | * As 'node' in the case of object-like macro expansion. |
| 1222 | * |
| 1223 | * As the token of the closing right parenthesis in the case of |
| 1224 | * function-like macro expansion. |
| 1225 | */ |
| 1226 | static token_list_t * |
| 1227 | _glcpp_parser_expand_node (glcpp_parser_t *parser, |
| 1228 | token_node_t *node, |
| 1229 | token_node_t **last) |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1230 | { |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1231 | token_t *token = node->token; |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1232 | const char *identifier; |
| 1233 | macro_t *macro; |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1234 | |
| 1235 | /* We only expand identifiers */ |
| 1236 | if (token->type != IDENTIFIER) { |
| 1237 | /* We change any COMMA into a COMMA_FINAL to prevent |
| 1238 | * it being mistaken for an argument separator |
| 1239 | * later. */ |
| 1240 | if (token->type == ',') { |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1241 | token->type = COMMA_FINAL; |
| 1242 | token->value.ival = COMMA_FINAL; |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1243 | } |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1244 | |
| 1245 | return NULL; |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | /* Look up this identifier in the hash table. */ |
| 1249 | identifier = token->value.str; |
| 1250 | macro = hash_table_find (parser->defines, identifier); |
| 1251 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1252 | /* Not a macro, so no expansion needed. */ |
| 1253 | if (macro == NULL) |
| 1254 | return NULL; |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1255 | |
| 1256 | /* Finally, don't expand this macro if we're already actively |
| 1257 | * expanding it, (to avoid infinite recursion). */ |
Carl Worth | 22b3ace | 2010-06-02 15:32:03 -0700 | [diff] [blame] | 1258 | if (_active_list_contains (parser->active, identifier)) { |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1259 | /* We change the token type here from IDENTIFIER to |
| 1260 | * OTHER to prevent any future expansion of this |
| 1261 | * unexpanded token. */ |
| 1262 | char *str; |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1263 | token_list_t *expansion; |
| 1264 | token_t *final; |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1265 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1266 | str = xtalloc_strdup (parser, token->value.str); |
| 1267 | final = _token_create_str (parser, OTHER, str); |
| 1268 | expansion = _token_list_create (parser); |
| 1269 | _token_list_append (expansion, final); |
| 1270 | *last = node; |
| 1271 | return expansion; |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1274 | if (! macro->is_function) |
| 1275 | { |
| 1276 | *last = node; |
| 1277 | |
| 1278 | if (macro->replacements == NULL) |
| 1279 | return _token_list_create (parser); |
| 1280 | |
Carl Worth | 22b3ace | 2010-06-02 15:32:03 -0700 | [diff] [blame] | 1281 | return _token_list_copy (parser, macro->replacements); |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1282 | } |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1283 | |
| 1284 | return _glcpp_parser_expand_function (parser, node, last); |
| 1285 | } |
| 1286 | |
Carl Worth | 22b3ace | 2010-06-02 15:32:03 -0700 | [diff] [blame] | 1287 | /* Push a new identifier onto the active list, returning the new list. |
| 1288 | * |
| 1289 | * Here, 'marker' is the token node that appears in the list after the |
| 1290 | * expansion of 'identifier'. That is, when the list iterator begins |
| 1291 | * examinging 'marker', then it is time to pop this node from the |
| 1292 | * active stack. |
| 1293 | */ |
| 1294 | active_list_t * |
| 1295 | _active_list_push (active_list_t *list, |
| 1296 | const char *identifier, |
| 1297 | token_node_t *marker) |
| 1298 | { |
| 1299 | active_list_t *node; |
| 1300 | |
| 1301 | node = xtalloc (list, active_list_t); |
| 1302 | node->identifier = xtalloc_strdup (node, identifier); |
| 1303 | node->marker = marker; |
| 1304 | node->next = list; |
| 1305 | |
| 1306 | return node; |
| 1307 | } |
| 1308 | |
| 1309 | active_list_t * |
| 1310 | _active_list_pop (active_list_t *list) |
| 1311 | { |
| 1312 | active_list_t *node = list; |
| 1313 | |
| 1314 | if (node == NULL) |
| 1315 | return NULL; |
| 1316 | |
| 1317 | node = list->next; |
| 1318 | talloc_free (list); |
| 1319 | |
| 1320 | return node; |
| 1321 | } |
| 1322 | |
| 1323 | int |
| 1324 | _active_list_contains (active_list_t *list, const char *identifier) |
| 1325 | { |
| 1326 | active_list_t *node; |
| 1327 | |
| 1328 | if (list == NULL) |
| 1329 | return 0; |
| 1330 | |
| 1331 | for (node = list; node; node = node->next) |
| 1332 | if (strcmp (node->identifier, identifier) == 0) |
| 1333 | return 1; |
| 1334 | |
| 1335 | return 0; |
| 1336 | } |
| 1337 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1338 | /* Walk over the token list replacing nodes with their expansion. |
| 1339 | * Whenever nodes are expanded the walking will walk over the new |
| 1340 | * nodes, continuing to expand as necessary. The results are placed in |
| 1341 | * 'list' itself; |
| 1342 | */ |
| 1343 | static void |
| 1344 | _glcpp_parser_expand_token_list (glcpp_parser_t *parser, |
| 1345 | token_list_t *list) |
| 1346 | { |
| 1347 | token_node_t *node_prev; |
| 1348 | token_node_t *node, *last; |
| 1349 | token_list_t *expansion; |
| 1350 | |
| 1351 | if (list == NULL) |
| 1352 | return; |
| 1353 | |
| 1354 | _token_list_trim_trailing_space (list); |
| 1355 | |
| 1356 | node_prev = NULL; |
| 1357 | node = list->head; |
| 1358 | |
| 1359 | while (node) { |
Carl Worth | 22b3ace | 2010-06-02 15:32:03 -0700 | [diff] [blame] | 1360 | |
| 1361 | while (parser->active && parser->active->marker == node) |
| 1362 | parser->active = _active_list_pop (parser->active); |
| 1363 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1364 | /* Find the expansion for node, which will replace all |
| 1365 | * nodes from node to last, inclusive. */ |
| 1366 | expansion = _glcpp_parser_expand_node (parser, node, &last); |
| 1367 | if (expansion) { |
Carl Worth | 22b3ace | 2010-06-02 15:32:03 -0700 | [diff] [blame] | 1368 | token_node_t *n; |
| 1369 | |
| 1370 | for (n = node; n != last->next; n = n->next) |
| 1371 | while (parser->active && |
| 1372 | parser->active->marker == n) |
| 1373 | { |
| 1374 | parser->active = _active_list_pop (parser->active); |
| 1375 | } |
| 1376 | |
| 1377 | parser->active = _active_list_push (parser->active, |
| 1378 | node->token->value.str, |
| 1379 | last->next); |
| 1380 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1381 | /* Splice expansion into list, supporting a |
| 1382 | * simple deletion if the expansion is |
| 1383 | * empty. */ |
| 1384 | if (expansion->head) { |
| 1385 | if (node_prev) |
| 1386 | node_prev->next = expansion->head; |
| 1387 | else |
| 1388 | list->head = expansion->head; |
| 1389 | expansion->tail->next = last->next; |
| 1390 | if (last == list->tail) |
| 1391 | list->tail = expansion->tail; |
| 1392 | } else { |
| 1393 | if (node_prev) |
| 1394 | node_prev->next = last->next; |
| 1395 | else |
| 1396 | list->head = last->next; |
| 1397 | if (last == list->tail) |
Kenneth Graunke | 0656f6b | 2010-06-16 11:56:36 -0700 | [diff] [blame] | 1398 | list->tail = NULL; |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1399 | } |
| 1400 | } else { |
| 1401 | node_prev = node; |
| 1402 | } |
| 1403 | node = node_prev ? node_prev->next : list->head; |
| 1404 | } |
| 1405 | |
Carl Worth | 22b3ace | 2010-06-02 15:32:03 -0700 | [diff] [blame] | 1406 | while (parser->active) |
| 1407 | parser->active = _active_list_pop (parser->active); |
| 1408 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1409 | list->non_space_tail = list->tail; |
Carl Worth | 3c93d39 | 2010-05-28 08:17:46 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 1412 | void |
| 1413 | _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser, |
| 1414 | token_list_t *list) |
| 1415 | { |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 1416 | if (list == NULL) |
| 1417 | return; |
| 1418 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1419 | _glcpp_parser_expand_token_list (parser, list); |
Carl Worth | 10ae438 | 2010-05-25 20:35:01 -0700 | [diff] [blame] | 1420 | |
Carl Worth | 681afbc | 2010-05-28 15:06:02 -0700 | [diff] [blame] | 1421 | _token_list_trim_trailing_space (list); |
Carl Worth | 0197e9b | 2010-05-26 08:05:19 -0700 | [diff] [blame] | 1422 | |
Kenneth Graunke | 4c8a1af | 2010-06-16 11:57:48 -0700 | [diff] [blame] | 1423 | _token_list_print (parser, list); |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | void |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 1427 | _check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc, |
| 1428 | const char *identifier) |
Kenneth Graunke | 2ab0b13 | 2010-06-04 14:53:58 -0700 | [diff] [blame] | 1429 | { |
| 1430 | /* According to the GLSL specification, macro names starting with "__" |
| 1431 | * or "GL_" are reserved for future use. So, don't allow them. |
| 1432 | */ |
| 1433 | if (strncmp(identifier, "__", 2) == 0) { |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 1434 | glcpp_error (loc, parser, "Macro names starting with \"__\" are reserved.\n"); |
Kenneth Graunke | 2ab0b13 | 2010-06-04 14:53:58 -0700 | [diff] [blame] | 1435 | } |
| 1436 | if (strncmp(identifier, "GL_", 3) == 0) { |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 1437 | glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n"); |
Kenneth Graunke | 2ab0b13 | 2010-06-04 14:53:58 -0700 | [diff] [blame] | 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | void |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 1442 | _define_object_macro (glcpp_parser_t *parser, |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 1443 | YYLTYPE *loc, |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 1444 | const char *identifier, |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 1445 | token_list_t *replacements) |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 1446 | { |
| 1447 | macro_t *macro; |
| 1448 | |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 1449 | _check_for_reserved_macro_name(parser, loc, identifier); |
Kenneth Graunke | 2ab0b13 | 2010-06-04 14:53:58 -0700 | [diff] [blame] | 1450 | |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 1451 | macro = xtalloc (parser, macro_t); |
| 1452 | |
| 1453 | macro->is_function = 0; |
Carl Worth | c5e9855 | 2010-05-14 10:12:21 -0700 | [diff] [blame] | 1454 | macro->parameters = NULL; |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 1455 | macro->identifier = talloc_strdup (macro, identifier); |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 1456 | macro->replacements = talloc_steal (macro, replacements); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 1457 | |
| 1458 | hash_table_insert (parser->defines, macro, identifier); |
| 1459 | } |
| 1460 | |
| 1461 | void |
| 1462 | _define_function_macro (glcpp_parser_t *parser, |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 1463 | YYLTYPE *loc, |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 1464 | const char *identifier, |
Carl Worth | c5e9855 | 2010-05-14 10:12:21 -0700 | [diff] [blame] | 1465 | string_list_t *parameters, |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 1466 | token_list_t *replacements) |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 1467 | { |
| 1468 | macro_t *macro; |
| 1469 | |
Kenneth Graunke | dcdf62f | 2010-06-17 12:21:53 -0700 | [diff] [blame] | 1470 | _check_for_reserved_macro_name(parser, loc, identifier); |
Kenneth Graunke | 2ab0b13 | 2010-06-04 14:53:58 -0700 | [diff] [blame] | 1471 | |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 1472 | macro = xtalloc (parser, macro_t); |
| 1473 | |
| 1474 | macro->is_function = 1; |
Carl Worth | c5e9855 | 2010-05-14 10:12:21 -0700 | [diff] [blame] | 1475 | macro->parameters = talloc_steal (macro, parameters); |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 1476 | macro->identifier = talloc_strdup (macro, identifier); |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 1477 | macro->replacements = talloc_steal (macro, replacements); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 1478 | |
| 1479 | hash_table_insert (parser->defines, macro, identifier); |
| 1480 | } |
| 1481 | |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 1482 | static int |
Kenneth Graunke | 465e03e | 2010-06-16 16:35:57 -0700 | [diff] [blame] | 1483 | glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser) |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 1484 | { |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 1485 | token_node_t *node; |
| 1486 | int ret; |
| 1487 | |
Carl Worth | 95951ea | 2010-05-26 15:57:10 -0700 | [diff] [blame] | 1488 | if (parser->lex_from_list == NULL) { |
Kenneth Graunke | 465e03e | 2010-06-16 16:35:57 -0700 | [diff] [blame] | 1489 | ret = glcpp_lex (yylval, yylloc, parser->scanner); |
Carl Worth | 95951ea | 2010-05-26 15:57:10 -0700 | [diff] [blame] | 1490 | |
| 1491 | /* XXX: This ugly block of code exists for the sole |
| 1492 | * purpose of converting a NEWLINE token into a SPACE |
| 1493 | * token, but only in the case where we have seen a |
| 1494 | * function-like macro name, but have not yet seen its |
| 1495 | * closing parenthesis. |
| 1496 | * |
| 1497 | * There's perhaps a more compact way to do this with |
| 1498 | * mid-rule actions in the grammar. |
| 1499 | * |
| 1500 | * I'm definitely not pleased with the complexity of |
| 1501 | * this code here. |
| 1502 | */ |
| 1503 | if (parser->newline_as_space) |
| 1504 | { |
| 1505 | if (ret == '(') { |
| 1506 | parser->paren_count++; |
| 1507 | } else if (ret == ')') { |
| 1508 | parser->paren_count--; |
| 1509 | if (parser->paren_count == 0) |
| 1510 | parser->newline_as_space = 0; |
| 1511 | } else if (ret == NEWLINE) { |
| 1512 | ret = SPACE; |
| 1513 | } else if (ret != SPACE) { |
| 1514 | if (parser->paren_count == 0) |
| 1515 | parser->newline_as_space = 0; |
| 1516 | } |
| 1517 | } |
| 1518 | else if (parser->in_control_line) |
| 1519 | { |
| 1520 | if (ret == NEWLINE) |
| 1521 | parser->in_control_line = 0; |
| 1522 | } |
| 1523 | else if (ret == HASH_DEFINE_OBJ || ret == HASH_DEFINE_FUNC || |
| 1524 | ret == HASH_UNDEF || ret == HASH_IF || |
| 1525 | ret == HASH_IFDEF || ret == HASH_IFNDEF || |
| 1526 | ret == HASH_ELIF || ret == HASH_ELSE || |
| 1527 | ret == HASH_ENDIF || ret == HASH) |
| 1528 | { |
| 1529 | parser->in_control_line = 1; |
| 1530 | } |
| 1531 | else if (ret == IDENTIFIER) |
| 1532 | { |
| 1533 | macro_t *macro; |
| 1534 | macro = hash_table_find (parser->defines, |
Kenneth Graunke | e0e429f | 2010-06-16 16:26:28 -0700 | [diff] [blame] | 1535 | yylval->str); |
Carl Worth | 95951ea | 2010-05-26 15:57:10 -0700 | [diff] [blame] | 1536 | if (macro && macro->is_function) { |
| 1537 | parser->newline_as_space = 1; |
| 1538 | parser->paren_count = 0; |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | return ret; |
| 1543 | } |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 1544 | |
| 1545 | node = parser->lex_from_node; |
| 1546 | |
| 1547 | if (node == NULL) { |
| 1548 | talloc_free (parser->lex_from_list); |
| 1549 | parser->lex_from_list = NULL; |
| 1550 | return NEWLINE; |
| 1551 | } |
| 1552 | |
Kenneth Graunke | e0e429f | 2010-06-16 16:26:28 -0700 | [diff] [blame] | 1553 | *yylval = node->token->value; |
Carl Worth | 8e82fcb | 2010-05-26 11:15:21 -0700 | [diff] [blame] | 1554 | ret = node->token->type; |
| 1555 | |
| 1556 | parser->lex_from_node = node->next; |
| 1557 | |
| 1558 | return ret; |
| 1559 | } |
| 1560 | |
| 1561 | static void |
| 1562 | glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list) |
| 1563 | { |
| 1564 | token_node_t *node; |
| 1565 | |
| 1566 | assert (parser->lex_from_list == NULL); |
| 1567 | |
| 1568 | /* Copy list, eliminating any space tokens. */ |
| 1569 | parser->lex_from_list = _token_list_create (parser); |
| 1570 | |
| 1571 | for (node = list->head; node; node = node->next) { |
| 1572 | if (node->token->type == SPACE) |
| 1573 | continue; |
| 1574 | _token_list_append (parser->lex_from_list, node->token); |
| 1575 | } |
| 1576 | |
| 1577 | talloc_free (list); |
| 1578 | |
| 1579 | parser->lex_from_node = parser->lex_from_list->head; |
| 1580 | |
| 1581 | /* It's possible the list consisted of nothing but whitespace. */ |
| 1582 | if (parser->lex_from_node == NULL) { |
| 1583 | talloc_free (parser->lex_from_list); |
| 1584 | parser->lex_from_list = NULL; |
| 1585 | } |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 1586 | } |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 1587 | |
| 1588 | static void |
Kenneth Graunke | 0774523 | 2010-06-17 12:41:46 -0700 | [diff] [blame] | 1589 | _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc, |
| 1590 | int condition) |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 1591 | { |
| 1592 | skip_type_t current = SKIP_NO_SKIP; |
| 1593 | skip_node_t *node; |
| 1594 | |
| 1595 | if (parser->skip_stack) |
| 1596 | current = parser->skip_stack->type; |
| 1597 | |
| 1598 | node = xtalloc (parser, skip_node_t); |
Kenneth Graunke | 0774523 | 2010-06-17 12:41:46 -0700 | [diff] [blame] | 1599 | node->loc = *loc; |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 1600 | |
| 1601 | if (current == SKIP_NO_SKIP) { |
| 1602 | if (condition) |
| 1603 | node->type = SKIP_NO_SKIP; |
| 1604 | else |
| 1605 | node->type = SKIP_TO_ELSE; |
| 1606 | } else { |
| 1607 | node->type = SKIP_TO_ENDIF; |
| 1608 | } |
| 1609 | |
| 1610 | node->next = parser->skip_stack; |
| 1611 | parser->skip_stack = node; |
| 1612 | } |
| 1613 | |
| 1614 | static void |
Kenneth Graunke | 8a132aa | 2010-06-17 12:30:57 -0700 | [diff] [blame] | 1615 | _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc, |
| 1616 | const char *type, int condition) |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 1617 | { |
| 1618 | if (parser->skip_stack == NULL) { |
Kenneth Graunke | 8a132aa | 2010-06-17 12:30:57 -0700 | [diff] [blame] | 1619 | glcpp_error (loc, parser, "%s without #if\n", type); |
Kenneth Graunke | e8e93a4 | 2010-06-17 12:58:54 -0700 | [diff] [blame] | 1620 | return; |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | if (parser->skip_stack->type == SKIP_TO_ELSE) { |
| 1624 | if (condition) |
| 1625 | parser->skip_stack->type = SKIP_NO_SKIP; |
| 1626 | } else { |
| 1627 | parser->skip_stack->type = SKIP_TO_ENDIF; |
| 1628 | } |
| 1629 | } |
Carl Worth | 80dc60b | 2010-05-25 14:42:00 -0700 | [diff] [blame] | 1630 | |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 1631 | static void |
Kenneth Graunke | 8a132aa | 2010-06-17 12:30:57 -0700 | [diff] [blame] | 1632 | _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc) |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 1633 | { |
| 1634 | skip_node_t *node; |
| 1635 | |
| 1636 | if (parser->skip_stack == NULL) { |
Kenneth Graunke | 8a132aa | 2010-06-17 12:30:57 -0700 | [diff] [blame] | 1637 | glcpp_error (loc, parser, "#endif without #if\n"); |
Kenneth Graunke | e8e93a4 | 2010-06-17 12:58:54 -0700 | [diff] [blame] | 1638 | return; |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | node = parser->skip_stack; |
| 1642 | parser->skip_stack = node->next; |
| 1643 | talloc_free (node); |
| 1644 | } |