r336715 - Revert r336591 "[libclang] NFC, simplify clang_Cursor_Evaluate"

Evgeniy Stepanov via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 10 12:48:54 PDT 2018


Author: eugenis
Date: Tue Jul 10 12:48:53 2018
New Revision: 336715

URL: http://llvm.org/viewvc/llvm-project?rev=336715&view=rev
Log:
Revert r336591 "[libclang] NFC, simplify clang_Cursor_Evaluate"

This change is blocking r336590 which is being reverted due to memory leaks.

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=336715&r1=336714&r2=336715&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Jul 10 12:48:53 2018
@@ -3889,32 +3889,33 @@ static const ExprEvalResult* evaluateExp
   return nullptr;
 }
 
-static const Expr *evaluateDeclExpr(const Decl *D) {
-  if (!D)
-    return nullptr;
-  if (auto *Var = dyn_cast<VarDecl>(D))
-    return Var->getInit();
-  else if (auto *Field = dyn_cast<FieldDecl>(D))
-    return Field->getInClassInitializer();
-  return nullptr;
-}
-
-static const Expr *evaluateCompoundStmtExpr(const CompoundStmt *CS) {
-  assert(CS && "invalid compound statement");
-  for (auto *bodyIterator : CS->body()) {
-    if (const auto *E = dyn_cast<Expr>(bodyIterator))
-      return E;
+CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
+  if (clang_getCursorKind(C) == CXCursor_CompoundStmt) {
+    const CompoundStmt *compoundStmt = cast<CompoundStmt>(getCursorStmt(C));
+    Expr *expr = nullptr;
+    for (auto *bodyIterator : compoundStmt->body()) {
+      if ((expr = dyn_cast<Expr>(bodyIterator))) {
+        break;
+      }
+    }
+    if (expr)
+      return const_cast<CXEvalResult>(
+          reinterpret_cast<const void *>(evaluateExpr(expr, C)));
   }
-  return nullptr;
-}
 
-CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
-  if (const Expr *E =
-          clang_getCursorKind(C) == CXCursor_CompoundStmt
-              ? evaluateCompoundStmtExpr(cast<CompoundStmt>(getCursorStmt(C)))
-              : evaluateDeclExpr(getCursorDecl(C)))
-    return const_cast<CXEvalResult>(
-        reinterpret_cast<const void *>(evaluateExpr(const_cast<Expr *>(E), C)));
+  const Decl *D = getCursorDecl(C);
+  if (D) {
+    const Expr *expr = nullptr;
+    if (auto *Var = dyn_cast<VarDecl>(D)) {
+      expr = Var->getInit();
+    } else if (auto *Field = dyn_cast<FieldDecl>(D)) {
+      expr = Field->getInClassInitializer();
+    }
+    if (expr)
+      return const_cast<CXEvalResult>(reinterpret_cast<const void *>(
+          evaluateExpr(const_cast<Expr *>(expr), C)));
+    return nullptr;
+  }
   return nullptr;
 }
 




More information about the cfe-commits mailing list