本文整理汇总了C++中CBotCStack::CheckVarLocal方法的典型用法代码示例。如果您正苦于以下问题:C++ CBotCStack::CheckVarLocal方法的具体用法?C++ CBotCStack::CheckVarLocal怎么用?C++ CBotCStack::CheckVarLocal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBotCStack
的用法示例。
在下文中一共展示了CBotCStack::CheckVarLocal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Compile
CBotInstr* CBotClassInst::Compile(CBotToken* &p, CBotCStack* pStack, CBotClass* pClass)
{
// seeks the corresponding classes
if ( pClass == NULL )
{
pStack->SetStartError(p->GetStart());
pClass = CBotClass::Find(p);
if ( pClass == NULL )
{
// not found? is bizare
pStack->SetError(TX_NOCLASS, p);
return NULL;
}
p = p->GetNext();
}
bool bIntrinsic = pClass->IsIntrinsic();
CBotTypResult type = CBotTypResult( bIntrinsic ? CBotTypIntrinsic : CBotTypPointer, pClass );
CBotClassInst* inst = static_cast<CBotClassInst*>(CompileArray(p, pStack, type));
if ( inst != NULL || !pStack->IsOk() ) return inst;
CBotCStack* pStk = pStack->TokenStack();
inst = new CBotClassInst();
/// \TODO Need to be revised and fixed after adding unit tests
CBotToken token(pClass->GetName(), CBotString(), p->GetStart(), p->GetEnd());
inst->SetToken(&token);
CBotToken* vartoken = p;
if ( NULL != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )) )
{
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_typevar = type;
if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable
{
pStk->SetStartError(vartoken->GetStart());
pStk->SetError(TX_REDEFVAR, vartoken->GetEnd());
goto error;
}
if (IsOfType(p, ID_OPBRK)) // with any clues?
{
delete inst; // is not type CBotInt
p = vartoken; // returns to the variable name
// compiles declaration an array
inst = static_cast<CBotClassInst*>(CBotInstArray::Compile( p, pStk, type ));
if (!pStk->IsOk() )
{
pStk->SetError(TX_CLBRK, p->GetStart());
goto error;
}
goto suite; // no assignment, variable already created
}
CBotVar* var;
var = CBotVar::Create(vartoken->GetString(), type); // creates the instance
// var->SetClass(pClass);
var->SetUniqNum(
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
// its attribute a unique number
pStack->AddVar(var); // placed on the stack
// look if there are parameters
inst->m_hasParams = (p->GetType() == ID_OPENPAR);
CBotVar* ppVars[1000];
inst->m_Parameters = CompileParams(p, pStk, ppVars);
if ( !pStk->IsOk() ) goto error;
// if there are parameters, is the equivalent to the stament "new"
// CPoint A ( 0, 0 ) is equivalent to
// CPoint A = new CPoint( 0, 0 )
// if ( NULL != inst->m_Parameters )
if ( inst->m_hasParams )
{
// the constructor is there?
// CBotString noname;
CBotTypResult r = pClass->CompileMethode(pClass->GetName(), var, ppVars, pStk, inst->m_nMethodeIdent);
delete pStk->TokenStack(); // releases the supplement stack
int typ = r.GetType();
if (typ == TX_UNDEFCALL)
{
// si le constructeur n'existe pas
if (inst->m_Parameters != NULL) // with parameters
{
pStk->SetError(TX_NOCONST, vartoken);
goto error;
}
typ = 0;
}
if (typ>20)
{
pStk->SetError(typ, vartoken->GetEnd());
goto error;
//.........这里部分代码省略.........
示例2: Compile
CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
{
CBotCStack* pStk = pStack->TokenStack(p);
CBotDefArray* inst = new CBotDefArray();
CBotToken* vartoken = p;
inst->SetToken(vartoken);
// determinse the expression is valid for the item on the left side
if (nullptr != (inst->m_var = CBotLeftExprVar::Compile( p, pStk )))
{
if (pStk->CheckVarLocal(vartoken)) // redefinition of the variable?
{
pStk->SetError(CBotErrRedefVar, vartoken);
goto error;
}
CBotInstr* i;
while (IsOfType(p, ID_OPBRK))
{
pStk->SetStartError(p->GetStart());
if (p->GetType() != ID_CLBRK)
{
i = CBotExpression::Compile(p, pStk); // expression for the value
if (i == nullptr || pStk->GetType() != CBotTypInt) // must be a number
{
pStk->SetError(CBotErrBadIndex, p->GetStart());
goto error;
}
}
else
i = new CBotEmpty(); // if no special formula
inst->AddNext3b(i); // construct a list
type = CBotTypResult(CBotTypArrayPointer, type);
if (IsOfType(p, ID_CLBRK)) continue;
pStk->SetError(CBotErrCloseIndex, p->GetStart());
goto error;
}
CBotVar* var = CBotVar::Create(*vartoken, type); // create an instance
inst->m_typevar = type;
var->SetUniqNum(
(static_cast<CBotLeftExprVar*>(inst->m_var))->m_nIdent = CBotVar::NextUniqNum());
pStack->AddVar(var); // place it on the stack
if (IsOfType(p, ID_ASS)) // with an assignment
{
pStk->SetStartError(p->GetStart());
if ( IsOfType(p, ID_SEP) )
{
pStk->SetError(CBotErrNoExpression, p->GetPrev());
goto error;
}
if ( nullptr == (inst->m_listass = CBotListArray::Compile(p, pStk, type.GetTypElem())) )
{
if (pStk->IsOk())
{
inst->m_listass = CBotTwoOpExpr::Compile(p, pStk);
if (inst->m_listass == nullptr || !pStk->GetTypResult().Compare(type)) // compatible type ?
{
pStk->SetError(CBotErrBadType1, p->GetStart());
goto error;
}
}
}
if (pStk->IsOk()) while (true) // mark initialized
{
var = var->GetItem(0, true);
if (var == nullptr) break;
if (var->GetType() == CBotTypArrayPointer) continue;
if (var->GetType() <= CBotTypString) var->SetInit(CBotVar::InitType::DEF);
break;
}
}
if (pStk->IsOk()) return pStack->Return(inst, pStk);
}
error:
delete inst;
return pStack->Return(nullptr, pStk);
}