Skip to content

Commit

Permalink
feat: Support for complex SQL types (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Jul 15, 2021
1 parent 547948e commit 3e85b98
Show file tree
Hide file tree
Showing 8 changed files with 568 additions and 74 deletions.
4 changes: 2 additions & 2 deletions parser_library/src/context/instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ hlasm_plugin::parser_library::context::instruction::get_machine_instructions()
add_machine_instr(result, "X", mach_format::RX_a, { reg_4_U, dxb_12_4x4_U }, 738);
add_machine_instr(result, "XY", mach_format::RXY_a, { reg_4_U, dxb_20_4x4_S }, 738);
add_machine_instr(result, "XG", mach_format::RXY_a, { reg_4_U, dxb_20_4x4_S }, 738);
add_machine_instr(result, "XI", mach_format::SI, { db_12_4_U, imm_8_S }, 739);
add_machine_instr(result, "XIY", mach_format::SIY, { db_20_4_S, imm_8_S }, 739);
add_machine_instr(result, "XI", mach_format::SI, { db_12_4_U, imm_8_U }, 739);
add_machine_instr(result, "XIY", mach_format::SIY, { db_20_4_S, imm_8_U }, 739);
add_machine_instr(result, "XC", mach_format::SS_a, { db_12_8x4L_U, db_20_4_S }, 739);
add_machine_instr(result, "EX", mach_format::RX_a, { reg_4_U, dxb_12_4x4_U }, 740);
add_machine_instr(result, "XIHF", mach_format::RIL_a, { reg_4_U, imm_32_S }, 740);
Expand Down
16 changes: 16 additions & 0 deletions parser_library/src/diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,22 @@ diagnostic_op diagnostic_op::error_P0003(const range& range, std::string_view li
range);
}

diagnostic_op diagnostic_op::error_P0004(const range& range)
{
return diagnostic_op(diagnostic_severity::error,
"P0004",
std::string("DB2 preprocessor - requested SQL TYPE not recognized"),
range);
}

diagnostic_op diagnostic_op::error_P0005(const range& range)
{
return diagnostic_op(diagnostic_severity::warning,
"P0005",
std::string("DB2 preprocessor - continuation detected on SQL TYPE statement"),
range);
}

diagnostic_s diagnostic_s::error_W002(const std::string& ws_uri, const std::string& ws_name)
{
return diagnostic_s(ws_uri,
Expand Down
4 changes: 4 additions & 0 deletions parser_library/src/diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ struct diagnostic_op
static diagnostic_op error_P0002(const range& range, std::string_view lib);

static diagnostic_op error_P0003(const range& range, std::string_view lib);

static diagnostic_op error_P0004(const range& range);

static diagnostic_op error_P0005(const range& range);
};

struct range_uri_s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,17 @@ context::SET_t ca_string::evaluate(const evaluation_context& eval_ctx) const
auto count =
substring.count ? substring.count->evaluate(eval_ctx).access_a() : (context::A_t)str.size() - start + 1;

if (start < 0 || count < 0 || (start == 0 && count > 0))
if (count == 0)
{
// when zero-length substring is requested, validation of the first parameter seems supressed
str = "";
}
else if (start < 0 || count < 0 || (start == 0 && count > 0))
{
eval_ctx.add_diagnostic(diagnostic_op::error_CE008(substring.substring_range));
return context::object_traits<context::C_t>::default_v();
}
if (start > (context::A_t)str.size())
else if (start > (context::A_t)str.size())
{
eval_ctx.add_diagnostic(diagnostic_op::error_CE009(substring.start->expr_range));
return context::object_traits<context::C_t>::default_v();
Expand All @@ -95,10 +100,8 @@ context::SET_t ca_string::evaluate(const evaluation_context& eval_ctx) const
if (start + count - 1 > (int)str.size())
eval_ctx.add_diagnostic(diagnostic_op::error_CW001(substring.count->expr_range));
*/
if (count != 0)
str = str.substr(start - 1, count);
else
str = "";
str = str.substr(start - 1, count);
}

return duplicate(duplication_factor, std::move(str), expr_range, eval_ctx);
Expand Down
Loading

0 comments on commit 3e85b98

Please sign in to comment.