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

Method optimize

include/chaiscript/language/chaiscript_optimizer.hpp:235–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233 struct If {
234 template<typename T>
235 auto optimize(eval::AST_Node_Impl_Ptr<T> node) {
236 if ((node->identifier == AST_Node_Type::If)
237 && node->children.size() >= 2
238 && node->children[0]->identifier == AST_Node_Type::Constant)
239 {
240 const auto condition = dynamic_cast<eval::Constant_AST_Node<T> *>(node->children[0].get())->m_value;
241 if (condition.get_type_info().bare_equal_type_info(typeid(bool))) {
242 if (boxed_cast<bool>(condition)) {
243 return std::move(node->children[1]);
244 } else if (node->children.size() == 3) {
245 return std::move(node->children[2]);
246 }
247 }
248 }
249
250 return node;
251 }
252 };
253
254 struct Partial_Fold {

Callers 2

build_matchMethod · 0.45
optimizeMethod · 0.45

Calls 3

bare_equal_type_infoMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected