File indexing completed on 2024-05-12 04:37:46
0001 /* 0002 SPDX-FileCopyrightText: 2012 Miha Čančula <miha@noughmad.eu> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVPLATFORM_CODEDESCRIPTION_H 0008 #define KDEVPLATFORM_CODEDESCRIPTION_H 0009 0010 #include <language/languageexport.h> 0011 #include <language/duchain/duchainpointer.h> 0012 0013 #include <QString> 0014 #include <QVariant> 0015 #include <QVector> 0016 0017 /** 0018 * NOTE: changes in this file will quite probably also require changes 0019 * in codedescriptionmetatype.h! 0020 */ 0021 0022 namespace KDevelop { 0023 /** 0024 * @brief Represents a variable 0025 * 0026 * A variable has two main properties: its type and name. 0027 **/ 0028 struct KDEVPLATFORMLANGUAGE_EXPORT VariableDescription 0029 { 0030 /** 0031 * Creates a variable with no type and no name 0032 * 0033 **/ 0034 VariableDescription(); 0035 /** 0036 * Creates a variable with type @p type and name @p name 0037 * 0038 * @param type the type of this variable 0039 * @param name the name of this variable 0040 **/ 0041 VariableDescription(const QString& type, const QString& name); 0042 /** 0043 * Creates a variable and determines it type and name from the @p declaration 0044 * 0045 **/ 0046 explicit VariableDescription(const DeclarationPointer& declaration); 0047 0048 /** 0049 * The name of this variable 0050 **/ 0051 QString name; 0052 /** 0053 * The type of this variable. 0054 * 0055 * In weakly typed languages, this field can be empty. 0056 **/ 0057 QString type; 0058 /** 0059 * Access specifier, only relevant for class members. 0060 * 0061 * Not all languages use these, so it can be left empty. 0062 **/ 0063 QString access; 0064 /** 0065 * The default value of this variable. 0066 */ 0067 QString value; 0068 }; 0069 0070 /** 0071 * List of variable descriptions 0072 **/ 0073 using VariableDescriptionList = QVector<VariableDescription>; 0074 0075 /** 0076 * @brief Represents a function 0077 * 0078 * A function has a name and any number of arguments and return values 0079 **/ 0080 struct KDEVPLATFORMLANGUAGE_EXPORT FunctionDescription 0081 { 0082 /** 0083 * Creates a function with no name and no arguments 0084 * 0085 **/ 0086 FunctionDescription(); 0087 /** 0088 * Creates a function with name @p and specified @p arguments and @p returnArguments 0089 * 0090 * @param name the name of the new function 0091 * @param arguments a list of variables that are passed to this function as arguments 0092 * @param returnArguments a list of variables that this function returns 0093 **/ 0094 FunctionDescription(const QString& name, 0095 const VariableDescriptionList& arguments, 0096 const VariableDescriptionList& returnArguments); 0097 /** 0098 * Creates a function and determines its properties from the @p declaration 0099 * 0100 * @param declaration a function declaration 0101 **/ 0102 explicit FunctionDescription(const DeclarationPointer& declaration); 0103 0104 /** 0105 * Convenience method, returns the type of the first variable in returnArguments 0106 * or an empty string if this function has no return arguments 0107 */ 0108 QString returnType() const; 0109 0110 /** 0111 * The name of this function 0112 **/ 0113 QString name; 0114 /** 0115 * This function's input arguments 0116 **/ 0117 QVector<VariableDescription> arguments; 0118 /** 0119 * This function's return values 0120 **/ 0121 QVector<VariableDescription> returnArguments; 0122 /** 0123 * Access specifier, only relevant for class members. 0124 * 0125 * Not all languages use these, so it can be left empty. 0126 **/ 0127 QString access; 0128 0129 /** 0130 * Specifies whether this function is a class constructor 0131 **/ 0132 bool isConstructor : 1; 0133 /** 0134 * Specifies whether this function is a class destructor 0135 */ 0136 bool isDestructor : 1; 0137 /** 0138 * Specifies whether this function is virtual and can be overridden by subclasses 0139 **/ 0140 bool isVirtual : 1; 0141 /** 0142 * Specifies whether this function is abstract and needs to be overridden by subclasses 0143 **/ 0144 bool isAbstract : 1; 0145 /** 0146 * Specifies whether this function overrides a virtual method of a base class 0147 **/ 0148 bool isOverriding : 1; 0149 /** 0150 * Specifies whether this function is final and cannot be overridden by subclasses 0151 **/ 0152 bool isFinal : 1; 0153 /** 0154 * Specifies whether this function is static and can be called without a class instance 0155 **/ 0156 bool isStatic : 1; 0157 /** 0158 * Specifies whether this function is a slot 0159 **/ 0160 bool isSlot : 1; 0161 /** 0162 * Specifies whether this function is a signal 0163 **/ 0164 bool isSignal : 1; 0165 /** 0166 * Specifies whether this function is constant 0167 **/ 0168 bool isConst : 1; 0169 }; 0170 0171 /** 0172 * List of function descriptions 0173 **/ 0174 using FunctionDescriptionList = QVector<FunctionDescription>; 0175 0176 /** 0177 * Description of an inheritance relation. 0178 **/ 0179 struct KDEVPLATFORMLANGUAGE_EXPORT InheritanceDescription 0180 { 0181 /** 0182 * @brief The mode of this inheritance. 0183 * 0184 * For C++ classes, mode string are the same as access specifiers (public, protected, private). 0185 * In other languages, the mode is used to differentiate between extends/implements 0186 * or other possible inheritance types. 0187 * 0188 * Some languages do not recognise distinct inheritance modes at all. 0189 **/ 0190 QString inheritanceMode; 0191 /** 0192 * The name of the base class 0193 **/ 0194 QString baseType; 0195 }; 0196 0197 /** 0198 * List of inheritance descriptions 0199 **/ 0200 using InheritanceDescriptionList = QVector<InheritanceDescription>; 0201 0202 /** 0203 * @brief Represents a class 0204 * 0205 * A class descriptions stores its name, its member variables and functions, as well as its superclasses and inheritance types. 0206 **/ 0207 struct KDEVPLATFORMLANGUAGE_EXPORT ClassDescription 0208 { 0209 /** 0210 * Creates an empty class 0211 * 0212 **/ 0213 ClassDescription(); 0214 /** 0215 * Creates an empty class named @p name 0216 * 0217 * @param name the name of the new class 0218 **/ 0219 explicit ClassDescription(const QString& name); 0220 0221 /** 0222 * The name of this class 0223 **/ 0224 QString name; 0225 /** 0226 * List of base classes (classes from which this one inherits) as well as inheritance types 0227 **/ 0228 InheritanceDescriptionList baseClasses; 0229 /** 0230 * List of all member variables in this class 0231 **/ 0232 VariableDescriptionList members; 0233 /** 0234 * List of all member functions (methods) in this class 0235 **/ 0236 FunctionDescriptionList methods; 0237 }; 0238 0239 namespace CodeDescription { 0240 template <class T> QVariant toVariantList(const QVector<T>& list) 0241 { 0242 QVariantList ret; 0243 ret.reserve(list.size()); 0244 for (const T& t : list) { 0245 ret << QVariant::fromValue<T>(t); 0246 } 0247 0248 return QVariant::fromValue(ret); 0249 } 0250 } 0251 } 0252 0253 Q_DECLARE_TYPEINFO(KDevelop::VariableDescription, Q_MOVABLE_TYPE); 0254 Q_DECLARE_TYPEINFO(KDevelop::FunctionDescription, Q_MOVABLE_TYPE); 0255 Q_DECLARE_TYPEINFO(KDevelop::InheritanceDescription, Q_MOVABLE_TYPE); 0256 Q_DECLARE_TYPEINFO(KDevelop::ClassDescription, Q_MOVABLE_TYPE); 0257 0258 Q_DECLARE_METATYPE(KDevelop::VariableDescription) 0259 Q_DECLARE_METATYPE(KDevelop::VariableDescriptionList) 0260 Q_DECLARE_METATYPE(KDevelop::FunctionDescription) 0261 Q_DECLARE_METATYPE(KDevelop::FunctionDescriptionList) 0262 Q_DECLARE_METATYPE(KDevelop::InheritanceDescription) 0263 Q_DECLARE_METATYPE(KDevelop::InheritanceDescriptionList) 0264 Q_DECLARE_METATYPE(KDevelop::ClassDescription) 0265 0266 #endif // KDEVPLATFORM_CODEDESCRIPTION_H