diff --git a/parser_library/src/expressions/conditional_assembly/ca_expression.h b/parser_library/src/expressions/conditional_assembly/ca_expression.h index 6e9f93a49..4174985ff 100644 --- a/parser_library/src/expressions/conditional_assembly/ca_expression.h +++ b/parser_library/src/expressions/conditional_assembly/ca_expression.h @@ -27,7 +27,6 @@ namespace hlasm_plugin::parser_library::expressions { class ca_expr_visitor; class ca_expression; using ca_expr_ptr = std::unique_ptr; -using undef_sym_set = std::set; struct evaluation_context; @@ -60,7 +59,8 @@ class ca_expression ca_expression(context::SET_t_enum expr_kind, range expr_range); // retrieves set of attributed symbols that are not yet defined - virtual bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const = 0; + virtual bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const = 0; // builds parts of the expression tree that could not be built during parsing virtual void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) = 0; diff --git a/parser_library/src/expressions/conditional_assembly/ca_operator_binary.cpp b/parser_library/src/expressions/conditional_assembly/ca_operator_binary.cpp index 9942317e7..99834702d 100644 --- a/parser_library/src/expressions/conditional_assembly/ca_operator_binary.cpp +++ b/parser_library/src/expressions/conditional_assembly/ca_operator_binary.cpp @@ -34,7 +34,7 @@ ca_binary_operator::ca_binary_operator( {} bool ca_binary_operator::get_undefined_attributed_symbols( - undef_sym_set& symbols, const evaluation_context& eval_ctx) const + std::vector& symbols, const evaluation_context& eval_ctx) const { bool result = false; result |= left_expr->get_undefined_attributed_symbols(symbols, eval_ctx); @@ -79,7 +79,7 @@ ca_function_binary_operator::ca_function_binary_operator(ca_expr_ptr left_expr, {} // Detects (T'&VAR EQ 'O') condition -std::optional t_attr_special_case(undef_sym_set& symbols, +std::optional t_attr_special_case(std::vector& symbols, const expressions::ca_expression* left, const expressions::ca_expression* right, const evaluation_context& eval_ctx) @@ -116,7 +116,7 @@ std::optional t_attr_special_case(undef_sym_set& symbols, } bool ca_function_binary_operator::get_undefined_attributed_symbols( - undef_sym_set& symbols, const evaluation_context& eval_ctx) const + std::vector& symbols, const evaluation_context& eval_ctx) const { if (is_relational() && m_expr_ctx.parent_expr_kind == context::SET_t_enum::B_TYPE) { diff --git a/parser_library/src/expressions/conditional_assembly/ca_operator_binary.h b/parser_library/src/expressions/conditional_assembly/ca_operator_binary.h index 9e0759fac..3bc5a3f39 100644 --- a/parser_library/src/expressions/conditional_assembly/ca_operator_binary.h +++ b/parser_library/src/expressions/conditional_assembly/ca_operator_binary.h @@ -29,7 +29,8 @@ class ca_binary_operator : public ca_expression ca_binary_operator(ca_expr_ptr left_expr, ca_expr_ptr right_expr, context::SET_t_enum expr_kind, range expr_range); - bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const override; + bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const override; void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) override; @@ -69,7 +70,8 @@ class ca_function_binary_operator final : public ca_binary_operator range expr_range, context::SET_t_enum parent_expr_kind = context::SET_t_enum::UNDEF_TYPE); - bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const override; + bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const override; void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) override; diff --git a/parser_library/src/expressions/conditional_assembly/ca_operator_unary.cpp b/parser_library/src/expressions/conditional_assembly/ca_operator_unary.cpp index 5884669cb..d1d25a855 100644 --- a/parser_library/src/expressions/conditional_assembly/ca_operator_unary.cpp +++ b/parser_library/src/expressions/conditional_assembly/ca_operator_unary.cpp @@ -28,7 +28,7 @@ ca_unary_operator::ca_unary_operator(ca_expr_ptr expr, context::SET_t_enum expr_ {} bool ca_unary_operator::get_undefined_attributed_symbols( - undef_sym_set& symbols, const evaluation_context& eval_ctx) const + std::vector& symbols, const evaluation_context& eval_ctx) const { return expr->get_undefined_attributed_symbols(symbols, eval_ctx); } diff --git a/parser_library/src/expressions/conditional_assembly/ca_operator_unary.h b/parser_library/src/expressions/conditional_assembly/ca_operator_unary.h index 5ea24bf5e..53e422de0 100644 --- a/parser_library/src/expressions/conditional_assembly/ca_operator_unary.h +++ b/parser_library/src/expressions/conditional_assembly/ca_operator_unary.h @@ -27,7 +27,8 @@ class ca_unary_operator : public ca_expression ca_unary_operator(ca_expr_ptr expr, context::SET_t_enum expr_kind, range expr_range); - bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const override; + bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const override; void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) override; diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_constant.cpp b/parser_library/src/expressions/conditional_assembly/terms/ca_constant.cpp index 953d68e20..a155685c4 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_constant.cpp +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_constant.cpp @@ -26,7 +26,10 @@ ca_constant::ca_constant(context::A_t value, range expr_range) , value(value) {} -bool ca_constant::get_undefined_attributed_symbols(undef_sym_set&, const evaluation_context&) const { return false; } +bool ca_constant::get_undefined_attributed_symbols(std::vector&, const evaluation_context&) const +{ + return false; +} void ca_constant::resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) { diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_constant.h b/parser_library/src/expressions/conditional_assembly/terms/ca_constant.h index 3fc98327f..10fce2955 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_constant.h +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_constant.h @@ -31,7 +31,8 @@ class ca_constant final : public ca_expression ca_constant(context::A_t value, range expr_range); - bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const override; + bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const override; void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) override; diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_expr_list.cpp b/parser_library/src/expressions/conditional_assembly/terms/ca_expr_list.cpp index 3bb085c4f..edc3d412a 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_expr_list.cpp +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_expr_list.cpp @@ -31,7 +31,8 @@ ca_expr_list::ca_expr_list(std::vector expr_list, range expr_range, , parenthesized(parenthesized) {} -bool ca_expr_list::get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const +bool ca_expr_list::get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const { bool result = false; for (auto&& expr : expr_list) diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_expr_list.h b/parser_library/src/expressions/conditional_assembly/terms/ca_expr_list.h index b0568e706..973c8461f 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_expr_list.h +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_expr_list.h @@ -28,7 +28,8 @@ class ca_expr_list final : public ca_expression public: ca_expr_list(std::vector expr_list, range expr_range, bool parenthesized); - bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const override; + bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const override; void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) override; diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_function.cpp b/parser_library/src/expressions/conditional_assembly/terms/ca_function.cpp index a549b7a12..08b450622 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_function.cpp +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_function.cpp @@ -48,7 +48,8 @@ ca_function::ca_function(context::id_index function_name, , duplication_factor(std::move(duplication_factor)) {} -bool ca_function::get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const +bool ca_function::get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const { bool result = false; for (auto&& expr : parameters) diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_function.h b/parser_library/src/expressions/conditional_assembly/terms/ca_function.h index 49e228240..0d0c7e1bc 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_function.h +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_function.h @@ -40,7 +40,8 @@ class ca_function final : public ca_expression ca_expr_ptr duplication_factor, range expr_range); - bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const override; + bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const override; void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) override; diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_string.cpp b/parser_library/src/expressions/conditional_assembly/terms/ca_string.cpp index 2260f3d6b..ff6bec089 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_string.cpp +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_string.cpp @@ -38,7 +38,8 @@ ca_string::ca_string( , substring(std::move(substring)) {} -bool ca_string::get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const +bool ca_string::get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const { bool result = false; if (duplication_factor) diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_string.h b/parser_library/src/expressions/conditional_assembly/terms/ca_string.h index a2c473a38..c3e4c2562 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_string.h +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_string.h @@ -39,7 +39,8 @@ class ca_string final : public ca_expression ca_string(semantics::concat_chain value, ca_expr_ptr duplication_factor, substring_t substring, range expr_range); - bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const override; + bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const override; void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) override; diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_symbol.cpp b/parser_library/src/expressions/conditional_assembly/terms/ca_symbol.cpp index 6f900883e..7d1117602 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_symbol.cpp +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_symbol.cpp @@ -25,7 +25,10 @@ ca_symbol::ca_symbol(context::id_index symbol, range expr_range) , symbol(symbol) {} -bool ca_symbol::get_undefined_attributed_symbols(undef_sym_set&, const evaluation_context&) const { return false; } +bool ca_symbol::get_undefined_attributed_symbols(std::vector&, const evaluation_context&) const +{ + return false; +} void ca_symbol::resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) { diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_symbol.h b/parser_library/src/expressions/conditional_assembly/terms/ca_symbol.h index 26c8bc69e..73f23fac4 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_symbol.h +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_symbol.h @@ -27,7 +27,8 @@ class ca_symbol final : public ca_expression ca_symbol(context::id_index symbol, range expr_range); - bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const override; + bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const override; void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) override; diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_symbol_attribute.cpp b/parser_library/src/expressions/conditional_assembly/terms/ca_symbol_attribute.cpp index e511f102d..ffc33fe80 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_symbol_attribute.cpp +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_symbol_attribute.cpp @@ -18,14 +18,12 @@ #include "ca_var_sym.h" #include "context/hlasm_context.h" #include "context/literal_pool.h" -#include "context/ordinary_assembly/dependable.h" #include "context/ordinary_assembly/ordinary_assembly_dependency_solver.h" #include "diagnostic_consumer.h" #include "ebcdic_encoding.h" #include "expressions/conditional_assembly/ca_expr_visitor.h" #include "expressions/evaluation_context.h" #include "lexing/lexer.h" -#include "lexing/token_stream.h" #include "parsing/parser_impl.h" #include "processing/op_code.h" #include "semantics/range_provider.h" @@ -78,7 +76,7 @@ ca_symbol_attribute::ca_symbol_attribute( {} bool ca_symbol_attribute::get_undefined_attributed_symbols( - undef_sym_set& symbols, const evaluation_context& eval_ctx) const + std::vector& symbols, const evaluation_context& eval_ctx) const { if (std::holds_alternative(symbol)) { @@ -86,7 +84,7 @@ bool ca_symbol_attribute::get_undefined_attributed_symbols( && !eval_ctx.hlasm_ctx.ord_ctx.get_symbol(std::get(symbol)) && !eval_ctx.hlasm_ctx.ord_ctx.get_symbol_reference(std::get(symbol))) { - symbols.emplace(std::get(symbol)); + symbols.emplace_back(std::get(symbol)); return true; } } @@ -113,7 +111,7 @@ bool ca_symbol_attribute::get_undefined_attributed_symbols( && !eval_ctx.hlasm_ctx.ord_ctx.get_symbol(ord_name) && !eval_ctx.hlasm_ctx.ord_ctx.get_symbol_reference(ord_name)) { - symbols.emplace(ord_name); + symbols.emplace_back(ord_name); return true; } } diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_symbol_attribute.h b/parser_library/src/expressions/conditional_assembly/terms/ca_symbol_attribute.h index 76964759a..f87f7954e 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_symbol_attribute.h +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_symbol_attribute.h @@ -42,7 +42,8 @@ class ca_symbol_attribute final : public ca_expression ca_symbol_attribute( semantics::literal_si lit, context::data_attr_kind attribute, range expr_range, range symbol_range); - bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const override; + bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const override; void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) override; diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_var_sym.cpp b/parser_library/src/expressions/conditional_assembly/terms/ca_var_sym.cpp index d3e88efa9..0f338a09e 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_var_sym.cpp +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_var_sym.cpp @@ -27,7 +27,7 @@ ca_var_sym::ca_var_sym(semantics::vs_ptr symbol, range expr_range) {} bool ca_var_sym::get_undefined_attributed_symbols_vs( - undef_sym_set& symbols, const semantics::vs_ptr& symbol, const evaluation_context& eval_ctx) + std::vector& symbols, const semantics::vs_ptr& symbol, const evaluation_context& eval_ctx) { bool result = false; @@ -44,7 +44,8 @@ bool ca_var_sym::get_undefined_attributed_symbols_vs( return result; } -bool ca_var_sym::get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const +bool ca_var_sym::get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const { return get_undefined_attributed_symbols_vs(symbols, symbol, eval_ctx); } diff --git a/parser_library/src/expressions/conditional_assembly/terms/ca_var_sym.h b/parser_library/src/expressions/conditional_assembly/terms/ca_var_sym.h index 03b2d9ca1..519918ddf 100644 --- a/parser_library/src/expressions/conditional_assembly/terms/ca_var_sym.h +++ b/parser_library/src/expressions/conditional_assembly/terms/ca_var_sym.h @@ -28,7 +28,8 @@ class ca_var_sym final : public ca_expression ca_var_sym(semantics::vs_ptr symbol, range expr_range); - bool get_undefined_attributed_symbols(undef_sym_set& symbols, const evaluation_context& eval_ctx) const override; + bool get_undefined_attributed_symbols( + std::vector& symbols, const evaluation_context& eval_ctx) const override; void resolve_expression_tree(ca_expression_ctx expr_ctx, diagnostic_op_consumer& diags) override; @@ -39,7 +40,7 @@ class ca_var_sym final : public ca_expression context::SET_t evaluate(const evaluation_context& eval_ctx) const override; static bool get_undefined_attributed_symbols_vs( - undef_sym_set& symbols, const semantics::vs_ptr& symbol, const evaluation_context& eval_ctx); + std::vector& symbols, const semantics::vs_ptr& symbol, const evaluation_context& eval_ctx); private: context::SET_t convert_return_types( diff --git a/parser_library/src/processing/opencode_provider.cpp b/parser_library/src/processing/opencode_provider.cpp index 7f9b5d7da..50e1d7ab7 100644 --- a/parser_library/src/processing/opencode_provider.cpp +++ b/parser_library/src/processing/opencode_provider.cpp @@ -477,7 +477,8 @@ std::shared_ptr opencode_provider::process_ordin if (proc.kind == processing_kind::ORDINARY && try_trigger_attribute_lookahead(*result, { *m_ctx->hlasm_ctx, library_info_transitional(*m_lib_provider), drop_diagnostic_op }, - *m_state_listener)) + *m_state_listener, + std::move(lookahead_references))) return nullptr; if (m_current_logical_line.segments.size() > 1) @@ -725,7 +726,8 @@ context::shared_stmt_ptr opencode_provider::get_next(const statement_processor& if (proc.kind == processing_kind::ORDINARY && try_trigger_attribute_lookahead(collector.current_instruction(), { *m_ctx->hlasm_ctx, library_info_transitional(*m_lib_provider), drop_diagnostic_op }, - *m_state_listener)) + *m_state_listener, + std::move(lookahead_references))) return nullptr; const auto& current_instr = collector.current_instruction(); diff --git a/parser_library/src/processing/opencode_provider.h b/parser_library/src/processing/opencode_provider.h index 3c2b72572..5a8c5589a 100644 --- a/parser_library/src/processing/opencode_provider.h +++ b/parser_library/src/processing/opencode_provider.h @@ -163,6 +163,8 @@ class opencode_provider final : public statement_provider encoding_warning_issued m_encoding_warning_issued = {}; + std::vector lookahead_references; + public: // rewinds position in file void rewind_input(context::source_position pos); diff --git a/parser_library/src/processing/statement_processors/lookahead_processing_info.h b/parser_library/src/processing/statement_processors/lookahead_processing_info.h index 5cf480fdd..7206ff5b7 100644 --- a/parser_library/src/processing/statement_processors/lookahead_processing_info.h +++ b/parser_library/src/processing/statement_processors/lookahead_processing_info.h @@ -15,7 +15,7 @@ #ifndef PROCESSING_LOOKAHEAD_PROCESSING_INFO_H #define PROCESSING_LOOKAHEAD_PROCESSING_INFO_H -#include +#include #include "context/ordinary_assembly/symbol.h" #include "context/source_snapshot.h" @@ -51,9 +51,9 @@ struct lookahead_start_data {} // ORD action - std::set targets; + std::vector targets; - lookahead_start_data(std::set targets, + lookahead_start_data(std::vector targets, context::source_position statement_position, context::source_snapshot snapshot) : action(lookahead_action::ORD) diff --git a/parser_library/src/processing/statement_processors/lookahead_processor.cpp b/parser_library/src/processing/statement_processors/lookahead_processor.cpp index 2867dfd24..52154d28e 100644 --- a/parser_library/src/processing/statement_processors/lookahead_processor.cpp +++ b/parser_library/src/processing/statement_processors/lookahead_processor.cpp @@ -324,7 +324,11 @@ void lookahead_processor::find_ord(const resolved_statement& statement) if (!valid) return; - to_find_.erase(id); + if (auto it = std::find(to_find_.begin(), to_find_.end(), id); it != to_find_.end()) + { + std::swap(*it, to_find_.back()); + to_find_.pop_back(); + } // find attributes // if found ord symbol on CA, macro or undefined instruction, only type attribute is assigned diff --git a/parser_library/src/processing/statement_processors/lookahead_processor.h b/parser_library/src/processing/statement_processors/lookahead_processor.h index 58b5c5d72..dc9e7fff2 100644 --- a/parser_library/src/processing/statement_processors/lookahead_processor.h +++ b/parser_library/src/processing/statement_processors/lookahead_processor.h @@ -36,7 +36,7 @@ class lookahead_processor final : public statement_processor processing_state_listener& listener_; workspaces::parse_lib_provider& lib_provider_; - std::set to_find_; + std::vector to_find_; context::id_index target_; public: diff --git a/parser_library/src/processing/statement_providers/members_statement_provider.cpp b/parser_library/src/processing/statement_providers/members_statement_provider.cpp index e9787dd7c..0b46a2693 100644 --- a/parser_library/src/processing/statement_providers/members_statement_provider.cpp +++ b/parser_library/src/processing/statement_providers/members_statement_provider.cpp @@ -48,7 +48,8 @@ context::shared_stmt_ptr members_statement_provider::get_next(const statement_pr { if (try_trigger_attribute_lookahead(*instr, { *m_ctx.hlasm_ctx, library_info_transitional(m_lib_provider), drop_diagnostic_op }, - m_listener)) + m_listener, + std::move(lookahead_references))) return nullptr; } } @@ -83,8 +84,10 @@ context::shared_stmt_ptr members_statement_provider::get_next(const statement_pr } if (processor.kind == processing_kind::ORDINARY - && try_trigger_attribute_lookahead( - *stmt, { *m_ctx.hlasm_ctx, library_info_transitional(m_lib_provider), drop_diagnostic_op }, m_listener)) + && try_trigger_attribute_lookahead(*stmt, + { *m_ctx.hlasm_ctx, library_info_transitional(m_lib_provider), drop_diagnostic_op }, + m_listener, + std::move(lookahead_references))) return nullptr; return stmt; diff --git a/parser_library/src/processing/statement_providers/members_statement_provider.h b/parser_library/src/processing/statement_providers/members_statement_provider.h index f39e2ff6c..d4e66fae0 100644 --- a/parser_library/src/processing/statement_providers/members_statement_provider.h +++ b/parser_library/src/processing/statement_providers/members_statement_provider.h @@ -37,6 +37,8 @@ namespace hlasm_plugin::parser_library::processing { // common class for copy and macro statement providers (provider of copy and macro members) class members_statement_provider : public statement_provider { + std::vector lookahead_references; + public: members_statement_provider(const statement_provider_kind kind, analyzing_context ctx, diff --git a/parser_library/src/processing/statement_providers/statement_provider.cpp b/parser_library/src/processing/statement_providers/statement_provider.cpp index 93ac7f92f..1a6ff9a45 100644 --- a/parser_library/src/processing/statement_providers/statement_provider.cpp +++ b/parser_library/src/processing/statement_providers/statement_provider.cpp @@ -26,25 +26,27 @@ statement_provider::statement_provider(const statement_provider_kind kind) bool statement_provider::try_trigger_attribute_lookahead(const semantics::instruction_si& instruction, expressions::evaluation_context eval_ctx, - processing::processing_state_listener& listener) + processing::processing_state_listener& listener, + std::vector&& references_buffer) { - std::set references; - process_instruction(references, instruction, eval_ctx); + references_buffer.clear(); + process_instruction(references_buffer, instruction, eval_ctx); - if (references.empty()) + if (references_buffer.empty()) return false; - trigger_attribute_lookahead(std::move(references), eval_ctx, listener); + trigger_attribute_lookahead(std::move(references_buffer), eval_ctx, listener); return true; } bool statement_provider::try_trigger_attribute_lookahead(const context::hlasm_statement& statement, expressions::evaluation_context eval_ctx, - processing::processing_state_listener& listener) + processing::processing_state_listener& listener, + std::vector&& references_buffer) { + references_buffer.clear(); const semantics::label_si* label; - std::set references; if (auto def_stmt = statement.access_deferred()) { @@ -54,31 +56,36 @@ bool statement_provider::try_trigger_attribute_lookahead(const context::hlasm_st { label = &res_stmt->label_ref(); - process_operands(references, res_stmt->operands_ref(), eval_ctx); + process_operands(references_buffer, res_stmt->operands_ref(), eval_ctx); } else return false; - process_label(references, *label, eval_ctx); + process_label(references_buffer, *label, eval_ctx); - if (references.empty()) + if (references_buffer.empty()) return false; - trigger_attribute_lookahead(std::move(references), eval_ctx, listener); + trigger_attribute_lookahead(std::move(references_buffer), eval_ctx, listener); return true; } -void statement_provider::trigger_attribute_lookahead(std::set references, +void statement_provider::trigger_attribute_lookahead(std::vector&& references_buffer, const expressions::evaluation_context& eval_ctx, processing::processing_state_listener& listener) { auto&& [statement_position, snapshot] = eval_ctx.hlasm_ctx.get_begin_snapshot(false); - listener.start_lookahead(lookahead_start_data(std::move(references), statement_position, std::move(snapshot))); + std::sort(references_buffer.begin(), references_buffer.end()); + + listener.start_lookahead(lookahead_start_data( + std::vector(references_buffer.begin(), std::unique(references_buffer.begin(), references_buffer.end())), + statement_position, + std::move(snapshot))); } -bool statement_provider::process_label(std::set& symbols, +bool statement_provider::process_label(std::vector& symbols, const semantics::label_si& label, const expressions::evaluation_context& eval_ctx) { @@ -95,7 +102,7 @@ bool statement_provider::process_label(std::set& symbols, } } -bool statement_provider::process_instruction(std::set& symbols, +bool statement_provider::process_instruction(std::vector& symbols, const semantics::instruction_si& instruction, const expressions::evaluation_context& eval_ctx) { @@ -107,7 +114,7 @@ bool statement_provider::process_instruction(std::set& symbol return semantics::concatenation_point::get_undefined_attributed_symbols(symbols, chain, eval_ctx); } -bool statement_provider::process_operands(std::set& symbols, +bool statement_provider::process_operands(std::vector& symbols, const semantics::operands_si& operands, const expressions::evaluation_context& eval_ctx) { diff --git a/parser_library/src/processing/statement_providers/statement_provider.h b/parser_library/src/processing/statement_providers/statement_provider.h index 19cf37356..89f34fb46 100644 --- a/parser_library/src/processing/statement_providers/statement_provider.h +++ b/parser_library/src/processing/statement_providers/statement_provider.h @@ -46,23 +46,25 @@ class statement_provider protected: static bool try_trigger_attribute_lookahead(const semantics::instruction_si& instruction, expressions::evaluation_context eval_ctx, - processing::processing_state_listener& listener); + processing::processing_state_listener& listener, + std::vector&& references_buffer); static bool try_trigger_attribute_lookahead(const context::hlasm_statement& statement, expressions::evaluation_context eval_ctx, - processing::processing_state_listener& listener); + processing::processing_state_listener& listener, + std::vector&& references_buffer); private: - static void trigger_attribute_lookahead(std::set references, + static void trigger_attribute_lookahead(std::vector&& references_buffer, const expressions::evaluation_context& eval_ctx, processing::processing_state_listener& listener); - static bool process_label(std::set& symbols, + static bool process_label(std::vector& symbols, const semantics::label_si& label, const expressions::evaluation_context& eval_ctx); - static bool process_instruction(std::set& symbols, + static bool process_instruction(std::vector& symbols, const semantics::instruction_si& instruction, const expressions::evaluation_context& eval_ctx); - static bool process_operands(std::set& symbols, + static bool process_operands(std::vector& symbols, const semantics::operands_si& operands, const expressions::evaluation_context& eval_ctx); }; diff --git a/parser_library/src/semantics/concatenation.cpp b/parser_library/src/semantics/concatenation.cpp index 109b72ce2..ee18416b3 100644 --- a/parser_library/src/semantics/concatenation.cpp +++ b/parser_library/src/semantics/concatenation.cpp @@ -213,7 +213,7 @@ const var_sym_conc* concatenation_point::find_var_sym( } bool concatenation_point::get_undefined_attributed_symbols( - std::set& symbols, const concat_chain& chain, const expressions::evaluation_context& eval_ctx) + std::vector& symbols, const concat_chain& chain, const expressions::evaluation_context& eval_ctx) { bool result = false; for (auto it = chain.begin(); it != chain.end(); ++it) diff --git a/parser_library/src/semantics/concatenation.h b/parser_library/src/semantics/concatenation.h index ffe69517f..71ec007fd 100644 --- a/parser_library/src/semantics/concatenation.h +++ b/parser_library/src/semantics/concatenation.h @@ -120,7 +120,7 @@ struct concatenation_point static const var_sym_conc* find_var_sym(concat_chain::const_iterator begin, concat_chain::const_iterator end); - static bool get_undefined_attributed_symbols(std::set& symbols, + static bool get_undefined_attributed_symbols(std::vector& symbols, const concat_chain& chain, const expressions::evaluation_context& eval_ctx); diff --git a/parser_library/src/semantics/operand_impls.cpp b/parser_library/src/semantics/operand_impls.cpp index 14928c420..41af6e9db 100644 --- a/parser_library/src/semantics/operand_impls.cpp +++ b/parser_library/src/semantics/operand_impls.cpp @@ -559,7 +559,7 @@ var_ca_operand::var_ca_operand(vs_ptr variable_symbol, range operand_range) {} bool var_ca_operand::get_undefined_attributed_symbols( - std::set& symbols, const expressions::evaluation_context& eval_ctx) + std::vector& symbols, const expressions::evaluation_context& eval_ctx) { return expressions::ca_var_sym::get_undefined_attributed_symbols_vs(symbols, variable_symbol, eval_ctx); } @@ -572,7 +572,7 @@ expr_ca_operand::expr_ca_operand(expressions::ca_expr_ptr expression, range oper {} bool expr_ca_operand::get_undefined_attributed_symbols( - std::set& symbols, const expressions::evaluation_context& eval_ctx) + std::vector& symbols, const expressions::evaluation_context& eval_ctx) { return expression->get_undefined_attributed_symbols(symbols, eval_ctx); } @@ -585,7 +585,7 @@ seq_ca_operand::seq_ca_operand(seq_sym sequence_symbol, range operand_range) {} bool seq_ca_operand::get_undefined_attributed_symbols( - std::set&, const expressions::evaluation_context&) + std::vector&, const expressions::evaluation_context&) { return false; } @@ -599,7 +599,7 @@ branch_ca_operand::branch_ca_operand(seq_sym sequence_symbol, expressions::ca_ex {} bool branch_ca_operand::get_undefined_attributed_symbols( - std::set& symbols, const expressions::evaluation_context& eval_ctx) + std::vector& symbols, const expressions::evaluation_context& eval_ctx) { return expression->get_undefined_attributed_symbols(symbols, eval_ctx); } diff --git a/parser_library/src/semantics/operand_impls.h b/parser_library/src/semantics/operand_impls.h index b747315e4..cd5116c8b 100644 --- a/parser_library/src/semantics/operand_impls.h +++ b/parser_library/src/semantics/operand_impls.h @@ -411,7 +411,7 @@ struct ca_operand : operand const branch_ca_operand* access_branch() const; virtual bool get_undefined_attributed_symbols( - std::set& symbols, const expressions::evaluation_context& eval_ctx) = 0; + std::vector& symbols, const expressions::evaluation_context& eval_ctx) = 0; const ca_kind kind; }; @@ -422,7 +422,7 @@ struct var_ca_operand final : ca_operand var_ca_operand(vs_ptr variable_symbol, const range operand_range); bool get_undefined_attributed_symbols( - std::set& symbols, const expressions::evaluation_context& eval_ctx) override; + std::vector& symbols, const expressions::evaluation_context& eval_ctx) override; vs_ptr variable_symbol; @@ -436,7 +436,7 @@ struct expr_ca_operand final : ca_operand bool get_undefined_attributed_symbols( - std::set& symbols, const expressions::evaluation_context& eval_ctx) override; + std::vector& symbols, const expressions::evaluation_context& eval_ctx) override; expressions::ca_expr_ptr expression; @@ -450,7 +450,7 @@ struct seq_ca_operand final : ca_operand bool get_undefined_attributed_symbols( - std::set& symbols, const expressions::evaluation_context& eval_ctx) override; + std::vector& symbols, const expressions::evaluation_context& eval_ctx) override; seq_sym sequence_symbol; @@ -464,7 +464,7 @@ struct branch_ca_operand final : ca_operand bool get_undefined_attributed_symbols( - std::set& symbols, const expressions::evaluation_context& eval_ctx) override; + std::vector& symbols, const expressions::evaluation_context& eval_ctx) override; seq_sym sequence_symbol; expressions::ca_expr_ptr expression; diff --git a/parser_library/test/expressions/ca_constant_test.cpp b/parser_library/test/expressions/ca_constant_test.cpp index 944f69356..66b7ab751 100644 --- a/parser_library/test/expressions/ca_constant_test.cpp +++ b/parser_library/test/expressions/ca_constant_test.cpp @@ -31,7 +31,7 @@ TEST(ca_constant, undefined_attributes) ca_constant c(1, range()); - std::set references; + std::vector references; EXPECT_FALSE(c.get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), 0U); } diff --git a/parser_library/test/expressions/ca_expr_list_test.cpp b/parser_library/test/expressions/ca_expr_list_test.cpp index 9258fa723..c5d103fc1 100644 --- a/parser_library/test/expressions/ca_expr_list_test.cpp +++ b/parser_library/test/expressions/ca_expr_list_test.cpp @@ -100,7 +100,7 @@ TEST(ca_expr_list, get_undefined_attributed_symbols) diagnostic_op_consumer_container diags; evaluation_context eval_ctx { ctx, library_info_transitional::empty, diags }; - std::set references; + std::vector references; EXPECT_TRUE(expr_list.get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_GT(references.size(), 0); diff --git a/parser_library/test/expressions/ca_function_test.cpp b/parser_library/test/expressions/ca_function_test.cpp index 2f1d33fee..d7b1bc9b8 100644 --- a/parser_library/test/expressions/ca_function_test.cpp +++ b/parser_library/test/expressions/ca_function_test.cpp @@ -62,7 +62,10 @@ class set_expr final : public ca_expression , value(std::move(value)) {} - bool get_undefined_attributed_symbols(undef_sym_set&, const evaluation_context&) const override { return false; }; + bool get_undefined_attributed_symbols(std::vector&, const evaluation_context&) const override + { + return false; + } void resolve_expression_tree(ca_expression_ctx, diagnostic_op_consumer&) override {} diff --git a/parser_library/test/expressions/ca_string_test.cpp b/parser_library/test/expressions/ca_string_test.cpp index 6ef703d72..4823a8bf3 100644 --- a/parser_library/test/expressions/ca_string_test.cpp +++ b/parser_library/test/expressions/ca_string_test.cpp @@ -44,7 +44,7 @@ TEST(ca_string, undefined_attributes) ca_string s(std::move(value), std::move(dupl), std::move(substr), range()); - std::set references; + std::vector references; EXPECT_FALSE(s.get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), 0U); diff --git a/parser_library/test/expressions/ca_symbol_attribute_test.cpp b/parser_library/test/expressions/ca_symbol_attribute_test.cpp index ce0952864..6e3e569db 100644 --- a/parser_library/test/expressions/ca_symbol_attribute_test.cpp +++ b/parser_library/test/expressions/ca_symbol_attribute_test.cpp @@ -40,7 +40,7 @@ TEST(ca_symbol_attr, undefined_attributes) ca_symbol_attribute attr(std::move(vs), context::data_attr_kind::D, range(), range()); - std::set references; + std::vector references; EXPECT_FALSE(attr.get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), 0U); diff --git a/parser_library/test/expressions/ca_symbol_test.cpp b/parser_library/test/expressions/ca_symbol_test.cpp index d12cb925e..c2a1cfcfd 100644 --- a/parser_library/test/expressions/ca_symbol_test.cpp +++ b/parser_library/test/expressions/ca_symbol_test.cpp @@ -32,7 +32,7 @@ TEST(ca_symbol, undefined_attributes) ca_symbol sym(context::id_index("N"), range()); - std::set references; + std::vector references; EXPECT_FALSE(sym.get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), 0U); diff --git a/parser_library/test/expressions/ca_var_sym_test.cpp b/parser_library/test/expressions/ca_var_sym_test.cpp index 9f997f522..bc23c4b9b 100644 --- a/parser_library/test/expressions/ca_var_sym_test.cpp +++ b/parser_library/test/expressions/ca_var_sym_test.cpp @@ -40,7 +40,7 @@ TEST(ca_var_sym_basic, undefined_attributes) ca_var_sym var(std::move(vs), range()); - std::set references; + std::vector references; EXPECT_FALSE(var.get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), 0U); @@ -64,7 +64,7 @@ TEST(ca_var_sym_created, undefined_attributes) ca_var_sym var(std::move(vs), range()); - std::set references; + std::vector references; EXPECT_FALSE(var.get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), 0U); diff --git a/parser_library/test/processing/lookahead_test.cpp b/parser_library/test/processing/lookahead_test.cpp index 03fb9913c..8480b67bc 100644 --- a/parser_library/test/processing/lookahead_test.cpp +++ b/parser_library/test/processing/lookahead_test.cpp @@ -219,7 +219,7 @@ TEST(attribute_lookahead, lookup_triggered) diagnostic_op_consumer_container diags; evaluation_context eval_ctx { a.hlasm_ctx(), library_info_transitional::empty, diags }; - std::set references; + std::vector references; EXPECT_TRUE(expr->get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), (size_t)1); @@ -240,10 +240,10 @@ TEST(attribute_lookahead, nested_lookup_triggered) auto v2 = a.hlasm_ctx().create_local_variable(id_index("V2"), true); v2->access_set_symbol()->set_value("B"); - std::set references; + std::vector references; EXPECT_TRUE(expr->get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), (size_t)1); - EXPECT_TRUE(references.find(id_index("B")) != references.end()); + EXPECT_EQ(std::count(references.begin(), references.end(), id_index("B")), 1); a.hlasm_ctx().ord_ctx.add_symbol_reference( context::symbol(id_index("B"), @@ -256,7 +256,7 @@ TEST(attribute_lookahead, nested_lookup_triggered) references.clear(); EXPECT_TRUE(expr->get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), (size_t)1); - EXPECT_TRUE(references.find(id_index("A")) != references.end()); + EXPECT_EQ(std::count(references.begin(), references.end(), id_index("A")), 1); EXPECT_EQ(a.diags().size(), (size_t)0); } @@ -279,7 +279,7 @@ TEST(attribute_lookahead, lookup_not_triggered) ASSERT_TRUE(tmp); // although length is undefined the actual symbol is defined so no lookup should happen - std::set references; + std::vector references; EXPECT_FALSE(expr->get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), (size_t)0); @@ -295,7 +295,7 @@ TEST(attribute_lookahead, lookup_of_two_refs) diagnostic_op_consumer_container diags; evaluation_context eval_ctx { a.hlasm_ctx(), library_info_transitional::empty, diags }; - std::set references; + std::vector references; EXPECT_TRUE(expr->get_undefined_attributed_symbols(references, eval_ctx)); EXPECT_EQ(references.size(), (size_t)2); @@ -311,9 +311,9 @@ TEST(attribute_lookahead, lookup_of_two_refs_but_one_symbol) diagnostic_op_consumer_container diags; evaluation_context eval_ctx { a.hlasm_ctx(), library_info_transitional::empty, diags }; - std::set references; + std::vector references; EXPECT_TRUE(expr->get_undefined_attributed_symbols(references, eval_ctx)); - EXPECT_EQ(references.size(), (size_t)1); + EXPECT_EQ(references.size(), (size_t)2); EXPECT_EQ(a.diags().size(), (size_t)0); }