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.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-05-28 17:17:11 +02:00
|
|
|
#ifndef CPLUSPLUS_FINDUSAGES_H
|
|
|
|
|
#define CPLUSPLUS_FINDUSAGES_H
|
2009-10-27 12:01:45 +01:00
|
|
|
|
2010-05-12 12:53:16 +02:00
|
|
|
#include "LookupContext.h"
|
2009-10-27 12:01:45 +01:00
|
|
|
#include "CppDocument.h"
|
|
|
|
|
#include "Semantic.h"
|
2010-05-17 13:06:49 +02:00
|
|
|
#include "TypeOfExpression.h"
|
2009-10-27 12:01:45 +01:00
|
|
|
#include <ASTVisitor.h>
|
2009-12-04 13:04:20 +01:00
|
|
|
#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) {}
|
|
|
|
|
|
2009-12-04 13:04:20 +01:00
|
|
|
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:
|
2009-12-04 13:04:20 +01:00
|
|
|
FindUsages(Document::Ptr doc, const Snapshot &snapshot);
|
2010-05-31 12:09:28 +02:00
|
|
|
FindUsages(const LookupContext &context);
|
2009-10-27 12:01:45 +01:00
|
|
|
|
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;
|
2010-05-12 12:53:16 +02:00
|
|
|
Scope *scopeAt(unsigned tokenIndex) const;
|
2009-10-27 12:01:45 +01:00
|
|
|
|
2010-07-16 11:03:39 +02:00
|
|
|
void reportResult(unsigned tokenIndex, const QList<LookupItem> &candidates);
|
2009-10-27 12:01:45 +01:00
|
|
|
void reportResult(unsigned tokenIndex);
|
|
|
|
|
|
2010-07-16 11:03:39 +02:00
|
|
|
bool checkCandidates(const QList<LookupItem> &candidates) const;
|
2009-10-27 12:01:45 +01:00
|
|
|
void checkExpression(unsigned startToken, unsigned endToken);
|
|
|
|
|
|
|
|
|
|
void ensureNameIsValid(NameAST *ast);
|
|
|
|
|
|
2010-08-05 12:49:29 +02:00
|
|
|
virtual bool visit(NamespaceAST *ast);
|
2009-10-27 12:01:45 +01:00
|
|
|
virtual bool visit(MemInitializerAST *ast);
|
|
|
|
|
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);
|
2010-03-12 11:32:22 +01:00
|
|
|
virtual bool visit(QtPropertyDeclarationAST *);
|
|
|
|
|
virtual void endVisit(QtPropertyDeclarationAST *);
|
2009-10-27 12:01:45 +01:00
|
|
|
|
2010-06-01 11:57:25 +02:00
|
|
|
virtual bool visit(TemplateDeclarationAST *ast);
|
|
|
|
|
virtual void endVisit(TemplateDeclarationAST *ast);
|
|
|
|
|
|
|
|
|
|
virtual bool visit(TypenameTypeParameterAST *ast);
|
|
|
|
|
virtual bool visit(TemplateTypeParameterAST *ast);
|
|
|
|
|
|
|
|
|
|
unsigned startOfTemplateDeclaration(TemplateDeclarationAST *ast) const;
|
2010-08-05 12:49:29 +02:00
|
|
|
static bool compareFullyQualifiedName(const QList<const Name *> &path, const QList<const Name *> &other);
|
2010-08-05 13:38:27 +02:00
|
|
|
static bool compareName(const Name *name, const Name *other);
|
2010-06-01 11:57:25 +02:00
|
|
|
|
2009-10-27 12:01:45 +01:00
|
|
|
private:
|
2009-12-01 11:33:13 +01:00
|
|
|
const Identifier *_id;
|
2010-08-05 12:49:29 +02:00
|
|
|
QList<const Name *> _declSymbolFullyQualifiedName;
|
2009-10-27 12:01:45 +01:00
|
|
|
Document::Ptr _doc;
|
|
|
|
|
Snapshot _snapshot;
|
2010-05-12 12:53:16 +02:00
|
|
|
LookupContext _context;
|
2009-10-27 12:01:45 +01:00
|
|
|
QByteArray _source;
|
|
|
|
|
Semantic _sem;
|
|
|
|
|
QList<QualifiedNameAST *> _qualifiedNameStack;
|
2010-06-01 11:57:25 +02:00
|
|
|
QList<TemplateDeclarationAST *> _templateDeclarationStack;
|
2009-10-27 12:01:45 +01:00
|
|
|
QList<int> _references;
|
2009-12-01 17:31:41 +01:00
|
|
|
QList<Usage> _usages;
|
2009-10-27 12:01:45 +01:00
|
|
|
int _inSimpleDeclaration;
|
2010-03-12 11:32:22 +01:00
|
|
|
bool _inQProperty;
|
2009-11-04 12:02:19 +01:00
|
|
|
QSet<unsigned> _processed;
|
2010-05-17 13:06:49 +02:00
|
|
|
TypeOfExpression typeofExpression;
|
2009-10-27 12:01:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end of namespace CPlusPlus
|
|
|
|
|
|
2010-05-28 17:17:11 +02:00
|
|
|
#endif // CPLUSPLUS_FINDUSAGES_H
|