]> granicus.if.org Git - clang/commitdiff
CastExpr should not hold a pointer to the base path. More cleanup.
authorAnders Carlsson <andersca@mac.com>
Sat, 24 Apr 2010 16:57:13 +0000 (16:57 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 24 Apr 2010 16:57:13 +0000 (16:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102249 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
include/clang/AST/Expr.h
include/clang/AST/UsuallyTinyPtrVector.h
lib/AST/ASTImporter.cpp
lib/AST/Expr.cpp
lib/CodeGen/CGObjC.cpp
lib/Frontend/RewriteObjC.cpp
lib/Sema/Sema.cpp
lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprCXX.cpp
lib/Sema/SemaInit.cpp
lib/Sema/SemaOverload.cpp
lib/Sema/SemaTemplate.cpp

index fc03bde93aa08d89a44a562b9a1a50bf3b9aa8bf..20981f74a4abd9092c46de790e43dcc066a2ceb7 100644 (file)
@@ -1653,7 +1653,7 @@ private:
 
   /// BasePath - For derived-to-base and base-to-derived casts, the base array
   /// contains the inheritance path.
-  CXXBaseSpecifierArray *BasePath;
+  CXXBaseSpecifierArray BasePath;
 
   void CheckBasePath() const {
 #ifndef NDEBUG
@@ -1687,7 +1687,7 @@ private:
     case CK_MemberPointerToBoolean:
     case CK_AnyPointerToObjCPointerCast:
     case CK_AnyPointerToBlockPointerCast:
-      assert(!BasePath && "Cast kind shoudl not have a base path!");
+      assert(BasePath.empty() && "Cast kind shoudl not have a base path!");
       break;
     }
 #endif
@@ -1695,7 +1695,7 @@ private:
 
 protected:
   CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op,
-           CXXBaseSpecifierArray *BasePath) :
+           CXXBaseSpecifierArray BasePath) :
     Expr(SC, ty,
          // Cast expressions are type-dependent if the type is
          // dependent (C++ [temp.dep.expr]p3).
@@ -1769,7 +1769,7 @@ class ImplicitCastExpr : public CastExpr {
 
 public:
   ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 
-                   CXXBaseSpecifierArray *BasePath, bool Lvalue)
+                   CXXBaseSpecifierArray BasePath, bool Lvalue)
     : CastExpr(ImplicitCastExprClass, ty, kind, op, BasePath), 
     LvalueCast(Lvalue) { }
 
@@ -1817,7 +1817,8 @@ class ExplicitCastExpr : public CastExpr {
 protected:
   ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind,
                    Expr *op, TypeSourceInfo *writtenTy)
-    : CastExpr(SC, exprTy, kind, op, 0), TInfo(writtenTy) {}
+    : CastExpr(SC, exprTy, kind, op, CXXBaseSpecifierArray()), 
+    TInfo(writtenTy) {}
 
   /// \brief Construct an empty explicit cast.
   ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
index f983c4e8e3dd08530cc194b3ac86b6e22ed4980f..5bf3ee94644bfc2eb9023a2b155cca75b8755695 100644 (file)
@@ -34,6 +34,8 @@ class UsuallyTinyPtrVector {
 public:
   UsuallyTinyPtrVector() : Storage(0) { }
 
+  bool empty() const { return !Storage; }
+
   typedef const T **iterator;
   iterator begin() const;
   iterator end() const;
index 9766d3a370559c97994c03cc080eab2f077bddc7..d9557d3e4c644c68410d73133040b8d563993d60 100644 (file)
@@ -2885,9 +2885,10 @@ Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
   if (!SubExpr)
     return 0;
   
+  // FIXME: Initialize the base path.
+  CXXBaseSpecifierArray BasePath;
   return new (Importer.getToContext()) ImplicitCastExpr(T, E->getCastKind(),
-                                                        SubExpr, 
-                                                        /* FIXME: */0,
+                                                        SubExpr, BasePath,
                                                         E->isLvalueCast());
 }
 
index b342507e7018e80a4dfc93715f9bffc3499d7c76..72ffe00f4867315398694349d071c3f8a0b6bcfe 100644 (file)
@@ -654,8 +654,7 @@ const char *CastExpr::getCastKindName() const {
 
 void CastExpr::DoDestroy(ASTContext &C)
 {
-  if (BasePath)
-    BasePath->Destroy();
+  BasePath.Destroy();
   Expr::DoDestroy(C);
 }
 
index fa21a39ff8f1281e524c1244333fe7162934f386..1ff30f263490b9a685a88ad52ac978f5a91a5704 100644 (file)
@@ -381,7 +381,7 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP,
     if (getContext().getCanonicalType(Ivar->getType()) !=
         getContext().getCanonicalType(ArgDecl->getType())) {
       ImplicitCastExpr ArgCasted(Ivar->getType(), CastExpr::CK_BitCast, &Arg,
-                                 0, false);
+                                 CXXBaseSpecifierArray(), false);
       BinaryOperator Assign(&IvarRef, &ArgCasted, BinaryOperator::Assign,
                             Ivar->getType(), Loc);
       EmitStmt(&Assign);
index fc674354c445149e0b780b2252c2f954bc294094..e3d9955387edd01dbba6dfdbb3142aaf096947e1 100644 (file)
@@ -2087,7 +2087,7 @@ CallExpr *RewriteObjC::SynthesizeCallToFunctionDecl(
   QualType pToFunc = Context->getPointerType(msgSendType);
   ImplicitCastExpr *ICE = 
     new (Context) ImplicitCastExpr(pToFunc, CastExpr::CK_Unknown,
-                                   DRE, /*InheritancePath=*/0,
+                                   DRE, CXXBaseSpecifierArray(),
                                    /*isLvalue=*/false);
 
   const FunctionType *FT = msgSendType->getAs<FunctionType>();
index ad4be1a3ab63b3d64af591c98bdebbefdfec88c0..6975da0b3e346bb2adc8666c99ae562913f7cab7 100644 (file)
@@ -159,8 +159,7 @@ Sema::~Sema() {
 /// If isLvalue, the result of the cast is an lvalue.
 void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty,
                              CastExpr::CastKind Kind, 
-                             CXXBaseSpecifierArray *BasePath,
-                             bool isLvalue) {
+                             bool isLvalue, CXXBaseSpecifierArray BasePath) {
   QualType ExprTy = Context.getCanonicalType(Expr->getType());
   QualType TypeTy = Context.getCanonicalType(Ty);
 
@@ -180,7 +179,7 @@ void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty,
 
   if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) {
     if (ImpCast->getCastKind() == Kind) {
-      assert(!BasePath && "FIXME: Merge paths!");
+      assert(BasePath.empty() && "FIXME: Merge paths!");
       ImpCast->setType(Ty);
       ImpCast->setLvalueCast(isLvalue);
       return;
index 862de98e1b646565dad884a6a7592ca0f2a90466..48b12b5712fcd893216c7992c2f9fea08cd4d527 100644 (file)
@@ -3959,8 +3959,9 @@ public:
   /// cast.  If there is already an implicit cast, merge into the existing one.
   /// If isLvalue, the result of the cast is an lvalue.
   void ImpCastExprToType(Expr *&Expr, QualType Type, CastExpr::CastKind Kind,
-                         CXXBaseSpecifierArray *BasePath = 0,
-                         bool isLvalue = false);
+                         bool isLvalue = false,
+                         CXXBaseSpecifierArray BasePath = 
+                          CXXBaseSpecifierArray());
 
   // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
   // functions and arrays to their respective pointers (C99 6.3.2.1).
index bf2cba10c7903a99b1240900cc8b1d0c4aae40a2..20e4200fbe124d74881fc28f8c3daa7c7df3f9a3 100644 (file)
@@ -6511,7 +6511,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
       ECD->setInitExpr(new (Context) ImplicitCastExpr(NewTy,
                                                       CastExpr::CK_IntegralCast,
                                                       ECD->getInitExpr(),
-                                                      /*InheritancePath=*/0,
+                                                      CXXBaseSpecifierArray(),
                                                       /*isLvalue=*/false));
     if (getLangOptions().CPlusPlus)
       // C++ [dcl.enum]p4: Following the closing brace of an
index f5ecff818443b7c9703b7df9e21283533830323f..02c41da30b2a07bc6c4967cb549aba8d8373299a 100644 (file)
@@ -1443,7 +1443,6 @@ Sema::PerformObjectMemberConversion(Expr *&From,
       if (PointerConversions)
         QType = Context.getPointerType(QType);
       ImpCastExprToType(From, QType, CastExpr::CK_UncheckedDerivedToBase,
-                        /*FIXME: InheritancePath=*/0,
                         /*isLvalue=*/!PointerConversions);
 
       FromType = QType;
@@ -1480,7 +1479,6 @@ Sema::PerformObjectMemberConversion(Expr *&From,
       if (PointerConversions)
         UType = Context.getPointerType(UType);
       ImpCastExprToType(From, UType, CastExpr::CK_UncheckedDerivedToBase,
-                        /*FIXME: InheritancePath=*/0,
                         /*isLvalue*/ !PointerConversions);
       FromType = UType;
       FromRecordType = URecordType;
@@ -1499,7 +1497,6 @@ Sema::PerformObjectMemberConversion(Expr *&From,
     return true;
 
   ImpCastExprToType(From, DestType, CastExpr::CK_UncheckedDerivedToBase,
-                    /*FIXME: InheritancePath=*/0,
                     /*isLvalue=*/!PointerConversions);
   return false;
 }
index 042f2c14abefd82224e6acc923588b9e25d346c7..71d891476143d5c3807ddc8f40b2f97dc132852a 100644 (file)
@@ -341,7 +341,7 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc,
       //   type.
       if (T.hasQualifiers()) {
         ImpCastExprToType(E, T.getUnqualifiedType(), CastExpr::CK_NoOp,
-                          /*InheritancePath=*/0, E->isLvalue(Context));
+                          E->isLvalue(Context));
         TyOrExpr = E;
       }
     }
@@ -392,7 +392,6 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E) {
   //   or "pointer to function returning T", [...]
   if (E->getType().hasQualifiers())
     ImpCastExprToType(E, E->getType().getUnqualifiedType(), CastExpr::CK_NoOp,
-                      /*InheritancePath=*/0,
                       E->isLvalue(Context) == Expr::LV_Valid);
   
   DefaultFunctionArrayConversion(E);
@@ -1792,8 +1791,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
     // FIXME: Not sure about lvalue vs rvalue here in the presence of rvalue
     // references.
     ImpCastExprToType(From, ToType.getNonReferenceType(),
-                      CastExpr::CK_NoOp, /*InheritancePath=*/0,
-                      ToType->isLValueReferenceType());
+                      CastExpr::CK_NoOp, ToType->isLValueReferenceType());
 
     if (SCS.DeprecatedStringLiteralToCharPtr)
       Diag(From->getLocStart(), diag::warn_deprecated_string_literal_conversion)
@@ -1887,8 +1885,7 @@ QualType Sema::CheckPointerToMemberOperands(
     // Cast LHS to type of use.
     QualType UseType = isIndirect ? Context.getPointerType(Class) : Class;
     bool isLValue = !isIndirect && lex->isLvalue(Context) == Expr::LV_Valid;
-    ImpCastExprToType(lex, UseType, CastExpr::CK_DerivedToBase, 
-                      /*FIXME: InheritancePath=*/0, isLValue);
+    ImpCastExprToType(lex, UseType, CastExpr::CK_DerivedToBase, isLValue);
   }
 
   if (isa<CXXZeroInitValueExpr>(rex->IgnoreParens())) {
index 904489cdd9c3bd88bc601d17a8e12a44ef558286..90c8e3bac6cfb1a83d8df0c554108ca66f6841a8 100644 (file)
@@ -3468,7 +3468,7 @@ InitializationSequence::Perform(Sema &S,
       CurInit = S.Owned(new (S.Context) ImplicitCastExpr(Step->Type,
                                                     CastExpr::CK_DerivedToBase,
                                                     (Expr*)CurInit.release(),
-                                                    /*FIXME:InheritancePath=*/0,
+                                                    CXXBaseSpecifierArray(),
                                      Step->Kind == SK_CastDerivedToBaseLValue));
       break;
     }
@@ -3586,10 +3586,10 @@ InitializationSequence::Perform(Sema &S,
 
       CurInitExpr = CurInit.takeAs<Expr>();
       CurInit = S.Owned(new (S.Context) ImplicitCastExpr(CurInitExpr->getType(),
-                                                         CastKind, 
-                                                         CurInitExpr,
-                                                         /*InheritancePath=*/0,
-                                                         IsLvalue));
+                                                        CastKind, 
+                                                        CurInitExpr,
+                                                        CXXBaseSpecifierArray(),
+                                                        IsLvalue));
       
       if (RequiresCopy)
         CurInit = CopyObject(S, Entity.getType().getNonReferenceType(), Entity,
@@ -3601,7 +3601,7 @@ InitializationSequence::Perform(Sema &S,
     case SK_QualificationConversionRValue:
       // Perform a qualification conversion; these can never go wrong.
       S.ImpCastExprToType(CurInitExpr, Step->Type,
-                          CastExpr::CK_NoOp, /*InheritancePath=*/0,
+                          CastExpr::CK_NoOp,
                           Step->Kind == SK_QualificationConversionLValue);
       CurInit.release();
       CurInit = S.Owned(CurInitExpr);
index 732b9ee3ebcc06eb366997f27f6defd27ee9eb39..50afb7e1bca2fa2e3a34e803ebc0be7e50a401b7 100644 (file)
@@ -2675,8 +2675,8 @@ Sema::PerformObjectArgumentInitialization(Expr *&From,
     return PerformObjectMemberConversion(From, Qualifier, FoundDecl, Method);
 
   if (!Context.hasSameType(From->getType(), DestType))
-    ImpCastExprToType(From, DestType, CastExpr::CK_NoOp, /*InheritancePath=*/0,
-                      /*isLvalue=*/!From->getType()->getAs<PointerType>());
+    ImpCastExprToType(From, DestType, CastExpr::CK_NoOp,
+                      /*isLvalue=*/!From->getType()->isPointerType());
   return false;
 }
 
@@ -3157,7 +3157,7 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion,
                             From->getLocStart());
   ImplicitCastExpr ConversionFn(Context.getPointerType(Conversion->getType()),
                                 CastExpr::CK_FunctionToPointerDecay,
-                                &ConversionRef, /*InheritancePath=*/0, false);
+                                &ConversionRef, CXXBaseSpecifierArray(), false);
 
   // Note that it is safe to allocate CallExpr on the stack here because
   // there are 0 arguments (i.e., nothing is allocated using ASTContext's
@@ -6859,8 +6859,7 @@ Expr *Sema::FixOverloadedFunctionReference(Expr *E, DeclAccessPair Found,
     
     return new (Context) ImplicitCastExpr(ICE->getType(), 
                                           ICE->getCastKind(),
-                                          SubExpr,
-                                          /*InheritancePath=*/0,
+                                          SubExpr, CXXBaseSpecifierArray(),
                                           ICE->isLvalueCast());
   } 
   
index 14d04563d69aab8b5e0062a41b2d4e69134dabef..7e7413f296b3447176e56f1ad82f09438966de24 100644 (file)
@@ -2868,7 +2868,6 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
 
     if (IsQualificationConversion(ArgType, ParamType.getNonReferenceType())) {
       ImpCastExprToType(Arg, ParamType, CastExpr::CK_NoOp,
-                        /*InheritancePath=*/0,
                         Arg->isLvalue(Context) == Expr::LV_Valid);
     } else if (!Context.hasSameUnqualifiedType(ArgType,
                                            ParamType.getNonReferenceType())) {
@@ -2933,7 +2932,6 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
     // Types match exactly: nothing more to do here.
   } else if (IsQualificationConversion(ArgType, ParamType)) {
     ImpCastExprToType(Arg, ParamType, CastExpr::CK_NoOp,
-                      /*InheritancePath=*/0,
                       Arg->isLvalue(Context) == Expr::LV_Valid);
   } else {
     // We can't perform this conversion.