MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / Return

Class Return

include/chaiscript/language/chaiscript_optimizer.hpp:75–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73
74
75 struct Return {
76 template<typename T>
77 auto optimize(eval::AST_Node_Impl_Ptr<T> p)
78 {
79 if ( (p->identifier == AST_Node_Type::Def || p->identifier == AST_Node_Type::Lambda)
80 && !p->children.empty())
81 {
82 auto &last_child = p->children.back();
83 if (last_child->identifier == AST_Node_Type::Block) {
84 auto &block_last_child = last_child->children.back();
85 if (block_last_child->identifier == AST_Node_Type::Return) {
86 if (block_last_child->children.size() == 1) {
87 last_child->children.back() = std::move(block_last_child->children[0]);
88 }
89 }
90 }
91 }
92
93 return p;
94 }
95 };
96
97 template<typename T>
98 bool contains_var_decl_in_scope(const eval::AST_Node_Impl<T> &node)

Callers 1

StatementsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected