aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/Sema.cpp
diff options
context:
space:
mode:
authorNicola Gigante <nicola.gigante@gmail.com>2011-11-28 12:21:57 +0000
committerNicola Gigante <nicola.gigante@gmail.com>2011-11-28 12:21:57 +0000
commit56f5d36fd13c5e271ebd05192c25c88d28e77f8d (patch)
tree1b5c2cebb1356ec0395190380414db6a58235b64 /lib/Sema/Sema.cpp
parentb6a1d9d3f63a26d90aa669696ba4a57cbdd9e960 (diff)
Removed useless ImplicitCast nodes in explicit cstyle and static casts
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145244 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r--lib/Sema/Sema.cpp58
1 files changed, 43 insertions, 15 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index fe393dd2fe..0ce816b8dc 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -234,13 +234,16 @@ void Sema::PrintStats() const {
AnalysisWarnings.PrintStats();
}
-/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
-/// If there is already an implicit cast, merge into the existing one.
-/// The result is of the given category.
-ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
- CastKind Kind, ExprValueKind VK,
- const CXXCastPath *BasePath,
- CheckedConversionKind CCK) {
+/// CastExprToType - If Expr is not of type 'Type', insert a cast of the
+/// specified kind.
+/// Redundant implicit casts are merged together.
+/// Pay attention: if CCK != CCK_ImplicitConversion,
+/// users of this function must fill
+/// SourceTypeInfos and SourceLocations later
+ExprResult Sema::CastExprToType(Expr *E, QualType Ty,
+ CastKind Kind, ExprValueKind VK,
+ const CXXCastPath *BasePath,
+ CheckedConversionKind CCK) {
#ifndef NDEBUG
if (VK == VK_RValue && !E->isRValue()) {
switch (Kind) {
@@ -276,16 +279,41 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
MarkVTableUsed(E->getLocStart(),
cast<CXXRecordDecl>(RecordTy->getDecl()));
}
-
- if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
- if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) {
- ImpCast->setType(Ty);
- ImpCast->setValueKind(VK);
- return Owned(E);
- }
+
+ switch(CCK) {
+ default:
+ llvm_unreachable("Unexpected CheckedConversionKind");
+ case CCK_ImplicitConversion:
+ if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
+ if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) {
+ ImpCast->setType(Ty);
+ ImpCast->setValueKind(VK);
+ return Owned(E);
+ }
+ }
+ return Owned(ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK));
+ case CCK_CStyleCast:
+ return Owned(CStyleCastExpr::Create(Context, Ty, VK, Kind, E, BasePath,
+ 0, SourceLocation(), SourceLocation()));
+ case CCK_FunctionalCast:
+ return Owned(CXXFunctionalCastExpr::Create(Context, Ty, VK, 0,
+ SourceLocation(), Kind, E,
+ BasePath, SourceLocation()));
+ case CCK_StaticCast:
+ return Owned(CXXStaticCastExpr::Create(Context, Ty, VK, Kind, E, BasePath,
+ 0, SourceLocation(),
+ SourceLocation()));
}
+
+}
- return Owned(ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK));
+/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
+/// If there is already an implicit cast, merge into the existing one.
+/// The result is of the given category.
+ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
+ CastKind Kind, ExprValueKind VK,
+ const CXXCastPath *BasePath) {
+ return CastExprToType(E, Ty, Kind, VK, BasePath, CCK_ImplicitConversion);
}
/// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding