File indexing completed on 2024-06-23 04:34:45

0001 /*
0002     SPDX-FileCopyrightText: 2006 Roberto Raggi <roberto@kdevelop.org>
0003     SPDX-FileCopyrightText: 2006-2008 Hamish Rodda <rodda@kde.org>
0004     SPDX-FileCopyrightText: 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #ifndef KDEVPLATFORM_INTEGRALTYPE_H
0010 #define KDEVPLATFORM_INTEGRALTYPE_H
0011 
0012 #include "abstracttype.h"
0013 
0014 namespace KDevelop {
0015 class IntegralTypeData;
0016 
0017 /**
0018  * \short A type representing inbuilt data types.
0019  *
0020  * IntegralType is used to represent types which are native to a programming language,
0021  * such as (e.g.) int, float, double, char, bool etc.
0022  */
0023 class KDEVPLATFORMLANGUAGE_EXPORT IntegralType
0024     : public AbstractType
0025 {
0026 public:
0027     using Ptr = TypePtr<IntegralType>;
0028 
0029     /**
0030      * Enumeration of frequently used integral types.
0031      * If your language has another integral type not listed here,
0032      * you can create custom types staring from TypeLanguageSpecific.
0033      */
0034     enum CommonIntegralTypes {
0035         TypeVoid,
0036         TypeNone,
0037         TypeNull,
0038         TypeChar,
0039         TypeBoolean,
0040         TypeByte,
0041         TypeSbyte,
0042         TypeShort,
0043         TypeInt,
0044         TypeLong,
0045         TypeFloat,
0046         TypeDouble,
0047         TypeWchar_t,
0048         TypeString,
0049         TypeMixed,
0050         TypeChar16_t,
0051         TypeChar32_t,
0052         TypeHalf,
0053         TypeLanguageSpecific = 200,
0054         TypeNotIntegralType = 255
0055     };
0056 
0057     /// Default constructor
0058     explicit IntegralType(uint type = TypeNone);
0059     /// Copy constructor. \param rhs type to copy
0060     IntegralType(const IntegralType& rhs);
0061     /// Constructor using raw data. \param data internal data.
0062     explicit IntegralType(IntegralTypeData& data);
0063     /// Destructor
0064     ~IntegralType() override;
0065 
0066     IntegralType& operator=(const IntegralType& rhs) = delete;
0067 
0068     /**
0069      * Access the integral type
0070      *
0071      * \returns the type's data type.
0072      */
0073     uint dataType() const;
0074 
0075     /**
0076      * Set the type's data type.
0077      *
0078      * \param dataType data type of this type.
0079      */
0080     void setDataType(uint dataType);
0081 
0082     /**
0083      * TODO: think of a way to make @c toString work properly for custom data types
0084      *       right now you need to create a custom type and overload it...
0085      */
0086     QString toString() const override;
0087 
0088     uint hash() const override;
0089 
0090     WhichType whichType() const override;
0091 
0092     AbstractType* clone() const override;
0093 
0094     bool equals(const AbstractType* rhs) const override;
0095 
0096     enum {
0097         Identity = 2
0098     };
0099 
0100     using Data = IntegralTypeData;
0101 
0102 protected:
0103     void accept0 (TypeVisitor* v) const override;
0104 
0105     TYPE_DECLARE_DATA(IntegralType)
0106 };
0107 }
0108 
0109 #endif