| 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.first = type; } |
| 54 | void setDeclaredReturnType(const QString &type) { m_returnType.second = type; } |
| 55 | void setVirtualness(const QString &value); |
| 56 | void setVirtualness(Virtualness virtualness) { m_virtualness = virtualness; } |
| 57 | void setConst(bool b) { m_const = b; } |
| 58 | void setDefault(bool b) { m_default = b; } |
| 59 | void setStatic(bool b) { m_static = b; } |
| 60 | void setReimpFlag() { m_reimpFlag = true; } |
| 61 | void setOverridesThis(const QString &path) { m_overridesThis = path; } |
| 62 | |
| 63 | [[nodiscard]] const QString &returnType() const { return m_returnType.first; } |
| 64 | [[nodiscard]] const std::optional<QString> &declaredReturnType() const { return m_returnType.second; } |
| 65 | [[nodiscard]] QString returnTypeString() const; |
| 66 | [[nodiscard]] QString virtualness() const; |
| 67 | [[nodiscard]] bool isConst() const { return m_const; } |
| 68 | [[nodiscard]] bool isDefault() const override { return m_default; } |
| 69 | [[nodiscard]] bool isStatic() const override { return m_static; } |
| 70 | [[nodiscard]] bool isOverload() const { return m_overloadFlag; } |
| 71 | [[nodiscard]] bool isMarkedReimp() const override { return m_reimpFlag; } |
| 72 | [[nodiscard]] bool isSomeCtor() const { return isCtor() || isCCtor() || isMCtor(); } |
| 73 | [[nodiscard]] bool isMacroWithParams() const { return (m_metaness == MacroWithParams); } |
| 74 | [[nodiscard]] bool isMacroWithoutParams() const { return (m_metaness == MacroWithoutParams); } |
| 75 | [[nodiscard]] bool isMacro() const override |
| 76 | { |
| 77 | return (isMacroWithParams() || isMacroWithoutParams()); |
| 78 | } |
| 79 | [[nodiscard]] bool isDeprecated() const override; |
| 80 | |
| 81 | void markExplicit() { m_explicit = true; } |
| 82 | bool isExplicit() const { return m_explicit; } |
| 83 | |
| 84 | void markConstexpr() { m_constexpr = true; } |
| 85 | bool isConstexpr() const { return m_constexpr; } |
| 86 | |
| 87 | void markNoexcept(QString expression = "" ) { m_noexcept = expression; } |
| 88 | const std::optional<QString>& getNoexcept() const { return m_noexcept; } |
| 89 | |
| 90 | [[nodiscard]] bool isCppFunction() const { return m_metaness == Plain; } // Is this correct? |
| 91 | [[nodiscard]] bool isSignal() const { return (m_metaness == Signal); } |
| 92 | [[nodiscard]] bool isSlot() const { return (m_metaness == Slot); } |
| 93 | [[nodiscard]] bool isCtor() const { return (m_metaness == Ctor); } |
| 94 | [[nodiscard]] bool isDtor() const { return (m_metaness == Dtor); } |
| 95 | [[nodiscard]] bool isCCtor() const { return (m_metaness == CCtor); } |
| 96 | [[nodiscard]] bool isMCtor() const { return (m_metaness == MCtor); } |
| 97 | [[nodiscard]] bool isCAssign() const { return (m_metaness == CAssign); } |
| 98 | [[nodiscard]] bool isMAssign() const { return (m_metaness == MAssign); } |
| 99 | |
| 100 | [[nodiscard]] bool isQmlMethod() const { return (m_metaness == QmlMethod); } |
| 101 | [[nodiscard]] bool isQmlSignal() const { return (m_metaness == QmlSignal); } |
| 102 | [[nodiscard]] bool isQmlSignalHandler() const { return (m_metaness == QmlSignalHandler); } |
| 103 | |
| 104 | [[nodiscard]] bool isSpecialMemberFunction() const |
| 105 | { |
| 106 | return (isCtor() || isDtor() || isCCtor() || isMCtor() || isCAssign() || isMAssign()); |
| 107 | } |
| 108 | [[nodiscard]] bool isNonvirtual() const { return (m_virtualness == NonVirtual); } |
| 109 | [[nodiscard]] bool isVirtual() const { return (m_virtualness == NormalVirtual); } |
| 110 | [[nodiscard]] bool isPureVirtual() const { return (m_virtualness == PureVirtual); } |
| 111 | [[nodiscard]] bool returnsBool() const { return (m_returnType.first == QLatin1String("bool" )); } |
| 112 | |
| 113 | Parameters ¶meters() { return m_parameters; } |
| 114 | [[nodiscard]] const Parameters ¶meters() const { return m_parameters; } |
| 115 | [[nodiscard]] bool isPrivateSignal() const { return m_parameters.isPrivateSignal(); } |
| 116 | void setParameters(const QString &signature) { m_parameters.set(signature); } |
| 117 | [[nodiscard]] QString signature(Node::SignatureOptions options) const override; |
| 118 | |
| 119 | [[nodiscard]] const QString &overridesThis() const { return m_overridesThis; } |
| 120 | [[nodiscard]] const QList<PropertyNode *> &associatedProperties() const { return m_associatedProperties; } |
| 121 | [[nodiscard]] bool hasAssociatedProperties() const { return !m_associatedProperties.isEmpty(); } |
| 122 | [[nodiscard]] const PropertyNode *primaryAssociatedProperty() const; |
| 123 | [[nodiscard]] QString element() const override { return parent()->name(); } |
| 124 | [[nodiscard]] bool isAttached() const override { return m_attached; } |
| 125 | [[nodiscard]] QString qmlTypeName() const override { return parent()->qmlTypeName(); } |
| 126 | [[nodiscard]] QString logicalModuleName() const override |
| 127 | { |
| 128 | return parent()->logicalModuleName(); |
| 129 | } |
| 130 | [[nodiscard]] QString logicalModuleVersion() const override |
| 131 | { |
| 132 | return parent()->logicalModuleVersion(); |
| 133 | } |
| 134 | [[nodiscard]] QString logicalModuleIdentifier() const override |
| 135 | { |
| 136 | return parent()->logicalModuleIdentifier(); |
| 137 | } |
| 138 | |
| 139 | void setFinal(bool b) { m_isFinal = b; } |
| 140 | [[nodiscard]] bool isFinal() const { return m_isFinal; } |
| 141 | |
| 142 | void setOverride(bool b) { m_isOverride = b; } |
| 143 | [[nodiscard]] bool isOverride() const { return m_isOverride; } |
| 144 | |
| 145 | void setRef(bool b) { m_isRef = b; } |
| 146 | [[nodiscard]] bool isRef() const { return m_isRef; } |
| 147 | |
| 148 | void setRefRef(bool b) { m_isRefRef = b; } |
| 149 | [[nodiscard]] bool isRefRef() const { return m_isRefRef; } |
| 150 | |
| 151 | void setInvokable(bool b) { m_isInvokable = b; } |
| 152 | [[nodiscard]] bool isInvokable() const { return m_isInvokable; } |
| 153 | |
| 154 | [[nodiscard]] bool hasTag(const QString &tag) const override { return (m_tag == tag); } |
| 155 | void setTag(const QString &tag) { m_tag = tag; } |
| 156 | [[nodiscard]] const QString &tag() const { return m_tag; } |
| 157 | [[nodiscard]] bool isIgnored() const; |
| 158 | [[nodiscard]] bool hasOverloads() const |
| 159 | { |
| 160 | return (m_overloadFlag || (parent() && parent()->hasOverloads(fn: this))); |
| 161 | } |
| 162 | void setOverloadFlag() { m_overloadFlag = true; } |
| 163 | void setOverloadNumber(signed short number); |
| 164 | [[nodiscard]] signed short overloadNumber() const { return m_overloadNumber; } |
| 165 | |
| 166 | friend int compare(const FunctionNode *f1, const FunctionNode *f2); |
| 167 | |
| 168 | private: |
| 169 | void addAssociatedProperty(PropertyNode *property); |
| 170 | |
| 171 | friend class Aggregate; |
| 172 | friend class PropertyNode; |
| 173 | |
| 174 | bool m_const : 1; |
| 175 | bool m_default : 1; |
| 176 | bool m_static : 1; |
| 177 | bool m_reimpFlag : 1; |
| 178 | bool m_attached : 1; |
| 179 | bool m_overloadFlag : 1; |
| 180 | bool m_isFinal : 1; |
| 181 | bool m_isOverride : 1; |
| 182 | bool m_isRef : 1; |
| 183 | bool m_isRefRef : 1; |
| 184 | bool m_isInvokable : 1; |
| 185 | bool m_explicit; |
| 186 | bool m_constexpr; |
| 187 | |
| 188 | std::optional<QString> m_noexcept; |
| 189 | |
| 190 | Metaness m_metaness {}; |
| 191 | Virtualness m_virtualness{ NonVirtual }; |
| 192 | signed short m_overloadNumber {}; |
| 193 | QPair<QString, std::optional<QString>> m_returnType {}; |
| 194 | QString m_overridesThis {}; |
| 195 | QString m_tag {}; |
| 196 | QList<PropertyNode *> m_associatedProperties {}; |
| 197 | Parameters m_parameters {}; |
| 198 | }; |
| 199 | |
| 200 | QT_END_NAMESPACE |
| 201 | |
| 202 | #endif // FUNCTIONNODE_H |
| 203 | |