diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-10-03 16:19:23 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-10-03 16:19:23 +0000 |
commit | 7a4253b68512edb5342047974f4080e5544dc027 (patch) | |
tree | 1d991007a3757e1c3163f81beb7e3f0cf4b06b6a | |
parent | 0bf8241d4bda427f47e3374f60f0203fdab0f5b1 (diff) | |
download | llvm-7a4253b68512edb5342047974f4080e5544dc027.zip llvm-7a4253b68512edb5342047974f4080e5544dc027.tar.gz llvm-7a4253b68512edb5342047974f4080e5544dc027.tar.bz2 |
[libclang] Introduce clang_Type_getClassType which returns the class type of a member pointer type.
Patch by Che-Liang Chiou!
llvm-svn: 191906
-rw-r--r-- | clang/bindings/python/clang/cindex.py | 12 | ||||
-rw-r--r-- | clang/include/clang-c/Index.h | 10 | ||||
-rw-r--r-- | clang/test/Index/print-type.cpp | 6 | ||||
-rw-r--r-- | clang/tools/libclang/CXType.cpp | 16 | ||||
-rw-r--r-- | clang/tools/libclang/libclang.exports | 1 |
5 files changed, 44 insertions, 1 deletions
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index fc32394..be65ebe 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -1487,6 +1487,7 @@ TypeKind.VECTOR = TypeKind(113) TypeKind.INCOMPLETEARRAY = TypeKind(114) TypeKind.VARIABLEARRAY = TypeKind(115) TypeKind.DEPENDENTSIZEDARRAY = TypeKind(116) +TypeKind.MEMBERPOINTER = TypeKind(117) class Type(Structure): """ @@ -1662,6 +1663,12 @@ class Type(Structure): """ return conf.lib.clang_getArraySize(self) + def get_class_type(self): + """ + Retrieve the class type of the member pointer type. + """ + return conf.lib.clang_Type_getClassType(self) + def get_align(self): """ Retrieve the alignment of the record. @@ -2694,6 +2701,11 @@ functionList = [ [Type], c_longlong), + ("clang_Type_getClassType", + [Type], + Type, + Type.from_result), + ("clang_getFieldDeclBitWidth", [Cursor], c_int), diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 4285cc5..ca0bc14 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -2678,7 +2678,8 @@ enum CXTypeKind { CXType_Vector = 113, CXType_IncompleteArray = 114, CXType_VariableArray = 115, - CXType_DependentSizedArray = 116 + CXType_DependentSizedArray = 116, + CXType_MemberPointer = 117 }; /** @@ -2969,6 +2970,13 @@ enum CXTypeLayoutError { CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T); /** + * \brief Return the class type of an member pointer type. + * + * If a non-member-pointer type is passed in, an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_Type_getClassType(CXType T); + +/** * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard. * * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned. diff --git a/clang/test/Index/print-type.cpp b/clang/test/Index/print-type.cpp index 5a9a06c..6324d43 100644 --- a/clang/test/Index/print-type.cpp +++ b/clang/test/Index/print-type.cpp @@ -34,6 +34,11 @@ T tbar(int[size]); void foo(int i, int incomplete_array[]) { int variable_array[i]; } +struct Blob { + int i; +}; +int Blob::*member_pointer; + // RUN: c-index-test -test-print-type %s | FileCheck %s // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0] @@ -73,3 +78,4 @@ void foo(int i, int incomplete_array[]) { int variable_array[i]; } // CHECK: ParmDecl=:33:11 (Definition) [type=int [size]] [typekind=DependentSizedArray] [isPOD=0] // CHECK: ParmDecl=incomplete_array:35:21 (Definition) [type=int []] [typekind=IncompleteArray] [isPOD=1] // CHECK: VarDecl=variable_array:35:47 (Definition) [type=int [i]] [typekind=VariableArray] [isPOD=1] +// CHECK: VarDecl=member_pointer:40:12 (Definition) [type=int Blob::*] [typekind=MemberPointer] [isPOD=1] diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp index a7d6386b..9233e97 100644 --- a/clang/tools/libclang/CXType.cpp +++ b/clang/tools/libclang/CXType.cpp @@ -89,6 +89,7 @@ static CXTypeKind GetTypeKind(QualType T) { TKCASE(VariableArray); TKCASE(DependentSizedArray); TKCASE(Vector); + TKCASE(MemberPointer); default: return CXType_Unexposed; } @@ -365,6 +366,9 @@ CXType clang_getPointeeType(CXType CT) { case Type::ObjCObjectPointer: T = cast<ObjCObjectPointerType>(TP)->getPointeeType(); break; + case Type::MemberPointer: + T = cast<MemberPointerType>(TP)->getPointeeType(); + break; default: T = QualType(); break; @@ -478,6 +482,7 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) { TKIND(VariableArray); TKIND(DependentSizedArray); TKIND(Vector); + TKIND(MemberPointer); } #undef TKIND return cxstring::createRef(s); @@ -707,6 +712,17 @@ long long clang_Type_getAlignOf(CXType T) { return Ctx.getTypeAlignInChars(QT).getQuantity(); } +CXType clang_Type_getClassType(CXType CT) { + QualType ET = QualType(); + QualType T = GetQualType(CT); + const Type *TP = T.getTypePtrOrNull(); + + if (TP && TP->getTypeClass() == Type::MemberPointer) { + ET = QualType(cast<MemberPointerType> (TP)->getClass(), 0); + } + return MakeCXType(ET, GetTU(CT)); +} + long long clang_Type_getSizeOf(CXType T) { if (T.kind == CXType_Invalid) return CXTypeLayoutError_Invalid; diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports index 92b060a..6f6e392 100644 --- a/clang/tools/libclang/libclang.exports +++ b/clang/tools/libclang/libclang.exports @@ -61,6 +61,7 @@ clang_TParamCommandComment_isParamPositionValid clang_TParamCommandComment_getDepth clang_TParamCommandComment_getIndex clang_Type_getAlignOf +clang_Type_getClassType clang_Type_getSizeOf clang_Type_getOffsetOf clang_VerbatimBlockLineComment_getText |