Skip to content

Commit e853fd0

Browse files
committed
Update AST
1 parent fe32f21 commit e853fd0

7 files changed

Lines changed: 101 additions & 34 deletions

File tree

config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,3 +485,15 @@ nodes:
485485
c_type: rbs_node
486486
- name: comment_location
487487
c_type: rbs_location
488+
- name: RBS::AST::Ruby::Annotations::ParamTypeAnnotation
489+
fields:
490+
- name: prefix_location
491+
c_type: rbs_location
492+
- name: name_location
493+
c_type: rbs_location
494+
- name: colon_location
495+
c_type: rbs_location
496+
- name: param_type
497+
c_type: rbs_node
498+
- name: comment_location
499+
c_type: rbs_location

ext/rbs_extension/ast_translation.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,24 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan
651651
&h
652652
);
653653
}
654+
case RBS_AST_RUBY_ANNOTATIONS_PARAM_TYPE_ANNOTATION: {
655+
rbs_ast_ruby_annotations_param_type_annotation_t *node = (rbs_ast_ruby_annotations_param_type_annotation_t *)instance;
656+
657+
VALUE h = rb_hash_new();
658+
rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_loc_to_ruby_location(ctx, node->base.location));
659+
rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_loc_to_ruby_location(ctx, node->prefix_location));
660+
rb_hash_aset(h, ID2SYM(rb_intern("name_location")), rbs_loc_to_ruby_location(ctx, node->name_location));
661+
rb_hash_aset(h, ID2SYM(rb_intern("colon_location")), rbs_loc_to_ruby_location(ctx, node->colon_location));
662+
rb_hash_aset(h, ID2SYM(rb_intern("param_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->param_type)); // rbs_node
663+
rb_hash_aset(h, ID2SYM(rb_intern("comment_location")), rbs_loc_to_ruby_location(ctx, node->comment_location));
664+
665+
666+
return CLASS_NEW_INSTANCE(
667+
RBS_AST_Ruby_Annotations_ParamTypeAnnotation,
668+
1,
669+
&h
670+
);
671+
}
654672
case RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION: {
655673
rbs_ast_ruby_annotations_return_type_annotation_t *node = (rbs_ast_ruby_annotations_return_type_annotation_t *)instance;
656674

ext/rbs_extension/class_constants.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ VALUE RBS_AST_Members_Public;
5252
VALUE RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation;
5353
VALUE RBS_AST_Ruby_Annotations_MethodTypesAnnotation;
5454
VALUE RBS_AST_Ruby_Annotations_NodeTypeAssertion;
55+
VALUE RBS_AST_Ruby_Annotations_ParamTypeAnnotation;
5556
VALUE RBS_AST_Ruby_Annotations_ReturnTypeAnnotation;
5657
VALUE RBS_AST_Ruby_Annotations_SkipAnnotation;
5758
VALUE RBS_AST_TypeParam;
@@ -133,6 +134,7 @@ void rbs__init_constants(void) {
133134
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation, RBS_AST_Ruby_Annotations, "ColonMethodTypeAnnotation");
134135
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_MethodTypesAnnotation, RBS_AST_Ruby_Annotations, "MethodTypesAnnotation");
135136
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_NodeTypeAssertion, RBS_AST_Ruby_Annotations, "NodeTypeAssertion");
137+
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ParamTypeAnnotation, RBS_AST_Ruby_Annotations, "ParamTypeAnnotation");
136138
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ReturnTypeAnnotation, RBS_AST_Ruby_Annotations, "ReturnTypeAnnotation");
137139
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_SkipAnnotation, RBS_AST_Ruby_Annotations, "SkipAnnotation");
138140
IMPORT_CONSTANT(RBS_AST_TypeParam, RBS_AST, "TypeParam");

ext/rbs_extension/class_constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extern VALUE RBS_AST_Members_Public;
5454
extern VALUE RBS_AST_Ruby_Annotations_ColonMethodTypeAnnotation;
5555
extern VALUE RBS_AST_Ruby_Annotations_MethodTypesAnnotation;
5656
extern VALUE RBS_AST_Ruby_Annotations_NodeTypeAssertion;
57+
extern VALUE RBS_AST_Ruby_Annotations_ParamTypeAnnotation;
5758
extern VALUE RBS_AST_Ruby_Annotations_ReturnTypeAnnotation;
5859
extern VALUE RBS_AST_Ruby_Annotations_SkipAnnotation;
5960
extern VALUE RBS_AST_TypeParam;

include/rbs/ast.h

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,40 +48,41 @@ enum rbs_node_type {
4848
RBS_AST_RUBY_ANNOTATIONS_COLON_METHOD_TYPE_ANNOTATION = 32,
4949
RBS_AST_RUBY_ANNOTATIONS_METHOD_TYPES_ANNOTATION = 33,
5050
RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION = 34,
51-
RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION = 35,
52-
RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION = 36,
53-
RBS_AST_STRING = 37,
54-
RBS_AST_TYPE_PARAM = 38,
55-
RBS_METHOD_TYPE = 39,
56-
RBS_NAMESPACE = 40,
57-
RBS_SIGNATURE = 41,
58-
RBS_TYPE_NAME = 42,
59-
RBS_TYPES_ALIAS = 43,
60-
RBS_TYPES_BASES_ANY = 44,
61-
RBS_TYPES_BASES_BOOL = 45,
62-
RBS_TYPES_BASES_BOTTOM = 46,
63-
RBS_TYPES_BASES_CLASS = 47,
64-
RBS_TYPES_BASES_INSTANCE = 48,
65-
RBS_TYPES_BASES_NIL = 49,
66-
RBS_TYPES_BASES_SELF = 50,
67-
RBS_TYPES_BASES_TOP = 51,
68-
RBS_TYPES_BASES_VOID = 52,
69-
RBS_TYPES_BLOCK = 53,
70-
RBS_TYPES_CLASS_INSTANCE = 54,
71-
RBS_TYPES_CLASS_SINGLETON = 55,
72-
RBS_TYPES_FUNCTION = 56,
73-
RBS_TYPES_FUNCTION_PARAM = 57,
74-
RBS_TYPES_INTERFACE = 58,
75-
RBS_TYPES_INTERSECTION = 59,
76-
RBS_TYPES_LITERAL = 60,
77-
RBS_TYPES_OPTIONAL = 61,
78-
RBS_TYPES_PROC = 62,
79-
RBS_TYPES_RECORD = 63,
80-
RBS_TYPES_RECORD_FIELD_TYPE = 64,
81-
RBS_TYPES_TUPLE = 65,
82-
RBS_TYPES_UNION = 66,
83-
RBS_TYPES_UNTYPED_FUNCTION = 67,
84-
RBS_TYPES_VARIABLE = 68,
51+
RBS_AST_RUBY_ANNOTATIONS_PARAM_TYPE_ANNOTATION = 35,
52+
RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION = 36,
53+
RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION = 37,
54+
RBS_AST_STRING = 38,
55+
RBS_AST_TYPE_PARAM = 39,
56+
RBS_METHOD_TYPE = 40,
57+
RBS_NAMESPACE = 41,
58+
RBS_SIGNATURE = 42,
59+
RBS_TYPE_NAME = 43,
60+
RBS_TYPES_ALIAS = 44,
61+
RBS_TYPES_BASES_ANY = 45,
62+
RBS_TYPES_BASES_BOOL = 46,
63+
RBS_TYPES_BASES_BOTTOM = 47,
64+
RBS_TYPES_BASES_CLASS = 48,
65+
RBS_TYPES_BASES_INSTANCE = 49,
66+
RBS_TYPES_BASES_NIL = 50,
67+
RBS_TYPES_BASES_SELF = 51,
68+
RBS_TYPES_BASES_TOP = 52,
69+
RBS_TYPES_BASES_VOID = 53,
70+
RBS_TYPES_BLOCK = 54,
71+
RBS_TYPES_CLASS_INSTANCE = 55,
72+
RBS_TYPES_CLASS_SINGLETON = 56,
73+
RBS_TYPES_FUNCTION = 57,
74+
RBS_TYPES_FUNCTION_PARAM = 58,
75+
RBS_TYPES_INTERFACE = 59,
76+
RBS_TYPES_INTERSECTION = 60,
77+
RBS_TYPES_LITERAL = 61,
78+
RBS_TYPES_OPTIONAL = 62,
79+
RBS_TYPES_PROC = 63,
80+
RBS_TYPES_RECORD = 64,
81+
RBS_TYPES_RECORD_FIELD_TYPE = 65,
82+
RBS_TYPES_TUPLE = 66,
83+
RBS_TYPES_UNION = 67,
84+
RBS_TYPES_UNTYPED_FUNCTION = 68,
85+
RBS_TYPES_VARIABLE = 69,
8586
RBS_KEYWORD,
8687
RBS_AST_SYMBOL,
8788
};
@@ -420,6 +421,16 @@ typedef struct rbs_ast_ruby_annotations_node_type_assertion {
420421
struct rbs_node *type;
421422
} rbs_ast_ruby_annotations_node_type_assertion_t;
422423

424+
typedef struct rbs_ast_ruby_annotations_param_type_annotation {
425+
rbs_node_t base;
426+
427+
struct rbs_location *prefix_location;
428+
struct rbs_location *name_location;
429+
struct rbs_location *colon_location;
430+
struct rbs_node *param_type;
431+
struct rbs_location *comment_location;
432+
} rbs_ast_ruby_annotations_param_type_annotation_t;
433+
423434
typedef struct rbs_ast_ruby_annotations_return_type_annotation {
424435
rbs_node_t base;
425436

@@ -655,6 +666,7 @@ typedef union rbs_ast_ruby_annotations {
655666
rbs_ast_ruby_annotations_node_type_assertion_t node_type_assertion;
656667
rbs_ast_ruby_annotations_return_type_annotation_t return_type_annotation;
657668
rbs_ast_ruby_annotations_skip_annotation_t skip_annotation;
669+
rbs_ast_ruby_annotations_param_type_annotation_t param_type_annotation;
658670
} rbs_ast_ruby_annotations_t;
659671

660672
/// `rbs_keyword_t` models RBS keywords like "private", "instance", "covariant", etc.
@@ -710,6 +722,7 @@ rbs_ast_members_public_t *rbs_ast_members_public_new(rbs_allocator_t *allocator,
710722
rbs_ast_ruby_annotations_colon_method_type_annotation_t *rbs_ast_ruby_annotations_colon_method_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_list_t *annotations, rbs_node_t *method_type);
711723
rbs_ast_ruby_annotations_method_types_annotation_t *rbs_ast_ruby_annotations_method_types_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_list_t *overloads, rbs_location_list_t *vertical_bar_locations);
712724
rbs_ast_ruby_annotations_node_type_assertion_t *rbs_ast_ruby_annotations_node_type_assertion_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_node_t *type);
725+
rbs_ast_ruby_annotations_param_type_annotation_t *rbs_ast_ruby_annotations_param_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *name_location, rbs_location_t *colon_location, rbs_node_t *param_type, rbs_location_t *comment_location);
713726
rbs_ast_ruby_annotations_return_type_annotation_t *rbs_ast_ruby_annotations_return_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *return_location, rbs_location_t *colon_location, rbs_node_t *return_type, rbs_location_t *comment_location);
714727
rbs_ast_ruby_annotations_skip_annotation_t *rbs_ast_ruby_annotations_skip_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *skip_location, rbs_location_t *comment_location);
715728
rbs_ast_string_t *rbs_ast_string_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_string_t string);

src/ast.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const char* rbs_node_type_name(rbs_node_t *node) {
4747
case RBS_AST_RUBY_ANNOTATIONS_COLON_METHOD_TYPE_ANNOTATION: return "RBS::AST::Ruby::Annotations::ColonMethodTypeAnnotation";
4848
case RBS_AST_RUBY_ANNOTATIONS_METHOD_TYPES_ANNOTATION: return "RBS::AST::Ruby::Annotations::MethodTypesAnnotation";
4949
case RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION: return "RBS::AST::Ruby::Annotations::NodeTypeAssertion";
50+
case RBS_AST_RUBY_ANNOTATIONS_PARAM_TYPE_ANNOTATION: return "RBS::AST::Ruby::Annotations::ParamTypeAnnotation";
5051
case RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION: return "RBS::AST::Ruby::Annotations::ReturnTypeAnnotation";
5152
case RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION: return "RBS::AST::Ruby::Annotations::SkipAnnotation";
5253
case RBS_AST_STRING: return "RBS::AST::String";
@@ -811,6 +812,25 @@ rbs_ast_ruby_annotations_node_type_assertion_t *rbs_ast_ruby_annotations_node_ty
811812
return instance;
812813
}
813814
#line 153 "prism/templates/src/ast.c.erb"
815+
rbs_ast_ruby_annotations_param_type_annotation_t *rbs_ast_ruby_annotations_param_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *name_location, rbs_location_t *colon_location, rbs_node_t *param_type, rbs_location_t *comment_location) {
816+
rbs_ast_ruby_annotations_param_type_annotation_t *instance = rbs_allocator_alloc(allocator, rbs_ast_ruby_annotations_param_type_annotation_t);
817+
818+
819+
*instance = (rbs_ast_ruby_annotations_param_type_annotation_t) {
820+
.base = (rbs_node_t) {
821+
.type = RBS_AST_RUBY_ANNOTATIONS_PARAM_TYPE_ANNOTATION,
822+
.location = location,
823+
},
824+
.prefix_location = prefix_location,
825+
.name_location = name_location,
826+
.colon_location = colon_location,
827+
.param_type = param_type,
828+
.comment_location = comment_location,
829+
};
830+
831+
return instance;
832+
}
833+
#line 153 "prism/templates/src/ast.c.erb"
814834
rbs_ast_ruby_annotations_return_type_annotation_t *rbs_ast_ruby_annotations_return_type_annotation_new(rbs_allocator_t *allocator, rbs_location_t *location, rbs_location_t *prefix_location, rbs_location_t *return_location, rbs_location_t *colon_location, rbs_node_t *return_type, rbs_location_t *comment_location) {
815835
rbs_ast_ruby_annotations_return_type_annotation_t *instance = rbs_allocator_alloc(allocator, rbs_ast_ruby_annotations_return_type_annotation_t);
816836

templates/include/rbs/ast.h.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ typedef union rbs_ast_ruby_annotations {
8282
rbs_ast_ruby_annotations_node_type_assertion_t node_type_assertion;
8383
rbs_ast_ruby_annotations_return_type_annotation_t return_type_annotation;
8484
rbs_ast_ruby_annotations_skip_annotation_t skip_annotation;
85+
rbs_ast_ruby_annotations_param_type_annotation_t param_type_annotation;
8586
} rbs_ast_ruby_annotations_t;
8687

8788
/// `rbs_keyword_t` models RBS keywords like "private", "instance", "covariant", etc.

0 commit comments

Comments
 (0)