本文整理汇总了C++中ExpressionPtr::getScope方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionPtr::getScope方法的具体用法?C++ ExpressionPtr::getScope怎么用?C++ ExpressionPtr::getScope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionPtr
的用法示例。
在下文中一共展示了ExpressionPtr::getScope方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeIsNull
static ExpressionPtr makeIsNull(AnalysisResultConstPtr ar,
LocationPtr loc, ExpressionPtr exp,
bool invert) {
/* Replace "$x === null" with an is_null call; this requires slightly
* less work at runtime. */
ExpressionListPtr expList =
ExpressionListPtr(new ExpressionList(exp->getScope(), loc));
expList->insertElement(exp);
SimpleFunctionCallPtr call
(new SimpleFunctionCall(exp->getScope(), loc,
"is_null", false, expList, ExpressionPtr()));
call->setValid();
call->setActualType(Type::Boolean);
call->setupScopes(ar);
ExpressionPtr result(call);
if (invert) {
result = ExpressionPtr(new UnaryOpExpression(
exp->getScope(), loc,
result, '!', true));
}
return result;
}
示例2: replaceValue
ExpressionPtr Expression::replaceValue(ExpressionPtr rep) {
if (hasContext(Expression::RefValue) &&
isRefable(true) && !rep->isRefable(true)) {
/*
An assignment isRefable, but the rhs may not be. Need this to
prevent "bad pass by reference" errors.
*/
ExpressionListPtr el(new ExpressionList(getScope(), getRange(),
ExpressionList::ListKindWrapped));
el->addElement(rep);
rep->clearContext(AssignmentRHS);
rep = el;
}
if (rep->is(KindOfSimpleVariable) && !is(KindOfSimpleVariable)) {
static_pointer_cast<SimpleVariable>(rep)->setAlwaysStash();
}
rep->copyContext(m_context & ~(DeadStore|AccessContext));
if (TypePtr t1 = getType()) {
if (TypePtr t2 = rep->getType()) {
if (!Type::SameType(t1, t2)) {
rep->setExpectedType(t1);
}
}
}
if (rep->getScope() != getScope()) {
rep->resetScope(getScope());
}
return rep;
}
示例3: replaceValue
ExpressionPtr Expression::replaceValue(ExpressionPtr rep, bool noWarn) {
if (hasContext(Expression::RefValue) &&
isRefable(true) && !rep->isRefable(true)) {
/*
An assignment isRefable, but the rhs may not be. Need this to
prevent "bad pass by reference" errors.
*/
auto el = std::make_shared<ExpressionList>(
getScope(), getRange(), noWarn ?
ExpressionList::ListKindWrappedNoWarn : ExpressionList::ListKindWrapped);
el->addElement(rep);
rep->clearContext(AssignmentRHS);
rep = el;
}
if (rep->is(KindOfSimpleVariable) && !is(KindOfSimpleVariable)) {
static_pointer_cast<SimpleVariable>(rep)->setAlwaysStash();
}
rep->copyContext(m_context & ~(DeadStore|AccessContext));
if (rep->getScope() != getScope()) {
rep->resetScope(getScope());
}
return rep;
}
示例4: visit
void RefDict::visit(ExpressionPtr e) {
if (!first_pass) {
// only need to record expressions once
return;
}
if (e->getScope()->inPseudoMain()) {
// bail out for psuedomain
return;
}
if (!e->is(Expression::KindOfSimpleVariable)) {
// only need to record simple variables
return;
}
SimpleVariablePtr ptr(static_pointer_cast<SimpleVariable>(e));
if (ptr->isSuperGlobal() || ptr->isThis()) {
// don't both recording for super globals or this
return;
}
// Good to go
if (m_am.insertForDict(e)) {
record(e);
}
}
示例5: analyzeProgram
void StaticStatement::analyzeProgram(AnalysisResultPtr ar) {
m_exp->analyzeProgram(ar);
if (ar->getPhase() == AnalysisResult::AnalyzeAll) {
BlockScopePtr scope = getScope();
for (int i = 0; i < m_exp->getCount(); i++) {
ExpressionPtr exp = (*m_exp)[i];
ExpressionPtr variable;
ExpressionPtr value;
// turn static $a; into static $a = null;
if (exp->is(Expression::KindOfSimpleVariable)) {
variable = dynamic_pointer_cast<SimpleVariable>(exp);
exp = AssignmentExpressionPtr
(new AssignmentExpression(exp->getScope(), exp->getLocation(),
variable,
CONSTANT("null"),
false));
(*m_exp)[i] = exp;
}
always_assert(exp->is(Expression::KindOfAssignmentExpression));
AssignmentExpressionPtr assignment_exp =
dynamic_pointer_cast<AssignmentExpression>(exp);
variable = assignment_exp->getVariable();
value = assignment_exp->getValue();
SimpleVariablePtr var = dynamic_pointer_cast<SimpleVariable>(variable);
// set the Declaration context here instead of all over this file - this phase
// is the first to run
var->setContext(Expression::Declaration);
Symbol *sym = var->getSymbol();
sym->setStaticInitVal(value);
}
}
}
示例6: newQueryParamRef
/**
* Appends the given expression to end of the m_capturedExpressions list
* and creates a new expression with the same scope and source location
* that represents a reference to a query parameter. Query parameters do
* not have a source code equivalent, but inform the query processor that
* this expression represents the ith argument value, where i is zero based
* and forms the last character of the special string @query_param_i.
*/
SimpleVariablePtr CaptureExtractor::newQueryParamRef(ExpressionPtr ae) {
assert(ae != nullptr);
char count = '0' + m_capturedExpressions.size();
std::string pname = "@query_param_";
pname.push_back(count);
auto param =
std::make_shared<SimpleVariable>(ae->getScope(), ae->getRange(), pname);
m_capturedExpressions.push_back(ae);
return param;
}
示例7: makeIsNull
static ExpressionPtr makeIsNull(AnalysisResultConstPtr ar,
const Location::Range& r, ExpressionPtr exp,
bool invert) {
/* Replace "$x === null" with an is_null call; this requires slightly
* less work at runtime. */
auto expList = std::make_shared<ExpressionList>(exp->getScope(), r);
expList->insertElement(exp);
auto call =
std::make_shared<SimpleFunctionCall>(
exp->getScope(), r, "is_null", false, expList, ExpressionPtr());
call->setValid();
call->setupScopes(ar);
if (!invert) return call;
return std::make_shared<UnaryOpExpression>(
exp->getScope(), r, call, '!', true);
}
示例8: mergeConcatAssign
bool StatementList::mergeConcatAssign() {
if (Option::LocalCopyProp) {
return false;
} else {
// check for vector string concat assignment such as
// $space = " ";
// $a .= "hello";
// $a .= $space;
// $a .= "world!";
// turn into (for constant folding and concat sequence)
// $a .= " " . "hello " . $space . "world!";
unsigned int i = 0;
bool merged = false;
do {
std::string lhsName;
int length = 0;
for (; i < m_stmts.size(); i++) {
StatementPtr stmt = m_stmts[i];
if (!stmt->is(Statement::KindOfExpStatement)) break;
ExpStatementPtr expStmt = dynamic_pointer_cast<ExpStatement>(stmt);
ExpressionPtr exp = expStmt->getExpression();
// check the first assignment
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment_exp =
dynamic_pointer_cast<AssignmentExpression>(exp);
ExpressionPtr variable = assignment_exp->getVariable();
ExpressionPtr value = assignment_exp->getValue();
std::string variableName = variable->getText();
if (variableName.find("->") != std::string::npos) break;
if (value->hasEffect()) break;
// cannot turn $a .= $b; a .= $a into $a .= $b . $a;
if (value->getText().find(variableName) != std::string::npos) break;
if (lhsName.empty()) {
lhsName = variable->getText();
length++;
continue;
} else {
break;
}
} else if (!exp->is(Expression::KindOfBinaryOpExpression)) {
break;
}
BinaryOpExpressionPtr binaryOpExp =
dynamic_pointer_cast<BinaryOpExpression>(exp);
if (binaryOpExp->getOp() != T_CONCAT_EQUAL) break;
ExpressionPtr exp1 = binaryOpExp->getExp1();
std::string exp1Text = exp1->getText();
if (exp1Text.find("->") != std::string::npos) break;
ExpressionPtr exp2 = binaryOpExp->getExp2();
if (exp2->hasEffect()) break;
if (exp2->getText().find(exp1Text) != std::string::npos) break;
if (lhsName.empty()) {
lhsName = exp1Text;
length++;
} else if (lhsName == exp1Text) {
length++;
} else {
break;
}
}
if (length > 1) {
// replace m_stmts[j] to m_stmts[i - 1] with a new statement
unsigned j = i - length;
ExpStatementPtr expStmt;
ExpressionPtr exp;
BinaryOpExpressionPtr binaryOpExp;
ExpressionPtr var;
ExpressionPtr exp1;
ExpressionPtr exp2;
bool isAssignment = false;
expStmt = dynamic_pointer_cast<ExpStatement>(m_stmts[j++]);
exp = expStmt->getExpression();
if (exp->is(Expression::KindOfAssignmentExpression)) {
isAssignment = true;
AssignmentExpressionPtr assignment_exp =
dynamic_pointer_cast<AssignmentExpression>(exp);
var = assignment_exp->getVariable();
exp1 = assignment_exp->getValue();
} else {
binaryOpExp = dynamic_pointer_cast<BinaryOpExpression>(exp);
var = binaryOpExp->getExp1();
exp1 = binaryOpExp->getExp2();
}
for (; j < i; j++) {
expStmt = dynamic_pointer_cast<ExpStatement>(m_stmts[j]);
exp = expStmt->getExpression();
binaryOpExp = dynamic_pointer_cast<BinaryOpExpression>(exp);
exp2 = binaryOpExp->getExp2();
exp1 = BinaryOpExpressionPtr
(new BinaryOpExpression(getScope(), getLocation(),
Expression::KindOfBinaryOpExpression,
exp1, exp2, '.'));
}
if (isAssignment) {
exp = AssignmentExpressionPtr
(new AssignmentExpression(exp->getScope(), exp->getLocation(),
Expression::KindOfAssignmentExpression,
var, exp1,
//.........这里部分代码省略.........
示例9: cloneForInlineRecur
static ExpressionPtr cloneForInlineRecur(InlineCloneInfo &info,
ExpressionPtr exp,
const std::string &prefix,
AnalysisResultConstPtr ar,
FunctionScopePtr scope) {
exp->getOriginalScope(); // make sure to cache the original scope
exp->setBlockScope(scope);
for (int i = 0, n = exp->getKidCount(); i < n; i++) {
if (ExpressionPtr k = exp->getNthExpr(i)) {
exp->setNthKid(i, cloneForInlineRecur(info, k, prefix, ar, scope));
}
}
StaticClassName *scn = dynamic_cast<StaticClassName*>(exp.get());
if (scn && scn->isStatic() && !info.staticClass.empty()) {
scn->resolveStatic(info.staticClass);
}
switch (exp->getKindOf()) {
case Expression::KindOfSimpleVariable:
{
SimpleVariablePtr sv(dynamic_pointer_cast<SimpleVariable>(exp));
if (sv->isSuperGlobal()) break;
string name;
if (sv->isThis()) {
if (!info.callWithThis) {
if (!sv->hasContext(Expression::ObjectContext)) {
exp = sv->makeConstant(ar, "null");
} else {
// This will produce the wrong error
// we really want a "throw_fatal" ast node.
exp = sv->makeConstant(ar, "null");
}
break;
}
if (info.localThis.empty()) break;
name = info.localThis;
} else {
name = prefix + sv->getName();
}
SimpleVariablePtr rep(new SimpleVariable(
exp->getScope(), exp->getLocation(), name));
rep->copyContext(sv);
rep->updateSymbol(SimpleVariablePtr());
rep->getSymbol()->setHidden();
// Conservatively set flags to prevent
// the alias manager from getting confused.
// On the next pass, it will correct the values,
// and optimize appropriately.
rep->getSymbol()->setUsed();
rep->getSymbol()->setReferenced();
if (exp->getContext() & (Expression::LValue|
Expression::RefValue|
Expression::RefParameter)) {
info.sepm[name] = rep;
}
exp = rep;
}
break;
case Expression::KindOfObjectMethodExpression:
{
FunctionCallPtr call(
static_pointer_cast<FunctionCall>(exp));
if (call->getFuncScope() == info.func) {
call->setNoInline();
}
break;
}
case Expression::KindOfSimpleFunctionCall:
{
SimpleFunctionCallPtr call(static_pointer_cast<SimpleFunctionCall>(exp));
call->addLateDependencies(ar);
call->setLocalThis(info.localThis);
if (call->getFuncScope() == info.func) {
call->setNoInline();
}
}
default:
break;
}
return exp;
}
示例10: updateAccess
void RefDict::updateAccess(ExpressionPtr e) {
always_assert(!e->getScope()->inPseudoMain());
int eid = e->getCanonID();
int context = e->getContext();
if (first_pass) {
if (!e->is(Expression::KindOfSimpleVariable) &&
!e->is(Expression::KindOfDynamicVariable)) return;
e->clearAvailable();
e->clearReferencedValid();
e->clearReferenced();
SimpleVariablePtr ptr(dynamic_pointer_cast<SimpleVariable>(e));
if (ptr && (ptr->isSuperGlobal() || ptr->isThis())) return;
if (e->is(Expression::KindOfSimpleVariable)) {
if (BitOps::get_bit(eid, m_referenced)) {
e->setReferenced();
} else if (!BitOps::get_bit(eid, m_killed)) {
// use as a temp place holder
e->setAvailable();
}
}
}
// let the first pass information propagate for both passes, since
// we need it in both contexts
if (context & Expression::RefAssignmentLHS ||
context & Expression::RefValue ||
context & Expression::RefParameter ||
((context & Expression::Declaration) == Expression::Declaration)) {
if (e->is(Expression::KindOfSimpleVariable)) {
BitOps::set_bit(eid, m_referenced, true);
BitOps::set_bit(eid, m_killed, false);
} else {
// for dynamic variables, we must assume the worst
BitOps::set(size(), m_referenced, -1);
BitOps::set(size(), m_killed, 0);
}
} else if (e->is(Expression::KindOfSimpleVariable) &&
context & Expression::LValue &&
context & Expression::UnsetContext) {
BitOps::set_bit(eid, m_referenced, false);
BitOps::set_bit(eid, m_killed, true);
}
if (first_pass) return;
// now we're on the second pass
if (context & Expression::AssignmentLHS ||
context & Expression::OprLValue) {
// we dealt with this node as a store expression
return;
}
int cls = e->getExprClass();
bool isRhsNeeded = false;
bool canKill = false;
ExpressionPtr lhs;
ExpressionPtr rhs;
if (cls & Expression::Store) {
// we care about two cases here
switch (e->getKindOf()) {
case Expression::KindOfAssignmentExpression:
// $x = ...
{
AssignmentExpressionPtr assign(
static_pointer_cast<AssignmentExpression>(e));
lhs = assign->getVariable();
rhs = assign->getValue();
isRhsNeeded = Expression::CheckNeededRHS(rhs);
canKill = true;
}
break;
case Expression::KindOfBinaryOpExpression:
// $x += ...
{
BinaryOpExpressionPtr binop(
static_pointer_cast<BinaryOpExpression>(e));
if (binop->getOp() == T_PLUS_EQUAL) {
lhs = binop->getExp1();
rhs = binop->getExp2();
isRhsNeeded = Expression::CheckNeededRHS(rhs);
}
}
break;
default:
break;
}
}
bool isLhsSimpleVar = false;
bool isLhsDynamic = false;
bool isRefd = false;
//.........这里部分代码省略.........