diff options
author | Sergey Kalinichev <kalinichev.so.0@gmail.com> | 2016-05-03 06:58:29 +0000 |
---|---|---|
committer | Sergey Kalinichev <kalinichev.so.0@gmail.com> | 2016-05-03 06:58:29 +0000 |
commit | 7cd277a1ffd44a36b2509856b29a28ff81d07304 (patch) | |
tree | a1268fe6add1a207aee3560f02ca7fb0c7851aae | |
parent | 5d99149b4624512b5d13de86fbd764565601109e (diff) |
[libclang] Expose the ElaboratedType
Differential Revision: http://reviews.llvm.org/D11797
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@268366 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | bindings/python/clang/cindex.py | 12 | ||||
-rw-r--r-- | include/clang-c/Index.h | 16 | ||||
-rw-r--r-- | test/Index/print-type.c | 8 | ||||
-rw-r--r-- | test/Index/print-type.cpp | 8 | ||||
-rw-r--r-- | tools/libclang/CXType.cpp | 12 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 1 |
6 files changed, 54 insertions, 3 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index b55c723dff..5f1c506adb 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -1750,6 +1750,7 @@ TypeKind.VARIABLEARRAY = TypeKind(115) TypeKind.DEPENDENTSIZEDARRAY = TypeKind(116) TypeKind.MEMBERPOINTER = TypeKind(117) TypeKind.AUTO = TypeKind(118) +TypeKind.ELABORATED = TypeKind(119) class RefQualifierKind(BaseEnumeration): """Describes a specific ref-qualifier of a type.""" @@ -1948,6 +1949,12 @@ class Type(Structure): """ return conf.lib.clang_Type_getClassType(self) + def get_named_type(self): + """ + Retrieve the type named by the qualified-id. + """ + return conf.lib.clang_Type_getNamedType(self) + def get_align(self): """ Retrieve the alignment of the record. @@ -3565,6 +3572,11 @@ functionList = [ [Type], c_uint), + ("clang_Type_getNamedType", + [Type], + Type, + Type.from_result), + ("clang_Type_visitFields", [Type, callbacks['fields_visit'], py_object], c_uint), diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index d520fce895..4ace0f5137 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -2950,7 +2950,14 @@ enum CXTypeKind { CXType_VariableArray = 115, CXType_DependentSizedArray = 116, CXType_MemberPointer = 117, - CXType_Auto = 118 + CXType_Auto = 118, + + /** + * \brief Represents a type that was referred to using an elaborated type keyword. + * + * E.g., struct S, or via a qualified name, e.g., N::M::type, or both. + */ + CXType_Elaborated = 119 }; /** @@ -3340,6 +3347,13 @@ CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T); CINDEX_LINKAGE long long clang_getArraySize(CXType T); /** + * \brief Retrieve the type named by the qualified-id. + * + * If a non-elaborated type is passed in, an invalid type is returned. + */ +CINDEX_LINKAGE CXType clang_Type_getNamedType(CXType T); + +/** * \brief List the possible error codes for \c clang_Type_getSizeOf, * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and * \c clang_Cursor_getOffsetOf. diff --git a/test/Index/print-type.c b/test/Index/print-type.c index 35aab711db..ebe42970ee 100644 --- a/test/Index/print-type.c +++ b/test/Index/print-type.c @@ -12,6 +12,9 @@ typedef int __attribute__((vector_size(16))) int4_t; int f2(int incompletearray[]); +enum Enum{i}; enum Enum elaboratedEnumType(); +struct Struct{}; struct Struct elaboratedStructType(); + // RUN: c-index-test -test-print-type %s | FileCheck %s // CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] [resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] [Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] [Pointer]] [isPOD=0] // CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] [isPOD=1] [pointeetype=int] [pointeekind=Int] @@ -45,3 +48,8 @@ int f2(int incompletearray[]); // CHECK: VarDecl=x:10:38 [type=__attribute__((__vector_size__(4 * sizeof(int)))) int] [typekind=Vector] [isPOD=1] // CHECK: TypedefDecl=int4_t:11:46 (Definition) [type=int4_t] [typekind=Typedef] [canonicaltype=__attribute__((__vector_size__(4 * sizeof(int)))) int] [canonicaltypekind=Vector] [isPOD=1] // CHECK: ParmDecl=incompletearray:13:12 (Definition) [type=int []] [typekind=IncompleteArray] [isPOD=1] +// CHECK: FunctionDecl=elaboratedEnumType:15:25 [type=enum Enum ()] [typekind=FunctionNoProto] [canonicaltype=enum Enum ()] [canonicaltypekind=FunctionNoProto] [resulttype=enum Enum] [resulttypekind=Elaborated] [isPOD=0] +// CHECK: TypeRef=enum Enum:15:6 [type=enum Enum] [typekind=Enum] [isPOD=1] +// CHECK: StructDecl=Struct:16:8 (Definition) [type=struct Struct] [typekind=Record] [isPOD=1] +// CHECK: FunctionDecl=elaboratedStructType:16:32 [type=struct Struct ()] [typekind=FunctionNoProto] [canonicaltype=struct Struct ()] [canonicaltypekind=FunctionNoProto] [resulttype=struct Struct] [resulttypekind=Elaborated] [isPOD=0] +// CHECK: TypeRef=struct Struct:16:8 [type=struct Struct] [typekind=Record] [isPOD=1] diff --git a/test/Index/print-type.cpp b/test/Index/print-type.cpp index d181f6b222..44fc11c365 100644 --- a/test/Index/print-type.cpp +++ b/test/Index/print-type.cpp @@ -48,7 +48,7 @@ struct Blob { }; int Blob::*member_pointer; - +namespace NS { struct Type{}; } NS::Type elaboratedNamespaceType(const NS::Type t); auto autoI = 0; auto autoTbar = tbar<int>(0); @@ -69,7 +69,7 @@ decltype(auto) autoInt = 5; // CHECK: Namespace=inner:14:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] // CHECK: StructDecl=Bar:16:8 (Definition) [type=outer::inner::Bar] [typekind=Record] [isPOD=0] [nbFields=3] // CHECK: CXXConstructor=Bar:17:3 (Definition) (converting constructor) [type=void (outer::Foo<bool> *){{.*}}] [typekind=FunctionProto] [canonicaltype=void (outer::Foo<bool> *){{.*}}] [canonicaltypekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [args= [outer::Foo<bool> *] [Pointer]] [isPOD=0] -// CHECK: ParmDecl=foo:17:25 (Definition) [type=outer::Foo<bool> *] [typekind=Pointer] [canonicaltype=outer::Foo<bool> *] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=outer::Foo<bool>] [pointeekind=Unexposed] +// CHECK: ParmDecl=foo:17:25 (Definition) [type=outer::Foo<bool> *] [typekind=Pointer] [canonicaltype=outer::Foo<bool> *] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=outer::Foo<bool>] [pointeekind=Elaborated] // CHECK: NamespaceRef=outer:1:11 [type=] [typekind=Invalid] [isPOD=0] // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0] // CHECK: CompoundStmt= [type=] [typekind=Invalid] [isPOD=0] @@ -127,6 +127,10 @@ decltype(auto) autoInt = 5; // CHECK: StructDecl=Blob:45:8 (Definition) [type=Blob] [typekind=Record] [isPOD=1] [nbFields=2] // CHECK: FieldDecl=i:46:7 (Definition) [type=int] [typekind=Int] [isPOD=1] // CHECK: VarDecl=member_pointer:49:12 (Definition) [type=int Blob::*] [typekind=MemberPointer] [isPOD=1] +// CHECK: FunctionDecl=elaboratedNamespaceType:51:42 [type=NS::Type (const NS::Type)] [typekind=FunctionProto] [canonicaltype=NS::Type (NS::Type)] [canonicaltypekind=FunctionProto] [resulttype=NS::Type] [resulttypekind=Elaborated] [args= [const NS::Type] [Elaborated]] [isPOD=0] +// CHECK: NamespaceRef=NS:51:11 [type=] [typekind=Invalid] [isPOD=0] +// CHECK: TypeRef=struct NS::Type:51:23 [type=NS::Type] [typekind=Record] [isPOD=1] +// CHECK: ParmDecl=t:51:81 (Definition) [type=const NS::Type] [typekind=Elaborated] const [canonicaltype=const NS::Type] [canonicaltypekind=Record] [isPOD=1] // CHECK: VarDecl=autoI:53:6 (Definition) [type=int] [typekind=Auto] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1] // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1] // CHECK: VarDecl=autoTbar:54:6 (Definition) [type=int] [typekind=Auto] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1] diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index 5cde236055..fbe1edae2a 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -91,6 +91,7 @@ static CXTypeKind GetTypeKind(QualType T) { TKCASE(Vector); TKCASE(MemberPointer); TKCASE(Auto); + TKCASE(Elaborated); default: return CXType_Unexposed; } @@ -491,6 +492,7 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) { TKIND(Vector); TKIND(MemberPointer); TKIND(Auto); + TKIND(Elaborated); } #undef TKIND return cxstring::createRef(s); @@ -987,4 +989,14 @@ unsigned clang_Cursor_isAnonymous(CXCursor C){ return 0; } +CXType clang_Type_getNamedType(CXType CT){ + QualType T = GetQualType(CT); + const Type *TP = T.getTypePtrOrNull(); + + if (TP && TP->getTypeClass() == Type::Elaborated) + return MakeCXType(cast<ElaboratedType>(TP)->getNamedType(), GetTU(CT)); + + return MakeCXType(QualType(), GetTU(CT)); +} + } // end: extern "C" diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index 14572f9154..c8fe0a21d0 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -87,6 +87,7 @@ clang_Type_getNumTemplateArguments clang_Type_getTemplateArgumentAsType clang_Type_getCXXRefQualifier clang_Type_visitFields +clang_Type_getNamedType clang_VerbatimBlockLineComment_getText clang_VerbatimLineComment_getText clang_HTMLTagComment_getAsString |