Skip to content

Commit

Permalink
Add a test for covering inlining of VERBATIM block (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
alkino authored Apr 13, 2023
1 parent 4cb05c8 commit 0514fbe
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 39 deletions.
29 changes: 0 additions & 29 deletions src/parser/unit_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
namespace nmodl {
namespace parser {

UnitDriver::UnitDriver(bool strace, bool ptrace)
: trace_scanner(strace)
, trace_parser(ptrace) {}

/// parse Units file provided as istream
bool UnitDriver::parse_stream(std::istream& in) {
UnitLexer scanner(*this, &in);
Expand All @@ -26,8 +22,6 @@ bool UnitDriver::parse_stream(std::istream& in) {
this->lexer = &scanner;
this->parser = &parser;

scanner.set_debug(trace_scanner);
parser.set_debug_level(trace_parser);
return (parser.parse() == 0);
}

Expand All @@ -48,28 +42,5 @@ bool UnitDriver::parse_string(const std::string& input) {
return parse_stream(iss);
}

void UnitDriver::error(const std::string& m) {
std::cerr << m << std::endl;
}

void UnitDriver::error(const std::string& m, const location& l) {
std::cerr << l << " : " << m << std::endl;
}

void UnitDriver::scan_string(std::string& text) {
std::istringstream in(text);
UnitLexer scanner(*this, &in);
UnitParser parser(scanner, *this);
this->lexer = &scanner;
this->parser = &parser;
while (true) {
auto sym = lexer->next_token();
auto token_type = sym.type_get();
if (token_type == UnitParser::by_type(UnitParser::token::END).type_get()) {
break;
}
}
}

} // namespace parser
} // namespace nmodl
9 changes: 0 additions & 9 deletions src/parser/unit_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ class location;
*/
class UnitDriver {
private:
/// enable debug output in the flex scanner
bool trace_scanner = false;

/// enable debug output in the bison parser
bool trace_parser = false;

/// pointer to the lexer instance being used
UnitLexer* lexer = nullptr;

Expand All @@ -68,12 +62,9 @@ class UnitDriver {

/// \}

static void error(const std::string& m);
bool parse_stream(std::istream& in);
bool parse_string(const std::string& input);
bool parse_file(const std::string& filename);
void scan_string(std::string& text);
static void error(const std::string& m, const location& l);

void set_verbose(bool b) {
verbose = b;
Expand Down
60 changes: 59 additions & 1 deletion test/unit/visitor/inline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ using namespace visitor;
using namespace test;
using namespace test_utils;

using Catch::Matchers::Equals;
using nmodl::parser::NmodlDriver;

//=============================================================================
Expand Down Expand Up @@ -55,7 +56,7 @@ SCENARIO("Inlining of external procedure calls", "[visitor][inline]") {
}
)";

THEN("nothing gets inlinine") {
THEN("nothing gets inlined") {
std::string input = reindent_text(nmodl_text);
auto result = run_inline_visitor(input);
REQUIRE(result == input);
Expand Down Expand Up @@ -646,3 +647,60 @@ SCENARIO("Inlining pass handles local-global name conflict", "[visitor][inline]"
}
}
}

SCENARIO("Trying to inline a function with VERBATIM block") {
GIVEN("A VERBATIM block without a return inside") {
std::string input_nmodl = R"(
PROCEDURE verb_1() {
VERBATIM
pow(1,2);
ENDVERBATIM
}
PROCEDURE verb_2() {
verb_1()
}
)";

std::string output_nmodl = R"(
PROCEDURE verb_1() {
VERBATIM
pow(1,2);
ENDVERBATIM
}
PROCEDURE verb_2() {
{
VERBATIM
pow(1,2);
ENDVERBATIM
}
}
)";
THEN("It gets inlined") {
std::string input = reindent_text(input_nmodl);
auto expected_result = reindent_text(output_nmodl);
auto result = run_inline_visitor(input);
REQUIRE(expected_result == result);
}
}
GIVEN("A VERBATIM block with a return value") {
std::string nmodl_text = R"(
PROCEDURE verb_1() {
VERBATIM
return pow(1,2);
ENDVERBATIM
}
PROCEDURE verb_2() {
verb_1()
}
)";

THEN("It is not inlined") {
std::string input = reindent_text(nmodl_text);
auto result = run_inline_visitor(input);
REQUIRE(result == input);
}
}
}

0 comments on commit 0514fbe

Please sign in to comment.