Skip to content

Commit

Permalink
Fix reference to local variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Sep 4, 2023
1 parent 638b870 commit 4dc631f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
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:
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 @@ std::string Ast::get_node_name() const {
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 {
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 @@ struct PyAst: public Ast {
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, );
}

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

0 comments on commit 4dc631f

Please sign in to comment.