r266224 - libclang: Use early-return to reduce indentation.
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 13 11:36:19 PDT 2016
Author: dblaikie
Date: Wed Apr 13 13:36:19 2016
New Revision: 266224
URL: http://llvm.org/viewvc/llvm-project?rev=266224&view=rev
Log:
libclang: Use early-return to reduce indentation.
& since I'll get blamed for all the lines anyway, remove some
else-after-return and otherwise tidy things up.
Modified:
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=266224&r1=266223&r2=266224&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Apr 13 13:36:19 2016
@@ -3459,146 +3459,138 @@ const char* clang_EvalResult_getAsStr(CX
static const ExprEvalResult* evaluateExpr(Expr *expr, CXCursor C) {
Expr::EvalResult ER;
ASTContext &ctx = getCursorContext(C);
- if (!expr) {
+ if (!expr)
return nullptr;
- }
+
expr = expr->IgnoreParens();
- bool res = expr->EvaluateAsRValue(ER, ctx);
+ if (!expr->EvaluateAsRValue(ER, ctx))
+ return nullptr;
+
QualType rettype;
CallExpr *callExpr;
auto result = llvm::make_unique<ExprEvalResult>();
result->EvalType = CXEval_UnExposed;
- if (res) {
-
- if (ER.Val.isInt()) {
- result->EvalType = CXEval_Int;
- result->EvalData.intVal = ER.Val.getInt().getExtValue();
- return result.release();
- } else if (ER.Val.isFloat()) {
-
- llvm::SmallVector<char, 100> Buffer;
- ER.Val.getFloat().toString(Buffer);
- std::string floatStr(Buffer.data(), Buffer.size());
- result->EvalType = CXEval_Float;
- bool ignored;
- llvm::APFloat apFloat = ER.Val.getFloat();
- apFloat.convert(llvm::APFloat::IEEEdouble,
- llvm::APFloat::rmNearestTiesToEven, &ignored);
- result->EvalData.floatVal = apFloat.convertToDouble();
- return result.release();
-
- } else if (expr->getStmtClass() == Stmt::ImplicitCastExprClass) {
-
- const ImplicitCastExpr *I = dyn_cast<ImplicitCastExpr>(expr);
- auto *subExpr = I->getSubExprAsWritten();
- if (subExpr->getStmtClass() == Stmt::StringLiteralClass ||
- subExpr->getStmtClass() == Stmt::ObjCStringLiteralClass) {
-
- const StringLiteral *StrE = nullptr;
- const ObjCStringLiteral *ObjCExpr;
- ObjCExpr = dyn_cast<ObjCStringLiteral>(subExpr);
-
- if (ObjCExpr) {
- StrE = ObjCExpr->getString();
- result->EvalType = CXEval_ObjCStrLiteral;
- } else {
- StrE = cast<StringLiteral>(I->getSubExprAsWritten());
- result->EvalType = CXEval_StrLiteral;
- }
-
- std::string strRef(StrE->getString().str());
- result->EvalData.stringVal = new char[strRef.size() + 1];
- strncpy((char*)result->EvalData.stringVal, strRef.c_str(),
- strRef.size());
- result->EvalData.stringVal[strRef.size()] = '\0';
- return result.release();
- }
+ if (ER.Val.isInt()) {
+ result->EvalType = CXEval_Int;
+ result->EvalData.intVal = ER.Val.getInt().getExtValue();
+ return result.release();
+ }
- } else if (expr->getStmtClass() == Stmt::ObjCStringLiteralClass ||
- expr->getStmtClass() == Stmt::StringLiteralClass) {
+ if (ER.Val.isFloat()) {
+ llvm::SmallVector<char, 100> Buffer;
+ ER.Val.getFloat().toString(Buffer);
+ std::string floatStr(Buffer.data(), Buffer.size());
+ result->EvalType = CXEval_Float;
+ bool ignored;
+ llvm::APFloat apFloat = ER.Val.getFloat();
+ apFloat.convert(llvm::APFloat::IEEEdouble,
+ llvm::APFloat::rmNearestTiesToEven, &ignored);
+ result->EvalData.floatVal = apFloat.convertToDouble();
+ return result.release();
+ }
+ if (expr->getStmtClass() == Stmt::ImplicitCastExprClass) {
+ const ImplicitCastExpr *I = dyn_cast<ImplicitCastExpr>(expr);
+ auto *subExpr = I->getSubExprAsWritten();
+ if (subExpr->getStmtClass() == Stmt::StringLiteralClass ||
+ subExpr->getStmtClass() == Stmt::ObjCStringLiteralClass) {
const StringLiteral *StrE = nullptr;
const ObjCStringLiteral *ObjCExpr;
- ObjCExpr = dyn_cast<ObjCStringLiteral>(expr);
+ ObjCExpr = dyn_cast<ObjCStringLiteral>(subExpr);
if (ObjCExpr) {
StrE = ObjCExpr->getString();
result->EvalType = CXEval_ObjCStrLiteral;
} else {
- StrE = cast<StringLiteral>(expr);
+ StrE = cast<StringLiteral>(I->getSubExprAsWritten());
result->EvalType = CXEval_StrLiteral;
}
std::string strRef(StrE->getString().str());
result->EvalData.stringVal = new char[strRef.size() + 1];
- strncpy((char*)result->EvalData.stringVal, strRef.c_str(),
- strRef.size());
+ strncpy((char *)result->EvalData.stringVal, strRef.c_str(),
+ strRef.size());
result->EvalData.stringVal[strRef.size()] = '\0';
return result.release();
+ }
+ } else if (expr->getStmtClass() == Stmt::ObjCStringLiteralClass ||
+ expr->getStmtClass() == Stmt::StringLiteralClass) {
+ const StringLiteral *StrE = nullptr;
+ const ObjCStringLiteral *ObjCExpr;
+ ObjCExpr = dyn_cast<ObjCStringLiteral>(expr);
+
+ if (ObjCExpr) {
+ StrE = ObjCExpr->getString();
+ result->EvalType = CXEval_ObjCStrLiteral;
+ } else {
+ StrE = cast<StringLiteral>(expr);
+ result->EvalType = CXEval_StrLiteral;
+ }
- } else if (expr->getStmtClass() == Stmt::CStyleCastExprClass) {
+ std::string strRef(StrE->getString().str());
+ result->EvalData.stringVal = new char[strRef.size() + 1];
+ strncpy((char *)result->EvalData.stringVal, strRef.c_str(), strRef.size());
+ result->EvalData.stringVal[strRef.size()] = '\0';
+ return result.release();
+ }
- CStyleCastExpr *CC = static_cast<CStyleCastExpr *>(expr);
+ if (expr->getStmtClass() == Stmt::CStyleCastExprClass) {
+ CStyleCastExpr *CC = static_cast<CStyleCastExpr *>(expr);
- rettype = CC->getType();
- if (rettype.getAsString() == "CFStringRef" &&
- CC->getSubExpr()->getStmtClass() == Stmt::CallExprClass) {
-
- callExpr = static_cast<CallExpr *>(CC->getSubExpr());
- StringLiteral* S = getCFSTR_value(callExpr);
- if (S) {
- std::string strLiteral(S->getString().str());
- result->EvalType = CXEval_CFStr;
-
- result->EvalData.stringVal = new char[strLiteral.size() + 1];
- strncpy((char*)result->EvalData.stringVal, strLiteral.c_str(),
- strLiteral.size());
- result->EvalData.stringVal[strLiteral.size()] = '\0';
- return result.release();
- }
+ rettype = CC->getType();
+ if (rettype.getAsString() == "CFStringRef" &&
+ CC->getSubExpr()->getStmtClass() == Stmt::CallExprClass) {
+
+ callExpr = static_cast<CallExpr *>(CC->getSubExpr());
+ StringLiteral *S = getCFSTR_value(callExpr);
+ if (S) {
+ std::string strLiteral(S->getString().str());
+ result->EvalType = CXEval_CFStr;
+
+ result->EvalData.stringVal = new char[strLiteral.size() + 1];
+ strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(),
+ strLiteral.size());
+ result->EvalData.stringVal[strLiteral.size()] = '\0';
+ return result.release();
}
+ }
- } else if (expr->getStmtClass() == Stmt::CallExprClass) {
-
- callExpr = static_cast<CallExpr *>(expr);
- rettype = callExpr->getCallReturnType(ctx);
-
- if (rettype->isVectorType() || callExpr->getNumArgs() > 1)
+ } else if (expr->getStmtClass() == Stmt::CallExprClass) {
+ callExpr = static_cast<CallExpr *>(expr);
+ rettype = callExpr->getCallReturnType(ctx);
+
+ if (rettype->isVectorType() || callExpr->getNumArgs() > 1)
+ return nullptr;
+
+ if (rettype->isIntegralType(ctx) || rettype->isRealFloatingType()) {
+ if (callExpr->getNumArgs() == 1 &&
+ !callExpr->getArg(0)->getType()->isIntegralType(ctx))
return nullptr;
+ } else if (rettype.getAsString() == "CFStringRef") {
- if (rettype->isIntegralType(ctx) || rettype->isRealFloatingType()) {
- if (callExpr->getNumArgs() == 1 &&
- !callExpr->getArg(0)->getType()->isIntegralType(ctx))
- return nullptr;
- } else if(rettype.getAsString() == "CFStringRef") {
-
- StringLiteral* S = getCFSTR_value(callExpr);
- if (S) {
- std::string strLiteral(S->getString().str());
- result->EvalType = CXEval_CFStr;
- result->EvalData.stringVal = new char[strLiteral.size() + 1];
- strncpy((char*)result->EvalData.stringVal, strLiteral.c_str(),
- strLiteral.size());
- result->EvalData.stringVal[strLiteral.size()] = '\0';
- return result.release();
- }
- }
-
- } else if (expr->getStmtClass() == Stmt::DeclRefExprClass) {
-
- DeclRefExpr *D = static_cast<DeclRefExpr *>(expr);
- ValueDecl *V = D->getDecl();
- if (V->getKind() == Decl::Function) {
- std::string strName = V->getNameAsString();
- result->EvalType = CXEval_Other;
- result->EvalData.stringVal = new char[strName.size() + 1];
- strncpy(result->EvalData.stringVal, strName.c_str(), strName.size());
- result->EvalData.stringVal[strName.size()] = '\0';
+ StringLiteral *S = getCFSTR_value(callExpr);
+ if (S) {
+ std::string strLiteral(S->getString().str());
+ result->EvalType = CXEval_CFStr;
+ result->EvalData.stringVal = new char[strLiteral.size() + 1];
+ strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(),
+ strLiteral.size());
+ result->EvalData.stringVal[strLiteral.size()] = '\0';
return result.release();
}
}
-
+ } else if (expr->getStmtClass() == Stmt::DeclRefExprClass) {
+ DeclRefExpr *D = static_cast<DeclRefExpr *>(expr);
+ ValueDecl *V = D->getDecl();
+ if (V->getKind() == Decl::Function) {
+ std::string strName = V->getNameAsString();
+ result->EvalType = CXEval_Other;
+ result->EvalData.stringVal = new char[strName.size() + 1];
+ strncpy(result->EvalData.stringVal, strName.c_str(), strName.size());
+ result->EvalData.stringVal[strName.size()] = '\0';
+ return result.release();
+ }
}
return nullptr;
More information about the cfe-commits
mailing list