ASTMatcher.cpp 53.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

Roberto Raggi's avatar
Roberto Raggi committed
30
#include "AST.h"
31
32
33
34
35
36
#include "ASTMatcher.h"
#include "Control.h"
#include "TranslationUnit.h"

using namespace CPlusPlus;

37
38
ASTMatcher::ASTMatcher(TranslationUnit *translationUnit, TranslationUnit *patternTranslationUnit)
    : _translationUnit(translationUnit), _patternTranslationUnit(patternTranslationUnit)
Roberto Raggi's avatar
Roberto Raggi committed
39
40
41
42
43
{ }

ASTMatcher::~ASTMatcher()
{ }

44
TranslationUnit *ASTMatcher::translationUnit() const
45
{ return _translationUnit; }
46

47
48
TranslationUnit *ASTMatcher::patternTranslationUnit() const
{ return _patternTranslationUnit; }
49

50
bool ASTMatcher::matchToken(unsigned tokenIndex, unsigned patternTokenIndex) const
51
{
52
53
    const Token &token = _translationUnit->tokenAt(tokenIndex);
    const Token &otherToken = _patternTranslationUnit->tokenAt(patternTokenIndex);
54
55
56
57
58
59
60
61
62
    if (token.f.kind != otherToken.f.kind)
        return false;
    else if (token.is(T_IDENTIFIER)) {
        if (token.identifier != otherToken.identifier)
            return false;
    }
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
63
bool ASTMatcher::match(SimpleSpecifierAST *node, SimpleSpecifierAST *pattern)
64
{
65
    if (! matchToken(node->specifier_token, pattern->specifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
66
        return false;
67
68
69
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
70
bool ASTMatcher::match(AttributeSpecifierAST *node, AttributeSpecifierAST *pattern)
71
{
72
    if (! matchToken(node->attribute_token, pattern->attribute_token))
Roberto Raggi's avatar
Roberto Raggi committed
73
        return false;
74
    if (! matchToken(node->first_lparen_token, pattern->first_lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
75
        return false;
76
    if (! matchToken(node->second_lparen_token, pattern->second_lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
77
78
79
        return false;
    if (! AST::match(node->attribute_list, pattern->attribute_list, this))
        return false;
80
    if (! matchToken(node->first_rparen_token, pattern->first_rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
81
        return false;
82
    if (! matchToken(node->second_rparen_token, pattern->second_rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
83
        return false;
84
85
86
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
87
bool ASTMatcher::match(AttributeAST *node, AttributeAST *pattern)
88
{
89
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
90
        return false;
91
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
92
        return false;
93
    if (! matchToken(node->tag_token, pattern->tag_token))
Roberto Raggi's avatar
Roberto Raggi committed
94
95
96
        return false;
    if (! AST::match(node->expression_list, pattern->expression_list, this))
        return false;
97
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
98
        return false;
99
100
101
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
102
bool ASTMatcher::match(TypeofSpecifierAST *node, TypeofSpecifierAST *pattern)
103
{
104
    if (! matchToken(node->typeof_token, pattern->typeof_token))
Roberto Raggi's avatar
Roberto Raggi committed
105
        return false;
106
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
107
108
109
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
110
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
111
        return false;
112
113
114
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
115
bool ASTMatcher::match(DeclaratorAST *node, DeclaratorAST *pattern)
116
{
Roberto Raggi's avatar
Roberto Raggi committed
117
118
119
120
121
122
123
124
125
126
    if (! AST::match(node->attribute_list, pattern->attribute_list, this))
        return false;
    if (! AST::match(node->ptr_operator_list, pattern->ptr_operator_list, this))
        return false;
    if (! AST::match(node->core_declarator, pattern->core_declarator, this))
        return false;
    if (! AST::match(node->postfix_declarator_list, pattern->postfix_declarator_list, this))
        return false;
    if (! AST::match(node->post_attribute_list, pattern->post_attribute_list, this))
        return false;
127
    if (! matchToken(node->equals_token, pattern->equals_token))
Roberto Raggi's avatar
Roberto Raggi committed
128
129
130
        return false;
    if (! AST::match(node->initializer, pattern->initializer, this))
        return false;
131
132
133
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
134
bool ASTMatcher::match(SimpleDeclarationAST *node, SimpleDeclarationAST *pattern)
135
{
136
    if (! matchToken(node->qt_invokable_token, pattern->qt_invokable_token))
Roberto Raggi's avatar
Roberto Raggi committed
137
138
139
140
141
        return false;
    if (! AST::match(node->decl_specifier_list, pattern->decl_specifier_list, this))
        return false;
    if (! AST::match(node->declarator_list, pattern->declarator_list, this))
        return false;
142
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
143
        return false;
144
145
146
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
147
bool ASTMatcher::match(EmptyDeclarationAST *node, EmptyDeclarationAST *pattern)
148
{
149
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
150
        return false;
151
152
153
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
154
bool ASTMatcher::match(AccessDeclarationAST *node, AccessDeclarationAST *pattern)
155
{
156
    if (! matchToken(node->access_specifier_token, pattern->access_specifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
157
        return false;
158
    if (! matchToken(node->slots_token, pattern->slots_token))
Roberto Raggi's avatar
Roberto Raggi committed
159
        return false;
160
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
161
        return false;
162
163
164
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
165
bool ASTMatcher::match(AsmDefinitionAST *node, AsmDefinitionAST *pattern)
166
{
167
    if (! matchToken(node->asm_token, pattern->asm_token))
Roberto Raggi's avatar
Roberto Raggi committed
168
        return false;
169
    if (! matchToken(node->volatile_token, pattern->volatile_token))
Roberto Raggi's avatar
Roberto Raggi committed
170
        return false;
171
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
172
        return false;
173
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
174
        return false;
175
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
176
        return false;
177
178
179
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
180
bool ASTMatcher::match(BaseSpecifierAST *node, BaseSpecifierAST *pattern)
181
{
182
    if (! matchToken(node->virtual_token, pattern->virtual_token))
Roberto Raggi's avatar
Roberto Raggi committed
183
        return false;
184
    if (! matchToken(node->access_specifier_token, pattern->access_specifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
185
186
187
        return false;
    if (! AST::match(node->name, pattern->name, this))
        return false;
188
189
190
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
191
bool ASTMatcher::match(CompoundLiteralAST *node, CompoundLiteralAST *pattern)
192
{
193
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
194
195
196
        return false;
    if (! AST::match(node->type_id, pattern->type_id, this))
        return false;
197
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
198
199
200
        return false;
    if (! AST::match(node->initializer, pattern->initializer, this))
        return false;
201
202
203
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
204
bool ASTMatcher::match(QtMethodAST *node, QtMethodAST *pattern)
205
{
206
    if (! matchToken(node->method_token, pattern->method_token))
Roberto Raggi's avatar
Roberto Raggi committed
207
        return false;
208
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
209
210
211
        return false;
    if (! AST::match(node->declarator, pattern->declarator, this))
        return false;
212
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
213
        return false;
214
215
216
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
217
bool ASTMatcher::match(BinaryExpressionAST *node, BinaryExpressionAST *pattern)
218
{
Roberto Raggi's avatar
Roberto Raggi committed
219
220
    if (! AST::match(node->left_expression, pattern->left_expression, this))
        return false;
221
    if (! matchToken(node->binary_op_token, pattern->binary_op_token))
Roberto Raggi's avatar
Roberto Raggi committed
222
223
224
        return false;
    if (! AST::match(node->right_expression, pattern->right_expression, this))
        return false;
225
226
227
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
228
bool ASTMatcher::match(CastExpressionAST *node, CastExpressionAST *pattern)
229
{
230
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
231
232
233
        return false;
    if (! AST::match(node->type_id, pattern->type_id, this))
        return false;
234
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
235
236
237
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
238
239
240
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
241
bool ASTMatcher::match(ClassSpecifierAST *node, ClassSpecifierAST *pattern)
242
{
243
    if (! matchToken(node->classkey_token, pattern->classkey_token))
Roberto Raggi's avatar
Roberto Raggi committed
244
245
246
247
248
        return false;
    if (! AST::match(node->attribute_list, pattern->attribute_list, this))
        return false;
    if (! AST::match(node->name, pattern->name, this))
        return false;
249
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
250
251
252
        return false;
    if (! AST::match(node->base_clause_list, pattern->base_clause_list, this))
        return false;
253
    if (! matchToken(node->lbrace_token, pattern->lbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
254
255
256
        return false;
    if (! AST::match(node->member_specifier_list, pattern->member_specifier_list, this))
        return false;
257
    if (! matchToken(node->rbrace_token, pattern->rbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
258
        return false;
259
260
261
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
262
bool ASTMatcher::match(CaseStatementAST *node, CaseStatementAST *pattern)
263
{
264
    if (! matchToken(node->case_token, pattern->case_token))
Roberto Raggi's avatar
Roberto Raggi committed
265
266
267
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
268
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
269
270
271
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
272
273
274
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
275
bool ASTMatcher::match(CompoundStatementAST *node, CompoundStatementAST *pattern)
276
{
277
    if (! matchToken(node->lbrace_token, pattern->lbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
278
279
280
        return false;
    if (! AST::match(node->statement_list, pattern->statement_list, this))
        return false;
281
    if (! matchToken(node->rbrace_token, pattern->rbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
282
        return false;
283
284
285
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
286
bool ASTMatcher::match(ConditionAST *node, ConditionAST *pattern)
287
{
Roberto Raggi's avatar
Roberto Raggi committed
288
289
290
291
    if (! AST::match(node->type_specifier_list, pattern->type_specifier_list, this))
        return false;
    if (! AST::match(node->declarator, pattern->declarator, this))
        return false;
292
293
294
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
295
bool ASTMatcher::match(ConditionalExpressionAST *node, ConditionalExpressionAST *pattern)
296
{
Roberto Raggi's avatar
Roberto Raggi committed
297
298
    if (! AST::match(node->condition, pattern->condition, this))
        return false;
299
    if (! matchToken(node->question_token, pattern->question_token))
Roberto Raggi's avatar
Roberto Raggi committed
300
301
302
        return false;
    if (! AST::match(node->left_expression, pattern->left_expression, this))
        return false;
303
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
304
305
306
        return false;
    if (! AST::match(node->right_expression, pattern->right_expression, this))
        return false;
307
308
309
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
310
bool ASTMatcher::match(CppCastExpressionAST *node, CppCastExpressionAST *pattern)
311
{
312
    if (! matchToken(node->cast_token, pattern->cast_token))
Roberto Raggi's avatar
Roberto Raggi committed
313
        return false;
314
    if (! matchToken(node->less_token, pattern->less_token))
Roberto Raggi's avatar
Roberto Raggi committed
315
316
317
        return false;
    if (! AST::match(node->type_id, pattern->type_id, this))
        return false;
318
    if (! matchToken(node->greater_token, pattern->greater_token))
Roberto Raggi's avatar
Roberto Raggi committed
319
        return false;
320
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
321
322
323
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
324
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
325
        return false;
326
327
328
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
329
bool ASTMatcher::match(CtorInitializerAST *node, CtorInitializerAST *pattern)
330
{
331
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
332
333
334
        return false;
    if (! AST::match(node->member_initializer_list, pattern->member_initializer_list, this))
        return false;
335
336
337
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
338
bool ASTMatcher::match(DeclarationStatementAST *node, DeclarationStatementAST *pattern)
339
{
Roberto Raggi's avatar
Roberto Raggi committed
340
341
    if (! AST::match(node->declaration, pattern->declaration, this))
        return false;
342
343
344
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
345
bool ASTMatcher::match(DeclaratorIdAST *node, DeclaratorIdAST *pattern)
346
{
Roberto Raggi's avatar
Roberto Raggi committed
347
348
    if (! AST::match(node->name, pattern->name, this))
        return false;
349
350
351
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
352
bool ASTMatcher::match(NestedDeclaratorAST *node, NestedDeclaratorAST *pattern)
353
{
354
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
355
356
357
        return false;
    if (! AST::match(node->declarator, pattern->declarator, this))
        return false;
358
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
359
        return false;
360
361
362
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
363
bool ASTMatcher::match(FunctionDeclaratorAST *node, FunctionDeclaratorAST *pattern)
364
{
365
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
366
367
368
        return false;
    if (! AST::match(node->parameters, pattern->parameters, this))
        return false;
369
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
370
371
372
373
374
375
376
        return false;
    if (! AST::match(node->cv_qualifier_list, pattern->cv_qualifier_list, this))
        return false;
    if (! AST::match(node->exception_specification, pattern->exception_specification, this))
        return false;
    if (! AST::match(node->as_cpp_initializer, pattern->as_cpp_initializer, this))
        return false;
377
378
379
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
380
bool ASTMatcher::match(ArrayDeclaratorAST *node, ArrayDeclaratorAST *pattern)
381
{
382
    if (! matchToken(node->lbracket_token, pattern->lbracket_token))
Roberto Raggi's avatar
Roberto Raggi committed
383
384
385
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
386
    if (! matchToken(node->rbracket_token, pattern->rbracket_token))
Roberto Raggi's avatar
Roberto Raggi committed
387
        return false;
388
389
390
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
391
bool ASTMatcher::match(DeleteExpressionAST *node, DeleteExpressionAST *pattern)
392
{
393
    if (! matchToken(node->scope_token, pattern->scope_token))
Roberto Raggi's avatar
Roberto Raggi committed
394
        return false;
395
    if (! matchToken(node->delete_token, pattern->delete_token))
Roberto Raggi's avatar
Roberto Raggi committed
396
        return false;
397
    if (! matchToken(node->lbracket_token, pattern->lbracket_token))
Roberto Raggi's avatar
Roberto Raggi committed
398
        return false;
399
    if (! matchToken(node->rbracket_token, pattern->rbracket_token))
Roberto Raggi's avatar
Roberto Raggi committed
400
401
402
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
403
404
405
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
406
bool ASTMatcher::match(DoStatementAST *node, DoStatementAST *pattern)
407
{
408
    if (! matchToken(node->do_token, pattern->do_token))
Roberto Raggi's avatar
Roberto Raggi committed
409
410
411
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
412
    if (! matchToken(node->while_token, pattern->while_token))
Roberto Raggi's avatar
Roberto Raggi committed
413
        return false;
414
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
415
416
417
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
418
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
419
        return false;
420
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
421
        return false;
422
423
424
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
425
bool ASTMatcher::match(NamedTypeSpecifierAST *node, NamedTypeSpecifierAST *pattern)
426
{
Roberto Raggi's avatar
Roberto Raggi committed
427
428
    if (! AST::match(node->name, pattern->name, this))
        return false;
429
430
431
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
432
bool ASTMatcher::match(ElaboratedTypeSpecifierAST *node, ElaboratedTypeSpecifierAST *pattern)
433
{
434
    if (! matchToken(node->classkey_token, pattern->classkey_token))
Roberto Raggi's avatar
Roberto Raggi committed
435
436
437
        return false;
    if (! AST::match(node->name, pattern->name, this))
        return false;
438
439
440
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
441
bool ASTMatcher::match(EnumSpecifierAST *node, EnumSpecifierAST *pattern)
442
{
443
    if (! matchToken(node->enum_token, pattern->enum_token))
Roberto Raggi's avatar
Roberto Raggi committed
444
445
446
        return false;
    if (! AST::match(node->name, pattern->name, this))
        return false;
447
    if (! matchToken(node->lbrace_token, pattern->lbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
448
449
450
        return false;
    if (! AST::match(node->enumerator_list, pattern->enumerator_list, this))
        return false;
451
    if (! matchToken(node->rbrace_token, pattern->rbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
452
        return false;
453
454
455
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
456
bool ASTMatcher::match(EnumeratorAST *node, EnumeratorAST *pattern)
457
{
458
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
459
        return false;
460
    if (! matchToken(node->equal_token, pattern->equal_token))
Roberto Raggi's avatar
Roberto Raggi committed
461
462
463
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
464
465
466
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
467
bool ASTMatcher::match(ExceptionDeclarationAST *node, ExceptionDeclarationAST *pattern)
468
{
Roberto Raggi's avatar
Roberto Raggi committed
469
470
471
472
    if (! AST::match(node->type_specifier_list, pattern->type_specifier_list, this))
        return false;
    if (! AST::match(node->declarator, pattern->declarator, this))
        return false;
473
    if (! matchToken(node->dot_dot_dot_token, pattern->dot_dot_dot_token))
Roberto Raggi's avatar
Roberto Raggi committed
474
        return false;
475
476
477
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
478
bool ASTMatcher::match(ExceptionSpecificationAST *node, ExceptionSpecificationAST *pattern)
479
{
480
    if (! matchToken(node->throw_token, pattern->throw_token))
Roberto Raggi's avatar
Roberto Raggi committed
481
        return false;
482
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
483
        return false;
484
    if (! matchToken(node->dot_dot_dot_token, pattern->dot_dot_dot_token))
Roberto Raggi's avatar
Roberto Raggi committed
485
486
487
        return false;
    if (! AST::match(node->type_id_list, pattern->type_id_list, this))
        return false;
488
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
489
        return false;
490
491
492
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
493
bool ASTMatcher::match(ExpressionOrDeclarationStatementAST *node, ExpressionOrDeclarationStatementAST *pattern)
494
{
Roberto Raggi's avatar
Roberto Raggi committed
495
496
497
498
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
    if (! AST::match(node->declaration, pattern->declaration, this))
        return false;
499
500
501
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
502
bool ASTMatcher::match(ExpressionStatementAST *node, ExpressionStatementAST *pattern)
503
{
Roberto Raggi's avatar
Roberto Raggi committed
504
505
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
506
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
507
        return false;
508
509
510
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
511
bool ASTMatcher::match(FunctionDefinitionAST *node, FunctionDefinitionAST *pattern)
512
{
513
    if (! matchToken(node->qt_invokable_token, pattern->qt_invokable_token))
Roberto Raggi's avatar
Roberto Raggi committed
514
515
516
517
518
519
520
521
522
        return false;
    if (! AST::match(node->decl_specifier_list, pattern->decl_specifier_list, this))
        return false;
    if (! AST::match(node->declarator, pattern->declarator, this))
        return false;
    if (! AST::match(node->ctor_initializer, pattern->ctor_initializer, this))
        return false;
    if (! AST::match(node->function_body, pattern->function_body, this))
        return false;
523
524
525
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
526
bool ASTMatcher::match(ForeachStatementAST *node, ForeachStatementAST *pattern)
527
{
528
    if (! matchToken(node->foreach_token, pattern->foreach_token))
Roberto Raggi's avatar
Roberto Raggi committed
529
        return false;
530
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
531
532
533
534
535
536
537
        return false;
    if (! AST::match(node->type_specifier_list, pattern->type_specifier_list, this))
        return false;
    if (! AST::match(node->declarator, pattern->declarator, this))
        return false;
    if (! AST::match(node->initializer, pattern->initializer, this))
        return false;
538
    if (! matchToken(node->comma_token, pattern->comma_token))
Roberto Raggi's avatar
Roberto Raggi committed
539
540
541
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
542
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
543
544
545
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
546
547
548
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
549
bool ASTMatcher::match(ForStatementAST *node, ForStatementAST *pattern)
550
{
551
    if (! matchToken(node->for_token, pattern->for_token))
Roberto Raggi's avatar
Roberto Raggi committed
552
        return false;
553
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
554
555
556
557
558
        return false;
    if (! AST::match(node->initializer, pattern->initializer, this))
        return false;
    if (! AST::match(node->condition, pattern->condition, this))
        return false;
559
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
560
561
562
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
563
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
564
565
566
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
567
568
569
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
570
bool ASTMatcher::match(IfStatementAST *node, IfStatementAST *pattern)
571
{
572
    if (! matchToken(node->if_token, pattern->if_token))
Roberto Raggi's avatar
Roberto Raggi committed
573
        return false;
574
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
575
576
577
        return false;
    if (! AST::match(node->condition, pattern->condition, this))
        return false;
578
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
579
580
581
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
582
    if (! matchToken(node->else_token, pattern->else_token))
Roberto Raggi's avatar
Roberto Raggi committed
583
584
585
        return false;
    if (! AST::match(node->else_statement, pattern->else_statement, this))
        return false;
586
587
588
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
589
bool ASTMatcher::match(ArrayInitializerAST *node, ArrayInitializerAST *pattern)
590
{
591
    if (! matchToken(node->lbrace_token, pattern->lbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
592
593
594
        return false;
    if (! AST::match(node->expression_list, pattern->expression_list, this))
        return false;
595
    if (! matchToken(node->rbrace_token, pattern->rbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
596
        return false;
597
598
599
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
600
bool ASTMatcher::match(LabeledStatementAST *node, LabeledStatementAST *pattern)
601
{
602
    if (! matchToken(node->label_token, pattern->label_token))
Roberto Raggi's avatar
Roberto Raggi committed
603
        return false;
604
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
605
606
607
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
608
609
610
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
611
bool ASTMatcher::match(LinkageBodyAST *node, LinkageBodyAST *pattern)
612
{
613
    if (! matchToken(node->lbrace_token, pattern->lbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
614
615
616
        return false;
    if (! AST::match(node->declaration_list, pattern->declaration_list, this))
        return false;
617
    if (! matchToken(node->rbrace_token, pattern->rbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
618
        return false;
619
620
621
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
622
bool ASTMatcher::match(LinkageSpecificationAST *node, LinkageSpecificationAST *pattern)
623
{
624
    if (! matchToken(node->extern_token, pattern->extern_token))
Roberto Raggi's avatar
Roberto Raggi committed
625
        return false;
626
    if (! matchToken(node->extern_type_token, pattern->extern_type_token))
Roberto Raggi's avatar
Roberto Raggi committed
627
628
629
        return false;
    if (! AST::match(node->declaration, pattern->declaration, this))
        return false;
630
631
632
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
633
bool ASTMatcher::match(MemInitializerAST *node, MemInitializerAST *pattern)
634
{
Roberto Raggi's avatar
Roberto Raggi committed
635
636
    if (! AST::match(node->name, pattern->name, this))
        return false;
637
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
638
639
640
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
641
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
642
        return false;
643
644
645
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
646
bool ASTMatcher::match(NestedNameSpecifierAST *node, NestedNameSpecifierAST *pattern)
647
{
Roberto Raggi's avatar
Roberto Raggi committed
648
649
    if (! AST::match(node->class_or_namespace_name, pattern->class_or_namespace_name, this))
        return false;
650
    if (! matchToken(node->scope_token, pattern->scope_token))
Roberto Raggi's avatar
Roberto Raggi committed
651
        return false;
652
653
654
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
655
bool ASTMatcher::match(QualifiedNameAST *node, QualifiedNameAST *pattern)
656
{
657
    if (! matchToken(node->global_scope_token, pattern->global_scope_token))
Roberto Raggi's avatar
Roberto Raggi committed
658
659
660
661
662
        return false;
    if (! AST::match(node->nested_name_specifier_list, pattern->nested_name_specifier_list, this))
        return false;
    if (! AST::match(node->unqualified_name, pattern->unqualified_name, this))
        return false;
663
664
665
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
666
bool ASTMatcher::match(OperatorFunctionIdAST *node, OperatorFunctionIdAST *pattern)
667
{
668
    if (! matchToken(node->operator_token, pattern->operator_token))
Roberto Raggi's avatar
Roberto Raggi committed
669
670
671
        return false;
    if (! AST::match(node->op, pattern->op, this))
        return false;
672
673
674
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
675
bool ASTMatcher::match(ConversionFunctionIdAST *node, ConversionFunctionIdAST *pattern)
676
{
677
    if (! matchToken(node->operator_token, pattern->operator_token))
Roberto Raggi's avatar
Roberto Raggi committed
678
679
680
681
682
        return false;
    if (! AST::match(node->type_specifier_list, pattern->type_specifier_list, this))
        return false;
    if (! AST::match(node->ptr_operator_list, pattern->ptr_operator_list, this))
        return false;
683
684
685
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
686
bool ASTMatcher::match(SimpleNameAST *node, SimpleNameAST *pattern)
687
{
688
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
689
        return false;
690
691
692
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
693
bool ASTMatcher::match(DestructorNameAST *node, DestructorNameAST *pattern)
694
{
695
    if (! matchToken(node->tilde_token, pattern->tilde_token))
Roberto Raggi's avatar
Roberto Raggi committed
696
        return false;
697
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
698
        return false;
699
700
701
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
702
bool ASTMatcher::match(TemplateIdAST *node, TemplateIdAST *pattern)
703
{
704
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
705
        return false;
706
    if (! matchToken(node->less_token, pattern->less_token))
Roberto Raggi's avatar
Roberto Raggi committed
707
708
709
        return false;
    if (! AST::match(node->template_argument_list, pattern->template_argument_list, this))
        return false;
710
    if (! matchToken(node->greater_token, pattern->greater_token))
Roberto Raggi's avatar
Roberto Raggi committed
711
        return false;
712
713
714
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
715
bool ASTMatcher::match(NamespaceAST *node, NamespaceAST *pattern)
716
{
717
    if (! matchToken(node->namespace_token, pattern->namespace_token))
Roberto Raggi's avatar
Roberto Raggi committed
718
        return false;
719
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
720
721
722
723
724
        return false;
    if (! AST::match(node->attribute_list, pattern->attribute_list, this))
        return false;
    if (! AST::match(node->linkage_body, pattern->linkage_body, this))
        return false;
725
726
727
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
728
bool ASTMatcher::match(NamespaceAliasDefinitionAST *node, NamespaceAliasDefinitionAST *pattern)
729
{
730
    if (! matchToken(node->namespace_token, pattern->namespace_token))
Roberto Raggi's avatar
Roberto Raggi committed
731
        return false;
732
    if (! matchToken(node->namespace_name_token, pattern->namespace_name_token))
Roberto Raggi's avatar
Roberto Raggi committed
733
        return false;
734
    if (! matchToken(node->equal_token, pattern->equal_token))
Roberto Raggi's avatar
Roberto Raggi committed
735
736
737
        return false;
    if (! AST::match(node->name, pattern->name, this))
        return false;
738
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
739
        return false;
740
741
742
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
743
bool ASTMatcher::match(NewPlacementAST *node, NewPlacementAST *pattern)
744
{
Roberto Raggi's avatar