forked from qt-creator/qt-creator
C++: Revert lookup to 3.4.2
...which was least buggy.
The bugs fixed by the changes we revert here (highlighting/completion
for code involving templates) were minor compared to ones we currently
have. Those bugs will be addressed by the clang code model anyway.
Relevant commits were collected via:
$ cd ${QTC}/src/libs/cplusplus
$ git log \
--no-merges \
--format=oneline \
v3.4.2..HEAD \
-- LookupContext.* ResolveExpression.* TypeResolver.* TypeOfExpression.* \
../../plugins/cpptools/cppcompletion_test.cpp
From this list the following were skipped due to irrelevance:
88c5b47e53 # CppTools: Minor cleanup in completion tests
e5255a1f5c # CppTools: Add a test for ObjC not replacing dot with arrow
5b12c8d63a # CppTools: Support ObjC in member access operator tests
9fef4fb9ca # CPlusPlus: Fix warnings about overriding visit(...) methods
There were only minor conflicts while reverting those.
This changes touches so many files because there were quite some
cleanups and renames after the 3.4.2 release.
Task-number: QTCREATORBUG-14889
Task-number: QTCREATORBUG-15211
Task-number: QTCREATORBUG-15213
Task-number: QTCREATORBUG-15257
Task-number: QTCREATORBUG-15264
Task-number: QTCREATORBUG-15291
Task-number: QTCREATORBUG-15329
Change-Id: I01f759f8f35ecb4228928a4f22086e279c1a5435
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
This commit is contained in:
@@ -41,7 +41,6 @@
|
||||
#include <cplusplus/Control.h>
|
||||
#include <cplusplus/Name.h>
|
||||
|
||||
#include <QEnableSharedFromThis>
|
||||
#include <QSet>
|
||||
#include <QMap>
|
||||
|
||||
@@ -59,78 +58,158 @@ struct FullyQualifiedName
|
||||
: fqn(fqn)
|
||||
{}
|
||||
};
|
||||
class LookupScopePrivate;
|
||||
class Instantiator;
|
||||
} // namespace Internal;
|
||||
|
||||
class CreateBindings;
|
||||
|
||||
class CPLUSPLUS_EXPORT LookupScope
|
||||
class CPLUSPLUS_EXPORT ClassOrNamespace
|
||||
{
|
||||
Q_DISABLE_COPY(LookupScope)
|
||||
Q_DISABLE_COPY(ClassOrNamespace)
|
||||
|
||||
LookupScope(CreateBindings *factory, LookupScope *parent);
|
||||
ClassOrNamespace(CreateBindings *factory, ClassOrNamespace *parent);
|
||||
|
||||
public:
|
||||
~LookupScope();
|
||||
~ClassOrNamespace();
|
||||
|
||||
LookupScope *instantiationOrigin() const;
|
||||
const TemplateNameId *templateId() const;
|
||||
ClassOrNamespace *instantiationOrigin() const;
|
||||
|
||||
LookupScope *parent() const;
|
||||
QList<LookupScope *> usings() const;
|
||||
ClassOrNamespace *parent() const;
|
||||
QList<ClassOrNamespace *> usings() const;
|
||||
QList<Enum *> unscopedEnums() const;
|
||||
QList<Symbol *> symbols() const;
|
||||
|
||||
ClassOrNamespace *globalNamespace() const;
|
||||
|
||||
QList<LookupItem> lookup(const Name *name);
|
||||
QList<LookupItem> find(const Name *name);
|
||||
|
||||
LookupScope *lookupType(const Name *name);
|
||||
LookupScope *lookupType(const Name *name, Block *block);
|
||||
LookupScope *findType(const Name *name);
|
||||
LookupScope *findBlock(Block *block);
|
||||
ClassOrNamespace *lookupType(const Name *name);
|
||||
ClassOrNamespace *lookupType(const Name *name, Block *block);
|
||||
ClassOrNamespace *findType(const Name *name);
|
||||
ClassOrNamespace *findBlock(Block *block);
|
||||
|
||||
/// The class this LookupScope is based on.
|
||||
Class *rootClass() const;
|
||||
Symbol *lookupInScope(const QList<const Name *> &fullName);
|
||||
|
||||
/// The class this ClassOrNamespace is based on.
|
||||
Class *rootClass() const { return _rootClass; }
|
||||
|
||||
private:
|
||||
Internal::LookupScopePrivate *d;
|
||||
typedef std::map<const Name *, ClassOrNamespace *, Name::Compare> Table;
|
||||
typedef std::map<const TemplateNameId *, ClassOrNamespace *, TemplateNameId::Compare> TemplateNameIdTable;
|
||||
typedef QHash<const AnonymousNameId *, ClassOrNamespace *> Anonymouses;
|
||||
|
||||
/// \internal
|
||||
void flush();
|
||||
|
||||
/// \internal
|
||||
ClassOrNamespace *findOrCreateType(const Name *name, ClassOrNamespace *origin = 0,
|
||||
Class *clazz = 0);
|
||||
|
||||
ClassOrNamespace *findOrCreateNestedAnonymousType(const AnonymousNameId *anonymousNameId);
|
||||
|
||||
void addTodo(Symbol *symbol);
|
||||
void addSymbol(Symbol *symbol);
|
||||
void addUnscopedEnum(Enum *e);
|
||||
void addUsing(ClassOrNamespace *u);
|
||||
void addNestedType(const Name *alias, ClassOrNamespace *e);
|
||||
|
||||
QList<LookupItem> lookup_helper(const Name *name, bool searchInEnclosingScope);
|
||||
|
||||
void lookup_helper(const Name *name, ClassOrNamespace *binding,
|
||||
QList<LookupItem> *result,
|
||||
QSet<ClassOrNamespace *> *processed,
|
||||
const TemplateNameId *templateId);
|
||||
|
||||
ClassOrNamespace *lookupType_helper(const Name *name, QSet<ClassOrNamespace *> *processed,
|
||||
bool searchInEnclosingScope, ClassOrNamespace *origin);
|
||||
|
||||
ClassOrNamespace *findBlock_helper(Block *block, QSet<ClassOrNamespace *> *processed,
|
||||
bool searchInEnclosingScope);
|
||||
|
||||
ClassOrNamespace *nestedType(const Name *name, ClassOrNamespace *origin);
|
||||
|
||||
void instantiateNestedClasses(ClassOrNamespace *enclosingTemplateClass,
|
||||
Clone &cloner,
|
||||
Subst &subst,
|
||||
ClassOrNamespace *enclosingTemplateClassInstantiation);
|
||||
ClassOrNamespace *findSpecialization(const TemplateNameId *templId,
|
||||
const TemplateNameIdTable &specializations);
|
||||
|
||||
CreateBindings *_factory;
|
||||
ClassOrNamespace *_parent;
|
||||
QList<Symbol *> _symbols;
|
||||
QList<ClassOrNamespace *> _usings;
|
||||
Table _classOrNamespaces;
|
||||
QHash<Block *, ClassOrNamespace *> _blocks;
|
||||
QList<Enum *> _enums;
|
||||
QList<Symbol *> _todo;
|
||||
QSharedPointer<Control> _control;
|
||||
TemplateNameIdTable _specializations;
|
||||
QMap<const TemplateNameId *, ClassOrNamespace *> _instantiations;
|
||||
Anonymouses _anonymouses;
|
||||
QSet<const AnonymousNameId *> _declaredOrTypedefedAnonymouses;
|
||||
|
||||
QHash<Internal::FullyQualifiedName, Symbol *> *_scopeLookupCache;
|
||||
|
||||
// it's an instantiation.
|
||||
const TemplateNameId *_templateId;
|
||||
ClassOrNamespace *_instantiationOrigin;
|
||||
|
||||
AlreadyConsideredClassContainer<Class> _alreadyConsideredClasses;
|
||||
AlreadyConsideredClassContainer<TemplateNameId> _alreadyConsideredTemplates;
|
||||
|
||||
Class *_rootClass;
|
||||
|
||||
class NestedClassInstantiator
|
||||
{
|
||||
public:
|
||||
NestedClassInstantiator(CreateBindings *factory, Clone &cloner, Subst &subst)
|
||||
: _factory(factory)
|
||||
, _cloner(cloner)
|
||||
, _subst(subst)
|
||||
{}
|
||||
void instantiate(ClassOrNamespace *enclosingTemplateClass,
|
||||
ClassOrNamespace *enclosingTemplateClassInstantiation);
|
||||
private:
|
||||
bool isInstantiateNestedClassNeeded(const QList<Symbol *> &symbols) const;
|
||||
bool containsTemplateType(Declaration *declaration) const;
|
||||
bool containsTemplateType(Function *function) const;
|
||||
NamedType *findNamedType(Type *memberType) const;
|
||||
|
||||
QSet<ClassOrNamespace *> _alreadyConsideredNestedClassInstantiations;
|
||||
CreateBindings *_factory;
|
||||
Clone &_cloner;
|
||||
Subst &_subst;
|
||||
};
|
||||
|
||||
public:
|
||||
const Name *_name; // For debug
|
||||
|
||||
friend class Internal::LookupScopePrivate;
|
||||
friend class Internal::Instantiator;
|
||||
friend class CreateBindings;
|
||||
};
|
||||
|
||||
class CPLUSPLUS_EXPORT CreateBindings
|
||||
: protected SymbolVisitor
|
||||
, public QEnableSharedFromThis<CreateBindings>
|
||||
class CPLUSPLUS_EXPORT CreateBindings: protected SymbolVisitor
|
||||
{
|
||||
Q_DISABLE_COPY(CreateBindings)
|
||||
|
||||
public:
|
||||
typedef QSharedPointer<CreateBindings> Ptr;
|
||||
|
||||
CreateBindings(Document::Ptr thisDocument, const Snapshot &snapshot);
|
||||
virtual ~CreateBindings();
|
||||
|
||||
/// Returns the binding for the global namespace.
|
||||
LookupScope *globalNamespace() const;
|
||||
ClassOrNamespace *globalNamespace() const;
|
||||
|
||||
/// Finds the binding associated to the given symbol.
|
||||
LookupScope *lookupType(Symbol *symbol, LookupScope *enclosingBinding = 0);
|
||||
LookupScope *lookupType(const QList<const Name *> &path, LookupScope *enclosingBinding = 0);
|
||||
ClassOrNamespace *lookupType(Symbol *symbol, ClassOrNamespace *enclosingBinding = 0);
|
||||
ClassOrNamespace *lookupType(const QList<const Name *> &path,
|
||||
ClassOrNamespace *enclosingBinding = 0);
|
||||
|
||||
/// Returns the Control that must be used to create temporary symbols.
|
||||
/// \internal
|
||||
QSharedPointer<Control> control() const
|
||||
{ return _control; }
|
||||
|
||||
Snapshot &snapshot()
|
||||
{ return _snapshot; }
|
||||
|
||||
/// Adds an expression document in order to keep their symbols and names alive
|
||||
void addExpressionDocument(Document::Ptr document)
|
||||
{ _expressionDocuments.append(document); }
|
||||
|
||||
bool expandTemplates() const
|
||||
{ return _expandTemplates; }
|
||||
void setExpandTemplates(bool expandTemplates)
|
||||
@@ -140,36 +219,28 @@ public:
|
||||
/// Store the result in \a results.
|
||||
/// \internal
|
||||
void lookupInScope(const Name *name, Scope *scope, QList<LookupItem> *result,
|
||||
LookupScope *binding = 0);
|
||||
const TemplateNameId *templateId, ClassOrNamespace *binding);
|
||||
|
||||
/// Create bindings for the symbols reachable from \a rootSymbol.
|
||||
/// \internal
|
||||
void process(Symbol *rootSymbol, LookupScope *lookupScope);
|
||||
void process(Symbol *rootSymbol, ClassOrNamespace *classOrNamespace);
|
||||
|
||||
/// Create an empty LookupScope binding with the given \a parent.
|
||||
/// Create an empty ClassOrNamespace binding with the given \a parent.
|
||||
/// \internal
|
||||
LookupScope *allocLookupScope(LookupScope *parent, const Name *name);
|
||||
|
||||
FullySpecifiedType resolveTemplateArgument(Clone &cloner, Subst &subst,
|
||||
LookupScope *origin,
|
||||
const Template *specialization,
|
||||
const TemplateNameId *instantiation,
|
||||
unsigned index);
|
||||
void initializeSubst(Clone &cloner, Subst &subst, LookupScope *origin,
|
||||
const Template *specialization, const TemplateNameId *instantiation);
|
||||
ClassOrNamespace *allocClassOrNamespace(ClassOrNamespace *parent);
|
||||
|
||||
protected:
|
||||
using SymbolVisitor::visit;
|
||||
|
||||
/// Change the current LookupScope binding.
|
||||
LookupScope *switchCurrentLookupScope(LookupScope *lookupScope);
|
||||
/// Change the current ClassOrNamespace binding.
|
||||
ClassOrNamespace *switchCurrentClassOrNamespace(ClassOrNamespace *classOrNamespace);
|
||||
|
||||
/// Enters the LookupScope binding associated with the given \a symbol.
|
||||
LookupScope *enterLookupScopeBinding(Symbol *symbol);
|
||||
/// Enters the ClassOrNamespace binding associated with the given \a symbol.
|
||||
ClassOrNamespace *enterClassOrNamespaceBinding(Symbol *symbol);
|
||||
|
||||
/// Enters a LookupScope binding for the given \a symbol in the global
|
||||
/// Enters a ClassOrNamespace binding for the given \a symbol in the global
|
||||
/// namespace binding.
|
||||
LookupScope *enterGlobalLookupScope(Symbol *symbol);
|
||||
ClassOrNamespace *enterGlobalClassOrNamespace(Symbol *symbol);
|
||||
|
||||
/// Creates bindings for the given \a document.
|
||||
void process(Document::Ptr document);
|
||||
@@ -178,7 +249,6 @@ protected:
|
||||
void process(Symbol *root);
|
||||
|
||||
virtual bool visit(Template *templ);
|
||||
virtual bool visit(ExplicitInstantiation *inst);
|
||||
virtual bool visit(Namespace *ns);
|
||||
virtual bool visit(Class *klass);
|
||||
virtual bool visit(ForwardClassDeclaration *klass);
|
||||
@@ -201,15 +271,16 @@ protected:
|
||||
virtual bool visit(ObjCMethod *);
|
||||
|
||||
private:
|
||||
Symbol *instantiateTemplateFunction(const TemplateNameId *instantiation,
|
||||
Template *specialization) const;
|
||||
|
||||
Snapshot _snapshot;
|
||||
QSharedPointer<Control> _control;
|
||||
QList<Document::Ptr> _expressionDocuments;
|
||||
QSet<Namespace *> _processed;
|
||||
QList<LookupScope *> _entities;
|
||||
LookupScope *_globalNamespace;
|
||||
LookupScope *_currentLookupScope;
|
||||
QList<ClassOrNamespace *> _entities;
|
||||
ClassOrNamespace *_globalNamespace;
|
||||
ClassOrNamespace *_currentClassOrNamespace;
|
||||
bool _expandTemplates;
|
||||
int _depth;
|
||||
};
|
||||
|
||||
class CPLUSPLUS_EXPORT LookupContext
|
||||
@@ -223,7 +294,7 @@ public:
|
||||
LookupContext(Document::Ptr expressionDocument,
|
||||
Document::Ptr thisDocument,
|
||||
const Snapshot &snapshot,
|
||||
CreateBindings::Ptr bindings = CreateBindings::Ptr());
|
||||
QSharedPointer<CreateBindings> bindings = QSharedPointer<CreateBindings>());
|
||||
|
||||
LookupContext(const LookupContext &other);
|
||||
LookupContext &operator = (const LookupContext &other);
|
||||
@@ -233,25 +304,25 @@ public:
|
||||
Document::Ptr document(const QString &fileName) const;
|
||||
Snapshot snapshot() const;
|
||||
|
||||
LookupScope *globalNamespace() const;
|
||||
ClassOrNamespace *globalNamespace() const;
|
||||
|
||||
QList<LookupItem> lookup(const Name *name, Scope *scope) const;
|
||||
LookupScope *lookupType(const Name *name, Scope *scope,
|
||||
LookupScope *enclosingBinding = 0,
|
||||
ClassOrNamespace *lookupType(const Name *name, Scope *scope,
|
||||
ClassOrNamespace *enclosingBinding = 0,
|
||||
QSet<const Declaration *> typedefsBeingResolved
|
||||
= QSet<const Declaration *>()) const;
|
||||
LookupScope *lookupType(Symbol *symbol,
|
||||
LookupScope *enclosingBinding = 0) const;
|
||||
LookupScope *lookupParent(Symbol *symbol) const;
|
||||
ClassOrNamespace *lookupType(Symbol *symbol,
|
||||
ClassOrNamespace *enclosingBinding = 0) const;
|
||||
ClassOrNamespace *lookupParent(Symbol *symbol) const;
|
||||
|
||||
/// \internal
|
||||
CreateBindings::Ptr bindings() const
|
||||
QSharedPointer<CreateBindings> bindings() const
|
||||
{ return _bindings; }
|
||||
|
||||
static QList<const Name *> fullyQualifiedName(Symbol *symbol);
|
||||
static QList<const Name *> path(Symbol *symbol);
|
||||
|
||||
static const Name *minimalName(Symbol *symbol, LookupScope *target, Control *control);
|
||||
static const Name *minimalName(Symbol *symbol, ClassOrNamespace *target, Control *control);
|
||||
|
||||
void setExpandTemplates(bool expandTemplates)
|
||||
{
|
||||
@@ -261,7 +332,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
QList<LookupItem> lookupByUsing(const Name *name, LookupScope *bindingScope) const;
|
||||
QList<LookupItem> lookupByUsing(const Name *name, ClassOrNamespace *bindingScope) const;
|
||||
|
||||
// The current expression.
|
||||
Document::Ptr _expressionDocument;
|
||||
@@ -273,7 +344,7 @@ private:
|
||||
Snapshot _snapshot;
|
||||
|
||||
// Bindings
|
||||
CreateBindings::Ptr _bindings;
|
||||
QSharedPointer<CreateBindings> _bindings;
|
||||
|
||||
bool m_expandTemplates;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user