OSDN Git Service

a3291e400f8408f95b9ecb817e3ea71e3bec654e
[qt-creator-jp/qt-creator-jp.git] / src / shared / cplusplus / Bind.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining a copy
36 // of this software and associated documentation files (the "Software"), to deal
37 // in the Software without restriction, including without limitation the rights
38 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39 // copies of the Software, and to permit persons to whom the Software is
40 // furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
51 // THE SOFTWARE.
52
53 #include "Bind.h"
54 #include "AST.h"
55 #include "TranslationUnit.h"
56 #include "Control.h"
57 #include "Names.h"
58 #include "Symbols.h"
59 #include "CoreTypes.h"
60 #include "Literals.h"
61 #include "Scope.h"
62 #include <vector>
63 #include <string>
64 #include <memory>
65 #include <cassert>
66
67 using namespace CPlusPlus;
68
69 const int Bind::kMaxDepth(100);
70
71 Bind::Bind(TranslationUnit *unit)
72     : ASTVisitor(unit),
73       _scope(0),
74       _expression(0),
75       _name(0),
76       _declaratorId(0),
77       _visibility(Symbol::Public),
78       _objcVisibility(Symbol::Public),
79       _methodKey(Function::NormalMethod),
80       _skipFunctionBodies(false),
81       _depth(0)
82 {
83 }
84
85 bool Bind::skipFunctionBodies() const
86 {
87     return _skipFunctionBodies;
88 }
89
90 void Bind::setSkipFunctionBodies(bool skipFunctionBodies)
91 {
92     _skipFunctionBodies = skipFunctionBodies;
93 }
94
95 unsigned Bind::location(DeclaratorAST *ast, unsigned defaultLocation) const
96 {
97     if (! ast)
98         return defaultLocation;
99
100     else if (ast->core_declarator)
101         return location(ast->core_declarator, defaultLocation);
102
103     return ast->firstToken();
104 }
105
106 unsigned Bind::location(CoreDeclaratorAST *ast, unsigned defaultLocation) const
107 {
108     if (! ast)
109         return defaultLocation;
110
111     else if (NestedDeclaratorAST *nested = ast->asNestedDeclarator())
112         return location(nested->declarator, defaultLocation);
113
114     else if (DeclaratorIdAST *id = ast->asDeclaratorId())
115         return location(id->name, defaultLocation);
116
117     return ast->firstToken();
118 }
119
120 unsigned Bind::location(NameAST *name, unsigned defaultLocation) const
121 {
122     if (! name)
123         return defaultLocation;
124
125     else if (DestructorNameAST *dtor = name->asDestructorName())
126         return dtor->identifier_token;
127
128     else if (TemplateIdAST *templId = name->asTemplateId())
129         return templId->identifier_token;
130
131     else if (QualifiedNameAST *q = name->asQualifiedName()) {
132         if (q->unqualified_name)
133             return location(q->unqualified_name, defaultLocation);
134     }
135
136     return name->firstToken();
137 }
138
139 void Bind::setDeclSpecifiers(Symbol *symbol, const FullySpecifiedType &declSpecifiers)
140 {
141     if (! symbol)
142         return;
143
144     int storage = Symbol::NoStorage;
145
146     if (declSpecifiers.isFriend())
147         storage = Symbol::Friend;
148     else if (declSpecifiers.isAuto())
149         storage = Symbol::Auto;
150     else if (declSpecifiers.isRegister())
151         storage = Symbol::Register;
152     else if (declSpecifiers.isStatic())
153         storage = Symbol::Static;
154     else if (declSpecifiers.isExtern())
155         storage = Symbol::Extern;
156     else if (declSpecifiers.isMutable())
157         storage = Symbol::Mutable;
158     else if (declSpecifiers.isTypedef())
159         storage = Symbol::Typedef;
160
161     symbol->setStorage(storage);
162
163     if (Function *funTy = symbol->asFunction()) {
164         if (declSpecifiers.isVirtual()) {
165             funTy->setVirtual(true);
166         }
167     }
168
169     if (declSpecifiers.isDeprecated())
170         symbol->setDeprecated(true);
171
172     if (declSpecifiers.isUnavailable())
173         symbol->setUnavailable(true);
174 }
175
176 Scope *Bind::switchScope(Scope *scope)
177 {
178     if (! scope)
179         return _scope;
180
181     std::swap(_scope, scope);
182     return scope;
183 }
184
185 int Bind::switchVisibility(int visibility)
186 {
187     std::swap(_visibility, visibility);
188     return visibility;
189 }
190
191 int Bind::switchObjCVisibility(int visibility)
192 {
193     std::swap(_objcVisibility, visibility);
194     return visibility;
195 }
196
197 int Bind::switchMethodKey(int methodKey)
198 {
199     std::swap(_methodKey, methodKey);
200     return methodKey;
201 }
202
203 void Bind::operator()(TranslationUnitAST *ast, Namespace *globalNamespace)
204 {
205     Scope *previousScope = switchScope(globalNamespace);
206     translationUnit(ast);
207     (void) switchScope(previousScope);
208 }
209
210 void Bind::operator()(DeclarationAST *ast, Scope *scope)
211 {
212     Scope *previousScope = switchScope(scope);
213     declaration(ast);
214     (void) switchScope(previousScope);
215 }
216
217 FullySpecifiedType Bind::operator()(ExpressionAST *ast, Scope *scope)
218 {
219     Scope *previousScope = switchScope(scope);
220     FullySpecifiedType ty = expression(ast);
221     (void) switchScope(previousScope);
222     return ty;
223 }
224
225 FullySpecifiedType Bind::operator()(NewTypeIdAST *ast, Scope *scope)
226 {
227     Scope *previousScope = switchScope(scope);
228     FullySpecifiedType ty = newTypeId(ast);
229     (void) switchScope(previousScope);
230     return ty;
231 }
232
233 void Bind::statement(StatementAST *ast)
234 {
235     accept(ast);
236 }
237
238 Bind::ExpressionTy Bind::expression(ExpressionAST *ast)
239 {
240     ExpressionTy value = ExpressionTy();
241     std::swap(_expression, value);
242     accept(ast);
243     std::swap(_expression, value);
244     return value;
245 }
246
247 void Bind::declaration(DeclarationAST *ast)
248 {
249     accept(ast);
250 }
251
252 const Name *Bind::name(NameAST *ast)
253 {
254     const Name *value = 0;
255     std::swap(_name, value);
256     accept(ast);
257     std::swap(_name, value);
258     return value;
259 }
260
261 FullySpecifiedType Bind::specifier(SpecifierAST *ast, const FullySpecifiedType &init)
262 {
263     FullySpecifiedType value = init;
264     std::swap(_type, value);
265     accept(ast);
266     std::swap(_type, value);
267     return value;
268 }
269
270 FullySpecifiedType Bind::ptrOperator(PtrOperatorAST *ast, const FullySpecifiedType &init)
271 {
272     FullySpecifiedType value = init;
273     std::swap(_type, value);
274     accept(ast);
275     std::swap(_type, value);
276     return value;
277 }
278
279 FullySpecifiedType Bind::coreDeclarator(CoreDeclaratorAST *ast, const FullySpecifiedType &init)
280 {
281     FullySpecifiedType value = init;
282     std::swap(_type, value);
283     accept(ast);
284     std::swap(_type, value);
285     return value;
286 }
287
288 FullySpecifiedType Bind::postfixDeclarator(PostfixDeclaratorAST *ast, const FullySpecifiedType &init)
289 {
290     FullySpecifiedType value = init;
291     std::swap(_type, value);
292     accept(ast);
293     std::swap(_type, value);
294     return value;
295 }
296
297 bool Bind::preVisit(AST *)
298 {
299     ++_depth;
300     if (_depth > kMaxDepth)
301         return false;
302     return true;
303 }
304
305 void Bind::postVisit(AST *)
306 {
307     --_depth;
308 }
309
310 // AST
311 bool Bind::visit(ObjCSelectorArgumentAST *ast)
312 {
313     (void) ast;
314     assert(!"unreachable");
315     return false;
316 }
317
318 const Name *Bind::objCSelectorArgument(ObjCSelectorArgumentAST *ast, bool *hasArg)
319 {
320     if (! (ast && ast->name_token))
321         return 0;
322
323     if (ast->colon_token)
324         *hasArg = true;
325
326     return identifier(ast->name_token);
327 }
328
329 bool Bind::visit(AttributeAST *ast)
330 {
331     (void) ast;
332     assert(!"unreachable");
333     return false;
334 }
335
336 void Bind::attribute(AttributeAST *ast)
337 {
338     if (! ast)
339         return;
340
341     // unsigned identifier_token = ast->identifier_token;
342     if (const Identifier *id = identifier(ast->identifier_token)) {
343         if (id == control()->deprecatedId())
344             _type.setDeprecated(true);
345         else if (id == control()->unavailableId())
346             _type.setUnavailable(true);
347     }
348
349     // unsigned lparen_token = ast->lparen_token;
350     // unsigned tag_token = ast->tag_token;
351     for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
352         ExpressionTy value = this->expression(it->value);
353     }
354     // unsigned rparen_token = ast->rparen_token;
355 }
356
357 bool Bind::visit(DeclaratorAST *ast)
358 {
359     (void) ast;
360     assert(!"unreachable");
361     return false;
362 }
363
364 FullySpecifiedType Bind::declarator(DeclaratorAST *ast, const FullySpecifiedType &init, DeclaratorIdAST **declaratorId)
365 {
366     FullySpecifiedType type = init;
367
368     if (! ast)
369         return type;
370
371     std::swap(_declaratorId, declaratorId);
372     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
373         type = this->specifier(it->value, type);
374     }
375     for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
376         type = this->ptrOperator(it->value, type);
377     }
378     for (PostfixDeclaratorListAST *it = ast->postfix_declarator_list; it; it = it->next) {
379         type = this->postfixDeclarator(it->value, type);
380     }
381     type = this->coreDeclarator(ast->core_declarator, type);
382     for (SpecifierListAST *it = ast->post_attribute_list; it; it = it->next) {
383         type = this->specifier(it->value, type);
384     }
385     // unsigned equals_token = ast->equals_token;
386     ExpressionTy initializer = this->expression(ast->initializer);
387     std::swap(_declaratorId, declaratorId);
388     return type;
389 }
390
391 bool Bind::visit(QtPropertyDeclarationItemAST *ast)
392 {
393     (void) ast;
394     assert(!"unreachable");
395     return false;
396 }
397
398 bool Bind::visit(QtInterfaceNameAST *ast)
399 {
400     (void) ast;
401     assert(!"unreachable");
402     return false;
403 }
404
405 void Bind::qtInterfaceName(QtInterfaceNameAST *ast)
406 {
407     if (! ast)
408         return;
409
410     /*const Name *interface_name =*/ this->name(ast->interface_name);
411     for (NameListAST *it = ast->constraint_list; it; it = it->next) {
412         /*const Name *value =*/ this->name(it->value);
413     }
414 }
415
416 bool Bind::visit(BaseSpecifierAST *ast)
417 {
418     (void) ast;
419     assert(!"unreachable");
420     return false;
421 }
422
423 void Bind::baseSpecifier(BaseSpecifierAST *ast, unsigned colon_token, Class *klass)
424 {
425     if (! ast)
426         return;
427
428     unsigned sourceLocation = location(ast->name, ast->firstToken());
429     if (! sourceLocation)
430         sourceLocation = std::max(colon_token, klass->sourceLocation());
431
432     const Name *baseClassName = this->name(ast->name);
433     BaseClass *baseClass = control()->newBaseClass(sourceLocation, baseClassName);
434     if (ast->virtual_token)
435         baseClass->setVirtual(true);
436     if (ast->access_specifier_token) {
437         const int visibility = visibilityForAccessSpecifier(tokenKind(ast->access_specifier_token));
438         baseClass->setVisibility(visibility); // ### well, not exactly.
439     }
440     klass->addBaseClass(baseClass);
441     ast->symbol = baseClass;
442 }
443
444 bool Bind::visit(CtorInitializerAST *ast)
445 {
446     (void) ast;
447     assert(!"unreachable");
448     return false;
449 }
450
451 void Bind::ctorInitializer(CtorInitializerAST *ast, Function *fun)
452 {
453     if (! ast)
454         return;
455
456     // unsigned colon_token = ast->colon_token;
457     for (MemInitializerListAST *it = ast->member_initializer_list; it; it = it->next) {
458         this->memInitializer(it->value, fun);
459     }
460     // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
461 }
462
463 bool Bind::visit(EnumeratorAST *ast)
464 {
465     (void) ast;
466     assert(!"unreachable");
467     return false;
468 }
469
470 void Bind::enumerator(EnumeratorAST *ast, Enum *symbol)
471 {
472     (void) symbol;
473
474     if (! ast)
475         return;
476
477     // unsigned identifier_token = ast->identifier_token;
478     // unsigned equal_token = ast->equal_token;
479     ExpressionTy expression = this->expression(ast->expression);
480
481     if (ast->identifier_token) {
482         const Name *name = identifier(ast->identifier_token);
483         Declaration *e = control()->newDeclaration(ast->identifier_token, name);
484         e->setType(control()->integerType(IntegerType::Int)); // ### introduce IntegerType::Enumerator
485         symbol->addMember(e);
486     }
487 }
488
489 bool Bind::visit(ExceptionSpecificationAST *ast)
490 {
491     (void) ast;
492     assert(!"unreachable");
493     return false;
494 }
495
496 FullySpecifiedType Bind::exceptionSpecification(ExceptionSpecificationAST *ast, const FullySpecifiedType &init)
497 {
498     FullySpecifiedType type = init;
499
500     if (! ast)
501         return type;
502
503     // unsigned throw_token = ast->throw_token;
504     // unsigned lparen_token = ast->lparen_token;
505     // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
506     for (ExpressionListAST *it = ast->type_id_list; it; it = it->next) {
507         ExpressionTy value = this->expression(it->value);
508     }
509     // unsigned rparen_token = ast->rparen_token;
510     return type;
511 }
512
513 bool Bind::visit(MemInitializerAST *ast)
514 {
515     (void) ast;
516     assert(!"unreachable");
517     return false;
518 }
519
520 void Bind::memInitializer(MemInitializerAST *ast, Function *fun)
521 {
522     if (! ast)
523         return;
524
525     /*const Name *name =*/ this->name(ast->name);
526
527     Scope *previousScope = switchScope(fun);
528     for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
529         /*ExpressionTy value =*/ this->expression(it->value);
530     }
531     (void) switchScope(previousScope);
532 }
533
534 bool Bind::visit(NestedNameSpecifierAST *ast)
535 {
536     (void) ast;
537     assert(!"unreachable");
538     return false;
539 }
540
541 const Name *Bind::nestedNameSpecifier(NestedNameSpecifierAST *ast)
542 {
543     if (! ast)
544         return 0;
545
546     const Name *class_or_namespace_name = this->name(ast->class_or_namespace_name);
547     return class_or_namespace_name;
548 }
549
550 bool Bind::visit(NewPlacementAST *ast)
551 {
552     (void) ast;
553     assert(!"unreachable");
554     return false;
555 }
556
557 void Bind::newPlacement(NewPlacementAST *ast)
558 {
559     if (! ast)
560         return;
561
562     // unsigned lparen_token = ast->lparen_token;
563     for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
564         ExpressionTy value = this->expression(it->value);
565     }
566     // unsigned rparen_token = ast->rparen_token;
567 }
568
569 bool Bind::visit(NewArrayDeclaratorAST *ast)
570 {
571     (void) ast;
572     assert(!"unreachable");
573     return false;
574 }
575
576 FullySpecifiedType Bind::newArrayDeclarator(NewArrayDeclaratorAST *ast, const FullySpecifiedType &init)
577 {
578     FullySpecifiedType type = init;
579
580     if (! ast)
581         return type;
582
583     // unsigned lbracket_token = ast->lbracket_token;
584     ExpressionTy expression = this->expression(ast->expression);
585     // unsigned rbracket_token = ast->rbracket_token;
586     return type;
587 }
588
589 bool Bind::visit(NewInitializerAST *ast)
590 {
591     (void) ast;
592     assert(!"unreachable");
593     return false;
594 }
595
596 void Bind::newInitializer(NewInitializerAST *ast)
597 {
598     if (! ast)
599         return;
600
601     // unsigned lparen_token = ast->lparen_token;
602     ExpressionTy expression = this->expression(ast->expression);
603     // unsigned rparen_token = ast->rparen_token;
604 }
605
606 bool Bind::visit(NewTypeIdAST *ast)
607 {
608     (void) ast;
609     assert(!"unreachable");
610     return false;
611 }
612
613 FullySpecifiedType Bind::newTypeId(NewTypeIdAST *ast)
614 {
615     FullySpecifiedType type;
616
617     if (! ast)
618         return type;
619
620
621     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
622         type = this->specifier(it->value, type);
623     }
624     for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
625         type = this->ptrOperator(it->value, type);
626     }
627     for (NewArrayDeclaratorListAST *it = ast->new_array_declarator_list; it; it = it->next) {
628         type = this->newArrayDeclarator(it->value, type);
629     }
630     return type;
631 }
632
633 bool Bind::visit(OperatorAST *ast)
634 {
635     (void) ast;
636     assert(!"unreachable");
637     return false;
638 }
639
640 OperatorNameId::Kind Bind::cppOperator(OperatorAST *ast)
641 {
642     OperatorNameId::Kind kind = OperatorNameId::InvalidOp;
643
644     if (! ast)
645         return kind;
646
647     // unsigned op_token = ast->op_token;
648     // unsigned open_token = ast->open_token;
649     // unsigned close_token = ast->close_token;
650
651     switch (tokenKind(ast->op_token)) {
652     case T_NEW:
653         if (ast->open_token)
654             kind = OperatorNameId::NewArrayOp;
655         else
656             kind = OperatorNameId::NewOp;
657         break;
658
659     case T_DELETE:
660         if (ast->open_token)
661             kind = OperatorNameId::DeleteArrayOp;
662         else
663             kind = OperatorNameId::DeleteOp;
664         break;
665
666     case T_PLUS:
667         kind = OperatorNameId::PlusOp;
668         break;
669
670     case T_MINUS:
671         kind = OperatorNameId::MinusOp;
672         break;
673
674     case T_STAR:
675         kind = OperatorNameId::StarOp;
676         break;
677
678     case T_SLASH:
679         kind = OperatorNameId::SlashOp;
680         break;
681
682     case T_PERCENT:
683         kind = OperatorNameId::PercentOp;
684         break;
685
686     case T_CARET:
687         kind = OperatorNameId::CaretOp;
688         break;
689
690     case T_AMPER:
691         kind = OperatorNameId::AmpOp;
692         break;
693
694     case T_PIPE:
695         kind = OperatorNameId::PipeOp;
696         break;
697
698     case T_TILDE:
699         kind = OperatorNameId::TildeOp;
700         break;
701
702     case T_EXCLAIM:
703         kind = OperatorNameId::ExclaimOp;
704         break;
705
706     case T_EQUAL:
707         kind = OperatorNameId::EqualOp;
708         break;
709
710     case T_LESS:
711         kind = OperatorNameId::LessOp;
712         break;
713
714     case T_GREATER:
715         kind = OperatorNameId::GreaterOp;
716         break;
717
718     case T_PLUS_EQUAL:
719         kind = OperatorNameId::PlusEqualOp;
720         break;
721
722     case T_MINUS_EQUAL:
723         kind = OperatorNameId::MinusEqualOp;
724         break;
725
726     case T_STAR_EQUAL:
727         kind = OperatorNameId::StarEqualOp;
728         break;
729
730     case T_SLASH_EQUAL:
731         kind = OperatorNameId::SlashEqualOp;
732         break;
733
734     case T_PERCENT_EQUAL:
735         kind = OperatorNameId::PercentEqualOp;
736         break;
737
738     case T_CARET_EQUAL:
739         kind = OperatorNameId::CaretEqualOp;
740         break;
741
742     case T_AMPER_EQUAL:
743         kind = OperatorNameId::AmpEqualOp;
744         break;
745
746     case T_PIPE_EQUAL:
747         kind = OperatorNameId::PipeEqualOp;
748         break;
749
750     case T_LESS_LESS:
751         kind = OperatorNameId::LessLessOp;
752         break;
753
754     case T_GREATER_GREATER:
755         kind = OperatorNameId::GreaterGreaterOp;
756         break;
757
758     case T_LESS_LESS_EQUAL:
759         kind = OperatorNameId::LessLessEqualOp;
760         break;
761
762     case T_GREATER_GREATER_EQUAL:
763         kind = OperatorNameId::GreaterGreaterEqualOp;
764         break;
765
766     case T_EQUAL_EQUAL:
767         kind = OperatorNameId::EqualEqualOp;
768         break;
769
770     case T_EXCLAIM_EQUAL:
771         kind = OperatorNameId::ExclaimEqualOp;
772         break;
773
774     case T_LESS_EQUAL:
775         kind = OperatorNameId::LessEqualOp;
776         break;
777
778     case T_GREATER_EQUAL:
779         kind = OperatorNameId::GreaterEqualOp;
780         break;
781
782     case T_AMPER_AMPER:
783         kind = OperatorNameId::AmpAmpOp;
784         break;
785
786     case T_PIPE_PIPE:
787         kind = OperatorNameId::PipePipeOp;
788         break;
789
790     case T_PLUS_PLUS:
791         kind = OperatorNameId::PlusPlusOp;
792         break;
793
794     case T_MINUS_MINUS:
795         kind = OperatorNameId::MinusMinusOp;
796         break;
797
798     case T_COMMA:
799         kind = OperatorNameId::CommaOp;
800         break;
801
802     case T_ARROW_STAR:
803         kind = OperatorNameId::ArrowStarOp;
804         break;
805
806     case T_ARROW:
807         kind = OperatorNameId::ArrowOp;
808         break;
809
810     case T_LPAREN:
811         kind = OperatorNameId::FunctionCallOp;
812         break;
813
814     case T_LBRACKET:
815         kind = OperatorNameId::ArrayAccessOp;
816         break;
817
818     default:
819         kind = OperatorNameId::InvalidOp;
820     } // switch
821
822     return kind;
823 }
824
825 bool Bind::visit(ParameterDeclarationClauseAST *ast)
826 {
827     (void) ast;
828     assert(!"unreachable");
829     return false;
830 }
831
832 void Bind::parameterDeclarationClause(ParameterDeclarationClauseAST *ast, unsigned lparen_token, Function *fun)
833 {
834     if (! ast)
835         return;
836
837     if (! fun) {
838         translationUnit()->warning(lparen_token, "undefined function");
839         return;
840     }
841
842     Scope *previousScope = switchScope(fun);
843
844     for (ParameterDeclarationListAST *it = ast->parameter_declaration_list; it; it = it->next) {
845         this->declaration(it->value);
846     }
847
848     if (ast->dot_dot_dot_token)
849         fun->setVariadic(true);
850
851     (void) switchScope(previousScope);
852 }
853
854 bool Bind::visit(TranslationUnitAST *ast)
855 {
856     (void) ast;
857     assert(!"unreachable");
858     return false;
859 }
860
861 void Bind::translationUnit(TranslationUnitAST *ast)
862 {
863     if (! ast)
864         return;
865
866     for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) {
867         this->declaration(it->value);
868     }
869 }
870
871 bool Bind::visit(ObjCProtocolRefsAST *ast)
872 {
873     (void) ast;
874     assert(!"unreachable");
875     return false;
876 }
877
878 void Bind::objCProtocolRefs(ObjCProtocolRefsAST *ast, Symbol *objcClassOrProtocol)
879 {
880     if (! ast)
881         return;
882
883     for (NameListAST *it = ast->identifier_list; it; it = it->next) {
884         const Name *protocolName = this->name(it->value);
885         ObjCBaseProtocol *baseProtocol = control()->newObjCBaseProtocol(it->value->firstToken(), protocolName);
886         if (ObjCClass *klass = objcClassOrProtocol->asObjCClass())
887             klass->addProtocol(baseProtocol);
888         else if (ObjCProtocol *proto = objcClassOrProtocol->asObjCProtocol())
889             proto->addProtocol(baseProtocol);
890     }
891 }
892
893 bool Bind::visit(ObjCMessageArgumentAST *ast)
894 {
895     (void) ast;
896     assert(!"unreachable");
897     return false;
898 }
899
900 void Bind::objCMessageArgument(ObjCMessageArgumentAST *ast)
901 {
902     if (! ast)
903         return;
904
905     ExpressionTy parameter_value_expression = this->expression(ast->parameter_value_expression);
906 }
907
908 bool Bind::visit(ObjCTypeNameAST *ast)
909 {
910     (void) ast;
911     assert(!"unreachable");
912     return false;
913 }
914
915 FullySpecifiedType Bind::objCTypeName(ObjCTypeNameAST *ast)
916 {
917     if (! ast)
918         return FullySpecifiedType();
919
920     // unsigned type_qualifier_token = ast->type_qualifier_token;
921     ExpressionTy type_id = this->expression(ast->type_id);
922     return type_id;
923 }
924
925 bool Bind::visit(ObjCInstanceVariablesDeclarationAST *ast)
926 {
927     (void) ast;
928     assert(!"unreachable");
929     return false;
930 }
931
932 void Bind::objCInstanceVariablesDeclaration(ObjCInstanceVariablesDeclarationAST *ast, ObjCClass *klass)
933 {
934     (void) klass;
935
936     if (! ast)
937         return;
938
939     // unsigned lbrace_token = ast->lbrace_token;
940     for (DeclarationListAST *it = ast->instance_variable_list; it; it = it->next) {
941         this->declaration(it->value);
942     }
943     // unsigned rbrace_token = ast->rbrace_token;
944 }
945
946 bool Bind::visit(ObjCPropertyAttributeAST *ast)
947 {
948     (void) ast;
949     assert(!"unreachable");
950     return false;
951 }
952
953 void Bind::objCPropertyAttribute(ObjCPropertyAttributeAST *ast)
954 {
955     if (! ast)
956         return;
957
958     // unsigned attribute_identifier_token = ast->attribute_identifier_token;
959     // unsigned equals_token = ast->equals_token;
960     /*const Name *method_selector =*/ this->name(ast->method_selector);
961 }
962
963 bool Bind::visit(ObjCMessageArgumentDeclarationAST *ast)
964 {
965     (void) ast;
966     assert(!"unreachable");
967     return false;
968 }
969
970 void Bind::objCMessageArgumentDeclaration(ObjCMessageArgumentDeclarationAST *ast, ObjCMethod *method)
971 {
972     if (! ast)
973         return;
974
975     FullySpecifiedType type = this->objCTypeName(ast->type_name);
976
977     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
978         type = this->specifier(it->value, type);
979     }
980
981     const Name *param_name = this->name(ast->param_name);
982     Argument *arg = control()->newArgument(location(ast->param_name, ast->firstToken()), param_name);
983     arg->setType(type);
984     ast->argument = arg;
985     method->addMember(arg);
986 }
987
988 bool Bind::visit(ObjCMethodPrototypeAST *ast)
989 {
990     (void) ast;
991     assert(!"unreachable");
992     return false;
993 }
994
995 ObjCMethod *Bind::objCMethodPrototype(ObjCMethodPrototypeAST *ast)
996 {
997     if (! ast)
998         return 0;
999
1000     // unsigned method_type_token = ast->method_type_token;
1001     FullySpecifiedType returnType = this->objCTypeName(ast->type_name);
1002     const Name *selector = this->name(ast->selector);
1003
1004     const unsigned sourceLocation = location(ast->selector, ast->firstToken());
1005     ObjCMethod *method = control()->newObjCMethod(sourceLocation, selector);
1006     // ### set the offsets
1007     method->setReturnType(returnType);
1008     if (isObjCClassMethod(tokenKind(ast->method_type_token)))
1009         method->setStorage(Symbol::Static);
1010     method->setVisibility(_objcVisibility);
1011     ast->symbol = method;
1012
1013     Scope *previousScope = switchScope(method);
1014     for (ObjCMessageArgumentDeclarationListAST *it = ast->argument_list; it; it = it->next) {
1015         this->objCMessageArgumentDeclaration(it->value, method);
1016     }
1017     (void) switchScope(previousScope);
1018
1019     if (ast->dot_dot_dot_token)
1020         method->setVariadic(true);
1021
1022     FullySpecifiedType specifiers;
1023     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
1024         specifiers = this->specifier(it->value, specifiers);
1025     }
1026     //setDeclSpecifiers(method, specifiers);
1027
1028     return method;
1029 }
1030
1031 bool Bind::visit(ObjCSynthesizedPropertyAST *ast)
1032 {
1033     (void) ast;
1034     assert(!"unreachable");
1035     return false;
1036 }
1037
1038 void Bind::objCSynthesizedProperty(ObjCSynthesizedPropertyAST *ast)
1039 {
1040     if (! ast)
1041         return;
1042
1043     // unsigned property_identifier_token = ast->property_identifier_token;
1044     // unsigned equals_token = ast->equals_token;
1045     // unsigned alias_identifier_token = ast->alias_identifier_token;
1046 }
1047
1048 bool Bind::visit(LambdaIntroducerAST *ast)
1049 {
1050     (void) ast;
1051     assert(!"unreachable");
1052     return false;
1053 }
1054
1055 void Bind::lambdaIntroducer(LambdaIntroducerAST *ast)
1056 {
1057     if (! ast)
1058         return;
1059
1060     // unsigned lbracket_token = ast->lbracket_token;
1061     this->lambdaCapture(ast->lambda_capture);
1062     // unsigned rbracket_token = ast->rbracket_token;
1063 }
1064
1065 bool Bind::visit(LambdaCaptureAST *ast)
1066 {
1067     (void) ast;
1068     assert(!"unreachable");
1069     return false;
1070 }
1071
1072 void Bind::lambdaCapture(LambdaCaptureAST *ast)
1073 {
1074     if (! ast)
1075         return;
1076
1077     // unsigned default_capture_token = ast->default_capture_token;
1078     for (CaptureListAST *it = ast->capture_list; it; it = it->next) {
1079         this->capture(it->value);
1080     }
1081 }
1082
1083 bool Bind::visit(CaptureAST *ast)
1084 {
1085     (void) ast;
1086     assert(!"unreachable");
1087     return false;
1088 }
1089
1090 void Bind::capture(CaptureAST *ast)
1091 {
1092     if (! ast)
1093         return;
1094
1095 }
1096
1097 bool Bind::visit(LambdaDeclaratorAST *ast)
1098 {
1099     (void) ast;
1100     assert(!"unreachable");
1101     return false;
1102 }
1103
1104 void Bind::lambdaDeclarator(LambdaDeclaratorAST *ast)
1105 {
1106     if (! ast)
1107         return;
1108
1109
1110     Function *fun = 0; // ### implement me
1111
1112     // unsigned lparen_token = ast->lparen_token;
1113     FullySpecifiedType type;
1114     this->parameterDeclarationClause(ast->parameter_declaration_clause, ast->lparen_token, fun);
1115     // unsigned rparen_token = ast->rparen_token;
1116     for (SpecifierListAST *it = ast->attributes; it; it = it->next) {
1117         type = this->specifier(it->value, type);
1118     }
1119     // unsigned mutable_token = ast->mutable_token;
1120     type = this->exceptionSpecification(ast->exception_specification, type);
1121     type = this->trailingReturnType(ast->trailing_return_type, type);
1122 }
1123
1124 bool Bind::visit(TrailingReturnTypeAST *ast)
1125 {
1126     (void) ast;
1127     assert(!"unreachable");
1128     return false;
1129 }
1130
1131 FullySpecifiedType Bind::trailingReturnType(TrailingReturnTypeAST *ast, const FullySpecifiedType &init)
1132 {
1133     FullySpecifiedType type = init;
1134
1135     if (! ast)
1136         return type;
1137
1138     // unsigned arrow_token = ast->arrow_token;
1139     for (SpecifierListAST *it = ast->attributes; it; it = it->next) {
1140         type = this->specifier(it->value, type);
1141     }
1142     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1143         type = this->specifier(it->value, type);
1144     }
1145     DeclaratorIdAST *declaratorId = 0;
1146     type = this->declarator(ast->declarator, type, &declaratorId);
1147     return type;
1148 }
1149
1150
1151 // StatementAST
1152 bool Bind::visit(QtMemberDeclarationAST *ast)
1153 {
1154     const Name *name = 0;
1155
1156     if (tokenKind(ast->q_token) == T_Q_D)
1157         name = control()->identifier("d");
1158     else
1159         name = control()->identifier("q");
1160
1161     FullySpecifiedType declTy = this->expression(ast->type_id);
1162
1163     if (tokenKind(ast->q_token) == T_Q_D) {
1164         if (NamedType *namedTy = declTy->asNamedType()) {
1165             if (const Identifier *nameId = namedTy->name()->asNameId()) {
1166                 std::string privateClass;
1167                 privateClass += nameId->identifier()->chars();
1168                 privateClass += "Private";
1169
1170                 const Name *privName = control()->identifier(privateClass.c_str(), privateClass.size());
1171                 declTy.setType(control()->namedType(privName));
1172             }
1173         }
1174     }
1175
1176     Declaration *symbol = control()->newDeclaration(/*generated*/ 0, name);
1177     symbol->setType(control()->pointerType(declTy));
1178
1179     _scope->addMember(symbol);
1180     return false;
1181 }
1182
1183 bool Bind::visit(CaseStatementAST *ast)
1184 {
1185     ExpressionTy expression = this->expression(ast->expression);
1186     this->statement(ast->statement);
1187     return false;
1188 }
1189
1190 bool Bind::visit(CompoundStatementAST *ast)
1191 {
1192     Block *block = control()->newBlock(ast->firstToken());
1193     unsigned startScopeToken = ast->lbrace_token ? ast->lbrace_token : ast->firstToken();
1194     block->setStartOffset(tokenAt(startScopeToken).end());
1195     block->setEndOffset(tokenAt(ast->lastToken() - 1).end());
1196     ast->symbol = block;
1197     _scope->addMember(block);
1198     Scope *previousScope = switchScope(block);
1199     for (StatementListAST *it = ast->statement_list; it; it = it->next) {
1200         this->statement(it->value);
1201     }
1202     (void) switchScope(previousScope);
1203     return false;
1204 }
1205
1206 bool Bind::visit(DeclarationStatementAST *ast)
1207 {
1208     this->declaration(ast->declaration);
1209     return false;
1210 }
1211
1212 bool Bind::visit(DoStatementAST *ast)
1213 {
1214     this->statement(ast->statement);
1215     ExpressionTy expression = this->expression(ast->expression);
1216     return false;
1217 }
1218
1219 bool Bind::visit(ExpressionOrDeclarationStatementAST *ast)
1220 {
1221     this->statement(ast->expression);
1222     this->statement(ast->declaration);
1223     return false;
1224 }
1225
1226 bool Bind::visit(ExpressionStatementAST *ast)
1227 {
1228     ExpressionTy expression = this->expression(ast->expression);
1229     // unsigned semicolon_token = ast->semicolon_token;
1230     return false;
1231 }
1232
1233 bool Bind::visit(ForeachStatementAST *ast)
1234 {
1235     Block *block = control()->newBlock(ast->firstToken());
1236     const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1237     block->setStartOffset(tokenAt(startScopeToken).end());
1238     block->setEndOffset(tokenAt(ast->lastToken()).begin());
1239     _scope->addMember(block);
1240     ast->symbol = block;
1241
1242     Scope *previousScope = switchScope(block);
1243
1244     FullySpecifiedType type;
1245     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1246         type = this->specifier(it->value, type);
1247     }
1248     DeclaratorIdAST *declaratorId = 0;
1249     type = this->declarator(ast->declarator, type, &declaratorId);
1250
1251     if (declaratorId && declaratorId->name) {
1252         unsigned sourceLocation = location(declaratorId->name, ast->firstToken());
1253         Declaration *decl = control()->newDeclaration(sourceLocation, declaratorId->name->name);
1254         decl->setType(type);
1255         block->addMember(decl);
1256     }
1257
1258     /*ExpressionTy initializer =*/ this->expression(ast->initializer);
1259     /*ExpressionTy expression =*/ this->expression(ast->expression);
1260     this->statement(ast->statement);
1261     (void) switchScope(previousScope);
1262     return false;
1263 }
1264
1265 bool Bind::visit(ForStatementAST *ast)
1266 {
1267     Block *block = control()->newBlock(ast->firstToken());
1268     const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1269     block->setStartOffset(tokenAt(startScopeToken).end());
1270     block->setEndOffset(tokenAt(ast->lastToken()).begin());
1271     _scope->addMember(block);
1272     ast->symbol = block;
1273
1274     Scope *previousScope = switchScope(block);
1275     this->statement(ast->initializer);
1276     /*ExpressionTy condition =*/ this->expression(ast->condition);
1277     // unsigned semicolon_token = ast->semicolon_token;
1278     /*ExpressionTy expression =*/ this->expression(ast->expression);
1279     // unsigned rparen_token = ast->rparen_token;
1280     this->statement(ast->statement);
1281     (void) switchScope(previousScope);
1282     return false;
1283 }
1284
1285 bool Bind::visit(IfStatementAST *ast)
1286 {
1287     Block *block = control()->newBlock(ast->firstToken());
1288     const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1289     block->setStartOffset(tokenAt(startScopeToken).end());
1290     block->setEndOffset(tokenAt(ast->lastToken()).begin());
1291     _scope->addMember(block);
1292     ast->symbol = block;
1293
1294     Scope *previousScope = switchScope(block);
1295     /*ExpressionTy condition =*/ this->expression(ast->condition);
1296     this->statement(ast->statement);
1297     this->statement(ast->else_statement);
1298     (void) switchScope(previousScope);
1299     return false;
1300 }
1301
1302 bool Bind::visit(LabeledStatementAST *ast)
1303 {
1304     // unsigned label_token = ast->label_token;
1305     // unsigned colon_token = ast->colon_token;
1306     this->statement(ast->statement);
1307     return false;
1308 }
1309
1310 bool Bind::visit(BreakStatementAST *ast)
1311 {
1312     (void) ast;
1313     // unsigned break_token = ast->break_token;
1314     // unsigned semicolon_token = ast->semicolon_token;
1315     return false;
1316 }
1317
1318 bool Bind::visit(ContinueStatementAST *ast)
1319 {
1320     (void) ast;
1321     // unsigned continue_token = ast->continue_token;
1322     // unsigned semicolon_token = ast->semicolon_token;
1323     return false;
1324 }
1325
1326 bool Bind::visit(GotoStatementAST *ast)
1327 {
1328     (void) ast;
1329     // unsigned goto_token = ast->goto_token;
1330     // unsigned identifier_token = ast->identifier_token;
1331     // unsigned semicolon_token = ast->semicolon_token;
1332     return false;
1333 }
1334
1335 bool Bind::visit(ReturnStatementAST *ast)
1336 {
1337     ExpressionTy expression = this->expression(ast->expression);
1338     return false;
1339 }
1340
1341 bool Bind::visit(SwitchStatementAST *ast)
1342 {
1343     Block *block = control()->newBlock(ast->firstToken());
1344     const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1345     block->setStartOffset(tokenAt(startScopeToken).end());
1346     block->setEndOffset(tokenAt(ast->lastToken()).begin());
1347     _scope->addMember(block);
1348     ast->symbol = block;
1349
1350     Scope *previousScope = switchScope(block);
1351     /*ExpressionTy condition =*/ this->expression(ast->condition);
1352     this->statement(ast->statement);
1353     (void) switchScope(previousScope);
1354     return false;
1355 }
1356
1357 bool Bind::visit(TryBlockStatementAST *ast)
1358 {
1359     // unsigned try_token = ast->try_token;
1360     this->statement(ast->statement);
1361     for (CatchClauseListAST *it = ast->catch_clause_list; it; it = it->next) {
1362         this->statement(it->value);
1363     }
1364     return false;
1365 }
1366
1367 bool Bind::visit(CatchClauseAST *ast)
1368 {
1369     Block *block = control()->newBlock(ast->firstToken());
1370     const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1371     block->setStartOffset(tokenAt(startScopeToken).end());
1372     block->setEndOffset(tokenAt(ast->lastToken()).begin());
1373     _scope->addMember(block);
1374     ast->symbol = block;
1375
1376     Scope *previousScope = switchScope(block);
1377     this->declaration(ast->exception_declaration);
1378     // unsigned rparen_token = ast->rparen_token;
1379     this->statement(ast->statement);
1380     (void) switchScope(previousScope);
1381     return false;
1382 }
1383
1384 bool Bind::visit(WhileStatementAST *ast)
1385 {
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     _scope->addMember(block);
1391     ast->symbol = block;
1392
1393     Scope *previousScope = switchScope(block);
1394     /*ExpressionTy condition =*/ this->expression(ast->condition);
1395     this->statement(ast->statement);
1396     (void) switchScope(previousScope);
1397     return false;
1398 }
1399
1400 bool Bind::visit(ObjCFastEnumerationAST *ast)
1401 {
1402     Block *block = control()->newBlock(ast->firstToken());
1403     const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1404     block->setStartOffset(tokenAt(startScopeToken).end());
1405     block->setEndOffset(tokenAt(ast->lastToken()).begin());
1406     _scope->addMember(block);
1407     ast->symbol = block;
1408
1409     Scope *previousScope = switchScope(block);
1410     FullySpecifiedType type;
1411     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1412         type = this->specifier(it->value, type);
1413     }
1414     DeclaratorIdAST *declaratorId = 0;
1415     type = this->declarator(ast->declarator, type, &declaratorId);
1416
1417     if (declaratorId && declaratorId->name) {
1418         unsigned sourceLocation = location(declaratorId->name, ast->firstToken());
1419         Declaration *decl = control()->newDeclaration(sourceLocation, declaratorId->name->name);
1420         decl->setType(type);
1421         block->addMember(decl);
1422     }
1423
1424     /*ExpressionTy initializer =*/ this->expression(ast->initializer);
1425     /*ExpressionTy fast_enumeratable_expression =*/ this->expression(ast->fast_enumeratable_expression);
1426     this->statement(ast->statement);
1427     (void) switchScope(previousScope);
1428     return false;
1429 }
1430
1431 bool Bind::visit(ObjCSynchronizedStatementAST *ast)
1432 {
1433     // unsigned synchronized_token = ast->synchronized_token;
1434     // unsigned lparen_token = ast->lparen_token;
1435     ExpressionTy synchronized_object = this->expression(ast->synchronized_object);
1436     // unsigned rparen_token = ast->rparen_token;
1437     this->statement(ast->statement);
1438     return false;
1439 }
1440
1441
1442 // ExpressionAST
1443 bool Bind::visit(IdExpressionAST *ast)
1444 {
1445     /*const Name *name =*/ this->name(ast->name);
1446     return false;
1447 }
1448
1449 bool Bind::visit(CompoundExpressionAST *ast)
1450 {
1451     // unsigned lparen_token = ast->lparen_token;
1452     this->statement(ast->statement);
1453     // unsigned rparen_token = ast->rparen_token;
1454     return false;
1455 }
1456
1457 bool Bind::visit(CompoundLiteralAST *ast)
1458 {
1459     // unsigned lparen_token = ast->lparen_token;
1460     ExpressionTy type_id = this->expression(ast->type_id);
1461     // unsigned rparen_token = ast->rparen_token;
1462     ExpressionTy initializer = this->expression(ast->initializer);
1463     return false;
1464 }
1465
1466 bool Bind::visit(QtMethodAST *ast)
1467 {
1468     // unsigned method_token = ast->method_token;
1469     // unsigned lparen_token = ast->lparen_token;
1470     FullySpecifiedType type;
1471     DeclaratorIdAST *declaratorId = 0;
1472     type = this->declarator(ast->declarator, type, &declaratorId);
1473     // unsigned rparen_token = ast->rparen_token;
1474     return false;
1475 }
1476
1477 bool Bind::visit(BinaryExpressionAST *ast)
1478 {
1479     ExpressionTy left_expression = this->expression(ast->left_expression);
1480     // unsigned binary_op_token = ast->binary_op_token;
1481     ExpressionTy right_expression = this->expression(ast->right_expression);
1482     return false;
1483 }
1484
1485 bool Bind::visit(CastExpressionAST *ast)
1486 {
1487     // unsigned lparen_token = ast->lparen_token;
1488     ExpressionTy type_id = this->expression(ast->type_id);
1489     // unsigned rparen_token = ast->rparen_token;
1490     ExpressionTy expression = this->expression(ast->expression);
1491     return false;
1492 }
1493
1494 bool Bind::visit(ConditionAST *ast)
1495 {
1496     FullySpecifiedType type;
1497     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1498         type = this->specifier(it->value, type);
1499     }
1500     DeclaratorIdAST *declaratorId = 0;
1501     type = this->declarator(ast->declarator, type, &declaratorId);
1502
1503     if (declaratorId && declaratorId->name) {
1504         unsigned sourceLocation = location(declaratorId->name, ast->firstToken());
1505         Declaration *decl = control()->newDeclaration(sourceLocation, declaratorId->name->name);
1506         decl->setType(type);
1507         _scope->addMember(decl);
1508     }
1509
1510     return false;
1511 }
1512
1513 bool Bind::visit(ConditionalExpressionAST *ast)
1514 {
1515     ExpressionTy condition = this->expression(ast->condition);
1516     // unsigned question_token = ast->question_token;
1517     ExpressionTy left_expression = this->expression(ast->left_expression);
1518     // unsigned colon_token = ast->colon_token;
1519     ExpressionTy right_expression = this->expression(ast->right_expression);
1520     return false;
1521 }
1522
1523 bool Bind::visit(CppCastExpressionAST *ast)
1524 {
1525     // unsigned cast_token = ast->cast_token;
1526     // unsigned less_token = ast->less_token;
1527     ExpressionTy type_id = this->expression(ast->type_id);
1528     // unsigned greater_token = ast->greater_token;
1529     // unsigned lparen_token = ast->lparen_token;
1530     ExpressionTy expression = this->expression(ast->expression);
1531     // unsigned rparen_token = ast->rparen_token;
1532     return false;
1533 }
1534
1535 bool Bind::visit(DeleteExpressionAST *ast)
1536 {
1537     // unsigned scope_token = ast->scope_token;
1538     // unsigned delete_token = ast->delete_token;
1539     // unsigned lbracket_token = ast->lbracket_token;
1540     // unsigned rbracket_token = ast->rbracket_token;
1541     ExpressionTy expression = this->expression(ast->expression);
1542     return false;
1543 }
1544
1545 bool Bind::visit(ArrayInitializerAST *ast)
1546 {
1547     // unsigned lbrace_token = ast->lbrace_token;
1548     for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
1549         ExpressionTy value = this->expression(it->value);
1550     }
1551     // unsigned rbrace_token = ast->rbrace_token;
1552     return false;
1553 }
1554
1555 bool Bind::visit(NewExpressionAST *ast)
1556 {
1557     // unsigned scope_token = ast->scope_token;
1558     // unsigned new_token = ast->new_token;
1559     this->newPlacement(ast->new_placement);
1560     // unsigned lparen_token = ast->lparen_token;
1561     ExpressionTy type_id = this->expression(ast->type_id);
1562     // unsigned rparen_token = ast->rparen_token;
1563     this->newTypeId(ast->new_type_id);
1564     this->newInitializer(ast->new_initializer);
1565     return false;
1566 }
1567
1568 bool Bind::visit(TypeidExpressionAST *ast)
1569 {
1570     // unsigned typeid_token = ast->typeid_token;
1571     // unsigned lparen_token = ast->lparen_token;
1572     ExpressionTy expression = this->expression(ast->expression);
1573     // unsigned rparen_token = ast->rparen_token;
1574     return false;
1575 }
1576
1577 bool Bind::visit(TypenameCallExpressionAST *ast)
1578 {
1579     // unsigned typename_token = ast->typename_token;
1580     /*const Name *name =*/ this->name(ast->name);
1581     // unsigned lparen_token = ast->lparen_token;
1582     for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
1583         ExpressionTy value = this->expression(it->value);
1584     }
1585     // unsigned rparen_token = ast->rparen_token;
1586     return false;
1587 }
1588
1589 bool Bind::visit(TypeConstructorCallAST *ast)
1590 {
1591     FullySpecifiedType type;
1592     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1593         type = this->specifier(it->value, type);
1594     }
1595     // unsigned lparen_token = ast->lparen_token;
1596     for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
1597         ExpressionTy value = this->expression(it->value);
1598     }
1599     // unsigned rparen_token = ast->rparen_token;
1600     return false;
1601 }
1602
1603 bool Bind::visit(SizeofExpressionAST *ast)
1604 {
1605     // unsigned sizeof_token = ast->sizeof_token;
1606     // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
1607     // unsigned lparen_token = ast->lparen_token;
1608     ExpressionTy expression = this->expression(ast->expression);
1609     // unsigned rparen_token = ast->rparen_token;
1610     return false;
1611 }
1612
1613 bool Bind::visit(NumericLiteralAST *ast)
1614 {
1615     (void) ast;
1616     // unsigned literal_token = ast->literal_token;
1617     return false;
1618 }
1619
1620 bool Bind::visit(BoolLiteralAST *ast)
1621 {
1622     (void) ast;
1623     // unsigned literal_token = ast->literal_token;
1624     return false;
1625 }
1626
1627 bool Bind::visit(ThisExpressionAST *ast)
1628 {
1629     (void) ast;
1630     // unsigned this_token = ast->this_token;
1631     return false;
1632 }
1633
1634 bool Bind::visit(NestedExpressionAST *ast)
1635 {
1636     // unsigned lparen_token = ast->lparen_token;
1637     ExpressionTy expression = this->expression(ast->expression);
1638     // unsigned rparen_token = ast->rparen_token;
1639     return false;
1640 }
1641
1642 bool Bind::visit(StringLiteralAST *ast)
1643 {
1644     // unsigned literal_token = ast->literal_token;
1645     ExpressionTy next = this->expression(ast->next);
1646     return false;
1647 }
1648
1649 bool Bind::visit(ThrowExpressionAST *ast)
1650 {
1651     // unsigned throw_token = ast->throw_token;
1652     ExpressionTy expression = this->expression(ast->expression);
1653     return false;
1654 }
1655
1656 bool Bind::visit(TypeIdAST *ast)
1657 {
1658     FullySpecifiedType type;
1659     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1660         type = this->specifier(it->value, type);
1661     }
1662     DeclaratorIdAST *declaratorId = 0;
1663     type = this->declarator(ast->declarator, type, &declaratorId);
1664     _expression = type;
1665     return false;
1666 }
1667
1668 bool Bind::visit(UnaryExpressionAST *ast)
1669 {
1670     // unsigned unary_op_token = ast->unary_op_token;
1671     ExpressionTy expression = this->expression(ast->expression);
1672     return false;
1673 }
1674
1675 bool Bind::visit(ObjCMessageExpressionAST *ast)
1676 {
1677     // unsigned lbracket_token = ast->lbracket_token;
1678     /*ExpressionTy receiver_expression =*/ this->expression(ast->receiver_expression);
1679     /*const Name *selector =*/ this->name(ast->selector);
1680     for (ObjCMessageArgumentListAST *it = ast->argument_list; it; it = it->next) {
1681         this->objCMessageArgument(it->value);
1682     }
1683     // unsigned rbracket_token = ast->rbracket_token;
1684     return false;
1685 }
1686
1687 bool Bind::visit(ObjCProtocolExpressionAST *ast)
1688 {
1689     (void) ast;
1690     // unsigned protocol_token = ast->protocol_token;
1691     // unsigned lparen_token = ast->lparen_token;
1692     // unsigned identifier_token = ast->identifier_token;
1693     // unsigned rparen_token = ast->rparen_token;
1694     return false;
1695 }
1696
1697 bool Bind::visit(ObjCEncodeExpressionAST *ast)
1698 {
1699     // unsigned encode_token = ast->encode_token;
1700     FullySpecifiedType type = this->objCTypeName(ast->type_name);
1701     return false;
1702 }
1703
1704 bool Bind::visit(ObjCSelectorExpressionAST *ast)
1705 {
1706     // unsigned selector_token = ast->selector_token;
1707     // unsigned lparen_token = ast->lparen_token;
1708     /*const Name *selector =*/ this->name(ast->selector);
1709     // unsigned rparen_token = ast->rparen_token;
1710     return false;
1711 }
1712
1713 bool Bind::visit(LambdaExpressionAST *ast)
1714 {
1715     this->lambdaIntroducer(ast->lambda_introducer);
1716     this->lambdaDeclarator(ast->lambda_declarator);
1717     this->statement(ast->statement);
1718     return false;
1719 }
1720
1721 bool Bind::visit(BracedInitializerAST *ast)
1722 {
1723     // unsigned lbrace_token = ast->lbrace_token;
1724     for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
1725         ExpressionTy value = this->expression(it->value);
1726     }
1727     // unsigned comma_token = ast->comma_token;
1728     // unsigned rbrace_token = ast->rbrace_token;
1729     return false;
1730 }
1731
1732 static int methodKeyForInvokableToken(int kind)
1733 {
1734     if (kind == T_Q_SIGNAL)
1735         return Function::SignalMethod;
1736     else if (kind == T_Q_SLOT)
1737         return Function::SlotMethod;
1738     else if (kind == T_Q_INVOKABLE)
1739         return Function::InvokableMethod;
1740
1741     return Function::NormalMethod;
1742 }
1743
1744 // DeclarationAST
1745 bool Bind::visit(SimpleDeclarationAST *ast)
1746 {
1747     int methodKey = _methodKey;
1748     if (ast->qt_invokable_token)
1749         methodKey = methodKeyForInvokableToken(tokenKind(ast->qt_invokable_token));
1750
1751     // unsigned qt_invokable_token = ast->qt_invokable_token;
1752     FullySpecifiedType type;
1753     for (SpecifierListAST *it = ast->decl_specifier_list; it; it = it->next) {
1754         type = this->specifier(it->value, type);
1755     }
1756
1757     List<Symbol *> **symbolTail = &ast->symbols;
1758
1759     if (! ast->declarator_list) {
1760         ElaboratedTypeSpecifierAST *elabTypeSpec = 0;
1761         for (SpecifierListAST *it = ast->decl_specifier_list; ! elabTypeSpec && it; it = it->next)
1762             elabTypeSpec = it->value->asElaboratedTypeSpecifier();
1763
1764         if (elabTypeSpec && tokenKind(elabTypeSpec->classkey_token) != T_TYPENAME) {
1765             unsigned sourceLocation = elabTypeSpec->firstToken();
1766             const Name *name = 0;
1767             if (elabTypeSpec->name) {
1768                 sourceLocation = location(elabTypeSpec->name, sourceLocation);
1769                 name = elabTypeSpec->name->name;
1770             }
1771
1772             ForwardClassDeclaration *decl = control()->newForwardClassDeclaration(sourceLocation, name);
1773             setDeclSpecifiers(decl, type);
1774             _scope->addMember(decl);
1775
1776             *symbolTail = new (translationUnit()->memoryPool()) List<Symbol *>(decl);
1777             symbolTail = &(*symbolTail)->next;
1778         }
1779     }
1780
1781     for (DeclaratorListAST *it = ast->declarator_list; it; it = it->next) {
1782         DeclaratorIdAST *declaratorId = 0;
1783         FullySpecifiedType declTy = this->declarator(it->value, type.qualifiedType(), &declaratorId);
1784
1785         const Name *declName = 0;
1786         unsigned sourceLocation = location(it->value, ast->firstToken());
1787         if (declaratorId && declaratorId->name) {
1788             declName = declaratorId->name->name;
1789         }
1790
1791         Declaration *decl = control()->newDeclaration(sourceLocation, declName);
1792         decl->setType(declTy);
1793         setDeclSpecifiers(decl, type);
1794
1795         if (Function *fun = decl->type()->asFunctionType()) {
1796             fun->setScope(_scope);
1797
1798             setDeclSpecifiers(fun, type);
1799             if (declaratorId && declaratorId->name)
1800                 fun->setName(declaratorId->name->name); // update the function name
1801         }
1802
1803         if (_scope->isClass()) {
1804             decl->setVisibility(_visibility);
1805
1806             if (Function *funTy = decl->type()->asFunctionType()) {
1807                 funTy->setMethodKey(methodKey);
1808
1809                 if (funTy->isVirtual() && it->value->equal_token)
1810                     funTy->setPureVirtual(true);
1811             }
1812         }
1813
1814         _scope->addMember(decl);
1815
1816         *symbolTail = new (translationUnit()->memoryPool()) List<Symbol *>(decl);
1817         symbolTail = &(*symbolTail)->next;
1818     }
1819     return false;
1820 }
1821
1822 bool Bind::visit(EmptyDeclarationAST *ast)
1823 {
1824     (void) ast;
1825     unsigned semicolon_token = ast->semicolon_token;
1826     if (_scope && (_scope->isClass() || _scope->isNamespace())) {
1827         const Token &tk = tokenAt(semicolon_token);
1828
1829         if (! tk.generated())
1830             translationUnit()->warning(semicolon_token, "extra `;'");
1831     }
1832     return false;
1833 }
1834
1835 bool Bind::visit(AccessDeclarationAST *ast)
1836 {
1837     const int accessSpecifier = tokenKind(ast->access_specifier_token);
1838     _visibility = visibilityForAccessSpecifier(accessSpecifier);
1839
1840     if (ast->slots_token)
1841         _methodKey = Function::SlotMethod;
1842     else if (accessSpecifier == T_Q_SIGNALS)
1843         _methodKey = Function::SignalMethod;
1844     else
1845         _methodKey = Function::NormalMethod;
1846
1847     return false;
1848 }
1849
1850 bool Bind::visit(QtObjectTagAST *ast)
1851 {
1852     (void) ast;
1853     // unsigned q_object_token = ast->q_object_token;
1854     return false;
1855 }
1856
1857 bool Bind::visit(QtPrivateSlotAST *ast)
1858 {
1859     // unsigned q_private_slot_token = ast->q_private_slot_token;
1860     // unsigned lparen_token = ast->lparen_token;
1861     // unsigned dptr_token = ast->dptr_token;
1862     // unsigned dptr_lparen_token = ast->dptr_lparen_token;
1863     // unsigned dptr_rparen_token = ast->dptr_rparen_token;
1864     // unsigned comma_token = ast->comma_token;
1865     FullySpecifiedType type;
1866     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1867         type = this->specifier(it->value, type);
1868     }
1869     DeclaratorIdAST *declaratorId = 0;
1870     type = this->declarator(ast->declarator, type, &declaratorId);
1871     // unsigned rparen_token = ast->rparen_token;
1872     return false;
1873 }
1874
1875 static void qtPropertyAttribute(TranslationUnit *unit, ExpressionAST *expression,
1876                                 int *flags,
1877                                 QtPropertyDeclaration::Flag flag,
1878                                 QtPropertyDeclaration::Flag function)
1879 {
1880     if (!expression)
1881         return;
1882     *flags &= ~function & ~flag;
1883     if (BoolLiteralAST *boollit = expression->asBoolLiteral()) {
1884         const int kind = unit->tokenAt(boollit->literal_token).kind();
1885         if (kind == T_TRUE)
1886             *flags |= flag;
1887     } else {
1888         *flags |= function;
1889     }
1890 }
1891
1892 bool Bind::visit(QtPropertyDeclarationAST *ast)
1893 {
1894     // unsigned property_specifier_token = ast->property_specifier_token;
1895     // unsigned lparen_token = ast->lparen_token;
1896     ExpressionTy type_id = this->expression(ast->type_id);
1897     const Name *property_name = this->name(ast->property_name);
1898
1899     unsigned sourceLocation = ast->firstToken();
1900     if (ast->property_name)
1901         sourceLocation = ast->property_name->firstToken();
1902     QtPropertyDeclaration *propertyDeclaration = control()->newQtPropertyDeclaration(sourceLocation, property_name);
1903     propertyDeclaration->setType(type_id);
1904
1905     int flags = QtPropertyDeclaration::DesignableFlag
1906             | QtPropertyDeclaration::ScriptableFlag
1907             | QtPropertyDeclaration::StoredFlag;
1908     for (QtPropertyDeclarationItemListAST *it = ast->property_declaration_item_list; it; it = it->next) {
1909         if (!it->value || !it->value->item_name_token)
1910             continue;
1911         this->expression(it->value->expression);
1912
1913         std::string name = spell(it->value->item_name_token);
1914
1915         if (name == "CONSTANT") {
1916             flags |= QtPropertyDeclaration::ConstantFlag;
1917         } else if (name == "FINAL") {
1918             flags |= QtPropertyDeclaration::FinalFlag;
1919         } else if (name == "READ") {
1920             flags |= QtPropertyDeclaration::ReadFunction;
1921         } else if (name == "WRITE") {
1922             flags |= QtPropertyDeclaration::WriteFunction;
1923         } else if (name == "RESET") {
1924             flags |= QtPropertyDeclaration::ResetFunction;
1925         } else if (name == "NOTIFY") {
1926             flags |= QtPropertyDeclaration::NotifyFunction;
1927         } else if (name == "DESIGNABLE") {
1928             qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
1929                                 QtPropertyDeclaration::DesignableFlag, QtPropertyDeclaration::DesignableFunction);
1930         } else if (name == "SCRIPTABLE") {
1931             qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
1932                                 QtPropertyDeclaration::ScriptableFlag, QtPropertyDeclaration::ScriptableFunction);
1933         } else if (name == "STORED") {
1934             qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
1935                                 QtPropertyDeclaration::StoredFlag, QtPropertyDeclaration::StoredFunction);
1936         } else if (name == "USER") {
1937             qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
1938                                 QtPropertyDeclaration::UserFlag, QtPropertyDeclaration::UserFunction);
1939         }
1940     }
1941     propertyDeclaration->setFlags(flags);
1942     _scope->addMember(propertyDeclaration);
1943     // unsigned rparen_token = ast->rparen_token;
1944     return false;
1945 }
1946
1947 bool Bind::visit(QtEnumDeclarationAST *ast)
1948 {
1949     // unsigned enum_specifier_token = ast->enum_specifier_token;
1950     // unsigned lparen_token = ast->lparen_token;
1951     for (NameListAST *it = ast->enumerator_list; it; it = it->next) {
1952         const Name *value = this->name(it->value);
1953         if (!value)
1954             continue;
1955         QtEnum *qtEnum = control()->newQtEnum(it->value->firstToken(), value);
1956         _scope->addMember(qtEnum);
1957     }
1958
1959     // unsigned rparen_token = ast->rparen_token;
1960     return false;
1961 }
1962
1963 bool Bind::visit(QtFlagsDeclarationAST *ast)
1964 {
1965     // unsigned flags_specifier_token = ast->flags_specifier_token;
1966     // unsigned lparen_token = ast->lparen_token;
1967     for (NameListAST *it = ast->flag_enums_list; it; it = it->next) {
1968         /*const Name *value =*/ this->name(it->value);
1969     }
1970     // unsigned rparen_token = ast->rparen_token;
1971     return false;
1972 }
1973
1974 bool Bind::visit(QtInterfacesDeclarationAST *ast)
1975 {
1976     // unsigned interfaces_token = ast->interfaces_token;
1977     // unsigned lparen_token = ast->lparen_token;
1978     for (QtInterfaceNameListAST *it = ast->interface_name_list; it; it = it->next) {
1979         this->qtInterfaceName(it->value);
1980     }
1981     // unsigned rparen_token = ast->rparen_token;
1982     return false;
1983 }
1984
1985 bool Bind::visit(AsmDefinitionAST *ast)
1986 {
1987     (void) ast;
1988     // unsigned asm_token = ast->asm_token;
1989     // unsigned volatile_token = ast->volatile_token;
1990     // unsigned lparen_token = ast->lparen_token;
1991     // unsigned rparen_token = ast->rparen_token;
1992     // unsigned semicolon_token = ast->semicolon_token;
1993     return false;
1994 }
1995
1996 bool Bind::visit(ExceptionDeclarationAST *ast)
1997 {
1998     FullySpecifiedType type;
1999     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
2000         type = this->specifier(it->value, type);
2001     }
2002     DeclaratorIdAST *declaratorId = 0;
2003     type = this->declarator(ast->declarator, type, &declaratorId);
2004     // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
2005     return false;
2006 }
2007
2008 bool Bind::visit(FunctionDefinitionAST *ast)
2009 {
2010     int methodKey = _methodKey;
2011     if (ast->qt_invokable_token)
2012         methodKey = methodKeyForInvokableToken(tokenKind(ast->qt_invokable_token));
2013
2014     FullySpecifiedType declSpecifiers;
2015     for (SpecifierListAST *it = ast->decl_specifier_list; it; it = it->next) {
2016         declSpecifiers = this->specifier(it->value, declSpecifiers);
2017     }
2018     DeclaratorIdAST *declaratorId = 0;
2019     FullySpecifiedType type = this->declarator(ast->declarator, declSpecifiers.qualifiedType(), &declaratorId);
2020
2021     Function *fun = type->asFunctionType();
2022     ast->symbol = fun;
2023
2024     if (fun) {
2025         setDeclSpecifiers(fun, declSpecifiers);
2026
2027         if (_scope->isClass()) {
2028             fun->setVisibility(_visibility);
2029             fun->setMethodKey(methodKey);
2030         }
2031
2032         if (declaratorId && declaratorId->name) {
2033             fun->setSourceLocation(location(declaratorId, ast->firstToken()), translationUnit());
2034             fun->setName(declaratorId->name->name);
2035         }
2036
2037         _scope->addMember(fun);
2038     } else
2039         translationUnit()->warning(ast->firstToken(), "expected a function declarator");
2040
2041     this->ctorInitializer(ast->ctor_initializer, fun);
2042
2043     if (fun && ! _skipFunctionBodies && ast->function_body) {
2044         Scope *previousScope = switchScope(fun);
2045         this->statement(ast->function_body);
2046         (void) switchScope(previousScope);
2047
2048         if (CompoundStatementAST *c = ast->function_body->asCompoundStatement()) {
2049             if (c->symbol) {
2050                 fun->setEndOffset(c->symbol->endOffset());
2051             }
2052         }
2053     }
2054
2055     return false;
2056 }
2057
2058 bool Bind::visit(LinkageBodyAST *ast)
2059 {
2060     // unsigned lbrace_token = ast->lbrace_token;
2061     for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) {
2062         this->declaration(it->value);
2063     }
2064     // unsigned rbrace_token = ast->rbrace_token;
2065     return false;
2066 }
2067
2068 bool Bind::visit(LinkageSpecificationAST *ast)
2069 {
2070     // unsigned extern_token = ast->extern_token;
2071     // unsigned extern_type_token = ast->extern_type_token;
2072     this->declaration(ast->declaration);
2073     return false;
2074 }
2075
2076 bool Bind::visit(NamespaceAST *ast)
2077 {
2078     // unsigned namespace_token = ast->namespace_token;
2079     // unsigned identifier_token = ast->identifier_token;
2080     FullySpecifiedType type;
2081     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2082         type = this->specifier(it->value, type);
2083     }
2084
2085     unsigned sourceLocation = ast->firstToken();
2086     const Name *namespaceName = 0;
2087     if (ast->identifier_token) {
2088         sourceLocation = ast->identifier_token;
2089         namespaceName = identifier(ast->identifier_token);
2090     }
2091
2092     Namespace *ns = control()->newNamespace(sourceLocation, namespaceName);
2093     ns->setStartOffset(tokenAt(sourceLocation).end()); // the scope starts after the namespace or the identifier token.
2094     ns->setEndOffset(tokenAt(ast->lastToken() - 1).end());
2095     ast->symbol = ns;
2096     _scope->addMember(ns);
2097
2098     Scope *previousScope = switchScope(ns);
2099     this->declaration(ast->linkage_body);
2100     (void) switchScope(previousScope);
2101     return false;
2102 }
2103
2104 bool Bind::visit(NamespaceAliasDefinitionAST *ast)
2105 {
2106     unsigned sourceLocation = ast->firstToken();
2107     const Name *name = 0;
2108     if (ast->namespace_name_token) {
2109         sourceLocation = ast->namespace_name_token;
2110         name = identifier(ast->namespace_name_token);
2111     }
2112
2113     NamespaceAlias *namespaceAlias = control()->newNamespaceAlias(sourceLocation, name);
2114     namespaceAlias->setNamespaceName(this->name(ast->name));
2115     _scope->addMember(namespaceAlias);
2116     return false;
2117 }
2118
2119 bool Bind::visit(ParameterDeclarationAST *ast)
2120 {
2121     FullySpecifiedType type;
2122     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
2123         type = this->specifier(it->value, type);
2124     }
2125     DeclaratorIdAST *declaratorId = 0;
2126     type = this->declarator(ast->declarator, type, &declaratorId);
2127     // unsigned equal_token = ast->equal_token;
2128     ExpressionTy expression = this->expression(ast->expression);
2129
2130     unsigned sourceLocation = ast->firstToken();
2131     if (declaratorId)
2132         sourceLocation = declaratorId->firstToken();
2133
2134     const Name *argName = 0;
2135     if (declaratorId && declaratorId->name)
2136         argName = declaratorId->name->name;
2137
2138     Argument *arg = control()->newArgument(location(declaratorId, ast->firstToken()), argName);
2139     arg->setType(type);
2140
2141     if (ast->expression) {
2142         unsigned startOfExpression = ast->expression->firstToken();
2143         unsigned endOfExpression = ast->expression->lastToken();
2144         std::string buffer;
2145         for (unsigned index = startOfExpression; index != endOfExpression; ++index) {
2146             const Token &tk = tokenAt(index);
2147             if (tk.whitespace() || tk.newline())
2148                 buffer += ' ';
2149             buffer += tk.spell();
2150         }
2151         const StringLiteral *initializer = control()->stringLiteral(buffer.c_str(), buffer.size());
2152         arg->setInitializer(initializer);
2153     }
2154
2155     _scope->addMember(arg);
2156
2157     ast->symbol = arg;
2158     return false;
2159 }
2160
2161 bool Bind::visit(TemplateDeclarationAST *ast)
2162 {
2163     Template *templ = control()->newTemplate(ast->firstToken(), 0);
2164     templ->setStartOffset(tokenAt(ast->firstToken()).begin());
2165     templ->setEndOffset(tokenAt(ast->lastToken() - 1).end());
2166     ast->symbol = templ;
2167     Scope *previousScope = switchScope(templ);
2168
2169     for (DeclarationListAST *it = ast->template_parameter_list; it; it = it->next) {
2170         this->declaration(it->value);
2171     }
2172     // unsigned greater_token = ast->greater_token;
2173     this->declaration(ast->declaration);
2174     (void) switchScope(previousScope);
2175
2176     if (Symbol *decl = templ->declaration()) {
2177         templ->setSourceLocation(decl->sourceLocation(), translationUnit());
2178         templ->setName(decl->name());
2179     }
2180
2181     _scope->addMember(templ);
2182     return false;
2183 }
2184
2185 bool Bind::visit(TypenameTypeParameterAST *ast)
2186 {
2187     unsigned sourceLocation = location(ast->name, ast->firstToken());
2188     // unsigned classkey_token = ast->classkey_token;
2189     // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
2190     const Name *name = this->name(ast->name);
2191     ExpressionTy type_id = this->expression(ast->type_id);
2192
2193     TypenameArgument *arg = control()->newTypenameArgument(sourceLocation, name);
2194     arg->setType(type_id);
2195     ast->symbol = arg;
2196     _scope->addMember(arg);
2197     return false;
2198 }
2199
2200 bool Bind::visit(TemplateTypeParameterAST *ast)
2201 {
2202     unsigned sourceLocation = location(ast->name, ast->firstToken());
2203
2204     // unsigned template_token = ast->template_token;
2205     // unsigned less_token = ast->less_token;
2206     // ### process the template prototype
2207 #if 0
2208     for (DeclarationListAST *it = ast->template_parameter_list; it; it = it->next) {
2209         this->declaration(it->value);
2210     }
2211 #endif
2212     // unsigned greater_token = ast->greater_token;
2213     // unsigned class_token = ast->class_token;
2214     // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
2215
2216     const Name *name = this->name(ast->name);
2217     ExpressionTy type_id = this->expression(ast->type_id);
2218
2219     // ### introduce TemplateTypeArgument
2220     TypenameArgument *arg = control()->newTypenameArgument(sourceLocation, name);
2221     arg->setType(type_id);
2222     ast->symbol = arg;
2223     _scope->addMember(arg);
2224
2225     return false;
2226 }
2227
2228 bool Bind::visit(UsingAST *ast)
2229 {
2230     unsigned sourceLocation = location(ast->name, ast->firstToken());
2231     const Name *name = this->name(ast->name);
2232
2233     UsingDeclaration *symbol = control()->newUsingDeclaration(sourceLocation, name);
2234     ast->symbol = symbol;
2235     _scope->addMember(symbol);
2236     return false;
2237 }
2238
2239 bool Bind::visit(UsingDirectiveAST *ast)
2240 {
2241     unsigned sourceLocation = location(ast->name, ast->firstToken());
2242     const Name *name = this->name(ast->name);
2243     UsingNamespaceDirective *symbol = control()->newUsingNamespaceDirective(sourceLocation, name);
2244     ast->symbol = symbol;
2245     _scope->addMember(symbol);
2246     return false;
2247 }
2248
2249 bool Bind::visit(ObjCClassForwardDeclarationAST *ast)
2250 {
2251     FullySpecifiedType declSpecifiers;
2252     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2253         declSpecifiers = this->specifier(it->value, declSpecifiers);
2254     }
2255
2256     List<ObjCForwardClassDeclaration *> **symbolTail = &ast->symbols;
2257
2258     // unsigned class_token = ast->class_token;
2259     for (NameListAST *it = ast->identifier_list; it; it = it->next) {
2260         const Name *name = this->name(it->value);
2261
2262         const unsigned sourceLocation = location(it->value, ast->firstToken());
2263         ObjCForwardClassDeclaration *fwd = control()->newObjCForwardClassDeclaration(sourceLocation, name);
2264         setDeclSpecifiers(fwd, declSpecifiers);
2265         _scope->addMember(fwd);
2266
2267         *symbolTail = new (translationUnit()->memoryPool()) List<ObjCForwardClassDeclaration *>(fwd);
2268         symbolTail = &(*symbolTail)->next;
2269     }
2270
2271     return false;
2272 }
2273
2274 unsigned Bind::calculateScopeStart(ObjCClassDeclarationAST *ast) const
2275 {
2276     if (ast->inst_vars_decl)
2277         if (unsigned pos = ast->inst_vars_decl->lbrace_token)
2278             return tokenAt(pos).end();
2279
2280     if (ast->protocol_refs)
2281         if (unsigned pos = ast->protocol_refs->lastToken())
2282             return tokenAt(pos - 1).end();
2283
2284     if (ast->superclass)
2285         if (unsigned pos = ast->superclass->lastToken())
2286             return tokenAt(pos - 1).end();
2287
2288     if (ast->colon_token)
2289         return tokenAt(ast->colon_token).end();
2290
2291     if (ast->rparen_token)
2292         return tokenAt(ast->rparen_token).end();
2293
2294     if (ast->category_name)
2295         if (unsigned pos = ast->category_name->lastToken())
2296             return tokenAt(pos - 1).end();
2297
2298     if (ast->lparen_token)
2299         return tokenAt(ast->lparen_token).end();
2300
2301     if (ast->class_name)
2302         if (unsigned pos = ast->class_name->lastToken())
2303             return tokenAt(pos - 1).end();
2304
2305     return tokenAt(ast->firstToken()).begin();
2306 }
2307
2308 bool Bind::visit(ObjCClassDeclarationAST *ast)
2309 {
2310     FullySpecifiedType declSpecifiers;
2311     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2312         declSpecifiers = this->specifier(it->value, declSpecifiers);
2313     }
2314     const Name *class_name = this->name(ast->class_name);
2315     const Name *category_name = this->name(ast->category_name);
2316
2317     const unsigned sourceLocation = location(ast->class_name, ast->firstToken());
2318     ObjCClass *klass = control()->newObjCClass(sourceLocation, class_name);
2319     ast->symbol = klass;
2320     _scope->addMember(klass);
2321
2322     klass->setStartOffset(calculateScopeStart(ast));
2323     klass->setEndOffset(tokenAt(ast->lastToken() - 1).begin());
2324
2325     if (ast->interface_token)
2326         klass->setInterface(true);
2327
2328     klass->setCategoryName(category_name);
2329
2330     Scope *previousScope = switchScope(klass);
2331
2332     if (const Name *superclass = this->name(ast->superclass)) {
2333         ObjCBaseClass *superKlass = control()->newObjCBaseClass(ast->superclass->firstToken(), superclass);
2334         klass->setBaseClass(superKlass);
2335     }
2336
2337     this->objCProtocolRefs(ast->protocol_refs, klass);
2338
2339     const int previousObjCVisibility = switchObjCVisibility(Function::Protected);
2340
2341     this->objCInstanceVariablesDeclaration(ast->inst_vars_decl, klass);
2342
2343     (void) switchObjCVisibility(Function::Public);
2344     for (DeclarationListAST *it = ast->member_declaration_list; it; it = it->next) {
2345         this->declaration(it->value);
2346     }
2347
2348     (void) switchObjCVisibility(previousObjCVisibility);
2349     (void) switchScope(previousScope);
2350     return false;
2351 }
2352
2353 bool Bind::visit(ObjCProtocolForwardDeclarationAST *ast)
2354 {
2355     FullySpecifiedType declSpecifiers;
2356     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2357         declSpecifiers = this->specifier(it->value, declSpecifiers);
2358     }
2359
2360     List<ObjCForwardProtocolDeclaration *> **symbolTail = &ast->symbols;
2361
2362     // unsigned class_token = ast->class_token;
2363     for (NameListAST *it = ast->identifier_list; it; it = it->next) {
2364         const Name *name = this->name(it->value);
2365
2366         const unsigned sourceLocation = location(it->value, ast->firstToken());
2367         ObjCForwardProtocolDeclaration *fwd = control()->newObjCForwardProtocolDeclaration(sourceLocation, name);
2368         setDeclSpecifiers(fwd, declSpecifiers);
2369         _scope->addMember(fwd);
2370
2371         *symbolTail = new (translationUnit()->memoryPool()) List<ObjCForwardProtocolDeclaration *>(fwd);
2372         symbolTail = &(*symbolTail)->next;
2373     }
2374
2375     return false;
2376 }
2377
2378 unsigned Bind::calculateScopeStart(ObjCProtocolDeclarationAST *ast) const
2379 {
2380     if (ast->protocol_refs)
2381         if (unsigned pos = ast->protocol_refs->lastToken())
2382             return tokenAt(pos - 1).end();
2383     if (ast->name)
2384         if (unsigned pos = ast->name->lastToken())
2385             return tokenAt(pos - 1).end();
2386
2387     return tokenAt(ast->firstToken()).begin();
2388 }
2389
2390 bool Bind::visit(ObjCProtocolDeclarationAST *ast)
2391 {
2392     FullySpecifiedType type;
2393     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2394         type = this->specifier(it->value, type);
2395     }
2396     // unsigned protocol_token = ast->protocol_token;
2397     const Name *name = this->name(ast->name);
2398
2399     const unsigned sourceLocation = location(ast->name, ast->firstToken());
2400     ObjCProtocol *protocol = control()->newObjCProtocol(sourceLocation, name);
2401     protocol->setStartOffset(calculateScopeStart(ast));
2402     protocol->setEndOffset(tokenAt(ast->lastToken() - 1).end());
2403     ast->symbol = protocol;
2404     _scope->addMember(protocol);
2405
2406     Scope *previousScope = switchScope(protocol);
2407     const int previousObjCVisibility = switchObjCVisibility(Function::Public);
2408
2409     this->objCProtocolRefs(ast->protocol_refs, protocol);
2410     for (DeclarationListAST *it = ast->member_declaration_list; it; it = it->next) {
2411         this->declaration(it->value);
2412     }
2413
2414     (void) switchObjCVisibility(previousObjCVisibility);
2415     (void) switchScope(previousScope);
2416     return false;
2417 }
2418
2419 bool Bind::visit(ObjCVisibilityDeclarationAST *ast)
2420 {
2421     _objcVisibility = visibilityForObjCAccessSpecifier(tokenKind(ast->visibility_token));
2422     return false;
2423 }
2424
2425 bool Bind::visit(ObjCPropertyDeclarationAST *ast)
2426 {
2427     (void) ast;
2428     FullySpecifiedType type;
2429     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2430         type = this->specifier(it->value, type);
2431     }
2432     // unsigned property_token = ast->property_token;
2433     // unsigned lparen_token = ast->lparen_token;
2434     for (ObjCPropertyAttributeListAST *it = ast->property_attribute_list; it; it = it->next) {
2435         this->objCPropertyAttribute(it->value);
2436     }
2437     // unsigned rparen_token = ast->rparen_token;
2438     this->declaration(ast->simple_declaration);
2439     // List<ObjCPropertyDeclaration *> *symbols = ast->symbols;
2440     return false;
2441 }
2442
2443 bool Bind::visit(ObjCMethodDeclarationAST *ast)
2444 {
2445     ObjCMethod *method = this->objCMethodPrototype(ast->method_prototype);
2446
2447     if (! ast->function_body) {
2448         const Name *name = method->name();
2449         unsigned sourceLocation = ast->firstToken();
2450         Declaration *decl = control()->newDeclaration(sourceLocation, name);
2451         decl->setType(method);
2452         _scope->addMember(decl);
2453     } else if (! _skipFunctionBodies && ast->function_body) {
2454         Scope *previousScope = switchScope(method);
2455         this->statement(ast->function_body);
2456         (void) switchScope(previousScope);
2457         _scope->addMember(method);
2458     }
2459
2460     return false;
2461 }
2462
2463 bool Bind::visit(ObjCSynthesizedPropertiesDeclarationAST *ast)
2464 {
2465     // unsigned synthesized_token = ast->synthesized_token;
2466     for (ObjCSynthesizedPropertyListAST *it = ast->property_identifier_list; it; it = it->next) {
2467         this->objCSynthesizedProperty(it->value);
2468     }
2469     // unsigned semicolon_token = ast->semicolon_token;
2470     return false;
2471 }
2472
2473 bool Bind::visit(ObjCDynamicPropertiesDeclarationAST *ast)
2474 {
2475     // unsigned dynamic_token = ast->dynamic_token;
2476     for (NameListAST *it = ast->property_identifier_list; it; it = it->next) {
2477         /*const Name *value =*/ this->name(it->value);
2478     }
2479     // unsigned semicolon_token = ast->semicolon_token;
2480     return false;
2481 }
2482
2483
2484 // NameAST
2485 bool Bind::visit(ObjCSelectorAST *ast) // ### review
2486 {
2487     std::vector<const Name *> arguments;
2488     bool hasArgs = false;
2489
2490     for (ObjCSelectorArgumentListAST *it = ast->selector_argument_list; it; it = it->next) {
2491         if (const Name *selector_argument = this->objCSelectorArgument(it->value, &hasArgs))
2492             arguments.push_back(selector_argument);
2493     }
2494
2495     if (! arguments.empty()) {
2496         _name = control()->selectorNameId(&arguments[0], arguments.size(), hasArgs);
2497         ast->name = _name;
2498     }
2499
2500     return false;
2501 }
2502
2503 bool Bind::visit(QualifiedNameAST *ast)
2504 {
2505     for (NestedNameSpecifierListAST *it = ast->nested_name_specifier_list; it; it = it->next) {
2506         const Name *class_or_namespace_name = this->nestedNameSpecifier(it->value);
2507         if (_name || ast->global_scope_token)
2508             _name = control()->qualifiedNameId(_name, class_or_namespace_name);
2509         else
2510             _name = class_or_namespace_name;
2511     }
2512
2513     const Name *unqualified_name = this->name(ast->unqualified_name);
2514     if (_name || ast->global_scope_token)
2515         _name = control()->qualifiedNameId(_name, unqualified_name);
2516     else
2517         _name = unqualified_name;
2518
2519     ast->name = _name;
2520     return false;
2521 }
2522
2523 bool Bind::visit(OperatorFunctionIdAST *ast)
2524 {
2525     const OperatorNameId::Kind op = this->cppOperator(ast->op);
2526     ast->name = _name = control()->operatorNameId(op);
2527     return false;
2528 }
2529
2530 bool Bind::visit(ConversionFunctionIdAST *ast)
2531 {
2532     FullySpecifiedType type;
2533     for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
2534         type = this->specifier(it->value, type);
2535     }
2536     for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
2537         type = this->ptrOperator(it->value, type);
2538     }
2539     ast->name = _name = control()->conversionNameId(type);
2540     return false;
2541 }
2542
2543 bool Bind::visit(SimpleNameAST *ast)
2544 {
2545     const Identifier *id = identifier(ast->identifier_token);
2546     _name = id;
2547     ast->name = _name;
2548     return false;
2549 }
2550
2551 bool Bind::visit(DestructorNameAST *ast)
2552 {
2553     const Identifier *id = identifier(ast->identifier_token);
2554     _name = control()->destructorNameId(id);
2555     ast->name = _name;
2556     return false;
2557 }
2558
2559 bool Bind::visit(TemplateIdAST *ast)
2560 {
2561     // collect the template parameters
2562     std::vector<FullySpecifiedType> templateArguments;
2563     for (ExpressionListAST *it = ast->template_argument_list; it; it = it->next) {
2564         ExpressionTy value = this->expression(it->value);
2565         templateArguments.push_back(value);
2566     }
2567
2568     const Identifier *id = identifier(ast->identifier_token);
2569     if (templateArguments.empty())
2570         _name = control()->templateNameId(id);
2571     else
2572         _name = control()->templateNameId(id, &templateArguments[0], templateArguments.size());
2573
2574     ast->name = _name;
2575     return false;
2576 }
2577
2578
2579 // SpecifierAST
2580 bool Bind::visit(SimpleSpecifierAST *ast)
2581 {
2582     switch (tokenKind(ast->specifier_token)) {
2583         case T_CONST:
2584             if (_type.isConst())
2585                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2586             _type.setConst(true);
2587             break;
2588
2589         case T_VOLATILE:
2590             if (_type.isVolatile())
2591                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2592             _type.setVolatile(true);
2593             break;
2594
2595         case T_FRIEND:
2596             if (_type.isFriend())
2597                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2598             _type.setFriend(true);
2599             break;
2600
2601         case T_AUTO:
2602             if (_type.isAuto())
2603                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2604             _type.setAuto(true);
2605             break;
2606
2607         case T_REGISTER:
2608             if (_type.isRegister())
2609                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2610             _type.setRegister(true);
2611             break;
2612
2613         case T_STATIC:
2614             if (_type.isStatic())
2615                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2616             _type.setStatic(true);
2617             break;
2618
2619         case T_EXTERN:
2620             if (_type.isExtern())
2621                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2622             _type.setExtern(true);
2623             break;
2624
2625         case T_MUTABLE:
2626             if (_type.isMutable())
2627                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2628             _type.setMutable(true);
2629             break;
2630
2631         case T_TYPEDEF:
2632             if (_type.isTypedef())
2633                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2634             _type.setTypedef(true);
2635             break;
2636
2637         case T_INLINE:
2638             if (_type.isInline())
2639                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2640             _type.setInline(true);
2641             break;
2642
2643         case T_VIRTUAL:
2644             if (_type.isVirtual())
2645                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2646             _type.setVirtual(true);
2647             break;
2648
2649         case T_EXPLICIT:
2650             if (_type.isExplicit())
2651                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2652             _type.setExplicit(true);
2653             break;
2654
2655         case T_SIGNED:
2656             if (_type.isSigned())
2657                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2658             _type.setSigned(true);
2659             break;
2660
2661         case T_UNSIGNED:
2662             if (_type.isUnsigned())
2663                 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2664             _type.setUnsigned(true);
2665             break;
2666
2667         case T_CHAR:
2668             if (_type)
2669                 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2670             _type.setType(control()->integerType(IntegerType::Char));
2671             break;
2672
2673         case T_WCHAR_T:
2674             if (_type)
2675                 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2676             _type.setType(control()->integerType(IntegerType::WideChar));
2677             break;
2678
2679         case T_BOOL:
2680             if (_type)
2681                 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2682             _type.setType(control()->integerType(IntegerType::Bool));
2683             break;
2684
2685         case T_SHORT:
2686             if (_type) {
2687                 IntegerType *intType = control()->integerType(IntegerType::Int);
2688                 if (_type.type() != intType)
2689                     translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2690             }
2691             _type.setType(control()->integerType(IntegerType::Short));
2692             break;
2693
2694         case T_INT:
2695             if (_type) {
2696                 Type *tp = _type.type();
2697                 IntegerType *shortType = control()->integerType(IntegerType::Short);
2698                 IntegerType *longType = control()->integerType(IntegerType::Long);
2699                 IntegerType *longLongType = control()->integerType(IntegerType::LongLong);
2700                 if (tp == shortType || tp == longType || tp == longLongType)
2701                     break;
2702                 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2703             }
2704             _type.setType(control()->integerType(IntegerType::Int));
2705             break;
2706
2707         case T_LONG:
2708             if (_type) {
2709                 Type *tp = _type.type();
2710                 IntegerType *intType = control()->integerType(IntegerType::Int);
2711                 IntegerType *longType = control()->integerType(IntegerType::Long);
2712                 FloatType *doubleType = control()->floatType(FloatType::Double);
2713                 if (tp == longType) {
2714                     _type.setType(control()->integerType(IntegerType::LongLong));
2715                     break;
2716                 } else if (tp == doubleType) {
2717                     _type.setType(control()->floatType(FloatType::LongDouble));
2718                     break;
2719                 } else if (tp != intType) {
2720                     translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2721                 }
2722             }
2723             _type.setType(control()->integerType(IntegerType::Long));
2724             break;
2725
2726         case T_FLOAT:
2727             if (_type)
2728                 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2729             _type.setType(control()->floatType(FloatType::Float));
2730             break;
2731
2732         case T_DOUBLE:
2733             if (_type) {
2734                 IntegerType *longType = control()->integerType(IntegerType::Long);
2735                 if (_type.type() == longType) {
2736                     _type.setType(control()->floatType(FloatType::LongDouble));
2737                     break;
2738                 }
2739                 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2740             }
2741             _type.setType(control()->floatType(FloatType::Double));
2742             break;
2743
2744         case T_VOID:
2745             if (_type)
2746                 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2747             _type.setType(control()->voidType());
2748             break;
2749
2750         default:
2751             break;
2752     } // switch
2753     return false;
2754 }
2755
2756 bool Bind::visit(AttributeSpecifierAST *ast)
2757 {
2758     // unsigned attribute_token = ast->attribute_token;
2759     // unsigned first_lparen_token = ast->first_lparen_token;
2760     // unsigned second_lparen_token = ast->second_lparen_token;
2761     for (AttributeListAST *it = ast->attribute_list; it; it = it->next) {
2762         this->attribute(it->value);
2763     }
2764     // unsigned first_rparen_token = ast->first_rparen_token;
2765     // unsigned second_rparen_token = ast->second_rparen_token;
2766     return false;
2767 }
2768
2769 bool Bind::visit(TypeofSpecifierAST *ast)
2770 {
2771     ExpressionTy expression = this->expression(ast->expression);
2772     _type = expression;
2773     return false;
2774 }
2775
2776 bool Bind::visit(ClassSpecifierAST *ast)
2777 {
2778     // unsigned classkey_token = ast->classkey_token;
2779     unsigned sourceLocation = ast->firstToken();
2780     unsigned startScopeOffset = tokenAt(sourceLocation).end(); // at the end of the class key
2781
2782     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2783         _type = this->specifier(it->value, _type);
2784     }
2785
2786     const Name *className = this->name(ast->name);
2787
2788     if (ast->name) {
2789         sourceLocation = location(ast->name, sourceLocation);
2790         startScopeOffset = tokenAt(sourceLocation).end(); // at the end of the class name
2791
2792         if (QualifiedNameAST *q = ast->name->asQualifiedName()) {
2793             if (q->unqualified_name) {
2794                 sourceLocation = q->unqualified_name->firstToken();
2795                 startScopeOffset = tokenAt(q->unqualified_name->lastToken() - 1).end(); // at the end of the unqualified name
2796             }
2797         }
2798     }
2799
2800     Class *klass = control()->newClass(sourceLocation, className);
2801     klass->setStartOffset(startScopeOffset);
2802     klass->setEndOffset(tokenAt(ast->lastToken() - 1).end());
2803     _scope->addMember(klass);
2804
2805     if (_scope->isClass())
2806         klass->setVisibility(_visibility);
2807
2808     // set the class key
2809     unsigned classKey = tokenKind(ast->classkey_token);
2810     if (classKey == T_CLASS)
2811         klass->setClassKey(Class::ClassKey);
2812     else if (classKey == T_STRUCT)
2813         klass->setClassKey(Class::StructKey);
2814     else if (classKey == T_UNION)
2815         klass->setClassKey(Class::UnionKey);
2816
2817     _type.setType(klass);
2818
2819     Scope *previousScope = switchScope(klass);
2820     const int previousVisibility = switchVisibility(visibilityForClassKey(classKey));
2821     const int previousMethodKey = switchMethodKey(Function::NormalMethod);
2822
2823     for (BaseSpecifierListAST *it = ast->base_clause_list; it; it = it->next) {
2824         this->baseSpecifier(it->value, ast->colon_token, klass);
2825     }
2826     // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
2827     for (DeclarationListAST *it = ast->member_specifier_list; it; it = it->next) {
2828         this->declaration(it->value);
2829     }
2830
2831     (void) switchMethodKey(previousMethodKey);
2832     (void) switchVisibility(previousVisibility);
2833     (void) switchScope(previousScope);
2834
2835     ast->symbol = klass;
2836     return false;
2837 }
2838
2839 bool Bind::visit(NamedTypeSpecifierAST *ast)
2840 {
2841     _type.setType(control()->namedType(this->name(ast->name)));
2842     return false;
2843 }
2844
2845 bool Bind::visit(ElaboratedTypeSpecifierAST *ast)
2846 {
2847     // unsigned classkey_token = ast->classkey_token;
2848     for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2849         _type = this->specifier(it->value, _type);
2850     }
2851     _type.setType(control()->namedType(this->name(ast->name)));
2852     return false;
2853 }
2854
2855 bool Bind::visit(EnumSpecifierAST *ast)
2856 {
2857     unsigned sourceLocation = location(ast->name, ast->firstToken());
2858     const Name *enumName = this->name(ast->name);
2859
2860     Enum *e = control()->newEnum(sourceLocation, enumName);
2861     e->setStartOffset(tokenAt(sourceLocation).end()); // at the end of the enum or identifier token.
2862     e->setEndOffset(tokenAt(ast->lastToken() - 1).end());
2863     ast->symbol = e;
2864     _scope->addMember(e);
2865
2866     if (_scope->isClass())
2867         e->setVisibility(_visibility);
2868
2869     Scope *previousScope = switchScope(e);
2870     for (EnumeratorListAST *it = ast->enumerator_list; it; it = it->next) {
2871         this->enumerator(it->value, e);
2872     }
2873
2874     if (ast->stray_comma_token /* && ! translationUnit()->cxx0xEnabled()*/) {
2875         const Token &tk = tokenAt(ast->stray_comma_token);
2876         if (! tk.generated())
2877             translationUnit()->warning(ast->stray_comma_token,
2878                                        "commas at the end of enumerator lists are a C++0x-specific feature");
2879     }
2880
2881     (void) switchScope(previousScope);
2882     return false;
2883 }
2884
2885
2886 // PtrOperatorAST
2887 bool Bind::visit(PointerToMemberAST *ast)
2888 {
2889     const Name *memberName = 0;
2890
2891     for (NestedNameSpecifierListAST *it = ast->nested_name_specifier_list; it; it = it->next) {
2892         const Name *class_or_namespace_name = this->nestedNameSpecifier(it->value);
2893         if (memberName || ast->global_scope_token)
2894             memberName = control()->qualifiedNameId(memberName, class_or_namespace_name);
2895         else
2896             memberName = class_or_namespace_name;
2897     }
2898
2899     FullySpecifiedType type(control()->pointerToMemberType(memberName, _type));
2900     for (SpecifierListAST *it = ast->cv_qualifier_list; it; it = it->next) {
2901         type = this->specifier(it->value, type);
2902     }
2903     _type = type;
2904     return false;
2905 }
2906
2907 bool Bind::visit(PointerAST *ast)
2908 {
2909     if (_type->isReferenceType())
2910         translationUnit()->error(ast->firstToken(), "cannot declare pointer to a reference");
2911
2912     FullySpecifiedType type(control()->pointerType(_type));
2913     for (SpecifierListAST *it = ast->cv_qualifier_list; it; it = it->next) {
2914         type = this->specifier(it->value, type);
2915     }
2916     _type = type;
2917     return false;
2918 }
2919
2920 bool Bind::visit(ReferenceAST *ast)
2921 {
2922     const bool rvalueRef = (tokenKind(ast->reference_token) == T_AMPER_AMPER);
2923
2924     if (_type->isReferenceType())
2925         translationUnit()->error(ast->firstToken(), "cannot declare reference to a reference");
2926
2927     FullySpecifiedType type(control()->referenceType(_type, rvalueRef));
2928     _type = type;
2929     return false;
2930 }
2931
2932
2933 // PostfixAST
2934 bool Bind::visit(CallAST *ast)
2935 {
2936     /*ExpressionTy base_expression =*/ this->expression(ast->base_expression);
2937     // unsigned lparen_token = ast->lparen_token;
2938     for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
2939         /*ExpressionTy value =*/ this->expression(it->value);
2940     }
2941     // unsigned rparen_token = ast->rparen_token;
2942     return false;
2943 }
2944
2945 bool Bind::visit(ArrayAccessAST *ast)
2946 {
2947     /*ExpressionTy base_expression =*/ this->expression(ast->base_expression);
2948     // unsigned lbracket_token = ast->lbracket_token;
2949     /*ExpressionTy expression =*/ this->expression(ast->expression);
2950     // unsigned rbracket_token = ast->rbracket_token;
2951     return false;
2952 }
2953
2954 bool Bind::visit(PostIncrDecrAST *ast)
2955 {
2956     ExpressionTy base_expression = this->expression(ast->base_expression);
2957     // unsigned incr_decr_token = ast->incr_decr_token;
2958     return false;
2959 }
2960
2961 bool Bind::visit(MemberAccessAST *ast)
2962 {
2963     ExpressionTy base_expression = this->expression(ast->base_expression);
2964     // unsigned access_token = ast->access_token;
2965     // unsigned template_token = ast->template_token;
2966     /*const Name *member_name =*/ this->name(ast->member_name);
2967     return false;
2968 }
2969
2970
2971 // CoreDeclaratorAST
2972 bool Bind::visit(DeclaratorIdAST *ast)
2973 {
2974     /*const Name *name =*/ this->name(ast->name);
2975     *_declaratorId = ast;
2976     return false;
2977 }
2978
2979 bool Bind::visit(NestedDeclaratorAST *ast)
2980 {
2981     _type = this->declarator(ast->declarator, _type, _declaratorId);
2982     return false;
2983 }
2984
2985
2986 // PostfixDeclaratorAST
2987 bool Bind::visit(FunctionDeclaratorAST *ast)
2988 {
2989     Function *fun = control()->newFunction(0, 0);
2990     fun->setStartOffset(tokenAt(ast->firstToken()).begin());
2991     fun->setEndOffset(tokenAt(ast->lastToken() - 1).end());
2992     fun->setReturnType(_type);
2993
2994     // unsigned lparen_token = ast->lparen_token;
2995     this->parameterDeclarationClause(ast->parameter_declaration_clause, ast->lparen_token, fun);
2996     // unsigned rparen_token = ast->rparen_token;
2997     FullySpecifiedType type(fun);
2998     for (SpecifierListAST *it = ast->cv_qualifier_list; it; it = it->next) {
2999         type = this->specifier(it->value, type);
3000     }
3001
3002     // propagate the cv-qualifiers
3003     fun->setConst(type.isConst());
3004     fun->setVolatile(type.isVolatile());
3005
3006     this->exceptionSpecification(ast->exception_specification, type);
3007     this->trailingReturnType(ast->trailing_return_type, type);
3008     if (ast->as_cpp_initializer != 0) {
3009         fun->setAmbiguous(true);
3010         /*ExpressionTy as_cpp_initializer =*/ this->expression(ast->as_cpp_initializer);
3011     }
3012     ast->symbol = fun;
3013     _type = type;
3014     return false;
3015 }
3016
3017 bool Bind::visit(ArrayDeclaratorAST *ast)
3018 {
3019     ExpressionTy expression = this->expression(ast->expression);
3020     FullySpecifiedType type(control()->arrayType(_type));
3021     _type = type;
3022     return false;
3023 }
3024
3025 int Bind::visibilityForAccessSpecifier(int tokenKind)
3026 {
3027     switch (tokenKind) {
3028     case T_PUBLIC:
3029         return Symbol::Public;
3030     case T_PROTECTED:
3031         return Symbol::Protected;
3032     case T_PRIVATE:
3033         return Symbol::Private;
3034     case T_Q_SIGNALS:
3035         return Symbol::Protected;
3036     default:
3037         return Symbol::Public;
3038     }
3039 }
3040
3041 int Bind::visibilityForClassKey(int tokenKind)
3042 {
3043     switch (tokenKind) {
3044     case T_CLASS:
3045         return Symbol::Private;
3046     case T_STRUCT:
3047     case T_UNION:
3048         return Symbol::Public;
3049     default:
3050         return Symbol::Public;
3051     }
3052 }
3053
3054 int Bind::visibilityForObjCAccessSpecifier(int tokenKind)
3055 {
3056     switch (tokenKind) {
3057     case T_AT_PUBLIC:
3058         return Symbol::Public;
3059     case T_AT_PROTECTED:
3060         return Symbol::Protected;
3061     case T_AT_PRIVATE:
3062         return Symbol::Private;
3063     case T_AT_PACKAGE:
3064         return Symbol::Package;
3065     default:
3066         return Symbol::Protected;
3067     }
3068 }
3069
3070 bool Bind::isObjCClassMethod(int tokenKind)
3071 {
3072     switch (tokenKind) {
3073     case T_PLUS:
3074         return true;
3075     case T_MINUS:
3076     default:
3077         return false;
3078     }
3079 }