Commit 405353ab authored by Roberto Raggi's avatar Roberto Raggi

Removed the CppBindings.

parent b68a16f1
This diff is collapsed.
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** 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 CPPBINDINGS_H
#define CPPBINDINGS_H
#include "CppDocument.h"
#include <QtCore/QList>
#include <QtCore/QSharedPointer>
#include <QtCore/QString>
#include <QtCore/QByteArray>
namespace CPlusPlus {
class Location;
class Binding;
class NamespaceBinding;
class ClassBinding;
typedef QSharedPointer<Binding> BindingPtr;
typedef QSharedPointer<ClassBinding> ClassBindingPtr;
typedef QSharedPointer<NamespaceBinding> NamespaceBindingPtr;
class CPLUSPLUS_EXPORT Location
{
public:
Location();
Location(Symbol *symbol);
Location(const StringLiteral *fileId, unsigned sourceLocation);
inline bool isValid() const
{ return _fileId != 0; }
inline operator bool() const
{ return _fileId != 0; }
inline const StringLiteral *fileId() const
{ return _fileId; }
inline unsigned sourceLocation() const
{ return _sourceLocation; }
private:
const StringLiteral *_fileId;
unsigned _sourceLocation;
};
class CPLUSPLUS_EXPORT Binding
{
Q_DISABLE_COPY(Binding)
public:
Binding() {}
virtual ~Binding() {}
virtual QByteArray qualifiedId() const = 0;
virtual NamespaceBinding *asNamespaceBinding() { return 0; }
virtual ClassBinding *asClassBinding() { return 0; }
virtual ClassBinding *findClassBinding(const Name *name, QSet<Binding *> *processed) = 0;
virtual Binding *findClassOrNamespaceBinding(const Identifier *id, QSet<Binding *> *processed) = 0;
};
class CPLUSPLUS_EXPORT NamespaceBinding: public Binding
{
public:
/// Constructs a binding with the given parent.
NamespaceBinding(NamespaceBinding *parent = 0);
/// Destroys the binding.
virtual ~NamespaceBinding();
/// Returns this binding's name.
const NameId *name() const;
/// Returns this binding's identifier.
const Identifier *identifier() const;
/// Returns the binding for the global namespace (aka ::).
NamespaceBinding *globalNamespaceBinding();
/// Returns the binding for the given namespace symbol.
NamespaceBinding *findNamespaceBinding(const Name *name);
/// Returns the binding associated with the given symbol.
NamespaceBinding *findOrCreateNamespaceBinding(Namespace *symbol);
NamespaceBinding *resolveNamespace(const Location &loc,
const Name *name,
bool lookAtParent = true);
virtual ClassBinding *findClassBinding(const Name *name, QSet<Binding *> *processed);
virtual Binding *findClassOrNamespaceBinding(const Identifier *id, QSet<Binding *> *processed);
/// Helpers.
virtual QByteArray qualifiedId() const;
void dump();
virtual NamespaceBinding *asNamespaceBinding() { return this; }
static NamespaceBinding *find(Namespace *symbol, NamespaceBinding *binding);
static ClassBinding *find(Class *symbol, NamespaceBinding *binding);
private:
NamespaceBinding *findNamespaceBindingForNameId(const NameId *name,
bool lookAtParentNamespace);
NamespaceBinding *findNamespaceBindingForNameId_helper(const NameId *name,
bool lookAtParentNamespace,
QSet<NamespaceBinding *> *processed);
public: // attributes
/// This binding's parent.
NamespaceBinding *parent;
/// Binding for anonymous namespace symbols.
NamespaceBinding *anonymousNamespaceBinding;
/// This binding's connections.
QList<NamespaceBinding *> children;
/// This binding's list of using namespaces.
QList<NamespaceBinding *> usings;
/// This binding's namespace symbols.
QList<Namespace *> symbols;
QList<ClassBinding *> classBindings;
};
class CPLUSPLUS_EXPORT ClassBinding: public Binding
{
public:
ClassBinding(NamespaceBinding *parent);
ClassBinding(ClassBinding *parentClass);
virtual ~ClassBinding();
virtual ClassBinding *asClassBinding() { return this; }
/// Returns this binding's name.
const Name *name() const;
/// Returns this binding's identifier.
const Identifier *identifier() const;
virtual QByteArray qualifiedId() const;
virtual ClassBinding *findClassBinding(const Name *name, QSet<Binding *> *processed);
virtual Binding *findClassOrNamespaceBinding(const Identifier *id, QSet<Binding *> *processed);
void dump();
public: // attributes
Binding *parent;
QList<ClassBinding *> children;
/// This binding's class symbols.
QList<Class *> symbols;
/// Bindings for the base classes.
QList<ClassBinding *> baseClassBindings;
};
CPLUSPLUS_EXPORT NamespaceBindingPtr bind(Document::Ptr doc, Snapshot snapshot);
} // end of namespace CPlusPlus
#endif // CPPBINDINGS_H
......@@ -30,7 +30,6 @@
#include "DeprecatedLookupContext.h"
#include "ResolveExpression.h"
#include "Overview.h"
#include "CppBindings.h"
#include <CoreTypes.h>
#include <Symbols.h>
......@@ -623,142 +622,3 @@ void DeprecatedLookupContext::expand(Scope *scope,
expandObjCClass(objcKlass, visibleScopes, expandedScopes);
}
}
static void visibleClassBindings_helper(ClassBinding *classBinding,
QList<ClassBinding *> *allClassBindings,
QSet<ClassBinding *> *processed)
{
if (! classBinding)
return;
else if (processed->contains(classBinding))
return;
processed->insert(classBinding);
foreach (ClassBinding *baseClassBinding, classBinding->baseClassBindings)
visibleClassBindings_helper(baseClassBinding, allClassBindings, processed);
allClassBindings->append(classBinding);
}
static QList<ClassBinding *> visibleClassBindings(Symbol *symbol, NamespaceBinding *globalNamespace)
{
QList<ClassBinding *> classBindings;
if (! symbol)
return classBindings;
else if (Class *klass = symbol->asClass()) {
QSet<ClassBinding *> processed;
visibleClassBindings_helper(NamespaceBinding::find(klass, globalNamespace),
&classBindings, &processed);
}
return classBindings;
}
Symbol *DeprecatedLookupContext::canonicalSymbol(Symbol *symbol,
NamespaceBinding *globalNamespace)
{
Symbol *canonicalSymbol = DeprecatedLookupContext::canonicalSymbol(symbol);
if (! canonicalSymbol)
return 0;
if (const Identifier *symbolId = canonicalSymbol->identifier()) {
if (symbolId && canonicalSymbol->type()->isFunctionType()) {
Class *enclosingClass = canonicalSymbol->scope()->owner()->asClass();
const QList<ClassBinding *> classBindings = visibleClassBindings(enclosingClass, globalNamespace);
foreach (ClassBinding *baseClassBinding, classBindings) {
if (! baseClassBinding)
continue;
foreach (Class *baseClass, baseClassBinding->symbols) {
if (! baseClass)
continue;
for (Symbol *c = baseClass->members()->lookat(symbolId); c; c = c->next()) {
if (! symbolId->isEqualTo(c->identifier()))
continue;
else if (Function *f = c->type()->asFunctionType()) {
if (f->isVirtual())
return DeprecatedLookupContext::canonicalSymbol(f);
}
}
}
}
}
}
return canonicalSymbol;
}
Symbol *DeprecatedLookupContext::canonicalSymbol(const QList<Symbol *> &candidates,
NamespaceBinding *globalNamespaceBinding)
{
if (candidates.isEmpty())
return 0;
return canonicalSymbol(candidates.first(), globalNamespaceBinding);
}
Symbol *DeprecatedLookupContext::canonicalSymbol(const QList<LookupItem> &results,
NamespaceBinding *globalNamespaceBinding)
{
QList<Symbol *> candidates;
foreach (const LookupItem &result, results)
candidates.append(result.declaration()); // ### not exactly.
return canonicalSymbol(candidates, globalNamespaceBinding);
}
Symbol *DeprecatedLookupContext::canonicalSymbol(Symbol *symbol)
{
Symbol *canonical = symbol;
Class *canonicalClass = 0;
ObjCClass *canonicalObjCClass = 0;
ObjCProtocol *canonicalObjCProto = 0;
for (; symbol; symbol = symbol->next()) {
if (symbol->identifier() == canonical->identifier()) {
canonical = symbol;
if (Class *klass = symbol->asClass())
canonicalClass = klass;
else if (ObjCClass *clazz = symbol->asObjCClass())
canonicalObjCClass = clazz;
else if (ObjCProtocol *proto = symbol->asObjCProtocol())
canonicalObjCProto = proto;
}
}
if (canonicalClass) {
Q_ASSERT(canonical != 0);
if (canonical->isForwardClassDeclaration())
return canonicalClass; // prefer class declarations when available.
} else if (canonicalObjCClass) {
Q_ASSERT(canonical != 0);
if (canonical->isObjCForwardClassDeclaration())
return canonicalObjCClass;
} else if (canonicalObjCProto) {
Q_ASSERT(canonical != 0);
if (canonical->isObjCForwardProtocolDeclaration())
return canonicalObjCProto;
}
if (canonical && canonical->scope()->isClassScope()) {
Class *enclosingClass = canonical->scope()->owner()->asClass();
if (enclosingClass->identifier() == canonical->identifier())
return enclosingClass;
}
return canonical;
}
......@@ -57,15 +57,6 @@ public:
Document::Ptr document(const QString &fileName) const;
Snapshot snapshot() const;
static Symbol *canonicalSymbol(const QList<Symbol *> &candidates,
NamespaceBinding *globalNamespaceBinding);
static Symbol *canonicalSymbol(Symbol *symbol,
NamespaceBinding *globalNamespaceBinding);
static Symbol *canonicalSymbol(const QList<LookupItem> &candidates,
NamespaceBinding *globalNamespaceBinding);
QList<Symbol *> resolve(const Name *name) const
{ return resolve(name, visibleScopes()); }
......@@ -157,7 +148,6 @@ public:
QList<Scope *> *expandedScopes) const;
private:
static Symbol *canonicalSymbol(Symbol *symbol);
QList<Symbol *> resolveQualifiedNameId(const QualifiedNameId *q,
const QList<Scope *> &visibleScopes,
......
......@@ -39,6 +39,7 @@
#include <TranslationUnit.h>
#include <QtCore/QDir>
#include <QtCore/QDebug>
using namespace CPlusPlus;
......@@ -56,11 +57,6 @@ FindUsages::FindUsages(Document::Ptr doc, const Snapshot &snapshot)
typeofExpression.init(_doc, _snapshot, _context.bindings());
}
void FindUsages::setGlobalNamespaceBinding(NamespaceBindingPtr globalNamespaceBinding)
{
_globalNamespaceBinding = globalNamespaceBinding;
}
QList<Usage> FindUsages::usages() const
{ return _usages; }
......@@ -153,61 +149,12 @@ void FindUsages::reportResult(unsigned tokenIndex)
bool FindUsages::checkCandidates(const QList<Symbol *> &candidates) const
{
if (Symbol *canonicalSymbol = DeprecatedLookupContext::canonicalSymbol(candidates, _globalNamespaceBinding.data())) {
#if 0
Symbol *c = candidates.first();
qDebug() << "*** canonical symbol:" << canonicalSymbol->fileName()
<< canonicalSymbol->line() << canonicalSymbol->column()
<< "candidates:" << candidates.size()
<< c->fileName() << c->line() << c->column();
#endif
return checkSymbol(canonicalSymbol);
}
return false;
}
bool FindUsages::checkScope(Symbol *symbol, Symbol *otherSymbol) const
{
if (! (symbol && otherSymbol))
return false;
else if (symbol->scope() == otherSymbol->scope())
return true;
else if (symbol->name() && otherSymbol->name()) {
if (! symbol->name()->isEqualTo(otherSymbol->name()))
return false;
} else if (symbol->name() != otherSymbol->name()) {
return false;
}
return checkScope(symbol->enclosingSymbol(), otherSymbol->enclosingSymbol());
}
bool FindUsages::checkSymbol(Symbol *symbol) const
{
if (! symbol) {
return false;
} else if (symbol == _declSymbol) {
return true;
} else if (symbol->line() == _declSymbol->line() && symbol->column() == _declSymbol->column()) {
if (! qstrcmp(symbol->fileName(), _declSymbol->fileName()))
return true;
} else if (symbol->isForwardClassDeclaration() && (_declSymbol->isClass() ||
_declSymbol->isForwardClassDeclaration())) {
return checkScope(symbol, _declSymbol);
} else if (_declSymbol->isForwardClassDeclaration() && (symbol->isClass() ||
symbol->isForwardClassDeclaration())) {
return checkScope(symbol, _declSymbol);
if (ClassOrNamespace *c = _context.lookupType(_declSymbol)) {
for (int i = candidates.size() - 1; i != -1; --i) {
Symbol *s = candidates.at(i);
if (_context.lookupType(s) == c)
return true;
}
}
return false;
......
......@@ -32,7 +32,6 @@
#include "LookupContext.h"
#include "CppDocument.h"
#include "CppBindings.h"
#include "Semantic.h"
#include "TypeOfExpression.h"
#include <ASTVisitor.h>
......@@ -62,8 +61,6 @@ class CPLUSPLUS_EXPORT FindUsages: protected ASTVisitor
public:
FindUsages(Document::Ptr doc, const Snapshot &snapshot);
void setGlobalNamespaceBinding(NamespaceBindingPtr globalNamespaceBinding);
void operator()(Symbol *symbol);
QList<Usage> usages() const;
......@@ -79,9 +76,7 @@ protected:
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);
......@@ -112,7 +107,6 @@ private:
QByteArray _source;
Document::Ptr _exprDoc;
Semantic _sem;
NamespaceBindingPtr _globalNamespaceBinding;
QList<PostfixExpressionAST *> _postfixExpressionStack;
QList<QualifiedNameAST *> _qualifiedNameStack;
QList<int> _references;
......
......@@ -30,7 +30,6 @@
#include "LookupContext.h"
#include "ResolveExpression.h"
#include "Overview.h"
#include "CppBindings.h"
#include "DeprecatedGenTemplateInstance.h"
#include <CoreTypes.h>
......@@ -186,10 +185,8 @@ QList<Symbol *> LookupContext::lookup(const Name *name, Scope *scope) const
if (! name)
return candidates;
const Identifier *id = name->identifier();
for (; scope; scope = scope->enclosingScope()) {
if (id && scope->isBlockScope()) {
if ((name->isNameId() || name->isTemplateNameId()) && scope->isBlockScope()) {
bindings()->lookupInScope(name, scope, &candidates, /*templateId = */ 0);
if (! candidates.isEmpty())
......
......@@ -37,7 +37,6 @@ HEADERS += \
$$PWD/LookupItem.h \
$$PWD/LookupContext.h \
$$PWD/DeprecatedLookupContext.h \
$$PWD/CppBindings.h \
$$PWD/ASTParent.h \
$$PWD/DeprecatedGenTemplateInstance.h \
$$PWD/FindUsages.h \
......@@ -64,7 +63,6 @@ SOURCES += \
$$PWD/LookupItem.cpp \
$$PWD/LookupContext.cpp \
$$PWD/DeprecatedLookupContext.cpp \
$$PWD/CppBindings.cpp \
$$PWD/ASTParent.cpp \
$$PWD/DeprecatedGenTemplateInstance.cpp \
$$PWD/FindUsages.cpp \
......
......@@ -48,7 +48,6 @@
#include <TranslationUnit.h>
#include <cplusplus/ExpressionUnderCursor.h>
#include <cplusplus/TypeOfExpression.h>
#include <cplusplus/DeprecatedLookupContext.h>
#include <cplusplus/Overview.h>
#include <cplusplus/OverviewModel.h>
#include <cplusplus/SimpleLexer.h>
......@@ -56,7 +55,6 @@
#include <cplusplus/MatchingText.h>
#include <cplusplus/BackwardsScanner.h>
#include <cplusplus/FastPreprocessor.h>
#include <cplusplus/CppBindings.h>
#include <cplusplus/CheckUndefinedSymbols.h>
#include <cpptools/cppmodelmanagerinterface.h>
......@@ -846,13 +844,17 @@ CPlusPlus::Symbol *CPPEditor::findCanonicalSymbol(const QTextCursor &cursor,
TypeOfExpression typeOfExpression;
typeOfExpression.init(doc, snapshot);
const QList<LookupItem> results = typeOfExpression(code, doc->scopeAt(line, col),
TypeOfExpression::Preprocess);
Scope *scope = doc->scopeAt(line, col);
NamespaceBindingPtr glo = bind(doc, snapshot);
Symbol *canonicalSymbol = DeprecatedLookupContext::canonicalSymbol(results, glo.data());
const QList<LookupItem> results = typeOfExpression(code, scope, TypeOfExpression::Preprocess);
for (int i = results.size() - 1; i != -1; --i) { // ### TODO virtual methods and classes.
const LookupItem &r = results.at(i);
return canonicalSymbol;
if (r.declaration())
return r.declaration();
}
return 0;
}
const Macro *CPPEditor::findCanonicalMacro(const QTextCursor &cursor,
......@@ -934,13 +936,13 @@ void CPPEditor::renameUsagesNow()
Symbol *CPPEditor::markSymbols()
{
updateSemanticInfo(m_semanticHighlighter->semanticInfo(currentSource()));
//updateSemanticInfo(m_semanticHighlighter->semanticInfo(currentSource()));
abortRename();
QList<QTextEdit::ExtraSelection> selections;
SemanticInfo info = m_lastSemanticInfo;
const SemanticInfo info = m_lastSemanticInfo;
Symbol *canonicalSymbol = findCanonicalSymbol(textCursor(), info.doc, info.snapshot);
if (canonicalSymbol) {
......@@ -1916,7 +1918,11 @@ void CPPEditor::updateSemanticInfo(const SemanticInfo &semanticInfo)
}
setExtraSelections(UnusedSymbolSelection, unusedSelections);
setExtraSelections(CodeSemanticsSelection, m_renameSelections); // ###
if (! m_renameSelections.isEmpty())
setExtraSelections(CodeSemanticsSelection, m_renameSelections); // ###
else
markSymbols();
m_lastSemanticInfo.forced = false; // clear the forced flag
}
......
......@@ -51,7 +51,6 @@
#include <Scope.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/CppBindings.h>
#include <cplusplus/Overview.h>
#include <QtCore/QTime>
......@@ -120,8 +119,6 @@ public:
doc->check();
FindUsages process(doc, snapshot);
process.setGlobalNamespaceBinding(bind(doc, snapshot));