Author: compnerd Date: Tue Oct 27 10:50:22 2015 New Revision: 251410 URL: http://llvm.org/viewvc/llvm-project?rev=251410&view=rev Log: Index: expose is_mutable_field
Expose isMutable via libClang and python bindings. Patch by Jonathan B Coe! Modified: cfe/trunk/bindings/python/clang/cindex.py cfe/trunk/bindings/python/tests/cindex/test_cursor.py cfe/trunk/include/clang-c/Index.h cfe/trunk/test/Index/index-file.cpp cfe/trunk/tools/c-index-test/c-index-test.c cfe/trunk/tools/libclang/CIndex.cpp cfe/trunk/tools/libclang/libclang.exports Modified: cfe/trunk/bindings/python/clang/cindex.py URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=251410&r1=251409&r2=251410&view=diff ============================================================================== --- cfe/trunk/bindings/python/clang/cindex.py (original) +++ cfe/trunk/bindings/python/clang/cindex.py Tue Oct 27 10:50:22 2015 @@ -1170,6 +1170,12 @@ class Cursor(Structure): """ return conf.lib.clang_CXXMethod_isConst(self) + def is_mutable_field(self): + """Returns True if the cursor refers to a C++ field that is declared + 'mutable'. + """ + return conf.lib.clang_CXXField_isMutable(self) + def is_pure_virtual_method(self): """Returns True if the cursor refers to a C++ member function or member function template that is declared pure virtual. @@ -2897,6 +2903,10 @@ functionList = [ [Index, c_char_p], c_object_p), + ("clang_CXXField_isMutable", + [Cursor], + bool), + ("clang_CXXMethod_isConst", [Cursor], bool), Modified: cfe/trunk/bindings/python/tests/cindex/test_cursor.py URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cursor.py?rev=251410&r1=251409&r2=251410&view=diff ============================================================================== --- cfe/trunk/bindings/python/tests/cindex/test_cursor.py (original) +++ cfe/trunk/bindings/python/tests/cindex/test_cursor.py Tue Oct 27 10:50:22 2015 @@ -112,6 +112,21 @@ def test_is_const_method(): assert foo.is_const_method() assert not bar.is_const_method() +def test_is_mutable_field(): + """Ensure Cursor.is_mutable_field works.""" + source = 'class X { int x_; mutable int y_; };' + tu = get_tu(source, lang='cpp') + + cls = get_cursor(tu, 'X') + x_ = get_cursor(tu, 'x_') + y_ = get_cursor(tu, 'y_') + assert cls is not None + assert x_ is not None + assert y_ is not None + + assert not x_.is_mutable_field() + assert y_.is_mutable_field() + def test_is_static_method(): """Ensure Cursor.is_static_method works.""" Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=251410&r1=251409&r2=251410&view=diff ============================================================================== --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Tue Oct 27 10:50:22 2015 @@ -3957,6 +3957,11 @@ CXFile clang_Module_getTopLevelHeader(CX */ /** + * \brief Determine if a C++ field is declared 'mutable'. + */ +CINDEX_LINKAGE unsigned clang_CXXField_isMutable(CXCursor C); + +/** * \brief Determine if a C++ member function or member function template is * pure virtual. */ Modified: cfe/trunk/test/Index/index-file.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-file.cpp?rev=251410&r1=251409&r2=251410&view=diff ============================================================================== --- cfe/trunk/test/Index/index-file.cpp (original) +++ cfe/trunk/test/Index/index-file.cpp Tue Oct 27 10:50:22 2015 @@ -24,6 +24,10 @@ template <> void A<int>::meth(); template class A<int>; } +class B { + mutable int x_; + int y_; +}; // RUN: c-index-test -index-file %s > %t // RUN: FileCheck %s -input-file=%t @@ -31,3 +35,5 @@ template class A<int>; // CHECK: [indexDeclaration]: kind: struct-template-spec | name: TS | {{.*}} | loc: 11:8 // CHECK: [indexDeclaration]: kind: function-template-spec | name: tfoo | {{.*}} | loc: 15:6 // CHECK: [indexDeclaration]: kind: c++-instance-method | name: meth | {{.*}} | loc: 23:26 +// CHECK: [indexDeclaration]: kind: field | name: x_ | USR: c:@S@B@FI@x_ | lang: C++ | cursor: FieldDecl=x_:28:15 (Definition) (mutable) | loc: 28:15 | semantic-container: [B:27:7] | lexical-container: [B:27:7] | isRedecl: 0 | isDef: 1 | isContainer: 0 | isImplicit: 0 +// CHECK: [indexDeclaration]: kind: field | name: y_ | USR: c:@S@B@FI@y_ | lang: C++ | cursor: FieldDecl=y_:29:7 (Definition) | loc: 29:7 | semantic-container: [B:27:7] | lexical-container: [B:27:7] | isRedecl: 0 | isDef: 1 | isContainer: 0 | isImplicit: 0 Modified: cfe/trunk/tools/c-index-test/c-index-test.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=251410&r1=251409&r2=251410&view=diff ============================================================================== --- cfe/trunk/tools/c-index-test/c-index-test.c (original) +++ cfe/trunk/tools/c-index-test/c-index-test.c Tue Oct 27 10:50:22 2015 @@ -767,6 +767,8 @@ static void PrintCursor(CXCursor Cursor, clang_disposeString(DeprecatedMessage); clang_disposeString(UnavailableMessage); + if (clang_CXXField_isMutable(Cursor)) + printf(" (mutable)"); if (clang_CXXMethod_isStatic(Cursor)) printf(" (static)"); if (clang_CXXMethod_isVirtual(Cursor)) Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=251410&r1=251409&r2=251410&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Tue Oct 27 10:50:22 2015 @@ -6888,6 +6888,16 @@ CXFile clang_Module_getTopLevelHeader(CX //===----------------------------------------------------------------------===// extern "C" { +unsigned clang_CXXField_isMutable(CXCursor C) { + if (!clang_isDeclaration(C.kind)) + return 0; + + if (const auto D = cxcursor::getCursorDecl(C)) + if (const auto FD = dyn_cast_or_null<FieldDecl>(D)) + return FD->isMutable() ? 1 : 0; + return 0; +} + unsigned clang_CXXMethod_isPureVirtual(CXCursor C) { if (!clang_isDeclaration(C.kind)) return 0; Modified: cfe/trunk/tools/libclang/libclang.exports URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=251410&r1=251409&r2=251410&view=diff ============================================================================== --- cfe/trunk/tools/libclang/libclang.exports (original) +++ cfe/trunk/tools/libclang/libclang.exports Tue Oct 27 10:50:22 2015 @@ -2,6 +2,7 @@ clang_CXCursorSet_contains clang_CXCursorSet_insert clang_CXIndex_getGlobalOptions clang_CXIndex_setGlobalOptions +clang_CXXField_isMutable clang_CXXMethod_isConst clang_CXXMethod_isPureVirtual clang_CXXMethod_isStatic _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits