Commit 96368496 authored by Christian Kandeler's avatar Christian Kandeler

Debugger: Refactor name demangler.

Now all the parsing logic as well as the stringification is in the tree
nodes.

Change-Id: Ie8222729c14c0102d94045026fc61a75cd31cc63
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@nokia.com>
parent 91d22556
......@@ -265,7 +265,9 @@ QtcPlugin {
"namedemangler/namedemangler.h",
"namedemangler/parsetreenodes.cpp",
"namedemangler/parsetreenodes.h",
"namedemangler/demanglerexceptions.h"
"namedemangler/demanglerexceptions.h",
"namedemangler/globalparsestate.h",
"namedemangler/globalparsestate.cpp"
]
Group {
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "globalparsestate.h"
#include "demanglerexceptions.h"
#include "parsetreenodes.h"
namespace Debugger {
namespace Internal {
char GlobalParseState::peek(int ahead)
{
Q_ASSERT(m_pos >= 0);
if (m_pos + ahead < m_mangledName.size())
return m_mangledName[m_pos + ahead];
return eoi;
}
char GlobalParseState::advance(int steps)
{
Q_ASSERT(steps > 0);
if (m_pos + steps > m_mangledName.size())
throw ParseException(QLatin1String("Unexpected end of input"));
const char c = m_mangledName[m_pos];
m_pos += steps;
return c;
}
QByteArray GlobalParseState::readAhead(int charCount) const
{
QByteArray str;
if (m_pos + charCount <= m_mangledName.size())
str = m_mangledName.mid(m_pos, charCount);
else
str.fill(eoi, charCount);
return str;
}
void GlobalParseState::addSubstitution(const ParseTreeNode *node)
{
const QByteArray symbol = node->toByteArray();
if (!symbol.isEmpty() && !m_substitutions.contains(symbol))
m_substitutions.append(symbol);
}
} // namespace Internal
} // namespace Debugger
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef GLOBAL_PARSE_STATE_H
#define GLOBAL_PARSE_STATE_H
#include <QByteArray>
#include <QStack>
namespace Debugger {
namespace Internal {
class NameDemanglerPrivate;
class ParseTreeNode;
class GlobalParseState
{
friend class NameDemanglerPrivate;
public:
char peek(int ahead = 0);
char advance(int steps = 1);
QByteArray readAhead(int charCount) const;
int stackElementCount() const { return m_parseStack.count(); }
ParseTreeNode *stackTop() const { return m_parseStack.top(); }
ParseTreeNode *stackElementAt(int index) const { return m_parseStack.at(index); }
void pushToStack(ParseTreeNode *node) { m_parseStack.push(node); }
ParseTreeNode *popFromStack() { return m_parseStack.pop(); }
int substitutionCount() const { return m_substitutions.count(); }
QByteArray substitutionAt(int index) const { return m_substitutions.at(index); }
void addSubstitution(const ParseTreeNode *node);
int templateParamCount() const { return m_templateParams.count(); }
ParseTreeNode *templateParamAt(int index) const { return m_templateParams.at(index); }
void addTemplateParam(ParseTreeNode *node) { m_templateParams << node; }
void clearTemplateParams() { m_templateParams.clear(); }
// TODO: Can we get rid of this by analyzing the stack?
bool isConversionOperator() const { return m_isConversionOperator; }
void setIsConversionOperator(bool is) { m_isConversionOperator = is; }
private:
int m_pos;
QByteArray m_mangledName;
QList<QByteArray> m_substitutions;
QList<ParseTreeNode *> m_templateParams;
bool m_isConversionOperator;
QStack<ParseTreeNode *> m_parseStack;
static const char eoi = '$';
};
} // namespace Internal
} // namespace Debugger
#endif // GLOBAL_PARSE_STATE_H
HEADERS += \
$$PWD/namedemangler.h \
$$PWD/parsetreenodes.h \
namedemangler/demanglerexceptions.h
$$PWD/demanglerexceptions.h \
$$PWD/globalparsestate.h
SOURCES += \
$$PWD/namedemangler.cpp \
$$PWD/parsetreenodes.cpp
$$PWD/parsetreenodes.cpp \
$$PWD/globalparsestate.cpp
include(../qttest.pri)
APPSOURCEDIR = $$CREATORSOURCEDIR/src/plugins/qt4projectmanager/wizards
LIBS *= -L$$IDE_LIBRARY_PATH -lUtils
DEBUGGERDIR = $$IDE_SOURCE_TREE/src/plugins/debugger
INCLUDEPATH += $$DEBUGGERDIR
HEADERS += \
$$DEBUGGERDIR/namedemangler/namedemangler.h \
$$DEBUGGERDIR/namedemangler/parsetreenodes.h
SOURCES += \
tst_namedemangler.cpp \
$$DEBUGGERDIR/namedemangler/namedemangler.cpp \
$$DEBUGGERDIR/namedemangler/parsetreenodes.cpp
SOURCES = tst_namedemangler.cpp
include($$DEBUGGERDIR/namedemangler/namedemangler.pri)
......@@ -49,7 +49,7 @@ class NameDemanglerAutoTest : public QObject
private slots:
void testUnmangledName();
void testDisjunctFirstSets();
void TEST_CORRECTLY_MANGLED_NAMEs();
void testCorrectlyMangledNames();
void testIncorrectlyMangledNames();
private:
......@@ -62,7 +62,7 @@ void NameDemanglerAutoTest::testUnmangledName()
QVERIFY(demangler.demangle("f") && demangler.demangledName() == "f");
}
void NameDemanglerAutoTest::TEST_CORRECTLY_MANGLED_NAMEs()
void NameDemanglerAutoTest::testCorrectlyMangledNames()
{
TEST_CORRECTLY_MANGLED_NAME("_Z1fv", "f()");
TEST_CORRECTLY_MANGLED_NAME("_Z1fi", "f(int)");
......@@ -313,7 +313,7 @@ void NameDemanglerAutoTest::testDisjunctFirstSets()
|| !SourceNameNode::mangledRepresentationStartsWith(c));
// <array-type>
QVERIFY(!NonNegativeNumberNode::mangledRepresentationStartsWith(c)
QVERIFY(!NonNegativeNumberNode<10>::mangledRepresentationStartsWith(c)
|| !ExpressionNode::mangledRepresentationStartsWith(c));
}
......@@ -399,18 +399,18 @@ void NameDemanglerAutoTest::testDisjunctFirstSets()
&& !CvQualifiersNode::mangledRepresentationStartsWith('D'));
// <array-type>
QVERIFY(!NonNegativeNumberNode::mangledRepresentationStartsWith('_'));
QVERIFY(!NonNegativeNumberNode<10>::mangledRepresentationStartsWith('_'));
QVERIFY(!ExpressionNode::mangledRepresentationStartsWith('_'));
// <substitution>
QVERIFY(!NonNegativeNumberNode::mangledRepresentationStartsWith('_', 36)
&& !NonNegativeNumberNode::mangledRepresentationStartsWith('t', 36)
&& !NonNegativeNumberNode::mangledRepresentationStartsWith('a', 36)
&& !NonNegativeNumberNode::mangledRepresentationStartsWith('b', 36)
&& !NonNegativeNumberNode::mangledRepresentationStartsWith('s', 36)
&& !NonNegativeNumberNode::mangledRepresentationStartsWith('i', 36)
&& !NonNegativeNumberNode::mangledRepresentationStartsWith('o', 36)
&& !NonNegativeNumberNode::mangledRepresentationStartsWith('d', 36));
QVERIFY(!NonNegativeNumberNode<36>::mangledRepresentationStartsWith('_')
&& !NonNegativeNumberNode<36>::mangledRepresentationStartsWith('t')
&& !NonNegativeNumberNode<36>::mangledRepresentationStartsWith('a')
&& !NonNegativeNumberNode<36>::mangledRepresentationStartsWith('b')
&& !NonNegativeNumberNode<36>::mangledRepresentationStartsWith('s')
&& !NonNegativeNumberNode<36>::mangledRepresentationStartsWith('i')
&& !NonNegativeNumberNode<36>::mangledRepresentationStartsWith('o')
&& !NonNegativeNumberNode<36>::mangledRepresentationStartsWith('d'));
// <special-name>
QVERIFY(!CallOffsetNode::mangledRepresentationStartsWith('V')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment