diff options
Diffstat (limited to 'src/libs/cplusplus/LookupContext.h')
-rw-r--r-- | src/libs/cplusplus/LookupContext.h | 209 |
1 files changed, 140 insertions, 69 deletions
diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index 8410c9000b..5858d80c95 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -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); + + Symbol *lookupInScope(const QList<const Name *> &fullName); - /// The class this LookupScope is based on. - Class *rootClass() const; + /// 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; }; |