File: abstractfunctiondeclaration.h

package info (click to toggle)
kdevelop 4%3A5.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 57,892 kB
  • sloc: cpp: 278,773; javascript: 3,558; python: 3,385; sh: 1,317; ansic: 689; xml: 273; php: 95; makefile: 40; lisp: 13; sed: 12
file content (142 lines) | stat: -rw-r--r-- 5,313 bytes parent folder | download
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* This file is part of KDevelop
    Copyright 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.
 */

#ifndef KDEVPLATFORM_ABSTRACTFUNCTIONDECLARATION_H
#define KDEVPLATFORM_ABSTRACTFUNCTIONDECLARATION_H

#include <language/languageexport.h>
#include "indexedducontext.h"

namespace KDevelop {
class DUContext;
class IndexedString;

class AbstractFunctionDeclarationData
{
public:
    AbstractFunctionDeclarationData() : m_isVirtual(false)
        , m_isInline(false)
        , m_isExplicit(false)
    {
    }
    IndexedDUContext m_functionContext;
    bool m_isVirtual : 1; ///@todo move into ClassFunctionDeclaration(Only valid for class-functions)
    bool m_isInline : 1;
    bool m_isExplicit : 1; ///@todo move into ClassFunctionDeclaration(Only valid for class-functions)
};

/**
 * Provides an interface to declarations which represent functions in a definition-use chain.
 * Don't inherit from this directly, use MergeAbstractFunctionDeclaration instead.
 */
class KDEVPLATFORMLANGUAGE_EXPORT AbstractFunctionDeclaration
{
public:
    virtual ~AbstractFunctionDeclaration();

    enum FunctionSpecifier {
        VirtualSpecifier  = 0x1 /**< indicates a virtual function */,
        InlineSpecifier   = 0x2 /**< indicates a inline function */,
        ExplicitSpecifier = 0x4 /**< indicates a explicit function */
    };
    Q_DECLARE_FLAGS(FunctionSpecifiers, FunctionSpecifier)

    void setFunctionSpecifiers(FunctionSpecifiers specifiers);

    bool isInline() const;
    void setInline(bool isInline);

    ///Only used for class-member function declarations(see ClassFunctionDeclaration)
    bool isVirtual() const;
    void setVirtual(bool isVirtual);

    ///Only used for class-member function declarations(see ClassFunctionDeclaration)
    bool isExplicit() const;
    void setExplicit(bool isExplicit);

    ///Return the DUContext::Function type ducontext (the function parameter context) of this function
    ///Same as internalContext if the function has no definition
    DUContext* internalFunctionContext() const;
    void setInternalFunctionContext(DUContext* context);

    /**
     * Returns the default-parameters that are set. The last default-parameter matches the last
     * argument of the function, but the returned vector will only contain default-values for those
     * arguments that have one, for performance-reasons.
     *
     * So the vector may be empty or smaller than the count of function-arguments.
     * */
    virtual const IndexedString* defaultParameters() const = 0;
    virtual unsigned int defaultParametersSize() const = 0;
    virtual void addDefaultParameter(const IndexedString& str) = 0;
    virtual void clearDefaultParameters()  = 0;
    ///Returns the default parameter assigned to the given argument number.
    ///This is a convenience-function.
    IndexedString defaultParameterForArgument(int index) const;

private:
    //Must be implemented by sub-classes to provide a pointer to the data
    virtual const AbstractFunctionDeclarationData* data() const = 0;
    virtual AbstractFunctionDeclarationData* dynamicData() = 0;
};

#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractFunctionDeclaration::FunctionSpecifiers)
#endif

///Use this to merge AbstractFunctionDeclaration into the class hierarchy. Base must be the base-class
///in the hierarchy, and Data must be the Data class of the following Declaration, and must be based on AbstractFunctionDeclarationData
///and BaseData.
template <class Base, class _Data>
class MergeAbstractFunctionDeclaration
    : public Base
    , public AbstractFunctionDeclaration
{
public:
    template <class BaseData>
    explicit MergeAbstractFunctionDeclaration(BaseData& data) : Base(data)
    {
    }
    template <class BaseData, class Arg2>
    MergeAbstractFunctionDeclaration(BaseData& data, const Arg2& arg2) : Base(data, arg2)
    {
    }
    template <class BaseData, class Arg2, class Arg3>
    MergeAbstractFunctionDeclaration(BaseData& data, const Arg2& arg2, const Arg3& arg3) : Base(data, arg2, arg3)
    {
    }

private:
    const AbstractFunctionDeclarationData* data() const override
    {
        return static_cast<const _Data*>(Base::d_func());
    }
    AbstractFunctionDeclarationData* dynamicData() override
    {
        return static_cast<_Data*>(Base::d_func_dynamic());
    }
};

}

#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
Q_DECLARE_OPERATORS_FOR_FLAGS(KDevelop::AbstractFunctionDeclaration::FunctionSpecifiers)
#endif

#endif // KDEVPLATFORM_ABSTRACTFUNCTIONDECLARATION_H