Commit baf7003b authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Merge branch 'master' of git@scm.dev.nokia.troll.no:creator/mainline

parents e332fbd3 b9ce92ec
......@@ -37,6 +37,7 @@
#include <QtCore/QHash>
#include <QtCore/QLinkedList>
#include <QtCore/QList>
#include <QtCore/QQueue>
#include <QtCore/QLocale>
#include <QtCore/QMap>
#include <QtCore/QMetaEnum>
......@@ -3572,15 +3573,15 @@ template <class Key, class Value>
{
QMapNode<Key, Value> *mn = 0;
const int valueOffset = (char *)&(mn->value) - (char*)mn;
d.put("(size_t)&(('"NS"QMapNode<");
d.put("[\"(size_t)&(('"NS"QMapNode<");
d.put(keyType);
d.put(',');
d.put(valueType);
if (valueType[qstrlen(valueType) - 1] == '>')
d.put(' ');
d.put(">'*)0)->value=\"");
d.put(">'*)0)->value\",\"");
d.put(valueOffset);
d.put('"');
d.put("\"]");
return d;
}
......@@ -3595,20 +3596,86 @@ template <class Key, class Value>
{
std::pair<Key, Value> *p = 0;
const int valueOffset = (char *)&(p->second) - (char*)p;
d.put("(size_t)&(('std::pair<");
d.put("[\"(size_t)&(('std::pair<");
d.put(keyType);
d.put(" const ,");
d.put(valueType);
if (valueType[qstrlen(valueType) - 1] == '>')
d.put(' ');
d.put(">'*)0)->second=\"");
d.put(">'*)0)->second\",\"");
d.put(valueOffset);
d.put('"');
d.put("\"]");
return d;
}
#endif // Q_CC_MSVC
// Dump out sizes for CDB
static inline void dumpSizes(QDumper &d)
{
// Sort by sizes
typedef QMultiMap<size_t, const char *> SizeMap;
SizeMap sizeMap;
sizeMap.insert(sizeof(int), "int");
sizeMap.insert(sizeof(char*), "char*");
sizeMap.insert(sizeof(QString), NS"QString");
sizeMap.insert(sizeof(QStringList), NS"QStringList");
#ifndef QT_BOOTSTRAPPED
sizeMap.insert(sizeof(QObject), NS"QObject");
sizeMap.insert(sizeof(QList<int>), NS"QList<int>");
sizeMap.insert(sizeof(QLinkedList<int>), NS"QLinkedList<int>");
sizeMap.insert(sizeof(QVector<int>), NS"QVector<int>");
sizeMap.insert(sizeof(QQueue<int>), NS"QQueue<int>");
#endif
#if USE_QT_GUI
sizeMap.insert(sizeof(QWidget), NS"QWidget");
#endif
#ifdef Q_OS_WIN
sizeMap.insert(sizeof(std::string), "string");
sizeMap.insert(sizeof(std::wstring), "wstring");
#endif
sizeMap.insert(sizeof(std::string), "std::string");
sizeMap.insert(sizeof(std::wstring), "std::wstring");
sizeMap.insert(sizeof(std::allocator<int>), "std::allocator");
sizeMap.insert(sizeof(std::char_traits<char>), "std::char_traits<char>");
sizeMap.insert(sizeof(std::char_traits<unsigned short>), "std::char_traits<unsigned short>");
#ifndef QT_BOOTSTRAPPED
#if QT_VERSION >= 0x040500
sizeMap.insert(sizeof(QSharedPointer<int>), NS"QSharedPointer");
sizeMap.insert(sizeof(QSharedDataPointer<QSharedData>), NS"QSharedDataPointer");
sizeMap.insert(sizeof(QWeakPointer<int>), NS"QWeakPointer");
#endif
#endif // QT_BOOTSTRAPPED
sizeMap.insert(sizeof(QPointer<QObject>), "QPointer");
// Common map node types
sizeMap.insert(sizeof(QMapNode<int,int >), NS"QMapNode<int,int>");
sizeMap.insert(sizeof(QMapNode<int, QString>), NS"QMapNode<int,"NS"QString>");
sizeMap.insert(sizeof(QMapNode<int, QVariant>), NS"QMapNode<int,"NS"QVariant>");
sizeMap.insert(sizeof(QMapNode<QString, int>), NS"QMapNode<"NS"QString,int>");
sizeMap.insert(sizeof(QMapNode<QString, QString>), NS"QMapNode<"NS"QString,"NS"QString>");
sizeMap.insert(sizeof(QMapNode<QString, QVariant>), NS"QMapNode<"NS"QString,"NS"QVariant>");
// Dump as lists of types preceded by size
size_t lastSize = 0;
d.put("sizes=[");
const SizeMap::const_iterator cend = sizeMap.constEnd();
for (SizeMap::const_iterator it = sizeMap.constBegin(); it != cend; ++it) {
// new size list
if (it.key() != lastSize) {
if (lastSize)
d.put("],");
d.put("[\"");
d.put(it.key());
lastSize = it.key();
d.put('"');
}
d.put(",\"");
d.put(it.value());
d.put('"');
}
d.put("]]");
}
extern "C" Q_DECL_EXPORT
void *qDumpObjectData440(
int protocolVersion,
......@@ -3702,45 +3769,10 @@ void *qDumpObjectData440(
d.put(",namespace=\""NS"\",");
d.put("dumperversion=\"1.3\",");
// Dump out size information
d.put("sizes={");
d.put("int=\"").put(sizeof(int)).put("\",")
.put("char*=\"").put(sizeof(char*)).put("\",")
.put(""NS"QString=\"").put(sizeof(QString)).put("\",")
.put(""NS"QStringList=\"").put(sizeof(QStringList)).put("\",")
#ifndef QT_BOOTSTRAPPED
.put(""NS"QObject=\"").put(sizeof(QObject)).put("\",")
#endif
#if USE_QT_GUI
.put(""NS"QWidget=\"").put(sizeof(QWidget)).put("\",")
#endif
#ifdef Q_OS_WIN
.put("string=\"").put(sizeof(std::string)).put("\",")
.put("wstring=\"").put(sizeof(std::wstring)).put("\",")
#endif
.put("std::string=\"").put(sizeof(std::string)).put("\",")
.put("std::wstring=\"").put(sizeof(std::wstring)).put("\",")
.put("std::allocator=\"").put(sizeof(std::allocator<int>)).put("\",")
.put("std::char_traits<char>=\"").put(sizeof(std::char_traits<char>)).put("\",")
.put("std::char_traits<unsigned short>=\"").put(sizeof(std::char_traits<unsigned short>)).put("\",")
#ifndef QT_BOOTSTRAPPED
#if QT_VERSION >= 0x040500
.put(NS"QSharedPointer=\"").put(sizeof(QSharedPointer<int>)).put("\",")
.put(NS"QSharedDataPointer=\"").put(sizeof(QSharedDataPointer<QSharedData>)).put("\",")
.put(NS"QWeakPointer=\"").put(sizeof(QWeakPointer<int>)).put("\",")
#endif
#endif // QT_BOOTSTRAPPED
.put("QPointer=\"").put(sizeof(QPointer<QObject>)).put("\",")
// Common map node types
.put(NS"QMapNode<int,int>=\"").put(sizeof(QMapNode<int,int >)).put("\",")
.put(NS"QMapNode<int,"NS"QString>=\"").put(sizeof(QMapNode<int, QString>)).put("\",")
.put(NS"QMapNode<int,"NS"QVariant>=\"").put(sizeof(QMapNode<int, QVariant>)).put("\",")
.put(NS"QMapNode<"NS"QString,int>=\"").put(sizeof(QMapNode<QString, int>)).put("\",")
.put(NS"QMapNode<"NS"QString,"NS"QString>=\"").put(sizeof(QMapNode<QString, QString>)).put("\",")
.put(NS"QMapNode<"NS"QString,"NS"QVariant>=\"").put(sizeof(QMapNode<QString, QVariant>))
.put("\"}");
dumpSizes(d);
// Write out common expression values for CDB
#ifdef Q_CC_MSVC
d.put(",expressions={");
d.put(",expressions=[");
putQMapNodeOffsetExpression<int,int>("int", "int", d).put(',');
putQMapNodeOffsetExpression<int,QString>("int", NS"QString", d).put(',');
putQMapNodeOffsetExpression<int,QVariant>("int", NS"QVariant", d).put(',');
......@@ -3754,11 +3786,11 @@ void *qDumpObjectData440(
putStdPairValueOffsetExpression<QString,int>(NS"QString", "int", d).put(',');
putStdPairValueOffsetExpression<std::string,std::string>(stdStringTypeC, stdStringTypeC, d).put(',');
putStdPairValueOffsetExpression<int,std::string>("int", stdStringTypeC, d).put(',');
putStdPairValueOffsetExpression<std::string,int>(stdStringTypeC, "int", d.put(','));
putStdPairValueOffsetExpression<std::string,int>(stdStringTypeC, "int", d).put(',');
putStdPairValueOffsetExpression<std::wstring,std::wstring>(stdWideStringTypeUShortC, stdWideStringTypeUShortC, d).put(',');
putStdPairValueOffsetExpression<int,std::wstring>("int", stdWideStringTypeUShortC, d).put(',');
putStdPairValueOffsetExpression<std::wstring,int>(stdWideStringTypeUShortC, "int", d);
d.put('}');
d.put(']');
#endif // Q_CC_MSVC
d.disarm();
}
......
......@@ -152,8 +152,6 @@ public:
QList<QObject *> pendingChildInsertedEvents;
QList<QPointer<QObject> > eventFilters;
void *currentChildBeingDeleted;
void *declarativeData;
void *objectGuards;
QAtomicPointer<void> sharedRefcount;
int *deleteWatch;
#endif
......
......@@ -28,10 +28,12 @@
**************************************************************************/
#include <QtCore/QStringList>
#include <QtCore/QLinkedList>
#include <QtCore/QVector>
#include <QtCore/QSharedPointer>
#include <QtCore/QTimer>
#include <QtCore/QMap>
#include <QtCore/QSet>
#include <QtCore/QVariant>
#include <QtGui/QAction>
......@@ -138,6 +140,16 @@ static int dumpQIntList()
return 0;
}
static int dumpQIntLinkedList()
{
QLinkedList<int> test = QLinkedList<int>() << 1 << 2;
prepareInBuffer("QLinkedList", "local.qintlinkedlist", "local.qlinkedintlist", "int");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), 0, 0, 0);
fputs(qDumpOutBuffer, stdout);
fputc('\n', stdout);
return 0;
}
static int dumpQIntVector()
{
QVector<int> test = QVector<int>() << 42 << 43;
......@@ -148,6 +160,16 @@ static int dumpQIntVector()
return 0;
}
static int dumpQQStringVector()
{
QVector<QString> test = QVector<QString>() << "42s" << "43s";
prepareInBuffer("QVector", "local.qstringvector", "local.qstringvector", "QString");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), 0, 0, 0);
fputs(qDumpOutBuffer, stdout);
fputc('\n', stdout);
return 0;
}
static int dumpQMapIntInt()
{
QMap<int,int> test;
......@@ -176,6 +198,33 @@ static int dumpQMapIntString()
return 0;
}
static int dumpQSetInt()
{
QSet<int> test;
test.insert(42);
test.insert(43);
prepareInBuffer("QSet", "local.qsetint", "local.qsetint", "int");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), 0, 0, 0);
fputs(qDumpOutBuffer, stdout);
fputc('\n', stdout);
return 0;
}
static int dumpQMapQStringString()
{
QMap<QString,QString> test;
QMapNode<QString,QString> mapNode;
const int valueOffset = (char*)&(mapNode.value) - (char*)&mapNode;
test.insert(QLatin1String("42s"), QLatin1String("fortytwo"));
test.insert(QLatin1String("423"), QLatin1String("fortytree"));
prepareInBuffer("QMap", "local.qmapqstringqstring", "local.qmapqstringqstring", "QString@QString");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), sizeof(QString), sizeof(mapNode), valueOffset);
fputs(qDumpOutBuffer, stdout);
fputc('\n', stdout);
return 0;
}
static int dumpQVariant()
{
QVariant test(QLatin1String("item"));
......@@ -417,10 +466,14 @@ static TypeDumpFunctionMap registerTypes()
rc.insert("QSharedPointer<QString>", dumpQSharedPointerQString);
rc.insert("QStringList", dumpQStringList);
rc.insert("QList<int>", dumpQIntList);
rc.insert("QLinkedList<int>", dumpQIntLinkedList);
rc.insert("QList<std::string>", dumpStdStringQList);
rc.insert("QVector<int>", dumpQIntVector);
rc.insert("QVector<QString>", dumpQQStringVector);
rc.insert("QMap<int,QString>", dumpQMapIntString);
rc.insert("QMap<QString,QString>", dumpQMapQStringString);
rc.insert("QMap<int,int>", dumpQMapIntInt);
rc.insert("QSet<int>", dumpQSetInt);
rc.insert("string", dumpStdString);
rc.insert("wstring", dumpStdWString);
rc.insert("list<int>", dumpStdIntList);
......
......@@ -38,6 +38,7 @@ BackwardsScanner::BackwardsScanner(const QTextCursor &cursor, const QString &suf
, _block(cursor.block())
, _maxBlockCount(maxBlockCount)
{
_tokenize.setQtMocRunEnabled(true);
_tokenize.setSkipComments(true);
_text = _block.text().left(cursor.position() - cursor.block().position());
......@@ -52,13 +53,10 @@ BackwardsScanner::BackwardsScanner(const QTextCursor &cursor, const QString &suf
int BackwardsScanner::state() const
{ return _tokenize.state(); }
const QList<SimpleToken> &BackwardsScanner::tokens() const
{ return _tokens; }
const SimpleToken &BackwardsScanner::LA(int index) const
SimpleToken BackwardsScanner::LA(int index) const
{ return const_cast<BackwardsScanner *>(this)->fetchToken(_startToken - index); }
const SimpleToken &BackwardsScanner::operator[](int index) const
SimpleToken BackwardsScanner::operator[](int index) const
{ return const_cast<BackwardsScanner *>(this)->fetchToken(index); }
const SimpleToken &BackwardsScanner::fetchToken(int i)
......@@ -72,16 +70,15 @@ const SimpleToken &BackwardsScanner::fetchToken(int i)
} else {
++_blocksTokenized;
QString blockText = _block.text();
const QString blockText = _block.text();
_text.prepend(blockText);
QList<SimpleToken> adaptedTokens;
for (int i = 0; i < _tokens.size(); ++i) {
const SimpleToken &t = _tokens.at(i);
const int position = t.position() + blockText.length();
adaptedTokens.append(SimpleToken(t.kind(),
position,
t.length(),
_text.midRef(position, t.length())));
SimpleToken t = _tokens.at(i);
t.setPosition(t.position() + blockText.length());
t.setText(_text.midRef(t.position(), t.length()));
adaptedTokens.append(t);
}
_tokens = _tokenize(blockText, previousBlockState(_block));
......@@ -102,18 +99,22 @@ int BackwardsScanner::startPosition() const
QString BackwardsScanner::text() const
{ return _text; }
QString BackwardsScanner::text(int begin, int end) const
QString BackwardsScanner::mid(int index) const
{
const SimpleToken &firstToken = _tokens.at(index + _offset);
return _text.mid(firstToken.begin());
}
QString BackwardsScanner::text(int index) const
{
const SimpleToken &firstToken = _tokens.at(begin + _offset);
const SimpleToken &lastToken = _tokens.at(end + _offset - 1);
return _text.mid(firstToken.begin(), lastToken.end() - firstToken.begin());
const SimpleToken &firstToken = _tokens.at(index + _offset);
return _text.mid(firstToken.begin(), firstToken.length());
}
QStringRef BackwardsScanner::textRef(int begin, int end) const
QStringRef BackwardsScanner::textRef(int index) const
{
const SimpleToken &firstToken = _tokens.at(begin + _offset);
const SimpleToken &lastToken = _tokens.at(end + _offset - 1);
return _text.midRef(firstToken.begin(), lastToken.end() - firstToken.begin());
const SimpleToken &firstToken = _tokens.at(index + _offset);
return _text.midRef(firstToken.begin(), firstToken.length());
}
int BackwardsScanner::previousBlockState(const QTextBlock &block) const
......@@ -156,6 +157,17 @@ int BackwardsScanner::startOfMatchingBrace(int index) const
--count;
--i;
} while (count != 0 && tk[i].isNot(T_EOF_SYMBOL));
} else if (tk[index - 1].is(T_RBRACE)) {
int i = index - 1;
int count = 0;
do {
if (tk[i].is(T_LBRACE)) {
if (! ++count)
return i;
} else if (tk[i].is(T_RBRACE))
--count;
--i;
} while (count != 0 && tk[i].isNot(T_EOF_SYMBOL));
} else if (tk[index - 1].is(T_GREATER)) {
int i = index - 1;
int count = 0;
......@@ -167,7 +179,71 @@ int BackwardsScanner::startOfMatchingBrace(int index) const
--count;
--i;
} while (count != 0 && tk[i].isNot(T_EOF_SYMBOL));
} else {
Q_ASSERT(0);
}
return index;
}
int BackwardsScanner::startOfLine(int index) const
{
const BackwardsScanner tk(*this);
forever {
const SimpleToken &tok = tk[index - 1];
if (tok.is(T_EOF_SYMBOL))
break;
else if (tok.followsNewline())
return index - 1;
--index;
}
return index;
}
int BackwardsScanner::startOfBlock(int index) const
{
const BackwardsScanner tk(*this);
const int start = index;
forever {
SimpleToken token = tk[index - 1];
if (token.is(T_EOF_SYMBOL)) {
break;
} else if (token.is(T_GREATER)) {
const int matchingBrace = startOfMatchingBrace(index);
if (matchingBrace != index && tk[matchingBrace - 1].is(T_TEMPLATE))
index = matchingBrace;
} else if (token.is(T_RPAREN) || token.is(T_RBRACKET) || token.is(T_RBRACE)) {
const int matchingBrace = startOfMatchingBrace(index);
if (matchingBrace != index)
index = matchingBrace;
} else if (token.is(T_LPAREN) || token.is(T_LBRACKET)) {
break; // unmatched brace
} else if (token.is(T_LBRACE)) {
return index - 1;
}
--index;
}
return start;
}
int BackwardsScanner::indentation(int index) const
{
SimpleToken newline = operator[](startOfLine(index + 1));
return newline.position();
}
......@@ -51,21 +51,26 @@ public:
int startPosition() const;
QString text() const;
QString text(int begin, int end) const;
QStringRef textRef(int begin, int end) const;
QString mid(int index) const;
QString text(int index) const;
QStringRef textRef(int index) const;
// 1-based
const SimpleToken &LA(int index) const;
SimpleToken LA(int index) const;
// n-la token is [startToken - n]
const SimpleToken &operator[](int index) const; // ### deprecate
SimpleToken operator[](int index) const; // ### deprecate
int indentation(int index) const;
int startOfLine(int index) const;
int startOfMatchingBrace(int index) const;
int startOfBlock(int index) const;
int previousBlockState(const QTextBlock &block) const;
private:
const SimpleToken &fetchToken(int i);
const QList<SimpleToken> &tokens() const;
private:
QList<SimpleToken> _tokens;
......
......@@ -150,7 +150,7 @@ QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
if (i == initialSize)
return QString();
return scanner.text(i, initialSize);
return scanner.mid(i);
}
int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor) const
......
......@@ -49,9 +49,9 @@ static bool shouldOverrideChar(const QChar &ch)
}
}
static bool isCompleteStringLiteral(const BackwardsScanner &tk, int index, int startToken)
static bool isCompleteStringLiteral(const BackwardsScanner &tk, int index)
{
const QStringRef text = tk.textRef(index, startToken);
const QStringRef text = tk.textRef(index);
if (text.length() < 2)
return false;
......@@ -62,9 +62,9 @@ static bool isCompleteStringLiteral(const BackwardsScanner &tk, int index, int s
return false;
}
static bool isCompleteCharLiteral(const BackwardsScanner &tk, int index, int startToken)
static bool isCompleteCharLiteral(const BackwardsScanner &tk, int index)
{
const QStringRef text = tk.textRef(index, startToken);
const QStringRef text = tk.textRef(index);
if (text.length() < 2)
return false;
......@@ -75,7 +75,16 @@ static bool isCompleteCharLiteral(const BackwardsScanner &tk, int index, int sta
return false;
}
static bool shouldInsertMatchingText(const QChar &lookAhead)
MatchingText::MatchingText()
{ }
bool MatchingText::shouldInsertMatchingText(const QTextCursor &tc)
{
QTextDocument *doc = tc.document();
return shouldInsertMatchingText(doc->characterAt(tc.selectionEnd()));
}
bool MatchingText::shouldInsertMatchingText(const QChar &lookAhead)
{
switch (lookAhead.unicode()) {
case '{': case '}':
......@@ -91,9 +100,6 @@ static bool shouldInsertMatchingText(const QChar &lookAhead)
} // switch
}
MatchingText::MatchingText()
{ }
QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QString &textToProcess,
const QChar &la, int *skippedChars) const
{
......@@ -133,7 +139,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
if (text.length() != 1)
qWarning() << Q_FUNC_INFO << "handle event compression";
if (isCompleteStringLiteral(tk, index - 1, startToken))
if (isCompleteStringLiteral(tk, index - 1))
return QLatin1String("\"");
return QString();
......@@ -141,7 +147,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
if (text.length() != 1)
qWarning() << Q_FUNC_INFO << "handle event compression";
if (isCompleteCharLiteral(tk, index - 1, startToken))
if (isCompleteCharLiteral(tk, index - 1))
return QLatin1String("'");
return QString();
......
......@@ -41,6 +41,9 @@ class CPLUSPLUS_EXPORT MatchingText
public:
MatchingText();
static bool shouldInsertMatchingText(const QTextCursor &tc);
static bool shouldInsertMatchingText(const QChar &lookAhead);
QString insertMatchingBrace(const QTextCursor &tc, const QString &text,
const QChar &la, int *skippedChars) const;
QString insertParagraphSeparator(const QTextCursor &tc) const;
......
......@@ -35,6 +35,17 @@
using namespace CPlusPlus;
SimpleToken::SimpleToken(const Token &token, const QStringRef &text)
: _kind(token.f.kind)
, _flags(0)
, _position(token.begin())
, _length(token.f.length)