Skip to content

Commit d22b984

Browse files
committed
[Expr] Allow OpaqueValueExpr to store an underlying expression
1 parent fd1dcf7 commit d22b984

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

include/swift/AST/Expr.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,11 +4021,14 @@ class DynamicTypeExpr : public Expr {
40214021
/// subexpressions of that AST node.
40224022
class OpaqueValueExpr : public Expr {
40234023
SourceRange Range;
4024+
Expr *UnderlyingValue;
40244025

40254026
public:
40264027
explicit OpaqueValueExpr(SourceRange Range, Type Ty,
4027-
bool isPlaceholder = false)
4028-
: Expr(ExprKind::OpaqueValue, /*Implicit=*/true, Ty), Range(Range) {
4028+
bool isPlaceholder = false,
4029+
Expr *underlyingValue = nullptr)
4030+
: Expr(ExprKind::OpaqueValue, /*Implicit=*/true, Ty),
4031+
Range(Range), UnderlyingValue(underlyingValue) {
40294032
Bits.OpaqueValueExpr.IsPlaceholder = isPlaceholder;
40304033
}
40314034

@@ -4038,6 +4041,14 @@ class OpaqueValueExpr : public Expr {
40384041
Bits.OpaqueValueExpr.IsPlaceholder = value;
40394042
}
40404043

4044+
Expr *getUnderlyingValue() const {
4045+
return UnderlyingValue;
4046+
}
4047+
4048+
void setUnderlyingValue(Expr *value) {
4049+
UnderlyingValue = value;
4050+
}
4051+
40414052
SourceRange getSourceRange() const { return Range; }
40424053

40434054
static bool classof(const Expr *E) {

lib/AST/ASTDumper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,6 +2498,10 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
24982498

24992499
void visitOpaqueValueExpr(OpaqueValueExpr *E) {
25002500
printCommon(E, "opaque_value_expr") << " @ " << (void*)E;
2501+
if (auto *underlyingValue = E->getUnderlyingValue()) {
2502+
OS << '\n';
2503+
printRec(underlyingValue);
2504+
}
25012505
PrintWithColorRAII(OS, ParenthesisColor) << ')';
25022506
}
25032507

lib/AST/ASTWalker.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,15 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
506506
return E;
507507
}
508508

509-
Expr *visitOpaqueValueExpr(OpaqueValueExpr *E) { return E; }
509+
Expr *visitOpaqueValueExpr(OpaqueValueExpr *E) {
510+
if (E->getUnderlyingValue()) {
511+
if (auto *newValue = doIt(E->getUnderlyingValue()))
512+
E->setUnderlyingValue(newValue);
513+
else
514+
return nullptr;
515+
}
516+
return E;
517+
}
510518

511519
Expr *visitDefaultArgumentExpr(DefaultArgumentExpr *E) { return E; }
512520

0 commit comments

Comments
 (0)