Skip to content

Commit e85c26f

Browse files
committed
---
yaml --- r: 345515 b: refs/heads/master c: 3bf55b6 h: refs/heads/master i: 345513: 251fade 345511: a4b743a
1 parent 8d613a5 commit e85c26f

File tree

12 files changed

+125
-47
lines changed

12 files changed

+125
-47
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: 1e297836a88f8023f422869c76be8723eb74a0c5
2+
refs/heads/master: 3bf55b62eb37822597dd1e70712d97819ed62b9c
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/include/swift/IDE/Utils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,16 @@ getCallArgInfo(SourceManager &SM, Expr *Arg, LabelRangeEndAt EndKind);
608608
std::vector<CharSourceRange>
609609
getCallArgLabelRanges(SourceManager &SM, Expr *Arg, LabelRangeEndAt EndKind);
610610

611+
/// Whether a decl is defined from clang source.
612+
bool isFromClang(const Decl *D);
613+
614+
/// Retrieve the effective Clang node for the given declaration, which
615+
/// copes with the odd case of imported Error enums.
616+
ClangNode getEffectiveClangNode(const Decl *decl);
617+
618+
/// Retrieve the Clang node for the given extension, if it has one.
619+
ClangNode extensionGetClangNode(const ExtensionDecl *ext);
620+
611621
} // namespace ide
612622
} // namespace swift
613623

trunk/lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -220,50 +220,10 @@ swift::ide::collectModuleGroups(ModuleDecl *M, std::vector<StringRef> &Scratch)
220220
return llvm::makeArrayRef(Scratch);
221221
}
222222

223-
/// Retrieve the effective Clang node for the given declaration, which
224-
/// copes with the odd case of imported Error enums.
225-
static ClangNode getEffectiveClangNode(const Decl *decl) {
226-
// Directly...
227-
if (auto clangNode = decl->getClangNode())
228-
return clangNode;
229-
230-
// Or via the nested "Code" enum.
231-
if (auto nominal =
232-
const_cast<NominalTypeDecl *>(dyn_cast<NominalTypeDecl>(decl))) {
233-
auto &ctx = nominal->getASTContext();
234-
auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>();
235-
flags |= NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
236-
for (auto code : nominal->lookupDirect(ctx.Id_Code, flags)) {
237-
if (auto clangDecl = code->getClangDecl())
238-
return clangDecl;
239-
}
240-
}
241-
242-
return ClangNode();
243-
}
244-
245-
/// Retrieve the Clang node for the given extension, if it has one.
246-
static ClangNode extensionGetClangNode(ExtensionDecl *ext) {
247-
// If it has a Clang node (directly),
248-
if (ext->hasClangNode()) return ext->getClangNode();
249-
250-
// Check whether it was syntheszed into a module-scope context.
251-
if (!isa<ClangModuleUnit>(ext->getModuleScopeContext()))
252-
return ClangNode();
253-
254-
// It may have a global imported as a member.
255-
for (auto member : ext->getMembers()) {
256-
if (auto clangNode = getEffectiveClangNode(member))
257-
return clangNode;
258-
}
259-
260-
return ClangNode();
261-
}
262-
263223
/// Determine whether the given extension has a Clang node that
264224
/// created it (vs. being a Swift extension).
265225
static bool extensionHasClangNode(ExtensionDecl *ext) {
266-
return static_cast<bool>(extensionGetClangNode(ext));
226+
return static_cast<bool>(swift::ide::extensionGetClangNode(ext));
267227
}
268228

269229
Optional<StringRef>
@@ -822,7 +782,7 @@ void ClangCommentPrinter::printDeclPre(const Decl *D,
822782
// single line.
823783
// FIXME: we should fix that, since it also affects struct members, etc.
824784
if (!isa<ParamDecl>(D)) {
825-
if (auto ClangN = getEffectiveClangNode(D)) {
785+
if (auto ClangN = swift::ide::getEffectiveClangNode(D)) {
826786
printCommentsUntil(ClangN);
827787
if (shouldPrintNewLineBefore(ClangN)) {
828788
*this << "\n";
@@ -846,7 +806,7 @@ void ClangCommentPrinter::printDeclPost(const Decl *D,
846806
*this << " " << ASTPrinter::sanitizeUtf8(CommentText);
847807
}
848808
PendingComments.clear();
849-
if (auto ClangN = getEffectiveClangNode(D))
809+
if (auto ClangN = swift::ide::getEffectiveClangNode(D))
850810
updateLastEntityLine(ClangN.getSourceRange().getEnd());
851811
}
852812

trunk/lib/IDE/Utils.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,3 +950,49 @@ accept(SourceManager &SM, RegionType RegionType,
950950
Impl.accept(SM, Replacement.Range, Replacement.Text);
951951
}
952952
}
953+
954+
bool swift::ide::isFromClang(const Decl *D) {
955+
if (getEffectiveClangNode(D))
956+
return true;
957+
if (auto *Ext = dyn_cast<ExtensionDecl>(D))
958+
return static_cast<bool>(extensionGetClangNode(Ext));
959+
return false;
960+
}
961+
962+
ClangNode swift::ide::getEffectiveClangNode(const Decl *decl) {
963+
// Directly...
964+
if (auto clangNode = decl->getClangNode())
965+
return clangNode;
966+
967+
// Or via the nested "Code" enum.
968+
if (auto nominal =
969+
const_cast<NominalTypeDecl *>(dyn_cast<NominalTypeDecl>(decl))) {
970+
auto &ctx = nominal->getASTContext();
971+
auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>();
972+
flags |= NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
973+
for (auto code : nominal->lookupDirect(ctx.Id_Code, flags)) {
974+
if (auto clangDecl = code->getClangDecl())
975+
return clangDecl;
976+
}
977+
}
978+
979+
return ClangNode();
980+
}
981+
982+
/// Retrieve the Clang node for the given extension, if it has one.
983+
ClangNode swift::ide::extensionGetClangNode(const ExtensionDecl *ext) {
984+
// If it has a Clang node (directly),
985+
if (ext->hasClangNode()) return ext->getClangNode();
986+
987+
// Check whether it was syntheszed into a module-scope context.
988+
if (!isa<ClangModuleUnit>(ext->getModuleScopeContext()))
989+
return ClangNode();
990+
991+
// It may have a global imported as a member.
992+
for (auto member : ext->getMembers()) {
993+
if (auto clangNode = getEffectiveClangNode(member))
994+
return clangNode;
995+
}
996+
997+
return ClangNode();
998+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Name: APINotesTest
2+
Globals:
3+
- Name: ANTGlobalValue
4+
SwiftName: NewType.newMember
5+
Protocols:
6+
- Name: TypeWithMethod
7+
SwiftName: SwiftTypeWithMethodRight
8+
9+
SwiftVersions:
10+
- Version: 3
11+
Typedefs:
12+
- Name: AnimalAttributeName
13+
SwiftName: AnimalAttributeName
14+
SwiftWrapper: none
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#import <objc_generics.h>
2+
extern int ANTGlobalValue;
3+
4+
@interface NewType
5+
@end
6+
@interface OldType
7+
@end
8+
9+
@protocol TypeWithMethod
10+
-(void) minusPrint;
11+
+(void) plusPrint;
12+
@property int PropertyA;
13+
@end
14+
15+
@protocol ObjcProt
16+
-(void) ProtMemberFunc;
17+
@end
18+
19+
typedef NSString * AnimalAttributeName NS_STRING_ENUM;
20+
21+
@interface AnimalStatusDescriptor
22+
- (nonnull AnimalStatusDescriptor *)animalStatusDescriptorByAddingAttributes:(nonnull NSDictionary<AnimalAttributeName, id> *)attributes;
23+
- (nonnull AnimalStatusDescriptor *)animalStatusDescriptorByAddingOptionalAttributes:(nullable NSDictionary<AnimalAttributeName, id> *)attributes;
24+
- (nonnull AnimalStatusDescriptor *)animalStatusDescriptorByAddingAttributesArray:(nonnull NSArray<AnimalAttributeName> *)attributes;
25+
- (nonnull AnimalStatusDescriptor *)animalStatusDescriptorByAddingOptionalAttributesArray:(nullable NSArray<AnimalAttributeName> *)attributes;
26+
+ (nonnull AnimalStatusDescriptor *)animalStatusSingleOptionalAttribute:(nullable AnimalAttributeName)attributes;
27+
+ (nonnull AnimalStatusDescriptor *)animalStatusSingleAttribute:(nonnull AnimalAttributeName)attributes;
28+
@end
29+
30+
extern AnimalAttributeName globalAttributeName;
31+
32+
typedef NSString * CatAttributeName NS_STRING_ENUM;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module cake {
2+
header "Cake.h"
3+
}

trunk/test/api-digester/Inputs/cake.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@_exported import cake
2+
13
public protocol P1 {}
24
public protocol P2 {}
35

trunk/test/api-digester/dump-module.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// RUN: %empty-directory(%t.mod)
22
// RUN: %empty-directory(%t.sdk)
33
// RUN: %empty-directory(%t.module-cache)
4-
// RUN: %swift -emit-module -o %t.mod/cake.swiftmodule %S/Inputs/cake.swift -parse-as-library
5-
// RUN: %api-digester -dump-sdk -module cake -o %t.dump.json -module-cache-path %t.module-cache -sdk %t.sdk -I %t.mod
4+
// RUN: %swift -emit-module -o %t.mod/cake.swiftmodule %S/Inputs/cake.swift -parse-as-library -I %S/Inputs/ClangCake %clang-importer-sdk-nosource
5+
// RUN: %api-digester -dump-sdk -module cake -o %t.dump.json -module-cache-path %t.module-cache -swift-only -I %t.mod -I %S/Inputs/ClangCake %clang-importer-sdk-nosource
66
// RUN: diff -u %S/Outputs/cake.json %t.dump.json
7-
// RUN: %api-digester -dump-sdk -module cake -o %t.dump.json -module-cache-path %t.module-cache -sdk %t.sdk -I %t.mod -abi
7+
// RUN: %api-digester -dump-sdk -module cake -o %t.dump.json -module-cache-path %t.module-cache -swift-only -I %t.mod -abi -I %S/Inputs/ClangCake %clang-importer-sdk-nosource
88
// RUN: diff -u %S/Outputs/cake-abi.json %t.dump.json
99
// RUN: %api-digester -diagnose-sdk --input-paths %t.dump.json -input-paths %S/Outputs/cake.json
1010

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,10 @@ SwiftDeclCollector::constructInitNode(ConstructorDecl *CD) {
12611261

12621262
bool swift::ide::api::
12631263
SDKContext::shouldIgnore(Decl *D, const Decl* Parent) const {
1264+
// Exclude all clang nodes if we're comparing Swift decls specifically.
1265+
if (Opts.SwiftOnly && isFromClang(D)) {
1266+
return true;
1267+
}
12641268
if (checkingABI()) {
12651269
if (auto *VD = dyn_cast<ValueDecl>(D)) {
12661270
// Private vars with fixed binary orders can have ABI-impact, so we should

trunk/tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ struct CheckerOptions {
142142
bool Verbose;
143143
bool AbortOnModuleLoadFailure;
144144
bool PrintModule;
145+
bool SwiftOnly;
145146
StringRef LocationFilter;
146147
};
147148

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ Verbose("v", llvm::cl::desc("Verbose"));
9999
static llvm::cl::opt<bool>
100100
Abi("abi", llvm::cl::desc("Dumping ABI interface"), llvm::cl::init(false));
101101

102+
static llvm::cl::opt<bool>
103+
SwiftOnly("swift-only",
104+
llvm::cl::desc("Only include APIs defined from Swift source"),
105+
llvm::cl::init(false));
106+
102107
static llvm::cl::opt<bool>
103108
PrintModule("print-module", llvm::cl::desc("Print module names in diagnostics"));
104109

@@ -2288,6 +2293,7 @@ static CheckerOptions getCheckOpts() {
22882293
Opts.AbortOnModuleLoadFailure = options::AbortOnModuleLoadFailure;
22892294
Opts.LocationFilter = options::LocationFilter;
22902295
Opts.PrintModule = options::PrintModule;
2296+
Opts.SwiftOnly = options::SwiftOnly;
22912297
return Opts;
22922298
}
22932299

0 commit comments

Comments
 (0)