本文整理汇总了C++中CodeGen::get_name_map_pos方法的典型用法代码示例。如果您正苦于以下问题:C++ CodeGen::get_name_map_pos方法的具体用法?C++ CodeGen::get_name_map_pos怎么用?C++ CodeGen::get_name_map_pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGen
的用法示例。
在下文中一共展示了CodeGen::get_name_map_pos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _parse_expression
int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expression, int p_stack_level,bool p_root) {
switch(p_expression->type) {
//should parse variable declaration and adjust stack accordingly...
case GDParser::Node::TYPE_IDENTIFIER: {
//return identifier
//wait, identifier could be a local variable or something else... careful here, must reference properly
//as stack may be more interesting to work with
//This could be made much simpler by just indexing "self", but done this way (with custom self-addressing modes) increases peformance a lot.
const GDParser::IdentifierNode *in = static_cast<const GDParser::IdentifierNode*>(p_expression);
StringName identifier = in->name;
// TRY STACK!
if (codegen.stack_identifiers.has(identifier)) {
int pos = codegen.stack_identifiers[identifier];
return pos|(GDFunction::ADDR_TYPE_STACK_VARIABLE<<GDFunction::ADDR_BITS);
}
//TRY ARGUMENTS!
if (!codegen.function_node || !codegen.function_node->_static) {
// TRY MEMBER VARIABLES!
//static function
if (codegen.script->member_indices.has(identifier)) {
int idx = codegen.script->member_indices[identifier];
return idx|(GDFunction::ADDR_TYPE_MEMBER<<GDFunction::ADDR_BITS); //argument (stack root)
}
}
//TRY CLASS CONSTANTS
GDScript *owner = codegen.script;
while (owner) {
GDScript *scr = owner;
GDNativeClass *nc=NULL;
while(scr) {
if (scr->constants.has(identifier)) {
//int idx=scr->constants[identifier];
int idx = codegen.get_name_map_pos(identifier);
return idx|(GDFunction::ADDR_TYPE_CLASS_CONSTANT<<GDFunction::ADDR_BITS); //argument (stack root)
}
if (scr->native.is_valid())
nc=scr->native.ptr();
scr=scr->_base;
}
// CLASS C++ Integer Constant
if (nc) {
bool success=false;
int constant = ObjectTypeDB::get_integer_constant(nc->get_name(),identifier,&success);
if (success) {
Variant key=constant;
int idx;
if (!codegen.constant_map.has(key)) {
idx=codegen.constant_map.size();
codegen.constant_map[key]=idx;
} else {
idx=codegen.constant_map[key];
}
return idx|(GDFunction::ADDR_TYPE_LOCAL_CONSTANT<<GDFunction::ADDR_BITS); //make it a local constant (faster access)
}
}
owner=owner->_owner;
}
/*
handled in constants now
if (codegen.script->subclasses.has(identifier)) {
//same with a subclass, make it a local constant.
int idx = codegen.get_constant_pos(codegen.script->subclasses[identifier]);
return idx|(GDFunction::ADDR_TYPE_LOCAL_CONSTANT<<GDFunction::ADDR_BITS); //make it a local constant (faster access)
}*/
if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) {
int idx = GDScriptLanguage::get_singleton()->get_global_map()[identifier];
return idx|(GDFunction::ADDR_TYPE_GLOBAL<<GDFunction::ADDR_BITS); //argument (stack root)
}
//not found, error
//.........这里部分代码省略.........
示例2: _parse_function
Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *p_class,const GDParser::FunctionNode *p_func) {
Vector<int> bytecode;
CodeGen codegen;
codegen.class_node=p_class;
codegen.script=p_script;
codegen.function_node=p_func;
codegen.stack_max=0;
codegen.current_line=0;
codegen.call_max=0;
codegen.debug_stack=ScriptDebugger::get_singleton()!=NULL;
int stack_level=0;
if (p_func) {
for(int i=0;i<p_func->arguments.size();i++) {
int idx = i;
codegen.add_stack_identifier(p_func->arguments[i],i);
}
stack_level=p_func->arguments.size();
}
codegen.alloc_stack(stack_level);
/* Parse initializer -if applies- */
bool is_initializer=false || !p_func;
if (!p_func || String(p_func->name)=="_init") {
//parse initializer for class members
if (!p_func && p_class->extends_used && p_script->native.is_null()){
//call implicit parent constructor
codegen.opcodes.push_back(GDFunction::OPCODE_CALL_SELF_BASE);
codegen.opcodes.push_back(codegen.get_name_map_pos("_init"));
codegen.opcodes.push_back(0);
codegen.opcodes.push_back((GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS)|0);
}
Error err = _parse_block(codegen,p_class->initializer,stack_level);
if (err)
return err;
is_initializer=true;
}
/* Parse default argument code -if applies- */
Vector<int> defarg_addr;
StringName func_name;
if (p_func) {
if (p_func->default_values.size()) {
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_TO_DEF_ARGUMENT);
defarg_addr.push_back(codegen.opcodes.size());
for(int i=0;i<p_func->default_values.size();i++) {
_parse_expression(codegen,p_func->default_values[i],stack_level,true);
defarg_addr.push_back(codegen.opcodes.size());
}
defarg_addr.invert();
}
Error err = _parse_block(codegen,p_func->body,stack_level);
if (err)
return err;
func_name=p_func->name;
} else {
func_name="_init";
}
codegen.opcodes.push_back(GDFunction::OPCODE_END);
GDFunction *gdfunc=NULL;
//if (String(p_func->name)=="") { //initializer func
// gdfunc = &p_script->initializer;
//} else { //regular func
p_script->member_functions[func_name]=GDFunction();
gdfunc = &p_script->member_functions[func_name];
//}
if (p_func)
gdfunc->_static=p_func->_static;
//constants
if (codegen.constant_map.size()) {
gdfunc->_constant_count=codegen.constant_map.size();
gdfunc->constants.resize(codegen.constant_map.size());
gdfunc->_constants_ptr=&gdfunc->constants[0];
const Variant *K=NULL;
while((K=codegen.constant_map.next(K))) {
//.........这里部分代码省略.........