2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-07-19 13:08:39 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2012-07-19 13:08:39 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-07-19 13:08:39 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2012-07-19 13:08:39 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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.
|
2012-07-19 13:08:39 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-07-19 13:08:39 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-07-19 13:08:39 +02:00
|
|
|
|
|
|
|
|
#include "Dumpers.h"
|
|
|
|
|
|
2013-03-27 18:54:03 +01:00
|
|
|
#include "Overview.h"
|
|
|
|
|
#include "LookupContext.h"
|
|
|
|
|
|
|
|
|
|
#include <cplusplus/Literals.h>
|
|
|
|
|
#include <cplusplus/Scope.h>
|
|
|
|
|
|
2012-07-19 13:08:39 +02:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
#include <typeinfo>
|
|
|
|
|
|
|
|
|
|
static QString indent(QString s, int level = 2)
|
|
|
|
|
{
|
|
|
|
|
QString indentString(level, QLatin1Char(' '));
|
|
|
|
|
QString result;
|
|
|
|
|
int last = 0;
|
|
|
|
|
for (int i = 0; i < s.length(); ++i) {
|
|
|
|
|
if (s.at(i) == QLatin1Char('\n') || i == s.length() - 1) {
|
|
|
|
|
result.append(indentString);
|
|
|
|
|
result.append(s.midRef(last, i + 1));
|
|
|
|
|
last = i + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CPlusPlus::toString(const Name *name, QString id)
|
|
|
|
|
{
|
|
|
|
|
Overview oo;
|
2012-11-27 22:07:47 +02:00
|
|
|
return QString::fromLatin1("%0: %1").arg(id, name ? oo.prettyName(name) : QLatin1String("(null)"));
|
2012-07-19 13:08:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CPlusPlus::toString(FullySpecifiedType ty, QString id)
|
|
|
|
|
{
|
|
|
|
|
Overview oo;
|
2012-11-27 22:07:47 +02:00
|
|
|
return QString::fromLatin1("%0: %1 (a %2)").arg(id, oo.prettyType(ty),
|
|
|
|
|
QLatin1String(ty.type() ? typeid(*ty.type()).name() : "(null)"));
|
2012-07-19 13:08:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CPlusPlus::toString(const Symbol *s, QString id)
|
|
|
|
|
{
|
|
|
|
|
if (!s)
|
2012-11-27 22:07:47 +02:00
|
|
|
return QString::fromLatin1("%0: (null)").arg(id);
|
2012-07-19 13:08:39 +02:00
|
|
|
|
2012-11-27 22:07:47 +02:00
|
|
|
return QString::fromLatin1("%0: %1 (%2) at %3:%4:%5\n%6").arg(
|
2012-07-19 13:08:39 +02:00
|
|
|
id,
|
|
|
|
|
QString::fromLatin1(typeid(*s).name()),
|
2012-11-27 22:07:47 +02:00
|
|
|
s->identifier() ? QString::fromUtf8(s->identifier()->chars()) : QLatin1String("no id"),
|
2012-07-19 13:08:39 +02:00
|
|
|
QString::fromLatin1(s->fileName()),
|
|
|
|
|
QString::number(s->line()),
|
|
|
|
|
QString::number(s->column()),
|
|
|
|
|
indent(toString(s->type())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CPlusPlus::toString(LookupItem it, QString id)
|
|
|
|
|
{
|
2012-11-27 22:07:47 +02:00
|
|
|
QString result = QString::fromLatin1("%1:").arg(id);
|
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>
2013-01-08 03:32:53 +02:00
|
|
|
if (it.declaration())
|
2012-11-27 22:07:47 +02:00
|
|
|
result.append(QString::fromLatin1("\n%1").arg(indent(toString(it.declaration(), QLatin1String("Decl")))));
|
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>
2013-01-08 03:32:53 +02:00
|
|
|
if (it.type().isValid())
|
2012-11-27 22:07:47 +02:00
|
|
|
result.append(QString::fromLatin1("\n%1").arg(indent(toString(it.type()))));
|
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>
2013-01-08 03:32:53 +02:00
|
|
|
if (it.scope())
|
2012-11-27 22:07:47 +02:00
|
|
|
result.append(QString::fromLatin1("\n%1").arg(indent(toString(it.scope(), QLatin1String("Scope")))));
|
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>
2013-01-08 03:32:53 +02:00
|
|
|
if (it.binding())
|
2012-11-27 22:07:47 +02:00
|
|
|
result.append(QString::fromLatin1("\n%1").arg(indent(toString(it.binding(), QLatin1String("Binding")))));
|
2012-07-19 13:08:39 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CPlusPlus::toString(const ClassOrNamespace *binding, QString id)
|
|
|
|
|
{
|
|
|
|
|
if (!binding)
|
2012-11-27 22:07:47 +02:00
|
|
|
return QString::fromLatin1("%0: (null)").arg(id);
|
2012-07-19 13:08:39 +02:00
|
|
|
|
2012-11-27 22:07:47 +02:00
|
|
|
QString result = QString::fromLatin1("%0: %1 symbols").arg(
|
2012-07-19 13:08:39 +02:00
|
|
|
id,
|
|
|
|
|
QString::number(binding->symbols().length()));
|
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>
2013-01-08 03:32:53 +02:00
|
|
|
if (binding->templateId())
|
2012-11-27 22:07:47 +02:00
|
|
|
result.append(QString::fromLatin1("\n%1").arg(indent(toString(binding->templateId(), QLatin1String("Template")))));
|
2012-07-19 13:08:39 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPlusPlus::dump(const Name *name)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << qPrintable(toString(name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPlusPlus::dump(FullySpecifiedType ty)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << qPrintable(toString(ty));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPlusPlus::dump(const Symbol *s)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << qPrintable(toString(s));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPlusPlus::dump(LookupItem it)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << qPrintable(toString(it));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPlusPlus::dump(const ClassOrNamespace *binding)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << qPrintable(toString(binding));
|
|
|
|
|
}
|