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