本文整理汇总了C++中ExpressionNode::Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionNode::Evaluate方法的具体用法?C++ ExpressionNode::Evaluate怎么用?C++ ExpressionNode::Evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionNode
的用法示例。
在下文中一共展示了ExpressionNode::Evaluate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Evaluate
int OperationNode::Evaluate(const mtlChars &dst, mtlString &out, int lane, int depth)
{
int ldepth = left->Evaluate(dst, out, lane, depth);
int rdepth = right->IsLeaf() ? 0 : right->Evaluate(dst, out, lane, depth+1);
int mdepth = 0;
mtlString addr_str;
if (depth > 0 || dst.GetSize() == 0) {
out.Append('[');
addr_str.FromInt(depth);
out.Append(addr_str);
out.Append(']');
mdepth = depth;
} else {
mtlString temp;
GetLane(dst, lane, temp);
out.Append(temp);
//out.Append(dst);
}
AppendValue(out);
out.Append('=');
if (right->IsLeaf()) {
right->AppendValue(out);
} else {
addr_str.FromInt(depth+1);
out.Append('[');
out.Append(addr_str);
out.Append(']');
}
out.Append(';');
return mmlMax(ldepth, mdepth, rdepth);
}
示例2: AssignVar
bool AssignVar(CompileInstance &inst, const mtlChars &name, const mtlChars &expr)
{
mtlChars base_name = GetBaseName(name);
Definition *type = GetType(inst, base_name);
if (type == NULL) {
AddError(inst, "Undeclared variable", name);
return false;
}
if (type->mut != Mutable) {
AddError(inst, "Modifying a constant", name);
return false;
}
ExpressionNode *tree = GenerateTree(expr);
if (tree == NULL) {
AddError(inst, "Malformed expression", expr);
return false;
}
mtlChars base_mem = GetBaseMembers(name);
bool result = true;
Parser parser;
mtlList<mtlChars> ops;
mtlList<mtlChars> m;
mtlString order_str;
const int num_lanes = (base_mem.GetSize() > 0) ? base_mem.GetSize() : type->type.size;
for (int lane = 0; lane < num_lanes; ++lane) {
order_str.Free();
const int stack_size = tree->Evaluate(name, order_str, lane, 0);
PushStack(inst, stack_size);
order_str.SplitByChar(ops, ';');
mtlItem<mtlChars> *op = ops.GetFirst();
while (op != NULL && op->GetItem().GetSize() > 0) {
parser.SetBuffer(op->GetItem());
switch (parser.MatchPart("%s+=%s%|%s-=%s%|%s*=%s%|%s/=%s%|%s=%s", m, NULL)) {
case 0:
EmitInstruction(inst, swsl::FLT_ADD_MM);
break;
case 1:
EmitInstruction(inst, swsl::FLT_SUB_MM);
break;
case 2:
EmitInstruction(inst, swsl::FLT_MUL_MM);
break;
case 3:
EmitInstruction(inst, swsl::FLT_DIV_MM);
break;
case 4:
EmitInstruction(inst, swsl::FLT_SET_MM);
break;
default:
AddError(inst, "Invalid syntax", op->GetItem());
return false;
break;
}
mtlItem<swsl::Instruction> *instr_item = inst.program.GetLast();
const mtlChars dst = m.GetFirst()->GetItem();
const mtlChars src = m.GetFirst()->GetNext()->GetItem();
EmitOperand(inst, dst);
if (src.IsFloat()) {
*((int*)(&instr_item->GetItem().instr)) += 1;
}
EmitOperand(inst, src);
op = op->GetNext();
}
PopStack(inst, stack_size);
}
delete tree;
return result;
}