]> granicus.if.org Git - clang/commitdiff
Add libclang API hook "clang_getIBOutletCollectionType" to query the collection type...
authorTed Kremenek <kremenek@apple.com>
Thu, 26 Aug 2010 01:42:22 +0000 (01:42 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 26 Aug 2010 01:42:22 +0000 (01:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112139 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
test/Index/c-index-api-loadTU-test.m
tools/c-index-test/c-index-test.c
tools/libclang/CIndex.cpp
tools/libclang/CMakeLists.txt
tools/libclang/CXCursor.cpp
tools/libclang/CXCursor.h
tools/libclang/CXType.cpp [moved from tools/libclang/CXTypes.cpp with 98% similarity]
tools/libclang/CXType.h [new file with mode: 0644]
tools/libclang/libclang.darwin.exports
tools/libclang/libclang.exports

index 4dfaec030d1c157852bd5c6dbb2f63c62af4228c..9b80d9f3a55c9d08de9bc6831f3730e6d68c5fda 100644 (file)
@@ -1304,7 +1304,7 @@ CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
 /**
  * @}
  */
-
+    
 /**
  * \defgroup CINDEX_TYPES Type information for CXCursors
  *
@@ -1438,6 +1438,24 @@ CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
  */
 CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
 
+/**
+ * @}
+ */
+  
+/**
+ * \defgroup CINDEX_TYPES Information for attributes
+ *
+ * @{
+ */
+
+
+/**
+ * \brief For cursors representing an iboutletcollection attribute,
+ *  this function returns the collection element type.
+ *
+ */
+CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
+
 /**
  * @}
  */
index a86bf629ea77d305e058d30f697f8ecf12b3ee31..5fe7cd669bc251a83dc08ef0901c12f6f98f1d7a 100644 (file)
@@ -56,7 +56,7 @@ int main (int argc, const char * argv[]) {
 
 // Test attribute traversal.
 #define IBOutlet __attribute__((iboutlet))
-#define IBOutletCollection(ClassName) __attribute__((iboutletcollection))
+#define IBOutletCollection(ClassName) __attribute__((iboutletcollection(ClassName)))
 #define IBAction void)__attribute__((ibaction)
 
 @interface TestAttributes {
@@ -143,10 +143,15 @@ struct X0  {};
 // CHECK: c-index-api-loadTU-test.m:63:19: ObjCIvarDecl=anOutlet:63:19 (Definition) Extent=[63:19 - 63:27]
 // CHECK: <invalid loc>:0:0: attribute(iboutlet)=
 // CHECK: c-index-api-loadTU-test.m:64:29: ObjCIvarDecl=anOutletCollection:64:29 (Definition) Extent=[64:29 - 64:47]
-// CHECK: <invalid loc>:0:0: attribute(iboutletcollection)=
+// CHECK: <invalid loc>:0:0: attribute(iboutletcollection)= [IBOutletCollection=ObjCObjectPointer]
 // CHECK: c-index-api-loadTU-test.m:64:26: TypeRef=id:0:0 Extent=[64:26 - 64:28]
 // CHECK: c-index-api-loadTU-test.m:66:1: ObjCInstanceMethodDecl=actionMethod::66:1 Extent=[66:1 - 66:35]
 // CHECK: <invalid loc>:0:0: attribute(ibaction)=
 // CHECK: c-index-api-loadTU-test.m:66:31: ParmDecl=arg:66:31 (Definition) Extent=[66:28 - 66:34]
 // CHECK: c-index-api-loadTU-test.m:66:28: TypeRef=id:0:0 Extent=[66:28 - 66:30]
+// CHECK: c-index-api-loadTU-test.m:69:16: StructDecl=X0:69:16 Extent=[69:9 - 69:18]
+// CHECK: c-index-api-loadTU-test.m:69:19: TypedefDecl=X1:69:19 (Definition) Extent=[69:19 - 69:21]
+// CHECK: c-index-api-loadTU-test.m:69:16: TypeRef=struct X0:71:8 Extent=[69:16 - 69:18]
+// CHECK: c-index-api-loadTU-test.m:70:8: StructDecl=X0:70:8 Extent=[70:1 - 70:10]
+// CHECK: c-index-api-loadTU-test.m:71:8: StructDecl=X0:71:8 (Definition) Extent=[71:1 - 71:14]
 
index 330fa545f9310fb1cc86f8caebc77ed78acf9ce6..3f702904a3dd87071ee66a6e283a0e51e3557c8e 100644 (file)
@@ -195,6 +195,14 @@ static void PrintCursor(CXCursor Cursor) {
         printf(" (unavailable)");
         break;
     }
+    
+    if (Cursor.kind == CXCursor_IBOutletCollectionAttr) {
+      CXType T =
+        clang_getCanonicalType(clang_getIBOutletCollectionType(Cursor));
+      CXString S = clang_getTypeKindSpelling(T.kind);
+      printf(" [IBOutletCollection=%s]", clang_getCString(S));
+      clang_disposeString(S);
+    }
   }
 }
 
index c696a27c5997705920da6a0c219f4b73e8caa8e2..4ec2bf4c291bb32ebac7a9dfb0c9ba2f35c6fdaa 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "CIndexer.h"
 #include "CXCursor.h"
+#include "CXType.h"
 #include "CXSourceLocation.h"
 #include "CIndexDiagnostic.h"
 
@@ -3055,6 +3056,22 @@ unsigned clang_CXXMethod_isStatic(CXCursor C) {
 
 } // end: extern "C"
 
+//===----------------------------------------------------------------------===//
+// Attribute introspection.
+//===----------------------------------------------------------------------===//
+
+extern "C" {
+CXType clang_getIBOutletCollectionType(CXCursor C) {
+  if (C.kind != CXCursor_IBOutletCollectionAttr)
+    return cxtype::MakeCXType(QualType(), cxcursor::getCursorASTUnit(C));
+  
+  IBOutletCollectionAttr *A =
+    cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(C));
+  
+  return cxtype::MakeCXType(A->getInterface(), cxcursor::getCursorASTUnit(C));  
+}
+} // end: extern "C"
+
 //===----------------------------------------------------------------------===//
 // CXString Operations.
 //===----------------------------------------------------------------------===//
index e06eecfb14940b617291317db5e6080d9cc6ffed..dbb28ec3bb2ce950f1c0aac809cb9db77d30108d 100644 (file)
@@ -27,7 +27,7 @@ add_clang_library(libclang
   CIndexUSRs.cpp
   CIndexer.cpp
   CXCursor.cpp
-  CXTypes.cpp
+  CXType.cpp
   ../../include/clang-c/Index.h
 )
 
index be3623f6e9e2ce2d4d1560c2a42f811f9d061366..318fd51dfb2c2cdf71f0a729ff21cea920cc0e37 100644 (file)
@@ -358,6 +358,10 @@ Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
   return (Stmt *)Cursor.data[1];
 }
 
+Attr *cxcursor::getCursorAttr(CXCursor Cursor) {
+  return (Attr *)Cursor.data[1];
+}
+
 ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
   return getCursorASTUnit(Cursor)->getASTContext();
 }
index 1664f5a9ced2afecdfbe4cc7ea93b9c3fdf5fb8b..5a8428a2ec8830d468d2da44c2879092a28e9f91 100644 (file)
@@ -98,6 +98,8 @@ MacroInstantiation *getCursorMacroInstantiation(CXCursor C);
 Decl *getCursorDecl(CXCursor Cursor);
 Expr *getCursorExpr(CXCursor Cursor);
 Stmt *getCursorStmt(CXCursor Cursor);
+Attr *getCursorAttr(CXCursor Cursor);
+
 ASTContext &getCursorContext(CXCursor Cursor);
 ASTUnit *getCursorASTUnit(CXCursor Cursor);
   
similarity index 98%
rename from tools/libclang/CXTypes.cpp
rename to tools/libclang/CXType.cpp
index b49ef191e3cccc1e801c3eb7e9bc8b51f1130393..aa173cae32c0be45b14468b07fbe51952a47b651 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "CIndexer.h"
 #include "CXCursor.h"
+#include "CXType.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/Decl.h"
@@ -85,12 +86,15 @@ static CXTypeKind GetTypeKind(QualType T) {
 #undef TKCASE
 }
 
-static CXType MakeCXType(QualType T, ASTUnit *TU) {
+
+CXType cxtype::MakeCXType(QualType T, ASTUnit *TU) {
   CXTypeKind TK = GetTypeKind(T);
   CXType CT = { TK, { TK == CXType_Invalid ? 0 : T.getAsOpaquePtr(), TU }};
   return CT;
 }
 
+using cxtype::MakeCXType;
+
 static inline QualType GetQualType(CXType CT) {
   return QualType::getFromOpaquePtr(CT.data[0]);
 }
diff --git a/tools/libclang/CXType.h b/tools/libclang/CXType.h
new file mode 100644 (file)
index 0000000..94151ed
--- /dev/null
@@ -0,0 +1,29 @@
+//===- CXTypes.h - Routines for manipulating CXTypes ----------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines routines for manipulating CXCursors.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_CXTYPES_H
+#define LLVM_CLANG_CXTYPES_H
+
+#include "clang-c/Index.h"
+#include "clang/AST/Type.h"
+
+namespace clang {
+  
+class ASTUnit;
+  
+namespace cxtype {
+  
+CXType MakeCXType(QualType T, ASTUnit *TU);
+  
+}} // end namespace clang::cxtype
+#endif
index f2087b73f2bcfc8f8dc7bc896b7283606eccdf35..6a3696650176c4685423d5373c928967be93b70f 100644 (file)
@@ -30,6 +30,7 @@ _clang_equalLocations
 _clang_equalTypes
 _clang_formatDiagnostic
 _clang_getCString
+_clang_getIBOutletCollectionType
 _clang_getCanonicalType
 _clang_getClangVersion
 _clang_getCompletionAvailability
index c1658f6032c377d5efaa3cc6a70047d69a31259c..8f1d6269574e70e5ce200c741cdfaa3b49b83842 100644 (file)
@@ -14,8 +14,8 @@ clang_createIndex
 clang_createTranslationUnit
 clang_createTranslationUnitFromSourceFile
 clang_defaultCodeCompleteOptions
-clang_defaultEditingTranslationUnitOptions
 clang_defaultDiagnosticDisplayOptions
+clang_defaultEditingTranslationUnitOptions
 clang_defaultReparseOptions
 clang_defaultSaveOptions
 clang_disposeCodeCompleteResults
@@ -47,8 +47,8 @@ clang_getCursorLanguage
 clang_getCursorLinkage
 clang_getCursorLocation
 clang_getCursorReferenced
-clang_getCursorSpelling
 clang_getCursorResultType
+clang_getCursorSpelling
 clang_getCursorType
 clang_getCursorUSR
 clang_getDefinitionSpellingAndExtent
@@ -63,6 +63,7 @@ clang_getDiagnosticSpelling
 clang_getFile
 clang_getFileName
 clang_getFileTime
+clang_getIBOutletCollectionType
 clang_getInclusions
 clang_getInstantiationLocation
 clang_getLocation
@@ -88,8 +89,8 @@ clang_isCursorDefinition
 clang_isDeclaration
 clang_isExpression
 clang_isInvalid
-clang_isPreprocessing
 clang_isPODType
+clang_isPreprocessing
 clang_isReference
 clang_isStatement
 clang_isTranslationUnit