Skip to content

Commit e1dfdba

Browse files
committed
Add doc comments and tests for AST / SIL
1 parent 4b3ee94 commit e1dfdba

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

include/swift/AST/Module.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ class ModuleDecl
194194
current = clangModule;
195195
}
196196

197+
/// Returns the name of the current module.
198+
/// Note that for a Swift module, it returns the current module's real (binary) name,
199+
/// which can be different from the name if module aliasing was used (see -module-alias).
197200
StringRef operator*() const;
198201
ReverseFullNameIterator &operator++();
199202

test/Frontend/module-alias-ast.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// Test AST with module aliasing.
2+
///
3+
/// Module 'Lib' imports module 'XLogging', and 'XLogging' is aliased 'AppleLogging'.
4+
5+
// RUN: %empty-directory(%t)
6+
// RUN: %{python} %utils/split_file.py -o %t %s
7+
8+
/// Create AppleLogging.swiftmodule by aliasing XLogging
9+
// RUN: %target-swift-frontend -module-name AppleLogging -module-alias XLogging=AppleLogging %t/FileLogging.swift -emit-module -emit-module-path %t/AppleLogging.swiftmodule
10+
// RUN: test -f %t/AppleLogging.swiftmodule
11+
12+
/// Verify AST contains XLogging, not AppleLogging
13+
// RUN: %target-swift-frontend -dump-ast %t/FileLib.swift -module-alias XLogging=AppleLogging -I %t > %t/result-ast.output
14+
15+
// RUN: %FileCheck %s -input-file %t/result-ast.output -check-prefix CHECK-AST
16+
// CHECK-AST: XLogging
17+
// RUN: not %FileCheck %s -input-file %t/result-ast.output -check-prefix CHECK-NOT-AST
18+
// CHECK-NOT-AST: AppleLogging
19+
20+
21+
// BEGIN FileLogging.swift
22+
public struct Logger {
23+
public init() {}
24+
}
25+
public func setup() -> XLogging.Logger? {
26+
return Logger()
27+
}
28+
29+
// BEGIN FileLib.swift
30+
import XLogging
31+
32+
public func start() -> XLogging.Logger? {
33+
return XLogging.setup()
34+
}
35+
36+
public func end(_ arg: XLogging.Logger) {
37+
}

test/Frontend/module-alias-sil.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// Test SIL with module aliasing.
2+
///
3+
/// Module 'Lib' imports module 'XLogging', and 'XLogging' is aliased 'AppleLogging'.
4+
5+
// RUN: %empty-directory(%t)
6+
// RUN: %{python} %utils/split_file.py -o %t %s
7+
8+
/// Create AppleLogging.swiftmodule by aliasing XLogging
9+
// RUN: %target-swift-frontend -module-name AppleLogging -module-alias XLogging=AppleLogging %t/FileLogging.swift -emit-module -emit-module-path %t/AppleLogging.swiftmodule
10+
// RUN: test -f %t/AppleLogging.swiftmodule
11+
12+
/// Verify generated SIL contains AppleLogging, and XLogging only appears in import lines in the prologue
13+
// RUN: %target-swift-frontend -emit-sil %t/FileLib.swift -module-alias XLogging=AppleLogging -I %t > %t/result-sil.output
14+
// RUN: %FileCheck %s -input-file %t/result-sil.output -check-prefix CHECK-SIL
15+
// CHECK-SIL: import XLogging
16+
// CHECK-SIL: s12AppleLogging
17+
// RUN: not %FileCheck %s -input-file %t/result-sil.output -check-prefix CHECK-NOT-SIL
18+
// CHECK-NOT-SIL: s8XLogging
19+
20+
// BEGIN FileLogging.swift
21+
public struct Logger {
22+
public init() {}
23+
}
24+
public func setup() -> XLogging.Logger? {
25+
return Logger()
26+
}
27+
28+
// BEGIN FileLib.swift
29+
import XLogging
30+
31+
public func start() -> XLogging.Logger? {
32+
return XLogging.setup()
33+
}
34+
35+
public func end(_ arg: XLogging.Logger) {
36+
}

0 commit comments

Comments
 (0)