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