Skip to content
Snippets Groups Projects
Commit cceaffca authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Keep the Control around for as long needed.

parent a56fd7b9
Branches
Tags
No related merge requests found
...@@ -363,7 +363,7 @@ FullySpecifiedType ApplySubstitution::applySubstitution(int index) const ...@@ -363,7 +363,7 @@ FullySpecifiedType ApplySubstitution::applySubstitution(int index) const
} // end of anonymous namespace } // end of anonymous namespace
DeprecatedGenTemplateInstance::DeprecatedGenTemplateInstance(Control *control, const Substitution &substitution) DeprecatedGenTemplateInstance::DeprecatedGenTemplateInstance(QSharedPointer<Control> control, const Substitution &substitution)
: _symbol(0), : _symbol(0),
_control(control), _control(control),
_substitution(substitution) _substitution(substitution)
...@@ -371,11 +371,12 @@ DeprecatedGenTemplateInstance::DeprecatedGenTemplateInstance(Control *control, c ...@@ -371,11 +371,12 @@ DeprecatedGenTemplateInstance::DeprecatedGenTemplateInstance(Control *control, c
FullySpecifiedType DeprecatedGenTemplateInstance::gen(Symbol *symbol) FullySpecifiedType DeprecatedGenTemplateInstance::gen(Symbol *symbol)
{ {
ApplySubstitution o(_control, symbol, _substitution); ApplySubstitution o(_control.data(), symbol, _substitution);
return o.apply(symbol->type()); 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> control)
{ {
if (className) { if (className) {
if (const TemplateNameId *templId = className->asTemplateNameId()) { if (const TemplateNameId *templId = className->asTemplateNameId()) {
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QPair> #include <QtCore/QPair>
#include <QtCore/QSharedPointer>
namespace CPlusPlus { namespace CPlusPlus {
...@@ -45,15 +46,15 @@ public: ...@@ -45,15 +46,15 @@ public:
typedef QList< QPair<const Identifier *, FullySpecifiedType> > Substitution; typedef QList< QPair<const Identifier *, FullySpecifiedType> > Substitution;
public: public:
static FullySpecifiedType instantiate(const Name *className, Symbol *candidate, Control *control); static FullySpecifiedType instantiate(const Name *className, Symbol *candidate, QSharedPointer<Control> control);
private: private:
DeprecatedGenTemplateInstance(Control *control, const Substitution &substitution); DeprecatedGenTemplateInstance(QSharedPointer<Control> control, const Substitution &substitution);
FullySpecifiedType gen(Symbol *symbol); FullySpecifiedType gen(Symbol *symbol);
private: private:
Symbol *_symbol; Symbol *_symbol;
Control *_control; QSharedPointer<Control> _control;
const Substitution _substitution; const Substitution _substitution;
}; };
......
...@@ -90,13 +90,15 @@ bool ClassOrNamespace::CompareName::operator()(const Name *name, const Name *oth ...@@ -90,13 +90,15 @@ bool ClassOrNamespace::CompareName::operator()(const Name *name, const Name *oth
// LookupContext // LookupContext
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
LookupContext::LookupContext() LookupContext::LookupContext()
: _control(new Control())
{ } { }
LookupContext::LookupContext(Document::Ptr thisDocument, LookupContext::LookupContext(Document::Ptr thisDocument,
const Snapshot &snapshot) const Snapshot &snapshot)
: _expressionDocument(Document::create("<LookupContext>")), : _expressionDocument(Document::create("<LookupContext>")),
_thisDocument(thisDocument), _thisDocument(thisDocument),
_snapshot(snapshot) _snapshot(snapshot),
_control(new Control())
{ {
} }
...@@ -105,7 +107,8 @@ LookupContext::LookupContext(Document::Ptr expressionDocument, ...@@ -105,7 +107,8 @@ LookupContext::LookupContext(Document::Ptr expressionDocument,
const Snapshot &snapshot) const Snapshot &snapshot)
: _expressionDocument(expressionDocument), : _expressionDocument(expressionDocument),
_thisDocument(thisDocument), _thisDocument(thisDocument),
_snapshot(snapshot) _snapshot(snapshot),
_control(new Control())
{ {
} }
...@@ -113,7 +116,8 @@ LookupContext::LookupContext(const LookupContext &other) ...@@ -113,7 +116,8 @@ LookupContext::LookupContext(const LookupContext &other)
: _expressionDocument(other._expressionDocument), : _expressionDocument(other._expressionDocument),
_thisDocument(other._thisDocument), _thisDocument(other._thisDocument),
_snapshot(other._snapshot), _snapshot(other._snapshot),
_bindings(other._bindings) _bindings(other._bindings),
_control(other._control)
{ } { }
LookupContext &LookupContext::operator = (const LookupContext &other) LookupContext &LookupContext::operator = (const LookupContext &other)
...@@ -122,6 +126,7 @@ LookupContext &LookupContext::operator = (const LookupContext &other) ...@@ -122,6 +126,7 @@ LookupContext &LookupContext::operator = (const LookupContext &other)
_thisDocument = other._thisDocument; _thisDocument = other._thisDocument;
_snapshot = other._snapshot; _snapshot = other._snapshot;
_bindings = other._bindings; _bindings = other._bindings;
_control = other._control;
return *this; return *this;
} }
...@@ -135,7 +140,7 @@ QList<const Name *> LookupContext::fullyQualifiedName(Symbol *symbol) ...@@ -135,7 +140,7 @@ QList<const Name *> LookupContext::fullyQualifiedName(Symbol *symbol)
QSharedPointer<CreateBindings> LookupContext::bindings() const QSharedPointer<CreateBindings> LookupContext::bindings() const
{ {
if (! _bindings) if (! _bindings)
_bindings = QSharedPointer<CreateBindings>(new CreateBindings(_thisDocument, _snapshot)); _bindings = QSharedPointer<CreateBindings>(new CreateBindings(_thisDocument, _snapshot, control()));
return _bindings; return _bindings;
} }
...@@ -145,8 +150,10 @@ void LookupContext::setBindings(QSharedPointer<CreateBindings> bindings) ...@@ -145,8 +150,10 @@ void LookupContext::setBindings(QSharedPointer<CreateBindings> bindings)
_bindings = bindings; _bindings = bindings;
} }
Control *LookupContext::control() const QSharedPointer<Control> LookupContext::control() const
{ return bindings()->control(); } {
return _control;
}
Document::Ptr LookupContext::expressionDocument() const Document::Ptr LookupContext::expressionDocument() const
{ return _expressionDocument; } { return _expressionDocument; }
...@@ -618,10 +625,9 @@ ClassOrNamespace *ClassOrNamespace::findOrCreateType(const Name *name) ...@@ -618,10 +625,9 @@ ClassOrNamespace *ClassOrNamespace::findOrCreateType(const Name *name)
return 0; return 0;
} }
CreateBindings::CreateBindings(Document::Ptr thisDocument, const Snapshot &snapshot) CreateBindings::CreateBindings(Document::Ptr thisDocument, const Snapshot &snapshot, QSharedPointer<Control> control)
: _snapshot(snapshot) : _snapshot(snapshot), _control(control)
{ {
_control = new Control();
_globalNamespace = allocClassOrNamespace(/*parent = */ 0); _globalNamespace = allocClassOrNamespace(/*parent = */ 0);
_currentClassOrNamespace = _globalNamespace; _currentClassOrNamespace = _globalNamespace;
...@@ -631,7 +637,6 @@ CreateBindings::CreateBindings(Document::Ptr thisDocument, const Snapshot &snaps ...@@ -631,7 +637,6 @@ CreateBindings::CreateBindings(Document::Ptr thisDocument, const Snapshot &snaps
CreateBindings::~CreateBindings() CreateBindings::~CreateBindings()
{ {
qDeleteAll(_entities); qDeleteAll(_entities);
delete _control;
} }
ClassOrNamespace *CreateBindings::switchCurrentClassOrNamespace(ClassOrNamespace *classOrNamespace) ClassOrNamespace *CreateBindings::switchCurrentClassOrNamespace(ClassOrNamespace *classOrNamespace)
...@@ -673,7 +678,7 @@ void CreateBindings::process(Symbol *symbol) ...@@ -673,7 +678,7 @@ void CreateBindings::process(Symbol *symbol)
_currentClassOrNamespace->addTodo(symbol); _currentClassOrNamespace->addTodo(symbol);
} }
Control *CreateBindings::control() const QSharedPointer<Control> CreateBindings::control() const
{ {
return _control; return _control;
} }
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <FullySpecifiedType.h> #include <FullySpecifiedType.h>
#include <Type.h> #include <Type.h>
#include <SymbolVisitor.h> #include <SymbolVisitor.h>
#include <Control.h>
#include <QtCore/QSet> #include <QtCore/QSet>
#include <map> #include <map>
#include <functional> #include <functional>
...@@ -116,7 +117,7 @@ class CPLUSPLUS_EXPORT CreateBindings: protected SymbolVisitor ...@@ -116,7 +117,7 @@ class CPLUSPLUS_EXPORT CreateBindings: protected SymbolVisitor
Q_DISABLE_COPY(CreateBindings) Q_DISABLE_COPY(CreateBindings)
public: public:
CreateBindings(Document::Ptr thisDocument, const Snapshot &snapshot); CreateBindings(Document::Ptr thisDocument, const Snapshot &snapshot, QSharedPointer<Control> control);
virtual ~CreateBindings(); virtual ~CreateBindings();
/// Returns the binding for the global namespace. /// Returns the binding for the global namespace.
...@@ -127,7 +128,7 @@ public: ...@@ -127,7 +128,7 @@ public:
/// Returns the Control that must be used to create temporary symbols. /// Returns the Control that must be used to create temporary symbols.
/// \internal /// \internal
Control *control() const; QSharedPointer<Control> control() const;
/// Searches in \a scope for symbols with the given \a name. /// Searches in \a scope for symbols with the given \a name.
/// Store the result in \a results. /// Store the result in \a results.
...@@ -182,8 +183,8 @@ protected: ...@@ -182,8 +183,8 @@ protected:
virtual bool visit(ObjCMethod *); virtual bool visit(ObjCMethod *);
private: private:
Control *_control;
Snapshot _snapshot; Snapshot _snapshot;
QSharedPointer<Control> _control;
QSet<Namespace *> _processed; QSet<Namespace *> _processed;
QList<ClassOrNamespace *> _entities; QList<ClassOrNamespace *> _entities;
ClassOrNamespace *_globalNamespace; ClassOrNamespace *_globalNamespace;
...@@ -222,7 +223,7 @@ public: ...@@ -222,7 +223,7 @@ public:
/// \internal /// \internal
void setBindings(QSharedPointer<CreateBindings> bindings); void setBindings(QSharedPointer<CreateBindings> bindings);
Control *control() const; // ### deprecate QSharedPointer<Control> control() const; // ### deprecate
static QList<const Name *> fullyQualifiedName(Symbol *symbol); static QList<const Name *> fullyQualifiedName(Symbol *symbol);
...@@ -238,6 +239,8 @@ private: ...@@ -238,6 +239,8 @@ private:
// Bindings // Bindings
mutable QSharedPointer<CreateBindings> _bindings; mutable QSharedPointer<CreateBindings> _bindings;
QSharedPointer<Control> _control;
}; };
} // end of namespace CPlusPlus } // end of namespace CPlusPlus
......
...@@ -604,7 +604,7 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas ...@@ -604,7 +604,7 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas
foreach (Symbol *overload, binding->find(arrowOp)) { foreach (Symbol *overload, binding->find(arrowOp)) {
if (overload->type()->isFunctionType()) { if (overload->type()->isFunctionType()) {
FullySpecifiedType overloadTy = DeprecatedGenTemplateInstance::instantiate(binding->templateId(), overload, control()); FullySpecifiedType overloadTy = instantiate(binding->templateId(), overload);
Function *instantiatedFunction = overloadTy->asFunctionType(); Function *instantiatedFunction = overloadTy->asFunctionType();
Q_ASSERT(instantiatedFunction != 0); Q_ASSERT(instantiatedFunction != 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment