Qt 4.8
Classes | Public Functions | Public Variables | List of all members
QDeclarativeBindingCompilerPrivate Struct Reference

Classes

struct  Result
 

Public Functions

int acquireReg (int cleanup=Instr::Noop, int cleanupType=0)
 
QByteArray buildExceptionData () const
 
bool buildName (QStringList &, QDeclarativeJS::AST::Node *, QList< QDeclarativeJS::AST::ExpressionNode *> *nodes=0)
 
QByteArray buildSignalTable () const
 
int commitCompile ()
 Mark the last compile as successful, and add it to the "committed data" section. More...
 
bool compile (QDeclarativeJS::AST::Node *)
 
QString contextName () const
 
quint8 exceptionId (QDeclarativeJS::AST::ExpressionNode *)
 
bool fetch (Result &type, const QMetaObject *, int reg, int idx, const QStringList &, QDeclarativeJS::AST::ExpressionNode *)
 
bool numberArith (Result &, const Result &, const Result &, QSOperator::Op op)
 
bool parseArith (QDeclarativeJS::AST::Node *, Result &)
 
bool parseConditional (QDeclarativeJS::AST::Node *, Result &)
 
bool parseConstant (QDeclarativeJS::AST::Node *, Result &)
 
bool parseExpression (QDeclarativeJS::AST::Node *, Result &)
 
bool parseLogic (QDeclarativeJS::AST::Node *, Result &)
 
bool parseMethod (QDeclarativeJS::AST::Node *, Result &)
 
bool parseName (QDeclarativeJS::AST::Node *, Result &)
 
 QDeclarativeBindingCompilerPrivate ()
 
void registerCleanup (int reg, int cleanup, int cleanupType=0)
 
int registerLiteralString (const QString &)
 
int registerString (const QString &)
 
void releaseReg (int)
 
void resetInstanceState ()
 Clear the state associated with attempting to compile a specific binding. More...
 
bool stringArith (Result &, const Result &, const Result &, QSOperator::Op op)
 
bool subscription (const QStringList &, Result *)
 
int subscriptionIndex (const QStringList &)
 
bool subscriptionNeutral (const QSet< QString > &base, const QSet< QString > &lhs, const QSet< QString > &rhs)
 
bool tryArith (QDeclarativeJS::AST::Node *)
 
bool tryConditional (QDeclarativeJS::AST::Node *)
 
bool tryConstant (QDeclarativeJS::AST::Node *)
 
bool tryLogic (QDeclarativeJS::AST::Node *)
 
bool tryMethod (QDeclarativeJS::AST::Node *)
 
bool tryName (QDeclarativeJS::AST::Node *)
 

Public Variables

QVector< Instr > bytecode
 
struct {
   QVector< Instr >   bytecode
 
   QByteArray   data
 
   QList< QSet< int > >   dependencies
 
   QVector< quint64 >   exceptions
 
   QList< int >   offsets
 
   QHash< QString, QPair< int, int > >   registeredStrings
 
   QHash< QString, int >   subscriptionIds
 
committed
 
QDeclarativeParser::Objectcomponent
 
QDeclarativeParser::Objectcontext
 
QByteArray data
 
QDeclarativeParser::Propertydestination
 
QDeclarativeEnginePrivateengine
 
QVector< quint64exceptions
 
QHash< QString, QDeclarativeParser::Object * > ids
 
QDeclarativeImports imports
 
QHash< int, QPair< int, int > > registerCleanups
 
QHash< QString, QPair< int, int > > registeredStrings
 
quint32 registers
 
QHash< QString, int > subscriptionIds
 
QSet< QStringsubscriptionSet
 
QSet< int > usedSubscriptionIds
 

Detailed Description

Definition at line 610 of file qdeclarativecompiledbindings.cpp.

Constructors and Destructors

◆ QDeclarativeBindingCompilerPrivate()

QDeclarativeBindingCompilerPrivate::QDeclarativeBindingCompilerPrivate ( )
inline

Functions

◆ acquireReg()

int QDeclarativeBindingCompilerPrivate::acquireReg ( int  cleanup = Instr::Noop,
int  cleanupType = 0 
)

Definition at line 2702 of file qdeclarativecompiledbindings.cpp.

2703 {
2704  for (int ii = 0; ii < 32; ++ii) {
2705  if (!(registers & (1 << ii))) {
2706  registers |= (1 << ii);
2707 
2708  if (cleanup != Instr::Noop)
2709  registerCleanup(ii, cleanup, cleanupType);
2710 
2711  return ii;
2712  }
2713  }
2714  return -1;
2715 }
void registerCleanup(int reg, int cleanup, int cleanupType=0)
static void cleanup()
Definition: qpicture.cpp:1508

◆ buildExceptionData()

QByteArray QDeclarativeBindingCompilerPrivate::buildExceptionData ( ) const

Definition at line 2907 of file qdeclarativecompiledbindings.cpp.

Referenced by QDeclarativeBindingCompiler::program().

2908 {
2909  QByteArray rv;
2910  rv.resize(committed.exceptions.count() * sizeof(quint64));
2911  ::memcpy(rv.data(), committed.exceptions.constData(), rv.size());
2912  return rv;
2913 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
struct QDeclarativeBindingCompilerPrivate::@134 committed
unsigned __int64 quint64
Definition: qglobal.h:943
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ buildName()

bool QDeclarativeBindingCompilerPrivate::buildName ( QStringList name,
QDeclarativeJS::AST::Node node,
QList< QDeclarativeJS::AST::ExpressionNode *> *  nodes = 0 
)

Definition at line 2595 of file qdeclarativecompiledbindings.cpp.

2598 {
2599  if (node->kind == AST::Node::Kind_IdentifierExpression) {
2600  name << static_cast<AST::IdentifierExpression*>(node)->name->asString();
2601  if (nodes) *nodes << static_cast<AST::IdentifierExpression*>(node);
2602  } else if (node->kind == AST::Node::Kind_FieldMemberExpression) {
2604  static_cast<AST::FieldMemberExpression *>(node);
2605 
2606  if (!buildName(name, expr->base, nodes))
2607  return false;
2608 
2609  name << expr->name->asString();
2610  if (nodes) *nodes << expr;
2611  } else {
2612  return false;
2613  }
2614 
2615  return true;
2616 }
const QString asString() const
bool buildName(QStringList &, QDeclarativeJS::AST::Node *, QList< QDeclarativeJS::AST::ExpressionNode *> *nodes=0)

◆ buildSignalTable()

QByteArray QDeclarativeBindingCompilerPrivate::buildSignalTable ( ) const

Definition at line 2883 of file qdeclarativecompiledbindings.cpp.

Referenced by QDeclarativeBindingCompiler::program().

2884 {
2885  QHash<int, QList<int> > table;
2886 
2887  for (int ii = 0; ii < committed.count(); ++ii) {
2888  const QSet<int> &deps = committed.dependencies.at(ii);
2889  for (QSet<int>::ConstIterator iter = deps.begin(); iter != deps.end(); ++iter)
2890  table[*iter].append(ii);
2891  }
2892 
2893  QVector<quint32> header;
2895  for (int ii = 0; ii < committed.subscriptionIds.count(); ++ii) {
2896  header.append(committed.subscriptionIds.count() + data.count());
2897  const QList<int> &bindings = table[ii];
2898  data.append(bindings.count());
2899  for (int jj = 0; jj < bindings.count(); ++jj)
2900  data.append(bindings.at(jj));
2901  }
2902  header << data;
2903 
2904  return QByteArray((const char *)header.constData(), header.count() * sizeof(quint32));
2905 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
iterator begin()
Definition: qset.h:166
struct QDeclarativeBindingCompilerPrivate::@134 committed
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
iterator end()
Definition: qset.h:169
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
unsigned int quint32
Definition: qglobal.h:938
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154

◆ commitCompile()

int QDeclarativeBindingCompilerPrivate::commitCompile ( )

Mark the last compile as successful, and add it to the "committed data" section.

Returns the index for the committed binding.

Definition at line 1737 of file qdeclarativecompiledbindings.cpp.

Referenced by QDeclarativeBindingCompiler::compile().

1738 {
1739  int rv = committed.count();
1740  committed.offsets << committed.bytecode.count();
1741  committed.dependencies << usedSubscriptionIds;
1742  committed.bytecode << bytecode;
1743  committed.data = data;
1744  committed.exceptions = exceptions;
1745  committed.subscriptionIds = subscriptionIds;
1746  committed.registeredStrings = registeredStrings;
1747  return rv;
1748 }
struct QDeclarativeBindingCompilerPrivate::@134 committed
QHash< QString, QPair< int, int > > registeredStrings

◆ compile()

bool QDeclarativeBindingCompilerPrivate::compile ( QDeclarativeJS::AST::Node node)

Definition at line 1750 of file qdeclarativecompiledbindings.cpp.

Referenced by QDeclarativeBindingCompiler::compile().

1751 {
1753 
1754  if (destination->type == -1)
1755  return false;
1756 
1757  if (bindingsDump()) {
1759  if (n) {
1760  Instr id;
1761  id.common.type = Instr::BindingId;
1762  id.id.column = n->firstSourceLocation().startColumn;
1763  id.id.line = n->firstSourceLocation().startLine;
1764  bytecode << id;
1765  }
1766  }
1767 
1768  Result type;
1769 
1770  if (!parseExpression(node, type))
1771  return false;
1772 
1773  if (subscriptionSet.count() > 0xFFFF ||
1774  registeredStrings.count() > 0xFFFF)
1775  return false;
1776 
1777  if (type.unknownType) {
1778  if (!qmlExperimental())
1779  return false;
1780 
1781  if (destination->type != QMetaType::QReal &&
1785  return false;
1786 
1787  int convertReg = acquireReg();
1788  if (convertReg == -1)
1789  return false;
1790 
1791  if (destination->type == QMetaType::QReal) {
1792  Instr convert;
1793  convert.common.type = Instr::ConvertGenericToReal;
1794  convert.unaryop.output = convertReg;
1795  convert.unaryop.src = type.reg;
1796  bytecode << convert;
1797  } else if (destination->type == QVariant::String) {
1798  Instr convert;
1799  convert.common.type = Instr::ConvertGenericToString;
1800  convert.unaryop.output = convertReg;
1801  convert.unaryop.src = type.reg;
1802  bytecode << convert;
1803  } else if (destination->type == QMetaType::Bool) {
1804  Instr convert;
1805  convert.common.type = Instr::ConvertGenericToBool;
1806  convert.unaryop.output = convertReg;
1807  convert.unaryop.src = type.reg;
1808  bytecode << convert;
1809  } else if (destination->type == QVariant::Url) {
1810  Instr convert;
1811  convert.common.type = Instr::ConvertGenericToUrl;
1812  convert.unaryop.output = convertReg;
1813  convert.unaryop.src = type.reg;
1814  bytecode << convert;
1815  }
1816 
1817  Instr cleanup;
1818  cleanup.common.type = Instr::CleanupGeneric;
1819  cleanup.cleanup.reg = type.reg;
1820  bytecode << cleanup;
1821 
1822  Instr instr;
1823  instr.common.type = Instr::Store;
1824  instr.store.output = 0;
1825  instr.store.index = destination->index;
1826  instr.store.reg = convertReg;
1827  instr.store.exceptionId = exceptionId(node->expressionCast());
1828  bytecode << instr;
1829 
1830  if (destination->type == QVariant::String) {
1831  Instr cleanup;
1832  cleanup.common.type = Instr::CleanupString;
1833  cleanup.cleanup.reg = convertReg;
1834  bytecode << cleanup;
1835  } else if (destination->type == QVariant::Url) {
1836  Instr cleanup;
1837  cleanup.common.type = Instr::CleanupUrl;
1838  cleanup.cleanup.reg = convertReg;
1839  bytecode << cleanup;
1840  }
1841 
1842  releaseReg(convertReg);
1843 
1844  Instr done;
1845  done.common.type = Instr::Done;
1846  bytecode << done;
1847 
1848  } else {
1849  // Can we store the final value?
1850  if (type.type == QVariant::Int &&
1852  Instr instr;
1853  instr.common.type = Instr::ConvertIntToReal;
1854  instr.unaryop.output = type.reg;
1855  instr.unaryop.src = type.reg;
1856  bytecode << instr;
1857  type.type = QMetaType::QReal;
1858  } else if (type.type == QMetaType::QReal &&
1860  Instr instr;
1861  instr.common.type = Instr::ConvertRealToInt;
1862  instr.unaryop.output = type.reg;
1863  instr.unaryop.src = type.reg;
1864  bytecode << instr;
1865  type.type = QVariant::Int;
1866  } else if (type.type == destination->type) {
1867  } else {
1868  const QMetaObject *from = type.metaObject;
1870 
1872  type.type = destination->type;
1873  }
1874 
1875  if (type.type == destination->type) {
1876  Instr instr;
1877  instr.common.type = Instr::Store;
1878  instr.store.output = 0;
1879  instr.store.index = destination->index;
1880  instr.store.reg = type.reg;
1881  instr.store.exceptionId = exceptionId(node->expressionCast());
1882  bytecode << instr;
1883 
1884  releaseReg(type.reg);
1885 
1886  Instr done;
1887  done.common.type = Instr::Done;
1888  bytecode << done;
1889  } else {
1890  return false;
1891  }
1892  }
1893 
1894  return true;
1895 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
int type
Definition: qmetatype.cpp:239
virtual SourceLocation firstSourceLocation() const =0
bool parseExpression(QDeclarativeJS::AST::Node *, Result &)
int acquireReg(int cleanup=Instr::Noop, int cleanupType=0)
QHash< QString, QPair< int, int > > registeredStrings
int count() const
Definition: qset.h:178
void resetInstanceState()
Clear the state associated with attempting to compile a specific binding.
static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, bool *ok)
Definition: qvariant.cpp:627
virtual ExpressionNode * expressionCast()
static void cleanup()
Definition: qpicture.cpp:1508
static bool canConvert(const QMetaObject *from, const QMetaObject *to)
Returns true if from inherits to.
int count(const Key &key) const
Returns the number of items associated with the key.
Definition: qhash.h:719
quint8 exceptionId(QDeclarativeJS::AST::ExpressionNode *)
const QMetaObject * rawMetaObjectForType(int) const

◆ contextName()

QString QDeclarativeBindingCompilerPrivate::contextName ( ) const
inline

Definition at line 643 of file qdeclarativecompiledbindings.cpp.

643 { return QLatin1String("$$$SCOPE_") + QString::number((quintptr)context, 16); }
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
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ exceptionId()

quint8 QDeclarativeBindingCompilerPrivate::exceptionId ( QDeclarativeJS::AST::ExpressionNode n)

Definition at line 2823 of file qdeclarativecompiledbindings.cpp.

2824 {
2825  quint8 rv = 0xFF;
2826  if (n && exceptions.count() < 0xFF) {
2827  rv = (quint8)exceptions.count();
2829  quint64 e = l.startLine;
2830  e <<= 32;
2831  e |= l.startColumn;
2832  exceptions.append(e);
2833  }
2834  return rv;
2835 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
virtual SourceLocation firstSourceLocation() const =0
unsigned char quint8
Definition: qglobal.h:934
unsigned __int64 quint64
Definition: qglobal.h:943
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QFactoryLoader * l

◆ fetch()

bool QDeclarativeBindingCompilerPrivate::fetch ( Result type,
const QMetaObject mo,
int  reg,
int  idx,
const QStringList subName,
QDeclarativeJS::AST::ExpressionNode node 
)

Definition at line 2618 of file qdeclarativecompiledbindings.cpp.

2621 {
2622  QMetaProperty prop = mo->property(idx);
2623  rv.metaObject = 0;
2624  rv.type = 0;
2625 
2626  //XXX binding optimizer doesn't handle properties with a revision
2627  if (prop.revision() > 0)
2628  return false;
2629 
2630  int fastFetchIndex = fastProperties()->accessorIndexForProperty(mo, idx);
2631 
2632  Instr fetch;
2633 
2634  if (!qmlDisableFastProperties() && fastFetchIndex != -1) {
2635  fetch.common.type = Instr::FetchAndSubscribe;
2636  fetch.fetchAndSubscribe.objectReg = reg;
2637  fetch.fetchAndSubscribe.output = reg;
2638  fetch.fetchAndSubscribe.function = fastFetchIndex;
2639  fetch.fetchAndSubscribe.subscription = subscriptionIndex(subName);
2640  fetch.fetchAndSubscribe.exceptionId = exceptionId(node);
2641  } else {
2642  if (subscription(subName, &rv) && prop.hasNotifySignal() && prop.notifySignalIndex() != -1) {
2643  Instr sub;
2644  sub.common.type = Instr::Subscribe;
2645  sub.subscribe.offset = subscriptionIndex(subName);
2646  sub.subscribe.reg = reg;
2647  sub.subscribe.index = prop.notifySignalIndex();
2648  bytecode << sub;
2649  }
2650 
2651  fetch.common.type = Instr::Fetch;
2652  fetch.fetch.objectReg = reg;
2653  fetch.fetch.index = idx;
2654  fetch.fetch.output = reg;
2655  fetch.fetch.exceptionId = exceptionId(node);
2656  }
2657 
2658  rv.type = prop.userType();
2659  rv.metaObject = engine->metaObjectForType(rv.type);
2660  rv.reg = reg;
2661 
2662  if (rv.type == QMetaType::QString) {
2663  int tmp = acquireReg();
2664  if (tmp == -1)
2665  return false;
2666  Instr copy;
2667  copy.common.type = Instr::Copy;
2668  copy.copy.reg = tmp;
2669  copy.copy.src = reg;
2670  bytecode << copy;
2671  releaseReg(tmp);
2672  fetch.fetch.objectReg = tmp;
2673 
2674  Instr setup;
2675  setup.common.type = Instr::NewString;
2676  setup.construct.reg = reg;
2677  bytecode << setup;
2678  registerCleanup(reg, Instr::CleanupString);
2679  }
2680 
2681  bytecode << fetch;
2682 
2683  if (!rv.metaObject &&
2684  rv.type != QMetaType::QReal &&
2685  rv.type != QMetaType::Int &&
2686  rv.type != QMetaType::Bool &&
2687  rv.type != qMetaTypeId<QDeclarativeAnchorLine>() &&
2688  rv.type != QMetaType::QString) {
2689  rv.metaObject = 0;
2690  rv.type = 0;
2691  return false; // Unsupported type (string not supported yet);
2692  }
2693 
2694  return true;
2695 }
int notifySignalIndex() const
Returns the index of the property change notifying signal if one was specified, otherwise returns -1...
bool fetch(Result &type, const QMetaObject *, int reg, int idx, const QStringList &, QDeclarativeJS::AST::ExpressionNode *)
void registerCleanup(int reg, int cleanup, int cleanupType=0)
int acquireReg(int cleanup=Instr::Noop, int cleanupType=0)
int userType() const
Returns this property&#39;s user type.
const QMetaObject * metaObjectForType(int) const
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
quint8 exceptionId(QDeclarativeJS::AST::ExpressionNode *)
int revision() const
Returns the property revision if one was specified by REVISION, otherwise returns 0...
bool hasNotifySignal() const
Returns true if this property has a corresponding change notify signal; otherwise returns false...
bool subscription(const QStringList &, Result *)
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
static void setup()
Definition: qtextcodec.cpp:718
QVariant::Type type() const
Returns this property&#39;s type.

◆ numberArith()

bool QDeclarativeBindingCompilerPrivate::numberArith ( Result type,
const Result lhs,
const Result rhs,
QSOperator::Op  op 
)

Definition at line 2198 of file qdeclarativecompiledbindings.cpp.

2199 {
2200  bool nativeReal = rhs.type == QMetaType::QReal ||
2201  lhs.type == QMetaType::QReal ||
2202  lhs.unknownType ||
2203  rhs.unknownType;
2204 
2205  if (nativeReal && lhs.type == QMetaType::Int) {
2206  Instr convert;
2207  convert.common.type = Instr::ConvertIntToReal;
2208  convert.unaryop.output = lhs.reg;
2209  convert.unaryop.src = lhs.reg;
2210  bytecode << convert;
2211  }
2212 
2213  if (nativeReal && rhs.type == QMetaType::Int) {
2214  Instr convert;
2215  convert.common.type = Instr::ConvertIntToReal;
2216  convert.unaryop.output = rhs.reg;
2217  convert.unaryop.src = rhs.reg;
2218  bytecode << convert;
2219  }
2220 
2221  int lhsTmp = -1;
2222  int rhsTmp = -1;
2223 
2224  if (lhs.unknownType) {
2225  if (!qmlExperimental())
2226  return false;
2227 
2228  lhsTmp = acquireReg();
2229  if (lhsTmp == -1)
2230  return false;
2231 
2232  Instr conv;
2233  conv.common.type = Instr::ConvertGenericToReal;
2234  conv.unaryop.output = lhsTmp;
2235  conv.unaryop.src = lhs.reg;
2236  bytecode << conv;
2237  }
2238 
2239  if (rhs.unknownType) {
2240  if (!qmlExperimental())
2241  return false;
2242 
2243  rhsTmp = acquireReg();
2244  if (rhsTmp == -1)
2245  return false;
2246 
2247  Instr conv;
2248  conv.common.type = Instr::ConvertGenericToReal;
2249  conv.unaryop.output = rhsTmp;
2250  conv.unaryop.src = rhs.reg;
2251  bytecode << conv;
2252  }
2253 
2254  Instr arith;
2255  if (op == QSOperator::Add) {
2256  arith.common.type = nativeReal?Instr::AddReal:Instr::AddInt;
2257  } else if (op == QSOperator::Sub) {
2258  arith.common.type = nativeReal?Instr::MinusReal:Instr::MinusInt;
2259  } else {
2260  qFatal("Unsupported arithmetic operator");
2261  }
2262 
2263  arith.binaryop.output = type.reg;
2264  arith.binaryop.src1 = (lhsTmp == -1)?lhs.reg:lhsTmp;
2265  arith.binaryop.src2 = (rhsTmp == -1)?rhs.reg:rhsTmp;
2266  bytecode << arith;
2267 
2268  type.metaObject = 0;
2269  type.type = nativeReal?QMetaType::QReal:QMetaType::Int;
2270  type.subscriptionSet.unite(lhs.subscriptionSet);
2271  type.subscriptionSet.unite(rhs.subscriptionSet);
2272 
2273  if (lhsTmp != -1) releaseReg(lhsTmp);
2274  if (rhsTmp != -1) releaseReg(rhsTmp);
2275  releaseReg(lhs.reg);
2276  releaseReg(rhs.reg);
2277 
2278  return true;
2279 }
int type
Definition: qmetatype.cpp:239
int acquireReg(int cleanup=Instr::Noop, int cleanupType=0)
static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, bool *ok)
Definition: qvariant.cpp:627
Q_CORE_EXPORT void qFatal(const char *,...)

◆ parseArith()

bool QDeclarativeBindingCompilerPrivate::parseArith ( QDeclarativeJS::AST::Node node,
Result type 
)

Definition at line 2171 of file qdeclarativecompiledbindings.cpp.

2172 {
2173  AST::BinaryExpression *expression = static_cast<AST::BinaryExpression *>(node);
2174 
2175  type.reg = acquireReg();
2176  if (type.reg == -1)
2177  return false;
2178 
2179  Result lhs;
2180  Result rhs;
2181 
2182  if (!parseExpression(expression->left, lhs)) return false;
2183  if (!parseExpression(expression->right, rhs)) return false;
2184 
2185  if ((lhs.type == QVariant::Int || lhs.type == QMetaType::QReal) &&
2186  (rhs.type == QVariant::Int || rhs.type == QMetaType::QReal))
2187  return numberArith(type, lhs, rhs, (QSOperator::Op)expression->op);
2188  else if(expression->op == QSOperator::Sub)
2189  return numberArith(type, lhs, rhs, (QSOperator::Op)expression->op);
2190  else if ((lhs.type == QMetaType::QString || lhs.unknownType) &&
2191  (rhs.type == QMetaType::QString || rhs.unknownType) &&
2192  (lhs.type == QMetaType::QString || rhs.type == QMetaType::QString))
2193  return stringArith(type, lhs, rhs, (QSOperator::Op)expression->op);
2194  else
2195  return false;
2196 }
int type
Definition: qmetatype.cpp:239
bool parseExpression(QDeclarativeJS::AST::Node *, Result &)
int acquireReg(int cleanup=Instr::Noop, int cleanupType=0)
bool stringArith(Result &, const Result &, const Result &, QSOperator::Op op)
bool numberArith(Result &, const Result &, const Result &, QSOperator::Op op)

◆ parseConditional()

bool QDeclarativeBindingCompilerPrivate::parseConditional ( QDeclarativeJS::AST::Node node,
Result type 
)

Definition at line 2417 of file qdeclarativecompiledbindings.cpp.

2418 {
2419  AST::ConditionalExpression *expression = static_cast<AST::ConditionalExpression *>(node);
2420 
2421  AST::Node *test = expression->expression;
2422  if (test->kind == AST::Node::Kind_NestedExpression)
2423  test = static_cast<AST::NestedExpression*>(test)->expression;
2424 
2425  Result etype;
2426  if (!parseExpression(test, etype)) return false;
2427 
2428  if (etype.type != QVariant::Bool)
2429  return false;
2430 
2431  Instr skip;
2432  skip.common.type = Instr::Skip;
2433  skip.skip.reg = etype.reg;
2434  skip.skip.count = 0;
2435  int skipIdx = bytecode.count();
2436  bytecode << skip;
2437 
2438  // Release to allow reuse of reg
2439  releaseReg(etype.reg);
2440 
2441  QSet<QString> preSubSet = subscriptionSet;
2442 
2443  // int preConditionalSubscriptions = subscriptionSet.count();
2444 
2445  Result ok;
2446  if (!parseExpression(expression->ok, ok)) return false;
2447  if (ok.unknownType) return false;
2448 
2449  int skipIdx2 = bytecode.count();
2450  skip.skip.reg = -1;
2451  bytecode << skip;
2452 
2453  // Release to allow reuse of reg in else path
2454  releaseReg(ok.reg);
2455  bytecode[skipIdx].skip.count = bytecode.count() - skipIdx - 1;
2456 
2457  subscriptionSet = preSubSet;
2458 
2459  Result ko;
2460  if (!parseExpression(expression->ko, ko)) return false;
2461  if (ko.unknownType) return false;
2462 
2463  // Do not release reg here, so that its ownership passes to the caller
2464  bytecode[skipIdx2].skip.count = bytecode.count() - skipIdx2 - 1;
2465 
2466  if (ok != ko)
2467  return false; // Must be same type and in same register
2468 
2469  subscriptionSet = preSubSet;
2470 
2471  if (!subscriptionNeutral(subscriptionSet, ok.subscriptionSet, ko.subscriptionSet))
2472  return false; // Conditionals cannot introduce new subscriptions
2473 
2474  type = ok;
2475 
2476  return true;
2477 }
int type
Definition: qmetatype.cpp:239
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool parseExpression(QDeclarativeJS::AST::Node *, Result &)
bool subscriptionNeutral(const QSet< QString > &base, const QSet< QString > &lhs, const QSet< QString > &rhs)

◆ parseConstant()

bool QDeclarativeBindingCompilerPrivate::parseConstant ( QDeclarativeJS::AST::Node node,
Result type 
)

Definition at line 2487 of file qdeclarativecompiledbindings.cpp.

2488 {
2489  type.metaObject = 0;
2490  type.type = -1;
2491  type.reg = acquireReg();
2492  if (type.reg == -1)
2493  return false;
2494 
2495  if (node->kind == AST::Node::Kind_TrueLiteral) {
2496  type.type = QVariant::Bool;
2497  Instr instr;
2498  instr.common.type = Instr::Bool;
2499  instr.bool_value.reg = type.reg;
2500  instr.bool_value.value = true;
2501  bytecode << instr;
2502  return true;
2503  } else if (node->kind == AST::Node::Kind_FalseLiteral) {
2504  type.type = QVariant::Bool;
2505  Instr instr;
2506  instr.common.type = Instr::Bool;
2507  instr.bool_value.reg = type.reg;
2508  instr.bool_value.value = false;
2509  bytecode << instr;
2510  return true;
2511  } else if (node->kind == AST::Node::Kind_NumericLiteral) {
2512  qreal value = qreal(static_cast<AST::NumericLiteral *>(node)->value);
2513 
2514  if (qreal(float(value)) != value)
2515  return false;
2516 
2517  type.type = QMetaType::QReal;
2518  Instr instr;
2519  instr.common.type = Instr::Real;
2520  instr.real_value.reg = type.reg;
2521  instr.real_value.value = float(value);
2522  bytecode << instr;
2523  return true;
2524  } else if (node->kind == AST::Node::Kind_StringLiteral) {
2525  QString str = static_cast<AST::StringLiteral *>(node)->value->asString();
2526  type.type = QMetaType::QString;
2527  type.reg = registerLiteralString(str);
2528  return true;
2529  } else {
2530  return false;
2531  }
2532 }
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
The QString class provides a Unicode character string.
Definition: qstring.h:83
int acquireReg(int cleanup=Instr::Noop, int cleanupType=0)

◆ parseExpression()

bool QDeclarativeBindingCompilerPrivate::parseExpression ( QDeclarativeJS::AST::Node node,
Result type 
)

Definition at line 1897 of file qdeclarativecompiledbindings.cpp.

1898 {
1899  while (node->kind == AST::Node::Kind_NestedExpression)
1900  node = static_cast<AST::NestedExpression *>(node)->expression;
1901 
1902  if (tryArith(node)) {
1903  if (!parseArith(node, type)) return false;
1904  } else if (tryLogic(node)) {
1905  if (!parseLogic(node, type)) return false;
1906  } else if (tryConditional(node)) {
1907  if (!parseConditional(node, type)) return false;
1908  } else if (tryName(node)) {
1909  if (!parseName(node, type)) return false;
1910  } else if (tryConstant(node)) {
1911  if (!parseConstant(node, type)) return false;
1912  } else if (tryMethod(node)) {
1913  if (!parseMethod(node, type)) return false;
1914  } else {
1915  return false;
1916  }
1917  return true;
1918 }
int type
Definition: qmetatype.cpp:239
bool tryConditional(QDeclarativeJS::AST::Node *)
bool tryMethod(QDeclarativeJS::AST::Node *)
bool parseLogic(QDeclarativeJS::AST::Node *, Result &)
bool parseMethod(QDeclarativeJS::AST::Node *, Result &)
bool tryArith(QDeclarativeJS::AST::Node *)
bool parseName(QDeclarativeJS::AST::Node *, Result &)
bool parseConstant(QDeclarativeJS::AST::Node *, Result &)
bool tryLogic(QDeclarativeJS::AST::Node *)
bool parseArith(QDeclarativeJS::AST::Node *, Result &)
bool parseConditional(QDeclarativeJS::AST::Node *, Result &)
bool tryConstant(QDeclarativeJS::AST::Node *)

◆ parseLogic()

bool QDeclarativeBindingCompilerPrivate::parseLogic ( QDeclarativeJS::AST::Node node,
Result type 
)

Definition at line 2354 of file qdeclarativecompiledbindings.cpp.

2355 {
2356  AST::BinaryExpression *expression = static_cast<AST::BinaryExpression *>(node);
2357 
2358  Result lhs;
2359  Result rhs;
2360 
2361  if (!parseExpression(expression->left, lhs)) return false;
2362  if (!parseExpression(expression->right, rhs)) return false;
2363 
2364  type.reg = acquireReg();
2365  if (type.reg == -1)
2366  return false;
2367 
2368  type.metaObject = 0;
2369  type.type = QVariant::Bool;
2370 
2371  if (lhs.type == QMetaType::QReal && rhs.type == QMetaType::QReal) {
2372 
2373  Instr op;
2374  if (expression->op == QSOperator::Gt)
2375  op.common.type = Instr::GreaterThanReal;
2376  else if (expression->op == QSOperator::Equal)
2377  op.common.type = Instr::CompareReal;
2378  else if (expression->op == QSOperator::NotEqual)
2379  op.common.type = Instr::NotCompareReal;
2380  else
2381  return false;
2382  op.binaryop.output = type.reg;
2383  op.binaryop.src1 = lhs.reg;
2384  op.binaryop.src2 = rhs.reg;
2385  bytecode << op;
2386 
2387 
2388  } else if (lhs.type == QMetaType::QString && rhs.type == QMetaType::QString) {
2389 
2390  Instr op;
2391  if (expression->op == QSOperator::Equal)
2392  op.common.type = Instr::CompareString;
2393  else if (expression->op == QSOperator::NotEqual)
2394  op.common.type = Instr::NotCompareString;
2395  else
2396  return false;
2397  op.binaryop.output = type.reg;
2398  op.binaryop.src1 = lhs.reg;
2399  op.binaryop.src2 = rhs.reg;
2400  bytecode << op;
2401 
2402  } else {
2403  return false;
2404  }
2405 
2406  releaseReg(lhs.reg);
2407  releaseReg(rhs.reg);
2408 
2409  return true;
2410 }
int type
Definition: qmetatype.cpp:239
bool parseExpression(QDeclarativeJS::AST::Node *, Result &)
int acquireReg(int cleanup=Instr::Noop, int cleanupType=0)

◆ parseMethod()

bool QDeclarativeBindingCompilerPrivate::parseMethod ( QDeclarativeJS::AST::Node node,
Result result 
)

Definition at line 2539 of file qdeclarativecompiledbindings.cpp.

2540 {
2541  AST::CallExpression *expr = static_cast<AST::CallExpression *>(node);
2542 
2543  QStringList name;
2544  if (!buildName(name, expr->base))
2545  return false;
2546 
2547  if (name.count() != 2 || name.at(0) != QLatin1String("Math"))
2548  return false;
2549 
2550  QString method = name.at(1);
2551 
2552  AST::ArgumentList *args = expr->arguments;
2553  if (!args) return false;
2554  AST::ExpressionNode *arg0 = args->expression;
2555  args = args->next;
2556  if (!args) return false;
2557  AST::ExpressionNode *arg1 = args->expression;
2558  if (args->next != 0) return false;
2559  if (!arg0 || !arg1) return false;
2560 
2561  Result r0;
2562  if (!parseExpression(arg0, r0)) return false;
2563  Result r1;
2564  if (!parseExpression(arg1, r1)) return false;
2565 
2566  if (r0.type != QMetaType::QReal || r1.type != QMetaType::QReal)
2567  return false;
2568 
2569  Instr op;
2570  if (method == QLatin1String("max")) {
2571  op.common.type = Instr::MaxReal;
2572  } else if (method == QLatin1String("min")) {
2573  op.common.type = Instr::MinReal;
2574  } else {
2575  return false;
2576  }
2577  // We release early to reuse registers
2578  releaseReg(r0.reg);
2579  releaseReg(r1.reg);
2580 
2581  op.binaryop.output = acquireReg();
2582  if (op.binaryop.output == -1)
2583  return false;
2584 
2585  op.binaryop.src1 = r0.reg;
2586  op.binaryop.src2 = r1.reg;
2587  bytecode << op;
2588 
2589  result.type = QMetaType::QReal;
2590  result.reg = op.binaryop.output;
2591 
2592  return true;
2593 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool parseExpression(QDeclarativeJS::AST::Node *, Result &)
bool buildName(QStringList &, QDeclarativeJS::AST::Node *, QList< QDeclarativeJS::AST::ExpressionNode *> *nodes=0)
The QString class provides a Unicode character string.
Definition: qstring.h:83
int acquireReg(int cleanup=Instr::Noop, int cleanupType=0)
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66

◆ parseName()

bool QDeclarativeBindingCompilerPrivate::parseName ( QDeclarativeJS::AST::Node node,
Result type 
)

Definition at line 1926 of file qdeclarativecompiledbindings.cpp.

1927 {
1928  QStringList nameParts;
1929  QList<AST::ExpressionNode *> nameNodes;
1930  if (!buildName(nameParts, node, &nameNodes))
1931  return false;
1932 
1933  int reg = acquireReg();
1934  if (reg == -1)
1935  return false;
1936  type.reg = reg;
1937 
1938  QDeclarativeParser::Object *absType = 0;
1939 
1940  QStringList subscribeName;
1941 
1942  bool wasAttachedObject = false;
1943 
1944  for (int ii = 0; ii < nameParts.count(); ++ii) {
1945  const QString &name = nameParts.at(ii);
1946 
1947  // We don't handle signal properties or attached properties
1948  if (name.length() > 2 && name.startsWith(QLatin1String("on")) &&
1949  name.at(2).isUpper())
1950  return false;
1951 
1952  QDeclarativeType *attachType = 0;
1953  if (name.at(0).isUpper()) {
1954  // Could be an attached property
1955  if (ii == nameParts.count() - 1)
1956  return false;
1957  if (nameParts.at(ii + 1).at(0).isUpper())
1958  return false;
1959 
1961  if (!imports.resolveType(name.toUtf8(), &attachType, 0, 0, 0, &ns))
1962  return false;
1963  if (ns || !attachType || !attachType->attachedPropertiesType())
1964  return false;
1965 
1966  wasAttachedObject = true;
1967  }
1968 
1969  if (ii == 0) {
1970 
1971  if (attachType) {
1972  Instr instr;
1973  instr.common.type = Instr::LoadScope;
1974  instr.load.index = 0;
1975  instr.load.reg = reg;
1976  bytecode << instr;
1977 
1978  Instr attach;
1979  attach.common.type = Instr::LoadAttached;
1980  attach.attached.output = reg;
1981  attach.attached.reg = reg;
1982  attach.attached.id = attachType->attachedPropertiesId();
1983  attach.attached.exceptionId = exceptionId(nameNodes.at(ii));
1984  bytecode << attach;
1985 
1986  subscribeName << contextName();
1987  subscribeName << QLatin1String("$$$ATTACH_") + name;
1988 
1989  absType = 0;
1990  type.metaObject = attachType->attachedPropertiesType();
1991 
1992  continue;
1993  } else if (ids.contains(name)) {
1994  QDeclarativeParser::Object *idObject = ids.value(name);
1995  absType = idObject;
1996  type.metaObject = absType->metaObject();
1997 
1998  // We check if the id object is the root or
1999  // scope object to avoid a subscription
2000  if (idObject == component) {
2001  Instr instr;
2002  instr.common.type = Instr::LoadRoot;
2003  instr.load.index = 0;
2004  instr.load.reg = reg;
2005  bytecode << instr;
2006  } else if (idObject == context) {
2007  Instr instr;
2008  instr.common.type = Instr::LoadScope;
2009  instr.load.index = 0;
2010  instr.load.reg = reg;
2011  bytecode << instr;
2012  } else {
2013  Instr instr;
2014  instr.common.type = Instr::LoadId;
2015  instr.load.index = idObject->idIndex;
2016  instr.load.reg = reg;
2017  bytecode << instr;
2018 
2019  subscribeName << QLatin1String("$$$ID_") + name;
2020 
2021  if (subscription(subscribeName, &type)) {
2022  Instr sub;
2023  sub.common.type = Instr::SubscribeId;
2024  sub.subscribe.offset = subscriptionIndex(subscribeName);
2025  sub.subscribe.reg = reg;
2026  sub.subscribe.index = instr.load.index;
2027  bytecode << sub;
2028  }
2029  }
2030 
2031  } else {
2032 
2033  QByteArray utf8Name = name.toUtf8();
2034  const char *cname = utf8Name.constData();
2035 
2036  int d0Idx = (context == component)?-1:context->metaObject()->indexOfProperty(cname);
2037  int d1Idx = -1;
2038  if (d0Idx == -1)
2039  d1Idx = component->metaObject()->indexOfProperty(cname);
2040 
2041  if (d0Idx != -1) {
2042  Instr instr;
2043  instr.common.type = Instr::LoadScope;
2044  instr.load.index = 0;
2045  instr.load.reg = reg;
2046  bytecode << instr;
2047 
2048  subscribeName << contextName();
2049  subscribeName << name;
2050 
2051  if (!fetch(type, context->metaObject(), reg, d0Idx, subscribeName, nameNodes.at(ii)))
2052  return false;
2053  } else if(d1Idx != -1) {
2054  Instr instr;
2055  instr.common.type = Instr::LoadRoot;
2056  instr.load.index = 0;
2057  instr.load.reg = reg;
2058  bytecode << instr;
2059 
2060  subscribeName << QLatin1String("$$$ROOT");
2061  subscribeName << name;
2062 
2063  if (!fetch(type, component->metaObject(), reg, d1Idx, subscribeName, nameNodes.at(ii)))
2064  return false;
2065  } else if (qmlExperimental()) {
2066  Instr find;
2067  if (nameParts.count() == 1)
2068  find.common.type = Instr::FindGenericTerminal;
2069  else
2070  find.common.type = Instr::FindGeneric;
2071 
2072  find.find.reg = reg;
2073  find.find.src = -1;
2074  find.find.name = registerString(name);
2075  find.find.exceptionId = exceptionId(nameNodes.at(ii));
2076 
2077  subscribeName << QString(QLatin1String("$$$Generic_") + name);
2078  if (subscription(subscribeName, &type))
2079  find.find.subscribeIndex = subscriptionIndex(subscribeName);
2080  else
2081  find.find.subscribeIndex = -1;
2082 
2083  bytecode << find;
2084  type.unknownType = true;
2085  }
2086 
2087  if (!type.unknownType && type.type == -1)
2088  return false; // Couldn't fetch that type
2089  }
2090 
2091  } else {
2092 
2093  if (attachType) {
2094  Instr attach;
2095  attach.common.type = Instr::LoadAttached;
2096  attach.attached.output = reg;
2097  attach.attached.reg = reg;
2098  attach.attached.id = attachType->attachedPropertiesId();
2099  bytecode << attach;
2100 
2101  absType = 0;
2102  type.metaObject = attachType->attachedPropertiesType();
2103 
2104  subscribeName << QLatin1String("$$$ATTACH_") + name;
2105  continue;
2106  }
2107 
2108  const QMetaObject *mo = 0;
2109  if (absType)
2110  mo = absType->metaObject();
2111  else if (type.metaObject)
2112  mo = type.metaObject;
2113 
2114  QByteArray utf8Name = name.toUtf8();
2115  const char *cname = utf8Name.constData();
2116  int idx = mo?mo->indexOfProperty(cname):-1;
2117  if (absType && idx == -1)
2118  return false;
2119 
2120  subscribeName << name;
2121 
2122  if (absType || (wasAttachedObject && idx != -1) || (mo && mo->property(idx).isFinal())) {
2123  absType = 0;
2124  if (!fetch(type, mo, reg, idx, subscribeName, nameNodes.at(ii)))
2125  return false;
2126  } else {
2127 
2128  Instr prop;
2129  if (ii == nameParts.count() -1 )
2130  prop.common.type = Instr::FindPropertyTerminal;
2131  else
2132  prop.common.type = Instr::FindProperty;
2133 
2134  prop.find.reg = reg;
2135  prop.find.src = reg;
2136  prop.find.name = registerString(name);
2137  prop.find.exceptionId = exceptionId(nameNodes.at(ii));
2138 
2139  if (subscription(subscribeName, &type))
2140  prop.find.subscribeIndex = subscriptionIndex(subscribeName);
2141  else
2142  prop.find.subscribeIndex = -1;
2143 
2144  type.unknownType = true;
2145  type.metaObject = 0;
2146  type.type = -1;
2147  type.reg = reg;
2148  bytecode << prop;
2149  }
2150  }
2151 
2152  wasAttachedObject = false;
2153  }
2154 
2155  return true;
2156 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
bool isFinal() const
int type
Definition: qmetatype.cpp:239
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
bool fetch(Result &type, const QMetaObject *, int reg, int idx, const QStringList &, QDeclarativeJS::AST::ExpressionNode *)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
const QMetaObject * metaObject() const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool resolveType(const QByteArray &type, QDeclarativeType **type_return, QUrl *url_return, int *version_major, int *version_minor, QDeclarativeImportedNamespace **ns_return, QString *errorString=0) const
The given (namespace qualified) type is resolved to either.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int attachedPropertiesId() const
bool buildName(QStringList &, QDeclarativeJS::AST::Node *, QList< QDeclarativeJS::AST::ExpressionNode *> *nodes=0)
The QString class provides a Unicode character string.
Definition: qstring.h:83
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
int acquireReg(int cleanup=Instr::Noop, int cleanupType=0)
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool isUpper() const
Returns true if the character is an uppercase letter, i.
Definition: qchar.h:273
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
const QMetaObject * attachedPropertiesType() const
quint8 exceptionId(QDeclarativeJS::AST::ExpressionNode *)
QHash< QString, QDeclarativeParser::Object * > ids
bool subscription(const QStringList &, Result *)
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ registerCleanup()

void QDeclarativeBindingCompilerPrivate::registerCleanup ( int  reg,
int  cleanup,
int  cleanupType = 0 
)

Definition at line 2697 of file qdeclarativecompiledbindings.cpp.

2698 {
2699  registerCleanups.insert(reg, qMakePair(cleanup, cleanupType));
2700 }
QHash< int, QPair< int, int > > registerCleanups
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
static void cleanup()
Definition: qpicture.cpp:1508

◆ registerLiteralString()

int QDeclarativeBindingCompilerPrivate::registerLiteralString ( const QString str)

Definition at line 2735 of file qdeclarativecompiledbindings.cpp.

2736 {
2737  QByteArray strdata((const char *)str.constData(), str.length() * sizeof(QChar));
2738  int offset = data.count();
2739  data += strdata;
2740 
2741  int reg = acquireReg(Instr::CleanupString);
2742  if (reg == -1)
2743  return false;
2744 
2745  Instr string;
2746  string.common.type = Instr::String;
2747  string.string_value.reg = reg;
2748  string.string_value.offset = offset;
2749  string.string_value.length = str.length();
2750  bytecode << string;
2751 
2752  return reg;
2753 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int acquireReg(int cleanup=Instr::Noop, int cleanupType=0)
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ registerString()

int QDeclarativeBindingCompilerPrivate::registerString ( const QString string)

Definition at line 2756 of file qdeclarativecompiledbindings.cpp.

2757 {
2758  Q_ASSERT(!string.isEmpty());
2759 
2760  QHash<QString, QPair<int, int> >::ConstIterator iter = registeredStrings.find(string);
2761 
2762  if (iter == registeredStrings.end()) {
2763  quint32 len = string.length();
2764  QByteArray lendata((const char *)&len, sizeof(quint32));
2765  QByteArray strdata((const char *)string.constData(), string.length() * sizeof(QChar));
2766  strdata.prepend(lendata);
2767  int rv = data.count();
2768  data += strdata;
2769 
2770  iter = registeredStrings.insert(string, qMakePair(registeredStrings.count(), rv));
2771  }
2772 
2773  Instr reg;
2774  reg.common.type = Instr::InitString;
2775  reg.initstring.offset = iter->first;
2776  reg.initstring.dataIdx = iter->second;
2777  bytecode << reg;
2778  return reg.initstring.offset;
2779 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static bool isEmpty(const char *str)
QHash< QString, QPair< int, int > > registeredStrings
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
unsigned int quint32
Definition: qglobal.h:938
int count(const Key &key) const
Returns the number of items associated with the key.
Definition: qhash.h:719
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865

◆ releaseReg()

void QDeclarativeBindingCompilerPrivate::releaseReg ( int  reg)

Definition at line 2717 of file qdeclarativecompiledbindings.cpp.

2718 {
2719  Q_ASSERT(reg >= 0 && reg <= 31);
2720 
2721  if (registerCleanups.contains(reg)) {
2723  registerCleanups.remove(reg);
2724  Instr cleanup;
2725  cleanup.common.type = (quint8)c.first;
2726  cleanup.cleanup.reg = reg;
2727  bytecode << cleanup;
2728  }
2729 
2730  quint32 mask = 1 << reg;
2731  registers &= ~mask;
2732 }
unsigned char c[8]
Definition: qnumeric_p.h:62
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
T1 first
Definition: qpair.h:65
unsigned char quint8
Definition: qglobal.h:934
QHash< int, QPair< int, int > > registerCleanups
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
unsigned int quint32
Definition: qglobal.h:938
static void cleanup()
Definition: qpicture.cpp:1508

◆ resetInstanceState()

void QDeclarativeBindingCompilerPrivate::resetInstanceState ( )

Clear the state associated with attempting to compile a specific binding.

This does not clear the global "committed binding" states.

Definition at line 1718 of file qdeclarativecompiledbindings.cpp.

1719 {
1720  registers = 0;
1722  data = committed.data;
1723  exceptions = committed.exceptions;
1726  subscriptionIds = committed.subscriptionIds;
1727  registeredStrings = committed.registeredStrings;
1728  bytecode.clear();
1729 }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
QHash< int, QPair< int, int > > registerCleanups
struct QDeclarativeBindingCompilerPrivate::@134 committed
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QHash< QString, QPair< int, int > > registeredStrings
void clear()
Definition: qset.h:87

◆ stringArith()

bool QDeclarativeBindingCompilerPrivate::stringArith ( Result type,
const Result lhs,
const Result rhs,
QSOperator::Op  op 
)

Definition at line 2281 of file qdeclarativecompiledbindings.cpp.

2282 {
2283  if (op != QSOperator::Add)
2284  return false;
2285 
2286  int lhsTmp = -1;
2287  int rhsTmp = -1;
2288 
2289  if (lhs.unknownType) {
2290  if (!qmlExperimental())
2291  return false;
2292 
2293  lhsTmp = acquireReg(Instr::CleanupString);
2294  if (lhsTmp == -1)
2295  return false;
2296 
2297  Instr convert;
2298  convert.common.type = Instr::ConvertGenericToString;
2299  convert.unaryop.output = lhsTmp;
2300  convert.unaryop.src = lhs.reg;
2301  bytecode << convert;
2302  }
2303 
2304  if (rhs.unknownType) {
2305  if (!qmlExperimental())
2306  return false;
2307 
2308  rhsTmp = acquireReg(Instr::CleanupString);
2309  if (rhsTmp == -1)
2310  return false;
2311 
2312  Instr convert;
2313  convert.common.type = Instr::ConvertGenericToString;
2314  convert.unaryop.output = rhsTmp;
2315  convert.unaryop.src = rhs.reg;
2316  bytecode << convert;
2317  }
2318 
2319  type.reg = acquireReg(Instr::CleanupString);
2320  if (type.reg == -1)
2321  return false;
2322 
2323  type.type = QMetaType::QString;
2324 
2325  Instr add;
2326  add.common.type = Instr::AddString;
2327  add.binaryop.output = type.reg;
2328  add.binaryop.src1 = (lhsTmp == -1)?lhs.reg:lhsTmp;
2329  add.binaryop.src2 = (rhsTmp == -1)?rhs.reg:rhsTmp;
2330  bytecode << add;
2331 
2332  if (lhsTmp != -1) releaseReg(lhsTmp);
2333  if (rhsTmp != -1) releaseReg(rhsTmp);
2334  releaseReg(lhs.reg);
2335  releaseReg(rhs.reg);
2336 
2337  return true;
2338 }
int type
Definition: qmetatype.cpp:239
#define add(aName)
int acquireReg(int cleanup=Instr::Noop, int cleanupType=0)
static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, bool *ok)
Definition: qvariant.cpp:627

◆ subscription()

bool QDeclarativeBindingCompilerPrivate::subscription ( const QStringList sub,
Result result 
)

Definition at line 2781 of file qdeclarativecompiledbindings.cpp.

2782 {
2783  QString str = sub.join(QLatin1String("."));
2784  result->subscriptionSet.insert(str);
2785 
2786  if (subscriptionSet.contains(str)) {
2787  return false;
2788  } else {
2789  subscriptionSet.insert(str);
2790  return true;
2791  }
2792 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool contains(const T &value) const
Definition: qset.h:91
const_iterator insert(const T &value)
Definition: qset.h:179
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671

◆ subscriptionIndex()

int QDeclarativeBindingCompilerPrivate::subscriptionIndex ( const QStringList sub)

Definition at line 2794 of file qdeclarativecompiledbindings.cpp.

2795 {
2796  QString str = sub.join(QLatin1String("."));
2798  if (iter == subscriptionIds.end())
2800  usedSubscriptionIds.insert(*iter);
2801  return *iter;
2802 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
const_iterator insert(const T &value)
Definition: qset.h:179
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
int count(const Key &key) const
Returns the number of items associated with the key.
Definition: qhash.h:719
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865

◆ subscriptionNeutral()

bool QDeclarativeBindingCompilerPrivate::subscriptionNeutral ( const QSet< QString > &  base,
const QSet< QString > &  lhs,
const QSet< QString > &  rhs 
)

Definition at line 2808 of file qdeclarativecompiledbindings.cpp.

2811 {
2812  QSet<QString> difflhs = lhs;
2813  difflhs.subtract(rhs);
2814  QSet<QString> diffrhs = rhs;
2815  diffrhs.subtract(lhs);
2816 
2817  difflhs.unite(diffrhs);
2818  difflhs.subtract(base);
2819 
2820  return difflhs.isEmpty();
2821 }
QSet< T > & unite(const QSet< T > &other)
Definition: qset.h:244
bool isEmpty() const
Definition: qset.h:77
QSet< T > & subtract(const QSet< T > &other)
Definition: qset.h:270

◆ tryArith()

bool QDeclarativeBindingCompilerPrivate::tryArith ( QDeclarativeJS::AST::Node node)

Definition at line 2158 of file qdeclarativecompiledbindings.cpp.

2159 {
2160  if (node->kind != AST::Node::Kind_BinaryExpression)
2161  return false;
2162 
2163  AST::BinaryExpression *expression = static_cast<AST::BinaryExpression *>(node);
2164  if (expression->op == QSOperator::Add ||
2165  expression->op == QSOperator::Sub)
2166  return true;
2167  else
2168  return false;
2169 }

◆ tryConditional()

bool QDeclarativeBindingCompilerPrivate::tryConditional ( QDeclarativeJS::AST::Node node)

Definition at line 2412 of file qdeclarativecompiledbindings.cpp.

2413 {
2414  return (node->kind == AST::Node::Kind_ConditionalExpression);
2415 }

◆ tryConstant()

bool QDeclarativeBindingCompilerPrivate::tryConstant ( QDeclarativeJS::AST::Node node)

Definition at line 2479 of file qdeclarativecompiledbindings.cpp.

2480 {
2481  return node->kind == AST::Node::Kind_TrueLiteral ||
2482  node->kind == AST::Node::Kind_FalseLiteral ||
2483  node->kind == AST::Node::Kind_NumericLiteral ||
2484  node->kind == AST::Node::Kind_StringLiteral;
2485 }

◆ tryLogic()

bool QDeclarativeBindingCompilerPrivate::tryLogic ( QDeclarativeJS::AST::Node node)

Definition at line 2340 of file qdeclarativecompiledbindings.cpp.

2341 {
2342  if (node->kind != AST::Node::Kind_BinaryExpression)
2343  return false;
2344 
2345  AST::BinaryExpression *expression = static_cast<AST::BinaryExpression *>(node);
2346  if (expression->op == QSOperator::Gt ||
2347  expression->op == QSOperator::Equal ||
2348  expression->op == QSOperator::NotEqual)
2349  return true;
2350  else
2351  return false;
2352 }

◆ tryMethod()

bool QDeclarativeBindingCompilerPrivate::tryMethod ( QDeclarativeJS::AST::Node node)

Definition at line 2534 of file qdeclarativecompiledbindings.cpp.

2535 {
2536  return node->kind == AST::Node::Kind_CallExpression;
2537 }

◆ tryName()

bool QDeclarativeBindingCompilerPrivate::tryName ( QDeclarativeJS::AST::Node node)

Definition at line 1920 of file qdeclarativecompiledbindings.cpp.

1921 {
1922  return node->kind == AST::Node::Kind_IdentifierExpression ||
1923  node->kind == AST::Node::Kind_FieldMemberExpression;
1924 }

Properties

◆ bytecode

QVector<Instr> QDeclarativeBindingCompilerPrivate::bytecode

◆ committed

struct { ... } QDeclarativeBindingCompilerPrivate::committed

◆ component

QDeclarativeParser::Object* QDeclarativeBindingCompilerPrivate::component

◆ context

QDeclarativeParser::Object* QDeclarativeBindingCompilerPrivate::context

◆ data

QByteArray QDeclarativeBindingCompilerPrivate::data

◆ dependencies

QList<QSet<int> > QDeclarativeBindingCompilerPrivate::dependencies

Definition at line 698 of file qdeclarativecompiledbindings.cpp.

◆ destination

QDeclarativeParser::Property* QDeclarativeBindingCompilerPrivate::destination

◆ engine

QDeclarativeEnginePrivate* QDeclarativeBindingCompilerPrivate::engine

◆ exceptions

QVector<quint64> QDeclarativeBindingCompilerPrivate::exceptions

Definition at line 688 of file qdeclarativecompiledbindings.cpp.

◆ ids

QHash<QString, QDeclarativeParser::Object *> QDeclarativeBindingCompilerPrivate::ids

◆ imports

QDeclarativeImports QDeclarativeBindingCompilerPrivate::imports

◆ offsets

QList<int> QDeclarativeBindingCompilerPrivate::offsets

◆ registerCleanups

QHash<int, QPair<int, int> > QDeclarativeBindingCompilerPrivate::registerCleanups

Definition at line 673 of file qdeclarativecompiledbindings.cpp.

◆ registeredStrings

QHash<QString, QPair<int, int> > QDeclarativeBindingCompilerPrivate::registeredStrings

◆ registers

quint32 QDeclarativeBindingCompilerPrivate::registers

Definition at line 672 of file qdeclarativecompiledbindings.cpp.

◆ subscriptionIds

QHash<QString, int> QDeclarativeBindingCompilerPrivate::subscriptionIds

◆ subscriptionSet

QSet<QString> QDeclarativeBindingCompilerPrivate::subscriptionSet

Definition at line 691 of file qdeclarativecompiledbindings.cpp.

◆ usedSubscriptionIds

QSet<int> QDeclarativeBindingCompilerPrivate::usedSubscriptionIds

Definition at line 690 of file qdeclarativecompiledbindings.cpp.


The documentation for this struct was generated from the following file: