2013-08-14 08:17:31 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
**
|
|
|
|
** This file is part of the QtQml module of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "qv4compileddata_p.h"
|
|
|
|
#include "qv4jsir_p.h"
|
2013-08-14 08:17:37 +00:00
|
|
|
#include <private/qv4engine_p.h>
|
2013-08-14 13:44:53 +00:00
|
|
|
#include <private/qv4function_p.h>
|
2013-08-29 12:31:32 +00:00
|
|
|
#include <private/qv4objectproto_p.h>
|
2013-08-15 10:48:05 +00:00
|
|
|
#include <private/qv4lookup_p.h>
|
2013-08-15 13:54:36 +00:00
|
|
|
#include <private/qv4regexpobject_p.h>
|
2013-08-14 08:17:31 +00:00
|
|
|
|
2013-09-12 09:06:59 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2013-08-18 13:35:02 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2013-08-14 08:17:31 +00:00
|
|
|
namespace QV4 {
|
|
|
|
|
|
|
|
namespace CompiledData {
|
|
|
|
|
2013-08-14 08:17:37 +00:00
|
|
|
CompilationUnit::~CompilationUnit()
|
|
|
|
{
|
2013-09-19 07:32:42 +00:00
|
|
|
unlink();
|
2013-08-14 08:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QV4::Function *CompilationUnit::linkToEngine(ExecutionEngine *engine)
|
|
|
|
{
|
2013-08-15 12:11:19 +00:00
|
|
|
this->engine = engine;
|
|
|
|
engine->compilationUnits.insert(this);
|
|
|
|
|
2013-08-15 08:36:41 +00:00
|
|
|
assert(!runtimeStrings);
|
2013-08-14 08:17:37 +00:00
|
|
|
assert(data);
|
2013-09-19 10:05:18 +00:00
|
|
|
runtimeStrings = (QV4::SafeString *)malloc(data->stringTableSize * sizeof(QV4::SafeString));
|
2013-09-20 13:13:14 +00:00
|
|
|
// memset the strings to 0 in case a GC run happens while we're within the loop below
|
|
|
|
memset(runtimeStrings, 0, data->stringTableSize * sizeof(QV4::SafeString));
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = 0; i < data->stringTableSize; ++i)
|
2013-08-17 12:54:56 +00:00
|
|
|
runtimeStrings[i] = engine->newIdentifier(data->stringAt(i));
|
2013-08-14 08:17:37 +00:00
|
|
|
|
2013-09-30 13:41:24 +00:00
|
|
|
runtimeRegularExpressions = new QV4::SafeValue[data->regexpTableSize];
|
2013-09-20 13:13:14 +00:00
|
|
|
// memset the regexps to 0 in case a GC run happens while we're within the loop below
|
2013-09-30 13:41:24 +00:00
|
|
|
memset(runtimeRegularExpressions, 0, data->regexpTableSize * sizeof(QV4::SafeValue));
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = 0; i < data->regexpTableSize; ++i) {
|
2013-08-15 13:54:36 +00:00
|
|
|
const CompiledData::RegExp *re = data->regexpAt(i);
|
|
|
|
int flags = 0;
|
|
|
|
if (re->flags & CompiledData::RegExp::RegExp_Global)
|
|
|
|
flags |= QQmlJS::V4IR::RegExp::RegExp_Global;
|
|
|
|
if (re->flags & CompiledData::RegExp::RegExp_IgnoreCase)
|
|
|
|
flags |= QQmlJS::V4IR::RegExp::RegExp_IgnoreCase;
|
|
|
|
if (re->flags & CompiledData::RegExp::RegExp_Multiline)
|
|
|
|
flags |= QQmlJS::V4IR::RegExp::RegExp_Multiline;
|
2013-09-30 13:41:24 +00:00
|
|
|
runtimeRegularExpressions[i] = engine->newRegExpObject(data->stringAt(re->stringIndex), flags);
|
2013-08-15 13:54:36 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 10:48:05 +00:00
|
|
|
if (data->lookupTableSize) {
|
|
|
|
runtimeLookups = new QV4::Lookup[data->lookupTableSize];
|
2013-10-11 12:58:45 +00:00
|
|
|
memset(runtimeLookups, 0, data->lookupTableSize * sizeof(QV4::Lookup));
|
2013-08-15 10:48:05 +00:00
|
|
|
const CompiledData::Lookup *compiledLookups = data->lookupTable();
|
|
|
|
for (uint i = 0; i < data->lookupTableSize; ++i) {
|
|
|
|
QV4::Lookup *l = runtimeLookups + i;
|
|
|
|
|
|
|
|
if (compiledLookups[i].type_and_flags == CompiledData::Lookup::Type_Getter)
|
|
|
|
l->getter = QV4::Lookup::getterGeneric;
|
|
|
|
else if (compiledLookups[i].type_and_flags == CompiledData::Lookup::Type_Setter)
|
|
|
|
l->setter = QV4::Lookup::setterGeneric;
|
|
|
|
else if (compiledLookups[i].type_and_flags == CompiledData::Lookup::Type_GlobalGetter)
|
|
|
|
l->globalGetter = QV4::Lookup::globalGetterGeneric;
|
|
|
|
|
2013-11-01 11:38:32 +00:00
|
|
|
for (int j = 0; j < QV4::Lookup::Size; ++j)
|
|
|
|
l->classList[j] = 0;
|
2013-08-15 10:48:05 +00:00
|
|
|
l->level = -1;
|
|
|
|
l->index = UINT_MAX;
|
2013-09-19 10:05:18 +00:00
|
|
|
l->name = runtimeStrings[compiledLookups[i].nameIndex].asString();
|
2013-08-15 10:48:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-16 11:21:31 +00:00
|
|
|
if (data->jsClassTableSize) {
|
|
|
|
runtimeClasses = (QV4::InternalClass**)malloc(data->jsClassTableSize * sizeof(QV4::InternalClass*));
|
|
|
|
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = 0; i < data->jsClassTableSize; ++i) {
|
2013-08-16 11:21:31 +00:00
|
|
|
int memberCount = 0;
|
|
|
|
const CompiledData::JSClassMember *member = data->jsClassAt(i, &memberCount);
|
2013-08-29 19:23:04 +00:00
|
|
|
QV4::InternalClass *klass = engine->objectClass;
|
2013-08-16 11:21:31 +00:00
|
|
|
for (int j = 0; j < memberCount; ++j, ++member)
|
2013-09-19 10:05:18 +00:00
|
|
|
klass = klass->addMember(runtimeStrings[member->nameOffset].asString(), member->isAccessor ? QV4::Attr_Accessor : QV4::Attr_Data);
|
2013-08-16 11:21:31 +00:00
|
|
|
|
|
|
|
runtimeClasses[i] = klass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-19 06:31:35 +00:00
|
|
|
linkBackendToEngine(engine);
|
2013-08-16 16:35:29 +00:00
|
|
|
|
2013-08-30 08:29:16 +00:00
|
|
|
#if 0
|
2013-08-16 16:35:29 +00:00
|
|
|
runtimeFunctionsSortedByAddress.resize(runtimeFunctions.size());
|
|
|
|
memcpy(runtimeFunctionsSortedByAddress.data(), runtimeFunctions.data(), runtimeFunctions.size() * sizeof(QV4::Function*));
|
2013-09-12 09:06:59 +00:00
|
|
|
std::sort(runtimeFunctionsSortedByAddress.begin(), runtimeFunctionsSortedByAddress.end(), functionSortHelper);
|
2013-08-30 08:29:16 +00:00
|
|
|
#endif
|
2013-08-16 16:35:29 +00:00
|
|
|
|
2013-10-18 13:36:40 +00:00
|
|
|
if (data->indexOfRootFunction != -1)
|
|
|
|
return runtimeFunctions[data->indexOfRootFunction];
|
|
|
|
else
|
|
|
|
return 0;
|
2013-08-14 08:17:37 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 07:32:42 +00:00
|
|
|
void CompilationUnit::unlink()
|
|
|
|
{
|
|
|
|
if (engine)
|
|
|
|
engine->compilationUnits.erase(engine->compilationUnits.find(this));
|
|
|
|
engine = 0;
|
|
|
|
if (ownsData)
|
|
|
|
free(data);
|
|
|
|
data = 0;
|
|
|
|
free(runtimeStrings);
|
|
|
|
runtimeStrings = 0;
|
|
|
|
delete [] runtimeLookups;
|
|
|
|
runtimeLookups = 0;
|
|
|
|
delete [] runtimeRegularExpressions;
|
|
|
|
runtimeRegularExpressions = 0;
|
|
|
|
free(runtimeClasses);
|
|
|
|
runtimeClasses = 0;
|
|
|
|
qDeleteAll(runtimeFunctions);
|
|
|
|
runtimeFunctions.clear();
|
|
|
|
}
|
|
|
|
|
2013-11-02 15:30:26 +00:00
|
|
|
void CompilationUnit::markObjects(QV4::ExecutionEngine *e)
|
2013-08-15 12:11:19 +00:00
|
|
|
{
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = 0; i < data->stringTableSize; ++i)
|
2013-11-02 15:30:26 +00:00
|
|
|
runtimeStrings[i].mark(e);
|
2013-10-11 12:58:45 +00:00
|
|
|
if (runtimeRegularExpressions) {
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = 0; i < data->regexpTableSize; ++i)
|
2013-11-02 15:30:26 +00:00
|
|
|
runtimeRegularExpressions[i].mark(e);
|
2013-10-11 12:58:45 +00:00
|
|
|
}
|
2013-08-16 16:35:29 +00:00
|
|
|
for (int i = 0; i < runtimeFunctions.count(); ++i)
|
2013-09-20 13:13:14 +00:00
|
|
|
if (runtimeFunctions[i])
|
2013-11-02 15:30:26 +00:00
|
|
|
runtimeFunctions[i]->mark(e);
|
2013-10-11 12:58:45 +00:00
|
|
|
if (runtimeLookups) {
|
2013-11-01 11:38:32 +00:00
|
|
|
for (uint i = 0; i < data->lookupTableSize; ++i)
|
2013-11-02 15:30:26 +00:00
|
|
|
runtimeLookups[i].name->mark(e);
|
2013-10-11 12:58:45 +00:00
|
|
|
}
|
2013-08-15 12:11:19 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 07:08:41 +00:00
|
|
|
QString Binding::valueAsString(const Unit *unit) const
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case Type_Script:
|
|
|
|
case Type_String:
|
|
|
|
return unit->stringAt(stringIndex);
|
|
|
|
case Type_Boolean:
|
|
|
|
return value.b ? QStringLiteral("true") : QStringLiteral("false");
|
|
|
|
case Type_Number:
|
|
|
|
return QString::number(value.d);
|
|
|
|
case Type_Invalid:
|
|
|
|
return QString();
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2013-08-14 08:17:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-08-18 13:35:02 +00:00
|
|
|
|
|
|
|
QT_END_NAMESPACE
|