本文整理汇总了C++中Tokens::getOperatorMethodName方法的典型用法代码示例。如果您正苦于以下问题:C++ Tokens::getOperatorMethodName方法的具体用法?C++ Tokens::getOperatorMethodName怎么用?C++ Tokens::getOperatorMethodName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokens
的用法示例。
在下文中一共展示了Tokens::getOperatorMethodName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
// TODO: Unify this with the JIT bc generator binary expressions
// https://theengineco.atlassian.net/browse/LOOM-640
// https://theengineco.atlassian.net/browse/LOOM-641
Expression *TypeCompiler::visit(BinaryOperatorExpression *expression)
{
Tokens *tok = Tokens::getSingletonPtr();
Expression *eleft = expression->leftExpression;
Expression *eright = expression->rightExpression;
// operator overloads
lmAssert(eleft->type && eright->type, "Untyped binary expression");
const char *opmethod = tok->getOperatorMethodName(expression->op);
if (opmethod)
{
MemberInfo *mi = eleft->type->findMember(opmethod);
if (mi)
{
lmAssert(mi->isMethod(), "Non-method operator");
MethodInfo *method = (MethodInfo *)mi;
lmAssert(method->isOperator(), "Non-operator method");
utArray<Expression *> args;
args.push_back(eleft);
args.push_back(eright);
ExpDesc opcall;
ExpDesc emethod;
BC::singleVar(cs, &opcall, eleft->type->getName());
BC::expString(cs, &emethod, method->getName());
BC::expToNextReg(cs->fs, &opcall);
BC::expToNextReg(cs->fs, &emethod);
BC::expToVal(cs->fs, &emethod);
BC::indexed(cs->fs, &opcall, &emethod);
generateCall(&opcall, &args, method);
expression->e = opcall;
return expression;
}
}
// dynamic cast
if ((expression->op == &tok->KEYWORD_IS) ||
(expression->op == &tok->KEYWORD_INSTANCEOF) ||
(expression->op == &tok->KEYWORD_AS))
{
lmAssert(eleft->type && eright->type, "Untype expression");
FuncState *fs = cs->fs;
ExpDesc object;
BC::singleVar(cs, &object, "Object");
ExpDesc method;
if (expression->op == &tok->KEYWORD_IS)
{
BC::expString(cs, &method, "_is");
}
else if (expression->op == &tok->KEYWORD_AS)
{
BC::expString(cs, &method, "_as");
}
else
{
BC::expString(cs, &method, "_instanceof");
}
BC::expToNextReg(fs, &object);
BC::expToNextReg(fs, &method);
BC::expToVal(fs, &method);
BC::indexed(fs, &object, &method);
utArray<Expression *> args;
args.push_back(eleft);
args.push_back(new StringLiteral(eright->type->getAssembly()->getName().c_str()));
args.push_back(new NumberLiteral(eright->type->getTypeID()));
generateCall(&object, &args);
expression->e = object;
return expression;
}
BinOpr op = getbinopr(expression->op);
if (op == OPR_LOOM_ADD)
{
lmAssert(eleft->type && eright->type, "Untyped add operaton %i",
lineNumber);
int ncheck = 0;
if (eleft->type->isEnum() || (eleft->type->getFullName() == "system.Number"))
{
ncheck++;
//.........这里部分代码省略.........
示例2: getassignmentopr
Expression *TypeCompiler::visit(AssignmentOperatorExpression *expression)
{
Tokens *tok = Tokens::getSingletonPtr();
BinOpr op = getassignmentopr(expression->type);
lmAssert(op != OPR_NOBINOPR, "Unknown bin op on AssignentOperatorExpression");
Expression *eleft = expression->leftExpression;
Expression *eright = expression->rightExpression;
lmAssert(eleft->type, "Untyped error on left expression");
const char *opmethod = tok->getOperatorMethodName(expression->type);
if (opmethod)
{
MemberInfo *mi = eleft->type->findMember(opmethod);
if (mi)
{
lmAssert(mi->isMethod(), "Non-method operator");
MethodInfo *method = (MethodInfo *)mi;
lmAssert(method->isOperator(), "Non-operator method");
utArray<Expression *> args;
args.push_back(eright);
ExpDesc opcall;
ExpDesc emethod;
eleft->visitExpression(this);
opcall = eleft->e;
BC::initExpDesc(&emethod, VKNUM, 0);
emethod.u.nval = method->getOrdinal();
BC::expToNextReg(cs->fs, &opcall);
BC::expToNextReg(cs->fs, &emethod);
BC::expToVal(cs->fs, &emethod);
BC::indexed(cs->fs, &opcall, &emethod);
generateCall(&opcall, &args, method);
expression->e = opcall;
return expression;
}
}
eleft->assignment = false;
eleft->visitExpression(this);
BC::infix(cs->fs, op, &eleft->e);
eright->visitExpression(this);
BC::expToNextReg(cs->fs, &eright->e);
BC::posFix(cs->fs, op, &eleft->e, &eright->e);
ExpDesc right = eleft->e;
BC::expToNextReg(cs->fs, &right);
memset(&eleft->e, 0, sizeof(ExpDesc));
eleft->assignment = true;
eleft->visitExpression(this);
ExpDesc left = eleft->e;
if (eleft->memberInfo && eleft->memberInfo->isProperty())
{
eright->e = right;
generatePropertySet(&eleft->e, eright, false);
}
else
{
BC::storeVar(cs->fs, &left, &right);
}
return expression;
}