1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the tools applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #ifndef PARAMETERS_H
30 #define PARAMETERS_H
31 
32 #include <QtCore/qregexp.h>
33 #include <QtCore/qset.h>
34 #include <QtCore/qvector.h>
35 
36 QT_BEGIN_NAMESPACE
37 
38 class Location;
39 class Tokenizer;
40 class CodeChunk;
41 
42 class Parameter
43 {
44 public:
Parameter()45     Parameter() {}
46     Parameter(const QString &type, const QString &name = QString(),
47               const QString &defaultValue = QString())
type_(type)48         : type_(type), name_(name), defaultValue_(defaultValue)
49     {
50     }
51 
setName(const QString & name)52     void setName(const QString &name) { name_ = name; }
hasType()53     bool hasType() const { return !type_.isEmpty(); }
type()54     const QString &type() const { return type_; }
name()55     const QString &name() const { return name_; }
defaultValue()56     const QString &defaultValue() const { return defaultValue_; }
setDefaultValue(const QString & t)57     void setDefaultValue(const QString &t) { defaultValue_ = t; }
58 
59     void set(const QString &type, const QString &name, const QString &defaultValue = QString())
60     {
61         type_ = type;
62         name_ = name;
63         defaultValue_ = defaultValue;
64     }
65 
66     QString signature(bool includeValue = false) const;
67 
68 public:
69     QString type_;
70     QString name_;
71     QString defaultValue_;
72 };
73 
74 typedef QVector<Parameter> ParameterVector;
75 
76 class Parameters
77 {
78 public:
79     Parameters();
80     Parameters(const QString &signature);
81 
clear()82     void clear()
83     {
84         parameters_.clear();
85         privateSignal_ = false;
86         valid_ = true;
87     }
parameters()88     const ParameterVector &parameters() const { return parameters_; }
isPrivateSignal()89     bool isPrivateSignal() const { return privateSignal_; }
isEmpty()90     bool isEmpty() const { return parameters_.isEmpty(); }
isValid()91     bool isValid() const { return valid_; }
count()92     int count() const { return parameters_.size(); }
reserve(int count)93     void reserve(int count) { parameters_.reserve(count); }
at(int i)94     const Parameter &at(int i) const { return parameters_.at(i); }
last()95     const Parameter &last() const { return parameters_.last(); }
96     inline Parameter &operator[](int index) { return parameters_[index]; }
97     void append(const QString &type, const QString &name, const QString &value);
append(const QString & type,const QString & name)98     void append(const QString &type, const QString &name) { append(type, name, QString()); }
append(const QString & type)99     void append(const QString &type) { append(type, QString(), QString()); }
pop_back()100     void pop_back() { parameters_.pop_back(); }
setPrivateSignal()101     void setPrivateSignal() { privateSignal_ = true; }
102     QString signature(bool includeValues = false) const;
103     QString rawSignature(bool names = false, bool values = false) const;
104     void set(const QString &signature);
105     QSet<QString> getNames() const;
106     QString generateTypeList() const;
107     QString generateTypeAndNameList() const;
108     bool match(const Parameters &parameters) const;
109 
110 private:
111     void readToken();
112     QString lexeme();
113     QString previousLexeme();
114     bool match(int target);
115     void matchTemplateAngles(CodeChunk &type);
116     bool matchTypeAndName(CodeChunk &type, QString &name, bool qProp = false);
117     bool matchParameter();
118     bool parse(const QString &signature);
119 
120 private:
121     static QRegExp varComment_;
122 
123     bool valid_;
124     bool privateSignal_;
125     int tok_;
126     Tokenizer *tokenizer_;
127     ParameterVector parameters_;
128 };
129 
130 QT_END_NAMESPACE
131 
132 #endif
133