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 | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 28 | #include <talloc.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 | |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 32 | #define YYLEX_PARAM parser->scanner |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 33 | |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 34 | typedef struct { |
| 35 | int is_function; |
| 36 | list_t *parameter_list; |
| 37 | list_t *replacement_list; |
| 38 | } macro_t; |
| 39 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 40 | struct glcpp_parser { |
| 41 | yyscan_t scanner; |
| 42 | struct hash_table *defines; |
| 43 | }; |
| 44 | |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 45 | void |
Carl Worth | a1e32bc | 2010-05-10 13:17:25 -0700 | [diff] [blame] | 46 | yyerror (void *scanner, const char *error); |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 47 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 48 | void |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 49 | _define_object_macro (glcpp_parser_t *parser, |
| 50 | const char *macro, |
| 51 | list_t *replacement_list); |
| 52 | |
| 53 | void |
| 54 | _define_function_macro (glcpp_parser_t *parser, |
| 55 | const char *macro, |
| 56 | list_t *parameter_list, |
| 57 | list_t *replacement_list); |
| 58 | |
| 59 | void |
| 60 | _print_expanded_object_macro (glcpp_parser_t *parser, const char *macro); |
| 61 | |
| 62 | void |
| 63 | _print_expanded_function_macro (glcpp_parser_t *parser, |
| 64 | const char *macro, |
| 65 | list_t *arguments); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 66 | |
| 67 | list_t * |
| 68 | _list_create (void *ctx); |
| 69 | |
| 70 | void |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 71 | _list_append_item (list_t *list, const char *str); |
| 72 | |
| 73 | void |
| 74 | _list_append_list (list_t *list, list_t *tail); |
Carl Worth | c6d5af3 | 2010-05-11 12:30:09 -0700 | [diff] [blame] | 75 | |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 76 | %} |
| 77 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 78 | %union { |
| 79 | char *str; |
| 80 | list_t *list; |
| 81 | } |
| 82 | |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 83 | %parse-param {glcpp_parser_t *parser} |
Carl Worth | 38aa835 | 2010-05-10 11:52:29 -0700 | [diff] [blame] | 84 | %lex-param {void *scanner} |
| 85 | |
Carl Worth | 0a93cbb | 2010-05-13 10:29:07 -0700 | [diff] [blame] | 86 | %token DEFINE FUNC_MACRO IDENTIFIER NEWLINE OBJ_MACRO SPACE TOKEN UNDEF |
| 87 | %type <str> FUNC_MACRO IDENTIFIER OBJ_MACRO TOKEN word word_or_symbol |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 88 | %type <list> argument argument_list parameter_list replacement_list |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 89 | |
| 90 | %% |
| 91 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 92 | input: |
| 93 | /* empty */ |
Carl Worth | 8bcb6f1 | 2010-05-12 13:21:20 -0700 | [diff] [blame] | 94 | | input content |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 95 | ; |
| 96 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 97 | content: |
Carl Worth | 9f62a7e | 2010-05-13 07:38:29 -0700 | [diff] [blame] | 98 | IDENTIFIER { |
| 99 | printf ("%s", $1); |
| 100 | talloc_free ($1); |
| 101 | } |
| 102 | | TOKEN { |
| 103 | printf ("%s", $1); |
| 104 | talloc_free ($1); |
| 105 | } |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 106 | | macro |
Carl Worth | cd27e64 | 2010-05-12 13:11:50 -0700 | [diff] [blame] | 107 | | directive_with_newline |
Carl Worth | 0a93cbb | 2010-05-13 10:29:07 -0700 | [diff] [blame] | 108 | | NEWLINE { printf ("\n"); } |
| 109 | | '(' { printf ("("); } |
| 110 | | ')' { printf (")"); } |
| 111 | | ',' { printf (","); } |
Carl Worth | cd27e64 | 2010-05-12 13:11:50 -0700 | [diff] [blame] | 112 | ; |
| 113 | |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 114 | macro: |
| 115 | FUNC_MACRO '(' argument_list ')' { |
| 116 | _print_expanded_function_macro (parser, $1, $3); |
| 117 | } |
| 118 | | OBJ_MACRO { |
| 119 | _print_expanded_object_macro (parser, $1); |
| 120 | talloc_free ($1); |
| 121 | } |
| 122 | ; |
| 123 | |
| 124 | argument_list: |
Carl Worth | db35d55 | 2010-05-14 08:47:32 -0700 | [diff] [blame] | 125 | argument { |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 126 | $$ = _list_create (parser); |
| 127 | _list_append_list ($$, $1); |
| 128 | } |
| 129 | | argument_list ',' argument { |
| 130 | _list_append_list ($1, $3); |
| 131 | $$ = $1; |
| 132 | } |
| 133 | ; |
| 134 | |
| 135 | argument: |
| 136 | /* empty */ { |
| 137 | $$ = _list_create (parser); |
| 138 | } |
Carl Worth | 0a93cbb | 2010-05-13 10:29:07 -0700 | [diff] [blame] | 139 | | argument word { |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 140 | _list_append_item ($1, $2); |
| 141 | talloc_free ($2); |
| 142 | } |
| 143 | | argument '(' argument ')' |
| 144 | ; |
| 145 | |
Carl Worth | cd27e64 | 2010-05-12 13:11:50 -0700 | [diff] [blame] | 146 | directive_with_newline: |
| 147 | directive NEWLINE { |
| 148 | printf ("\n"); |
| 149 | } |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 150 | ; |
| 151 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 152 | directive: |
Carl Worth | 0a93cbb | 2010-05-13 10:29:07 -0700 | [diff] [blame] | 153 | DEFINE IDENTIFIER { |
| 154 | list_t *list = _list_create (parser); |
| 155 | _define_object_macro (parser, $2, list); |
| 156 | } |
| 157 | | DEFINE IDENTIFIER SPACE replacement_list { |
| 158 | _define_object_macro (parser, $2, $4); |
Carl Worth | cd27e64 | 2010-05-12 13:11:50 -0700 | [diff] [blame] | 159 | } |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 160 | | DEFINE IDENTIFIER '(' parameter_list ')' replacement_list { |
| 161 | _define_function_macro (parser, $2, $4, $6); |
| 162 | } |
| 163 | | UNDEF FUNC_MACRO { |
| 164 | list_t *replacement = hash_table_find (parser->defines, $2); |
| 165 | if (replacement) { |
| 166 | /* XXX: Need hash table to support a real way |
| 167 | * to remove an element rather than prefixing |
| 168 | * a new node with data of NULL like this. */ |
| 169 | hash_table_insert (parser->defines, NULL, $2); |
| 170 | talloc_free (replacement); |
| 171 | } |
| 172 | talloc_free ($2); |
| 173 | } |
| 174 | | UNDEF OBJ_MACRO { |
Carl Worth | cd27e64 | 2010-05-12 13:11:50 -0700 | [diff] [blame] | 175 | list_t *replacement = hash_table_find (parser->defines, $2); |
| 176 | if (replacement) { |
| 177 | /* XXX: Need hash table to support a real way |
| 178 | * to remove an element rather than prefixing |
| 179 | * a new node with data of NULL like this. */ |
| 180 | hash_table_insert (parser->defines, NULL, $2); |
| 181 | talloc_free (replacement); |
| 182 | } |
| 183 | talloc_free ($2); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 184 | } |
| 185 | ; |
| 186 | |
| 187 | replacement_list: |
| 188 | /* empty */ { |
| 189 | $$ = _list_create (parser); |
| 190 | } |
Carl Worth | 0a93cbb | 2010-05-13 10:29:07 -0700 | [diff] [blame] | 191 | | replacement_list word_or_symbol { |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 192 | _list_append_item ($1, $2); |
Carl Worth | 5070a20 | 2010-05-12 12:45:33 -0700 | [diff] [blame] | 193 | talloc_free ($2); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 194 | $$ = $1; |
| 195 | } |
| 196 | ; |
| 197 | |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 198 | parameter_list: |
| 199 | /* empty */ { |
| 200 | $$ = _list_create (parser); |
| 201 | } |
| 202 | | IDENTIFIER { |
| 203 | $$ = _list_create (parser); |
| 204 | _list_append_item ($$, $1); |
| 205 | talloc_free ($1); |
| 206 | } |
| 207 | | parameter_list ',' IDENTIFIER { |
| 208 | _list_append_item ($1, $3); |
| 209 | talloc_free ($3); |
| 210 | $$ = $1; |
| 211 | } |
| 212 | ; |
| 213 | |
Carl Worth | 0a93cbb | 2010-05-13 10:29:07 -0700 | [diff] [blame] | 214 | word_or_symbol: |
| 215 | word { $$ = $1; } |
| 216 | | '(' { $$ = xtalloc_strdup (parser, "("); } |
| 217 | | ')' { $$ = xtalloc_strdup (parser, ")"); } |
| 218 | | ',' { $$ = xtalloc_strdup (parser, ","); } |
| 219 | ; |
| 220 | |
| 221 | word: |
Carl Worth | 9f62a7e | 2010-05-13 07:38:29 -0700 | [diff] [blame] | 222 | IDENTIFIER { $$ = $1; } |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 223 | | FUNC_MACRO { $$ = $1; } |
| 224 | | OBJ_MACRO { $$ = $1; } |
Carl Worth | 9f62a7e | 2010-05-13 07:38:29 -0700 | [diff] [blame] | 225 | | TOKEN { $$ = $1; } |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 226 | ; |
| 227 | |
| 228 | %% |
| 229 | |
| 230 | list_t * |
| 231 | _list_create (void *ctx) |
| 232 | { |
| 233 | list_t *list; |
| 234 | |
Carl Worth | 5070a20 | 2010-05-12 12:45:33 -0700 | [diff] [blame] | 235 | list = xtalloc (ctx, list_t); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 236 | list->head = NULL; |
| 237 | list->tail = NULL; |
| 238 | |
| 239 | return list; |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 240 | } |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 241 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 242 | void |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 243 | _list_append_list (list_t *list, list_t *tail) |
| 244 | { |
| 245 | if (list->head == NULL) { |
| 246 | list->head = tail->head; |
| 247 | } else { |
| 248 | list->tail->next = tail->head; |
| 249 | } |
| 250 | |
| 251 | list->tail = tail->tail; |
| 252 | } |
| 253 | |
| 254 | void |
| 255 | _list_append_item (list_t *list, const char *str) |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 256 | { |
| 257 | node_t *node; |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 258 | |
Carl Worth | 5070a20 | 2010-05-12 12:45:33 -0700 | [diff] [blame] | 259 | node = xtalloc (list, node_t); |
| 260 | node->str = xtalloc_strdup (node, str); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 261 | |
| 262 | node->next = NULL; |
| 263 | |
| 264 | if (list->head == NULL) { |
| 265 | list->head = node; |
| 266 | } else { |
| 267 | list->tail->next = node; |
| 268 | } |
| 269 | |
| 270 | list->tail = node; |
| 271 | } |
| 272 | |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 273 | void |
Carl Worth | a1e32bc | 2010-05-10 13:17:25 -0700 | [diff] [blame] | 274 | yyerror (void *scanner, const char *error) |
Carl Worth | 3a37b87 | 2010-05-10 11:44:09 -0700 | [diff] [blame] | 275 | { |
| 276 | fprintf (stderr, "Parse error: %s\n", error); |
| 277 | } |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 278 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 279 | glcpp_parser_t * |
| 280 | glcpp_parser_create (void) |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 281 | { |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 282 | glcpp_parser_t *parser; |
| 283 | |
Carl Worth | 5070a20 | 2010-05-12 12:45:33 -0700 | [diff] [blame] | 284 | parser = xtalloc (NULL, glcpp_parser_t); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 285 | |
Carl Worth | 5070a20 | 2010-05-12 12:45:33 -0700 | [diff] [blame] | 286 | yylex_init_extra (parser, &parser->scanner); |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 287 | parser->defines = hash_table_ctor (32, hash_table_string_hash, |
| 288 | hash_table_string_compare); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 289 | |
| 290 | return parser; |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | int |
| 294 | glcpp_parser_parse (glcpp_parser_t *parser) |
| 295 | { |
| 296 | return yyparse (parser); |
| 297 | } |
| 298 | |
| 299 | void |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 300 | glcpp_parser_destroy (glcpp_parser_t *parser) |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 301 | { |
| 302 | yylex_destroy (parser->scanner); |
| 303 | hash_table_dtor (parser->defines); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 304 | talloc_free (parser); |
Carl Worth | 0b27b5f | 2010-05-10 16:16:06 -0700 | [diff] [blame] | 305 | } |
Carl Worth | c6d5af3 | 2010-05-11 12:30:09 -0700 | [diff] [blame] | 306 | |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 307 | macro_type_t |
| 308 | glcpp_parser_macro_type (glcpp_parser_t *parser, const char *identifier) |
Carl Worth | 9f62a7e | 2010-05-13 07:38:29 -0700 | [diff] [blame] | 309 | { |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 310 | macro_t *macro; |
| 311 | |
| 312 | macro = hash_table_find (parser->defines, identifier); |
| 313 | |
| 314 | if (macro == NULL) |
| 315 | return MACRO_TYPE_UNDEFINED; |
| 316 | |
| 317 | if (macro->is_function) |
| 318 | return MACRO_TYPE_FUNCTION; |
| 319 | else |
| 320 | return MACRO_TYPE_OBJECT; |
Carl Worth | 9f62a7e | 2010-05-13 07:38:29 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 323 | static void |
Carl Worth | 9f62a7e | 2010-05-13 07:38:29 -0700 | [diff] [blame] | 324 | _print_expanded_macro_recursive (glcpp_parser_t *parser, |
| 325 | const char *token, |
| 326 | const char *orig, |
| 327 | int *first) |
Carl Worth | c6d5af3 | 2010-05-11 12:30:09 -0700 | [diff] [blame] | 328 | { |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 329 | macro_t *macro; |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 330 | node_t *node; |
Carl Worth | c6d5af3 | 2010-05-11 12:30:09 -0700 | [diff] [blame] | 331 | |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 332 | macro = hash_table_find (parser->defines, token); |
| 333 | if (macro == NULL) { |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 334 | printf ("%s%s", *first ? "" : " ", token); |
| 335 | *first = 0; |
| 336 | } else { |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 337 | list_t *replacement_list = macro->replacement_list; |
| 338 | |
| 339 | for (node = replacement_list->head ; node ; node = node->next) { |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 340 | token = node->str; |
| 341 | if (strcmp (token, orig) == 0) { |
| 342 | printf ("%s%s", *first ? "" : " ", token); |
| 343 | *first = 0; |
| 344 | } else { |
Carl Worth | 9f62a7e | 2010-05-13 07:38:29 -0700 | [diff] [blame] | 345 | _print_expanded_macro_recursive (parser, |
| 346 | token, orig, |
| 347 | first); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
Carl Worth | c6d5af3 | 2010-05-11 12:30:09 -0700 | [diff] [blame] | 350 | } |
Carl Worth | c6d5af3 | 2010-05-11 12:30:09 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 353 | void |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 354 | _define_object_macro (glcpp_parser_t *parser, |
| 355 | const char *identifier, |
| 356 | list_t *replacement_list) |
| 357 | { |
| 358 | macro_t *macro; |
| 359 | |
| 360 | macro = xtalloc (parser, macro_t); |
| 361 | |
| 362 | macro->is_function = 0; |
| 363 | macro->parameter_list = NULL; |
| 364 | macro->replacement_list = talloc_steal (macro, replacement_list); |
| 365 | |
| 366 | hash_table_insert (parser->defines, macro, identifier); |
| 367 | } |
| 368 | |
| 369 | void |
| 370 | _define_function_macro (glcpp_parser_t *parser, |
| 371 | const char *identifier, |
| 372 | list_t *parameter_list, |
| 373 | list_t *replacement_list) |
| 374 | { |
| 375 | macro_t *macro; |
| 376 | |
| 377 | macro = xtalloc (parser, macro_t); |
| 378 | |
| 379 | macro->is_function = 1; |
| 380 | macro->parameter_list = talloc_steal (macro, parameter_list); |
| 381 | macro->replacement_list = talloc_steal (macro, replacement_list); |
| 382 | |
| 383 | hash_table_insert (parser->defines, macro, identifier); |
| 384 | } |
| 385 | |
| 386 | void |
| 387 | _print_expanded_object_macro (glcpp_parser_t *parser, const char *identifier) |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 388 | { |
| 389 | int first = 1; |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 390 | macro_t *macro; |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 391 | |
Carl Worth | fcbbb46 | 2010-05-13 09:36:23 -0700 | [diff] [blame] | 392 | macro = hash_table_find (parser->defines, identifier); |
| 393 | assert (! macro->is_function); |
| 394 | |
| 395 | _print_expanded_macro_recursive (parser, identifier, identifier, &first); |
| 396 | } |
| 397 | |
| 398 | void |
| 399 | _print_expanded_function_macro (glcpp_parser_t *parser, |
| 400 | const char *identifier, |
| 401 | list_t *arguments) |
| 402 | { |
| 403 | int first = 1; |
| 404 | macro_t *macro; |
| 405 | |
| 406 | macro = hash_table_find (parser->defines, identifier); |
| 407 | assert (macro->is_function); |
| 408 | |
| 409 | /* XXX: Need to use argument list here in the expansion. */ |
| 410 | |
| 411 | _print_expanded_macro_recursive (parser, identifier, identifier, &first); |
Carl Worth | 33cc400 | 2010-05-12 12:17:10 -0700 | [diff] [blame] | 412 | } |