diff options
author | Antti Piira <[email protected]> | 2013-09-24 12:49:10 -0700 |
---|---|---|
committer | The Qt Project <[email protected]> | 2013-10-21 21:43:32 +0200 |
commit | 9de3630a513aa598855f7d40461c5aec9ecce319 (patch) | |
tree | 69eb5b78efbfe6cba7b7266a9adbe0e2bce77336 /src/qml/compiler/qqmlcodegenerator.cpp | |
parent | de31a57672ec461c2081f65e3631134ee45de887 (diff) |
Add support CompositeSingleton to the new V4 compiler.v5.2.0-beta1
Implements QQmlCodeGenerator::visit(AST::UiPragma *) to process any
pragma statements in a QML file for the new V4 compiler approach.
Only pragma Singleton is supported, others will generate errors.
Also adds necessary hooks to treat types as Singletons. Basic
functionality is working, but three of the QML Singleton unit tests
fail. Some of them are dependent on other language capabilities that
seem to have problems.
In addition removes unnecessary toString() call in the equivalent
visit(AST::UiPragma *) function of the old parser.
Change-Id: Iec9fa887f953b80b7f9a11878d846637a8f519ef
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/compiler/qqmlcodegenerator.cpp')
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index ed5f4c3772..2aa5aa5a3c 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -118,6 +118,7 @@ bool QQmlCodeGenerator::generateFromQml(const QString &code, const QUrl &url, co output->program = program; qSwap(_imports, output->imports); + qSwap(_pragmas, output->pragmas); qSwap(_objects, output->objects); qSwap(_functions, output->functions); qSwap(_typeReferences, output->typeReferences); @@ -147,6 +148,7 @@ bool QQmlCodeGenerator::generateFromQml(const QString &code, const QUrl &url, co collectTypeReferences(); qSwap(_imports, output->imports); + qSwap(_pragmas, output->pragmas); qSwap(_objects, output->objects); qSwap(_functions, output->functions); qSwap(_typeReferences, output->typeReferences); @@ -403,6 +405,11 @@ bool QQmlCodeGenerator::visit(AST::UiImport *node) error.setColumn(node->importIdToken.startColumn); errors << error; return false; + } else { + // For backward compatibility in how the imports are loaded we + // must otherwise initialize the major and minor version to -1. + import->majorVersion = -1; + import->minorVersion = -1; } import->location.line = node->importToken.startLine; @@ -415,9 +422,38 @@ bool QQmlCodeGenerator::visit(AST::UiImport *node) return false; } -bool QQmlCodeGenerator::visit(AST::UiPragma *ast) +bool QQmlCodeGenerator::visit(AST::UiPragma *node) { - return true; + Pragma *pragma = New<Pragma>(); + + // For now the only valid pragma is Singleton, so lets validate the input + if (!node->pragmaType->name.isNull()) + { + if (QLatin1String("Singleton") == node->pragmaType->name) + { + pragma->type = Pragma::PragmaSingleton; + } else { + QQmlError error; + error.setDescription(QCoreApplication::translate("QQmlParser","Pragma requires a valid qualifier")); + error.setLine(node->pragmaToken.startLine); + error.setColumn(node->pragmaToken.startColumn); + errors << error; + return false; + } + } else { + QQmlError error; + error.setDescription(QCoreApplication::translate("QQmlParser","Pragma requires a valid qualifier")); + error.setLine(node->pragmaToken.startLine); + error.setColumn(node->pragmaToken.startColumn); + errors << error; + return false; + } + + pragma->location.line = node->pragmaToken.startLine; + pragma->location.column = node->pragmaToken.startColumn; + _pragmas.append(pragma); + + return false; } static QStringList astNodeToStringList(QQmlJS::AST::Node *node) @@ -1146,6 +1182,14 @@ QV4::CompiledData::QmlUnit *QmlUnitGenerator::generate(ParsedQML &output, const objectPtr += signalTableSize; } + // enable flag if we encountered pragma Singleton + foreach (Pragma *p, output.pragmas) { + if (p->type == Pragma::PragmaSingleton) { + qmlUnit->header.flags |= QV4::CompiledData::Unit::IsSingleton; + break; + } + } + return qmlUnit; } |