r338675 - Test commit access
Author: mwu Date: Thu Aug 2 00:28:11 2018 New Revision: 338675 URL: http://llvm.org/viewvc/llvm-project?rev=338675&view=rev Log: Test commit access Modified: cfe/trunk/include/clang-c/Index.h Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338675&r1=338674&r2=338675&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 00:28:11 2018 @@ -178,7 +178,6 @@ typedef struct CXVersion { * A negative value indicates that the cursor is not a function declaration. */ enum CXCursor_ExceptionSpecificationKind { - /** * The cursor has no exception specification. */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r338804 - [libclang 1/8] Add support for ObjCObjectType
Author: mwu Date: Thu Aug 2 20:03:20 2018 New Revision: 338804 URL: http://llvm.org/viewvc/llvm-project?rev=338804&view=rev Log: [libclang 1/8] Add support for ObjCObjectType Summary: This patch adds support to the clang-c API for identifying ObjCObjects in CXTypes, enumerating type args and protocols on ObjCObjectTypes, and retrieving the base type of ObjCObjectTypes. Currently only ObjCInterfaceTypes are exposed, which do not have type args or protocols. Reviewers: yvvan, jbcoe Reviewed By: yvvan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49063 Added: cfe/trunk/test/Index/objc-typeargs-protocols.m Modified: cfe/trunk/include/clang-c/Index.h cfe/trunk/test/Index/print-type.m cfe/trunk/tools/c-index-test/c-index-test.c cfe/trunk/tools/libclang/CXType.cpp cfe/trunk/tools/libclang/libclang.exports Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338804&r1=338803&r2=338804&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 20:03:20 2018 @@ -3265,7 +3265,9 @@ enum CXTypeKind { CXType_OCLSampler = 157, CXType_OCLEvent = 158, CXType_OCLQueue = 159, - CXType_OCLReserveID = 160 + CXType_OCLReserveID = 160, + + CXType_ObjCObject = 161 }; /** @@ -3627,6 +3629,43 @@ CINDEX_LINKAGE int clang_getNumArgTypes( CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i); /** + * Retrieves the base type of the ObjCObjectType. + * + * If the type is not an ObjC object, an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_Type_getObjCObjectBaseType(CXType T); + +/** + * Retrieve the number of protocol references associated with an ObjC object/id. + * + * If the type is not an ObjC object, 0 is returned. + */ +CINDEX_LINKAGE unsigned clang_Type_getNumObjCProtocolRefs(CXType T); + +/** + * Retrieve the decl for a protocol reference for an ObjC object/id. + * + * If the type is not an ObjC object or there are not enough protocol + * references, an invalid cursor is returned. + */ +CINDEX_LINKAGE CXCursor clang_Type_getObjCProtocolDecl(CXType T, unsigned i); + +/** + * Retreive the number of type arguments associated with an ObjC object. + * + * If the type is not an ObjC object, 0 is returned. + */ +CINDEX_LINKAGE unsigned clang_Type_getNumObjCTypeArgs(CXType T); + +/** + * Retrieve a type argument associated with an ObjC object. + * + * If the type is not an ObjC or the index is not valid, + * an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_Type_getObjCTypeArg(CXType T, unsigned i); + +/** * Return 1 if the CXType is a variadic function type, and 0 otherwise. */ CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T); Added: cfe/trunk/test/Index/objc-typeargs-protocols.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/objc-typeargs-protocols.m?rev=338804&view=auto == --- cfe/trunk/test/Index/objc-typeargs-protocols.m (added) +++ cfe/trunk/test/Index/objc-typeargs-protocols.m Thu Aug 2 20:03:20 2018 @@ -0,0 +1,28 @@ + +@interface TestA +@end + +@interface TestB +@end + +@protocol Bar +@end + +@interface Base +@end + +@interface Foo : Base +@end + +Foo *a; +Foo *b; +Foo *c; +Foo *d; +id e; + +// RUN: c-index-test -test-print-type %s | FileCheck %s +// CHECK: VarDecl=a:17:6 [type=Foo *] [typekind=ObjCObjectPointer] [basetype=Foo] [basekind=ObjCInterface] [isPOD=1] [pointeetype=Foo] [pointeekind=ObjCInterface] +// CHECK: VarDecl=b:18:24 [type=Foo *] [typekind=ObjCObjectPointer] [basetype=Foo] [basekind=ObjCInterface] [typeargs= [TestA *] [ObjCObjectPointer] [TestB *] [ObjCObjectPointer]] [isPOD=1] [pointeetype=Foo] [pointeekind=ObjCObject] +// CHECK: VarDecl=c:19:11 [type=Foo *] [typekind=ObjCObjectPointer] [basetype=Foo] [basekind=ObjCInterface] [protocols=ObjCProtocolDecl=Bar:8:11 (Definition)] [isPOD=1] [pointeetype=Foo] [pointeekind=ObjCObject] +// CHECK: VarDecl=d:20:29 [type=Foo *] [typekind=ObjCObjectPointer] [basetype=Foo] [basekind=ObjCInterface] [typeargs= [TestA *] [ObjCObjectPointer] [TestB *] [ObjCObjectPointer]] [protocols=ObjCProtocolDecl=Bar:8:11 (Definition)] [isPOD=1] [pointeetype=Foo] [pointeekind=ObjCObject] +// CHECK: VarDecl=e:21:9 [type=id] [typekind=ObjCObjectPointer] [basetype=id] [basekind=ObjCId] [protocols=ObjCProtocolDecl=Bar:8:11 (Definition)] [isPOD=1] [pointeetype=id] [pointeekind=ObjCObject] Modified: cfe/trunk/test/Index/print-type.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.m?rev=338804&r1=338803&r2=338804&view=diff == --- cfe/trunk/test/Index/print-type.m (original) +++ cfe/trunk/test/Index/print-type.m Thu Aug 2 20:03:20 2018 @@ -15,5 +15,5 @@ // CHEC
r338807 - [libclang 2/8] Add support for ObjCTypeParam
Author: mwu Date: Thu Aug 2 21:02:40 2018 New Revision: 338807 URL: http://llvm.org/viewvc/llvm-project?rev=338807&view=rev Log: [libclang 2/8] Add support for ObjCTypeParam Summary: This patch adds support to the libclang API for identifying ObjCTypeParams in CXTypes. This patch depends on D49063 since both patches add new values to CXTypeKind. Reviewers: yvvan, jbcoe Reviewed By: yvvan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49066 Modified: cfe/trunk/include/clang-c/Index.h cfe/trunk/test/Index/print-type.m cfe/trunk/tools/libclang/CXType.cpp Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338807&r1=338806&r2=338807&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 21:02:40 2018 @@ -3267,7 +3267,8 @@ enum CXTypeKind { CXType_OCLQueue = 159, CXType_OCLReserveID = 160, - CXType_ObjCObject = 161 + CXType_ObjCObject = 161, + CXType_ObjCTypeParam = 162 }; /** Modified: cfe/trunk/test/Index/print-type.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.m?rev=338807&r1=338806&r2=338807&view=diff == --- cfe/trunk/test/Index/print-type.m (original) +++ cfe/trunk/test/Index/print-type.m Thu Aug 2 21:02:40 2018 @@ -7,6 +7,10 @@ @property (class) int classProp; @end +@interface Bar : Foo +-(SomeType)generic; +@end + // RUN: c-index-test -test-print-type %s | FileCheck %s // CHECK: ObjCPropertyDecl=x:2:25 [readonly,] [type=id] [typekind=ObjCId] [canonicaltype=id] [canonicaltypekind=ObjCObjectPointer] [isPOD=1] // CHECK: ObjCInstanceMethodDecl=mymethod:3:8 [type=] [typekind=Invalid] [resulttype=int] [resulttypekind=Int] [isPOD=0] @@ -17,3 +21,4 @@ // CHECK: ParmDecl=j:5:49 (Definition) [Out,] [type=short *] [typekind=Pointer] [isPOD=1] [pointeetype=short] [pointeekind=Short] // CHECK: ParmDecl=p:6:36 (Definition) [type=__kindof Foo *] [typekind=ObjCObjectPointer] [canonicaltype=__kindof Foo *] [canonicaltypekind=ObjCObjectPointer] [basetype=Foo] [basekind=ObjCInterface] [isPOD=1] [pointeetype=Foo] [pointeekind=ObjCInterface] // CHECK: ObjCPropertyDecl=classProp:7:23 [class,] [type=int] [typekind=Int] [isPOD=1] +// CHECK: ObjCInstanceMethodDecl=generic:11:12 [type=] [typekind=Invalid] [resulttype=SomeType] [resulttypekind=ObjCTypeParam] [isPOD=0] Modified: cfe/trunk/tools/libclang/CXType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=338807&r1=338806&r2=338807&view=diff == --- cfe/trunk/tools/libclang/CXType.cpp (original) +++ cfe/trunk/tools/libclang/CXType.cpp Thu Aug 2 21:02:40 2018 @@ -100,6 +100,7 @@ static CXTypeKind GetTypeKind(QualType T TKCASE(ObjCInterface); TKCASE(ObjCObject); TKCASE(ObjCObjectPointer); +TKCASE(ObjCTypeParam); TKCASE(FunctionNoProto); TKCASE(FunctionProto); TKCASE(ConstantArray); @@ -578,6 +579,7 @@ CXString clang_getTypeKindSpelling(enum TKIND(ObjCInterface); TKIND(ObjCObject); TKIND(ObjCObjectPointer); +TKIND(ObjCTypeParam); TKIND(FunctionNoProto); TKIND(FunctionProto); TKIND(ConstantArray); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r338808 - [libclang 3/8] Add support for AttributedType
Author: mwu Date: Thu Aug 2 21:21:25 2018 New Revision: 338808 URL: http://llvm.org/viewvc/llvm-project?rev=338808&view=rev Log: [libclang 3/8] Add support for AttributedType Summary: This patch adds support to the libclang API for identifying AttributedTypes in CXTypes and reading the modified type that the type points to. Currently AttributedTypes are skipped. This patch continues to skip AttributedTypes by default, but adds a parsing option to CXTranslationUnit to include AttributedTypes. This patch depends on D49066 since it also adds a CXType. Testing will be added in another patch which depends on this one. Reviewers: yvvan, jbcoe Reviewed By: yvvan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49081 Modified: cfe/trunk/include/clang-c/Index.h cfe/trunk/tools/libclang/CXType.cpp cfe/trunk/tools/libclang/libclang.exports Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338808&r1=338807&r2=338808&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 21:21:25 2018 @@ -1331,7 +1331,12 @@ enum CXTranslationUnit_Flags { * * The function bodies of the main file are not skipped. */ - CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800 + CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800, + + /** + * Used to indicate that attributed types should be included in CXType. + */ + CXTranslationUnit_IncludeAttributedTypes = 0x1000 }; /** @@ -3268,7 +3273,8 @@ enum CXTypeKind { CXType_OCLReserveID = 160, CXType_ObjCObject = 161, - CXType_ObjCTypeParam = 162 + CXType_ObjCTypeParam = 162, + CXType_Attributed = 163 }; /** @@ -3818,6 +3824,13 @@ CINDEX_LINKAGE long long clang_Type_getS CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S); /** + * Return the type that was modified by this attributed type. + * + * If the type is not an attributed type, an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_Type_getModifiedType(CXType T); + +/** * Return the offset of the field represented by the Cursor. * * If the cursor is not a field declaration, -1 is returned. Modified: cfe/trunk/tools/libclang/CXType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=338808&r1=338807&r2=338808&view=diff == --- cfe/trunk/tools/libclang/CXType.cpp (original) +++ cfe/trunk/tools/libclang/CXType.cpp Thu Aug 2 21:21:25 2018 @@ -112,6 +112,7 @@ static CXTypeKind GetTypeKind(QualType T TKCASE(Auto); TKCASE(Elaborated); TKCASE(Pipe); +TKCASE(Attributed); default: return CXType_Unexposed; } @@ -125,7 +126,9 @@ CXType cxtype::MakeCXType(QualType T, CX if (TU && !T.isNull()) { // Handle attributed types as the original type if (auto *ATT = T->getAs()) { - return MakeCXType(ATT->getModifiedType(), TU); + if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes)) { +return MakeCXType(ATT->getModifiedType(), TU); + } } // Handle paren types as the original type if (auto *PTT = T->getAs()) { @@ -591,6 +594,7 @@ CXString clang_getTypeKindSpelling(enum TKIND(Auto); TKIND(Elaborated); TKIND(Pipe); +TKIND(Attributed); #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) TKIND(Id); #include "clang/Basic/OpenCLImageTypes.def" #undef IMAGE_TYPE @@ -996,6 +1000,17 @@ long long clang_Type_getOffsetOf(CXType return CXTypeLayoutError_InvalidFieldName; } +CXType clang_Type_getModifiedType(CXType CT) { + QualType T = GetQualType(CT); + if (T.isNull()) +return MakeCXType(QualType(), GetTU(CT)); + + if (auto *ATT = T->getAs()) +return MakeCXType(ATT->getModifiedType(), GetTU(CT)); + + return MakeCXType(QualType(), GetTU(CT)); +} + long long clang_Cursor_getOffsetOfField(CXCursor C) { if (clang_isDeclaration(C.kind)) { // we need to validate the parent type Modified: cfe/trunk/tools/libclang/libclang.exports URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=338808&r1=338807&r2=338808&view=diff == --- cfe/trunk/tools/libclang/libclang.exports (original) +++ cfe/trunk/tools/libclang/libclang.exports Thu Aug 2 21:21:25 2018 @@ -103,6 +103,7 @@ clang_Type_getNumObjCProtocolRefs clang_Type_getObjCProtocolDecl clang_Type_getNumObjCTypeArgs clang_Type_getObjCTypeArg +clang_Type_getModifiedType clang_VerbatimBlockLineComment_getText clang_VerbatimLineComment_getText clang_HTMLTagComment_getAsString ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listin
r338809 - [libclang 4/8] Add the clang_Type_getNullability() API
Author: mwu Date: Thu Aug 2 21:38:04 2018 New Revision: 338809 URL: http://llvm.org/viewvc/llvm-project?rev=338809&view=rev Log: [libclang 4/8] Add the clang_Type_getNullability() API Summary: This patch adds a clang-c API for querying the nullability of an AttributedType. The test here also tests D49081 Reviewers: yvvan, jbcoe Reviewed By: yvvan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49082 Added: cfe/trunk/test/Index/nullability.c Modified: cfe/trunk/include/clang-c/Index.h cfe/trunk/tools/c-index-test/c-index-test.c cfe/trunk/tools/libclang/CXType.cpp cfe/trunk/tools/libclang/libclang.exports Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338809&r1=338808&r2=338809&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 21:38:04 2018 @@ -3745,6 +3745,33 @@ CINDEX_LINKAGE CXType clang_Type_getName */ CINDEX_LINKAGE unsigned clang_Type_isTransparentTagTypedef(CXType T); +enum CXTypeNullabilityKind { + /** + * Values of this type can never be null. + */ + CXTypeNullability_NonNull = 0, + /** + * Values of this type can be null. + */ + CXTypeNullability_Nullable = 1, + /** + * Whether values of this type can be null is (explicitly) + * unspecified. This captures a (fairly rare) case where we + * can't conclude anything about the nullability of the type even + * though it has been considered. + */ + CXTypeNullability_Unspecified = 2, + /** + * Nullability is not applicable to this type. + */ + CXTypeNullability_Invalid = 3 +}; + +/** + * Retrieve the nullability kind of a pointer type. + */ +CINDEX_LINKAGE enum CXTypeNullabilityKind clang_Type_getNullability(CXType T); + /** * List the possible error codes for \c clang_Type_getSizeOf, * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and Added: cfe/trunk/test/Index/nullability.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/nullability.c?rev=338809&view=auto == --- cfe/trunk/test/Index/nullability.c (added) +++ cfe/trunk/test/Index/nullability.c Thu Aug 2 21:38:04 2018 @@ -0,0 +1,10 @@ +int *a; +int * _Nonnull b; +int * _Nullable c; +int * _Null_unspecified d; + +// RUN: env CINDEXTEST_INCLUDE_ATTRIBUTED_TYPES=1 c-index-test -test-print-type %s | FileCheck %s +// CHECK: VarDecl=a:1:6 [type=int *] [typekind=Pointer] [isPOD=1] [pointeetype=int] [pointeekind=Int] +// CHECK: VarDecl=b:2:16 [type=int * _Nonnull] [typekind=Attributed] [nullability=nonnull] [canonicaltype=int *] [canonicaltypekind=Pointer] [modifiedtype=int *] [modifiedtypekind=Pointer] [isPOD=1] +// CHECK: VarDecl=c:3:17 [type=int * _Nullable] [typekind=Attributed] [nullability=nullable] [canonicaltype=int *] [canonicaltypekind=Pointer] [modifiedtype=int *] [modifiedtypekind=Pointer] [isPOD=1] +// CHECK: VarDecl=d:4:25 [type=int * _Null_unspecified] [typekind=Attributed] [nullability=unspecified] [canonicaltype=int *] [canonicaltypekind=Pointer] [modifiedtype=int *] [modifiedtypekind=Pointer] [isPOD=1] 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=338809&r1=338808&r2=338809&view=diff == --- cfe/trunk/tools/c-index-test/c-index-test.c (original) +++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Aug 2 21:38:04 2018 @@ -84,6 +84,8 @@ static unsigned getDefaultParsingOptions options |= CXTranslationUnit_KeepGoing; if (getenv("CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE")) options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble; + if (getenv("CINDEXTEST_INCLUDE_ATTRIBUTED_TYPES")) +options |= CXTranslationUnit_IncludeAttributedTypes; return options; } @@ -1496,6 +1498,22 @@ static void PrintTypeTemplateArgs(CXType } } +static void PrintNullabilityKind(CXType T, const char *Format) { + enum CXTypeNullabilityKind N = clang_Type_getNullability(T); + + const char *nullability = 0; + switch (N) { +case CXTypeNullability_NonNull: nullability = "nonnull"; break; +case CXTypeNullability_Nullable: nullability = "nullable"; break; +case CXTypeNullability_Unspecified: nullability = "unspecified"; break; +case CXTypeNullability_Invalid: break; + } + + if (nullability) { +printf(Format, nullability); + } +} + static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p, CXClientData d) { if (!clang_isInvalid(clang_getCursorKind(cursor))) { @@ -1504,6 +1522,7 @@ static enum CXChildVisitResult PrintType enum CXRefQualifierKind RQ = clang_Type_getCXXRefQualifier(T); PrintCursor(cursor, NULL); Pr
r338813 - [libclang 5/8] Add support for ObjC attributes without args
Author: mwu Date: Thu Aug 2 22:03:22 2018 New Revision: 338813 URL: http://llvm.org/viewvc/llvm-project?rev=338813&view=rev Log: [libclang 5/8] Add support for ObjC attributes without args Summary: This adds support to libclang for identifying ObjC related attributes that don't take arguments. All attributes but NSObject and NSConsumed are tested. Reviewers: yvvan, jbcoe Reviewed By: yvvan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49127 Modified: cfe/trunk/include/clang-c/Index.h cfe/trunk/test/Index/index-attrs.m cfe/trunk/tools/libclang/CIndex.cpp cfe/trunk/tools/libclang/CXCursor.cpp Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338813&r1=338812&r2=338813&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 22:03:22 2018 @@ -2563,7 +2563,24 @@ enum CXCursorKind { CXCursor_VisibilityAttr= 417, CXCursor_DLLExport = 418, CXCursor_DLLImport = 419, - CXCursor_LastAttr = CXCursor_DLLImport, + CXCursor_NSReturnsRetained = 420, + CXCursor_NSReturnsNotRetained = 421, + CXCursor_NSReturnsAutoreleased = 422, + CXCursor_NSConsumesSelf= 423, + CXCursor_NSConsumed= 424, + CXCursor_ObjCException = 425, + CXCursor_ObjCNSObject = 426, + CXCursor_ObjCIndependentClass = 427, + CXCursor_ObjCPreciseLifetime = 428, + CXCursor_ObjCReturnsInnerPointer = 429, + CXCursor_ObjCRequiresSuper = 430, + CXCursor_ObjCRootClass = 431, + CXCursor_ObjCSubclassingRestricted = 432, + CXCursor_ObjCExplicitProtocolImpl = 433, + CXCursor_ObjCDesignatedInitializer = 434, + CXCursor_ObjCRuntimeVisible= 435, + CXCursor_ObjCBoxable = 436, + CXCursor_LastAttr = CXCursor_ObjCBoxable, /* Preprocessing */ CXCursor_PreprocessingDirective= 500, Modified: cfe/trunk/test/Index/index-attrs.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-attrs.m?rev=338813&r1=338812&r2=338813&view=diff == --- cfe/trunk/test/Index/index-attrs.m (original) +++ cfe/trunk/test/Index/index-attrs.m Thu Aug 2 22:03:22 2018 @@ -9,9 +9,48 @@ @property (assign) id prop __attribute__((annotate("anno"))); @end +__attribute__((objc_protocol_requires_explicit_implementation)) +@protocol P +@end + +typedef id __attribute__((objc_independent_class)) T2; +id __attribute__((objc_precise_lifetime)) x; +struct __attribute__((objc_boxable)) S { + int x; +}; + +__attribute__((objc_exception)) +__attribute__((objc_root_class)) +__attribute__((objc_subclassing_restricted)) +__attribute__((objc_runtime_visible)) +@interface J +-(id)a __attribute__((ns_returns_retained)); +-(id)b __attribute__((ns_returns_not_retained)); +-(id)c __attribute__((ns_returns_autoreleased)); +-(id)d __attribute__((ns_consumes_self)); +-(id)e __attribute__((objc_requires_super)); +-(int *)f __attribute__((objc_returns_inner_pointer)); +-(id)init __attribute__((objc_designated_initializer)); +@end + // RUN: c-index-test -index-file %s | FileCheck %s // CHECK: : attribute(iboutletcollection)= [IBOutletCollection=ObjCInterface] // CHECK: : attribute(annotate)=anno // CHECK: : kind: objc-instance-method | name: prop | {{.*}} : attribute(annotate)=anno // CHECK: : kind: objc-instance-method | name: setProp: | {{.*}} : attribute(annotate)=anno +// CHECK: : attribute(objc_protocol_requires_explicit_implementation)= +// CHECK: : attribute(objc_independent_class)= +// CHECK: : attribute(objc_precise_lifetime)= +// CHECK: : attribute(objc_boxable)= +// CHECK: : attribute(objc_exception)= +// CHECK: : attribute(objc_root_class)= +// CHECK: : attribute(objc_subclassing_restricted)= +// CHECK: : attribute(objc_runtime_visible)= +// CHECK: : attribute(ns_returns_retained)= +// CHECK: : attribute(ns_returns_not_retained)= +// CHECK: : attribute(ns_returns_autoreleased)= +// CHECK: : attribute(ns_consumes_self)= +// CHECK: : attribute(objc_requires_super)= +// CHECK: : attribute(objc_returns_inner_pointer)= +// CHECK: : attribute(objc_designated_initializer)= Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=338813&r1=338812&r2=338813&view=diff == --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Thu Aug 2 22:03:22 2018 @@ -5277,6 +5277,40 @@ CXString clang_getCursorKindSpelling(enu return cxstring::createRef("attribute(dlle
r338815 - [libclang 6/8] Add support for reading implicit attributes
Author: mwu Date: Thu Aug 2 22:20:23 2018 New Revision: 338815 URL: http://llvm.org/viewvc/llvm-project?rev=338815&view=rev Log: [libclang 6/8] Add support for reading implicit attributes Summary: Having access to implicit attributes is sometimes useful so users of libclang don't have to duplicate some of the logic in sema. This depends on D49081 since it also adds a CXTranslationUnit flag. Reviewers: yvvan, jbcoe Reviewed By: yvvan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49631 Added: cfe/trunk/test/Index/implicit-attrs.m Modified: cfe/trunk/include/clang-c/Index.h cfe/trunk/tools/c-index-test/c-index-test.c cfe/trunk/tools/libclang/CIndex.cpp Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338815&r1=338814&r2=338815&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 22:20:23 2018 @@ -1336,7 +1336,12 @@ enum CXTranslationUnit_Flags { /** * Used to indicate that attributed types should be included in CXType. */ - CXTranslationUnit_IncludeAttributedTypes = 0x1000 + CXTranslationUnit_IncludeAttributedTypes = 0x1000, + + /** + * Used to indicate that implicit attributes should be visited. + */ + CXTranslationUnit_VisitImplicitAttributes = 0x2000 }; /** Added: cfe/trunk/test/Index/implicit-attrs.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/implicit-attrs.m?rev=338815&view=auto == --- cfe/trunk/test/Index/implicit-attrs.m (added) +++ cfe/trunk/test/Index/implicit-attrs.m Thu Aug 2 22:20:23 2018 @@ -0,0 +1,6 @@ +@interface Foo +-(instancetype)init; +@end + +// RUN: env CINDEXTEST_VISIT_IMPLICIT_ATTRIBUTES=1 c-index-test -test-print-decl-attributes %s -fobjc-arc | FileCheck %s +// CHECK: ObjCInstanceMethodDecl=init:2:16 attribute(ns_consumes_self)= attribute(ns_returns_retained)= 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=338815&r1=338814&r2=338815&view=diff == --- cfe/trunk/tools/c-index-test/c-index-test.c (original) +++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Aug 2 22:20:23 2018 @@ -86,6 +86,8 @@ static unsigned getDefaultParsingOptions options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble; if (getenv("CINDEXTEST_INCLUDE_ATTRIBUTED_TYPES")) options |= CXTranslationUnit_IncludeAttributedTypes; + if (getenv("CINDEXTEST_VISIT_IMPLICIT_ATTRIBUTES")) +options |= CXTranslationUnit_VisitImplicitAttributes; return options; } @@ -1783,6 +1785,23 @@ static enum CXChildVisitResult PrintType } /**/ +/* Declaration attributes testing */ +/**/ + +static enum CXChildVisitResult PrintDeclAttributes(CXCursor cursor, CXCursor p, + CXClientData d) { + if (clang_isDeclaration(cursor.kind)) { +printf("\n"); +PrintCursor(cursor, NULL); +return CXChildVisit_Recurse; + } else if (clang_isAttribute(cursor.kind)) { +printf(" "); +PrintCursor(cursor, NULL); + } + return CXChildVisit_Continue; +} + +/**/ /* Target information testing. */ /**/ @@ -4793,6 +4812,9 @@ int cindextest_main(int argc, const char else if (argc > 2 && strcmp(argv[1], "-test-print-type-declaration") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintTypeDeclaration, 0); + else if (argc > 2 && strcmp(argv[1], "-test-print-decl-attributes") == 0) +return perform_test_load_source(argc - 2, argv + 2, "all", +PrintDeclAttributes, 0); else if (argc > 2 && strcmp(argv[1], "-test-print-bitwidth") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintBitWidth, 0); Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=338815&r1=338814&r2=338815&view=diff == --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Thu Aug 2 22:20:23 2018 @@ -1802,7 +1802,9 @@ bool CursorVisitor::VisitCXXRecordDecl(C bool CursorVisitor::VisitAttributes(Decl *D) { for
r338816 - [libclang 7/8] Add support for getting property setter and getter names
Author: mwu Date: Thu Aug 2 22:38:29 2018 New Revision: 338816 URL: http://llvm.org/viewvc/llvm-project?rev=338816&view=rev Log: [libclang 7/8] Add support for getting property setter and getter names Summary: This allows libclang to access the actual names of property setters and getters without needing to go through the indexer API. Usually default names are used, but the property can specify a different name. Reviewers: yvvan, jbcoe Reviewed By: yvvan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49634 Added: cfe/trunk/test/Index/property-getter-setter.m Modified: cfe/trunk/include/clang-c/Index.h 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/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338816&r1=338815&r2=338816&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 22:38:29 2018 @@ -4449,6 +4449,18 @@ CINDEX_LINKAGE unsigned clang_Cursor_get unsigned reserved); /** + * Given a cursor that represents a property declaration, return the + * name of the method that implements the getter. + */ +CINDEX_LINKAGE CXString clang_Cursor_getObjCPropertyGetterName(CXCursor C); + +/** + * Given a cursor that represents a property declaration, return the + * name of the method that implements the setter, if any. + */ +CINDEX_LINKAGE CXString clang_Cursor_getObjCPropertySetterName(CXCursor C); + +/** * 'Qualifiers' written next to the return and parameter types in * Objective-C method declarations. */ Added: cfe/trunk/test/Index/property-getter-setter.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/property-getter-setter.m?rev=338816&view=auto == --- cfe/trunk/test/Index/property-getter-setter.m (added) +++ cfe/trunk/test/Index/property-getter-setter.m Thu Aug 2 22:38:29 2018 @@ -0,0 +1,10 @@ +@interface Foo +@property (assign,readwrite,getter=b,setter=c:) id a; +@property (assign,readonly,getter=e) id d; +@property (assign,readwrite) id f; +@end + +// RUN: c-index-test -test-print-type-declaration %s | FileCheck %s +// CHECK: ObjCPropertyDecl=a:2:52 [getter,assign,readwrite,setter,] (getter=b) (setter=c:) [typedeclaration=id] [typekind=ObjCId] +// CHECK: ObjCPropertyDecl=d:3:41 [readonly,getter,assign,] (getter=e) [typedeclaration=id] [typekind=ObjCId] +// CHECK: ObjCPropertyDecl=f:4:33 [assign,readwrite,] [typedeclaration=id] [typekind=ObjCId] 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=338816&r1=338815&r2=338816&view=diff == --- cfe/trunk/tools/c-index-test/c-index-test.c (original) +++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Aug 2 22:38:29 2018 @@ -1103,6 +1103,34 @@ static void PrintCursor(CXCursor Cursor, } } +if (Cursor.kind == CXCursor_ObjCPropertyDecl) { + CXString Name = clang_Cursor_getObjCPropertyGetterName(Cursor); + CXString Spelling = clang_getCursorSpelling(Cursor); + const char *CName = clang_getCString(Name); + const char *CSpelling = clang_getCString(Spelling); + if (CName && strcmp(CName, CSpelling)) { +printf(" (getter=%s)", CName); + } + clang_disposeString(Spelling); + clang_disposeString(Name); +} + +if (Cursor.kind == CXCursor_ObjCPropertyDecl) { + CXString Name = clang_Cursor_getObjCPropertySetterName(Cursor); + CXString Spelling = clang_getCursorSpelling(Cursor); + const char *CName = clang_getCString(Name); + const char *CSpelling = clang_getCString(Spelling); + char *DefaultSetter = malloc(strlen(CSpelling) + 5); + sprintf(DefaultSetter, "set%s:", CSpelling); + DefaultSetter[3] &= ~(1 << 5); /* Make uppercase */ + if (CName && strcmp(CName, DefaultSetter)) { +printf(" (setter=%s)", CName); + } + free(DefaultSetter); + clang_disposeString(Spelling); + clang_disposeString(Name); +} + { unsigned QT = clang_Cursor_getObjCDeclQualifiers(Cursor); if (QT != CXObjCDeclQualifier_None) { Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=338816&r1=338815&r2=338816&view=diff == --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Thu Aug 2 22:38:29 2018 @@ -7913,6 +7913,30 @@ unsigned clang_Cursor_getObjCPropertyAtt return Result; } +CXString clang_Curso
r338820 - [libclang 8/8] Add support for the flag_enum attribute
Author: mwu Date: Thu Aug 2 22:55:40 2018 New Revision: 338820 URL: http://llvm.org/viewvc/llvm-project?rev=338820&view=rev Log: [libclang 8/8] Add support for the flag_enum attribute Summary: This adds support to libclang for reading the flag_enum attribute. This also bumps CINDEX_VERSION_MINOR for this patch series. Reviewers: yvvan, jbcoe Reviewed By: yvvan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49635 Modified: cfe/trunk/include/clang-c/Index.h cfe/trunk/test/Index/attributes.c cfe/trunk/tools/libclang/CIndex.cpp cfe/trunk/tools/libclang/CXCursor.cpp Modified: cfe/trunk/include/clang-c/Index.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338820&r1=338819&r2=338820&view=diff == --- cfe/trunk/include/clang-c/Index.h (original) +++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 22:55:40 2018 @@ -32,7 +32,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 49 +#define CINDEX_VERSION_MINOR 50 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 1) \ @@ -2585,7 +2585,8 @@ enum CXCursorKind { CXCursor_ObjCDesignatedInitializer = 434, CXCursor_ObjCRuntimeVisible= 435, CXCursor_ObjCBoxable = 436, - CXCursor_LastAttr = CXCursor_ObjCBoxable, + CXCursor_FlagEnum = 437, + CXCursor_LastAttr = CXCursor_FlagEnum, /* Preprocessing */ CXCursor_PreprocessingDirective= 500, Modified: cfe/trunk/test/Index/attributes.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/attributes.c?rev=338820&r1=338819&r2=338820&view=diff == --- cfe/trunk/test/Index/attributes.c (original) +++ cfe/trunk/test/Index/attributes.c Thu Aug 2 22:55:40 2018 @@ -8,6 +8,10 @@ void pure_fn() __attribute__((pure)); void const_fn() __attribute__((const)); void noduplicate_fn() __attribute__((noduplicate)); +enum __attribute((flag_enum)) FlagEnum { + Foo +}; + // CHECK: attributes.c:3:32: StructDecl=Test2:3:32 (Definition) Extent=[3:1 - 5:2] // CHECK: attributes.c:3:23: attribute(packed)=packed Extent=[3:23 - 3:29] // CHECK: attributes.c:4:8: FieldDecl=a:4:8 (Definition) Extent=[4:3 - 4:9] [access=public] @@ -18,3 +22,5 @@ void noduplicate_fn() __attribute__((nod // CHECK: attributes.c:8:32: attribute(const)= Extent=[8:32 - 8:37] // CHECK: attributes.c:9:6: FunctionDecl=noduplicate_fn:9:6 Extent=[9:1 - 9:51] // CHECK: attributes.c:9:38: attribute(noduplicate)= Extent=[9:38 - 9:49] +// CHECK: attributes.c:11:31: EnumDecl=FlagEnum:11:31 (Definition) Extent=[11:1 - 13:2] +// CHECK: attributes.c:11:19: attribute(flag_enum)= Extent=[11:19 - 11:28] Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=338820&r1=338819&r2=338820&view=diff == --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Thu Aug 2 22:55:40 2018 @@ -5313,6 +5313,8 @@ CXString clang_getCursorKindSpelling(enu return cxstring::createRef("attribute(objc_runtime_visible)"); case CXCursor_ObjCBoxable: return cxstring::createRef("attribute(objc_boxable)"); + case CXCursor_FlagEnum: +return cxstring::createRef("attribute(flag_enum)"); case CXCursor_PreprocessingDirective: return cxstring::createRef("preprocessing directive"); case CXCursor_MacroDefinition: Modified: cfe/trunk/tools/libclang/CXCursor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=338820&r1=338819&r2=338820&view=diff == --- cfe/trunk/tools/libclang/CXCursor.cpp (original) +++ cfe/trunk/tools/libclang/CXCursor.cpp Thu Aug 2 22:55:40 2018 @@ -78,6 +78,7 @@ static CXCursorKind GetCursorKind(const case attr::ObjCDesignatedInitializer: return CXCursor_ObjCDesignatedInitializer; case attr::ObjCRuntimeVisible: return CXCursor_ObjCRuntimeVisible; case attr::ObjCBoxable: return CXCursor_ObjCBoxable; +case attr::FlagEnum: return CXCursor_FlagEnum; } return CXCursor_UnexposedAttr; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r346633 - Support Swift in platform availability attribute
Author: mwu Date: Sun Nov 11 18:44:33 2018 New Revision: 346633 URL: http://llvm.org/viewvc/llvm-project?rev=346633&view=rev Log: Support Swift in platform availability attribute Summary: This adds support for Swift platform availability attributes. It's largely a port of the changes made to https://github.com/apple/swift-clang/ for Swift availability attributes. Specifically, https://github.com/apple/swift-clang/commit/84b5a21c31cb5b0d7d958a478bc01964939b6952 and https://github.com/apple/swift-clang/commit/e5b87f265aede41c8381094bbf54e2715c8293b0 . The implementation of attribute_availability_swift is a little different and additional tests in test/Index/availability.c were added. Reviewers: manmanren, friss, doug.gregor, arphaman, jfb, erik.pilkington, aaron.ballman Reviewed By: aaron.ballman Subscribers: aaron.ballman, ColinKinloch, jrmuizel, cfe-commits Differential Revision: https://reviews.llvm.org/D50318 Added: cfe/trunk/test/Sema/attr-availability-swift.c Modified: cfe/trunk/include/clang/Basic/Attr.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Basic/Features.def cfe/trunk/lib/Parse/ParseDecl.cpp cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/test/Index/availability.c Modified: cfe/trunk/include/clang/Basic/Attr.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=346633&r1=346632&r2=346633&view=diff == --- cfe/trunk/include/clang/Basic/Attr.td (original) +++ cfe/trunk/include/clang/Basic/Attr.td Sun Nov 11 18:44:33 2018 @@ -723,6 +723,7 @@ def Availability : InheritableAttr { .Case("macos_app_extension", "macOS (App Extension)") .Case("tvos_app_extension", "tvOS (App Extension)") .Case("watchos_app_extension", "watchOS (App Extension)") + .Case("swift", "Swift") .Default(llvm::StringRef()); } static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) { Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=346633&r1=346632&r2=346633&view=diff == --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Nov 11 18:44:33 2018 @@ -2993,6 +2993,9 @@ def warn_availability_on_static_initiali InGroup; def note_overridden_method : Note< "overridden method is here">; +def warn_availability_swift_unavailable_deprecated_only : Warning< + "only 'unavailable' and 'deprecated' are supported for Swift availability">, + InGroup; def note_protocol_method : Note< "protocol method is here">; Modified: cfe/trunk/include/clang/Basic/Features.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Features.def?rev=346633&r1=346632&r2=346633&view=diff == --- cfe/trunk/include/clang/Basic/Features.def (original) +++ cfe/trunk/include/clang/Basic/Features.def Sun Nov 11 18:44:33 2018 @@ -51,6 +51,7 @@ FEATURE(attribute_availability_watchos, FEATURE(attribute_availability_with_strict, true) FEATURE(attribute_availability_with_replacement, true) FEATURE(attribute_availability_in_templates, true) +FEATURE(attribute_availability_swift, true) FEATURE(attribute_cf_returns_not_retained, true) FEATURE(attribute_cf_returns_retained, true) FEATURE(attribute_cf_returns_on_parameters, true) Modified: cfe/trunk/lib/Parse/ParseDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=346633&r1=346632&r2=346633&view=diff == --- cfe/trunk/lib/Parse/ParseDecl.cpp (original) +++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Nov 11 18:44:33 2018 @@ -1001,6 +1001,21 @@ void Parser::ParseAvailabilityAttribute( continue; } +if (Keyword == Ident_deprecated && Platform->Ident && +Platform->Ident->isStr("swift")) { + // For swift, we deprecate for all versions. + if (Changes[Deprecated].KeywordLoc.isValid()) { +Diag(KeywordLoc, diag::err_availability_redundant) + << Keyword + << SourceRange(Changes[Deprecated].KeywordLoc); + } + + Changes[Deprecated].KeywordLoc = KeywordLoc; + // Use a fake version here. + Changes[Deprecated].Version = VersionTuple(1); + continue; +} + if (Tok.isNot(tok::equal)) { Diag(Tok, diag::err_expected_after) << Keyword << tok::equal; SkipUntil(tok::r_paren, StopAtSemi); Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=346633&r1=346632&r2=346633&view=diff =
[PATCH] D13317: clang_Cursor_getMangling shouldn't mangle if the declaration isn't mangled
michaelwu created this revision. michaelwu added a subscriber: cfe-commits. Right now clang_Cursor_getMangling will attempt to mangle any declaration, even if the declaration isn't mangled (extern "C"). This results in a partially mangled name which isn't useful for much. This patch makes clang_Cursor_getMangling return an empty string if the declaration isn't mangled. http://reviews.llvm.org/D13317 Files: test/Index/print-mangled-name.cpp tools/libclang/CIndex.cpp Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3891,6 +3891,10 @@ ASTContext &Ctx = ND->getASTContext(); std::unique_ptr MC(Ctx.createMangleContext()); + // Don't mangle if we don't need to. + if (!MC->shouldMangleCXXName(ND)) +return cxstring::createEmpty(); + std::string FrontendBuf; llvm::raw_string_ostream FrontendBufOS(FrontendBuf); MC->mangleName(ND, FrontendBufOS); Index: test/Index/print-mangled-name.cpp === --- test/Index/print-mangled-name.cpp +++ test/Index/print-mangled-name.cpp @@ -29,3 +29,8 @@ // ITANIUM: mangled=_Z3foo1SRS_ // MACHO: mangled=__Z3foo1SRS_ // MICROSOFT: mangled=?foo@@YAHUS + +extern "C" int foo(int); +// ITANIUM: mangled= +// MACHO: mangled= +// MICROSOFT: mangled= Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3891,6 +3891,10 @@ ASTContext &Ctx = ND->getASTContext(); std::unique_ptr MC(Ctx.createMangleContext()); + // Don't mangle if we don't need to. + if (!MC->shouldMangleCXXName(ND)) +return cxstring::createEmpty(); + std::string FrontendBuf; llvm::raw_string_ostream FrontendBufOS(FrontendBuf); MC->mangleName(ND, FrontendBufOS); Index: test/Index/print-mangled-name.cpp === --- test/Index/print-mangled-name.cpp +++ test/Index/print-mangled-name.cpp @@ -29,3 +29,8 @@ // ITANIUM: mangled=_Z3foo1SRS_ // MACHO: mangled=__Z3foo1SRS_ // MICROSOFT: mangled=?foo@@YAHUS + +extern "C" int foo(int); +// ITANIUM: mangled= +// MACHO: mangled= +// MICROSOFT: mangled= ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13317: clang_Cursor_getMangling shouldn't mangle if the declaration isn't mangled
michaelwu updated this revision to Diff 36330. michaelwu added a comment. Thanks for the review. I switched to shouldMangleDeclName instead of shouldMangleCXXName, and made it skip the frontend mangling instead of returning an empty string. I tried making mangleName do that instead, but it seemed to cause a bunch of test failures.. The nice thing about returning a valid symbol name instead of an empty string is that I discovered my new test was incomplete. This diff also adds a change to properly handle declarations inside an extern "C". http://reviews.llvm.org/D13317 Files: test/Index/print-mangled-name.cpp tools/c-index-test/c-index-test.c tools/libclang/CIndex.cpp Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3890,7 +3890,11 @@ std::string FrontendBuf; llvm::raw_string_ostream FrontendBufOS(FrontendBuf); - MC->mangleName(ND, FrontendBufOS); + if (MC->shouldMangleDeclName(ND)) { +MC->mangleName(ND, FrontendBufOS); + } else { +ND->printName(FrontendBufOS); + } // Now apply backend mangling. std::unique_ptr DL( Index: tools/c-index-test/c-index-test.c === --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -1429,6 +1429,8 @@ static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p, CXClientData d) { + if (clang_getCursorKind(cursor) == CXCursor_UnexposedDecl) +return CXChildVisit_Recurse; CXString MangledName; PrintCursor(cursor, NULL); MangledName = clang_Cursor_getMangling(cursor); Index: test/Index/print-mangled-name.cpp === --- test/Index/print-mangled-name.cpp +++ test/Index/print-mangled-name.cpp @@ -29,3 +29,8 @@ // ITANIUM: mangled=_Z3foo1SRS_ // MACHO: mangled=__Z3foo1SRS_ // MICROSOFT: mangled=?foo@@YAHUS + +extern "C" int foo(int); +// ITANIUM: mangled=foo +// MACHO: mangled=_foo +// MICROSOFT: mangled=_foo Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3890,7 +3890,11 @@ std::string FrontendBuf; llvm::raw_string_ostream FrontendBufOS(FrontendBuf); - MC->mangleName(ND, FrontendBufOS); + if (MC->shouldMangleDeclName(ND)) { +MC->mangleName(ND, FrontendBufOS); + } else { +ND->printName(FrontendBufOS); + } // Now apply backend mangling. std::unique_ptr DL( Index: tools/c-index-test/c-index-test.c === --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -1429,6 +1429,8 @@ static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p, CXClientData d) { + if (clang_getCursorKind(cursor) == CXCursor_UnexposedDecl) +return CXChildVisit_Recurse; CXString MangledName; PrintCursor(cursor, NULL); MangledName = clang_Cursor_getMangling(cursor); Index: test/Index/print-mangled-name.cpp === --- test/Index/print-mangled-name.cpp +++ test/Index/print-mangled-name.cpp @@ -29,3 +29,8 @@ // ITANIUM: mangled=_Z3foo1SRS_ // MACHO: mangled=__Z3foo1SRS_ // MICROSOFT: mangled=?foo@@YAHUS + +extern "C" int foo(int); +// ITANIUM: mangled=foo +// MACHO: mangled=_foo +// MICROSOFT: mangled=_foo ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D13388: Add support for querying the visibility of a cursor
michaelwu created this revision. michaelwu added a subscriber: cfe-commits. This patch implements clang_getCursorVisibility which provides access to NamedDecl::getVisibility. It's been very useful for me when generating bindings. http://reviews.llvm.org/D13388 Files: include/clang-c/Index.h test/Index/symbol-visibility.c tools/c-index-test/c-index-test.c tools/libclang/CIndex.cpp tools/libclang/libclang.exports Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -173,6 +173,7 @@ clang_getCursorSpelling clang_getCursorType clang_getCursorUSR +clang_getCursorVisibility clang_getDeclObjCTypeEncoding clang_getDefinitionSpellingAndExtent clang_getDiagnostic Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -6351,6 +6351,27 @@ } // end: extern "C" //===--===// +// Operations for querying visibility of a cursor. +//===--===// + +extern "C" { +CXVisibilityKind clang_getCursorVisibility(CXCursor cursor) { + if (!clang_isDeclaration(cursor.kind)) +return CXVisibility_Invalid; + + const Decl *D = cxcursor::getCursorDecl(cursor); + if (const NamedDecl *ND = dyn_cast_or_null(D)) +switch (ND->getVisibility()) { + case HiddenVisibility: return CXVisibility_Hidden; + case ProtectedVisibility: return CXVisibility_Protected; + case DefaultVisibility: return CXVisibility_Default; +}; + + return CXVisibility_Invalid; +} +} // end: extern "C" + +//===--===// // Operations for querying language of a cursor. //===--===// Index: tools/c-index-test/c-index-test.c === --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -1246,6 +1246,32 @@ } /**/ +/* Visibility testing.*/ +/**/ + +static enum CXChildVisitResult PrintVisibility(CXCursor cursor, CXCursor p, + CXClientData d) { + const char *visibility = 0; + + if (clang_isInvalid(clang_getCursorKind(cursor))) +return CXChildVisit_Recurse; + + switch (clang_getCursorVisibility(cursor)) { +case CXVisibility_Invalid: break; +case CXVisibility_Hidden: visibility = "Hidden"; break; +case CXVisibility_Protected: visibility = "Protected"; break; +case CXVisibility_Default: visibility = "Default"; break; + } + + if (visibility) { +PrintCursor(cursor, NULL); +printf("visibility=%s\n", visibility); + } + + return CXChildVisit_Recurse; +} + +/**/ /* Typekind testing. */ /**/ @@ -4061,6 +4087,7 @@ " c-index-test -test-inclusion-stack-tu \n"); fprintf(stderr, " c-index-test -test-print-linkage-source {}*\n" +" c-index-test -test-print-visibility {}*\n" " c-index-test -test-print-type {}*\n" " c-index-test -test-print-type-size {}*\n" " c-index-test -test-print-bitwidth {}*\n" @@ -4148,6 +4175,9 @@ else if (argc > 2 && strcmp(argv[1], "-test-print-linkage-source") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintLinkage, NULL); + else if (argc > 2 && strcmp(argv[1], "-test-print-visibility") == 0) +return perform_test_load_source(argc - 2, argv + 2, "all", PrintVisibility, +NULL); else if (argc > 2 && strcmp(argv[1], "-test-print-type") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintType, 0); Index: test/Index/symbol-visibility.c === --- /dev/null +++ test/Index/symbol-visibility.c @@ -0,0 +1,9 @@ +// RUN: c-index-test -test-print-visibility %s | FileCheck %s + +__attribute__ ((visibility ("default"))) void foo1(); +__attribute__ ((visibility ("protected"))) void foo2(); +__attribute__ ((visibility ("hidden"))) void foo3(); + +// CHECK: FunctionDecl=foo1:3:47visibility=Default +// CHECK: FunctionDecl=foo2:4:49visibility=Protected +// CHECK: FunctionDecl=foo3:5:46visibility=Hidden Index: include/clang-c/Index.h =
Re: [PATCH] D13317: clang_Cursor_getMangling shouldn't mangle if the declaration isn't mangled
michaelwu marked 2 inline comments as done. michaelwu added a comment. http://reviews.llvm.org/D13317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13317: clang_Cursor_getMangling shouldn't mangle if the declaration isn't mangled
michaelwu updated this revision to Diff 36518. michaelwu added a comment. This uses clang_isInvalid in PrintMangledName instead of checking for CXCursor_UnexposedDecl. http://reviews.llvm.org/D13317 Files: test/Index/print-mangled-name.cpp tools/c-index-test/c-index-test.c tools/libclang/CIndex.cpp Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3890,7 +3890,11 @@ std::string FrontendBuf; llvm::raw_string_ostream FrontendBufOS(FrontendBuf); - MC->mangleName(ND, FrontendBufOS); + if (MC->shouldMangleDeclName(ND)) { +MC->mangleName(ND, FrontendBufOS); + } else { +ND->printName(FrontendBufOS); + } // Now apply backend mangling. std::unique_ptr DL( Index: tools/c-index-test/c-index-test.c === --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -1429,6 +1429,8 @@ static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p, CXClientData d) { + if (clang_isInvalid(clang_getCursorKind(cursor))) +return CXChildVisit_Recurse; CXString MangledName; PrintCursor(cursor, NULL); MangledName = clang_Cursor_getMangling(cursor); Index: test/Index/print-mangled-name.cpp === --- test/Index/print-mangled-name.cpp +++ test/Index/print-mangled-name.cpp @@ -29,3 +29,8 @@ // ITANIUM: mangled=_Z3foo1SRS_ // MACHO: mangled=__Z3foo1SRS_ // MICROSOFT: mangled=?foo@@YAHUS + +extern "C" int foo(int); +// ITANIUM: mangled=foo +// MACHO: mangled=_foo +// MICROSOFT: mangled=_foo Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3890,7 +3890,11 @@ std::string FrontendBuf; llvm::raw_string_ostream FrontendBufOS(FrontendBuf); - MC->mangleName(ND, FrontendBufOS); + if (MC->shouldMangleDeclName(ND)) { +MC->mangleName(ND, FrontendBufOS); + } else { +ND->printName(FrontendBufOS); + } // Now apply backend mangling. std::unique_ptr DL( Index: tools/c-index-test/c-index-test.c === --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -1429,6 +1429,8 @@ static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p, CXClientData d) { + if (clang_isInvalid(clang_getCursorKind(cursor))) +return CXChildVisit_Recurse; CXString MangledName; PrintCursor(cursor, NULL); MangledName = clang_Cursor_getMangling(cursor); Index: test/Index/print-mangled-name.cpp === --- test/Index/print-mangled-name.cpp +++ test/Index/print-mangled-name.cpp @@ -29,3 +29,8 @@ // ITANIUM: mangled=_Z3foo1SRS_ // MACHO: mangled=__Z3foo1SRS_ // MICROSOFT: mangled=?foo@@YAHUS + +extern "C" int foo(int); +// ITANIUM: mangled=foo +// MACHO: mangled=_foo +// MICROSOFT: mangled=_foo ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13317: clang_Cursor_getMangling shouldn't mangle if the declaration isn't mangled
michaelwu updated this revision to Diff 36645. michaelwu added a comment. Turns out clang_isUnexposed is what I wanted, rather than clang_isInvalid. I remember seeing clang_isInvalid work though.. http://reviews.llvm.org/D13317 Files: test/Index/print-mangled-name.cpp tools/c-index-test/c-index-test.c tools/libclang/CIndex.cpp Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3890,7 +3890,11 @@ std::string FrontendBuf; llvm::raw_string_ostream FrontendBufOS(FrontendBuf); - MC->mangleName(ND, FrontendBufOS); + if (MC->shouldMangleDeclName(ND)) { +MC->mangleName(ND, FrontendBufOS); + } else { +ND->printName(FrontendBufOS); + } // Now apply backend mangling. std::unique_ptr DL( Index: tools/c-index-test/c-index-test.c === --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -1429,6 +1429,8 @@ static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p, CXClientData d) { + if (clang_isUnexposed(clang_getCursorKind(cursor))) +return CXChildVisit_Recurse; CXString MangledName; PrintCursor(cursor, NULL); MangledName = clang_Cursor_getMangling(cursor); Index: test/Index/print-mangled-name.cpp === --- test/Index/print-mangled-name.cpp +++ test/Index/print-mangled-name.cpp @@ -29,3 +29,8 @@ // ITANIUM: mangled=_Z3foo1SRS_ // MACHO: mangled=__Z3foo1SRS_ // MICROSOFT: mangled=?foo@@YAHUS + +extern "C" int foo(int); +// ITANIUM: mangled=foo +// MACHO: mangled=_foo +// MICROSOFT: mangled=_foo Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -3890,7 +3890,11 @@ std::string FrontendBuf; llvm::raw_string_ostream FrontendBufOS(FrontendBuf); - MC->mangleName(ND, FrontendBufOS); + if (MC->shouldMangleDeclName(ND)) { +MC->mangleName(ND, FrontendBufOS); + } else { +ND->printName(FrontendBufOS); + } // Now apply backend mangling. std::unique_ptr DL( Index: tools/c-index-test/c-index-test.c === --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -1429,6 +1429,8 @@ static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p, CXClientData d) { + if (clang_isUnexposed(clang_getCursorKind(cursor))) +return CXChildVisit_Recurse; CXString MangledName; PrintCursor(cursor, NULL); MangledName = clang_Cursor_getMangling(cursor); Index: test/Index/print-mangled-name.cpp === --- test/Index/print-mangled-name.cpp +++ test/Index/print-mangled-name.cpp @@ -29,3 +29,8 @@ // ITANIUM: mangled=_Z3foo1SRS_ // MACHO: mangled=__Z3foo1SRS_ // MICROSOFT: mangled=?foo@@YAHUS + +extern "C" int foo(int); +// ITANIUM: mangled=foo +// MACHO: mangled=_foo +// MICROSOFT: mangled=_foo ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13388: Add support for querying the visibility of a cursor
michaelwu added a comment. Visibility can be set via command line args without any attributes in the AST, so I don't think that's sufficient. http://reviews.llvm.org/D13388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13388: Add support for querying the visibility of a cursor
michaelwu added a comment. Review ping? http://reviews.llvm.org/D13388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13388: Add support for querying the visibility of a cursor
michaelwu added inline comments. Comment at: test/Index/symbol-visibility.c:8 @@ +7,3 @@ +// CHECK: FunctionDecl=foo1:3:47visibility=Default +// CHECK: FunctionDecl=foo2:4:49visibility=Protected +// CHECK: FunctionDecl=foo3:5:46visibility=Hidden skalinichev wrote: > Are you sure that this is correct? > Looking at r246931, it seems like the protected visibility is not supported > on all platforms. Not sure about this. For most purposes, default and hidden is all you need so I don't think there's much lost by cutting this part of this test. I was on the fence about whether to test for protected. http://reviews.llvm.org/D13388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13388: Add support for querying the visibility of a cursor
michaelwu updated this revision to Diff 40100. michaelwu added a comment. This removes the test for protected visibility and improves documentation for clang_getCursorVisibility. http://reviews.llvm.org/D13388 Files: include/clang-c/Index.h test/Index/symbol-visibility.c tools/c-index-test/c-index-test.c tools/libclang/CIndex.cpp tools/libclang/libclang.exports Index: tools/libclang/libclang.exports === --- tools/libclang/libclang.exports +++ tools/libclang/libclang.exports @@ -176,6 +176,7 @@ clang_getCursorSpelling clang_getCursorType clang_getCursorUSR +clang_getCursorVisibility clang_getDeclObjCTypeEncoding clang_getDefinitionSpellingAndExtent clang_getDiagnostic Index: tools/libclang/CIndex.cpp === --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -6428,6 +6428,27 @@ } // end: extern "C" //===--===// +// Operations for querying visibility of a cursor. +//===--===// + +extern "C" { +CXVisibilityKind clang_getCursorVisibility(CXCursor cursor) { + if (!clang_isDeclaration(cursor.kind)) +return CXVisibility_Invalid; + + const Decl *D = cxcursor::getCursorDecl(cursor); + if (const NamedDecl *ND = dyn_cast_or_null(D)) +switch (ND->getVisibility()) { + case HiddenVisibility: return CXVisibility_Hidden; + case ProtectedVisibility: return CXVisibility_Protected; + case DefaultVisibility: return CXVisibility_Default; +}; + + return CXVisibility_Invalid; +} +} // end: extern "C" + +//===--===// // Operations for querying language of a cursor. //===--===// Index: tools/c-index-test/c-index-test.c === --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -1248,6 +1248,32 @@ } /**/ +/* Visibility testing.*/ +/**/ + +static enum CXChildVisitResult PrintVisibility(CXCursor cursor, CXCursor p, + CXClientData d) { + const char *visibility = 0; + + if (clang_isInvalid(clang_getCursorKind(cursor))) +return CXChildVisit_Recurse; + + switch (clang_getCursorVisibility(cursor)) { +case CXVisibility_Invalid: break; +case CXVisibility_Hidden: visibility = "Hidden"; break; +case CXVisibility_Protected: visibility = "Protected"; break; +case CXVisibility_Default: visibility = "Default"; break; + } + + if (visibility) { +PrintCursor(cursor, NULL); +printf("visibility=%s\n", visibility); + } + + return CXChildVisit_Recurse; +} + +/**/ /* Typekind testing. */ /**/ @@ -4084,6 +4110,7 @@ " c-index-test -test-inclusion-stack-tu \n"); fprintf(stderr, " c-index-test -test-print-linkage-source {}*\n" +" c-index-test -test-print-visibility {}*\n" " c-index-test -test-print-type {}*\n" " c-index-test -test-print-type-size {}*\n" " c-index-test -test-print-bitwidth {}*\n" @@ -4171,6 +4198,9 @@ else if (argc > 2 && strcmp(argv[1], "-test-print-linkage-source") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintLinkage, NULL); + else if (argc > 2 && strcmp(argv[1], "-test-print-visibility") == 0) +return perform_test_load_source(argc - 2, argv + 2, "all", PrintVisibility, +NULL); else if (argc > 2 && strcmp(argv[1], "-test-print-type") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintType, 0); Index: test/Index/symbol-visibility.c === --- /dev/null +++ test/Index/symbol-visibility.c @@ -0,0 +1,7 @@ +// RUN: c-index-test -test-print-visibility %s | FileCheck %s + +__attribute__ ((visibility ("default"))) void foo1(); +__attribute__ ((visibility ("hidden"))) void foo2(); + +// CHECK: FunctionDecl=foo1:3:47visibility=Default +// CHECK: FunctionDecl=foo2:4:46visibility=Hidden Index: include/clang-c/Index.h === --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -2449,6 +2449,32 @@ CINDEX_LINKAGE enum CXLinkageKind clang_getCursorL
Re: [PATCH] D13388: Add support for querying the visibility of a cursor
michaelwu added a comment. Anyone mind landing this for me? I don't have commit access. http://reviews.llvm.org/D13388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits