Skip to content

Commit 4b16d4a

Browse files
committed
Change ast_node_type_to_string to use hb_string
1 parent 818278a commit 4b16d4a

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

templates/ext/herb/nodes.c.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ static VALUE rb_<%= node.human %>_from_c_struct(<%= node.struct_type %>* <%= nod
2222
VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
2323
VALUE <%= node.name %> = rb_define_class_under(AST, "<%= node.name %>", Node);
2424

25-
VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
25+
hb_string_T node_type = ast_node_type_to_string(node);
26+
VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
2627
VALUE location = rb_location_from_c_struct(node->location);
2728
VALUE errors = rb_errors_array_from_c_array(node->errors);
2829

templates/javascript/packages/node/extension/nodes.cpp.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ napi_value <%= node.human %>NodeFromCStruct(napi_env env, <%= node.struct_type %
2525
napi_value result;
2626
napi_create_object(env, &result);
2727

28-
napi_value type = CreateString(env, ast_node_type_to_string(&<%= node.human %>->base));
28+
napi_value type = CreateStringFromHbString(env, ast_node_type_to_string(&<%= node.human %>->base));
2929
napi_set_named_property(env, result, "type", type);
3030

3131
napi_value location = CreateLocation(env, <%= node.human %>->base.location);

templates/src/ast_nodes.c.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
}
5050
<%- end -%>
5151

52-
const char* ast_node_type_to_string(AST_NODE_T* node) {
52+
hb_string_T ast_node_type_to_string(AST_NODE_T* node) {
5353
switch (node->type) {
5454
<%- nodes.each do |node| -%>
55-
case <%= node.type %>: return "<%= node.type %>";
55+
case <%= node.type %>: return hb_string("<%= node.type %>");
5656
<%- end -%>
5757
}
5858

59-
return "Unknown ast_node_type_T";
59+
return hb_string("Unknown ast_node_type_T");
6060
}
6161

6262
hb_string_T ast_node_human_type(AST_NODE_T* node) {

templates/src/include/ast_nodes.h.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef struct <%= node.struct_name %> {
4141
<%= node.struct_type %>* ast_<%= node.human %>_init(<%= arguments.join(", ") %>);
4242
<%- end -%>
4343

44-
const char* ast_node_type_to_string(AST_NODE_T* node);
44+
hb_string_T ast_node_type_to_string(AST_NODE_T* node);
4545
hb_string_T ast_node_human_type(AST_NODE_T* node);
4646

4747
#endif

templates/wasm/nodes.cpp.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ val <%= node.name %>FromCStruct(<%= node.struct_type %>* <%= node.human %>) {
2121
if (!<%= node.human %>) return val::null();
2222

2323
val result = val::object();
24-
result.set("type", CreateString(ast_node_type_to_string(&<%= node.human %>->base)));
24+
result.set("type", CreateStringFromHbString(ast_node_type_to_string(&<%= node.human %>->base)));
2525
result.set("location", CreateLocation(<%= node.human %>->base.location));
2626
result.set("errors", ErrorsArrayFromCArray(<%= node.human %>->base.errors));
2727

0 commit comments

Comments
 (0)