aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/compiler/qqmlirbuilder.cpp5
-rw-r--r--src/qml/compiler/qqmlirbuilder_p.h2
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp2
-rw-r--r--src/qml/compiler/qv4codegen.cpp3
-rw-r--r--src/qml/compiler/qv4codegen_p.h14
-rw-r--r--src/qml/compiler/qv4compiler.cpp35
-rw-r--r--src/qml/compiler/qv4compiler_p.h2
-rw-r--r--src/qml/compiler/qv4jsir_p.h1
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp4
-rw-r--r--src/qml/jsruntime/qv4script.cpp6
-rw-r--r--tools/qmlcachegen/qmlcachegen.cpp10
11 files changed, 68 insertions, 16 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp
index d8cd31de29..9cc8346160 100644
--- a/src/qml/compiler/qqmlirbuilder.cpp
+++ b/src/qml/compiler/qqmlirbuilder.cpp
@@ -1551,9 +1551,10 @@ char *QmlUnitGenerator::writeBindings(char *bindingPtr, const Object *o, Binding
return bindingPtr;
}
-JSCodeGen::JSCodeGen(const QString &fileName, const QString &sourceCode, QV4::IR::Module *jsModule, QQmlJS::Engine *jsEngine,
+JSCodeGen::JSCodeGen(const QString &fileName, const QString &sourceCode, QV4::Compiler::JSUnitGenerator *jsUnitGenerator,
+ QV4::IR::Module *jsModule, QQmlJS::Engine *jsEngine,
QQmlJS::AST::UiProgram *qmlRoot, QQmlTypeNameCache *imports, const QV4::Compiler::StringTableGenerator *stringPool)
- : QQmlJS::Codegen(/*strict mode*/false)
+ : QQmlJS::Codegen(jsUnitGenerator, /*strict mode*/false)
, sourceCode(sourceCode)
, jsEngine(jsEngine)
, qmlRoot(qmlRoot)
diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h
index 64bf111d9a..2bdf61ddde 100644
--- a/src/qml/compiler/qqmlirbuilder_p.h
+++ b/src/qml/compiler/qqmlirbuilder_p.h
@@ -583,7 +583,7 @@ struct Q_QML_EXPORT PropertyResolver
struct Q_QML_PRIVATE_EXPORT JSCodeGen : public QQmlJS::Codegen
{
- JSCodeGen(const QString &fileName, const QString &sourceCode, QV4::IR::Module *jsModule,
+ JSCodeGen(const QString &fileName, const QString &sourceCode, QV4::Compiler::JSUnitGenerator *jsUnitGenerator, QV4::IR::Module *jsModule,
QQmlJS::Engine *jsEngine, QQmlJS::AST::UiProgram *qmlRoot, QQmlTypeNameCache *imports,
const QV4::Compiler::StringTableGenerator *stringPool);
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp
index c09fde86f1..ed7a2774ea 100644
--- a/src/qml/compiler/qqmltypecompiler.cpp
+++ b/src/qml/compiler/qqmltypecompiler.cpp
@@ -140,7 +140,7 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile()
sss.scan();
}
- QmlIR::JSCodeGen v4CodeGenerator(typeData->finalUrlString(), document->code, &document->jsModule, &document->jsParserEngine, document->program, typeNameCache, &document->jsGenerator.stringTable);
+ QmlIR::JSCodeGen v4CodeGenerator(typeData->finalUrlString(), document->code, &document->jsGenerator, &document->jsModule, &document->jsParserEngine, document->program, typeNameCache, &document->jsGenerator.stringTable);
QQmlJSCodeGenerator jsCodeGen(this, &v4CodeGenerator);
if (!jsCodeGen.generateCodeForComponents())
return nullptr;
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 5b7a7f9050..7e4d98653b 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -484,7 +484,7 @@ void Codegen::ScanFunctions::enterFunction(Node *ast, const QString &name, Forma
}
-Codegen::Codegen(bool strict)
+Codegen::Codegen(QV4::Compiler::JSUnitGenerator *jsUnitGenerator, bool strict)
: _module(0)
, _function(0)
, _block(0)
@@ -494,6 +494,7 @@ Codegen::Codegen(bool strict)
, _loop(0)
, _labelledStatement(0)
, _scopeAndFinally(0)
+ , jsUnitGenerator(jsUnitGenerator)
, _strictMode(strict)
, _fileNameIsUrl(false)
, hasError(false)
diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h
index 31e9cc0f46..1e385c61b2 100644
--- a/src/qml/compiler/qv4codegen_p.h
+++ b/src/qml/compiler/qv4codegen_p.h
@@ -64,16 +64,21 @@
QT_BEGIN_NAMESPACE
+namespace QV4 {
+namespace Compiler {
+struct JSUnitGenerator;
+}
+}
+
namespace QQmlJS {
namespace AST {
class UiParameterList;
}
-
class Q_QML_PRIVATE_EXPORT Codegen: protected AST::Visitor
{
public:
- Codegen(bool strict);
+ Codegen(QV4::Compiler::JSUnitGenerator *jsUnitGenerator, bool strict);
enum CompilationMode {
GlobalCode,
@@ -483,6 +488,7 @@ protected:
QHash<AST::Node *, Environment *> _envMap;
QHash<AST::FunctionExpression *, int> _functionMap;
QStack<QV4::IR::BasicBlock *> _exceptionHandlers;
+ QV4::Compiler::JSUnitGenerator *jsUnitGenerator;
bool _strictMode;
bool _fileNameIsUrl;
@@ -567,8 +573,8 @@ protected:
class RuntimeCodegen : public Codegen
{
public:
- RuntimeCodegen(QV4::ExecutionEngine *engine, bool strict)
- : Codegen(strict)
+ RuntimeCodegen(QV4::ExecutionEngine *engine, QV4::Compiler::JSUnitGenerator *jsUnitGenerator, bool strict)
+ : Codegen(jsUnitGenerator, strict)
, engine(engine)
{}
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp
index f7e63437e1..6ef3d10780 100644
--- a/src/qml/compiler/qv4compiler.cpp
+++ b/src/qml/compiler/qv4compiler.cpp
@@ -43,6 +43,8 @@
#include <private/qv4string_p.h>
#include <private/qv4value_p.h>
#include <private/qv4alloca_p.h>
+#include <private/qqmljslexer_p.h>
+#include <private/qqmljsast_p.h>
#include <wtf/MathExtras.h>
#include <QCryptographicHash>
@@ -168,6 +170,23 @@ int QV4::Compiler::JSUnitGenerator::registerRegExp(QV4::IR::RegExp *regexp)
return regexps.size() - 1;
}
+int QV4::Compiler::JSUnitGenerator::registerRegExp(QQmlJS::AST::RegExpLiteral *regexp)
+{
+ CompiledData::RegExp re;
+ re.stringIndex = registerString(regexp->pattern.toString());
+
+ re.flags = 0;
+ if (regexp->flags & QQmlJS::Lexer::RegExp_Global)
+ re.flags |= CompiledData::RegExp::RegExp_Global;
+ if (regexp->flags & QQmlJS::Lexer::RegExp_IgnoreCase)
+ re.flags |= CompiledData::RegExp::RegExp_IgnoreCase;
+ if (regexp->flags & QQmlJS::Lexer::RegExp_Multiline)
+ re.flags |= CompiledData::RegExp::RegExp_Multiline;
+
+ regexps.append(re);
+ return regexps.size() - 1;
+}
+
int QV4::Compiler::JSUnitGenerator::registerConstant(QV4::ReturnedValue v)
{
int idx = constants.indexOf(v);
@@ -209,6 +228,22 @@ int QV4::Compiler::JSUnitGenerator::registerJSClass(int count, IR::ExprList *arg
return jsClassOffsets.size() - 1;
}
+int QV4::Compiler::JSUnitGenerator::registerJSClass(int count, CompiledData::JSClassMember *members)
+{
+ const int size = CompiledData::JSClass::calculateSize(count);
+ jsClassOffsets.append(jsClassData.size());
+ const int oldSize = jsClassData.size();
+ jsClassData.resize(jsClassData.size() + size);
+ memset(jsClassData.data() + oldSize, 0, size);
+
+ CompiledData::JSClass *jsClass = reinterpret_cast<CompiledData::JSClass*>(jsClassData.data() + oldSize);
+ jsClass->nMembers = count;
+ CompiledData::JSClassMember *jsClassMembers = reinterpret_cast<CompiledData::JSClassMember*>(jsClass + 1);
+ memcpy(jsClassMembers, members, sizeof(CompiledData::JSClassMember)*count);
+
+ return jsClassOffsets.size() - 1;
+}
+
QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(GeneratorOption option)
{
registerString(irModule->fileName);
diff --git a/src/qml/compiler/qv4compiler_p.h b/src/qml/compiler/qv4compiler_p.h
index 49b8664513..7c4b48132f 100644
--- a/src/qml/compiler/qv4compiler_p.h
+++ b/src/qml/compiler/qv4compiler_p.h
@@ -103,10 +103,12 @@ struct Q_QML_PRIVATE_EXPORT JSUnitGenerator {
uint registerIndexedSetterLookup();
int registerRegExp(IR::RegExp *regexp);
+ int registerRegExp(QQmlJS::AST::RegExpLiteral *regexp);
int registerConstant(ReturnedValue v);
int registerJSClass(int count, IR::ExprList *args);
+ int registerJSClass(int count, CompiledData::JSClassMember *members);
enum GeneratorOption {
GenerateWithStringTable,
diff --git a/src/qml/compiler/qv4jsir_p.h b/src/qml/compiler/qv4jsir_p.h
index 190fb1bd5b..1b77dbf096 100644
--- a/src/qml/compiler/qv4jsir_p.h
+++ b/src/qml/compiler/qv4jsir_p.h
@@ -1290,6 +1290,7 @@ struct Function {
QList<const QString *> locals;
QVector<Function *> nestedFunctions;
Function *outer;
+ QByteArray code;
int insideWithOrCatch;
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 45fdde98f7..2ca4584fc1 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -221,10 +221,10 @@ void FunctionCtor::construct(const Managed *that, Scope &scope, CallData *callDa
IR::Module module(scope.engine->debugger() != 0);
- QQmlJS::RuntimeCodegen cg(scope.engine, f->strictMode());
+ Compiler::JSUnitGenerator jsGenerator(&module);
+ QQmlJS::RuntimeCodegen cg(scope.engine, &jsGenerator, f->strictMode());
cg.generateFromFunctionExpression(QString(), function, fe, &module);
- Compiler::JSUnitGenerator jsGenerator(&module);
QScopedPointer<EvalInstructionSelection> isel(scope.engine->iselFactory->create(QQmlEnginePrivate::get(scope.engine), scope.engine->executableAllocator, &module, &jsGenerator));
QQmlRefPointer<CompiledData::CompilationUnit> compilationUnit = isel->compile();
Function *vmf = compilationUnit->linkToEngine(scope.engine);
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index 62145f36cc..c0b38bd7ef 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -126,12 +126,12 @@ void Script::parse()
}
}
- RuntimeCodegen cg(v4, strictMode);
+ QV4::Compiler::JSUnitGenerator jsGenerator(&module);
+ RuntimeCodegen cg(v4, &jsGenerator, strictMode);
cg.generateFromProgram(sourceFile, sourceCode, program, &module, QQmlJS::Codegen::EvalCode, inheritedLocals);
if (v4->hasException)
return;
- QV4::Compiler::JSUnitGenerator jsGenerator(&module);
QScopedPointer<EvalInstructionSelection> isel(v4->iselFactory->create(QQmlEnginePrivate::get(v4), v4->executableAllocator, &module, &jsGenerator));
if (inheritContext)
isel->setUseFastLookups(false);
@@ -230,7 +230,7 @@ QQmlRefPointer<QV4::CompiledData::CompilationUnit> Script::precompile(IR::Module
return 0;
}
- QQmlJS::Codegen cg(/*strict mode*/false);
+ QQmlJS::Codegen cg(unitGenerator, /*strict mode*/false);
cg.generateFromProgram(url.toString(), source, program, module, QQmlJS::Codegen::EvalCode);
errors = cg.qmlErrors();
if (!errors.isEmpty()) {
diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp
index b201176d5e..6bc199ee6b 100644
--- a/tools/qmlcachegen/qmlcachegen.cpp
+++ b/tools/qmlcachegen/qmlcachegen.cpp
@@ -149,7 +149,10 @@ static bool compileQmlFile(const QString &inputFileName, const QString &outputFi
annotateListElements(&irDocument);
{
- QmlIR::JSCodeGen v4CodeGen(/*empty input file name*/QString(), irDocument.code, &irDocument.jsModule, &irDocument.jsParserEngine, irDocument.program, /*import cache*/0, &irDocument.jsGenerator.stringTable);
+ QmlIR::JSCodeGen v4CodeGen(/*empty input file name*/QString(), irDocument.code,
+ &irDocument.jsGenerator, &irDocument.jsModule,
+ &irDocument.jsParserEngine, irDocument.program,
+ /*import cache*/0, &irDocument.jsGenerator.stringTable);
for (QmlIR::Object *object: qAsConst(irDocument.objects)) {
if (object->functionsAndExpressions->count == 0)
continue;
@@ -253,7 +256,10 @@ static bool compileJSFile(const QString &inputFileName, const QString &outputFil
}
{
- QmlIR::JSCodeGen v4CodeGen(inputFileName, irDocument.code, &irDocument.jsModule, &irDocument.jsParserEngine, irDocument.program, /*import cache*/0, &irDocument.jsGenerator.stringTable);
+ QmlIR::JSCodeGen v4CodeGen(inputFileName, irDocument.code, &irDocument.jsGenerator,
+ &irDocument.jsModule, &irDocument.jsParserEngine,
+ irDocument.program, /*import cache*/0,
+ &irDocument.jsGenerator.stringTable);
v4CodeGen.generateFromProgram(/*empty input file name*/QString(), sourceCode, program, &irDocument.jsModule, QQmlJS::Codegen::GlobalCode);
QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors();
if (!jsErrors.isEmpty()) {