Skip to content

Commit 09d0a14

Browse files
committed
Rename constant pool fields to name or operator
* `constant_id` and `operator_id` are confusing. * See #1296
1 parent b5fba6d commit 09d0a14

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

config.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ nodes:
662662
type: location
663663
- name: value
664664
type: node
665-
- name: operator_id
665+
- name: operator
666666
type: constant
667667
comment: |
668668
Represents the use of an assignment operator on a call.
@@ -1492,7 +1492,7 @@ nodes:
14921492
type: location
14931493
- name: value
14941494
type: node
1495-
- name: constant_id
1495+
- name: name
14961496
type: constant
14971497
- name: depth
14981498
type: uint32
@@ -1509,9 +1509,9 @@ nodes:
15091509
type: location
15101510
- name: value
15111511
type: node
1512-
- name: constant_id
1512+
- name: name
15131513
type: constant
1514-
- name: operator_id
1514+
- name: operator
15151515
type: constant
15161516
- name: depth
15171517
type: uint32
@@ -1528,7 +1528,7 @@ nodes:
15281528
type: location
15291529
- name: value
15301530
type: node
1531-
- name: constant_id
1531+
- name: name
15321532
type: constant
15331533
- name: depth
15341534
type: uint32
@@ -1539,7 +1539,7 @@ nodes:
15391539
^^^^^^^^^^^^^^^^
15401540
- name: LocalVariableReadNode
15411541
child_nodes:
1542-
- name: constant_id
1542+
- name: name
15431543
type: constant
15441544
- name: depth
15451545
type: uint32
@@ -1552,7 +1552,7 @@ nodes:
15521552
^^^
15531553
- name: LocalVariableTargetNode
15541554
child_nodes:
1555-
- name: constant_id
1555+
- name: name
15561556
type: constant
15571557
- name: depth
15581558
type: uint32
@@ -1563,7 +1563,7 @@ nodes:
15631563
^^^ ^^^
15641564
- name: LocalVariableWriteNode
15651565
child_nodes:
1566-
- name: constant_id
1566+
- name: name
15671567
type: constant
15681568
- name: depth
15691569
type: uint32
@@ -1682,7 +1682,7 @@ nodes:
16821682
^^
16831683
- name: OptionalParameterNode
16841684
child_nodes:
1685-
- name: constant_id
1685+
- name: name
16861686
type: constant
16871687
- name: name_loc
16881688
type: location
@@ -1883,7 +1883,7 @@ nodes:
18831883
end
18841884
- name: RequiredParameterNode
18851885
child_nodes:
1886-
- name: constant_id
1886+
- name: name
18871887
type: constant
18881888
comment: |
18891889
Represents a required parameter to a method, block, or lambda definition.

lib/yarp.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,10 @@ def self.yarp_locals(source)
462462
# order here so that we can compare properly.
463463
if params
464464
sorted = [
465-
*params.requireds.grep(RequiredParameterNode).map(&:constant_id),
466-
*params.optionals.map(&:constant_id),
465+
*params.requireds.grep(RequiredParameterNode).map(&:name),
466+
*params.optionals.map(&:name),
467467
*((params.rest.name ? params.rest.name.to_sym : :*) if params.rest && params.rest.operator != ","),
468-
*params.posts.grep(RequiredParameterNode).map(&:constant_id),
468+
*params.posts.grep(RequiredParameterNode).map(&:name),
469469
*params.keywords.reject(&:value).map { |param| param.name.chomp(":").to_sym },
470470
*params.keywords.select(&:value).map { |param| param.name.chomp(":").to_sym }
471471
]
@@ -485,9 +485,9 @@ def self.yarp_locals(source)
485485
when RequiredDestructuredParameterNode
486486
param_stack.concat(param.parameters.reverse)
487487
when RequiredParameterNode
488-
sorted << param.constant_id
488+
sorted << param.name
489489
when SplatNode
490-
sorted << param.expression.constant_id if param.expression
490+
sorted << param.expression.name if param.expression
491491
end
492492
end
493493

lib/yarp/desugar_visitor.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ def visit_instance_variable_operator_write_node(node)
210210
# foo && foo = bar
211211
def visit_local_variable_and_write_node(node)
212212
AndNode.new(
213-
LocalVariableReadNode.new(node.constant_id, node.depth, node.name_loc),
214-
LocalVariableWriteNode.new(node.constant_id, node.depth, node.name_loc, node.value, node.operator_loc, node.location),
213+
LocalVariableReadNode.new(node.name, node.depth, node.name_loc),
214+
LocalVariableWriteNode.new(node.name, node.depth, node.name_loc, node.value, node.operator_loc, node.location),
215215
node.operator_loc,
216216
node.location
217217
)
@@ -224,8 +224,8 @@ def visit_local_variable_and_write_node(node)
224224
# foo || foo = bar
225225
def visit_local_variable_or_write_node(node)
226226
OrNode.new(
227-
LocalVariableReadNode.new(node.constant_id, node.depth, node.name_loc),
228-
LocalVariableWriteNode.new(node.constant_id, node.depth, node.name_loc, node.value, node.operator_loc, node.location),
227+
LocalVariableReadNode.new(node.name, node.depth, node.name_loc),
228+
LocalVariableWriteNode.new(node.name, node.depth, node.name_loc, node.value, node.operator_loc, node.location),
229229
node.operator_loc,
230230
node.location
231231
)
@@ -237,7 +237,7 @@ def visit_local_variable_or_write_node(node)
237237
#
238238
# foo = foo + bar
239239
def visit_local_variable_operator_write_node(node)
240-
desugar_operator_write_node(node, LocalVariableWriteNode, LocalVariableReadNode, arguments: [node.constant_id, node.depth])
240+
desugar_operator_write_node(node, LocalVariableWriteNode, LocalVariableReadNode, arguments: [node.name, node.depth])
241241
end
242242

243243
private

src/yarp.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ yp_call_operator_write_node_create(yp_parser_t *parser, yp_call_node_t *target,
14341434
.target = target,
14351435
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
14361436
.value = value,
1437-
.operator_id = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
1437+
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
14381438
};
14391439

14401440
return node;
@@ -2959,7 +2959,7 @@ yp_lambda_node_create(
29592959

29602960
// Allocate and initialize a new LocalVariableAndWriteNode node.
29612961
static yp_local_variable_and_write_node_t *
2962-
yp_local_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t constant_id, uint32_t depth) {
2962+
yp_local_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t name, uint32_t depth) {
29632963
assert(YP_NODE_TYPE_P(target, YP_NODE_LOCAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_CALL_NODE));
29642964
assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL);
29652965
yp_local_variable_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_and_write_node_t);
@@ -2975,7 +2975,7 @@ yp_local_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target,
29752975
.name_loc = target->location,
29762976
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
29772977
.value = value,
2978-
.constant_id = constant_id,
2978+
.name = name,
29792979
.depth = depth
29802980
};
29812981

@@ -2984,7 +2984,7 @@ yp_local_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target,
29842984

29852985
// Allocate and initialize a new LocalVariableOperatorWriteNode node.
29862986
static yp_local_variable_operator_write_node_t *
2987-
yp_local_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t constant_id, uint32_t depth) {
2987+
yp_local_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t name, uint32_t depth) {
29882988
yp_local_variable_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_operator_write_node_t);
29892989

29902990
*node = (yp_local_variable_operator_write_node_t) {
@@ -2998,8 +2998,8 @@ yp_local_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *tar
29982998
.name_loc = target->location,
29992999
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
30003000
.value = value,
3001-
.constant_id = constant_id,
3002-
.operator_id = yp_parser_constant_id_location(parser, operator->start, operator->end - 1),
3001+
.name = name,
3002+
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1),
30033003
.depth = depth
30043004
};
30053005

@@ -3008,7 +3008,7 @@ yp_local_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *tar
30083008

30093009
// Allocate and initialize a new LocalVariableOrWriteNode node.
30103010
static yp_local_variable_or_write_node_t *
3011-
yp_local_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t constant_id, uint32_t depth) {
3011+
yp_local_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t name, uint32_t depth) {
30123012
assert(YP_NODE_TYPE_P(target, YP_NODE_LOCAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_CALL_NODE));
30133013
assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL);
30143014
yp_local_variable_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_or_write_node_t);
@@ -3024,7 +3024,7 @@ yp_local_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target, c
30243024
.name_loc = target->location,
30253025
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
30263026
.value = value,
3027-
.constant_id = constant_id,
3027+
.name = name,
30283028
.depth = depth
30293029
};
30303030

@@ -3041,7 +3041,7 @@ yp_local_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name,
30413041
.type = YP_NODE_LOCAL_VARIABLE_READ_NODE,
30423042
.location = YP_LOCATION_TOKEN_VALUE(name)
30433043
},
3044-
.constant_id = yp_parser_constant_id_token(parser, name),
3044+
.name = yp_parser_constant_id_token(parser, name),
30453045
.depth = depth
30463046
};
30473047

@@ -3050,7 +3050,7 @@ yp_local_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name,
30503050

30513051
// Allocate and initialize a new LocalVariableWriteNode node.
30523052
static yp_local_variable_write_node_t *
3053-
yp_local_variable_write_node_create(yp_parser_t *parser, yp_constant_id_t constant_id, uint32_t depth, yp_node_t *value, const yp_location_t *name_loc, const yp_token_t *operator) {
3053+
yp_local_variable_write_node_create(yp_parser_t *parser, yp_constant_id_t name, uint32_t depth, yp_node_t *value, const yp_location_t *name_loc, const yp_token_t *operator) {
30543054
yp_local_variable_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_write_node_t);
30553055

30563056
*node = (yp_local_variable_write_node_t) {
@@ -3061,7 +3061,7 @@ yp_local_variable_write_node_create(yp_parser_t *parser, yp_constant_id_t consta
30613061
.end = value->location.end
30623062
}
30633063
},
3064-
.constant_id = constant_id,
3064+
.name = name,
30653065
.depth = depth,
30663066
.value = value,
30673067
.name_loc = *name_loc,
@@ -3081,7 +3081,7 @@ yp_local_variable_target_node_create(yp_parser_t *parser, const yp_token_t *name
30813081
.type = YP_NODE_LOCAL_VARIABLE_TARGET_NODE,
30823082
.location = YP_LOCATION_TOKEN_VALUE(name)
30833083
},
3084-
.constant_id = yp_parser_constant_id_token(parser, name),
3084+
.name = yp_parser_constant_id_token(parser, name),
30853085
.depth = 0
30863086
};
30873087

@@ -3279,7 +3279,7 @@ yp_optional_parameter_node_create(yp_parser_t *parser, const yp_token_t *name, c
32793279
.end = value->location.end
32803280
}
32813281
},
3282-
.constant_id = yp_parser_constant_id_token(parser, name),
3282+
.name = yp_parser_constant_id_token(parser, name),
32833283
.name_loc = YP_LOCATION_TOKEN_VALUE(name),
32843284
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
32853285
.value = value
@@ -3630,7 +3630,7 @@ yp_required_parameter_node_create(yp_parser_t *parser, const yp_token_t *token)
36303630
.type = YP_NODE_REQUIRED_PARAMETER_NODE,
36313631
.location = YP_LOCATION_TOKEN_VALUE(token)
36323632
},
3633-
.constant_id = yp_parser_constant_id_token(parser, token)
3633+
.name = yp_parser_constant_id_token(parser, token)
36343634
};
36353635

36363636
return node;
@@ -7987,7 +7987,7 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod
79877987
case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
79887988
yp_local_variable_read_node_t *local_read = (yp_local_variable_read_node_t *) target;
79897989

7990-
yp_constant_id_t constant_id = local_read->constant_id;
7990+
yp_constant_id_t constant_id = local_read->name;
79917991
uint32_t depth = local_read->depth;
79927992

79937993
yp_location_t name_loc = target->location;
@@ -12793,7 +12793,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
1279312793
parser_lex(parser);
1279412794

1279512795
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
12796-
yp_node_t *result = (yp_node_t *) yp_local_variable_and_write_node_create(parser, node, &token, value, cast->constant_id, cast->depth);
12796+
yp_node_t *result = (yp_node_t *) yp_local_variable_and_write_node_create(parser, node, &token, value, cast->name, cast->depth);
1279712797

1279812798
yp_node_destroy(parser, node);
1279912799
return result;
@@ -12894,7 +12894,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
1289412894
parser_lex(parser);
1289512895

1289612896
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||=");
12897-
yp_node_t *result = (yp_node_t *) yp_local_variable_or_write_node_create(parser, node, &token, value, cast->constant_id, cast->depth);
12897+
yp_node_t *result = (yp_node_t *) yp_local_variable_or_write_node_create(parser, node, &token, value, cast->name, cast->depth);
1289812898

1289912899
yp_node_destroy(parser, node);
1290012900
return result;
@@ -13005,7 +13005,7 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
1300513005
parser_lex(parser);
1300613006

1300713007
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
13008-
yp_node_t *result = (yp_node_t *) yp_local_variable_operator_write_node_create(parser, node, &token, value, cast->constant_id, cast->depth);
13008+
yp_node_t *result = (yp_node_t *) yp_local_variable_operator_write_node_create(parser, node, &token, value, cast->name, cast->depth);
1300913009

1301013010
yp_node_destroy(parser, node);
1301113011
return result;

0 commit comments

Comments
 (0)