summaryrefslogtreecommitdiffstats
path: root/src/qdoc/parameters.h
blob: f2f4d93a171fb620c78ee5cb8b7531e3a3c0634b (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
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
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef PARAMETERS_H
#define PARAMETERS_H

#include <QtCore/qlist.h>
#include <QtCore/qregularexpression.h>
#include <QtCore/qset.h>

#include <utility>

QT_BEGIN_NAMESPACE

class Location;
class Tokenizer;
class CodeChunk;

class Parameter
{
public:
    Parameter() = default;
    explicit Parameter(QString type, QString name = QString(), QString defaultValue = QString())
        : m_type(std::move(type)), m_name(std::move(name)), m_defaultValue(std::move(defaultValue))
    {
    }

    void setName(const QString &name) { m_name = name; }
    [[nodiscard]] bool hasType() const { return !m_type.isEmpty(); }
    [[nodiscard]] const QString &type() const { return m_type; }
    [[nodiscard]] const QString &name() const { return m_name; }
    [[nodiscard]] const QString &defaultValue() const { return m_defaultValue; }
    void setDefaultValue(const QString &t) { m_defaultValue = t; }

    void set(const QString &type, const QString &name, const QString &defaultValue = QString())
    {
        m_type = type;
        m_name = name;
        m_defaultValue = defaultValue;
    }

    [[nodiscard]] QString signature(bool includeValue = false) const;

    [[nodiscard]] const QString &canonicalType() const { return m_canonicalType; }
    void setCanonicalType(const QString &t) { m_canonicalType = t; }

public:
    QString m_canonicalType {};
    QString m_type {};
    QString m_name {};
    QString m_defaultValue {};
};

typedef QList<Parameter> ParameterVector;

class Parameters
{
public:
    Parameters();
    Parameters(const QString &signature); // TODO: Making this explicit breaks QDoc

    void clear()
    {
        m_parameters.clear();
        m_privateSignal = false;
        m_valid = true;
    }
    [[nodiscard]] const ParameterVector &parameters() const { return m_parameters; }
    [[nodiscard]] bool isPrivateSignal() const { return m_privateSignal; }
    [[nodiscard]] bool isEmpty() const { return m_parameters.isEmpty(); }
    [[nodiscard]] bool isValid() const { return m_valid; }
    [[nodiscard]] int count() const { return m_parameters.size(); }
    void reserve(int count) { m_parameters.reserve(count); }
    [[nodiscard]] const Parameter &at(int i) const { return m_parameters.at(i); }
    Parameter &last() { return m_parameters.last(); }
    [[nodiscard]] const Parameter &last() const { return m_parameters.last(); }
    inline Parameter &operator[](int index) { return m_parameters[index]; }
    void append(const QString &type, const QString &name, const QString &value);
    void append(const QString &type, const QString &name) { append(type, name, QString()); }
    void append(const QString &type) { append(type, QString(), QString()); }
    void pop_back() { m_parameters.pop_back(); }
    void setPrivateSignal() { m_privateSignal = true; }
    [[nodiscard]] QString signature(bool includeValues = false) const;
    [[nodiscard]] QString rawSignature(bool names = false, bool values = false) const;
    void set(const QString &signature);
    [[nodiscard]] QSet<QString> getNames() const;
    [[nodiscard]] QString generateTypeList() const;
    [[nodiscard]] QString generateTypeAndNameList() const;
    [[nodiscard]] bool match(const Parameters &parameters) const;

private:
    void readToken();
    QString lexeme();
    QString previousLexeme();
    bool match(int target);
    void matchTemplateAngles(CodeChunk &type);
    bool matchTypeAndName(CodeChunk &type, QString &name);
    bool matchParameter();
    bool parse(const QString &signature);

private:
    static QRegularExpression s_varComment;

    bool m_valid {};
    bool m_privateSignal {};
    int m_tok {};
    Tokenizer *m_tokenizer { nullptr };
    ParameterVector m_parameters;
};

QT_END_NAMESPACE

#endif