2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-08-13 16:38:45 +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
|
2010-08-13 16:38:45 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-08-13 16:38:45 +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.
|
2010-08-13 16:38:45 +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.
|
2010-08-13 16:38:45 +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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-08-13 16:38:45 +02:00
|
|
|
|
|
|
|
|
#include "cppelementevaluator.h"
|
|
|
|
|
|
2014-05-22 11:04:57 -04:00
|
|
|
#include "cppeditor.h"
|
|
|
|
|
|
2011-07-08 09:56:02 +02:00
|
|
|
#include <cpptools/cpptoolsreuse.h>
|
2013-04-02 11:52:31 +02:00
|
|
|
#include <cpptools/typehierarchybuilder.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2010-08-13 16:38:45 +02:00
|
|
|
#include <cplusplus/ExpressionUnderCursor.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <cplusplus/Icons.h>
|
|
|
|
|
#include <cplusplus/TypeOfExpression.h>
|
2010-08-13 16:38:45 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QSet>
|
|
|
|
|
#include <QQueue>
|
2010-08-13 16:38:45 +02:00
|
|
|
|
|
|
|
|
using namespace CppEditor;
|
2014-06-17 17:41:39 -07:00
|
|
|
using namespace CppEditor::Internal;
|
2010-08-13 16:38:45 +02:00
|
|
|
using namespace CPlusPlus;
|
|
|
|
|
|
|
|
|
|
namespace {
|
2010-10-01 11:15:28 +02:00
|
|
|
QStringList stripName(const QString &name) {
|
|
|
|
|
QStringList all;
|
|
|
|
|
all << name;
|
|
|
|
|
int colonColon = 0;
|
|
|
|
|
const int size = name.size();
|
|
|
|
|
while ((colonColon = name.indexOf(QLatin1String("::"), colonColon)) != -1) {
|
|
|
|
|
all << name.right(size - colonColon - 2);
|
|
|
|
|
colonColon += 2;
|
|
|
|
|
}
|
|
|
|
|
return all;
|
|
|
|
|
}
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-22 11:04:57 -04:00
|
|
|
CppElementEvaluator::CppElementEvaluator(TextEditor::BaseTextEditorWidget *editor) :
|
2010-08-13 16:38:45 +02:00
|
|
|
m_editor(editor),
|
2013-04-02 11:28:11 +02:00
|
|
|
m_modelManager(CppTools::CppModelManagerInterface::instance()),
|
2010-08-13 16:38:45 +02:00
|
|
|
m_tc(editor->textCursor()),
|
2011-07-08 09:56:02 +02:00
|
|
|
m_lookupBaseClasses(false),
|
|
|
|
|
m_lookupDerivedClasses(false)
|
2010-08-13 16:38:45 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void CppElementEvaluator::setTextCursor(const QTextCursor &tc)
|
|
|
|
|
{ m_tc = tc; }
|
|
|
|
|
|
|
|
|
|
void CppElementEvaluator::setLookupBaseClasses(const bool lookup)
|
|
|
|
|
{ m_lookupBaseClasses = lookup; }
|
|
|
|
|
|
2011-07-08 09:56:02 +02:00
|
|
|
void CppElementEvaluator::setLookupDerivedClasses(const bool lookup)
|
|
|
|
|
{ m_lookupDerivedClasses = lookup; }
|
|
|
|
|
|
2010-08-13 16:38:45 +02:00
|
|
|
// @todo: Consider refactoring code from CPPEditor::findLinkAt into here.
|
2011-01-17 16:29:57 +01:00
|
|
|
void CppElementEvaluator::execute()
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
2011-01-17 16:29:57 +01:00
|
|
|
clear();
|
|
|
|
|
|
2010-08-13 16:38:45 +02:00
|
|
|
if (!m_modelManager)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const Snapshot &snapshot = m_modelManager->snapshot();
|
2014-08-01 23:31:56 +02:00
|
|
|
Document::Ptr doc = snapshot.document(m_editor->textDocument()->filePath());
|
2010-08-13 16:38:45 +02:00
|
|
|
if (!doc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int line = 0;
|
|
|
|
|
int column = 0;
|
|
|
|
|
const int pos = m_tc.position();
|
|
|
|
|
m_editor->convertPosition(pos, &line, &column);
|
|
|
|
|
|
2011-08-24 12:01:50 +02:00
|
|
|
checkDiagnosticMessage(pos);
|
2010-08-13 16:38:45 +02:00
|
|
|
|
2011-01-17 16:29:57 +01:00
|
|
|
if (!matchIncludeFile(doc, line) && !matchMacroInUse(doc, pos)) {
|
2011-07-08 09:56:02 +02:00
|
|
|
CppTools::moveCursorToEndOfIdentifier(&m_tc);
|
2010-08-13 16:38:45 +02:00
|
|
|
|
2011-01-17 16:29:57 +01:00
|
|
|
// Fetch the expression's code
|
|
|
|
|
ExpressionUnderCursor expressionUnderCursor;
|
|
|
|
|
const QString &expression = expressionUnderCursor(m_tc);
|
|
|
|
|
Scope *scope = doc->scopeAt(line, column);
|
2010-08-13 16:38:45 +02:00
|
|
|
|
2011-01-17 16:29:57 +01:00
|
|
|
TypeOfExpression typeOfExpression;
|
|
|
|
|
typeOfExpression.init(doc, snapshot);
|
2013-01-19 13:17:34 +01:00
|
|
|
// make possible to instantiate templates
|
|
|
|
|
typeOfExpression.setExpandTemplates(true);
|
2012-01-12 17:35:37 +01:00
|
|
|
const QList<LookupItem> &lookupItems = typeOfExpression(expression.toUtf8(), scope);
|
2011-01-17 16:29:57 +01:00
|
|
|
if (lookupItems.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const LookupItem &lookupItem = lookupItems.first(); // ### TODO: select best candidate.
|
2013-08-18 21:47:14 +02:00
|
|
|
handleLookupItemMatch(snapshot, lookupItem, typeOfExpression.context(), scope);
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-24 12:01:50 +02:00
|
|
|
void CppElementEvaluator::checkDiagnosticMessage(int pos)
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
2011-08-24 12:01:50 +02:00
|
|
|
foreach (const QTextEdit::ExtraSelection &sel,
|
|
|
|
|
m_editor->extraSelections(TextEditor::BaseTextEditorWidget::CodeWarningsSelection)) {
|
|
|
|
|
if (pos >= sel.cursor.selectionStart() && pos <= sel.cursor.selectionEnd()) {
|
|
|
|
|
m_diagnosis = sel.format.toolTip();
|
2011-01-17 16:29:57 +01:00
|
|
|
break;
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CppElementEvaluator::matchIncludeFile(const CPlusPlus::Document::Ptr &document, unsigned line)
|
|
|
|
|
{
|
2013-07-25 11:21:31 +02:00
|
|
|
foreach (const Document::Include &includeFile, document->resolvedIncludes()) {
|
2010-08-13 16:38:45 +02:00
|
|
|
if (includeFile.line() == line) {
|
|
|
|
|
m_element = QSharedPointer<CppElement>(new CppInclude(includeFile));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CppElementEvaluator::matchMacroInUse(const CPlusPlus::Document::Ptr &document, unsigned pos)
|
|
|
|
|
{
|
|
|
|
|
foreach (const Document::MacroUse &use, document->macroUses()) {
|
2014-05-09 10:04:13 -04:00
|
|
|
if (use.containsUtf16charOffset(pos)) {
|
|
|
|
|
const unsigned begin = use.utf16charsBegin();
|
|
|
|
|
if (pos < begin + use.macro().nameToQString().size()) {
|
2010-08-13 16:38:45 +02:00
|
|
|
m_element = QSharedPointer<CppElement>(new CppMacro(use.macro()));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppElementEvaluator::handleLookupItemMatch(const Snapshot &snapshot,
|
|
|
|
|
const LookupItem &lookupItem,
|
2013-08-18 21:47:14 +02:00
|
|
|
const LookupContext &context,
|
|
|
|
|
const Scope *scope)
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
|
|
|
|
Symbol *declaration = lookupItem.declaration();
|
|
|
|
|
if (!declaration) {
|
|
|
|
|
const QString &type = Overview().prettyType(lookupItem.type(), QString());
|
2013-08-18 21:47:14 +02:00
|
|
|
// special case for bug QTCREATORBUG-4780
|
|
|
|
|
if (scope && scope->isFunction()
|
2014-05-15 12:00:13 -04:00
|
|
|
&& lookupItem.type().match(scope->asFunction()->returnType())) {
|
2013-08-18 21:47:14 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2010-08-13 16:38:45 +02:00
|
|
|
m_element = QSharedPointer<CppElement>(new Unknown(type));
|
|
|
|
|
} else {
|
|
|
|
|
const FullySpecifiedType &type = declaration->type();
|
|
|
|
|
if (declaration->isNamespace()) {
|
|
|
|
|
m_element = QSharedPointer<CppElement>(new CppNamespace(declaration));
|
2011-07-08 09:56:02 +02:00
|
|
|
} else if (declaration->isClass()
|
|
|
|
|
|| declaration->isForwardClassDeclaration()
|
|
|
|
|
|| (declaration->isTemplate() && declaration->asTemplate()->declaration()
|
|
|
|
|
&& (declaration->asTemplate()->declaration()->isClass()
|
|
|
|
|
|| declaration->asTemplate()->declaration()->isForwardClassDeclaration()))) {
|
2013-11-19 18:12:20 +01:00
|
|
|
LookupContext contextToUse = context;
|
2010-08-13 16:38:45 +02:00
|
|
|
if (declaration->isForwardClassDeclaration())
|
2012-01-20 14:43:21 +01:00
|
|
|
if (Symbol *classDeclaration =
|
2012-01-24 11:07:26 +01:00
|
|
|
m_symbolFinder.findMatchingClassDeclaration(declaration, snapshot)) {
|
2010-08-13 16:38:45 +02:00
|
|
|
declaration = classDeclaration;
|
2013-11-19 18:12:20 +01:00
|
|
|
const QString fileName = QString::fromUtf8(declaration->fileName(),
|
|
|
|
|
declaration->fileNameLength());
|
|
|
|
|
const Document::Ptr declarationDocument = snapshot.document(fileName);
|
|
|
|
|
if (declarationDocument != context.thisDocument())
|
|
|
|
|
contextToUse = LookupContext(declarationDocument, snapshot);
|
2012-01-20 14:43:21 +01:00
|
|
|
}
|
2013-11-19 18:12:20 +01:00
|
|
|
|
2010-08-13 16:38:45 +02:00
|
|
|
CppClass *cppClass = new CppClass(declaration);
|
|
|
|
|
if (m_lookupBaseClasses)
|
2013-11-19 18:12:20 +01:00
|
|
|
cppClass->lookupBases(declaration, contextToUse);
|
2011-07-08 09:56:02 +02:00
|
|
|
if (m_lookupDerivedClasses)
|
|
|
|
|
cppClass->lookupDerived(declaration, snapshot);
|
2010-08-13 16:38:45 +02:00
|
|
|
m_element = QSharedPointer<CppElement>(cppClass);
|
2011-06-09 09:30:32 +02:00
|
|
|
} else if (Enum *enumDecl = declaration->asEnum()) {
|
|
|
|
|
m_element = QSharedPointer<CppElement>(new CppEnum(enumDecl));
|
|
|
|
|
} else if (EnumeratorDeclaration *enumerator = dynamic_cast<EnumeratorDeclaration *>(declaration)) {
|
|
|
|
|
m_element = QSharedPointer<CppElement>(new CppEnumerator(enumerator));
|
2010-08-13 16:38:45 +02:00
|
|
|
} else if (declaration->isTypedef()) {
|
|
|
|
|
m_element = QSharedPointer<CppElement>(new CppTypedef(declaration));
|
2011-07-08 09:56:02 +02:00
|
|
|
} else if (declaration->isFunction()
|
|
|
|
|
|| (type.isValid() && type->isFunctionType())
|
|
|
|
|
|| declaration->isTemplate()) {
|
2010-08-13 16:38:45 +02:00
|
|
|
m_element = QSharedPointer<CppElement>(new CppFunction(declaration));
|
|
|
|
|
} else if (declaration->isDeclaration() && type.isValid()) {
|
|
|
|
|
m_element = QSharedPointer<CppElement>(
|
|
|
|
|
new CppVariable(declaration, context, lookupItem.scope()));
|
|
|
|
|
} else {
|
|
|
|
|
m_element = QSharedPointer<CppElement>(new CppDeclarableElement(declaration));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-17 16:29:57 +01:00
|
|
|
bool CppElementEvaluator::identifiedCppElement() const
|
|
|
|
|
{
|
|
|
|
|
return !m_element.isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QSharedPointer<CppElement> &CppElementEvaluator::cppElement() const
|
|
|
|
|
{
|
|
|
|
|
return m_element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CppElementEvaluator::hasDiagnosis() const
|
|
|
|
|
{
|
|
|
|
|
return !m_diagnosis.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString &CppElementEvaluator::diagnosis() const
|
|
|
|
|
{
|
|
|
|
|
return m_diagnosis;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppEditor::Internal::CppElementEvaluator::clear()
|
|
|
|
|
{
|
|
|
|
|
m_element.clear();
|
|
|
|
|
m_diagnosis.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-13 16:38:45 +02:00
|
|
|
// CppElement
|
2012-10-10 22:32:31 +02:00
|
|
|
CppElement::CppElement() : helpCategory(TextEditor::HelpItem::Unknown)
|
2010-08-13 16:38:45 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
CppElement::~CppElement()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
// Unknown
|
2012-10-10 22:32:31 +02:00
|
|
|
Unknown::Unknown(const QString &type) : type(type)
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
2012-10-10 22:32:31 +02:00
|
|
|
tooltip = type;
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CppInclude
|
|
|
|
|
|
|
|
|
|
CppInclude::CppInclude(const Document::Include &includeFile) :
|
2013-06-06 09:35:40 +02:00
|
|
|
path(QDir::toNativeSeparators(includeFile.resolvedFileName())),
|
|
|
|
|
fileName(QFileInfo(includeFile.resolvedFileName()).fileName())
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
2012-10-10 22:32:31 +02:00
|
|
|
helpCategory = TextEditor::HelpItem::Brief;
|
|
|
|
|
helpIdCandidates = QStringList(fileName);
|
|
|
|
|
helpMark = fileName;
|
2014-05-22 11:04:57 -04:00
|
|
|
link = TextEditor::BaseTextEditorWidget::Link(path);
|
2012-10-10 22:32:31 +02:00
|
|
|
tooltip = path;
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CppMacro
|
2012-10-10 22:32:31 +02:00
|
|
|
CppMacro::CppMacro(const Macro ¯o)
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
2012-10-10 22:32:31 +02:00
|
|
|
helpCategory = TextEditor::HelpItem::Macro;
|
2014-05-09 10:04:13 -04:00
|
|
|
const QString macroName = QString::fromUtf8(macro.name(), macro.name().size());
|
2012-10-10 22:32:31 +02:00
|
|
|
helpIdCandidates = QStringList(macroName);
|
|
|
|
|
helpMark = macroName;
|
2014-05-22 11:04:57 -04:00
|
|
|
link = TextEditor::BaseTextEditorWidget::Link(macro.fileName(), macro.line());
|
2012-10-10 22:32:31 +02:00
|
|
|
tooltip = macro.toStringWithLineBreaks();
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CppDeclarableElement
|
2011-07-08 09:56:02 +02:00
|
|
|
|
2013-07-04 20:11:10 +02:00
|
|
|
CppDeclarableElement::CppDeclarableElement(Symbol *declaration)
|
|
|
|
|
: CppElement()
|
|
|
|
|
, declaration(declaration)
|
|
|
|
|
, icon(Icons().iconForSymbol(declaration))
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
|
|
|
|
Overview overview;
|
2012-10-10 22:09:44 +02:00
|
|
|
overview.showArgumentNames = true;
|
|
|
|
|
overview.showReturnTypes = true;
|
2012-10-10 22:32:31 +02:00
|
|
|
name = overview.prettyName(declaration->name());
|
2010-08-26 16:16:22 +02:00
|
|
|
if (declaration->enclosingScope()->isClass() ||
|
|
|
|
|
declaration->enclosingScope()->isNamespace() ||
|
|
|
|
|
declaration->enclosingScope()->isEnum()) {
|
2012-10-10 22:32:31 +02:00
|
|
|
qualifiedName = overview.prettyName(LookupContext::fullyQualifiedName(declaration));
|
|
|
|
|
helpIdCandidates = stripName(qualifiedName);
|
2010-08-13 16:38:45 +02:00
|
|
|
} else {
|
2012-10-10 22:32:31 +02:00
|
|
|
qualifiedName = name;
|
|
|
|
|
helpIdCandidates.append(name);
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-10 22:32:31 +02:00
|
|
|
tooltip = overview.prettyType(declaration->type(), qualifiedName);
|
2014-07-30 16:30:31 +02:00
|
|
|
link = CppEditorWidget::linkToSymbol(declaration);
|
2012-10-10 22:32:31 +02:00
|
|
|
helpMark = name;
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CppNamespace
|
|
|
|
|
CppNamespace::CppNamespace(Symbol *declaration) : CppDeclarableElement(declaration)
|
|
|
|
|
{
|
2012-10-10 22:32:31 +02:00
|
|
|
helpCategory = TextEditor::HelpItem::ClassOrNamespace;
|
|
|
|
|
tooltip = qualifiedName;
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CppClass
|
|
|
|
|
CppClass::CppClass(Symbol *declaration) : CppDeclarableElement(declaration)
|
|
|
|
|
{
|
2012-10-10 22:32:31 +02:00
|
|
|
helpCategory = TextEditor::HelpItem::ClassOrNamespace;
|
|
|
|
|
tooltip = qualifiedName;
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
2013-07-04 20:11:10 +02:00
|
|
|
bool CppClass::operator==(const CppClass &other)
|
|
|
|
|
{
|
|
|
|
|
return this->declaration == other.declaration;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-13 16:38:45 +02:00
|
|
|
void CppClass::lookupBases(Symbol *declaration, const CPlusPlus::LookupContext &context)
|
|
|
|
|
{
|
|
|
|
|
typedef QPair<ClassOrNamespace *, CppClass *> Data;
|
|
|
|
|
|
|
|
|
|
if (ClassOrNamespace *clazz = context.lookupType(declaration)) {
|
|
|
|
|
QSet<ClassOrNamespace *> visited;
|
|
|
|
|
|
|
|
|
|
QQueue<Data> q;
|
|
|
|
|
q.enqueue(qMakePair(clazz, this));
|
|
|
|
|
while (!q.isEmpty()) {
|
|
|
|
|
Data current = q.dequeue();
|
|
|
|
|
clazz = current.first;
|
|
|
|
|
visited.insert(clazz);
|
|
|
|
|
const QList<ClassOrNamespace *> &bases = clazz->usings();
|
|
|
|
|
foreach (ClassOrNamespace *baseClass, bases) {
|
|
|
|
|
const QList<Symbol *> &symbols = baseClass->symbols();
|
|
|
|
|
foreach (Symbol *symbol, symbols) {
|
|
|
|
|
if (symbol->isClass() && (
|
|
|
|
|
clazz = context.lookupType(symbol)) &&
|
|
|
|
|
!visited.contains(clazz)) {
|
|
|
|
|
CppClass baseCppClass(symbol);
|
|
|
|
|
CppClass *cppClass = current.second;
|
2012-10-10 22:32:31 +02:00
|
|
|
cppClass->bases.append(baseCppClass);
|
|
|
|
|
q.enqueue(qMakePair(clazz, &cppClass->bases.last()));
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-08 09:56:02 +02:00
|
|
|
void CppClass::lookupDerived(CPlusPlus::Symbol *declaration, const CPlusPlus::Snapshot &snapshot)
|
|
|
|
|
{
|
2013-04-02 11:28:11 +02:00
|
|
|
typedef QPair<CppClass *, CppTools::TypeHierarchy> Data;
|
2011-07-08 09:56:02 +02:00
|
|
|
|
2013-04-02 11:28:11 +02:00
|
|
|
CppTools::TypeHierarchyBuilder builder(declaration, snapshot);
|
|
|
|
|
const CppTools::TypeHierarchy &completeHierarchy = builder.buildDerivedTypeHierarchy();
|
2011-07-08 09:56:02 +02:00
|
|
|
|
|
|
|
|
QQueue<Data> q;
|
|
|
|
|
q.enqueue(qMakePair(this, completeHierarchy));
|
|
|
|
|
while (!q.isEmpty()) {
|
|
|
|
|
const Data ¤t = q.dequeue();
|
|
|
|
|
CppClass *clazz = current.first;
|
2013-04-02 11:28:11 +02:00
|
|
|
const CppTools::TypeHierarchy &classHierarchy = current.second;
|
|
|
|
|
foreach (const CppTools::TypeHierarchy &derivedHierarchy, classHierarchy.hierarchy()) {
|
2012-10-10 22:32:31 +02:00
|
|
|
clazz->derived.append(CppClass(derivedHierarchy.symbol()));
|
|
|
|
|
q.enqueue(qMakePair(&clazz->derived.last(), derivedHierarchy));
|
2011-07-08 09:56:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-13 16:38:45 +02:00
|
|
|
// CppFunction
|
2012-10-10 22:32:31 +02:00
|
|
|
CppFunction::CppFunction(Symbol *declaration)
|
|
|
|
|
: CppDeclarableElement(declaration)
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
2012-10-10 22:32:31 +02:00
|
|
|
helpCategory = TextEditor::HelpItem::Function;
|
2010-08-13 16:38:45 +02:00
|
|
|
|
|
|
|
|
const FullySpecifiedType &type = declaration->type();
|
|
|
|
|
|
|
|
|
|
// Functions marks can be found either by the main overload or signature based
|
|
|
|
|
// (with no argument names and no return). Help ids have no signature at all.
|
|
|
|
|
Overview overview;
|
2012-10-10 22:09:44 +02:00
|
|
|
overview.showDefaultArguments = false;
|
2012-10-10 22:32:31 +02:00
|
|
|
helpMark = overview.prettyType(type, name);
|
2010-08-13 16:38:45 +02:00
|
|
|
|
2012-10-10 22:09:44 +02:00
|
|
|
overview.showFunctionSignatures = false;
|
2012-10-10 22:32:31 +02:00
|
|
|
helpIdCandidates.append(overview.prettyName(declaration->name()));
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CppEnum
|
2011-06-09 09:30:32 +02:00
|
|
|
CppEnum::CppEnum(Enum *declaration)
|
|
|
|
|
: CppDeclarableElement(declaration)
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
2012-10-10 22:32:31 +02:00
|
|
|
helpCategory = TextEditor::HelpItem::Enum;
|
|
|
|
|
tooltip = qualifiedName;
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CppTypedef
|
2010-09-22 18:29:08 +02:00
|
|
|
CppTypedef::CppTypedef(Symbol *declaration) : CppDeclarableElement(declaration)
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
2012-10-10 22:32:31 +02:00
|
|
|
helpCategory = TextEditor::HelpItem::Typedef;
|
|
|
|
|
tooltip = Overview().prettyType(declaration->type(), qualifiedName);
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CppVariable
|
|
|
|
|
CppVariable::CppVariable(Symbol *declaration, const LookupContext &context, Scope *scope) :
|
|
|
|
|
CppDeclarableElement(declaration)
|
|
|
|
|
{
|
|
|
|
|
const FullySpecifiedType &type = declaration->type();
|
|
|
|
|
|
|
|
|
|
const Name *typeName = 0;
|
|
|
|
|
if (type->isNamedType()) {
|
|
|
|
|
typeName = type->asNamedType()->name();
|
|
|
|
|
} else if (type->isPointerType() || type->isReferenceType()) {
|
|
|
|
|
FullySpecifiedType associatedType;
|
|
|
|
|
if (type->isPointerType())
|
|
|
|
|
associatedType = type->asPointerType()->elementType();
|
|
|
|
|
else
|
|
|
|
|
associatedType = type->asReferenceType()->elementType();
|
|
|
|
|
if (associatedType->isNamedType())
|
|
|
|
|
typeName = associatedType->asNamedType()->name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeName) {
|
|
|
|
|
if (ClassOrNamespace *clazz = context.lookupType(typeName, scope)) {
|
|
|
|
|
if (!clazz->symbols().isEmpty()) {
|
|
|
|
|
Overview overview;
|
|
|
|
|
Symbol *symbol = clazz->symbols().at(0);
|
|
|
|
|
const QString &name =
|
|
|
|
|
overview.prettyName(LookupContext::fullyQualifiedName(symbol));
|
2010-10-01 11:15:28 +02:00
|
|
|
if (!name.isEmpty()) {
|
2012-10-10 22:32:31 +02:00
|
|
|
tooltip = name;
|
|
|
|
|
helpCategory = TextEditor::HelpItem::ClassOrNamespace;
|
2010-10-01 11:15:28 +02:00
|
|
|
const QStringList &allNames = stripName(name);
|
|
|
|
|
if (!allNames.isEmpty()) {
|
2012-10-10 22:32:31 +02:00
|
|
|
helpMark = allNames.last();
|
|
|
|
|
helpIdCandidates = allNames;
|
2010-10-01 11:15:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-09 09:30:32 +02:00
|
|
|
CppEnumerator::CppEnumerator(CPlusPlus::EnumeratorDeclaration *declaration)
|
|
|
|
|
: CppDeclarableElement(declaration)
|
|
|
|
|
{
|
2012-10-10 22:32:31 +02:00
|
|
|
helpCategory = TextEditor::HelpItem::Enum;
|
2011-06-09 09:30:32 +02:00
|
|
|
|
|
|
|
|
Overview overview;
|
|
|
|
|
|
|
|
|
|
Symbol *enumSymbol = declaration->enclosingScope()->asEnum();
|
|
|
|
|
const QString enumName = overview.prettyName(LookupContext::fullyQualifiedName(enumSymbol));
|
|
|
|
|
const QString enumeratorName = overview.prettyName(declaration->name());
|
|
|
|
|
QString enumeratorValue;
|
2012-10-10 22:32:31 +02:00
|
|
|
if (const StringLiteral *value = declaration->constantValue())
|
2011-06-09 09:30:32 +02:00
|
|
|
enumeratorValue = QString::fromUtf8(value->chars(), value->size());
|
|
|
|
|
|
2012-10-10 22:32:31 +02:00
|
|
|
helpMark = overview.prettyName(enumSymbol->name());
|
2011-06-09 09:30:32 +02:00
|
|
|
|
2012-10-10 22:32:31 +02:00
|
|
|
tooltip = enumeratorName;
|
2011-06-09 09:30:32 +02:00
|
|
|
if (!enumName.isEmpty())
|
|
|
|
|
tooltip.prepend(enumName + QLatin1Char(' '));
|
|
|
|
|
if (!enumeratorValue.isEmpty())
|
|
|
|
|
tooltip.append(QLatin1String(" = ") + enumeratorValue);
|
|
|
|
|
}
|