File indexing completed on 2024-06-16 04:23:17

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_REFERENCETYPE_H
0010 #define KDEVPLATFORM_REFERENCETYPE_H
0011 
0012 #include "abstracttype.h"
0013 
0014 namespace KDevelop {
0015 class ReferenceTypeData;
0016 
0017 /**
0018  * \short A type representing reference types.
0019  *
0020  * ReferenceType is used to represent types which hold a reference to a
0021  * variable.
0022  */
0023 class KDEVPLATFORMLANGUAGE_EXPORT ReferenceType
0024     : public AbstractType
0025 {
0026 public:
0027     using Ptr = TypePtr<ReferenceType>;
0028 
0029     /// Default constructor
0030     ReferenceType ();
0031     /// Copy constructor. \param rhs type to copy
0032     ReferenceType (const ReferenceType& rhs);
0033     /// Constructor using raw data. \param data internal data.
0034     explicit ReferenceType(ReferenceTypeData& data);
0035     /// Destructor
0036     ~ReferenceType() override;
0037 
0038     ReferenceType& operator=(const ReferenceType& rhs) = delete;
0039 
0040     /**
0041      * Retrieve the referenced type, ie. what type of data this type references.
0042      *
0043      * \returns the base type.
0044      */
0045     AbstractType::Ptr baseType () const;
0046 
0047     /**
0048      * Sets the referenced type, ie. what type of data this type references.
0049      *
0050      * \param baseType the base type.
0051      */
0052     void setBaseType(const AbstractType::Ptr& baseType);
0053 
0054     /**
0055      * Checks whether this type is an rvalue- or lvalue-reference type.
0056      *
0057      * \returns true for rvalue-references, false for lvalue-references
0058      */
0059     bool isRValue() const;
0060 
0061     /**
0062      * Sets whether this type is an rvalue- or lvalue-reference type.
0063      *
0064      * \param isRValue true for rvalue-references, false for lvalue-references
0065      */
0066     void setIsRValue(bool isRValue);
0067 
0068     QString toString() const override;
0069 
0070     uint hash() const override;
0071 
0072     WhichType whichType() const override;
0073 
0074     AbstractType* clone() const override;
0075 
0076     bool equals(const AbstractType* rhs) const override;
0077 
0078     void exchangeTypes(TypeExchanger* exchanger) override;
0079 
0080     enum {
0081         Identity = 4
0082     };
0083 
0084     using Data = ReferenceTypeData;
0085 
0086 protected:
0087     void accept0 (TypeVisitor* v) const override;
0088 
0089     TYPE_DECLARE_DATA(ReferenceType)
0090 };
0091 }
0092 
0093 #endif // KDEVPLATFORM_TYPESYSTEM_H