本文整理汇总了C++中CBotCStack::AddVar方法的典型用法代码示例。如果您正苦于以下问题:C++ CBotCStack::AddVar方法的具体用法?C++ CBotCStack::AddVar怎么用?C++ CBotCStack::AddVar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBotCStack
的用法示例。
在下文中一共展示了CBotCStack::AddVar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Compile
// compiles a new function
// bLocal allows of the declaration of parameters on the same level
// as the elements belonging to the class for methods
CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunction* finput, bool bLocal)
{
CBotToken* pp;
CBotFunction* func = finput;
if ( func == NULL ) func = new CBotFunction();
CBotCStack* pStk = pStack->TokenStack(p, bLocal);
// func->m_nFuncIdent = CBotVar::NextUniqNum();
while (true)
{
if ( IsOfType(p, ID_PUBLIC) )
{
func->m_bPublic = true;
continue;
}
pp = p;
if ( IsOfType(p, ID_EXTERN) )
{
func->m_extern = pp; // for the position of the word "extern"
func->m_bExtern = true;
// func->m_bPublic = true; // therefore also public!
continue;
}
break;
}
func->m_retToken = *p;
// CBotClass* pClass;
func->m_retTyp = TypeParam(p, pStk); // type of the result
if (func->m_retTyp.GetType() >= 0)
{
CBotToken* pp = p;
func->m_token = *p;
if ( IsOfType(p, ID_NOT) )
{
CBotToken d("~" + p->GetString());
func->m_token = d;
}
// un nom de fonction est-il là ?
if (IsOfType(p, TokenTypVar))
{
if ( IsOfType( p, ID_DBLDOTS ) ) // method for a class
{
func->m_MasterClass = pp->GetString();
CBotClass* pClass = CBotClass::Find(pp);
if ( pClass == NULL ) goto bad;
// pp = p;
func->m_token = *p;
if (!IsOfType(p, TokenTypVar)) goto bad;
}
func->m_openpar = p;
func->m_Param = CBotDefParam::Compile( p, pStk );
func->m_closepar = p->GetPrev();
if (pStk->IsOk())
{
pStk->SetRetType(func->m_retTyp); // for knowledge what type returns
if (!func->m_MasterClass.IsEmpty())
{
// return "this" known
CBotVar* pThis = CBotVar::Create("this", CBotTypResult( CBotTypClass, func->m_MasterClass ));
pThis->SetInit(2);
// pThis->SetUniqNum(func->m_nThisIdent = -2); //CBotVar::NextUniqNum() will not
pThis->SetUniqNum(-2);
pStk->AddVar(pThis);
// initialize variables acording to This
// only saves the pointer to the first,
// the rest is chained
CBotVar* pv = pThis->GetItemList();
// int num = 1;
while (pv != NULL)
{
CBotVar* pcopy = CBotVar::Create(pv);
// pcopy->SetInit(2);
pcopy->Copy(pv);
pcopy->SetPrivate(pv->GetPrivate());
// pcopy->SetUniqNum(pv->GetUniqNum()); //num++);
pStk->AddVar(pcopy);
pv = pv->GetNext();
}
}
// and compiles the following instruction block
func->m_openblk = p;
func->m_Block = CBotBlock::Compile(p, pStk, false);
func->m_closeblk = p->GetPrev();
if ( pStk->IsOk() )
{
if ( func->m_bPublic ) // public function, return known for all
//.........这里部分代码省略.........
示例2: CompileDefItem
bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
{
bool bStatic = false;
int mProtect = PR_PUBLIC;
bool bSynchro = false;
while (IsOfType(p, ID_SEP)) ;
CBotTypResult type( -1 );
if ( IsOfType(p, ID_SYNCHO) ) bSynchro = true;
CBotToken* pBase = p;
if ( IsOfType(p, ID_STATIC) ) bStatic = true;
if ( IsOfType(p, ID_PUBLIC) ) mProtect = PR_PUBLIC;
if ( IsOfType(p, ID_PRIVATE) ) mProtect = PR_PRIVATE;
if ( IsOfType(p, ID_PROTECTED) ) mProtect = PR_PROTECT;
if ( IsOfType(p, ID_STATIC) ) bStatic = true;
// CBotClass* pClass = NULL;
type = TypeParam(p, pStack); // type of the result
if ( type.Eq(-1) )
{
pStack->SetError(TX_NOTYP, p);
return false;
}
while (pStack->IsOk())
{
CBotToken* pp = p;
IsOfType(p, ID_NOT); // skips ~ eventual (destructor)
if (IsOfType(p, TokenTypVar))
{
CBotInstr* limites = NULL;
while ( IsOfType( p, ID_OPBRK ) ) // a table?
{
CBotInstr* i = NULL;
if ( p->GetType() != ID_CLBRK )
i = CBotExpression::Compile( p, pStack ); // expression for the value
else
i = new CBotEmpty(); // special if not a formula
type = CBotTypResult(CBotTypArrayPointer, type);
if (!pStack->IsOk() || !IsOfType( p, ID_CLBRK ) )
{
pStack->SetError(TX_CLBRK, p->GetStart());
return false;
}
/* CBotVar* pv = pStack->GetVar();
if ( pv->GetType()>= CBotTypBoolean )
{
pStack->SetError(TX_BADTYPE, p->GetStart());
return false;
}*/
if (limites == NULL) limites = i;
else limites->AddNext3(i);
}
if ( p->GetType() == ID_OPENPAR )
{
if ( !bSecond )
{
p = pBase;
CBotFunction* f =
CBotFunction::Compile1(p, pStack, this);
if ( f == NULL ) return false;
if (m_pMethod == NULL) m_pMethod = f;
else m_pMethod->AddNext(f);
}
else
{
// return a method precompiled in pass 1
CBotFunction* pf = m_pMethod;
CBotFunction* prev = NULL;
while ( pf != NULL )
{
if (pf->GetName() == pp->GetString()) break;
prev = pf;
pf = pf->Next();
}
bool bConstructor = (pp->GetString() == GetName());
CBotCStack* pile = pStack->TokenStack(NULL, true);
// make "this" known
CBotToken TokenThis(CBotString("this"), CBotString());
CBotVar* pThis = CBotVar::Create(&TokenThis, CBotTypResult( CBotTypClass, this ) );
pThis->SetUniqNum(-2);
pile->AddVar(pThis);
if ( m_pParent )
{
//.........这里部分代码省略.........