forked from qt-creator/qt-creator
C++: Moved completion/highlighting into the model manager.
This way the editor does not need to know all the details of instantiating or maintaining classes for highlighting and/or completion, it can just ask the model manager. The change also enables different highlighting- or completion-engines without changes to the cppeditor. Change-Id: I8000d9d9fe446b292defddb2295493cf77d0f14a Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
1110
src/plugins/cpptools/cppchecksymbols.cpp
Normal file
1110
src/plugins/cpptools/cppchecksymbols.cpp
Normal file
File diff suppressed because it is too large
Load Diff
178
src/plugins/cpptools/cppchecksymbols.h
Normal file
178
src/plugins/cpptools/cppchecksymbols.h
Normal file
@@ -0,0 +1,178 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef CPLUSPLUS_CHECKSYMBOLS_H
|
||||
#define CPLUSPLUS_CHECKSYMBOLS_H
|
||||
|
||||
#include "cppsemanticinfo.h"
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <cplusplus/LookupContext.h>
|
||||
#include <cplusplus/TypeOfExpression.h>
|
||||
|
||||
#include <texteditor/semantichighlighter.h>
|
||||
|
||||
#include <ASTVisitor.h>
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QFuture>
|
||||
#include <QtCore/QtConcurrentRun>
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
class CheckSymbols:
|
||||
protected ASTVisitor,
|
||||
public QRunnable,
|
||||
public QFutureInterface<TextEditor::SemanticHighlighter::Result>
|
||||
{
|
||||
public:
|
||||
virtual ~CheckSymbols();
|
||||
|
||||
typedef TextEditor::SemanticHighlighter::Result Use;
|
||||
typedef CppTools::SemanticInfo::UseKind UseKind;
|
||||
|
||||
virtual void run();
|
||||
|
||||
typedef QFuture<Use> Future;
|
||||
|
||||
Future start()
|
||||
{
|
||||
this->setRunnable(this);
|
||||
this->reportStarted();
|
||||
Future future = this->future();
|
||||
QThreadPool::globalInstance()->start(this, QThread::LowestPriority);
|
||||
return future;
|
||||
}
|
||||
|
||||
static Future go(Document::Ptr doc, const LookupContext &context);
|
||||
|
||||
static QMap<int, QVector<Use> > chunks(const QFuture<Use> &future, int from, int to)
|
||||
{
|
||||
QMap<int, QVector<Use> > chunks;
|
||||
|
||||
for (int i = from; i < to; ++i) {
|
||||
const Use use = future.resultAt(i);
|
||||
if (! use.line)
|
||||
continue; // skip it, it's an invalid use.
|
||||
|
||||
const int blockNumber = use.line - 1;
|
||||
chunks[blockNumber].append(use);
|
||||
}
|
||||
|
||||
return chunks;
|
||||
}
|
||||
|
||||
protected:
|
||||
using ASTVisitor::visit;
|
||||
using ASTVisitor::endVisit;
|
||||
|
||||
CheckSymbols(Document::Ptr doc, const LookupContext &context);
|
||||
|
||||
bool hasVirtualDestructor(Class *klass) const;
|
||||
bool hasVirtualDestructor(ClassOrNamespace *binding) const;
|
||||
|
||||
bool warning(unsigned line, unsigned column, const QString &text, unsigned length = 0);
|
||||
bool warning(AST *ast, const QString &text);
|
||||
|
||||
QByteArray textOf(AST *ast) const;
|
||||
|
||||
bool maybeType(const Name *name) const;
|
||||
bool maybeMember(const Name *name) const;
|
||||
bool maybeStatic(const Name *name) const;
|
||||
bool maybeVirtualMethod(const Name *name) const;
|
||||
|
||||
void checkName(NameAST *ast, Scope *scope = 0);
|
||||
void checkNamespace(NameAST *name);
|
||||
|
||||
void addUse(const Use &use);
|
||||
void addUse(unsigned tokenIndex, UseKind kind);
|
||||
void addUse(NameAST *name, UseKind kind);
|
||||
|
||||
void addType(ClassOrNamespace *b, NameAST *ast);
|
||||
|
||||
void addTypeOrStatic(const QList<LookupItem> &candidates, NameAST *ast);
|
||||
void addStatic(const QList<LookupItem> &candidates, NameAST *ast);
|
||||
void addClassMember(const QList<LookupItem> &candidates, NameAST *ast);
|
||||
void addVirtualMethod(const QList<LookupItem> &candidates, NameAST *ast, unsigned argumentCount);
|
||||
|
||||
bool isTemplateClass(Symbol *s) const;
|
||||
|
||||
Scope *enclosingScope() const;
|
||||
FunctionDefinitionAST *enclosingFunctionDefinition(bool skipTopOfStack = false) const;
|
||||
TemplateDeclarationAST *enclosingTemplateDeclaration() const;
|
||||
|
||||
virtual bool preVisit(AST *);
|
||||
virtual void postVisit(AST *);
|
||||
|
||||
virtual bool visit(NamespaceAST *);
|
||||
virtual bool visit(UsingDirectiveAST *);
|
||||
virtual bool visit(SimpleDeclarationAST *);
|
||||
virtual bool visit(NamedTypeSpecifierAST *);
|
||||
virtual bool visit(ElaboratedTypeSpecifierAST *ast);
|
||||
|
||||
virtual bool visit(EnumeratorAST *);
|
||||
|
||||
virtual bool visit(SimpleNameAST *ast);
|
||||
virtual bool visit(DestructorNameAST *ast);
|
||||
virtual bool visit(QualifiedNameAST *ast);
|
||||
virtual bool visit(TemplateIdAST *ast);
|
||||
|
||||
virtual bool visit(TypenameTypeParameterAST *ast);
|
||||
virtual bool visit(TemplateTypeParameterAST *ast);
|
||||
|
||||
virtual bool visit(FunctionDefinitionAST *ast);
|
||||
virtual bool visit(MemberAccessAST *ast);
|
||||
virtual bool visit(CallAST *ast);
|
||||
|
||||
virtual bool visit(MemInitializerAST *ast);
|
||||
|
||||
NameAST *declaratorId(DeclaratorAST *ast) const;
|
||||
|
||||
void flush();
|
||||
|
||||
private:
|
||||
Document::Ptr _doc;
|
||||
LookupContext _context;
|
||||
TypeOfExpression typeOfExpression;
|
||||
QString _fileName;
|
||||
QList<Document::DiagnosticMessage> _diagnosticMessages;
|
||||
QSet<QByteArray> _potentialTypes;
|
||||
QSet<QByteArray> _potentialMembers;
|
||||
QSet<QByteArray> _potentialVirtualMethods;
|
||||
QSet<QByteArray> _potentialStatics;
|
||||
QList<AST *> _astStack;
|
||||
QVector<Use> _usages;
|
||||
unsigned _lineOfLastUsage;
|
||||
};
|
||||
|
||||
} // namespace CPlusPlus
|
||||
|
||||
#endif // CPLUSPLUS_CHECKSYMBOLS_H
|
||||
72
src/plugins/cpptools/cppcompletionsupport.cpp
Normal file
72
src/plugins/cpptools/cppcompletionsupport.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "cppcompletionassist.h"
|
||||
#include "cppcompletionsupport.h"
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cpptoolseditorsupport.h"
|
||||
|
||||
#include <coreplugin/ifile.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <texteditor/codeassist/iassistinterface.h>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
using namespace CppTools;
|
||||
using namespace CppTools::Internal;
|
||||
|
||||
CppCompletionSupport::CppCompletionSupport(CppEditorSupport *editorSupport)
|
||||
: m_editorSupport(editorSupport)
|
||||
{
|
||||
Q_ASSERT(editorSupport);
|
||||
}
|
||||
|
||||
TextEditor::IAssistInterface *CppCompletionSupport::createAssistInterface(ProjectExplorer::Project *project,
|
||||
QTextDocument *document,
|
||||
int position,
|
||||
TextEditor::AssistReason reason) const
|
||||
{
|
||||
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
|
||||
QStringList includePaths;
|
||||
QStringList frameworkPaths;
|
||||
if (project) {
|
||||
includePaths = modelManager->projectInfo(project).includePaths;
|
||||
frameworkPaths = modelManager->projectInfo(project).frameworkPaths;
|
||||
}
|
||||
return new CppTools::Internal::CppCompletionAssistInterface(
|
||||
document,
|
||||
position,
|
||||
m_editorSupport->textEditor()->file(),
|
||||
reason,
|
||||
modelManager->snapshot(),
|
||||
includePaths,
|
||||
frameworkPaths);
|
||||
}
|
||||
77
src/plugins/cpptools/cppcompletionsupport.h
Normal file
77
src/plugins/cpptools/cppcompletionsupport.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef CPPTOOLS_CPPCOMPLETIONSUPPORT_H
|
||||
#define CPPTOOLS_CPPCOMPLETIONSUPPORT_H
|
||||
|
||||
#include "cpptools_global.h"
|
||||
|
||||
#include <texteditor/codeassist/assistenums.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTextDocument;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
class IFile;
|
||||
}
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Project;
|
||||
}
|
||||
|
||||
namespace TextEditor {
|
||||
class IAssistInterface;
|
||||
}
|
||||
|
||||
namespace CppTools {
|
||||
namespace Internal {
|
||||
class CppEditorSupport;
|
||||
}
|
||||
|
||||
class CPPTOOLS_EXPORT CppCompletionSupport
|
||||
{
|
||||
public:
|
||||
CppCompletionSupport(Internal::CppEditorSupport *editorSupport);
|
||||
|
||||
TextEditor::IAssistInterface *createAssistInterface(ProjectExplorer::Project *project,
|
||||
QTextDocument *document,
|
||||
int position,
|
||||
TextEditor::AssistReason reason) const;
|
||||
|
||||
private:
|
||||
Internal::CppEditorSupport *m_editorSupport;
|
||||
};
|
||||
|
||||
} // namespace CppTools
|
||||
|
||||
#endif // CPPTOOLS_CPPCOMPLETIONSUPPORT_H
|
||||
52
src/plugins/cpptools/cpphighlightingsupport.cpp
Normal file
52
src/plugins/cpptools/cpphighlightingsupport.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "cppchecksymbols.h"
|
||||
#include "cpphighlightingsupport.h"
|
||||
#include "cpptoolseditorsupport.h"
|
||||
|
||||
#include <cplusplus/LookupContext.h>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
using namespace CppTools;
|
||||
using namespace CppTools::Internal;
|
||||
|
||||
CppHighlightingSupport::CppHighlightingSupport()
|
||||
{
|
||||
}
|
||||
|
||||
QFuture<CppHighlightingSupport::Use> CppHighlightingSupport::highlightingFuture(
|
||||
const Document::Ptr &doc, const Snapshot &snapshot) const
|
||||
{
|
||||
LookupContext context(doc, snapshot);
|
||||
return CheckSymbols::go(doc, context);
|
||||
}
|
||||
62
src/plugins/cpptools/cpphighlightingsupport.h
Normal file
62
src/plugins/cpptools/cpphighlightingsupport.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef CPPTOOLS_CPPHIGHLIGHTINGSUPPORT_H
|
||||
#define CPPTOOLS_CPPHIGHLIGHTINGSUPPORT_H
|
||||
|
||||
#include "cpptools_global.h"
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <texteditor/semantichighlighter.h>
|
||||
|
||||
#include <QtCore/QFuture>
|
||||
|
||||
namespace CppTools {
|
||||
namespace Internal {
|
||||
class CppEditorSupport;
|
||||
}
|
||||
|
||||
class CPPTOOLS_EXPORT CppHighlightingSupport
|
||||
{
|
||||
public:
|
||||
typedef TextEditor::SemanticHighlighter::Result Use;
|
||||
|
||||
public:
|
||||
CppHighlightingSupport();
|
||||
|
||||
QFuture<Use> highlightingFuture(const CPlusPlus::Document::Ptr &doc,
|
||||
const CPlusPlus::Snapshot &snapshot) const;
|
||||
};
|
||||
|
||||
} // namespace CppTools
|
||||
|
||||
#endif // CPPTOOLS_CPPHIGHLIGHTINGSUPPORT_H
|
||||
302
src/plugins/cpptools/cpplocalsymbols.cpp
Normal file
302
src/plugins/cpptools/cpplocalsymbols.cpp
Normal file
@@ -0,0 +1,302 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#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;
|
||||
using namespace CppTools;
|
||||
|
||||
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) {
|
||||
_functionScope = def->symbol;
|
||||
accept(ast);
|
||||
}
|
||||
} else if (ObjCMethodDeclarationAST *decl = ast->asObjCMethodDeclaration()) {
|
||||
if (decl->method_prototype->symbol) {
|
||||
_functionScope = decl->method_prototype->symbol;
|
||||
accept(ast);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
using ASTVisitor::visit;
|
||||
using ASTVisitor::endVisit;
|
||||
|
||||
void enterScope(Scope *scope)
|
||||
{
|
||||
_scopeStack.append(scope);
|
||||
|
||||
for (unsigned i = 0; i < scope->memberCount(); ++i) {
|
||||
if (Symbol *member = scope->memberAt(i)) {
|
||||
if (member->isTypedef())
|
||||
continue;
|
||||
else if (! member->isGenerated() && (member->isDeclaration() || member->isArgument())) {
|
||||
if (member->name() && member->name()->isNameId()) {
|
||||
const Identifier *id = member->identifier();
|
||||
unsigned line, column;
|
||||
getTokenStartPosition(member->sourceLocation(), &line, &column);
|
||||
localUses[member].append(SemanticInfo::Use(line, column, id->size(), SemanticInfo::LocalUse));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool checkLocalUse(NameAST *nameAst, unsigned firstToken)
|
||||
{
|
||||
if (SimpleNameAST *simpleName = nameAst->asSimpleName()) {
|
||||
const Identifier *id = identifier(simpleName->identifier_token);
|
||||
for (int i = _scopeStack.size() - 1; i != -1; --i) {
|
||||
if (Symbol *member = _scopeStack.at(i)->find(id)) {
|
||||
if (member->isTypedef() ||
|
||||
!(member->isDeclaration() || member->isArgument()))
|
||||
continue;
|
||||
else if (!member->isGenerated() && (member->sourceLocation() < firstToken || member->enclosingScope()->isFunction())) {
|
||||
unsigned line, column;
|
||||
getTokenStartPosition(simpleName->identifier_token, &line, &column);
|
||||
localUses[member].append(SemanticInfo::Use(line, column, id->size(), SemanticInfo::LocalUse));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
virtual bool visit(QtMemberDeclarationAST *ast)
|
||||
{
|
||||
if (tokenKind(ast->q_token) == T_Q_D)
|
||||
hasD = true;
|
||||
else
|
||||
hasQ = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool visit(FunctionDefinitionAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
enterScope(ast->symbol);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void endVisit(FunctionDefinitionAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
_scopeStack.removeLast();
|
||||
}
|
||||
|
||||
virtual bool visit(CompoundStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
enterScope(ast->symbol);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void endVisit(CompoundStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
_scopeStack.removeLast();
|
||||
}
|
||||
|
||||
virtual bool visit(IfStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
enterScope(ast->symbol);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void endVisit(IfStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
_scopeStack.removeLast();
|
||||
}
|
||||
|
||||
virtual bool visit(WhileStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
enterScope(ast->symbol);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void endVisit(WhileStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
_scopeStack.removeLast();
|
||||
}
|
||||
|
||||
virtual bool visit(ForStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
enterScope(ast->symbol);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void endVisit(ForStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
_scopeStack.removeLast();
|
||||
}
|
||||
|
||||
virtual bool visit(ForeachStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
enterScope(ast->symbol);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void endVisit(ForeachStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
_scopeStack.removeLast();
|
||||
}
|
||||
|
||||
virtual bool visit(SwitchStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
enterScope(ast->symbol);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void endVisit(SwitchStatementAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
_scopeStack.removeLast();
|
||||
}
|
||||
|
||||
virtual bool visit(CatchClauseAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
enterScope(ast->symbol);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void endVisit(CatchClauseAST *ast)
|
||||
{
|
||||
if (ast->symbol)
|
||||
_scopeStack.removeLast();
|
||||
}
|
||||
|
||||
virtual bool visit(ExpressionOrDeclarationStatementAST *ast)
|
||||
{
|
||||
accept(ast->declaration);
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
QList<Scope *> _scopeStack;
|
||||
};
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
||||
|
||||
LocalSymbols::LocalSymbols(CPlusPlus::Document::Ptr doc, CPlusPlus::DeclarationAST *ast)
|
||||
{
|
||||
FindLocalSymbols findLocalSymbols(doc);
|
||||
findLocalSymbols(ast);
|
||||
hasD = findLocalSymbols.hasD;
|
||||
hasQ = findLocalSymbols.hasQ;
|
||||
uses = findLocalSymbols.localUses;
|
||||
}
|
||||
58
src/plugins/cpptools/cpplocalsymbols.h
Normal file
58
src/plugins/cpptools/cpplocalsymbols.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef CPPLOCALSYMBOLS_H
|
||||
#define CPPLOCALSYMBOLS_H
|
||||
|
||||
#include "cpptools_global.h"
|
||||
#include "cppsemanticinfo.h"
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <ASTfwd.h>
|
||||
|
||||
namespace CppTools {
|
||||
|
||||
class CPPTOOLS_EXPORT LocalSymbols
|
||||
{
|
||||
Q_DISABLE_COPY(LocalSymbols)
|
||||
|
||||
public:
|
||||
LocalSymbols(CPlusPlus::Document::Ptr doc, CPlusPlus::DeclarationAST *ast);
|
||||
|
||||
bool hasD;
|
||||
bool hasQ;
|
||||
SemanticInfo::LocalUseMap uses;
|
||||
};
|
||||
|
||||
} // namespace CppTools
|
||||
|
||||
#endif // CPPLOCALSYMBOLS_H
|
||||
@@ -1308,6 +1308,21 @@ void CppModelManager::finishedRefreshingSourceFiles(const QStringList &files)
|
||||
emit sourceFilesRefreshed(files);
|
||||
}
|
||||
|
||||
CppCompletionSupport *CppModelManager::completionSupport(Core::IEditor *editor) const
|
||||
{
|
||||
if (CppEditorSupport *es = editorSupport(qobject_cast<TextEditor::ITextEditor *>(editor)))
|
||||
return es->completionSupport();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
CppHighlightingSupport *CppModelManager::highlightingSupport(Core::IEditor *editor) const
|
||||
{
|
||||
if (CppEditorSupport *es = editorSupport(qobject_cast<TextEditor::ITextEditor *>(editor)))
|
||||
return es->highlightingSupport();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CppModelManager::setExtraDiagnostics(const QString &fileName, int kind,
|
||||
const QList<Document::DiagnosticMessage> &diagnostics)
|
||||
|
||||
@@ -131,9 +131,11 @@ public:
|
||||
virtual QList<CPlusPlus::Document::DiagnosticMessage> extraDiagnostics(
|
||||
const QString &fileName, int key = AllExtraDiagnostics) const;
|
||||
|
||||
|
||||
void finishedRefreshingSourceFiles(const QStringList &files);
|
||||
|
||||
virtual CppCompletionSupport *completionSupport(Core::IEditor *editor) const;
|
||||
virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void projectPathChanged(const QString &projectPath);
|
||||
|
||||
|
||||
40
src/plugins/cpptools/cppsemanticinfo.cpp
Normal file
40
src/plugins/cpptools/cppsemanticinfo.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "cppsemanticinfo.h"
|
||||
|
||||
using namespace CppTools;
|
||||
|
||||
SemanticInfo::SemanticInfo()
|
||||
: revision(0), hasQ(false), hasD(false), forced(false)
|
||||
{
|
||||
}
|
||||
74
src/plugins/cpptools/cppsemanticinfo.h
Normal file
74
src/plugins/cpptools/cppsemanticinfo.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef CPPSEMANTICINFO_H
|
||||
#define CPPSEMANTICINFO_H
|
||||
|
||||
#include "cpptools_global.h"
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <cplusplus/LookupContext.h>
|
||||
#include <texteditor/semantichighlighter.h>
|
||||
#include <QtCore/QHash>
|
||||
|
||||
namespace CppTools {
|
||||
|
||||
class CPPTOOLS_EXPORT SemanticInfo
|
||||
{
|
||||
public:
|
||||
enum UseKind {
|
||||
TypeUse = 0,
|
||||
LocalUse,
|
||||
FieldUse,
|
||||
StaticUse,
|
||||
VirtualMethodUse
|
||||
};
|
||||
typedef TextEditor::SemanticHighlighter::Result Use;
|
||||
|
||||
typedef QHash<CPlusPlus::Symbol *, QList<Use> > LocalUseMap;
|
||||
typedef QHashIterator<CPlusPlus::Symbol *, QList<Use> > LocalUseIterator;
|
||||
|
||||
SemanticInfo();
|
||||
|
||||
unsigned revision;
|
||||
bool hasQ: 1;
|
||||
bool hasD: 1;
|
||||
bool forced: 1;
|
||||
CPlusPlus::Snapshot snapshot;
|
||||
CPlusPlus::Document::Ptr doc;
|
||||
LocalUseMap localUses;
|
||||
QList<Use> objcKeywords;
|
||||
};
|
||||
|
||||
} // namespace CppTools
|
||||
|
||||
#endif // CPPSEMANTICINFO_H
|
||||
@@ -38,7 +38,12 @@ HEADERS += completionsettingspage.h \
|
||||
cpptoolsreuse.h \
|
||||
doxygengenerator.h \
|
||||
commentssettings.h \
|
||||
symbolfinder.h
|
||||
symbolfinder.h \
|
||||
cppcompletionsupport.h \
|
||||
cpphighlightingsupport.h \
|
||||
cppchecksymbols.h \
|
||||
cpplocalsymbols.h \
|
||||
cppsemanticinfo.h
|
||||
|
||||
SOURCES += completionsettingspage.cpp \
|
||||
cppclassesfilter.cpp \
|
||||
@@ -68,7 +73,12 @@ SOURCES += completionsettingspage.cpp \
|
||||
cpptoolsreuse.cpp \
|
||||
doxygengenerator.cpp \
|
||||
commentssettings.cpp \
|
||||
symbolfinder.cpp
|
||||
symbolfinder.cpp \
|
||||
cppcompletionsupport.cpp \
|
||||
cpphighlightingsupport.cpp \
|
||||
cppchecksymbols.cpp \
|
||||
cpplocalsymbols.cpp \
|
||||
cppsemanticinfo.cpp
|
||||
|
||||
FORMS += completionsettingspage.ui \
|
||||
cppfilesettingspage.ui \
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "cppcompletionsupport.h"
|
||||
#include "cpphighlightingsupport.h"
|
||||
#include "cpptoolseditorsupport.h"
|
||||
#include "cppmodelmanager.h"
|
||||
|
||||
@@ -44,13 +46,16 @@
|
||||
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
using namespace CppTools;
|
||||
using namespace CppTools::Internal;
|
||||
using namespace CPlusPlus;
|
||||
|
||||
CppEditorSupport::CppEditorSupport(CppModelManager *modelManager)
|
||||
: QObject(modelManager),
|
||||
_modelManager(modelManager),
|
||||
_updateDocumentInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL)
|
||||
_updateDocumentInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL),
|
||||
m_completionSupport(new CppCompletionSupport(this)),
|
||||
m_highlightingSupport(new CppHighlightingSupport)
|
||||
{
|
||||
_revision = 0;
|
||||
|
||||
@@ -98,6 +103,16 @@ unsigned CppEditorSupport::editorRevision() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
CppTools::CppCompletionSupport *CppEditorSupport::completionSupport() const
|
||||
{
|
||||
return m_completionSupport.data();
|
||||
}
|
||||
|
||||
CppHighlightingSupport *CppEditorSupport::highlightingSupport() const
|
||||
{
|
||||
return m_highlightingSupport.data();
|
||||
}
|
||||
|
||||
int CppEditorSupport::updateDocumentInterval() const
|
||||
{ return _updateDocumentInterval; }
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtCore/QFuture>
|
||||
#include <QtCore/QScopedPointer>
|
||||
#include <QtCore/QSharedPointer>
|
||||
|
||||
#include <QtGui/QTextCursor>
|
||||
@@ -56,6 +57,10 @@ namespace TextEditor {
|
||||
} // namespace TextEditor
|
||||
|
||||
namespace CppTools {
|
||||
|
||||
class CppCompletionSupport;
|
||||
class CppHighlightingSupport;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class CppModelManager;
|
||||
@@ -77,6 +82,9 @@ public:
|
||||
QString contents();
|
||||
unsigned editorRevision() const;
|
||||
|
||||
CppCompletionSupport *completionSupport() const;
|
||||
CppHighlightingSupport *highlightingSupport() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void contentsChanged();
|
||||
|
||||
@@ -94,6 +102,8 @@ private:
|
||||
QFuture<void> _documentParser;
|
||||
QString _cachedContents;
|
||||
unsigned _revision;
|
||||
QScopedPointer<CppCompletionSupport> m_completionSupport;
|
||||
QScopedPointer<CppHighlightingSupport> m_highlightingSupport;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user