@@ -59,6 +59,8 @@ class ParsedRawSyntaxNode {
59
59
ParsedRawSyntaxNode &operator =(const ParsedRawSyntaxNode &other) = delete ;
60
60
61
61
public:
62
+ // MARK: - Constructors
63
+
62
64
ParsedRawSyntaxNode ()
63
65
: Data(nullptr , DataKind::Null), Range(),
64
66
SynKind (uint16_t (syntax::SyntaxKind::Unknown)),
@@ -73,17 +75,6 @@ class ParsedRawSyntaxNode {
73
75
assert (getTokenKind () == TokKind && " Token kind with too large value!" );
74
76
}
75
77
76
- #ifndef NDEBUG
77
- bool ensureDataIsNotRecorded () {
78
- if (getDataKind () != DataKind::Recorded)
79
- return true ;
80
- llvm::dbgs () << " Leaking node: " ;
81
- dump (llvm::dbgs ());
82
- llvm::dbgs () << " \n " ;
83
- return false ;
84
- }
85
- #endif
86
-
87
78
ParsedRawSyntaxNode &operator =(ParsedRawSyntaxNode &&other) {
88
79
assert (ensureDataIsNotRecorded () &&
89
80
" recorded data is being destroyed by assignment" );
@@ -95,17 +86,36 @@ class ParsedRawSyntaxNode {
95
86
other.reset ();
96
87
return *this ;
97
88
}
89
+
98
90
ParsedRawSyntaxNode (ParsedRawSyntaxNode &&other) : ParsedRawSyntaxNode() {
99
91
*this = std::move (other);
100
92
}
93
+
94
+ static ParsedRawSyntaxNode null () {
95
+ return ParsedRawSyntaxNode{};
96
+ }
97
+
101
98
~ParsedRawSyntaxNode () {
102
99
assert (ensureDataIsNotRecorded () && " recorded data is being destructed" );
103
100
}
104
101
102
+ // MARK: - Retrieving node kind
103
+
105
104
// / Returns the type of this node (recorded, deferred layout, deferred token,
106
105
// / null).
107
106
DataKind getDataKind () const { return Data.getKind (); }
108
107
108
+ bool isNull () const { return getDataKind () == DataKind::Null; }
109
+ bool isRecorded () const { return getDataKind () == DataKind::Recorded; }
110
+ bool isDeferredLayout () const {
111
+ return getDataKind () == DataKind::DeferredLayout;
112
+ }
113
+ bool isDeferredToken () const {
114
+ return getDataKind () == DataKind::DeferredToken;
115
+ }
116
+
117
+ // MARK: - Retrieving opaque data
118
+
109
119
// / Returns the opaque data of this node, assuming that it is deferred. This
110
120
// / must be interpreted by the \c SyntaxParseAction, which likely also needs
111
121
// / the node type (layout or token) to interpret the data.
@@ -116,19 +126,21 @@ class ParsedRawSyntaxNode {
116
126
return Data.getOpaque ();
117
127
}
118
128
119
- RecordedOrDeferredNode takeRecordedOrDeferredNode () {
120
- RecordedOrDeferredNode Data = this ->Data ;
129
+ // / Return the opaque data of this node and reset it.
130
+ OpaqueSyntaxNode takeData () {
131
+ OpaqueSyntaxNode Data = this ->Data .getOpaque ();
121
132
reset ();
122
133
return Data;
123
134
}
124
135
125
- // / Return the opaque data of this node and reset it.
126
- OpaqueSyntaxNode takeData () {
127
- OpaqueSyntaxNode Data = this ->Data .getOpaque ();
136
+ RecordedOrDeferredNode takeRecordedOrDeferredNode () {
137
+ RecordedOrDeferredNode Data = this ->Data ;
128
138
reset ();
129
139
return Data;
130
140
}
131
141
142
+ // MARK: - Retrieving additional node info
143
+
132
144
syntax::SyntaxKind getKind () const { return syntax::SyntaxKind (SynKind); }
133
145
tok getTokenKind () const { return tok (TokKind); }
134
146
@@ -138,25 +150,31 @@ class ParsedRawSyntaxNode {
138
150
bool isToken (tok tokKind) const {
139
151
return getTokenKind () == tokKind;
140
152
}
153
+ bool isMissing () const { return IsMissing; }
141
154
142
- bool isNull () const { return getDataKind () == DataKind::Null; }
155
+ // / Returns the range of this node including leading and trailing trivia.
156
+ CharSourceRange getRange () const { return Range; }
143
157
144
- bool isRecorded () const { return getDataKind () == DataKind::Recorded; }
145
- bool isDeferredLayout () const {
146
- return getDataKind () == DataKind::DeferredLayout;
147
- }
148
- bool isDeferredToken () const {
149
- return getDataKind () == DataKind::DeferredToken;
150
- }
158
+ size_t
159
+ getDeferredNumChildren (const SyntaxParsingContext *SyntaxContext) const ;
151
160
152
- // / Primary used for a deferred missing token.
153
- bool isMissing () const { return IsMissing; }
161
+ // / If this node is a deferred layout node, return the child at index \p
162
+ // / ChildIndex.
163
+ // / Note that this may be an expensive operation since the \c
164
+ // / SyntaxParseAction, which created the node (implicitly passed via the
165
+ // / \p SyntaxContext) needs to be consulted to retrieve the child.
166
+ ParsedRawSyntaxNode
167
+ getDeferredChild (size_t ChildIndex,
168
+ const SyntaxParsingContext *SyntaxContext) const ;
169
+
170
+ // MARK: - Miscellaneous
154
171
155
172
void reset () {
156
173
Data = RecordedOrDeferredNode (nullptr , DataKind::Null);
157
174
SynKind = uint16_t (syntax::SyntaxKind::Unknown);
158
175
TokKind = uint16_t (tok::unknown);
159
176
IsMissing = false ;
177
+ Range = CharSourceRange ();
160
178
}
161
179
162
180
ParsedRawSyntaxNode unsafeCopy () const {
@@ -169,23 +187,6 @@ class ParsedRawSyntaxNode {
169
187
return copy;
170
188
}
171
189
172
- // / Returns the range of this node including leading and trailing trivia.
173
- CharSourceRange getRange () const { return Range; }
174
-
175
- // Deferred Layout Data ====================================================//
176
-
177
- // / If this node is a deferred layout node, return the child at index \p
178
- // / ChildIndex.
179
- // / Note that this may be an expensive operation since the \c
180
- // / SyntaxParseAction, which created the node (implicitly passed via the
181
- // / \p SyntaxContext) needs to be consulted to retrieve the child.
182
- ParsedRawSyntaxNode
183
- getDeferredChild (size_t ChildIndex,
184
- const SyntaxParsingContext *SyntaxContext) const ;
185
-
186
- size_t
187
- getDeferredNumChildren (const SyntaxParsingContext *SyntaxContext) const ;
188
-
189
190
ParsedRawSyntaxNode copyDeferred () const {
190
191
assert (isDeferredLayout () || isDeferredToken () && " node not deferred" );
191
192
ParsedRawSyntaxNode copy;
@@ -197,7 +198,18 @@ class ParsedRawSyntaxNode {
197
198
return copy;
198
199
}
199
200
200
- // ==========================================================================//
201
+ #ifndef NDEBUG
202
+ bool ensureDataIsNotRecorded () {
203
+ if (getDataKind () != DataKind::Recorded)
204
+ return true ;
205
+ llvm::dbgs () << " Leaking node: " ;
206
+ dump (llvm::dbgs ());
207
+ llvm::dbgs () << " \n " ;
208
+ return false ;
209
+ }
210
+ #endif
211
+
212
+ // MARK: - Printing
201
213
202
214
// / Dump this piece of syntax recursively for debugging or testing.
203
215
SWIFT_DEBUG_DUMP;
@@ -206,10 +218,6 @@ class ParsedRawSyntaxNode {
206
218
// / method is also able to traverse its children and dump them.
207
219
void dump (raw_ostream &OS, const SyntaxParsingContext *Context = nullptr ,
208
220
unsigned Indent = 0 ) const ;
209
-
210
- static ParsedRawSyntaxNode null () {
211
- return ParsedRawSyntaxNode{};
212
- }
213
221
};
214
222
215
223
} // end namespace swift
0 commit comments