| 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) { |
nothing calls this directly
no test coverage detected