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

Get rid of BindPtr.

There is no reason to store the Bind object in a QSharedPointer because the `binder' has the same
lifetime of its document.
parent 976d74ca
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "qmljsbind.h" #include "qmljsbind.h"
#include "qmljslink.h" #include "qmljslink.h"
#include "qmljscheck.h" #include "qmljscheck.h"
#include "qmljsdocument.h"
#include "qmljsmetatypesystem.h" #include "qmljsmetatypesystem.h"
#include <QtCore/QDir> #include <QtCore/QDir>
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include <qmljs/parser/qmljsastvisitor_p.h> #include <qmljs/parser/qmljsastvisitor_p.h>
#include <qmljs/qmljsinterpreter.h> #include <qmljs/qmljsinterpreter.h>
#include <qmljs/qmljsdocument.h>
#include <QtCore/QHash> #include <QtCore/QHash>
#include <QtCore/QStringList> #include <QtCore/QStringList>
...@@ -42,9 +41,12 @@ namespace QmlJS { ...@@ -42,9 +41,12 @@ namespace QmlJS {
class LinkImports; class LinkImports;
class Link; class Link;
class Document;
class QMLJS_EXPORT Bind: protected AST::Visitor class QMLJS_EXPORT Bind: protected AST::Visitor
{ {
Q_DISABLE_COPY(Bind)
public: public:
Bind(Document *doc); Bind(Document *doc);
virtual ~Bind(); virtual ~Bind();
...@@ -96,7 +98,6 @@ private: ...@@ -96,7 +98,6 @@ private:
friend class LinkImports; friend class LinkImports;
friend class Link; friend class Link;
}; };
typedef QSharedPointer<Bind> BindPtr;
} // end of namespace Qml } // end of namespace Qml
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include <qmljs/parser/qmljsastfwd_p.h> #include <qmljs/parser/qmljsastfwd_p.h>
#include <QtCore/QDir> #include <QtCore/QDir>
using namespace QmlJS;
using namespace QmlJS; using namespace QmlJS;
using namespace QmlJS::AST; using namespace QmlJS::AST;
...@@ -44,6 +43,7 @@ Document::Document(const QString &fileName) ...@@ -44,6 +43,7 @@ Document::Document(const QString &fileName)
: _engine(0) : _engine(0)
, _pool(0) , _pool(0)
, _ast(0) , _ast(0)
, _bind(0)
, _documentRevision(0) , _documentRevision(0)
, _parsedCorrectly(false) , _parsedCorrectly(false)
, _fileName(fileName) , _fileName(fileName)
...@@ -65,6 +65,9 @@ Document::Document(const QString &fileName) ...@@ -65,6 +65,9 @@ Document::Document(const QString &fileName)
Document::~Document() Document::~Document()
{ {
if (_bind)
delete _bind;
if (_engine) if (_engine)
delete _engine; delete _engine;
...@@ -131,6 +134,7 @@ bool Document::parseQml() ...@@ -131,6 +134,7 @@ bool Document::parseQml()
Q_ASSERT(! _engine); Q_ASSERT(! _engine);
Q_ASSERT(! _pool); Q_ASSERT(! _pool);
Q_ASSERT(! _ast); Q_ASSERT(! _ast);
Q_ASSERT(! _bind);
_engine = new Engine(); _engine = new Engine();
_pool = new NodePool(_fileName, _engine); _pool = new NodePool(_fileName, _engine);
...@@ -144,7 +148,7 @@ bool Document::parseQml() ...@@ -144,7 +148,7 @@ bool Document::parseQml()
_ast = parser.ast(); _ast = parser.ast();
_diagnosticMessages = parser.diagnosticMessages(); _diagnosticMessages = parser.diagnosticMessages();
_bind = BindPtr(new Bind(this)); _bind = new Bind(this);
return _parsedCorrectly; return _parsedCorrectly;
} }
...@@ -154,6 +158,7 @@ bool Document::parseJavaScript() ...@@ -154,6 +158,7 @@ bool Document::parseJavaScript()
Q_ASSERT(! _engine); Q_ASSERT(! _engine);
Q_ASSERT(! _pool); Q_ASSERT(! _pool);
Q_ASSERT(! _ast); Q_ASSERT(! _ast);
Q_ASSERT(! _bind);
_engine = new Engine(); _engine = new Engine();
_pool = new NodePool(_fileName, _engine); _pool = new NodePool(_fileName, _engine);
...@@ -167,7 +172,7 @@ bool Document::parseJavaScript() ...@@ -167,7 +172,7 @@ bool Document::parseJavaScript()
_ast = cast<Program*>(parser.rootNode()); _ast = cast<Program*>(parser.rootNode());
_diagnosticMessages = parser.diagnosticMessages(); _diagnosticMessages = parser.diagnosticMessages();
_bind = BindPtr(new Bind(this)); _bind = new Bind(this);
return _parsedCorrectly; return _parsedCorrectly;
} }
...@@ -195,7 +200,7 @@ bool Document::parseExpression() ...@@ -195,7 +200,7 @@ bool Document::parseExpression()
return _parsedCorrectly; return _parsedCorrectly;
} }
BindPtr Document::bind() const Bind *Document::bind() const
{ {
return _bind; return _bind;
} }
...@@ -214,11 +219,11 @@ void Snapshot::insert(const Document::Ptr &document) ...@@ -214,11 +219,11 @@ void Snapshot::insert(const Document::Ptr &document)
_documents.insert(document->fileName(), document); _documents.insert(document->fileName(), document);
} }
Document::PtrList Snapshot::importedDocuments(const Document::Ptr &doc, const QString &importPath) const QList<Document::Ptr> Snapshot::importedDocuments(const Document::Ptr &doc, const QString &importPath) const
{ {
// ### TODO: maybe we should add all imported documents in the parse Document::parse() method, regardless of whether they're in the path or not. // ### TODO: maybe we should add all imported documents in the parse Document::parse() method, regardless of whether they're in the path or not.
Document::PtrList result; QList<Document::Ptr> result;
QString docPath = doc->path(); QString docPath = doc->path();
docPath += QLatin1Char('/'); docPath += QLatin1Char('/');
......
...@@ -41,13 +41,11 @@ ...@@ -41,13 +41,11 @@
namespace QmlJS { namespace QmlJS {
class Bind; class Bind;
typedef QSharedPointer<Bind> BindPtr;
class QMLJS_EXPORT Document class QMLJS_EXPORT Document
{ {
public: public:
typedef QSharedPointer<Document> Ptr; typedef QSharedPointer<Document> Ptr;
typedef QList<Document::Ptr> PtrList;
protected: protected:
Document(const QString &fileName); Document(const QString &fileName);
...@@ -57,12 +55,12 @@ public: ...@@ -57,12 +55,12 @@ public:
static Document::Ptr create(const QString &fileName); static Document::Ptr create(const QString &fileName);
QmlJS::AST::UiProgram *qmlProgram() const; AST::UiProgram *qmlProgram() const;
QmlJS::AST::Program *jsProgram() const; AST::Program *jsProgram() const;
QmlJS::AST::ExpressionNode *expression() const; AST::ExpressionNode *expression() const;
QmlJS::AST::Node *ast() const; AST::Node *ast() const;
QList<QmlJS::DiagnosticMessage> diagnosticMessages() const; QList<DiagnosticMessage> diagnosticMessages() const;
QString source() const; QString source() const;
void setSource(const QString &source); void setSource(const QString &source);
...@@ -74,7 +72,7 @@ public: ...@@ -74,7 +72,7 @@ public:
bool isParsedCorrectly() const bool isParsedCorrectly() const
{ return _parsedCorrectly; } { return _parsedCorrectly; }
BindPtr bind() const; Bind *bind() const;
int documentRevision() const; int documentRevision() const;
void setDocumentRevision(int documentRevision); void setDocumentRevision(int documentRevision);
...@@ -85,8 +83,9 @@ public: ...@@ -85,8 +83,9 @@ public:
private: private:
QmlJS::Engine *_engine; QmlJS::Engine *_engine;
QmlJS::NodePool *_pool; NodePool *_pool;
QmlJS::AST::Node *_ast; AST::Node *_ast;
Bind *_bind;
int _documentRevision; int _documentRevision;
bool _parsedCorrectly; bool _parsedCorrectly;
QList<QmlJS::DiagnosticMessage> _diagnosticMessages; QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
...@@ -94,7 +93,6 @@ private: ...@@ -94,7 +93,6 @@ private:
QString _path; QString _path;
QString _componentName; QString _componentName;
QString _source; QString _source;
BindPtr _bind;
}; };
class QMLJS_EXPORT Snapshot class QMLJS_EXPORT Snapshot
...@@ -117,7 +115,7 @@ public: ...@@ -117,7 +115,7 @@ public:
Document::Ptr document(const QString &fileName) const Document::Ptr document(const QString &fileName) const
{ return _documents.value(fileName); } { return _documents.value(fileName); }
Document::PtrList importedDocuments(const Document::Ptr &doc, const QString &importPath) const; QList<Document::Ptr> importedDocuments(const Document::Ptr &doc, const QString &importPath) const;
QMap<QString, Document::Ptr> componentsDefinedByImportedDocuments(const Document::Ptr &doc, const QString &importPath) const; QMap<QString, Document::Ptr> componentsDefinedByImportedDocuments(const Document::Ptr &doc, const QString &importPath) const;
}; };
......
...@@ -45,7 +45,7 @@ void Link::scopeChainAt(Document::Ptr doc, Node *currentObject) ...@@ -45,7 +45,7 @@ void Link::scopeChainAt(Document::Ptr doc, Node *currentObject)
if (doc->qmlProgram() != 0) if (doc->qmlProgram() != 0)
_context.setLookupMode(Context::QmlLookup); _context.setLookupMode(Context::QmlLookup);
BindPtr bind = doc->bind(); Bind *bind = doc->bind();
// Build the scope chain. // Build the scope chain.
......
...@@ -40,7 +40,7 @@ private: ...@@ -40,7 +40,7 @@ private:
AST::UiImport *import, const QString &startPath); AST::UiImport *import, const QString &startPath);
void importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, void importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc,
AST::UiImport *import); AST::UiImport *import);
void importObject(BindPtr bind, const QString &name, Interpreter::ObjectValue *object, NameId* targetNamespace); void importObject(Bind *bind, const QString &name, Interpreter::ObjectValue *object, NameId *targetNamespace);
private: private:
Snapshot _snapshot; Snapshot _snapshot;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment