本文整理汇总了C++中ExpressionPtr::hasContext方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionPtr::hasContext方法的具体用法?C++ ExpressionPtr::hasContext怎么用?C++ ExpressionPtr::hasContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionPtr
的用法示例。
在下文中一共展示了ExpressionPtr::hasContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: outputCPPArguments
void FunctionScope::outputCPPArguments(ExpressionListPtr params,
CodeGenerator &cg,
AnalysisResultPtr ar, int extraArg,
bool variableArgument,
int extraArgArrayId /* = -1 */) {
int paramCount = params ? params->getOutputCount() : 0;
ASSERT(extraArg <= paramCount);
int iMax = paramCount - extraArg;
bool extra = false;
if (variableArgument) {
if (paramCount == 0) {
cg.printf("0");
} else {
cg.printf("%d, ", paramCount);
}
}
int firstExtra = 0;
for (int i = 0; i < paramCount; i++) {
ExpressionPtr param = (*params)[i];
cg.setItemIndex(i);
if (i > 0) cg.printf(extra ? "." : ", ");
if (!extra && (i == iMax || extraArg < 0)) {
if (extraArgArrayId != -1) {
if (cg.getOutput() == CodeGenerator::SystemCPP) {
cg.printf("SystemScalarArrays::%s[%d]",
Option::SystemScalarArrayName, extraArgArrayId);
} else {
cg.printf("ScalarArrays::%s[%d]",
Option::ScalarArrayName, extraArgArrayId);
}
break;
}
extra = true;
// Parameter arrays are always vectors.
cg.printf("Array(ArrayInit(%d, true).", paramCount - i);
firstExtra = i;
}
if (extra) {
bool needRef = param->hasContext(Expression::RefValue) &&
!param->hasContext(Expression::NoRefWrapper) &&
param->isRefable();
cg.printf("set%s(%d, ", needRef ? "Ref" : "", i - firstExtra);
if (needRef) {
// The parameter itself shouldn't be wrapped with ref() any more.
param->setContext(Expression::NoRefWrapper);
}
param->outputCPP(cg, ar);
cg.printf(")");
} else {
param->outputCPP(cg, ar);
}
}
if (extra) {
cg.printf(".create())");
}
}
示例2: markParam
void ExpressionList::markParam(int p) {
ExpressionPtr param = (*this)[p];
if (param->hasContext(Expression::InvokeArgument)) {
} else if (!param->hasContext(Expression::RefParameter)) {
param->setContext(Expression::InvokeArgument);
param->setContext(Expression::RefValue);
}
param->setArgNum(p);
}
示例3: markRefParams
void FunctionCall::markRefParams(FunctionScopePtr func,
const std::string &fooBarName) {
ExpressionList ¶ms = *m_params;
if (func) {
int mpc = func->getMaxParamCount();
for (int i = params.getCount(); i--; ) {
ExpressionPtr p = params[i];
if (i < mpc ? func->isRefParam(i) :
func->isReferenceVariableArgument()) {
p->setContext(Expression::RefValue);
} else if (i < mpc && p->hasContext(RefParameter)) {
Symbol *sym = func->getVariables()->addSymbol(func->getParamName(i));
sym->setLvalParam();
sym->setCallTimeRef();
}
}
} else if (Option::WholeProgram && !m_origName.empty()) {
FunctionScope::FunctionInfoPtr info =
FunctionScope::GetFunctionInfo(m_origName);
if (info) {
for (int i = params.getCount(); i--; ) {
if (info->isRefParam(i)) {
m_params->markParam(i);
}
}
}
// If we cannot find information of the so-named function, it might not
// exist, or it might go through __call(), either of which cannot have
// reference parameters.
} else {
for (int i = params.getCount(); i--; ) {
m_params->markParam(i);
}
}
}
示例4: markParam
void ExpressionList::markParam(int p, bool noRefWrapper) {
ExpressionPtr param = (*this)[p];
if (param->hasContext(Expression::InvokeArgument)) {
if (noRefWrapper) {
param->setContext(Expression::NoRefWrapper);
} else {
param->clearContext(Expression::NoRefWrapper);
}
} else if (!param->hasContext(Expression::RefValue)) {
param->setContext(Expression::InvokeArgument);
param->setContext(Expression::RefValue);
if (noRefWrapper) {
param->setContext(Expression::NoRefWrapper);
}
}
}
示例5: process
void DataFlowWalker::process(ExpressionPtr e, bool doAccessChains) {
if ((e->getContext() & (Expression::AssignmentLHS|Expression::OprLValue)) ||
(!doAccessChains && e->hasContext(Expression::AccessContext))) {
return;
}
switch (e->getKindOf()) {
case Expression::KindOfListAssignment:
processAccessChainLA(static_pointer_cast<ListAssignment>(e));
processAccess(e);
break;
case Expression::KindOfArrayElementExpression:
case Expression::KindOfObjectPropertyExpression:
if (!e->hasContext(Expression::AccessContext)) {
processAccessChain(e);
}
// fall through
case Expression::KindOfObjectMethodExpression:
case Expression::KindOfDynamicFunctionCall:
case Expression::KindOfSimpleFunctionCall:
case Expression::KindOfNewObjectExpression:
case Expression::KindOfIncludeExpression:
case Expression::KindOfSimpleVariable:
case Expression::KindOfDynamicVariable:
case Expression::KindOfStaticMemberExpression:
case Expression::KindOfConstantExpression:
processAccess(e);
break;
case Expression::KindOfAssignmentExpression:
case Expression::KindOfBinaryOpExpression:
case Expression::KindOfUnaryOpExpression: {
ExpressionPtr var = e->getStoreVariable();
if (var && var->getContext() & (Expression::AssignmentLHS|
Expression::OprLValue)) {
processAccessChain(var);
processAccess(var);
}
// fall through
}
default:
processAccess(e);
break;
}
}
示例6: outputCodeModel
void ExpressionList::outputCodeModel(CodeGenerator &cg) {
for (unsigned int i = 0; i < m_exps.size(); i++) {
ExpressionPtr exp = m_exps[i];
if (exp) {
cg.printExpression(exp, exp->hasContext(RefParameter));
} else {
cg.printNull();
}
}
}
示例7: getExprClass
Expression::ExprClass Expression::getExprClass() const {
assert(m_kindOf > Construct::KindOfExpression);
auto const idx = static_cast<int32_t>(m_kindOf) -
static_cast<int32_t>(Construct::KindOfExpression);
assert(idx > 0);
ExprClass cls = Classes[idx];
if (cls == Update) {
ExpressionPtr k = getStoreVariable();
if (!k || !(k->hasContext(OprLValue))) cls = Expression::None;
}
return cls;
}
示例8: outputPHP
void ExpressionList::outputPHP(CodeGenerator &cg, AnalysisResultPtr ar) {
for (unsigned int i = 0; i < m_exps.size(); i++) {
if (i > 0) cg_printf(", ");
ExpressionPtr exp = m_exps[i];
if (exp) {
if (exp->hasContext(RefParameter)) {
cg_printf("&");
}
exp->outputPHP(cg, ar);
}
}
}
示例9: hasNonArrayCreateValue
bool ExpressionList::hasNonArrayCreateValue(
bool arrayElements /* = true */, unsigned int start /* = 0 */) const {
for (unsigned int i = start; i < m_exps.size(); i++) {
ExpressionPtr value = m_exps[i];
if (arrayElements) {
ArrayPairExpressionPtr ap =
dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
value = ap->getValue();
}
ASSERT(value);
if (value->hasContext(RefValue)) {
return true;
}
}
return false;
}
示例10: checkUnpackParams
void FunctionCall::checkUnpackParams() {
if (!m_params) { return; }
ExpressionList ¶ms = *m_params;
const auto numParams = params.getCount();
// when supporting multiple unpacks at the end of the param list, this
// will need to disallow transitions from unpack to non-unpack.
for (int i = 0; i < (numParams - 1); ++i) {
ExpressionPtr p = params[i];
if (p->hasContext(Expression::UnpackParameter)) {
parseTimeFatal(
Compiler::NoError,
"Only the last parameter in a function call is allowed to use ...");
}
}
}
示例11: cloneStmtsForInline
static int cloneStmtsForInline(InlineCloneInfo &info, StatementPtr s,
const std::string &prefix,
AnalysisResultConstPtr ar,
FunctionScopePtr scope) {
switch (s->getKindOf()) {
case Statement::KindOfStatementList:
{
for (int i = 0, n = s->getKidCount(); i < n; ++i) {
if (int ret = cloneStmtsForInline(info, s->getNthStmt(i),
prefix, ar, scope)) {
return ret;
}
}
return 0;
}
case Statement::KindOfExpStatement:
info.elist->addElement(cloneForInline(
info, dynamic_pointer_cast<ExpStatement>(s)->
getExpression(), prefix, ar, scope));
return 0;
case Statement::KindOfReturnStatement:
{
ExpressionPtr exp =
dynamic_pointer_cast<ReturnStatement>(s)->getRetExp();
if (exp) {
exp = cloneForInline(info, exp, prefix, ar, scope);
if (exp->hasContext(Expression::RefValue)) {
exp->clearContext(Expression::RefValue);
if (exp->isRefable()) exp->setContext(Expression::LValue);
}
info.elist->addElement(exp);
return 1;
}
return -1;
}
default:
not_reached();
}
return 1;
}
示例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: inliner
//.........这里部分代码省略.........
obj->getLocation(),
var, obj, false));
info.elist->addElement(ae);
info.sepm[var->getName()] = var;
info.localThis = var->getName();
}
} else {
if (m_classScope) {
if (!m_funcScope->isStatic()) {
ClassScopeRawPtr oCls = getOriginalClass();
FunctionScopeRawPtr oFunc = getOriginalFunction();
if (oCls && !oFunc->isStatic() &&
(oCls == m_classScope ||
oCls->derivesFrom(ar, m_className, true, false))) {
info.callWithThis = true;
info.localThis = localThis;
}
}
if (!isSelf() && !isParent() && !isStatic()) {
info.staticClass = m_className;
}
}
}
ExpressionListPtr plist = m->getParams();
int i;
for (i = 0; i < nMax || i < nAct; i++) {
ParameterExpressionPtr param
(i < nMax ?
dynamic_pointer_cast<ParameterExpression>((*plist)[i]) :
ParameterExpressionPtr());
ExpressionPtr arg = i < nAct ? (*m_params)[i] :
Clone(param->defaultValue(), getScope());
SimpleVariablePtr var
(new SimpleVariable(getScope(),
(i < nAct ? arg.get() : this)->getLocation(),
prefix + (param ?
param->getName() :
lexical_cast<string>(i))));
var->updateSymbol(SimpleVariablePtr());
var->getSymbol()->setHidden();
var->getSymbol()->setUsed();
var->getSymbol()->setReferenced();
bool ref =
(i < nMax && m_funcScope->isRefParam(i)) ||
arg->hasContext(RefParameter);
arg->clearContext(RefParameter);
AssignmentExpressionPtr ae
(new AssignmentExpression(getScope(),
arg->getLocation(),
var, arg, ref));
info.elist->addElement(ae);
if (i < nAct && (ref || !arg->isScalar())) {
info.sepm[var->getName()] = var;
}
}
if (cloneStmtsForInline(info, m->getStmts(), prefix, ar,
getFunctionScope()) <= 0) {
info.elist->addElement(makeConstant(ar, "null"));
}
if (info.sepm.size()) {
ExpressionListPtr unset_list
(new ExpressionList(getScope(), getLocation()));
for (StringToExpressionPtrMap::iterator it = info.sepm.begin(),
end = info.sepm.end(); it != end; ++it) {
ExpressionPtr var = it->second->clone();
var->clearContext((Context)(unsigned)-1);
unset_list->addElement(var);
}
ExpressionPtr unset(
new UnaryOpExpression(getScope(), getLocation(),
unset_list, T_UNSET, true));
i = info.elist->getCount();
ExpressionPtr ret = (*info.elist)[--i];
if (ret->isScalar()) {
info.elist->insertElement(unset, i);
} else {
ExpressionListPtr result_list
(new ExpressionList(getScope(), getLocation(),
ExpressionList::ListKindLeft));
if (ret->hasContext(LValue)) {
result_list->setContext(LValue);
result_list->setContext(ReturnContext);
}
result_list->addElement(ret);
result_list->addElement(unset);
(*info.elist)[i] = result_list;
}
}
recomputeEffects();
return replaceValue(info.elist);
}
示例14: inferParamTypes
int FunctionScope::inferParamTypes(AnalysisResultPtr ar, ConstructPtr exp,
ExpressionListPtr params, bool &valid) {
if (!params) {
if (m_minParam > 0) {
if (exp->getScope()->isFirstPass()) {
Compiler::Error(Compiler::TooFewArgument, exp, m_stmt);
}
valid = false;
if (!Option::AllDynamic) setDynamic();
}
return 0;
}
int ret = 0;
if (params->getCount() < m_minParam) {
if (exp->getScope()->isFirstPass()) {
Compiler::Error(Compiler::TooFewArgument, exp, m_stmt);
}
valid = false;
if (!Option::AllDynamic) setDynamic();
}
if (params->getCount() > m_maxParam) {
if (isVariableArgument()) {
ret = params->getCount() - m_maxParam;
} else {
if (exp->getScope()->isFirstPass()) {
Compiler::Error(Compiler::TooManyArgument, exp, m_stmt);
}
valid = false;
if (!Option::AllDynamic) setDynamic();
}
}
bool canSetParamType = isUserFunction() && !m_overriding && !m_perfectVirtual;
for (int i = 0; i < params->getCount(); i++) {
ExpressionPtr param = (*params)[i];
if (i < m_maxParam && param->hasContext(Expression::RefParameter)) {
/**
* This should be very un-likely, since call time pass by ref is a
* deprecated, not very widely used (at least in FB codebase) feature.
*/
TRY_LOCK_THIS();
Symbol *sym = getVariables()->addSymbol(m_paramNames[i]);
sym->setLvalParam();
sym->setCallTimeRef();
}
if (valid && param->hasContext(Expression::InvokeArgument)) {
param->clearContext(Expression::InvokeArgument);
param->clearContext(Expression::RefValue);
param->clearContext(Expression::NoRefWrapper);
}
bool isRefVararg = (i >= m_maxParam && isReferenceVariableArgument());
if ((i < m_maxParam && isRefParam(i)) || isRefVararg) {
param->setContext(Expression::LValue);
param->setContext(Expression::RefValue);
param->inferAndCheck(ar, Type::Variant, true);
} else if (!(param->getContext() & Expression::RefParameter)) {
param->clearContext(Expression::LValue);
param->clearContext(Expression::RefValue);
param->clearContext(Expression::InvokeArgument);
param->clearContext(Expression::NoRefWrapper);
}
TypePtr expType;
/**
* Duplicate the logic of getParamType(i), w/o the mutation
*/
TypePtr paramType(i < m_maxParam && !isZendParamMode() ?
m_paramTypes[i] : TypePtr());
if (!paramType) paramType = Type::Some;
if (valid && !canSetParamType && i < m_maxParam &&
(!Option::HardTypeHints || !m_paramTypeSpecs[i])) {
/**
* What is this magic, you might ask?
*
* Here, we take advantage of implicit conversion from every type to
* Variant. Essentially, we don't really care what type comes out of this
* expression since it'll just get converted anyways. Doing it this way
* allows us to generate less temporaries along the way.
*/
TypePtr optParamType(paramType->is(Type::KindOfVariant) ?
Type::Some : paramType);
expType = param->inferAndCheck(ar, optParamType, false);
} else {
expType = param->inferAndCheck(ar, Type::Some, false);
}
if (i < m_maxParam) {
if (!Option::HardTypeHints || !m_paramTypeSpecs[i]) {
if (canSetParamType) {
if (!Type::SameType(paramType, expType) &&
!paramType->is(Type::KindOfVariant)) {
TRY_LOCK_THIS();
paramType = setParamType(ar, i, expType);
} else {
// do nothing - how is this safe? well, if we ever observe
// paramType == expType, then this means at some point in the past,
// somebody called setParamType() with expType. thus, by calling
// setParamType() again with expType, we contribute no "new"
// information. this argument also still applies in the face of
// concurrency
}
//.........这里部分代码省略.........
示例15: updateAccess
void ExprDict::updateAccess(ExpressionPtr e) {
int cls = e->getExprClass();
int eid = e->getCanonID();
e->clearAnticipated();
e->clearAvailable();
// bail on non-canonical expressions
if (!isCanonicalStructure(eid)) {
// but record we saw a type assertion belonging to this block
m_avlTypeAsserts.push_back(eid);
return;
}
if (m_anticipated &&
(cls & Expression::Update ?
!BitOps::get_bit(eid, m_altered) : !e->getLocalEffects())) {
/*
Anticipated can be computed bottom up as we go. But note that we
only know altered for Load/Store expressions.
*/
int i = e->getKidCount();
while (true) {
if (!i--) {
e->setAnticipated();
if (!e->hasContext(Expression::AssignmentLHS)) {
setStructureOps(eid, m_anticipated, true);
}
break;
}
if (ExpressionPtr k = e->getNthExpr(i)) {
if (!isCanonicalStructure(k->getCanonID())) continue;
if (!k->isAnticipated()) {
break;
}
}
}
}
if (m_available) {
/*
Available has to be computed optimistically, because we dont yet
know what is going to be altered between here and the end of the block
So keep a list of the potentially-available accesses (avlAccess), and
for each id, the last potentially-available expression (avlExpr).
For each modifying expression that we process, we remove expressions
from avlAccess, and at the end, we build up the available expressions
bottom up.
*/
if ((cls & (Expression::Store|Expression::Call)) ||
(cls & Expression::Load &&
e->getContext() & (Expression::LValue|
Expression::RefValue|
Expression::UnsetContext|
Expression::DeepReference))) {
bool isLoad;
int depth = 0, effects = 0;
for (int i = 0, n = m_avlAccess.size(); i < n; ) {
ExpressionRawPtr a = m_avlAccess[i];
if (m_am.checkAnyInterf(e, a, isLoad, depth, effects) !=
AliasManager::DisjointAccess) {
int aid = a->getCanonID();
assert(isCanonicalStructure(aid));
if (eid != aid || cls == Expression::Load) {
BitOps::set_bit(aid, m_altered, true);
}
if (!(cls & Expression::Store) ||
a != e->getStoreVariable()) {
a->clearAvailable();
m_avlAccess[i] = m_avlAccess[--n];
m_avlAccess.resize(n);
continue;
}
}
i++;
}
}
if (cls & Expression::Update ||
!e->getContainedEffects()) {
int i = e->getKidCount();
while (true) {
if (!i--) {
e->setAvailable();
if (cls & Expression::Update) {
m_avlAccess.push_back(e);
}
m_avlExpr[eid] = e;
break;
}
if (ExpressionPtr k = e->getNthExpr(i)) {
if (!isCanonicalStructure(k->getCanonID())) continue;
if (!k->isAvailable()) {
break;
}
}
}
}
}
if ((cls & (Expression::Store|Expression::Call)) ||
(cls & Expression::Load &&
//.........这里部分代码省略.........