[libclang] Expose array size and element type, patch by Vinay Sajip!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140614 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index 45c7346..0e62e27 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -84,6 +84,7 @@
TKCASE(ObjCObjectPointer);
TKCASE(FunctionNoProto);
TKCASE(FunctionProto);
+ TKCASE(ConstantArray);
default:
return CXType_Unexposed;
}
@@ -330,6 +331,7 @@
TKIND(ObjCObjectPointer);
TKIND(FunctionNoProto);
TKIND(FunctionProto);
+ TKIND(ConstantArray);
}
#undef TKIND
return cxstring::createCXString(s);
@@ -373,6 +375,40 @@
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/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index 019110a..4ebbf9e 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -43,6 +43,8 @@
clang_equalTypes
clang_executeOnThread
clang_formatDiagnostic
+clang_getArrayElementType
+clang_getArraySize
clang_getCString
clang_getCXTUResourceUsage
clang_getCXXAccessSpecifier