1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
33 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
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:
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
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
55 #include "TranslationUnit.h"
59 #include "CoreTypes.h"
67 using namespace CPlusPlus;
69 const int Bind::kMaxDepth(100);
71 Bind::Bind(TranslationUnit *unit)
77 _visibility(Symbol::Public),
78 _objcVisibility(Symbol::Public),
79 _methodKey(Function::NormalMethod),
80 _skipFunctionBodies(false),
85 bool Bind::skipFunctionBodies() const
87 return _skipFunctionBodies;
90 void Bind::setSkipFunctionBodies(bool skipFunctionBodies)
92 _skipFunctionBodies = skipFunctionBodies;
95 unsigned Bind::location(DeclaratorAST *ast, unsigned defaultLocation) const
98 return defaultLocation;
100 else if (ast->core_declarator)
101 return location(ast->core_declarator, defaultLocation);
103 return ast->firstToken();
106 unsigned Bind::location(CoreDeclaratorAST *ast, unsigned defaultLocation) const
109 return defaultLocation;
111 else if (NestedDeclaratorAST *nested = ast->asNestedDeclarator())
112 return location(nested->declarator, defaultLocation);
114 else if (DeclaratorIdAST *id = ast->asDeclaratorId())
115 return location(id->name, defaultLocation);
117 return ast->firstToken();
120 unsigned Bind::location(NameAST *name, unsigned defaultLocation) const
123 return defaultLocation;
125 else if (DestructorNameAST *dtor = name->asDestructorName())
126 return dtor->identifier_token;
128 else if (TemplateIdAST *templId = name->asTemplateId())
129 return templId->identifier_token;
131 else if (QualifiedNameAST *q = name->asQualifiedName()) {
132 if (q->unqualified_name)
133 return location(q->unqualified_name, defaultLocation);
136 return name->firstToken();
139 void Bind::setDeclSpecifiers(Symbol *symbol, const FullySpecifiedType &declSpecifiers)
144 int storage = Symbol::NoStorage;
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;
161 symbol->setStorage(storage);
163 if (Function *funTy = symbol->asFunction()) {
164 if (declSpecifiers.isVirtual()) {
165 funTy->setVirtual(true);
169 if (declSpecifiers.isDeprecated())
170 symbol->setDeprecated(true);
172 if (declSpecifiers.isUnavailable())
173 symbol->setUnavailable(true);
176 Scope *Bind::switchScope(Scope *scope)
181 std::swap(_scope, scope);
185 int Bind::switchVisibility(int visibility)
187 std::swap(_visibility, visibility);
191 int Bind::switchObjCVisibility(int visibility)
193 std::swap(_objcVisibility, visibility);
197 int Bind::switchMethodKey(int methodKey)
199 std::swap(_methodKey, methodKey);
203 void Bind::operator()(TranslationUnitAST *ast, Namespace *globalNamespace)
205 Scope *previousScope = switchScope(globalNamespace);
206 translationUnit(ast);
207 (void) switchScope(previousScope);
210 void Bind::operator()(DeclarationAST *ast, Scope *scope)
212 Scope *previousScope = switchScope(scope);
214 (void) switchScope(previousScope);
217 FullySpecifiedType Bind::operator()(ExpressionAST *ast, Scope *scope)
219 Scope *previousScope = switchScope(scope);
220 FullySpecifiedType ty = expression(ast);
221 (void) switchScope(previousScope);
225 FullySpecifiedType Bind::operator()(NewTypeIdAST *ast, Scope *scope)
227 Scope *previousScope = switchScope(scope);
228 FullySpecifiedType ty = newTypeId(ast);
229 (void) switchScope(previousScope);
233 void Bind::statement(StatementAST *ast)
238 Bind::ExpressionTy Bind::expression(ExpressionAST *ast)
240 ExpressionTy value = ExpressionTy();
241 std::swap(_expression, value);
243 std::swap(_expression, value);
247 void Bind::declaration(DeclarationAST *ast)
252 const Name *Bind::name(NameAST *ast)
254 const Name *value = 0;
255 std::swap(_name, value);
257 std::swap(_name, value);
261 FullySpecifiedType Bind::specifier(SpecifierAST *ast, const FullySpecifiedType &init)
263 FullySpecifiedType value = init;
264 std::swap(_type, value);
266 std::swap(_type, value);
270 FullySpecifiedType Bind::ptrOperator(PtrOperatorAST *ast, const FullySpecifiedType &init)
272 FullySpecifiedType value = init;
273 std::swap(_type, value);
275 std::swap(_type, value);
279 FullySpecifiedType Bind::coreDeclarator(CoreDeclaratorAST *ast, const FullySpecifiedType &init)
281 FullySpecifiedType value = init;
282 std::swap(_type, value);
284 std::swap(_type, value);
288 FullySpecifiedType Bind::postfixDeclarator(PostfixDeclaratorAST *ast, const FullySpecifiedType &init)
290 FullySpecifiedType value = init;
291 std::swap(_type, value);
293 std::swap(_type, value);
297 bool Bind::preVisit(AST *)
300 if (_depth > kMaxDepth)
305 void Bind::postVisit(AST *)
311 bool Bind::visit(ObjCSelectorArgumentAST *ast)
314 assert(!"unreachable");
318 const Name *Bind::objCSelectorArgument(ObjCSelectorArgumentAST *ast, bool *hasArg)
320 if (! (ast && ast->name_token))
323 if (ast->colon_token)
326 return identifier(ast->name_token);
329 bool Bind::visit(AttributeAST *ast)
332 assert(!"unreachable");
336 void Bind::attribute(AttributeAST *ast)
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);
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);
354 // unsigned rparen_token = ast->rparen_token;
357 bool Bind::visit(DeclaratorAST *ast)
360 assert(!"unreachable");
364 FullySpecifiedType Bind::declarator(DeclaratorAST *ast, const FullySpecifiedType &init, DeclaratorIdAST **declaratorId)
366 FullySpecifiedType type = init;
371 std::swap(_declaratorId, declaratorId);
372 for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
373 type = this->specifier(it->value, type);
375 for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
376 type = this->ptrOperator(it->value, type);
378 for (PostfixDeclaratorListAST *it = ast->postfix_declarator_list; it; it = it->next) {
379 type = this->postfixDeclarator(it->value, type);
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);
385 // unsigned equals_token = ast->equals_token;
386 ExpressionTy initializer = this->expression(ast->initializer);
387 std::swap(_declaratorId, declaratorId);
391 bool Bind::visit(QtPropertyDeclarationItemAST *ast)
394 assert(!"unreachable");
398 bool Bind::visit(QtInterfaceNameAST *ast)
401 assert(!"unreachable");
405 void Bind::qtInterfaceName(QtInterfaceNameAST *ast)
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);
416 bool Bind::visit(BaseSpecifierAST *ast)
419 assert(!"unreachable");
423 void Bind::baseSpecifier(BaseSpecifierAST *ast, unsigned colon_token, Class *klass)
428 unsigned sourceLocation = location(ast->name, ast->firstToken());
429 if (! sourceLocation)
430 sourceLocation = std::max(colon_token, klass->sourceLocation());
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.
440 klass->addBaseClass(baseClass);
441 ast->symbol = baseClass;
444 bool Bind::visit(CtorInitializerAST *ast)
447 assert(!"unreachable");
451 void Bind::ctorInitializer(CtorInitializerAST *ast, Function *fun)
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);
460 // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
463 bool Bind::visit(EnumeratorAST *ast)
466 assert(!"unreachable");
470 void Bind::enumerator(EnumeratorAST *ast, Enum *symbol)
477 // unsigned identifier_token = ast->identifier_token;
478 // unsigned equal_token = ast->equal_token;
479 ExpressionTy expression = this->expression(ast->expression);
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);
489 bool Bind::visit(ExceptionSpecificationAST *ast)
492 assert(!"unreachable");
496 FullySpecifiedType Bind::exceptionSpecification(ExceptionSpecificationAST *ast, const FullySpecifiedType &init)
498 FullySpecifiedType type = init;
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);
509 // unsigned rparen_token = ast->rparen_token;
513 bool Bind::visit(MemInitializerAST *ast)
516 assert(!"unreachable");
520 void Bind::memInitializer(MemInitializerAST *ast, Function *fun)
525 /*const Name *name =*/ this->name(ast->name);
527 Scope *previousScope = switchScope(fun);
528 for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
529 /*ExpressionTy value =*/ this->expression(it->value);
531 (void) switchScope(previousScope);
534 bool Bind::visit(NestedNameSpecifierAST *ast)
537 assert(!"unreachable");
541 const Name *Bind::nestedNameSpecifier(NestedNameSpecifierAST *ast)
546 const Name *class_or_namespace_name = this->name(ast->class_or_namespace_name);
547 return class_or_namespace_name;
550 bool Bind::visit(NewPlacementAST *ast)
553 assert(!"unreachable");
557 void Bind::newPlacement(NewPlacementAST *ast)
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);
566 // unsigned rparen_token = ast->rparen_token;
569 bool Bind::visit(NewArrayDeclaratorAST *ast)
572 assert(!"unreachable");
576 FullySpecifiedType Bind::newArrayDeclarator(NewArrayDeclaratorAST *ast, const FullySpecifiedType &init)
578 FullySpecifiedType type = init;
583 // unsigned lbracket_token = ast->lbracket_token;
584 ExpressionTy expression = this->expression(ast->expression);
585 // unsigned rbracket_token = ast->rbracket_token;
589 bool Bind::visit(NewInitializerAST *ast)
592 assert(!"unreachable");
596 void Bind::newInitializer(NewInitializerAST *ast)
601 // unsigned lparen_token = ast->lparen_token;
602 ExpressionTy expression = this->expression(ast->expression);
603 // unsigned rparen_token = ast->rparen_token;
606 bool Bind::visit(NewTypeIdAST *ast)
609 assert(!"unreachable");
613 FullySpecifiedType Bind::newTypeId(NewTypeIdAST *ast)
615 FullySpecifiedType type;
621 for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
622 type = this->specifier(it->value, type);
624 for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
625 type = this->ptrOperator(it->value, type);
627 for (NewArrayDeclaratorListAST *it = ast->new_array_declarator_list; it; it = it->next) {
628 type = this->newArrayDeclarator(it->value, type);
633 bool Bind::visit(OperatorAST *ast)
636 assert(!"unreachable");
640 OperatorNameId::Kind Bind::cppOperator(OperatorAST *ast)
642 OperatorNameId::Kind kind = OperatorNameId::InvalidOp;
647 // unsigned op_token = ast->op_token;
648 // unsigned open_token = ast->open_token;
649 // unsigned close_token = ast->close_token;
651 switch (tokenKind(ast->op_token)) {
654 kind = OperatorNameId::NewArrayOp;
656 kind = OperatorNameId::NewOp;
661 kind = OperatorNameId::DeleteArrayOp;
663 kind = OperatorNameId::DeleteOp;
667 kind = OperatorNameId::PlusOp;
671 kind = OperatorNameId::MinusOp;
675 kind = OperatorNameId::StarOp;
679 kind = OperatorNameId::SlashOp;
683 kind = OperatorNameId::PercentOp;
687 kind = OperatorNameId::CaretOp;
691 kind = OperatorNameId::AmpOp;
695 kind = OperatorNameId::PipeOp;
699 kind = OperatorNameId::TildeOp;
703 kind = OperatorNameId::ExclaimOp;
707 kind = OperatorNameId::EqualOp;
711 kind = OperatorNameId::LessOp;
715 kind = OperatorNameId::GreaterOp;
719 kind = OperatorNameId::PlusEqualOp;
723 kind = OperatorNameId::MinusEqualOp;
727 kind = OperatorNameId::StarEqualOp;
731 kind = OperatorNameId::SlashEqualOp;
734 case T_PERCENT_EQUAL:
735 kind = OperatorNameId::PercentEqualOp;
739 kind = OperatorNameId::CaretEqualOp;
743 kind = OperatorNameId::AmpEqualOp;
747 kind = OperatorNameId::PipeEqualOp;
751 kind = OperatorNameId::LessLessOp;
754 case T_GREATER_GREATER:
755 kind = OperatorNameId::GreaterGreaterOp;
758 case T_LESS_LESS_EQUAL:
759 kind = OperatorNameId::LessLessEqualOp;
762 case T_GREATER_GREATER_EQUAL:
763 kind = OperatorNameId::GreaterGreaterEqualOp;
767 kind = OperatorNameId::EqualEqualOp;
770 case T_EXCLAIM_EQUAL:
771 kind = OperatorNameId::ExclaimEqualOp;
775 kind = OperatorNameId::LessEqualOp;
778 case T_GREATER_EQUAL:
779 kind = OperatorNameId::GreaterEqualOp;
783 kind = OperatorNameId::AmpAmpOp;
787 kind = OperatorNameId::PipePipeOp;
791 kind = OperatorNameId::PlusPlusOp;
795 kind = OperatorNameId::MinusMinusOp;
799 kind = OperatorNameId::CommaOp;
803 kind = OperatorNameId::ArrowStarOp;
807 kind = OperatorNameId::ArrowOp;
811 kind = OperatorNameId::FunctionCallOp;
815 kind = OperatorNameId::ArrayAccessOp;
819 kind = OperatorNameId::InvalidOp;
825 bool Bind::visit(ParameterDeclarationClauseAST *ast)
828 assert(!"unreachable");
832 void Bind::parameterDeclarationClause(ParameterDeclarationClauseAST *ast, unsigned lparen_token, Function *fun)
838 translationUnit()->warning(lparen_token, "undefined function");
842 Scope *previousScope = switchScope(fun);
844 for (ParameterDeclarationListAST *it = ast->parameter_declaration_list; it; it = it->next) {
845 this->declaration(it->value);
848 if (ast->dot_dot_dot_token)
849 fun->setVariadic(true);
851 (void) switchScope(previousScope);
854 bool Bind::visit(TranslationUnitAST *ast)
857 assert(!"unreachable");
861 void Bind::translationUnit(TranslationUnitAST *ast)
866 for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) {
867 this->declaration(it->value);
871 bool Bind::visit(ObjCProtocolRefsAST *ast)
874 assert(!"unreachable");
878 void Bind::objCProtocolRefs(ObjCProtocolRefsAST *ast, Symbol *objcClassOrProtocol)
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);
893 bool Bind::visit(ObjCMessageArgumentAST *ast)
896 assert(!"unreachable");
900 void Bind::objCMessageArgument(ObjCMessageArgumentAST *ast)
905 ExpressionTy parameter_value_expression = this->expression(ast->parameter_value_expression);
908 bool Bind::visit(ObjCTypeNameAST *ast)
911 assert(!"unreachable");
915 FullySpecifiedType Bind::objCTypeName(ObjCTypeNameAST *ast)
918 return FullySpecifiedType();
920 // unsigned type_qualifier_token = ast->type_qualifier_token;
921 ExpressionTy type_id = this->expression(ast->type_id);
925 bool Bind::visit(ObjCInstanceVariablesDeclarationAST *ast)
928 assert(!"unreachable");
932 void Bind::objCInstanceVariablesDeclaration(ObjCInstanceVariablesDeclarationAST *ast, ObjCClass *klass)
939 // unsigned lbrace_token = ast->lbrace_token;
940 for (DeclarationListAST *it = ast->instance_variable_list; it; it = it->next) {
941 this->declaration(it->value);
943 // unsigned rbrace_token = ast->rbrace_token;
946 bool Bind::visit(ObjCPropertyAttributeAST *ast)
949 assert(!"unreachable");
953 void Bind::objCPropertyAttribute(ObjCPropertyAttributeAST *ast)
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);
963 bool Bind::visit(ObjCMessageArgumentDeclarationAST *ast)
966 assert(!"unreachable");
970 void Bind::objCMessageArgumentDeclaration(ObjCMessageArgumentDeclarationAST *ast, ObjCMethod *method)
975 FullySpecifiedType type = this->objCTypeName(ast->type_name);
977 for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
978 type = this->specifier(it->value, type);
981 const Name *param_name = this->name(ast->param_name);
982 Argument *arg = control()->newArgument(location(ast->param_name, ast->firstToken()), param_name);
985 method->addMember(arg);
988 bool Bind::visit(ObjCMethodPrototypeAST *ast)
991 assert(!"unreachable");
995 ObjCMethod *Bind::objCMethodPrototype(ObjCMethodPrototypeAST *ast)
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);
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;
1013 Scope *previousScope = switchScope(method);
1014 for (ObjCMessageArgumentDeclarationListAST *it = ast->argument_list; it; it = it->next) {
1015 this->objCMessageArgumentDeclaration(it->value, method);
1017 (void) switchScope(previousScope);
1019 if (ast->dot_dot_dot_token)
1020 method->setVariadic(true);
1022 FullySpecifiedType specifiers;
1023 for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
1024 specifiers = this->specifier(it->value, specifiers);
1026 //setDeclSpecifiers(method, specifiers);
1031 bool Bind::visit(ObjCSynthesizedPropertyAST *ast)
1034 assert(!"unreachable");
1038 void Bind::objCSynthesizedProperty(ObjCSynthesizedPropertyAST *ast)
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;
1048 bool Bind::visit(LambdaIntroducerAST *ast)
1051 assert(!"unreachable");
1055 void Bind::lambdaIntroducer(LambdaIntroducerAST *ast)
1060 // unsigned lbracket_token = ast->lbracket_token;
1061 this->lambdaCapture(ast->lambda_capture);
1062 // unsigned rbracket_token = ast->rbracket_token;
1065 bool Bind::visit(LambdaCaptureAST *ast)
1068 assert(!"unreachable");
1072 void Bind::lambdaCapture(LambdaCaptureAST *ast)
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);
1083 bool Bind::visit(CaptureAST *ast)
1086 assert(!"unreachable");
1090 void Bind::capture(CaptureAST *ast)
1097 bool Bind::visit(LambdaDeclaratorAST *ast)
1100 assert(!"unreachable");
1104 void Bind::lambdaDeclarator(LambdaDeclaratorAST *ast)
1110 Function *fun = 0; // ### implement me
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);
1119 // unsigned mutable_token = ast->mutable_token;
1120 type = this->exceptionSpecification(ast->exception_specification, type);
1121 type = this->trailingReturnType(ast->trailing_return_type, type);
1124 bool Bind::visit(TrailingReturnTypeAST *ast)
1127 assert(!"unreachable");
1131 FullySpecifiedType Bind::trailingReturnType(TrailingReturnTypeAST *ast, const FullySpecifiedType &init)
1133 FullySpecifiedType type = init;
1138 // unsigned arrow_token = ast->arrow_token;
1139 for (SpecifierListAST *it = ast->attributes; it; it = it->next) {
1140 type = this->specifier(it->value, type);
1142 for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1143 type = this->specifier(it->value, type);
1145 DeclaratorIdAST *declaratorId = 0;
1146 type = this->declarator(ast->declarator, type, &declaratorId);
1152 bool Bind::visit(QtMemberDeclarationAST *ast)
1154 const Name *name = 0;
1156 if (tokenKind(ast->q_token) == T_Q_D)
1157 name = control()->identifier("d");
1159 name = control()->identifier("q");
1161 FullySpecifiedType declTy = this->expression(ast->type_id);
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";
1170 const Name *privName = control()->identifier(privateClass.c_str(), privateClass.size());
1171 declTy.setType(control()->namedType(privName));
1176 Declaration *symbol = control()->newDeclaration(/*generated*/ 0, name);
1177 symbol->setType(control()->pointerType(declTy));
1179 _scope->addMember(symbol);
1183 bool Bind::visit(CaseStatementAST *ast)
1185 ExpressionTy expression = this->expression(ast->expression);
1186 this->statement(ast->statement);
1190 bool Bind::visit(CompoundStatementAST *ast)
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);
1202 (void) switchScope(previousScope);
1206 bool Bind::visit(DeclarationStatementAST *ast)
1208 this->declaration(ast->declaration);
1212 bool Bind::visit(DoStatementAST *ast)
1214 this->statement(ast->statement);
1215 ExpressionTy expression = this->expression(ast->expression);
1219 bool Bind::visit(ExpressionOrDeclarationStatementAST *ast)
1221 this->statement(ast->expression);
1222 this->statement(ast->declaration);
1226 bool Bind::visit(ExpressionStatementAST *ast)
1228 ExpressionTy expression = this->expression(ast->expression);
1229 // unsigned semicolon_token = ast->semicolon_token;
1233 bool Bind::visit(ForeachStatementAST *ast)
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;
1242 Scope *previousScope = switchScope(block);
1244 FullySpecifiedType type;
1245 for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1246 type = this->specifier(it->value, type);
1248 DeclaratorIdAST *declaratorId = 0;
1249 type = this->declarator(ast->declarator, type, &declaratorId);
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);
1258 /*ExpressionTy initializer =*/ this->expression(ast->initializer);
1259 /*ExpressionTy expression =*/ this->expression(ast->expression);
1260 this->statement(ast->statement);
1261 (void) switchScope(previousScope);
1265 bool Bind::visit(ForStatementAST *ast)
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;
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);
1285 bool Bind::visit(IfStatementAST *ast)
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;
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);
1302 bool Bind::visit(LabeledStatementAST *ast)
1304 // unsigned label_token = ast->label_token;
1305 // unsigned colon_token = ast->colon_token;
1306 this->statement(ast->statement);
1310 bool Bind::visit(BreakStatementAST *ast)
1313 // unsigned break_token = ast->break_token;
1314 // unsigned semicolon_token = ast->semicolon_token;
1318 bool Bind::visit(ContinueStatementAST *ast)
1321 // unsigned continue_token = ast->continue_token;
1322 // unsigned semicolon_token = ast->semicolon_token;
1326 bool Bind::visit(GotoStatementAST *ast)
1329 // unsigned goto_token = ast->goto_token;
1330 // unsigned identifier_token = ast->identifier_token;
1331 // unsigned semicolon_token = ast->semicolon_token;
1335 bool Bind::visit(ReturnStatementAST *ast)
1337 ExpressionTy expression = this->expression(ast->expression);
1341 bool Bind::visit(SwitchStatementAST *ast)
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;
1350 Scope *previousScope = switchScope(block);
1351 /*ExpressionTy condition =*/ this->expression(ast->condition);
1352 this->statement(ast->statement);
1353 (void) switchScope(previousScope);
1357 bool Bind::visit(TryBlockStatementAST *ast)
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);
1367 bool Bind::visit(CatchClauseAST *ast)
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;
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);
1384 bool Bind::visit(WhileStatementAST *ast)
1386 Block *block = control()->newBlock(ast->firstToken());
1387 const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
1388 block->setStartOffset(tokenAt(startScopeToken).end());
1389 block->setEndOffset(tokenAt(ast->lastToken()).begin());
1390 _scope->addMember(block);
1391 ast->symbol = block;
1393 Scope *previousScope = switchScope(block);
1394 /*ExpressionTy condition =*/ this->expression(ast->condition);
1395 this->statement(ast->statement);
1396 (void) switchScope(previousScope);
1400 bool Bind::visit(ObjCFastEnumerationAST *ast)
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;
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);
1414 DeclaratorIdAST *declaratorId = 0;
1415 type = this->declarator(ast->declarator, type, &declaratorId);
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);
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);
1431 bool Bind::visit(ObjCSynchronizedStatementAST *ast)
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);
1443 bool Bind::visit(IdExpressionAST *ast)
1445 /*const Name *name =*/ this->name(ast->name);
1449 bool Bind::visit(CompoundExpressionAST *ast)
1451 // unsigned lparen_token = ast->lparen_token;
1452 this->statement(ast->statement);
1453 // unsigned rparen_token = ast->rparen_token;
1457 bool Bind::visit(CompoundLiteralAST *ast)
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);
1466 bool Bind::visit(QtMethodAST *ast)
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;
1477 bool Bind::visit(BinaryExpressionAST *ast)
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);
1485 bool Bind::visit(CastExpressionAST *ast)
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);
1494 bool Bind::visit(ConditionAST *ast)
1496 FullySpecifiedType type;
1497 for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1498 type = this->specifier(it->value, type);
1500 DeclaratorIdAST *declaratorId = 0;
1501 type = this->declarator(ast->declarator, type, &declaratorId);
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);
1513 bool Bind::visit(ConditionalExpressionAST *ast)
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);
1523 bool Bind::visit(CppCastExpressionAST *ast)
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;
1535 bool Bind::visit(DeleteExpressionAST *ast)
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);
1545 bool Bind::visit(ArrayInitializerAST *ast)
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);
1551 // unsigned rbrace_token = ast->rbrace_token;
1555 bool Bind::visit(NewExpressionAST *ast)
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);
1568 bool Bind::visit(TypeidExpressionAST *ast)
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;
1577 bool Bind::visit(TypenameCallExpressionAST *ast)
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);
1585 // unsigned rparen_token = ast->rparen_token;
1589 bool Bind::visit(TypeConstructorCallAST *ast)
1591 FullySpecifiedType type;
1592 for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1593 type = this->specifier(it->value, type);
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);
1599 // unsigned rparen_token = ast->rparen_token;
1603 bool Bind::visit(SizeofExpressionAST *ast)
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;
1613 bool Bind::visit(NumericLiteralAST *ast)
1616 // unsigned literal_token = ast->literal_token;
1620 bool Bind::visit(BoolLiteralAST *ast)
1623 // unsigned literal_token = ast->literal_token;
1627 bool Bind::visit(ThisExpressionAST *ast)
1630 // unsigned this_token = ast->this_token;
1634 bool Bind::visit(NestedExpressionAST *ast)
1636 // unsigned lparen_token = ast->lparen_token;
1637 ExpressionTy expression = this->expression(ast->expression);
1638 // unsigned rparen_token = ast->rparen_token;
1642 bool Bind::visit(StringLiteralAST *ast)
1644 // unsigned literal_token = ast->literal_token;
1645 ExpressionTy next = this->expression(ast->next);
1649 bool Bind::visit(ThrowExpressionAST *ast)
1651 // unsigned throw_token = ast->throw_token;
1652 ExpressionTy expression = this->expression(ast->expression);
1656 bool Bind::visit(TypeIdAST *ast)
1658 FullySpecifiedType type;
1659 for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
1660 type = this->specifier(it->value, type);
1662 DeclaratorIdAST *declaratorId = 0;
1663 type = this->declarator(ast->declarator, type, &declaratorId);
1668 bool Bind::visit(UnaryExpressionAST *ast)
1670 // unsigned unary_op_token = ast->unary_op_token;
1671 ExpressionTy expression = this->expression(ast->expression);
1675 bool Bind::visit(ObjCMessageExpressionAST *ast)
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);
1683 // unsigned rbracket_token = ast->rbracket_token;
1687 bool Bind::visit(ObjCProtocolExpressionAST *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;
1697 bool Bind::visit(ObjCEncodeExpressionAST *ast)
1699 // unsigned encode_token = ast->encode_token;
1700 FullySpecifiedType type = this->objCTypeName(ast->type_name);
1704 bool Bind::visit(ObjCSelectorExpressionAST *ast)
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;
1713 bool Bind::visit(LambdaExpressionAST *ast)
1715 this->lambdaIntroducer(ast->lambda_introducer);
1716 this->lambdaDeclarator(ast->lambda_declarator);
1717 this->statement(ast->statement);
1721 bool Bind::visit(BracedInitializerAST *ast)
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);
1727 // unsigned comma_token = ast->comma_token;
1728 // unsigned rbrace_token = ast->rbrace_token;
1732 static int methodKeyForInvokableToken(int kind)
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;
1741 return Function::NormalMethod;
1745 bool Bind::visit(SimpleDeclarationAST *ast)
1747 int methodKey = _methodKey;
1748 if (ast->qt_invokable_token)
1749 methodKey = methodKeyForInvokableToken(tokenKind(ast->qt_invokable_token));
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);
1757 List<Symbol *> **symbolTail = &ast->symbols;
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();
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;
1772 ForwardClassDeclaration *decl = control()->newForwardClassDeclaration(sourceLocation, name);
1773 setDeclSpecifiers(decl, type);
1774 _scope->addMember(decl);
1776 *symbolTail = new (translationUnit()->memoryPool()) List<Symbol *>(decl);
1777 symbolTail = &(*symbolTail)->next;
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);
1785 const Name *declName = 0;
1786 unsigned sourceLocation = location(it->value, ast->firstToken());
1787 if (declaratorId && declaratorId->name) {
1788 declName = declaratorId->name->name;
1791 Declaration *decl = control()->newDeclaration(sourceLocation, declName);
1792 decl->setType(declTy);
1793 setDeclSpecifiers(decl, type);
1795 if (Function *fun = decl->type()->asFunctionType()) {
1796 fun->setScope(_scope);
1798 setDeclSpecifiers(fun, type);
1799 if (declaratorId && declaratorId->name)
1800 fun->setName(declaratorId->name->name); // update the function name
1803 if (_scope->isClass()) {
1804 decl->setVisibility(_visibility);
1806 if (Function *funTy = decl->type()->asFunctionType()) {
1807 funTy->setMethodKey(methodKey);
1809 if (funTy->isVirtual() && it->value->equal_token)
1810 funTy->setPureVirtual(true);
1814 _scope->addMember(decl);
1816 *symbolTail = new (translationUnit()->memoryPool()) List<Symbol *>(decl);
1817 symbolTail = &(*symbolTail)->next;
1822 bool Bind::visit(EmptyDeclarationAST *ast)
1825 unsigned semicolon_token = ast->semicolon_token;
1826 if (_scope && (_scope->isClass() || _scope->isNamespace())) {
1827 const Token &tk = tokenAt(semicolon_token);
1829 if (! tk.generated())
1830 translationUnit()->warning(semicolon_token, "extra `;'");
1835 bool Bind::visit(AccessDeclarationAST *ast)
1837 const int accessSpecifier = tokenKind(ast->access_specifier_token);
1838 _visibility = visibilityForAccessSpecifier(accessSpecifier);
1840 if (ast->slots_token)
1841 _methodKey = Function::SlotMethod;
1842 else if (accessSpecifier == T_Q_SIGNALS)
1843 _methodKey = Function::SignalMethod;
1845 _methodKey = Function::NormalMethod;
1850 bool Bind::visit(QtObjectTagAST *ast)
1853 // unsigned q_object_token = ast->q_object_token;
1857 bool Bind::visit(QtPrivateSlotAST *ast)
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);
1869 DeclaratorIdAST *declaratorId = 0;
1870 type = this->declarator(ast->declarator, type, &declaratorId);
1871 // unsigned rparen_token = ast->rparen_token;
1875 static void qtPropertyAttribute(TranslationUnit *unit, ExpressionAST *expression,
1877 QtPropertyDeclaration::Flag flag,
1878 QtPropertyDeclaration::Flag function)
1882 *flags &= ~function & ~flag;
1883 if (BoolLiteralAST *boollit = expression->asBoolLiteral()) {
1884 const int kind = unit->tokenAt(boollit->literal_token).kind();
1892 bool Bind::visit(QtPropertyDeclarationAST *ast)
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);
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);
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)
1911 this->expression(it->value->expression);
1913 std::string name = spell(it->value->item_name_token);
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);
1941 propertyDeclaration->setFlags(flags);
1942 _scope->addMember(propertyDeclaration);
1943 // unsigned rparen_token = ast->rparen_token;
1947 bool Bind::visit(QtEnumDeclarationAST *ast)
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);
1955 QtEnum *qtEnum = control()->newQtEnum(it->value->firstToken(), value);
1956 _scope->addMember(qtEnum);
1959 // unsigned rparen_token = ast->rparen_token;
1963 bool Bind::visit(QtFlagsDeclarationAST *ast)
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);
1970 // unsigned rparen_token = ast->rparen_token;
1974 bool Bind::visit(QtInterfacesDeclarationAST *ast)
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);
1981 // unsigned rparen_token = ast->rparen_token;
1985 bool Bind::visit(AsmDefinitionAST *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;
1996 bool Bind::visit(ExceptionDeclarationAST *ast)
1998 FullySpecifiedType type;
1999 for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
2000 type = this->specifier(it->value, type);
2002 DeclaratorIdAST *declaratorId = 0;
2003 type = this->declarator(ast->declarator, type, &declaratorId);
2004 // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
2008 bool Bind::visit(FunctionDefinitionAST *ast)
2010 int methodKey = _methodKey;
2011 if (ast->qt_invokable_token)
2012 methodKey = methodKeyForInvokableToken(tokenKind(ast->qt_invokable_token));
2014 FullySpecifiedType declSpecifiers;
2015 for (SpecifierListAST *it = ast->decl_specifier_list; it; it = it->next) {
2016 declSpecifiers = this->specifier(it->value, declSpecifiers);
2018 DeclaratorIdAST *declaratorId = 0;
2019 FullySpecifiedType type = this->declarator(ast->declarator, declSpecifiers.qualifiedType(), &declaratorId);
2021 Function *fun = type->asFunctionType();
2025 setDeclSpecifiers(fun, declSpecifiers);
2027 if (_scope->isClass()) {
2028 fun->setVisibility(_visibility);
2029 fun->setMethodKey(methodKey);
2032 if (declaratorId && declaratorId->name) {
2033 fun->setSourceLocation(location(declaratorId, ast->firstToken()), translationUnit());
2034 fun->setName(declaratorId->name->name);
2037 _scope->addMember(fun);
2039 translationUnit()->warning(ast->firstToken(), "expected a function declarator");
2041 this->ctorInitializer(ast->ctor_initializer, fun);
2043 if (fun && ! _skipFunctionBodies && ast->function_body) {
2044 Scope *previousScope = switchScope(fun);
2045 this->statement(ast->function_body);
2046 (void) switchScope(previousScope);
2048 if (CompoundStatementAST *c = ast->function_body->asCompoundStatement()) {
2050 fun->setEndOffset(c->symbol->endOffset());
2058 bool Bind::visit(LinkageBodyAST *ast)
2060 // unsigned lbrace_token = ast->lbrace_token;
2061 for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) {
2062 this->declaration(it->value);
2064 // unsigned rbrace_token = ast->rbrace_token;
2068 bool Bind::visit(LinkageSpecificationAST *ast)
2070 // unsigned extern_token = ast->extern_token;
2071 // unsigned extern_type_token = ast->extern_type_token;
2072 this->declaration(ast->declaration);
2076 bool Bind::visit(NamespaceAST *ast)
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);
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);
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());
2096 _scope->addMember(ns);
2098 Scope *previousScope = switchScope(ns);
2099 this->declaration(ast->linkage_body);
2100 (void) switchScope(previousScope);
2104 bool Bind::visit(NamespaceAliasDefinitionAST *ast)
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);
2113 NamespaceAlias *namespaceAlias = control()->newNamespaceAlias(sourceLocation, name);
2114 namespaceAlias->setNamespaceName(this->name(ast->name));
2115 _scope->addMember(namespaceAlias);
2119 bool Bind::visit(ParameterDeclarationAST *ast)
2121 FullySpecifiedType type;
2122 for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
2123 type = this->specifier(it->value, type);
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);
2130 unsigned sourceLocation = ast->firstToken();
2132 sourceLocation = declaratorId->firstToken();
2134 const Name *argName = 0;
2135 if (declaratorId && declaratorId->name)
2136 argName = declaratorId->name->name;
2138 Argument *arg = control()->newArgument(location(declaratorId, ast->firstToken()), argName);
2141 if (ast->expression) {
2142 unsigned startOfExpression = ast->expression->firstToken();
2143 unsigned endOfExpression = ast->expression->lastToken();
2145 for (unsigned index = startOfExpression; index != endOfExpression; ++index) {
2146 const Token &tk = tokenAt(index);
2147 if (tk.whitespace() || tk.newline())
2149 buffer += tk.spell();
2151 const StringLiteral *initializer = control()->stringLiteral(buffer.c_str(), buffer.size());
2152 arg->setInitializer(initializer);
2155 _scope->addMember(arg);
2161 bool Bind::visit(TemplateDeclarationAST *ast)
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);
2169 for (DeclarationListAST *it = ast->template_parameter_list; it; it = it->next) {
2170 this->declaration(it->value);
2172 // unsigned greater_token = ast->greater_token;
2173 this->declaration(ast->declaration);
2174 (void) switchScope(previousScope);
2176 if (Symbol *decl = templ->declaration()) {
2177 templ->setSourceLocation(decl->sourceLocation(), translationUnit());
2178 templ->setName(decl->name());
2181 _scope->addMember(templ);
2185 bool Bind::visit(TypenameTypeParameterAST *ast)
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);
2193 TypenameArgument *arg = control()->newTypenameArgument(sourceLocation, name);
2194 arg->setType(type_id);
2196 _scope->addMember(arg);
2200 bool Bind::visit(TemplateTypeParameterAST *ast)
2202 unsigned sourceLocation = location(ast->name, ast->firstToken());
2204 // unsigned template_token = ast->template_token;
2205 // unsigned less_token = ast->less_token;
2206 // ### process the template prototype
2208 for (DeclarationListAST *it = ast->template_parameter_list; it; it = it->next) {
2209 this->declaration(it->value);
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;
2216 const Name *name = this->name(ast->name);
2217 ExpressionTy type_id = this->expression(ast->type_id);
2219 // ### introduce TemplateTypeArgument
2220 TypenameArgument *arg = control()->newTypenameArgument(sourceLocation, name);
2221 arg->setType(type_id);
2223 _scope->addMember(arg);
2228 bool Bind::visit(UsingAST *ast)
2230 unsigned sourceLocation = location(ast->name, ast->firstToken());
2231 const Name *name = this->name(ast->name);
2233 UsingDeclaration *symbol = control()->newUsingDeclaration(sourceLocation, name);
2234 ast->symbol = symbol;
2235 _scope->addMember(symbol);
2239 bool Bind::visit(UsingDirectiveAST *ast)
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);
2249 bool Bind::visit(ObjCClassForwardDeclarationAST *ast)
2251 FullySpecifiedType declSpecifiers;
2252 for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2253 declSpecifiers = this->specifier(it->value, declSpecifiers);
2256 List<ObjCForwardClassDeclaration *> **symbolTail = &ast->symbols;
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);
2262 const unsigned sourceLocation = location(it->value, ast->firstToken());
2263 ObjCForwardClassDeclaration *fwd = control()->newObjCForwardClassDeclaration(sourceLocation, name);
2264 setDeclSpecifiers(fwd, declSpecifiers);
2265 _scope->addMember(fwd);
2267 *symbolTail = new (translationUnit()->memoryPool()) List<ObjCForwardClassDeclaration *>(fwd);
2268 symbolTail = &(*symbolTail)->next;
2274 unsigned Bind::calculateScopeStart(ObjCClassDeclarationAST *ast) const
2276 if (ast->inst_vars_decl)
2277 if (unsigned pos = ast->inst_vars_decl->lbrace_token)
2278 return tokenAt(pos).end();
2280 if (ast->protocol_refs)
2281 if (unsigned pos = ast->protocol_refs->lastToken())
2282 return tokenAt(pos - 1).end();
2284 if (ast->superclass)
2285 if (unsigned pos = ast->superclass->lastToken())
2286 return tokenAt(pos - 1).end();
2288 if (ast->colon_token)
2289 return tokenAt(ast->colon_token).end();
2291 if (ast->rparen_token)
2292 return tokenAt(ast->rparen_token).end();
2294 if (ast->category_name)
2295 if (unsigned pos = ast->category_name->lastToken())
2296 return tokenAt(pos - 1).end();
2298 if (ast->lparen_token)
2299 return tokenAt(ast->lparen_token).end();
2301 if (ast->class_name)
2302 if (unsigned pos = ast->class_name->lastToken())
2303 return tokenAt(pos - 1).end();
2305 return tokenAt(ast->firstToken()).begin();
2308 bool Bind::visit(ObjCClassDeclarationAST *ast)
2310 FullySpecifiedType declSpecifiers;
2311 for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2312 declSpecifiers = this->specifier(it->value, declSpecifiers);
2314 const Name *class_name = this->name(ast->class_name);
2315 const Name *category_name = this->name(ast->category_name);
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);
2322 klass->setStartOffset(calculateScopeStart(ast));
2323 klass->setEndOffset(tokenAt(ast->lastToken() - 1).begin());
2325 if (ast->interface_token)
2326 klass->setInterface(true);
2328 klass->setCategoryName(category_name);
2330 Scope *previousScope = switchScope(klass);
2332 if (const Name *superclass = this->name(ast->superclass)) {
2333 ObjCBaseClass *superKlass = control()->newObjCBaseClass(ast->superclass->firstToken(), superclass);
2334 klass->setBaseClass(superKlass);
2337 this->objCProtocolRefs(ast->protocol_refs, klass);
2339 const int previousObjCVisibility = switchObjCVisibility(Function::Protected);
2341 this->objCInstanceVariablesDeclaration(ast->inst_vars_decl, klass);
2343 (void) switchObjCVisibility(Function::Public);
2344 for (DeclarationListAST *it = ast->member_declaration_list; it; it = it->next) {
2345 this->declaration(it->value);
2348 (void) switchObjCVisibility(previousObjCVisibility);
2349 (void) switchScope(previousScope);
2353 bool Bind::visit(ObjCProtocolForwardDeclarationAST *ast)
2355 FullySpecifiedType declSpecifiers;
2356 for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2357 declSpecifiers = this->specifier(it->value, declSpecifiers);
2360 List<ObjCForwardProtocolDeclaration *> **symbolTail = &ast->symbols;
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);
2366 const unsigned sourceLocation = location(it->value, ast->firstToken());
2367 ObjCForwardProtocolDeclaration *fwd = control()->newObjCForwardProtocolDeclaration(sourceLocation, name);
2368 setDeclSpecifiers(fwd, declSpecifiers);
2369 _scope->addMember(fwd);
2371 *symbolTail = new (translationUnit()->memoryPool()) List<ObjCForwardProtocolDeclaration *>(fwd);
2372 symbolTail = &(*symbolTail)->next;
2378 unsigned Bind::calculateScopeStart(ObjCProtocolDeclarationAST *ast) const
2380 if (ast->protocol_refs)
2381 if (unsigned pos = ast->protocol_refs->lastToken())
2382 return tokenAt(pos - 1).end();
2384 if (unsigned pos = ast->name->lastToken())
2385 return tokenAt(pos - 1).end();
2387 return tokenAt(ast->firstToken()).begin();
2390 bool Bind::visit(ObjCProtocolDeclarationAST *ast)
2392 FullySpecifiedType type;
2393 for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2394 type = this->specifier(it->value, type);
2396 // unsigned protocol_token = ast->protocol_token;
2397 const Name *name = this->name(ast->name);
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);
2406 Scope *previousScope = switchScope(protocol);
2407 const int previousObjCVisibility = switchObjCVisibility(Function::Public);
2409 this->objCProtocolRefs(ast->protocol_refs, protocol);
2410 for (DeclarationListAST *it = ast->member_declaration_list; it; it = it->next) {
2411 this->declaration(it->value);
2414 (void) switchObjCVisibility(previousObjCVisibility);
2415 (void) switchScope(previousScope);
2419 bool Bind::visit(ObjCVisibilityDeclarationAST *ast)
2421 _objcVisibility = visibilityForObjCAccessSpecifier(tokenKind(ast->visibility_token));
2425 bool Bind::visit(ObjCPropertyDeclarationAST *ast)
2428 FullySpecifiedType type;
2429 for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2430 type = this->specifier(it->value, type);
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);
2437 // unsigned rparen_token = ast->rparen_token;
2438 this->declaration(ast->simple_declaration);
2439 // List<ObjCPropertyDeclaration *> *symbols = ast->symbols;
2443 bool Bind::visit(ObjCMethodDeclarationAST *ast)
2445 ObjCMethod *method = this->objCMethodPrototype(ast->method_prototype);
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);
2463 bool Bind::visit(ObjCSynthesizedPropertiesDeclarationAST *ast)
2465 // unsigned synthesized_token = ast->synthesized_token;
2466 for (ObjCSynthesizedPropertyListAST *it = ast->property_identifier_list; it; it = it->next) {
2467 this->objCSynthesizedProperty(it->value);
2469 // unsigned semicolon_token = ast->semicolon_token;
2473 bool Bind::visit(ObjCDynamicPropertiesDeclarationAST *ast)
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);
2479 // unsigned semicolon_token = ast->semicolon_token;
2485 bool Bind::visit(ObjCSelectorAST *ast) // ### review
2487 std::vector<const Name *> arguments;
2488 bool hasArgs = false;
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);
2495 if (! arguments.empty()) {
2496 _name = control()->selectorNameId(&arguments[0], arguments.size(), hasArgs);
2503 bool Bind::visit(QualifiedNameAST *ast)
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);
2510 _name = class_or_namespace_name;
2513 const Name *unqualified_name = this->name(ast->unqualified_name);
2514 if (_name || ast->global_scope_token)
2515 _name = control()->qualifiedNameId(_name, unqualified_name);
2517 _name = unqualified_name;
2523 bool Bind::visit(OperatorFunctionIdAST *ast)
2525 const OperatorNameId::Kind op = this->cppOperator(ast->op);
2526 ast->name = _name = control()->operatorNameId(op);
2530 bool Bind::visit(ConversionFunctionIdAST *ast)
2532 FullySpecifiedType type;
2533 for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
2534 type = this->specifier(it->value, type);
2536 for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
2537 type = this->ptrOperator(it->value, type);
2539 ast->name = _name = control()->conversionNameId(type);
2543 bool Bind::visit(SimpleNameAST *ast)
2545 const Identifier *id = identifier(ast->identifier_token);
2551 bool Bind::visit(DestructorNameAST *ast)
2553 const Identifier *id = identifier(ast->identifier_token);
2554 _name = control()->destructorNameId(id);
2559 bool Bind::visit(TemplateIdAST *ast)
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);
2568 const Identifier *id = identifier(ast->identifier_token);
2569 if (templateArguments.empty())
2570 _name = control()->templateNameId(id);
2572 _name = control()->templateNameId(id, &templateArguments[0], templateArguments.size());
2580 bool Bind::visit(SimpleSpecifierAST *ast)
2582 switch (tokenKind(ast->specifier_token)) {
2584 if (_type.isConst())
2585 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2586 _type.setConst(true);
2590 if (_type.isVolatile())
2591 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2592 _type.setVolatile(true);
2596 if (_type.isFriend())
2597 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2598 _type.setFriend(true);
2603 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2604 _type.setAuto(true);
2608 if (_type.isRegister())
2609 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2610 _type.setRegister(true);
2614 if (_type.isStatic())
2615 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2616 _type.setStatic(true);
2620 if (_type.isExtern())
2621 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2622 _type.setExtern(true);
2626 if (_type.isMutable())
2627 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2628 _type.setMutable(true);
2632 if (_type.isTypedef())
2633 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2634 _type.setTypedef(true);
2638 if (_type.isInline())
2639 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2640 _type.setInline(true);
2644 if (_type.isVirtual())
2645 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2646 _type.setVirtual(true);
2650 if (_type.isExplicit())
2651 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2652 _type.setExplicit(true);
2656 if (_type.isSigned())
2657 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2658 _type.setSigned(true);
2662 if (_type.isUnsigned())
2663 translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
2664 _type.setUnsigned(true);
2669 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2670 _type.setType(control()->integerType(IntegerType::Char));
2675 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2676 _type.setType(control()->integerType(IntegerType::WideChar));
2681 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2682 _type.setType(control()->integerType(IntegerType::Bool));
2687 IntegerType *intType = control()->integerType(IntegerType::Int);
2688 if (_type.type() != intType)
2689 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2691 _type.setType(control()->integerType(IntegerType::Short));
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)
2702 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2704 _type.setType(control()->integerType(IntegerType::Int));
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));
2716 } else if (tp == doubleType) {
2717 _type.setType(control()->floatType(FloatType::LongDouble));
2719 } else if (tp != intType) {
2720 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2723 _type.setType(control()->integerType(IntegerType::Long));
2728 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2729 _type.setType(control()->floatType(FloatType::Float));
2734 IntegerType *longType = control()->integerType(IntegerType::Long);
2735 if (_type.type() == longType) {
2736 _type.setType(control()->floatType(FloatType::LongDouble));
2739 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2741 _type.setType(control()->floatType(FloatType::Double));
2746 translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
2747 _type.setType(control()->voidType());
2756 bool Bind::visit(AttributeSpecifierAST *ast)
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);
2764 // unsigned first_rparen_token = ast->first_rparen_token;
2765 // unsigned second_rparen_token = ast->second_rparen_token;
2769 bool Bind::visit(TypeofSpecifierAST *ast)
2771 ExpressionTy expression = this->expression(ast->expression);
2776 bool Bind::visit(ClassSpecifierAST *ast)
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
2782 for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
2783 _type = this->specifier(it->value, _type);
2786 const Name *className = this->name(ast->name);
2789 sourceLocation = location(ast->name, sourceLocation);
2790 startScopeOffset = tokenAt(sourceLocation).end(); // at the end of the class name
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
2800 Class *klass = control()->newClass(sourceLocation, className);
2801 klass->setStartOffset(startScopeOffset);
2802 klass->setEndOffset(tokenAt(ast->lastToken() - 1).end());
2803 _scope->addMember(klass);
2805 if (_scope->isClass())
2806 klass->setVisibility(_visibility);
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);
2817 _type.setType(klass);
2819 Scope *previousScope = switchScope(klass);
2820 const int previousVisibility = switchVisibility(visibilityForClassKey(classKey));
2821 const int previousMethodKey = switchMethodKey(Function::NormalMethod);
2823 for (BaseSpecifierListAST *it = ast->base_clause_list; it; it = it->next) {
2824 this->baseSpecifier(it->value, ast->colon_token, klass);
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);
2831 (void) switchMethodKey(previousMethodKey);
2832 (void) switchVisibility(previousVisibility);
2833 (void) switchScope(previousScope);
2835 ast->symbol = klass;
2839 bool Bind::visit(NamedTypeSpecifierAST *ast)
2841 _type.setType(control()->namedType(this->name(ast->name)));
2845 bool Bind::visit(ElaboratedTypeSpecifierAST *ast)
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);
2851 _type.setType(control()->namedType(this->name(ast->name)));
2855 bool Bind::visit(EnumSpecifierAST *ast)
2857 unsigned sourceLocation = location(ast->name, ast->firstToken());
2858 const Name *enumName = this->name(ast->name);
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());
2864 _scope->addMember(e);
2866 if (_scope->isClass())
2867 e->setVisibility(_visibility);
2869 Scope *previousScope = switchScope(e);
2870 for (EnumeratorListAST *it = ast->enumerator_list; it; it = it->next) {
2871 this->enumerator(it->value, e);
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");
2881 (void) switchScope(previousScope);
2887 bool Bind::visit(PointerToMemberAST *ast)
2889 const Name *memberName = 0;
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);
2896 memberName = class_or_namespace_name;
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);
2907 bool Bind::visit(PointerAST *ast)
2909 if (_type->isReferenceType())
2910 translationUnit()->error(ast->firstToken(), "cannot declare pointer to a reference");
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);
2920 bool Bind::visit(ReferenceAST *ast)
2922 const bool rvalueRef = (tokenKind(ast->reference_token) == T_AMPER_AMPER);
2924 if (_type->isReferenceType())
2925 translationUnit()->error(ast->firstToken(), "cannot declare reference to a reference");
2927 FullySpecifiedType type(control()->referenceType(_type, rvalueRef));
2934 bool Bind::visit(CallAST *ast)
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);
2941 // unsigned rparen_token = ast->rparen_token;
2945 bool Bind::visit(ArrayAccessAST *ast)
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;
2954 bool Bind::visit(PostIncrDecrAST *ast)
2956 ExpressionTy base_expression = this->expression(ast->base_expression);
2957 // unsigned incr_decr_token = ast->incr_decr_token;
2961 bool Bind::visit(MemberAccessAST *ast)
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);
2971 // CoreDeclaratorAST
2972 bool Bind::visit(DeclaratorIdAST *ast)
2974 /*const Name *name =*/ this->name(ast->name);
2975 *_declaratorId = ast;
2979 bool Bind::visit(NestedDeclaratorAST *ast)
2981 _type = this->declarator(ast->declarator, _type, _declaratorId);
2986 // PostfixDeclaratorAST
2987 bool Bind::visit(FunctionDeclaratorAST *ast)
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);
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);
3002 // propagate the cv-qualifiers
3003 fun->setConst(type.isConst());
3004 fun->setVolatile(type.isVolatile());
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);
3017 bool Bind::visit(ArrayDeclaratorAST *ast)
3019 ExpressionTy expression = this->expression(ast->expression);
3020 FullySpecifiedType type(control()->arrayType(_type));
3025 int Bind::visibilityForAccessSpecifier(int tokenKind)
3027 switch (tokenKind) {
3029 return Symbol::Public;
3031 return Symbol::Protected;
3033 return Symbol::Private;
3035 return Symbol::Protected;
3037 return Symbol::Public;
3041 int Bind::visibilityForClassKey(int tokenKind)
3043 switch (tokenKind) {
3045 return Symbol::Private;
3048 return Symbol::Public;
3050 return Symbol::Public;
3054 int Bind::visibilityForObjCAccessSpecifier(int tokenKind)
3056 switch (tokenKind) {
3058 return Symbol::Public;
3059 case T_AT_PROTECTED:
3060 return Symbol::Protected;
3062 return Symbol::Private;
3064 return Symbol::Package;
3066 return Symbol::Protected;
3070 bool Bind::isObjCClassMethod(int tokenKind)
3072 switch (tokenKind) {