File: complete_macros_expanded.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (96 lines) | stat: -rw-r--r-- 4,347 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// REQUIRES: swift_swift_parser

// RUN: %empty-directory(%t)
// RUN: mkdir -p %t/plugins

//##-- Prepare the macro plugin.
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/plugins/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/../Macros/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath

// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -plugin-path %t/plugins -parse-as-library 

@freestanding(declaration, names: named(A), named(B), named(foo), named(addOne))
macro defineDeclsWithKnownNames() = #externalMacro(module: "MacroDefinition", type: "DefineDeclsWithKnownNamesMacro")

@attached(peer, names: suffixed(_peer))
macro PeerWithSuffix() = #externalMacro(module: "MacroDefinition", type: "PeerValueWithSuffixNameMacro")

@attached(peer, names: arbitrary)
macro PeerWithSuffixAsArbitrary() = #externalMacro(module: "MacroDefinition", type: "PeerValueWithSuffixNameMacro")

@freestanding(declaration, names: arbitrary)
macro VarValueDecl() = #externalMacro(module: "MacroDefinition", type: "VarValueMacro")


#defineDeclsWithKnownNames

@PeerWithSuffix
func globalFunc() {}

func test() {
   #^GLOBAL^#
// GLOBAL-DAG: Decl[Struct]/CurrModule:            A[#A#]; name=A
// GLOBAL-DAG: Decl[Struct]/CurrModule:            B[#B#]; name=B
// GLOBAL-DAG: Decl[GlobalVar]/CurrModule:         foo[#Int#]; name=foo
// GLOBAL-DAG: Decl[GlobalVar]/CurrModule:         addOne[#(Int) -> Int#]; name=addOne
// GLOBAL-DAG: Decl[FreeFunction]/CurrModule:      globalFunc()[#Void#]; name=globalFunc()
// GLOBAL-DAG: Decl[GlobalVar]/CurrModule:         globalFunc_peer[#Int#]; name=globalFunc_peer
}

struct MyStruct {
  @PeerWithSuffix
  func instanceMethod() {}

  @PeerWithSuffix
  static func staticMethod() {}

  @PeerWithSuffixAsArbitrary
  func forArbitrary() {}

  #defineDeclsWithKnownNames

  #VarValueDecl
}

func testMemberInstance(value: MyStruct) {
  value.#^MEMBER_INSTANCE^#
// MEMBER_INSTANCE-DAG: Keyword[self]/CurrNominal:          self[#MyStruct#]; name=self
// MEMBER_INSTANCE-DAG: Decl[InstanceMethod]/CurrNominal:   instanceMethod()[#Void#]; name=instanceMethod()
// MEMBER_INSTANCE-DAG: Decl[InstanceVar]/CurrNominal:      instanceMethod_peer[#Int#]; name=instanceMethod_peer
// MEMBER_INSTANCE-DAG: Decl[InstanceVar]/CurrNominal:      staticMethod_peer[#Int#]; name=staticMethod_peer
// MEMBER_INSTANCE-DAG: Decl[InstanceMethod]/CurrNominal:   forArbitrary()[#Void#]; name=forArbitrary()
// MEMBER_INSTANCE-DAG: Decl[InstanceVar]/CurrNominal:      forArbitrary_peer[#Int#]; name=forArbitrary_peer
// MEMBER_INSTANCE-DAG: Decl[InstanceVar]/CurrNominal:      foo[#Int#]; name=foo
// MEMBER_INSTANCE-DAG: Decl[InstanceVar]/CurrNominal:      addOne[#(Int) -> Int#]; name=addOne
// MEMBER_INSTANCE-DAG: Decl[InstanceVar]/CurrNominal:      value[#Int#]; name=value
// NOTE: 'staticMethod_peer' is a instance var because the macro emits the decl without 'static'
}

func testMemberStatic() {
  MyStruct.#^MEMBER_STATIC^#
// MEMBER_STATIC-NOT: _peer
// MEMBER_STATIC-DAG: Keyword[self]/CurrNominal:          self[#MyStruct.Type#]; name=self
// MEMBER_STATIC-DAG: Keyword/CurrNominal:                Type[#MyStruct.Type#]; name=Type
// MEMBER_STATIC-DAG: Decl[Struct]/CurrNominal:           A[#MyStruct.A#]; name=A
// MEMBER_STATIC-DAG: Decl[Struct]/CurrNominal:           B[#MyStruct.B#]; name=B
// MEMBER_STATIC-DAG: Decl[InstanceMethod]/CurrNominal:   instanceMethod({#(self): MyStruct#})[#() -> Void#]; name=instanceMethod(:)
// MEMBER_STATIC-DAG: Decl[StaticMethod]/CurrNominal:     staticMethod()[#Void#]; name=staticMethod()
// MEMBER_STATIC-NOT: _peer
}

func testLocal() {
  #defineDeclsWithKnownNames

  @PeerWithSuffix func localFunc() {}

  do {
    #^LOCAL?check=LOCAL;check=LOCAL_MACRO^#
// LOCAL-DAG:       Decl[FreeFunction]/Local: localFunc()[#Void#]; name=localFunc()

// Local macros cannot introduce peer decls, so make sure they don't show up.
// LOCAL_MACRO-NOT: Decl[LocalVar]/Local: localFunc_peer[#Int#]; name=localFunc_peer
// LOCAL_MACRO-NOT: Decl[Struct]/Local:   A[#A#]; name=A
// LOCAL_MACRO-NOT: Decl[Struct]/Local:   B[#B#]; name=B
// LOCAL_MACRO-NOT: Decl[LocalVar]/Local: foo[#Int#]; name=foo
// LOCAL_MACRO-NOT: Decl[LocalVar]/Local: addOne[#(Int) -> Int#]; name=addOne
  }
}