Qt 4.8
Classes | Macros | Functions
qdeclarativecompiledbindings.cpp File Reference
#include "private/qdeclarativecompiledbindings_p.h"
#include <QtDeclarative/qdeclarativeinfo.h>
#include <private/qdeclarativecontext_p.h>
#include <private/qdeclarativejsast_p.h>
#include <private/qdeclarativejsengine_p.h>
#include <private/qdeclarativeexpression_p.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qdebug.h>
#include <QtCore/qnumeric.h>
#include <private/qdeclarativeanchors_p_p.h>
#include <private/qdeclarativeglobal_p.h>
#include <private/qdeclarativefastproperties_p.h>
#include <private/qdeclarativedebugtrace_p.h>

Go to the source code of this file.

Classes

struct  QDeclarativeBindingCompilerPrivate
 
struct  QDeclarativeBindingCompilerPrivate::Result
 
class  QDeclarativeCompiledBindingsPrivate
 
struct  QDeclarativeCompiledBindingsPrivate::Binding
 

Macros

#define FOR_EACH_QML_INSTR(F)
 
#define QML_BEGIN_INSTR(I)   case Instr::I:
 
#define QML_END_INSTR(I)   break;
 
#define QML_INSTR_ADDR(I)   &&op_##I,
 
#define QML_INSTR_ENUM(I)   I,
 
#define QML_INSTR_HEADER
 

Functions

 DEFINE_BOOL_CONFIG_OPTION (qmlExperimental, QML_EXPERIMENTAL)
 
 DEFINE_BOOL_CONFIG_OPTION (qmlDisableOptimizer, QML_DISABLE_OPTIMIZER)
 
 DEFINE_BOOL_CONFIG_OPTION (qmlDisableFastProperties, QML_DISABLE_FAST_PROPERTIES)
 
 DEFINE_BOOL_CONFIG_OPTION (bindingsDump, QML_BINDINGS_DUMP)
 
static void dumpInstruction (const Instr *instr)
 
 Q_GLOBAL_STATIC (QDeclarativeFastProperties, fastProperties)
 
static void throwException (int id, QDeclarativeDelayedError *error, Program *program, QDeclarativeContextData *context, const QString &description=QString())
 
static bool toBool (Register *reg, int type, bool *ok=0)
 
static qreal toReal (Register *reg, int type, bool *ok=0)
 
static QString toString (Register *reg, int type, bool *ok=0)
 
static QUrl toUrl (Register *reg, int type, QDeclarativeContextData *context, bool *ok=0)
 
static QObjectvariantToQObject (const QVariant &value, bool *ok)
 

Macro Definition Documentation

◆ FOR_EACH_QML_INSTR

#define FOR_EACH_QML_INSTR (   F)

◆ QML_BEGIN_INSTR

#define QML_BEGIN_INSTR (   I)    case Instr::I:

◆ QML_END_INSTR

#define QML_END_INSTR (   I)    break;

◆ QML_INSTR_ADDR

#define QML_INSTR_ADDR (   I)    &&op_##I,

◆ QML_INSTR_ENUM

#define QML_INSTR_ENUM (   I)    I,

◆ QML_INSTR_HEADER

#define QML_INSTR_HEADER

Function Documentation

◆ DEFINE_BOOL_CONFIG_OPTION() [1/4]

DEFINE_BOOL_CONFIG_OPTION ( qmlExperimental  ,
QML_EXPERIMENTAL   
)

◆ DEFINE_BOOL_CONFIG_OPTION() [2/4]

DEFINE_BOOL_CONFIG_OPTION ( qmlDisableOptimizer  ,
QML_DISABLE_OPTIMIZER   
)

◆ DEFINE_BOOL_CONFIG_OPTION() [3/4]

DEFINE_BOOL_CONFIG_OPTION ( qmlDisableFastProperties  ,
QML_DISABLE_FAST_PROPERTIES   
)

◆ DEFINE_BOOL_CONFIG_OPTION() [4/4]

DEFINE_BOOL_CONFIG_OPTION ( bindingsDump  ,
QML_BINDINGS_DUMP   
)

◆ dumpInstruction()

static void dumpInstruction ( const Instr *  instr)
static

Definition at line 1033 of file qdeclarativecompiledbindings.cpp.

Referenced by QDeclarativeBindingCompiler::dump(), and QDeclarativeCompiledBindingsPrivate::run().

1034 {
1035  switch (instr->common.type) {
1036  case Instr::Noop:
1037  qWarning().nospace() << "\t" << "Noop";
1038  break;
1039  case Instr::BindingId:
1040  qWarning().nospace() << instr->id.line << ":" << instr->id.column << ":";
1041  break;
1042  case Instr::Subscribe:
1043  qWarning().nospace() << "\t" << "Subscribe" << "\t\t" << instr->subscribe.offset << "\t" << instr->subscribe.reg << "\t" << instr->subscribe.index;
1044  break;
1045  case Instr::SubscribeId:
1046  qWarning().nospace() << "\t" << "SubscribeId" << "\t\t" << instr->subscribe.offset << "\t" << instr->subscribe.reg << "\t" << instr->subscribe.index;
1047  break;
1048  case Instr::FetchAndSubscribe:
1049  qWarning().nospace() << "\t" << "FetchAndSubscribe" << "\t" << instr->fetchAndSubscribe.output << "\t" << instr->fetchAndSubscribe.objectReg << "\t" << instr->fetchAndSubscribe.subscription;
1050  break;
1051  case Instr::LoadId:
1052  qWarning().nospace() << "\t" << "LoadId" << "\t\t\t" << instr->load.index << "\t" << instr->load.reg;
1053  break;
1054  case Instr::LoadScope:
1055  qWarning().nospace() << "\t" << "LoadScope" << "\t\t" << instr->load.index << "\t" << instr->load.reg;
1056  break;
1057  case Instr::LoadRoot:
1058  qWarning().nospace() << "\t" << "LoadRoot" << "\t\t" << instr->load.index << "\t" << instr->load.reg;
1059  break;
1060  case Instr::LoadAttached:
1061  qWarning().nospace() << "\t" << "LoadAttached" << "\t\t" << instr->attached.output << "\t" << instr->attached.reg << "\t" << instr->attached.id;
1062  break;
1063  case Instr::ConvertIntToReal:
1064  qWarning().nospace() << "\t" << "ConvertIntToReal" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src;
1065  break;
1066  case Instr::ConvertRealToInt:
1067  qWarning().nospace() << "\t" << "ConvertRealToInt" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src;
1068  break;
1069  case Instr::Real:
1070  qWarning().nospace() << "\t" << "Real" << "\t\t\t" << instr->real_value.reg << "\t" << instr->real_value.value;
1071  break;
1072  case Instr::Int:
1073  qWarning().nospace() << "\t" << "Int" << "\t\t\t" << instr->int_value.reg << "\t" << instr->int_value.value;
1074  break;
1075  case Instr::Bool:
1076  qWarning().nospace() << "\t" << "Bool" << "\t\t\t" << instr->bool_value.reg << "\t" << instr->bool_value.value;
1077  break;
1078  case Instr::String:
1079  qWarning().nospace() << "\t" << "String" << "\t\t\t" << instr->string_value.reg << "\t" << instr->string_value.offset << "\t" << instr->string_value.length;
1080  break;
1081  case Instr::AddReal:
1082  qWarning().nospace() << "\t" << "AddReal" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1083  break;
1084  case Instr::AddInt:
1085  qWarning().nospace() << "\t" << "AddInt" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1086  break;
1087  case Instr::AddString:
1088  qWarning().nospace() << "\t" << "AddString" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1089  break;
1090  case Instr::MinusReal:
1091  qWarning().nospace() << "\t" << "MinusReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1092  break;
1093  case Instr::MinusInt:
1094  qWarning().nospace() << "\t" << "MinusInt" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1095  break;
1096  case Instr::CompareReal:
1097  qWarning().nospace() << "\t" << "CompareReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1098  break;
1099  case Instr::CompareString:
1100  qWarning().nospace() << "\t" << "CompareString" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1101  break;
1102  case Instr::NotCompareReal:
1103  qWarning().nospace() << "\t" << "NotCompareReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1104  break;
1105  case Instr::NotCompareString:
1106  qWarning().nospace() << "\t" << "NotCompareString" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1107  break;
1108  case Instr::GreaterThanReal:
1109  qWarning().nospace() << "\t" << "GreaterThanReal" << "\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1110  break;
1111  case Instr::MaxReal:
1112  qWarning().nospace() << "\t" << "MaxReal" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1113  break;
1114  case Instr::MinReal:
1115  qWarning().nospace() << "\t" << "MinReal" << "\t\t\t" << instr->binaryop.output << "\t" << instr->binaryop.src1 << "\t" << instr->binaryop.src2;
1116  break;
1117  case Instr::NewString:
1118  qWarning().nospace() << "\t" << "NewString" << "\t\t" << instr->construct.reg;
1119  break;
1120  case Instr::NewUrl:
1121  qWarning().nospace() << "\t" << "NewUrl" << "\t\t\t" << instr->construct.reg;
1122  break;
1123  case Instr::CleanupString:
1124  qWarning().nospace() << "\t" << "CleanupString" << "\t\t" << instr->cleanup.reg;
1125  break;
1126  case Instr::CleanupUrl:
1127  qWarning().nospace() << "\t" << "CleanupUrl" << "\t\t" << instr->cleanup.reg;
1128  break;
1129  case Instr::Fetch:
1130  qWarning().nospace() << "\t" << "Fetch" << "\t\t\t" << instr->fetch.output << "\t" << instr->fetch.index << "\t" << instr->fetch.objectReg;
1131  break;
1132  case Instr::Store:
1133  qWarning().nospace() << "\t" << "Store" << "\t\t\t" << instr->store.output << "\t" << instr->store.index << "\t" << instr->store.reg;
1134  break;
1135  case Instr::Copy:
1136  qWarning().nospace() << "\t" << "Copy" << "\t\t\t" << instr->copy.reg << "\t" << instr->copy.src;
1137  break;
1138  case Instr::Skip:
1139  qWarning().nospace() << "\t" << "Skip" << "\t\t\t" << instr->skip.reg << "\t" << instr->skip.count;
1140  break;
1141  case Instr::Done:
1142  qWarning().nospace() << "\t" << "Done";
1143  break;
1144  case Instr::InitString:
1145  qWarning().nospace() << "\t" << "InitString" << "\t\t" << instr->initstring.offset << "\t" << instr->initstring.dataIdx;
1146  break;
1147  case Instr::FindGeneric:
1148  qWarning().nospace() << "\t" << "FindGeneric" << "\t\t" << instr->find.reg << "\t" << instr->find.name;
1149  break;
1150  case Instr::FindGenericTerminal:
1151  qWarning().nospace() << "\t" << "FindGenericTerminal" << "\t" << instr->find.reg << "\t" << instr->find.name;
1152  break;
1153  case Instr::FindProperty:
1154  qWarning().nospace() << "\t" << "FindProperty" << "\t\t" << instr->find.reg << "\t" << instr->find.src << "\t" << instr->find.name;
1155  break;
1156  case Instr::FindPropertyTerminal:
1157  qWarning().nospace() << "\t" << "FindPropertyTerminal" << "\t" << instr->find.reg << "\t" << instr->find.src << "\t" << instr->find.name;
1158  break;
1159  case Instr::CleanupGeneric:
1160  qWarning().nospace() << "\t" << "CleanupGeneric" << "\t\t" << instr->cleanup.reg;
1161  break;
1162  case Instr::ConvertGenericToReal:
1163  qWarning().nospace() << "\t" << "ConvertGenericToReal" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src;
1164  break;
1165  case Instr::ConvertGenericToBool:
1166  qWarning().nospace() << "\t" << "ConvertGenericToBool" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src;
1167  break;
1168  case Instr::ConvertGenericToString:
1169  qWarning().nospace() << "\t" << "ConvertGenericToString" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src;
1170  break;
1171  case Instr::ConvertGenericToUrl:
1172  qWarning().nospace() << "\t" << "ConvertGenericToUrl" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src;
1173  break;
1174  default:
1175  qWarning().nospace() << "\t" << "Unknown";
1176  break;
1177  }
1178 }
Q_CORE_EXPORT void qWarning(const char *,...)

◆ Q_GLOBAL_STATIC()

Q_GLOBAL_STATIC ( QDeclarativeFastProperties  ,
fastProperties   
)

◆ throwException()

static void throwException ( int  id,
QDeclarativeDelayedError error,
Program *  program,
QDeclarativeContextData context,
const QString description = QString() 
)
static

Definition at line 1012 of file qdeclarativecompiledbindings.cpp.

Referenced by QDeclarativeCompiledBindingsPrivate::run().

1015 {
1016  error->error.setUrl(context->url);
1017  if (description.isEmpty())
1018  error->error.setDescription(QLatin1String("TypeError: Result of expression is not an object"));
1019  else
1020  error->error.setDescription(description);
1021  if (id != 0xFF) {
1022  quint64 e = *((quint64 *)(program->data() + program->exceptionDataOffset) + id);
1023  error->error.setLine((e >> 32) & 0xFFFFFFFF);
1024  error->error.setColumn(e & 0xFFFFFFFF);
1025  } else {
1026  error->error.setLine(-1);
1027  error->error.setColumn(-1);
1028  }
1029  if (!context->engine || !error->addError(QDeclarativeEnginePrivate::get(context->engine)))
1031 }
void setDescription(const QString &)
Sets the error description.
QDeclarativeEngine * engine
void setColumn(int)
Sets the error column number.
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
unsigned __int64 quint64
Definition: qglobal.h:943
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void setLine(int)
Sets the error line number.
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
void warning(const QDeclarativeError &)
bool addError(QDeclarativeEnginePrivate *)

◆ toBool()

static bool toBool ( Register *  reg,
int  type,
bool *  ok = 0 
)
inlinestatic

Definition at line 811 of file qdeclarativecompiledbindings.cpp.

Referenced by QX11Data::clipboardWaitForEvent(), QScriptEnginePrivate::convertValue(), QScriptEnginePrivate::get(), QMacPrintEngine::metric(), QNetworkAccessHttpBackend::postRequest(), QDBusDemarshaller::QDBusDemarshaller(), QDeclarativeCompiledBindingsPrivate::run(), and QVariant::swap().

812 {
813  if (ok) *ok = true;
814 
815  if (type == QMetaType::Bool) {
816  return reg->getbool();
817  } else if (type == qMetaTypeId<QVariant>()) {
818  return reg->getvariantptr()->toBool();
819  } else {
820  if (ok) *ok = false;
821  return false;
822  }
823 }
int type
Definition: qmetatype.cpp:239

◆ toReal()

static qreal toReal ( Register *  reg,
int  type,
bool *  ok = 0 
)
inlinestatic

◆ toString()

static QString toString ( Register *  reg,
int  type,
bool *  ok = 0 
)
inlinestatic

Definition at line 793 of file qdeclarativecompiledbindings.cpp.

Referenced by QDeclarativeImports::addImport(), QIcdEngine::asyncUpdateConfigurationsSlot(), QStringRef::clear(), QAxBase::connectNotify(), convert(), QScriptEnginePrivate::convertValue(), DumpIDL(), QScreen::exposeRegion(), QPatternist::AnyURI::fromLexical(), QNetworkAccessFtpBackend::ftpDone(), QScriptEnginePrivate::get(), QMainWindowLayout::insertIntoMacToolbar(), QSqlRecord::isGenerated(), QDate::isNull(), QTime::isNull(), QNetworkAccessFileBackend::loadFileInfo(), QFSFileEnginePrivate::map(), QScriptErrorLogWidget::message(), messageToScriptValue(), QSqlIndex::name(), QSettingsGroup::name(), QFSFileEnginePrivate::nativeRead(), QFSFileEnginePrivate::nativeWrite(), QDomDocument::nodeType(), QNetworkAccessCacheBackend::open(), QNetworkAccessFileBackend::open(), QUuid::operator QString(), QSqlRecord::operator!=(), QXmlStreamReaderPrivate::parse(), QEglProperties::properties(), QDBusDemarshaller::QDBusDemarshaller(), QFontEngineQPA::QFontEngineQPA(), QFontEngineQPF::QFontEngineQPF(), QNetworkSessionPrivateImpl::QNetworkSessionPrivateImpl(), QUuid::QUuid(), MetaObjectGenerator::readClassInfo(), QNetworkAccessFileBackend::readMoreFromFile(), QDeclarativeImports::resolveType(), QDeclarativeCompiledBindingsPrivate::run(), setCloseOnExec(), QSqlIndex::setDescending(), QMacPrintEnginePrivate::setPaperSize(), QDirModelPrivate::size(), QFileSystemModelPrivate::size(), QSortedModelEngine::sortOrder(), QDeclarativeVisualDataModel::stringValue(), QUrl::swap(), QVariant::swap(), QAccessibleItemRow::text(), QLocale::toString(), QFSFileEnginePrivate::unmap(), QNetworkAccessFileBackend::uploadReadyReadSlot(), QPatternist::MaintainingReader< XSLTTokenLookup >::validateElement(), and QListModelInterface::~QListModelInterface().

794 {
795  if (ok) *ok = true;
796 
797  if (type == QMetaType::QReal) {
798  return QString::number(reg->getqreal());
799  } else if (type == QMetaType::Int) {
800  return QString::number(reg->getint());
801  } else if (type == qMetaTypeId<QVariant>()) {
802  return reg->getvariantptr()->toString();
803  } else if (type == QMetaType::QString) {
804  return *reg->getstringptr();
805  } else {
806  if (ok) *ok = false;
807  return QString();
808  }
809 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
int type
Definition: qmetatype.cpp:239
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ toUrl()

static QUrl toUrl ( Register *  reg,
int  type,
QDeclarativeContextData context,
bool *  ok = 0 
)
inlinestatic

Definition at line 825 of file qdeclarativecompiledbindings.cpp.

Referenced by QUrlModel::addUrls(), QDragManager::drag(), QDeclarativeCompiledBindingsPrivate::run(), QSidebar::showContextMenu(), QVariant::swap(), and QUrlModel::urls().

826 {
827  if (ok) *ok = true;
828 
829  QUrl base;
830  if (type == qMetaTypeId<QVariant>()) {
831  QVariant *var = reg->getvariantptr();
832  int vt = var->type();
833  if (vt == QVariant::Url) {
834  base = var->toUrl();
835  } else if (vt == QVariant::ByteArray) {
836  base = QUrl(QString::fromUtf8(var->toByteArray()));
837  } else if (vt == QVariant::String) {
838  base = QUrl(var->toString());
839  } else {
840  if (ok) *ok = false;
841  return QUrl();
842  }
843  } else if (type == QMetaType::QString) {
844  base = QUrl(*reg->getstringptr());
845  } else {
846  if (ok) *ok = false;
847  return QUrl();
848  }
849 
850  if (!base.isEmpty() && base.isRelative())
851  return context->url.resolved(base);
852  else
853  return base;
854 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int type
Definition: qmetatype.cpp:239
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
static const uint base
Definition: qurl.cpp:268
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
Definition: qvariant.cpp:2528
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819

◆ variantToQObject()

static QObject* variantToQObject ( const QVariant value,
bool *  ok 
)
static

Definition at line 856 of file qdeclarativecompiledbindings.cpp.

Referenced by QDeclarativeCompiledBindingsPrivate::findgeneric(), and QDeclarativeCompiledBindingsPrivate::findproperty().

857 {
858  if (ok) *ok = true;
859 
860  if (value.userType() == QMetaType::QObjectStar) {
861  return qvariant_cast<QObject*>(value);
862  } else {
863  if (ok) *ok = false;
864  return 0;
865  }
866 }
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
Definition: qvariant.h:571