MCPcopy Create free account
hub / github.com/covscript/covscript / opt_expr

Method opt_expr

sources/compiler/compiler.cpp:796–1048  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

794 }
795
796 void
797 compiler_type::opt_expr(tree_type<token_base *> &tree, tree_type<token_base *>::iterator it, optm_type do_optm)
798 {
799 if (!it.usable())
800 return;
801 token_base *token = it.data();
802 if (token == nullptr)
803 return;
804 switch (token->get_type()) {
805 default:
806 break;
807 case token_types::id: {
808 var value = context->instance->storage.get_var_optimizable(static_cast<token_id *>(token)->get_id());
809 if (value.usable() && value.is_protect()) {
810 if (do_optm == optm_type::enable_namespace_optm || !value.is_type_of<namespace_t>() ||
811 !value.const_val<namespace_t>()->get_domain().exist("__PRAGMA_CS_NAMESPACE_DEFINITION__"))
812 it.data() = new_value(value);
813 }
814 return;
815 }
816 case token_types::literal: {
817 token_literal *ptr = static_cast<token_literal *>(token);
818 token_base *oldt = it.data();
819 try {
820 it.data() = new_value(context->instance->get_string_literal(ptr->get_data(), ptr->get_literal()));
821 }
822 catch (...) {
823 it.data() = oldt;
824 }
825 return;
826 }
827 case token_types::expand: {
828 tree_type<token_base *> &tree = static_cast<token_expand *>(token)->get_tree();
829 opt_expr(tree, tree.root(), do_optm);
830 return;
831 }
832 case token_types::array: {
833 token_base *ptr = nullptr;
834 for (auto &tree : static_cast<token_array *>(token)->get_array()) {
835 ptr = tree.root().data();
836 if (ptr != nullptr && ptr->get_type() == token_types::expand) {
837 auto &child_tree = static_cast<token_expand *>(ptr)->get_tree();
838 optimize_expression(child_tree, do_optm);
839 if (!optimizable(child_tree.root()))
840 return;
841 }
842 else {
843 optimize_expression(tree, do_optm);
844 if (!optimizable(tree.root()))
845 return;
846 }
847 }
848 token_base *oldt = it.data();
849 try {
850 array arr;
851 for (auto &tree : static_cast<token_array *>(token)->get_array()) {
852 ptr = tree.root().data();
853 if (ptr != nullptr && ptr->get_type() == token_types::expand) {

Callers

nothing calls this directly

Calls 15

compile_errorClass · 0.85
lvalueFunction · 0.85
dataMethod · 0.80
get_var_optimizableMethod · 0.80
is_protectMethod · 0.80
get_string_literalMethod · 0.80
parse_exprMethod · 0.80
get_signalMethod · 0.80
leftMethod · 0.80
rightMethod · 0.80
reserve_leftMethod · 0.80
reserve_rightMethod · 0.80

Tested by

no test coverage detected