aboutsummaryrefslogtreecommitdiffstats
path: root/polymorphicdata.h
blob: 1e47419020c20ad653f7246c30d3c7758a5c4ab6 (plain)
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
/*
 * This file is part of the Shiboken Python Binding Generator project.
 *
 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 *
 * Contact: PySide team <contact@pyside.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#ifndef POLYMORPHICDATA_H
#define POLYMORPHICDATA_H

#include <apiextractor/abstractmetalang.h>
#include <QtCore/QList>
#include <QtCore/QBitArray>

class PolymorphicData;
typedef QList<PolymorphicData*> PolymorphicDataList;

class PolymorphicData
{
public:
    PolymorphicData(const AbstractMetaFunctionList overloads);

    int minArgs() const { return m_headPolymorphicData->m_minArgs; }
    int maxArgs() const { return m_headPolymorphicData->m_maxArgs; }
    int argPos() const { return m_argPos; }

    const AbstractMetaType* argType() const { return m_argType; }
    const AbstractMetaFunction* referenceFunction() const;
    const AbstractMetaArgument* argument(const AbstractMetaFunction* func) const;
    PolymorphicDataList polymorphicDataOnPosition(int argPos) const;

    bool isHeadPolymorphicData() const { return this == m_headPolymorphicData; }
    bool hasDefaultValue() const;
    bool nextArgumentHasDefaultValue() const;
    bool isFinalOccurrence(const AbstractMetaFunction* func) const;

    QList<const AbstractMetaFunction*> overloads() const { return m_overloads; }
    PolymorphicDataList nextPolymorphicData() const { return m_nextPolymorphicData; }

    QList<int> invalidArgumentLengths() const;

    static int numberOfRemovedArguments(const AbstractMetaFunction* func, int finalArgPos = -1);
    static QPair<int, int> getMinMaxArguments(const AbstractMetaFunctionList overloads);

    void dumpGraph(QString filename) const;

    ~PolymorphicData();

private:
    PolymorphicData(PolymorphicData* headPolymorphicData, const AbstractMetaFunction* func,
                    const AbstractMetaType* argType, int argPos);

    void addPolymorphic(const AbstractMetaFunction* func);
    PolymorphicData* addPolymorphicData(const AbstractMetaFunction* func, const AbstractMetaType* argType);

    QString dumpGraph(const PolymorphicData* polyData) const;
    int functionNumber(const AbstractMetaFunction* func) const;
    PolymorphicDataList polymorphicDataOnPosition(PolymorphicData* polyData, int argPos) const;

    int m_minArgs;
    int m_maxArgs;
    int m_argPos;
    const AbstractMetaType* m_argType;
    QList<const AbstractMetaFunction*> m_overloads;

    PolymorphicData* m_headPolymorphicData;
    PolymorphicDataList m_nextPolymorphicData;
};


#endif // POLYMORPHICDATA_H