1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef FUNCTIONNODE_H |
5 | #define FUNCTIONNODE_H |
6 | |
7 | #include "aggregate.h" |
8 | #include "node.h" |
9 | #include "parameters.h" |
10 | |
11 | #include <QtCore/qglobal.h> |
12 | #include <QtCore/qstring.h> |
13 | |
14 | #include <optional> |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | class FunctionNode : public Node |
19 | { |
20 | public: |
21 | enum Virtualness { NonVirtual, NormalVirtual, PureVirtual }; |
22 | |
23 | enum Metaness { |
24 | Plain, |
25 | Signal, |
26 | Slot, |
27 | Ctor, |
28 | Dtor, |
29 | CCtor, // copy constructor |
30 | MCtor, // move-copy constructor |
31 | MacroWithParams, |
32 | MacroWithoutParams, |
33 | Native, |
34 | CAssign, // copy-assignment operator |
35 | MAssign, // move-assignment operator |
36 | QmlSignal, |
37 | QmlSignalHandler, |
38 | QmlMethod, |
39 | }; |
40 | |
41 | FunctionNode(Aggregate *parent, const QString &name); // C++ function (Plain) |
42 | FunctionNode(Metaness type, Aggregate *parent, const QString &name, bool attached = false); |
43 | |
44 | Node *clone(Aggregate *parent) override; |
45 | [[nodiscard]] Metaness metaness() const { return m_metaness; } |
46 | [[nodiscard]] QString metanessString() const; |
47 | void setMetaness(Metaness metaness) { m_metaness = metaness; } |
48 | [[nodiscard]] QString kindString() const; |
49 | static Metaness getMetaness(const QString &value); |
50 | static Metaness getMetanessFromTopic(const QString &topic); |
51 | static Genus getGenus(Metaness metaness); |
52 | |
53 | void setReturnType(const QString &type) { m_returnType = type; } |
54 | void setVirtualness(const QString &value); |
55 | void setVirtualness(Virtualness virtualness) { m_virtualness = virtualness; } |
56 | void setConst(bool b) { m_const = b; } |
57 | void setDefault(bool b) { m_default = b; } |
58 | void setStatic(bool b) { m_static = b; } |
59 | void setReimpFlag() { m_reimpFlag = true; } |
60 | void setOverridesThis(const QString &path) { m_overridesThis = path; } |
61 | |
62 | [[nodiscard]] const QString &returnType() const { return m_returnType; } |
63 | [[nodiscard]] QString virtualness() const; |
64 | [[nodiscard]] bool isConst() const { return m_const; } |
65 | [[nodiscard]] bool isDefault() const override { return m_default; } |
66 | [[nodiscard]] bool isStatic() const override { return m_static; } |
67 | [[nodiscard]] bool isOverload() const { return m_overloadFlag; } |
68 | [[nodiscard]] bool isMarkedReimp() const override { return m_reimpFlag; } |
69 | [[nodiscard]] bool isSomeCtor() const { return isCtor() || isCCtor() || isMCtor(); } |
70 | [[nodiscard]] bool isMacroWithParams() const { return (m_metaness == MacroWithParams); } |
71 | [[nodiscard]] bool isMacroWithoutParams() const { return (m_metaness == MacroWithoutParams); } |
72 | [[nodiscard]] bool isMacro() const override |
73 | { |
74 | return (isMacroWithParams() || isMacroWithoutParams()); |
75 | } |
76 | [[nodiscard]] bool isDeprecated() const override; |
77 | |
78 | void markExplicit() { m_explicit = true; } |
79 | bool isExplicit() const { return m_explicit; } |
80 | |
81 | void markConstexpr() { m_constexpr = true; } |
82 | bool isConstexpr() const { return m_constexpr; } |
83 | |
84 | void markNoexcept(QString expression = "" ) { m_noexcept = expression; } |
85 | const std::optional<QString>& getNoexcept() const { return m_noexcept; } |
86 | |
87 | [[nodiscard]] bool isCppFunction() const { return m_metaness == Plain; } // Is this correct? |
88 | [[nodiscard]] bool isSignal() const { return (m_metaness == Signal); } |
89 | [[nodiscard]] bool isSlot() const { return (m_metaness == Slot); } |
90 | [[nodiscard]] bool isCtor() const { return (m_metaness == Ctor); } |
91 | [[nodiscard]] bool isDtor() const { return (m_metaness == Dtor); } |
92 | [[nodiscard]] bool isCCtor() const { return (m_metaness == CCtor); } |
93 | [[nodiscard]] bool isMCtor() const { return (m_metaness == MCtor); } |
94 | [[nodiscard]] bool isCAssign() const { return (m_metaness == CAssign); } |
95 | [[nodiscard]] bool isMAssign() const { return (m_metaness == MAssign); } |
96 | |
97 | [[nodiscard]] bool isQmlMethod() const { return (m_metaness == QmlMethod); } |
98 | [[nodiscard]] bool isQmlSignal() const { return (m_metaness == QmlSignal); } |
99 | [[nodiscard]] bool isQmlSignalHandler() const { return (m_metaness == QmlSignalHandler); } |
100 | |
101 | [[nodiscard]] bool isSpecialMemberFunction() const |
102 | { |
103 | return (isCtor() || isDtor() || isCCtor() || isMCtor() || isCAssign() || isMAssign()); |
104 | } |
105 | [[nodiscard]] bool isNonvirtual() const { return (m_virtualness == NonVirtual); } |
106 | [[nodiscard]] bool isVirtual() const { return (m_virtualness == NormalVirtual); } |
107 | [[nodiscard]] bool isPureVirtual() const { return (m_virtualness == PureVirtual); } |
108 | [[nodiscard]] bool returnsBool() const { return (m_returnType == QLatin1String("bool" )); } |
109 | |
110 | Parameters ¶meters() { return m_parameters; } |
111 | [[nodiscard]] const Parameters ¶meters() const { return m_parameters; } |
112 | [[nodiscard]] bool isPrivateSignal() const { return m_parameters.isPrivateSignal(); } |
113 | void setParameters(const QString &signature) { m_parameters.set(signature); } |
114 | [[nodiscard]] QString signature(Node::SignatureOptions options) const override; |
115 | |
116 | [[nodiscard]] const QString &overridesThis() const { return m_overridesThis; } |
117 | [[nodiscard]] const QList<PropertyNode *> &associatedProperties() const { return m_associatedProperties; } |
118 | [[nodiscard]] bool hasAssociatedProperties() const { return !m_associatedProperties.isEmpty(); } |
119 | [[nodiscard]] bool hasOneAssociatedProperty() const |
120 | { |
121 | return (m_associatedProperties.size() == 1); |
122 | } |
123 | [[nodiscard]] QString element() const override { return parent()->name(); } |
124 | [[nodiscard]] bool isAttached() const override { return m_attached; } |
125 | [[nodiscard]] bool isQtQuickNode() const override { return parent()->isQtQuickNode(); } |
126 | [[nodiscard]] QString qmlTypeName() const override { return parent()->qmlTypeName(); } |
127 | [[nodiscard]] QString logicalModuleName() const override |
128 | { |
129 | return parent()->logicalModuleName(); |
130 | } |
131 | [[nodiscard]] QString logicalModuleVersion() const override |
132 | { |
133 | return parent()->logicalModuleVersion(); |
134 | } |
135 | [[nodiscard]] QString logicalModuleIdentifier() const override |
136 | { |
137 | return parent()->logicalModuleIdentifier(); |
138 | } |
139 | |
140 | void setFinal(bool b) { m_isFinal = b; } |
141 | [[nodiscard]] bool isFinal() const { return m_isFinal; } |
142 | |
143 | void setOverride(bool b) { m_isOverride = b; } |
144 | [[nodiscard]] bool isOverride() const { return m_isOverride; } |
145 | |
146 | void setRef(bool b) { m_isRef = b; } |
147 | [[nodiscard]] bool isRef() const { return m_isRef; } |
148 | |
149 | void setRefRef(bool b) { m_isRefRef = b; } |
150 | [[nodiscard]] bool isRefRef() const { return m_isRefRef; } |
151 | |
152 | void setInvokable(bool b) { m_isInvokable = b; } |
153 | [[nodiscard]] bool isInvokable() const { return m_isInvokable; } |
154 | |
155 | [[nodiscard]] bool hasTag(const QString &tag) const override { return (m_tag == tag); } |
156 | void setTag(const QString &tag) { m_tag = tag; } |
157 | [[nodiscard]] const QString &tag() const { return m_tag; } |
158 | bool compare(const Node *node, bool sameParent = true) const; |
159 | [[nodiscard]] bool isIgnored() const; |
160 | [[nodiscard]] bool hasOverloads() const; |
161 | void setOverloadFlag() { m_overloadFlag = true; } |
162 | void setOverloadNumber(signed short number); |
163 | void appendOverload(FunctionNode *functionNode); |
164 | void removeOverload(FunctionNode *functionNode); |
165 | [[nodiscard]] signed short overloadNumber() const { return m_overloadNumber; } |
166 | FunctionNode *nextOverload() { return m_nextOverload; } |
167 | void setNextOverload(FunctionNode *functionNode) { m_nextOverload = functionNode; } |
168 | FunctionNode *findPrimaryFunction(); |
169 | |
170 | private: |
171 | void addAssociatedProperty(PropertyNode *property); |
172 | |
173 | friend class Aggregate; |
174 | friend class PropertyNode; |
175 | |
176 | bool m_const : 1; |
177 | bool m_default : 1; |
178 | bool m_static : 1; |
179 | bool m_reimpFlag : 1; |
180 | bool m_attached : 1; |
181 | bool m_overloadFlag : 1; |
182 | bool m_isFinal : 1; |
183 | bool m_isOverride : 1; |
184 | bool m_isRef : 1; |
185 | bool m_isRefRef : 1; |
186 | bool m_isInvokable : 1; |
187 | bool m_explicit; |
188 | bool m_constexpr; |
189 | |
190 | std::optional<QString> m_noexcept; |
191 | |
192 | Metaness m_metaness {}; |
193 | Virtualness m_virtualness{ NonVirtual }; |
194 | signed short m_overloadNumber {}; |
195 | FunctionNode *m_nextOverload { nullptr }; |
196 | QString m_returnType {}; |
197 | QString m_overridesThis {}; |
198 | QString m_tag {}; |
199 | QList<PropertyNode *> m_associatedProperties {}; |
200 | Parameters m_parameters {}; |
201 | }; |
202 | |
203 | QT_END_NAMESPACE |
204 | |
205 | #endif // FUNCTIONNODE_H |
206 | |