in legacy/objc/src/XPFlagRefactoring/XPFlagRefactoring.cpp [178:278]
static Value evalExpr(const Expr *expr,
const MatchFinder::MatchResult &Result,
const ObjCMessageExpr *reqSelector, FlagType flagType) {
if (isa<ParenExpr>(expr)) {
const ParenExpr *pe = cast<ParenExpr>(expr);
const Expr *eSub = pe->getSubExpr();
if (eSub != NULL) {
return evalExpr(eSub, Result, reqSelector, flagType);
}
}
if (isa<IntegerLiteral>(expr)) {
const IntegerLiteral *il = cast<IntegerLiteral>(expr);
if (!(il->getValue())) {
return IS_FALSE;
} else {
return IS_TRUE;
}
}
if (isa<UnaryOperator>(expr)) {
const UnaryOperator *uo = cast<UnaryOperator>(expr);
const Expr *eSub = uo->getSubExpr();
if (eSub != NULL) {
Value v = evalExpr(eSub, Result, reqSelector, flagType);
if (uo->getOpcode() == UO_LNot) {
if (v == IS_TRUE) {
return IS_FALSE;
} else if (v == IS_FALSE) {
return IS_TRUE;
}
return IS_UNKNOWN;
} else {
return v;
}
}
}
if (isa<BinaryOperator>(expr)) {
const BinaryOperator *bo = cast<BinaryOperator>(expr);
const Expr *lhs = bo->getLHS();
const Expr *rhs = bo->getRHS();
Value l = evalExpr(lhs, Result, reqSelector, flagType);
Value r = evalExpr(rhs, Result, reqSelector, flagType);
if (bo->getOpcode() == BO_LOr) {
if (l == IS_TRUE || r == IS_TRUE) {
return IS_TRUE;
}
if (l == IS_FALSE && r == IS_FALSE) {
return IS_FALSE;
}
} else if (bo->getOpcode() == BO_LAnd) {
if (l == IS_TRUE && r == IS_TRUE) {
return IS_TRUE;
}
if (l == IS_FALSE || r == IS_FALSE) {
return IS_FALSE;
}
}
}
if (isa<ObjCMessageExpr>(expr)) {
const ObjCMessageExpr *msgExpr = cast<ObjCMessageExpr>(expr);
if (msgExpr != NULL && (msgExpr == reqSelector)) {
FlagType foundType = getFlagType(msgExpr);
Value v = computeValue(foundType, flagType);
return v;
} else {
return IS_UNKNOWN;
}
}
if (isa<ExprWithCleanups>(expr)) {
const ExprWithCleanups *ewc = cast<ExprWithCleanups>(expr);
const Expr *eSub = ewc->getSubExpr();
if (eSub != NULL) {
return evalExpr(eSub, Result, reqSelector, flagType);
}
}
if (isa<ImplicitCastExpr>(expr)) {
const ImplicitCastExpr *ice = cast<ImplicitCastExpr>(expr);
const Expr *eSub = ice->getSubExpr();
if (eSub != NULL) {
return evalExpr(eSub, Result, reqSelector, flagType);
}
}
if (isa<PseudoObjectExpr>(expr)) {
const PseudoObjectExpr *poe = cast<PseudoObjectExpr>(expr);
const Expr *eResult = poe->getResultExpr();
if (eResult != NULL) {
return evalExpr(eResult, Result, reqSelector, flagType);
}
}
return IS_UNKNOWN;
}