Skip to content
Merged
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: 4 additions & 0 deletions src/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,6 +2282,8 @@ std::string Generator::interfaceCode(const AnalyserModelPtr &analyserModel, cons

pFunc()->addInterfaceComputeModelMethodsCode();

pFunc()->mAnalyserModel = nullptr;
Comment thread
agarny marked this conversation as resolved.

return pFunc()->mCode;
}

Expand Down Expand Up @@ -2414,6 +2416,8 @@ std::string Generator::implementationCode(const AnalyserModelPtr &analyserModel,

pFunc()->addImplementationComputeVariablesMethodCode(remainingAnalyserEquations);

pFunc()->mAnalyserModel = nullptr;
Comment thread
agarny marked this conversation as resolved.

return pFunc()->mCode;
}

Expand Down
23 changes: 23 additions & 0 deletions tests/generator/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1754,3 +1754,26 @@ TEST(Generator, generateCodeUsingProfileEnum)

EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_computed_var_on_rhs/model.py", generator->implementationCode(analyserModel, libcellml::GeneratorProfile::Profile::PYTHON));
}

TEST(Generator, checkGeneratorReleasesAnalyserModel)
{
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/algebraic_eqn_computed_var_on_rhs/model.cellml"));
auto analyser = libcellml::Analyser::create();

analyser->analyseModel(model);

auto analyserModel = analyser->analyserModel();

EXPECT_EQ(2, analyserModel.use_count());
EXPECT_EQ("x = a", libcellml::Generator::equationCode(analyserModel->analyserEquation(0)->ast()));
EXPECT_EQ(2, analyserModel.use_count());

auto generator = libcellml::Generator::create();

EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_computed_var_on_rhs/model.c", generator->implementationCode(analyserModel));
EXPECT_EQ(2, analyserModel.use_count());

EXPECT_EQ_FILE_CONTENTS("generator/algebraic_eqn_computed_var_on_rhs/model.h", generator->interfaceCode(analyserModel));
EXPECT_EQ(2, analyserModel.use_count());
}
Loading