Introduce new libclang API functions that determine the availability
of a cursor or code-completion result, e.g., whether that result
refers to an unavailable, deleted, or deprecated declaration.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111858 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index ff0d92a..9615a6d 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -97,6 +97,19 @@
   unsigned long Length;
 };
 
+/// \brief Describes the availability of a particular entity, which indicates
+/// whether the use of this entity will result in a warning or error due to
+/// it being deprecated or unavailable.
+enum CXAvailabilityKind {
+  /// \brief The entity is available.
+  CXAvailability_Available,
+  /// \brief The entity is available, but has been deprecated (and its use is
+  /// not recommended).
+  CXAvailability_Deprecated,
+  /// \brief The entity is not available; any use of it will be an error.
+  CXAvailability_NotAvailable
+};
+  
 /**
  * \defgroup CINDEX_STRING String manipulation routines
  *
@@ -1199,6 +1212,16 @@
 CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
 
 /**
+ * \brief Determine the availability of the entity that this cursor refers to.
+ *
+ * \param cursor The cursor to query.
+ *
+ * \returns The availability of the cursor.
+ */
+CINDEX_LINKAGE enum CXAvailabilityKind 
+clang_getCursorAvailability(CXCursor cursor);
+
+/**
  * \brief Describe the "language" of the entity referred to by a cursor.
  */
 CINDEX_LINKAGE enum CXLanguageKind {
@@ -2073,6 +2096,17 @@
 clang_getCompletionPriority(CXCompletionString completion_string);
   
 /**
+ * \brief Determine the availability of the entity that this code-completion
+ * string refers to.
+ *
+ * \param completion_string The completion string to query.
+ *
+ * \returns The availability of the completion string.
+ */
+CINDEX_LINKAGE enum CXAvailabilityKind 
+clang_getCompletionAvailability(CXCompletionString completion_string);
+
+/**
  * \brief Contains the results of code-completion.
  *
  * This data structure contains the results of code completion, as
@@ -2294,7 +2328,7 @@
  */
 CINDEX_LINKAGE
 void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
-
+  
 /**
  * \brief Determine the number of diagnostics produced prior to the
  * location where code completion was performed.
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h
index e323170..614807b 100644
--- a/include/clang/Frontend/ASTUnit.h
+++ b/include/clang/Frontend/ASTUnit.h
@@ -239,6 +239,9 @@
     /// result.
     CXCursorKind Kind;
     
+    /// \brief The availability of this code-completion result.
+    CXAvailabilityKind Availability;
+    
     /// \brief The simplified type class for a non-macro completion result.
     SimplifiedTypeClass TypeClass;
     
diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h
index aadc459..59d8a4f 100644
--- a/include/clang/Sema/CodeCompleteConsumer.h
+++ b/include/clang/Sema/CodeCompleteConsumer.h
@@ -476,6 +476,9 @@
     /// \brief The cursor kind that describes this result.
     CXCursorKind CursorKind;
     
+    /// \brief The availability of this result.
+    CXAvailabilityKind Availability;
+    
     /// \brief Specifies which parameter (of a function, Objective-C method,
     /// macro, etc.) we should start with when formatting the result.
     unsigned StartParameter;
@@ -508,39 +511,43 @@
            NestedNameSpecifier *Qualifier = 0,
            bool QualifierIsInformative = false)
       : Kind(RK_Declaration), Declaration(Declaration), 
-        Priority(getPriorityFromDecl(Declaration)), StartParameter(0), 
+        Priority(getPriorityFromDecl(Declaration)), 
+        Availability(CXAvailability_Available), StartParameter(0), 
         Hidden(false), QualifierIsInformative(QualifierIsInformative),
         StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
         DeclaringEntity(false), Qualifier(Qualifier) { 
-      computeCursorKind();
+      computeCursorKindAndAvailability();
     }
     
     /// \brief Build a result that refers to a keyword or symbol.
     Result(const char *Keyword, unsigned Priority = CCP_Keyword)
       : Kind(RK_Keyword), Keyword(Keyword), Priority(Priority), 
+        Availability(CXAvailability_Available), 
         StartParameter(0), Hidden(false), QualifierIsInformative(0), 
         StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
         DeclaringEntity(false), Qualifier(0) {
-      computeCursorKind();
+      computeCursorKindAndAvailability();
     }
     
     /// \brief Build a result that refers to a macro.
     Result(IdentifierInfo *Macro, unsigned Priority = CCP_Macro)
-      : Kind(RK_Macro), Macro(Macro), Priority(Priority), StartParameter(0), 
+      : Kind(RK_Macro), Macro(Macro), Priority(Priority), 
+        Availability(CXAvailability_Available), StartParameter(0), 
         Hidden(false), QualifierIsInformative(0), 
         StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
         DeclaringEntity(false), Qualifier(0) { 
-      computeCursorKind();
+      computeCursorKindAndAvailability();
     }
 
     /// \brief Build a result that refers to a pattern.
     Result(CodeCompletionString *Pattern, unsigned Priority = CCP_CodePattern,
-           CXCursorKind CursorKind = CXCursor_NotImplemented)
+           CXCursorKind CursorKind = CXCursor_NotImplemented,
+           CXAvailabilityKind Availability = CXAvailability_Available)
       : Kind(RK_Pattern), Pattern(Pattern), Priority(Priority), 
-        CursorKind(CursorKind), StartParameter(0), Hidden(false), 
-        QualifierIsInformative(0), StartsNestedNameSpecifier(false), 
-        AllParametersAreInformative(false), DeclaringEntity(false), 
-        Qualifier(0) 
+        CursorKind(CursorKind), Availability(Availability), StartParameter(0), 
+        Hidden(false), QualifierIsInformative(0), 
+        StartsNestedNameSpecifier(false), AllParametersAreInformative(false), 
+        DeclaringEntity(false), Qualifier(0) 
     { 
     }
     
@@ -573,7 +580,7 @@
     static unsigned getPriorityFromDecl(NamedDecl *ND);
     
   private:
-    void computeCursorKind();
+    void computeCursorKindAndAvailability();
   };
     
   class OverloadCandidate {