1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/* This is part of KDevelop
Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
Copyright 2006 Adam Treat <treat@kde.org>
Copyright 2006-2007 Hamish Rodda <rodda@kde.org>
Copyright 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "functiondeclaration.h"
#include "ducontext.h"
#include "duchainregister.h"
#include "types/functiontype.h"
#include <debug.h>
namespace KDevelop {
REGISTER_DUCHAIN_ITEM(FunctionDeclaration);
DEFINE_LIST_MEMBER_HASH(FunctionDeclarationData, m_defaultParameters, IndexedString)
FunctionDeclaration::FunctionDeclaration(FunctionDeclarationData& data) : FunctionDeclarationBase(data)
{
}
FunctionDeclaration::FunctionDeclaration(FunctionDeclarationData& data,
const RangeInRevision& range) : FunctionDeclarationBase(data, range)
{
}
FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration& rhs) : FunctionDeclarationBase(*new FunctionDeclarationData(
*rhs.d_func()))
{
}
FunctionDeclaration::FunctionDeclaration(const RangeInRevision& range, DUContext* context)
: FunctionDeclarationBase(*new FunctionDeclarationData, range)
{
d_func_dynamic()->setClassId(this);
if (context)
setContext(context);
}
FunctionDeclaration::~FunctionDeclaration()
{
}
Declaration* FunctionDeclaration::clonePrivate() const
{
return new FunctionDeclaration(*this);
}
bool FunctionDeclaration::isFunctionDeclaration() const
{
return true;
}
void FunctionDeclaration::setAbstractType(AbstractType::Ptr type)
{
if (type && !type.cast<FunctionType>()) {
qCDebug(LANGUAGE) << "wrong type attached to function declaration:" << type->toString();
}
Declaration::setAbstractType(type);
}
QString FunctionDeclaration::toString() const
{
AbstractType::Ptr type = abstractType();
if (!type)
return Declaration::toString();
TypePtr<FunctionType> function = type.cast<FunctionType>();
if (function) {
return QStringLiteral("%1 %2 %3").arg(function->partToString(FunctionType::SignatureReturn),
identifier().toString(),
function->partToString(FunctionType::SignatureArguments));
} else {
return Declaration::toString();
}
}
uint FunctionDeclaration::additionalIdentity() const
{
if (abstractType())
return abstractType()->hash();
else
return 0;
}
const IndexedString* FunctionDeclaration::defaultParameters() const
{
return d_func()->m_defaultParameters();
}
unsigned int FunctionDeclaration::defaultParametersSize() const
{
return d_func()->m_defaultParametersSize();
}
void FunctionDeclaration::addDefaultParameter(const IndexedString& str)
{
d_func_dynamic()->m_defaultParametersList().append(str);
}
void FunctionDeclaration::clearDefaultParameters()
{
d_func_dynamic()->m_defaultParametersList().clear();
}
}
|