Skip to content

Commit 186c64b

Browse files
tausbnCopilot
andcommitted
Unified: Give accessors their own source ranges
Keep inherited property metadata at its original source while limiting each accessor declaration to its own keyword and optional body. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent dbfddab commit 186c64b

5 files changed

Lines changed: 36 additions & 34 deletions

File tree

‎unified/extractor/src/languages/swift/swift.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
405405
}
406406
None => None,
407407
};
408-
tree!(
408+
tree_spanning!(
409+
ctx,
410+
std::iter::once(spec).chain(body),
409411
(accessor_declaration
410412
modifier: {binding}
411413
modifier: {chained}

‎unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ sourceFile
9292

9393
---
9494

95-
top_level source="⟨body⟩\n}"
95+
top_level source="var p: Int {\n ⟨body⟩\n}"
9696
body:
9797
block source="⟨stmt⟩"
9898
stmt:
99-
accessor_declaration source="⟨modifier⟩ ⟨name_node⟩: ⟨type⟩ {\n ⟨accessor_kind⟩ ⟨body⟩"
100-
modifier: modifier "var" source="var"
101-
name_node: identifier "p" source="p"
99+
accessor_declaration source="⟨accessor_kind⟩ ⟨body⟩"
100+
modifier: modifier "var" source="var" (external)
101+
name_node: identifier "p" source="p" (external)
102102
accessor_kind: accessor_kind "get" source="get"
103-
type: identifier "Int" source="Int"
103+
type: identifier "Int" source="Int" (external)
104104
body:
105105
block source="{\n ⟨stmt⟩\n }"
106106
stmt:

‎unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ top_level source="⟨body⟩"
106106
body:
107107
block source="⟨stmt⟩"
108108
stmt:
109-
class_like_declaration source="⟨modifier⟩ ⟨name_node⟩ {\n ⟨member⟩\n ⟨member⟩⟨member⟩\n }\n}"
109+
class_like_declaration source="⟨modifier⟩ ⟨name_node⟩ {\n ⟨member⟩\n var v: Int {\n ⟨member⟩\n ⟨member⟩\n }\n}"
110110
modifier: modifier "class" source="class"
111111
name_node: identifier "Box" source="Box"
112112
member:
@@ -116,23 +116,23 @@ top_level source="⟨body⟩"
116116
modifier "private" source="private"
117117
pattern: identifier "_v" source="_v"
118118
value: int_literal "0" source="0"
119-
accessor_declaration source="⟨modifier⟩ ⟨name_node⟩: ⟨type⟩ {\n ⟨accessor_kind⟩ ⟨body⟩"
120-
modifier: modifier "var" source="var"
121-
name_node: identifier "v" source="v"
119+
accessor_declaration source="⟨accessor_kind⟩ ⟨body⟩"
120+
modifier: modifier "var" source="var" (external)
121+
name_node: identifier "v" source="v" (external)
122122
accessor_kind: accessor_kind "get" source="get"
123-
type: identifier "Int" source="Int"
123+
type: identifier "Int" source="Int" (external)
124124
body:
125125
block source="{ ⟨stmt⟩ }"
126126
stmt:
127127
return_expr source="return ⟨value⟩"
128128
value: identifier "_v" source="_v"
129-
accessor_declaration source="⟨modifier⟩ ⟨name_node⟩: ⟨type⟩ {\n get { return _v }\n ⟨accessor_kind⟩ ⟨body⟩"
129+
accessor_declaration source="⟨accessor_kind⟩ ⟨body⟩"
130130
modifier:
131-
modifier "var" source="var"
131+
modifier "var" source="var" (external)
132132
modifier "chained_declaration" source=""
133-
name_node: identifier "v" source="v"
133+
name_node: identifier "v" source="v" (external)
134134
accessor_kind: accessor_kind "set" source="set"
135-
type: identifier "Int" source="Int"
135+
type: identifier "Int" source="Int" (external)
136136
body:
137137
block source="{ ⟨stmt⟩ }"
138138
stmt:

‎unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,24 @@ top_level source="⟨body⟩"
106106
body:
107107
block source="⟨stmt⟩"
108108
stmt:
109-
class_like_declaration source="⟨modifier⟩ ⟨name_node⟩ {\n var ⟨member⟩ }\n var ⟨member⟩⟨member⟩ }\n var ⟨member⟩ }\n}"
109+
class_like_declaration source="⟨modifier⟩ ⟨name_node⟩ {\n var foo: Int { ⟨member⟩ }\n var bar: String { ⟨member⟩ ⟨member⟩ }\n var count: Int { ⟨member⟩ }\n}"
110110
modifier: modifier "protocol" source="protocol"
111111
name_node: identifier "P" source="P"
112112
member:
113-
accessor_declaration source="⟨name_node⟩: ⟨type⟩ { ⟨accessor_kind⟩"
114-
name_node: identifier "foo" source="foo"
113+
accessor_declaration source="⟨accessor_kind⟩"
114+
name_node: identifier "foo" source="foo" (external)
115115
accessor_kind: accessor_kind "get" source="get"
116-
type: identifier "Int" source="Int"
117-
accessor_declaration source="⟨name_node⟩: ⟨type⟩ { ⟨accessor_kind⟩"
118-
name_node: identifier "bar" source="bar"
116+
type: identifier "Int" source="Int" (external)
117+
accessor_declaration source="⟨accessor_kind⟩"
118+
name_node: identifier "bar" source="bar" (external)
119119
accessor_kind: accessor_kind "get" source="get"
120-
type: identifier "String" source="String"
121-
accessor_declaration source="⟨name_node⟩: ⟨type⟩ { get ⟨accessor_kind⟩"
120+
type: identifier "String" source="String" (external)
121+
accessor_declaration source="⟨accessor_kind⟩"
122122
modifier: modifier "chained_declaration" source=""
123-
name_node: identifier "bar" source="bar"
123+
name_node: identifier "bar" source="bar" (external)
124124
accessor_kind: accessor_kind "set" source="set"
125-
type: identifier "String" source="String"
126-
accessor_declaration source="⟨name_node⟩: ⟨type⟩ { ⟨accessor_kind⟩"
127-
name_node: identifier "count" source="count"
125+
type: identifier "String" source="String" (external)
126+
accessor_declaration source="⟨accessor_kind⟩"
127+
name_node: identifier "count" source="count" (external)
128128
accessor_kind: accessor_kind "get" source="get"
129-
type: identifier "Int" source="Int"
129+
type: identifier "Int" source="Int" (external)

‎unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ top_level source="⟨body⟩"
110110
pattern: identifier "x" source="x"
111111
type: identifier "Int" source="Int"
112112
value: int_literal "0" source="0"
113-
accessor_declaration source="⟨modifier⟩ ⟨name_node⟩: Int = 0 {\n ⟨accessor_kind⟩ ⟨body⟩"
113+
accessor_declaration source="⟨accessor_kind⟩ ⟨body⟩"
114114
modifier:
115-
modifier "var" source="var"
115+
modifier "var" source="var" (external)
116116
modifier "chained_declaration" source=""
117-
name_node: identifier "x" source="x"
117+
name_node: identifier "x" source="x" (external)
118118
accessor_kind: accessor_kind "willSet" source="willSet"
119119
body:
120120
block source="{ ⟨stmt⟩ }"
@@ -124,11 +124,11 @@ top_level source="⟨body⟩"
124124
argument:
125125
argument source="⟨value⟩"
126126
value: identifier "newValue" source="newValue"
127-
accessor_declaration source="⟨modifier⟩ ⟨name_node⟩: Int = 0 {\n willSet { print(newValue) }\n ⟨accessor_kind⟩ ⟨body⟩"
127+
accessor_declaration source="⟨accessor_kind⟩ ⟨body⟩"
128128
modifier:
129-
modifier "var" source="var"
129+
modifier "var" source="var" (external)
130130
modifier "chained_declaration" source=""
131-
name_node: identifier "x" source="x"
131+
name_node: identifier "x" source="x" (external)
132132
accessor_kind: accessor_kind "didSet" source="didSet"
133133
body:
134134
block source="{ ⟨stmt⟩ }"

0 commit comments

Comments
 (0)