File indexing completed on 2024-05-12 04:38:03
0001 /* 0002 SPDX-FileCopyrightText: 2007 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #ifndef KDEVPLATFORM_NAMESPACEALIASDECLARATION_H 0008 #define KDEVPLATFORM_NAMESPACEALIASDECLARATION_H 0009 0010 #include "declaration.h" 0011 #include "declarationdata.h" 0012 0013 namespace KDevelop { 0014 class KDEVPLATFORMLANGUAGE_EXPORT NamespaceAliasDeclarationData 0015 : public DeclarationData 0016 { 0017 public: 0018 NamespaceAliasDeclarationData() {} 0019 NamespaceAliasDeclarationData(const NamespaceAliasDeclarationData& rhs) 0020 : DeclarationData(rhs) 0021 , m_importIdentifier(rhs.m_importIdentifier) 0022 { 0023 } 0024 ~NamespaceAliasDeclarationData() = default; 0025 NamespaceAliasDeclarationData& operator=(const NamespaceAliasDeclarationData& rhs) = delete; 0026 IndexedQualifiedIdentifier m_importIdentifier; //The identifier that was imported 0027 }; 0028 /** 0029 * A class which represents a "using namespace" statement, or a "namespace A = B" statement. 0030 * 0031 * This class is used by the duchain search process to transparently transform the search according to 0032 * namespace aliases and namespace imports. 0033 * 0034 * A namespace import declaration must have an identifier that equals globalImportIdentifier. 0035 * 0036 * If the identifier of the declaration does not equal globalImportIdentifier, then the declaration 0037 * represents a namespace alias, where the name of the alias equals the declaration. In that case, 0038 * the declaration is additionally added to the persistent symbol table with its real scope and globalAliasIdentifer 0039 * appended, to allow an efficient lookup. 0040 */ 0041 class KDEVPLATFORMLANGUAGE_EXPORT NamespaceAliasDeclaration 0042 : public Declaration 0043 { 0044 public: 0045 NamespaceAliasDeclaration(const NamespaceAliasDeclaration& rhs); 0046 NamespaceAliasDeclaration(const RangeInRevision& range, DUContext* context); 0047 explicit NamespaceAliasDeclaration(NamespaceAliasDeclarationData& data); 0048 0049 ~NamespaceAliasDeclaration() override; 0050 0051 NamespaceAliasDeclaration& operator=(const NamespaceAliasDeclaration& rhs) = delete; 0052 0053 ///A NamespaceAliasDeclaration cannot have a type, so setAbstractType does nothing here. 0054 void setAbstractType(AbstractType::Ptr type) override; 0055 0056 /**The identifier that was imported.*/ 0057 QualifiedIdentifier importIdentifier() const; 0058 /** 0059 * The identifier must be absolute (Resolve it before setting it!) 0060 * Although the identifier is global, the explicitlyGlobal() member must not be set 0061 */ 0062 void setImportIdentifier(const QualifiedIdentifier& id); 0063 0064 void setInSymbolTable(bool inSymbolTable) override; 0065 0066 enum { 0067 Identity = 13 0068 }; 0069 0070 using BaseClass = Declaration; 0071 0072 QString toString() const override; 0073 0074 private: 0075 void unregisterAliasIdentifier(); 0076 void registerAliasIdentifier(); 0077 Declaration* clonePrivate() const override; 0078 DUCHAIN_DECLARE_DATA(NamespaceAliasDeclaration) 0079 }; 0080 } 0081 0082 #endif // KDEVPLATFORM_NAMESPACEALIASDECLARATION_H