本文整理汇总了C++中ExpReturn类的典型用法代码示例。如果您正苦于以下问题:C++ ExpReturn类的具体用法?C++ ExpReturn怎么用?C++ ExpReturn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExpReturn类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eGetFuncName
long ExtObject::eGetFuncName(LPVAL params, ExpReturn& ret)
{
if (funcStack.empty())
return ret.ReturnString(pRuntime, "");
return ret.ReturnString(pRuntime, funcStack.back().name);
}
示例2: eGetMessages
long ExtObject::eGetMessages(LPVAL params, ExpReturn& ret)
{
if(taggedMessages.IsEmpty())
return ret.ReturnString(pRuntime, "");
int start = clamp(params[0].GetInt() - 1, 0, taggedMessages.GetUpperBound());
int end = clamp(params[1].GetInt() - 1, 0, taggedMessages.GetUpperBound());
return ret.ReturnString(pRuntime, getMessages(start, end));
}
示例3: Evaluate
//OPTIMISE: necessary to perform new stack every call?
//OPTIMISE: maintain expParamList when all parameters are constant? partially maintain when some are constant?
void ExpDot::Evaluate(ExpReturn* er)
{
ExpReturn* expPtr = expParamList;
// Check parameter count OK
if (!pCExp->CheckParamCount(objName, fname, parameters.size())) {
CString msg;
msg.Format("'%s.%s' does not take %d parameters", objName, fname, parameters.size());
throw runtime_error((const char*)msg);
}
// Parameters exist? Evaluate them
if (hasParameters) {
ExpParamIterator i = parameters.begin();
ExpParamConstIterator parameters_end = parameters.end();
int index = 0;
// Evaluate every parameter
for ( ; i != parameters_end; i++, index++) {
// Send to address of corresponding expParamList array entry
(*i)->Evaluate(expPtr);
// Special check for variable name param
if (expPtr->Type() == EXPTYPE_VARIABLENAME) {
if (!pCExp->PrivateVariableExists(objName, fname, index, parameters.size(), *(expPtr->GetStringPtr()))) {
CString msg;
msg.Format("'%s' is not a private variable in '%s' (parameter %d)", *(expPtr->GetStringPtr()), fname, index + 1);
throw runtime_error((const char*)msg);
}
}
else if (!pCExp->ParamValid(objName, fname, index, parameters.size(), expPtr->Type())) {
CString msg;
msg.Format("Parameter %d of '%s.%s' does not take '%s'", index+1, objName, fname, GetTypeName(expPtr->Type()));
throw runtime_error((const char*)msg);
}
expPtr++;
}
}
// Undefined expression call?
if (unnamedExp) {
// TODO: check unnamed expression call is valid
}
// Obtain expression type from IDE
er->eType = pCExp->GetExpressionType(objName, fname);
}
示例4: eGetMessagesByTags
long ExtObject::eGetMessagesByTags(LPVAL params, ExpReturn &ret)
{
if(taggedMessages.IsEmpty())
return ret.ReturnString(pRuntime, "");
int start = clamp(params[0].GetInt() - 1, 0, taggedMessages.GetUpperBound());
int end = clamp(params[1].GetInt() - 1, 0, taggedMessages.GetUpperBound());
CStringList tags;
Messenger::splitTags(params[2].GetString(), tags);
return ret.ReturnString(pRuntime, getMessages(start, end, &tags));
}
示例5: runtime_error
///////////
// Collapse a constant tree
// If an ExpPart* returns true for Constant(), evaluate it, and reallocate a new
// literal to represent the constant part of that expression.
// Ctor
CollapseConstantTreeObj::CollapseConstantTreeObj(ExpPart*& p)
{
// Store existing details
CExpression* pExpression = p->pCExp;
int tnum = p->tokennum;
// Create an ExpReturn, evaluate in to it, then delete the old ExpPart.
ExpReturn e;
p->Evaluate(&e);
// For deleting later (the string might be used)
ExpPart* oldPart = p;
// Reallocate a literal to represent that part of the tree.
switch(e.Type()) {
case EXPTYPE_INTEGER:
p = new ExpInteger;
p->t = T_INTEGER;
static_cast<ExpInteger*>(p)->value = e.GetInt64();
break;
case EXPTYPE_FLOAT:
p = new ExpFloat;
p->t = T_FLOAT;
static_cast<ExpFloat*>(p)->value = e.GetDouble();
break;
case EXPTYPE_STRING:
p = new ExpString;
p->t = T_STRINGLITERAL;
static_cast<ExpString*>(p)->value = *(e.GetStringPtr());
break;
case EXPTYPE_ARRAY:
// Arrays cannot be folded; they collapse their elements but nothing can be
// done with a const array
p = oldPart;
return;
case EXPTYPE_VARIABLENAME:
p = new ExpVariableName;
static_cast<ExpVariableName*>(p)->index = e.eData.vni.varIndex;
static_cast<ExpVariableName*>(p)->pOwnerType = e.eData.vni.pOwnerType;
break;
default:
throw runtime_error("Unexpected type in a constant expression");
}
// Set the pCExp and tokennum back.
p->pCExp = pExpression;
p->tokennum = tnum;
// Delete the old tree part now
delete oldPart;
}
示例6: cmn_eGetXY
long ExtObject::cmn_eGetXY(LPVAL params, ExpReturn &ret)
{
// Store and return this instance's X and Y in the array {x, y}
cmn_xyRet[0] = info.x;
cmn_xyRet[1] = info.y;
return ret.ReturnArray(cmn_xyRet, 2);
}
示例7: eGetAnimName
long ExtObject::eGetAnimName(LPVAL params, ExpReturn& ret)
{
map<int, KeyAnimation>::iterator i = anim.find(animation);
if(i != anim.end())
{
return ret.ReturnString(pRuntime, i->second.name);
}
return NULL;
}
示例8: ReturnDefaultValue
// Return the Default Value. This is the value to be returned if your object name
// is used without an expression name, eg. in "Counter + 1".
// Parameters can be passed, eg. MyObject(3,7). You can check the Type() or GetNumParams() to check for overloads.
long ExtObject::ReturnDefaultValue(LPVAL theParams, ExpReturn& ret)
{
// ACCESS PRIVATE VALUE
if (theParams[0].Type() == EXPTYPE_VARIABLENAME) {
return ret.ReturnCustom(pRuntime, privateVars[theParams[0].GetVariableIndex(pRuntime, pType)]);
}
else {
return ret = 0;
}
}
示例9: ExpStore
ExpStore::ExpStore(const ExpReturn& r) {
switch (r.Type()) {
case EXPTYPE_STRING:
eData.str = new CString;
*(eData.str) = (const char*)*(r.GetStringPtr());
break;
case EXPTYPE_ARRAY:
{
const int size = eData.arr.size = r.eData.arr.size;
eData.arr.pArray = new ExpStore[size];
for( int i = 0; i < eData.arr.size; i++)
eData.arr.pArray[i] = ExpStore( r.eData.arr.pArray[i] );
}
break;
default:
// Other types can simply copy the eData union content
eData.iVal = r.eData.iVal;
}
eType = r.Type();
}
示例10: eGetParam
long ExtObject::eGetParam(LPVAL params, ExpReturn& ret)
{
if (funcStack.empty())
return ret = 0;
int index = params[0].GetInt() - 1;
vector<ExpStore>& paramList = funcStack.back().paramList;
if (index < 0 || index >= paramList.size()) {
pRuntime->AddDebugLogMessage("Function object: Attempted to retrieve a non-existant parameter; returning 0");
return 0;
}
else return ret.ReturnCustom(pRuntime, paramList[index]);
}
示例11:
// Bitwise copy!
inline long operator=(const ExpReturn& r)
{
eType = r.Type();
eData.iVal = r.eData.iVal;
return 0;
}
示例12: switch
void ExpAt::Evaluate(ExpReturn *er)
{
ExpReturn param;
// Evaluate both sides
l->Evaluate(er);
r->Evaluate(¶m);
// Left side not an array? Have no effect
if (er->Type() != EXPTYPE_ARRAY) {
#ifdef CONSTRUCT_DEBUGGER
pCExp->pRuntime->LogMsg("Expression 'at': Expression on left is not an array. Operator had no effect.");
#endif
return;
}
// List of array indices to access, eg. 5 then 6 then 3 for at {5,6,3}
int derefs[32];
int derefCount = 0;
// Check right side type and get index
switch(param.Type()) {
case EXPTYPE_INTEGER:
derefs[0] = param.eData.iVal;
derefs[0]--; // Make 0-based
derefCount = 1;
break;
case EXPTYPE_FLOAT:
derefs[0] = param.eData.fVal;
derefs[0]--; // Make 0-based
derefCount = 1;
break;
case EXPTYPE_ARRAY:
const ExpStore* i = param.GetArray();
const ExpStore* const arr_end = i + param.GetArraySize();
for ( ; i != arr_end; i++) {
derefs[derefCount] = i->GetInt() - 1;
derefCount++;
}
}
const ExpReturn* elementPtr = er;
// Dereference the array as needed
for (int i = 0; i < derefCount; i++) {
int index = derefs[i];
// Return 0 for out-of-bounds
if (index < 0 || index >= elementPtr->GetArraySize()) {
er->eType = EXPTYPE_INTEGER;
er->eData.iVal = 0;
#ifdef CONSTRUCT_DEBUGGER
pCExp->pRuntime->LogMsg("Expression 'at': Array access out-of-bounds: returning 0");
#endif
return;
}
elementPtr = (ExpReturn*)&(elementPtr->GetArray()[index]);
}
// Array element is another array? Just pass on the reference
if (elementPtr->Type() == EXPTYPE_ARRAY) {
er->eType = EXPTYPE_ARRAY;
er->eData.arr = elementPtr->eData.arr;
return;
}
// Array element not another array: copy to temp value (arrays are reference semantics)
else {
// operator= copy to ExpStore, then operator= reference to ExpReturn
value = *elementPtr;
*er = (ExpReturn&)value; // force reference copy
return;
}
}
示例13: eGetValue
long ExtObject::eGetValue(LPVAL params, ExpReturn& ret)
{
return ret.ReturnCustom(pRuntime, privateVars[params[0].GetVariableIndex(pRuntime, pType)]);
}
示例14: eGetReturn
long ExtObject::eGetReturn(LPVAL params, ExpReturn& ret)
{
return ret.ReturnCustom(pRuntime, retVal);
}