-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathmacro_expand_other.swift
44 lines (29 loc) · 1.61 KB
/
macro_expand_other.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Expanding macros that are defined in terms of other macros.
// RUN: %empty-directory(%t)
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -parse-as-library -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift
// Diagnostics testing
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS
// Execution testing
// RUN: %target-build-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) %s -o %t/main -module-name MacroUser
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main | %FileCheck %s
// REQUIRES: swift_swift_parser, executable_test
@freestanding(expression) macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
@freestanding(expression) macro stringifySeven() -> (Int, String) = #stringify(7)
@freestanding(expression) macro recurse(_: Bool) = #externalMacro(module: "MacroDefinition", type: "RecursiveMacro")
@freestanding(expression) macro recurseThrough(_ value: Bool) = #recurse(value)
func testFreestandingExpansionOfOther() {
// CHECK: ---testFreestandingExpansionOfOther
print("---testFreestandingExpansionOfOther")
// CHECK-NEXT: (7, "7")
print(#stringifySeven)
#recurseThrough(false)
#if TEST_DIAGNOSTICS
#recurseThrough(true)
// expected-note@-1 {{in expansion of macro 'recurseThrough' here}}
#endif
}
@freestanding(expression)
macro myLineMacro() -> Int = #line
var thisLine = #myLineMacro
testFreestandingExpansionOfOther()