summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-08-26 01:42:22 +0000
committerTed Kremenek <kremenek@apple.com>2010-08-26 01:42:22 +0000
commit95f33555a6d51b6537a9ed3968c3d1c2e4991b51 (patch)
tree3c81eccf2bf7be2c9a886f9915235871d8727d14 /tools
parent2dc70ad391cb75ea90a2fb5d14a7f1d271534da3 (diff)
downloadclang-95f33555a6d51b6537a9ed3968c3d1c2e4991b51.tar.gz
Add libclang API hook "clang_getIBOutletCollectionType" to query the collection type for iboutletcollection attributes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112139 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/c-index-test/c-index-test.c8
-rw-r--r--tools/libclang/CIndex.cpp17
-rw-r--r--tools/libclang/CMakeLists.txt2
-rw-r--r--tools/libclang/CXCursor.cpp4
-rw-r--r--tools/libclang/CXCursor.h2
-rw-r--r--tools/libclang/CXType.cpp (renamed from tools/libclang/CXTypes.cpp)6
-rw-r--r--tools/libclang/CXType.h29
-rw-r--r--tools/libclang/libclang.darwin.exports1
-rw-r--r--tools/libclang/libclang.exports7
9 files changed, 71 insertions, 5 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 330fa545f9..3f702904a3 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -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);
+ }
}
}
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index c696a27c59..4ec2bf4c29 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -14,6 +14,7 @@
#include "CIndexer.h"
#include "CXCursor.h"
+#include "CXType.h"
#include "CXSourceLocation.h"
#include "CIndexDiagnostic.h"
@@ -3056,6 +3057,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.
//===----------------------------------------------------------------------===//
diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt
index e06eecfb14..dbb28ec3bb 100644
--- a/tools/libclang/CMakeLists.txt
+++ b/tools/libclang/CMakeLists.txt
@@ -27,7 +27,7 @@ add_clang_library(libclang
CIndexUSRs.cpp
CIndexer.cpp
CXCursor.cpp
- CXTypes.cpp
+ CXType.cpp
../../include/clang-c/Index.h
)
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index be3623f6e9..318fd51dfb 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -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();
}
diff --git a/tools/libclang/CXCursor.h b/tools/libclang/CXCursor.h
index 1664f5a9ce..5a8428a2ec 100644
--- a/tools/libclang/CXCursor.h
+++ b/tools/libclang/CXCursor.h
@@ -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);
diff --git a/tools/libclang/CXTypes.cpp b/tools/libclang/CXType.cpp
index b49ef191e3..aa173cae32 100644
--- a/tools/libclang/CXTypes.cpp
+++ b/tools/libclang/CXType.cpp
@@ -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
index 0000000000..94151ed6b9
--- /dev/null
+++ b/tools/libclang/CXType.h
@@ -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
diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports
index f2087b73f2..6a36966501 100644
--- a/tools/libclang/libclang.darwin.exports
+++ b/tools/libclang/libclang.darwin.exports
@@ -30,6 +30,7 @@ _clang_equalLocations
_clang_equalTypes
_clang_formatDiagnostic
_clang_getCString
+_clang_getIBOutletCollectionType
_clang_getCanonicalType
_clang_getClangVersion
_clang_getCompletionAvailability
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index c1658f6032..8f1d626957 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -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