diff --git a/src/libs/cplusplus/DeprecatedGenTemplateInstance.cpp b/src/libs/cplusplus/DeprecatedGenTemplateInstance.cpp index 760d8bce4ec..9c8ebfe3b58 100644 --- a/src/libs/cplusplus/DeprecatedGenTemplateInstance.cpp +++ b/src/libs/cplusplus/DeprecatedGenTemplateInstance.cpp @@ -363,7 +363,7 @@ FullySpecifiedType ApplySubstitution::applySubstitution(int index) const } // end of anonymous namespace -DeprecatedGenTemplateInstance::DeprecatedGenTemplateInstance(Control *control, const Substitution &substitution) +DeprecatedGenTemplateInstance::DeprecatedGenTemplateInstance(QSharedPointer control, const Substitution &substitution) : _symbol(0), _control(control), _substitution(substitution) @@ -371,11 +371,12 @@ DeprecatedGenTemplateInstance::DeprecatedGenTemplateInstance(Control *control, c FullySpecifiedType DeprecatedGenTemplateInstance::gen(Symbol *symbol) { - ApplySubstitution o(_control, symbol, _substitution); + ApplySubstitution o(_control.data(), symbol, _substitution); return o.apply(symbol->type()); } -FullySpecifiedType DeprecatedGenTemplateInstance::instantiate(const Name *className, Symbol *candidate, Control *control) +FullySpecifiedType DeprecatedGenTemplateInstance::instantiate(const Name *className, Symbol *candidate, + QSharedPointer control) { if (className) { if (const TemplateNameId *templId = className->asTemplateNameId()) { diff --git a/src/libs/cplusplus/DeprecatedGenTemplateInstance.h b/src/libs/cplusplus/DeprecatedGenTemplateInstance.h index d90990eb92d..f40c951ba50 100644 --- a/src/libs/cplusplus/DeprecatedGenTemplateInstance.h +++ b/src/libs/cplusplus/DeprecatedGenTemplateInstance.h @@ -36,6 +36,7 @@ #include #include +#include namespace CPlusPlus { @@ -45,15 +46,15 @@ public: typedef QList< QPair > Substitution; public: - static FullySpecifiedType instantiate(const Name *className, Symbol *candidate, Control *control); + static FullySpecifiedType instantiate(const Name *className, Symbol *candidate, QSharedPointer control); private: - DeprecatedGenTemplateInstance(Control *control, const Substitution &substitution); + DeprecatedGenTemplateInstance(QSharedPointer control, const Substitution &substitution); FullySpecifiedType gen(Symbol *symbol); private: Symbol *_symbol; - Control *_control; + QSharedPointer _control; const Substitution _substitution; }; diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index 21cecac3098..4e035dbca3a 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -90,13 +90,15 @@ bool ClassOrNamespace::CompareName::operator()(const Name *name, const Name *oth // LookupContext ///////////////////////////////////////////////////////////////////// LookupContext::LookupContext() + : _control(new Control()) { } LookupContext::LookupContext(Document::Ptr thisDocument, const Snapshot &snapshot) : _expressionDocument(Document::create("")), _thisDocument(thisDocument), - _snapshot(snapshot) + _snapshot(snapshot), + _control(new Control()) { } @@ -105,7 +107,8 @@ LookupContext::LookupContext(Document::Ptr expressionDocument, const Snapshot &snapshot) : _expressionDocument(expressionDocument), _thisDocument(thisDocument), - _snapshot(snapshot) + _snapshot(snapshot), + _control(new Control()) { } @@ -113,7 +116,8 @@ LookupContext::LookupContext(const LookupContext &other) : _expressionDocument(other._expressionDocument), _thisDocument(other._thisDocument), _snapshot(other._snapshot), - _bindings(other._bindings) + _bindings(other._bindings), + _control(other._control) { } LookupContext &LookupContext::operator = (const LookupContext &other) @@ -122,6 +126,7 @@ LookupContext &LookupContext::operator = (const LookupContext &other) _thisDocument = other._thisDocument; _snapshot = other._snapshot; _bindings = other._bindings; + _control = other._control; return *this; } @@ -135,7 +140,7 @@ QList LookupContext::fullyQualifiedName(Symbol *symbol) QSharedPointer LookupContext::bindings() const { if (! _bindings) - _bindings = QSharedPointer(new CreateBindings(_thisDocument, _snapshot)); + _bindings = QSharedPointer(new CreateBindings(_thisDocument, _snapshot, control())); return _bindings; } @@ -145,8 +150,10 @@ void LookupContext::setBindings(QSharedPointer bindings) _bindings = bindings; } -Control *LookupContext::control() const -{ return bindings()->control(); } +QSharedPointer LookupContext::control() const +{ + return _control; +} Document::Ptr LookupContext::expressionDocument() const { return _expressionDocument; } @@ -618,10 +625,9 @@ ClassOrNamespace *ClassOrNamespace::findOrCreateType(const Name *name) return 0; } -CreateBindings::CreateBindings(Document::Ptr thisDocument, const Snapshot &snapshot) - : _snapshot(snapshot) +CreateBindings::CreateBindings(Document::Ptr thisDocument, const Snapshot &snapshot, QSharedPointer control) + : _snapshot(snapshot), _control(control) { - _control = new Control(); _globalNamespace = allocClassOrNamespace(/*parent = */ 0); _currentClassOrNamespace = _globalNamespace; @@ -631,7 +637,6 @@ CreateBindings::CreateBindings(Document::Ptr thisDocument, const Snapshot &snaps CreateBindings::~CreateBindings() { qDeleteAll(_entities); - delete _control; } ClassOrNamespace *CreateBindings::switchCurrentClassOrNamespace(ClassOrNamespace *classOrNamespace) @@ -673,7 +678,7 @@ void CreateBindings::process(Symbol *symbol) _currentClassOrNamespace->addTodo(symbol); } -Control *CreateBindings::control() const +QSharedPointer CreateBindings::control() const { return _control; } diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index 195fea8275f..73893a66701 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -116,7 +117,7 @@ class CPLUSPLUS_EXPORT CreateBindings: protected SymbolVisitor Q_DISABLE_COPY(CreateBindings) public: - CreateBindings(Document::Ptr thisDocument, const Snapshot &snapshot); + CreateBindings(Document::Ptr thisDocument, const Snapshot &snapshot, QSharedPointer control); virtual ~CreateBindings(); /// Returns the binding for the global namespace. @@ -127,7 +128,7 @@ public: /// Returns the Control that must be used to create temporary symbols. /// \internal - Control *control() const; + QSharedPointer control() const; /// Searches in \a scope for symbols with the given \a name. /// Store the result in \a results. @@ -182,8 +183,8 @@ protected: virtual bool visit(ObjCMethod *); private: - Control *_control; Snapshot _snapshot; + QSharedPointer _control; QSet _processed; QList _entities; ClassOrNamespace *_globalNamespace; @@ -222,7 +223,7 @@ public: /// \internal void setBindings(QSharedPointer bindings); - Control *control() const; // ### deprecate + QSharedPointer control() const; // ### deprecate static QList fullyQualifiedName(Symbol *symbol); @@ -238,6 +239,8 @@ private: // Bindings mutable QSharedPointer _bindings; + + QSharedPointer _control; }; } // end of namespace CPlusPlus diff --git a/src/libs/cplusplus/ResolveExpression.cpp b/src/libs/cplusplus/ResolveExpression.cpp index 939c48eb18c..5ac7ca2df78 100644 --- a/src/libs/cplusplus/ResolveExpression.cpp +++ b/src/libs/cplusplus/ResolveExpression.cpp @@ -604,7 +604,7 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList &bas foreach (Symbol *overload, binding->find(arrowOp)) { if (overload->type()->isFunctionType()) { - FullySpecifiedType overloadTy = DeprecatedGenTemplateInstance::instantiate(binding->templateId(), overload, control()); + FullySpecifiedType overloadTy = instantiate(binding->templateId(), overload); Function *instantiatedFunction = overloadTy->asFunctionType(); Q_ASSERT(instantiatedFunction != 0);