本文整理汇总了C++中FunctionState::GetVariableOffset方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionState::GetVariableOffset方法的具体用法?C++ FunctionState::GetVariableOffset怎么用?C++ FunctionState::GetVariableOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FunctionState
的用法示例。
在下文中一共展示了FunctionState::GetVariableOffset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenExprIdentifier
bool gmCodeGenPrivate::GenExprIdentifier(const gmCodeTreeNode * a_node, gmByteCodeGen * a_byteCode)
{
GM_ASSERT(a_node->m_type == CTNT_EXPRESSION && a_node->m_subType == CTNET_IDENTIFIER);
// if local, get local regardless
// if member, get this
// if global, get global
// get global
if((a_node->m_flags & gmCodeTreeNode::CTN_MEMBER) > 0)
{
return a_byteCode->EmitPtr(BC_GETTHIS, m_hooks->GetSymbolId(a_node->m_data.m_string));
}
gmCodeTreeVariableType type;
int offset = m_currentFunction->GetVariableOffset(a_node->m_data.m_string, type);
if(offset >= 0 && type == CTVT_LOCAL)
{
return a_byteCode->Emit(BC_GETLOCAL, (gmuint32) offset);
}
else if(offset != -2)
{
if(type == CTVT_MEMBER)
{
return a_byteCode->EmitPtr(BC_GETTHIS, m_hooks->GetSymbolId(a_node->m_data.m_string));
}
else if(type == CTVT_GLOBAL)
{
return a_byteCode->EmitPtr(BC_GETGLOBAL, m_hooks->GetSymbolId(a_node->m_data.m_string));
}
if(m_log) m_log->LogEntry("internal error");
return false;
}
return a_byteCode->EmitPtr(BC_GETGLOBAL, m_hooks->GetSymbolId(a_node->m_data.m_string));
}
示例2: GenExprCall
bool gmCodeGenPrivate::GenExprCall(const gmCodeTreeNode * a_node, gmByteCodeGen * a_byteCode)
{
GM_ASSERT(a_node->m_type == CTNT_EXPRESSION && a_node->m_subType == CTNET_CALL);
// mark the stack.
int stackLevel = a_byteCode->GetTos();
// if callee is a dot function, push left side of dot as 'this'
const gmCodeTreeNode * callee = a_node->m_children[0];
if(callee->m_type == CTNT_EXPRESSION && callee->m_subType == CTNET_OPERATION && callee->m_subTypeType == CTNOT_DOT)
{
if(!Generate(callee->m_children[0], a_byteCode)) return false;
a_byteCode->Emit(BC_DUP);
a_byteCode->EmitPtr(BC_GETDOT, m_hooks->GetSymbolId(callee->m_children[1]->m_data.m_string));
}
else
{
if(a_node->m_children[2])
{
if(!Generate(a_node->m_children[2], a_byteCode)) return false;
}
else
{
#if GM_COMPILE_PASS_THIS_ALWAYS
a_byteCode->Emit(BC_PUSHTHIS);
#else // !GM_COMPILE_PASS_THIS_ALWAYS
// if the lvalue is a member, pass 'this', otherwise pass 'null'
bool pushed = false;
if(callee->m_type == CTNT_EXPRESSION && callee->m_subType == CTNET_IDENTIFIER)
{
gmCodeTreeVariableType vtype;
int offset = m_currentFunction->GetVariableOffset(callee->m_data.m_string, vtype);
if(((callee->m_flags & gmCodeTreeNode::CTN_MEMBER) > 0) || (offset == -1 && vtype == CTVT_MEMBER))
{
a_byteCode->Emit(BC_PUSHTHIS);
pushed = true;
}
}
if(!pushed)
{
a_byteCode->Emit(BC_PUSHNULL);
}
#endif // !GM_COMPILE_PASS_THIS_ALWAYS
}
if(!Generate(callee, a_byteCode)) return false;
}
// push parameters, count the number of parameters
gmuint32 numParams = 0;
const gmCodeTreeNode * params = a_node->m_children[1];
while(params)
{
++numParams;
if(!Generate(params, a_byteCode, false)) return false;
params = params->m_sibling;
}
// call
a_byteCode->Emit(BC_CALL, (gmuint32) numParams);
// restore the stack level.
a_byteCode->SetTos(stackLevel + 1);
return true;
}
示例3: GenExprOpAssign
bool gmCodeGenPrivate::GenExprOpAssign(const gmCodeTreeNode * a_node, gmByteCodeGen * a_byteCode)
{
GM_ASSERT(a_node->m_type == CTNT_EXPRESSION && a_node->m_subType == CTNET_OPERATION);
// value on left hand side must be an l-value... ie, a dot, array or identifier.
const gmCodeTreeNode * lValue = a_node->m_children[0];
int type = 0;
if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_OPERATION && lValue->m_subTypeType == CTNOT_DOT)
{
// Generate half l-value
if(!Generate(lValue->m_children[0], a_byteCode)) return false;
type = 0;
}
else if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_OPERATION && lValue->m_subTypeType == CTNOT_ARRAY_INDEX)
{
// Generate half l-value
if(!Generate(lValue->m_children[0], a_byteCode)) return false;
if(!Generate(lValue->m_children[1], a_byteCode)) return false;
type = 1;
}
else if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_IDENTIFIER)
{
type = 2;
}
else
{
if(m_log) m_log->LogEntry("error (%d) illegal l-value for '=' operator", a_node->m_lineNumber);
return false;
}
// Generate r-value
if(!Generate(a_node->m_children[1], a_byteCode)) return false;
// complete assignment
if(type == 0)
{
a_byteCode->EmitPtr(BC_SETDOT, m_hooks->GetSymbolId(lValue->m_children[1]->m_data.m_string));
}
else if(type == 1)
{
a_byteCode->Emit(BC_SETIND);
}
else if(type == 2)
{
gmCodeTreeVariableType vtype;
int offset = m_currentFunction->GetVariableOffset(lValue->m_data.m_string, vtype);
// if local, set local regardless
// if member set this
// if global, set global
// set and add local
if((lValue->m_flags & gmCodeTreeNode::CTN_MEMBER) > 0)
{
return a_byteCode->EmitPtr(BC_SETTHIS, m_hooks->GetSymbolId(lValue->m_data.m_string));
}
if(offset >= 0 && vtype == CTVT_LOCAL)
{
return a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
}
else if(offset == -1)
{
if(vtype == CTVT_MEMBER)
{
return a_byteCode->EmitPtr(BC_SETTHIS, m_hooks->GetSymbolId(lValue->m_data.m_string));
}
else if(vtype == CTVT_GLOBAL)
{
return a_byteCode->EmitPtr(BC_SETGLOBAL, m_hooks->GetSymbolId(lValue->m_data.m_string));
}
if(m_log) m_log->LogEntry("internal error");
return false;
}
offset = m_currentFunction->SetVariableType(lValue->m_data.m_string, CTVT_LOCAL);
return a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
}
else
{
// paranoia
if(m_log) m_log->LogEntry("internal error");
return false;
}
return true;
}
示例4: GenExprOpPreIncDec
bool gmCodeGenPrivate::GenExprOpPreIncDec(const gmCodeTreeNode * a_node, gmByteCodeGen * a_byteCode)
{
GM_ASSERT(a_node->m_type == CTNT_EXPRESSION && a_node->m_subType == CTNET_OPERATION);
// Make sure child 0 is an l-value
const gmCodeTreeNode * lValue = a_node->m_children[0];
int type = 0;
if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_OPERATION && lValue->m_subTypeType == CTNOT_DOT)
{
// Generate half l-value
if(!Generate(lValue->m_children[0], a_byteCode)) return false;
a_byteCode->Emit(BC_DUP);
a_byteCode->EmitPtr(BC_GETDOT, m_hooks->GetSymbolId(lValue->m_children[1]->m_data.m_string));
type = 0;
}
else if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_OPERATION && lValue->m_subTypeType == CTNOT_ARRAY_INDEX)
{
// Generate half l-value
if(!Generate(lValue->m_children[0], a_byteCode)) return false;
if(!Generate(lValue->m_children[1], a_byteCode)) return false;
a_byteCode->Emit(BC_DUP2);
a_byteCode->Emit(BC_GETIND);
type = 1;
}
else if(lValue->m_type == CTNT_EXPRESSION && lValue->m_subType == CTNET_IDENTIFIER)
{
if(!Generate(lValue, a_byteCode)) return false;
type = 2;
}
else
{
if(m_log) m_log->LogEntry("illegal l-value for '++/--' operator, line %d", a_node->m_lineNumber);
return false;
}
// Perform inc/dec
switch(a_node->m_subTypeType)
{
case CTNOT_PRE_INC : a_byteCode->Emit(BC_OP_INC); break;
case CTNOT_PRE_DEC : a_byteCode->Emit(BC_OP_DEC); break;
default :
{
if(m_log) m_log->LogEntry("unkown operator");
return false;
}
}
// Write back the value
if(type == 0)
{
int offset = m_currentFunction->SetVariableType(s_tempVarName0, CTVT_LOCAL);
a_byteCode->Emit(BC_DUP);
a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
a_byteCode->EmitPtr(BC_SETDOT, m_hooks->GetSymbolId(lValue->m_children[1]->m_data.m_string));
a_byteCode->Emit(BC_GETLOCAL, (gmuint32) offset);
}
else if(type == 1)
{
int offset = m_currentFunction->SetVariableType(s_tempVarName0, CTVT_LOCAL);
a_byteCode->Emit(BC_DUP);
a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
a_byteCode->Emit(BC_SETIND);
a_byteCode->Emit(BC_GETLOCAL, (gmuint32) offset);
}
else if(type == 2)
{
a_byteCode->Emit(BC_DUP);
gmCodeTreeVariableType vtype;
int offset = m_currentFunction->GetVariableOffset(lValue->m_data.m_string, vtype);
// if local, set local regardless
// if member set this
// if global, set global
// set and add local
if((lValue->m_flags & gmCodeTreeNode::CTN_MEMBER) > 0)
{
return a_byteCode->EmitPtr(BC_SETTHIS, m_hooks->GetSymbolId(lValue->m_data.m_string));
}
if(offset >= 0 && vtype == CTVT_LOCAL)
{
return a_byteCode->Emit(BC_SETLOCAL, (gmuint32) offset);
}
else if(offset == -1)
{
if(vtype == CTVT_MEMBER)
{
return a_byteCode->EmitPtr(BC_SETTHIS, m_hooks->GetSymbolId(lValue->m_data.m_string));
}
else if(vtype == CTVT_GLOBAL)
{
return a_byteCode->EmitPtr(BC_SETGLOBAL, m_hooks->GetSymbolId(lValue->m_data.m_string));
}
if(m_log) m_log->LogEntry("internal error");
return false;
}
offset = m_currentFunction->SetVariableType(lValue->m_data.m_string, CTVT_LOCAL);
//.........这里部分代码省略.........