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 | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 28 | |
Carl Worth | a1e32bc | 2010-05-10 13:17:25 -0700 | [diff] [blame] | 29 | #include "glcpp.h" |
| 30 | |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 31 | void |
Carl Worth | a1e32bc | 2010-05-10 13:17:25 -0700 | [diff] [blame] | 32 | yyerror (void *scanner, const char *error); |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 33 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 34 | void |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 35 | _define_object_macro (glcpp_parser_t *parser, |
| 36 | const char *macro, |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 37 | token_list_t *replacements); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 38 | |
| 39 | void |
| 40 | _define_function_macro (glcpp_parser_t *parser, |
| 41 | const char *macro, |
Carl Worth | c5e9855 | 2010-05-14 10:12:21 -0700 | [diff] [blame] | 42 | string_list_t *parameters, |
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 | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 45 | void |
Carl Worth | 2be8be0 | 2010-05-14 10:31:43 -0700 | [diff] [blame] | 46 | _expand_object_macro (glcpp_parser_t *parser, const char *identifier); |
| 47 | |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 48 | void |
Carl Worth | 2be8be0 | 2010-05-14 10:31:43 -0700 | [diff] [blame] | 49 | _expand_function_macro (glcpp_parser_t *parser, |
| 50 | const char *identifier, |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 51 | argument_list_t *arguments); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 52 | |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 53 | string_list_t * |
| 54 | _string_list_create (void *ctx); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 55 | |
| 56 | void |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 57 | _string_list_append_item (string_list_t *list, const char *str); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 58 | |
| 59 | void |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 60 | _string_list_append_list (string_list_t *list, string_list_t *tail); |
Carl Worth | c6d5af3 | 2010-05-11 12:30:09 -0700 | [diff] [blame] | 61 | |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 62 | void |
| 63 | _string_list_push (string_list_t *list, const char *str); |
| 64 | |
| 65 | void |
| 66 | _string_list_pop (string_list_t *list); |
| 67 | |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 68 | int |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 69 | _string_list_contains (string_list_t *list, const char *member, int *index); |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 70 | |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 71 | int |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 72 | _string_list_length (string_list_t *list); |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 73 | |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 74 | argument_list_t * |
| 75 | _argument_list_create (void *ctx); |
| 76 | |
| 77 | void |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 78 | _argument_list_append (argument_list_t *list, token_list_t *argument); |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 79 | |
| 80 | int |
| 81 | _argument_list_length (argument_list_t *list); |
| 82 | |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 83 | token_list_t * |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 84 | _argument_list_member_at (argument_list_t *list, int index); |
| 85 | |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 86 | /* Note: This function talloc_steal()s the str pointer. */ |
| 87 | token_t * |
| 88 | _token_create_str (void *ctx, int type, char *str); |
| 89 | |
| 90 | token_t * |
| 91 | _token_create_ival (void *ctx, int type, int ival); |
| 92 | |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 93 | token_list_t * |
| 94 | _token_list_create (void *ctx); |
| 95 | |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 96 | /* Note: This function add a talloc_reference() to token. |
| 97 | * |
| 98 | * You may want to talloc_unlink any current reference if you no |
| 99 | * longer need it. */ |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 100 | void |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 101 | _token_list_append (token_list_t *list, token_t *token); |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 102 | |
| 103 | void |
| 104 | _token_list_append_list (token_list_t *list, token_list_t *tail); |
| 105 | |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 106 | void |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 107 | _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser, |
| 108 | token_list_t *list); |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 109 | |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 110 | static void |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 111 | glcpp_parser_pop_expansion (glcpp_parser_t *parser); |
| 112 | |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 113 | static void |
| 114 | _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, int condition); |
| 115 | |
| 116 | static void |
| 117 | _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, const char *type, |
| 118 | int condition); |
Carl Worth | 80dc60b | 2010-05-25 14:42:00 -0700 | [diff] [blame] | 119 | |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 120 | static void |
| 121 | _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser); |
| 122 | |
Carl Worth | 0293b2e | 2010-05-19 10:05:40 -0700 | [diff] [blame] | 123 | #define yylex glcpp_parser_lex |
| 124 | |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 125 | static int |
Carl Worth | 0293b2e | 2010-05-19 10:05:40 -0700 | [diff] [blame] | 126 | glcpp_parser_lex (glcpp_parser_t *parser); |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 127 | |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 128 | %} |
| 129 | |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 130 | %parse-param {glcpp_parser_t *parser} |
Carl Worth | 0293b2e | 2010-05-19 10:05:40 -0700 | [diff] [blame] | 131 | %lex-param {glcpp_parser_t *parser} |
Carl Worth | 38aa835 | 2010-05-10 11:52:29 -0700 | [diff] [blame] | 132 | |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 133 | %token HASH HASH_DEFINE_FUNC HASH_DEFINE_OBJ HASH_UNDEF IDENTIFIER NEWLINE OTHER SPACE |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 134 | %token LEFT_SHIFT RIGHT_SHIFT LESS_OR_EQUAL GREATER_OR_EQUAL EQUAL NOT_EQUAL AND OR PASTE |
Carl Worth | e939786 | 2010-05-25 17:08:07 -0700 | [diff] [blame^] | 135 | %type <ival> punctuator SPACE |
| 136 | %type <str> IDENTIFIER OTHER |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 137 | %type <string_list> identifier_list |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 138 | %type <token> preprocessing_token |
| 139 | %type <token_list> pp_tokens replacement_list text_line |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 140 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 141 | /* Stale stuff just to allow code to compile. */ |
| 142 | %token IDENTIFIER_FINALIZED FUNC_MACRO OBJ_MACRO |
Carl Worth | 796e1f0 | 2010-05-17 12:45:16 -0700 | [diff] [blame] | 143 | |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 144 | %% |
| 145 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 146 | input: |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 147 | /* empty */ |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 148 | | input line { |
| 149 | printf ("\n"); |
| 150 | } |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 151 | ; |
| 152 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 153 | line: |
| 154 | control_line |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 155 | | text_line { |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 156 | _glcpp_parser_print_expanded_token_list (parser, $1); |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 157 | talloc_free ($1); |
| 158 | } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 159 | | HASH non_directive |
Carl Worth | cd27e64 | 2010-05-12 13:11:50 -0700 | [diff] [blame] | 160 | ; |
| 161 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 162 | control_line: |
Carl Worth | f34a000 | 2010-05-25 16:59:02 -0700 | [diff] [blame] | 163 | HASH_DEFINE_OBJ IDENTIFIER replacement_list NEWLINE { |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 164 | _define_object_macro (parser, $2, $3); |
| 165 | } |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 166 | | HASH_DEFINE_FUNC IDENTIFIER '(' ')' replacement_list NEWLINE { |
| 167 | _define_function_macro (parser, $2, NULL, $5); |
| 168 | } |
| 169 | | HASH_DEFINE_FUNC IDENTIFIER '(' identifier_list ')' replacement_list NEWLINE { |
| 170 | _define_function_macro (parser, $2, $4, $6); |
| 171 | } |
Carl Worth | e6fb782 | 2010-05-25 15:28:58 -0700 | [diff] [blame] | 172 | | HASH_UNDEF IDENTIFIER NEWLINE { |
| 173 | string_list_t *macro = hash_table_find (parser->defines, $2); |
| 174 | if (macro) { |
| 175 | /* XXX: Need hash table to support a real way |
| 176 | * to remove an element rather than prefixing |
| 177 | * a new node with data of NULL like this. */ |
| 178 | hash_table_insert (parser->defines, NULL, $2); |
| 179 | talloc_free (macro); |
| 180 | } |
| 181 | talloc_free ($2); |
| 182 | } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 183 | | HASH NEWLINE |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 184 | ; |
| 185 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 186 | identifier_list: |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 187 | IDENTIFIER { |
| 188 | $$ = _string_list_create (parser); |
| 189 | _string_list_append_item ($$, $1); |
| 190 | talloc_steal ($$, $1); |
| 191 | } |
| 192 | | identifier_list ',' IDENTIFIER { |
| 193 | $$ = $1; |
| 194 | _string_list_append_item ($$, $3); |
| 195 | talloc_steal ($$, $3); |
| 196 | } |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 197 | ; |
| 198 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 199 | text_line: |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 200 | NEWLINE { $$ = NULL; } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 201 | | pp_tokens NEWLINE |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 202 | ; |
| 203 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 204 | non_directive: |
| 205 | pp_tokens NEWLINE |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 206 | ; |
| 207 | |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 208 | replacement_list: |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 209 | /* empty */ { $$ = NULL; } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 210 | | pp_tokens |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 211 | ; |
| 212 | |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 213 | pp_tokens: |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 214 | preprocessing_token { |
Carl Worth | f34a000 | 2010-05-25 16:59:02 -0700 | [diff] [blame] | 215 | parser->space_tokens = 1; |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 216 | $$ = _token_list_create (parser); |
| 217 | _token_list_append ($$, $1); |
| 218 | talloc_unlink (parser, $1); |
| 219 | } |
| 220 | | pp_tokens preprocessing_token { |
| 221 | $$ = $1; |
| 222 | _token_list_append ($$, $2); |
| 223 | talloc_unlink (parser, $2); |
| 224 | } |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 225 | ; |
| 226 | |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 227 | preprocessing_token: |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 228 | IDENTIFIER { |
| 229 | $$ = _token_create_str (parser, IDENTIFIER, $1); |
| 230 | } |
| 231 | | punctuator { |
| 232 | $$ = _token_create_ival (parser, $1, $1); |
| 233 | } |
| 234 | | OTHER { |
| 235 | $$ = _token_create_str (parser, OTHER, $1); |
| 236 | } |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 237 | | SPACE { |
Carl Worth | e939786 | 2010-05-25 17:08:07 -0700 | [diff] [blame^] | 238 | $$ = _token_create_ival (parser, SPACE, SPACE); |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 239 | } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 240 | ; |
| 241 | |
| 242 | punctuator: |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 243 | '[' { $$ = '['; } |
| 244 | | ']' { $$ = ']'; } |
| 245 | | '(' { $$ = '('; } |
| 246 | | ')' { $$ = ')'; } |
| 247 | | '{' { $$ = '{'; } |
| 248 | | '}' { $$ = '}'; } |
| 249 | | '.' { $$ = '.'; } |
| 250 | | '&' { $$ = '&'; } |
| 251 | | '*' { $$ = '*'; } |
| 252 | | '+' { $$ = '+'; } |
| 253 | | '-' { $$ = '-'; } |
| 254 | | '~' { $$ = '~'; } |
| 255 | | '!' { $$ = '!'; } |
| 256 | | '/' { $$ = '/'; } |
| 257 | | '%' { $$ = '%'; } |
| 258 | | LEFT_SHIFT { $$ = LEFT_SHIFT; } |
| 259 | | RIGHT_SHIFT { $$ = RIGHT_SHIFT; } |
| 260 | | '<' { $$ = '<'; } |
| 261 | | '>' { $$ = '>'; } |
| 262 | | LESS_OR_EQUAL { $$ = LESS_OR_EQUAL; } |
| 263 | | GREATER_OR_EQUAL { $$ = GREATER_OR_EQUAL; } |
| 264 | | EQUAL { $$ = EQUAL; } |
| 265 | | NOT_EQUAL { $$ = NOT_EQUAL; } |
| 266 | | '^' { $$ = '^'; } |
| 267 | | '|' { $$ = '|'; } |
| 268 | | AND { $$ = AND; } |
| 269 | | OR { $$ = OR; } |
| 270 | | ';' { $$ = ';'; } |
| 271 | | ',' { $$ = ','; } |
| 272 | | PASTE { $$ = PASTE; } |
Carl Worth | 3ff8167 | 2010-05-25 13:09:03 -0700 | [diff] [blame] | 273 | ; |
| 274 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 275 | %% |
| 276 | |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 277 | string_list_t * |
| 278 | _string_list_create (void *ctx) |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 279 | { |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 280 | string_list_t *list; |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 281 | |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 282 | list = xtalloc (ctx, string_list_t); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 283 | list->head = NULL; |
| 284 | list->tail = NULL; |
| 285 | |
| 286 | return list; |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 287 | } |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 288 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 289 | void |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 290 | _string_list_append_list (string_list_t *list, string_list_t *tail) |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 291 | { |
| 292 | if (list->head == NULL) { |
| 293 | list->head = tail->head; |
| 294 | } else { |
| 295 | list->tail->next = tail->head; |
| 296 | } |
| 297 | |
| 298 | list->tail = tail->tail; |
| 299 | } |
| 300 | |
| 301 | void |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 302 | _string_list_append_item (string_list_t *list, const char *str) |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 303 | { |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 304 | string_node_t *node; |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 305 | |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 306 | node = xtalloc (list, string_node_t); |
Carl Worth | 5070a20 | 2010-05-12 12:45:33 -0700 | [diff] [blame] | 307 | node->str = xtalloc_strdup (node, str); |
Carl Worth | 80dc60b | 2010-05-25 14:42:00 -0700 | [diff] [blame] | 308 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 309 | node->next = NULL; |
| 310 | |
| 311 | if (list->head == NULL) { |
| 312 | list->head = node; |
| 313 | } else { |
| 314 | list->tail->next = node; |
| 315 | } |
| 316 | |
| 317 | list->tail = node; |
| 318 | } |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 319 | |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 320 | void |
| 321 | _string_list_push (string_list_t *list, const char *str) |
| 322 | { |
| 323 | string_node_t *node; |
| 324 | |
| 325 | node = xtalloc (list, string_node_t); |
| 326 | node->str = xtalloc_strdup (node, str); |
| 327 | node->next = list->head; |
| 328 | |
| 329 | if (list->tail == NULL) { |
| 330 | list->tail = node; |
| 331 | } |
| 332 | list->head = node; |
| 333 | } |
| 334 | |
| 335 | void |
| 336 | _string_list_pop (string_list_t *list) |
| 337 | { |
| 338 | string_node_t *node; |
| 339 | |
| 340 | node = list->head; |
| 341 | |
| 342 | if (node == NULL) { |
| 343 | fprintf (stderr, "Internal error: _string_list_pop called on an empty list.\n"); |
| 344 | exit (1); |
| 345 | } |
| 346 | |
| 347 | list->head = node->next; |
| 348 | if (list->tail == node) { |
| 349 | assert (node->next == NULL); |
| 350 | list->tail = NULL; |
| 351 | } |
| 352 | |
| 353 | talloc_free (node); |
| 354 | } |
| 355 | |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 356 | int |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 357 | _string_list_contains (string_list_t *list, const char *member, int *index) |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 358 | { |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 359 | string_node_t *node; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 360 | int i; |
| 361 | |
| 362 | if (list == NULL) |
| 363 | return 0; |
| 364 | |
| 365 | for (i = 0, node = list->head; node; i++, node = node->next) { |
| 366 | if (strcmp (node->str, member) == 0) { |
Carl Worth | 420d05a | 2010-05-17 10:15:23 -0700 | [diff] [blame] | 367 | if (index) |
| 368 | *index = i; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 369 | return 1; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | int |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 377 | _string_list_length (string_list_t *list) |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 378 | { |
| 379 | int length = 0; |
Carl Worth | 610053b | 2010-05-14 10:05:11 -0700 | [diff] [blame] | 380 | string_node_t *node; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 381 | |
| 382 | if (list == NULL) |
| 383 | return 0; |
| 384 | |
| 385 | for (node = list->head; node; node = node->next) |
| 386 | length++; |
| 387 | |
| 388 | return length; |
| 389 | } |
| 390 | |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 391 | argument_list_t * |
| 392 | _argument_list_create (void *ctx) |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 393 | { |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 394 | argument_list_t *list; |
| 395 | |
| 396 | list = xtalloc (ctx, argument_list_t); |
| 397 | list->head = NULL; |
| 398 | list->tail = NULL; |
| 399 | |
| 400 | return list; |
| 401 | } |
| 402 | |
| 403 | void |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 404 | _argument_list_append (argument_list_t *list, token_list_t *argument) |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 405 | { |
| 406 | argument_node_t *node; |
| 407 | |
| 408 | if (argument == NULL || argument->head == NULL) |
| 409 | return; |
| 410 | |
| 411 | node = xtalloc (list, argument_node_t); |
| 412 | node->argument = argument; |
| 413 | |
| 414 | node->next = NULL; |
| 415 | |
| 416 | if (list->head == NULL) { |
| 417 | list->head = node; |
| 418 | } else { |
| 419 | list->tail->next = node; |
| 420 | } |
| 421 | |
| 422 | list->tail = node; |
| 423 | } |
| 424 | |
| 425 | int |
| 426 | _argument_list_length (argument_list_t *list) |
| 427 | { |
| 428 | int length = 0; |
| 429 | argument_node_t *node; |
| 430 | |
| 431 | if (list == NULL) |
| 432 | return 0; |
| 433 | |
| 434 | for (node = list->head; node; node = node->next) |
| 435 | length++; |
| 436 | |
| 437 | return length; |
| 438 | } |
| 439 | |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 440 | token_list_t * |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 441 | _argument_list_member_at (argument_list_t *list, int index) |
| 442 | { |
| 443 | argument_node_t *node; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 444 | int i; |
| 445 | |
| 446 | if (list == NULL) |
| 447 | return NULL; |
| 448 | |
| 449 | node = list->head; |
| 450 | for (i = 0; i < index; i++) { |
| 451 | node = node->next; |
| 452 | if (node == NULL) |
| 453 | break; |
| 454 | } |
| 455 | |
| 456 | if (node) |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 457 | return node->argument; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 458 | |
| 459 | return NULL; |
| 460 | } |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 461 | |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 462 | /* Note: This function talloc_steal()s the str pointer. */ |
| 463 | token_t * |
| 464 | _token_create_str (void *ctx, int type, char *str) |
| 465 | { |
| 466 | token_t *token; |
| 467 | |
| 468 | token = xtalloc (ctx, token_t); |
| 469 | token->type = type; |
| 470 | token->value.str = talloc_steal (token, str); |
| 471 | |
| 472 | return token; |
| 473 | } |
| 474 | |
| 475 | token_t * |
| 476 | _token_create_ival (void *ctx, int type, int ival) |
| 477 | { |
| 478 | token_t *token; |
| 479 | |
| 480 | token = xtalloc (ctx, token_t); |
| 481 | token->type = type; |
| 482 | token->value.ival = ival; |
| 483 | |
| 484 | return token; |
| 485 | } |
| 486 | |
| 487 | void |
| 488 | _token_print (token_t *token) |
| 489 | { |
| 490 | if (token->type < 256) { |
| 491 | printf ("%c", token->type); |
| 492 | return; |
| 493 | } |
| 494 | |
| 495 | switch (token->type) { |
| 496 | case IDENTIFIER: |
| 497 | case OTHER: |
| 498 | printf ("%s", token->value.str); |
| 499 | break; |
Carl Worth | e939786 | 2010-05-25 17:08:07 -0700 | [diff] [blame^] | 500 | case SPACE: |
| 501 | printf (" "); |
| 502 | break; |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 503 | case LEFT_SHIFT: |
| 504 | printf ("<<"); |
| 505 | break; |
| 506 | case RIGHT_SHIFT: |
| 507 | printf (">>"); |
| 508 | break; |
| 509 | case LESS_OR_EQUAL: |
| 510 | printf ("<="); |
| 511 | break; |
| 512 | case GREATER_OR_EQUAL: |
| 513 | printf (">="); |
| 514 | break; |
| 515 | case EQUAL: |
| 516 | printf ("=="); |
| 517 | break; |
| 518 | case NOT_EQUAL: |
| 519 | printf ("!="); |
| 520 | break; |
| 521 | case AND: |
| 522 | printf ("&&"); |
| 523 | break; |
| 524 | case OR: |
| 525 | printf ("||"); |
| 526 | break; |
| 527 | case PASTE: |
| 528 | printf ("##"); |
| 529 | break; |
| 530 | default: |
| 531 | fprintf (stderr, "Error: Don't know how to print token type %d\n", token->type); |
| 532 | break; |
| 533 | } |
| 534 | } |
| 535 | |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 536 | token_list_t * |
| 537 | _token_list_create (void *ctx) |
| 538 | { |
| 539 | token_list_t *list; |
| 540 | |
| 541 | list = xtalloc (ctx, token_list_t); |
| 542 | list->head = NULL; |
| 543 | list->tail = NULL; |
| 544 | |
| 545 | return list; |
| 546 | } |
| 547 | |
| 548 | void |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 549 | _token_list_append (token_list_t *list, token_t *token) |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 550 | { |
| 551 | token_node_t *node; |
| 552 | |
| 553 | node = xtalloc (list, token_node_t); |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 554 | node->token = xtalloc_reference (list, token); |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 555 | |
| 556 | node->next = NULL; |
| 557 | |
| 558 | if (list->head == NULL) { |
| 559 | list->head = node; |
| 560 | } else { |
| 561 | list->tail->next = node; |
| 562 | } |
| 563 | |
| 564 | list->tail = node; |
| 565 | } |
| 566 | |
| 567 | void |
| 568 | _token_list_append_list (token_list_t *list, token_list_t *tail) |
| 569 | { |
| 570 | if (list->head == NULL) { |
| 571 | list->head = tail->head; |
| 572 | } else { |
| 573 | list->tail->next = tail->head; |
| 574 | } |
| 575 | |
| 576 | list->tail = tail->tail; |
| 577 | } |
Carl Worth | 80dc60b | 2010-05-25 14:42:00 -0700 | [diff] [blame] | 578 | |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 579 | void |
Carl Worth | a1e32bc | 2010-05-10 13:17:25 -0700 | [diff] [blame] | 580 | yyerror (void *scanner, const char *error) |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 581 | { |
| 582 | fprintf (stderr, "Parse error: %s\n", error); |
| 583 | } |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 584 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 585 | glcpp_parser_t * |
| 586 | glcpp_parser_create (void) |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 587 | { |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 588 | glcpp_parser_t *parser; |
| 589 | |
Carl Worth | 5070a20 | 2010-05-12 12:45:33 -0700 | [diff] [blame] | 590 | parser = xtalloc (NULL, glcpp_parser_t); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 591 | |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 592 | glcpp_lex_init_extra (parser, &parser->scanner); |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 593 | parser->defines = hash_table_ctor (32, hash_table_string_hash, |
| 594 | hash_table_string_compare); |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 595 | parser->active = _string_list_create (parser); |
Carl Worth | f34a000 | 2010-05-25 16:59:02 -0700 | [diff] [blame] | 596 | parser->space_tokens = 1; |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 597 | parser->expansions = NULL; |
| 598 | |
Carl Worth | 5a6b9a2 | 2010-05-20 14:29:43 -0700 | [diff] [blame] | 599 | parser->just_printed_separator = 1; |
Carl Worth | 876e510 | 2010-05-20 14:38:06 -0700 | [diff] [blame] | 600 | parser->need_newline = 0; |
Carl Worth | 5a6b9a2 | 2010-05-20 14:29:43 -0700 | [diff] [blame] | 601 | |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 602 | parser->skip_stack = NULL; |
| 603 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 604 | return parser; |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | int |
| 608 | glcpp_parser_parse (glcpp_parser_t *parser) |
| 609 | { |
| 610 | return yyparse (parser); |
| 611 | } |
| 612 | |
| 613 | void |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 614 | glcpp_parser_destroy (glcpp_parser_t *parser) |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 615 | { |
Carl Worth | 876e510 | 2010-05-20 14:38:06 -0700 | [diff] [blame] | 616 | if (parser->need_newline) |
| 617 | printf ("\n"); |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 618 | if (parser->skip_stack) |
| 619 | fprintf (stderr, "Error: Unterminated #if\n"); |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 620 | glcpp_lex_destroy (parser->scanner); |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 621 | hash_table_dtor (parser->defines); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 622 | talloc_free (parser); |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 623 | } |
Carl Worth | c6d5af3 | 2010-05-11 12:30:09 -0700 | [diff] [blame] | 624 | |
Carl Worth | be0e2e9 | 2010-05-19 07:29:22 -0700 | [diff] [blame] | 625 | static int |
| 626 | glcpp_parser_is_expanding (glcpp_parser_t *parser, const char *member) |
| 627 | { |
| 628 | expansion_node_t *node; |
| 629 | |
| 630 | for (node = parser->expansions; node; node = node->next) { |
| 631 | if (node->macro && |
| 632 | strcmp (node->macro->identifier, member) == 0) |
| 633 | { |
| 634 | return 1; |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 641 | token_class_t |
| 642 | glcpp_parser_classify_token (glcpp_parser_t *parser, |
| 643 | const char *identifier, |
| 644 | int *parameter_index) |
Carl Worth | 9f62a7e | 2010-05-13 07:38:29 -0700 | [diff] [blame] | 645 | { |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 646 | macro_t *macro; |
| 647 | |
Carl Worth | c10a51b | 2010-05-20 15:15:26 -0700 | [diff] [blame] | 648 | /* Is this token a defined macro? */ |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 649 | macro = hash_table_find (parser->defines, identifier); |
| 650 | |
| 651 | if (macro == NULL) |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 652 | return TOKEN_CLASS_IDENTIFIER; |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 653 | |
Carl Worth | be0e2e9 | 2010-05-19 07:29:22 -0700 | [diff] [blame] | 654 | /* Don't consider this a macro if we are already actively |
| 655 | * expanding this macro. */ |
| 656 | if (glcpp_parser_is_expanding (parser, identifier)) |
Carl Worth | b569383 | 2010-05-20 08:01:44 -0700 | [diff] [blame] | 657 | return TOKEN_CLASS_IDENTIFIER_FINALIZED; |
Carl Worth | be0e2e9 | 2010-05-19 07:29:22 -0700 | [diff] [blame] | 658 | |
| 659 | /* Definitely a macro. Just need to check if it's function-like. */ |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 660 | if (macro->is_function) |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 661 | return TOKEN_CLASS_FUNC_MACRO; |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 662 | else |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 663 | return TOKEN_CLASS_OBJ_MACRO; |
Carl Worth | 9f62a7e | 2010-05-13 07:38:29 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 666 | /* Print a non-macro token, or the expansion of an object-like macro. |
| 667 | * |
| 668 | * Returns 0 if this token is completely printed. |
| 669 | * |
| 670 | * Returns 1 in the case that 'token' is a function-like macro that |
| 671 | * needs further expansion. |
| 672 | */ |
| 673 | static int |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 674 | _glcpp_parser_print_expanded_token (glcpp_parser_t *parser, |
| 675 | token_t *token) |
| 676 | { |
| 677 | const char *identifier; |
| 678 | macro_t *macro; |
| 679 | |
| 680 | /* We only expand identifiers */ |
| 681 | if (token->type != IDENTIFIER) { |
| 682 | _token_print (token); |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 683 | return 0; |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | /* Look up this identifier in the hash table. */ |
| 687 | identifier = token->value.str; |
| 688 | macro = hash_table_find (parser->defines, identifier); |
| 689 | |
| 690 | /* Not a macro, so just print directly. */ |
| 691 | if (macro == NULL) { |
| 692 | printf ("%s", identifier); |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 693 | return 0; |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 696 | /* For function-like macros return 1 for further processing. */ |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 697 | if (macro->is_function) { |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 698 | return 1; |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /* Finally, don't expand this macro if we're already actively |
| 702 | * expanding it, (to avoid infinite recursion). */ |
| 703 | if (_string_list_contains (parser->active, identifier, NULL)) { |
| 704 | printf ("%s", identifier); |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | _string_list_push (parser->active, identifier); |
| 709 | _glcpp_parser_print_expanded_token_list (parser, |
| 710 | macro->replacements); |
| 711 | _string_list_pop (parser->active); |
| 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | typedef enum function_status |
| 717 | { |
| 718 | FUNCTION_STATUS_SUCCESS, |
| 719 | FUNCTION_NOT_A_FUNCTION, |
| 720 | FUNCTION_UNBALANCED_PARENTHESES |
| 721 | } function_status_t; |
| 722 | |
| 723 | /* Find a set of function-like macro arguments by looking for a |
| 724 | * balanced set of parentheses. Upon return *node will be the last |
| 725 | * consumed node, such that further processing can continue with |
| 726 | * node->next. |
| 727 | * |
| 728 | * Return values: |
| 729 | * |
| 730 | * FUNCTION_STATUS_SUCCESS: |
| 731 | * |
| 732 | * Successfully parsed a set of function arguments. |
| 733 | * |
| 734 | * FUNCTION_NOT_A_FUNCTION: |
| 735 | * |
| 736 | * Macro name not followed by a '('. This is not an error, but |
| 737 | * simply that the macro name should be treated as a non-macro. |
| 738 | * |
| 739 | * FUNCTION_UNBLANCED_PARENTHESES |
| 740 | * |
| 741 | * Macro name is not followed by a balanced set of parentheses. |
| 742 | */ |
| 743 | static function_status_t |
| 744 | _find_arguments (token_node_t **node_ret, argument_list_t **arguments) |
| 745 | { |
| 746 | token_node_t *node = *node_ret, *last; |
| 747 | int paren_count; |
| 748 | int arg_count; |
| 749 | |
| 750 | last = node; |
| 751 | node = node->next; |
| 752 | |
| 753 | /* Ignore whitespace before first parenthesis. */ |
| 754 | while (node && node->token->type == SPACE) |
| 755 | node = node->next; |
| 756 | |
| 757 | if (node == NULL || node->token->type != '(') |
| 758 | return FUNCTION_NOT_A_FUNCTION; |
| 759 | |
| 760 | paren_count = 0; |
| 761 | arg_count = 0; |
| 762 | do { |
| 763 | if (node->token->type == '(') |
| 764 | { |
| 765 | paren_count++; |
| 766 | } |
| 767 | else if (node->token->type == ')') |
| 768 | { |
| 769 | paren_count--; |
| 770 | } |
| 771 | else if (node->token->type == ',' && |
| 772 | paren_count == 1) |
| 773 | { |
| 774 | arg_count++; |
| 775 | } |
| 776 | |
| 777 | last = node; |
| 778 | node = node->next; |
| 779 | |
| 780 | } while (node && paren_count); |
| 781 | |
| 782 | if (node && paren_count) |
| 783 | return FUNCTION_UNBALANCED_PARENTHESES; |
| 784 | |
| 785 | *node_ret = last; |
| 786 | |
| 787 | return FUNCTION_STATUS_SUCCESS; |
| 788 | } |
| 789 | |
| 790 | /* Prints the expansion of *node (consuming further tokens from the |
| 791 | * list as necessary). Upon return *node will be the last consumed |
| 792 | * node, such that further processing can continue with node->next. */ |
| 793 | static void |
| 794 | _glcpp_parser_print_expanded_function (glcpp_parser_t *parser, |
| 795 | token_node_t **node_ret) |
| 796 | { |
| 797 | macro_t *macro; |
| 798 | token_node_t *node; |
| 799 | const char *identifier; |
| 800 | argument_list_t *arguments; |
| 801 | function_status_t status; |
| 802 | |
| 803 | node = *node_ret; |
| 804 | identifier = node->token->value.str; |
| 805 | |
| 806 | macro = hash_table_find (parser->defines, identifier); |
| 807 | |
| 808 | assert (macro->is_function); |
| 809 | |
| 810 | status = _find_arguments (node_ret, &arguments); |
| 811 | |
| 812 | switch (status) { |
| 813 | case FUNCTION_STATUS_SUCCESS: |
| 814 | break; |
| 815 | case FUNCTION_NOT_A_FUNCTION: |
| 816 | printf ("%s", identifier); |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 817 | return; |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 818 | case FUNCTION_UNBALANCED_PARENTHESES: |
| 819 | fprintf (stderr, "Error: Macro %s call has unbalanced parentheses\n", |
| 820 | identifier); |
| 821 | exit (1); |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | _string_list_push (parser->active, identifier); |
| 825 | _glcpp_parser_print_expanded_token_list (parser, |
| 826 | macro->replacements); |
| 827 | _string_list_pop (parser->active); |
| 828 | } |
| 829 | |
| 830 | void |
| 831 | _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser, |
| 832 | token_list_t *list) |
| 833 | { |
| 834 | token_node_t *node; |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 835 | function_status_t function_status; |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 836 | |
| 837 | if (list == NULL) |
| 838 | return; |
| 839 | |
| 840 | for (node = list->head; node; node = node->next) { |
Carl Worth | b1854fd | 2010-05-25 16:28:26 -0700 | [diff] [blame] | 841 | if (_glcpp_parser_print_expanded_token (parser, node->token)) |
| 842 | _glcpp_parser_print_expanded_function (parser, &node); |
Carl Worth | ae6517f | 2010-05-25 15:24:59 -0700 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | |
| 846 | void |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 847 | _define_object_macro (glcpp_parser_t *parser, |
| 848 | const char *identifier, |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 849 | token_list_t *replacements) |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 850 | { |
| 851 | macro_t *macro; |
| 852 | |
| 853 | macro = xtalloc (parser, macro_t); |
| 854 | |
| 855 | macro->is_function = 0; |
Carl Worth | c5e9855 | 2010-05-14 10:12:21 -0700 | [diff] [blame] | 856 | macro->parameters = NULL; |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 857 | macro->identifier = talloc_strdup (macro, identifier); |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 858 | macro->replacements = talloc_steal (macro, replacements); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 859 | |
| 860 | hash_table_insert (parser->defines, macro, identifier); |
| 861 | } |
| 862 | |
| 863 | void |
| 864 | _define_function_macro (glcpp_parser_t *parser, |
| 865 | const char *identifier, |
Carl Worth | c5e9855 | 2010-05-14 10:12:21 -0700 | [diff] [blame] | 866 | string_list_t *parameters, |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 867 | token_list_t *replacements) |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 868 | { |
| 869 | macro_t *macro; |
| 870 | |
| 871 | macro = xtalloc (parser, macro_t); |
| 872 | |
| 873 | macro->is_function = 1; |
Carl Worth | c5e9855 | 2010-05-14 10:12:21 -0700 | [diff] [blame] | 874 | macro->parameters = talloc_steal (macro, parameters); |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 875 | macro->identifier = talloc_strdup (macro, identifier); |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 876 | macro->replacements = talloc_steal (macro, replacements); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 877 | |
| 878 | hash_table_insert (parser->defines, macro, identifier); |
| 879 | } |
| 880 | |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 881 | static void |
Carl Worth | c10a51b | 2010-05-20 15:15:26 -0700 | [diff] [blame] | 882 | _glcpp_parser_push_expansion (glcpp_parser_t *parser, |
| 883 | macro_t *macro, |
| 884 | token_node_t *replacements) |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 885 | { |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 886 | expansion_node_t *node; |
| 887 | |
| 888 | node = xtalloc (parser, expansion_node_t); |
| 889 | |
| 890 | node->macro = macro; |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 891 | node->replacements = replacements; |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 892 | |
| 893 | node->next = parser->expansions; |
| 894 | parser->expansions = node; |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 897 | static void |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 898 | glcpp_parser_pop_expansion (glcpp_parser_t *parser) |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 899 | { |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 900 | expansion_node_t *node; |
Carl Worth | 420d05a | 2010-05-17 10:15:23 -0700 | [diff] [blame] | 901 | |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 902 | node = parser->expansions; |
Carl Worth | 420d05a | 2010-05-17 10:15:23 -0700 | [diff] [blame] | 903 | |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 904 | if (node == NULL) { |
| 905 | fprintf (stderr, "Internal error: _expansion_list_pop called on an empty list.\n"); |
| 906 | exit (1); |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 909 | parser->expansions = node->next; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 910 | |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 911 | talloc_free (node); |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 914 | void |
Carl Worth | 2be8be0 | 2010-05-14 10:31:43 -0700 | [diff] [blame] | 915 | _expand_object_macro (glcpp_parser_t *parser, const char *identifier) |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 916 | { |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 917 | macro_t *macro; |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 918 | |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 919 | macro = hash_table_find (parser->defines, identifier); |
| 920 | assert (! macro->is_function); |
Carl Worth | be0e2e9 | 2010-05-19 07:29:22 -0700 | [diff] [blame] | 921 | assert (! glcpp_parser_is_expanding (parser, identifier)); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 922 | |
Carl Worth | c10a51b | 2010-05-20 15:15:26 -0700 | [diff] [blame] | 923 | _glcpp_parser_push_expansion (parser, macro, macro->replacements->head); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 926 | void |
Carl Worth | 2be8be0 | 2010-05-14 10:31:43 -0700 | [diff] [blame] | 927 | _expand_function_macro (glcpp_parser_t *parser, |
| 928 | const char *identifier, |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 929 | argument_list_t *arguments) |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 930 | { |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 931 | macro_t *macro; |
Carl Worth | c10a51b | 2010-05-20 15:15:26 -0700 | [diff] [blame] | 932 | token_list_t *expanded; |
| 933 | token_node_t *i, *j; |
| 934 | int parameter_index; |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 935 | |
| 936 | macro = hash_table_find (parser->defines, identifier); |
| 937 | assert (macro->is_function); |
Carl Worth | be0e2e9 | 2010-05-19 07:29:22 -0700 | [diff] [blame] | 938 | assert (! glcpp_parser_is_expanding (parser, identifier)); |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 939 | |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 940 | if (_argument_list_length (arguments) != |
Carl Worth | 2be8be0 | 2010-05-14 10:31:43 -0700 | [diff] [blame] | 941 | _string_list_length (macro->parameters)) |
| 942 | { |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 943 | fprintf (stderr, |
| 944 | "Error: macro %s invoked with %d arguments (expected %d)\n", |
| 945 | identifier, |
Carl Worth | 8f6a828 | 2010-05-14 10:44:19 -0700 | [diff] [blame] | 946 | _argument_list_length (arguments), |
Carl Worth | c5e9855 | 2010-05-14 10:12:21 -0700 | [diff] [blame] | 947 | _string_list_length (macro->parameters)); |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 948 | return; |
Carl Worth | dcc2ecd | 2010-05-13 12:56:42 -0700 | [diff] [blame] | 949 | } |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 950 | |
Carl Worth | c10a51b | 2010-05-20 15:15:26 -0700 | [diff] [blame] | 951 | expanded = _token_list_create (macro); |
| 952 | |
| 953 | for (i = macro->replacements->head; i; i = i->next) { |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 954 | if (_string_list_contains (macro->parameters, |
| 955 | i->token->value.str, |
Carl Worth | c10a51b | 2010-05-20 15:15:26 -0700 | [diff] [blame] | 956 | ¶meter_index)) |
| 957 | { |
| 958 | token_list_t *argument; |
| 959 | argument = _argument_list_member_at (arguments, |
| 960 | parameter_index); |
| 961 | for (j = argument->head; j; j = j->next) |
| 962 | { |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 963 | _token_list_append (expanded, j->token); |
Carl Worth | c10a51b | 2010-05-20 15:15:26 -0700 | [diff] [blame] | 964 | } |
| 965 | } else { |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 966 | _token_list_append (expanded, i->token); |
Carl Worth | c10a51b | 2010-05-20 15:15:26 -0700 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
| 970 | _glcpp_parser_push_expansion (parser, macro, expanded->head); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 971 | } |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 972 | |
| 973 | static int |
Carl Worth | 0293b2e | 2010-05-19 10:05:40 -0700 | [diff] [blame] | 974 | glcpp_parser_lex (glcpp_parser_t *parser) |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 975 | { |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 976 | expansion_node_t *expansion; |
Carl Worth | 4725244 | 2010-05-19 13:54:37 -0700 | [diff] [blame] | 977 | token_node_t *replacements; |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 978 | int parameter_index; |
Carl Worth | d8327e5 | 2010-05-20 15:18:54 -0700 | [diff] [blame] | 979 | const char *token; |
| 980 | token_class_t class; |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 981 | |
| 982 | /* Who says C can't do efficient tail recursion? */ |
| 983 | RECURSE: |
| 984 | |
| 985 | expansion = parser->expansions; |
| 986 | |
| 987 | if (expansion == NULL) |
| 988 | return glcpp_lex (parser->scanner); |
| 989 | |
| 990 | replacements = expansion->replacements; |
| 991 | |
| 992 | /* Pop expansion when replacements is exhausted. */ |
| 993 | if (replacements == NULL) { |
| 994 | glcpp_parser_pop_expansion (parser); |
| 995 | goto RECURSE; |
| 996 | } |
| 997 | |
| 998 | expansion->replacements = replacements->next; |
| 999 | |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 1000 | token = replacements->token->value.str; |
Carl Worth | d8327e5 | 2010-05-20 15:18:54 -0700 | [diff] [blame] | 1001 | |
| 1002 | /* Implement token pasting. */ |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 1003 | if (replacements->next && strcmp (replacements->next->token->value.str, "##") == 0) { |
Carl Worth | d8327e5 | 2010-05-20 15:18:54 -0700 | [diff] [blame] | 1004 | token_node_t *next_node; |
| 1005 | |
| 1006 | next_node = replacements->next->next; |
| 1007 | |
| 1008 | if (next_node == NULL) { |
| 1009 | fprintf (stderr, "Error: '##' cannot appear at the end of a macro expansion.\n"); |
| 1010 | exit (1); |
| 1011 | } |
| 1012 | |
| 1013 | token = xtalloc_asprintf (parser, "%s%s", |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 1014 | token, next_node->token->value.str); |
Carl Worth | d8327e5 | 2010-05-20 15:18:54 -0700 | [diff] [blame] | 1015 | expansion->replacements = next_node->next; |
| 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | if (strcmp (token, "(") == 0) |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 1020 | return '('; |
Carl Worth | d8327e5 | 2010-05-20 15:18:54 -0700 | [diff] [blame] | 1021 | else if (strcmp (token, ")") == 0) |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 1022 | return ')'; |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 1023 | |
Carl Worth | d8327e5 | 2010-05-20 15:18:54 -0700 | [diff] [blame] | 1024 | yylval.str = xtalloc_strdup (parser, token); |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 1025 | |
Carl Worth | b569383 | 2010-05-20 08:01:44 -0700 | [diff] [blame] | 1026 | /* Carefully refuse to expand any finalized identifier. */ |
Carl Worth | 808401f | 2010-05-25 14:52:43 -0700 | [diff] [blame] | 1027 | if (replacements->token->type == IDENTIFIER_FINALIZED) |
Carl Worth | b569383 | 2010-05-20 08:01:44 -0700 | [diff] [blame] | 1028 | return IDENTIFIER_FINALIZED; |
| 1029 | |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 1030 | switch (glcpp_parser_classify_token (parser, yylval.str, |
| 1031 | ¶meter_index)) |
| 1032 | { |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 1033 | case TOKEN_CLASS_IDENTIFIER: |
| 1034 | return IDENTIFIER; |
| 1035 | break; |
Carl Worth | b569383 | 2010-05-20 08:01:44 -0700 | [diff] [blame] | 1036 | case TOKEN_CLASS_IDENTIFIER_FINALIZED: |
| 1037 | return IDENTIFIER_FINALIZED; |
| 1038 | break; |
Carl Worth | aaa9acb | 2010-05-19 13:28:24 -0700 | [diff] [blame] | 1039 | case TOKEN_CLASS_FUNC_MACRO: |
| 1040 | return FUNC_MACRO; |
| 1041 | break; |
| 1042 | default: |
| 1043 | case TOKEN_CLASS_OBJ_MACRO: |
| 1044 | return OBJ_MACRO; |
| 1045 | break; |
| 1046 | } |
Carl Worth | 8f38aff | 2010-05-19 10:01:29 -0700 | [diff] [blame] | 1047 | } |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 1048 | |
| 1049 | static void |
| 1050 | _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, int condition) |
| 1051 | { |
| 1052 | skip_type_t current = SKIP_NO_SKIP; |
| 1053 | skip_node_t *node; |
| 1054 | |
| 1055 | if (parser->skip_stack) |
| 1056 | current = parser->skip_stack->type; |
| 1057 | |
| 1058 | node = xtalloc (parser, skip_node_t); |
| 1059 | |
| 1060 | if (current == SKIP_NO_SKIP) { |
| 1061 | if (condition) |
| 1062 | node->type = SKIP_NO_SKIP; |
| 1063 | else |
| 1064 | node->type = SKIP_TO_ELSE; |
| 1065 | } else { |
| 1066 | node->type = SKIP_TO_ENDIF; |
| 1067 | } |
| 1068 | |
| 1069 | node->next = parser->skip_stack; |
| 1070 | parser->skip_stack = node; |
| 1071 | } |
| 1072 | |
| 1073 | static void |
| 1074 | _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, const char *type, |
| 1075 | int condition) |
| 1076 | { |
| 1077 | if (parser->skip_stack == NULL) { |
| 1078 | fprintf (stderr, "Error: %s without #if\n", type); |
| 1079 | exit (1); |
| 1080 | } |
| 1081 | |
| 1082 | if (parser->skip_stack->type == SKIP_TO_ELSE) { |
| 1083 | if (condition) |
| 1084 | parser->skip_stack->type = SKIP_NO_SKIP; |
| 1085 | } else { |
| 1086 | parser->skip_stack->type = SKIP_TO_ENDIF; |
| 1087 | } |
| 1088 | } |
Carl Worth | 80dc60b | 2010-05-25 14:42:00 -0700 | [diff] [blame] | 1089 | |
Carl Worth | b20d33c | 2010-05-20 22:27:07 -0700 | [diff] [blame] | 1090 | static void |
| 1091 | _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser) |
| 1092 | { |
| 1093 | skip_node_t *node; |
| 1094 | |
| 1095 | if (parser->skip_stack == NULL) { |
| 1096 | fprintf (stderr, "Error: #endif without #if\n"); |
| 1097 | exit (1); |
| 1098 | } |
| 1099 | |
| 1100 | node = parser->skip_stack; |
| 1101 | parser->skip_stack = node->next; |
| 1102 | talloc_free (node); |
| 1103 | } |