Skip to content

Commit

Permalink
perf: Improve parsing performance of CA operands
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Aug 17, 2022
1 parent 25761e8 commit dbcdcff
Show file tree
Hide file tree
Showing 29 changed files with 1,131 additions and 348 deletions.
1 change: 1 addition & 0 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- False positive diagnostics generated for statements included by the COPY instruction
- Sequence symbol redefinition diagnostic issued even for symbols excluded by CA statements
- Validation of mnemonics with optional operands produced incorrect diagnostics
- Improve parsing performance of CA operands

## [1.3.0](https://github.com/eclipse/che-che4z-lsp-for-hlasm/compare/1.2.0...1.3.0) (2022-06-30)

Expand Down
9 changes: 5 additions & 4 deletions parser_library/src/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

#include "analyzer.h"

#include "hlasmparser.h"
#include "hlasmparser_multiline.h"
#include "parsing/error_strategy.h"
#include "processing/opencode_provider.h"
#include "processing/preprocessor.h"

using namespace hlasm_plugin::parser_library;
Expand Down Expand Up @@ -103,8 +104,8 @@ analyzer::analyzer(const std::string& text, analyzer_options opts)
return result;
},
*this),
opts.parsing_opencode == file_is_opencode::yes ? opencode_provider_options { true, 10 }
: opencode_provider_options {},
opts.parsing_opencode == file_is_opencode::yes ? processing::opencode_provider_options { true, 10 }
: processing::opencode_provider_options {},
opts.vf_monitor),
ctx_,
opts.library_data,
Expand All @@ -118,7 +119,7 @@ analyzing_context analyzer::context() const { return ctx_; }

context::hlasm_context& analyzer::hlasm_ctx() { return *ctx_.hlasm_ctx; }

parsing::hlasmparser& analyzer::parser() { return mngr_.opencode_parser(); }
parsing::hlasmparser_multiline& analyzer::parser() { return mngr_.opencode_parser(); }

size_t analyzer::debug_syntax_errors() { return mngr_.opencode_parser().getNumberOfSyntaxErrors(); }

Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class analyzer : public diagnosable_ctx

void register_stmt_analyzer(processing::statement_analyzer* stmt_analyzer);

parsing::hlasmparser& parser(); // for testing only
parsing::hlasmparser_multiline& parser(); // for testing only
size_t debug_syntax_errors(); // for testing only
};

Expand Down
2 changes: 2 additions & 0 deletions parser_library/src/context/id_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ id_storage::well_known_strings::well_known_strings(std::unordered_set<std::strin
, MHELP(&*ptr.emplace("MHELP").first)
, ASPACE(&*ptr.emplace("ASPACE").first)
, AIF(&*ptr.emplace("AIF").first)
, AIFB(&*ptr.emplace("AIFB").first)
, AGO(&*ptr.emplace("AGO").first)
, AGOB(&*ptr.emplace("AGOB").first)
, ACTR(&*ptr.emplace("ACTR").first)
, AREAD(&*ptr.emplace("AREAD").first)
, ALIAS(&*ptr.emplace("ALIAS").first)
Expand Down
2 changes: 2 additions & 0 deletions parser_library/src/context/id_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ class id_storage
const std::string* MHELP;
const std::string* ASPACE;
const std::string* AIF;
const std::string* AIFB;
const std::string* AGO;
const std::string* AGOB;
const std::string* ACTR;
const std::string* AREAD;
const std::string* ALIAS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "ebcdic_encoding.h"
#include "expressions/conditional_assembly/ca_expr_visitor.h"
#include "expressions/evaluation_context.h"
#include "hlasmparser.h"
#include "lexing/lexer.h"
#include "lexing/token_stream.h"
#include "parsing/parser_impl.h"
Expand Down Expand Up @@ -451,32 +450,23 @@ semantics::literal_si ca_symbol_attribute::reparse_substituted_literal(
diag.message = diagnostic_decorate_message(text, diag.message);
eval_ctx.diags.add_diagnostic(std::move(diag));
});
auto h = parsing::parser_holder::create(nullptr, &eval_ctx.hlasm_ctx, &add_diag_subst);
auto h = parsing::parser_holder::create(nullptr, &eval_ctx.hlasm_ctx, &add_diag_subst, false);

h->input->reset(text);

h->lex->reset();
h->lex->set_file_offset(var_range.start);
h->lex->set_unlimited_line(true);

h->stream->reset();

h->parser->reinitialize(&eval_ctx.hlasm_ctx,
h->prepare_parser(text,
&eval_ctx.hlasm_ctx,
&add_diag_subst,
semantics::range_provider(var_range, semantics::adjusting_state::SUBSTITUTION),
var_range,
processing::processing_status(processing::processing_format(processing::processing_kind::ORDINARY,
processing::processing_form::CA,
processing::operand_occurence::ABSENT),
processing::op_code()),
&add_diag_subst);

h->parser->reset();

h->parser->get_collector().prepare_for_next_statement();
true);

auto literal_context = h->parser->literal_reparse();
auto literal_value = h->literal_reparse();

if (!error)
return std::move(literal_context->value);
return literal_value;

return {};
}
Expand Down
13 changes: 9 additions & 4 deletions parser_library/src/parsing/grammar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
#generated grammar source files

set(GENERATED_SRC_CPP
${GENERATED_FOLDER}/hlasmparser.cpp
${GENERATED_FOLDER}/hlasmparser_singleline.cpp
${GENERATED_FOLDER}/hlasmparser_multiline.cpp
)

set(GENERATED_SRC
${GENERATED_SRC_CPP}
${GENERATED_FOLDER}/hlasmparser.h
${GENERATED_FOLDER}/hlasmparser_singleline.h
${GENERATED_FOLDER}/hlasmparser_multiline.h
)

file(GLOB GRAMMAR_SRC
Expand All @@ -28,13 +30,16 @@ add_custom_command(OUTPUT ${GENERATED_SRC}
COMMAND
${CMAKE_COMMAND} -E make_directory ${GENERATED_FOLDER}
COMMAND
"${Java_JAVA_EXECUTABLE}" -jar ${ANTLR_JAR_LOCATION} -Werror -Dlanguage=Cpp -lib ${PROJECT_SOURCE_DIR}/src/parsing/grammar/ -o ${GENERATED_FOLDER}/ -package hlasm_plugin::parser_library::parsing hlasmparser.g4
"${Java_JAVA_EXECUTABLE}" -jar ${ANTLR_JAR_LOCATION} -Werror -Dlanguage=Cpp -lib ${PROJECT_SOURCE_DIR}/src/parsing/grammar/ -o ${GENERATED_FOLDER}/ -package hlasm_plugin::parser_library::parsing hlasmparser_singleline.g4
COMMAND
"${Java_JAVA_EXECUTABLE}" -jar ${ANTLR_JAR_LOCATION} -Werror -Dlanguage=Cpp -lib ${PROJECT_SOURCE_DIR}/src/parsing/grammar/ -o ${GENERATED_FOLDER}/ -package hlasm_plugin::parser_library::parsing hlasmparser_multiline.g4
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/src/parsing/grammar/"
DEPENDS antlr4jar ${GRAMMAR_SRC} lex.tokens
)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_source_files_properties(${GENERATED_FOLDER}/hlasmparser.cpp PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")
set_source_files_properties(${GENERATED_FOLDER}/hlasmparser_singleline.cpp PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")
set_source_files_properties(${GENERATED_FOLDER}/hlasmparser_multiline.cpp PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")
endif()

add_library(parser_library_generated OBJECT "${GENERATED_SRC}")
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/parsing/grammar/ca_expr_rules.g4
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ expr_space_c returns [std::vector<ca_expr_ptr> ca_exprs]
$ca_exprs = std::move($tmp.ca_exprs);
};

seq_symbol returns [seq_sym ss]
seq_symbol returns [seq_sym ss = seq_sym{}]
: DOT id_no_dot
{
$ss = seq_sym{$id_no_dot.name,provider.get_range( $DOT, $id_no_dot.ctx->getStop())};
Expand Down
29 changes: 21 additions & 8 deletions parser_library/src/parsing/grammar/ca_operand_rules.g4
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,39 @@
//rules for CA operands
parser grammar ca_operand_rules;

ca_op returns [operand_ptr op]
ca_op_branch returns [operand_ptr op]
: expr_list seq_symbol
{
collector.add_hl_symbol(token_info(provider.get_range($seq_symbol.ctx),hl_scopes::seq_symbol));
resolve_expression($expr_list.ca_expr);
auto r = provider.get_range($expr_list.ctx->getStart(),$seq_symbol.ctx->getStop());
$op = std::make_unique<branch_ca_operand>(std::move($seq_symbol.ss), std::move($expr_list.ca_expr), r);
if ($seq_symbol.ss.name)
$op = std::make_unique<branch_ca_operand>(std::move($seq_symbol.ss), std::move($expr_list.ca_expr), r);
}
| seq_symbol
{
collector.add_hl_symbol(token_info(provider.get_range($seq_symbol.ctx),hl_scopes::seq_symbol));
$op = std::make_unique<seq_ca_operand>(std::move($seq_symbol.ss),provider.get_range($seq_symbol.ctx));
}
| {!is_var_def()}? expr
if ($seq_symbol.ss.name)
$op = std::make_unique<seq_ca_operand>(std::move($seq_symbol.ss),provider.get_range($seq_symbol.ctx));
};
finally
{if (!$op) $op = std::make_unique<semantics::empty_operand>(provider.get_range(_localctx));}


ca_op_expr returns [operand_ptr op]
: expr
{
resolve_expression($expr.ca_expr);
$op = std::make_unique<expr_ca_operand>(std::move($expr.ca_expr), provider.get_range($expr.ctx));
}
| { is_var_def()}? var_def
};
finally
{if (!$op) $op = std::make_unique<semantics::empty_operand>(provider.get_range(_localctx));}

ca_op_var_def returns [operand_ptr op]
: var_def
{
$op = std::make_unique<var_ca_operand>(std::move($var_def.vs), provider.get_range($var_def.ctx));
};
};
finally
{if (!$op) $op = std::make_unique<semantics::empty_operand>(provider.get_range(_localctx));}
30 changes: 1 addition & 29 deletions parser_library/src/parsing/grammar/deferred_operand_rules.g4
Original file line number Diff line number Diff line change
Expand Up @@ -114,32 +114,4 @@ deferred_entry returns [std::vector<vs_ptr> vs]
)?
;
finally
{enable_ca_string();}

deferred_op_rem returns [remark_list remarks, std::vector<vs_ptr> var_list]
:
(
deferred_entry
{
for (auto&v : $deferred_entry.vs)
$var_list.push_back(std::move(v));
}
)*
{enable_continuation();}
remark_o {if($remark_o.value) $remarks.push_back(*$remark_o.value);}
(
CONTINUATION
{disable_continuation();}
(
deferred_entry
{
for (auto&v : $deferred_entry.vs)
$var_list.push_back(std::move(v));
}
)*
{enable_continuation();}
remark_o {if($remark_o.value) $remarks.push_back(*$remark_o.value);}
)*
;
finally
{disable_continuation();}
{enable_ca_string();}
Loading

0 comments on commit dbcdcff

Please sign in to comment.