diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-12-22 15:35:07 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-12-22 15:35:07 +0000 |
commit | d6542d8efcf8389c3aab764f9e29ac284e16eda6 (patch) | |
tree | 4d383f402c5436bc5a23ed146ab9c75d2a233fcb | |
parent | bdc601b196c48d4cd56a5ceb45d41ae4e87371ab (diff) |
Switch InitializedEntity from TypeLoc down to just QualTypes, since we don't use the location information but we did spend a bunch of time building faked-up TypeLocs
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91905 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 11 | ||||
-rw-r--r-- | lib/Sema/SemaInit.cpp | 109 | ||||
-rw-r--r-- | lib/Sema/SemaInit.h | 53 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 30 |
5 files changed, 60 insertions, 150 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 718d5ab577..d01516c77f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3465,10 +3465,7 @@ Sema::ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, SourceLocation RParenLoc, ExprArg InitExpr) { assert((Ty != 0) && "ActOnCompoundLiteral(): missing type"); - TypeSourceInfo *TInfo = 0; - QualType literalType = GetTypeFromParser(Ty, &TInfo); - if (!TInfo) - TInfo = Context.getTrivialTypeSourceInfo(literalType, LParenLoc); + QualType literalType = GetTypeFromParser(Ty); // FIXME: put back this assert when initializers are worked out. //assert((InitExpr != 0) && "ActOnCompoundLiteral(): missing expression"); @@ -3486,7 +3483,7 @@ Sema::ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty, return ExprError(); InitializedEntity Entity - = InitializedEntity::InitializeTemporary(TInfo->getTypeLoc()); + = InitializedEntity::InitializeTemporary(literalType); InitializationKind Kind = InitializationKind::CreateCast(SourceRange(LParenLoc, RParenLoc), /*IsCStyleCast=*/true); diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 7c4ab890d0..92a94daea6 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -446,18 +446,9 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, ConstructorLParen, ConstructorRParen); - // FIXME: We shouldn't have to fake this. - TypeSourceInfo *TInfo - = Context.getTrivialTypeSourceInfo(AllocType, TypeLoc); InitializedEntity Entity - = InitializedEntity::InitializeNew(StartLoc, TInfo->getTypeLoc()); + = InitializedEntity::InitializeNew(StartLoc, AllocType); InitializationSequence InitSeq(*this, Entity, Kind, ConsArgs, NumConsArgs); - - if (!InitSeq) { - InitSeq.Diagnose(*this, Entity, Kind, ConsArgs, NumConsArgs); - return ExprError(); - } - OwningExprResult FullInit = InitSeq.Perform(*this, Entity, Kind, move(ConstructorArgs)); if (FullInit.isInvalid()) diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index f831b41512..b72fede8bb 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -21,6 +21,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" +#include "clang/AST/TypeLoc.h" #include "llvm/Support/ErrorHandling.h" #include <map> using namespace clang; @@ -1788,49 +1789,10 @@ InitializedEntity::InitializedEntity(ASTContext &Context, unsigned Index, const InitializedEntity &Parent) : Kind(EK_ArrayOrVectorElement), Parent(&Parent), Index(Index) { - if (isa<ArrayType>(Parent.TL.getType())) { - TL = cast<ArrayTypeLoc>(Parent.TL).getElementLoc(); - return; - } - - // FIXME: should be able to get type location information for vectors, too. - - QualType T; - if (const ArrayType *AT = Context.getAsArrayType(Parent.TL.getType())) - T = AT->getElementType(); + if (const ArrayType *AT = Context.getAsArrayType(Parent.getType())) + Type = AT->getElementType(); else - T = Parent.TL.getType()->getAs<VectorType>()->getElementType(); - - // FIXME: Once we've gone through the effort to create the fake - // TypeSourceInfo, should we cache it somewhere? (If not, we "leak" it). - TypeSourceInfo *DI = Context.CreateTypeSourceInfo(T); - DI->getTypeLoc().initialize(Parent.TL.getSourceRange().getBegin()); - TL = DI->getTypeLoc(); -} - -void InitializedEntity::InitDeclLoc() { - assert((Kind == EK_Variable || Kind == EK_Parameter || Kind == EK_Member) && - "InitDeclLoc cannot be used with non-declaration entities."); - - ASTContext &Context = VariableOrMember->getASTContext(); - if (Kind == EK_Parameter && - !Context.hasSameUnqualifiedType( - cast<ParmVarDecl>(VariableOrMember)->getOriginalType(), - VariableOrMember->getType())) { - // For a parameter whose type has decayed, use the decayed type to - // build new source information. - } else if (TypeSourceInfo *DI = VariableOrMember->getTypeSourceInfo()) { - TL = DI->getTypeLoc(); - return; - } - - // FIXME: Once we've gone through the effort to create the fake - // TypeSourceInfo, should we cache it in the declaration? - // (If not, we "leak" it). - TypeSourceInfo *DI - = Context.CreateTypeSourceInfo(VariableOrMember->getType()); - DI->getTypeLoc().initialize(VariableOrMember->getLocation()); - TL = DI->getTypeLoc(); + Type = Parent.getType()->getAs<VectorType>()->getElementType(); } InitializedEntity InitializedEntity::InitializeBase(ASTContext &Context, @@ -1839,10 +1801,7 @@ InitializedEntity InitializedEntity::InitializeBase(ASTContext &Context, InitializedEntity Result; Result.Kind = EK_Base; Result.Base = Base; - // FIXME: CXXBaseSpecifier should store a TypeLoc. - TypeSourceInfo *DI = Context.CreateTypeSourceInfo(Base->getType()); - DI->getTypeLoc().initialize(Base->getSourceRange().getBegin()); - Result.TL = DI->getTypeLoc(); + Result.Type = Base->getType(); return Result; } @@ -2029,7 +1988,7 @@ static void TryListInitialization(Sema &S, // force us to perform more checking here. Sequence.setSequenceKind(InitializationSequence::ListInitialization); - QualType DestType = Entity.getType().getType(); + QualType DestType = Entity.getType(); // C++ [dcl.init]p13: // If T is a scalar type, then a declaration of the form @@ -2073,7 +2032,7 @@ static OverloadingResult TryRefInitWithConversionFunction(Sema &S, Expr *Initializer, bool AllowRValues, InitializationSequence &Sequence) { - QualType DestType = Entity.getType().getType(); + QualType DestType = Entity.getType(); QualType cv1T1 = DestType->getAs<ReferenceType>()->getPointeeType(); QualType T1 = cv1T1.getUnqualifiedType(); QualType cv2T2 = Initializer->getType(); @@ -2221,7 +2180,7 @@ static void TryReferenceInitialization(Sema &S, InitializationSequence &Sequence) { Sequence.setSequenceKind(InitializationSequence::ReferenceBinding); - QualType DestType = Entity.getType().getType(); + QualType DestType = Entity.getType(); QualType cv1T1 = DestType->getAs<ReferenceType>()->getPointeeType(); QualType T1 = cv1T1.getUnqualifiedType(); QualType cv2T2 = Initializer->getType(); @@ -2417,7 +2376,7 @@ static void TryStringLiteralInitialization(Sema &S, Expr *Initializer, InitializationSequence &Sequence) { Sequence.setSequenceKind(InitializationSequence::StringInit); - Sequence.AddStringInitStep(Entity.getType().getType()); + Sequence.AddStringInitStep(Entity.getType()); } /// \brief Attempt initialization by constructor (C++ [dcl.init]), which @@ -2509,7 +2468,7 @@ static void TryValueInitialization(Sema &S, // C++ [dcl.init]p5: // // To value-initialize an object of type T means: - QualType T = Entity.getType().getType(); + QualType T = Entity.getType(); // -- if T is an array type, then each element is value-initialized; while (const ArrayType *AT = S.Context.getAsArrayType(T)) @@ -2534,13 +2493,13 @@ static void TryValueInitialization(Sema &S, if ((ClassDecl->getTagKind() == TagDecl::TK_class || ClassDecl->getTagKind() == TagDecl::TK_struct) && !ClassDecl->hasTrivialConstructor()) { - Sequence.AddZeroInitializationStep(Entity.getType().getType()); + Sequence.AddZeroInitializationStep(Entity.getType()); return TryConstructorInitialization(S, Entity, Kind, 0, 0, T, Sequence); } } } - Sequence.AddZeroInitializationStep(Entity.getType().getType()); + Sequence.AddZeroInitializationStep(Entity.getType()); Sequence.setSequenceKind(InitializationSequence::ZeroInitialization); } @@ -2554,7 +2513,7 @@ static void TryDefaultInitialization(Sema &S, // C++ [dcl.init]p6: // To default-initialize an object of type T means: // - if T is an array type, each element is default-initialized; - QualType DestType = Entity.getType().getType(); + QualType DestType = Entity.getType(); while (const ArrayType *Array = S.Context.getAsArrayType(DestType)) DestType = Array->getElementType(); @@ -2589,7 +2548,7 @@ static void TryUserDefinedConversion(Sema &S, InitializationSequence &Sequence) { Sequence.setSequenceKind(InitializationSequence::UserDefinedConversion); - QualType DestType = Entity.getType().getType(); + QualType DestType = Entity.getType(); assert(!DestType->isReferenceType() && "References are handled elsewhere"); QualType SourceType = Initializer->getType(); assert((DestType->isRecordType() || SourceType->isRecordType()) && @@ -2721,7 +2680,7 @@ static void TryImplicitConversion(Sema &S, Expr *Initializer, InitializationSequence &Sequence) { ImplicitConversionSequence ICS - = S.TryImplicitConversion(Initializer, Entity.getType().getType(), + = S.TryImplicitConversion(Initializer, Entity.getType(), /*SuppressUserConversions=*/true, /*AllowExplicit=*/false, /*ForceRValue=*/false, @@ -2733,7 +2692,7 @@ static void TryImplicitConversion(Sema &S, return; } - Sequence.AddConversionSequenceStep(ICS, Entity.getType().getType()); + Sequence.AddConversionSequenceStep(ICS, Entity.getType()); } InitializationSequence::InitializationSequence(Sema &S, @@ -2749,7 +2708,7 @@ InitializationSequence::InitializationSequence(Sema &S, // type is the type of the initializer expression. The source type is not // defined when the initializer is a braced-init-list or when it is a // parenthesized list of expressions. - QualType DestType = Entity.getType().getType(); + QualType DestType = Entity.getType(); if (DestType->isDependentType() || Expr::hasAnyTypeDependentArguments(Args, NumArgs)) { @@ -2836,7 +2795,7 @@ InitializationSequence::InitializationSequence(Sema &S, (Context.hasSameUnqualifiedType(SourceType, DestType) || S.IsDerivedFrom(SourceType, DestType)))) TryConstructorInitialization(S, Entity, Kind, Args, NumArgs, - Entity.getType().getType(), *this); + Entity.getType(), *this); // - Otherwise (i.e., for the remaining copy-initialization cases), // user-defined conversion sequences that can convert from the source // type to the destination type or (when a conversion function is @@ -2944,7 +2903,7 @@ static Sema::OwningExprResult CopyIfRequiredForEntity(Sema &S, switch (Entity.getKind()) { case InitializedEntity::EK_Result: - if (Entity.getType().getType()->isReferenceType()) + if (Entity.getType()->isReferenceType()) return move(CurInit); Loc = Entity.getReturnLoc(); break; @@ -2954,7 +2913,7 @@ static Sema::OwningExprResult CopyIfRequiredForEntity(Sema &S, break; case InitializedEntity::EK_Variable: - if (Entity.getType().getType()->isReferenceType() || + if (Entity.getType()->isReferenceType() || Kind.getKind() != InitializationKind::IK_Copy) return move(CurInit); Loc = Entity.getDecl()->getLocation(); @@ -3049,9 +3008,9 @@ InitializationSequence::Perform(Sema &S, // If the declaration is a non-dependent, incomplete array type // that has an initializer, then its type will be completed once // the initializer is instantiated. - if (ResultType && !Entity.getType().getType()->isDependentType() && + if (ResultType && !Entity.getType()->isDependentType() && Args.size() == 1) { - QualType DeclType = Entity.getType().getType(); + QualType DeclType = Entity.getType(); if (const IncompleteArrayType *ArrayT = S.Context.getAsIncompleteArrayType(DeclType)) { // FIXME: We don't currently have the ability to accurately @@ -3063,11 +3022,15 @@ InitializationSequence::Perform(Sema &S, // bound. if (isa<InitListExpr>((Expr *)Args.get()[0])) { SourceRange Brackets; + // Scavange the location of the brackets from the entity, if we can. - if (isa<IncompleteArrayTypeLoc>(Entity.getType())) { - IncompleteArrayTypeLoc ArrayLoc - = cast<IncompleteArrayTypeLoc>(Entity.getType()); - Brackets = ArrayLoc.getBracketsRange(); + if (DeclaratorDecl *DD = Entity.getDecl()) { + if (TypeSourceInfo *TInfo = DD->getTypeSourceInfo()) { + TypeLoc TL = TInfo->getTypeLoc(); + if (IncompleteArrayTypeLoc *ArrayLoc + = dyn_cast<IncompleteArrayTypeLoc>(&TL)) + Brackets = ArrayLoc->getBracketsRange(); + } } *ResultType @@ -3095,13 +3058,13 @@ InitializationSequence::Perform(Sema &S, if (SequenceKind == NoInitialization) return S.Owned((Expr *)0); - QualType DestType = Entity.getType().getType().getNonReferenceType(); - // FIXME: Ugly hack around the fact that Entity.getType().getType() is not + QualType DestType = Entity.getType().getNonReferenceType(); + // FIXME: Ugly hack around the fact that Entity.getType() is not // the same as Entity.getDecl()->getType() in cases involving type merging, // and we want latter when it makes sense. if (ResultType) *ResultType = Entity.getDecl() ? Entity.getDecl()->getType() : - Entity.getType().getType(); + Entity.getType(); Sema::OwningExprResult CurInit = S.Owned((Expr *)0); @@ -3176,7 +3139,7 @@ InitializationSequence::Perform(Sema &S, if (FieldDecl *BitField = CurInitExpr->getBitField()) { // References cannot bind to bit fields (C++ [dcl.init.ref]p5). S.Diag(Kind.getLocation(), diag::err_reference_bind_to_bitfield) - << Entity.getType().getType().isVolatileQualified() + << Entity.getType().isVolatileQualified() << BitField->getDeclName() << CurInitExpr->getSourceRange(); S.Diag(BitField->getLocation(), diag::note_bitfield_decl); @@ -3312,7 +3275,7 @@ InitializationSequence::Perform(Sema &S, return S.ExprError(); // Build the an expression that constructs a temporary. - CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType().getType(), + CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType(), Constructor, move_arg(ConstructorArgs), ConstructorInitRequiresZeroInit); @@ -3392,7 +3355,7 @@ bool InitializationSequence::Diagnose(Sema &S, if (SequenceKind != FailedSequence) return false; - QualType DestType = Entity.getType().getType(); + QualType DestType = Entity.getType(); switch (Failure) { case FK_TooManyInitsForReference: S.Diag(Kind.getLocation(), diag::err_reference_has_multiple_inits) diff --git a/lib/Sema/SemaInit.h b/lib/Sema/SemaInit.h index 85f3d2c1a3..c5ba57c726 100644 --- a/lib/Sema/SemaInit.h +++ b/lib/Sema/SemaInit.h @@ -14,7 +14,7 @@ #define LLVM_CLANG_SEMA_INIT_H #include "SemaOverload.h" -#include "clang/AST/TypeLoc.h" +#include "clang/AST/Type.h" #include "clang/Parse/Action.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/PointerIntPair.h" @@ -70,9 +70,8 @@ private: /// initialization occurs. const InitializedEntity *Parent; - /// \brief The type of the object or reference being initialized along with - /// its location information. - TypeLoc TL; + /// \brief The type of the object or reference being initialized. + QualType Type; union { /// \brief When Kind == EK_Variable, EK_Parameter, or EK_Member, @@ -98,40 +97,28 @@ private: /// \brief Create the initialization entity for a variable. InitializedEntity(VarDecl *Var) - : Kind(EK_Variable), Parent(0), - VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Var)) - { - InitDeclLoc(); - } + : Kind(EK_Variable), Parent(0), Type(Var->getType()), + VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Var)) { } /// \brief Create the initialization entity for a parameter. InitializedEntity(ParmVarDecl *Parm) - : Kind(EK_Parameter), Parent(0), - VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Parm)) - { - InitDeclLoc(); - } + : Kind(EK_Parameter), Parent(0), Type(Parm->getType()), + VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Parm)) { } /// \brief Create the initialization entity for the result of a function, /// throwing an object, or performing an explicit cast. - InitializedEntity(EntityKind Kind, SourceLocation Loc, TypeLoc TL) - : Kind(Kind), Parent(0), TL(TL), Location(Loc.getRawEncoding()) { } + InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type) + : Kind(Kind), Parent(0), Type(Type), Location(Loc.getRawEncoding()) { } /// \brief Create the initialization entity for a member subobject. InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent) - : Kind(EK_Member), Parent(Parent), - VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Member)) - { - InitDeclLoc(); - } + : Kind(EK_Member), Parent(Parent), Type(Member->getType()), + VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Member)) { } /// \brief Create the initialization entity for an array element. InitializedEntity(ASTContext &Context, unsigned Index, const InitializedEntity &Parent); - /// \brief Initialize type-location information from a declaration. - void InitDeclLoc(); - public: /// \brief Create the initialization entity for a variable. static InitializedEntity InitializeVariable(VarDecl *Var) { @@ -145,24 +132,24 @@ public: /// \brief Create the initialization entity for the result of a function. static InitializedEntity InitializeResult(SourceLocation ReturnLoc, - TypeLoc TL) { - return InitializedEntity(EK_Result, ReturnLoc, TL); + QualType Type) { + return InitializedEntity(EK_Result, ReturnLoc, Type); } /// \brief Create the initialization entity for an exception object. static InitializedEntity InitializeException(SourceLocation ThrowLoc, - TypeLoc TL) { - return InitializedEntity(EK_Exception, ThrowLoc, TL); + QualType Type) { + return InitializedEntity(EK_Exception, ThrowLoc, Type); } /// \brief Create the initialization entity for an object allocated via new. - static InitializedEntity InitializeNew(SourceLocation NewLoc, TypeLoc TL) { - return InitializedEntity(EK_New, NewLoc, TL); + static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type) { + return InitializedEntity(EK_New, NewLoc, Type); } /// \brief Create the initialization entity for a temporary. - static InitializedEntity InitializeTemporary(TypeLoc TL) { - return InitializedEntity(EK_Temporary, SourceLocation(), TL); + static InitializedEntity InitializeTemporary(QualType Type) { + return InitializedEntity(EK_Temporary, SourceLocation(), Type); } /// \brief Create the initialization entity for a base class subobject. @@ -191,7 +178,7 @@ public: const InitializedEntity *getParent() const { return Parent; } /// \brief Retrieve type being initialized. - TypeLoc getType() const { return TL; } + QualType getType() const { return Type; } /// \brief Retrieve the name of the entity being initialized. DeclarationName getName() const; diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 6a68db75ea..0ff933325e 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -1028,23 +1028,11 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { return ActOnBlockReturnStmt(ReturnLoc, RetValExp); QualType FnRetType; - TypeLoc FnRetTypeLoc; if (const FunctionDecl *FD = getCurFunctionDecl()) { FnRetType = FD->getResultType(); if (FD->hasAttr<NoReturnAttr>()) Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr) << getCurFunctionOrMethodDecl()->getDeclName(); - -#if 0 - // FIXME: Useful, once we're sure it has all of the information we - // need. - if (TypeSourceInfo *TInfo = FD->getTypeSourceInfo()) { - TypeLoc TL = TInfo->getTypeLoc(); - if (FunctionTypeLoc *FTL = dyn_cast<FunctionTypeLoc>(&TL)) - FnRetTypeLoc = FTL->getResultLoc(); - } -#endif - } else if (ObjCMethodDecl *MD = getCurMethodDecl()) FnRetType = MD->getResultType(); else // If we don't have a function/method context, bail. @@ -1108,27 +1096,11 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { // FIXME: Elidable (void)Elidable; - // If we somehow didn't get a - - // FIXME: Should we allocate the TypeSourceInfo and attach it to - // the declaration? Alternatively, we could require that all - // function and method declarations have TypeSourceInfos, so that - // this is never required. FIXME: Also, the allocated TInfo goes - // into the bump pointer, so it cannot actually be freed. - TypeSourceInfo *AllocatedTInfo = 0; - if (!FnRetTypeLoc) { - const FunctionDecl *FD = getCurFunctionDecl(); - SourceLocation Loc = FD? FD->getLocation() - : getCurMethodDecl()->getLocation(); - AllocatedTInfo = Context.getTrivialTypeSourceInfo(FnRetType, Loc); - FnRetTypeLoc = AllocatedTInfo->getTypeLoc(); - } - // In C++ the return statement is handled via a copy initialization. // the C version of which boils down to CheckSingleAssignmentConstraints. OwningExprResult Res = PerformCopyInitialization( InitializedEntity::InitializeResult(ReturnLoc, - FnRetTypeLoc), + FnRetType), SourceLocation(), Owned(RetValExp)); if (Res.isInvalid()) { |