Skip to content

Commit 784116a

Browse files
committed
swift-api-digester: simplify some code. NFC
1 parent b2c4375 commit 784116a

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,11 @@ class SDKNode {
383383
void removeChild(ChildIt CI) { Children.erase(CI); }
384384
ChildIt getChildBegin() { return Children.begin(); }
385385
void annotate(NodeAnnotation Anno) { Annotations.insert(Anno); }
386+
void annotate(NodeAnnotation Anno, StringRef Comment);
386387
NodePtr getParent() const { return Parent; };
387388
unsigned getChildrenCount() const { return Children.size(); }
388389
NodePtr childAt(unsigned I) const;
389390
void removeChild(NodePtr C);
390-
void addAnnotateComment(NodeAnnotation Anno, StringRef Comment);
391391
StringRef getAnnotateComment(NodeAnnotation Anno) const;
392392
bool isAnnotatedAs(NodeAnnotation Anno) const;
393393
void addChild(SDKNode *Child);
@@ -603,8 +603,9 @@ void SDKNode::removeChild(NodePtr C) {
603603
Children.erase(std::find(Children.begin(), Children.end(), C));
604604
}
605605

606-
void SDKNode::addAnnotateComment(NodeAnnotation Anno, StringRef Comment) {
607-
assert(isAnnotatedAs(Anno) && "Cannot find annotation");
606+
void SDKNode::annotate(NodeAnnotation Anno, StringRef Comment) {
607+
assert(!isAnnotatedAs(Anno) && "already annotated");
608+
annotate(Anno);
608609
AnnotateComments[Anno] = Comment;
609610
}
610611

@@ -1974,8 +1975,7 @@ class RemovedAddedNodeMatcher : public NodeMatcher, public MatchedNodeListener {
19741975
} else {
19751976
return false;
19761977
}
1977-
R->annotate(NodeAnnotation::PropertyName);
1978-
R->addAnnotateComment(NodeAnnotation::PropertyName, A->getPrintedName());
1978+
R->annotate(NodeAnnotation::PropertyName, A->getPrintedName());
19791979
foundMatch(R, A);
19801980
return true;
19811981
}
@@ -2012,11 +2012,10 @@ class RemovedAddedNodeMatcher : public NodeMatcher, public MatchedNodeListener {
20122012
if (auto VC = dyn_cast<SDKNodeVar>(Child)) {
20132013
auto LastPartOfA = getLastPartOfUsr(VC);
20142014
if (LastPartOfA && LastPartOfR.getValue() == LastPartOfA.getValue()) {
2015-
R->annotate(NodeAnnotation::ModernizeEnum);
20162015
std::string FullName = (llvm::Twine(A->getName()) + "." +
20172016
Child->getName()).str();
2018-
R->addAnnotateComment(NodeAnnotation::ModernizeEnum,
2019-
R->getSDKContext().buffer(FullName));
2017+
R->annotate(NodeAnnotation::ModernizeEnum,
2018+
R->getSDKContext().buffer(FullName));
20202019
foundMatch(R, A);
20212020
return true;
20222021
}
@@ -2321,10 +2320,8 @@ static void detectRename(NodePtr L, NodePtr R) {
23212320
assert(L->getKind() == R->getKind());
23222321
if (isa<SDKNodeDecl>(L) && L->getPrintedName() != R->getPrintedName()) {
23232322
L->annotate(NodeAnnotation::Rename);
2324-
L->annotate(NodeAnnotation::RenameOldName);
2325-
L->addAnnotateComment(NodeAnnotation::RenameOldName, L->getPrintedName());
2326-
L->annotate(NodeAnnotation::RenameNewName);
2327-
L->addAnnotateComment(NodeAnnotation::RenameNewName, R->getPrintedName());
2323+
L->annotate(NodeAnnotation::RenameOldName, L->getPrintedName());
2324+
L->annotate(NodeAnnotation::RenameNewName, R->getPrintedName());
23282325
}
23292326
}
23302327

@@ -2494,12 +2491,10 @@ class TypeMemberDiffFinder : public SDKNodeVisitor {
24942491
diffNode->getKind() == SDKNodeKind::Function &&
24952492
node->isNameValid()) {
24962493
diffNode->annotate(NodeAnnotation::Rename);
2497-
diffNode->annotate(NodeAnnotation::RenameOldName);
2498-
diffNode->addAnnotateComment(NodeAnnotation::RenameOldName,
2499-
diffNode->getPrintedName());
2500-
diffNode->annotate(NodeAnnotation::RenameNewName);
2501-
diffNode->addAnnotateComment(NodeAnnotation::RenameNewName,
2502-
node->getParent()->getPrintedName());
2494+
diffNode->annotate(NodeAnnotation::RenameOldName,
2495+
diffNode->getPrintedName());
2496+
diffNode->annotate(NodeAnnotation::RenameNewName,
2497+
node->getParent()->getPrintedName());
25032498
}
25042499
}
25052500

@@ -2604,12 +2599,9 @@ class ChangeRefinementPass : public SDKTreeDiffPass, public SDKNodeVisitor {
26042599
(Node->getName() != Counter->getName()||
26052600
Node->getChildrenCount() != Counter->getChildrenCount())) {
26062601
Node->annotate(NodeAnnotation::TypeRewritten);
2607-
Node->annotate(NodeAnnotation::TypeRewrittenLeft);
2608-
Node->annotate(NodeAnnotation::TypeRewrittenRight);
2609-
Node->addAnnotateComment(NodeAnnotation::TypeRewrittenLeft,
2610-
Node->getPrintedName());
2611-
Node->addAnnotateComment(NodeAnnotation::TypeRewrittenRight,
2612-
Counter->getPrintedName());
2602+
Node->annotate(NodeAnnotation::TypeRewrittenLeft, Node->getPrintedName());
2603+
Node->annotate(NodeAnnotation::TypeRewrittenRight,
2604+
Counter->getPrintedName());
26132605
return true;
26142606
}
26152607
return false;
@@ -2638,9 +2630,8 @@ class ChangeRefinementPass : public SDKTreeDiffPass, public SDKNodeVisitor {
26382630
if (auto DT = dyn_cast<SDKNodeTypeDecl>(Results.front())) {
26392631
if (DT->isConformingTo(KnownProtocolKind::RawRepresentable)) {
26402632
L->annotate(NodeAnnotation::DictionaryKeyUpdate);
2641-
L->annotate(NodeAnnotation::TypeRewrittenRight);
2642-
L->addAnnotateComment(NodeAnnotation::TypeRewrittenRight,
2643-
DT->getFullyQualifiedName());
2633+
L->annotate(NodeAnnotation::TypeRewrittenRight,
2634+
DT->getFullyQualifiedName());
26442635
return true;
26452636
}
26462637
}

0 commit comments

Comments
 (0)