diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-24 14:14:46 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-25 12:51:34 +0100 |
commit | 140a34afdd9ecbb7bc5f9db3f68dcd43a6c534e3 (patch) | |
tree | b235dbaabac9e900992c76baf6b7f919b9a7195a /src/qmlcompiler/qqmljstypereader.cpp | |
parent | 927dd69db9bbffcc423b735a7f89e950e052892a (diff) |
QmlCompiler: Unify parsing of QML components, JS programs, ES modules
There is no reason to duplicate the code for retrieving method
signatures 3 times over. As an added benefit, the types on those methods
are resolved now.
Change-Id: I2f9681911b938c4a260b6593ab49e9cc5098c546
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljstypereader.cpp')
-rw-r--r-- | src/qmlcompiler/qqmljstypereader.cpp | 58 |
1 files changed, 7 insertions, 51 deletions
diff --git a/src/qmlcompiler/qqmljstypereader.cpp b/src/qmlcompiler/qqmljstypereader.cpp index 789166a301..25636dbe32 100644 --- a/src/qmlcompiler/qqmljstypereader.cpp +++ b/src/qmlcompiler/qqmljstypereader.cpp @@ -40,43 +40,6 @@ QT_BEGIN_NAMESPACE -static QQmlJSScope::Ptr parseModule(QQmlJS::AST::ESModule *module, const QString &name) -{ - using namespace QQmlJS::AST; - QQmlJSScope::Ptr result = QQmlJSScope::create(QQmlJSScope::JSLexicalScope); - result->setInternalName(name); - for (auto *statement = module->body; statement; statement = statement->next) { - if (auto *exp = cast<ExportDeclaration *>(statement->statement)) { - // TODO: There are a number of other things we could find here - if (auto *function = cast<FunctionDeclaration *>(exp->variableStatementOrDeclaration)) { - QQmlJSMetaMethod method(function->name.toString()); - method.setMethodType(QQmlJSMetaMethod::Method); - for (auto *argument = function->formals; argument; argument = argument->next) - method.addParameter(argument->element->bindingIdentifier.toString(), QString()); - result->addOwnMethod(method); - } - } - } - return result; -} - -static QQmlJSScope::Ptr parseProgram(QQmlJS::AST::Program *program, const QString &name) -{ - using namespace QQmlJS::AST; - QQmlJSScope::Ptr result = QQmlJSScope::create(QQmlJSScope::JSLexicalScope); - result->setInternalName(name); - for (auto *statement = program->statements; statement; statement = statement->next) { - if (auto *function = cast<FunctionDeclaration *>(statement->statement)) { - QQmlJSMetaMethod method(function->name.toString()); - method.setMethodType(QQmlJSMetaMethod::Method); - for (auto *parameters = function->formals; parameters; parameters = parameters->next) - method.addParameter(parameters->element->bindingIdentifier.toString(), QString()); - result->addOwnMethod(method); - } - } - return result; -} - QQmlJSScope::Ptr QQmlJSTypeReader::operator()() { using namespace QQmlJS::AST; @@ -116,20 +79,13 @@ QQmlJSScope::Ptr QQmlJSTypeReader::operator()() return result; } - if (!isJavaScript) { - QQmlJS::AST::UiProgram *program = parser.ast(); - QQmlJSImportVisitor membersVisitor(m_importer, QFileInfo(m_file).canonicalPath(), - m_qmltypesFiles); - program->accept(&membersVisitor); - m_errors = membersVisitor.errors(); - return membersVisitor.result(); - } - - - if (isESModule) - return parseModule(cast<ESModule *>(parser.rootNode()), scopeName); - else - return parseProgram(cast<Program *>(parser.rootNode()), scopeName); + QQmlJS::AST::Node *rootNode = parser.rootNode(); + QQmlJSImportVisitor membersVisitor(m_importer, QFileInfo(m_file).canonicalPath(), + m_qmltypesFiles); + rootNode->accept(&membersVisitor); + auto result = membersVisitor.result(); + result->setInternalName(scopeName); + return result; } QT_END_NAMESPACE |