diff options
| -rw-r--r-- | yarp/templates/include/yarp/ast.h.erb | 1 | ||||
| -rwxr-xr-x | yarp/templates/template.rb | 2 | ||||
| -rw-r--r-- | yarp/yarp.c | 62 |
3 files changed, 56 insertions, 9 deletions
diff --git a/yarp/templates/include/yarp/ast.h.erb b/yarp/templates/include/yarp/ast.h.erb index 09841408eb..25a485d77b 100644 --- a/yarp/templates/include/yarp/ast.h.erb +++ b/yarp/templates/include/yarp/ast.h.erb @@ -59,6 +59,7 @@ typedef uint16_t yp_node_flags_t; // We store the flags enum in every node in the tree. Some flags are common to // all nodes (the ones listed below). Others are specific to certain node types. static const yp_node_flags_t YP_NODE_FLAG_NEWLINE = 0x1; +static const yp_node_flags_t YP_NODE_FLAG_STATIC_LITERAL = 0x2; // For easy access, we define some macros to check node type #define YP_NODE_TYPE(node) ((enum yp_node_type)node->type) diff --git a/yarp/templates/template.rb b/yarp/templates/template.rb index 928ade61a6..f0b240eb6f 100755 --- a/yarp/templates/template.rb +++ b/yarp/templates/template.rb @@ -5,7 +5,7 @@ require "fileutils" require "yaml" module YARP - COMMON_FLAGS = 1 + COMMON_FLAGS = 2 # This represents a field on a node. It contains all of the necessary # information to template out the code for that field. diff --git a/yarp/yarp.c b/yarp/yarp.c index 2ff228c540..8ecc5d5179 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -2207,7 +2207,13 @@ static yp_false_node_t * yp_false_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD_FALSE); yp_false_node_t *node = YP_ALLOC_NODE(parser, yp_false_node_t); - *node = (yp_false_node_t) {{ .type = YP_FALSE_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + + *node = (yp_false_node_t) {{ + .type = YP_FALSE_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, + .location = YP_LOCATION_TOKEN_VALUE(token) + }}; + return node; } @@ -2257,7 +2263,13 @@ static yp_float_node_t * yp_float_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_FLOAT); yp_float_node_t *node = YP_ALLOC_NODE(parser, yp_float_node_t); - *node = (yp_float_node_t) {{ .type = YP_FLOAT_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + + *node = (yp_float_node_t) {{ + .type = YP_FLOAT_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, + .location = YP_LOCATION_TOKEN_VALUE(token) + }}; + return node; } @@ -2270,6 +2282,7 @@ yp_float_node_imaginary_create(yp_parser_t *parser, const yp_token_t *token) { *node = (yp_imaginary_node_t) { { .type = YP_IMAGINARY_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_float_node_create(parser, &((yp_token_t) { @@ -2291,6 +2304,7 @@ yp_float_node_rational_create(yp_parser_t *parser, const yp_token_t *token) { *node = (yp_rational_node_t) { { .type = YP_RATIONAL_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_float_node_create(parser, &((yp_token_t) { @@ -2312,6 +2326,7 @@ yp_float_node_rational_imaginary_create(yp_parser_t *parser, const yp_token_t *t *node = (yp_imaginary_node_t) { { .type = YP_IMAGINARY_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_float_node_rational_create(parser, &((yp_token_t) { @@ -2725,7 +2740,7 @@ yp_integer_node_create(yp_parser_t *parser, yp_node_flags_t base, const yp_token *node = (yp_integer_node_t) {{ .type = YP_INTEGER_NODE, - .flags = base, + .flags = base | YP_NODE_FLAG_STATIC_LITERAL, .location = YP_LOCATION_TOKEN_VALUE(token) }}; @@ -2741,6 +2756,7 @@ yp_integer_node_imaginary_create(yp_parser_t *parser, yp_node_flags_t base, cons *node = (yp_imaginary_node_t) { { .type = YP_IMAGINARY_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_integer_node_create(parser, base, &((yp_token_t) { @@ -2762,6 +2778,7 @@ yp_integer_node_rational_create(yp_parser_t *parser, yp_node_flags_t base, const *node = (yp_rational_node_t) { { .type = YP_RATIONAL_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_integer_node_create(parser, base, &((yp_token_t) { @@ -2783,6 +2800,7 @@ yp_integer_node_rational_imaginary_create(yp_parser_t *parser, yp_node_flags_t b *node = (yp_imaginary_node_t) { { .type = YP_IMAGINARY_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, .location = YP_LOCATION_TOKEN_VALUE(token) }, .numeric = (yp_node_t *) yp_integer_node_rational_create(parser, base, &((yp_token_t) { @@ -3458,7 +3476,12 @@ yp_nil_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD_NIL); yp_nil_node_t *node = YP_ALLOC_NODE(parser, yp_nil_node_t); - *node = (yp_nil_node_t) {{ .type = YP_NIL_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_nil_node_t) {{ + .type = YP_NIL_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, + .location = YP_LOCATION_TOKEN_VALUE(token) + }}; + return node; } @@ -4005,7 +4028,12 @@ yp_self_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD_SELF); yp_self_node_t *node = YP_ALLOC_NODE(parser, yp_self_node_t); - *node = (yp_self_node_t) {{ .type = YP_SELF_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_self_node_t) {{ + .type = YP_SELF_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, + .location = YP_LOCATION_TOKEN_VALUE(token) + }}; + return node; } @@ -4039,7 +4067,12 @@ yp_source_encoding_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD___ENCODING__); yp_source_encoding_node_t *node = YP_ALLOC_NODE(parser, yp_source_encoding_node_t); - *node = (yp_source_encoding_node_t) {{ .type = YP_SOURCE_ENCODING_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_source_encoding_node_t) {{ + .type = YP_SOURCE_ENCODING_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, + .location = YP_LOCATION_TOKEN_VALUE(token) + }}; + return node; } @@ -4052,6 +4085,7 @@ yp_source_file_node_create(yp_parser_t *parser, const yp_token_t *file_keyword) *node = (yp_source_file_node_t) { { .type = YP_SOURCE_FILE_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, .location = YP_LOCATION_TOKEN_VALUE(file_keyword), }, .filepath = parser->filepath_string, @@ -4066,7 +4100,12 @@ yp_source_line_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD___LINE__); yp_source_line_node_t *node = YP_ALLOC_NODE(parser, yp_source_line_node_t); - *node = (yp_source_line_node_t) {{ .type = YP_SOURCE_LINE_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_source_line_node_t) {{ + .type = YP_SOURCE_LINE_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, + .location = YP_LOCATION_TOKEN_VALUE(token) + }}; + return node; } @@ -4220,6 +4259,7 @@ yp_symbol_node_create(yp_parser_t *parser, const yp_token_t *opening, const yp_t *node = (yp_symbol_node_t) { { .type = YP_SYMBOL_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, .location = { .start = (opening->type == YP_TOKEN_NOT_PROVIDED ? value->start : opening->start), .end = (closing->type == YP_TOKEN_NOT_PROVIDED ? value->end : closing->end) @@ -4297,6 +4337,7 @@ yp_string_node_to_symbol_node(yp_parser_t *parser, yp_string_node_t *node, const *new_node = (yp_symbol_node_t) { { .type = YP_SYMBOL_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, .location = { .start = opening->start, .end = closing->end @@ -4346,7 +4387,12 @@ yp_true_node_create(yp_parser_t *parser, const yp_token_t *token) { assert(token->type == YP_TOKEN_KEYWORD_TRUE); yp_true_node_t *node = YP_ALLOC_NODE(parser, yp_true_node_t); - *node = (yp_true_node_t) {{ .type = YP_TRUE_NODE, .location = YP_LOCATION_TOKEN_VALUE(token) }}; + *node = (yp_true_node_t) {{ + .type = YP_TRUE_NODE, + .flags = YP_NODE_FLAG_STATIC_LITERAL, + .location = YP_LOCATION_TOKEN_VALUE(token) + }}; + return node; } |
