File: extension.swift.gyb

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 (108 lines) | stat: -rw-r--r-- 5,759 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
97
98
99
100
101
102
103
104
105
106
107
108
// RUN: %empty-directory(%t)
// RUN: %gyb %s > %t/main.swift

// Other module is not resilient:
// RUN: %empty-directory(%t/types)
// RUN: %target-build-swift %S/Inputs/extension_types.swift -module-name ExtensionTypes -emit-module -emit-module-path %t/types/ExtensionTypes.swiftmodule
// This module is both not resilient:
// RUN: %target-swift-frontend -emit-ir -o%t/not_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift
// RUN: %target-swift-frontend -emit-ir -o%t/not_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -O
// ... and resilient:
// RUN: %target-swift-frontend -emit-ir -o%t/not_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-library-evolution
// RUN: %target-swift-frontend -emit-ir -o%t/not_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-library-evolution -O
// The same, but with -enable-testing:
// RUN: %target-swift-frontend -emit-ir -o%t/not_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-testing
// RUN: %target-swift-frontend -emit-ir -o%t/not_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-testing -O
// RUN: %target-swift-frontend -emit-ir -o%t/not_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-library-evolution -enable-testing
// RUN: %target-swift-frontend -emit-ir -o%t/not_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=all -I %t/types %t/main.swift -enable-library-evolution -enable-testing -O

// Other module is resilient:
// RUN: %empty-directory(%t/types)
// RUN: %target-build-swift %S/Inputs/extension_types.swift -module-name ExtensionTypes -emit-module -emit-module-path %t/types/ExtensionTypes.swiftmodule -enable-library-evolution
// This module is both not resilient:
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -O
// ... and resilient:
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-library-evolution
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-library-evolution -O
// The same but with -enable-testing:
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-testing
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_not.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-testing -O
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-library-evolution -enable-testing
// RUN: %target-swift-frontend -emit-ir -o%t/resilient_resilient.ll -parse-as-library -module-name test -validate-tbd-against-ir=missing -I %t/types %t/main.swift -enable-library-evolution -enable-testing -O


import ExtensionTypes

// This generates all combinations of a public/internal/private struct
// (plus a public one from another module) being extended to conform
// to a public/internal/private protocol (plus a public one from
// another module), both with and without inheritance/defaulting.

%{
local_decl_names = ["Public", "Internal", "Private"]
all_decl_names = ["Foreign"] + local_decl_names
decl_name_to_access = {
    "Foreign": "public",
    "Public": "public",
    "Internal": "internal",
    "Private": "fileprivate"
}
def conformanceBody(protocol):
    return """
    {access} func {name}Method() {{}}
    {access} var {name}Get: Int {{ return 0 }}
    {access} var {name}GetSet: Int {{
        get {{ return 0 }}
        set {{}}
    }}
    """.format(access = decl_name_to_access[protocol],
               name = protocol.lower())
}%

% for name in local_decl_names:
% access = name.lower()

${access} protocol Extension${name} {
    func ${access}Method()
    var ${access}Get: Int { get }
    var ${access}GetSet: Int { get set }
}

// Defaulted methods:
${access} protocol Extension${name}Inherit: ExtensionForeign {}
extension Extension${name}Inherit {
    ${conformanceBody(name)}
}

${access} struct ${name}Struct {}
${access} struct ${name}StructInherit {}
${access} struct ${name}StructInheritNoDefault {}
${access} struct ${name}StructOneExtension {}
% end

% for sname in all_decl_names:
% access = sname.lower()

% for pname in all_decl_names:
// e.g. extension PublicStruct: Private { ... }
extension ${sname}Struct: Extension${pname} {
    ${conformanceBody(pname)}
}

// e.g. extension PublicStructInherit: PrivateInherit {}
extension ${sname}StructInherit: Extension${pname}Inherit {}

// e.g. extension PublicStructInheritNoDefault: PrivateInherit { ... }
extension ${sname}StructInheritNoDefault: Extension${pname}Inherit {
    ${conformanceBody(pname)}
}
% end

// e.g. extension PublicStructOneExtension: ExtensionForeign, ExtensionPublic, ExtensionInternal, ExtensionPrivate { ... }
extension ${sname}StructOneExtension: ${", ".join("Extension" + p for p in all_decl_names)} {
% for pname in all_decl_names:
    ${conformanceBody(pname)}
% end
}
% end