本文整理汇总了C++中ConstantScope::module方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstantScope::module方法的具体用法?C++ ConstantScope::module怎么用?C++ ConstantScope::module使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConstantScope
的用法示例。
在下文中一共展示了ConstantScope::module方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enclosure_name
std::string LLVMState::enclosure_name(CompiledCode* code) {
ConstantScope* cs = code->scope();
if(!kind_of<ConstantScope>(cs) || !kind_of<Module>(cs->module())) {
return "ANONYMOUS";
}
return symbol_debug_str(cs->module()->module_name());
}
示例2: rbx_add_scope
Object* rbx_add_scope(STATE, CallFrame* call_frame, Object* top) {
CPP_TRY
Module* mod = as<Module>(top);
ConstantScope* scope = ConstantScope::create(state);
scope->module(state, mod);
scope->parent(state, call_frame->constant_scope());
call_frame->constant_scope_ = scope;
return cNil;
CPP_CATCH
}
示例3: const_missing
Object* const_missing(STATE, Symbol* sym, CallFrame* call_frame) {
Module* under;
call_frame = call_frame->top_ruby_frame();
ConstantScope* scope = call_frame->constant_scope();
if(scope->nil_p()) {
under = G(object);
} else {
under = scope->module();
}
Array* args = Array::create(state, 1);
args->set(state, 0, sym);
return under->send(state, call_frame, G(sym_const_missing), args);
}
示例4: const_get
Object* const_get(STATE, CallFrame* call_frame, Symbol* name, bool* found, Object* filter) {
ConstantScope *cur;
Object* result;
*found = false;
call_frame = call_frame->top_ruby_frame();
// Ok, this has to be explained or it will be considered black magic.
// The scope chain always ends with an entry at the top that contains
// a parent of nil, and a module of Object. This entry is put in
// regardless of lexical scoping, it's the fallback scope (the default
// scope). This is not case when deriving from BasicObject, which is
// explained later.
//
// When looking up a constant, we don't want to consider the fallback
// scope (ie, Object) initially because we need to lookup up
// the superclass chain first, because falling back on the default.
//
// The rub comes from the fact that if a user explicitly opens up
// Object in their code, we DO consider it. Like:
//
// class Idiot
// A = 2
// end
//
// class ::Object
// A = 1
// class Stupid < Idiot
// def foo
// p A
// end
// end
// end
//
// In this code, when A is looked up, Object must be considering during
// the scope walk, NOT during the superclass walk.
//
// So, in this case, foo would print "1", not "2".
//
// As indicated above, the fallback scope isn't used when the superclass
// chain directly rooted from BasicObject. To determine this is the
// case, we record whether Object is seen when looking up the superclass
// chain. If Object isn't seen, this means we are directly deriving from
// BasicObject.
cur = call_frame->constant_scope();
while(!cur->nil_p()) {
// Detect the toplevel scope (the default) and get outta dodge.
if(cur->top_level_p(state)) break;
result = cur->module()->get_const(state, name, found);
if(*found) {
if(result != filter) return result;
*found = false;
}
cur = cur->parent();
}
// Now look up the superclass chain.
Module *fallback = G(object);
bool object_seen = false;
cur = call_frame->constant_scope();
if(!cur->nil_p()) {
Module* mod = cur->module();
while(!mod->nil_p()) {
if(mod == G(object)) {
object_seen = true;
}
if(!object_seen && mod == G(basicobject)) {
fallback = NULL;
}
result = mod->get_const(state, name, found);
if(*found) {
if(result != filter) return result;
*found = false;
}
mod = mod->superclass();
}
}
// Lastly, check the fallback scope (=Object) specifically if needed
if(fallback) {
result = fallback->get_const(state, name, found, true);
if(*found) {
if(result != filter) return result;
*found = false;
}
}
return cNil;
}