• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevelop/kdevplatform/language/duchain

  • extragear
  • kdevelop
  • kdevelop
  • kdevplatform
  • language
  • duchain
namespacealiasdeclaration.cpp
Go to the documentation of this file.
1 /* This is part of KDevelop
2  Copyright 2007 David Nolden <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17  */
18 
19 #include "namespacealiasdeclaration.h"
20 
21 #include "ducontext.h"
22 #include "duchainregister.h"
23 #include "persistentsymboltable.h"
24 
25 namespace KDevelop {
26 REGISTER_DUCHAIN_ITEM(NamespaceAliasDeclaration);
27 
28 NamespaceAliasDeclaration::NamespaceAliasDeclaration(const NamespaceAliasDeclaration& rhs)
29  : Declaration(*new NamespaceAliasDeclarationData(*rhs.d_func()))
30 {
31 }
32 
33 NamespaceAliasDeclaration::NamespaceAliasDeclaration(const RangeInRevision& range, DUContext* context)
34  : Declaration(*new NamespaceAliasDeclarationData, range)
35 {
36  d_func_dynamic()->setClassId(this);
37  setKind(NamespaceAlias);
38  if (context)
39  setContext(context);
40 }
41 
42 NamespaceAliasDeclaration::NamespaceAliasDeclaration(NamespaceAliasDeclarationData& data) : Declaration(data)
43 {
44 }
45 
46 QualifiedIdentifier NamespaceAliasDeclaration::importIdentifier() const
47 {
48  return d_func()->m_importIdentifier.identifier();
49 }
50 
51 void NamespaceAliasDeclaration::setImportIdentifier(const QualifiedIdentifier& id)
52 {
53  Q_ASSERT(!id.explicitlyGlobal());
54  d_func_dynamic()->m_importIdentifier = id;
55 }
56 
57 NamespaceAliasDeclaration::~NamespaceAliasDeclaration()
58 {
59  if (persistentlyDestroying() && d_func()->m_inSymbolTable)
60  unregisterAliasIdentifier();
61 }
62 
63 void NamespaceAliasDeclaration::setInSymbolTable(bool inSymbolTable)
64 {
65  if (d_func()->m_inSymbolTable && !inSymbolTable) {
66  unregisterAliasIdentifier();
67  } else if (!d_func()->m_inSymbolTable && inSymbolTable) {
68  registerAliasIdentifier();
69  }
70  KDevelop::Declaration::setInSymbolTable(inSymbolTable);
71 }
72 
73 void NamespaceAliasDeclaration::unregisterAliasIdentifier()
74 {
75  if (indexedIdentifier() != globalIndexedImportIdentifier()) {
76  QualifiedIdentifier aliasId = qualifiedIdentifier();
77  aliasId.push(globalIndexedAliasIdentifier());
78  KDevelop::PersistentSymbolTable::self().removeDeclaration(aliasId, this);
79  }
80 }
81 
82 void NamespaceAliasDeclaration::registerAliasIdentifier()
83 {
84  if (indexedIdentifier() != globalIndexedImportIdentifier()) {
85  QualifiedIdentifier aliasId = qualifiedIdentifier();
86  aliasId.push(globalIndexedAliasIdentifier());
87  KDevelop::PersistentSymbolTable::self().addDeclaration(aliasId, this);
88  }
89 }
90 
91 Declaration* NamespaceAliasDeclaration::clonePrivate() const
92 {
93  return new NamespaceAliasDeclaration(*this);
94 }
95 
96 void NamespaceAliasDeclaration::setAbstractType(AbstractType::Ptr type)
97 {
98  //A namespace-import does not have a type, so ignore any set type
99  Q_UNUSED(type);
100 }
101 
102 QString NamespaceAliasDeclaration::toString() const
103 {
104  DUCHAIN_D(NamespaceAliasDeclaration);
105  if (indexedIdentifier() != globalIndexedImportIdentifier())
106  return i18n("Import %1 as %2", d->m_importIdentifier.identifier().toString(), identifier().toString());
107  else
108  return i18n("Import %1", d->m_importIdentifier.identifier().toString());
109 }
110 }
KDevelop::Declaration
Represents a single declaration in a definition-use chain.
Definition: declaration.h:51
KDevelop::globalIndexedImportIdentifier
const IndexedIdentifier & globalIndexedImportIdentifier()
This is the identifier that can be used to search namespace-import declarations, and should be used t...
Definition: ducontext.cpp:96
KDevelop::NamespaceAliasDeclaration::setAbstractType
void setAbstractType(AbstractType::Ptr type) override
A NamespaceAliasDeclaration cannot have a type, so setAbstractType does nothing here.
Definition: namespacealiasdeclaration.cpp:96
KDevelop::REGISTER_DUCHAIN_ITEM
REGISTER_DUCHAIN_ITEM(AliasDeclaration)
KDevelop::PersistentSymbolTable::removeDeclaration
void removeDeclaration(const IndexedQualifiedIdentifier &id, const IndexedDeclaration &declaration)
Adds declaration declaration with id id to the symbol table.
Definition: persistentsymboltable.cpp:251
KDevelop::m_inSymbolTable
bool m_inSymbolTable
Definition: ducontextdata.h:75
KDevelop::Declaration::setContext
void setContext(DUContext *context, bool anonymous=false)
Set the context in which this declaration occurs.
Definition: declaration.cpp:290
KDevelop::Declaration::id
virtual DeclarationId id(bool forceDirect=false) const
Definition: declaration.cpp:567
KDevelop::TypePtr< AbstractType >
KDevelop::NamespaceAliasDeclaration::importIdentifier
QualifiedIdentifier importIdentifier() const
The identifier that was imported.
Definition: namespacealiasdeclaration.cpp:46
KDevelop::Identifier::toString
QString toString(IdentifierStringFormattingOptions options=NoOptions) const
Definition: identifier.cpp:594
KDevelop::PersistentSymbolTable::self
static PersistentSymbolTable & self()
Definition: persistentsymboltable.cpp:486
KDevelop::globalIndexedAliasIdentifier
const IndexedIdentifier & globalIndexedAliasIdentifier()
This is the identifier that can be used to search namespace-alias declarations.
Definition: ducontext.cpp:102
namespacealiasdeclaration.h
KDevelop::NamespaceAliasDeclarationData
Definition: namespacealiasdeclaration.h:26
KDevelop::Declaration::indexedIdentifier
const IndexedIdentifier & indexedIdentifier() const
Access this declaration's identifier.
Definition: declaration.cpp:210
KDevelop::Declaration::identifier
Identifier identifier() const
Access this declaration's identifier.
Definition: declaration.cpp:204
KDevelop::NamespaceAliasDeclaration::setInSymbolTable
void setInSymbolTable(bool inSymbolTable) override
Adds or removes this declaration to/from the symbol table.
Definition: namespacealiasdeclaration.cpp:63
QString
KDevelop::QualifiedIdentifier::push
void push(const IndexedIdentifier &id)
Append id to this qualified identifier.
Definition: identifier.cpp:995
ducontext.h
KDevelop::QualifiedIdentifier
Represents a qualified identifier.
Definition: identifier.h:245
DUCHAIN_D
#define DUCHAIN_D(Class)
Definition: duchainbase.h:47
KDevelop::Declaration::NamespaceAlias
This is a namespace-alias.
Definition: declaration.h:66
KDevelop::Declaration::setKind
void setKind(Kind kind)
Set the kind.
Definition: declaration.cpp:84
KDevelop::Declaration::qualifiedIdentifier
QualifiedIdentifier qualifiedIdentifier() const
Determine the global qualified identifier of this declaration.
Definition: declaration.cpp:267
KDevelop::NamespaceAliasDeclaration
A class which represents a "using namespace" statement, or a "namespace A = B" statement.
Definition: namespacealiasdeclaration.h:53
KDevelop::Declaration::persistentlyDestroying
bool persistentlyDestroying() const
Returns true if this declaration is being currently destroyed persistently, which means that it shoul...
Definition: declaration.cpp:134
KDevelop::NamespaceAliasDeclaration::~NamespaceAliasDeclaration
~NamespaceAliasDeclaration() override
Definition: namespacealiasdeclaration.cpp:57
KDevelop::PersistentSymbolTable::addDeclaration
void addDeclaration(const IndexedQualifiedIdentifier &id, const IndexedDeclaration &declaration)
Adds declaration declaration with id id to the symbol table.
Definition: persistentsymboltable.cpp:200
KDevelop::Declaration::setInSymbolTable
virtual void setInSymbolTable(bool inSymbolTable)
Adds or removes this declaration to/from the symbol table.
Definition: declaration.cpp:617
duchainregister.h
KDevelop::NamespaceAliasDeclaration::setImportIdentifier
void setImportIdentifier(const QualifiedIdentifier &id)
The identifier must be absolute (Resolve it before setting it!) Although the identifier is global...
Definition: namespacealiasdeclaration.cpp:51
KDevelop::NamespaceAliasDeclaration::NamespaceAliasDeclaration
NamespaceAliasDeclaration(const NamespaceAliasDeclaration &rhs)
Definition: namespacealiasdeclaration.cpp:28
KDevelop::DUContext
A single context in source code, represented as a node in a directed acyclic graph.
Definition: ducontext.h:72
persistentsymboltable.h
KDevelop::NamespaceAliasDeclaration::toString
QString toString() const override
Determine this declaration as a string.
Definition: namespacealiasdeclaration.cpp:102
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Dec 9 2019 02:48:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevelop/kdevplatform/language/duchain

Skip menu "kdevelop/kdevplatform/language/duchain"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  •   kdevplatform
  •     debugger
  •     documentation
  •     interfaces
  •     language
  •       assistant
  •       backgroundparser
  •       checks
  •       classmodel
  •       codecompletion
  •       codegen
  •       duchain
  •       editor
  •       highlighting
  •       interfaces
  •       util
  •     outputview
  •     project
  •     serialization
  •     shell
  •     sublime
  •     tests
  •     util
  •     vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal