@@ -1622,10 +1622,16 @@ namespace {
1622
1622
class PrintExpr : public ExprVisitor <PrintExpr> {
1623
1623
public:
1624
1624
raw_ostream &OS;
1625
+ llvm::function_ref<Type(const Expr *)> GetTypeOfExpr;
1626
+ llvm::function_ref<Type(const TypeLoc &)> GetTypeOfTypeLoc;
1625
1627
unsigned Indent;
1626
1628
1627
- PrintExpr (raw_ostream &os, unsigned indent) : OS(os), Indent(indent) {
1628
- }
1629
+ PrintExpr (raw_ostream &os,
1630
+ llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
1631
+ llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
1632
+ unsigned indent)
1633
+ : OS(os), GetTypeOfExpr(getTypeOfExpr),
1634
+ GetTypeOfTypeLoc (getTypeOfTypeLoc), Indent(indent) {}
1629
1635
1630
1636
void printRec (Expr *E) {
1631
1637
Indent += 2 ;
@@ -1669,15 +1675,15 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
1669
1675
1670
1676
if (E->isImplicit ())
1671
1677
PrintWithColorRAII (OS, ExprModifierColor) << " implicit" ;
1672
- PrintWithColorRAII (OS, TypeColor) << " type='" << E-> getType ( ) << ' \' ' ;
1678
+ PrintWithColorRAII (OS, TypeColor) << " type='" << GetTypeOfExpr (E ) << ' \' ' ;
1673
1679
1674
1680
if (E->hasLValueAccessKind ()) {
1675
1681
PrintWithColorRAII (OS, ExprModifierColor)
1676
1682
<< " accessKind=" << getAccessKindString (E->getLValueAccessKind ());
1677
1683
}
1678
1684
1679
1685
// If we have a source range and an ASTContext, print the source range.
1680
- if (auto Ty = E-> getType ( )) {
1686
+ if (auto Ty = GetTypeOfExpr (E )) {
1681
1687
auto &Ctx = Ty->getASTContext ();
1682
1688
auto L = E->getLoc ();
1683
1689
if (L.isValid ()) {
@@ -1719,7 +1725,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
1719
1725
if (E->isNegative ())
1720
1726
PrintWithColorRAII (OS, LiteralValueColor) << " negative" ;
1721
1727
PrintWithColorRAII (OS, LiteralValueColor) << " value=" ;
1722
- Type T = E-> getType ( );
1728
+ Type T = GetTypeOfExpr (E );
1723
1729
if (T.isNull () || !T->is <BuiltinIntegerType>())
1724
1730
PrintWithColorRAII (OS, LiteralValueColor) << E->getDigitsText ();
1725
1731
else
@@ -2345,7 +2351,7 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
2345
2351
if (auto checkedCast = dyn_cast<CheckedCastExpr>(E))
2346
2352
OS << getCheckedCastKindName (checkedCast->getCastKind ()) << ' ' ;
2347
2353
OS << " writtenType='" ;
2348
- E->getCastTypeLoc (). getType ( ).print (OS);
2354
+ GetTypeOfTypeLoc ( E->getCastTypeLoc ()).print (OS);
2349
2355
OS << " '\n " ;
2350
2356
printRec (E->getSubExpr ());
2351
2357
PrintWithColorRAII (OS, ParenthesisColor) << ' )' ;
@@ -2546,12 +2552,23 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
2546
2552
2547
2553
} // end anonymous namespace
2548
2554
2555
+ void Expr::dump (
2556
+ raw_ostream &OS, llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
2557
+ llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc) const {
2558
+ if (auto ty = getTypeOfExpr (this )) {
2559
+ llvm::SaveAndRestore<bool > X (
2560
+ ty->getASTContext ().LangOpts .DebugConstraintSolver , true );
2561
+ print (OS, getTypeOfExpr, getTypeOfTypeLoc);
2562
+ } else {
2563
+ print (OS, getTypeOfExpr, getTypeOfTypeLoc);
2564
+ }
2565
+ OS << ' \n ' ;
2566
+ }
2549
2567
2550
2568
void Expr::dump (raw_ostream &OS) const {
2551
2569
if (auto ty = getType ()) {
2552
2570
llvm::SaveAndRestore<bool > X (ty->getASTContext ().LangOpts .
2553
2571
DebugConstraintSolver, true );
2554
-
2555
2572
print (OS);
2556
2573
} else {
2557
2574
print (OS);
@@ -2563,8 +2580,26 @@ void Expr::dump() const {
2563
2580
dump (llvm::errs ());
2564
2581
}
2565
2582
2583
+ void Expr::dump (
2584
+ llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
2585
+ llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc) const {
2586
+ dump (llvm::errs (), getTypeOfExpr, getTypeOfTypeLoc);
2587
+ }
2588
+
2589
+ void Expr::print (raw_ostream &OS,
2590
+ llvm::function_ref<Type(const Expr *)> getTypeOfExpr,
2591
+ llvm::function_ref<Type(const TypeLoc &)> getTypeOfTypeLoc,
2592
+ unsigned Indent) const {
2593
+ PrintExpr (OS, getTypeOfExpr, getTypeOfTypeLoc, Indent)
2594
+ .visit (const_cast <Expr *>(this ));
2595
+ }
2596
+
2566
2597
void Expr::print (raw_ostream &OS, unsigned Indent) const {
2567
- PrintExpr (OS, Indent).visit (const_cast <Expr*>(this ));
2598
+ auto getTypeOfExpr = [](const Expr *E) -> Type { return E->getType (); };
2599
+ auto getTypeOfTypeLoc = [](const TypeLoc &TL) -> Type {
2600
+ return TL.getType ();
2601
+ };
2602
+ print (OS, getTypeOfExpr, getTypeOfTypeLoc, Indent);
2568
2603
}
2569
2604
2570
2605
void Expr::print (ASTPrinter &Printer, const PrintOptions &Opts) const {
0 commit comments