1 //===- CXTypes.cpp - Implements 'CXTypes' aspect of libclang ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===--------------------------------------------------------------------===//
10 // This file implements the 'CXTypes' API hooks in the Clang-C library.
12 //===--------------------------------------------------------------------===//
17 #include "CXTranslationUnit.h"
19 #include "clang/AST/Decl.h"
20 #include "clang/AST/DeclObjC.h"
21 #include "clang/AST/DeclTemplate.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/Type.h"
24 #include "clang/Frontend/ASTUnit.h"
26 using namespace clang;
28 static CXTypeKind GetBuiltinTypeKind(const BuiltinType *BT) {
29 #define BTCASE(K) case BuiltinType::K: return CXType_##K
30 switch (BT->getKind()) {
44 case BuiltinType::WChar_S: return CXType_WChar;
45 case BuiltinType::WChar_U: return CXType_WChar;
61 return CXType_Unexposed;
66 static CXTypeKind GetTypeKind(QualType T) {
67 const Type *TP = T.getTypePtrOrNull();
69 return CXType_Invalid;
71 #define TKCASE(K) case Type::K: return CXType_##K
72 switch (TP->getTypeClass()) {
74 return GetBuiltinTypeKind(cast<BuiltinType>(TP));
78 TKCASE(LValueReference);
79 TKCASE(RValueReference);
83 TKCASE(ObjCInterface);
84 TKCASE(ObjCObjectPointer);
85 TKCASE(FunctionNoProto);
86 TKCASE(FunctionProto);
87 TKCASE(ConstantArray);
88 TKCASE(IncompleteArray);
89 TKCASE(VariableArray);
90 TKCASE(DependentSizedArray);
92 TKCASE(MemberPointer);
94 return CXType_Unexposed;
100 CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) {
101 CXTypeKind TK = CXType_Invalid;
103 if (TU && !T.isNull()) {
104 ASTContext &Ctx = cxtu::getASTUnit(TU)->getASTContext();
105 if (Ctx.getLangOpts().ObjC1) {
106 QualType UnqualT = T.getUnqualifiedType();
107 if (Ctx.isObjCIdType(UnqualT))
109 else if (Ctx.isObjCClassType(UnqualT))
110 TK = CXType_ObjCClass;
111 else if (Ctx.isObjCSelType(UnqualT))
115 /* Handle decayed types as the original type */
116 if (const DecayedType *DT = T->getAs<DecayedType>()) {
117 return MakeCXType(DT->getOriginalType(), TU);
120 if (TK == CXType_Invalid)
123 CXType CT = { TK, { TK == CXType_Invalid ? nullptr
124 : T.getAsOpaquePtr(), TU } };
128 using cxtype::MakeCXType;
130 static inline QualType GetQualType(CXType CT) {
131 return QualType::getFromOpaquePtr(CT.data[0]);
134 static inline CXTranslationUnit GetTU(CXType CT) {
135 return static_cast<CXTranslationUnit>(CT.data[1]);
140 CXType clang_getCursorType(CXCursor C) {
141 using namespace cxcursor;
143 CXTranslationUnit TU = cxcursor::getCursorTU(C);
145 return MakeCXType(QualType(), TU);
147 ASTContext &Context = cxtu::getASTUnit(TU)->getASTContext();
148 if (clang_isExpression(C.kind)) {
149 QualType T = cxcursor::getCursorExpr(C)->getType();
150 return MakeCXType(T, TU);
153 if (clang_isDeclaration(C.kind)) {
154 const Decl *D = cxcursor::getCursorDecl(C);
156 return MakeCXType(QualType(), TU);
158 if (const TypeDecl *TD = dyn_cast<TypeDecl>(D))
159 return MakeCXType(Context.getTypeDeclType(TD), TU);
160 if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
161 return MakeCXType(Context.getObjCInterfaceType(ID), TU);
162 if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
163 if (TypeSourceInfo *TSInfo = DD->getTypeSourceInfo())
164 return MakeCXType(TSInfo->getType(), TU);
165 return MakeCXType(DD->getType(), TU);
167 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
168 return MakeCXType(VD->getType(), TU);
169 if (const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D))
170 return MakeCXType(PD->getType(), TU);
171 if (const FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(D)) {
172 if (TypeSourceInfo *TSInfo = FTD->getTemplatedDecl()->getTypeSourceInfo())
173 return MakeCXType(TSInfo->getType(), TU);
174 return MakeCXType(FTD->getTemplatedDecl()->getType(), TU);
176 return MakeCXType(QualType(), TU);
179 if (clang_isReference(C.kind)) {
181 case CXCursor_ObjCSuperClassRef: {
183 = Context.getObjCInterfaceType(getCursorObjCSuperClassRef(C).first);
184 return MakeCXType(T, TU);
187 case CXCursor_ObjCClassRef: {
188 QualType T = Context.getObjCInterfaceType(getCursorObjCClassRef(C).first);
189 return MakeCXType(T, TU);
192 case CXCursor_TypeRef: {
193 QualType T = Context.getTypeDeclType(getCursorTypeRef(C).first);
194 return MakeCXType(T, TU);
198 case CXCursor_CXXBaseSpecifier:
199 return cxtype::MakeCXType(getCursorCXXBaseSpecifier(C)->getType(), TU);
201 case CXCursor_MemberRef:
202 return cxtype::MakeCXType(getCursorMemberRef(C).first->getType(), TU);
204 case CXCursor_VariableRef:
205 return cxtype::MakeCXType(getCursorVariableRef(C).first->getType(), TU);
207 case CXCursor_ObjCProtocolRef:
208 case CXCursor_TemplateRef:
209 case CXCursor_NamespaceRef:
210 case CXCursor_OverloadedDeclRef:
215 return MakeCXType(QualType(), TU);
218 return MakeCXType(QualType(), TU);
221 CXString clang_getTypeSpelling(CXType CT) {
222 QualType T = GetQualType(CT);
224 return cxstring::createEmpty();
226 CXTranslationUnit TU = GetTU(CT);
228 llvm::raw_svector_ostream OS(Str);
229 PrintingPolicy PP(cxtu::getASTUnit(TU)->getASTContext().getLangOpts());
233 return cxstring::createDup(OS.str());
236 CXType clang_getTypedefDeclUnderlyingType(CXCursor C) {
237 using namespace cxcursor;
238 CXTranslationUnit TU = cxcursor::getCursorTU(C);
240 if (clang_isDeclaration(C.kind)) {
241 const Decl *D = cxcursor::getCursorDecl(C);
243 if (const TypedefNameDecl *TD = dyn_cast_or_null<TypedefNameDecl>(D)) {
244 QualType T = TD->getUnderlyingType();
245 return MakeCXType(T, TU);
248 return MakeCXType(QualType(), TU);
251 return MakeCXType(QualType(), TU);
254 CXType clang_getEnumDeclIntegerType(CXCursor C) {
255 using namespace cxcursor;
256 CXTranslationUnit TU = cxcursor::getCursorTU(C);
258 if (clang_isDeclaration(C.kind)) {
259 const Decl *D = cxcursor::getCursorDecl(C);
261 if (const EnumDecl *TD = dyn_cast_or_null<EnumDecl>(D)) {
262 QualType T = TD->getIntegerType();
263 return MakeCXType(T, TU);
266 return MakeCXType(QualType(), TU);
269 return MakeCXType(QualType(), TU);
272 long long clang_getEnumConstantDeclValue(CXCursor C) {
273 using namespace cxcursor;
275 if (clang_isDeclaration(C.kind)) {
276 const Decl *D = cxcursor::getCursorDecl(C);
278 if (const EnumConstantDecl *TD = dyn_cast_or_null<EnumConstantDecl>(D)) {
279 return TD->getInitVal().getSExtValue();
288 unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C) {
289 using namespace cxcursor;
291 if (clang_isDeclaration(C.kind)) {
292 const Decl *D = cxcursor::getCursorDecl(C);
294 if (const EnumConstantDecl *TD = dyn_cast_or_null<EnumConstantDecl>(D)) {
295 return TD->getInitVal().getZExtValue();
304 int clang_getFieldDeclBitWidth(CXCursor C) {
305 using namespace cxcursor;
307 if (clang_isDeclaration(C.kind)) {
308 const Decl *D = getCursorDecl(C);
310 if (const FieldDecl *FD = dyn_cast_or_null<FieldDecl>(D)) {
311 if (FD->isBitField())
312 return FD->getBitWidthValue(getCursorContext(C));
319 CXType clang_getCanonicalType(CXType CT) {
320 if (CT.kind == CXType_Invalid)
323 QualType T = GetQualType(CT);
324 CXTranslationUnit TU = GetTU(CT);
327 return MakeCXType(QualType(), GetTU(CT));
329 return MakeCXType(cxtu::getASTUnit(TU)->getASTContext()
330 .getCanonicalType(T),
334 unsigned clang_isConstQualifiedType(CXType CT) {
335 QualType T = GetQualType(CT);
336 return T.isLocalConstQualified();
339 unsigned clang_isVolatileQualifiedType(CXType CT) {
340 QualType T = GetQualType(CT);
341 return T.isLocalVolatileQualified();
344 unsigned clang_isRestrictQualifiedType(CXType CT) {
345 QualType T = GetQualType(CT);
346 return T.isLocalRestrictQualified();
349 CXType clang_getPointeeType(CXType CT) {
350 QualType T = GetQualType(CT);
351 const Type *TP = T.getTypePtrOrNull();
354 return MakeCXType(QualType(), GetTU(CT));
356 switch (TP->getTypeClass()) {
358 T = cast<PointerType>(TP)->getPointeeType();
360 case Type::BlockPointer:
361 T = cast<BlockPointerType>(TP)->getPointeeType();
363 case Type::LValueReference:
364 case Type::RValueReference:
365 T = cast<ReferenceType>(TP)->getPointeeType();
367 case Type::ObjCObjectPointer:
368 T = cast<ObjCObjectPointerType>(TP)->getPointeeType();
370 case Type::MemberPointer:
371 T = cast<MemberPointerType>(TP)->getPointeeType();
377 return MakeCXType(T, GetTU(CT));
380 CXCursor clang_getTypeDeclaration(CXType CT) {
381 if (CT.kind == CXType_Invalid)
382 return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
384 QualType T = GetQualType(CT);
385 const Type *TP = T.getTypePtrOrNull();
388 return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
393 switch (TP->getTypeClass()) {
395 D = cast<TypedefType>(TP)->getDecl();
397 case Type::ObjCObject:
398 D = cast<ObjCObjectType>(TP)->getInterface();
400 case Type::ObjCInterface:
401 D = cast<ObjCInterfaceType>(TP)->getDecl();
405 D = cast<TagType>(TP)->getDecl();
407 case Type::TemplateSpecialization:
408 if (const RecordType *Record = TP->getAs<RecordType>())
409 D = Record->getDecl();
411 D = cast<TemplateSpecializationType>(TP)->getTemplateName()
412 .getAsTemplateDecl();
415 case Type::InjectedClassName:
416 D = cast<InjectedClassNameType>(TP)->getDecl();
419 // FIXME: Template type parameters!
421 case Type::Elaborated:
422 TP = cast<ElaboratedType>(TP)->getNamedType().getTypePtrOrNull();
430 return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
432 return cxcursor::MakeCXCursor(D, GetTU(CT));
435 CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
436 const char *s = nullptr;
437 #define TKIND(X) case CXType_##X: s = "" #X ""; break
454 case CXType_WChar: s = "WChar"; break;
472 TKIND(LValueReference);
473 TKIND(RValueReference);
477 TKIND(ObjCInterface);
478 TKIND(ObjCObjectPointer);
479 TKIND(FunctionNoProto);
480 TKIND(FunctionProto);
481 TKIND(ConstantArray);
482 TKIND(IncompleteArray);
483 TKIND(VariableArray);
484 TKIND(DependentSizedArray);
486 TKIND(MemberPointer);
489 return cxstring::createRef(s);
492 unsigned clang_equalTypes(CXType A, CXType B) {
493 return A.data[0] == B.data[0] && A.data[1] == B.data[1];;
496 unsigned clang_isFunctionTypeVariadic(CXType X) {
497 QualType T = GetQualType(X);
501 if (const FunctionProtoType *FD = T->getAs<FunctionProtoType>())
502 return (unsigned)FD->isVariadic();
504 if (T->getAs<FunctionNoProtoType>())
510 CXCallingConv clang_getFunctionTypeCallingConv(CXType X) {
511 QualType T = GetQualType(X);
513 return CXCallingConv_Invalid;
515 if (const FunctionType *FD = T->getAs<FunctionType>()) {
516 #define TCALLINGCONV(X) case CC_##X: return CXCallingConv_##X
517 switch (FD->getCallConv()) {
519 TCALLINGCONV(X86StdCall);
520 TCALLINGCONV(X86FastCall);
521 TCALLINGCONV(X86ThisCall);
522 TCALLINGCONV(X86Pascal);
523 TCALLINGCONV(X86_64Win64);
524 TCALLINGCONV(X86_64SysV);
526 TCALLINGCONV(AAPCS_VFP);
527 TCALLINGCONV(PnaclCall);
528 TCALLINGCONV(IntelOclBicc);
533 return CXCallingConv_Invalid;
536 int clang_getNumArgTypes(CXType X) {
537 QualType T = GetQualType(X);
541 if (const FunctionProtoType *FD = T->getAs<FunctionProtoType>()) {
542 return FD->getNumParams();
545 if (T->getAs<FunctionNoProtoType>()) {
552 CXType clang_getArgType(CXType X, unsigned i) {
553 QualType T = GetQualType(X);
555 return MakeCXType(QualType(), GetTU(X));
557 if (const FunctionProtoType *FD = T->getAs<FunctionProtoType>()) {
558 unsigned numParams = FD->getNumParams();
560 return MakeCXType(QualType(), GetTU(X));
562 return MakeCXType(FD->getParamType(i), GetTU(X));
565 return MakeCXType(QualType(), GetTU(X));
568 CXType clang_getResultType(CXType X) {
569 QualType T = GetQualType(X);
571 return MakeCXType(QualType(), GetTU(X));
573 if (const FunctionType *FD = T->getAs<FunctionType>())
574 return MakeCXType(FD->getReturnType(), GetTU(X));
576 return MakeCXType(QualType(), GetTU(X));
579 CXType clang_getCursorResultType(CXCursor C) {
580 if (clang_isDeclaration(C.kind)) {
581 const Decl *D = cxcursor::getCursorDecl(C);
582 if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
583 return MakeCXType(MD->getReturnType(), cxcursor::getCursorTU(C));
585 return clang_getResultType(clang_getCursorType(C));
588 return MakeCXType(QualType(), cxcursor::getCursorTU(C));
591 unsigned clang_isPODType(CXType X) {
592 QualType T = GetQualType(X);
596 CXTranslationUnit TU = GetTU(X);
598 return T.isPODType(cxtu::getASTUnit(TU)->getASTContext()) ? 1 : 0;
601 CXType clang_getElementType(CXType CT) {
602 QualType ET = QualType();
603 QualType T = GetQualType(CT);
604 const Type *TP = T.getTypePtrOrNull();
607 switch (TP->getTypeClass()) {
608 case Type::ConstantArray:
609 ET = cast<ConstantArrayType> (TP)->getElementType();
611 case Type::IncompleteArray:
612 ET = cast<IncompleteArrayType> (TP)->getElementType();
614 case Type::VariableArray:
615 ET = cast<VariableArrayType> (TP)->getElementType();
617 case Type::DependentSizedArray:
618 ET = cast<DependentSizedArrayType> (TP)->getElementType();
621 ET = cast<VectorType> (TP)->getElementType();
624 ET = cast<ComplexType> (TP)->getElementType();
630 return MakeCXType(ET, GetTU(CT));
633 long long clang_getNumElements(CXType CT) {
634 long long result = -1;
635 QualType T = GetQualType(CT);
636 const Type *TP = T.getTypePtrOrNull();
639 switch (TP->getTypeClass()) {
640 case Type::ConstantArray:
641 result = cast<ConstantArrayType> (TP)->getSize().getSExtValue();
644 result = cast<VectorType> (TP)->getNumElements();
653 CXType clang_getArrayElementType(CXType CT) {
654 QualType ET = QualType();
655 QualType T = GetQualType(CT);
656 const Type *TP = T.getTypePtrOrNull();
659 switch (TP->getTypeClass()) {
660 case Type::ConstantArray:
661 ET = cast<ConstantArrayType> (TP)->getElementType();
663 case Type::IncompleteArray:
664 ET = cast<IncompleteArrayType> (TP)->getElementType();
666 case Type::VariableArray:
667 ET = cast<VariableArrayType> (TP)->getElementType();
669 case Type::DependentSizedArray:
670 ET = cast<DependentSizedArrayType> (TP)->getElementType();
676 return MakeCXType(ET, GetTU(CT));
679 long long clang_getArraySize(CXType CT) {
680 long long result = -1;
681 QualType T = GetQualType(CT);
682 const Type *TP = T.getTypePtrOrNull();
685 switch (TP->getTypeClass()) {
686 case Type::ConstantArray:
687 result = cast<ConstantArrayType> (TP)->getSize().getSExtValue();
696 long long clang_Type_getAlignOf(CXType T) {
697 if (T.kind == CXType_Invalid)
698 return CXTypeLayoutError_Invalid;
699 ASTContext &Ctx = cxtu::getASTUnit(GetTU(T))->getASTContext();
700 QualType QT = GetQualType(T);
701 // [expr.alignof] p1: return size_t value for complete object type, reference
703 // [expr.alignof] p3: if reference type, return size of referenced type
704 if (QT->isReferenceType())
705 QT = QT.getNonReferenceType();
706 if (QT->isIncompleteType())
707 return CXTypeLayoutError_Incomplete;
708 if (QT->isDependentType())
709 return CXTypeLayoutError_Dependent;
710 // Exceptions by GCC extension - see ASTContext.cpp:1313 getTypeInfoImpl
711 // if (QT->isFunctionType()) return 4; // Bug #15511 - should be 1
712 // if (QT->isVoidType()) return 1;
713 return Ctx.getTypeAlignInChars(QT).getQuantity();
716 CXType clang_Type_getClassType(CXType CT) {
717 QualType ET = QualType();
718 QualType T = GetQualType(CT);
719 const Type *TP = T.getTypePtrOrNull();
721 if (TP && TP->getTypeClass() == Type::MemberPointer) {
722 ET = QualType(cast<MemberPointerType> (TP)->getClass(), 0);
724 return MakeCXType(ET, GetTU(CT));
727 long long clang_Type_getSizeOf(CXType T) {
728 if (T.kind == CXType_Invalid)
729 return CXTypeLayoutError_Invalid;
730 ASTContext &Ctx = cxtu::getASTUnit(GetTU(T))->getASTContext();
731 QualType QT = GetQualType(T);
732 // [expr.sizeof] p2: if reference type, return size of referenced type
733 if (QT->isReferenceType())
734 QT = QT.getNonReferenceType();
735 // [expr.sizeof] p1: return -1 on: func, incomplete, bitfield, incomplete
737 // Note: We get the cxtype, not the cxcursor, so we can't call
738 // FieldDecl->isBitField()
739 // [expr.sizeof] p3: pointer ok, function not ok.
740 // [gcc extension] lib/AST/ExprConstant.cpp:1372 HandleSizeof : vla == error
741 if (QT->isIncompleteType())
742 return CXTypeLayoutError_Incomplete;
743 if (QT->isDependentType())
744 return CXTypeLayoutError_Dependent;
745 if (!QT->isConstantSizeType())
746 return CXTypeLayoutError_NotConstantSize;
747 // [gcc extension] lib/AST/ExprConstant.cpp:1372
748 // HandleSizeof : {voidtype,functype} == 1
749 // not handled by ASTContext.cpp:1313 getTypeInfoImpl
750 if (QT->isVoidType() || QT->isFunctionType())
752 return Ctx.getTypeSizeInChars(QT).getQuantity();
755 static long long visitRecordForValidation(const RecordDecl *RD) {
756 for (const auto *I : RD->fields()){
757 QualType FQT = I->getType();
758 if (FQT->isIncompleteType())
759 return CXTypeLayoutError_Incomplete;
760 if (FQT->isDependentType())
761 return CXTypeLayoutError_Dependent;
763 if (const RecordType *ChildType = I->getType()->getAs<RecordType>()) {
764 if (const RecordDecl *Child = ChildType->getDecl()) {
765 long long ret = visitRecordForValidation(Child);
770 // else try next field
775 long long clang_Type_getOffsetOf(CXType PT, const char *S) {
776 // check that PT is not incomplete/dependent
777 CXCursor PC = clang_getTypeDeclaration(PT);
778 if (clang_isInvalid(PC.kind))
779 return CXTypeLayoutError_Invalid;
780 const RecordDecl *RD =
781 dyn_cast_or_null<RecordDecl>(cxcursor::getCursorDecl(PC));
782 if (!RD || RD->isInvalidDecl())
783 return CXTypeLayoutError_Invalid;
784 RD = RD->getDefinition();
786 return CXTypeLayoutError_Incomplete;
787 if (RD->isInvalidDecl())
788 return CXTypeLayoutError_Invalid;
789 QualType RT = GetQualType(PT);
790 if (RT->isIncompleteType())
791 return CXTypeLayoutError_Incomplete;
792 if (RT->isDependentType())
793 return CXTypeLayoutError_Dependent;
794 // We recurse into all record fields to detect incomplete and dependent types.
795 long long Error = visitRecordForValidation(RD);
799 return CXTypeLayoutError_InvalidFieldName;
801 ASTContext &Ctx = cxtu::getASTUnit(GetTU(PT))->getASTContext();
802 IdentifierInfo *II = &Ctx.Idents.get(S);
803 DeclarationName FieldName(II);
804 RecordDecl::lookup_const_result Res = RD->lookup(FieldName);
805 // If a field of the parent record is incomplete, lookup will fail.
806 // and we would return InvalidFieldName instead of Incomplete.
807 // But this erroneous results does protects again a hidden assertion failure
808 // in the RecordLayoutBuilder
810 return CXTypeLayoutError_InvalidFieldName;
811 if (const FieldDecl *FD = dyn_cast<FieldDecl>(Res.front()))
812 return Ctx.getFieldOffset(FD);
813 if (const IndirectFieldDecl *IFD = dyn_cast<IndirectFieldDecl>(Res.front()))
814 return Ctx.getFieldOffset(IFD);
815 // we don't want any other Decl Type.
816 return CXTypeLayoutError_InvalidFieldName;
819 enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T) {
820 QualType QT = GetQualType(T);
822 return CXRefQualifier_None;
823 const FunctionProtoType *FD = QT->getAs<FunctionProtoType>();
825 return CXRefQualifier_None;
826 switch (FD->getRefQualifier()) {
828 return CXRefQualifier_None;
830 return CXRefQualifier_LValue;
832 return CXRefQualifier_RValue;
834 return CXRefQualifier_None;
837 unsigned clang_Cursor_isBitField(CXCursor C) {
838 if (!clang_isDeclaration(C.kind))
840 const FieldDecl *FD = dyn_cast_or_null<FieldDecl>(cxcursor::getCursorDecl(C));
843 return FD->isBitField();
846 CXString clang_getDeclObjCTypeEncoding(CXCursor C) {
847 if (!clang_isDeclaration(C.kind))
848 return cxstring::createEmpty();
850 const Decl *D = cxcursor::getCursorDecl(C);
851 ASTContext &Ctx = cxcursor::getCursorContext(C);
852 std::string encoding;
854 if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
855 if (Ctx.getObjCEncodingForMethodDecl(OMD, encoding))
856 return cxstring::createRef("?");
857 } else if (const ObjCPropertyDecl *OPD = dyn_cast<ObjCPropertyDecl>(D))
858 Ctx.getObjCEncodingForPropertyDecl(OPD, nullptr, encoding);
859 else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
860 Ctx.getObjCEncodingForFunctionDecl(FD, encoding);
863 if (const TypeDecl *TD = dyn_cast<TypeDecl>(D))
864 Ty = Ctx.getTypeDeclType(TD);
865 if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
867 else return cxstring::createRef("?");
868 Ctx.getObjCEncodingForType(Ty, encoding);
871 return cxstring::createDup(encoding);
874 int clang_Type_getNumTemplateArguments(CXType CT) {
875 QualType T = GetQualType(CT);
878 const CXXRecordDecl *RecordDecl = T->getAsCXXRecordDecl();
881 const ClassTemplateSpecializationDecl *TemplateDecl =
882 dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl);
885 return TemplateDecl->getTemplateArgs().size();
888 CXType clang_Type_getTemplateArgumentAsType(CXType CT, unsigned i) {
889 QualType T = GetQualType(CT);
891 return MakeCXType(QualType(), GetTU(CT));
892 const CXXRecordDecl *RecordDecl = T->getAsCXXRecordDecl();
894 return MakeCXType(QualType(), GetTU(CT));
895 const ClassTemplateSpecializationDecl *TemplateDecl =
896 dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl);
898 return MakeCXType(QualType(), GetTU(CT));
899 const TemplateArgumentList &TA = TemplateDecl->getTemplateArgs();
901 return MakeCXType(QualType(), GetTU(CT));
902 const TemplateArgument &A = TA.get(i);
903 if (A.getKind() != TemplateArgument::Type)
904 return MakeCXType(QualType(), GetTU(CT));
905 return MakeCXType(A.getAsType(), GetTU(CT));