Skip to content

Commit a619ffb

Browse files
committed
Unified: Add conditional compilation tests
1 parent 81a1deb commit a619ffb

21 files changed

Lines changed: 1159 additions & 28 deletions
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#if DEBUG
2+
@available(*, deprecated)
3+
#endif
4+
func f() {}
5+
6+
#if DEBUG
7+
@available(*, deprecated)
8+
#endif
9+
let x = 1
10+
11+
---
12+
13+
sourceFile
14+
endOfFileToken: endOfFile
15+
statements:
16+
codeBlockItem
17+
item:
18+
functionDecl
19+
attributes:
20+
ifConfigDecl
21+
clauses:
22+
ifConfigClause
23+
elements:
24+
attribute
25+
leftParen: (
26+
rightParen: )
27+
arguments:
28+
availabilityArgument
29+
trailingComma: ,
30+
argument: binaryOperator "*"
31+
availabilityArgument
32+
argument: deprecated
33+
atSign: @
34+
attributeName:
35+
identifierType
36+
name: identifier "available"
37+
condition:
38+
declReferenceExpr
39+
baseName: identifier "DEBUG"
40+
poundKeyword: #if
41+
poundEndif: #endif
42+
body:
43+
codeBlock
44+
leftBrace: {
45+
rightBrace: }
46+
statements:
47+
name: identifier "f"
48+
modifiers:
49+
signature:
50+
functionSignature
51+
parameterClause:
52+
functionParameterClause
53+
leftParen: (
54+
rightParen: )
55+
parameters:
56+
funcKeyword: func
57+
codeBlockItem
58+
item:
59+
variableDecl
60+
attributes:
61+
ifConfigDecl
62+
clauses:
63+
ifConfigClause
64+
elements:
65+
attribute
66+
leftParen: (
67+
rightParen: )
68+
arguments:
69+
availabilityArgument
70+
trailingComma: ,
71+
argument: binaryOperator "*"
72+
availabilityArgument
73+
argument: deprecated
74+
atSign: @
75+
attributeName:
76+
identifierType
77+
name: identifier "available"
78+
condition:
79+
declReferenceExpr
80+
baseName: identifier "DEBUG"
81+
poundKeyword: #if
82+
poundEndif: #endif
83+
modifiers:
84+
bindingSpecifier: let
85+
bindings:
86+
patternBinding
87+
initializer:
88+
initializerClause
89+
equal: =
90+
value:
91+
integerLiteralExpr
92+
literal: integerLiteral "1"
93+
pattern:
94+
identifierPattern
95+
identifier: identifier "x"
96+
97+
---
98+
99+
top_level source="⟨body⟩"
100+
body:
101+
block source="⟨stmt⟩\n\n⟨stmt⟩"
102+
stmt:
103+
function_declaration source="#if DEBUG\n @available(*, deprecated)\n#endif\nfunc ⟨name_node⟩() ⟨body⟩"
104+
name_node: identifier "f" source="f"
105+
body: block "{}" source="{}"
106+
variable_declaration source="⟨modifier⟩\n⟨modifier⟩ ⟨pattern⟩ = ⟨value⟩"
107+
modifier:
108+
modifier "let" source="let"
109+
unsupported_node "#if DEBUG\n @available(*, deprecated)\n#endif" source="#if DEBUG\n @available(*, deprecated)\n#endif" <-- ERROR: The field variable_declaration.modifier should contain modifier, but got unsupported_node
110+
pattern: identifier "x" source="x"
111+
value: int_literal "1" source="1"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#if DEBUG
2+
@available(*, deprecated)
3+
#endif
4+
func f() {}
5+
6+
#if DEBUG
7+
@available(*, deprecated)
8+
#endif
9+
let x = 1

unified/extractor/tests/corpus/swift/types/conditional-compilation-in-class-body.output renamed to unified/extractor/tests/corpus/swift/conditional-compilation/conditional-compilation-in-class-body.output

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
// Conditional compilation is not yet supported: swift-syntax reports a
2-
// structured `ifConfigDecl` (whose branches hold ordinary member items), but
3-
// the mapping has no rule for it, so the whole block becomes one
4-
// `unsupported_node` and its members are not extracted.
1+
// Conditional compilation branches hold ordinary member declarations.
52
class C {
6-
#if DEBUG
7-
init(x: Int) {}
8-
deinit {}
9-
#endif
3+
#if DEBUG
4+
init(x: Int) {}
5+
deinit {}
6+
#endif
107
}
118

129
---
@@ -81,11 +78,11 @@ top_level source="⟨body⟩"
8178
body:
8279
block source="⟨stmt⟩"
8380
stmt:
84-
class_like_declaration source="⟨modifier⟩ ⟨name_node⟩ {\n⟨member⟩\n}"
81+
class_like_declaration source="⟨modifier⟩ ⟨name_node⟩ {\n ⟨member⟩\n}"
8582
modifier: modifier "class" source="class"
8683
name_node: identifier "C" source="C"
8784
member:
88-
unsupported_node "#if DEBUG\n init(x: Int) {}\n deinit {}\n#endif" source="#if DEBUG\n init(x: Int) {}\n deinit {}\n#endif"
85+
unsupported_node "#if DEBUG\n init(x: Int) {}\n deinit {}\n #endif" source="#if DEBUG\n init(x: Int) {}\n deinit {}\n #endif"
8986
constructor_declaration source=""
9087
modifier: modifier "generated" source=""
9188
name_node: identifier "init" source=""
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Conditional compilation branches hold ordinary member declarations.
2+
class C {
3+
#if DEBUG
4+
init(x: Int) {}
5+
deinit {}
6+
#endif
7+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
func f(_ x: Int) {
2+
switch x {
3+
#if DEBUG
4+
case 0: break
5+
case 1: break
6+
#endif
7+
default: break
8+
}
9+
}
10+
11+
---
12+
13+
sourceFile
14+
endOfFileToken: endOfFile
15+
statements:
16+
codeBlockItem
17+
item:
18+
functionDecl
19+
attributes:
20+
body:
21+
codeBlock
22+
leftBrace: {
23+
rightBrace: }
24+
statements:
25+
codeBlockItem
26+
item:
27+
expressionStmt
28+
expression:
29+
switchExpr
30+
leftBrace: {
31+
rightBrace: }
32+
cases:
33+
ifConfigDecl
34+
clauses:
35+
ifConfigClause
36+
elements:
37+
switchCase
38+
label:
39+
switchCaseLabel
40+
colon: :
41+
caseKeyword: case
42+
caseItems:
43+
switchCaseItem
44+
pattern:
45+
expressionPattern
46+
expression:
47+
integerLiteralExpr
48+
literal: integerLiteral "0"
49+
statements:
50+
codeBlockItem
51+
item:
52+
breakStmt
53+
breakKeyword: break
54+
switchCase
55+
label:
56+
switchCaseLabel
57+
colon: :
58+
caseKeyword: case
59+
caseItems:
60+
switchCaseItem
61+
pattern:
62+
expressionPattern
63+
expression:
64+
integerLiteralExpr
65+
literal: integerLiteral "1"
66+
statements:
67+
codeBlockItem
68+
item:
69+
breakStmt
70+
breakKeyword: break
71+
condition:
72+
declReferenceExpr
73+
baseName: identifier "DEBUG"
74+
poundKeyword: #if
75+
poundEndif: #endif
76+
switchCase
77+
label:
78+
switchDefaultLabel
79+
colon: :
80+
defaultKeyword: default
81+
statements:
82+
codeBlockItem
83+
item:
84+
breakStmt
85+
breakKeyword: break
86+
subject:
87+
declReferenceExpr
88+
baseName: identifier "x"
89+
switchKeyword: switch
90+
name: identifier "f"
91+
modifiers:
92+
signature:
93+
functionSignature
94+
parameterClause:
95+
functionParameterClause
96+
leftParen: (
97+
rightParen: )
98+
parameters:
99+
functionParameter
100+
colon: :
101+
attributes:
102+
modifiers:
103+
type:
104+
identifierType
105+
name: identifier "Int"
106+
firstName: _
107+
secondName: identifier "x"
108+
funcKeyword: func
109+
110+
---
111+
112+
top_level source="⟨body⟩"
113+
body:
114+
block source="⟨stmt⟩"
115+
stmt:
116+
function_declaration source="func ⟨name_node⟩(⟨parameter⟩) ⟨body⟩"
117+
name_node: identifier "f" source="f"
118+
parameter:
119+
parameter source="⟨external_name_node⟩ ⟨pattern⟩: ⟨type⟩"
120+
external_name_node: identifier "_" source="_"
121+
type: identifier "Int" source="Int"
122+
pattern: identifier "x" source="x"
123+
body:
124+
block source="{\n ⟨stmt⟩\n}"
125+
stmt:
126+
switch_expr source="switch ⟨value⟩ {\n ⟨case⟩\n ⟨case⟩\n }"
127+
value: identifier "x" source="x"
128+
case:
129+
unsupported_node "#if DEBUG\n case 0: break\n case 1: break\n #endif" source="#if DEBUG\n case 0: break\n case 1: break\n #endif" <-- ERROR: The field switch_expr.case should contain switch_case, but got unsupported_node
130+
switch_case source="default: ⟨body⟩"
131+
body:
132+
block source="⟨stmt⟩"
133+
stmt: break_expr "break" source="break"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
func f(_ x: Int) {
2+
switch x {
3+
#if DEBUG
4+
case 0: break
5+
case 1: break
6+
#endif
7+
default: break
8+
}
9+
}

0 commit comments

Comments
 (0)