Skip to content

Commit e0cbc62

Browse files
committed
Generalize shouldLog over ASTNode as suggested in Code Review.
1 parent af5f647 commit e0cbc62

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/Sema/PlaygroundTransform.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ class Instrumenter : InstrumenterBase {
429429
++EI;
430430
}
431431
}
432-
} else if (shouldLogType(AE->getSrc()->getType())) {
432+
} else if (shouldLog(AE->getSrc())) {
433433
std::pair<PatternBindingDecl *, VarDecl *> PV =
434434
buildPatternAndVariable(AE->getSrc());
435435
DeclRefExpr *DRE = new (Context)
@@ -521,7 +521,7 @@ class Instrumenter : InstrumenterBase {
521521
}
522522
Handled = true; // Never log ()
523523
}
524-
if (!Handled && shouldLogType(E->getType())) {
524+
if (!Handled && shouldLog(E)) {
525525
// do the same as for all other expressions
526526
std::pair<PatternBindingDecl *, VarDecl *> PV =
527527
buildPatternAndVariable(E);
@@ -539,7 +539,7 @@ class Instrumenter : InstrumenterBase {
539539
}
540540
}
541541
} else {
542-
if (E->getType()->getCanonicalType() != Context.TheEmptyTupleType && shouldLogType(E->getType())) {
542+
if (E->getType()->getCanonicalType() != Context.TheEmptyTupleType && shouldLog(E)) {
543543
std::pair<PatternBindingDecl *, VarDecl *> PV =
544544
buildPatternAndVariable(E);
545545
Added<Stmt *> Log = buildLoggerCall(
@@ -559,7 +559,7 @@ class Instrumenter : InstrumenterBase {
559559
} else if (auto *S = Element.dyn_cast<Stmt *>()) {
560560
S->walk(CF);
561561
if (auto *RS = dyn_cast<ReturnStmt>(S)) {
562-
if (RS->hasResult() && shouldLogType(RS->getResult()->getType())) {
562+
if (RS->hasResult() && shouldLog(RS->getResult())) {
563563
std::pair<PatternBindingDecl *, VarDecl *> PV =
564564
buildPatternAndVariable(RS->getResult());
565565
DeclRefExpr *DRE = new (Context) DeclRefExpr(
@@ -621,7 +621,7 @@ class Instrumenter : InstrumenterBase {
621621
if (PL && Options.LogFunctionParameters) {
622622
size_t EI = 0;
623623
for (const auto &PD : *PL) {
624-
if (PD->hasName() && shouldLogType(PD->getInterfaceType())) {
624+
if (PD->hasName() && shouldLog(PD)) {
625625
DeclBaseName Name = PD->getName();
626626
Expr *PVVarRef = new (Context)
627627
DeclRefExpr(PD, DeclNameLoc(), /*implicit=*/true,
@@ -658,7 +658,7 @@ class Instrumenter : InstrumenterBase {
658658
// after or instead of the expression they're looking at. Only call this
659659
// if the variable has an initializer.
660660
Added<Stmt *> logVarDecl(VarDecl *VD) {
661-
if (!shouldLogType(VD->getInterfaceType())) {
661+
if (!shouldLog(VD)) {
662662
return nullptr;
663663
}
664664

@@ -678,7 +678,7 @@ class Instrumenter : InstrumenterBase {
678678
if (auto *DRE = dyn_cast<DeclRefExpr>(*RE)) {
679679
VarDecl *VD = cast<VarDecl>(DRE->getDecl());
680680

681-
if (!shouldLogType(VD->getInterfaceType())) {
681+
if (!shouldLog(VD)) {
682682
return nullptr;
683683
}
684684

@@ -694,9 +694,8 @@ class Instrumenter : InstrumenterBase {
694694
} else if (auto *MRE = dyn_cast<MemberRefExpr>(*RE)) {
695695
Expr *B = MRE->getBase();
696696
ConcreteDeclRef M = MRE->getMember();
697-
VarDecl *VD = cast<VarDecl>(M.getDecl());
698697

699-
if (!shouldLogType(VD->getInterfaceType())) {
698+
if (!shouldLog(M.getDecl())) {
700699
return nullptr;
701700
}
702701

@@ -799,11 +798,12 @@ class Instrumenter : InstrumenterBase {
799798
return std::make_pair(PBD, VD);
800799
}
801800

802-
bool shouldLogType(Type Ty) {
801+
bool shouldLog(ASTNode node) {
803802
// Don't try to log ~Copyable types, as we can't pass them to the generic logging functions yet.
804-
if (Ty->isNoncopyable()) {
805-
return false;
806-
}
803+
if (auto *VD = dyn_cast_or_null<ValueDecl>(node.dyn_cast<Decl *>()))
804+
return VD->hasInterfaceType() ? !VD->getInterfaceType()->isNoncopyable() : true;
805+
if (auto *E = node.dyn_cast<Expr *>())
806+
return !E->getType()->isNoncopyable();
807807
return true;
808808
}
809809

0 commit comments

Comments
 (0)