diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 710f7377ee32..8197cf72a870 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -32,7 +32,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 35 +#define CINDEX_VERSION_MINOR 36 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 10000) \ @@ -2404,8 +2404,12 @@ enum CXCursorKind { * \brief A static_assert or _Static_assert node */ CXCursor_StaticAssert = 602, + /** + * \brief a friend declaration. + */ + CXCursor_FriendDecl = 603, CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl, - CXCursor_LastExtraDecl = CXCursor_StaticAssert, + CXCursor_LastExtraDecl = CXCursor_FriendDecl, /** * \brief A code completion overload candidate. diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index f2b85b6da872..445b8b4597a2 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -3100,6 +3100,7 @@ CXCursorKind clang::getCursorKindForDecl(const Decl *D) { return CXCursor_ClassTemplatePartialSpecialization; case Decl::UsingDirective: return CXCursor_UsingDirective; case Decl::StaticAssert: return CXCursor_StaticAssert; + case Decl::Friend: return CXCursor_FriendDecl; case Decl::TranslationUnit: return CXCursor_TranslationUnit; case Decl::Using: diff --git a/clang/test/Index/load-classes.cpp b/clang/test/Index/load-classes.cpp index f527db521089..8b1ed317e3be 100644 --- a/clang/test/Index/load-classes.cpp +++ b/clang/test/Index/load-classes.cpp @@ -18,13 +18,18 @@ private: virtual void virtualMemberFunction(); virtual void pureVirtualMemberFunction() = 0; + + friend void friendFunction(); + template + friend void friendFunctionTemplate(); + friend class F; }; 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 - 21:2] +// CHECK: load-classes.cpp:3:8: StructDecl=X:3:8 (Definition) Extent=[3:1 - 26:2] // CHECK: load-classes.cpp:4:3: CXXConstructor=X:4:3 (converting constructor) 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] @@ -46,7 +51,14 @@ X::X(int value) { // CHECK: load-classes.cpp:16:21: TemplateTypeParameter=T:16:21 (Definition) Extent=[16:12 - 16:22] [access=public] // CHECK: load-classes.cpp:19:16: CXXMethod=virtualMemberFunction:19:16 (virtual) Extent=[19:3 - 19:39] [access=private] // CHECK: load-classes.cpp:20:16: CXXMethod=pureVirtualMemberFunction:20:16 (virtual) (pure) Extent=[20:3 - 20:47] [access=private] -// CHECK: load-classes.cpp:23:4: CXXConstructor=X:23:4 (Definition) (converting constructor) Extent=[23:1 - 24:2] [access=public] -// CHECK: load-classes.cpp:23:1: TypeRef=struct X:3:8 Extent=[23:1 - 23:2] -// CHECK: load-classes.cpp:23:10: ParmDecl=value:23:10 (Definition) Extent=[23:6 - 23:15] -// CHECK: load-classes.cpp:23:17: CompoundStmt= Extent=[23:17 - 24:2] +// CHECK: load-classes.cpp:22:15: FriendDecl=:22:15 Extent=[22:3 - 22:31] [access=public] +// CHECK: load-classes.cpp:22:15: FunctionDecl=friendFunction:22:15 Extent=[22:3 - 22:31] [access=public] +// CHECK: load-classes.cpp:24:15: FriendDecl=:24:15 Extent=[23:3 - 24:39] [access=public] +// CHECK: load-classes.cpp:24:15: FunctionTemplate=friendFunctionTemplate:24:15 Extent=[23:3 - 24:39] [access=public] +// CHECK: load-classes.cpp:23:22: TemplateTypeParameter=T:23:22 (Definition) Extent=[23:13 - 23:23] [access=public] +// CHECK: load-classes.cpp:25:10: FriendDecl=:25:10 Extent=[25:3 - 25:17] [access=public] +// CHECK: load-classes.cpp:25:16: TypeRef=class F:25:16 Extent=[25:16 - 25:17] +// CHECK: load-classes.cpp:28:4: CXXConstructor=X:28:4 (Definition) (converting constructor) Extent=[28:1 - 29:2] [access=public] +// CHECK: load-classes.cpp:28:1: TypeRef=struct X:3:8 Extent=[28:1 - 28:2] +// CHECK: load-classes.cpp:28:10: ParmDecl=value:28:10 (Definition) Extent=[28:6 - 28:15] +// CHECK: load-classes.cpp:28:17: CompoundStmt= Extent=[28:17 - 29:2] diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 284373c149bb..17fe88b631b6 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -1249,6 +1249,17 @@ bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) { return false; } +bool CursorVisitor::VisitFriendDecl(FriendDecl *D) { + if (NamedDecl *FriendD = D->getFriendDecl()) { + if (Visit(MakeCXCursor(FriendD, TU, RegionOfInterest))) + return true; + } else if (TypeSourceInfo *TI = D->getFriendType()) { + if (Visit(TI->getTypeLoc())) + return true; + } + return false; +} + bool CursorVisitor::VisitDeclarationNameInfo(DeclarationNameInfo Name) { switch (Name.getName().getNameKind()) { case clang::DeclarationName::Identifier: @@ -4923,6 +4934,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { return cxstring::createRef("TypeAliasTemplateDecl"); case CXCursor_StaticAssert: return cxstring::createRef("StaticAssert"); + case CXCursor_FriendDecl: + return cxstring::createRef("FriendDecl"); } llvm_unreachable("Unhandled CXCursorKind"); diff --git a/clang/tools/libclang/CursorVisitor.h b/clang/tools/libclang/CursorVisitor.h index a2dfaeedccc8..82f251a348f0 100644 --- a/clang/tools/libclang/CursorVisitor.h +++ b/clang/tools/libclang/CursorVisitor.h @@ -239,7 +239,8 @@ public: bool VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); bool VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); bool VisitStaticAssertDecl(StaticAssertDecl *D); - + bool VisitFriendDecl(FriendDecl *D); + // Name visitor bool VisitDeclarationNameInfo(DeclarationNameInfo Name); bool VisitNestedNameSpecifier(NestedNameSpecifier *NNS, SourceRange Range);