Bind.cpp 89.8 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
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include "Bind.h"
#include "AST.h"
#include "TranslationUnit.h"
#include "Control.h"
#include "Names.h"
#include "Symbols.h"
#include "CoreTypes.h"
#include "Literals.h"
#include "Scope.h"
Roberto Raggi's avatar
Roberto Raggi committed
30
#include <vector>
31
#include <string>
32
33
34
35
36
#include <memory>
#include <cassert>

using namespace CPlusPlus;

37
38
const int Bind::kMaxDepth(100);

39
40
Bind::Bind(TranslationUnit *unit)
    : ASTVisitor(unit),
Roberto Raggi's avatar
Roberto Raggi committed
41
42
      _scope(0),
      _expression(0),
Roberto Raggi's avatar
Roberto Raggi committed
43
      _name(0),
Roberto Raggi's avatar
Roberto Raggi committed
44
45
      _declaratorId(0),
      _visibility(Symbol::Public),
46
      _objcVisibility(Symbol::Public),
Roberto Raggi's avatar
Roberto Raggi committed
47
      _methodKey(Function::NormalMethod),
48
49
      _skipFunctionBodies(false),
      _depth(0)
50
51
52
{
}

Roberto Raggi's avatar
Roberto Raggi committed
53
54
55
56
57
58
59
60
61
62
bool Bind::skipFunctionBodies() const
{
    return _skipFunctionBodies;
}

void Bind::setSkipFunctionBodies(bool skipFunctionBodies)
{
    _skipFunctionBodies = skipFunctionBodies;
}

Roberto Raggi's avatar
Roberto Raggi committed
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
unsigned Bind::location(DeclaratorAST *ast, unsigned defaultLocation) const
{
    if (! ast)
        return defaultLocation;

    else if (ast->core_declarator)
        return location(ast->core_declarator, defaultLocation);

    return ast->firstToken();
}

unsigned Bind::location(CoreDeclaratorAST *ast, unsigned defaultLocation) const
{
    if (! ast)
        return defaultLocation;

    else if (NestedDeclaratorAST *nested = ast->asNestedDeclarator())
        return location(nested->declarator, defaultLocation);

    else if (DeclaratorIdAST *id = ast->asDeclaratorId())
        return location(id->name, defaultLocation);

    return ast->firstToken();
}

unsigned Bind::location(NameAST *name, unsigned defaultLocation) const
{
    if (! name)
        return defaultLocation;

    else if (DestructorNameAST *dtor = name->asDestructorName())
        return dtor->identifier_token;

    else if (TemplateIdAST *templId = name->asTemplateId())
        return templId->identifier_token;

    else if (QualifiedNameAST *q = name->asQualifiedName()) {
        if (q->unqualified_name)
            return location(q->unqualified_name, defaultLocation);
    }

    return name->firstToken();
}

Roberto Raggi's avatar
Roberto Raggi committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
void Bind::setDeclSpecifiers(Symbol *symbol, const FullySpecifiedType &declSpecifiers)
{
    if (! symbol)
        return;

    int storage = Symbol::NoStorage;

    if (declSpecifiers.isFriend())
        storage = Symbol::Friend;
    else if (declSpecifiers.isAuto())
        storage = Symbol::Auto;
    else if (declSpecifiers.isRegister())
        storage = Symbol::Register;
    else if (declSpecifiers.isStatic())
        storage = Symbol::Static;
    else if (declSpecifiers.isExtern())
        storage = Symbol::Extern;
    else if (declSpecifiers.isMutable())
        storage = Symbol::Mutable;
    else if (declSpecifiers.isTypedef())
        storage = Symbol::Typedef;

    symbol->setStorage(storage);

    if (Function *funTy = symbol->asFunction()) {
Roberto Raggi's avatar
Roberto Raggi committed
132
        if (declSpecifiers.isVirtual()) {
Roberto Raggi's avatar
Roberto Raggi committed
133
            funTy->setVirtual(true);
Roberto Raggi's avatar
Roberto Raggi committed
134
        }
Roberto Raggi's avatar
Roberto Raggi committed
135
136
137
138
139
140
141
142
143
    }

    if (declSpecifiers.isDeprecated())
        symbol->setDeprecated(true);

    if (declSpecifiers.isUnavailable())
        symbol->setUnavailable(true);
}

Roberto Raggi's avatar
Roberto Raggi committed
144
Scope *Bind::switchScope(Scope *scope)
145
{
Roberto Raggi's avatar
Roberto Raggi committed
146
147
148
    if (! scope)
        return _scope;

Roberto Raggi's avatar
Roberto Raggi committed
149
150
    std::swap(_scope, scope);
    return scope;
151
152
}

Roberto Raggi's avatar
Roberto Raggi committed
153
154
155
156
157
158
int Bind::switchVisibility(int visibility)
{
    std::swap(_visibility, visibility);
    return visibility;
}

159
160
161
162
163
164
int Bind::switchObjCVisibility(int visibility)
{
    std::swap(_objcVisibility, visibility);
    return visibility;
}

Roberto Raggi's avatar
Roberto Raggi committed
165
int Bind::switchMethodKey(int methodKey)
166
{
Roberto Raggi's avatar
Roberto Raggi committed
167
168
    std::swap(_methodKey, methodKey);
    return methodKey;
169
170
}

171
172
173
174
175
176
177
void Bind::operator()(TranslationUnitAST *ast, Namespace *globalNamespace)
{
    Scope *previousScope = switchScope(globalNamespace);
    translationUnit(ast);
    (void) switchScope(previousScope);
}

178
179
180
181
182
183
184
void Bind::operator()(DeclarationAST *ast, Scope *scope)
{
    Scope *previousScope = switchScope(scope);
    declaration(ast);
    (void) switchScope(previousScope);
}

185
FullySpecifiedType Bind::operator()(ExpressionAST *ast, Scope *scope)
186
187
{
    Scope *previousScope = switchScope(scope);
188
    FullySpecifiedType ty = expression(ast);
189
    (void) switchScope(previousScope);
190
191
192
193
194
195
196
197
198
    return ty;
}

FullySpecifiedType Bind::operator()(NewTypeIdAST *ast, Scope *scope)
{
    Scope *previousScope = switchScope(scope);
    FullySpecifiedType ty = newTypeId(ast);
    (void) switchScope(previousScope);
    return ty;
199
200
}

201
202
203
204
205
206
207
208
void Bind::statement(StatementAST *ast)
{
    accept(ast);
}

Bind::ExpressionTy Bind::expression(ExpressionAST *ast)
{
    ExpressionTy value = ExpressionTy();
Roberto Raggi's avatar
Roberto Raggi committed
209
    std::swap(_expression, value);
210
    accept(ast);
Roberto Raggi's avatar
Roberto Raggi committed
211
    std::swap(_expression, value);
212
213
214
215
216
217
218
219
220
221
222
    return value;
}

void Bind::declaration(DeclarationAST *ast)
{
    accept(ast);
}

const Name *Bind::name(NameAST *ast)
{
    const Name *value = 0;
Roberto Raggi's avatar
Roberto Raggi committed
223
    std::swap(_name, value);
224
    accept(ast);
Roberto Raggi's avatar
Roberto Raggi committed
225
    std::swap(_name, value);
226
227
228
229
230
231
    return value;
}

FullySpecifiedType Bind::specifier(SpecifierAST *ast, const FullySpecifiedType &init)
{
    FullySpecifiedType value = init;
Roberto Raggi's avatar
Roberto Raggi committed
232
    std::swap(_type, value);
233
    accept(ast);
Roberto Raggi's avatar
Roberto Raggi committed
234
    std::swap(_type, value);
235
236
237
238
239
240
    return value;
}

FullySpecifiedType Bind::ptrOperator(PtrOperatorAST *ast, const FullySpecifiedType &init)
{
    FullySpecifiedType value = init;
Roberto Raggi's avatar
Roberto Raggi committed
241
    std::swap(_type, value);
242
    accept(ast);
Roberto Raggi's avatar
Roberto Raggi committed
243
    std::swap(_type, value);
244
245
246
247
248
249
    return value;
}

FullySpecifiedType Bind::coreDeclarator(CoreDeclaratorAST *ast, const FullySpecifiedType &init)
{
    FullySpecifiedType value = init;
Roberto Raggi's avatar
Roberto Raggi committed
250
    std::swap(_type, value);
251
    accept(ast);
Roberto Raggi's avatar
Roberto Raggi committed
252
    std::swap(_type, value);
253
254
255
256
257
258
    return value;
}

FullySpecifiedType Bind::postfixDeclarator(PostfixDeclaratorAST *ast, const FullySpecifiedType &init)
{
    FullySpecifiedType value = init;
Roberto Raggi's avatar
Roberto Raggi committed
259
    std::swap(_type, value);
260
    accept(ast);
Roberto Raggi's avatar
Roberto Raggi committed
261
    std::swap(_type, value);
262
263
264
    return value;
}

265
266
267
268
269
270
271
272
273
274
275
276
277
bool Bind::preVisit(AST *)
{
    ++_depth;
    if (_depth > kMaxDepth)
        return false;
    return true;
}

void Bind::postVisit(AST *)
{
    --_depth;
}

278
279
280
281
282
283
284
285
// AST
bool Bind::visit(ObjCSelectorArgumentAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
286
const Name *Bind::objCSelectorArgument(ObjCSelectorArgumentAST *ast, bool *hasArg)
287
{
Roberto Raggi's avatar
Roberto Raggi committed
288
289
    if (! (ast && ast->name_token))
        return 0;
290

Roberto Raggi's avatar
Roberto Raggi committed
291
292
293
    if (ast->colon_token)
        *hasArg = true;

294
    return identifier(ast->name_token);
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
}

bool Bind::visit(AttributeAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::attribute(AttributeAST *ast)
{
    if (! ast)
        return;

    // unsigned identifier_token = ast->identifier_token;
310
311
312
313
314
315
316
    if (const Identifier *id = identifier(ast->identifier_token)) {
        if (id == control()->deprecatedId())
            _type.setDeprecated(true);
        else if (id == control()->unavailableId())
            _type.setUnavailable(true);
    }

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
    // unsigned lparen_token = ast->lparen_token;
    // unsigned tag_token = ast->tag_token;
    for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
        ExpressionTy value = this->expression(it->value);
    }
    // unsigned rparen_token = ast->rparen_token;
}

bool Bind::visit(DeclaratorAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
332
FullySpecifiedType Bind::declarator(DeclaratorAST *ast, const FullySpecifiedType &init, DeclaratorIdAST **declaratorId)
333
334
335
336
337
338
{
    FullySpecifiedType type = init;

    if (! ast)
        return type;

Roberto Raggi's avatar
Roberto Raggi committed
339
    std::swap(_declaratorId, declaratorId);
340
341
342
343
344
345
346
347
348
    for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
    for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
        type = this->ptrOperator(it->value, type);
    }
    for (PostfixDeclaratorListAST *it = ast->postfix_declarator_list; it; it = it->next) {
        type = this->postfixDeclarator(it->value, type);
    }
349
    type = this->coreDeclarator(ast->core_declarator, type);
350
351
352
353
354
    for (SpecifierListAST *it = ast->post_attribute_list; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
    // unsigned equals_token = ast->equals_token;
    ExpressionTy initializer = this->expression(ast->initializer);
Roberto Raggi's avatar
Roberto Raggi committed
355
    std::swap(_declaratorId, declaratorId);
356
    return type;
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
}

bool Bind::visit(QtPropertyDeclarationItemAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

bool Bind::visit(QtInterfaceNameAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::qtInterfaceName(QtInterfaceNameAST *ast)
{
    if (! ast)
        return;

    /*const Name *interface_name =*/ this->name(ast->interface_name);
    for (NameListAST *it = ast->constraint_list; it; it = it->next) {
        /*const Name *value =*/ this->name(it->value);
    }
}

bool Bind::visit(BaseSpecifierAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

391
void Bind::baseSpecifier(BaseSpecifierAST *ast, unsigned colon_token, Class *klass)
392
393
394
395
{
    if (! ast)
        return;

Roberto Raggi's avatar
Roberto Raggi committed
396
    unsigned sourceLocation = location(ast->name, ast->firstToken());
397
398
399
400
401
402
403
404
405
406
407
    if (! sourceLocation)
        sourceLocation = std::max(colon_token, klass->sourceLocation());

    const Name *baseClassName = this->name(ast->name);
    BaseClass *baseClass = control()->newBaseClass(sourceLocation, baseClassName);
    if (ast->virtual_token)
        baseClass->setVirtual(true);
    if (ast->access_specifier_token) {
        const int visibility = visibilityForAccessSpecifier(tokenKind(ast->access_specifier_token));
        baseClass->setVisibility(visibility); // ### well, not exactly.
    }
408
    klass->addBaseClass(baseClass);
409
    ast->symbol = baseClass;
410
411
412
413
414
415
416
417
418
}

bool Bind::visit(CtorInitializerAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
419
void Bind::ctorInitializer(CtorInitializerAST *ast, Function *fun)
420
421
422
423
424
425
{
    if (! ast)
        return;

    // unsigned colon_token = ast->colon_token;
    for (MemInitializerListAST *it = ast->member_initializer_list; it; it = it->next) {
Roberto Raggi's avatar
Roberto Raggi committed
426
        this->memInitializer(it->value, fun);
427
428
429
430
431
432
433
434
435
436
437
    }
    // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
}

bool Bind::visit(EnumeratorAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
438
void Bind::enumerator(EnumeratorAST *ast, Enum *symbol)
439
{
Roberto Raggi's avatar
Roberto Raggi committed
440
441
    (void) symbol;

442
443
444
445
446
    if (! ast)
        return;

    // unsigned identifier_token = ast->identifier_token;
    // unsigned equal_token = ast->equal_token;
447
    /*ExpressionTy expression =*/ this->expression(ast->expression);
Roberto Raggi's avatar
Roberto Raggi committed
448
449

    if (ast->identifier_token) {
450
        const Name *name = identifier(ast->identifier_token);
451
        EnumeratorDeclaration *e = control()->newEnumeratorDeclaration(ast->identifier_token, name);
Roberto Raggi's avatar
Roberto Raggi committed
452
        e->setType(control()->integerType(IntegerType::Int)); // ### introduce IntegerType::Enumerator
453
454
455
456
457

        if (ExpressionAST *expr = ast->expression) {
            e->setConstantValue(asStringLiteral(expr->firstToken(), expr->lastToken()));
        }

Roberto Raggi's avatar
Roberto Raggi committed
458
459
        symbol->addMember(e);
    }
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
}

bool Bind::visit(ExceptionSpecificationAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

FullySpecifiedType Bind::exceptionSpecification(ExceptionSpecificationAST *ast, const FullySpecifiedType &init)
{
    FullySpecifiedType type = init;

    if (! ast)
        return type;

    // unsigned throw_token = ast->throw_token;
    // unsigned lparen_token = ast->lparen_token;
    // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
    for (ExpressionListAST *it = ast->type_id_list; it; it = it->next) {
        ExpressionTy value = this->expression(it->value);
    }
    // unsigned rparen_token = ast->rparen_token;
    return type;
}

bool Bind::visit(MemInitializerAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
493
void Bind::memInitializer(MemInitializerAST *ast, Function *fun)
494
495
496
497
498
{
    if (! ast)
        return;

    /*const Name *name =*/ this->name(ast->name);
Roberto Raggi's avatar
Roberto Raggi committed
499
500

    Scope *previousScope = switchScope(fun);
501
502
503
    for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
        /*ExpressionTy value =*/ this->expression(it->value);
    }
Roberto Raggi's avatar
Roberto Raggi committed
504
    (void) switchScope(previousScope);
505
506
507
508
509
510
511
512
513
}

bool Bind::visit(NestedNameSpecifierAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
514
const Name *Bind::nestedNameSpecifier(NestedNameSpecifierAST *ast)
515
516
{
    if (! ast)
Roberto Raggi's avatar
Roberto Raggi committed
517
        return 0;
518

Roberto Raggi's avatar
Roberto Raggi committed
519
520
    const Name *class_or_namespace_name = this->name(ast->class_or_namespace_name);
    return class_or_namespace_name;
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
}

bool Bind::visit(NewPlacementAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::newPlacement(NewPlacementAST *ast)
{
    if (! ast)
        return;

    // unsigned lparen_token = ast->lparen_token;
    for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
        ExpressionTy value = this->expression(it->value);
    }
    // unsigned rparen_token = ast->rparen_token;
}

bool Bind::visit(NewArrayDeclaratorAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

FullySpecifiedType Bind::newArrayDeclarator(NewArrayDeclaratorAST *ast, const FullySpecifiedType &init)
{
    FullySpecifiedType type = init;

    if (! ast)
        return type;

    // unsigned lbracket_token = ast->lbracket_token;
    ExpressionTy expression = this->expression(ast->expression);
    // unsigned rbracket_token = ast->rbracket_token;
    return type;
}

bool Bind::visit(NewInitializerAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::newInitializer(NewInitializerAST *ast)
{
    if (! ast)
        return;

    // unsigned lparen_token = ast->lparen_token;
    ExpressionTy expression = this->expression(ast->expression);
    // unsigned rparen_token = ast->rparen_token;
}

bool Bind::visit(NewTypeIdAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

FullySpecifiedType Bind::newTypeId(NewTypeIdAST *ast)
{
    FullySpecifiedType type;

    if (! ast)
        return type;


    for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
    for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
        type = this->ptrOperator(it->value, type);
    }
    for (NewArrayDeclaratorListAST *it = ast->new_array_declarator_list; it; it = it->next) {
        type = this->newArrayDeclarator(it->value, type);
    }
    return type;
}

bool Bind::visit(OperatorAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

613
OperatorNameId::Kind Bind::cppOperator(OperatorAST *ast)
614
{
Roberto Raggi's avatar
Roberto Raggi committed
615
616
    OperatorNameId::Kind kind = OperatorNameId::InvalidOp;

617
    if (! ast)
Roberto Raggi's avatar
Roberto Raggi committed
618
        return kind;
619
620
621
622

    // unsigned op_token = ast->op_token;
    // unsigned open_token = ast->open_token;
    // unsigned close_token = ast->close_token;
Roberto Raggi's avatar
Roberto Raggi committed
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795

    switch (tokenKind(ast->op_token)) {
    case T_NEW:
        if (ast->open_token)
            kind = OperatorNameId::NewArrayOp;
        else
            kind = OperatorNameId::NewOp;
        break;

    case T_DELETE:
        if (ast->open_token)
            kind = OperatorNameId::DeleteArrayOp;
        else
            kind = OperatorNameId::DeleteOp;
        break;

    case T_PLUS:
        kind = OperatorNameId::PlusOp;
        break;

    case T_MINUS:
        kind = OperatorNameId::MinusOp;
        break;

    case T_STAR:
        kind = OperatorNameId::StarOp;
        break;

    case T_SLASH:
        kind = OperatorNameId::SlashOp;
        break;

    case T_PERCENT:
        kind = OperatorNameId::PercentOp;
        break;

    case T_CARET:
        kind = OperatorNameId::CaretOp;
        break;

    case T_AMPER:
        kind = OperatorNameId::AmpOp;
        break;

    case T_PIPE:
        kind = OperatorNameId::PipeOp;
        break;

    case T_TILDE:
        kind = OperatorNameId::TildeOp;
        break;

    case T_EXCLAIM:
        kind = OperatorNameId::ExclaimOp;
        break;

    case T_EQUAL:
        kind = OperatorNameId::EqualOp;
        break;

    case T_LESS:
        kind = OperatorNameId::LessOp;
        break;

    case T_GREATER:
        kind = OperatorNameId::GreaterOp;
        break;

    case T_PLUS_EQUAL:
        kind = OperatorNameId::PlusEqualOp;
        break;

    case T_MINUS_EQUAL:
        kind = OperatorNameId::MinusEqualOp;
        break;

    case T_STAR_EQUAL:
        kind = OperatorNameId::StarEqualOp;
        break;

    case T_SLASH_EQUAL:
        kind = OperatorNameId::SlashEqualOp;
        break;

    case T_PERCENT_EQUAL:
        kind = OperatorNameId::PercentEqualOp;
        break;

    case T_CARET_EQUAL:
        kind = OperatorNameId::CaretEqualOp;
        break;

    case T_AMPER_EQUAL:
        kind = OperatorNameId::AmpEqualOp;
        break;

    case T_PIPE_EQUAL:
        kind = OperatorNameId::PipeEqualOp;
        break;

    case T_LESS_LESS:
        kind = OperatorNameId::LessLessOp;
        break;

    case T_GREATER_GREATER:
        kind = OperatorNameId::GreaterGreaterOp;
        break;

    case T_LESS_LESS_EQUAL:
        kind = OperatorNameId::LessLessEqualOp;
        break;

    case T_GREATER_GREATER_EQUAL:
        kind = OperatorNameId::GreaterGreaterEqualOp;
        break;

    case T_EQUAL_EQUAL:
        kind = OperatorNameId::EqualEqualOp;
        break;

    case T_EXCLAIM_EQUAL:
        kind = OperatorNameId::ExclaimEqualOp;
        break;

    case T_LESS_EQUAL:
        kind = OperatorNameId::LessEqualOp;
        break;

    case T_GREATER_EQUAL:
        kind = OperatorNameId::GreaterEqualOp;
        break;

    case T_AMPER_AMPER:
        kind = OperatorNameId::AmpAmpOp;
        break;

    case T_PIPE_PIPE:
        kind = OperatorNameId::PipePipeOp;
        break;

    case T_PLUS_PLUS:
        kind = OperatorNameId::PlusPlusOp;
        break;

    case T_MINUS_MINUS:
        kind = OperatorNameId::MinusMinusOp;
        break;

    case T_COMMA:
        kind = OperatorNameId::CommaOp;
        break;

    case T_ARROW_STAR:
        kind = OperatorNameId::ArrowStarOp;
        break;

    case T_ARROW:
        kind = OperatorNameId::ArrowOp;
        break;

    case T_LPAREN:
        kind = OperatorNameId::FunctionCallOp;
        break;

    case T_LBRACKET:
        kind = OperatorNameId::ArrayAccessOp;
        break;

    default:
        kind = OperatorNameId::InvalidOp;
    } // switch

    return kind;
796
797
798
799
800
801
802
803
804
}

bool Bind::visit(ParameterDeclarationClauseAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

805
void Bind::parameterDeclarationClause(ParameterDeclarationClauseAST *ast, unsigned lparen_token, Function *fun)
806
807
808
809
{
    if (! ast)
        return;

810
811
812
813
814
815
816
    if (! fun) {
        translationUnit()->warning(lparen_token, "undefined function");
        return;
    }

    Scope *previousScope = switchScope(fun);

Roberto Raggi's avatar
Roberto Raggi committed
817
    for (ParameterDeclarationListAST *it = ast->parameter_declaration_list; it; it = it->next) {
818
819
        this->declaration(it->value);
    }
820
821
822
823
824

    if (ast->dot_dot_dot_token)
        fun->setVariadic(true);

    (void) switchScope(previousScope);
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
}

bool Bind::visit(TranslationUnitAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::translationUnit(TranslationUnitAST *ast)
{
    if (! ast)
        return;

    for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) {
        this->declaration(it->value);
    }
}

bool Bind::visit(ObjCProtocolRefsAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

851
void Bind::objCProtocolRefs(ObjCProtocolRefsAST *ast, Symbol *objcClassOrProtocol)
852
853
854
855
856
{
    if (! ast)
        return;

    for (NameListAST *it = ast->identifier_list; it; it = it->next) {
857
858
859
860
861
862
        const Name *protocolName = this->name(it->value);
        ObjCBaseProtocol *baseProtocol = control()->newObjCBaseProtocol(it->value->firstToken(), protocolName);
        if (ObjCClass *klass = objcClassOrProtocol->asObjCClass())
            klass->addProtocol(baseProtocol);
        else if (ObjCProtocol *proto = objcClassOrProtocol->asObjCProtocol())
            proto->addProtocol(baseProtocol);
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
    }
}

bool Bind::visit(ObjCMessageArgumentAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::objCMessageArgument(ObjCMessageArgumentAST *ast)
{
    if (! ast)
        return;

    ExpressionTy parameter_value_expression = this->expression(ast->parameter_value_expression);
}

bool Bind::visit(ObjCTypeNameAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
888
FullySpecifiedType Bind::objCTypeName(ObjCTypeNameAST *ast)
889
890
{
    if (! ast)
Roberto Raggi's avatar
Roberto Raggi committed
891
        return FullySpecifiedType();
892
893
894

    // unsigned type_qualifier_token = ast->type_qualifier_token;
    ExpressionTy type_id = this->expression(ast->type_id);
Roberto Raggi's avatar
Roberto Raggi committed
895
    return type_id;
896
897
898
899
900
901
902
903
904
}

bool Bind::visit(ObjCInstanceVariablesDeclarationAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

905
void Bind::objCInstanceVariablesDeclaration(ObjCInstanceVariablesDeclarationAST *ast, ObjCClass *klass)
906
{
907
908
    (void) klass;

909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
    if (! ast)
        return;

    // unsigned lbrace_token = ast->lbrace_token;
    for (DeclarationListAST *it = ast->instance_variable_list; it; it = it->next) {
        this->declaration(it->value);
    }
    // unsigned rbrace_token = ast->rbrace_token;
}

bool Bind::visit(ObjCPropertyAttributeAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::objCPropertyAttribute(ObjCPropertyAttributeAST *ast)
{
    if (! ast)
        return;

    // unsigned attribute_identifier_token = ast->attribute_identifier_token;
    // unsigned equals_token = ast->equals_token;
    /*const Name *method_selector =*/ this->name(ast->method_selector);
}

bool Bind::visit(ObjCMessageArgumentDeclarationAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
943
void Bind::objCMessageArgumentDeclaration(ObjCMessageArgumentDeclarationAST *ast, ObjCMethod *method)
944
945
946
947
{
    if (! ast)
        return;

Roberto Raggi's avatar
Roberto Raggi committed
948
949
    FullySpecifiedType type = this->objCTypeName(ast->type_name);

950
951
952
    for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
Roberto Raggi's avatar
Roberto Raggi committed
953
954

    const Name *param_name = this->name(ast->param_name);
Roberto Raggi's avatar
Roberto Raggi committed
955
    Argument *arg = control()->newArgument(location(ast->param_name, ast->firstToken()), param_name);
Roberto Raggi's avatar
Roberto Raggi committed
956
957
958
    arg->setType(type);
    ast->argument = arg;
    method->addMember(arg);
959
960
961
962
963
964
965
966
967
}

bool Bind::visit(ObjCMethodPrototypeAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

Roberto Raggi's avatar
Roberto Raggi committed
968
ObjCMethod *Bind::objCMethodPrototype(ObjCMethodPrototypeAST *ast)
969
970
{
    if (! ast)
Roberto Raggi's avatar
Roberto Raggi committed
971
        return 0;
972
973

    // unsigned method_type_token = ast->method_type_token;
Roberto Raggi's avatar
Roberto Raggi committed
974
975
976
    FullySpecifiedType returnType = this->objCTypeName(ast->type_name);
    const Name *selector = this->name(ast->selector);

Roberto Raggi's avatar
Roberto Raggi committed
977
    const unsigned sourceLocation = location(ast->selector, ast->firstToken());
Roberto Raggi's avatar
Roberto Raggi committed
978
979
980
981
982
983
984
985
986
    ObjCMethod *method = control()->newObjCMethod(sourceLocation, selector);
    // ### set the offsets
    method->setReturnType(returnType);
    if (isObjCClassMethod(tokenKind(ast->method_type_token)))
        method->setStorage(Symbol::Static);
    method->setVisibility(_objcVisibility);
    ast->symbol = method;

    Scope *previousScope = switchScope(method);
987
    for (ObjCMessageArgumentDeclarationListAST *it = ast->argument_list; it; it = it->next) {
Roberto Raggi's avatar
Roberto Raggi committed
988
        this->objCMessageArgumentDeclaration(it->value, method);
989
    }
Roberto Raggi's avatar
Roberto Raggi committed
990
991
992
993
994
995
    (void) switchScope(previousScope);

    if (ast->dot_dot_dot_token)
        method->setVariadic(true);

    FullySpecifiedType specifiers;
996
    for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
Roberto Raggi's avatar
Roberto Raggi committed
997
        specifiers = this->specifier(it->value, specifiers);
998
    }
Roberto Raggi's avatar
Roberto Raggi committed
999
    //setDeclSpecifiers(method, specifiers);
Roberto Raggi's avatar
Roberto Raggi committed
1000
1001

    return method;
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
}

bool Bind::visit(ObjCSynthesizedPropertyAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::objCSynthesizedProperty(ObjCSynthesizedPropertyAST *ast)
{
    if (! ast)
        return;

    // unsigned property_identifier_token = ast->property_identifier_token;
    // unsigned equals_token = ast->equals_token;
    // unsigned alias_identifier_token = ast->alias_identifier_token;
}

bool Bind::visit(LambdaIntroducerAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::lambdaIntroducer(LambdaIntroducerAST *ast)
{
    if (! ast)
        return;

    // unsigned lbracket_token = ast->lbracket_token;
    this->lambdaCapture(ast->lambda_capture);
    // unsigned rbracket_token = ast->rbracket_token;
}

bool Bind::visit(LambdaCaptureAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::lambdaCapture(LambdaCaptureAST *ast)
{
    if (! ast)
        return;

    // unsigned default_capture_token = ast->default_capture_token;
    for (CaptureListAST *it = ast->capture_list; it; it = it->next) {
        this->capture(it->value);
    }
}

bool Bind::visit(CaptureAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::capture(CaptureAST *ast)
{
    if (! ast)
        return;

}

bool Bind::visit(LambdaDeclaratorAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

void Bind::lambdaDeclarator(LambdaDeclaratorAST *ast)
{
    if (! ast)
        return;

1082
1083
1084

    Function *fun = 0; // ### implement me

1085
1086
    // unsigned lparen_token = ast->lparen_token;
    FullySpecifiedType type;
1087
    this->parameterDeclarationClause(ast->parameter_declaration_clause, ast->lparen_token, fun);
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
    // unsigned rparen_token = ast->rparen_token;
    for (SpecifierListAST *it = ast->attributes; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
    // unsigned mutable_token = ast->mutable_token;
    type = this->exceptionSpecification(ast->exception_specification, type);
    type = this->trailingReturnType(ast->trailing_return_type, type);
}

bool Bind::visit(TrailingReturnTypeAST *ast)
{
    (void) ast;
    assert(!"unreachable");
    return false;
}

FullySpecifiedType Bind::trailingReturnType(TrailingReturnTypeAST *ast, const FullySpecifiedType &init)
{
    FullySpecifiedType type = init;

    if (! ast)
        return type;

    // unsigned arrow_token = ast->arrow_token;
    for (SpecifierListAST *it = ast->attributes; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
Roberto Raggi's avatar
Roberto Raggi committed
1115
    for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1116
1117
        type = this->specifier(it->value, type);
    }
Roberto Raggi's avatar
Roberto Raggi committed
1118
1119
    DeclaratorIdAST *declaratorId = 0;
    type = this->declarator(ast->declarator, type, &declaratorId);
1120
1121
1122
    return type;
}

1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
const StringLiteral *Bind::asStringLiteral(unsigned firstToken, unsigned lastToken)
{
    std::string buffer;
    for (unsigned index = firstToken; index != lastToken; ++index) {
        const Token &tk = tokenAt(index);
        if (tk.whitespace() || tk.newline())
            buffer += ' ';
        buffer += tk.spell();
    }
    return control()->stringLiteral(buffer.c_str(), buffer.size());
}
1134
1135
1136
1137

// StatementAST
bool Bind::visit(QtMemberDeclarationAST *ast)
{
1138
1139
1140
    const Name *name = 0;

    if (tokenKind(ast->q_token) == T_Q_D)
1141
        name = control()->identifier("d");
1142
    else
1143
        name = control()->identifier("q");
1144
1145
1146
1147
1148

    FullySpecifiedType declTy = this->expression(ast->type_id);

    if (tokenKind(ast->q_token) == T_Q_D) {
        if (NamedType *namedTy = declTy->asNamedType()) {
1149
            if (const Identifier *nameId = namedTy->name()->asNameId()) {
1150
1151
1152
1153
                std::string privateClass;
                privateClass += nameId->identifier()->chars();
                privateClass += "Private";

1154
                const Name *privName = control()->identifier(privateClass.c_str(), privateClass.size());
1155
1156
1157
1158
1159
1160
1161
1162
1163
                declTy.setType(control()->namedType(privName));
            }
        }
    }

    Declaration *symbol = control()->newDeclaration(/*generated*/ 0, name);
    symbol->setType(control()->pointerType(declTy));

    _scope->addMember(symbol);
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
    return false;
}

bool Bind::visit(CaseStatementAST *ast)
{
    ExpressionTy expression = this->expression(ast->expression);
    this->statement(ast->statement);
    return false;
}

bool Bind::visit(CompoundStatementAST *ast)
{
Roberto Raggi's avatar
Roberto Raggi committed
1176
    Block *block = control()->newBlock(ast->firstToken());
1177
1178
    unsigned startScopeToken = ast->lbrace_token ? ast->lbrace_token : ast->firstToken();
    block->setStartOffset(tokenAt(startScopeToken).end());
Roberto Raggi's avatar
Roberto Raggi committed
1179
    block->setEndOffset(tokenAt(ast->lastToken() - 1).end());
Roberto Raggi's avatar
Roberto Raggi committed
1180
1181
1182
    ast->symbol = block;
    _scope->addMember(block);
    Scope *previousScope = switchScope(block);
1183
1184
1185
    for (StatementListAST *it = ast->statement_list; it; it = it->next) {
        this->statement(it->value);
    }
Roberto Raggi's avatar
Roberto Raggi committed
1186
    (void) switchScope(previousScope);
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
    return false;
}

bool Bind::visit(DeclarationStatementAST *ast)
{
    this->declaration(ast->declaration);
    return false;
}

bool Bind::visit(DoStatementAST *ast)
{
    this->statement(ast->statement);
    ExpressionTy expression = this->expression(ast->expression);
    return false;
}

bool Bind::visit(ExpressionOrDeclarationStatementAST *ast)
{
    this->statement(ast->expression);
    this->statement(ast->declaration);
    return false;
}

bool Bind::visit(ExpressionStatementAST *ast)
{
    ExpressionTy expression = this->expression(ast->expression);
    // unsigned semicolon_token = ast->semicolon_token;
    return false;
}

bool Bind::visit(ForeachStatementAST *ast)
{
1219
    Block *block = control()->newBlock(ast->firstToken());
1220
    const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1221
    block->setStartOffset(tokenAt(startScopeToken).end());
1222
    block->setEndOffset(tokenAt(ast->lastToken()).begin());
1223
1224
1225
1226
1227
    _scope->addMember(block);
    ast->symbol = block;

    Scope *previousScope = switchScope(block);

1228
1229
1230
1231
    FullySpecifiedType type;
    for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
Roberto Raggi's avatar
Roberto Raggi committed
1232
1233
    DeclaratorIdAST *declaratorId = 0;
    type = this->declarator(ast->declarator, type, &declaratorId);
1234
1235

    if (declaratorId && declaratorId->name) {
Roberto Raggi's avatar
Roberto Raggi committed
1236
        unsigned sourceLocation = location(declaratorId->name, ast->firstToken());
1237
1238
1239
1240
1241
        Declaration *decl = control()->newDeclaration(sourceLocation, declaratorId->name->name);
        decl->setType(type);
        block->addMember(decl);
    }

1242
1243
    /*ExpressionTy initializer =*/ this->expression(ast->initializer);
    /*ExpressionTy expression =*/ this->expression(ast->expression);
1244
    this->statement(ast->statement);
1245
    (void) switchScope(previousScope);
1246
1247
1248
1249
1250
    return false;
}

bool Bind::visit(ForStatementAST *ast)
{
1251
    Block *block = control()->newBlock(ast->firstToken());
1252
    const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1253
    block->setStartOffset(tokenAt(startScopeToken).end());
1254
    block->setEndOffset(tokenAt(ast->lastToken()).begin());
1255
1256
1257
1258
    _scope->addMember(block);
    ast->symbol = block;

    Scope *previousScope = switchScope(block);
1259
    this->statement(ast->initializer);
1260
    /*ExpressionTy condition =*/ this->expression(ast->condition);
1261
    // unsigned semicolon_token = ast->semicolon_token;
1262
    /*ExpressionTy expression =*/ this->expression(ast->expression);
1263
1264
    // unsigned rparen_token = ast->rparen_token;
    this->statement(ast->statement);
1265
    (void) switchScope(previousScope);
1266
1267
1268
1269
1270
    return false;
}

bool Bind::visit(IfStatementAST *ast)
{
1271
    Block *block = control()->newBlock(ast->firstToken());
1272
    const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1273
    block->setStartOffset(tokenAt(startScopeToken).end());
1274
    block->setEndOffset(tokenAt(ast->lastToken()).begin());
1275
1276
1277
1278
    _scope->addMember(block);
    ast->symbol = block;

    Scope *previousScope = switchScope(block);
1279
    /*ExpressionTy condition =*/ this->expression(ast->condition);
1280
1281
    this->statement(ast->statement);
    this->statement(ast->else_statement);
1282
    (void) switchScope(previousScope);
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
    return false;
}

bool Bind::visit(LabeledStatementAST *ast)
{
    // unsigned label_token = ast->label_token;
    // unsigned colon_token = ast->colon_token;
    this->statement(ast->statement);
    return false;
}

bool Bind::visit(BreakStatementAST *ast)
{
Roberto Raggi's avatar
Roberto Raggi committed
1296
    (void) ast;
1297
1298
1299
1300
1301
1302
1303
    // unsigned break_token = ast->break_token;
    // unsigned semicolon_token = ast->semicolon_token;
    return false;
}

bool Bind::visit(ContinueStatementAST *ast)
{
Roberto Raggi's avatar
Roberto Raggi committed
1304
    (void) ast;
1305
1306
1307
1308
1309
1310
1311
    // unsigned continue_token = ast->continue_token;
    // unsigned semicolon_token = ast->semicolon_token;
    return false;
}

bool Bind::visit(GotoStatementAST *ast)
{
Roberto Raggi's avatar
Roberto Raggi committed
1312
    (void) ast;
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
    // unsigned goto_token = ast->goto_token;
    // unsigned identifier_token = ast->identifier_token;
    // unsigned semicolon_token = ast->semicolon_token;
    return false;
}

bool Bind::visit(ReturnStatementAST *ast)
{
    ExpressionTy expression = this->expression(ast->expression);
    return false;
}

bool Bind::visit(SwitchStatementAST *ast)
{
1327
    Block *block = control()->newBlock(ast->firstToken());
1328
    const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1329
    block->setStartOffset(tokenAt(startScopeToken).end());
1330
    block->setEndOffset(tokenAt(ast->lastToken()).begin());
1331
1332
1333
1334
    _scope->addMember(block);
    ast->symbol = block;

    Scope *previousScope = switchScope(block);
1335
    /*ExpressionTy condition =*/ this->expression(ast->condition);
1336
    this->statement(ast->statement);
1337
    (void) switchScope(previousScope);
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
    return false;
}

bool Bind::visit(TryBlockStatementAST *ast)
{
    // unsigned try_token = ast->try_token;
    this->statement(ast->statement);
    for (CatchClauseListAST *it = ast->catch_clause_list; it; it = it->next) {
        this->statement(it->value);
    }
    return false;
}

bool Bind::visit(CatchClauseAST *ast)
{
1353
    Block *block = control()->newBlock(ast->firstToken());
1354
    const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1355
    block->setStartOffset(tokenAt(startScopeToken).end());
1356
    block->setEndOffset(tokenAt(ast->lastToken()).begin());
1357
1358
1359
1360
    _scope->addMember(block);
    ast->symbol = block;

    Scope *previousScope = switchScope(block);
1361
1362
1363
    this->declaration(ast->exception_declaration);
    // unsigned rparen_token = ast->rparen_token;
    this->statement(ast->statement);
1364
    (void) switchScope(previousScope);
1365
1366
1367
1368
1369
    return false;
}

bool Bind::visit(WhileStatementAST *ast)
{
1370
    Block *block = control()->newBlock(ast->firstToken());
1371
    const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1372
    block->setStartOffset(tokenAt(startScopeToken).end());
1373
    block->setEndOffset(tokenAt(ast->lastToken()).begin());
1374
1375
1376
1377
    _scope->addMember(block);
    ast->symbol = block;

    Scope *previousScope = switchScope(block);
1378
    /*ExpressionTy condition =*/ this->expression(ast->condition);
1379
    this->statement(ast->statement);
1380
    (void) switchScope(previousScope);
1381
1382
1383
1384
1385
    return false;
}

bool Bind::visit(ObjCFastEnumerationAST *ast)
{
1386
    Block *block = control()->newBlock(ast->firstToken());
1387
    const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1388
    block->setStartOffset(tokenAt(startScopeToken).end());
1389
    block->setEndOffset(tokenAt(ast->lastToken()).begin());
1390
1391
1392
1393
    _scope->addMember(block);
    ast->symbol = block;

    Scope *previousScope = switchScope(block);
1394
1395
1396
1397
    FullySpecifiedType type;
    for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
Roberto Raggi's avatar
Roberto Raggi committed
1398
1399
    DeclaratorIdAST *declaratorId = 0;
    type = this->declarator(ast->declarator, type, &declaratorId);
1400
1401

    if (declaratorId && declaratorId->name) {
Roberto Raggi's avatar
Roberto Raggi committed
1402
        unsigned sourceLocation = location(declaratorId->name, ast->firstToken());
1403
1404
1405
1406
1407
        Declaration *decl = control()->newDeclaration(sourceLocation, declaratorId->name->name);
        decl->setType(type);
        block->addMember(decl);
    }

1408
1409
    /*ExpressionTy initializer =*/ this->expression(ast->initializer);
    /*ExpressionTy fast_enumeratable_expression =*/ this->expression(ast->fast_enumeratable_expression);
1410
    this->statement(ast->statement);
1411
    (void) switchScope(previousScope);
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
    return false;
}

bool Bind::visit(ObjCSynchronizedStatementAST *ast)
{
    // unsigned synchronized_token = ast->synchronized_token;
    // unsigned lparen_token = ast->lparen_token;
    ExpressionTy synchronized_object = this->expression(ast->synchronized_object);
    // unsigned rparen_token = ast->rparen_token;
    this->statement(ast->statement);
    return false;
}


// ExpressionAST
bool Bind::visit(IdExpressionAST *ast)
{
    /*const Name *name =*/ this->name(ast->name);
    return false;
}

bool Bind::visit(CompoundExpressionAST *ast)
{
    // unsigned lparen_token = ast->lparen_token;
    this->statement(ast->statement);
    // unsigned rparen_token = ast->rparen_token;
    return false;
}

bool Bind::visit(CompoundLiteralAST *ast)
{
    // unsigned lparen_token = ast->lparen_token;
    ExpressionTy type_id = this->expression(ast->type_id);
    // unsigned rparen_token = ast->rparen_token;
    ExpressionTy initializer = this->expression(ast->initializer);
    return false;
}

bool Bind::visit(QtMethodAST *ast)
{
    // unsigned method_token = ast->method_token;
    // unsigned lparen_token = ast->lparen_token;
    FullySpecifiedType type;
Roberto Raggi's avatar
Roberto Raggi committed
1455
1456
    DeclaratorIdAST *declaratorId = 0;
    type = this->declarator(ast->declarator, type, &declaratorId);
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
    // unsigned rparen_token = ast->rparen_token;
    return false;
}

bool Bind::visit(BinaryExpressionAST *ast)
{
    ExpressionTy left_expression = this->expression(ast->left_expression);
    // unsigned binary_op_token = ast->binary_op_token;
    ExpressionTy right_expression = this->expression(ast->right_expression);
    return false;
}

bool Bind::visit(CastExpressionAST *ast)
{
    // unsigned lparen_token = ast->lparen_token;
    ExpressionTy type_id = this->expression(ast->type_id);
    // unsigned rparen_token = ast->rparen_token;
    ExpressionTy expression = this->expression(ast->expression);
    return false;
}

bool Bind::visit(ConditionAST *ast)
{
    FullySpecifiedType type;
    for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
Roberto Raggi's avatar
Roberto Raggi committed
1484
1485
    DeclaratorIdAST *declaratorId = 0;
    type = this->declarator(ast->declarator, type, &declaratorId);
1486
1487

    if (declaratorId && declaratorId->name) {
Roberto Raggi's avatar
Roberto Raggi committed
1488
        unsigned sourceLocation = location(declaratorId->name, ast->firstToken());
1489
1490
1491
1492
1493
        Declaration *decl = control()->newDeclaration(sourceLocation, declaratorId->name->name);
        decl->setType(type);
        _scope->addMember(decl);
    }

1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
    return false;
}

bool Bind::visit(ConditionalExpressionAST *ast)
{
    ExpressionTy condition = this->expression(ast->condition);
    // unsigned question_token = ast->question_token;
    ExpressionTy left_expression = this->expression(ast->left_expression);
    // unsigned colon_token = ast->colon_token;
    ExpressionTy right_expression = this->expression(ast->right_expression);
    return false;
}

bool Bind::visit(CppCastExpressionAST *ast)
{
    // unsigned cast_token = ast->cast_token;
    // unsigned less_token = ast->less_token;
    ExpressionTy type_id = this->expression(ast->type_id);
    // unsigned greater_token = ast->greater_token;
    // unsigned lparen_token = ast->lparen_token;
    ExpressionTy expression = this->expression(ast->expression);
    // unsigned rparen_token = ast->rparen_token;
    return false;
}

bool Bind::visit(DeleteExpressionAST *ast)
{
    // unsigned scope_token = ast->scope_token;
    // unsigned delete_token = ast->delete_token;
    // unsigned lbracket_token = ast->lbracket_token;
    // unsigned rbracket_token = ast->rbracket_token;
    ExpressionTy expression = this->expression(ast->expression);
    return false;
}

bool Bind::visit(ArrayInitializerAST *ast)
{
    // unsigned lbrace_token = ast->lbrace_token;
    for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
        ExpressionTy value = this->expression(it->value);
    }
    // unsigned rbrace_token = ast->rbrace_token;
    return false;
}

bool Bind::visit(NewExpressionAST *ast)
{
    // unsigned scope_token = ast->scope_token;
    // unsigned new_token = ast->new_token;
    this->newPlacement(ast->new_placement);
    // unsigned lparen_token = ast->lparen_token;
    ExpressionTy type_id = this->expression(ast->type_id);
    // unsigned rparen_token = ast->rparen_token;
    this->newTypeId(ast->new_type_id);
    this->newInitializer(ast->new_initializer);
    return false;
}

bool Bind::visit(TypeidExpressionAST *ast)
{
    // unsigned typeid_token = ast->typeid_token;
    // unsigned lparen_token = ast->lparen_token;
    ExpressionTy expression = this->expression(ast->expression);
    // unsigned rparen_token = ast->rparen_token;
    return false;
}

bool Bind::visit(TypenameCallExpressionAST *ast)
{
    // unsigned typename_token = ast->typename_token;
    /*const Name *name =*/ this->name(ast->name);
    // unsigned lparen_token = ast->lparen_token;
    for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
        ExpressionTy value = this->expression(it->value);
    }
    // unsigned rparen_token = ast->rparen_token;
    return false;
}

bool Bind::visit(TypeConstructorCallAST *ast)
{
    FullySpecifiedType type;
    for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
    // unsigned lparen_token = ast->lparen_token;
    for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
        ExpressionTy value = this->expression(it->value);
    }
    // unsigned rparen_token = ast->rparen_token;
    return false;
}

bool Bind::visit(SizeofExpressionAST *ast)
{
    // unsigned sizeof_token = ast->sizeof_token;
    // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
    // unsigned lparen_token = ast->lparen_token;
    ExpressionTy expression = this->expression(ast->expression);
    // unsigned rparen_token = ast->rparen_token;
    return false;
}

bool Bind::visit(NumericLiteralAST *ast)
{
Roberto Raggi's avatar
Roberto Raggi committed
1599
    (void) ast;
1600
1601
1602
1603
1604
1605
    // unsigned literal_token = ast->literal_token;
    return false;
}

bool Bind::visit(BoolLiteralAST *ast)
{
Roberto Raggi's avatar
Roberto Raggi committed
1606
    (void) ast;
1607
1608
1609
1610
1611
1612
    // unsigned literal_token = ast->literal_token;
    return false;
}

bool Bind::visit(ThisExpressionAST *ast)
{
Roberto Raggi's avatar
Roberto Raggi committed
1613
    (void) ast;
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
    // unsigned this_token = ast->this_token;
    return false;
}

bool Bind::visit(NestedExpressionAST *ast)
{
    // unsigned lparen_token = ast->lparen_token;
    ExpressionTy expression = this->expression(ast->expression);
    // unsigned rparen_token = ast->rparen_token;
    return false;
}

bool Bind::visit(StringLiteralAST *ast)
{
    // unsigned literal_token = ast->literal_token;
    ExpressionTy next = this->expression(ast->next);
    return false;
}

bool Bind::visit(ThrowExpressionAST *ast)
{
    // unsigned throw_token = ast->throw_token;
    ExpressionTy expression = this->expression(ast->expression);
    return false;
}

bool Bind::visit(TypeIdAST *ast)
{
    FullySpecifiedType type;
    for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
        type = this->specifier(it->value, type);
    }
Roberto Raggi's avatar
Roberto Raggi committed
1646
1647
    DeclaratorIdAST *declaratorId = 0;
    type = this->declarator(ast->declarator, type, &declaratorId);
Roberto Raggi's avatar
Roberto Raggi committed
1648
    _expression = type;
1649
1650