Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reference to local variable. #1060

Merged
merged 2 commits into from
Sep 6, 2023
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
2 changes: 1 addition & 1 deletion src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4060,7 +4060,7 @@ void CodegenCppVisitor::visit_for_netcon(const ast::ForNetcon& node) {
// to the next netcon.
const auto& args = node.get_parameters();
RenameVisitor v;
auto& statement_block = node.get_statement_block();
const auto& statement_block = node.get_statement_block();
for (size_t i_arg = 0; i_arg < args.size(); ++i_arg) {
// sanitize node_name since we want to substitute names like (*w) as they are
auto old_name =
Expand Down
6 changes: 5 additions & 1 deletion src/language/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,15 @@ def member_typename(self):

return type_name

@property
def _is_member_type_wrapped_as_shared_pointer(self):
return not (self.is_vector or self.is_base_type_node or self.is_ptr_excluded_node)

@property
def member_rvalue_typename(self):
"""returns rvalue reference type when used as returned or parameter type"""
typename = self.member_typename
if not self.is_integral_type_node:
if not self.is_integral_type_node and not self._is_member_type_wrapped_as_shared_pointer:
pramodk marked this conversation as resolved.
Show resolved Hide resolved
return "const " + typename + "&"
return typename

Expand Down
2 changes: 1 addition & 1 deletion src/language/templates/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
throw std::logic_error("get_node_name() not implemented");
}

const std::shared_ptr<StatementBlock>& Ast::get_statement_block() const {
std::shared_ptr<StatementBlock> Ast::get_statement_block() const {

Check warning on line 33 in src/language/templates/ast/ast.cpp

View check run for this annotation

Codecov / codecov/patch

src/language/templates/ast/ast.cpp#L33

Added line #L33 was not covered by tests
throw std::runtime_error("get_statement_block not implemented");
}

Expand Down
2 changes: 1 addition & 1 deletion src/language/templates/ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ struct Ast: public std::enable_shared_from_this<Ast> {
*
* \sa ast::StatementBlock
*/
virtual const std::shared_ptr<StatementBlock>& get_statement_block() const;
virtual std::shared_ptr<StatementBlock> get_statement_block() const;

/**
* \brief Set symbol table for the AST node
Expand Down
4 changes: 2 additions & 2 deletions src/language/templates/pybind/pyast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
PYBIND11_OVERRIDE(symtab::SymbolTable*, Ast, get_symbol_table, );
}

const std::shared_ptr<StatementBlock>& get_statement_block() const override {
PYBIND11_OVERRIDE(const std::shared_ptr<StatementBlock>&, Ast, get_statement_block, );
std::shared_ptr<StatementBlock> get_statement_block() const override {
PYBIND11_OVERRIDE(std::shared_ptr<StatementBlock>, Ast, get_statement_block, );

Check warning on line 118 in src/language/templates/pybind/pyast.hpp

View check run for this annotation

Codecov / codecov/patch

src/language/templates/pybind/pyast.hpp#L117-L118

Added lines #L117 - L118 were not covered by tests
}

void set_symbol_table(symtab::SymbolTable* newsymtab) override {
Expand Down
2 changes: 1 addition & 1 deletion src/visitors/global_var_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void GlobalToRangeVisitor::visit_neuron_block(ast::NeuronBlock& node) {
std::unordered_set<ast::GlobalVar*> global_variables_to_remove;
std::unordered_set<ast::Statement*> global_statements_to_remove;

auto& statement_block = node.get_statement_block();
auto const& statement_block = node.get_statement_block();
auto& statements = (*statement_block).get_statements();
const auto& symbol_table = ast.get_symbol_table();

Expand Down
2 changes: 1 addition & 1 deletion src/visitors/neuron_solve_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void NeuronSolveVisitor::visit_derivative_block(ast::DerivativeBlock& node) {
node.visit_children(*this);
derivative_block = false;
if (solve_blocks[derivative_block_name] == codegen::naming::EULER_METHOD) {
auto& statement_block = node.get_statement_block();
const auto& statement_block = node.get_statement_block();
for (auto& e: euler_solution_expressions) {
statement_block->emplace_back_statement(e);
}
Expand Down
16 changes: 8 additions & 8 deletions src/visitors/sympy_replace_solutions_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@

void SympyReplaceSolutionsVisitor::try_replace_tagged_statement(
const ast::Node& node,
const std::shared_ptr<ast::Expression>& get_lhs(const ast::Node& node),
const std::shared_ptr<ast::Expression>& get_rhs(const ast::Node& node)) {
std::shared_ptr<ast::Expression> get_lhs(const ast::Node& node),
std::shared_ptr<ast::Expression> get_rhs(const ast::Node& node)) {
interleaves_counter.new_equation(true);

const auto& statement = std::static_pointer_cast<ast::Statement>(
Expand Down Expand Up @@ -212,11 +212,11 @@

void SympyReplaceSolutionsVisitor::visit_diff_eq_expression(ast::DiffEqExpression& node) {
logger->debug("SympyReplaceSolutionsVisitor :: visit {}", to_nmodl(node));
auto get_lhs = [](const ast::Node& node) -> const std::shared_ptr<ast::Expression>& {
auto get_lhs = [](const ast::Node& node) -> std::shared_ptr<ast::Expression> {

Check warning on line 215 in src/visitors/sympy_replace_solutions_visitor.cpp

View check run for this annotation

Codecov / codecov/patch

src/visitors/sympy_replace_solutions_visitor.cpp#L215

Added line #L215 was not covered by tests
return dynamic_cast<const ast::DiffEqExpression&>(node).get_expression()->get_lhs();
};

auto get_rhs = [](const ast::Node& node) -> const std::shared_ptr<ast::Expression>& {
auto get_rhs = [](const ast::Node& node) -> std::shared_ptr<ast::Expression> {

Check warning on line 219 in src/visitors/sympy_replace_solutions_visitor.cpp

View check run for this annotation

Codecov / codecov/patch

src/visitors/sympy_replace_solutions_visitor.cpp#L219

Added line #L219 was not covered by tests
return dynamic_cast<const ast::DiffEqExpression&>(node).get_expression()->get_rhs();
};

Expand All @@ -225,11 +225,11 @@

void SympyReplaceSolutionsVisitor::visit_lin_equation(ast::LinEquation& node) {
logger->debug("SympyReplaceSolutionsVisitor :: visit {}", to_nmodl(node));
auto get_lhs = [](const ast::Node& node) -> const std::shared_ptr<ast::Expression>& {
auto get_lhs = [](const ast::Node& node) -> std::shared_ptr<ast::Expression> {
return dynamic_cast<const ast::LinEquation&>(node).get_left_linxpression();
};

auto get_rhs = [](const ast::Node& node) -> const std::shared_ptr<ast::Expression>& {
auto get_rhs = [](const ast::Node& node) -> std::shared_ptr<ast::Expression> {
return dynamic_cast<const ast::LinEquation&>(node).get_left_linxpression();
};

Expand All @@ -239,11 +239,11 @@

void SympyReplaceSolutionsVisitor::visit_non_lin_equation(ast::NonLinEquation& node) {
logger->debug("SympyReplaceSolutionsVisitor :: visit {}", to_nmodl(node));
auto get_lhs = [](const ast::Node& node) -> const std::shared_ptr<ast::Expression>& {
auto get_lhs = [](const ast::Node& node) -> std::shared_ptr<ast::Expression> {

Check warning on line 242 in src/visitors/sympy_replace_solutions_visitor.cpp

View check run for this annotation

Codecov / codecov/patch

src/visitors/sympy_replace_solutions_visitor.cpp#L242

Added line #L242 was not covered by tests
return dynamic_cast<const ast::NonLinEquation&>(node).get_lhs();
};

auto get_rhs = [](const ast::Node& node) -> const std::shared_ptr<ast::Expression>& {
auto get_rhs = [](const ast::Node& node) -> std::shared_ptr<ast::Expression> {

Check warning on line 246 in src/visitors/sympy_replace_solutions_visitor.cpp

View check run for this annotation

Codecov / codecov/patch

src/visitors/sympy_replace_solutions_visitor.cpp#L246

Added line #L246 was not covered by tests
return dynamic_cast<const ast::NonLinEquation&>(node).get_rhs();
};

Expand Down
4 changes: 2 additions & 2 deletions src/visitors/sympy_replace_solutions_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ class SympyReplaceSolutionsVisitor: public AstVisitor {
*/
void try_replace_tagged_statement(
const ast::Node& node,
const std::shared_ptr<ast::Expression>& get_lhs(const ast::Node& node),
const std::shared_ptr<ast::Expression>& get_rhs(const ast::Node& node));
std::shared_ptr<ast::Expression> get_lhs(const ast::Node& node),
std::shared_ptr<ast::Expression> get_rhs(const ast::Node& node));

/**
* \struct InterleavesCounter
Expand Down
Loading