forked from OSchip/llvm-project
[AST] Sink 'part of explicit cast' down into ImplicitCastExpr
Summary: As discussed in IRC with @rsmith, it is slightly not good to keep that in the `CastExpr` itself: Given the explicit cast, which is represented in AST as an `ExplicitCastExpr` + `ImplicitCastExpr`'s, only the `ImplicitCastExpr`'s will be marked as `PartOfExplicitCast`, but not the `ExplicitCastExpr` itself. Thus, it is only ever `true` for `ImplicitCastExpr`'s, so we don't need to write/read/dump it for `ExplicitCastExpr`'s. We don't need to worry that we write the `PartOfExplicitCast` in PCH after `CastExpr::path_iterator`, since the `ExprImplicitCastAbbrev` is only used when the `NumBaseSpecs == 0`, i.e. there is no 'path'. Reviewers: rsmith, rjmccall, erichkeane, aaron.ballman Reviewed By: rsmith, erichkeane Subscribers: vsk, cfe-commits, rsmith Tags: #clang Differential Revision: https://reviews.llvm.org/D49838 llvm-svn: 338108
This commit is contained in:
parent
eeab694cea
commit
12216f1d4a
|
@ -2830,6 +2830,7 @@ protected:
|
|||
/// Construct an empty cast.
|
||||
CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
|
||||
: Expr(SC, Empty) {
|
||||
CastExprBits.PartOfExplicitCast = false;
|
||||
setBasePathSize(BasePathSize);
|
||||
}
|
||||
|
||||
|
@ -2837,13 +2838,6 @@ public:
|
|||
CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
|
||||
void setCastKind(CastKind K) { CastExprBits.Kind = K; }
|
||||
|
||||
bool getIsPartOfExplicitCast() const {
|
||||
return CastExprBits.PartOfExplicitCast;
|
||||
}
|
||||
void setIsPartOfExplicitCast(bool PartOfExplicitCast) {
|
||||
CastExprBits.PartOfExplicitCast = PartOfExplicitCast;
|
||||
}
|
||||
|
||||
static const char *getCastKindName(CastKind CK);
|
||||
const char *getCastKindName() const { return getCastKindName(getCastKind()); }
|
||||
|
||||
|
@ -2932,6 +2926,11 @@ public:
|
|||
: CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
|
||||
}
|
||||
|
||||
bool isPartOfExplicitCast() const { return CastExprBits.PartOfExplicitCast; }
|
||||
void setIsPartOfExplicitCast(bool PartOfExplicitCast) {
|
||||
CastExprBits.PartOfExplicitCast = PartOfExplicitCast;
|
||||
}
|
||||
|
||||
static ImplicitCastExpr *Create(const ASTContext &Context, QualType T,
|
||||
CastKind Kind, Expr *Operand,
|
||||
const CXXCastPath *BasePath,
|
||||
|
|
|
@ -198,11 +198,12 @@ protected:
|
|||
|
||||
class CastExprBitfields {
|
||||
friend class CastExpr;
|
||||
friend class ImplicitCastExpr;
|
||||
|
||||
unsigned : NumExprBits;
|
||||
|
||||
unsigned Kind : 6;
|
||||
unsigned PartOfExplicitCast : 1;
|
||||
unsigned PartOfExplicitCast : 1; // Only set for ImplicitCastExpr.
|
||||
unsigned BasePathSize : 32 - 6 - 1 - NumExprBits;
|
||||
};
|
||||
|
||||
|
|
|
@ -521,6 +521,7 @@ namespace {
|
|||
// Exprs
|
||||
void VisitExpr(const Expr *Node);
|
||||
void VisitCastExpr(const CastExpr *Node);
|
||||
void VisitImplicitCastExpr(const ImplicitCastExpr *Node);
|
||||
void VisitDeclRefExpr(const DeclRefExpr *Node);
|
||||
void VisitPredefinedExpr(const PredefinedExpr *Node);
|
||||
void VisitCharacterLiteral(const CharacterLiteral *Node);
|
||||
|
@ -2117,8 +2118,11 @@ void ASTDumper::VisitCastExpr(const CastExpr *Node) {
|
|||
}
|
||||
dumpBasePath(OS, Node);
|
||||
OS << ">";
|
||||
}
|
||||
|
||||
if (Node->getIsPartOfExplicitCast())
|
||||
void ASTDumper::VisitImplicitCastExpr(const ImplicitCastExpr *Node) {
|
||||
VisitCastExpr(Node);
|
||||
if (Node->isPartOfExplicitCast())
|
||||
OS << " part_of_explicit_cast";
|
||||
}
|
||||
|
||||
|
|
|
@ -93,8 +93,8 @@ namespace {
|
|||
// Walk down from the CE to the OrigSrcExpr, and mark all immediate
|
||||
// ImplicitCastExpr's as being part of ExplicitCastExpr. The original CE
|
||||
// (which is a ExplicitCastExpr), and the OrigSrcExpr are not touched.
|
||||
while ((CE = dyn_cast<ImplicitCastExpr>(CE->getSubExpr())))
|
||||
CE->setIsPartOfExplicitCast(true);
|
||||
for (; auto *ICE = dyn_cast<ImplicitCastExpr>(CE->getSubExpr()); CE = ICE)
|
||||
ICE->setIsPartOfExplicitCast(true);
|
||||
}
|
||||
|
||||
/// Complete an apparently-successful cast operation that yields
|
||||
|
|
|
@ -723,7 +723,6 @@ void ASTStmtReader::VisitCastExpr(CastExpr *E) {
|
|||
assert(NumBaseSpecs == E->path_size());
|
||||
E->setSubExpr(Record.readSubExpr());
|
||||
E->setCastKind((CastKind)Record.readInt());
|
||||
E->setIsPartOfExplicitCast(Record.readInt());
|
||||
CastExpr::path_iterator BaseI = E->path_begin();
|
||||
while (NumBaseSpecs--) {
|
||||
auto *BaseSpec = new (Record.getContext()) CXXBaseSpecifier;
|
||||
|
@ -770,6 +769,7 @@ ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
|
|||
|
||||
void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
|
||||
VisitCastExpr(E);
|
||||
E->setIsPartOfExplicitCast(Record.readInt());
|
||||
}
|
||||
|
||||
void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
|
||||
|
|
|
@ -665,7 +665,6 @@ void ASTStmtWriter::VisitCastExpr(CastExpr *E) {
|
|||
Record.push_back(E->path_size());
|
||||
Record.AddStmt(E->getSubExpr());
|
||||
Record.push_back(E->getCastKind()); // FIXME: stable encoding
|
||||
Record.push_back(E->getIsPartOfExplicitCast());
|
||||
|
||||
for (CastExpr::path_iterator
|
||||
PI = E->path_begin(), PE = E->path_end(); PI != PE; ++PI)
|
||||
|
@ -714,6 +713,7 @@ ASTStmtWriter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
|
|||
|
||||
void ASTStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
|
||||
VisitCastExpr(E);
|
||||
Record.push_back(E->isPartOfExplicitCast());
|
||||
|
||||
if (E->path_size() == 0)
|
||||
AbbrevToUse = Writer.getExprImplicitCastAbbrev();
|
||||
|
|
Loading…
Reference in New Issue