]> granicus.if.org Git - clang/commitdiff
Preserve type source information for C++ named casts through template
authorJohn McCall <rjmccall@apple.com>
Fri, 15 Jan 2010 19:13:16 +0000 (19:13 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 15 Jan 2010 19:13:16 +0000 (19:13 +0000)
instantiation.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93533 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaCXXCast.cpp
lib/Sema/TreeTransform.h

index e86da5d48fc4f3ffd5a0cf578ad4bf1c7e4cbaab..00a85f885186763d002aa07b2c02333e4f507407 100644 (file)
@@ -1925,6 +1925,13 @@ public:
                                              ExprArg E,
                                              SourceLocation RParenLoc);
 
+  OwningExprResult BuildCXXNamedCast(SourceLocation OpLoc,
+                                     tok::TokenKind Kind,
+                                     TypeSourceInfo *Ty,
+                                     ExprArg E,
+                                     SourceRange AngleBrackets,
+                                     SourceRange Parens);
+
   /// ActOnCXXTypeid - Parse typeid( something ).
   virtual OwningExprResult ActOnCXXTypeid(SourceLocation OpLoc,
                                           SourceLocation LParenLoc, bool isType,
index 178bc7a0140710ae0b9dcdcd6b867eab72e09ad3..57c4f9bc2a27b603d56f544f4ca61c43ab3d5ff3 100644 (file)
@@ -116,13 +116,26 @@ Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
                         SourceLocation RAngleBracketLoc,
                         SourceLocation LParenLoc, ExprArg E,
                         SourceLocation RParenLoc) {
-  Expr *Ex = E.takeAs<Expr>();
+  
   TypeSourceInfo *DestTInfo;
   QualType DestType = GetTypeFromParser(Ty, &DestTInfo);
   if (!DestTInfo)
     DestTInfo = Context.getTrivialTypeSourceInfo(DestType, SourceLocation());
-  SourceRange OpRange(OpLoc, RParenLoc);
-  SourceRange DestRange(LAngleBracketLoc, RAngleBracketLoc);
+
+  return BuildCXXNamedCast(OpLoc, Kind, DestTInfo, move(E),
+                           SourceRange(LAngleBracketLoc, RAngleBracketLoc),
+                           SourceRange(LParenLoc, RParenLoc));
+}
+
+Action::OwningExprResult
+Sema::BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
+                        TypeSourceInfo *DestTInfo, ExprArg E,
+                        SourceRange AngleBrackets, SourceRange Parens) {
+  Expr *Ex = E.takeAs<Expr>();
+  QualType DestType = DestTInfo->getType();
+
+  SourceRange OpRange(OpLoc, Parens.getEnd());
+  SourceRange DestRange = AngleBrackets;
 
   // If the type is dependent, we won't do the semantic analysis now.
   // FIXME: should we check this in a more fine-grained manner?
index 469ff72d3fc09b750802371067c534c2af6672ea..41f465f595caa0240f1e1aa147b6e813640dc129 100644 (file)
@@ -1237,11 +1237,10 @@ public:
                                             SourceLocation LParenLoc,
                                             ExprArg SubExpr,
                                             SourceLocation RParenLoc) {
-    return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
-                                       LAngleLoc,
-                                       TInfo->getType().getAsOpaquePtr(),
-                                       RAngleLoc,
-                                       LParenLoc, move(SubExpr), RParenLoc);
+    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
+                                       TInfo, move(SubExpr),
+                                       SourceRange(LAngleLoc, RAngleLoc),
+                                       SourceRange(LParenLoc, RParenLoc));
   }
 
   /// \brief Build a new C++ dynamic_cast expression.
@@ -1255,11 +1254,10 @@ public:
                                              SourceLocation LParenLoc,
                                              ExprArg SubExpr,
                                              SourceLocation RParenLoc) {
-    return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
-                                       LAngleLoc,
-                                       TInfo->getType().getAsOpaquePtr(),
-                                       RAngleLoc,
-                                       LParenLoc, move(SubExpr), RParenLoc);
+    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
+                                       TInfo, move(SubExpr),
+                                       SourceRange(LAngleLoc, RAngleLoc),
+                                       SourceRange(LParenLoc, RParenLoc));
   }
 
   /// \brief Build a new C++ reinterpret_cast expression.
@@ -1273,11 +1271,10 @@ public:
                                                  SourceLocation LParenLoc,
                                                  ExprArg SubExpr,
                                                  SourceLocation RParenLoc) {
-    return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
-                                       LAngleLoc,
-                                       TInfo->getType().getAsOpaquePtr(),
-                                       RAngleLoc,
-                                       LParenLoc, move(SubExpr), RParenLoc);
+    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
+                                       TInfo, move(SubExpr),
+                                       SourceRange(LAngleLoc, RAngleLoc),
+                                       SourceRange(LParenLoc, RParenLoc));
   }
 
   /// \brief Build a new C++ const_cast expression.
@@ -1291,11 +1288,10 @@ public:
                                            SourceLocation LParenLoc,
                                            ExprArg SubExpr,
                                            SourceLocation RParenLoc) {
-    return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
-                                       LAngleLoc,
-                                       TInfo->getType().getAsOpaquePtr(),
-                                       RAngleLoc,
-                                       LParenLoc, move(SubExpr), RParenLoc);
+    return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
+                                       TInfo, move(SubExpr),
+                                       SourceRange(LAngleLoc, RAngleLoc),
+                                       SourceRange(LParenLoc, RParenLoc));
   }
 
   /// \brief Build a new C++ functional-style cast expression.