* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
*/
#define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 7
+#define CINDEX_VERSION_MINOR 8
#define CINDEX_VERSION_ENCODE(major, minor) ( \
((major) * 10000) \
*/
CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
+/**
+ * \brief Retrieve the bit width of a bit field declaration as an integer.
+ *
+ * If a cursor that is not a bit field declaration is passed in, -1 is returned.
+ */
+CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
+
/**
* \brief Retrieve the number of non-variadic arguments associated with a given
* cursor.
--- /dev/null
+union S {
+ unsigned ac : 4;
+ unsigned : 4;
+ unsigned clock : 1;
+ unsigned : 0;
+ unsigned flag : 1;
+};
+
+struct X {
+ unsigned light : 1;
+ unsigned toaster : 1;
+ int count;
+ union S stat;
+};
+
+// RUN: c-index-test -test-print-bitwidth %s | FileCheck %s
+// CHECK: FieldDecl=ac:2:12 (Definition) bitwidth=4
+// CHECK: FieldDecl=:3:3 (Definition) bitwidth=4
+// CHECK: FieldDecl=clock:4:12 (Definition) bitwidth=1
+// CHECK: FieldDecl=:5:3 (Definition) bitwidth=0
+// CHECK: FieldDecl=flag:6:12 (Definition) bitwidth=1
+// CHECK: FieldDecl=light:10:12 (Definition) bitwidth=1
+// CHECK: FieldDecl=toaster:11:12 (Definition) bitwidth=1
+// CHECK-NOT: count
+// CHECK-NOT: stat
return CXChildVisit_Recurse;
}
+/******************************************************************************/
+/* Bitwidth testing. */
+/******************************************************************************/
+
+static enum CXChildVisitResult PrintBitWidth(CXCursor cursor, CXCursor p,
+ CXClientData d) {
+ if (clang_getCursorKind(cursor) != CXCursor_FieldDecl)
+ return CXChildVisit_Recurse;
+
+ int Bitwidth = clang_getFieldDeclBitWidth(cursor);
+ if (Bitwidth >= 0) {
+ PrintCursor(cursor, NULL);
+ printf(" bitwidth=%d\n", Bitwidth);
+ }
+
+ return CXChildVisit_Recurse;
+}
/******************************************************************************/
/* Loading ASTs/source. */
fprintf(stderr,
" c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-typekind {<args>}*\n"
+ " c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n"
" c-index-test -write-pch <file> <compiler arguments>\n");
else if (argc > 2 && strcmp(argv[1], "-test-print-typekind") == 0)
return perform_test_load_source(argc - 2, argv + 2, "all",
PrintTypeKind, 0);
+ else if (argc > 2 && strcmp(argv[1], "-test-print-bitwidth") == 0)
+ return perform_test_load_source(argc - 2, argv + 2, "all",
+ PrintBitWidth, 0);
else if (argc > 1 && strcmp(argv[1], "-print-usr") == 0) {
if (argc > 2)
return print_usrs(argv + 2, argv + argc);
return ULLONG_MAX;
}
+int clang_getFieldDeclBitWidth(CXCursor C) {
+ using namespace cxcursor;
+
+ if (clang_isDeclaration(C.kind)) {
+ Decl *D = getCursorDecl(C);
+
+ if (FieldDecl *FD = dyn_cast_or_null<FieldDecl>(D)) {
+ if (FD->isBitField())
+ return FD->getBitWidthValue(getCursorContext(C));
+ }
+ }
+
+ return -1;
+}
+
CXType clang_getCanonicalType(CXType CT) {
if (CT.kind == CXType_Invalid)
return CT;
clang_getEnumConstantDeclUnsignedValue
clang_getEnumConstantDeclValue
clang_getEnumDeclIntegerType
+clang_getFieldDeclBitWidth
clang_getExpansionLocation
clang_getFile
clang_getFileName