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

Method get_namespace

sources/compiler/codegen.cpp:74–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72 }
73
74 var method_import_as::get_namespace(const context_t &context, tree_type<token_base *>::iterator it)
75 {
76 token_base *token = it.data();
77 if (token == nullptr)
78 return var();
79 if (token->get_type() == token_types::id) {
80 const var_id &package_name = static_cast<token_id *>(token)->get_id();
81 return make_namespace(context->instance->import(current_process->import_path, package_name));
82 }
83 else if (token->get_type() == token_types::signal &&
84 static_cast<token_signal *>(token)->get_signal() == signal_types::dot_) {
85 const var &ext = get_namespace(context, it.left());
86 token_base *id = it.right().data();
87 if (id == nullptr || id->get_type() != token_types::id)
88 throw compile_error(
89 "Wrong grammar for import-as statement, expect <package name> or <package name>.<namespace id>...");
90 if (ext.is_type_of<namespace_t>())
91 return ext.const_val<namespace_t>()->get_var(static_cast<token_id *>(id)->get_id());
92 else
93 throw compile_error("Access non-namespace object.");
94 }
95 else
96 throw compile_error(
97 "Wrong grammar for import-as statement, expect <package name> or <package name>.<namespace id>...");
98 }
99
100 void method_import_as::preprocess(const context_t &context, const std::deque<std::deque<token_base *>> &raw)
101 {

Callers 2

source_importMethod · 0.45
importMethod · 0.45

Calls 8

make_namespaceFunction · 0.85
compile_errorClass · 0.85
dataMethod · 0.80
importMethod · 0.80
get_signalMethod · 0.80
leftMethod · 0.80
rightMethod · 0.80
get_typeMethod · 0.45

Tested by

no test coverage detected