@@ -87,24 +87,24 @@ class MacroMatchFragment : public MacroMatch
87
87
{
88
88
Identifier ident;
89
89
MacroFragSpec frag_spec;
90
-
91
- // TODO: should store location information?
90
+ Location locus;
92
91
93
92
public:
94
- MacroMatchFragment (Identifier ident, MacroFragSpec frag_spec)
95
- : ident (std::move (ident)), frag_spec (frag_spec)
93
+ MacroMatchFragment (Identifier ident, MacroFragSpec frag_spec, Location locus )
94
+ : ident (std::move (ident)), frag_spec (frag_spec), locus (locus)
96
95
{}
97
96
98
97
// Returns whether macro match fragment is in an error state.
99
98
bool is_error () const { return frag_spec == INVALID; }
100
99
101
100
// Creates an error state macro match fragment.
102
- static MacroMatchFragment create_error ()
101
+ static MacroMatchFragment create_error (Location locus )
103
102
{
104
- return MacroMatchFragment (std::string (" " ), INVALID);
103
+ return MacroMatchFragment (std::string (" " ), INVALID, locus );
105
104
}
106
105
107
106
std::string as_string () const override ;
107
+ Location get_match_locus () const override { return locus; };
108
108
109
109
void accept_vis (ASTVisitor &vis) override ;
110
110
@@ -137,20 +137,22 @@ class MacroMatchRepetition : public MacroMatch
137
137
typedef Token MacroRepSep;
138
138
// any token except delimiters and repetition operators
139
139
std::unique_ptr<MacroRepSep> sep;
140
-
141
- // TODO: should store location information?
140
+ Location locus;
142
141
143
142
public:
144
143
// Returns whether macro match repetition has separator token.
145
144
bool has_sep () const { return sep != nullptr ; }
146
145
147
146
MacroMatchRepetition (std::vector<std::unique_ptr<MacroMatch> > matches,
148
- MacroRepOp op, std::unique_ptr<MacroRepSep> sep)
149
- : matches (std::move (matches)), op (op), sep (std::move (sep))
147
+ MacroRepOp op, std::unique_ptr<MacroRepSep> sep,
148
+ Location locus)
149
+ : matches (std::move (matches)), op (op), sep (std::move (sep)),
150
+ locus (locus)
150
151
{}
151
152
152
153
// Copy constructor with clone
153
- MacroMatchRepetition (MacroMatchRepetition const &other) : op (other.op)
154
+ MacroMatchRepetition (MacroMatchRepetition const &other)
155
+ : op (other.op), locus (other.locus)
154
156
{
155
157
// guard to protect from null pointer dereference
156
158
if (other.sep != nullptr )
@@ -165,6 +167,7 @@ class MacroMatchRepetition : public MacroMatch
165
167
MacroMatchRepetition &operator = (MacroMatchRepetition const &other)
166
168
{
167
169
op = other.op ;
170
+ locus = other.locus ;
168
171
169
172
// guard to protect from null pointer dereference
170
173
if (other.sep != nullptr )
@@ -184,6 +187,7 @@ class MacroMatchRepetition : public MacroMatch
184
187
MacroMatchRepetition &operator = (MacroMatchRepetition &&other) = default ;
185
188
186
189
std::string as_string () const override ;
190
+ Location get_match_locus () const override { return locus; };
187
191
188
192
void accept_vis (ASTVisitor &vis) override ;
189
193
@@ -201,20 +205,22 @@ class MacroMatcher : public MacroMatch
201
205
{
202
206
DelimType delim_type;
203
207
std::vector<std::unique_ptr<MacroMatch> > matches;
208
+ Location locus;
204
209
205
210
// TODO: think of way to mark invalid that doesn't take up more space
206
211
bool is_invalid;
207
212
208
- // TODO: should store location information?
209
-
210
213
public:
211
214
MacroMatcher (DelimType delim_type,
212
- std::vector<std::unique_ptr<MacroMatch> > matches)
213
- : delim_type (delim_type), matches (std::move (matches)), is_invalid (false )
215
+ std::vector<std::unique_ptr<MacroMatch> > matches,
216
+ Location locus)
217
+ : delim_type (delim_type), matches (std::move (matches)), locus (locus),
218
+ is_invalid (false )
214
219
{}
215
220
216
221
// copy constructor with vector clone
217
- MacroMatcher (MacroMatcher const &other) : delim_type (other.delim_type)
222
+ MacroMatcher (MacroMatcher const &other)
223
+ : delim_type (other.delim_type), locus (other.locus)
218
224
{
219
225
matches.reserve (other.matches .size ());
220
226
for (const auto &e : other.matches )
@@ -225,6 +231,7 @@ class MacroMatcher : public MacroMatch
225
231
MacroMatcher &operator = (MacroMatcher const &other)
226
232
{
227
233
delim_type = other.delim_type ;
234
+ locus = other.locus ;
228
235
229
236
matches.reserve (other.matches .size ());
230
237
for (const auto &e : other.matches )
@@ -238,10 +245,14 @@ class MacroMatcher : public MacroMatch
238
245
MacroMatcher &operator = (MacroMatcher &&other) = default ;
239
246
240
247
// Creates an error state macro matcher.
241
- static MacroMatcher create_error () { return MacroMatcher (true ); }
248
+ static MacroMatcher create_error (Location locus)
249
+ {
250
+ return MacroMatcher (true , locus);
251
+ }
242
252
243
253
// Returns whether MacroMatcher is in an error state.
244
254
bool is_error () const { return is_invalid; }
255
+ Location get_match_locus () const override { return locus; }
245
256
246
257
std::string as_string () const override ;
247
258
@@ -256,7 +267,8 @@ class MacroMatcher : public MacroMatch
256
267
}
257
268
258
269
// constructor only used to create error matcher
259
- MacroMatcher (bool is_invalid) : delim_type (PARENS), is_invalid (is_invalid)
270
+ MacroMatcher (bool is_invalid, Location locus)
271
+ : delim_type (PARENS), locus (locus), is_invalid (is_invalid)
260
272
{}
261
273
};
262
274
@@ -296,7 +308,8 @@ struct MacroRule
296
308
// Creates an error state macro rule.
297
309
static MacroRule create_error ()
298
310
{
299
- return MacroRule (MacroMatcher::create_error (),
311
+ // FIXME: Once #928 is merged, give location to MacroMatcher
312
+ return MacroRule (MacroMatcher::create_error (Location ()),
300
313
MacroTranscriber (DelimTokenTree::create_empty ()));
301
314
}
302
315
0 commit comments