diff options
author | Carl Worth <[email protected]> | 2012-11-28 12:11:02 -0800 |
---|---|---|
committer | Carl Worth <[email protected]> | 2012-11-29 13:03:01 -0800 |
commit | 01b83171c9d5529a9660ba404cc059daa318fc64 (patch) | |
tree | a45f77a4c3b166d2b5104ad8aa12a665b791cb48 /src/glsl/glcpp/glcpp-parse.y | |
parent | ea34ac499d46407d8d90baa4a8fd9082ba6b3ea7 (diff) |
glcpp: More factoring-out of common code to simplify things.
This time creating a new _token_list_create_with_one_integer function
modeled after the existing _token_list_create_with_one_space function
(both implemented with new _token_list_create_with_one_ival).
Reviewed-by: Matt Turner <[email protected]>
Diffstat (limited to 'src/glsl/glcpp/glcpp-parse.y')
-rw-r--r-- | src/glsl/glcpp/glcpp-parse.y | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y index 5b322fa14c0..20390758f18 100644 --- a/src/glsl/glcpp/glcpp-parse.y +++ b/src/glsl/glcpp/glcpp-parse.y @@ -1300,18 +1300,30 @@ _arguments_parse (argument_list_t *arguments, } static token_list_t * -_token_list_create_with_one_space (void *ctx) +_token_list_create_with_one_ival (void *ctx, int type, int ival) { token_list_t *list; - token_t *space; + token_t *node; list = _token_list_create (ctx); - space = _token_create_ival (list, SPACE, SPACE); - _token_list_append (list, space); + node = _token_create_ival (list, type, ival); + _token_list_append (list, node); return list; } +static token_list_t * +_token_list_create_with_one_space (void *ctx) +{ + return _token_list_create_with_one_ival (ctx, SPACE, SPACE); +} + +static token_list_t * +_token_list_create_with_one_integer (void *ctx, int ival) +{ + return _token_list_create_with_one_ival (ctx, INTEGER, ival); +} + /* Perform macro expansion on 'list', placing the resulting tokens * into a new list which is initialized with a first token of type * 'head_token_type'. Then begin lexing from the resulting list, @@ -1533,29 +1545,11 @@ _glcpp_parser_expand_node (glcpp_parser_t *parser, /* Special handling for __LINE__ and __FILE__, (not through * the hash table). */ - if (strcmp(identifier, "__LINE__") == 0) { - token_list_t *replacement; - token_t *value; - - replacement = _token_list_create (parser); - value = _token_create_ival (parser, INTEGER, - node->token->location.first_line); - _token_list_append (replacement, value); - - return replacement; - } + if (strcmp(identifier, "__LINE__") == 0) + return _token_list_create_with_one_integer (parser, node->token->location.first_line); - if (strcmp(identifier, "__FILE__") == 0) { - token_list_t *replacement; - token_t *value; - - replacement = _token_list_create (parser); - value = _token_create_ival (parser, INTEGER, - node->token->location.source); - _token_list_append (replacement, value); - - return replacement; - } + if (strcmp(identifier, "__FILE__") == 0) + return _token_list_create_with_one_integer (parser, node->token->location.source); /* Look up this identifier in the hash table. */ macro = hash_table_find (parser->defines, identifier); |