2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
#include "qmakeparser.h"
|
|
|
|
|
2013-05-29 18:18:51 +00:00
|
|
|
#include "qmakevfs.h"
|
2012-09-05 16:29:19 +00:00
|
|
|
#include "ioutils.h"
|
|
|
|
using namespace QMakeInternal;
|
|
|
|
|
|
|
|
#include <qfile.h>
|
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
# include <qthreadpool.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ProFileCache
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-24 18:50:32 +00:00
|
|
|
ProFileCache::ProFileCache()
|
|
|
|
{
|
|
|
|
QMakeVfs::ref();
|
|
|
|
}
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
ProFileCache::~ProFileCache()
|
|
|
|
{
|
2022-10-06 09:08:21 +00:00
|
|
|
for (const Entry &ent : std::as_const(parsed_files))
|
2012-09-05 16:29:19 +00:00
|
|
|
if (ent.pro)
|
|
|
|
ent.pro->deref();
|
2018-05-24 18:50:32 +00:00
|
|
|
QMakeVfs::deref();
|
2012-09-05 16:29:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-24 17:30:24 +00:00
|
|
|
void ProFileCache::discardFile(const QString &fileName, QMakeVfs *vfs)
|
|
|
|
{
|
|
|
|
int eid = vfs->idForFileName(fileName, QMakeVfs::VfsExact | QMakeVfs::VfsAccessedOnly);
|
|
|
|
if (eid)
|
|
|
|
discardFile(eid);
|
|
|
|
int cid = vfs->idForFileName(fileName, QMakeVfs::VfsCumulative | QMakeVfs::VfsAccessedOnly);
|
|
|
|
if (cid && cid != eid)
|
|
|
|
discardFile(cid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProFileCache::discardFile(int id)
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
QMutexLocker lck(&mutex);
|
|
|
|
#endif
|
2016-10-24 17:30:24 +00:00
|
|
|
auto it = parsed_files.find(id);
|
2012-09-05 16:29:19 +00:00
|
|
|
if (it != parsed_files.end()) {
|
2015-07-16 15:42:08 +00:00
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
if (it->locker) {
|
|
|
|
if (!it->locker->done) {
|
|
|
|
++it->locker->waiters;
|
|
|
|
it->locker->cond.wait(&mutex);
|
|
|
|
if (!--it->locker->waiters) {
|
|
|
|
delete it->locker;
|
|
|
|
it->locker = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2012-09-05 16:29:19 +00:00
|
|
|
if (it->pro)
|
|
|
|
it->pro->deref();
|
|
|
|
parsed_files.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-24 17:30:24 +00:00
|
|
|
void ProFileCache::discardFiles(const QString &prefix, QMakeVfs *vfs)
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
QMutexLocker lck(&mutex);
|
|
|
|
#endif
|
2016-10-24 17:30:24 +00:00
|
|
|
auto it = parsed_files.begin(), end = parsed_files.end();
|
|
|
|
while (it != end) {
|
|
|
|
// Note: this is empty for virtual files from other VFSes.
|
|
|
|
QString fn = vfs->fileNameForId(it.key());
|
|
|
|
if (fn.startsWith(prefix)) {
|
2015-07-16 15:42:08 +00:00
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
if (it->locker) {
|
|
|
|
if (!it->locker->done) {
|
|
|
|
++it->locker->waiters;
|
|
|
|
it->locker->cond.wait(&mutex);
|
|
|
|
if (!--it->locker->waiters) {
|
|
|
|
delete it->locker;
|
|
|
|
it->locker = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2012-09-05 16:29:19 +00:00
|
|
|
if (it->pro)
|
|
|
|
it->pro->deref();
|
|
|
|
it = parsed_files.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
2016-10-24 17:30:24 +00:00
|
|
|
}
|
2012-09-05 16:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////// Parser ///////////
|
|
|
|
|
|
|
|
#define fL1S(s) QString::fromLatin1(s)
|
|
|
|
|
|
|
|
namespace { // MSVC2010 doesn't seem to know the semantics of "static" ...
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
QString strelse;
|
|
|
|
QString strfor;
|
|
|
|
QString strdefineTest;
|
|
|
|
QString strdefineReplace;
|
2016-11-11 10:40:24 +00:00
|
|
|
QString strbypassNesting;
|
2012-09-05 16:29:19 +00:00
|
|
|
QString stroption;
|
2012-09-11 17:30:29 +00:00
|
|
|
QString strreturn;
|
|
|
|
QString strnext;
|
|
|
|
QString strbreak;
|
2012-09-05 16:29:19 +00:00
|
|
|
QString strhost_build;
|
|
|
|
QString strLINE;
|
|
|
|
QString strFILE;
|
|
|
|
QString strLITERAL_HASH;
|
|
|
|
QString strLITERAL_DOLLAR;
|
|
|
|
QString strLITERAL_WHITESPACE;
|
|
|
|
} statics;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::initialize()
|
|
|
|
{
|
|
|
|
if (!statics.strelse.isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
statics.strelse = QLatin1String("else");
|
|
|
|
statics.strfor = QLatin1String("for");
|
|
|
|
statics.strdefineTest = QLatin1String("defineTest");
|
|
|
|
statics.strdefineReplace = QLatin1String("defineReplace");
|
2016-11-11 10:40:24 +00:00
|
|
|
statics.strbypassNesting = QLatin1String("bypassNesting");
|
2012-09-05 16:29:19 +00:00
|
|
|
statics.stroption = QLatin1String("option");
|
2012-09-11 17:30:29 +00:00
|
|
|
statics.strreturn = QLatin1String("return");
|
|
|
|
statics.strnext = QLatin1String("next");
|
|
|
|
statics.strbreak = QLatin1String("break");
|
2012-09-05 16:29:19 +00:00
|
|
|
statics.strhost_build = QLatin1String("host_build");
|
|
|
|
statics.strLINE = QLatin1String("_LINE_");
|
|
|
|
statics.strFILE = QLatin1String("_FILE_");
|
|
|
|
statics.strLITERAL_HASH = QLatin1String("LITERAL_HASH");
|
|
|
|
statics.strLITERAL_DOLLAR = QLatin1String("LITERAL_DOLLAR");
|
|
|
|
statics.strLITERAL_WHITESPACE = QLatin1String("LITERAL_WHITESPACE");
|
|
|
|
}
|
|
|
|
|
2013-05-29 18:18:51 +00:00
|
|
|
QMakeParser::QMakeParser(ProFileCache *cache, QMakeVfs *vfs, QMakeParserHandler *handler)
|
2012-09-05 16:29:19 +00:00
|
|
|
: m_cache(cache)
|
|
|
|
, m_handler(handler)
|
2013-05-29 18:18:51 +00:00
|
|
|
, m_vfs(vfs)
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
|
|
|
// So that single-threaded apps don't have to call initialize() for now.
|
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
|
2013-07-24 17:28:33 +00:00
|
|
|
ProFile *QMakeParser::parsedProFile(const QString &fileName, ParseFlags flags)
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
|
|
|
ProFile *pro;
|
2016-10-24 17:30:24 +00:00
|
|
|
QMakeVfs::VfsFlags vfsFlags = ((flags & ParseCumulative) ? QMakeVfs::VfsCumulative
|
|
|
|
: QMakeVfs::VfsExact);
|
|
|
|
int id = m_vfs->idForFileName(fileName, vfsFlags);
|
2017-08-14 16:30:29 +00:00
|
|
|
if ((flags & ParseUseCache) && m_cache) {
|
2012-09-05 16:29:19 +00:00
|
|
|
ProFileCache::Entry *ent;
|
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
QMutexLocker locker(&m_cache->mutex);
|
|
|
|
#endif
|
2016-10-24 17:30:24 +00:00
|
|
|
auto it = m_cache->parsed_files.find(id);
|
2012-09-05 16:29:19 +00:00
|
|
|
if (it != m_cache->parsed_files.end()) {
|
|
|
|
ent = &*it;
|
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
if (ent->locker && !ent->locker->done) {
|
|
|
|
++ent->locker->waiters;
|
|
|
|
QThreadPool::globalInstance()->releaseThread();
|
|
|
|
ent->locker->cond.wait(locker.mutex());
|
|
|
|
QThreadPool::globalInstance()->reserveThread();
|
|
|
|
if (!--ent->locker->waiters) {
|
|
|
|
delete ent->locker;
|
|
|
|
ent->locker = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if ((pro = ent->pro))
|
|
|
|
pro->ref();
|
2017-08-14 16:30:29 +00:00
|
|
|
} else {
|
2016-10-24 17:30:24 +00:00
|
|
|
ent = &m_cache->parsed_files[id];
|
2012-09-05 16:29:19 +00:00
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
ent->locker = new ProFileCache::Entry::Locker;
|
|
|
|
locker.unlock();
|
|
|
|
#endif
|
2016-10-24 17:30:24 +00:00
|
|
|
QString contents;
|
|
|
|
if (readFile(id, flags, &contents)) {
|
2020-05-30 21:29:21 +00:00
|
|
|
pro = parsedProBlock(QStringView(contents), id, fileName, 1, FullGrammar);
|
2012-09-05 16:29:19 +00:00
|
|
|
pro->itemsRef()->squeeze();
|
|
|
|
pro->ref();
|
2016-10-24 17:30:24 +00:00
|
|
|
} else {
|
2018-08-02 22:22:24 +00:00
|
|
|
pro = nullptr;
|
2012-09-05 16:29:19 +00:00
|
|
|
}
|
|
|
|
ent->pro = pro;
|
|
|
|
#ifdef PROPARSER_THREAD_SAFE
|
|
|
|
locker.relock();
|
|
|
|
if (ent->locker->waiters) {
|
|
|
|
ent->locker->done = true;
|
|
|
|
ent->locker->cond.wakeAll();
|
|
|
|
} else {
|
|
|
|
delete ent->locker;
|
|
|
|
ent->locker = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2017-08-14 16:30:29 +00:00
|
|
|
} else {
|
2016-10-24 17:30:24 +00:00
|
|
|
QString contents;
|
|
|
|
if (readFile(id, flags, &contents))
|
2020-05-30 21:29:21 +00:00
|
|
|
pro = parsedProBlock(QStringView(contents), id, fileName, 1, FullGrammar);
|
2016-10-24 17:30:24 +00:00
|
|
|
else
|
2018-08-02 22:22:24 +00:00
|
|
|
pro = nullptr;
|
2012-09-05 16:29:19 +00:00
|
|
|
}
|
|
|
|
return pro;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProFile *QMakeParser::parsedProBlock(
|
2020-05-30 21:29:21 +00:00
|
|
|
QStringView contents, int id, const QString &name, int line, SubGrammar grammar)
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
2016-10-24 17:30:24 +00:00
|
|
|
ProFile *pro = new ProFile(id, name);
|
2015-02-02 17:52:24 +00:00
|
|
|
read(pro, contents, line, grammar);
|
2012-09-05 16:29:19 +00:00
|
|
|
return pro;
|
|
|
|
}
|
|
|
|
|
2016-10-24 17:30:24 +00:00
|
|
|
void QMakeParser::discardFileFromCache(int id)
|
2012-10-25 08:55:00 +00:00
|
|
|
{
|
|
|
|
if (m_cache)
|
2016-10-24 17:30:24 +00:00
|
|
|
m_cache->discardFile(id);
|
2012-10-25 08:55:00 +00:00
|
|
|
}
|
|
|
|
|
2016-10-24 17:30:24 +00:00
|
|
|
bool QMakeParser::readFile(int id, ParseFlags flags, QString *contents)
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
2013-05-29 18:18:51 +00:00
|
|
|
QString errStr;
|
2016-10-24 17:30:24 +00:00
|
|
|
QMakeVfs::ReadResult result = m_vfs->readFile(id, contents, &errStr);
|
2016-10-28 18:10:40 +00:00
|
|
|
if (result != QMakeVfs::ReadOk) {
|
|
|
|
if (m_handler && ((flags & ParseReportMissing) || result != QMakeVfs::ReadNotFound))
|
2012-09-05 16:29:19 +00:00
|
|
|
m_handler->message(QMakeParserHandler::ParserIoError,
|
2016-10-24 17:30:24 +00:00
|
|
|
fL1S("Cannot read %1: %2").arg(m_vfs->fileNameForId(id), errStr));
|
2012-09-05 16:29:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-02-02 17:52:24 +00:00
|
|
|
return true;
|
2012-09-05 16:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::putTok(ushort *&tokPtr, ushort tok)
|
|
|
|
{
|
|
|
|
*tokPtr++ = tok;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::putBlockLen(ushort *&tokPtr, uint len)
|
|
|
|
{
|
|
|
|
*tokPtr++ = (ushort)len;
|
|
|
|
*tokPtr++ = (ushort)(len >> 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::putBlock(ushort *&tokPtr, const ushort *buf, uint len)
|
|
|
|
{
|
|
|
|
memcpy(tokPtr, buf, len * 2);
|
|
|
|
tokPtr += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::putHashStr(ushort *&pTokPtr, const ushort *buf, uint len)
|
|
|
|
{
|
2020-10-02 11:19:48 +00:00
|
|
|
const size_t hash = ProString::hash((const QChar *)buf, len);
|
2012-09-05 16:29:19 +00:00
|
|
|
ushort *tokPtr = pTokPtr;
|
|
|
|
*tokPtr++ = (ushort)hash;
|
|
|
|
*tokPtr++ = (ushort)(hash >> 16);
|
|
|
|
*tokPtr++ = (ushort)len;
|
2016-03-07 14:29:44 +00:00
|
|
|
if (len) // buf may be nullptr; don't pass that to memcpy (-> undefined behavior)
|
|
|
|
memcpy(tokPtr, buf, len * 2);
|
2012-09-05 16:29:19 +00:00
|
|
|
pTokPtr = tokPtr + len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::finalizeHashStr(ushort *buf, uint len)
|
|
|
|
{
|
|
|
|
buf[-4] = TokHashLiteral;
|
|
|
|
buf[-1] = len;
|
2020-10-02 11:19:48 +00:00
|
|
|
const size_t hash = ProString::hash((const QChar *)buf, len);
|
2012-09-05 16:29:19 +00:00
|
|
|
buf[-3] = (ushort)hash;
|
|
|
|
buf[-2] = (ushort)(hash >> 16);
|
|
|
|
}
|
|
|
|
|
2020-05-30 21:29:21 +00:00
|
|
|
void QMakeParser::read(ProFile *pro, QStringView in, int line, SubGrammar grammar)
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
|
|
|
m_proFile = pro;
|
|
|
|
m_lineNo = line;
|
|
|
|
|
|
|
|
// Final precompiled token stream buffer
|
|
|
|
QString tokBuff;
|
|
|
|
// Worst-case size calculations:
|
|
|
|
// - line marker adds 1 (2-nl) to 1st token of each line
|
|
|
|
// - empty assignment "A=":2 =>
|
2016-07-05 18:00:17 +00:00
|
|
|
// TokHashLiteral(1) + hash(2) + len(1) + "A"(1) + TokAssign(1) + size_hint(1) +
|
2012-09-05 19:26:28 +00:00
|
|
|
// TokValueTerminator(1) == 8 (9)
|
2012-09-05 16:29:19 +00:00
|
|
|
// - non-empty assignment "A=B C":5 =>
|
2016-07-05 18:00:17 +00:00
|
|
|
// TokHashLiteral(1) + hash(2) + len(1) + "A"(1) + TokAssign(1) + size_hint(1) +
|
2012-09-05 16:29:19 +00:00
|
|
|
// TokLiteral(1) + len(1) + "B"(1) +
|
2012-09-05 19:26:28 +00:00
|
|
|
// TokLiteral(1) + len(1) + "C"(1) + TokValueTerminator(1) == 14 (15)
|
2012-09-05 16:29:19 +00:00
|
|
|
// - variable expansion: "$$f":3 =>
|
|
|
|
// TokVariable(1) + hash(2) + len(1) + "f"(1) = 5
|
|
|
|
// - function expansion: "$$f()":5 =>
|
|
|
|
// TokFuncName(1) + hash(2) + len(1) + "f"(1) + TokFuncTerminator(1) = 6
|
2016-07-05 18:00:17 +00:00
|
|
|
// - test literal: "X":1 =>
|
|
|
|
// TokHashLiteral(1) + hash(2) + len(1) + "A"(1) + TokCondition(1) = 6 (7)
|
2012-09-05 16:29:19 +00:00
|
|
|
// - scope: "X:":2 =>
|
|
|
|
// TokHashLiteral(1) + hash(2) + len(1) + "A"(1) + TokCondition(1) +
|
2016-07-05 18:00:17 +00:00
|
|
|
// TokBranch(1) + len(2) + ... + len(2) + ... == 11 (12)
|
|
|
|
// - test call: "X():":4 =>
|
2012-09-05 16:29:19 +00:00
|
|
|
// TokHashLiteral(1) + hash(2) + len(1) + "A"(1) + TokTestCall(1) + TokFuncTerminator(1) +
|
2016-07-05 18:00:17 +00:00
|
|
|
// TokBranch(1) + len(2) + ... + len(2) + ... == 12 (13)
|
2012-09-05 16:29:19 +00:00
|
|
|
// - "for(A,B):":9 =>
|
|
|
|
// TokForLoop(1) + hash(2) + len(1) + "A"(1) +
|
|
|
|
// len(2) + TokLiteral(1) + len(1) + "B"(1) + TokValueTerminator(1) +
|
|
|
|
// len(2) + ... + TokTerminator(1) == 14 (15)
|
2016-07-05 18:00:17 +00:00
|
|
|
// One extra for possibly missing trailing newline.
|
|
|
|
tokBuff.reserve((in.size() + 1) * 7);
|
2012-09-05 16:29:19 +00:00
|
|
|
ushort *tokPtr = (ushort *)tokBuff.constData(); // Current writing position
|
|
|
|
|
|
|
|
// Expression precompiler buffer.
|
|
|
|
QString xprBuff;
|
|
|
|
xprBuff.reserve(tokBuff.capacity()); // Excessive, but simple
|
|
|
|
ushort *buf = (ushort *)xprBuff.constData();
|
|
|
|
|
|
|
|
// Parser state
|
|
|
|
m_blockstack.clear();
|
|
|
|
m_blockstack.resize(1);
|
|
|
|
|
|
|
|
QStack<ParseCtx> xprStack;
|
|
|
|
xprStack.reserve(10);
|
|
|
|
|
2020-05-30 21:29:21 +00:00
|
|
|
const ushort *cur = (const ushort *)in.data();
|
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that the on() matcher has been replaced by one that doesn't
ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache,
to avoid porting calls that explicitly test count().
Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-09-30 12:09:04 +00:00
|
|
|
const ushort *inend = cur + in.size();
|
2012-09-05 16:29:19 +00:00
|
|
|
m_canElse = false;
|
|
|
|
freshLine:
|
|
|
|
m_state = StNew;
|
2015-02-19 12:25:10 +00:00
|
|
|
m_invert = 0;
|
2012-09-05 16:29:19 +00:00
|
|
|
m_operator = NoOperator;
|
|
|
|
m_markLine = m_lineNo;
|
|
|
|
m_inError = false;
|
|
|
|
int parens = 0; // Braces in value context
|
|
|
|
int argc = 0;
|
|
|
|
int wordCount = 0; // Number of words in currently accumulated expression
|
|
|
|
int lastIndent = 0; // Previous line's indentation, to detect accidental continuation abuse
|
|
|
|
bool lineMarked = true; // For in-expression markers
|
2020-05-06 09:08:00 +00:00
|
|
|
char16_t needSep = TokNewStr; // Met unquoted whitespace
|
|
|
|
char16_t quote = 0;
|
|
|
|
char16_t term = 0;
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
Context context;
|
|
|
|
ushort *ptr;
|
|
|
|
if (grammar == ValueGrammar) {
|
|
|
|
context = CtxPureValue;
|
|
|
|
ptr = tokPtr + 2;
|
|
|
|
} else {
|
|
|
|
context = CtxTest;
|
|
|
|
ptr = buf + 4;
|
|
|
|
}
|
|
|
|
ushort *xprPtr = ptr;
|
|
|
|
|
|
|
|
#define FLUSH_LHS_LITERAL() \
|
|
|
|
do { \
|
|
|
|
if ((tlen = ptr - xprPtr)) { \
|
|
|
|
finalizeHashStr(xprPtr, tlen); \
|
|
|
|
if (needSep) { \
|
|
|
|
wordCount++; \
|
|
|
|
needSep = 0; \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
ptr -= 4; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define FLUSH_RHS_LITERAL() \
|
|
|
|
do { \
|
|
|
|
if ((tlen = ptr - xprPtr)) { \
|
|
|
|
xprPtr[-2] = TokLiteral | needSep; \
|
|
|
|
xprPtr[-1] = tlen; \
|
|
|
|
if (needSep) { \
|
|
|
|
wordCount++; \
|
|
|
|
needSep = 0; \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
ptr -= 2; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define FLUSH_LITERAL() \
|
|
|
|
do { \
|
|
|
|
if (context == CtxTest) \
|
|
|
|
FLUSH_LHS_LITERAL(); \
|
|
|
|
else \
|
|
|
|
FLUSH_RHS_LITERAL(); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define FLUSH_VALUE_LIST() \
|
|
|
|
do { \
|
|
|
|
if (wordCount > 1) { \
|
|
|
|
xprPtr = tokPtr; \
|
|
|
|
if (*xprPtr == TokLine) \
|
|
|
|
xprPtr += 2; \
|
|
|
|
tokPtr[-1] = ((*xprPtr & TokMask) == TokLiteral) ? wordCount : 0; \
|
|
|
|
} else { \
|
|
|
|
tokPtr[-1] = 0; \
|
|
|
|
} \
|
|
|
|
tokPtr = ptr; \
|
|
|
|
putTok(tokPtr, TokValueTerminator); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
const ushort *end; // End of this line
|
|
|
|
const ushort *cptr; // Start of next line
|
|
|
|
bool lineCont;
|
|
|
|
int indent;
|
|
|
|
|
|
|
|
if (context == CtxPureValue) {
|
2016-05-13 13:32:50 +00:00
|
|
|
end = inend;
|
2018-08-02 22:22:24 +00:00
|
|
|
cptr = nullptr;
|
2012-09-05 16:29:19 +00:00
|
|
|
lineCont = false;
|
|
|
|
indent = 0; // just gcc being stupid
|
|
|
|
goto nextChr;
|
|
|
|
}
|
|
|
|
|
|
|
|
forever {
|
2020-05-06 09:08:00 +00:00
|
|
|
char16_t c;
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
// First, skip leading whitespace
|
|
|
|
for (indent = 0; ; ++cur, ++indent) {
|
2016-05-13 13:32:50 +00:00
|
|
|
if (cur == inend) {
|
2018-08-02 22:22:24 +00:00
|
|
|
cur = nullptr;
|
2016-05-13 13:32:50 +00:00
|
|
|
goto flushLine;
|
|
|
|
}
|
2012-09-05 16:29:19 +00:00
|
|
|
c = *cur;
|
|
|
|
if (c == '\n') {
|
|
|
|
++cur;
|
|
|
|
goto flushLine;
|
|
|
|
}
|
2016-05-13 13:32:50 +00:00
|
|
|
if (c != ' ' && c != '\t' && c != '\r')
|
|
|
|
break;
|
2012-09-05 16:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Then strip comments. Yep - no escaping is possible.
|
|
|
|
for (cptr = cur;; ++cptr) {
|
2016-05-13 13:32:50 +00:00
|
|
|
if (cptr == inend) {
|
|
|
|
end = cptr;
|
|
|
|
break;
|
|
|
|
}
|
2012-09-05 16:29:19 +00:00
|
|
|
c = *cptr;
|
|
|
|
if (c == '#') {
|
2016-05-13 13:32:50 +00:00
|
|
|
end = cptr;
|
|
|
|
while (++cptr < inend) {
|
|
|
|
if (*cptr == '\n') {
|
2012-09-05 16:29:19 +00:00
|
|
|
++cptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (end == cur) { // Line with only a comment (sans whitespace)
|
|
|
|
if (m_markLine == m_lineNo)
|
|
|
|
m_markLine++;
|
|
|
|
// Qmake bizarreness: such lines do not affect line continuations
|
|
|
|
goto ignore;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (c == '\n') {
|
|
|
|
end = cptr++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then look for line continuations. Yep - no escaping here as well.
|
|
|
|
forever {
|
|
|
|
// We don't have to check for underrun here, as we already determined
|
|
|
|
// that the line is non-empty.
|
|
|
|
ushort ec = *(end - 1);
|
|
|
|
if (ec == '\\') {
|
|
|
|
--end;
|
|
|
|
lineCont = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ec != ' ' && ec != '\t' && ec != '\r') {
|
|
|
|
lineCont = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--end;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, do the tokenization
|
|
|
|
ushort tok, rtok;
|
|
|
|
int tlen;
|
|
|
|
newWord:
|
|
|
|
do {
|
|
|
|
if (cur == end)
|
|
|
|
goto lineEnd;
|
|
|
|
c = *cur++;
|
|
|
|
} while (c == ' ' || c == '\t');
|
|
|
|
forever {
|
|
|
|
if (c == '$') {
|
|
|
|
if (*cur == '$') { // may be EOF, EOL, WS, '#' or '\\' if past end
|
|
|
|
cur++;
|
|
|
|
FLUSH_LITERAL();
|
|
|
|
if (!lineMarked) {
|
|
|
|
lineMarked = true;
|
|
|
|
*ptr++ = TokLine;
|
|
|
|
*ptr++ = (ushort)m_lineNo;
|
|
|
|
}
|
|
|
|
term = 0;
|
|
|
|
tok = TokVariable;
|
|
|
|
c = *cur;
|
|
|
|
if (c == '[') {
|
|
|
|
ptr += 4;
|
|
|
|
tok = TokProperty;
|
|
|
|
term = ']';
|
|
|
|
c = *++cur;
|
|
|
|
} else if (c == '{') {
|
|
|
|
ptr += 4;
|
|
|
|
term = '}';
|
|
|
|
c = *++cur;
|
|
|
|
} else if (c == '(') {
|
|
|
|
ptr += 2;
|
|
|
|
tok = TokEnvVar;
|
|
|
|
term = ')';
|
|
|
|
c = *++cur;
|
|
|
|
} else {
|
|
|
|
ptr += 4;
|
|
|
|
}
|
|
|
|
xprPtr = ptr;
|
|
|
|
rtok = tok;
|
|
|
|
while ((c & 0xFF00) || c == '.' || c == '_' ||
|
|
|
|
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
|
|
|
|
(c >= '0' && c <= '9') || (c == '/' && term)) {
|
|
|
|
*ptr++ = c;
|
|
|
|
if (++cur == end) {
|
|
|
|
c = 0;
|
|
|
|
goto notfunc;
|
|
|
|
}
|
|
|
|
c = *cur;
|
|
|
|
}
|
|
|
|
if (tok == TokVariable && c == '(')
|
|
|
|
tok = TokFuncName;
|
|
|
|
notfunc:
|
|
|
|
if (ptr == xprPtr)
|
|
|
|
languageWarning(fL1S("Missing name in expansion"));
|
|
|
|
if (quote)
|
|
|
|
tok |= TokQuoted;
|
|
|
|
if (needSep) {
|
|
|
|
tok |= needSep;
|
|
|
|
wordCount++;
|
|
|
|
}
|
|
|
|
tlen = ptr - xprPtr;
|
|
|
|
if (rtok != TokVariable
|
|
|
|
|| !resolveVariable(xprPtr, tlen, needSep, &ptr,
|
|
|
|
&buf, &xprBuff, &tokPtr, &tokBuff, cur, in)) {
|
|
|
|
if (rtok == TokVariable || rtok == TokProperty) {
|
|
|
|
xprPtr[-4] = tok;
|
2020-10-02 11:19:48 +00:00
|
|
|
const size_t hash = ProString::hash((const QChar *)xprPtr, tlen);
|
2012-09-05 16:29:19 +00:00
|
|
|
xprPtr[-3] = (ushort)hash;
|
|
|
|
xprPtr[-2] = (ushort)(hash >> 16);
|
|
|
|
xprPtr[-1] = tlen;
|
|
|
|
} else {
|
|
|
|
xprPtr[-2] = tok;
|
|
|
|
xprPtr[-1] = tlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((tok & TokMask) == TokFuncName) {
|
|
|
|
cur++;
|
|
|
|
funcCall:
|
|
|
|
{
|
|
|
|
xprStack.resize(xprStack.size() + 1);
|
|
|
|
ParseCtx &top = xprStack.top();
|
|
|
|
top.parens = parens;
|
|
|
|
top.quote = quote;
|
|
|
|
top.terminator = term;
|
|
|
|
top.context = context;
|
|
|
|
top.argc = argc;
|
|
|
|
top.wordCount = wordCount;
|
|
|
|
}
|
|
|
|
parens = 0;
|
|
|
|
quote = 0;
|
|
|
|
term = 0;
|
|
|
|
argc = 1;
|
|
|
|
context = CtxArgs;
|
|
|
|
nextToken:
|
|
|
|
wordCount = 0;
|
|
|
|
nextWord:
|
|
|
|
ptr += (context == CtxTest) ? 4 : 2;
|
|
|
|
xprPtr = ptr;
|
|
|
|
needSep = TokNewStr;
|
|
|
|
goto newWord;
|
|
|
|
}
|
|
|
|
if (term) {
|
|
|
|
checkTerm:
|
|
|
|
if (c != term) {
|
|
|
|
parseError(fL1S("Missing %1 terminator [found %2]")
|
|
|
|
.arg(QChar(term))
|
2019-06-18 18:11:18 +00:00
|
|
|
.arg(c ? QString(QChar(c)) : QString::fromLatin1("end-of-line")));
|
2012-09-05 16:29:19 +00:00
|
|
|
m_inError = true;
|
|
|
|
// Just parse on, as if there was a terminator ...
|
|
|
|
} else {
|
|
|
|
cur++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
joinToken:
|
|
|
|
ptr += (context == CtxTest) ? 4 : 2;
|
|
|
|
xprPtr = ptr;
|
|
|
|
needSep = 0;
|
|
|
|
goto nextChr;
|
|
|
|
}
|
|
|
|
} else if (c == '\\') {
|
|
|
|
static const char symbols[] = "[]{}()$\\'\"";
|
2020-05-06 09:08:00 +00:00
|
|
|
char16_t c2;
|
2012-09-05 16:29:19 +00:00
|
|
|
if (cur != end && !((c2 = *cur) & 0xff00) && strchr(symbols, c2)) {
|
|
|
|
c = c2;
|
|
|
|
cur++;
|
|
|
|
} else {
|
|
|
|
deprecationWarning(fL1S("Unescaped backslashes are deprecated"));
|
|
|
|
}
|
|
|
|
} else if (quote) {
|
|
|
|
if (c == quote) {
|
|
|
|
quote = 0;
|
|
|
|
goto nextChr;
|
|
|
|
} else if (c == '!' && ptr == xprPtr && context == CtxTest) {
|
2015-02-19 12:25:10 +00:00
|
|
|
m_invert++;
|
2012-09-05 16:29:19 +00:00
|
|
|
goto nextChr;
|
|
|
|
}
|
|
|
|
} else if (c == '\'' || c == '"') {
|
|
|
|
quote = c;
|
|
|
|
goto nextChr;
|
|
|
|
} else if (context == CtxArgs) {
|
|
|
|
// Function arg context
|
|
|
|
if (c == ' ' || c == '\t') {
|
|
|
|
FLUSH_RHS_LITERAL();
|
|
|
|
goto nextWord;
|
|
|
|
} else if (c == '(') {
|
|
|
|
++parens;
|
|
|
|
} else if (c == ')') {
|
|
|
|
if (--parens < 0) {
|
|
|
|
FLUSH_RHS_LITERAL();
|
|
|
|
*ptr++ = TokFuncTerminator;
|
|
|
|
int theargc = argc;
|
|
|
|
{
|
|
|
|
ParseCtx &top = xprStack.top();
|
|
|
|
parens = top.parens;
|
|
|
|
quote = top.quote;
|
|
|
|
term = top.terminator;
|
|
|
|
context = top.context;
|
|
|
|
argc = top.argc;
|
|
|
|
wordCount = top.wordCount;
|
|
|
|
xprStack.resize(xprStack.size() - 1);
|
|
|
|
}
|
|
|
|
if (term == ':') {
|
|
|
|
finalizeCall(tokPtr, buf, ptr, theargc);
|
|
|
|
goto nextItem;
|
|
|
|
} else if (term == '}') {
|
|
|
|
c = (cur == end) ? 0 : *cur;
|
|
|
|
goto checkTerm;
|
|
|
|
} else {
|
|
|
|
Q_ASSERT(!term);
|
|
|
|
goto joinToken;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!parens && c == ',') {
|
|
|
|
FLUSH_RHS_LITERAL();
|
|
|
|
*ptr++ = TokArgSeparator;
|
|
|
|
argc++;
|
|
|
|
goto nextToken;
|
|
|
|
}
|
|
|
|
} else if (context == CtxTest) {
|
|
|
|
// Test or LHS context
|
|
|
|
if (c == ' ' || c == '\t') {
|
|
|
|
FLUSH_LHS_LITERAL();
|
|
|
|
goto nextWord;
|
|
|
|
} else if (c == '(') {
|
|
|
|
FLUSH_LHS_LITERAL();
|
|
|
|
if (wordCount != 1) {
|
|
|
|
if (wordCount)
|
|
|
|
parseError(fL1S("Extra characters after test expression."));
|
|
|
|
else
|
|
|
|
parseError(fL1S("Opening parenthesis without prior test name."));
|
|
|
|
ptr = buf; // Put empty function name
|
|
|
|
}
|
|
|
|
*ptr++ = TokTestCall;
|
|
|
|
term = ':';
|
|
|
|
goto funcCall;
|
|
|
|
} else if (c == '!' && ptr == xprPtr) {
|
2015-02-19 12:25:10 +00:00
|
|
|
m_invert++;
|
2012-09-05 16:29:19 +00:00
|
|
|
goto nextChr;
|
|
|
|
} else if (c == ':') {
|
|
|
|
FLUSH_LHS_LITERAL();
|
|
|
|
finalizeCond(tokPtr, buf, ptr, wordCount);
|
2015-02-18 10:20:01 +00:00
|
|
|
warnOperator("in front of AND operator");
|
2012-09-05 16:29:19 +00:00
|
|
|
if (m_state == StNew)
|
2015-02-18 09:55:10 +00:00
|
|
|
parseError(fL1S("AND operator without prior condition."));
|
2012-09-05 16:29:19 +00:00
|
|
|
else
|
|
|
|
m_operator = AndOperator;
|
|
|
|
nextItem:
|
|
|
|
ptr = buf;
|
|
|
|
goto nextToken;
|
|
|
|
} else if (c == '|') {
|
|
|
|
FLUSH_LHS_LITERAL();
|
|
|
|
finalizeCond(tokPtr, buf, ptr, wordCount);
|
2015-02-18 10:20:01 +00:00
|
|
|
warnOperator("in front of OR operator");
|
2012-09-05 16:29:19 +00:00
|
|
|
if (m_state != StCond)
|
2015-02-18 09:55:10 +00:00
|
|
|
parseError(fL1S("OR operator without prior condition."));
|
2012-09-05 16:29:19 +00:00
|
|
|
else
|
|
|
|
m_operator = OrOperator;
|
|
|
|
goto nextItem;
|
|
|
|
} else if (c == '{') {
|
|
|
|
FLUSH_LHS_LITERAL();
|
|
|
|
finalizeCond(tokPtr, buf, ptr, wordCount);
|
2015-02-18 10:20:01 +00:00
|
|
|
if (m_operator == AndOperator) {
|
|
|
|
languageWarning(fL1S("Excess colon in front of opening brace."));
|
|
|
|
m_operator = NoOperator;
|
|
|
|
}
|
|
|
|
failOperator("in front of opening brace");
|
2012-09-05 16:29:19 +00:00
|
|
|
flushCond(tokPtr);
|
2015-02-18 10:20:01 +00:00
|
|
|
m_state = StNew; // Reset possible StCtrl, so colons get rejected.
|
2012-09-05 16:29:19 +00:00
|
|
|
++m_blockstack.top().braceLevel;
|
2015-02-18 16:32:34 +00:00
|
|
|
if (grammar == TestGrammar)
|
2012-09-05 16:29:19 +00:00
|
|
|
parseError(fL1S("Opening scope not permitted in this context."));
|
|
|
|
goto nextItem;
|
|
|
|
} else if (c == '}') {
|
|
|
|
FLUSH_LHS_LITERAL();
|
|
|
|
finalizeCond(tokPtr, buf, ptr, wordCount);
|
2015-02-18 10:17:06 +00:00
|
|
|
m_state = StNew; // De-facto newline
|
2012-09-05 16:29:19 +00:00
|
|
|
closeScope:
|
2015-02-18 10:17:06 +00:00
|
|
|
flushScopes(tokPtr);
|
2015-02-18 10:20:01 +00:00
|
|
|
failOperator("in front of closing brace");
|
2012-09-05 16:29:19 +00:00
|
|
|
if (!m_blockstack.top().braceLevel) {
|
|
|
|
parseError(fL1S("Excess closing brace."));
|
|
|
|
} else if (!--m_blockstack.top().braceLevel
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
&& m_blockstack.size() != 1) {
|
2012-09-05 16:29:19 +00:00
|
|
|
leaveScope(tokPtr);
|
|
|
|
m_state = StNew;
|
|
|
|
m_canElse = false;
|
|
|
|
m_markLine = m_lineNo;
|
|
|
|
}
|
|
|
|
goto nextItem;
|
|
|
|
} else if (c == '+') {
|
|
|
|
tok = TokAppend;
|
|
|
|
goto do2Op;
|
|
|
|
} else if (c == '-') {
|
|
|
|
tok = TokRemove;
|
|
|
|
goto do2Op;
|
|
|
|
} else if (c == '*') {
|
|
|
|
tok = TokAppendUnique;
|
|
|
|
goto do2Op;
|
|
|
|
} else if (c == '~') {
|
|
|
|
tok = TokReplace;
|
|
|
|
do2Op:
|
|
|
|
if (*cur == '=') {
|
|
|
|
cur++;
|
|
|
|
goto doOp;
|
|
|
|
}
|
|
|
|
} else if (c == '=') {
|
|
|
|
tok = TokAssign;
|
|
|
|
doOp:
|
|
|
|
FLUSH_LHS_LITERAL();
|
|
|
|
flushCond(tokPtr);
|
2015-02-18 10:20:01 +00:00
|
|
|
acceptColon("in front of assignment");
|
2012-09-05 16:29:19 +00:00
|
|
|
putLineMarker(tokPtr);
|
|
|
|
if (grammar == TestGrammar) {
|
|
|
|
parseError(fL1S("Assignment not permitted in this context."));
|
|
|
|
} else if (wordCount != 1) {
|
|
|
|
parseError(fL1S("Assignment needs exactly one word on the left hand side."));
|
|
|
|
// Put empty variable name.
|
|
|
|
} else {
|
|
|
|
putBlock(tokPtr, buf, ptr - buf);
|
|
|
|
}
|
|
|
|
putTok(tokPtr, tok);
|
|
|
|
context = CtxValue;
|
|
|
|
ptr = ++tokPtr;
|
|
|
|
goto nextToken;
|
|
|
|
}
|
|
|
|
} else if (context == CtxValue) {
|
|
|
|
if (c == ' ' || c == '\t') {
|
|
|
|
FLUSH_RHS_LITERAL();
|
|
|
|
goto nextWord;
|
|
|
|
} else if (c == '{') {
|
|
|
|
++parens;
|
|
|
|
} else if (c == '}') {
|
|
|
|
if (!parens) {
|
|
|
|
FLUSH_RHS_LITERAL();
|
|
|
|
FLUSH_VALUE_LIST();
|
|
|
|
context = CtxTest;
|
|
|
|
goto closeScope;
|
|
|
|
}
|
|
|
|
--parens;
|
|
|
|
} else if (c == '=') {
|
|
|
|
if (indent < lastIndent)
|
|
|
|
languageWarning(fL1S("Possible accidental line continuation"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ptr++ = c;
|
|
|
|
nextChr:
|
|
|
|
if (cur == end)
|
|
|
|
goto lineEnd;
|
|
|
|
c = *cur++;
|
|
|
|
}
|
|
|
|
|
|
|
|
lineEnd:
|
|
|
|
if (lineCont) {
|
|
|
|
if (quote) {
|
2012-09-03 15:05:33 +00:00
|
|
|
*ptr++ = ' ';
|
2012-09-05 16:29:19 +00:00
|
|
|
} else {
|
|
|
|
FLUSH_LITERAL();
|
|
|
|
needSep = TokNewStr;
|
|
|
|
ptr += (context == CtxTest) ? 4 : 2;
|
|
|
|
xprPtr = ptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cur = cptr;
|
|
|
|
flushLine:
|
|
|
|
FLUSH_LITERAL();
|
|
|
|
if (quote) {
|
|
|
|
parseError(fL1S("Missing closing %1 quote").arg(QChar(quote)));
|
|
|
|
if (!xprStack.isEmpty()) {
|
|
|
|
context = xprStack.at(0).context;
|
|
|
|
xprStack.clear();
|
|
|
|
}
|
|
|
|
goto flErr;
|
|
|
|
} else if (!xprStack.isEmpty()) {
|
|
|
|
parseError(fL1S("Missing closing parenthesis in function call"));
|
|
|
|
context = xprStack.at(0).context;
|
|
|
|
xprStack.clear();
|
|
|
|
flErr:
|
|
|
|
pro->setOk(false);
|
|
|
|
if (context == CtxValue) {
|
|
|
|
tokPtr[-1] = 0; // sizehint
|
|
|
|
putTok(tokPtr, TokValueTerminator);
|
|
|
|
} else if (context == CtxPureValue) {
|
|
|
|
putTok(tokPtr, TokValueTerminator);
|
|
|
|
} else {
|
2015-02-19 19:53:53 +00:00
|
|
|
bogusTest(tokPtr, QString());
|
2012-09-05 16:29:19 +00:00
|
|
|
}
|
|
|
|
} else if (context == CtxValue) {
|
|
|
|
FLUSH_VALUE_LIST();
|
|
|
|
if (parens)
|
|
|
|
languageWarning(fL1S("Possible braces mismatch"));
|
|
|
|
} else if (context == CtxPureValue) {
|
|
|
|
tokPtr = ptr;
|
|
|
|
putTok(tokPtr, TokValueTerminator);
|
|
|
|
} else {
|
|
|
|
finalizeCond(tokPtr, buf, ptr, wordCount);
|
2015-02-18 10:20:01 +00:00
|
|
|
warnOperator("at end of line");
|
2012-09-05 16:29:19 +00:00
|
|
|
}
|
|
|
|
if (!cur)
|
|
|
|
break;
|
|
|
|
++m_lineNo;
|
|
|
|
goto freshLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastIndent = indent;
|
|
|
|
lineMarked = false;
|
|
|
|
ignore:
|
|
|
|
cur = cptr;
|
|
|
|
++m_lineNo;
|
|
|
|
}
|
|
|
|
|
|
|
|
flushScopes(tokPtr);
|
2015-02-19 13:05:27 +00:00
|
|
|
if (m_blockstack.size() > 1 || m_blockstack.top().braceLevel)
|
2012-09-05 16:29:19 +00:00
|
|
|
parseError(fL1S("Missing closing brace(s)."));
|
|
|
|
while (m_blockstack.size())
|
|
|
|
leaveScope(tokPtr);
|
|
|
|
tokBuff.resize(tokPtr - (ushort *)tokBuff.constData()); // Reserved capacity stays
|
|
|
|
*pro->itemsRef() = tokBuff;
|
|
|
|
|
|
|
|
#undef FLUSH_VALUE_LIST
|
|
|
|
#undef FLUSH_LITERAL
|
|
|
|
#undef FLUSH_LHS_LITERAL
|
|
|
|
#undef FLUSH_RHS_LITERAL
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::putLineMarker(ushort *&tokPtr)
|
|
|
|
{
|
|
|
|
if (m_markLine) {
|
|
|
|
*tokPtr++ = TokLine;
|
|
|
|
*tokPtr++ = (ushort)m_markLine;
|
|
|
|
m_markLine = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::enterScope(ushort *&tokPtr, bool special, ScopeState state)
|
|
|
|
{
|
2012-09-11 17:30:29 +00:00
|
|
|
uchar nest = m_blockstack.top().nest;
|
2012-09-05 16:29:19 +00:00
|
|
|
m_blockstack.resize(m_blockstack.size() + 1);
|
|
|
|
m_blockstack.top().special = special;
|
|
|
|
m_blockstack.top().start = tokPtr;
|
2012-09-11 17:30:29 +00:00
|
|
|
m_blockstack.top().nest = nest;
|
2012-09-05 16:29:19 +00:00
|
|
|
tokPtr += 2;
|
|
|
|
m_state = state;
|
|
|
|
m_canElse = false;
|
|
|
|
if (special)
|
|
|
|
m_markLine = m_lineNo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::leaveScope(ushort *&tokPtr)
|
|
|
|
{
|
|
|
|
if (m_blockstack.top().inBranch) {
|
|
|
|
// Put empty else block
|
|
|
|
putBlockLen(tokPtr, 0);
|
|
|
|
}
|
|
|
|
if (ushort *start = m_blockstack.top().start) {
|
|
|
|
putTok(tokPtr, TokTerminator);
|
|
|
|
uint len = tokPtr - start - 2;
|
|
|
|
start[0] = (ushort)len;
|
|
|
|
start[1] = (ushort)(len >> 16);
|
|
|
|
}
|
|
|
|
m_blockstack.resize(m_blockstack.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are on a fresh line, close all open one-line scopes.
|
|
|
|
void QMakeParser::flushScopes(ushort *&tokPtr)
|
|
|
|
{
|
|
|
|
if (m_state == StNew) {
|
|
|
|
while (!m_blockstack.top().braceLevel && m_blockstack.size() > 1)
|
|
|
|
leaveScope(tokPtr);
|
|
|
|
if (m_blockstack.top().inBranch) {
|
|
|
|
m_blockstack.top().inBranch = false;
|
|
|
|
// Put empty else block
|
|
|
|
putBlockLen(tokPtr, 0);
|
|
|
|
}
|
|
|
|
m_canElse = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is a pending conditional, enter a new scope, otherwise flush scopes.
|
|
|
|
void QMakeParser::flushCond(ushort *&tokPtr)
|
|
|
|
{
|
|
|
|
if (m_state == StCond) {
|
|
|
|
putTok(tokPtr, TokBranch);
|
|
|
|
m_blockstack.top().inBranch = true;
|
|
|
|
enterScope(tokPtr, false, StNew);
|
|
|
|
} else {
|
|
|
|
flushScopes(tokPtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 10:20:01 +00:00
|
|
|
void QMakeParser::warnOperator(const char *msg)
|
|
|
|
{
|
|
|
|
if (m_invert) {
|
|
|
|
languageWarning(fL1S("Stray NOT operator %1.").arg(fL1S(msg)));
|
2015-02-19 12:25:10 +00:00
|
|
|
m_invert = 0;
|
2015-02-18 10:20:01 +00:00
|
|
|
}
|
|
|
|
if (m_operator == AndOperator) {
|
|
|
|
languageWarning(fL1S("Stray AND operator %1.").arg(fL1S(msg)));
|
|
|
|
m_operator = NoOperator;
|
|
|
|
} else if (m_operator == OrOperator) {
|
|
|
|
languageWarning(fL1S("Stray OR operator %1.").arg(fL1S(msg)));
|
|
|
|
m_operator = NoOperator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QMakeParser::failOperator(const char *msg)
|
|
|
|
{
|
|
|
|
bool fail = false;
|
|
|
|
if (m_invert) {
|
|
|
|
parseError(fL1S("Unexpected NOT operator %1.").arg(fL1S(msg)));
|
2015-02-19 12:25:10 +00:00
|
|
|
m_invert = 0;
|
2015-02-18 10:20:01 +00:00
|
|
|
fail = true;
|
|
|
|
}
|
|
|
|
if (m_operator == AndOperator) {
|
|
|
|
parseError(fL1S("Unexpected AND operator %1.").arg(fL1S(msg)));
|
|
|
|
m_operator = NoOperator;
|
|
|
|
fail = true;
|
|
|
|
} else if (m_operator == OrOperator) {
|
|
|
|
parseError(fL1S("Unexpected OR operator %1.").arg(fL1S(msg)));
|
|
|
|
m_operator = NoOperator;
|
|
|
|
fail = true;
|
|
|
|
}
|
|
|
|
return fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QMakeParser::acceptColon(const char *msg)
|
|
|
|
{
|
|
|
|
if (m_operator == AndOperator)
|
|
|
|
m_operator = NoOperator;
|
|
|
|
return !failOperator(msg);
|
|
|
|
}
|
|
|
|
|
2015-02-17 19:45:08 +00:00
|
|
|
void QMakeParser::putOperator(ushort *&tokPtr)
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
2015-02-18 09:54:24 +00:00
|
|
|
if (m_operator== AndOperator) {
|
|
|
|
// A colon must be used after else and for() if no brace is used,
|
|
|
|
// but in this case it is obviously not a binary operator.
|
|
|
|
if (m_state == StCond)
|
|
|
|
putTok(tokPtr, TokAnd);
|
|
|
|
m_operator = NoOperator;
|
|
|
|
} else if (m_operator == OrOperator) {
|
|
|
|
putTok(tokPtr, TokOr);
|
2012-09-05 16:29:19 +00:00
|
|
|
m_operator = NoOperator;
|
|
|
|
}
|
2015-02-17 19:45:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::finalizeTest(ushort *&tokPtr)
|
|
|
|
{
|
|
|
|
flushScopes(tokPtr);
|
|
|
|
putLineMarker(tokPtr);
|
|
|
|
putOperator(tokPtr);
|
2015-02-19 12:25:10 +00:00
|
|
|
if (m_invert & 1)
|
2012-09-05 16:29:19 +00:00
|
|
|
putTok(tokPtr, TokNot);
|
2015-02-19 12:25:10 +00:00
|
|
|
m_invert = 0;
|
2012-09-05 16:29:19 +00:00
|
|
|
m_state = StCond;
|
|
|
|
m_canElse = true;
|
|
|
|
}
|
|
|
|
|
2015-02-19 19:53:53 +00:00
|
|
|
void QMakeParser::bogusTest(ushort *&tokPtr, const QString &msg)
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
2015-02-19 19:53:53 +00:00
|
|
|
if (!msg.isEmpty())
|
|
|
|
parseError(msg);
|
2012-09-05 16:29:19 +00:00
|
|
|
flushScopes(tokPtr);
|
|
|
|
m_operator = NoOperator;
|
2015-02-19 12:25:10 +00:00
|
|
|
m_invert = 0;
|
2012-09-05 16:29:19 +00:00
|
|
|
m_state = StCond;
|
|
|
|
m_canElse = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::finalizeCond(ushort *&tokPtr, ushort *uc, ushort *ptr, int wordCount)
|
|
|
|
{
|
|
|
|
if (wordCount != 1) {
|
2015-02-19 19:53:53 +00:00
|
|
|
if (wordCount)
|
|
|
|
bogusTest(tokPtr, fL1S("Extra characters after test expression."));
|
2012-09-05 16:29:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for magic tokens
|
|
|
|
if (*uc == TokHashLiteral) {
|
|
|
|
uint nlen = uc[3];
|
|
|
|
ushort *uce = uc + 4 + nlen;
|
|
|
|
if (uce == ptr) {
|
|
|
|
m_tmp.setRawData((QChar *)uc + 4, nlen);
|
|
|
|
if (!m_tmp.compare(statics.strelse, Qt::CaseInsensitive)) {
|
2015-02-18 10:20:01 +00:00
|
|
|
if (failOperator("in front of else"))
|
2012-09-05 16:29:19 +00:00
|
|
|
return;
|
|
|
|
BlockScope &top = m_blockstack.top();
|
|
|
|
if (m_canElse && (!top.special || top.braceLevel)) {
|
|
|
|
// A list of tests (the last one likely with side effects),
|
|
|
|
// but no assignment, scope, etc.
|
|
|
|
putTok(tokPtr, TokBranch);
|
|
|
|
// Put empty then block
|
|
|
|
putBlockLen(tokPtr, 0);
|
|
|
|
enterScope(tokPtr, false, StCtrl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
forever {
|
|
|
|
BlockScope &top = m_blockstack.top();
|
|
|
|
if (top.inBranch && (!top.special || top.braceLevel)) {
|
|
|
|
top.inBranch = false;
|
|
|
|
enterScope(tokPtr, false, StCtrl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (top.braceLevel || m_blockstack.size() == 1)
|
|
|
|
break;
|
|
|
|
leaveScope(tokPtr);
|
|
|
|
}
|
|
|
|
parseError(fL1S("Unexpected 'else'."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finalizeTest(tokPtr);
|
|
|
|
putBlock(tokPtr, uc, ptr - uc);
|
|
|
|
putTok(tokPtr, TokCondition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::finalizeCall(ushort *&tokPtr, ushort *uc, ushort *ptr, int argc)
|
|
|
|
{
|
|
|
|
// Check for magic tokens
|
|
|
|
if (*uc == TokHashLiteral) {
|
|
|
|
uint nlen = uc[3];
|
|
|
|
ushort *uce = uc + 4 + nlen;
|
|
|
|
if (*uce == TokTestCall) {
|
|
|
|
uce++;
|
|
|
|
m_tmp.setRawData((QChar *)uc + 4, nlen);
|
|
|
|
const QString *defName;
|
|
|
|
ushort defType;
|
|
|
|
if (m_tmp == statics.strfor) {
|
2015-02-18 10:20:01 +00:00
|
|
|
if (!acceptColon("in front of for()")) {
|
|
|
|
bogusTest(tokPtr, QString());
|
2012-09-05 16:29:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-09-11 16:43:29 +00:00
|
|
|
flushCond(tokPtr);
|
|
|
|
putLineMarker(tokPtr);
|
2015-02-13 14:27:22 +00:00
|
|
|
--ptr;
|
|
|
|
Q_ASSERT(*ptr == TokFuncTerminator);
|
2012-09-05 16:29:19 +00:00
|
|
|
if (*uce == (TokLiteral|TokNewStr)) {
|
|
|
|
nlen = uce[1];
|
|
|
|
uc = uce + 2 + nlen;
|
2015-02-13 14:27:22 +00:00
|
|
|
if (uc == ptr) {
|
2012-09-05 16:29:19 +00:00
|
|
|
// for(literal) (only "ever" would be legal if qmake was sane)
|
|
|
|
putTok(tokPtr, TokForLoop);
|
2018-08-02 22:22:24 +00:00
|
|
|
putHashStr(tokPtr, nullptr, (uint)0);
|
2012-09-05 16:29:19 +00:00
|
|
|
putBlockLen(tokPtr, 1 + 3 + nlen + 1);
|
|
|
|
putTok(tokPtr, TokHashLiteral);
|
|
|
|
putHashStr(tokPtr, uce + 2, nlen);
|
|
|
|
didFor:
|
|
|
|
putTok(tokPtr, TokValueTerminator);
|
|
|
|
enterScope(tokPtr, true, StCtrl);
|
2012-09-11 17:30:29 +00:00
|
|
|
m_blockstack.top().nest |= NestLoop;
|
2012-09-05 16:29:19 +00:00
|
|
|
return;
|
|
|
|
} else if (*uc == TokArgSeparator && argc == 2) {
|
|
|
|
// for(var, something)
|
|
|
|
uc++;
|
|
|
|
putTok(tokPtr, TokForLoop);
|
|
|
|
putHashStr(tokPtr, uce + 2, nlen);
|
|
|
|
doFor:
|
|
|
|
nlen = ptr - uc;
|
|
|
|
putBlockLen(tokPtr, nlen + 1);
|
|
|
|
putBlock(tokPtr, uc, nlen);
|
|
|
|
goto didFor;
|
|
|
|
}
|
|
|
|
} else if (argc == 1) {
|
|
|
|
// for(non-literal) (this wouldn't be here if qmake was sane)
|
|
|
|
putTok(tokPtr, TokForLoop);
|
2018-08-02 22:22:24 +00:00
|
|
|
putHashStr(tokPtr, nullptr, (uint)0);
|
2012-09-05 16:29:19 +00:00
|
|
|
uc = uce;
|
|
|
|
goto doFor;
|
|
|
|
}
|
|
|
|
parseError(fL1S("Syntax is for(var, list), for(var, forever) or for(ever)."));
|
|
|
|
return;
|
|
|
|
} else if (m_tmp == statics.strdefineReplace) {
|
|
|
|
defName = &statics.strdefineReplace;
|
|
|
|
defType = TokReplaceDef;
|
|
|
|
goto deffunc;
|
|
|
|
} else if (m_tmp == statics.strdefineTest) {
|
|
|
|
defName = &statics.strdefineTest;
|
|
|
|
defType = TokTestDef;
|
|
|
|
deffunc:
|
|
|
|
if (m_invert) {
|
2015-02-18 09:55:10 +00:00
|
|
|
bogusTest(tokPtr, fL1S("Unexpected NOT operator in front of function definition."));
|
2012-09-05 16:29:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-09-11 16:43:29 +00:00
|
|
|
flushScopes(tokPtr);
|
|
|
|
putLineMarker(tokPtr);
|
2012-09-05 16:29:19 +00:00
|
|
|
if (*uce == (TokLiteral|TokNewStr)) {
|
|
|
|
uint nlen = uce[1];
|
|
|
|
if (uce[nlen + 2] == TokFuncTerminator) {
|
2015-02-17 19:45:08 +00:00
|
|
|
putOperator(tokPtr);
|
2012-09-05 16:29:19 +00:00
|
|
|
putTok(tokPtr, defType);
|
|
|
|
putHashStr(tokPtr, uce + 2, nlen);
|
|
|
|
enterScope(tokPtr, true, StCtrl);
|
2012-09-11 17:30:29 +00:00
|
|
|
m_blockstack.top().nest = NestFunction;
|
2012-09-05 16:29:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parseError(fL1S("%1(function) requires one literal argument.").arg(*defName));
|
|
|
|
return;
|
2016-11-11 10:40:24 +00:00
|
|
|
} else if (m_tmp == statics.strbypassNesting) {
|
|
|
|
if (*uce != TokFuncTerminator) {
|
|
|
|
bogusTest(tokPtr, fL1S("%1() requires zero arguments.").arg(m_tmp));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(m_blockstack.top().nest & NestFunction)) {
|
|
|
|
bogusTest(tokPtr, fL1S("Unexpected %1().").arg(m_tmp));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_invert) {
|
|
|
|
bogusTest(tokPtr, fL1S("Unexpected NOT operator in front of %1().").arg(m_tmp));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
flushScopes(tokPtr);
|
|
|
|
putLineMarker(tokPtr);
|
|
|
|
putOperator(tokPtr);
|
|
|
|
putTok(tokPtr, TokBypassNesting);
|
|
|
|
enterScope(tokPtr, true, StCtrl);
|
|
|
|
return;
|
2012-09-11 17:30:29 +00:00
|
|
|
} else if (m_tmp == statics.strreturn) {
|
2013-03-05 11:35:05 +00:00
|
|
|
if (m_blockstack.top().nest & NestFunction) {
|
|
|
|
if (argc > 1) {
|
2015-02-19 19:53:53 +00:00
|
|
|
bogusTest(tokPtr, fL1S("return() requires zero or one argument."));
|
2013-03-05 11:35:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (*uce != TokFuncTerminator) {
|
2015-02-19 19:53:53 +00:00
|
|
|
bogusTest(tokPtr, fL1S("Top-level return() requires zero arguments."));
|
2013-03-05 11:35:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-09-11 17:30:29 +00:00
|
|
|
}
|
|
|
|
defType = TokReturn;
|
|
|
|
goto ctrlstm2;
|
|
|
|
} else if (m_tmp == statics.strnext) {
|
|
|
|
defType = TokNext;
|
|
|
|
goto ctrlstm;
|
|
|
|
} else if (m_tmp == statics.strbreak) {
|
|
|
|
defType = TokBreak;
|
|
|
|
ctrlstm:
|
|
|
|
if (*uce != TokFuncTerminator) {
|
2015-02-19 19:53:53 +00:00
|
|
|
bogusTest(tokPtr, fL1S("%1() requires zero arguments.").arg(m_tmp));
|
2012-09-11 17:30:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-03-05 11:35:05 +00:00
|
|
|
if (!(m_blockstack.top().nest & NestLoop)) {
|
2015-02-19 19:53:53 +00:00
|
|
|
bogusTest(tokPtr, fL1S("Unexpected %1().").arg(m_tmp));
|
2012-09-11 17:30:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-03-05 11:35:05 +00:00
|
|
|
ctrlstm2:
|
|
|
|
if (m_invert) {
|
2015-02-19 19:53:53 +00:00
|
|
|
bogusTest(tokPtr, fL1S("Unexpected NOT operator in front of %1().").arg(m_tmp));
|
2012-09-11 17:30:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
finalizeTest(tokPtr);
|
|
|
|
putBlock(tokPtr, uce, ptr - uce - 1); // Only for TokReturn
|
|
|
|
putTok(tokPtr, defType);
|
|
|
|
return;
|
2012-09-05 16:29:19 +00:00
|
|
|
} else if (m_tmp == statics.stroption) {
|
|
|
|
if (m_state != StNew || m_blockstack.top().braceLevel || m_blockstack.size() > 1
|
|
|
|
|| m_invert || m_operator != NoOperator) {
|
2015-02-19 19:53:53 +00:00
|
|
|
bogusTest(tokPtr, fL1S("option() must appear outside any control structures."));
|
2012-09-05 16:29:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*uce == (TokLiteral|TokNewStr)) {
|
|
|
|
uint nlen = uce[1];
|
|
|
|
if (uce[nlen + 2] == TokFuncTerminator) {
|
|
|
|
m_tmp.setRawData((QChar *)uce + 2, nlen);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
(cherry picked from qtcreator/29a93998df8405e8799ad23934a56cd99fb36403)
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
2013-01-08 01:32:53 +00:00
|
|
|
if (m_tmp == statics.strhost_build)
|
2012-09-05 16:29:19 +00:00
|
|
|
m_proFile->setHostBuild(true);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
(cherry picked from qtcreator/29a93998df8405e8799ad23934a56cd99fb36403)
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
2013-01-08 01:32:53 +00:00
|
|
|
else
|
2012-09-05 16:29:19 +00:00
|
|
|
parseError(fL1S("Unknown option() %1.").arg(m_tmp));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parseError(fL1S("option() requires one literal argument."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finalizeTest(tokPtr);
|
|
|
|
putBlock(tokPtr, uc, ptr - uc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QMakeParser::resolveVariable(ushort *xprPtr, int tlen, int needSep, ushort **ptr,
|
|
|
|
ushort **buf, QString *xprBuff,
|
|
|
|
ushort **tokPtr, QString *tokBuff,
|
2020-05-30 21:29:21 +00:00
|
|
|
const ushort *cur, QStringView in)
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
|
|
|
QString out;
|
|
|
|
m_tmp.setRawData((const QChar *)xprPtr, tlen);
|
|
|
|
if (m_tmp == statics.strLINE) {
|
|
|
|
out.setNum(m_lineNo);
|
|
|
|
} else if (m_tmp == statics.strFILE) {
|
|
|
|
out = m_proFile->fileName();
|
|
|
|
// The string is typically longer than the variable reference, so we need
|
|
|
|
// to ensure that there is enough space in the output buffer - as unlikely
|
|
|
|
// as an overflow is to actually happen in practice.
|
Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
except that the on() matcher has been replaced by one that doesn't
ignoreParens().
a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.
Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache,
to avoid porting calls that explicitly test count().
Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-09-30 12:09:04 +00:00
|
|
|
int need = (in.size() - (cur - (const ushort *)in.constData()) + 2) * 5 + out.size();
|
2012-09-05 16:29:19 +00:00
|
|
|
int tused = *tokPtr - (ushort *)tokBuff->constData();
|
|
|
|
int xused;
|
|
|
|
int total;
|
|
|
|
bool ptrFinal = xprPtr >= (ushort *)tokBuff->constData()
|
|
|
|
&& xprPtr < (ushort *)tokBuff->constData() + tokBuff->capacity();
|
|
|
|
if (ptrFinal) {
|
|
|
|
xused = xprPtr - (ushort *)tokBuff->constData();
|
|
|
|
total = xused + need;
|
|
|
|
} else {
|
|
|
|
xused = xprPtr - *buf;
|
|
|
|
total = tused + xused + need;
|
|
|
|
}
|
|
|
|
if (tokBuff->capacity() < total) {
|
|
|
|
tokBuff->reserve(total);
|
|
|
|
*tokPtr = (ushort *)tokBuff->constData() + tused;
|
|
|
|
xprBuff->reserve(total);
|
|
|
|
*buf = (ushort *)xprBuff->constData();
|
|
|
|
xprPtr = (ptrFinal ? (ushort *)tokBuff->constData() : *buf) + xused;
|
|
|
|
}
|
|
|
|
} else if (m_tmp == statics.strLITERAL_HASH) {
|
|
|
|
out = QLatin1String("#");
|
|
|
|
} else if (m_tmp == statics.strLITERAL_DOLLAR) {
|
|
|
|
out = QLatin1String("$");
|
|
|
|
} else if (m_tmp == statics.strLITERAL_WHITESPACE) {
|
|
|
|
out = QLatin1String("\t");
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
xprPtr -= 2; // Was set up for variable reference
|
|
|
|
xprPtr[-2] = TokLiteral | needSep;
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
xprPtr[-1] = out.size();
|
|
|
|
memcpy(xprPtr, out.constData(), out.size() * 2);
|
|
|
|
*ptr = xprPtr + out.size();
|
2012-09-05 16:29:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QMakeParser::message(int type, const QString &msg) const
|
|
|
|
{
|
|
|
|
if (!m_inError && m_handler)
|
|
|
|
m_handler->message(type, msg, m_proFile->fileName(), m_lineNo);
|
|
|
|
}
|
|
|
|
|
2015-02-25 11:10:34 +00:00
|
|
|
#ifdef PROPARSER_DEBUG
|
|
|
|
|
|
|
|
#define BOUNDS_CHECK(need) \
|
|
|
|
do { \
|
|
|
|
int have = limit - offset; \
|
|
|
|
if (have < (int)need) { \
|
|
|
|
*outStr += fL1S("<out of bounds (need %1, got %2)>").arg(need).arg(have); \
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static bool getRawUshort(const ushort *tokens, int limit, int &offset, ushort *outVal, QString *outStr)
|
|
|
|
{
|
|
|
|
BOUNDS_CHECK(1);
|
|
|
|
uint val = tokens[offset++];
|
|
|
|
*outVal = val;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool getUshort(const ushort *tokens, int limit, int &offset, ushort *outVal, QString *outStr)
|
|
|
|
{
|
|
|
|
*outStr += fL1S(" << H(");
|
|
|
|
if (!getRawUshort(tokens, limit, offset, outVal, outStr))
|
|
|
|
return false;
|
|
|
|
*outStr += QString::number(*outVal) + QLatin1Char(')');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool getRawUint(const ushort *tokens, int limit, int &offset, uint *outVal, QString *outStr)
|
|
|
|
{
|
|
|
|
BOUNDS_CHECK(2);
|
|
|
|
uint val = tokens[offset++];
|
|
|
|
val |= (uint)tokens[offset++] << 16;
|
|
|
|
*outVal = val;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool getUint(const ushort *tokens, int limit, int &offset, uint *outVal, QString *outStr)
|
|
|
|
{
|
|
|
|
*outStr += fL1S(" << I(");
|
|
|
|
if (!getRawUint(tokens, limit, offset, outVal, outStr))
|
|
|
|
return false;
|
|
|
|
*outStr += QString::number(*outVal) + QLatin1Char(')');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool getRawStr(const ushort *tokens, int limit, int &offset, int strLen, QString *outStr)
|
|
|
|
{
|
|
|
|
BOUNDS_CHECK(strLen);
|
|
|
|
*outStr += fL1S("L\"");
|
|
|
|
bool attn = false;
|
|
|
|
for (int i = 0; i < strLen; i++) {
|
|
|
|
ushort val = tokens[offset++];
|
|
|
|
switch (val) {
|
|
|
|
case '"': *outStr += fL1S("\\\""); break;
|
|
|
|
case '\n': *outStr += fL1S("\\n"); break;
|
|
|
|
case '\r': *outStr += fL1S("\\r"); break;
|
|
|
|
case '\t': *outStr += fL1S("\\t"); break;
|
|
|
|
case '\\': *outStr += fL1S("\\\\"); break;
|
|
|
|
default:
|
|
|
|
if (val < 32 || val > 126) {
|
|
|
|
*outStr += (val > 255 ? fL1S("\\u") : fL1S("\\x")) + QString::number(val, 16);
|
|
|
|
attn = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (attn && isxdigit(val))
|
|
|
|
*outStr += fL1S("\"\"");
|
|
|
|
*outStr += QChar(val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
attn = false;
|
|
|
|
}
|
|
|
|
*outStr += QLatin1Char('"');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool getStr(const ushort *tokens, int limit, int &offset, QString *outStr)
|
|
|
|
{
|
|
|
|
*outStr += fL1S(" << S(");
|
|
|
|
ushort len;
|
|
|
|
if (!getRawUshort(tokens, limit, offset, &len, outStr))
|
|
|
|
return false;
|
|
|
|
if (!getRawStr(tokens, limit, offset, len, outStr))
|
|
|
|
return false;
|
|
|
|
*outStr += QLatin1Char(')');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool getHashStr(const ushort *tokens, int limit, int &offset, QString *outStr)
|
|
|
|
{
|
|
|
|
*outStr += fL1S(" << HS(");
|
|
|
|
uint hash;
|
|
|
|
if (!getRawUint(tokens, limit, offset, &hash, outStr))
|
|
|
|
return false;
|
|
|
|
ushort len;
|
|
|
|
if (!getRawUshort(tokens, limit, offset, &len, outStr))
|
|
|
|
return false;
|
|
|
|
const QChar *chars = (const QChar *)tokens + offset;
|
|
|
|
if (!getRawStr(tokens, limit, offset, len, outStr))
|
|
|
|
return false;
|
|
|
|
uint realhash = ProString::hash(chars, len);
|
|
|
|
if (realhash != hash)
|
|
|
|
*outStr += fL1S(" /* Bad hash ") + QString::number(hash) + fL1S(" */");
|
|
|
|
*outStr += QLatin1Char(')');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool getBlock(const ushort *tokens, int limit, int &offset, QString *outStr, int indent);
|
|
|
|
|
|
|
|
static bool getSubBlock(const ushort *tokens, int limit, int &offset, QString *outStr, int indent,
|
|
|
|
const char *scope)
|
|
|
|
{
|
|
|
|
*outStr += fL1S("\n /* %1 */ ").arg(offset, 5)
|
|
|
|
+ QString(indent * 4, QLatin1Char(' '))
|
|
|
|
+ fL1S("/* ") + fL1S(scope) + fL1S(" */");
|
|
|
|
uint len;
|
|
|
|
if (!getUint(tokens, limit, offset, &len, outStr))
|
|
|
|
return false;
|
|
|
|
if (len) {
|
|
|
|
BOUNDS_CHECK(len);
|
|
|
|
int tmpOff = offset;
|
|
|
|
offset += len;
|
|
|
|
forever {
|
|
|
|
if (!getBlock(tokens, offset, tmpOff, outStr, indent + 1))
|
|
|
|
break; // Error was already reported, try to continue
|
|
|
|
if (tmpOff == offset)
|
|
|
|
break;
|
|
|
|
*outStr += QLatin1Char('\n') + QString(20 + indent * 4, QLatin1Char(' '))
|
|
|
|
+ fL1S("/* Warning: Excess tokens follow. */");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool getBlock(const ushort *tokens, int limit, int &offset, QString *outStr, int indent)
|
|
|
|
{
|
|
|
|
static const char * const tokNames[] = {
|
|
|
|
"TokTerminator",
|
|
|
|
"TokLine",
|
|
|
|
"TokAssign", "TokAppend", "TokAppendUnique", "TokRemove", "TokReplace",
|
|
|
|
"TokValueTerminator",
|
|
|
|
"TokLiteral", "TokHashLiteral", "TokVariable", "TokProperty", "TokEnvVar",
|
|
|
|
"TokFuncName", "TokArgSeparator", "TokFuncTerminator",
|
|
|
|
"TokCondition", "TokTestCall",
|
|
|
|
"TokReturn", "TokBreak", "TokNext",
|
|
|
|
"TokNot", "TokAnd", "TokOr",
|
|
|
|
"TokBranch", "TokForLoop",
|
2016-11-11 10:40:24 +00:00
|
|
|
"TokTestDef", "TokReplaceDef", "TokBypassNesting"
|
2015-02-25 11:10:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
while (offset != limit) {
|
|
|
|
*outStr += fL1S("\n /* %1 */").arg(offset, 5)
|
|
|
|
+ QString(indent * 4, QLatin1Char(' '));
|
|
|
|
BOUNDS_CHECK(1);
|
|
|
|
ushort tok = tokens[offset++];
|
|
|
|
ushort maskedTok = tok & TokMask;
|
|
|
|
if (maskedTok >= sizeof(tokNames)/sizeof(tokNames[0])
|
|
|
|
|| (tok & ~(TokNewStr | TokQuoted | TokMask))) {
|
|
|
|
*outStr += fL1S(" << {invalid token %1}").arg(tok);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*outStr += fL1S(" << H(") + fL1S(tokNames[maskedTok]);
|
|
|
|
if (tok & TokNewStr)
|
|
|
|
*outStr += fL1S(" | TokNewStr");
|
|
|
|
if (tok & TokQuoted)
|
|
|
|
*outStr += fL1S(" | TokQuoted");
|
|
|
|
*outStr += QLatin1Char(')');
|
|
|
|
bool ok;
|
|
|
|
switch (maskedTok) {
|
|
|
|
case TokFuncTerminator: // Recursion, but not a sub-block
|
|
|
|
return true;
|
|
|
|
case TokArgSeparator:
|
|
|
|
case TokValueTerminator: // Not recursion
|
|
|
|
case TokTerminator: // Recursion, and limited by (sub-)block length
|
|
|
|
case TokCondition:
|
|
|
|
case TokReturn:
|
|
|
|
case TokBreak:
|
|
|
|
case TokNext:
|
|
|
|
case TokNot:
|
|
|
|
case TokAnd:
|
|
|
|
case TokOr:
|
|
|
|
ok = true;
|
|
|
|
break;
|
|
|
|
case TokTestCall:
|
|
|
|
ok = getBlock(tokens, limit, offset, outStr, indent + 1);
|
|
|
|
break;
|
|
|
|
case TokBranch:
|
|
|
|
ok = getSubBlock(tokens, limit, offset, outStr, indent, "then branch");
|
|
|
|
if (ok)
|
|
|
|
ok = getSubBlock(tokens, limit, offset, outStr, indent, "else branch");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
switch (maskedTok) {
|
|
|
|
case TokAssign:
|
|
|
|
case TokAppend:
|
|
|
|
case TokAppendUnique:
|
|
|
|
case TokRemove:
|
|
|
|
case TokReplace:
|
|
|
|
// The parameter is the sizehint for the output.
|
|
|
|
// fallthrough
|
|
|
|
case TokLine: {
|
|
|
|
ushort dummy;
|
|
|
|
ok = getUshort(tokens, limit, offset, &dummy, outStr);
|
|
|
|
break; }
|
|
|
|
case TokLiteral:
|
|
|
|
case TokEnvVar:
|
|
|
|
ok = getStr(tokens, limit, offset, outStr);
|
|
|
|
break;
|
|
|
|
case TokHashLiteral:
|
|
|
|
case TokVariable:
|
|
|
|
case TokProperty:
|
|
|
|
ok = getHashStr(tokens, limit, offset, outStr);
|
|
|
|
break;
|
|
|
|
case TokFuncName:
|
|
|
|
ok = getHashStr(tokens, limit, offset, outStr);
|
|
|
|
if (ok)
|
|
|
|
ok = getBlock(tokens, limit, offset, outStr, indent + 1);
|
|
|
|
break;
|
|
|
|
case TokForLoop:
|
|
|
|
ok = getHashStr(tokens, limit, offset, outStr);
|
|
|
|
if (ok)
|
|
|
|
ok = getSubBlock(tokens, limit, offset, outStr, indent, "iterator");
|
|
|
|
if (ok)
|
|
|
|
ok = getSubBlock(tokens, limit, offset, outStr, indent, "body");
|
|
|
|
break;
|
|
|
|
case TokTestDef:
|
|
|
|
case TokReplaceDef:
|
|
|
|
ok = getHashStr(tokens, limit, offset, outStr);
|
|
|
|
if (ok)
|
|
|
|
ok = getSubBlock(tokens, limit, offset, outStr, indent, "body");
|
|
|
|
break;
|
2016-11-11 10:40:24 +00:00
|
|
|
case TokBypassNesting:
|
|
|
|
ok = getSubBlock(tokens, limit, offset, outStr, indent, "block");
|
|
|
|
break;
|
2015-02-25 11:10:34 +00:00
|
|
|
default:
|
2022-01-22 20:07:21 +00:00
|
|
|
// unhandled token
|
|
|
|
Q_UNREACHABLE();
|
2015-02-25 11:10:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ok)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QMakeParser::formatProBlock(const QString &block)
|
|
|
|
{
|
|
|
|
QString outStr;
|
|
|
|
outStr += fL1S("\n << TS(");
|
|
|
|
int offset = 0;
|
Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:
auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.
<classes> are:
// sequential:
"QByteArray",
"QList",
"QQueue",
"QStack",
"QString",
"QVarLengthArray",
"QVector",
// associative:
"QHash",
"QMultiHash",
"QMap",
"QMultiMap",
"QSet",
// Qt has no QMultiSet
Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-09-30 12:09:04 +00:00
|
|
|
getBlock(reinterpret_cast<const ushort *>(block.constData()), block.size(),
|
2015-02-25 11:10:34 +00:00
|
|
|
offset, &outStr, 0);
|
|
|
|
outStr += QLatin1Char(')');
|
|
|
|
return outStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PROPARSER_DEBUG
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QT_END_NAMESPACE
|