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

Method optimize

include/chaiscript/language/chaiscript_optimizer.hpp:77–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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>

Callers

nothing calls this directly

Calls 3

backMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected