[PATCH] D49844: [AST] Add a isActuallyImplicitCast() helper to the CastExpr class.

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 26 07:45:20 PDT 2018


lebedev.ri updated this revision to Diff 157484.
lebedev.ri marked 2 inline comments as done.
lebedev.ri added a comment.

Comment fine-tuning.

In https://reviews.llvm.org/D49844#1176639, @erichkeane wrote:

> I'm not sure that this logic requires a separate function.  Since you've fixed the getIsPartOfExplicitCast logic correctly, it is pretty simple...


Certainly. I can **totally** inline it into the caller,
but i *think* @rsmith suggested that such functionality should be present, so i'll wait for him to comment.


Repository:
  rC Clang

https://reviews.llvm.org/D49844

Files:
  include/clang/AST/Expr.h


Index: include/clang/AST/Expr.h
===================================================================
--- include/clang/AST/Expr.h
+++ include/clang/AST/Expr.h
@@ -2852,6 +2852,15 @@
     return const_cast<CastExpr *>(this)->getSubExprAsWritten();
   }
 
+  /// There are two global types of casts - implicit and explicit. An explicit
+  /// cast corresponds to a cast written in the source code, while an implicit
+  /// cast is materialized for the purposes of automatic conversions.
+  /// But in AST, some explicit casts are represented as ExplicitCastExpr plus
+  /// one or more immediate ImplicitCastExpr (i.e. with nothing inbetween).
+  /// This function returns false if this cast is either an ExplicitCastExpr
+  /// itself, or it is a part of the ExplicitCastExpr group.
+  bool isActuallyImplicitCast() const;
+
   /// If this cast applies a user-defined conversion, retrieve the conversion
   /// function that it invokes.
   NamedDecl *getConversionFunction() const;
@@ -3009,6 +3018,13 @@
   }
 };
 
+inline bool CastExpr::isActuallyImplicitCast() const {
+  if (auto *IC = dyn_cast<ImplicitCastExpr>(this))
+    return !IC->getIsPartOfExplicitCast();
+  assert(isa<ExplicitCastExpr>(this) && "it has to be Explicit cast then.");
+  return false; // Explicit cast is clearly not an Implicit cast.
+}
+
 /// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
 /// cast in C++ (C++ [expr.cast]), which uses the syntax
 /// (Type)expr. For example: @c (int)f.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49844.157484.patch
Type: text/x-patch
Size: 1484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180726/2dab1a69/attachment.bin>


More information about the cfe-commits mailing list