r179297 - [libclang] Have clang_getCXXAccessSpecifier() also return the access control of a C++ declaration within its parent scope.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Apr 11 10:02:10 PDT 2013
Author: akirtzidis
Date: Thu Apr 11 12:02:10 2013
New Revision: 179297
URL: http://llvm.org/viewvc/llvm-project?rev=179297&view=rev
Log:
[libclang] Have clang_getCXXAccessSpecifier() also return the access control of a C++ declaration within its parent scope.
Suggested by Stefan Seefeld.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/test/Index/load-classes.cpp
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/CIndexCXX.cpp
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=179297&r1=179296&r2=179297&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Apr 11 12:02:10 2013
@@ -2995,9 +2995,10 @@ enum CX_CXXAccessSpecifier {
};
/**
- * \brief Returns the access control level for the C++ base specifier
- * represented by a cursor with kind CXCursor_CXXBaseSpecifier or
- * CXCursor_AccessSpecifier.
+ * \brief Returns the access control level for the referenced object.
+ * If the cursor refers to a C++ declaration, its access control level within its
+ * parent scope is returned. Otherwise, if the cursor refers to a base specifier or
+ * access specifier, the specifier itself is returned.
*/
CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
Modified: cfe/trunk/test/Index/load-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/load-classes.cpp?rev=179297&r1=179296&r2=179297&view=diff
==============================================================================
--- cfe/trunk/test/Index/load-classes.cpp (original)
+++ cfe/trunk/test/Index/load-classes.cpp Thu Apr 11 12:02:10 2013
@@ -3,7 +3,9 @@
struct X {
X(int value);
X(const X& x);
+protected:
~X();
+private:
operator X*();
};
@@ -11,18 +13,18 @@ X::X(int value) {
}
// RUN: c-index-test -test-load-source all %s | FileCheck %s
-// CHECK: load-classes.cpp:3:8: StructDecl=X:3:8 (Definition) Extent=[3:1 - 8:2]
-// CHECK: load-classes.cpp:4:3: CXXConstructor=X:4:3 Extent=[4:3 - 4:15]
+// CHECK: load-classes.cpp:3:8: StructDecl=X:3:8 (Definition) Extent=[3:1 - 10:2]
+// CHECK: load-classes.cpp:4:3: CXXConstructor=X:4:3 Extent=[4:3 - 4:15] [access=public]
// FIXME: missing TypeRef in the constructor name
// CHECK: load-classes.cpp:4:9: ParmDecl=value:4:9 (Definition) Extent=[4:5 - 4:14]
-// CHECK: load-classes.cpp:5:3: CXXConstructor=X:5:3 Extent=[5:3 - 5:16]
+// CHECK: load-classes.cpp:5:3: CXXConstructor=X:5:3 Extent=[5:3 - 5:16] [access=public]
// FIXME: missing TypeRef in the constructor name
// CHECK: load-classes.cpp:5:14: ParmDecl=x:5:14 (Definition) Extent=[5:5 - 5:15]
// CHECK: load-classes.cpp:5:11: TypeRef=struct X:3:8 Extent=[5:11 - 5:12]
-// CHECK: load-classes.cpp:6:3: CXXDestructor=~X:6:3 Extent=[6:3 - 6:7]
+// CHECK: load-classes.cpp:7:3: CXXDestructor=~X:7:3 Extent=[7:3 - 7:7] [access=protected]
// FIXME: missing TypeRef in the destructor name
-// CHECK: load-classes.cpp:7:3: CXXConversion=operator struct X *:7:3 Extent=[7:3 - 7:16]
-// CHECK: load-classes.cpp:7:12: TypeRef=struct X:3:8 Extent=[7:12 - 7:13]
-// CHECK: load-classes.cpp:10:4: CXXConstructor=X:10:4 (Definition) Extent=[10:1 - 11:2]
-// CHECK: load-classes.cpp:10:1: TypeRef=struct X:3:8 Extent=[10:1 - 10:2]
-// CHECK: load-classes.cpp:10:10: ParmDecl=value:10:10 (Definition) Extent=[10:6 - 10:15]
+// CHECK: load-classes.cpp:9:3: CXXConversion=operator struct X *:9:3 Extent=[9:3 - 9:16] [access=private]
+// CHECK: load-classes.cpp:9:12: TypeRef=struct X:3:8 Extent=[9:12 - 9:13]
+// CHECK: load-classes.cpp:12:4: CXXConstructor=X:12:4 (Definition) Extent=[12:1 - 13:2] [access=public]
+// CHECK: load-classes.cpp:12:1: TypeRef=struct X:3:8 Extent=[12:1 - 12:2]
+// CHECK: load-classes.cpp:12:10: ParmDecl=value:12:10 (Definition) Extent=[12:6 - 12:15]
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=179297&r1=179296&r2=179297&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Apr 11 12:02:10 2013
@@ -934,6 +934,23 @@ enum CXChildVisitResult FilteredPrinting
GetCursorSource(Cursor), line, column);
PrintCursor(Cursor, &Data->ValidationData);
PrintCursorExtent(Cursor);
+ if (clang_isDeclaration(Cursor.kind)) {
+ enum CX_CXXAccessSpecifier access = clang_getCXXAccessSpecifier(Cursor);
+ const char *accessStr = 0;
+
+ switch (access) {
+ case CX_CXXInvalidAccessSpecifier: break;
+ case CX_CXXPublic:
+ accessStr = "public"; break;
+ case CX_CXXProtected:
+ accessStr = "protected"; break;
+ case CX_CXXPrivate:
+ accessStr = "private"; break;
+ }
+
+ if (accessStr)
+ printf(" [access=%s]", accessStr);
+ }
printf("\n");
return CXChildVisit_Recurse;
}
Modified: cfe/trunk/tools/libclang/CIndexCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCXX.cpp?rev=179297&r1=179296&r2=179297&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCXX.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCXX.cpp Thu Apr 11 12:02:10 2013
@@ -33,7 +33,7 @@ unsigned clang_isVirtualBase(CXCursor C)
enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor C) {
AccessSpecifier spec = AS_none;
- if (C.kind == CXCursor_CXXAccessSpecifier)
+ if (C.kind == CXCursor_CXXAccessSpecifier || clang_isDeclaration(C.kind))
spec = getCursorDecl(C)->getAccess();
else if (C.kind == CXCursor_CXXBaseSpecifier)
spec = getCursorCXXBaseSpecifier(C)->getAccessSpecifier();
More information about the cfe-commits
mailing list