File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -5934,6 +5934,7 @@ typedef void *CXEvalResult;
5934
5934
* If cursor is a statement declaration tries to evaluate the
5935
5935
* statement and if its variable, tries to evaluate its initializer,
5936
5936
* into its corresponding type.
5937
+ * If it's an expression, tries to evaluate the expression.
5937
5938
*/
5938
5939
CINDEX_LINKAGE CXEvalResult clang_Cursor_Evaluate (CXCursor C );
5939
5940
Original file line number Diff line number Diff line change @@ -26,6 +26,9 @@ template <typename d> class e {
26
26
static const auto g = alignof(f);
27
27
};
28
28
29
+ constexpr static int calc_val () { return 1 + 2 ; }
30
+ const auto the_value = calc_val() + sizeof (char );
31
+
29
32
// RUN: c-index-test -evaluate-cursor-at=%s:4:7 \
30
33
// RUN: -evaluate-cursor-at=%s:8:7 \
31
34
// RUN: -evaluate-cursor-at=%s:8:11 -std=c++11 %s | FileCheck %s
@@ -53,3 +56,12 @@ template <typename d> class e {
53
56
// RUN: -evaluate-cursor-at=%s:26:21 \
54
57
// RUN: -std=c++11 %s | FileCheck -check-prefix=CHECK-DOES-NOT-CRASH %s
55
58
// CHECK-DOES-NOT-CRASH: Not Evaluatable
59
+
60
+ // RUN: c-index-test -evaluate-cursor-at=%s:30:1 \
61
+ // RUN: -evaluate-cursor-at=%s:30:32 \
62
+ // RUN: -evaluate-cursor-at=%s:30:35 \
63
+ // RUN: -evaluate-cursor-at=%s:30:37 -std=c++11 %s | FileCheck %s -check-prefix=CHECK-EXPR
64
+ // CHECK-EXPR: unsigned, Value: 4
65
+ // CHECK-EXPR: Value: 3
66
+ // CHECK-EXPR: unsigned, Value: 4
67
+ // CHECK-EXPR: unsigned, Value: 1
Original file line number Diff line number Diff line change @@ -4056,10 +4056,14 @@ static const Expr *evaluateCompoundStmtExpr(const CompoundStmt *CS) {
4056
4056
}
4057
4057
4058
4058
CXEvalResult clang_Cursor_Evaluate (CXCursor C) {
4059
- if (const Expr *E =
4060
- clang_getCursorKind (C) == CXCursor_CompoundStmt
4061
- ? evaluateCompoundStmtExpr (cast<CompoundStmt>(getCursorStmt (C)))
4062
- : evaluateDeclExpr (getCursorDecl (C)))
4059
+ const Expr *E = nullptr ;
4060
+ if (clang_getCursorKind (C) == CXCursor_CompoundStmt)
4061
+ E = evaluateCompoundStmtExpr (cast<CompoundStmt>(getCursorStmt (C)));
4062
+ else if (clang_isDeclaration (C.kind ))
4063
+ E = evaluateDeclExpr (getCursorDecl (C));
4064
+ else if (clang_isExpression (C.kind ))
4065
+ E = getCursorExpr (C);
4066
+ if (E)
4063
4067
return const_cast <CXEvalResult>(
4064
4068
reinterpret_cast <const void *>(evaluateExpr (const_cast <Expr *>(E), C)));
4065
4069
return nullptr ;
You can’t perform that action at this time.
0 commit comments