Files
qt-creator/src/libs/cplusplus/FindUsages.h

127 lines
3.9 KiB
C
Raw Normal View History

2009-10-27 12:01:45 +01:00
/**************************************************************************
**
** This file is part of Qt Creator
**
2010-03-05 11:25:49 +01:00
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
2009-10-27 12:01:45 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef FINDUSAGES_H
#define FINDUSAGES_H
#include "LookupContext.h"
2009-10-27 12:01:45 +01:00
#include "CppDocument.h"
#include "CppBindings.h"
#include "Semantic.h"
#include <ASTVisitor.h>
#include <QtCore/QSet>
2009-10-27 12:01:45 +01:00
namespace CPlusPlus {
class CPLUSPLUS_EXPORT Usage
{
public:
Usage()
: line(0), col(0), len(0) {}
Usage(const QString &path, const QString &lineText, int line, int col, int len)
2009-12-01 17:31:41 +01:00
: path(path), lineText(lineText), line(line), col(col), len(len) {}
2009-10-27 12:01:45 +01:00
public:
QString path;
QString lineText;
2009-12-01 17:31:41 +01:00
int line;
2009-10-27 12:01:45 +01:00
int col;
int len;
};
class CPLUSPLUS_EXPORT FindUsages: protected ASTVisitor
{
public:
FindUsages(Document::Ptr doc, const Snapshot &snapshot);
2009-10-27 12:01:45 +01:00
void setGlobalNamespaceBinding(NamespaceBindingPtr globalNamespaceBinding);
2009-12-03 11:59:37 +01:00
void operator()(Symbol *symbol);
2009-12-01 17:31:41 +01:00
QList<Usage> usages() const;
QList<int> references() const;
2009-10-27 12:01:45 +01:00
protected:
using ASTVisitor::visit;
using ASTVisitor::endVisit;
QString matchingLine(const Token &tk) const;
Scope *scopeAt(unsigned tokenIndex) const;
2009-10-27 12:01:45 +01:00
void reportResult(unsigned tokenIndex, const QList<Symbol *> &candidates);
void reportResult(unsigned tokenIndex);
bool checkSymbol(Symbol *symbol) const;
bool checkCandidates(const QList<Symbol *> &candidates) const;
bool checkScope(Symbol *symbol, Symbol *otherSymbol) const;
void checkExpression(unsigned startToken, unsigned endToken);
void ensureNameIsValid(NameAST *ast);
virtual bool visit(MemInitializerAST *ast);
virtual bool visit(PostfixExpressionAST *ast);
virtual void endVisit(PostfixExpressionAST *);
virtual bool visit(MemberAccessAST *ast);
virtual bool visit(QualifiedNameAST *ast);
virtual bool visit(EnumeratorAST *ast);
virtual bool visit(SimpleNameAST *ast);
virtual bool visit(DestructorNameAST *ast);
virtual bool visit(TemplateIdAST *ast);
virtual bool visit(ParameterDeclarationAST *ast);
virtual bool visit(ExpressionOrDeclarationStatementAST *ast);
virtual bool visit(FunctionDeclaratorAST *ast);
virtual bool visit(SimpleDeclarationAST *);
2010-02-23 17:43:40 +01:00
virtual bool visit(ObjCSelectorAST *ast);
virtual bool visit(QtPropertyDeclarationAST *);
virtual void endVisit(QtPropertyDeclarationAST *);
2009-10-27 12:01:45 +01:00
private:
2009-12-01 11:33:13 +01:00
const Identifier *_id;
2009-10-27 12:01:45 +01:00
Symbol *_declSymbol;
Document::Ptr _doc;
Snapshot _snapshot;
LookupContext _context;
2009-10-27 12:01:45 +01:00
QByteArray _source;
Document::Ptr _exprDoc;
Semantic _sem;
NamespaceBindingPtr _globalNamespaceBinding;
QList<PostfixExpressionAST *> _postfixExpressionStack;
QList<QualifiedNameAST *> _qualifiedNameStack;
QList<int> _references;
2009-12-01 17:31:41 +01:00
QList<Usage> _usages;
2009-10-27 12:01:45 +01:00
int _inSimpleDeclaration;
bool _inQProperty;
2009-11-04 12:02:19 +01:00
QSet<unsigned> _processed;
2009-10-27 12:01:45 +01:00
};
} // end of namespace CPlusPlus
#endif // FINDUSAGES_H