|
21 | 21 | #include "Symbol.h"
|
22 | 22 | #include "SymbolGraph.h"
|
23 | 23 | #include "SymbolGraphASTWalker.h"
|
| 24 | +#include "DeclarationFragmentPrinter.h" |
24 | 25 |
|
25 | 26 | using namespace swift;
|
26 | 27 | using namespace symbolgraphgen;
|
@@ -518,6 +519,33 @@ Symbol::getPathComponents(SmallVectorImpl<PathComponent> &Components) const {
|
518 | 519 | std::reverse(Components.begin(), Components.end());
|
519 | 520 | }
|
520 | 521 |
|
| 522 | +void Symbol:: |
| 523 | +getFragmentInfo(SmallVectorImpl<FragmentInfo> &FragmentInfos) const { |
| 524 | + SmallPtrSet<const Decl*, 8> Referenced; |
| 525 | + |
| 526 | + auto Options = Graph->getDeclarationFragmentsPrintOptions(); |
| 527 | + if (getBaseType()) { |
| 528 | + Options.setBaseType(getBaseType()); |
| 529 | + Options.PrintAsMember = true; |
| 530 | + } |
| 531 | + |
| 532 | + llvm::json::OStream OS(llvm::nulls()); |
| 533 | + OS.object([&]{ |
| 534 | + DeclarationFragmentPrinter Printer(Graph, OS, {"ignored"}, &Referenced); |
| 535 | + getSymbolDecl()->print(Printer, Options); |
| 536 | + }); |
| 537 | + |
| 538 | + for (auto *D: Referenced) { |
| 539 | + if (!Symbol::supportsKind(D->getKind())) |
| 540 | + continue; |
| 541 | + if (auto *VD = dyn_cast<ValueDecl>(D)) { |
| 542 | + FragmentInfos.push_back(FragmentInfo{VD, {}}); |
| 543 | + Symbol RefSym(Graph, VD, nullptr); |
| 544 | + RefSym.getPathComponents(FragmentInfos.back().ParentContexts); |
| 545 | + } |
| 546 | + } |
| 547 | +} |
| 548 | + |
521 | 549 | void Symbol::printPath(llvm::raw_ostream &OS) const {
|
522 | 550 | SmallVector<PathComponent, 8> Components;
|
523 | 551 | getPathComponents(Components);
|
|
0 commit comments