@@ -105,8 +105,8 @@ contains (std::vector<T> &vec, T elm)
105
105
*/
106
106
107
107
template <typename T>
108
- static T *
109
- get_back_ptr (std::vector<std::unique_ptr<T>> &values)
108
+ static const T *
109
+ get_back_ptr (const std::vector<std::unique_ptr<T>> &values)
110
110
{
111
111
if (values.empty ())
112
112
return nullptr ;
@@ -115,8 +115,8 @@ get_back_ptr (std::vector<std::unique_ptr<T>> &values)
115
115
}
116
116
117
117
template <typename T>
118
- static T *
119
- get_front_ptr (std::vector<std::unique_ptr<T>> &values)
118
+ static const T *
119
+ get_front_ptr (const std::vector<std::unique_ptr<T>> &values)
120
120
{
121
121
if (values.empty ())
122
122
return nullptr ;
@@ -151,8 +151,8 @@ peculiar_fragment_match_compatible_fragment (
151
151
}
152
152
153
153
static bool
154
- peculiar_fragment_match_compatible (AST::MacroMatchFragment &last_match,
155
- AST::MacroMatch &match)
154
+ peculiar_fragment_match_compatible (const AST::MacroMatchFragment &last_match,
155
+ const AST::MacroMatch &match)
156
156
{
157
157
static std::unordered_map<AST::MacroFragSpec::Kind, std::vector<TokenId>>
158
158
follow_set
@@ -208,7 +208,7 @@ peculiar_fragment_match_compatible (AST::MacroMatchFragment &last_match,
208
208
switch (match.get_macro_match_type ())
209
209
{
210
210
case AST::MacroMatch::Tok: {
211
- auto tok = static_cast <AST::Token *> (&match);
211
+ auto tok = static_cast <const AST::Token *> (&match);
212
212
if (contains (allowed_toks, tok->get_id ()))
213
213
return true ;
214
214
kind_str = " token `"
@@ -218,15 +218,16 @@ peculiar_fragment_match_compatible (AST::MacroMatchFragment &last_match,
218
218
}
219
219
break ;
220
220
case AST::MacroMatch::Repetition: {
221
- auto repetition = static_cast <AST::MacroMatchRepetition *> (&match);
221
+ auto repetition
222
+ = static_cast <const AST::MacroMatchRepetition *> (&match);
222
223
auto &matches = repetition->get_matches ();
223
224
auto first_frag = get_front_ptr (matches);
224
225
if (first_frag)
225
226
return peculiar_fragment_match_compatible (last_match, *first_frag);
226
227
break ;
227
228
}
228
229
case AST::MacroMatch::Matcher: {
229
- auto matcher = static_cast <AST::MacroMatcher *> (&match);
230
+ auto matcher = static_cast <const AST::MacroMatcher *> (&match);
230
231
auto first_token = matcher->get_delim_type ();
231
232
TokenId delim_id;
232
233
switch (first_token)
@@ -250,7 +251,7 @@ peculiar_fragment_match_compatible (AST::MacroMatchFragment &last_match,
250
251
}
251
252
case AST::MacroMatch::Fragment: {
252
253
auto last_spec = last_match.get_frag_spec ();
253
- auto fragment = static_cast <AST::MacroMatchFragment *> (&match);
254
+ auto fragment = static_cast <const AST::MacroMatchFragment *> (&match);
254
255
if (last_spec.has_follow_set_fragment_restrictions ())
255
256
return peculiar_fragment_match_compatible_fragment (
256
257
last_spec, fragment->get_frag_spec (), match.get_match_locus ());
@@ -273,9 +274,10 @@ peculiar_fragment_match_compatible (AST::MacroMatchFragment &last_match,
273
274
}
274
275
275
276
bool
276
- is_match_compatible (AST::MacroMatch &last_match, AST::MacroMatch &match)
277
+ is_match_compatible (const AST::MacroMatch &last_match,
278
+ const AST::MacroMatch &match)
277
279
{
278
- AST::MacroMatch *new_last = nullptr ;
280
+ const AST::MacroMatch *new_last = nullptr ;
279
281
280
282
// We want to "extract" the concerning matches. In cases such as matchers and
281
283
// repetitions, we actually store multiple matchers, but are only concerned
@@ -290,7 +292,8 @@ is_match_compatible (AST::MacroMatch &last_match, AST::MacroMatch &match)
290
292
// last match (or its actual last component), and it is a fragment, it
291
293
// may contain some follow up restrictions.
292
294
case AST::MacroMatch::Fragment: {
293
- auto fragment = static_cast <AST::MacroMatchFragment *> (&last_match);
295
+ auto fragment
296
+ = static_cast <const AST::MacroMatchFragment *> (&last_match);
294
297
if (fragment->get_frag_spec ().has_follow_set_restrictions ())
295
298
return peculiar_fragment_match_compatible (*fragment, match);
296
299
else
@@ -300,7 +303,7 @@ is_match_compatible (AST::MacroMatch &last_match, AST::MacroMatch &match)
300
303
// A repetition on the left hand side means we want to make sure the
301
304
// last match of the repetition is compatible with the new match
302
305
auto repetition
303
- = static_cast <AST::MacroMatchRepetition *> (&last_match);
306
+ = static_cast <const AST::MacroMatchRepetition *> (&last_match);
304
307
new_last = get_back_ptr (repetition->get_matches ());
305
308
// If there are no matches in the matcher, then it can be followed by
306
309
// anything
0 commit comments