[cfe-commits] r140614 - in /cfe/trunk: include/clang-c/Index.h test/Index/print-typekind.c tools/libclang/CXType.cpp tools/libclang/libclang.exports
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Sep 27 10:44:35 PDT 2011
Author: akirtzidis
Date: Tue Sep 27 12:44:34 2011
New Revision: 140614
URL: http://llvm.org/viewvc/llvm-project?rev=140614&view=rev
Log:
[libclang] Expose array size and element type, patch by Vinay Sajip!
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/test/Index/print-typekind.c
cfe/trunk/tools/libclang/CXType.cpp
cfe/trunk/tools/libclang/libclang.exports
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=140614&r1=140613&r2=140614&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Sep 27 12:44:34 2011
@@ -1965,7 +1965,8 @@
CXType_ObjCInterface = 108,
CXType_ObjCObjectPointer = 109,
CXType_FunctionNoProto = 110,
- CXType_FunctionProto = 111
+ CXType_FunctionProto = 111,
+ CXType_ConstantArray = 112
};
/**
@@ -2057,6 +2058,20 @@
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.
*/
Modified: cfe/trunk/test/Index/print-typekind.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-typekind.c?rev=140614&r1=140613&r2=140614&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-typekind.c (original)
+++ cfe/trunk/test/Index/print-typekind.c Tue Sep 27 12:44:34 2011
@@ -5,6 +5,7 @@
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 @@
// 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]
Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=140614&r1=140613&r2=140614&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Tue Sep 27 12:44:34 2011
@@ -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("");
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=140614&r1=140613&r2=140614&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Tue Sep 27 12:44:34 2011
@@ -43,6 +43,8 @@
clang_equalTypes
clang_executeOnThread
clang_formatDiagnostic
+clang_getArrayElementType
+clang_getArraySize
clang_getCString
clang_getCXTUResourceUsage
clang_getCXXAccessSpecifier
More information about the cfe-commits
mailing list