本文整理汇总了C++中ArrayPairExpressionPtr::getValue方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayPairExpressionPtr::getValue方法的具体用法?C++ ArrayPairExpressionPtr::getValue怎么用?C++ ArrayPairExpressionPtr::getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayPairExpressionPtr
的用法示例。
在下文中一共展示了ArrayPairExpressionPtr::getValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getScalarValue
bool ExpressionList::getScalarValue(Variant &value) {
if (m_arrayElements) {
if (isScalarArrayPairs()) {
ArrayInit init(m_exps.size());
for (unsigned int i = 0; i < m_exps.size(); i++) {
ArrayPairExpressionPtr exp =
dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
ExpressionPtr name = exp->getName();
ExpressionPtr val = exp->getValue();
if (!name) {
Variant v;
bool ret = val->getScalarValue(v);
if (!ret) ASSERT(false);
init.set(v);
} else {
Variant n;
Variant v;
bool ret1 = name->getScalarValue(n);
bool ret2 = val->getScalarValue(v);
if (!(ret1 && ret2)) return ExpressionPtr();
init.set(n, v);
}
}
value = Array(init.create());
return true;
}
return false;
}
if (m_kind != ListKindParam && !hasEffect()) {
ExpressionPtr v(listValue());
return v ? v->getScalarValue(value) : false;
}
return false;
}
示例2: outputCPPUniqLitKeyArrayInit
void ExpressionList::outputCPPUniqLitKeyArrayInit(
CodeGenerator &cg, AnalysisResultPtr ar, int64 max,
bool arrayElements /* = true */, unsigned int start /* = 0 */) {
if (arrayElements) ASSERT(m_arrayElements);
unsigned int n = m_exps.size();
cg_printf("array_create%d(%lu, ", n - start, max);
for (unsigned int i = start; i < n; i++) {
if (ExpressionPtr exp = m_exps[i]) {
ExpressionPtr name;
ExpressionPtr value = exp;
if (arrayElements) {
ArrayPairExpressionPtr ap =
dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
name = ap->getName();
value = ap->getValue();
}
if (name) {
name->outputCPP(cg, ar);
} else {
cg_printf("%d", i - start);
}
cg_printf(", ");
value->outputCPP(cg, ar);
if (i < n-1) {
cg_printf(", ");
} else {
cg_printf(")");
}
}
}
}
示例3: if
bool
ExpressionList::flattenLiteralStrings(vector<ExpressionPtr> &literals) const {
for (unsigned i = 0; i < m_exps.size(); i++) {
ExpressionPtr e = m_exps[i];
if (e->is(Expression::KindOfArrayPairExpression)) {
ArrayPairExpressionPtr ap = dynamic_pointer_cast<ArrayPairExpression>(e);
if (ap->getName()) return false;
e = ap->getValue();
}
if (e->is(Expression::KindOfUnaryOpExpression)) {
UnaryOpExpressionPtr unary = dynamic_pointer_cast<UnaryOpExpression>(e);
if (unary->getOp() == T_ARRAY) {
ExpressionListPtr el =
dynamic_pointer_cast<ExpressionList>(unary->getExpression());
if (!el->flattenLiteralStrings(literals)) {
return false;
}
}
}
else if (e->isLiteralString()) {
literals.push_back(e);
} else {
return false;
}
}
return true;
}
示例4: getScalarValue
bool ExpressionList::getScalarValue(Variant &value) {
if (m_elems_kind != ElemsKind::None) {
if (isScalarArrayPairs()) {
ArrayInit init(m_exps.size(), ArrayInit::Mixed{});
for (unsigned int i = 0; i < m_exps.size(); i++) {
ArrayPairExpressionPtr exp =
dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
ExpressionPtr name = exp->getName();
ExpressionPtr val = exp->getValue();
if (!name) {
Variant v;
bool ret = val->getScalarValue(v);
if (!ret) assert(false);
init.append(v);
} else {
Variant n;
Variant v;
bool ret1 = name->getScalarValue(n);
bool ret2 = val->getScalarValue(v);
if (!(ret1 && ret2)) return false;
init.setKeyUnconverted(n, v);
}
}
value = Array(init.create());
return true;
}
return false;
}
if (m_kind != ListKindParam && !hasEffect()) {
ExpressionPtr v(listValue());
return v ? v->getScalarValue(value) : false;
}
return false;
}
示例5: getScalarValue
bool ExpressionList::getScalarValue(Variant &value) {
if (!isScalarArrayPairs()) return false;
ArrayInit init(m_exps.size());
for (unsigned int i = 0; i < m_exps.size(); i++) {
ArrayPairExpressionPtr exp =
dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
ExpressionPtr name = exp->getName();
ExpressionPtr val = exp->getValue();
if (!name) {
Variant v;
bool ret = val->getScalarValue(v);
if (!ret) ASSERT(false);
init.set(i, v);
} else {
Variant n;
Variant v;
bool ret1 = name->getScalarValue(n);
bool ret2 = val->getScalarValue(v);
if (!(ret1 && ret2)) ASSERT(false);
init.set(i, n, v);
}
}
value = Array(init.create());
return true;
}
示例6: Load
bool Option::Load(map<string, int> &option, ExpressionPtr value) {
ExpressionListPtr elements;
if (!GetArrayElements(value, elements)) return false;
for (int i = 0; i < elements->getCount(); i++) {
ExpressionPtr e = (*elements)[i];
ArrayPairExpressionPtr pair = dynamic_pointer_cast<ArrayPairExpression>(e);
bool negative = false;
ScalarExpressionPtr n, v;
if (pair) n = dynamic_pointer_cast<ScalarExpression>(pair->getName());
if (pair) {
if (pair->getValue()->is(Expression::KindOfUnaryOpExpression)) {
UnaryOpExpressionPtr una =
dynamic_pointer_cast<UnaryOpExpression>(pair->getValue());
if (una->getOp() != '+' && una->getOp() != '-') {
Logger::Error("Line %d: invalid integer: %s",
una->getLocation()->line1, una->getText().c_str());
return false;
}
v = dynamic_pointer_cast<ScalarExpression>(una->getExpression());
if (una->getOp() == '-') {
negative = true;
}
} else {
v = dynamic_pointer_cast<ScalarExpression>(pair->getValue());
}
}
if (!pair || !n || !v || !n->isLiteralString() || !v->isLiteralInteger()) {
Logger::Error("Line %d: invalid element: %s", e->getLocation()->line1,
e->getText().c_str());
return false;
}
if (negative) {
option[n->getLiteralString()] = - v->getLiteralInteger();
} else {
option[n->getLiteralString()] = v->getLiteralInteger();
}
}
return true;
}
示例7: 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;
}
示例8: 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(")");
}
}
}
示例9: outputCPPInternal
bool ExpressionList::outputCPPInternal(CodeGenerator &cg,
AnalysisResultPtr ar,
bool needed, bool pre) {
bool needsComma = false;
bool anyOutput = false;
if (m_arrayElements) {
bool isVector = true;
for (unsigned int i = 0; i < m_exps.size(); i++) {
ArrayPairExpressionPtr ap =
dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
if (ap->getName()) {
isVector = false;
break;
}
}
if (outputCPPArrayCreate(cg, ar, isVector, pre)) return true;
cg_printf("ArrayInit");
if (pre) {
cg_printf(" %s", m_cppTemp.c_str());
}
cg_printf("(%d)", (int)m_exps.size());
if (pre) cg_printf(";\n");
needsComma = true;
anyOutput = true;
}
bool trailingComma = false;
unsigned i = 0, s = m_exps.size();
unsigned ix = m_kind == ListKindLeft ? 0 : s - 1;
bool uniqueStringKeys =
m_arrayElements && (checkLitstrKeys() == s); // TODO integer keys as well
for ( ; i < s; i++) {
if (ExpressionPtr exp = m_exps[i]) {
if (pre) {
exp->preOutputCPP(cg, ar, 0);
cg_printf("%s", m_cppTemp.c_str());
}
if (needsComma) {
cg_printf(m_arrayElements ? "." : ", ");
trailingComma = true;
}
if (m_arrayElements) {
ArrayPairExpressionPtr ap =
dynamic_pointer_cast<ArrayPairExpression>(exp);
if (ap->isRef()) {
cg_printf("setRef(");
// The value itself shouldn't be wrapped with ref() any more.
ap->getValue()->setContext(NoRefWrapper);
} else {
cg_printf(uniqueStringKeys ? "add(" : "set(");
}
exp->outputCPP(cg, ar);
cg_printf(")");
if (pre) {
cg_printf(";\n");
}
needsComma = true;
} else if (m_kind != ListKindParam && (i != ix || !needed)) {
needsComma = exp->outputCPPUnneeded(cg, ar);
} else {
bool wrap =
exp->hasCPPTemp() &&
hasContext(LValue) && !hasAnyContext(RefValue|InvokeArgument) &&
!(exp->hasContext(LValue) &&
!exp->hasAnyContext(RefValue|InvokeArgument));
if (wrap) cg_printf("const_cast<Variant&>(");
bool noRef = !exp->hasCPPTemp() &&
hasContext(RefValue) &&
!exp->hasAllContext(LValue|ReturnContext) &&
!exp->hasContext(RefValue) &&
!exp->isTemporary() &&
Type::IsMappedToVariant(exp->getActualType());
if (noRef) cg_printf("wrap_variant(");
exp->outputCPP(cg, ar);
if (noRef) cg_printf(")");
if (wrap) cg_printf(")");
needsComma = true;
}
if (needsComma) {
trailingComma = false;
anyOutput = true;
}
}
}
if (trailingComma) {
cg_printf("id(0)");
}
if (m_arrayElements && !pre) {
cg_printf(".create()");
anyOutput = true;
}
return anyOutput;
}
示例10: outputCPPInternal
bool ExpressionList::outputCPPInternal(CodeGenerator &cg,
AnalysisResultPtr ar,
bool needed, bool pre) {
bool needsComma = false;
bool anyOutput = false;
if (m_arrayElements) {
bool isVector = true;
for (unsigned int i = 0; i < m_exps.size(); i++) {
ArrayPairExpressionPtr ap =
dynamic_pointer_cast<ArrayPairExpression>(m_exps[i]);
if (ap->getName()) {
isVector = false;
break;
}
}
if (outputCPPArrayCreate(cg, ar, isVector, pre)) return true;
cg_printf("ArrayInit");
if (pre) {
cg_printf(" %s", m_cppTemp.c_str());
}
cg_printf("(%d, %s)", m_exps.size(), isVector ? "true" : "false");
if (pre) cg_printf(";\n");
needsComma = true;
anyOutput = true;
}
bool trailingComma = false;
unsigned i = 0, s = m_exps.size();
unsigned ix = m_kind == ListKindLeft ? 0 : s - 1;
for ( ; i < s; i++) {
if (ExpressionPtr exp = m_exps[i]) {
if (pre) {
exp->preOutputCPP(cg, ar, 0);
cg_printf("%s", m_cppTemp.c_str());
}
if (needsComma) {
cg_printf(m_arrayElements ? "." : ", ");
trailingComma = true;
}
if (m_arrayElements) {
ArrayPairExpressionPtr ap =
dynamic_pointer_cast<ArrayPairExpression>(exp);
if (ap->isRef()) {
cg_printf("setRef(");
// The value itself shouldn't be wrapped with ref() any more.
ap->getValue()->setContext(NoRefWrapper);
} else {
cg_printf("set(");
}
exp->outputCPP(cg, ar);
cg_printf(")");
if (pre) {
cg_printf(";\n");
}
needsComma = true;
} else if (m_kind != ListKindParam && (i != ix || !needed)) {
needsComma = exp->outputCPPUnneeded(cg, ar);
} else {
exp->outputCPP(cg, ar);
needsComma = true;
}
if (needsComma) {
trailingComma = false;
anyOutput = true;
}
}
}
if (trailingComma) {
cg_printf("id(0)");
}
if (m_arrayElements && !pre) {
cg_printf(".create()");
anyOutput = true;
}
return anyOutput;
}