本文整理汇总了C++中CBotCStack::FindVar方法的典型用法代码示例。如果您正苦于以下问题:C++ CBotCStack::FindVar方法的具体用法?C++ CBotCStack::FindVar怎么用?C++ CBotCStack::FindVar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBotCStack
的用法示例。
在下文中一共展示了CBotCStack::FindVar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Compile
CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotCStack* pStk = pStack->TokenStack();
pStk->SetStartError(p->GetStart());
// is it a variable name?
if (p->GetType() == TokenTypVar)
{
CBotLeftExpr* inst = new CBotLeftExpr(); // creates the object
inst->SetToken(p);
CBotVar* var;
if (nullptr != (var = pStk->FindVar(p))) // seek if known variable
{
inst->m_nIdent = var->GetUniqNum();
if (inst->m_nIdent > 0 && inst->m_nIdent < 9000)
{
if (CBotFieldExpr::CheckProtectionError(pStk, nullptr, var, CBotVar::ProtectionLevel::ReadOnly))
{
pStk->SetError(CBotErrPrivate, p);
goto err;
}
// this is an element of the current class
// adds the equivalent of this. before
CBotToken pthis("this");
inst->SetToken(&pthis);
inst->m_nIdent = -2; // indent for this
CBotFieldExpr* i = new CBotFieldExpr(); // new element
i->SetToken(p); // keeps the name of the token
inst->AddNext3(i); // add after
var = pStk->FindVar(pthis);
var = var->GetItem(p->GetString());
i->SetUniqNum(var->GetUniqNum());
}
p = p->GetNext(); // next token
while (true)
{
if (var->GetType() == CBotTypArrayPointer)
{
if (IsOfType( p, ID_OPBRK ))
{
CBotIndexExpr* i = new CBotIndexExpr();
i->m_expr = CBotExpression::Compile(p, pStk);
inst->AddNext3(i); // add to the chain
var = (static_cast<CBotVarArray*>(var))->GetItem(0,true); // gets the component [0]
if (i->m_expr == nullptr)
{
pStk->SetError(CBotErrBadIndex, p->GetStart());
goto err;
}
if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK ))
{
pStk->SetError(CBotErrCloseIndex, p->GetStart());
goto err;
}
continue;
}
}
if (var->GetType(CBotVar::GetTypeMode::CLASS_AS_POINTER) == CBotTypPointer) // for classes
{
if (IsOfType(p, ID_DOT))
{
CBotToken* pp = p;
CBotFieldExpr* i = new CBotFieldExpr(); // new element
i->SetToken(pp); // keeps the name of the token
inst->AddNext3(i); // adds after
if (p->GetType() == TokenTypVar) // must be a name
{
CBotVar* preVar = var;
var = var->GetItem(p->GetString()); // get item correspondent
if (var != nullptr)
{
if (CBotFieldExpr::CheckProtectionError(pStk, preVar, var,
CBotVar::ProtectionLevel::ReadOnly))
{
pStk->SetError(CBotErrPrivate, pp);
goto err;
}
i->SetUniqNum(var->GetUniqNum());
p = p->GetNext(); // skips the name
continue;
}
pStk->SetError(CBotErrUndefItem, p);
}
pStk->SetError(CBotErrUndefClass, p->GetStart());
goto err;
}
//.........这里部分代码省略.........