Skip to content

Commit 1485fe5

Browse files
committed
[SourceKit] Add print and dump methods for cursor info results
We will be using the string serialized results to verify that solver-based cursor info results match the old implementation. This is necessary because cursor info results on their own contain stack references that cannot be stored.
1 parent b6e9a1d commit 1485fe5

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,15 @@ struct RefactoringInfo {
386386

387387
RefactoringInfo(UIdent Kind, StringRef KindName, StringRef UnavailableReason)
388388
: Kind(Kind), KindName(KindName), UnavailableReason(UnavailableReason) {}
389+
390+
void print(llvm::raw_ostream &OS, std::string Indentation) const {
391+
OS << Indentation << "RefactoringInfo" << '\n';
392+
OS << Indentation << " Kind: " << Kind.getName() << '\n';
393+
OS << Indentation << " KindName: " << KindName << '\n';
394+
OS << Indentation << " UnavailableReason: " << UnavailableReason << '\n';
395+
}
396+
397+
SWIFT_DEBUG_DUMP { print(llvm::errs(), ""); }
389398
};
390399

391400
struct ParentInfo {
@@ -395,6 +404,15 @@ struct ParentInfo {
395404

396405
ParentInfo(StringRef Title, StringRef KindName, StringRef USR)
397406
: Title(Title), KindName(KindName), USR(USR) {}
407+
408+
void print(llvm::raw_ostream &OS, std::string Indentation) const {
409+
OS << Indentation << "ParentInfo" << '\n';
410+
OS << Indentation << " Title: " << Title << '\n';
411+
OS << Indentation << " KindName: " << KindName << '\n';
412+
OS << Indentation << " USR: " << USR << '\n';
413+
}
414+
415+
SWIFT_DEBUG_DUMP { print(llvm::errs(), ""); }
398416
};
399417

400418
struct ReferencedDeclInfo {
@@ -413,6 +431,24 @@ struct ReferencedDeclInfo {
413431
: USR(USR), DeclarationLang(DeclLang), AccessLevel(AccessLevel),
414432
FilePath(FilePath), ModuleName(ModuleName), IsSystem(System),
415433
IsSPI(SPI), ParentContexts(Parents) {}
434+
435+
void print(llvm::raw_ostream &OS, std::string Indentation) const {
436+
OS << Indentation << "ReferencedDeclInfo" << '\n';
437+
OS << Indentation << " USR: " << USR << '\n';
438+
OS << Indentation << " DeclarationLang: " << DeclarationLang.getName()
439+
<< '\n';
440+
OS << Indentation << " AccessLevel: " << AccessLevel << '\n';
441+
OS << Indentation << " FilePath: " << FilePath << '\n';
442+
OS << Indentation << " ModuleName: " << ModuleName << '\n';
443+
OS << Indentation << " IsSystem: " << IsSystem << '\n';
444+
OS << Indentation << " IsSPI: " << IsSPI << '\n';
445+
OS << Indentation << " ParentContexts:" << '\n';
446+
for (auto ParentCtx : ParentContexts) {
447+
ParentCtx.print(OS, Indentation + " ");
448+
}
449+
}
450+
451+
SWIFT_DEBUG_DUMP { print(llvm::errs(), ""); }
416452
};
417453

418454
struct LocationInfo {
@@ -421,6 +457,17 @@ struct LocationInfo {
421457
unsigned Length = 0;
422458
unsigned Line = 0;
423459
unsigned Column = 0;
460+
461+
void print(llvm::raw_ostream &OS, std::string Indentation) const {
462+
OS << Indentation << "LocationInfo" << '\n';
463+
OS << Indentation << " Filename: " << Filename << '\n';
464+
OS << Indentation << " Offset: " << Offset << '\n';
465+
OS << Indentation << " Length: " << Length << '\n';
466+
OS << Indentation << " Line: " << Line << '\n';
467+
OS << Indentation << " Column: " << Column << '\n';
468+
}
469+
470+
SWIFT_DEBUG_DUMP { print(llvm::errs(), ""); }
424471
};
425472

426473
struct CursorSymbolInfo {
@@ -470,6 +517,60 @@ struct CursorSymbolInfo {
470517
bool IsSynthesized = false;
471518

472519
llvm::Optional<unsigned> ParentNameOffset;
520+
521+
void print(llvm::raw_ostream &OS, std::string Indentation) const {
522+
OS << Indentation << "CursorSymbolInfo" << '\n';
523+
OS << Indentation << " Kind: " << Kind.getName() << '\n';
524+
OS << Indentation << " DeclarationLang: " << DeclarationLang.getName()
525+
<< '\n';
526+
OS << Indentation << " Name: " << Name << '\n';
527+
OS << Indentation << " USR: " << USR << '\n';
528+
OS << Indentation << " TypeName: " << TypeName << '\n';
529+
OS << Indentation << " TypeUSR: " << TypeUSR << '\n';
530+
OS << Indentation << " ContainerTypeUSR: " << ContainerTypeUSR << '\n';
531+
OS << Indentation << " DocComment: " << DocComment << '\n';
532+
OS << Indentation << " GroupName: " << GroupName << '\n';
533+
OS << Indentation << " LocalizationKey: " << LocalizationKey << '\n';
534+
OS << Indentation << " AnnotatedDeclaration: " << AnnotatedDeclaration
535+
<< '\n';
536+
OS << Indentation
537+
<< " FullyAnnotatedDeclaration: " << FullyAnnotatedDeclaration << '\n';
538+
OS << Indentation << " SymbolGraph: " << SymbolGraph << '\n';
539+
OS << Indentation << " ModuleName: " << ModuleName << '\n';
540+
OS << Indentation << " ModuleInterfaceName: " << ModuleInterfaceName
541+
<< '\n';
542+
Location.print(OS, Indentation + " ");
543+
OS << Indentation << " OverrideUSRs:" << '\n';
544+
for (auto OverrideUSR : OverrideUSRs) {
545+
OS << Indentation << " " << OverrideUSR << '\n';
546+
}
547+
OS << Indentation << " AnnotatedRelatedDeclarations:" << '\n';
548+
for (auto AnnotatedRelatedDeclaration : AnnotatedRelatedDeclarations) {
549+
OS << Indentation << " " << AnnotatedRelatedDeclaration << '\n';
550+
}
551+
OS << Indentation << " ModuleGroupArray:" << '\n';
552+
for (auto ModuleGroup : ModuleGroupArray) {
553+
OS << Indentation << " " << ModuleGroup << '\n';
554+
}
555+
OS << Indentation << " ParentContexts:" << '\n';
556+
for (auto ParentContext : ParentContexts) {
557+
ParentContext.print(OS, Indentation + " ");
558+
}
559+
OS << Indentation << "ReferencedSymbols:" << '\n';
560+
for (auto ReferencedSymbol : ReferencedSymbols) {
561+
ReferencedSymbol.print(OS, Indentation + " ");
562+
}
563+
OS << Indentation << "ReceiverUSRs:" << '\n';
564+
for (auto ReceiverUSR : ReceiverUSRs) {
565+
OS << Indentation << " " << ReceiverUSR << '\n';
566+
}
567+
OS << Indentation << "IsSystem: " << IsSystem << '\n';
568+
OS << Indentation << "IsDynamic: " << IsDynamic << '\n';
569+
OS << Indentation << "IsSynthesized: " << IsSynthesized << '\n';
570+
OS << Indentation << "ParentNameOffset: " << ParentNameOffset << '\n';
571+
}
572+
573+
SWIFT_DEBUG_DUMP { print(llvm::errs(), ""); }
473574
};
474575

475576
struct CursorInfoData {
@@ -480,6 +581,20 @@ struct CursorInfoData {
480581
llvm::ArrayRef<CursorSymbolInfo> Symbols;
481582
/// All available actions on the code under cursor.
482583
llvm::ArrayRef<RefactoringInfo> AvailableActions;
584+
585+
void print(llvm::raw_ostream &OS, std::string Indentation) const {
586+
OS << Indentation << "CursorInfoData" << '\n';
587+
OS << Indentation << " Symbols:" << '\n';
588+
for (auto Symbol : Symbols) {
589+
Symbol.print(OS, Indentation + " ");
590+
}
591+
OS << Indentation << " AvailableActions:" << '\n';
592+
for (auto AvailableAction : AvailableActions) {
593+
AvailableAction.print(OS, Indentation + " ");
594+
}
595+
}
596+
597+
SWIFT_DEBUG_DUMP { print(llvm::errs(), ""); }
483598
};
484599

485600
/// The result type of `LangSupport::getDiagnostics`

0 commit comments

Comments
 (0)