forked from qt-creator/qt-creator
		
	QmlJS: Stop doing significant work in constructors.
To avoid order-of-initialization problems. Reviewed-by: Thomas Hartmann
This commit is contained in:
		| @@ -43,7 +43,6 @@ | ||||
|  | ||||
| namespace QmlJS { | ||||
|  | ||||
| class Link; | ||||
| class Document; | ||||
|  | ||||
| class QMLJS_EXPORT Bind: protected AST::Visitor | ||||
|   | ||||
| @@ -375,6 +375,7 @@ Check::Check(Document::Ptr doc, const Context *linkedContextNoScope) | ||||
|           | WarnCaseWithoutFlowControlEnd | ErrCheckTypeErrors) | ||||
|     , _lastValue(0) | ||||
| { | ||||
|     _scopeBuilder.initializeRootScope(); | ||||
| } | ||||
|  | ||||
| Check::~Check() | ||||
|   | ||||
| @@ -3286,6 +3286,7 @@ const Value *ASTPropertyReference::value(const Context *context) const | ||||
|         QmlJS::Document::Ptr doc = _doc->ptr(); | ||||
|         Context localContext(*context); | ||||
|         QmlJS::ScopeBuilder builder(&localContext, doc); | ||||
|         builder.initializeRootScope(); | ||||
|  | ||||
|         int offset = _ast->expression->firstSourceLocation().begin(); | ||||
|         builder.push(ScopeAstPath(doc)(offset)); | ||||
|   | ||||
| @@ -110,8 +110,7 @@ public: | ||||
|     \l{Context} with \l{Link}. | ||||
| */ | ||||
|  | ||||
| Link::Link(Context *context, const Snapshot &snapshot, const QStringList &importPaths, | ||||
|            QHash<QString, QList<DiagnosticMessage> > *messages) | ||||
| Link::Link(Context *context, const Snapshot &snapshot, const QStringList &importPaths) | ||||
|     : d_ptr(new LinkPrivate) | ||||
| { | ||||
|     Q_D(Link); | ||||
| @@ -120,30 +119,6 @@ Link::Link(Context *context, const Snapshot &snapshot, const QStringList &import | ||||
|     d->importPaths = importPaths; | ||||
|  | ||||
|     d->diagnosticMessages = 0; | ||||
|     d->allDiagnosticMessages = messages; | ||||
|  | ||||
|     // populate engine with types from C++ | ||||
|     ModelManagerInterface *modelManager = ModelManagerInterface::instance(); | ||||
|     if (modelManager) { | ||||
|         foreach (const QList<FakeMetaObject::ConstPtr> &cppTypes, modelManager->cppQmlTypes()) { | ||||
|             engine()->cppQmlTypes().load(engine(), cppTypes); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     linkImports(); | ||||
| } | ||||
|  | ||||
| Link::Link(Context *context, const Snapshot &snapshot, const QStringList &importPaths, | ||||
|            const Document::Ptr &doc, QList<DiagnosticMessage> *messages) | ||||
|     : d_ptr(new LinkPrivate) | ||||
| { | ||||
|     Q_D(Link); | ||||
|     d->context = context; | ||||
|     d->snapshot = snapshot; | ||||
|     d->importPaths = importPaths; | ||||
|  | ||||
|     d->doc = doc; | ||||
|     d->diagnosticMessages = messages; | ||||
|     d->allDiagnosticMessages = 0; | ||||
|  | ||||
|     // populate engine with types from C++ | ||||
| @@ -153,7 +128,20 @@ Link::Link(Context *context, const Snapshot &snapshot, const QStringList &import | ||||
|             engine()->cppQmlTypes().load(engine(), cppTypes); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| void Link::operator()(QHash<QString, QList<DiagnosticMessage> > *messages) | ||||
| { | ||||
|     Q_D(Link); | ||||
|     d->allDiagnosticMessages = messages; | ||||
|     linkImports(); | ||||
| } | ||||
|  | ||||
| void Link::operator()(const Document::Ptr &doc, QList<DiagnosticMessage> *messages) | ||||
| { | ||||
|     Q_D(Link); | ||||
|     d->doc = doc; | ||||
|     d->diagnosticMessages = messages; | ||||
|     linkImports(); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -54,14 +54,15 @@ class QMLJS_EXPORT Link | ||||
|     Q_DECLARE_TR_FUNCTIONS(QmlJS::Link) | ||||
|  | ||||
| public: | ||||
|     // Link all documents in snapshot, collecting all diagnostic messages | ||||
|     Link(Interpreter::Context *context, const Snapshot &snapshot, | ||||
|          const QStringList &importPaths, QHash<QString, QList<DiagnosticMessage> > *messages = 0); | ||||
|          const QStringList &importPaths); | ||||
|  | ||||
|     // Link all documents in snapshot, collecting all diagnostic messages (if messages != 0) | ||||
|     void operator()(QHash<QString, QList<DiagnosticMessage> > *messages = 0); | ||||
|  | ||||
|     // Link all documents in snapshot, appending the diagnostic messages | ||||
|     // for 'doc' in 'messages' | ||||
|     Link(Interpreter::Context *context, const Snapshot &snapshot, | ||||
|          const QStringList &importPaths, const Document::Ptr &doc, QList<DiagnosticMessage> *messages); | ||||
|     void operator()(const Document::Ptr &doc, QList<DiagnosticMessage> *messages); | ||||
|  | ||||
|     ~Link(); | ||||
|  | ||||
|   | ||||
| @@ -48,18 +48,21 @@ public: | ||||
|     { | ||||
|         // since we keep the document and snapshot around, we don't need to keep the Link instance | ||||
|         Link link(&context, snapshot, ModelManagerInterface::instance()->importPaths()); | ||||
|         link(); | ||||
|  | ||||
|         ScopeBuilder scopeBuilder(&context, doc); | ||||
|         scopeBuilder.initializeRootScope(); | ||||
|         scopeBuilder.push(path); | ||||
|     } | ||||
|  | ||||
|     LookupContextData(Document::Ptr doc, const Snapshot &snapshot, | ||||
|     LookupContextData(Document::Ptr doc, | ||||
|                       const Interpreter::Context &linkedContextWithoutScope, | ||||
|                       const QList<AST::Node *> &path) | ||||
|         : context(linkedContextWithoutScope), | ||||
|           doc(doc) | ||||
|     { | ||||
|         ScopeBuilder scopeBuilder(&context, doc); | ||||
|         scopeBuilder.initializeRootScope(); | ||||
|         scopeBuilder.push(path); | ||||
|     } | ||||
|  | ||||
| @@ -73,10 +76,10 @@ LookupContext::LookupContext(Document::Ptr doc, const Snapshot &snapshot, const | ||||
| { | ||||
| } | ||||
|  | ||||
| LookupContext::LookupContext(const Document::Ptr doc, const Snapshot &snapshot, | ||||
| LookupContext::LookupContext(const Document::Ptr doc, | ||||
|                              const Interpreter::Context &linkedContextWithoutScope, | ||||
|                              const QList<AST::Node *> &path) | ||||
|     : d(new LookupContextData(doc, snapshot, linkedContextWithoutScope, path)) | ||||
|     : d(new LookupContextData(doc, linkedContextWithoutScope, path)) | ||||
| { | ||||
| } | ||||
|  | ||||
| @@ -90,11 +93,11 @@ LookupContext::Ptr LookupContext::create(Document::Ptr doc, const Snapshot &snap | ||||
|     return ptr; | ||||
| } | ||||
|  | ||||
| LookupContext::Ptr LookupContext::create(const Document::Ptr doc, const Snapshot &snapshot, | ||||
| LookupContext::Ptr LookupContext::create(const Document::Ptr doc, | ||||
|                                          const Interpreter::Context &linkedContextWithoutScope, | ||||
|                                          const QList<AST::Node *> &path) | ||||
| { | ||||
|     Ptr ptr(new LookupContext(doc, snapshot, linkedContextWithoutScope, path)); | ||||
|     Ptr ptr(new LookupContext(doc, linkedContextWithoutScope, path)); | ||||
|     return ptr; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -54,7 +54,7 @@ class QMLJS_EXPORT LookupContext | ||||
|     Q_DISABLE_COPY(LookupContext) | ||||
|  | ||||
|     LookupContext(const Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path); | ||||
|     LookupContext(const Document::Ptr doc, const Snapshot &snapshot, | ||||
|     LookupContext(const Document::Ptr doc, | ||||
|                   const Interpreter::Context &linkedContextWithoutScope, | ||||
|                   const QList<AST::Node *> &path); | ||||
|  | ||||
| @@ -66,7 +66,7 @@ public: | ||||
|     // consider using SemanticInfo::lookupContext instead, it's faster | ||||
|     static Ptr create(const Document::Ptr doc, const Snapshot &snapshot, | ||||
|                       const QList<AST::Node *> &path); | ||||
|     static Ptr create(const Document::Ptr doc, const Snapshot &snapshot, | ||||
|     static Ptr create(const Document::Ptr doc, | ||||
|                       const Interpreter::Context &linkedContextWithoutScope, | ||||
|                       const QList<AST::Node *> &path); | ||||
|  | ||||
|   | ||||
| @@ -45,7 +45,6 @@ ScopeBuilder::ScopeBuilder(Context *context, Document::Ptr doc) | ||||
|     : _doc(doc) | ||||
|     , _context(context) | ||||
| { | ||||
|     initializeScopeChain(); | ||||
| } | ||||
|  | ||||
| ScopeBuilder::~ScopeBuilder() | ||||
| @@ -98,7 +97,7 @@ void ScopeBuilder::pop() | ||||
|     _context->scopeChain().update(); | ||||
| } | ||||
|  | ||||
| void ScopeBuilder::initializeScopeChain() | ||||
| void ScopeBuilder::initializeRootScope() | ||||
| { | ||||
|     ScopeChain &scopeChain = _context->scopeChain(); | ||||
|     if (scopeChain.qmlComponentScope | ||||
|   | ||||
| @@ -50,6 +50,8 @@ public: | ||||
|     ScopeBuilder(Interpreter::Context *context, Document::Ptr doc); | ||||
|     ~ScopeBuilder(); | ||||
|  | ||||
|     void initializeRootScope(); | ||||
|  | ||||
|     void push(AST::Node *node); | ||||
|     void push(const QList<AST::Node *> &nodes); | ||||
|     void pop(); | ||||
| @@ -57,7 +59,6 @@ public: | ||||
|     static const Interpreter::ObjectValue *isPropertyChangesObject(const Interpreter::Context *context, const Interpreter::ObjectValue *object); | ||||
|  | ||||
| private: | ||||
|     void initializeScopeChain(); | ||||
|     void makeComponentChain(Document::Ptr doc, const Snapshot &snapshot, | ||||
|                             Interpreter::ScopeChain::QmlComponentChain *target, | ||||
|                             QHash<Document *, Interpreter::ScopeChain::QmlComponentChain *> *components); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user