swift-api-digester: if a removed declaration has been hoisted to a type member,

show this declaration as renamed instead of removed.
This commit is contained in:
Xi Ge
2018-04-03 13:25:19 -07:00
parent 95b7f502b8
commit 6ffad8085b
2 changed files with 22 additions and 3 deletions

View File

@@ -2681,6 +2681,8 @@ typedef std::vector<TypeMemberDiffItem> TypeMemberDiffVector;
} // end anonymous namespace
static void findTypeMemberDiffs(NodePtr leftSDKRoot, NodePtr rightSDKRoot,
TypeMemberDiffVector &out);
static void printNode(llvm::raw_ostream &os, NodePtr node) {
os << "{" << node->getName() << " " << node->getKind() << " "
@@ -3005,7 +3007,10 @@ class DiagnosisEmitter : public SDKNodeVisitor {
DiagBag<RemovedDeclDiag> RemovedDecls;
UpdatedNodesMap &UpdateMap;
DiagnosisEmitter(UpdatedNodesMap &UpdateMap) : UpdateMap(UpdateMap) {}
TypeMemberDiffVector &MemberChanges;
DiagnosisEmitter(UpdatedNodesMap &UpdateMap,
TypeMemberDiffVector &MemberChanges):
UpdateMap(UpdateMap), MemberChanges(MemberChanges) {}
public:
static void diagnosis(NodePtr LeftRoot, NodePtr RightRoot,
UpdatedNodesMap &UpdateMap);
@@ -3126,7 +3131,10 @@ void DiagnosisEmitter::DeclAttrDiag::output() const {
void DiagnosisEmitter::diagnosis(NodePtr LeftRoot, NodePtr RightRoot,
UpdatedNodesMap &UpdateMap) {
DiagnosisEmitter Emitter(UpdateMap);
// Find member hoist changes to help refine diagnostics.
TypeMemberDiffVector MemberChanges;
findTypeMemberDiffs(LeftRoot, RightRoot, MemberChanges);
DiagnosisEmitter Emitter(UpdateMap, MemberChanges);
collectAddedDecls(RightRoot, Emitter.AddedDecls);
SDKNode::postorderVisit(LeftRoot, Emitter);
}
@@ -3152,6 +3160,17 @@ void DiagnosisEmitter::handle(const SDKNodeDecl *Node, NodeAnnotation Anno) {
}
}
// If we can find a hoisted member for this removed delcaration, we
// emit the diagnostics as rename instead of removal.
auto It = std::find_if(MemberChanges.begin(), MemberChanges.end(),
[&](TypeMemberDiffItem &Item) { return Item.usr == Node->getUsr(); });
if (It != MemberChanges.end()) {
RenamedDecls.Diags.emplace_back(ScreenInfo, Node->getDeclKind(),
Node->getDeclKind(), Node->getFullyQualifiedName(),
Ctx.buffer((Twine(It->newTypeName) + "." + It->newPrintedName).str()));
return;
}
// We should exlude those declarations that are pulled up to the super classes.
bool FoundInSuperclass = false;
if (auto PD = dyn_cast<SDKNodeDecl>(Node->getParent())) {