forked from qt-creator/qt-creator
QmlProfiler: Add some sanity to details rewriter's PropertyVisitor
Take care of possible integer overflows and apply coding style. Change-Id: Ib3922f30c102575ab773f7708864886fc0b53d15 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -42,53 +42,53 @@ namespace Internal {
|
|||||||
|
|
||||||
class PropertyVisitor: protected QmlJS::AST::Visitor
|
class PropertyVisitor: protected QmlJS::AST::Visitor
|
||||||
{
|
{
|
||||||
QmlJS::AST::Node * _lastValidNode;
|
|
||||||
unsigned _line;
|
|
||||||
unsigned _col;
|
|
||||||
public:
|
public:
|
||||||
QmlJS::AST::Node * operator()(QmlJS::AST::Node *node, unsigned line, unsigned col)
|
QmlJS::AST::Node *operator()(QmlJS::AST::Node *node, int line, int column)
|
||||||
{
|
{
|
||||||
_line = line;
|
QTC_ASSERT(line >= 0, return nullptr);
|
||||||
_col = col;
|
QTC_ASSERT(column >= 0, return nullptr);
|
||||||
_lastValidNode = 0;
|
QTC_ASSERT(node, return nullptr);
|
||||||
accept(node);
|
m_line = line;
|
||||||
return _lastValidNode;
|
m_column = column;
|
||||||
|
m_lastValidNode = nullptr;
|
||||||
|
node->accept(this);
|
||||||
|
return m_lastValidNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
using QmlJS::AST::Visitor::visit;
|
using QmlJS::AST::Visitor::visit;
|
||||||
|
|
||||||
void accept(QmlJS::AST::Node *node)
|
bool preVisit(QmlJS::AST::Node *node) override
|
||||||
{
|
|
||||||
if (node)
|
|
||||||
node->accept(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool containsLocation(QmlJS::AST::SourceLocation start, QmlJS::AST::SourceLocation end)
|
|
||||||
{
|
|
||||||
return (_line > start.startLine || (_line == start.startLine && _col >= start.startColumn))
|
|
||||||
&& (_line < end.startLine || (_line == end.startLine && _col <= end.startColumn));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool preVisit(QmlJS::AST::Node *node)
|
|
||||||
{
|
{
|
||||||
if (QmlJS::AST::cast<QmlJS::AST::UiQualifiedId *>(node))
|
if (QmlJS::AST::cast<QmlJS::AST::UiQualifiedId *>(node))
|
||||||
return false;
|
return false;
|
||||||
return containsLocation(node->firstSourceLocation(), node->lastSourceLocation());
|
return containsLocation(node->firstSourceLocation(), node->lastSourceLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool visit(QmlJS::AST::UiScriptBinding *ast)
|
bool visit(QmlJS::AST::UiScriptBinding *ast) override
|
||||||
{
|
{
|
||||||
_lastValidNode = ast;
|
m_lastValidNode = ast;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool visit(QmlJS::AST::UiPublicMember *ast)
|
bool visit(QmlJS::AST::UiPublicMember *ast) override
|
||||||
{
|
{
|
||||||
_lastValidNode = ast;
|
m_lastValidNode = ast;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QmlJS::AST::Node *m_lastValidNode = nullptr;
|
||||||
|
quint32 m_line = 0;
|
||||||
|
quint32 m_column = 0;
|
||||||
|
|
||||||
|
bool containsLocation(QmlJS::AST::SourceLocation start, QmlJS::AST::SourceLocation end)
|
||||||
|
{
|
||||||
|
return (m_line > start.startLine
|
||||||
|
|| (m_line == start.startLine && m_column >= start.startColumn))
|
||||||
|
&& (m_line < end.startLine
|
||||||
|
|| (m_line == end.startLine && m_column <= end.startColumn));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QmlProfilerDetailsRewriter::QmlProfilerDetailsRewriter(QObject *parent)
|
QmlProfilerDetailsRewriter::QmlProfilerDetailsRewriter(QObject *parent)
|
||||||
@@ -148,7 +148,6 @@ void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(
|
|||||||
{
|
{
|
||||||
PropertyVisitor propertyVisitor;
|
PropertyVisitor propertyVisitor;
|
||||||
QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line(), location.column());
|
QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line(), location.column());
|
||||||
|
|
||||||
if (!node)
|
if (!node)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user