forked from qt-creator/qt-creator
QmlJS: Fix compiler warnings
Change-Id: I94fccd913a4a06fb55acee3df974859f9a163b4f Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
@@ -388,7 +388,7 @@ protected:
|
||||
QTC_ASSERT(_block == 0, _block = 0);
|
||||
}
|
||||
|
||||
void postVisit(Node *ast)
|
||||
void postVisit(Node *ast) override
|
||||
{
|
||||
if (!_seenNonDeclarationStatement && ast->statementCast()
|
||||
&& !cast<VariableStatement *>(ast)) {
|
||||
@@ -396,7 +396,7 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
bool visit(IdentifierExpression *ast)
|
||||
bool visit(IdentifierExpression *ast) override
|
||||
{
|
||||
if (ast->name.isEmpty())
|
||||
return false;
|
||||
@@ -409,14 +409,14 @@ protected:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool visit(VariableStatement *ast)
|
||||
bool visit(VariableStatement *ast) override
|
||||
{
|
||||
if (_seenNonDeclarationStatement)
|
||||
addMessage(HintDeclarationsShouldBeAtStartOfFunction, ast->declarationKindToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool visit(PatternElement *ast)
|
||||
bool visit(PatternElement *ast) override
|
||||
{
|
||||
if (ast->bindingIdentifier.isEmpty() || !ast->isVariableDeclaration())
|
||||
return true;
|
||||
@@ -433,12 +433,13 @@ protected:
|
||||
if (_declaredVariables.contains(name)) {
|
||||
addMessage(WarnDuplicateDeclaration, ast->identifierToken, name);
|
||||
} else {
|
||||
for (auto k : _declaredBlockVariables.keys()) {
|
||||
if (k.first == name) {
|
||||
addMessage(WarnDuplicateDeclaration, ast->identifierToken, name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
const auto found = std::find_if(_declaredBlockVariables.keyBegin(),
|
||||
_declaredBlockVariables.keyEnd(),
|
||||
[name](const auto &key) {
|
||||
return key.first == name;
|
||||
});
|
||||
if (found != _declaredBlockVariables.keyEnd())
|
||||
addMessage(WarnDuplicateDeclaration, ast->identifierToken, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,7 +457,7 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool visit(FunctionDeclaration *ast)
|
||||
bool visit(FunctionDeclaration *ast) override
|
||||
{
|
||||
if (_seenNonDeclarationStatement)
|
||||
addMessage(HintDeclarationsShouldBeAtStartOfFunction, ast->functionToken);
|
||||
@@ -464,7 +465,7 @@ protected:
|
||||
return visit(static_cast<FunctionExpression *>(ast));
|
||||
}
|
||||
|
||||
bool visit(FunctionExpression *ast)
|
||||
bool visit(FunctionExpression *ast) override
|
||||
{
|
||||
if (ast->name.isEmpty())
|
||||
return false;
|
||||
@@ -879,7 +880,7 @@ static bool checkTopLevelBindingForParentReference(ExpressionStatement *expStmt,
|
||||
return false;
|
||||
|
||||
SourceLocation location = locationFromRange(expStmt->firstSourceLocation(), expStmt->lastSourceLocation());
|
||||
QString stmtSource = source.mid(location.begin(), location.length);
|
||||
QString stmtSource = source.mid(int(location.begin()), int(location.length));
|
||||
|
||||
if (stmtSource.contains(QRegExp("(^|\\W)parent\\.")))
|
||||
return true;
|
||||
@@ -1245,8 +1246,8 @@ bool Check::visit(BinaryExpression *ast)
|
||||
|
||||
// check spacing
|
||||
SourceLocation op = ast->operatorToken;
|
||||
if ((op.begin() > 0 && !source.at(op.begin() - 1).isSpace())
|
||||
|| (int(op.end()) < source.size() && !source.at(op.end()).isSpace())) {
|
||||
if ((op.begin() > 0 && !source.at(int(op.begin()) - 1).isSpace())
|
||||
|| (int(op.end()) < source.size() && !source.at(int(op.end())).isSpace())) {
|
||||
addMessage(HintBinaryOperatorSpacing, op);
|
||||
}
|
||||
|
||||
@@ -1281,15 +1282,13 @@ bool Check::visit(BinaryExpression *ast)
|
||||
}
|
||||
|
||||
if (int(op.end()) + 1 < source.size()) {
|
||||
const QChar next = source.at(op.end());
|
||||
if (next.isSpace() && next != newline
|
||||
&& source.at(op.end() + 1) == match)
|
||||
addMessage(msg, SourceLocation(op.begin(), 3, op.startLine, op.startColumn));
|
||||
const QChar next = source.at(int(op.end()));
|
||||
if (next.isSpace() && next != newline && source.at(int(op.end()) + 1) == match)
|
||||
addMessage(msg, SourceLocation((op.begin()), 3, op.startLine, op.startColumn));
|
||||
}
|
||||
if (op.begin() >= 2) {
|
||||
const QChar prev = source.at(op.begin() - 1);
|
||||
if (prev.isSpace() && prev != newline
|
||||
&& source.at(op.begin() - 2) == match)
|
||||
const QChar prev = source.at(int(op.begin()) - 1);
|
||||
if (prev.isSpace() && prev != newline && source.at(int(op.begin()) - 2) == match)
|
||||
addMessage(msg, SourceLocation(op.begin() - 2, 3, op.startLine, op.startColumn - 2));
|
||||
}
|
||||
}
|
||||
@@ -1379,6 +1378,7 @@ bool Check::visit(ExpressionStatement *ast)
|
||||
case QSOperator::InplaceURightShift:
|
||||
case QSOperator::InplaceXor:
|
||||
ok = true;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -1511,8 +1511,9 @@ static bool hasOnlySpaces(const QString &s)
|
||||
void Check::addMessage(const Message &message)
|
||||
{
|
||||
if (message.isValid() && _enabledMessages.contains(message.type)) {
|
||||
if (m_disabledMessageTypesByLine.contains(message.location.startLine)) {
|
||||
QList<MessageTypeAndSuppression> &disabledMessages = m_disabledMessageTypesByLine[message.location.startLine];
|
||||
if (m_disabledMessageTypesByLine.contains(int(message.location.startLine))) {
|
||||
QList<MessageTypeAndSuppression> &disabledMessages
|
||||
= m_disabledMessageTypesByLine[int(message.location.startLine)];
|
||||
for (int i = 0; i < disabledMessages.size(); ++i) {
|
||||
if (disabledMessages[i].type == message.type) {
|
||||
disabledMessages[i].wasSuppressed = true;
|
||||
@@ -1536,7 +1537,7 @@ void Check::scanCommentsForAnnotations()
|
||||
QRegExp disableCommentPattern(Message::suppressionPattern());
|
||||
|
||||
foreach (const SourceLocation &commentLoc, _doc->engine()->comments()) {
|
||||
const QString &comment = _doc->source().mid(commentLoc.begin(), commentLoc.length);
|
||||
const QString &comment = _doc->source().mid(int(commentLoc.begin()), int(commentLoc.length));
|
||||
|
||||
// enable all checks annotation
|
||||
if (comment.contains("@enable-all-checks"))
|
||||
@@ -1552,25 +1553,26 @@ void Check::scanCommentsForAnnotations()
|
||||
MessageTypeAndSuppression entry;
|
||||
entry.type = static_cast<StaticAnalysis::Type>(disableCommentPattern.cap(1).toInt());
|
||||
entry.wasSuppressed = false;
|
||||
entry.suppressionSource = SourceLocation(commentLoc.offset + lastOffset,
|
||||
disableCommentPattern.matchedLength(),
|
||||
entry.suppressionSource = SourceLocation(commentLoc.offset + quint32(lastOffset),
|
||||
quint32(disableCommentPattern.matchedLength()),
|
||||
commentLoc.startLine,
|
||||
commentLoc.startColumn + lastOffset);
|
||||
commentLoc.startColumn + quint32(lastOffset));
|
||||
disabledMessageTypes += entry;
|
||||
}
|
||||
if (!disabledMessageTypes.isEmpty()) {
|
||||
int appliesToLine = commentLoc.startLine;
|
||||
quint32 appliesToLine = commentLoc.startLine;
|
||||
|
||||
// if the comment is preceded by spaces only, it applies to the next line
|
||||
// note: startColumn is 1-based and *after* the starting // or /*
|
||||
if (commentLoc.startColumn >= 3) {
|
||||
const QString &beforeComment = _doc->source().mid(commentLoc.begin() - commentLoc.startColumn + 1,
|
||||
commentLoc.startColumn - 3);
|
||||
const QString &beforeComment = _doc->source().mid(int(commentLoc.begin()
|
||||
- commentLoc.startColumn + 1),
|
||||
int(commentLoc.startColumn) - 3);
|
||||
if (hasOnlySpaces(beforeComment))
|
||||
++appliesToLine;
|
||||
}
|
||||
|
||||
m_disabledMessageTypesByLine[appliesToLine] += disabledMessageTypes;
|
||||
m_disabledMessageTypesByLine[int(appliesToLine)] += disabledMessageTypes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1859,7 +1861,8 @@ void Check::checkCaseFallthrough(StatementList *statements, SourceLocation error
|
||||
|| comment.end() > nextLoc.begin())
|
||||
continue;
|
||||
|
||||
const QString &commentText = _doc->source().mid(comment.begin(), comment.length);
|
||||
const QString &commentText = _doc->source().mid(int(comment.begin()),
|
||||
int(comment.length));
|
||||
if (commentText.contains("fall through")
|
||||
|| commentText.contains("fall-through")
|
||||
|| commentText.contains("fallthrough")) {
|
||||
|
@@ -39,6 +39,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
static constexpr int sizeofQChar = int(sizeof(QChar));
|
||||
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::AST;
|
||||
|
||||
@@ -248,12 +250,6 @@ public:
|
||||
|
||||
{}
|
||||
|
||||
void pragmaLibrary(int line, int column)
|
||||
{
|
||||
isLibrary = true;
|
||||
addLocation(line, column);
|
||||
}
|
||||
|
||||
void importFile(const QString &jsfile, const QString &module,
|
||||
int line, int column) override
|
||||
{
|
||||
@@ -306,12 +302,13 @@ bool Document::parse_helper(int startToken)
|
||||
_parsedCorrectly = parser.parse();
|
||||
break;
|
||||
case QmlJSGrammar::T_FEED_JS_SCRIPT:
|
||||
case QmlJSGrammar::T_FEED_JS_MODULE:
|
||||
case QmlJSGrammar::T_FEED_JS_MODULE: {
|
||||
_parsedCorrectly = parser.parseProgram();
|
||||
for (const auto &d: directives.locations()) {
|
||||
const QList<SourceLocation> locations = directives.locations();
|
||||
for (const auto &d : locations) {
|
||||
_jsdirectives << d;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case QmlJSGrammar::T_FEED_JS_EXPRESSION:
|
||||
_parsedCorrectly = parser.parseExpression();
|
||||
@@ -383,10 +380,6 @@ LibraryInfo::LibraryInfo(const QmlDirParser &parser, const QByteArray &fingerpri
|
||||
updateFingerprint();
|
||||
}
|
||||
|
||||
LibraryInfo::~LibraryInfo()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray LibraryInfo::calculateFingerprint() const
|
||||
{
|
||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
||||
@@ -396,12 +389,14 @@ QByteArray LibraryInfo::calculateFingerprint() const
|
||||
foreach (const QmlDirParser::Component &component, _components) {
|
||||
len = component.fileName.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(component.fileName.constData()), len * sizeof(QChar));
|
||||
hash.addData(reinterpret_cast<const char *>(component.fileName.constData()),
|
||||
len * sizeofQChar);
|
||||
hash.addData(reinterpret_cast<const char *>(&component.majorVersion), sizeof(component.majorVersion));
|
||||
hash.addData(reinterpret_cast<const char *>(&component.minorVersion), sizeof(component.minorVersion));
|
||||
len = component.typeName.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(component.typeName.constData()), component.typeName.size() * sizeof(QChar));
|
||||
hash.addData(reinterpret_cast<const char *>(component.typeName.constData()),
|
||||
component.typeName.size() * sizeofQChar);
|
||||
int flags = (component.singleton ? (1 << 0) : 0) + (component.internal ? (1 << 1) : 0);
|
||||
hash.addData(reinterpret_cast<const char *>(&flags), sizeof(flags));
|
||||
}
|
||||
@@ -410,17 +405,18 @@ QByteArray LibraryInfo::calculateFingerprint() const
|
||||
foreach (const QmlDirParser::Plugin &plugin, _plugins) {
|
||||
len = plugin.path.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(plugin.path.constData()), len * sizeof(QChar));
|
||||
hash.addData(reinterpret_cast<const char *>(plugin.path.constData()), len * sizeofQChar);
|
||||
len = plugin.name.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(plugin.name.constData()), len * sizeof(QChar));
|
||||
hash.addData(reinterpret_cast<const char *>(plugin.name.constData()), len * sizeofQChar);
|
||||
}
|
||||
len = _typeinfos.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
foreach (const QmlDirParser::TypeInfo &typeinfo, _typeinfos) {
|
||||
len = typeinfo.fileName.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(typeinfo.fileName.constData()), len * sizeof(QChar));
|
||||
hash.addData(reinterpret_cast<const char *>(typeinfo.fileName.constData()),
|
||||
len * sizeofQChar);
|
||||
}
|
||||
len = _metaObjects.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
@@ -433,7 +429,7 @@ QByteArray LibraryInfo::calculateFingerprint() const
|
||||
hash.addData(reinterpret_cast<const char *>(&_dumpStatus), sizeof(_dumpStatus));
|
||||
len = _dumpError.size(); // localization dependent (avoid?)
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(_dumpError.constData()), len * sizeof(QChar));
|
||||
hash.addData(reinterpret_cast<const char *>(_dumpError.constData()), len * sizeofQChar);
|
||||
|
||||
len = _moduleApis.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
@@ -623,9 +619,9 @@ void ModuleApiInfo::addToHash(QCryptographicHash &hash) const
|
||||
{
|
||||
int len = uri.length();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(uri.constData()), len * sizeof(QChar));
|
||||
hash.addData(reinterpret_cast<const char *>(uri.constData()), len * sizeofQChar);
|
||||
version.addToHash(hash);
|
||||
len = cppName.length();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(cppName.constData()), len * sizeof(QChar));
|
||||
hash.addData(reinterpret_cast<const char *>(cppName.constData()), len * sizeofQChar);
|
||||
}
|
||||
|
@@ -167,7 +167,8 @@ public:
|
||||
LibraryInfo();
|
||||
explicit LibraryInfo(Status status);
|
||||
explicit LibraryInfo(const QmlDirParser &parser, const QByteArray &fingerprint = QByteArray());
|
||||
~LibraryInfo();
|
||||
~LibraryInfo() = default;
|
||||
LibraryInfo(const LibraryInfo &other) = default;
|
||||
|
||||
QByteArray calculateFingerprint() const;
|
||||
void updateFingerprint();
|
||||
|
Reference in New Issue
Block a user