451
458
if (comments::FullComment *FC = getCommentForDecl(TD, PP))
452
459
return cloneFullComment(FC, D);
461
else if (const ObjCInterfaceDecl *IC = dyn_cast<ObjCInterfaceDecl>(D)) {
462
while (IC->getSuperClass()) {
463
IC = IC->getSuperClass();
464
if (comments::FullComment *FC = getCommentForDecl(IC, PP))
465
return cloneFullComment(FC, D);
468
else if (const ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(D)) {
469
if (const ObjCInterfaceDecl *IC = CD->getClassInterface())
470
if (comments::FullComment *FC = getCommentForDecl(IC, PP))
471
return cloneFullComment(FC, D);
473
else if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
474
if (!(RD = RD->getDefinition()))
476
// Check non-virtual bases.
477
for (CXXRecordDecl::base_class_const_iterator I =
478
RD->bases_begin(), E = RD->bases_end(); I != E; ++I) {
479
if (I->isVirtual() || (I->getAccessSpecifier() != AS_public))
481
QualType Ty = I->getType();
484
if (const CXXRecordDecl *NonVirtualBase = Ty->getAsCXXRecordDecl()) {
485
if (!(NonVirtualBase= NonVirtualBase->getDefinition()))
488
if (comments::FullComment *FC = getCommentForDecl((NonVirtualBase), PP))
489
return cloneFullComment(FC, D);
492
// Check virtual bases.
493
for (CXXRecordDecl::base_class_const_iterator I =
494
RD->vbases_begin(), E = RD->vbases_end(); I != E; ++I) {
495
if (I->getAccessSpecifier() != AS_public)
497
QualType Ty = I->getType();
500
if (const CXXRecordDecl *VirtualBase = Ty->getAsCXXRecordDecl()) {
501
if (!(VirtualBase= VirtualBase->getDefinition()))
503
if (comments::FullComment *FC = getCommentForDecl((VirtualBase), PP))
504
return cloneFullComment(FC, D);
850
904
InitBuiltinType(Int128Ty, BuiltinType::Int128);
851
905
InitBuiltinType(UnsignedInt128Ty, BuiltinType::UInt128);
853
if (LangOpts.CPlusPlus && LangOpts.WChar) { // C++ 3.9.1p5
854
if (TargetInfo::isTypeSigned(Target.getWCharType()))
855
InitBuiltinType(WCharTy, BuiltinType::WChar_S);
856
else // -fshort-wchar makes wchar_t be unsigned.
857
InitBuiltinType(WCharTy, BuiltinType::WChar_U);
858
} else // C99 (or C++ using -fno-wchar)
859
WCharTy = getFromTargetType(Target.getWCharType());
908
if (TargetInfo::isTypeSigned(Target.getWCharType()))
909
InitBuiltinType(WCharTy, BuiltinType::WChar_S);
910
else // -fshort-wchar makes wchar_t be unsigned.
911
InitBuiltinType(WCharTy, BuiltinType::WChar_U);
912
if (LangOpts.CPlusPlus && LangOpts.WChar)
913
WideCharTy = WCharTy;
915
// C99 (or C++ using -fno-wchar).
916
WideCharTy = getFromTargetType(Target.getWCharType());
861
919
WIntTy = getFromTargetType(Target.getWIntType());
1288
1350
return sizeAndAlign;
1353
/// getConstantArrayInfoInChars - Performing the computation in CharUnits
1354
/// instead of in bits prevents overflowing the uint64_t for some large arrays.
1355
std::pair<CharUnits, CharUnits>
1356
static getConstantArrayInfoInChars(const ASTContext &Context,
1357
const ConstantArrayType *CAT) {
1358
std::pair<CharUnits, CharUnits> EltInfo =
1359
Context.getTypeInfoInChars(CAT->getElementType());
1360
uint64_t Size = CAT->getSize().getZExtValue();
1361
assert((Size == 0 || static_cast<uint64_t>(EltInfo.first.getQuantity()) <=
1362
(uint64_t)(-1)/Size) &&
1363
"Overflow in array type char size evaluation");
1364
uint64_t Width = EltInfo.first.getQuantity() * Size;
1365
unsigned Align = EltInfo.second.getQuantity();
1366
Width = llvm::RoundUpToAlignment(Width, Align);
1367
return std::make_pair(CharUnits::fromQuantity(Width),
1368
CharUnits::fromQuantity(Align));
1291
1371
std::pair<CharUnits, CharUnits>
1292
1372
ASTContext::getTypeInfoInChars(const Type *T) const {
1373
if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(T))
1374
return getConstantArrayInfoInChars(*this, CAT);
1293
1375
std::pair<uint64_t, unsigned> Info = getTypeInfo(T);
1294
1376
return std::make_pair(toCharUnitsFromBits(Info.first),
1295
1377
toCharUnitsFromBits(Info.second));
1644
1727
/// getTypeSizeInChars - Return the size of the specified type, in characters.
1645
1728
/// This method does not work on incomplete types.
1646
1729
CharUnits ASTContext::getTypeSizeInChars(QualType T) const {
1647
return toCharUnitsFromBits(getTypeSize(T));
1730
return getTypeInfoInChars(T).first;
1649
1732
CharUnits ASTContext::getTypeSizeInChars(const Type *T) const {
1650
return toCharUnitsFromBits(getTypeSize(T));
1733
return getTypeInfoInChars(T).first;
1653
1736
/// getTypeAlignInChars - Return the ABI-specified alignment of a type, in
1677
1760
return ABIAlign;
1763
/// getAlignOfGlobalVar - Return the alignment in bits that should be given
1764
/// to a global variable of the specified type.
1765
unsigned ASTContext::getAlignOfGlobalVar(QualType T) const {
1766
return std::max(getTypeAlign(T), getTargetInfo().getMinGlobalAlign());
1769
/// getAlignOfGlobalVarInChars - Return the alignment in characters that
1770
/// should be given to a global variable of the specified type.
1771
CharUnits ASTContext::getAlignOfGlobalVarInChars(QualType T) const {
1772
return toCharUnitsFromBits(getAlignOfGlobalVar(T));
1680
1775
/// DeepCollectObjCIvars -
1681
1776
/// This routine first collects all declared, but not synthesized, ivars in
1682
1777
/// super class and then collects all ivars, including those synthesized for
1987
2082
return cast<FunctionType>(Result.getTypePtr());
2085
void ASTContext::adjustDeducedFunctionResultType(FunctionDecl *FD,
2086
QualType ResultType) {
2087
FD = FD->getMostRecentDecl();
2089
const FunctionProtoType *FPT = FD->getType()->castAs<FunctionProtoType>();
2090
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
2091
FD->setType(getFunctionType(ResultType, FPT->getArgTypes(), EPI));
2092
if (FunctionDecl *Next = FD->getPreviousDecl())
2097
if (ASTMutationListener *L = getASTMutationListener())
2098
L->DeducedReturnType(FD, ResultType);
1990
2101
/// getComplexType - Return the uniqued reference to the type for a complex
1991
2102
/// number with the specified element type.
1992
2103
QualType ASTContext::getComplexType(QualType T) const {
3515
3626
return QualType(Ty, 0);
3518
/// getAutoType - We only unique auto types after they've been deduced.
3519
QualType ASTContext::getAutoType(QualType DeducedType) const {
3629
/// getAutoType - Return the uniqued reference to the 'auto' type which has been
3630
/// deduced to the given type, or to the canonical undeduced 'auto' type, or the
3631
/// canonical deduced-but-dependent 'auto' type.
3632
QualType ASTContext::getAutoType(QualType DeducedType, bool IsDecltypeAuto,
3633
bool IsDependent) const {
3634
if (DeducedType.isNull() && !IsDecltypeAuto && !IsDependent)
3635
return getAutoDeductType();
3637
// Look in the folding set for an existing type.
3520
3638
void *InsertPos = 0;
3521
if (!DeducedType.isNull()) {
3522
// Look in the folding set for an existing type.
3523
llvm::FoldingSetNodeID ID;
3524
AutoType::Profile(ID, DeducedType);
3525
if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
3526
return QualType(AT, 0);
3639
llvm::FoldingSetNodeID ID;
3640
AutoType::Profile(ID, DeducedType, IsDecltypeAuto, IsDependent);
3641
if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
3642
return QualType(AT, 0);
3529
AutoType *AT = new (*this, TypeAlignment) AutoType(DeducedType);
3644
AutoType *AT = new (*this, TypeAlignment) AutoType(DeducedType,
3530
3647
Types.push_back(AT);
3532
3649
AutoTypes.InsertNode(AT, InsertPos);
5893
6021
return VaListTypeDecl;
6024
static TypedefDecl *
6025
CreateSystemZBuiltinVaListDecl(const ASTContext *Context) {
6026
// typedef struct __va_list_tag {
6027
RecordDecl *VaListTagDecl;
6028
VaListTagDecl = CreateRecordDecl(*Context, TTK_Struct,
6029
Context->getTranslationUnitDecl(),
6030
&Context->Idents.get("__va_list_tag"));
6031
VaListTagDecl->startDefinition();
6033
const size_t NumFields = 4;
6034
QualType FieldTypes[NumFields];
6035
const char *FieldNames[NumFields];
6038
FieldTypes[0] = Context->LongTy;
6039
FieldNames[0] = "__gpr";
6042
FieldTypes[1] = Context->LongTy;
6043
FieldNames[1] = "__fpr";
6045
// void *__overflow_arg_area;
6046
FieldTypes[2] = Context->getPointerType(Context->VoidTy);
6047
FieldNames[2] = "__overflow_arg_area";
6049
// void *__reg_save_area;
6050
FieldTypes[3] = Context->getPointerType(Context->VoidTy);
6051
FieldNames[3] = "__reg_save_area";
6054
for (unsigned i = 0; i < NumFields; ++i) {
6055
FieldDecl *Field = FieldDecl::Create(const_cast<ASTContext &>(*Context),
6059
&Context->Idents.get(FieldNames[i]),
6060
FieldTypes[i], /*TInfo=*/0,
6064
Field->setAccess(AS_public);
6065
VaListTagDecl->addDecl(Field);
6067
VaListTagDecl->completeDefinition();
6068
QualType VaListTagType = Context->getRecordType(VaListTagDecl);
6069
Context->VaListTagTy = VaListTagType;
6072
TypedefDecl *VaListTagTypedefDecl
6073
= TypedefDecl::Create(const_cast<ASTContext &>(*Context),
6074
Context->getTranslationUnitDecl(),
6075
SourceLocation(), SourceLocation(),
6076
&Context->Idents.get("__va_list_tag"),
6077
Context->getTrivialTypeSourceInfo(VaListTagType));
6078
QualType VaListTagTypedefType =
6079
Context->getTypedefType(VaListTagTypedefDecl);
6081
// typedef __va_list_tag __builtin_va_list[1];
6082
llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1);
6083
QualType VaListTagArrayType
6084
= Context->getConstantArrayType(VaListTagTypedefType,
6085
Size, ArrayType::Normal,0);
6086
TypeSourceInfo *TInfo
6087
= Context->getTrivialTypeSourceInfo(VaListTagArrayType);
6088
TypedefDecl *VaListTypedefDecl
6089
= TypedefDecl::Create(const_cast<ASTContext &>(*Context),
6090
Context->getTranslationUnitDecl(),
6091
SourceLocation(), SourceLocation(),
6092
&Context->Idents.get("__builtin_va_list"),
6095
return VaListTypedefDecl;
5896
6098
static TypedefDecl *CreateVaListDecl(const ASTContext *Context,
5897
6099
TargetInfo::BuiltinVaListKind Kind) {
5898
6100
switch (Kind) {
7589
7796
GVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) {
7797
if (!FD->isExternallyVisible())
7798
return GVA_Internal;
7590
7800
GVALinkage External = GVA_StrongExternal;
7592
Linkage L = FD->getLinkage();
7595
case InternalLinkage:
7596
case UniqueExternalLinkage:
7597
return GVA_Internal;
7599
case ExternalLinkage:
7600
switch (FD->getTemplateSpecializationKind()) {
7601
case TSK_Undeclared:
7602
case TSK_ExplicitSpecialization:
7603
External = GVA_StrongExternal;
7606
case TSK_ExplicitInstantiationDefinition:
7607
return GVA_ExplicitTemplateInstantiation;
7609
case TSK_ExplicitInstantiationDeclaration:
7610
case TSK_ImplicitInstantiation:
7611
External = GVA_TemplateInstantiation;
7801
switch (FD->getTemplateSpecializationKind()) {
7802
case TSK_Undeclared:
7803
case TSK_ExplicitSpecialization:
7804
External = GVA_StrongExternal;
7807
case TSK_ExplicitInstantiationDefinition:
7808
return GVA_ExplicitTemplateInstantiation;
7810
case TSK_ExplicitInstantiationDeclaration:
7811
case TSK_ImplicitInstantiation:
7812
External = GVA_TemplateInstantiation;
7616
7816
if (!FD->isInlined())
7647
7850
if (VD->isStaticDataMember())
7648
7851
TSK = VD->getTemplateSpecializationKind();
7650
Linkage L = VD->getLinkage();
7654
case InternalLinkage:
7655
case UniqueExternalLinkage:
7656
return GVA_Internal;
7658
case ExternalLinkage:
7660
case TSK_Undeclared:
7661
case TSK_ExplicitSpecialization:
7662
return GVA_StrongExternal;
7664
case TSK_ExplicitInstantiationDeclaration:
7665
llvm_unreachable("Variable should not be instantiated");
7666
// Fall through to treat this like any other instantiation.
7668
case TSK_ExplicitInstantiationDefinition:
7669
return GVA_ExplicitTemplateInstantiation;
7671
case TSK_ImplicitInstantiation:
7672
return GVA_TemplateInstantiation;
7854
case TSK_Undeclared:
7855
case TSK_ExplicitSpecialization:
7856
return GVA_StrongExternal;
7858
case TSK_ExplicitInstantiationDeclaration:
7859
llvm_unreachable("Variable should not be instantiated");
7860
// Fall through to treat this like any other instantiation.
7862
case TSK_ExplicitInstantiationDefinition:
7863
return GVA_ExplicitTemplateInstantiation;
7865
case TSK_ImplicitInstantiation:
7866
return GVA_TemplateInstantiation;
7676
7869
llvm_unreachable("Invalid Linkage!");
7806
7999
void ASTContext::addUnnamedTag(const TagDecl *Tag) {
7807
8000
// FIXME: This mangling should be applied to function local classes too
7808
8001
if (!Tag->getName().empty() || Tag->getTypedefNameForAnonDecl() ||
7809
!isa<CXXRecordDecl>(Tag->getParent()) || Tag->getLinkage() != ExternalLinkage)
8002
!isa<CXXRecordDecl>(Tag->getParent()) ||
8003
!Tag->isExternallyVisible())
7812
8006
std::pair<llvm::DenseMap<const DeclContext *, unsigned>::iterator, bool> P =