Skip to content

Commit 1780c2f

Browse files
committed
Update AST
1 parent 4832918 commit 1780c2f

7 files changed

Lines changed: 103 additions & 36 deletions

File tree

config.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,19 @@ nodes:
784784
- name: type_name_location
785785
c_type: rbs_location_range
786786
optional: true
787+
- name: RBS::AST::Ruby::Annotations::ParamTypeAnnotation
788+
fields:
789+
- name: prefix_location
790+
c_type: rbs_location_range
791+
- name: name_location
792+
c_type: rbs_location_range
793+
- name: colon_location
794+
c_type: rbs_location_range
795+
- name: param_type
796+
c_type: rbs_node
797+
- name: comment_location
798+
c_type: rbs_location_range
799+
optional: true
787800

788801
enums:
789802
attribute_visibility:
@@ -815,4 +828,4 @@ enums:
815828
symbols:
816829
- invariant
817830
- covariant
818-
- contravariant
831+
- contravariant

ext/rbs_extension/ast_translation.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,23 @@ VALUE rbs_struct_to_ruby_value(rbs_translation_context_t ctx, rbs_node_t *instan
921921
&h
922922
);
923923
}
924+
case RBS_AST_RUBY_ANNOTATIONS_PARAM_TYPE_ANNOTATION: {
925+
rbs_ast_ruby_annotations_param_type_annotation_t *node = (rbs_ast_ruby_annotations_param_type_annotation_t *) instance;
926+
927+
VALUE h = rb_hash_new();
928+
rb_hash_aset(h, ID2SYM(rb_intern("location")), rbs_location_range_to_ruby_location(ctx, node->base.location));
929+
rb_hash_aset(h, ID2SYM(rb_intern("prefix_location")), rbs_location_range_to_ruby_location(ctx, node->prefix_location));
930+
rb_hash_aset(h, ID2SYM(rb_intern("name_location")), rbs_location_range_to_ruby_location(ctx, node->name_location));
931+
rb_hash_aset(h, ID2SYM(rb_intern("colon_location")), rbs_location_range_to_ruby_location(ctx, node->colon_location));
932+
rb_hash_aset(h, ID2SYM(rb_intern("param_type")), rbs_struct_to_ruby_value(ctx, (rbs_node_t *) node->param_type)); // rbs_node
933+
rb_hash_aset(h, ID2SYM(rb_intern("comment_location")), rbs_location_range_to_ruby_location(ctx, node->comment_location)); // optional
934+
935+
return CLASS_NEW_INSTANCE(
936+
RBS_AST_Ruby_Annotations_ParamTypeAnnotation,
937+
1,
938+
&h
939+
);
940+
}
924941
case RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION: {
925942
rbs_ast_ruby_annotations_return_type_annotation_t *node = (rbs_ast_ruby_annotations_return_type_annotation_t *) instance;
926943

ext/rbs_extension/class_constants.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ VALUE RBS_AST_Ruby_Annotations_InstanceVariableAnnotation;
5353
VALUE RBS_AST_Ruby_Annotations_MethodTypesAnnotation;
5454
VALUE RBS_AST_Ruby_Annotations_ModuleAliasAnnotation;
5555
VALUE RBS_AST_Ruby_Annotations_NodeTypeAssertion;
56+
VALUE RBS_AST_Ruby_Annotations_ParamTypeAnnotation;
5657
VALUE RBS_AST_Ruby_Annotations_ReturnTypeAnnotation;
5758
VALUE RBS_AST_Ruby_Annotations_SkipAnnotation;
5859
VALUE RBS_AST_Ruby_Annotations_TypeApplicationAnnotation;
@@ -142,6 +143,7 @@ void rbs__init_constants(void) {
142143
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_MethodTypesAnnotation, RBS_AST_Ruby_Annotations, "MethodTypesAnnotation");
143144
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ModuleAliasAnnotation, RBS_AST_Ruby_Annotations, "ModuleAliasAnnotation");
144145
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_NodeTypeAssertion, RBS_AST_Ruby_Annotations, "NodeTypeAssertion");
146+
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ParamTypeAnnotation, RBS_AST_Ruby_Annotations, "ParamTypeAnnotation");
145147
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_ReturnTypeAnnotation, RBS_AST_Ruby_Annotations, "ReturnTypeAnnotation");
146148
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_SkipAnnotation, RBS_AST_Ruby_Annotations, "SkipAnnotation");
147149
IMPORT_CONSTANT(RBS_AST_Ruby_Annotations_TypeApplicationAnnotation, RBS_AST_Ruby_Annotations, "TypeApplicationAnnotation");

ext/rbs_extension/class_constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extern VALUE RBS_AST_Ruby_Annotations_InstanceVariableAnnotation;
6161
extern VALUE RBS_AST_Ruby_Annotations_MethodTypesAnnotation;
6262
extern VALUE RBS_AST_Ruby_Annotations_ModuleAliasAnnotation;
6363
extern VALUE RBS_AST_Ruby_Annotations_NodeTypeAssertion;
64+
extern VALUE RBS_AST_Ruby_Annotations_ParamTypeAnnotation;
6465
extern VALUE RBS_AST_Ruby_Annotations_ReturnTypeAnnotation;
6566
extern VALUE RBS_AST_Ruby_Annotations_SkipAnnotation;
6667
extern VALUE RBS_AST_Ruby_Annotations_TypeApplicationAnnotation;

include/rbs/ast.h

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -96,41 +96,42 @@ enum rbs_node_type {
9696
RBS_AST_RUBY_ANNOTATIONS_METHOD_TYPES_ANNOTATION = 35,
9797
RBS_AST_RUBY_ANNOTATIONS_MODULE_ALIAS_ANNOTATION = 36,
9898
RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION = 37,
99-
RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION = 38,
100-
RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION = 39,
101-
RBS_AST_RUBY_ANNOTATIONS_TYPE_APPLICATION_ANNOTATION = 40,
102-
RBS_AST_STRING = 41,
103-
RBS_AST_TYPE_PARAM = 42,
104-
RBS_METHOD_TYPE = 43,
105-
RBS_NAMESPACE = 44,
106-
RBS_SIGNATURE = 45,
107-
RBS_TYPE_NAME = 46,
108-
RBS_TYPES_ALIAS = 47,
109-
RBS_TYPES_BASES_ANY = 48,
110-
RBS_TYPES_BASES_BOOL = 49,
111-
RBS_TYPES_BASES_BOTTOM = 50,
112-
RBS_TYPES_BASES_CLASS = 51,
113-
RBS_TYPES_BASES_INSTANCE = 52,
114-
RBS_TYPES_BASES_NIL = 53,
115-
RBS_TYPES_BASES_SELF = 54,
116-
RBS_TYPES_BASES_TOP = 55,
117-
RBS_TYPES_BASES_VOID = 56,
118-
RBS_TYPES_BLOCK = 57,
119-
RBS_TYPES_CLASS_INSTANCE = 58,
120-
RBS_TYPES_CLASS_SINGLETON = 59,
121-
RBS_TYPES_FUNCTION = 60,
122-
RBS_TYPES_FUNCTION_PARAM = 61,
123-
RBS_TYPES_INTERFACE = 62,
124-
RBS_TYPES_INTERSECTION = 63,
125-
RBS_TYPES_LITERAL = 64,
126-
RBS_TYPES_OPTIONAL = 65,
127-
RBS_TYPES_PROC = 66,
128-
RBS_TYPES_RECORD = 67,
129-
RBS_TYPES_RECORD_FIELD_TYPE = 68,
130-
RBS_TYPES_TUPLE = 69,
131-
RBS_TYPES_UNION = 70,
132-
RBS_TYPES_UNTYPED_FUNCTION = 71,
133-
RBS_TYPES_VARIABLE = 72,
99+
RBS_AST_RUBY_ANNOTATIONS_PARAM_TYPE_ANNOTATION = 38,
100+
RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION = 39,
101+
RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION = 40,
102+
RBS_AST_RUBY_ANNOTATIONS_TYPE_APPLICATION_ANNOTATION = 41,
103+
RBS_AST_STRING = 42,
104+
RBS_AST_TYPE_PARAM = 43,
105+
RBS_METHOD_TYPE = 44,
106+
RBS_NAMESPACE = 45,
107+
RBS_SIGNATURE = 46,
108+
RBS_TYPE_NAME = 47,
109+
RBS_TYPES_ALIAS = 48,
110+
RBS_TYPES_BASES_ANY = 49,
111+
RBS_TYPES_BASES_BOOL = 50,
112+
RBS_TYPES_BASES_BOTTOM = 51,
113+
RBS_TYPES_BASES_CLASS = 52,
114+
RBS_TYPES_BASES_INSTANCE = 53,
115+
RBS_TYPES_BASES_NIL = 54,
116+
RBS_TYPES_BASES_SELF = 55,
117+
RBS_TYPES_BASES_TOP = 56,
118+
RBS_TYPES_BASES_VOID = 57,
119+
RBS_TYPES_BLOCK = 58,
120+
RBS_TYPES_CLASS_INSTANCE = 59,
121+
RBS_TYPES_CLASS_SINGLETON = 60,
122+
RBS_TYPES_FUNCTION = 61,
123+
RBS_TYPES_FUNCTION_PARAM = 62,
124+
RBS_TYPES_INTERFACE = 63,
125+
RBS_TYPES_INTERSECTION = 64,
126+
RBS_TYPES_LITERAL = 65,
127+
RBS_TYPES_OPTIONAL = 66,
128+
RBS_TYPES_PROC = 67,
129+
RBS_TYPES_RECORD = 68,
130+
RBS_TYPES_RECORD_FIELD_TYPE = 69,
131+
RBS_TYPES_TUPLE = 70,
132+
RBS_TYPES_UNION = 71,
133+
RBS_TYPES_UNTYPED_FUNCTION = 72,
134+
RBS_TYPES_VARIABLE = 73,
134135
RBS_AST_SYMBOL,
135136
};
136137

@@ -612,6 +613,16 @@ typedef struct rbs_ast_ruby_annotations_node_type_assertion {
612613
struct rbs_node *type;
613614
} rbs_ast_ruby_annotations_node_type_assertion_t;
614615

616+
typedef struct rbs_ast_ruby_annotations_param_type_annotation {
617+
rbs_node_t base;
618+
619+
rbs_location_range prefix_location;
620+
rbs_location_range name_location;
621+
rbs_location_range colon_location;
622+
struct rbs_node *param_type;
623+
rbs_location_range comment_location; /* Optional */
624+
} rbs_ast_ruby_annotations_param_type_annotation_t;
625+
615626
typedef struct rbs_ast_ruby_annotations_return_type_annotation {
616627
rbs_node_t base;
617628

@@ -881,6 +892,7 @@ typedef union rbs_ast_ruby_annotations {
881892
rbs_ast_ruby_annotations_node_type_assertion_t node_type_assertion;
882893
rbs_ast_ruby_annotations_return_type_annotation_t return_type_annotation;
883894
rbs_ast_ruby_annotations_skip_annotation_t skip_annotation;
895+
rbs_ast_ruby_annotations_param_type_annotation_t param_type_annotation;
884896
} rbs_ast_ruby_annotations_t;
885897

886898
/// `rbs_ast_symbol_t` models user-defined identifiers like class names, method names, etc.
@@ -929,6 +941,7 @@ rbs_ast_ruby_annotations_instance_variable_annotation_t *rbs_ast_ruby_annotation
929941
rbs_ast_ruby_annotations_method_types_annotation_t *rbs_ast_ruby_annotations_method_types_annotation_new(rbs_allocator_t *allocator, rbs_location_range location, rbs_location_range prefix_location, rbs_node_list_t *overloads, rbs_location_range_list_t *vertical_bar_locations, rbs_location_range dot3_location);
930942
rbs_ast_ruby_annotations_module_alias_annotation_t *rbs_ast_ruby_annotations_module_alias_annotation_new(rbs_allocator_t *allocator, rbs_location_range location, rbs_location_range prefix_location, rbs_location_range keyword_location, rbs_type_name_t *type_name, rbs_location_range type_name_location);
931943
rbs_ast_ruby_annotations_node_type_assertion_t *rbs_ast_ruby_annotations_node_type_assertion_new(rbs_allocator_t *allocator, rbs_location_range location, rbs_location_range prefix_location, rbs_node_t *type);
944+
rbs_ast_ruby_annotations_param_type_annotation_t *rbs_ast_ruby_annotations_param_type_annotation_new(rbs_allocator_t *allocator, rbs_location_range location, rbs_location_range prefix_location, rbs_location_range name_location, rbs_location_range colon_location, rbs_node_t *param_type, rbs_location_range comment_location);
932945
rbs_ast_ruby_annotations_return_type_annotation_t *rbs_ast_ruby_annotations_return_type_annotation_new(rbs_allocator_t *allocator, rbs_location_range location, rbs_location_range prefix_location, rbs_location_range return_location, rbs_location_range colon_location, rbs_node_t *return_type, rbs_location_range comment_location);
933946
rbs_ast_ruby_annotations_skip_annotation_t *rbs_ast_ruby_annotations_skip_annotation_new(rbs_allocator_t *allocator, rbs_location_range location, rbs_location_range prefix_location, rbs_location_range skip_location, rbs_location_range comment_location);
934947
rbs_ast_ruby_annotations_type_application_annotation_t *rbs_ast_ruby_annotations_type_application_annotation_new(rbs_allocator_t *allocator, rbs_location_range location, rbs_location_range prefix_location, rbs_node_list_t *type_args, rbs_location_range close_bracket_location, rbs_location_range_list_t *comma_locations);

src/ast.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ const char *rbs_node_type_name(rbs_node_t *node) {
8787
return "RBS::AST::Ruby::Annotations::ModuleAliasAnnotation";
8888
case RBS_AST_RUBY_ANNOTATIONS_NODE_TYPE_ASSERTION:
8989
return "RBS::AST::Ruby::Annotations::NodeTypeAssertion";
90+
case RBS_AST_RUBY_ANNOTATIONS_PARAM_TYPE_ANNOTATION:
91+
return "RBS::AST::Ruby::Annotations::ParamTypeAnnotation";
9092
case RBS_AST_RUBY_ANNOTATIONS_RETURN_TYPE_ANNOTATION:
9193
return "RBS::AST::Ruby::Annotations::ReturnTypeAnnotation";
9294
case RBS_AST_RUBY_ANNOTATIONS_SKIP_ANNOTATION:
@@ -983,6 +985,24 @@ rbs_ast_ruby_annotations_node_type_assertion_t *rbs_ast_ruby_annotations_node_ty
983985
return instance;
984986
}
985987
#line 140 "prism/templates/src/ast.c.erb"
988+
rbs_ast_ruby_annotations_param_type_annotation_t *rbs_ast_ruby_annotations_param_type_annotation_new(rbs_allocator_t *allocator, rbs_location_range location, rbs_location_range prefix_location, rbs_location_range name_location, rbs_location_range colon_location, rbs_node_t *param_type, rbs_location_range comment_location) {
989+
rbs_ast_ruby_annotations_param_type_annotation_t *instance = rbs_allocator_alloc(allocator, rbs_ast_ruby_annotations_param_type_annotation_t);
990+
991+
*instance = (rbs_ast_ruby_annotations_param_type_annotation_t) {
992+
.base = (rbs_node_t) {
993+
.type = RBS_AST_RUBY_ANNOTATIONS_PARAM_TYPE_ANNOTATION,
994+
.location = location,
995+
},
996+
.prefix_location = prefix_location,
997+
.name_location = name_location,
998+
.colon_location = colon_location,
999+
.param_type = param_type,
1000+
.comment_location = comment_location,
1001+
};
1002+
1003+
return instance;
1004+
}
1005+
#line 140 "prism/templates/src/ast.c.erb"
9861006
rbs_ast_ruby_annotations_return_type_annotation_t *rbs_ast_ruby_annotations_return_type_annotation_new(rbs_allocator_t *allocator, rbs_location_range location, rbs_location_range prefix_location, rbs_location_range return_location, rbs_location_range colon_location, rbs_node_t *return_type, rbs_location_range comment_location) {
9871007
rbs_ast_ruby_annotations_return_type_annotation_t *instance = rbs_allocator_alloc(allocator, rbs_ast_ruby_annotations_return_type_annotation_t);
9881008

templates/include/rbs/ast.h.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ typedef union rbs_ast_ruby_annotations {
110110
rbs_ast_ruby_annotations_node_type_assertion_t node_type_assertion;
111111
rbs_ast_ruby_annotations_return_type_annotation_t return_type_annotation;
112112
rbs_ast_ruby_annotations_skip_annotation_t skip_annotation;
113+
rbs_ast_ruby_annotations_param_type_annotation_t param_type_annotation;
113114
} rbs_ast_ruby_annotations_t;
114115

115116
/// `rbs_ast_symbol_t` models user-defined identifiers like class names, method names, etc.

0 commit comments

Comments
 (0)