]> granicus.if.org Git - clang/commitdiff
More CastKind work.
authorAnders Carlsson <andersca@mac.com>
Fri, 7 Aug 2009 22:21:05 +0000 (22:21 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 7 Aug 2009 22:21:05 +0000 (22:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78415 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaCXXCast.cpp
lib/Sema/SemaChecking.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprCXX.cpp

index e83fcf579fd9652fafd81c624d4013aafa96f714..6094e6dae03998fc5afcfec4a3e16f84b46eba31 100644 (file)
@@ -3264,7 +3264,7 @@ public:
   /// CheckCastTypes - Check type constraints for casting between types under
   /// C semantics, or forward to CXXCheckCStyleCast in C++.
   bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr,
-                      bool FunctionalStyle = false);
+                      CastExpr::CastKind &Kind, bool FunctionalStyle = false);
 
   // CheckVectorCast - check type constraints for vectors. 
   // Since vectors are an extension, there are no C standard reference for this.
@@ -3282,7 +3282,7 @@ public:
   /// CXXCheckCStyleCast - Check constraints of a C-style or function-style
   /// cast under C++ semantics.
   bool CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr,
-                          bool FunctionalStyle);
+                          CastExpr::CastKind &Kind, bool FunctionalStyle);
 
   /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 
   /// \param Method - May be null.
index 254af541710d5c3dba93d30409fc3306bcc1e08f..b8dbd18eb31a90f631e173eb9f4e1ab522609d5d 100644 (file)
@@ -42,7 +42,8 @@ static void CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
                                  const SourceRange &OpRange,
                                  const SourceRange &DestRange);
 static void CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
-                            const SourceRange &OpRange);
+                            const SourceRange &OpRange,
+                            CastExpr::CastKind &Kind);
 static void CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
                              const SourceRange &OpRange,
                              const SourceRange &DestRange, 
@@ -87,7 +88,7 @@ static TryCastResult TryStaticImplicitCast(Sema &Self, Expr *SrcExpr,
 static TryCastResult TryStaticCast(Sema &Self, Expr *SrcExpr,
                                    QualType DestType, bool CStyle,
                                    const SourceRange &OpRange,
-                                   unsigned &msg);
+                                   CastExpr::CastKind &Kind, unsigned &msg);
 static TryCastResult TryConstCast(Sema &Self, Expr *SrcExpr, QualType DestType,
                                   bool CStyle, unsigned &msg);
 static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr,
@@ -134,12 +135,13 @@ Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
                                   DestType.getNonReferenceType(),
                                   Ex, DestType, OpLoc));
 
-  case tok::kw_static_cast:
+  case tok::kw_static_cast: {
+    CastExpr::CastKind Kind = CastExpr::CK_Unknown;
     if (!TypeDependent)
-      CheckStaticCast(*this, Ex, DestType, OpRange);
+      CheckStaticCast(*this, Ex, DestType, OpRange, Kind);
     return Owned(new (Context) CXXStaticCastExpr(DestType.getNonReferenceType(),
-                                                 CastExpr::CK_Unknown, Ex, 
-                                                 DestType, OpLoc));
+                                                 Kind, Ex, DestType, OpLoc));
+  }
   }
 
   return ExprError();
@@ -354,7 +356,7 @@ CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
 /// implicit conversions explicit and getting rid of data loss warnings.
 void
 CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
-                const SourceRange &OpRange)
+                const SourceRange &OpRange, CastExpr::CastKind &Kind)
 {
   // This test is outside everything else because it's the only case where
   // a non-lvalue-reference target type does not lead to decay.
@@ -367,7 +369,8 @@ CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
     Self.DefaultFunctionArrayConversion(SrcExpr);
 
   unsigned msg = diag::err_bad_cxx_cast_generic;
-  if (TryStaticCast(Self, SrcExpr, DestType, /*CStyle*/false, OpRange, msg)
+  if (TryStaticCast(Self, SrcExpr, DestType, /*CStyle*/false, OpRange, 
+                    Kind, msg)
       != TC_Success && msg != 0)
     Self.Diag(OpRange.getBegin(), msg) << CT_Static
       << SrcExpr->getType() << DestType << OpRange;
@@ -379,7 +382,7 @@ CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
 static TryCastResult TryStaticCast(Sema &Self, Expr *SrcExpr,
                                    QualType DestType, bool CStyle,
                                    const SourceRange &OpRange,
-                                   unsigned &msg)
+                                   CastExpr::CastKind &Kind, unsigned &msg)
 {
   // The order the tests is not entirely arbitrary. There is one conversion
   // that can be handled in two different ways. Given:
@@ -1003,9 +1006,8 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr,
   return TC_Success;
 }
 
-
 bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr,
-                              bool FunctionalStyle)
+                              CastExpr::CastKind &Kind, bool FunctionalStyle)
 {
   // This test is outside everything else because it's the only case where
   // a non-lvalue-reference target type does not lead to decay.
@@ -1035,7 +1037,7 @@ bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr,
   TryCastResult tcr = TryConstCast(*this, CastExpr, CastTy, /*CStyle*/true,msg);
   if (tcr == TC_NotApplicable) {
     // ... or if that is not possible, a static_cast, ignoring const, ...
-    tcr = TryStaticCast(*this, CastExpr, CastTy, /*CStyle*/true, R, msg);
+    tcr = TryStaticCast(*this, CastExpr, CastTy, /*CStyle*/true, R, Kind, msg);
     if (tcr == TC_NotApplicable) {
       // ... and finally a reinterpret_cast, ignoring const.
       tcr = TryReinterpretCast(*this, CastExpr, CastTy, /*CStyle*/true, R, msg);
index 949c33dfff806b0b115149f281b8752e844e8b14..b35287aa31eb78a4d88e81b8f8235674984df2b3 100644 (file)
@@ -383,7 +383,8 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) {
     
     // GCC does an implicit conversion to the pointer or integer ValType.  This
     // can fail in some cases (1i -> int**), check for this error case now.
-    if (CheckCastTypes(Arg->getSourceRange(), ValType, Arg))
+    CastExpr::CastKind Kind = CastExpr::CK_Unknown;
+    if (CheckCastTypes(Arg->getSourceRange(), ValType, Arg, Kind))
       return true;
     
     // Okay, we have something that *can* be converted to the right type.  Check
@@ -392,8 +393,7 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) {
     // pass in 42.  The 42 gets converted to char.  This is even more strange
     // for things like 45.123 -> char, etc.
     // FIXME: Do this check.  
-    ImpCastExprToType(Arg, ValType, CastExpr::CK_Unknown,
-                      /*isLvalue=*/false);
+    ImpCastExprToType(Arg, ValType, Kind, /*isLvalue=*/false);
     TheCall->setArg(i+1, Arg);
   }
   
index 51ebd079a496f6968562050956bf18187ab2d160..684c2dafdbaf36430c3677b8da87dcc9087d869b 100644 (file)
@@ -2972,9 +2972,9 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg initlist,
 
 /// CheckCastTypes - Check type constraints for casting between types.
 bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr,
-                          bool FunctionalStyle) {
+                          CastExpr::CastKind& Kind, bool FunctionalStyle) {
   if (getLangOptions().CPlusPlus)
-    return CXXCheckCStyleCast(TyR, castType, castExpr, FunctionalStyle);
+    return CXXCheckCStyleCast(TyR, castType, castExpr, Kind, FunctionalStyle);
 
   UsualUnaryConversions(castExpr);
 
@@ -3087,17 +3087,20 @@ bool Sema::CheckExtVectorCast(SourceRange R, QualType DestTy, QualType SrcTy) {
 Action::OwningExprResult
 Sema::ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
                     SourceLocation RParenLoc, ExprArg Op) {
+  CastExpr::CastKind Kind = CastExpr::CK_Unknown;
+  
   assert((Ty != 0) && (Op.get() != 0) &&
          "ActOnCastExpr(): missing type or expr");
 
   Expr *castExpr = Op.takeAs<Expr>();
   QualType castType = QualType::getFromOpaquePtr(Ty);
 
-  if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), castType, castExpr))
+  if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), castType, castExpr, 
+                     Kind))
     return ExprError();
   return Owned(new (Context) CStyleCastExpr(castType.getNonReferenceType(),
-                                            CastExpr::CK_Unknown, castExpr
-                                            castType, LParenLoc, RParenLoc));
+                                            Kind, castExpr, castType
+                                            LParenLoc, RParenLoc));
 }
 
 /// Note that lhs is not null here, even if this is the gnu "x ?: y" extension.
index 5b7493819103229c1e9d2a83930902311d577fb0..8a352c4ee298af04d8a19a357d2944b9e44d89f1 100644 (file)
@@ -203,12 +203,12 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep,
   // corresponding cast expression.
   //
   if (NumExprs == 1) {
-    if (CheckCastTypes(TypeRange, Ty, Exprs[0], /*functional-style*/true))
+    CastExpr::CastKind Kind = CastExpr::CK_Unknown;
+    if (CheckCastTypes(TypeRange, Ty, Exprs[0], Kind, /*functional-style*/true))
       return ExprError();
     exprs.release();
     return Owned(new (Context) CXXFunctionalCastExpr(Ty.getNonReferenceType(),
-                                                     Ty, TyBeginLoc, 
-                                                     CastExpr::CK_Unknown, 
+                                                     Ty, TyBeginLoc, Kind,
                                                      Exprs[0], RParenLoc));
   }