| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-01-26 18:33:46 +01:00
										 |  |  | ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-11-02 15:59:12 +01:00
										 |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** This file may be used under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  | ** License version 2.1 as published by the Free Software Foundation and | 
					
						
							|  |  |  | ** appearing in the file LICENSE.LGPL included in the packaging of this file. | 
					
						
							|  |  |  | ** Please review the following information to ensure the GNU Lesser General | 
					
						
							|  |  |  | ** Public License version 2.1 requirements will be met: | 
					
						
							|  |  |  | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** In addition, as a special exception, Nokia gives you certain additional | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** rights. These rights are described in the Nokia Qt LGPL Exception | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** Other Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used in accordance with the terms and | 
					
						
							|  |  |  | ** conditions contained in a signed written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** If you have questions regarding the use of this file, please contact | 
					
						
							| 
									
										
										
										
											2011-11-02 15:59:12 +01:00
										 |  |  | ** Nokia at qt-info@nokia.com. | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "cpplocalsymbols.h"
 | 
					
						
							|  |  |  | #include "cppsemanticinfo.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <cplusplus/CppDocument.h>
 | 
					
						
							|  |  |  | #include <ASTVisitor.h>
 | 
					
						
							|  |  |  | #include <AST.h>
 | 
					
						
							|  |  |  | #include <Scope.h>
 | 
					
						
							|  |  |  | #include <Symbols.h>
 | 
					
						
							|  |  |  | #include <CoreTypes.h>
 | 
					
						
							|  |  |  | #include <Names.h>
 | 
					
						
							|  |  |  | #include <Literals.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace CPlusPlus; | 
					
						
							| 
									
										
										
										
											2012-02-07 15:09:08 +01:00
										 |  |  | using namespace CppTools; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FindLocalSymbols: protected ASTVisitor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Scope *_functionScope; | 
					
						
							|  |  |  |     Document::Ptr _doc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     FindLocalSymbols(Document::Ptr doc) | 
					
						
							|  |  |  |         : ASTVisitor(doc->translationUnit()), _doc(doc), hasD(false), hasQ(false) | 
					
						
							|  |  |  |     { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // local and external uses.
 | 
					
						
							|  |  |  |     SemanticInfo::LocalUseMap localUses; | 
					
						
							|  |  |  |     bool hasD; | 
					
						
							|  |  |  |     bool hasQ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void operator()(DeclarationAST *ast) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         localUses.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!ast) | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (FunctionDefinitionAST *def = ast->asFunctionDefinition()) { | 
					
						
							|  |  |  |             if (def->symbol) { | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |                 _functionScope = def->symbol; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |                 accept(ast); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else if (ObjCMethodDeclarationAST *decl = ast->asObjCMethodDeclaration()) { | 
					
						
							|  |  |  |             if (decl->method_prototype->symbol) { | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |                 _functionScope = decl->method_prototype->symbol; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |                 accept(ast); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     using ASTVisitor::visit; | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     using ASTVisitor::endVisit; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     void enterScope(Scope *scope) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         _scopeStack.append(scope); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |         for (unsigned i = 0; i < scope->memberCount(); ++i) { | 
					
						
							|  |  |  |             if (Symbol *member = scope->memberAt(i)) { | 
					
						
							| 
									
										
										
										
											2010-08-12 12:40:43 +02:00
										 |  |  |                 if (member->isTypedef()) | 
					
						
							|  |  |  |                     continue; | 
					
						
							|  |  |  |                 else if (! member->isGenerated() && (member->isDeclaration() || member->isArgument())) { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |                     if (member->name() && member->name()->isNameId()) { | 
					
						
							|  |  |  |                         const Identifier *id = member->identifier(); | 
					
						
							|  |  |  |                         unsigned line, column; | 
					
						
							|  |  |  |                         getTokenStartPosition(member->sourceLocation(), &line, &column); | 
					
						
							| 
									
										
										
										
											2011-08-16 09:47:54 +02:00
										 |  |  |                         localUses[member].append(SemanticInfo::Use(line, column, id->size(), SemanticInfo::LocalUse)); | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-26 11:51:02 +02:00
										 |  |  |     bool checkLocalUse(NameAST *nameAst, unsigned firstToken) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-10-26 11:51:02 +02:00
										 |  |  |         if (SimpleNameAST *simpleName = nameAst->asSimpleName()) { | 
					
						
							| 
									
										
										
										
											2012-03-16 15:31:41 +01:00
										 |  |  |             if (tokenAt(simpleName->identifier_token).generated()) | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |             const Identifier *id = identifier(simpleName->identifier_token); | 
					
						
							|  |  |  |             for (int i = _scopeStack.size() - 1; i != -1; --i) { | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |                 if (Symbol *member = _scopeStack.at(i)->find(id)) { | 
					
						
							| 
									
										
										
										
											2011-10-26 12:45:53 +02:00
										 |  |  |                     if (member->isTypedef() || | 
					
						
							|  |  |  |                             !(member->isDeclaration() || member->isArgument())) | 
					
						
							| 
									
										
										
										
											2010-08-12 12:40:43 +02:00
										 |  |  |                         continue; | 
					
						
							| 
									
										
										
										
											2011-10-26 11:51:02 +02:00
										 |  |  |                     else if (!member->isGenerated() && (member->sourceLocation() < firstToken || member->enclosingScope()->isFunction())) { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |                         unsigned line, column; | 
					
						
							|  |  |  |                         getTokenStartPosition(simpleName->identifier_token, &line, &column); | 
					
						
							| 
									
										
										
										
											2011-08-16 09:47:54 +02:00
										 |  |  |                         localUses[member].append(SemanticInfo::Use(line, column, id->size(), SemanticInfo::LocalUse)); | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |                         return false; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-26 11:51:02 +02:00
										 |  |  |     virtual bool visit(IdExpressionAST *ast) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return checkLocalUse(ast->name, ast->firstToken()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual bool visit(SizeofExpressionAST *ast) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (ast->expression && ast->expression->asTypeId()) { | 
					
						
							|  |  |  |             TypeIdAST *typeId = ast->expression->asTypeId(); | 
					
						
							|  |  |  |             if (!typeId->declarator && typeId->type_specifier_list && !typeId->type_specifier_list->next) { | 
					
						
							|  |  |  |                 if (NamedTypeSpecifierAST *namedTypeSpec = typeId->type_specifier_list->value->asNamedTypeSpecifier()) { | 
					
						
							|  |  |  |                     if (checkLocalUse(namedTypeSpec->name, namedTypeSpec->firstToken())) | 
					
						
							|  |  |  |                         return false; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-26 14:35:52 +02:00
										 |  |  |     virtual bool visit(CastExpressionAST *ast) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (ast->expression && ast->expression->asUnaryExpression()) { | 
					
						
							|  |  |  |             TypeIdAST *typeId = ast->type_id->asTypeId(); | 
					
						
							|  |  |  |             if (typeId && !typeId->declarator && typeId->type_specifier_list && !typeId->type_specifier_list->next) { | 
					
						
							|  |  |  |                 if (NamedTypeSpecifierAST *namedTypeSpec = typeId->type_specifier_list->value->asNamedTypeSpecifier()) { | 
					
						
							|  |  |  |                     if (checkLocalUse(namedTypeSpec->name, namedTypeSpec->firstToken())) { | 
					
						
							|  |  |  |                         accept(ast->expression); | 
					
						
							|  |  |  |                         return false; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual bool visit(QtMemberDeclarationAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (tokenKind(ast->q_token) == T_Q_D) | 
					
						
							|  |  |  |             hasD = true; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             hasQ = true; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual bool visit(FunctionDefinitionAST *ast) | 
					
						
							| 
									
										
										
										
											2010-08-03 13:01:24 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |             enterScope(ast->symbol); | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2010-08-03 13:01:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual void endVisit(FunctionDefinitionAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							|  |  |  |             _scopeStack.removeLast(); | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual bool visit(CompoundStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |             enterScope(ast->symbol); | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual void endVisit(CompoundStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							|  |  |  |             _scopeStack.removeLast(); | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual bool visit(IfStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |             enterScope(ast->symbol); | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual void endVisit(IfStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							|  |  |  |             _scopeStack.removeLast(); | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual bool visit(WhileStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |             enterScope(ast->symbol); | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual void endVisit(WhileStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							|  |  |  |             _scopeStack.removeLast(); | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual bool visit(ForStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |             enterScope(ast->symbol); | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual void endVisit(ForStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							|  |  |  |             _scopeStack.removeLast(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual bool visit(ForeachStatementAST *ast) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (ast->symbol) | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |             enterScope(ast->symbol); | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual void endVisit(ForeachStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							|  |  |  |             _scopeStack.removeLast(); | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-02-19 16:33:25 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual bool visit(RangeBasedForStatementAST *ast) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (ast->symbol) | 
					
						
							|  |  |  |             enterScope(ast->symbol); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void endVisit(RangeBasedForStatementAST *ast) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (ast->symbol) | 
					
						
							|  |  |  |             _scopeStack.removeLast(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual bool visit(SwitchStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |             enterScope(ast->symbol); | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual void endVisit(SwitchStatementAST *ast) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (ast->symbol) | 
					
						
							|  |  |  |             _scopeStack.removeLast(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual bool visit(CatchClauseAST *ast) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (ast->symbol) | 
					
						
							| 
									
										
										
										
											2010-08-11 12:26:02 +02:00
										 |  |  |             enterScope(ast->symbol); | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual void endVisit(CatchClauseAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         if (ast->symbol) | 
					
						
							|  |  |  |             _scopeStack.removeLast(); | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |     virtual bool visit(ExpressionOrDeclarationStatementAST *ast) | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  |         accept(ast->declaration); | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-08-06 11:29:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     QList<Scope *> _scopeStack; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // end of anonymous namespace
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | LocalSymbols::LocalSymbols(CPlusPlus::Document::Ptr doc, CPlusPlus::DeclarationAST *ast) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-08-12 12:45:46 +02:00
										 |  |  |     FindLocalSymbols findLocalSymbols(doc); | 
					
						
							|  |  |  |     findLocalSymbols(ast); | 
					
						
							|  |  |  |     hasD = findLocalSymbols.hasD; | 
					
						
							|  |  |  |     hasQ = findLocalSymbols.hasQ; | 
					
						
							|  |  |  |     uses = findLocalSymbols.localUses; | 
					
						
							| 
									
										
										
										
											2010-07-15 16:03:48 +02:00
										 |  |  | } |