Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/analyze/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static bool analyze_erb_content(const AST_NODE_T* node, void* data) {
erb_content_node->base.location.start,
erb_content_node->base.location.end,
allocator,
erb_content_node->base.errors
&erb_content_node->base.errors
);
}

Expand All @@ -97,7 +97,7 @@ static bool analyze_erb_content(const AST_NODE_T* node, void* data) {
erb_content_node->base.location.start,
erb_content_node->base.location.end,
allocator,
erb_content_node->base.errors
&erb_content_node->base.errors
);
}
} else {
Expand Down
13 changes: 6 additions & 7 deletions src/analyze/conditional_elements.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <string.h>

typedef struct {
hb_array_T* document_errors;
hb_array_T** document_errors;
hb_allocator_T* allocator;
} conditional_elements_context_T;

Expand Down Expand Up @@ -182,9 +182,8 @@ typedef struct {
bool is_if;
} conditional_open_tag_T;

static void rewrite_conditional_elements(hb_array_T* nodes, hb_array_T* document_errors, hb_allocator_T* allocator) {
static void rewrite_conditional_elements(hb_array_T* nodes, hb_array_T** document_errors, hb_allocator_T* allocator) {
if (!nodes || hb_array_size(nodes) == 0) { return; }
if (!document_errors) { return; }

for (size_t open_index = 0; open_index < hb_array_size(nodes); open_index++) {
AST_NODE_T* open_node = (AST_NODE_T*) hb_array_get(nodes, open_index);
Expand Down Expand Up @@ -235,7 +234,7 @@ static void rewrite_conditional_elements(hb_array_T* nodes, hb_array_T* document
allocator
);

hb_array_append(document_errors, multiple_tags_error);
hb_array_append_lazy(document_errors, multiple_tags_error, allocator);
break;
}
}
Expand Down Expand Up @@ -339,7 +338,7 @@ static void rewrite_conditional_elements(hb_array_T* nodes, hb_array_T* document
allocator
);

hb_array_append(document_errors, mismatch_error);
hb_array_append_lazy(document_errors, mismatch_error, allocator);
continue;
}

Expand All @@ -355,7 +354,7 @@ static void rewrite_conditional_elements(hb_array_T* nodes, hb_array_T* document

position_T start_position = matched_open->open_conditional->location.start;
position_T end_position = node->location.end;
hb_array_T* errors = hb_array_init(0, allocator);
hb_array_T* errors = NULL;

AST_HTML_CONDITIONAL_ELEMENT_NODE_T* conditional_element = ast_html_conditional_element_node_init(
matched_open->condition,
Expand Down Expand Up @@ -589,6 +588,6 @@ static bool transform_conditional_elements_visitor(const AST_NODE_T* node, void*
}

void herb_transform_conditional_elements(AST_DOCUMENT_NODE_T* document, hb_allocator_T* allocator) {
conditional_elements_context_T context = { .document_errors = document->base.errors, .allocator = allocator };
conditional_elements_context_T context = { .document_errors = &document->base.errors, .allocator = allocator };
herb_visit_node((AST_NODE_T*) document, transform_conditional_elements_visitor, &context);
}
4 changes: 1 addition & 3 deletions src/analyze/conditional_open_tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ static void add_multiple_tags_error_to_erb_node(
allocator
);

if (!erb_node->errors) { erb_node->errors = hb_array_init(0, allocator); }

hb_array_append(erb_node->errors, error);
hb_array_append_lazy(&erb_node->errors, error, allocator);
}

static void check_and_report_multiple_tags_in_if(AST_ERB_IF_NODE_T* if_node, hb_allocator_T* allocator) {
Expand Down
4 changes: 2 additions & 2 deletions src/analyze/invalid_structures.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) {
node->location.start,
node->location.end,
context->allocator,
node->errors
&((AST_NODE_T*) node)->errors
);
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) {
subsequent->location.start,
subsequent->location.end,
context->allocator,
subsequent->errors
&((AST_NODE_T*) subsequent)->errors
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/analyze/parse_errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void parse_erb_content_errors(AST_NODE_T* erb_node, const char* source, h
allocator
);

hb_array_append(erb_node->errors, parse_error);
hb_array_append_lazy(&erb_node->errors, parse_error, allocator);
}

pm_node_destroy(&parser, root);
Expand Down Expand Up @@ -74,7 +74,7 @@ void herb_analyze_parse_errors(AST_DOCUMENT_NODE_T* document, const char* source

RUBY_PARSE_ERROR_T* parse_error =
ruby_parse_error_from_prism_error(error, (AST_NODE_T*) document, source, &parser, allocator);
hb_array_append(document->base.errors, parse_error);
hb_array_append_lazy(&document->base.errors, parse_error, allocator);
}

pm_node_destroy(&parser, root);
Expand Down
16 changes: 8 additions & 8 deletions src/analyze/render_nodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(

if (!locals) { locals = hb_array_init(0, allocator); }

hb_array_T* errors = hb_array_init(0, allocator);
hb_array_T* errors = NULL;

if (!has_keyword_partial && partial && keyword_hash) {
keyword_result_T locals_keyword = find_keyword_value(keyword_hash, "locals", allocator);
Expand All @@ -478,7 +478,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
erb_node->base.location.start,
erb_node->base.location.end,
allocator,
errors
&errors
);

hb_allocator_dealloc(allocator, locals_keyword.value);
Expand Down Expand Up @@ -551,7 +551,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
erb_node->base.location.start,
erb_node->base.location.end,
allocator,
errors
&errors
);

hb_allocator_dealloc(allocator, keywords_buffer);
Expand All @@ -560,7 +560,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(

if (!partial && !template_path && !layout && !file && !inline_template && !body && !plain && !html && !renderable
&& !has_positional_partial && !object) {
append_render_no_arguments_error(erb_node->base.location.start, erb_node->base.location.end, allocator, errors);
append_render_no_arguments_error(erb_node->base.location.start, erb_node->base.location.end, allocator, &errors);
}

if (has_positional_partial && has_keyword_partial && keyword_hash) {
Expand All @@ -572,7 +572,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
erb_node->base.location.start,
erb_node->base.location.end,
allocator,
errors
&errors
);

if (keyword_partial.value) { hb_allocator_dealloc(allocator, keyword_partial.value); }
Expand Down Expand Up @@ -600,7 +600,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
erb_node->base.location.start,
erb_node->base.location.end,
allocator,
errors
&errors
);
}
}
Expand All @@ -610,7 +610,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
erb_node->base.location.start,
erb_node->base.location.end,
allocator,
errors
&errors
);
}

Expand All @@ -620,7 +620,7 @@ static AST_ERB_RENDER_NODE_T* create_render_node_from_call(
erb_node->base.location.start,
erb_node->base.location.end,
allocator,
errors
&errors
);
}

Expand Down
12 changes: 6 additions & 6 deletions src/analyze/strict_locals.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static hb_array_T* extract_strict_locals(
);

hb_array_T* node_errors = hb_array_init(1, allocator);
append_strict_locals_positional_argument_error(hb_string_from_c_string(name), start, end, allocator, node_errors);
append_strict_locals_positional_argument_error(hb_string_from_c_string(name), start, end, allocator, &node_errors);

AST_RUBY_STRICT_LOCAL_NODE_T* local =
ast_ruby_strict_local_node_init(name_token, value_node, false, false, start, value_end, node_errors, allocator);
Expand Down Expand Up @@ -229,7 +229,7 @@ static hb_array_T* extract_strict_locals(
position_T end = name_token ? name_token->location.end : start;

hb_array_T* node_errors = hb_array_init(1, allocator);
append_strict_locals_positional_argument_error(hb_string_from_c_string(name), start, end, allocator, node_errors);
append_strict_locals_positional_argument_error(hb_string_from_c_string(name), start, end, allocator, &node_errors);

AST_RUBY_STRICT_LOCAL_NODE_T* local =
ast_ruby_strict_local_node_init(name_token, NULL, true, false, start, end, node_errors, allocator);
Expand Down Expand Up @@ -262,7 +262,7 @@ static hb_array_T* extract_strict_locals(
position_T end = name_token ? name_token->location.end : start;

hb_array_T* node_errors = hb_array_init(1, allocator);
append_strict_locals_block_argument_error(hb_string_from_c_string(name), start, end, allocator, node_errors);
append_strict_locals_block_argument_error(hb_string_from_c_string(name), start, end, allocator, &node_errors);

AST_RUBY_STRICT_LOCAL_NODE_T* local =
ast_ruby_strict_local_node_init(name_token, NULL, false, false, start, end, node_errors, allocator);
Expand Down Expand Up @@ -296,7 +296,7 @@ static hb_array_T* extract_strict_locals(
position_T end = name_token ? name_token->location.end : start;

hb_array_T* node_errors = hb_array_init(1, allocator);
append_strict_locals_splat_argument_error(hb_string_from_c_string(name), start, end, allocator, node_errors);
append_strict_locals_splat_argument_error(hb_string_from_c_string(name), start, end, allocator, &node_errors);

AST_RUBY_STRICT_LOCAL_NODE_T* local =
ast_ruby_strict_local_node_init(name_token, NULL, false, false, start, end, node_errors, allocator);
Expand Down Expand Up @@ -486,7 +486,7 @@ static AST_ERB_STRICT_LOCALS_NODE_T* create_strict_locals_node(
error_start,
error_end,
allocator,
errors
&errors
);
hb_allocator_dealloc(allocator, rest);

Expand Down Expand Up @@ -609,7 +609,7 @@ static void transform_strict_locals_in_array(hb_array_T* array, analyze_ruby_con
strict_locals_node->base.location.start,
strict_locals_node->base.location.end,
context->allocator,
strict_locals_node->base.errors
&strict_locals_node->base.errors
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/ast_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ void ast_node_init(
node->location.start = start;
node->location.end = end;

(void) allocator;

if (errors == NULL) {
node->errors = hb_array_init(0, allocator);
node->errors = NULL;
} else {
node->errors = errors;
}
Expand Down
14 changes: 7 additions & 7 deletions src/include/parser_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ token_T* parser_pop_open_tag(const parser_T* parser);

void parser_append_unexpected_error_impl(
parser_T* parser,
hb_array_T* errors,
hb_array_T** errors,
const char* description,
token_type_T first_token,
...
Expand All @@ -25,11 +25,11 @@ void parser_append_unexpected_error_impl(

void parser_append_unexpected_error_string(
parser_T* parser,
hb_array_T* errors,
hb_array_T** errors,
const char* description,
const char* expected
);
void parser_append_unexpected_token_error(parser_T* parser, token_type_T expected_type, hb_array_T* errors);
void parser_append_unexpected_token_error(parser_T* parser, token_type_T expected_type, hb_array_T** errors);

void parser_append_literal_node_from_buffer(
const parser_T* parser,
Expand All @@ -51,21 +51,21 @@ bool parser_is_expected_closing_tag_name(hb_string_T tag_name, foreign_content_t

token_T* parser_advance(parser_T* parser);
token_T* parser_consume_if_present(parser_T* parser, token_type_T type);
token_T* parser_consume_expected(parser_T* parser, token_type_T type, hb_array_T* array);
token_T* parser_consume_expected(parser_T* parser, token_type_T type, hb_array_T** array);

AST_HTML_ELEMENT_NODE_T* parser_handle_missing_close_tag(
parser_T* parser,
AST_HTML_OPEN_TAG_NODE_T* open_tag,
hb_array_T* body,
hb_array_T* errors
hb_array_T** errors
);
void parser_handle_mismatched_tags(
const parser_T* parser,
const AST_HTML_CLOSE_TAG_NODE_T* close_tag,
hb_array_T* errors
hb_array_T** errors
);

void parser_synchronize(parser_T* parser, hb_array_T* errors);
void parser_synchronize(parser_T* parser, hb_array_T** errors);

bool parser_can_close_ancestor(const parser_T* parser, hb_string_T tag_name);
size_t parser_find_ancestor_depth(const parser_T* parser, hb_string_T tag_name);
Expand Down
1 change: 1 addition & 0 deletions src/include/util/hb_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void* hb_array_first(hb_array_T* array);
void* hb_array_last(hb_array_T* array);

bool hb_array_append(hb_array_T* array, void* item);
bool hb_array_append_lazy(hb_array_T** array, void* item, struct hb_allocator* allocator);
void hb_array_set(const hb_array_T* array, size_t index, void* item);
void hb_array_free(hb_array_T** array);
void hb_array_remove(hb_array_T* array, size_t index);
Expand Down
Loading
Loading