1 /* This file is part of KDevelop
2 Copyright 2007 Hamish Rodda <rodda@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #ifndef ABSTRACTFUNCTIONDECLARATION_H
20 #define ABSTRACTFUNCTIONDECLARATION_H
22 #include <QtCore/QString>
23 #include "../languageexport.h"
24 #include "indexedstring.h"
29 class AbstractFunctionDeclarationData
32 AbstractFunctionDeclarationData() : m_isVirtual(false), m_isInline(false), m_isExplicit(false) {
40 * Provides an interface to declarations which represent functions in a definition-use chain.
41 * Don't inherit from this directly, use MergeAbstractFunctionDeclaration instead.
43 class KDEVPLATFORMLANGUAGE_EXPORT AbstractFunctionDeclaration
46 virtual ~AbstractFunctionDeclaration();
48 enum FunctionSpecifier
{
49 VirtualSpecifier
= 0x1 /**< indicates a virtual function */,
50 InlineSpecifier
= 0x2 /**< indicates a inline function */,
51 ExplicitSpecifier
= 0x4 /**< indicates a explicit function */
53 Q_DECLARE_FLAGS(FunctionSpecifiers
, FunctionSpecifier
)
55 void setFunctionSpecifiers(FunctionSpecifiers specifiers
);
57 bool isInline() const;
58 void setInline(bool isInline
);
60 ///Only used for class-member function declarations(see ClassFunctionDeclaration)
61 bool isVirtual() const;
62 void setVirtual(bool isVirtual
);
64 ///Only used for class-member function declarations(see ClassFunctionDeclaration)
65 bool isExplicit() const;
66 void setExplicit(bool isExplicit
);
69 * Returns the default-parameters that are set. The last default-parameter matches the last
70 * argument of the function, but the returned vector will only contain default-values for those
71 * arguments that have one, for performance-reasons.
73 * So the vector may be empty or smaller than the count of function-arguments.
75 virtual const IndexedString
* defaultParameters() const = 0;
76 virtual int defaultParametersSize() const = 0;
77 virtual void addDefaultParameter(const IndexedString
& str
) = 0;
78 virtual void clearDefaultParameters() = 0;
80 //Must be implemented by sub-classes to provide a pointer to the data
81 virtual const AbstractFunctionDeclarationData
* data() const = 0;
82 virtual AbstractFunctionDeclarationData
* dynamicData() = 0;
85 Q_DECLARE_OPERATORS_FOR_FLAGS(KDevelop::AbstractFunctionDeclaration::FunctionSpecifiers
)
87 ///Use this to merge AbstractFunctionDeclaration into the class hierarchy. Base must be the base-class
88 ///in the hierarchy, and Data must be the Data class of the following Declaration, and must be based on AbstractFunctionDeclarationData
90 template<class Base
, class Data
>
91 class MergeAbstractFunctionDeclaration
: public Base
, public AbstractFunctionDeclaration
{
93 template<class BaseData
>
94 MergeAbstractFunctionDeclaration(BaseData
& data
) : Base(data
) {
96 template<class BaseData
, class Arg2
>
97 MergeAbstractFunctionDeclaration(BaseData
& data
, const Arg2
& arg2
) : Base(data
, arg2
) {
99 template<class BaseData
, class Arg2
, class Arg3
>
100 MergeAbstractFunctionDeclaration(BaseData
& data
, const Arg2
& arg2
, const Arg3
& arg3
) : Base(data
, arg2
, arg3
) {
104 virtual const AbstractFunctionDeclarationData
* data() const {
105 return static_cast<const Data
*>(Base::d_func());
107 virtual AbstractFunctionDeclarationData
* dynamicData() {
108 return static_cast<Data
*>(Base::d_func_dynamic());
114 #endif // ABSTRACTFUNCTIONDECLARATION_H
116 // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on