@@ -462,67 +462,6 @@ class ScopeCreator final {
462
462
return -1 == signum;
463
463
}
464
464
465
- public:
466
- // / For debugging. Return true if scope tree contains all the decl contexts in
467
- // / the AST May modify the scope tree in order to update obsolete scopes.
468
- // / Likely slow.
469
- bool containsAllDeclContextsFromAST () {
470
- auto allDeclContexts = findLocalizableDeclContextsInAST ();
471
- llvm::DenseMap<const DeclContext *, const ASTScopeImpl *> bogusDCs;
472
- sourceFileScope->preOrderDo ([&](ASTScopeImpl *scope) {
473
- scope->expandAndBeCurrentDetectingRecursion (*this );
474
- });
475
- sourceFileScope->postOrderDo ([&](ASTScopeImpl *scope) {
476
- if (auto *dc = scope->getDeclContext ().getPtrOrNull ()) {
477
- auto iter = allDeclContexts.find (dc);
478
- if (iter != allDeclContexts.end ())
479
- ++iter->second ;
480
- else
481
- bogusDCs.insert ({dc, scope});
482
- }
483
- });
484
-
485
- auto printDecl = [&](const Decl *d) {
486
- llvm::errs () << " \n getAsDecl() -> " << d << " " ;
487
- d->getSourceRange ().print (llvm::errs (), ctx.SourceMgr );
488
- llvm::errs () << " : " ;
489
- d->dump (llvm::errs ());
490
- llvm::errs () << " \n " ;
491
- };
492
- bool foundOmission = false ;
493
- for (const auto &p : allDeclContexts) {
494
- if (p.second == 0 ) {
495
- if (auto *d = p.first ->getAsDecl ()) {
496
- if (isLocalizable (d)) {
497
- llvm::errs () << " \n ASTScope tree omitted DeclContext: " << p.first
498
- << " "
499
- << " :\n " ;
500
- p.first ->printContext (llvm::errs ());
501
- printDecl (d);
502
- foundOmission = true ;
503
- }
504
- } else {
505
- // If no decl, no source range, so no scope
506
- }
507
- }
508
- }
509
- for (const auto &dcAndScope : bogusDCs) {
510
- llvm::errs () << " ASTScope tree confabulated: " << dcAndScope.getFirst ()
511
- << " :\n " ;
512
- dcAndScope.getFirst ()->printContext (llvm::errs ());
513
- if (auto *d = dcAndScope.getFirst ()->getAsDecl ())
514
- printDecl (d);
515
- dcAndScope.getSecond ()->print (llvm::errs (), 0 , false );
516
- }
517
- return !foundOmission && bogusDCs.empty ();
518
- }
519
-
520
- private:
521
- // / Return a map of every DeclContext in the AST, and zero in the 2nd element.
522
- // / For debugging.
523
- llvm::DenseMap<const DeclContext *, unsigned >
524
- findLocalizableDeclContextsInAST () const ;
525
-
526
465
public:
527
466
SWIFT_DEBUG_DUMP { print (llvm::errs ()); }
528
467
@@ -1535,75 +1474,6 @@ IterableTypeBodyPortion::insertionPointForDeferredExpansion(
1535
1474
1536
1475
#pragma mark verification
1537
1476
1538
- namespace {
1539
- class LocalizableDeclContextCollector : public ASTWalker {
1540
-
1541
- public:
1542
- llvm::DenseMap<const DeclContext *, unsigned > declContexts;
1543
-
1544
- void record (const DeclContext *dc) {
1545
- if (dc)
1546
- declContexts.insert ({dc, 0 });
1547
- }
1548
-
1549
- bool walkToDeclPre (Decl *D) override {
1550
- // catchForDebugging(D, "DictionaryBridging.swift", 694);
1551
- if (const auto *dc = dyn_cast<DeclContext>(D))
1552
- record (dc);
1553
- if (isa<IfConfigDecl>(D))
1554
- return false ;
1555
- if (auto *pd = dyn_cast<ParamDecl>(D))
1556
- record (pd->getDefaultArgumentInitContext ());
1557
- else if (auto *pbd = dyn_cast<PatternBindingDecl>(D))
1558
- recordInitializers (pbd);
1559
- else if (auto *vd = dyn_cast<VarDecl>(D)) {
1560
- vd->visitParsedAccessors ([&](AccessorDecl *ad) {
1561
- ad->walk (*this );
1562
- });
1563
- }
1564
- return ASTWalker::walkToDeclPre (D);
1565
- }
1566
-
1567
- std::pair<bool , Expr *> walkToExprPre (Expr *E) override {
1568
- if (const auto *ce = dyn_cast<ClosureExpr>(E))
1569
- record (ce);
1570
- return ASTWalker::walkToExprPre (E);
1571
- }
1572
-
1573
- private:
1574
- void recordInitializers (PatternBindingDecl *pbd) {
1575
- for (auto idx : range (pbd->getNumPatternEntries ()))
1576
- record (pbd->getInitContext (idx));
1577
- }
1578
-
1579
- void catchForDebugging (Decl *D, const char *file, const unsigned line) {
1580
- auto &SM = D->getASTContext ().SourceMgr ;
1581
- auto loc = D->getStartLoc ();
1582
- if (!loc.isValid ())
1583
- return ;
1584
- auto bufID = SM.findBufferContainingLoc (loc);
1585
- auto f = SM.getIdentifierForBuffer (bufID);
1586
- auto lin = SM.getLineAndColumnInBuffer (loc).first ;
1587
- if (f.endswith (file) && lin == line)
1588
- if (isa<PatternBindingDecl>(D))
1589
- llvm::errs () << " *** catchForDebugging: " << lin << " ***\n " ;
1590
- }
1591
- };
1592
- } // end namespace
1593
-
1594
- llvm::DenseMap<const DeclContext *, unsigned >
1595
- ScopeCreator::findLocalizableDeclContextsInAST () const {
1596
- LocalizableDeclContextCollector collector;
1597
- sourceFileScope->SF ->walk (collector);
1598
- // Walker omits the top
1599
- collector.record (sourceFileScope->SF );
1600
- return collector.declContexts ;
1601
- }
1602
-
1603
- bool ASTSourceFileScope::crossCheckWithAST () {
1604
- return scopeCreator->containsAllDeclContextsFromAST ();
1605
- }
1606
-
1607
1477
void ast_scope::simple_display (llvm::raw_ostream &out,
1608
1478
const ScopeCreator *scopeCreator) {
1609
1479
scopeCreator->print (out);
0 commit comments