* If cursor is a statement declaration tries to evaluate the
* statement and if its variable, tries to evaluate its initializer,
* into its corresponding type.
+ * If it's an expression, tries to evaluate the expression.
*/
CINDEX_LINKAGE CXEvalResult clang_Cursor_Evaluate(CXCursor C);
static const auto g = alignof(f);
};
+constexpr static int calc_val() { return 1 + 2; }
+const auto the_value = calc_val() + sizeof(char);
+
// RUN: c-index-test -evaluate-cursor-at=%s:4:7 \
// RUN: -evaluate-cursor-at=%s:8:7 \
// RUN: -evaluate-cursor-at=%s:8:11 -std=c++11 %s | FileCheck %s
// RUN: -evaluate-cursor-at=%s:26:21 \
// RUN: -std=c++11 %s | FileCheck -check-prefix=CHECK-DOES-NOT-CRASH %s
// CHECK-DOES-NOT-CRASH: Not Evaluatable
+
+// RUN: c-index-test -evaluate-cursor-at=%s:30:1 \
+// RUN: -evaluate-cursor-at=%s:30:32 \
+// RUN: -evaluate-cursor-at=%s:30:35 \
+// RUN: -evaluate-cursor-at=%s:30:37 -std=c++11 %s | FileCheck %s -check-prefix=CHECK-EXPR
+// CHECK-EXPR: unsigned, Value: 4
+// CHECK-EXPR: Value: 3
+// CHECK-EXPR: unsigned, Value: 4
+// CHECK-EXPR: unsigned, Value: 1
}
CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
- if (const Expr *E =
- clang_getCursorKind(C) == CXCursor_CompoundStmt
- ? evaluateCompoundStmtExpr(cast<CompoundStmt>(getCursorStmt(C)))
- : evaluateDeclExpr(getCursorDecl(C)))
+ const Expr *E = nullptr;
+ if (clang_getCursorKind(C) == CXCursor_CompoundStmt)
+ E = evaluateCompoundStmtExpr(cast<CompoundStmt>(getCursorStmt(C)));
+ else if (clang_isDeclaration(C.kind))
+ E = evaluateDeclExpr(getCursorDecl(C));
+ else if (clang_isExpression(C.kind))
+ E = getCursorExpr(C);
+ if (E)
return const_cast<CXEvalResult>(
reinterpret_cast<const void *>(evaluateExpr(const_cast<Expr *>(E), C)));
return nullptr;