Skip to content

Commit 2419c2e

Browse files
committed
---
yaml --- r: 348963 b: refs/heads/master c: ba6891d h: refs/heads/master i: 348961: b167af3 348959: 4b99b7c
1 parent f0b0e66 commit 2419c2e

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: adb9e1d42c368006839db2a8f9fd864337410ca0
2+
refs/heads/master: ba6891d7c8704e4a32fc85c716e5f5707d6f3599
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/Serialization/SerializeDoc.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -298,41 +298,48 @@ static void writeGroupNames(const comment_block::GroupNamesLayout &GroupNames,
298298
GroupNames.emit(Scratch, BlobStream.str());
299299
}
300300

301-
static bool shouldIncludeDecl(Decl *D) {
302-
if (auto *VD = dyn_cast<ValueDecl>(D)) {
303-
// Skip the decl if it's not visible to clients. The use of
304-
// getEffectiveAccess is unusual here; we want to take the testability
305-
// state into account and emit documentation if and only if they are
306-
// visible to clients (which means public ordinarily, but
307-
// public+internal when testing enabled).
308-
if (VD->getEffectiveAccess() < swift::AccessLevel::Public)
309-
return false;
310-
}
301+
static bool hasDoubleUnderscore(Decl *D) {
311302
// Exclude decls with double-underscored names, either in arguments or
312303
// base names.
313-
StringRef Prefix = "__";
314-
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
315-
return shouldIncludeDecl(ED->getExtendedNominal());
316-
}
304+
static StringRef Prefix = "__";
317305

318306
if (auto AFD = dyn_cast<AbstractFunctionDecl>(D)) {
319307
// If it's a function with a parameter with leading double underscore,
320308
// it's a private function.
321309
if (AFD->getParameters()->hasInternalParameter(Prefix))
322-
return false;
310+
return true;
323311
}
324312

325313
if (auto SubscriptD = dyn_cast<SubscriptDecl>(D)) {
326314
if (SubscriptD->getIndices()->hasInternalParameter(Prefix))
327-
return false;
315+
return true;
328316
}
329317
if (auto *VD = dyn_cast<ValueDecl>(D)) {
330318
auto Name = VD->getBaseName();
331319
if (!Name.isSpecial() &&
332320
Name.getIdentifier().str().startswith(Prefix)) {
333-
return false;
321+
return true;
334322
}
335323
}
324+
return false;
325+
}
326+
327+
static bool shouldIncludeDecl(Decl *D, bool ExcludeDoubleUnderscore) {
328+
if (auto *VD = dyn_cast<ValueDecl>(D)) {
329+
// Skip the decl if it's not visible to clients. The use of
330+
// getEffectiveAccess is unusual here; we want to take the testability
331+
// state into account and emit documentation if and only if they are
332+
// visible to clients (which means public ordinarily, but
333+
// public+internal when testing enabled).
334+
if (VD->getEffectiveAccess() < swift::AccessLevel::Public)
335+
return false;
336+
}
337+
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
338+
return shouldIncludeDecl(ED->getExtendedNominal(), ExcludeDoubleUnderscore);
339+
}
340+
if (ExcludeDoubleUnderscore && hasDoubleUnderscore(D)) {
341+
return false;
342+
}
336343
return true;
337344
}
338345

@@ -393,7 +400,7 @@ static void writeDeclCommentTable(
393400
}
394401

395402
bool walkToDeclPre(Decl *D) override {
396-
if (!shouldIncludeDecl(D))
403+
if (!shouldIncludeDecl(D, /*ExcludeDoubleUnderscore*/true))
397404
return false;
398405
if (!shouldSerializeDoc(D))
399406
return true;
@@ -789,7 +796,10 @@ struct BasicDeclLocsTableWriter : public ASTWalker {
789796

790797
bool walkToDeclPre(Decl *D) override {
791798
// We shouldn't expose any Decls that .swiftdoc file isn't willing to expose.
792-
if (!shouldIncludeDecl(D))
799+
// .swiftdoc doesn't include comments for double underscored symbols, but for .swiftsourceinfo,
800+
// having the source location for these symbols isn't a concern becuase these
801+
// symbols are in .swiftinterface anyway.
802+
if (!shouldIncludeDecl(D, /*ExcludeDoubleUnderscore*/false))
793803
return false;
794804
if (!shouldSerializeSourceLoc(D))
795805
return true;

trunk/test/Serialization/comments-hidden.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
// RUN: %FileCheck %s -check-prefix=TESTING < %t.testing.txt
1515
// RUN: %FileCheck %s -check-prefix=TESTING-NEGATIVE < %t.testing.txt
1616

17+
// Test the case when we have .swiftsourceinfo
18+
//
19+
// RUN: %empty-directory(%t)
20+
// RUN: %target-swift-frontend -enable-testing -module-name comments -emit-module -emit-module-path %t/comments.swiftmodule -emit-module-doc -emit-module-doc-path %t/comments.swiftdoc -emit-module-source-info-path %t/comments.swiftsourceinfo %s
21+
// RUN: %target-swift-ide-test -print-module-comments -module-to-print=comments -source-filename %s -I %t > %t.testing.txt
22+
// RUN: %FileCheck %s -check-prefix=SOURCE-LOC < %t.testing.txt
23+
1724
/// PublicClass Documentation
1825
public class PublicClass {
1926
/// Public Function Documentation
@@ -73,4 +80,9 @@ private class PrivateClass {
7380
// TESTING: InternalClass Documentation
7481
// TESTING: Internal Function Documentation
7582

76-
83+
// SOURCE-LOC: comments-hidden.swift:37:15: Func/PublicClass.__UnderscoredPublic RawComment=none BriefComment=none DocCommentAsXML=none
84+
// SOURCE-LOC: comments-hidden.swift:39:10: Constructor/PublicClass.init RawComment=none BriefComment=none DocCommentAsXML=none
85+
// SOURCE-LOC: comments-hidden.swift:41:10: Subscript/PublicClass.subscript RawComment=none BriefComment=none DocCommentAsXML=none
86+
// SOURCE-LOC: comments-hidden.swift:43:10: Constructor/PublicClass.init RawComment=none BriefComment=none DocCommentAsXML=none
87+
// SOURCE-LOC: comments-hidden.swift:45:10: Subscript/PublicClass.subscript RawComment=none BriefComment=none DocCommentAsXML=none
88+
// SOURCE-LOC: comments-hidden.swift:50:15: Func/-= RawComment=none BriefComment=none DocCommentAsXML=none

0 commit comments

Comments
 (0)