• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

classfunctiondeclaration.cpp

00001 /* This  is part of KDevelop
00002     Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
00003     Copyright 2006 Adam Treat <treat@kde.org>
00004     Copyright 2006 Hamish Rodda <rodda@kde.org>
00005     Copyright 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License version 2 as published by the Free Software Foundation.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "classfunctiondeclaration.h"
00023 
00024 #include "ducontext.h"
00025 #include "types/functiontype.h"
00026 #include "duchainregister.h"
00027 
00028 namespace KDevelop
00029 {
00030 Identifier conversionIdentifier("operator{...cast...}");
00031 
00032 REGISTER_DUCHAIN_ITEM(ClassFunctionDeclaration);
00033 
00034 ClassFunctionDeclaration::ClassFunctionDeclaration(const ClassFunctionDeclaration& rhs)
00035     : ClassFunctionDeclarationBase(*new ClassFunctionDeclarationData( *rhs.d_func() )) {
00036   setSmartRange(rhs.smartRange(), DocumentRangeObject::DontOwn);
00037 }
00038 
00039 void ClassFunctionDeclaration::setAbstractType(AbstractType::Ptr type) {
00040   if(!( !type || dynamic_cast<FunctionType*>(type.unsafeData()) )) {
00041     kWarning(9505) << "WARNING: Non-function type assigned to function declaration";
00042   }
00043   ClassMemberDeclaration::setAbstractType(type);
00044 }
00045 
00046 DEFINE_LIST_MEMBER_HASH(ClassFunctionDeclarationData, m_defaultParameters, IndexedString)
00047 
00048 ClassFunctionDeclaration::ClassFunctionDeclaration(ClassFunctionDeclarationData& data) : ClassFunctionDeclarationBase(data)
00049 {
00050 }
00051 
00052 ClassFunctionDeclaration::ClassFunctionDeclaration(const SimpleRange& range, DUContext* context)
00053   : ClassFunctionDeclarationBase(*new ClassFunctionDeclarationData, range)
00054 {
00055   d_func_dynamic()->setClassId(this);
00056   if( context )
00057     setContext( context );
00058 }
00059 
00060 ClassFunctionDeclaration::ClassFunctionDeclaration(ClassFunctionDeclarationData& data, const SimpleRange& range, DUContext* context)
00061   : ClassFunctionDeclarationBase(data, range)
00062 {
00063   if( context )
00064     setContext( context );
00065 }
00066 
00067 Declaration* ClassFunctionDeclaration::clonePrivate() const {
00068   return new ClassFunctionDeclaration(*this);
00069 }
00070 
00071 ClassFunctionDeclaration::~ClassFunctionDeclaration()
00072 {
00073 }
00074 
00075 bool ClassFunctionDeclaration::isFunctionDeclaration() const
00076 {
00077   return true;
00078 }
00079 
00080 QString ClassFunctionDeclaration::toString() const {
00081   if( !abstractType() )
00082     return ClassMemberDeclaration::toString();
00083 
00084   TypePtr<FunctionType> function = type<FunctionType>();
00085   if(function) {
00086     return QString("%1 %2 %3").arg(function->partToString( FunctionType::SignatureReturn )).arg(identifier().toString()).arg(function->partToString( FunctionType::SignatureArguments ));
00087   } else {
00088     QString type = abstractType() ? abstractType()->toString() : QString("<notype>");
00089     kDebug(9505) << "A function has a bad type attached:" << type;
00090     return QString("invalid member-function %1 type %2").arg(identifier().toString()).arg(type);
00091   }
00092 }
00093 
00094 
00095 /*bool ClassFunctionDeclaration::isSimilar(KDevelop::CodeItem *other, bool strict ) const
00096 {
00097   if (!CppClassMemberType::isSimilar(other,strict))
00098     return false;
00099 
00100   FunctionModelItem func = dynamic_cast<ClassFunctionDeclaration*>(other);
00101 
00102   if (isConstant() != func->isConstant())
00103     return false;
00104 
00105   if (arguments().count() != func->arguments().count())
00106     return false;
00107 
00108   for (int i=0; i<arguments().count(); ++i)
00109     {
00110       ArgumentModelItem arg1 = arguments().at(i);
00111       ArgumentModelItem arg2 = arguments().at(i);
00112 
00113       if (arg1->type() != arg2->type())
00114         return false;
00115     }
00116 
00117   return true;
00118 }*/
00119 
00120 uint setFlag(bool enable, uint flag, uint flags) {
00121   if(enable)
00122     return flags | flag;
00123   else
00124     return flags & (~flag);
00125 }
00126 
00127 bool ClassFunctionDeclaration::isAbstract() const
00128 {
00129   return d_func()->m_functionFlags & AbstractFunctionFlag;
00130 }
00131 
00132 void ClassFunctionDeclaration::setIsAbstract(bool abstract)
00133 {
00134   d_func_dynamic()->m_functionFlags = (ClassFunctionFlags)setFlag(abstract, AbstractFunctionFlag, d_func()->m_functionFlags);
00135 }
00136 
00137 bool ClassFunctionDeclaration::isFinal() const
00138 {
00139   return d_func()->m_functionFlags & FinalFunctionFlag;
00140 }
00141 
00142 void ClassFunctionDeclaration::setIsFinal(bool final)
00143 {
00144   d_func_dynamic()->m_functionFlags = (ClassFunctionFlags)setFlag(final, FinalFunctionFlag, d_func()->m_functionFlags);
00145 }
00146 
00147 bool ClassFunctionDeclaration::isSignal() const
00148 {
00149   return d_func()->m_functionFlags & FunctionSignalFlag;
00150 }
00151 
00152 void ClassFunctionDeclaration::setIsSignal(bool isSignal) {
00153   d_func_dynamic()->m_functionFlags = (ClassFunctionFlags)setFlag(isSignal, FunctionSignalFlag, d_func()->m_functionFlags);
00154 }
00155 
00156 bool ClassFunctionDeclaration::isSlot() const
00157 {
00158   return d_func()->m_functionFlags & FunctionSlotFlag;
00159 }
00160 
00161 void ClassFunctionDeclaration::setIsSlot(bool isSlot) {
00162   d_func_dynamic()->m_functionFlags = (ClassFunctionFlags)setFlag(isSlot, FunctionSlotFlag, d_func()->m_functionFlags);
00163 }
00164 
00165 bool ClassFunctionDeclaration::isConversionFunction() const {
00166   return identifier() == conversionIdentifier;
00167 }
00168 
00169 bool ClassFunctionDeclaration::isConstructor() const
00170 {
00171   DUContext* ctx = context();
00172   if (ctx && ctx->type() == DUContext::Class && ctx->localScopeIdentifier().top().nameEquals(identifier()))
00173     return true;
00174   return false;
00175 }
00176 
00177 bool ClassFunctionDeclaration::isDestructor() const
00178 {
00179   DUContext* ctx = context();
00180   QString id = identifier().toString();
00181   return ctx && ctx->type() == DUContext::Class && id.startsWith('~') && id.mid(1) == ctx->localScopeIdentifier().top().toString();
00182 }
00183 
00184 uint ClassFunctionDeclaration::additionalIdentity() const
00185 {
00186   if(abstractType())
00187     return abstractType()->hash();
00188   else
00189     return 0;
00190 }
00191 
00192 const IndexedString* ClassFunctionDeclaration::defaultParameters() const
00193 {
00194   return d_func()->m_defaultParameters();
00195 }
00196 
00197 unsigned int ClassFunctionDeclaration::defaultParametersSize() const
00198 {
00199   return d_func()->m_defaultParametersSize();
00200 }
00201 
00202 void ClassFunctionDeclaration::addDefaultParameter(const IndexedString& str)
00203 {
00204   d_func_dynamic()->m_defaultParametersList().append(str);
00205 }
00206 
00207 void ClassFunctionDeclaration::clearDefaultParameters()
00208 {
00209   d_func_dynamic()->m_defaultParametersList().clear();
00210 }
00211 
00212 }
00213 // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on

language/duchain

Skip menu "language/duchain"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal