[cfe-commits] r91905 - in /cfe/trunk/lib/Sema: SemaExpr.cpp SemaExprCXX.cpp SemaInit.cpp SemaInit.h SemaStmt.cpp
Douglas Gregor
dgregor at apple.com
Tue Dec 22 07:35:08 PST 2009
Author: dgregor
Date: Tue Dec 22 09:35:07 2009
New Revision: 91905
URL: http://llvm.org/viewvc/llvm-project?rev=91905&view=rev
Log:
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
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaInit.h
cfe/trunk/lib/Sema/SemaStmt.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=91905&r1=91904&r2=91905&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Dec 22 09:35:07 2009
@@ -3465,10 +3465,7 @@
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 @@
return ExprError();
InitializedEntity Entity
- = InitializedEntity::InitializeTemporary(TInfo->getTypeLoc());
+ = InitializedEntity::InitializeTemporary(literalType);
InitializationKind Kind
= InitializationKind::CreateCast(SourceRange(LParenLoc, RParenLoc),
/*IsCStyleCast=*/true);
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=91905&r1=91904&r2=91905&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Dec 22 09:35:07 2009
@@ -446,18 +446,9 @@
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())
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=91905&r1=91904&r2=91905&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Dec 22 09:35:07 2009
@@ -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 @@
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 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 @@
// 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 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
// 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 @@
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 @@
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 @@
return;
}
- Sequence.AddConversionSequenceStep(ICS, Entity.getType().getType());
+ Sequence.AddConversionSequenceStep(ICS, Entity.getType());
}
InitializationSequence::InitializationSequence(Sema &S,
@@ -2749,7 +2708,7 @@
// 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 @@
(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 @@
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 @@
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 @@
// 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 @@
// 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 @@
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 @@
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 @@
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 @@
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)
Modified: cfe/trunk/lib/Sema/SemaInit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.h?rev=91905&r1=91904&r2=91905&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.h (original)
+++ cfe/trunk/lib/Sema/SemaInit.h Tue Dec 22 09:35:07 2009
@@ -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 @@
/// 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 @@
/// \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 @@
/// \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 @@
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;
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=91905&r1=91904&r2=91905&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Dec 22 09:35:07 2009
@@ -1028,23 +1028,11 @@
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 @@
// 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()) {
More information about the cfe-commits
mailing list