1 /* 2 SPDX-FileCopyrightText: 2006 Roberto Raggi <roberto@kdevelop.org> 3 SPDX-FileCopyrightText: 2006-2008 Hamish Rodda <rodda@kde.org> 4 SPDX-FileCopyrightText: 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de> 5 6 SPDX-License-Identifier: LGPL-2.0-only 7 */ 8 9 #ifndef KDEVPLATFORM_INTEGRALTYPE_H 10 #define KDEVPLATFORM_INTEGRALTYPE_H 11 12 #include "abstracttype.h" 13 14 namespace KDevelop { 15 class IntegralTypeData; 16 17 /** 18 * \short A type representing inbuilt data types. 19 * 20 * IntegralType is used to represent types which are native to a programming language, 21 * such as (e.g.) int, float, double, char, bool etc. 22 */ 23 class KDEVPLATFORMLANGUAGE_EXPORT IntegralType 24 : public AbstractType 25 { 26 public: 27 using Ptr = TypePtr<IntegralType>; 28 29 /** 30 * Enumeration of frequently used integral types. 31 * If your language has another integral type not listed here, 32 * you can create custom types staring from TypeLanguageSpecific. 33 */ 34 enum CommonIntegralTypes { 35 TypeVoid, 36 TypeNone, 37 TypeNull, 38 TypeChar, 39 TypeBoolean, 40 TypeByte, 41 TypeSbyte, 42 TypeShort, 43 TypeInt, 44 TypeLong, 45 TypeFloat, 46 TypeDouble, 47 TypeWchar_t, 48 TypeString, 49 TypeMixed, 50 TypeChar16_t, 51 TypeChar32_t, 52 TypeLanguageSpecific = 200 53 }; 54 55 /// Default constructor 56 explicit IntegralType(uint type = TypeNone); 57 /// Copy constructor. \param rhs type to copy 58 IntegralType(const IntegralType& rhs); 59 /// Constructor using raw data. \param data internal data. 60 explicit IntegralType(IntegralTypeData& data); 61 /// Destructor 62 ~IntegralType() override; 63 64 IntegralType& operator=(const IntegralType& rhs) = delete; 65 66 /** 67 * Access the integral type 68 * 69 * \returns the type's data type. 70 */ 71 uint dataType() const; 72 73 /** 74 * Set the type's data type. 75 * 76 * \param dataType data type of this type. 77 */ 78 void setDataType(uint dataType); 79 80 /** 81 * TODO: think of a way to make @c toString work properly for custom data types 82 * right now you need to create a custom type and overload it... 83 */ 84 QString toString() const override; 85 86 uint hash() const override; 87 88 WhichType whichType() const override; 89 90 AbstractType* clone() const override; 91 92 bool equals(const AbstractType* rhs) const override; 93 94 enum { 95 Identity = 2 96 }; 97 98 using Data = IntegralTypeData; 99 100 protected: 101 void accept0 (TypeVisitor* v) const override; 102 103 TYPE_DECLARE_DATA(IntegralType) 104 }; 105 106 template <> 107 inline IntegralType* fastCast<IntegralType*>(AbstractType* from) 108 { 109 if (!from || from->whichType() != AbstractType::TypeIntegral) 110 return nullptr; 111 else 112 return static_cast<IntegralType*>(from); 113 } 114 } 115 116 #endif 117