diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-05-08 00:14:45 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-05-08 00:14:45 +0000 |
commit | cc889664dec7776ebb598e4584e7df5ba2f59ab4 (patch) | |
tree | 93474d20a4c2b3de8072befe1f00092fc5b3a800 /tools/c-index-test/c-index-test.c | |
parent | c91fdf662d4f453ce9bb975b25cec348d0ced9c6 (diff) |
Introduce a new libclang API to determine the platform availability of
a given entity, so that we can tell when the entity was
introduced/deprecated/obsoleted on each platform for which we have an
annotation. Addresses <rdar://problem/11365715>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156347 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/c-index-test/c-index-test.c')
-rw-r--r-- | tools/c-index-test/c-index-test.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index eb2a4063e7..497c9ee6af 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -180,6 +180,20 @@ static void PrintRange(CXSourceRange R, const char *str) { int want_display_name = 0; +static void printVersion(const char *Prefix, CXVersion Version) { + if (Version.Major < 0) + return; + printf("%s%d", Prefix, Version.Major); + + if (Version.Minor < 0) + return; + printf(".%d", Version.Minor); + + if (Version.Subminor < 0) + return; + printf(".%d", Version.Subminor); +} + static void PrintCursor(CXCursor Cursor) { CXTranslationUnit TU = clang_Cursor_getTranslationUnit(Cursor); if (clang_isInvalid(Cursor.kind)) { @@ -197,7 +211,14 @@ static void PrintCursor(CXCursor Cursor) { unsigned RefNameRangeNr; CXSourceRange CursorExtent; CXSourceRange RefNameRange; - + int AlwaysUnavailable; + int AlwaysDeprecated; + CXString UnavailableMessage; + CXString DeprecatedMessage; + CXPlatformAvailability PlatformAvailability[2]; + int NumPlatformAvailability; + int I; + ks = clang_getCursorKindSpelling(Cursor.kind); string = want_display_name? clang_getCursorDisplayName(Cursor) : clang_getCursorSpelling(Cursor); @@ -249,6 +270,47 @@ static void PrintCursor(CXCursor Cursor) { break; } + NumPlatformAvailability + = clang_getCursorPlatformAvailability(Cursor, + &AlwaysDeprecated, + &DeprecatedMessage, + &AlwaysUnavailable, + &UnavailableMessage, + PlatformAvailability, 2); + if (AlwaysUnavailable) { + printf(" (always unavailable: \"%s\")", + clang_getCString(UnavailableMessage)); + } else if (AlwaysDeprecated) { + printf(" (always deprecated: \"%s\")", + clang_getCString(DeprecatedMessage)); + } else { + for (I = 0; I != NumPlatformAvailability; ++I) { + if (I >= 2) + break; + + printf(" (%s", clang_getCString(PlatformAvailability[I].Platform)); + if (PlatformAvailability[I].Unavailable) + printf(", unavailable"); + else { + printVersion(", introduced=", PlatformAvailability[I].Introduced); + printVersion(", deprecated=", PlatformAvailability[I].Deprecated); + printVersion(", obsoleted=", PlatformAvailability[I].Obsoleted); + } + if (clang_getCString(PlatformAvailability[I].Message)[0]) + printf(", message=\"%s\"", + clang_getCString(PlatformAvailability[I].Message)); + printf(")"); + } + } + for (I = 0; I != NumPlatformAvailability; ++I) { + if (I >= 2) + break; + clang_disposeCXPlatformAvailability(PlatformAvailability + I); + } + + clang_disposeString(DeprecatedMessage); + clang_disposeString(UnavailableMessage); + if (clang_CXXMethod_isStatic(Cursor)) printf(" (static)"); if (clang_CXXMethod_isVirtual(Cursor)) |