2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01: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
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "Icons.h"
|
|
|
|
|
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <cplusplus/FullySpecifiedType.h>
|
|
|
|
|
#include <cplusplus/Scope.h>
|
|
|
|
|
#include <cplusplus/Symbols.h>
|
|
|
|
|
#include <cplusplus/Type.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2019-11-15 18:53:02 +01:00
|
|
|
namespace CPlusPlus {
|
|
|
|
|
namespace Icons {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2019-11-15 18:53:02 +01:00
|
|
|
QIcon iconForSymbol(const Symbol *symbol)
|
2010-07-16 11:18:29 +02:00
|
|
|
{
|
|
|
|
|
return iconForType(iconTypeForSymbol(symbol));
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 18:53:02 +01:00
|
|
|
QIcon keywordIcon()
|
2010-07-16 11:18:29 +02:00
|
|
|
{
|
2018-07-25 10:00:38 +02:00
|
|
|
return iconForType(Utils::CodeModelIcon::Keyword);
|
2010-07-16 11:18:29 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 18:53:02 +01:00
|
|
|
QIcon macroIcon()
|
2010-07-16 11:18:29 +02:00
|
|
|
{
|
2018-07-25 10:00:38 +02:00
|
|
|
return iconForType(Utils::CodeModelIcon::Macro);
|
2010-07-16 11:18:29 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 18:53:02 +01:00
|
|
|
Utils::CodeModelIcon::Type iconTypeForSymbol(const Symbol *symbol)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-07-25 10:00:38 +02:00
|
|
|
using namespace Utils::CodeModelIcon;
|
2010-08-13 18:10:36 +02:00
|
|
|
if (const Template *templ = symbol->asTemplate()) {
|
|
|
|
|
if (Symbol *decl = templ->declaration())
|
|
|
|
|
return iconTypeForSymbol(decl);
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-09 17:44:06 +01:00
|
|
|
FullySpecifiedType symbolType = symbol->type();
|
|
|
|
|
if (symbol->isFunction() || (symbol->isDeclaration() && symbolType &&
|
|
|
|
|
symbolType->isFunctionType()))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-05 12:21:18 +01:00
|
|
|
const Function *function = symbol->asFunction();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!function)
|
2009-02-09 17:44:06 +01:00
|
|
|
function = symbol->type()->asFunctionType();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
if (function->isSlot()) {
|
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 (function->isPublic())
|
2018-07-25 10:00:38 +02:00
|
|
|
return SlotPublic;
|
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
|
|
|
else if (function->isProtected())
|
2018-07-25 10:00:38 +02:00
|
|
|
return SlotProtected;
|
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
|
|
|
else if (function->isPrivate())
|
2018-07-25 10:00:38 +02:00
|
|
|
return SlotPrivate;
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (function->isSignal()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return Signal;
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (symbol->isPublic()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return symbol->isStatic() ? FuncPublicStatic : FuncPublic;
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (symbol->isProtected()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return symbol->isStatic() ? FuncProtectedStatic : FuncProtected;
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (symbol->isPrivate()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return symbol->isStatic() ? FuncPrivateStatic : FuncPrivate;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-08-26 16:16:22 +02:00
|
|
|
} else if (symbol->enclosingScope() && symbol->enclosingScope()->isEnum()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return Enumerator;
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (symbol->isDeclaration() || symbol->isArgument()) {
|
2014-10-30 19:43:48 +03:00
|
|
|
if (symbol->isPublic()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return symbol->isStatic() ? VarPublicStatic : VarPublic;
|
2014-10-30 19:43:48 +03:00
|
|
|
} else if (symbol->isProtected()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return symbol->isStatic() ? VarProtectedStatic : VarProtected;
|
2014-10-30 19:43:48 +03:00
|
|
|
} else if (symbol->isPrivate()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return symbol->isStatic() ? VarPrivateStatic : VarPrivate;
|
2014-10-30 19:43:48 +03:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (symbol->isEnum()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return Utils::CodeModelIcon::Enum;
|
2015-02-24 11:33:39 +01:00
|
|
|
} else if (symbol->isForwardClassDeclaration()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return Utils::CodeModelIcon::Class; // TODO: Store class key in ForwardClassDeclaration
|
2015-02-24 11:33:39 +01:00
|
|
|
} else if (const Class *klass = symbol->asClass()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return klass->isStruct() ? Struct : Utils::CodeModelIcon::Class;
|
2009-07-28 16:34:15 +02:00
|
|
|
} else if (symbol->isObjCClass() || symbol->isObjCForwardClassDeclaration()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return Utils::CodeModelIcon::Class;
|
2009-07-28 16:34:15 +02:00
|
|
|
} else if (symbol->isObjCProtocol() || symbol->isObjCForwardProtocolDeclaration()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return Utils::CodeModelIcon::Class;
|
2009-08-05 18:30:18 +02:00
|
|
|
} else if (symbol->isObjCMethod()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return FuncPublic;
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (symbol->isNamespace()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return Utils::CodeModelIcon::Namespace;
|
2013-04-04 11:27:06 +04:00
|
|
|
} else if (symbol->isTypenameArgument()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return Utils::CodeModelIcon::Class;
|
2017-06-12 18:27:57 +02:00
|
|
|
} else if (symbol->isQtPropertyDeclaration() || symbol->isObjCPropertyDeclaration()) {
|
2018-07-25 10:00:38 +02:00
|
|
|
return Property;
|
2008-12-02 12:01:29 +01:00
|
|
|
} else if (symbol->isUsingNamespaceDirective() ||
|
|
|
|
|
symbol->isUsingDeclaration()) {
|
|
|
|
|
// TODO: Might be nice to have a different icons for these things
|
2018-07-25 10:00:38 +02:00
|
|
|
return Utils::CodeModelIcon::Namespace;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-25 10:00:38 +02:00
|
|
|
return Unknown;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2019-11-15 18:53:02 +01:00
|
|
|
|
|
|
|
|
} // Icons
|
|
|
|
|
} // CPlusPlus
|