ASTMatcher.cpp 55.1 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;

Roberto Raggi's avatar
Roberto Raggi committed
37
38
39
40
41
42
43
ASTMatcher::ASTMatcher(Control *control)
    : _control(control)
{ }

ASTMatcher::~ASTMatcher()
{ }

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Control *ASTMatcher::control() const
{ return _control; }

TranslationUnit *ASTMatcher::translationUnit() const
{ return _control->translationUnit(); }

unsigned ASTMatcher::tokenCount() const
{ return translationUnit()->tokenCount(); }

const Token &ASTMatcher::tokenAt(unsigned index) const
{ return translationUnit()->tokenAt(index); }

int ASTMatcher::tokenKind(unsigned index) const
{ return translationUnit()->tokenKind(index); }

const char *ASTMatcher::spell(unsigned index) const
{ return translationUnit()->spell(index); }

Identifier *ASTMatcher::identifier(unsigned index) const
{ return translationUnit()->identifier(index); }

Literal *ASTMatcher::literal(unsigned index) const
{ return translationUnit()->literal(index); }

NumericLiteral *ASTMatcher::numericLiteral(unsigned index) const
{ return translationUnit()->numericLiteral(index); }

StringLiteral *ASTMatcher::stringLiteral(unsigned index) const
{ return translationUnit()->stringLiteral(index); }

void ASTMatcher::getPosition(unsigned offset,
                             unsigned *line,
                             unsigned *column,
                             StringLiteral **fileName) const
{ translationUnit()->getPosition(offset, line, column, fileName); }

void ASTMatcher::getTokenPosition(unsigned index,
                                  unsigned *line,
                                  unsigned *column,
                                  StringLiteral **fileName) const
{ translationUnit()->getTokenPosition(index, line, column, fileName); }

void ASTMatcher::getTokenStartPosition(unsigned index, unsigned *line, unsigned *column) const
{ getPosition(tokenAt(index).begin(), line, column); }

void ASTMatcher::getTokenEndPosition(unsigned index, unsigned *line, unsigned *column) const
{ getPosition(tokenAt(index).end(), line, column); }

92
93
94
95
96
97
98
99
100
101
102
103
104
bool ASTMatcher::matchToken(unsigned index, unsigned otherIndex) const
{
    const Token &token = tokenAt(index);
    const Token &otherToken = tokenAt(otherIndex);
    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
105
bool ASTMatcher::match(SimpleSpecifierAST *node, SimpleSpecifierAST *pattern)
106
{
107
    if (! matchToken(node->specifier_token, pattern->specifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
108
        return false;
109
110
111
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
112
bool ASTMatcher::match(AttributeSpecifierAST *node, AttributeSpecifierAST *pattern)
113
{
114
    if (! matchToken(node->attribute_token, pattern->attribute_token))
Roberto Raggi's avatar
Roberto Raggi committed
115
        return false;
116
    if (! matchToken(node->first_lparen_token, pattern->first_lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
117
        return false;
118
    if (! matchToken(node->second_lparen_token, pattern->second_lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
119
120
121
        return false;
    if (! AST::match(node->attribute_list, pattern->attribute_list, this))
        return false;
122
    if (! matchToken(node->first_rparen_token, pattern->first_rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
123
        return false;
124
    if (! matchToken(node->second_rparen_token, pattern->second_rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
125
        return false;
126
127
128
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
129
bool ASTMatcher::match(AttributeAST *node, AttributeAST *pattern)
130
{
131
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
132
        return false;
133
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
134
        return false;
135
    if (! matchToken(node->tag_token, pattern->tag_token))
Roberto Raggi's avatar
Roberto Raggi committed
136
137
138
        return false;
    if (! AST::match(node->expression_list, pattern->expression_list, this))
        return false;
139
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
140
        return false;
141
142
143
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
144
bool ASTMatcher::match(TypeofSpecifierAST *node, TypeofSpecifierAST *pattern)
145
{
146
    if (! matchToken(node->typeof_token, pattern->typeof_token))
Roberto Raggi's avatar
Roberto Raggi committed
147
        return false;
148
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
149
150
151
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
152
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
153
        return false;
154
155
156
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
157
bool ASTMatcher::match(DeclaratorAST *node, DeclaratorAST *pattern)
158
{
Roberto Raggi's avatar
Roberto Raggi committed
159
160
161
162
163
164
165
166
167
168
    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;
169
    if (! matchToken(node->equals_token, pattern->equals_token))
Roberto Raggi's avatar
Roberto Raggi committed
170
171
172
        return false;
    if (! AST::match(node->initializer, pattern->initializer, this))
        return false;
173
174
175
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
176
bool ASTMatcher::match(SimpleDeclarationAST *node, SimpleDeclarationAST *pattern)
177
{
178
    if (! matchToken(node->qt_invokable_token, pattern->qt_invokable_token))
Roberto Raggi's avatar
Roberto Raggi committed
179
180
181
182
183
        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;
184
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
185
        return false;
186
187
188
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
189
bool ASTMatcher::match(EmptyDeclarationAST *node, EmptyDeclarationAST *pattern)
190
{
191
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
192
        return false;
193
194
195
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
196
bool ASTMatcher::match(AccessDeclarationAST *node, AccessDeclarationAST *pattern)
197
{
198
    if (! matchToken(node->access_specifier_token, pattern->access_specifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
199
        return false;
200
    if (! matchToken(node->slots_token, pattern->slots_token))
Roberto Raggi's avatar
Roberto Raggi committed
201
        return false;
202
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
203
        return false;
204
205
206
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
207
bool ASTMatcher::match(AsmDefinitionAST *node, AsmDefinitionAST *pattern)
208
{
209
    if (! matchToken(node->asm_token, pattern->asm_token))
Roberto Raggi's avatar
Roberto Raggi committed
210
        return false;
211
    if (! matchToken(node->volatile_token, pattern->volatile_token))
Roberto Raggi's avatar
Roberto Raggi committed
212
        return false;
213
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
214
        return false;
215
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
216
        return false;
217
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
218
        return false;
219
220
221
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
222
bool ASTMatcher::match(BaseSpecifierAST *node, BaseSpecifierAST *pattern)
223
{
224
    if (! matchToken(node->virtual_token, pattern->virtual_token))
Roberto Raggi's avatar
Roberto Raggi committed
225
        return false;
226
    if (! matchToken(node->access_specifier_token, pattern->access_specifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
227
228
229
        return false;
    if (! AST::match(node->name, pattern->name, this))
        return false;
230
231
232
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
233
bool ASTMatcher::match(CompoundLiteralAST *node, CompoundLiteralAST *pattern)
234
{
235
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
236
237
238
        return false;
    if (! AST::match(node->type_id, pattern->type_id, this))
        return false;
239
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
240
241
242
        return false;
    if (! AST::match(node->initializer, pattern->initializer, this))
        return false;
243
244
245
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
246
bool ASTMatcher::match(QtMethodAST *node, QtMethodAST *pattern)
247
{
248
    if (! matchToken(node->method_token, pattern->method_token))
Roberto Raggi's avatar
Roberto Raggi committed
249
        return false;
250
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
251
252
253
        return false;
    if (! AST::match(node->declarator, pattern->declarator, this))
        return false;
254
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
255
        return false;
256
257
258
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
259
bool ASTMatcher::match(BinaryExpressionAST *node, BinaryExpressionAST *pattern)
260
{
Roberto Raggi's avatar
Roberto Raggi committed
261
262
    if (! AST::match(node->left_expression, pattern->left_expression, this))
        return false;
263
    if (! matchToken(node->binary_op_token, pattern->binary_op_token))
Roberto Raggi's avatar
Roberto Raggi committed
264
265
266
        return false;
    if (! AST::match(node->right_expression, pattern->right_expression, this))
        return false;
267
268
269
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
270
bool ASTMatcher::match(CastExpressionAST *node, CastExpressionAST *pattern)
271
{
272
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
273
274
275
        return false;
    if (! AST::match(node->type_id, pattern->type_id, this))
        return false;
276
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
277
278
279
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
280
281
282
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
283
bool ASTMatcher::match(ClassSpecifierAST *node, ClassSpecifierAST *pattern)
284
{
285
    if (! matchToken(node->classkey_token, pattern->classkey_token))
Roberto Raggi's avatar
Roberto Raggi committed
286
287
288
289
290
        return false;
    if (! AST::match(node->attribute_list, pattern->attribute_list, this))
        return false;
    if (! AST::match(node->name, pattern->name, this))
        return false;
291
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
292
293
294
        return false;
    if (! AST::match(node->base_clause_list, pattern->base_clause_list, this))
        return false;
295
    if (! matchToken(node->lbrace_token, pattern->lbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
296
297
298
        return false;
    if (! AST::match(node->member_specifier_list, pattern->member_specifier_list, this))
        return false;
299
    if (! matchToken(node->rbrace_token, pattern->rbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
300
        return false;
301
302
303
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
304
bool ASTMatcher::match(CaseStatementAST *node, CaseStatementAST *pattern)
305
{
306
    if (! matchToken(node->case_token, pattern->case_token))
Roberto Raggi's avatar
Roberto Raggi committed
307
308
309
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
310
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
311
312
313
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
314
315
316
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
317
bool ASTMatcher::match(CompoundStatementAST *node, CompoundStatementAST *pattern)
318
{
319
    if (! matchToken(node->lbrace_token, pattern->lbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
320
321
322
        return false;
    if (! AST::match(node->statement_list, pattern->statement_list, this))
        return false;
323
    if (! matchToken(node->rbrace_token, pattern->rbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
324
        return false;
325
326
327
    return true;
}

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

Roberto Raggi's avatar
Roberto Raggi committed
337
bool ASTMatcher::match(ConditionalExpressionAST *node, ConditionalExpressionAST *pattern)
338
{
Roberto Raggi's avatar
Roberto Raggi committed
339
340
    if (! AST::match(node->condition, pattern->condition, this))
        return false;
341
    if (! matchToken(node->question_token, pattern->question_token))
Roberto Raggi's avatar
Roberto Raggi committed
342
343
344
        return false;
    if (! AST::match(node->left_expression, pattern->left_expression, this))
        return false;
345
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
346
347
348
        return false;
    if (! AST::match(node->right_expression, pattern->right_expression, this))
        return false;
349
350
351
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
352
bool ASTMatcher::match(CppCastExpressionAST *node, CppCastExpressionAST *pattern)
353
{
354
    if (! matchToken(node->cast_token, pattern->cast_token))
Roberto Raggi's avatar
Roberto Raggi committed
355
        return false;
356
    if (! matchToken(node->less_token, pattern->less_token))
Roberto Raggi's avatar
Roberto Raggi committed
357
358
359
        return false;
    if (! AST::match(node->type_id, pattern->type_id, this))
        return false;
360
    if (! matchToken(node->greater_token, pattern->greater_token))
Roberto Raggi's avatar
Roberto Raggi committed
361
        return false;
362
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
363
364
365
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
366
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
367
        return false;
368
369
370
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
371
bool ASTMatcher::match(CtorInitializerAST *node, CtorInitializerAST *pattern)
372
{
373
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
374
375
376
        return false;
    if (! AST::match(node->member_initializer_list, pattern->member_initializer_list, this))
        return false;
377
378
379
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
380
bool ASTMatcher::match(DeclarationStatementAST *node, DeclarationStatementAST *pattern)
381
{
Roberto Raggi's avatar
Roberto Raggi committed
382
383
    if (! AST::match(node->declaration, pattern->declaration, this))
        return false;
384
385
386
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
387
bool ASTMatcher::match(DeclaratorIdAST *node, DeclaratorIdAST *pattern)
388
{
Roberto Raggi's avatar
Roberto Raggi committed
389
390
    if (! AST::match(node->name, pattern->name, this))
        return false;
391
392
393
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
394
bool ASTMatcher::match(NestedDeclaratorAST *node, NestedDeclaratorAST *pattern)
395
{
396
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
397
398
399
        return false;
    if (! AST::match(node->declarator, pattern->declarator, this))
        return false;
400
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
401
        return false;
402
403
404
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
405
bool ASTMatcher::match(FunctionDeclaratorAST *node, FunctionDeclaratorAST *pattern)
406
{
407
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
408
409
410
        return false;
    if (! AST::match(node->parameters, pattern->parameters, this))
        return false;
411
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
412
413
414
415
416
417
418
        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;
419
420
421
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
422
bool ASTMatcher::match(ArrayDeclaratorAST *node, ArrayDeclaratorAST *pattern)
423
{
424
    if (! matchToken(node->lbracket_token, pattern->lbracket_token))
Roberto Raggi's avatar
Roberto Raggi committed
425
426
427
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
428
    if (! matchToken(node->rbracket_token, pattern->rbracket_token))
Roberto Raggi's avatar
Roberto Raggi committed
429
        return false;
430
431
432
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
433
bool ASTMatcher::match(DeleteExpressionAST *node, DeleteExpressionAST *pattern)
434
{
435
    if (! matchToken(node->scope_token, pattern->scope_token))
Roberto Raggi's avatar
Roberto Raggi committed
436
        return false;
437
    if (! matchToken(node->delete_token, pattern->delete_token))
Roberto Raggi's avatar
Roberto Raggi committed
438
        return false;
439
    if (! matchToken(node->lbracket_token, pattern->lbracket_token))
Roberto Raggi's avatar
Roberto Raggi committed
440
        return false;
441
    if (! matchToken(node->rbracket_token, pattern->rbracket_token))
Roberto Raggi's avatar
Roberto Raggi committed
442
443
444
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
445
446
447
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
448
bool ASTMatcher::match(DoStatementAST *node, DoStatementAST *pattern)
449
{
450
    if (! matchToken(node->do_token, pattern->do_token))
Roberto Raggi's avatar
Roberto Raggi committed
451
452
453
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
454
    if (! matchToken(node->while_token, pattern->while_token))
Roberto Raggi's avatar
Roberto Raggi committed
455
        return false;
456
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
457
458
459
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
460
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
461
        return false;
462
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
463
        return false;
464
465
466
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
467
bool ASTMatcher::match(NamedTypeSpecifierAST *node, NamedTypeSpecifierAST *pattern)
468
{
Roberto Raggi's avatar
Roberto Raggi committed
469
470
    if (! AST::match(node->name, pattern->name, this))
        return false;
471
472
473
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
474
bool ASTMatcher::match(ElaboratedTypeSpecifierAST *node, ElaboratedTypeSpecifierAST *pattern)
475
{
476
    if (! matchToken(node->classkey_token, pattern->classkey_token))
Roberto Raggi's avatar
Roberto Raggi committed
477
478
479
        return false;
    if (! AST::match(node->name, pattern->name, this))
        return false;
480
481
482
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
483
bool ASTMatcher::match(EnumSpecifierAST *node, EnumSpecifierAST *pattern)
484
{
485
    if (! matchToken(node->enum_token, pattern->enum_token))
Roberto Raggi's avatar
Roberto Raggi committed
486
487
488
        return false;
    if (! AST::match(node->name, pattern->name, this))
        return false;
489
    if (! matchToken(node->lbrace_token, pattern->lbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
490
491
492
        return false;
    if (! AST::match(node->enumerator_list, pattern->enumerator_list, this))
        return false;
493
    if (! matchToken(node->rbrace_token, pattern->rbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
494
        return false;
495
496
497
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
498
bool ASTMatcher::match(EnumeratorAST *node, EnumeratorAST *pattern)
499
{
500
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
501
        return false;
502
    if (! matchToken(node->equal_token, pattern->equal_token))
Roberto Raggi's avatar
Roberto Raggi committed
503
504
505
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
506
507
508
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
509
bool ASTMatcher::match(ExceptionDeclarationAST *node, ExceptionDeclarationAST *pattern)
510
{
Roberto Raggi's avatar
Roberto Raggi committed
511
512
513
514
    if (! AST::match(node->type_specifier_list, pattern->type_specifier_list, this))
        return false;
    if (! AST::match(node->declarator, pattern->declarator, this))
        return false;
515
    if (! matchToken(node->dot_dot_dot_token, pattern->dot_dot_dot_token))
Roberto Raggi's avatar
Roberto Raggi committed
516
        return false;
517
518
519
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
520
bool ASTMatcher::match(ExceptionSpecificationAST *node, ExceptionSpecificationAST *pattern)
521
{
522
    if (! matchToken(node->throw_token, pattern->throw_token))
Roberto Raggi's avatar
Roberto Raggi committed
523
        return false;
524
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
525
        return false;
526
    if (! matchToken(node->dot_dot_dot_token, pattern->dot_dot_dot_token))
Roberto Raggi's avatar
Roberto Raggi committed
527
528
529
        return false;
    if (! AST::match(node->type_id_list, pattern->type_id_list, this))
        return false;
530
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
531
        return false;
532
533
534
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
535
bool ASTMatcher::match(ExpressionOrDeclarationStatementAST *node, ExpressionOrDeclarationStatementAST *pattern)
536
{
Roberto Raggi's avatar
Roberto Raggi committed
537
538
539
540
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
    if (! AST::match(node->declaration, pattern->declaration, this))
        return false;
541
542
543
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
544
bool ASTMatcher::match(ExpressionStatementAST *node, ExpressionStatementAST *pattern)
545
{
Roberto Raggi's avatar
Roberto Raggi committed
546
547
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
548
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
549
        return false;
550
551
552
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
553
bool ASTMatcher::match(FunctionDefinitionAST *node, FunctionDefinitionAST *pattern)
554
{
555
    if (! matchToken(node->qt_invokable_token, pattern->qt_invokable_token))
Roberto Raggi's avatar
Roberto Raggi committed
556
557
558
559
560
561
562
563
564
        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;
565
566
567
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
568
bool ASTMatcher::match(ForeachStatementAST *node, ForeachStatementAST *pattern)
569
{
570
    if (! matchToken(node->foreach_token, pattern->foreach_token))
Roberto Raggi's avatar
Roberto Raggi committed
571
        return false;
572
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
573
574
575
576
577
578
579
        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;
580
    if (! matchToken(node->comma_token, pattern->comma_token))
Roberto Raggi's avatar
Roberto Raggi committed
581
582
583
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
584
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
585
586
587
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
588
589
590
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
591
bool ASTMatcher::match(ForStatementAST *node, ForStatementAST *pattern)
592
{
593
    if (! matchToken(node->for_token, pattern->for_token))
Roberto Raggi's avatar
Roberto Raggi committed
594
        return false;
595
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
596
597
598
599
600
        return false;
    if (! AST::match(node->initializer, pattern->initializer, this))
        return false;
    if (! AST::match(node->condition, pattern->condition, this))
        return false;
601
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
602
603
604
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
605
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
606
607
608
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
609
610
611
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
612
bool ASTMatcher::match(IfStatementAST *node, IfStatementAST *pattern)
613
{
614
    if (! matchToken(node->if_token, pattern->if_token))
Roberto Raggi's avatar
Roberto Raggi committed
615
        return false;
616
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
617
618
619
        return false;
    if (! AST::match(node->condition, pattern->condition, this))
        return false;
620
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
621
622
623
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
624
    if (! matchToken(node->else_token, pattern->else_token))
Roberto Raggi's avatar
Roberto Raggi committed
625
626
627
        return false;
    if (! AST::match(node->else_statement, pattern->else_statement, this))
        return false;
628
629
630
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
631
bool ASTMatcher::match(ArrayInitializerAST *node, ArrayInitializerAST *pattern)
632
{
633
    if (! matchToken(node->lbrace_token, pattern->lbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
634
635
636
        return false;
    if (! AST::match(node->expression_list, pattern->expression_list, this))
        return false;
637
    if (! matchToken(node->rbrace_token, pattern->rbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
638
        return false;
639
640
641
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
642
bool ASTMatcher::match(LabeledStatementAST *node, LabeledStatementAST *pattern)
643
{
644
    if (! matchToken(node->label_token, pattern->label_token))
Roberto Raggi's avatar
Roberto Raggi committed
645
        return false;
646
    if (! matchToken(node->colon_token, pattern->colon_token))
Roberto Raggi's avatar
Roberto Raggi committed
647
648
649
        return false;
    if (! AST::match(node->statement, pattern->statement, this))
        return false;
650
651
652
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
653
bool ASTMatcher::match(LinkageBodyAST *node, LinkageBodyAST *pattern)
654
{
655
    if (! matchToken(node->lbrace_token, pattern->lbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
656
657
658
        return false;
    if (! AST::match(node->declaration_list, pattern->declaration_list, this))
        return false;
659
    if (! matchToken(node->rbrace_token, pattern->rbrace_token))
Roberto Raggi's avatar
Roberto Raggi committed
660
        return false;
661
662
663
    return true;
}

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

Roberto Raggi's avatar
Roberto Raggi committed
675
bool ASTMatcher::match(MemInitializerAST *node, MemInitializerAST *pattern)
676
{
Roberto Raggi's avatar
Roberto Raggi committed
677
678
    if (! AST::match(node->name, pattern->name, this))
        return false;
679
    if (! matchToken(node->lparen_token, pattern->lparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
680
681
682
        return false;
    if (! AST::match(node->expression, pattern->expression, this))
        return false;
683
    if (! matchToken(node->rparen_token, pattern->rparen_token))
Roberto Raggi's avatar
Roberto Raggi committed
684
        return false;
685
686
687
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
688
bool ASTMatcher::match(NestedNameSpecifierAST *node, NestedNameSpecifierAST *pattern)
689
{
Roberto Raggi's avatar
Roberto Raggi committed
690
691
    if (! AST::match(node->class_or_namespace_name, pattern->class_or_namespace_name, this))
        return false;
692
    if (! matchToken(node->scope_token, pattern->scope_token))
Roberto Raggi's avatar
Roberto Raggi committed
693
        return false;
694
695
696
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
697
bool ASTMatcher::match(QualifiedNameAST *node, QualifiedNameAST *pattern)
698
{
699
    if (! matchToken(node->global_scope_token, pattern->global_scope_token))
Roberto Raggi's avatar
Roberto Raggi committed
700
701
702
703
704
        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;
705
706
707
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
708
bool ASTMatcher::match(OperatorFunctionIdAST *node, OperatorFunctionIdAST *pattern)
709
{
710
    if (! matchToken(node->operator_token, pattern->operator_token))
Roberto Raggi's avatar
Roberto Raggi committed
711
712
713
        return false;
    if (! AST::match(node->op, pattern->op, this))
        return false;
714
715
716
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
717
bool ASTMatcher::match(ConversionFunctionIdAST *node, ConversionFunctionIdAST *pattern)
718
{
719
    if (! matchToken(node->operator_token, pattern->operator_token))
Roberto Raggi's avatar
Roberto Raggi committed
720
721
722
723
724
        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;
725
726
727
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
728
bool ASTMatcher::match(SimpleNameAST *node, SimpleNameAST *pattern)
729
{
730
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
731
        return false;
732
733
734
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
735
bool ASTMatcher::match(DestructorNameAST *node, DestructorNameAST *pattern)
736
{
737
    if (! matchToken(node->tilde_token, pattern->tilde_token))
Roberto Raggi's avatar
Roberto Raggi committed
738
        return false;
739
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
740
        return false;
741
742
743
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
744
bool ASTMatcher::match(TemplateIdAST *node, TemplateIdAST *pattern)
745
{
746
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
747
        return false;
748
    if (! matchToken(node->less_token, pattern->less_token))
Roberto Raggi's avatar
Roberto Raggi committed
749
750
751
        return false;
    if (! AST::match(node->template_argument_list, pattern->template_argument_list, this))
        return false;
752
    if (! matchToken(node->greater_token, pattern->greater_token))
Roberto Raggi's avatar
Roberto Raggi committed
753
        return false;
754
755
756
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
757
bool ASTMatcher::match(NamespaceAST *node, NamespaceAST *pattern)
758
{
759
    if (! matchToken(node->namespace_token, pattern->namespace_token))
Roberto Raggi's avatar
Roberto Raggi committed
760
        return false;
761
    if (! matchToken(node->identifier_token, pattern->identifier_token))
Roberto Raggi's avatar
Roberto Raggi committed
762
763
764
765
766
        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;
767
768
769
    return true;
}

Roberto Raggi's avatar
Roberto Raggi committed
770
bool ASTMatcher::match(NamespaceAliasDefinitionAST *node, NamespaceAliasDefinitionAST *pattern)
771
{
772
    if (! matchToken(node->namespace_token, pattern->namespace_token))
Roberto Raggi's avatar
Roberto Raggi committed
773
        return false;
774
    if (! matchToken(node->namespace_name_token, pattern->namespace_name_token))
Roberto Raggi's avatar
Roberto Raggi committed
775
        return false;
776
    if (! matchToken(node->equal_token, pattern->equal_token))
Roberto Raggi's avatar
Roberto Raggi committed
777
778
779
        return false;
    if (! AST::match(node->name, pattern->name, this))
        return false;
780
    if (! matchToken(node->semicolon_token, pattern->semicolon_token))
Roberto Raggi's avatar
Roberto Raggi committed
781
        return false;
782
783
784
    return true;
}