1
/* This file is part of KDevelop
2
Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
3
Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License version 2 as published by the Free Software Foundation.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#ifndef NAME_VISITOR_H
21
#define NAME_VISITOR_H
23
#include "default_visitor.h"
24
#include <language/duchain/identifier.h>
25
#include <cppduchainexport.h>
26
#include "cppducontext.h"
27
#include <language/duchain/ducontext.h>
37
class ExpressionVisitor;
40
///This searches for the name while walking its AST.
41
class KDEVCPPDUCHAIN_EXPORT NameASTVisitor: protected DefaultVisitor
44
///@param context Context in which to look up the name
45
///@param source The source top-context from where the parsing was triggerd
46
///@param localVisibilityContext Local context from where to look up template parameters
47
NameASTVisitor(ParseSession* session, Cpp::ExpressionVisitor* visitor, const KDevelop::DUContext* context, const KDevelop::TopDUContext* source, const KDevelop::DUContext* localVisibilityContext, const KDevelop::SimpleCursor& position, KDevelop::DUContext::SearchFlags localSearchFlags = KDevelop::DUContext::NoSearchFlags, bool debug = false);
49
void run(NameAST *node, bool skipLastNamePart = false);
50
///@param skipThisName if this is true, only the template-parameters of the given node are processed
51
void run(UnqualifiedNameAST *node, bool skipThisName = false);
53
QString name() const { if(m_stopSearch) return QString(); return _M_name.toString(); }
54
QStringList qualifiedName() const { if(m_stopSearch) return QStringList(); return _M_name.toStringList(); }
56
const KDevelop::QualifiedIdentifier& identifier() const;
59
* When the name contains one type-specifier, this should contain that specifier after the run.
60
* Especially this is the type-specifier of a conversion-operator like "operator int()"
62
TypeSpecifierAST* lastTypeSpecifier() const;
64
///Retrieve the declarations found for the name
65
QList<KDevelop::DeclarationPointer> declarations() const;
67
bool stoppedSearch() const {
71
///Whether at least one part of the scope could be resolved
72
DeclarationPointer foundSomething() const;
74
///This can be used from outside to only process the type of a template-argument.
75
///This NameASTVisitor will be in an invalid state after this is called, so don't continue using it!
76
Cpp::ExpressionEvaluationResult processTemplateArgument(TemplateArgumentAST *node);
78
virtual void visitUnqualifiedName(UnqualifiedNameAST *node);
79
void visitTemplateArgument(TemplateArgumentAST *node);
82
ParseSession* m_session;
83
Cpp::ExpressionVisitor* m_visitor;
84
const KDevelop::DUContext* m_context;
85
const KDevelop::TopDUContext* m_source;
86
const KDevelop::DUContext* m_localContext;
87
TypeSpecifierAST* m_typeSpecifier;
88
KDevelop::Identifier m_currentIdentifier;
89
KDevelop::QualifiedIdentifier _M_name;
90
Cpp::FindDeclaration m_find;
92
UnqualifiedNameAST* m_finalName;
93
KDevelop::DUContext::SearchFlags m_flags;
95
DeclarationPointer m_foundSomething;
98
QString decode(ParseSession* session, AST* ast, bool without_spaces = false);
100
#endif // NAME_VISITOR_H