本文整理汇总了C++中ExpressionPtr::isScalar方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionPtr::isScalar方法的具体用法?C++ ExpressionPtr::isScalar怎么用?C++ ExpressionPtr::isScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionPtr
的用法示例。
在下文中一共展示了ExpressionPtr::isScalar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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(")");
}
示例2: preOptimize
ExpressionPtr ClassConstantExpression::preOptimize(AnalysisResultConstPtr ar) {
if (ar->getPhase() < AnalysisResult::FirstPreOptimize) {
return ExpressionPtr();
}
if (m_class) {
updateClassName();
if (m_class) {
return ExpressionPtr();
}
}
ClassScopePtr cls = resolveClass();
if (!cls || (cls->isVolatile() && !isPresent())) {
if (cls && !m_depsSet) {
cls->addUse(getScope(), BlockScope::UseKindConstRef);
m_depsSet = true;
}
return ExpressionPtr();
}
ConstantTablePtr constants = cls->getConstants();
ClassScopePtr defClass = cls;
ConstructPtr decl = constants->getValueRecur(ar, m_varName, defClass);
if (decl) {
BlockScope::s_constMutex.lock();
ExpressionPtr value = dynamic_pointer_cast<Expression>(decl);
BlockScope::s_constMutex.unlock();
if (!value->isScalar() &&
(value->is(KindOfClassConstantExpression) ||
value->is(KindOfConstantExpression))) {
std::set<ExpressionPtr> seen;
do {
if (!seen.insert(value).second) return ExpressionPtr();
value = value->preOptimize(ar);
if (!value) return ExpressionPtr();
} while (!value->isScalar() &&
(value->is(KindOfClassConstantExpression) ||
value->is(KindOfConstantExpression)));
}
ExpressionPtr rep = Clone(value, getScope());
rep->setComment(getText());
copyLocationTo(rep);
return replaceValue(rep);
}
return ExpressionPtr();
}
示例3: 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);
}
示例4: analyzeProgram
void SwitchStatement::analyzeProgram(AnalysisResultPtr ar) {
m_exp->analyzeProgram(ar);
if (m_cases) m_cases->analyzeProgram(ar);
if (ar->getPhase() == AnalysisResult::AnalyzeAll &&
m_exp->is(Expression::KindOfSimpleVariable)) {
auto exp = dynamic_pointer_cast<SimpleVariable>(m_exp);
if (exp && exp->getSymbol() && exp->getSymbol()->isClassName()) {
// Mark some classes as volatile since the name is used in switch
for (int i = 0; i < m_cases->getCount(); i++) {
auto stmt = dynamic_pointer_cast<CaseStatement>((*m_cases)[i]);
assert(stmt);
ExpressionPtr caseCond = stmt->getCondition();
if (caseCond && caseCond->isScalar()) {
auto name = dynamic_pointer_cast<ScalarExpression>(caseCond);
if (name && name->isLiteralString()) {
string className = name->getLiteralString();
ClassScopePtr cls = ar->findClass(toLower(className));
if (cls && cls->isUserClass()) {
cls->setVolatile();
}
}
}
}
// Also note this down as code error
ConstructPtr self = shared_from_this();
Compiler::Error(Compiler::ConditionalClassLoading, self);
}
}
}
示例5: optimizeArgArray
void FunctionCall::optimizeArgArray(AnalysisResultPtr ar) {
if (m_extraArg <= 0) return;
int paramCount = m_params->getOutputCount();
int iMax = paramCount - m_extraArg;
bool isScalar = true;
for (int i = iMax; i < paramCount; i++) {
ExpressionPtr param = (*m_params)[i];
if (!param->isScalar()) {
isScalar = false;
break;
}
}
if (isScalar) {
ExpressionPtr argArrayPairs =
ExpressionListPtr(new ExpressionList(getLocation(),
Expression::KindOfExpressionList));
for (int i = iMax; i < paramCount; i++) {
ExpressionPtr param = (*m_params)[i];
argArrayPairs->addElement(ArrayPairExpressionPtr(
new ArrayPairExpression(param->getLocation(),
Expression::KindOfArrayPairExpression,
ExpressionPtr(), param, false)));
}
m_argArrayId = ar->registerScalarArray(argArrayPairs);
}
}
示例6: preOptimize
ExpressionPtr AssignmentExpression::preOptimize(AnalysisResultConstPtr ar) {
if (m_variable->getContainedEffects() & ~(CreateEffect|AccessorEffect)) {
return ExpressionPtr();
}
ExpressionPtr val = m_value;
while (val) {
if (val->is(KindOfExpressionList)) {
val = static_pointer_cast<ExpressionList>(val)->listValue();
continue;
}
if (val->is(KindOfAssignmentExpression)) {
val = static_pointer_cast<AssignmentExpression>(val)->m_value;
continue;
}
break;
}
if (val && val->isScalar()) {
if (val != m_value) {
ExpressionListPtr rep(new ExpressionList(
getScope(), getRange(),
ExpressionList::ListKindWrapped));
rep->addElement(m_value);
m_value = val->clone();
rep->addElement(static_pointer_cast<Expression>(shared_from_this()));
return replaceValue(rep);
}
}
return ExpressionPtr();
}
示例7: 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;
}
示例8: 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;
}
return needed;
}
示例9: 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);
}
示例10: preOptimize
ExpressionPtr ConstantExpression::preOptimize(AnalysisResultConstPtr ar) {
if (ar->getPhase() < AnalysisResult::FirstPreOptimize) {
return ExpressionPtr();
}
ConstructPtr decl;
while (!isScalar() && !m_dynamic && !(m_context & LValue)) {
const Symbol *sym = resolveNS(ar);
if (sym &&
(!const_cast<Symbol*>(sym)->checkDefined() || sym->isDynamic())) {
sym = 0;
m_dynamic = true;
}
if (!sym) break;
if (!sym->isSystem()) BlockScope::s_constMutex.lock();
ExpressionPtr value = dynamic_pointer_cast<Expression>(sym->getValue());
if (!sym->isSystem()) BlockScope::s_constMutex.unlock();
if (!value || !value->isScalar()) {
if (!m_depsSet && sym->getDeclaration()) {
sym->getDeclaration()->getScope()->addUse(
getScope(), BlockScope::UseKindConstRef);
m_depsSet = true;
}
break;
}
Variant scalarValue;
if (value->getScalarValue(scalarValue) &&
!scalarValue.isAllowedAsConstantValue()) {
// block further optimization
const_cast<Symbol*>(sym)->setDynamic();
m_dynamic = true;
break;
}
if (sym->isSystem() && !value->is(KindOfScalarExpression)) {
if (ExpressionPtr opt = value->preOptimize(ar)) {
value = opt;
}
}
ExpressionPtr rep = Clone(value, getScope());
rep->setComment(getText());
copyLocationTo(rep);
return replaceValue(rep);
}
return ExpressionPtr();
}
示例11: getEffectiveImpl
ExpressionPtr StatementList::getEffectiveImpl(AnalysisResultConstPtr ar) const {
for (unsigned int i = 0; i < m_stmts.size(); i++) {
StatementPtr s = m_stmts[i];
if (s->is(KindOfReturnStatement)) {
ExpressionPtr e = static_pointer_cast<ReturnStatement>(s)->getRetExp();
if (!e) {
e = CONSTANT("null");
} else if (!e->isScalar()) {
break;
}
return e;
}
if (m_stmts[i]->hasImpl()) break;
}
return ExpressionPtr();
}
示例12: 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(")");
}
示例13: isDefineWithoutImpl
bool SimpleFunctionCall::isDefineWithoutImpl(AnalysisResultPtr ar) {
if (!m_className.empty()) return false;
if (m_type == DefineFunction && m_params && m_params->getCount() >= 2) {
if (m_dynamicConstant) return false;
ScalarExpressionPtr name =
dynamic_pointer_cast<ScalarExpression>((*m_params)[0]);
if (!name) return false;
string varName = name->getIdentifier();
if (varName.empty()) return false;
if (ar->getConstants()->isSystem(varName)) return true;
ExpressionPtr value = (*m_params)[1];
return (!ar->isConstantRedeclared(varName)) && value->isScalar();
} else {
return false;
}
}
示例14: outputCPPUniqLitKeyArrayInit
void ExpressionList::outputCPPUniqLitKeyArrayInit(
CodeGenerator &cg, AnalysisResultPtr ar, bool litstrKeys, int64 num,
bool arrayElements /* = true */, unsigned int start /* = 0 */) {
if (arrayElements) ASSERT(m_arrayElements);
unsigned int n = m_exps.size();
cg_printf("array_createv%c(%lld, ", litstrKeys ? 's' : 'i', num);
assert(n - start == num);
for (unsigned int i = start; i < n; i++) {
ExpressionPtr exp = m_exps[i];
assert(exp);
ExpressionPtr name;
ExpressionPtr value = exp;
if (arrayElements) {
ArrayPairExpressionPtr ap =
dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
name = ap->getName();
value = ap->getValue();
}
if (name) {
assert(litstrKeys);
cg_printf("toSPOD(");
name->outputCPP(cg, ar);
cg_printf("), ");
}
cg_printf("toVPOD(");
if (value->isScalar()) {
assert(!cg.hasScalarVariant());
cg.setScalarVariant();
if (!Option::UseScalarVariant) cg_printf("VarNR(");
value->outputCPP(cg, ar);
if (!Option::UseScalarVariant) cg_printf(")");
cg.clearScalarVariant();
} else {
bool wrap = Expression::CheckVarNR(value, Type::Variant);
if (wrap) cg_printf("VarNR(");
value->outputCPP(cg, ar);
if (wrap) cg_printf(")");
}
cg_printf(")");
if (i < n-1) {
cg_printf(", ");
} else {
cg_printf(")");
}
}
}
示例15: 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;
}