本文整理汇总了C++中ExpressionPtr::getActualType方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionPtr::getActualType方法的具体用法?C++ ExpressionPtr::getActualType怎么用?C++ ExpressionPtr::getActualType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionPtr
的用法示例。
在下文中一共展示了ExpressionPtr::getActualType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: preOutputCPP
bool AssignmentExpression::preOutputCPP(CodeGenerator &cg, AnalysisResultPtr ar,
int state) {
if (m_variable->is(Expression::KindOfArrayElementExpression)) {
ExpressionPtr exp = m_value;
ExpressionPtr vv(
static_pointer_cast<ArrayElementExpression>(m_variable)->getVariable());
if ((vv->is(KindOfArrayElementExpression) ||
vv->is(KindOfObjectPropertyExpression)) &&
(vv->getContainedEffects() && (CreateEffect|AccessorEffect))) {
/*
We are in a case such as
$a->b['c'] = ...;
$a['b']['c'] = ...;
Where evaluating m_variable may modify $a. Unless we can prove that
the rhs is not referring to the same thing as $a, we must generate
a temporary for it (note that we could do better with the following
checks).
*/
if (!(m_ref && exp->isRefable()) &&
!exp->isTemporary() && !exp->isScalar() &&
exp->getActualType() && !exp->getActualType()->isPrimitive() &&
exp->getActualType()->getKindOf() != Type::KindOfString) {
state |= Expression::StashAll;
}
}
}
return Expression::preOutputCPP(cg, ar, state);
}
示例2: wrapValue
static void wrapValue(CodeGenerator &cg, AnalysisResultPtr ar,
ExpressionPtr exp, bool ref, bool array, bool varnr) {
bool close = false;
if (ref) {
cg_printf("ref(");
close = true;
} else if (array && !exp->hasCPPTemp() &&
!exp->isTemporary() && !exp->isScalar() &&
exp->getActualType() && !exp->getActualType()->isPrimitive() &&
exp->getActualType()->getKindOf() != Type::KindOfString) {
cg_printf("wrap_variant(");
close = true;
} else if (varnr && exp->getCPPType()->isExactType()) {
bool isScalar = exp->isScalar();
if (!isScalar || !Option::UseScalarVariant) {
cg_printf("VarNR(");
close = true;
} else if (isScalar) {
ASSERT(!cg.hasScalarVariant());
cg.setScalarVariant();
}
}
exp->outputCPP(cg, ar);
cg.clearScalarVariant();
if (close) cg_printf(")");
}
示例3: preOutputCPP
bool AssignmentExpression::preOutputCPP(CodeGenerator &cg, AnalysisResultPtr ar,
int state) {
if (m_variable->is(Expression::KindOfArrayElementExpression)) {
ExpressionPtr exp = m_value;
if (!(m_ref && exp->isRefable()) &&
!exp->isTemporary() && !exp->isScalar() &&
exp->getActualType() && !exp->getActualType()->isPrimitive() &&
exp->getActualType()->getKindOf() != Type::KindOfString) {
state |= Expression::StashAll;
}
}
return Expression::preOutputCPP(cg, ar, state);
}
示例4: getConcatList
int BinaryOpExpression::getConcatList(ExpressionPtrVec &ev, ExpressionPtr exp,
bool &hasVoid) {
if (!exp->hasCPPTemp()) {
if (exp->is(Expression::KindOfUnaryOpExpression)) {
UnaryOpExpressionPtr u = static_pointer_cast<UnaryOpExpression>(exp);
if (u->getOp() == '(') {
return getConcatList(ev, u->getExpression(), hasVoid);
}
} else if (exp->is(Expression::KindOfBinaryOpExpression)) {
BinaryOpExpressionPtr b = static_pointer_cast<BinaryOpExpression>(exp);
if (b->getOp() == '.') {
if (b->getExp1()->is(Expression::KindOfSimpleVariable) &&
b->getExp1()->isLocalExprAltered() &&
!b->getExp1()->hasCPPTemp() &&
b->getExp2()->hasEffect() &&
!b->getExp2()->hasCPPTemp()) {
/*
In this case, the simple variable must be evaluated
after b->getExp2(). But when we output a concat list we
explicitly order the expressions from left to right.
*/
} else {
return getConcatList(ev, b->getExp1(), hasVoid) +
getConcatList(ev, b->getExp2(), hasVoid);
}
}
} else if (exp->is(Expression::KindOfEncapsListExpression)) {
EncapsListExpressionPtr e =
static_pointer_cast<EncapsListExpression>(exp);
if (e->getType() != '`') {
ExpressionListPtr el = e->getExpressions();
int num = 0;
for (int i = 0, s = el->getCount(); i < s; i++) {
ExpressionPtr exp = (*el)[i];
num += getConcatList(ev, exp, hasVoid);
}
return num;
}
}
} else if (!exp->getActualType()) {
return 0;
}
ev.push_back(exp);
bool isVoid = !exp->getActualType();
hasVoid |= isVoid;
return isVoid ? 0 : 1;
}
示例5: getConcatList
int BinaryOpExpression::getConcatList(ExpressionPtrVec &ev, ExpressionPtr exp,
bool &hasVoid) {
if (!exp->hasCPPTemp()) {
if (exp->is(Expression::KindOfUnaryOpExpression)) {
UnaryOpExpressionPtr u = static_pointer_cast<UnaryOpExpression>(exp);
if (u->getOp() == '(') {
return getConcatList(ev, u->getExpression(), hasVoid);
}
} else if (exp->is(Expression::KindOfBinaryOpExpression)) {
BinaryOpExpressionPtr b = static_pointer_cast<BinaryOpExpression>(exp);
if (b->getOp() == '.') {
return getConcatList(ev, b->getExp1(), hasVoid) +
getConcatList(ev, b->getExp2(), hasVoid);
}
} else if (exp->is(Expression::KindOfEncapsListExpression)) {
EncapsListExpressionPtr e =
static_pointer_cast<EncapsListExpression>(exp);
if (e->getType() != '`') {
ExpressionListPtr el = e->getExpressions();
int num = 0;
for (int i = 0, s = el->getCount(); i < s; i++) {
ExpressionPtr exp = (*el)[i];
num += getConcatList(ev, exp, hasVoid);
}
return num;
}
}
}
ev.push_back(exp);
bool isVoid = !exp->getActualType();
hasVoid |= isVoid;
return isVoid ? 0 : 1;
}
示例6: wrapValue
static void wrapValue(CodeGenerator &cg, AnalysisResultPtr ar,
ExpressionPtr exp, bool ref, bool array) {
bool close = false;
if (ref) {
cg_printf("ref(");
close = true;
} else if (array && !exp->hasCPPTemp() &&
!exp->isTemporary() && !exp->isScalar() &&
exp->getActualType() && !exp->getActualType()->isPrimitive() &&
exp->getActualType()->getKindOf() != Type::KindOfString) {
cg_printf("wrap_variant(");
close = true;
}
exp->outputCPP(cg, ar);
if (close) cg_printf(")");
}
示例7: outputCPPImpl
void QOpExpression::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
if (!m_cppValue.empty()) {
cg_printf("%s", m_cppValue.c_str());
} else {
ExpressionPtr expYes = m_expYes ? m_expYes : m_condition;
bool wrapped = !isUnused();
if (wrapped) {
cg_printf("(");
}
wrapBoolean(cg, ar, m_condition);
if (isUnused()) {
cg_printf(" ? ");
outputUnneededExpr(cg, ar, expYes);
cg_printf(" : ");
outputUnneededExpr(cg, ar, m_expNo);
} else {
TypePtr typeYes = expYes->getActualType();
TypePtr typeNo = m_expNo->getActualType();
const char *castType =
typeYes && typeNo && Type::SameType(typeYes, typeNo) &&
!typeYes->is(Type::KindOfVariant) &&
expYes->isLiteralString() == m_expNo->isLiteralString()
? "" : "(Variant)";
cg_printf(" ? (%s(", castType);
expYes->outputCPP(cg, ar);
cg_printf(")) : (%s(", castType);
m_expNo->outputCPP(cg, ar);
cg_printf("))");
}
if (wrapped) {
cg_printf(")");
}
}
}
示例8: ExpressionPtr
TypePtr AssignmentExpression::
inferTypesImpl(AnalysisResultPtr ar, TypePtr type, bool coerce,
ExpressionPtr variable,
ExpressionPtr value /* = ExpressionPtr() */) {
TypePtr ret = type;
if (value) {
if (coerce) {
ret = value->inferAndCheck(ar, type, coerce);
} else {
ret = value->inferAndCheck(ar, NEW_TYPE(Some), coerce);
}
}
BlockScopePtr scope = ar->getScope();
if (variable->is(Expression::KindOfConstantExpression)) {
// ...as in ClassConstant statement
ConstantExpressionPtr exp =
dynamic_pointer_cast<ConstantExpression>(variable);
bool p;
scope->getConstants()->check(exp->getName(), ret, true, ar, variable, p);
} else if (variable->is(Expression::KindOfDynamicVariable)) {
// simptodo: not too sure about this
ar->getFileScope()->setAttribute(FileScope::ContainsLDynamicVariable);
} else if (variable->is(Expression::KindOfSimpleVariable)) {
SimpleVariablePtr var = dynamic_pointer_cast<SimpleVariable>(variable);
if (var->getName() == "this" && ar->getClassScope()) {
if (ar->isFirstPass()) {
ar->getCodeError()->record(variable, CodeError::ReassignThis,
variable);
}
}
if (ar->getPhase() == AnalysisResult::LastInference && value) {
if (!value->getExpectedType()) {
value->setExpectedType(variable->getActualType());
}
}
}
// if the value may involve object, consider the variable as "referenced"
// so that objects are not destructed prematurely.
bool referenced = true;
if (value && value->isScalar()) referenced = false;
if (ret && ret->isNoObjectInvolved()) referenced = false;
if (referenced && variable->is(Expression::KindOfSimpleVariable)) {
SimpleVariablePtr var =
dynamic_pointer_cast<SimpleVariable>(variable);
const std::string &name = var->getName();
VariableTablePtr variables = ar->getScope()->getVariables();
variables->addReferenced(name);
}
TypePtr vt = variable->inferAndCheck(ar, ret, true);
if (!coerce && type->is(Type::KindOfAny)) {
ret = vt;
}
return ret;
}
示例9: CheckNeededRHS
bool Expression::CheckNeededRHS(ExpressionPtr value) {
bool needed = true;
always_assert(value);
while (value->is(KindOfAssignmentExpression)) {
value = dynamic_pointer_cast<AssignmentExpression>(value)->getValue();
}
if (value->isScalar()) {
needed = false;
} else {
TypePtr type = value->getType();
if (type && (type->is(Type::KindOfSome) || type->is(Type::KindOfAny))) {
type = value->getActualType();
}
if (type && type->isNoObjectInvolved()) needed = false;
}
return needed;
}
示例10: SetExpTypeForExistsContext
void UnaryOpExpression::SetExpTypeForExistsContext(AnalysisResultPtr ar,
ExpressionPtr e,
bool allowPrimitives) {
if (!e) return;
TypePtr at(e->getActualType());
if (!allowPrimitives && at &&
at->isExactType() && at->isPrimitive()) {
at = e->inferAndCheck(ar, Type::Variant, true);
}
TypePtr it(e->getImplementedType());
TypePtr et(e->getExpectedType());
if (et && et->is(Type::KindOfVoid)) e->setExpectedType(TypePtr());
if (at && (!it || Type::IsMappedToVariant(it)) &&
((allowPrimitives && Type::HasFastCastMethod(at)) ||
(!allowPrimitives &&
(at->is(Type::KindOfObject) ||
at->is(Type::KindOfArray) ||
at->is(Type::KindOfString))))) {
e->setExpectedType(it ? at : TypePtr());
}
}
示例11: checkCopyElision
static bool checkCopyElision(FunctionScopePtr func, ExpressionPtr exp) {
if (!exp->getType()->is(Type::KindOfVariant) || func->isRefReturn()) {
return false;
}
TypePtr imp = exp->getImplementedType();
if (!imp) imp = exp->getActualType();
if (!imp || !imp->is(Type::KindOfVariant)) return false;
if (func->getNRVOFix() && exp->is(Expression::KindOfSimpleVariable)) {
return true;
}
if (FunctionCallPtr fc = dynamic_pointer_cast<FunctionCall>(exp)) {
FunctionScopePtr fs = fc->getFuncScope();
if (!fs || fs->isRefReturn()) {
return true;
}
}
return false;
}
示例12: outputStringExpr
static void outputStringExpr(CodeGenerator &cg, AnalysisResultPtr ar,
ExpressionPtr exp, bool asLitStr) {
if (asLitStr && exp->isLiteralString()) {
const std::string &s = exp->getLiteralString();
char *enc = string_cplus_escape(s.c_str(), s.size());
cg_printf("\"%s\", %d", enc, s.size());
free(enc);
return;
}
bool close = false;
if ((exp->hasContext(Expression::LValue) &&
(!exp->getActualType()->is(Type::KindOfString) ||
(exp->getImplementedType() &&
!exp->getImplementedType()->is(Type::KindOfString))))
||
!exp->getType()->is(Type::KindOfString)) {
cg_printf("toString(");
close = true;
}
exp->outputCPP(cg, ar);
if (close) cg_printf(")");
}
示例13: outputCPPImpl
//.........这里部分代码省略.........
case '>':
cg_printf("more");
break;
case T_IS_GREATER_OR_EQUAL:
cg_printf("not_less");
break;
case '/':
cg_printf("divide");
break;
case '%':
cg_printf("modulo");
break;
case T_INSTANCEOF:
cg_printf("instanceOf");
break;
default:
wrapped = !isUnused();
break;
}
if (wrapped) cg_printf("(");
ExpressionPtr first = m_exp1;
ExpressionPtr second = m_exp2;
// we could implement these functions natively on String and Array classes
switch (m_op) {
case '+':
case '-':
case '*':
case '/':
if (!first->outputCPPArithArg(cg, ar, m_op == '+')) {
TypePtr argType = first->hasCPPTemp() ?
first->getType() : first->getActualType();
bool flag = castIfNeeded(getActualType(), argType, cg, ar, getScope());
first->outputCPP(cg, ar);
if (flag) {
cg_printf(")");
}
}
break;
case T_SL:
case T_SR:
ASSERT(first->getType()->is(Type::KindOfInt64));
first->outputCPP(cg, ar);
break;
default:
first->outputCPP(cg, ar);
break;
}
switch (m_op) {
case T_PLUS_EQUAL:
cg_printf(" += ");
break;
case T_MINUS_EQUAL:
cg_printf(" -= ");
break;
case T_MUL_EQUAL:
cg_printf(" *= ");
break;
case T_DIV_EQUAL:
cg_printf(" /= ");
break;
case T_MOD_EQUAL:
cg_printf(" %%= ");
示例14: outputCPPImpl
void BinaryOpExpression::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
if (isOpEqual() && outputCPPImplOpEqual(cg, ar)) return;
bool wrapped = true;
switch (m_op) {
case T_CONCAT_EQUAL:
if (const char *prefix = stringBufferPrefix(cg, ar, m_exp1)) {
SimpleVariablePtr sv = static_pointer_cast<SimpleVariable>(m_exp1);
ExpressionPtrVec ev;
bool hasVoid = false;
getConcatList(ev, m_exp2, hasVoid);
cg_printf("%s", stringBufferName(Option::TempPrefix, prefix,
sv->getName().c_str()).c_str());
outputStringBufExprs(ev, cg, ar);
return;
}
cg_printf("concat_assign");
break;
case '.':
{
ExpressionPtr self = static_pointer_cast<Expression>(shared_from_this());
ExpressionPtrVec ev;
bool hasVoid = false;
int num = getConcatList(ev, self, hasVoid);
assert(!hasVoid);
if ((num <= MAX_CONCAT_ARGS ||
(Option::GenConcat &&
cg.getOutput() != CodeGenerator::SystemCPP))) {
assert(num >= 2);
if (num == 2) {
cg_printf("concat(");
} else {
if (num > MAX_CONCAT_ARGS) ar->m_concatLengths.insert(num);
cg_printf("concat%d(", num);
}
for (size_t i = 0; i < ev.size(); i++) {
ExpressionPtr exp = ev[i];
if (i) cg_printf(", ");
outputStringExpr(cg, ar, exp, false);
}
cg_printf(")");
} else {
cg_printf("StringBuffer()");
outputStringBufExprs(ev, cg, ar);
cg_printf(".detach()");
}
}
return;
case T_LOGICAL_XOR: cg_printf("logical_xor"); break;
case '|': cg_printf("bitwise_or"); break;
case '&': cg_printf("bitwise_and"); break;
case '^': cg_printf("bitwise_xor"); break;
case T_IS_IDENTICAL: cg_printf("same"); break;
case T_IS_NOT_IDENTICAL: cg_printf("!same"); break;
case T_IS_EQUAL: cg_printf("equal"); break;
case T_IS_NOT_EQUAL: cg_printf("!equal"); break;
case '<': cg_printf("less"); break;
case T_IS_SMALLER_OR_EQUAL: cg_printf("not_more"); break;
case '>': cg_printf("more"); break;
case T_IS_GREATER_OR_EQUAL: cg_printf("not_less"); break;
case '/': cg_printf("divide"); break;
case '%': cg_printf("modulo"); break;
case T_INSTANCEOF: cg_printf("instanceOf"); break;
default:
wrapped = !isUnused();
break;
}
if (wrapped) cg_printf("(");
ExpressionPtr first = m_exp1;
ExpressionPtr second = m_exp2;
// we could implement these functions natively on String and Array classes
switch (m_op) {
case '+':
case '-':
case '*':
case '/': {
TypePtr actualType = first->getActualType();
if (actualType &&
(actualType->is(Type::KindOfString) ||
(m_op != '+' && actualType->is(Type::KindOfArray)))) {
cg_printf("(Variant)(");
first->outputCPP(cg, ar);
cg_printf(")");
} else {
bool flag = castIfNeeded(getActualType(), actualType, cg, ar, getScope());
first->outputCPP(cg, ar);
if (flag) {
cg_printf(")");
}
}
break;
}
case T_SL:
case T_SR:
//.........这里部分代码省略.........
示例15: Dump
void Type::Dump(ExpressionPtr exp) {
Dump(exp->getExpectedType(), "Expected: %s\t");
Dump(exp->getActualType(), "Actual: %s\n");
}