本文整理汇总了C++中ScalarExpressionPtr::getLiteralString方法的典型用法代码示例。如果您正苦于以下问题:C++ ScalarExpressionPtr::getLiteralString方法的具体用法?C++ ScalarExpressionPtr::getLiteralString怎么用?C++ ScalarExpressionPtr::getLiteralString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScalarExpressionPtr
的用法示例。
在下文中一共展示了ScalarExpressionPtr::getLiteralString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Expression
FunctionCall::FunctionCall
(EXPRESSION_CONSTRUCTOR_BASE_PARAMETERS,
ExpressionPtr nameExp, const std::string &name, ExpressionListPtr params,
ExpressionPtr classExp)
: Expression(EXPRESSION_CONSTRUCTOR_BASE_PARAMETER_VALUES),
StaticClassName(classExp), m_nameExp(nameExp),
m_ciTemp(-1), m_params(params), m_valid(false),
m_extraArg(0), m_variableArgument(false), m_voidReturn(false),
m_voidWrapper(false), m_redeclared(false),
m_noStatic(false), m_noInline(false), m_invokeFewArgsDecision(true),
m_arrayParams(false),
m_argArrayId(-1), m_argArrayHash(-1), m_argArrayIndex(-1) {
if (m_nameExp &&
m_nameExp->getKindOf() == Expression::KindOfScalarExpression) {
assert(m_name.empty());
ScalarExpressionPtr c = dynamic_pointer_cast<ScalarExpression>(m_nameExp);
m_origName = c->getOriginalLiteralString();
c->toLower(true /* func call*/);
m_name = c->getLiteralString();
} else {
m_origName = name;
m_name = Util::toLower(name);
}
m_clsNameTemp = -1;
}
示例2: analyzeProgramImpl
void SwitchStatement::analyzeProgramImpl(AnalysisResultPtr ar) {
m_exp->analyzeProgram(ar);
if (m_cases) m_cases->analyzeProgram(ar);
if (ar->getPhase() == AnalysisResult::AnalyzeAll &&
m_exp->is(Expression::KindOfSimpleVariable)) {
SimpleVariablePtr exp = dynamic_pointer_cast<SimpleVariable>(m_exp);
if (exp && exp->getSymbol() && exp->getSymbol()->isClassName()) {
// Mark some classes as volitle since the name is used in switch
for (int i = 0; i < m_cases->getCount(); i++) {
CaseStatementPtr stmt =
dynamic_pointer_cast<CaseStatement>((*m_cases)[i]);
ASSERT(stmt);
ExpressionPtr caseCond = stmt->getCondition();
if (caseCond && caseCond->isScalar()) {
ScalarExpressionPtr name =
dynamic_pointer_cast<ScalarExpression>(caseCond);
if (name && name->isLiteralString()) {
string className = name->getLiteralString();
ClassScopePtr cls = ar->findClass(Util::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);
}
}
}
示例3: outputCPPImplOpEqual
bool BinaryOpExpression::outputCPPImplOpEqual(CodeGenerator &cg,
AnalysisResultPtr ar) {
if (m_exp1->is(Expression::KindOfArrayElementExpression)) {
ArrayElementExpressionPtr exp =
dynamic_pointer_cast<ArrayElementExpression>(m_exp1);
if (exp->isSuperGlobal() || exp->isDynamicGlobal()) return false;
if (TypePtr t = exp->getVariable()->getActualType()) {
TypePtr it(exp->getVariable()->getImplementedType());
if (t->is(Type::KindOfArray) &&
(!it ||
it->is(Type::KindOfArray) ||
Type::IsMappedToVariant(it) /* fast cast will kick in */)) {
return false;
}
}
// turning $a['elem'] Op= $b into $a.setOpEqual('elem', $b);
exp->getVariable()->outputCPP(cg, ar);
if (exp->getOffset()) {
cg_printf(".setOpEqual(%d, ", m_op);
exp->getOffset()->outputCPP(cg, ar);
cg_printf(", (");
} else {
cg_printf(".appendOpEqual(%d, (", m_op);
}
m_exp2->outputCPP(cg, ar);
cg_printf(")");
ExpressionPtr off = exp->getOffset();
if (off) {
ScalarExpressionPtr sc = dynamic_pointer_cast<ScalarExpression>(off);
if (sc) {
if (sc->isLiteralString()) {
String s(sc->getLiteralString());
int64 n;
if (!s.get()->isStrictlyInteger(n)) {
cg_printf(", true"); // skip toKey() at run time
}
}
}
}
cg_printf(")");
return true;
}
if (m_exp1->is(Expression::KindOfObjectPropertyExpression)) {
ObjectPropertyExpressionPtr var(
dynamic_pointer_cast<ObjectPropertyExpression>(m_exp1));
if (var->isValid()) return false;
var->outputCPPObject(cg, ar);
cg_printf("o_assign_op<%s,%d>(",
isUnused() ? "void" : "Variant", m_op);
var->outputCPPProperty(cg, ar);
cg_printf(", ");
m_exp2->outputCPP(cg, ar);
cg_printf("%s)", originalClassName(cg, true).c_str());
return true;
}
return false;
}
示例4: Load
bool Option::Load(string &option, ExpressionPtr value) {
ScalarExpressionPtr v = dynamic_pointer_cast<ScalarExpression>(value);
if (!v || !v->isLiteralString()) {
Logger::Error("Line %d: invalid string: %s", value->getLocation()->line1,
value->getText().c_str());
return false;
}
option = v->getLiteralString();
return true;
}
示例5: isNonPrivate
bool ObjectPropertyExpression::isNonPrivate(AnalysisResultPtr ar) {
// To tell whether a property is declared as private in the context
ClassScopePtr cls = getClassScope();
if (!cls || !cls->getVariables()->hasNonStaticPrivate()) return true;
if (m_property->getKindOf() != Expression::KindOfScalarExpression) {
return false;
}
ScalarExpressionPtr name =
dynamic_pointer_cast<ScalarExpression>(m_property);
string propName = name->getLiteralString();
if (propName.empty()) {
return false;
}
Symbol *sym = cls->getVariables()->getSymbol(propName);
if (!sym || sym->isStatic() || !sym->isPrivate()) return true;
return false;
}
示例6: outputCPPImplOpEqual
bool BinaryOpExpression::outputCPPImplOpEqual(CodeGenerator &cg,
AnalysisResultPtr ar) {
if (!m_exp1->is(Expression::KindOfArrayElementExpression)) return false;
ArrayElementExpressionPtr exp =
dynamic_pointer_cast<ArrayElementExpression>(m_exp1);
if (exp->isSuperGlobal() || exp->isDynamicGlobal()) return false;
bool linemap = outputLineMap(cg, ar);
// turning $a['elem'] Op= $b into $a.setOpEqual('elem', $b);
exp->getVariable()->outputCPP(cg, ar);
if (exp->getOffset()) {
cg_printf(".setOpEqual(%d, ", m_op);
exp->getOffset()->outputCPP(cg, ar);
cg_printf(", (");
} else {
cg_printf(".appendOpEqual(%d, (", m_op);
}
m_exp2->outputCPP(cg, ar);
cg_printf(")");
ExpressionPtr off = exp->getOffset();
if (off) {
ScalarExpressionPtr sc = dynamic_pointer_cast<ScalarExpression>(off);
if (sc) {
int64 hash = sc->getHash();
if (hash >= 0) {
cg_printf(", 0x%016llXLL", hash);
} else {
cg_printf(", -1");
}
if (sc->isLiteralString()) {
String s(sc->getLiteralString());
int64 n;
if (!s.get()->isStrictlyInteger(n)) {
cg_printf(", true"); // skip toKey() at run time
}
}
}
}
cg_printf(")");
if (linemap) cg_printf(")");
return true;
}
示例7: outputCPPName
bool ArrayPairExpression::outputCPPName(CodeGenerator &cg,
AnalysisResultPtr ar) {
assert(m_name);
ScalarExpressionPtr sc = dynamic_pointer_cast<ScalarExpression>(m_name);
if (sc) {
if (sc->isLiteralString()) {
string s = sc->getLiteralString();
int64 res;
if (is_strictly_integer(s.c_str(), s.size(), res)) {
cg_printf("%sL", s.c_str());
} else {
m_name->outputCPP(cg, ar);
}
return true;
}
if (sc->isLiteralInteger()) {
m_name->outputCPP(cg, ar);
return true;
}
}
m_name->outputCPP(cg, ar);
return false;
}
示例8: outputCPPUnset
void ArrayElementExpression::outputCPPUnset(CodeGenerator &cg,
AnalysisResultPtr ar) {
if (isSuperGlobal()) {
Expression::outputCPPUnset(cg, ar);
} else {
TypePtr expected = m_variable->getExpectedType();
TypePtr implemented = m_variable->getImplementedType();
bool wrap = false;
if (TypePtr t = m_variable->getActualType()) {
if (t->is(Type::KindOfObject)) {
if (!m_variable->getImplementedType() ||
!m_variable->getImplementedType()->is(Type::KindOfVariant)) {
cg_printf("((Variant)(");
wrap = true;
}
m_variable->setImplementedType(TypePtr());
m_variable->setExpectedType(TypePtr());
}
}
m_variable->outputCPP(cg, ar);
if (wrap) cg_printf("))");
m_variable->setExpectedType(expected);
m_variable->setImplementedType(implemented);
cg_printf(".weakRemove(");
m_offset->outputCPP(cg, ar);
ScalarExpressionPtr sc =
dynamic_pointer_cast<ScalarExpression>(m_offset);
if (sc && sc->isLiteralString()) {
String s(sc->getLiteralString());
int64 n;
if (!s->isStrictlyInteger(n)) {
cg_printf(", true");
}
}
cg_printf(")");
}
}
示例9: outputCPPImpl
void ArrayElementExpression::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
if (m_global) {
if (!m_globalName.empty()) {
VariableTablePtr variables = getScope()->getVariables();
string name = variables->getGlobalVariableName(cg, ar, m_globalName);
cg_printf("g->%s", name.c_str());
} else {
cg_printf("((LVariableTable *)g)->get(");
m_offset->outputCPP(cg, ar);
cg_printf(")");
}
} else {
TypePtr type = m_variable->getActualType();
if (hasContext(UnsetContext)) {
cg_printf("unsetLval(");
m_variable->outputCPP(cg, ar);
cg_printf(", ");
} else {
if (m_variable->is(Expression::KindOfScalarExpression) ||
(type && (type->isInteger() ||
type->is(Type::KindOfDouble) ||
type->is(Type::KindOfObject) ||
type->is(Type::KindOfBoolean)))) {
cg_printf(type && type->is(Type::KindOfString) ? "((String)" :
"((Variant)");
m_variable->outputCPP(cg, ar);
cg_printf(")");
} else {
TypePtr act;
if (!m_variable->hasCPPTemp() && m_variable->getImplementedType() &&
type->is(Type::KindOfArray) &&
!Type::SameType(m_variable->getImplementedType(), type)) {
act = type;
type = m_variable->getImplementedType();
m_variable->setActualType(m_variable->getImplementedType());
}
m_variable->outputCPP(cg, ar);
if (act) {
m_variable->setActualType(act);
}
}
}
if (m_offset) {
bool lvalAt = false;
bool rvalAt = false;
bool byRef = false;
bool arrRef = false;
const char *sep = ", AccessFlags::";
if (hasContext(UnsetContext)) {
// do nothing
} else if (hasContext(InvokeArgument) && cg.callInfoTop() != -1) {
cg_printf(".argvalAt(cit%d->isRef(%d), ", cg.callInfoTop(), m_argNum);
} else if (m_context & (LValue|RefValue|DeepReference)) {
cg_printf(".lvalAt(");
lvalAt = true;
} else {
byRef = (m_context & AccessContext) &&
(!type || !type->is(Type::KindOfString));
arrRef = byRef && type && type->is(Type::KindOfArray);
cg_printf(".rval%s%s(",
arrRef || !byRef ? "At" : "", byRef ? "Ref" : "");
rvalAt = true;
}
m_offset->outputCPP(cg, ar);
if (!type || !type->is(Type::KindOfString)) {
if (rvalAt) {
if (byRef && !arrRef) {
const string &tmp = cg.getReferenceTemp();
cg_printf(", %s", tmp.empty() ? "Variant()" : tmp.c_str());
}
if (!hasContext(ExistContext)) {
cg_printf(", AccessFlags::Error"); // raise undefined index error
sep = "_";
}
} else if (lvalAt) {
if (hasContext(AccessContext)) {
// Dont copy the array if the element is an object, or
// is referenced.
// This is safe in AccessContext (the parent is an ArrayElement,
// or an ObjectProperty) because applying [] to an object will
// either invoke OffsetGet, or fatal, and modifications to a
// referenced element would be reflected in all copies
// of the array anyway.
cg_printf(", AccessFlags::CheckExist");
sep = "_";
}
}
ScalarExpressionPtr sc =
dynamic_pointer_cast<ScalarExpression>(m_offset);
if (!hasContext(UnsetContext) && sc && sc->isLiteralString()) {
String s(sc->getLiteralString());
int64 n;
if (!s.get()->isStrictlyInteger(n)) {
if (lvalAt || rvalAt) {
cg_printf("%sKey", sep);
} else {
cg_printf(", true"); // skip toKey() at run time
}
}
//.........这里部分代码省略.........
示例10: inferTypes
TypePtr ObjectPropertyExpression::inferTypes(AnalysisResultPtr ar,
TypePtr type, bool coerce) {
m_valid = false;
ConstructPtr self = shared_from_this();
TypePtr objectType = m_object->inferAndCheck(ar, Type::Some, false);
if (!m_property->is(Expression::KindOfScalarExpression)) {
m_property->inferAndCheck(ar, Type::String, false);
// we also lost track of which class variable an expression is about, hence
// any type inference could be wrong. Instead, we just force variants on
// all class variables.
if (m_context & (LValue | RefValue)) {
ar->forceClassVariants(getOriginalClass(), false, true);
}
return Type::Variant; // we have to use a variant to hold dynamic value
}
ScalarExpressionPtr exp = dynamic_pointer_cast<ScalarExpression>(m_property);
const string &name = exp->getLiteralString();
if (name.empty()) {
m_property->inferAndCheck(ar, Type::String, false);
if (m_context & (LValue | RefValue)) {
ar->forceClassVariants(getOriginalClass(), false, true);
}
return Type::Variant; // we have to use a variant to hold dynamic value
}
m_property->inferAndCheck(ar, Type::String, false);
ClassScopePtr cls;
if (objectType && !objectType->getName().empty()) {
// what object-> has told us
cls = ar->findExactClass(shared_from_this(), objectType->getName());
} else {
if ((m_context & LValue) && objectType &&
!objectType->is(Type::KindOfObject) &&
!objectType->is(Type::KindOfVariant) &&
!objectType->is(Type::KindOfSome) &&
!objectType->is(Type::KindOfAny)) {
m_object->inferAndCheck(ar, Type::Object, true);
}
}
if (!cls) {
if (m_context & (LValue | RefValue | DeepReference | UnsetContext)) {
ar->forceClassVariants(name, getOriginalClass(), false, true);
}
return Type::Variant;
}
// resolved to this class
if (m_context & RefValue) {
type = Type::Variant;
coerce = true;
}
// use $this inside a static function
if (m_object->isThis()) {
FunctionScopePtr func = m_object->getOriginalFunction();
if (!func || func->isStatic()) {
if (getScope()->isFirstPass()) {
Compiler::Error(Compiler::MissingObjectContext, self);
}
m_actualType = Type::Variant;
return m_actualType;
}
}
assert(cls);
if (!m_propSym || cls != m_objectClass.lock()) {
m_objectClass = cls;
ClassScopePtr parent;
m_propSym = cls->findProperty(parent, name, ar);
if (m_propSym) {
if (!parent) {
parent = cls;
}
m_symOwner = parent;
always_assert(m_propSym->isPresent());
m_propSymValid =
(!m_propSym->isPrivate() || getOriginalClass() == parent) &&
!m_propSym->isStatic();
if (m_propSymValid) {
m_symOwner->addUse(getScope(),
BlockScope::GetNonStaticRefUseKind(
m_propSym->getHash()));
}
}
}
TypePtr ret;
if (m_propSymValid && (!cls->derivesFromRedeclaring() ||
m_propSym->isPrivate())) {
always_assert(m_symOwner);
TypePtr t(m_propSym->getType());
if (t && t->is(Type::KindOfVariant)) {
// only check property if we could possibly do some work
ret = t;
//.........这里部分代码省略.........
示例11: outputCPPImpl
void AssignmentExpression::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
BlockScopePtr scope = ar->getScope();
bool ref = (m_ref && !m_value->is(Expression::KindOfNewObjectExpression));
bool setElement = false; // turning $a['elem'] = $b into $a.set('elem', $b);
bool type_cast = false;
bool setNull = false;
TypePtr m_actualType;
if (m_variable->is(Expression::KindOfArrayElementExpression)) {
ArrayElementExpressionPtr exp =
dynamic_pointer_cast<ArrayElementExpression>(m_variable);
m_actualType = m_variable->getActualType();
if (m_actualType && m_actualType->getKindOf() == Type::KindOfVariant
&& !ref) {
//type_cast = true;
}
if (!exp->isSuperGlobal() && !exp->isDynamicGlobal()) {
exp->getVariable()->outputCPP(cg, ar);
if (exp->getOffset()) {
cg.printf(".set(");
exp->getOffset()->outputCPP(cg, ar);
cg.printf(", (");
} else {
cg.printf(".append((");
}
if (type_cast) {
m_actualType->outputCPPCast(cg, ar);
cg.printf("(");
}
if (ref && m_value->isRefable()) cg.printf("ref(");
m_value->outputCPP(cg, ar);
if (ref && m_value->isRefable()) cg.printf(")");
if (type_cast) cg.printf(")");
cg.printf(")");
ExpressionPtr off = exp->getOffset();
if (off) {
ScalarExpressionPtr sc =
dynamic_pointer_cast<ScalarExpression>(off);
if (sc) {
int64 hash = sc->getHash();
if (hash >= 0) {
cg.printf(", 0x%016llXLL", hash);
} else {
cg.printf(", -1");
}
if (sc->isLiteralString()) {
String s(sc->getLiteralString());
int64 n;
if (!s.get()->isStrictlyInteger(n)) {
cg.printf(", true"); // skip toKey() at run time
}
}
}
}
cg.printf(")");
setElement = true;
}
}
if (m_variable->is(Expression::KindOfSimpleVariable) &&
m_value->is(Expression::KindOfConstantExpression)) {
ConstantExpressionPtr exp =
dynamic_pointer_cast<ConstantExpression>(m_value);
if (exp->isNull()) setNull = true;
}
if (!setElement) {
if (setNull) {
cg.printf("setNull(");
m_variable->outputCPP(cg, ar);
} else {
cg.printf("(");
m_variable->outputCPP(cg, ar);
cg.printf(" = ");
if (type_cast) {
m_actualType->outputCPPCast(cg, ar);
cg.printf("(");
}
if (ref && m_value->isRefable()) cg.printf("ref(");
m_value->outputCPP(cg, ar);
if (ref && m_value->isRefable()) cg.printf(")");
if (type_cast) cg.printf(")");
}
cg.printf(")");
}
}
示例12: outputCPPImpl
//.........这里部分代码省略.........
m_variable->outputCPP(cg, ar);
cg_printf(")");
} else {
m_variable->outputCPP(cg, ar);
}
}
if (m_offset) {
bool lvalAt = false;
bool rvalAt = false;
bool byRef = false;
bool arrRef = false;
const char *sep = ", AccessFlags::";
bool isArrayType = type && type->is(Type::KindOfArray);
bool isStringType = type && type->is(Type::KindOfString);
bool isRealChainRoot = isChainRoot() && hasCPPCseTemp();
TypePtr t;
bool hasCseStore = isRealChainRoot && GetCseTempInfo(
ar,
static_pointer_cast<Expression>(shared_from_this()),
t);
if (hasContext(UnsetContext)) {
// do nothing
} else if (hasContext(InvokeArgument) && cg.callInfoTop() != -1) {
ASSERT(!isRealChainRoot); // TODO: handle this case
cg_printf(".argvalAt(cit%d->isRef(%d), ", cg.callInfoTop(), m_argNum);
} else if (m_context & (LValue|RefValue|DeepReference)) {
// if we see an array access element in LValue context, the
// type inference pass will never infer its type to be a string
ASSERT(!isStringType);
if (isRealChainRoot && !isArrayType) {
// chain roots for non array types (variants) should call
// lvalRef()
cg_printf(".lvalRef(");
} else {
cg_printf(".lvalAt(");
}
lvalAt = true;
} else {
byRef =
((m_context & AccessContext) || isRealChainRoot) && !isStringType;
arrRef = byRef && isArrayType;
cg_printf(".rval%s%s(",
arrRef || !byRef ? "At" : "", byRef ? "Ref" : "");
rvalAt = true;
}
m_offset->outputCPP(cg, ar);
if (!isStringType) {
if (rvalAt) {
if (byRef && !arrRef) {
string tmp;
if (hasCseStore) {
tmp = string(Option::CseTempStoragePrefix) + m_cppCseTemp;
} else {
tmp = cg.getReferenceTemp();
}
cg_printf(", %s", tmp.empty() ? "Variant()" : tmp.c_str());
}
if (!hasContext(ExistContext)) {
cg_printf(", AccessFlags::Error"); // raise undefined index error
sep = "_";
}
} else if (lvalAt) {
if (hasCseStore && !isArrayType) {
cg_printf(", %s%s",
Option::CseTempStoragePrefix, m_cppCseTemp.c_str());
}
if (hasContext(AccessContext)) {
// Dont copy the array if the element is an object, or
// is referenced.
// This is safe in AccessContext (the parent is an ArrayElement,
// or an ObjectProperty) because applying [] to an object will
// either invoke OffsetGet, or fatal, and modifications to a
// referenced element would be reflected in all copies
// of the array anyway.
cg_printf(", AccessFlags::CheckExist");
sep = "_";
}
}
ScalarExpressionPtr sc =
dynamic_pointer_cast<ScalarExpression>(m_offset);
if (!hasContext(UnsetContext) && sc && sc->isLiteralString()) {
String s(sc->getLiteralString());
int64 n;
if (!s.get()->isStrictlyInteger(n)) {
if (lvalAt || rvalAt) {
cg_printf("%sKey", sep);
} else {
cg_printf(", true"); // skip toKey() at run time
}
}
}
}
cg_printf(")");
} else {
cg_printf(".lvalAt()");
}
}
}
示例13: getLiteralString
string CaseStatement::getLiteralString() const {
assert(m_condition->is(Expression::KindOfScalarExpression));
ScalarExpressionPtr exp =
dynamic_pointer_cast<ScalarExpression>(m_condition);
return exp->getLiteralString();
}
示例14: outputCPPImpl
void AssignmentExpression::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
BlockScopePtr scope = ar->getScope();
bool ref = (m_ref && m_value->isRefable());
bool setNull = false;
bool arrayLike = false;
if (m_variable->is(Expression::KindOfArrayElementExpression)) {
ArrayElementExpressionPtr exp =
dynamic_pointer_cast<ArrayElementExpression>(m_variable);
if (!exp->isSuperGlobal() && !exp->isDynamicGlobal()) {
exp->getVariable()->outputCPP(cg, ar);
if (exp->getOffset()) {
cg_printf(".set(");
exp->getOffset()->outputCPP(cg, ar);
cg_printf(", (");
} else {
cg_printf(".append((");
}
wrapValue(cg, ar, m_value, ref, true);
cg_printf(")");
ExpressionPtr off = exp->getOffset();
if (off) {
ScalarExpressionPtr sc =
dynamic_pointer_cast<ScalarExpression>(off);
if (sc) {
if (sc->isLiteralString()) {
String s(sc->getLiteralString());
int64 n;
if (!s.get()->isStrictlyInteger(n)) {
cg_printf(", true"); // skip toKey() at run time
}
}
}
}
cg_printf(")");
return;
}
} else if (m_variable->is(Expression::KindOfObjectPropertyExpression)) {
ObjectPropertyExpressionPtr var(
dynamic_pointer_cast<ObjectPropertyExpression>(m_variable));
if (!var->isValid()) {
var->outputCPPObject(cg, ar);
cg_printf("o_set(");
var->outputCPPProperty(cg, ar);
cg_printf(", %s", ref ? "ref(" : "");
m_value->outputCPP(cg, ar);
cg_printf("%s, %s)",
ref ? ")" : "",
ar->getClassScope() ? "s_class_name" : "empty_string");
return;
}
} else if (m_variable->is(Expression::KindOfSimpleVariable) &&
m_value->is(Expression::KindOfConstantExpression)) {
ConstantExpressionPtr exp =
dynamic_pointer_cast<ConstantExpression>(m_value);
if (exp->isNull()) setNull = true;
}
bool wrapped = true;
if (setNull) {
cg_printf("setNull(");
m_variable->outputCPP(cg, ar);
} else {
if ((wrapped = !isUnused())) {
cg_printf("(");
}
m_variable->outputCPP(cg, ar);
cg_printf(" = ");
wrapValue(cg, ar, m_value, ref, arrayLike);
}
if (wrapped) {
cg_printf(")");
}
}
示例15: analyzeProgram
void SimpleFunctionCall::analyzeProgram(AnalysisResultPtr ar) {
if (m_className.empty()) {
addUserFunction(ar, m_name);
} else if (m_className != "parent") {
addUserClass(ar, m_className);
} else {
m_parentClass = true;
}
if (ar->getPhase() == AnalysisResult::AnalyzeInclude) {
CHECK_HOOK(onSimpleFunctionCallAnalyzeInclude);
ConstructPtr self = shared_from_this();
// We need to know the name of the constant so that we can associate it
// with this file before we do type inference.
if (m_className.empty() && m_type == DefineFunction) {
ScalarExpressionPtr name =
dynamic_pointer_cast<ScalarExpression>((*m_params)[0]);
string varName;
if (name) {
varName = name->getIdentifier();
if (!varName.empty()) {
ar->getFileScope()->declareConstant(ar, varName);
}
}
// handling define("CONSTANT", ...);
if (m_params && m_params->getCount() >= 2) {
ScalarExpressionPtr name =
dynamic_pointer_cast<ScalarExpression>((*m_params)[0]);
string varName;
if (name) {
varName = name->getIdentifier();
if (!varName.empty()) {
ExpressionPtr value = (*m_params)[1];
ConstantTablePtr constants =
ar->findConstantDeclarer(varName)->getConstants();
if (constants != ar->getConstants()) {
constants->add(varName, NEW_TYPE(Some), value, ar, self);
if (name->hasHphpNote("Dynamic")) {
constants->setDynamic(ar, varName);
}
}
}
}
}
}
if (m_type == UnserializeFunction) {
ar->forceClassVariants();
}
}
if (ar->getPhase() == AnalysisResult::AnalyzeAll) {
// Look up the corresponding FunctionScope and ClassScope
// for this function call
{
FunctionScopePtr func;
ClassScopePtr cls;
if (m_className.empty()) {
func = ar->findFunction(m_name);
} else {
cls = ar->resolveClass(m_className);
if (cls) {
if (m_name == "__construct") {
func = cls->findConstructor(ar, true);
} else {
func = cls->findFunction(ar, m_name, true, true);
}
}
}
if (func && !func->isRedeclaring()) {
if (m_funcScope != func) {
m_funcScope = func;
Construct::recomputeEffects();
}
}
if (cls && !cls->isRedeclaring())
m_classScope = cls;
}
// check for dynamic constant and volatile function/class
if (m_className.empty() &&
(m_type == DefinedFunction ||
m_type == FunctionExistsFunction ||
m_type == ClassExistsFunction ||
m_type == InterfaceExistsFunction) &&
m_params && m_params->getCount() >= 1) {
ExpressionPtr value = (*m_params)[0];
if (value->isScalar()) {
ScalarExpressionPtr name =
dynamic_pointer_cast<ScalarExpression>(value);
if (name && name->isLiteralString()) {
string symbol = name->getLiteralString();
switch (m_type) {
case DefinedFunction: {
ConstantTablePtr constants = ar->getConstants();
if (!constants->isPresent(symbol)) {
// user constant
//.........这里部分代码省略.........