本文整理汇总了C++中CBotCStack::GetTypResult方法的典型用法代码示例。如果您正苦于以下问题:C++ CBotCStack::GetTypResult方法的具体用法?C++ CBotCStack::GetTypResult怎么用?C++ CBotCStack::GetTypResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBotCStack
的用法示例。
在下文中一共展示了CBotCStack::GetTypResult方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CompileParams
CBotInstr* CompileParams(CBotToken* &p, CBotCStack* pStack, CBotVar** ppVars)
{
bool first = true;
CBotInstr* ret = nullptr; // to return to the list
CBotCStack* pile = pStack;
int i = 0;
if (IsOfType(p, ID_OPENPAR))
{
int start, end;
if (!IsOfType(p, ID_CLOSEPAR)) while (true)
{
start = p->GetStart();
pile = pile->TokenStack(); // keeps the result on the stack
if (first) pStack->SetStartError(start);
first = false;
CBotInstr* param = CBotExpression::Compile(p, pile);
end = p->GetStart();
if (!pile->IsOk())
{
return pStack->Return(nullptr, pile);
}
if (ret == nullptr) ret = param;
else ret->AddNext(param); // construct the list
if (param != nullptr)
{
if (pile->GetTypResult().Eq(99))
{
delete pStack->TokenStack();
pStack->SetError(CBotErrVoid, p->GetStart());
return nullptr;
}
ppVars[i] = pile->GetVar();
ppVars[i]->GetToken()->SetPos(start, end);
i++;
if (IsOfType(p, ID_COMMA)) continue; // skips the comma
if (IsOfType(p, ID_CLOSEPAR)) break;
}
pStack->SetError(CBotErrClosePar, p->GetStart());
delete pStack->TokenStack();
return nullptr;
}
}
ppVars[i] = nullptr;
return ret;
}
示例2: Compile
CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResult type)
{
CBotCStack* pStk = pStack->TokenStack(p);
CBotToken* pp = p;
if (IsOfType( p, ID_NULL ) || (IsOfType(p, ID_OPBLK) && IsOfType(p, ID_CLBLK)))
{
CBotInstr* inst = new CBotExprLitNull();
inst->SetToken(pp);
return pStack->Return(inst, pStk); // ok with empty element
}
p = pp;
CBotListArray* inst = new CBotListArray();
if (IsOfType( p, ID_OPBLK ))
{
// each element takes the one after the other
if (type.Eq( CBotTypArrayPointer ))
{
pStk->SetStartError(p->GetStart());
if (nullptr == ( inst->m_expr = CBotListArray::Compile( p, pStk, type.GetTypElem() ) ))
{
if (pStk->IsOk())
{
inst->m_expr = CBotTwoOpExpr::Compile(p, pStk);
if (inst->m_expr == nullptr || !pStk->GetTypResult().Compare(type)) // compatible type ?
{
pStk->SetError(CBotErrBadType1, p->GetStart());
goto error;
}
}
}
while (IsOfType( p, ID_COMMA )) // other elements?
{
pStk->SetStartError(p->GetStart());
CBotInstr* i = nullptr;
if (nullptr == ( i = CBotListArray::Compile(p, pStk, type.GetTypElem() ) ))
{
if (pStk->IsOk())
{
i = CBotTwoOpExpr::Compile(p, pStk);
if (i == nullptr || !pStk->GetTypResult().Compare(type)) // compatible type ?
{
pStk->SetError(CBotErrBadType1, p->GetStart());
goto error;
}
}
}
inst->m_expr->AddNext3b(i);
if ( p->GetType() == ID_COMMA ) continue;
if ( p->GetType() == ID_CLBLK ) break;
pStk->SetError(CBotErrClosePar, p);
goto error;
}
}
else
{
pStk->SetStartError(p->GetStart());
if (nullptr == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )))
{
goto error;
}
CBotTypResult valType = pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC);
if (!TypeCompatible(valType, type, ID_ASS) )
{
pStk->SetError(CBotErrBadType1, p->GetStart());
goto error;
}
while (IsOfType( p, ID_COMMA )) // other elements?
{
pStk->SetStartError(p->GetStart());
CBotInstr* i = CBotTwoOpExpr::Compile(p, pStk) ;
if (nullptr == i)
{
goto error;
}
CBotTypResult valType = pStk->GetTypResult(CBotVar::GetTypeMode::CLASS_AS_INTRINSIC);
if (!TypeCompatible(valType, type, ID_ASS) )
{
pStk->SetError(CBotErrBadType1, p->GetStart());
goto error;
}
inst->m_expr->AddNext3b(i);
if (p->GetType() == ID_COMMA) continue;
if (p->GetType() == ID_CLBLK) break;
//.........这里部分代码省略.........
示例3: Compile
CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations)
{
int typeMask;
if ( pOperations == nullptr ) pOperations = ListOp;
int* pOp = pOperations;
while ( *pOp++ != 0 ); // follows the table
CBotCStack* pStk = pStack->TokenStack(); // one end of stack please
// search the intructions that may be suitable to the left of the operation
CBotInstr* left = (*pOp == 0) ?
CBotParExpr::Compile( p, pStk ) : // expression (...) left
CBotTwoOpExpr::Compile( p, pStk, pOp ); // expression A * B left
if (left == nullptr) return pStack->Return(nullptr, pStk); // if error, transmit
// did we expected the operand?
int typeOp = p->GetType();
if ( IsInList(typeOp, pOperations, typeMask) )
{
CBotTypResult type1, type2;
type1 = pStk->GetTypResult(); // what kind of the first operand?
if (typeOp == ID_LOGIC) // special case provided for: ? op1: op2;
{
if ( !type1.Eq(CBotTypBoolean) )
{
pStk->SetError( CBotErrBadType1, p);
return pStack->Return(nullptr, pStk);
}
CBotLogicExpr* inst = new CBotLogicExpr();
inst->m_condition = left;
p = p->GetNext(); // skip the token of the operation
inst->m_op1 = CBotExpression::Compile(p, pStk);
CBotToken* pp = p;
if ( inst->m_op1 == nullptr || !IsOfType( p, ID_DOTS ) )
{
pStk->SetError( CBotErrNoDoubleDots, p->GetStart());
delete inst;
return pStack->Return(nullptr, pStk);
}
type1 = pStk->GetTypResult();
inst->m_op2 = CBotExpression::Compile(p, pStk);
if ( inst->m_op2 == nullptr )
{
pStk->SetError( CBotErrNoTerminator, p->GetStart() );
delete inst;
return pStack->Return(nullptr, pStk);
}
type2 = pStk->GetTypResult();
if (!TypeCompatible(type1, type2))
{
pStk->SetError( CBotErrBadType2, pp );
delete inst;
return pStack->Return(nullptr, pStk);
}
pStk->SetType(type1); // the greatest of 2 types
return pStack->Return(inst, pStk);
}
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // element for operation
inst->SetToken(p); // stores the operation
p = p->GetNext(); // skip the token of the operation
// looking statements that may be suitable for right
if ( nullptr != (inst->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp )) )
// expression (...) right
{
// there is an second operand acceptable
type2 = pStk->GetTypResult(); // what kind of results?
if ( type1.Eq(99) || type2.Eq(99) ) // operand is void
{
pStack->SetError(CBotErrBadType2, &inst->m_token);
delete inst;
return nullptr;
}
// what kind of result?
int TypeRes = std::max( type1.GetType(CBotTypResult::GetTypeMode::NULL_AS_POINTER), type2.GetType(CBotTypResult::GetTypeMode::NULL_AS_POINTER) );
if (typeOp == ID_ADD && type1.Eq(CBotTypString))
{
TypeRes = CBotTypString;
type2 = type1; // any type convertible chain
}
else if (typeOp == ID_ADD && type2.Eq(CBotTypString))
{
TypeRes = CBotTypString;
type1 = type2; // any type convertible chain
}
else if (!TypeOk(TypeRes, typeMask)) type1.SetType(99);// error of type
//.........这里部分代码省略.........
示例4: Compile
//.........这里部分代码省略.........
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;
}
}
if (IsOfType(p, ID_ASS)) // with a assignment?
{
if (inst->m_hasParams)
{
pStk->SetError(TX_ENDOF, p->GetStart());
goto error;
}
if ( NULL == ( inst->m_expr = CBotTwoOpExpr::Compile( p, pStk )) )
{
goto error;
}
CBotClass* result = pStk->GetClass();
if ( !pStk->GetTypResult(1).Eq(CBotTypNullPointer) &&
( !pStk->GetTypResult(1).Eq(CBotTypPointer) ||
( result != NULL && !pClass->IsChildOf(result) ))) // type compatible ?
{
pStk->SetError(TX_BADTYPE, p->GetStart());
goto error;
}
// if ( !bIntrinsic ) var->SetPointer(pStk->GetVar()->GetPointer());
if ( !bIntrinsic )
{
// does not use the result on the stack, to impose the class
CBotVar* pvar = CBotVar::Create("", pClass);
var->SetPointer( pvar ); // variable already declared instance pointer
delete pvar; // removes the second pointer
}
var->SetInit(true); // marks the pointer as init
}
else if (inst->m_hasParams)
{
// creates the object on the "job" (\TODO "tas")
// with a pointer to the object
if ( !bIntrinsic )
{
CBotVar* pvar = CBotVar::Create("", pClass);
var->SetPointer( pvar ); // variable already declared instance pointer
delete pvar; // removes the second pointer
}
var->SetInit(2); // marks the pointer as init
}
suite:
if (IsOfType(p, ID_COMMA)) // several chained definitions
{
if ( NULL != ( inst->m_next = CBotClassInst::Compile(p, pStk, pClass) )) // compiles the following
{
return pStack->Return(inst, pStk);
}
}
if (IsOfType(p, ID_SEP)) // complete instruction
{
return pStack->Return(inst, pStk);
}
pStk->SetError(TX_ENDOF, p->GetStart());
}
error:
delete inst;
return pStack->Return(NULL, pStk);
}
示例5: 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);
}
示例6: Compile
CBotInstr* CBotInstrCall::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotVar* ppVars[1000];
int i = 0;
CBotToken* pp = p;
p = p->GetNext();
pStack->SetStartError(p->GetStart());
CBotCStack* pile = pStack;
if ( IsOfType(p, ID_OPENPAR) )
{
int start, end;
CBotInstrCall* inst = new CBotInstrCall();
inst->SetToken(pp);
// compile la list of parameters
if (!IsOfType(p, ID_CLOSEPAR)) while (true)
{
start = p->GetStart();
pile = pile->TokenStack(); // keeps the results on the stack
CBotInstr* param = CBotExpression::Compile(p, pile);
end = p->GetStart();
if ( inst->m_Parameters == NULL ) inst->m_Parameters = param;
else inst->m_Parameters->AddNext(param); // constructs the list
if ( !pile->IsOk() )
{
delete inst;
return pStack->Return(NULL, pile);
}
if ( param != NULL )
{
if ( pile->GetTypResult().Eq(99) )
{
delete pStack->TokenStack();
pStack->SetError(TX_VOID, p->GetStart());
delete inst;
return NULL;
}
ppVars[i] = pile->GetVar();
ppVars[i]->GetToken()->SetPos(start, end);
i++;
if (IsOfType(p, ID_COMMA)) continue; // skips the comma
if (IsOfType(p, ID_CLOSEPAR)) break;
}
pStack->SetError(TX_CLOSEPAR, p->GetStart());
delete pStack->TokenStack();
delete inst;
return NULL;
}
ppVars[i] = NULL;
// the routine is known?
// CBotClass* pClass = NULL;
inst->m_typRes = pStack->CompileCall(pp, ppVars, inst->m_nFuncIdent);
if ( inst->m_typRes.GetType() >= 20 )
{
// if (pVar2!=NULL) pp = pVar2->RetToken();
pStack->SetError( inst->m_typRes.GetType(), pp );
delete pStack->TokenStack();
delete inst;
return NULL;
}
delete pStack->TokenStack();
if ( inst->m_typRes.GetType() > 0 )
{
CBotVar* pRes = CBotVar::Create("", inst->m_typRes);
pStack->SetVar(pRes); // for knowing the type of the result
}
else pStack->SetVar(NULL); // routine returns void
return inst;
}
p = pp;
delete pStack->TokenStack();
return NULL;
}