Skip to content

Commit 0f75036

Browse files
authored
Merge pull request #5702 from nkcsgexi/digester-compare
2 parents 3682476 + f3a13e3 commit 0f75036

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

test/api-digester/Inputs/cake1.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ public struct S1 {
33
public func foo1() {}
44
mutating public func foo2() {}
55
public func foo3() {}
6+
public func foo4() -> Void {}
67
}
78

89
public class C1 {

test/api-digester/Inputs/cake2.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ public struct S1 {
33
mutating public func foo1() {}
44
mutating public func foo2() {}
55
public static func foo3() {}
6+
public func foo4() {}
67
}
78

89
public class C1 {

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class SDKNode {
335335
ArrayRef<NodeUniquePtr> getChildren() const;
336336
void collectChildren(NodeVector &Bucket) const;
337337
unsigned getChildIndex(NodePtr Child) const;
338-
NodePtr getOnlyChild() const;
338+
const SDKNode* getOnlyChild() const;
339339
template <typename T> const T *getAs() const;
340340
template <typename T> T *getAs();
341341
};
@@ -418,9 +418,14 @@ class SDKNodeTypeNameAlias : public SDKNodeType {
418418
public:
419419
SDKNodeTypeNameAlias(SDKNodeInitInfo Info) : SDKNodeType(Info,
420420
SDKNodeKind::TypeNameAlias) {}
421+
const SDKNodeType *getUnderlyingType() const;
421422
static bool classof(const SDKNode *N);
422423
};
423424

425+
const SDKNodeType *SDKNodeTypeNameAlias::getUnderlyingType() const {
426+
return getOnlyChild()->getAs<SDKNodeType>();
427+
}
428+
424429
template <typename T> const T *
425430
SDKNode::getAs() const {
426431
if (T::classof(this))
@@ -440,7 +445,7 @@ unsigned SDKNode::getChildIndex(NodePtr Child) const {
440445
[&](const NodeUniquePtr &P) { return P.get() == Child; }) - Children.begin();
441446
}
442447

443-
NodePtr SDKNode::getOnlyChild() const {
448+
const SDKNode* SDKNode::getOnlyChild() const {
444449
assert(Children.size() == 1 && "more that one child.");
445450
return (*Children.begin()).get();
446451
}
@@ -876,6 +881,15 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
876881
}
877882

878883
bool SDKNode::operator==(const SDKNode &Other) const {
884+
auto *LeftAlias = dyn_cast<SDKNodeTypeNameAlias>(this);
885+
auto *RightAlias = dyn_cast<SDKNodeTypeNameAlias>(&Other);
886+
if (LeftAlias || RightAlias) {
887+
// Comparing the underlying types if any of the inputs are alias.
888+
const SDKNode *Left = LeftAlias ? LeftAlias->getUnderlyingType() : this;
889+
const SDKNode *Right = RightAlias ? RightAlias->getUnderlyingType() : &Other;
890+
return *Left == *Right;
891+
}
892+
879893
if (getKind() != Other.getKind())
880894
return false;
881895

0 commit comments

Comments
 (0)