[cfe-commits] r78415 - in /cfe/trunk/lib/Sema: Sema.h SemaCXXCast.cpp SemaChecking.cpp SemaExpr.cpp SemaExprCXX.cpp

Anders Carlsson andersca at mac.com
Fri Aug 7 15:21:05 PDT 2009


Author: andersca
Date: Fri Aug  7 17:21:05 2009
New Revision: 78415

URL: http://llvm.org/viewvc/llvm-project?rev=78415&view=rev
Log:
More CastKind work.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaCXXCast.cpp
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=78415&r1=78414&r2=78415&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Aug  7 17:21:05 2009
@@ -3264,7 +3264,7 @@
   /// 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 @@
   /// 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.

Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=78415&r1=78414&r2=78415&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Fri Aug  7 17:21:05 2009
@@ -42,7 +42,8 @@
                                  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 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 @@
                                   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 @@
 /// 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 @@
     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 @@
 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 @@
   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 @@
   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);

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=78415&r1=78414&r2=78415&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Aug  7 17:21:05 2009
@@ -383,7 +383,8 @@
     
     // 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 @@
     // 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);
   }
   

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=78415&r1=78414&r2=78415&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Aug  7 17:21:05 2009
@@ -2972,9 +2972,9 @@
 
 /// 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 @@
 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.

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=78415&r1=78414&r2=78415&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Aug  7 17:21:05 2009
@@ -203,12 +203,12 @@
   // 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));
   }
 





More information about the cfe-commits mailing list