summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-27 17:44:34 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-27 17:44:34 +0000
commit2b0cf60df39067f689687a7411be1077af0a234d (patch)
tree8108af3d105b7818c95b15e0a511bc84754d9993
parentfec95198aa4000ad7bdcb284ac390f1cfbf8d479 (diff)
downloadbcm5719-llvm-2b0cf60df39067f689687a7411be1077af0a234d.tar.gz
bcm5719-llvm-2b0cf60df39067f689687a7411be1077af0a234d.zip
[libclang] Expose array size and element type, patch by Vinay Sajip!
llvm-svn: 140614
-rw-r--r--clang/include/clang-c/Index.h17
-rw-r--r--clang/test/Index/print-typekind.c3
-rw-r--r--clang/tools/libclang/CXType.cpp36
-rw-r--r--clang/tools/libclang/libclang.exports2
4 files changed, 56 insertions, 2 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index fbeb14d3657..f1e62ae4207 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -1965,7 +1965,8 @@ enum CXTypeKind {
CXType_ObjCInterface = 108,
CXType_ObjCObjectPointer = 109,
CXType_FunctionNoProto = 110,
- CXType_FunctionProto = 111
+ CXType_FunctionProto = 111,
+ CXType_ConstantArray = 112
};
/**
@@ -2057,6 +2058,20 @@ CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
/**
+ * \brief Return the element type of an array type.
+ *
+ * If a non-array type is passed in, an invalid type is returned.
+ */
+CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
+
+/**
+ * \brief Return the the array size of a constant array.
+ *
+ * If a non-array type is passed in, -1 is returned.
+ */
+CINDEX_LINKAGE long long clang_getArraySize(CXType T);
+
+/**
* \brief Returns 1 if the base class specified by the cursor with kind
* CX_CXXBaseSpecifier is virtual.
*/
diff --git a/clang/test/Index/print-typekind.c b/clang/test/Index/print-typekind.c
index 30bd409b090..920674fc0f2 100644
--- a/clang/test/Index/print-typekind.c
+++ b/clang/test/Index/print-typekind.c
@@ -5,6 +5,7 @@ int *f(int *p, char *x, FooType z) {
return p + z;
}
typedef double OtherType;
+typedef int ArrayType[5];
// RUN: c-index-test -test-print-typekind %s | FileCheck %s
// CHECK: TypedefDecl=FooType:1:13 (Definition) typekind=Typedef [canonical=Int] [isPOD=1]
@@ -24,4 +25,4 @@ typedef double OtherType;
// CHECK: DeclRefExpr=p:3:13 typekind=Pointer [isPOD=1]
// CHECK: DeclRefExpr=z:3:33 typekind=Typedef [canonical=Int] [isPOD=1]
// CHECK: TypedefDecl=OtherType:7:16 (Definition) typekind=Typedef [canonical=Double] [isPOD=1]
-
+// CHECK: TypedefDecl=ArrayType:8:13 (Definition) typekind=Typedef [canonical=ConstantArray] [isPOD=1]
diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index 45c73468d97..0e62e2734b0 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -84,6 +84,7 @@ static CXTypeKind GetTypeKind(QualType T) {
TKCASE(ObjCObjectPointer);
TKCASE(FunctionNoProto);
TKCASE(FunctionProto);
+ TKCASE(ConstantArray);
default:
return CXType_Unexposed;
}
@@ -330,6 +331,7 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
TKIND(ObjCObjectPointer);
TKIND(FunctionNoProto);
TKIND(FunctionProto);
+ TKIND(ConstantArray);
}
#undef TKIND
return cxstring::createCXString(s);
@@ -373,6 +375,40 @@ unsigned clang_isPODType(CXType X) {
return T.isPODType(AU->getASTContext()) ? 1 : 0;
}
+CXType clang_getArrayElementType(CXType CT) {
+ QualType ET = QualType();
+ QualType T = GetQualType(CT);
+ const Type *TP = T.getTypePtrOrNull();
+
+ if (TP) {
+ switch (TP->getTypeClass()) {
+ case Type::ConstantArray:
+ ET = cast<ConstantArrayType> (TP)->getElementType();
+ break;
+ default:
+ break;
+ }
+ }
+ return MakeCXType(ET, GetTU(CT));
+}
+
+long long clang_getArraySize(CXType CT) {
+ long long result = -1;
+ QualType T = GetQualType(CT);
+ const Type *TP = T.getTypePtrOrNull();
+
+ if (TP) {
+ switch (TP->getTypeClass()) {
+ case Type::ConstantArray:
+ result = cast<ConstantArrayType> (TP)->getSize().getSExtValue();
+ break;
+ default:
+ break;
+ }
+ }
+ return result;
+}
+
CXString clang_getDeclObjCTypeEncoding(CXCursor C) {
if ((C.kind < CXCursor_FirstDecl) || (C.kind > CXCursor_LastDecl))
return cxstring::createCXString("");
diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports
index 019110a5e74..4ebbf9ebd69 100644
--- a/clang/tools/libclang/libclang.exports
+++ b/clang/tools/libclang/libclang.exports
@@ -43,6 +43,8 @@ clang_equalRanges
clang_equalTypes
clang_executeOnThread
clang_formatDiagnostic
+clang_getArrayElementType
+clang_getArraySize
clang_getCString
clang_getCXTUResourceUsage
clang_getCXXAccessSpecifier
OpenPOWER on IntegriCloud