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

Method trim_expr

sources/compiler/compiler.cpp:531–794  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

529 }
530
531 void
532 compiler_type::trim_expr(tree_type<token_base *> &tree, tree_type<token_base *>::iterator it, trim_type do_trim)
533 {
534 if (!it.usable())
535 return;
536 token_base *token = it.data();
537 if (token == nullptr)
538 return;
539 switch (token->get_type()) {
540 default:
541 break;
542 case token_types::id: {
543 if (do_trim != trim_type::no_this_deduce) {
544 const std::string &id = static_cast<token_id *>(token)->get_id();
545 if (!context->instance->storage.exist_record(id) &&
546 context->instance->storage.exist_record_in_struct(id)) {
547 it.data() = new token_signal(signal_types::dot_);
548 tree.emplace_left_left(it, token);
549 tree.emplace_left_left(it, new token_id("this"));
550 tree.emplace_right_right(it, token);
551 }
552 }
553 return;
554 }
555 case token_types::expr: {
556 if (do_trim != trim_type::no_expr_fold) {
557 tree_type<token_base *> &t = static_cast<token_expr *>(it.data())->get_tree();
558 trim_expression(t, do_trim);
559 tree.merge(it, t);
560 }
561 return;
562 }
563 case token_types::array: {
564 for (auto &tree : static_cast<token_array *>(token)->get_array())
565 trim_expression(tree, do_trim);
566 return;
567 }
568 case token_types::signal: {
569 switch (static_cast<token_signal *>(token)->get_signal()) {
570 default:
571 break;
572 case signal_types::addr_:
573 if (it.left().data() != nullptr)
574 throw compile_error("Wrong grammar for addr expression.");
575 break;
576 case signal_types::new_:
577 if (it.left().data() != nullptr)
578 throw compile_error("Wrong grammar for new expression.");
579 break;
580 case signal_types::gcnew_:
581 if (it.left().data() != nullptr)
582 throw compile_error("Wrong grammar for gcnew expression.");
583 trim_expr(tree, it.right(), do_trim);
584 return;
585 break;
586 case signal_types::typeid_:
587 if (it.left().data() != nullptr)
588 throw compile_error("Wrong grammar for typeid expression.");

Callers

nothing calls this directly

Calls 15

compile_errorClass · 0.85
internal_errorClass · 0.85
runtime_errorClass · 0.85
dataMethod · 0.80
exist_recordMethod · 0.80
emplace_left_leftMethod · 0.80
emplace_right_rightMethod · 0.80
mergeMethod · 0.80
get_signalMethod · 0.80
leftMethod · 0.80
rightMethod · 0.80

Tested by

no test coverage detected