diff options
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r-- | lib/AST/Type.cpp | 165 |
1 files changed, 82 insertions, 83 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 9bcfb2ad8f..1a6ea0a136 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -64,7 +64,7 @@ void DependentSizedArrayType::Destroy(ASTContext& C) { C.Deallocate(this); } -void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, +void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, QualType ET, ArraySizeModifier SizeMod, @@ -76,8 +76,8 @@ void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, E->Profile(ID, Context, true); } -void -DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, +void +DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, QualType ElementType, Expr *SizeExpr) { ID.AddPointer(ElementType.getAsOpaquePtr()); @@ -99,7 +99,7 @@ const Type *Type::getArrayElementTypeNoTypeQual() const { // If this is directly an array type, return it. if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) return ATy->getElementType().getTypePtr(); - + // If the canonical form of this type isn't the right kind, reject it. if (!isa<ArrayType>(CanonicalType)) { // Look through type qualifiers @@ -107,7 +107,7 @@ const Type *Type::getArrayElementTypeNoTypeQual() const { return AT->getElementType().getTypePtr(); return 0; } - + // If this is a typedef for an array type, strip the typedef off without // losing all typedef information. return cast<ArrayType>(getDesugaredType())->getElementType().getTypePtr(); @@ -153,7 +153,7 @@ QualType Type::getDesugaredType(bool ForDisplay) const { if (!DTT->getUnderlyingType()->isDependentType()) return DTT->getUnderlyingType().getDesugaredType(); } - if (const TemplateSpecializationType *Spec + if (const TemplateSpecializationType *Spec = dyn_cast<TemplateSpecializationType>(this)) { if (ForDisplay) return QualType(this, 0); @@ -262,7 +262,7 @@ const ComplexType *Type::getAsComplexIntegerType() const { return CTy; return 0; } - + // If the canonical form of this type isn't what we want, reject it. if (!isa<ComplexType>(CanonicalType)) { // Look through type qualifiers (e.g. ExtQualType's). @@ -270,7 +270,7 @@ const ComplexType *Type::getAsComplexIntegerType() const { return CanonicalType.getUnqualifiedType()->getAsComplexIntegerType(); return 0; } - + // If this is a typedef for a complex type, strip the typedef off without // losing all typedef information. return cast<ComplexType>(getDesugaredType()); @@ -306,7 +306,7 @@ const FunctionType *Type::getAsFunctionType() const { return CanonicalType.getUnqualifiedType()->getAsFunctionType(); return 0; } - + // If this is a typedef for a function type, strip the typedef off without // losing all typedef information. return cast<FunctionType>(getDesugaredType()); @@ -374,7 +374,7 @@ const RecordType *Type::getAsStructureType() const { if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { if (!RT->getDecl()->isStruct()) return 0; - + // If this is a typedef for a structure type, strip the typedef off without // losing all typedef information. return cast<RecordType>(getDesugaredType()); @@ -385,13 +385,13 @@ const RecordType *Type::getAsStructureType() const { return 0; } -const RecordType *Type::getAsUnionType() const { +const RecordType *Type::getAsUnionType() const { // If this is directly a union type, return it. if (const RecordType *RT = dyn_cast<RecordType>(this)) { if (RT->getDecl()->isUnion()) return RT; } - + // If the canonical form of this type isn't the right kind, reject it. if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { if (!RT->getDecl()->isUnion()) @@ -401,7 +401,7 @@ const RecordType *Type::getAsUnionType() const { // losing all typedef information. return cast<RecordType>(getDesugaredType()); } - + // Look through type qualifiers if (isa<RecordType>(CanonicalType.getUnqualifiedType())) return CanonicalType.getUnqualifiedType()->getAsUnionType(); @@ -419,7 +419,7 @@ const ComplexType *Type::getAsComplexType() const { // Are we directly a complex type? if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) return CTy; - + // If the canonical form of this type isn't the right kind, reject it. if (!isa<ComplexType>(CanonicalType)) { // Look through type qualifiers @@ -437,7 +437,7 @@ const VectorType *Type::getAsVectorType() const { // Are we directly a vector type? if (const VectorType *VTy = dyn_cast<VectorType>(this)) return VTy; - + // If the canonical form of this type isn't the right kind, reject it. if (!isa<VectorType>(CanonicalType)) { // Look through type qualifiers @@ -455,9 +455,9 @@ const ExtVectorType *Type::getAsExtVectorType() const { // Are we directly an OpenCU vector type? if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this)) return VTy; - + // If the canonical form of this type isn't the right kind, reject it. - if (!isa<ExtVectorType>(CanonicalType)) { + if (!isa<ExtVectorType>(CanonicalType)) { // Look through type qualifiers if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType())) return CanonicalType.getUnqualifiedType()->getAsExtVectorType(); @@ -612,14 +612,14 @@ bool Type::isSignedIntegerType() const { return BT->getKind() >= BuiltinType::Char_S && BT->getKind() <= BuiltinType::LongLong; } - + if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) return ET->getDecl()->getIntegerType()->isSignedIntegerType(); - + if (const FixedWidthIntType *FWIT = dyn_cast<FixedWidthIntType>(CanonicalType)) return FWIT->isSigned(); - + if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) return VT->getElementType()->isSignedIntegerType(); if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) @@ -763,8 +763,8 @@ bool Type::isConstantSizeType() const { /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) /// - a type that can describe objects, but which lacks information needed to /// determine its size. -bool Type::isIncompleteType() const { - switch (CanonicalType->getTypeClass()) { +bool Type::isIncompleteType() const { + switch (CanonicalType->getTypeClass()) { default: return false; case ExtQual: return cast<ExtQualType>(CanonicalType)->getBaseType()->isIncompleteType(); @@ -816,7 +816,7 @@ bool Type::isPODType() const { return true; case Record: - if (CXXRecordDecl *ClassDecl + if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) return ClassDecl->isPOD(); @@ -836,7 +836,7 @@ bool Type::isPromotableIntegerType() const { case BuiltinType::Short: case BuiltinType::UShort: return true; - default: + default: return false; } return false; @@ -918,7 +918,7 @@ void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, ID.AddInteger(hasExceptionSpec); if (hasExceptionSpec) { ID.AddInteger(anyExceptionSpec); - for(unsigned i = 0; i != NumExceptions; ++i) + for (unsigned i = 0; i != NumExceptions; ++i) ID.AddPointer(Exs[i].getAsOpaquePtr()); } ID.AddInteger(NoReturn); @@ -957,14 +957,14 @@ QualType TypedefType::LookThroughTypedefs() const { QualType FirstType = getDecl()->getUnderlyingType(); if (!isa<TypedefType>(FirstType)) return FirstType; - + // Otherwise, do the fully general loop. unsigned TypeQuals = 0; const TypedefType *TDT = this; while (1) { QualType CurType = TDT->getDecl()->getUnderlyingType(); - - + + /// FIXME: /// FIXME: This is incorrect for ExtQuals! /// FIXME: @@ -980,25 +980,25 @@ TypeOfExprType::TypeOfExprType(Expr *E, QualType can) : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) { } -void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, +void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, Expr *E) { E->Profile(ID, Context, true); } DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) - : Type(Decltype, can, E->isTypeDependent()), E(E), + : Type(Decltype, can, E->isTypeDependent()), E(E), UnderlyingType(underlyingType) { } DependentDecltypeType::DependentDecltypeType(ASTContext &Context, Expr *E) : DecltypeType(E, Context.DependentTy), Context(Context) { } -void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, +void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, Expr *E) { E->Profile(ID, Context, true); } -TagType::TagType(TypeClass TC, TagDecl *D, QualType can) +TagType::TagType(TypeClass TC, TagDecl *D, QualType can) : Type(TC, can, D->isDependentType()), decl(D, 0) {} bool RecordType::classof(const TagType *TT) { @@ -1009,7 +1009,7 @@ bool EnumType::classof(const TagType *TT) { return isa<EnumDecl>(TT->getDecl()); } -bool +bool TemplateSpecializationType:: anyDependentTemplateArguments(const TemplateArgument *Args, unsigned NumArgs) { for (unsigned Idx = 0; Idx < NumArgs; ++Idx) { @@ -1017,12 +1017,12 @@ anyDependentTemplateArguments(const TemplateArgument *Args, unsigned NumArgs) { case TemplateArgument::Null: assert(false && "Should not have a NULL template argument"); break; - + case TemplateArgument::Type: if (Args[Idx].getAsType()->isDependentType()) return true; break; - + case TemplateArgument::Declaration: case TemplateArgument::Integral: // Never dependent @@ -1033,7 +1033,7 @@ anyDependentTemplateArguments(const TemplateArgument *Args, unsigned NumArgs) { Args[Idx].getAsExpr()->isValueDependent()) return true; break; - + case TemplateArgument::Pack: assert(0 && "FIXME: Implement!"); break; @@ -1044,20 +1044,19 @@ anyDependentTemplateArguments(const TemplateArgument *Args, unsigned NumArgs) { } TemplateSpecializationType:: -TemplateSpecializationType(ASTContext &Context, TemplateName T, +TemplateSpecializationType(ASTContext &Context, TemplateName T, const TemplateArgument *Args, unsigned NumArgs, QualType Canon) - : Type(TemplateSpecialization, + : Type(TemplateSpecialization, Canon.isNull()? QualType(this, 0) : Canon, T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)), Context(Context), - Template(T), NumArgs(NumArgs) -{ - assert((!Canon.isNull() || + Template(T), NumArgs(NumArgs) { + assert((!Canon.isNull() || T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) && "No canonical type for non-dependent class template specialization"); - TemplateArgument *TemplateArgs + TemplateArgument *TemplateArgs = reinterpret_cast<TemplateArgument *>(this + 1); for (unsigned Arg = 0; Arg < NumArgs; ++Arg) new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); @@ -1083,10 +1082,10 @@ TemplateSpecializationType::getArg(unsigned Idx) const { return getArgs()[Idx]; } -void -TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, - TemplateName T, - const TemplateArgument *Args, +void +TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, + TemplateName T, + const TemplateArgument *Args, unsigned NumArgs, ASTContext &Context) { T.Profile(ID); @@ -1097,7 +1096,7 @@ TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, const Type *QualifierSet::strip(const Type* T) { QualType DT = T->getDesugaredType(); addCVR(DT.getCVRQualifiers()); - + if (const ExtQualType* EQT = dyn_cast<ExtQualType>(DT)) { if (EQT->getAddressSpace()) addAddressSpace(EQT->getAddressSpace()); @@ -1162,8 +1161,8 @@ std::string QualType::getAsString() const { return S; } -void -QualType::getAsStringInternal(std::string &S, +void +QualType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { if (isNull()) { S += "NULL TYPE"; @@ -1186,7 +1185,7 @@ QualType::getAsStringInternal(std::string &S, getTypePtr()->getAsStringInternal(S, Policy); } -void BuiltinType::getAsStringInternal(std::string &S, +void BuiltinType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { if (S.empty()) { S = getName(Policy.LangOpts); @@ -1238,12 +1237,12 @@ void ExtQualType::getAsStringInternal(std::string &S, const PrintingPolicy &Poli void PointerType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { S = '*' + S; - + // Handle things like 'int (*A)[4];' correctly. // FIXME: this should include vectors, but vectors use attributes I guess. if (isa<ArrayType>(getPointeeType())) S = '(' + S + ')'; - + getPointeeType().getAsStringInternal(S, Policy); } @@ -1292,7 +1291,7 @@ void ConstantArrayType::getAsStringInternal(std::string &S, const PrintingPolicy S += '['; S += llvm::utostr(getSize().getZExtValue()); S += ']'; - + getElementType().getAsStringInternal(S, Policy); } @@ -1327,17 +1326,17 @@ void IncompleteArrayType::getAsStringInternal(std::string &S, const PrintingPoli void VariableArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { S += '['; - + if (getIndexTypeQualifier()) { AppendTypeQualList(S, getIndexTypeQualifier()); S += ' '; } - + if (getSizeModifier() == Static) S += "static"; else if (getSizeModifier() == Star) S += '*'; - + if (getSizeExpr()) { std::string SStr; llvm::raw_string_ostream s(SStr); @@ -1345,23 +1344,23 @@ void VariableArrayType::getAsStringInternal(std::string &S, const PrintingPolicy S += s.str(); } S += ']'; - + getElementType().getAsStringInternal(S, Policy); } void DependentSizedArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { S += '['; - + if (getIndexTypeQualifier()) { AppendTypeQualList(S, getIndexTypeQualifier()); S += ' '; } - + if (getSizeModifier() == Static) S += "static"; else if (getSizeModifier() == Star) S += '*'; - + if (getSizeExpr()) { std::string SStr; llvm::raw_string_ostream s(SStr); @@ -1369,7 +1368,7 @@ void DependentSizedArrayType::getAsStringInternal(std::string &S, const Printing S += s.str(); } S += ']'; - + getElementType().getAsStringInternal(S, Policy); } @@ -1419,7 +1418,7 @@ void TypeOfType::getAsStringInternal(std::string &InnerString, const PrintingPol InnerString = "typeof(" + Tmp + ")" + InnerString; } -void DecltypeType::getAsStringInternal(std::string &InnerString, +void DecltypeType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { if (!InnerString.empty()) // Prefix the basic type, e.g. 'decltype(t) X'. InnerString = ' ' + InnerString; @@ -1433,7 +1432,7 @@ void FunctionNoProtoType::getAsStringInternal(std::string &S, const PrintingPoli // If needed for precedence reasons, wrap the inner part in grouping parens. if (!S.empty()) S = "(" + S + ")"; - + S += "()"; if (getNoReturnAttr()) S += " __attribute__((noreturn))"; @@ -1444,7 +1443,7 @@ void FunctionProtoType::getAsStringInternal(std::string &S, const PrintingPolicy // If needed for precedence reasons, wrap the inner part in grouping parens. if (!S.empty()) S = "(" + S + ")"; - + S += "("; std::string Tmp; PrintingPolicy ParamPolicy(Policy); @@ -1455,7 +1454,7 @@ void FunctionProtoType::getAsStringInternal(std::string &S, const PrintingPolicy S += Tmp; Tmp.clear(); } - + if (isVariadic()) { if (getNumArgs()) S += ", "; @@ -1464,7 +1463,7 @@ void FunctionProtoType::getAsStringInternal(std::string &S, const PrintingPolicy // Do not emit int() if we have a proto, emit 'int(void)'. S += "void"; } - + S += ")"; if (getNoReturnAttr()) S += " __attribute__((noreturn))"; @@ -1483,13 +1482,13 @@ void TemplateTypeParmType::getAsStringInternal(std::string &InnerString, const P InnerString = ' ' + InnerString; if (!Name) - InnerString = "type-parameter-" + llvm::utostr_32(Depth) + '-' + + InnerString = "type-parameter-" + llvm::utostr_32(Depth) + '-' + llvm::utostr_32(Index) + InnerString; else InnerString = Name->getName() + InnerString; } -std::string +std::string TemplateSpecializationType::PrintTemplateArgumentList( const TemplateArgument *Args, unsigned NumArgs, @@ -1499,7 +1498,7 @@ TemplateSpecializationType::PrintTemplateArgumentList( for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { if (Arg) SpecString += ", "; - + // Print the argument into a string. std::string ArgString; switch (Args[Arg].getKind()) { @@ -1549,7 +1548,7 @@ TemplateSpecializationType::PrintTemplateArgumentList( return SpecString; } -void +void TemplateSpecializationType:: getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { std::string SpecString; @@ -1573,7 +1572,7 @@ void QualifiedNameType::getAsStringInternal(std::string &InnerString, const Prin llvm::raw_string_ostream OS(MyString); NNS->print(OS, Policy); } - + std::string TypeStr; PrintingPolicy InnerPolicy(Policy); InnerPolicy.SuppressTagKind = true; @@ -1600,12 +1599,12 @@ void TypenameType::getAsStringInternal(std::string &InnerString, const PrintingP else if (const TemplateSpecializationType *Spec = getTemplateId()) { Spec->getTemplateName().print(OS, Policy, true); OS << TemplateSpecializationType::PrintTemplateArgumentList( - Spec->getArgs(), + Spec->getArgs(), Spec->getNumArgs(), Policy); } } - + if (InnerString.empty()) InnerString.swap(MyString); else @@ -1614,7 +1613,7 @@ void TypenameType::getAsStringInternal(std::string &InnerString, const PrintingP void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID, const ObjCInterfaceDecl *Decl, - ObjCProtocolDecl **protocols, + ObjCProtocolDecl **protocols, unsigned NumProtocols) { ID.AddPointer(Decl); for (unsigned i = 0; i != NumProtocols; i++) @@ -1632,7 +1631,7 @@ void ObjCInterfaceType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. InnerString = ' ' + InnerString; - + std::string ObjCQIString = getDecl()->getNameAsString(); if (getNumProtocols()) { ObjCQIString += '<'; @@ -1649,10 +1648,10 @@ void ObjCInterfaceType::getAsStringInternal(std::string &InnerString, InnerString = ObjCQIString + InnerString; } -void ObjCObjectPointerType::getAsStringInternal(std::string &InnerString, +void ObjCObjectPointerType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { std::string ObjCQIString; - + if (isObjCIdType() || isObjCQualifiedIdType()) ObjCQIString = "id"; else if (isObjCClassType() || isObjCQualifiedClassType()) @@ -1677,7 +1676,7 @@ void ObjCObjectPointerType::getAsStringInternal(std::string &InnerString, InnerString = ObjCQIString + InnerString; } -void ElaboratedType::getAsStringInternal(std::string &InnerString, +void ElaboratedType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { std::string TypeStr; PrintingPolicy InnerPolicy(Policy); @@ -1693,7 +1692,7 @@ void TagType::getAsStringInternal(std::string &InnerString, const PrintingPolicy if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. InnerString = ' ' + InnerString; - + const char *Kind = Policy.SuppressTagKind? 0 : getDecl()->getKindName(); const char *ID; if (const IdentifierInfo *II = getDecl()->getIdentifier()) @@ -1707,10 +1706,10 @@ void TagType::getAsStringInternal(std::string &InnerString, const PrintingPolicy // If this is a class template specialization, print the template // arguments. - if (ClassTemplateSpecializationDecl *Spec + if (ClassTemplateSpecializationDecl *Spec = dyn_cast<ClassTemplateSpecializationDecl>(getDecl())) { const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); - std::string TemplateArgsStr + std::string TemplateArgsStr = TemplateSpecializationType::PrintTemplateArgumentList( TemplateArgs.getFlatArgumentList(), TemplateArgs.flat_size(), @@ -1722,13 +1721,13 @@ void TagType::getAsStringInternal(std::string &InnerString, const PrintingPolicy // Compute the full nested-name-specifier for this type. In C, // this will always be empty. std::string ContextStr; - for (DeclContext *DC = getDecl()->getDeclContext(); + for (DeclContext *DC = getDecl()->getDeclContext(); !DC->isTranslationUnit(); DC = DC->getParent()) { std::string MyPart; if (NamespaceDecl *NS = dyn_cast<NamespaceDecl>(DC)) { if (NS->getIdentifier()) MyPart = NS->getNameAsString(); - } else if (ClassTemplateSpecializationDecl *Spec + } else if (ClassTemplateSpecializationDecl *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) { const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); std::string TemplateArgsStr |