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

kdevplatform/language/duchain

  • sources
  • kfour-appscomplete
  • kdevelop
  • kdevplatform
  • language
  • duchain
  • types
containertypes.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of KDevelop
3  * Copyright (C) 2011-2014 Sven Brauch <[email protected]>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Library General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "containertypes.h"
20 
21 #include "typeutils.h"
22 #include "typeregister.h"
23 
24 #include "../duchain.h"
25 #include "../duchainlock.h"
26 
27 #include <KLocalizedString>
28 
29 namespace KDevelop {
30 REGISTER_TYPE(ListType);
31 REGISTER_TYPE(MapType);
32 
33 ListType::ListType()
34  : KDevelop::StructureType(createData<ListType>()) { }
35 
36 ListType::ListType(StructureTypeData& data)
37  : KDevelop::StructureType(data) { }
38 
39 ListType::ListType(const ListType& rhs)
40  : KDevelop::StructureType(copyData<ListType>(*rhs.d_func())) { }
41 
42 MapType::MapType()
43  : ListType(createData<MapType>()) { }
44 
45 MapType::MapType(ListTypeData& data)
46  : ListType(data) { }
47 
48 MapType::MapType(const MapType& rhs)
49  : ListType(copyData<MapType>(*rhs.d_func())) { }
50 
51 void ListType::replaceContentType(const AbstractType::Ptr& newType)
52 {
53  d_func_dynamic()->m_contentType = IndexedType(newType);
54 }
55 
56 void MapType::replaceKeyType(const AbstractType::Ptr& newType)
57 {
58  d_func_dynamic()->m_keyType = IndexedType(newType);
59 }
60 
61 IndexedType ListType::contentType() const
62 {
63  return d_func()->m_contentType;
64 }
65 
66 IndexedType MapType::keyType() const
67 {
68  return d_func()->m_keyType;
69 }
70 
71 AbstractType* ListType::clone() const
72 {
73  return new ListType(*this);
74 }
75 
76 AbstractType* MapType::clone() const
77 {
78  return new MapType(*this);
79 }
80 
81 QString ListType::toString() const
82 {
83  QString prefix = KDevelop::StructureType::toString();
84  auto content = contentType().abstractType();
85  if (content) {
86  return i18n("%1 of %2", prefix, content->toString());
87  }
88  return prefix;
89 }
90 
91 QString MapType::toString() const
92 {
93  QString prefix = KDevelop::StructureType::toString();
94  auto content = contentType().abstractType();
95  auto key = keyType().abstractType();
96  auto key_str = (key ? key->toString() : i18n("unknown"));
97  auto content_str = (content ? content->toString() : i18n("unknown"));
98  if (key || content) {
99  return i18n("%1 of %2 : %3", prefix, key_str, content_str);
100  }
101  return prefix;
102 }
103 
104 QString ListType::containerToString() const
105 {
106  return KDevelop::StructureType::toString();
107 }
108 
109 bool ListType::equals(const AbstractType* rhs) const
110 {
111  if (this == rhs) {
112  return true;
113  }
114  if (!KDevelop::StructureType::equals(rhs)) {
115  return false;
116  }
117  auto c = dynamic_cast<const ListType*>(rhs);
118  if (!c) {
119  return false;
120  }
121  if (c->contentType() != d_func()->m_contentType) {
122  return false;
123  }
124  return true;
125 }
126 
127 bool MapType::equals(const AbstractType* rhs) const
128 {
129  if (!ListType::equals(rhs)) {
130  return false;
131  }
132  auto c = dynamic_cast<const MapType*>(rhs);
133 
134  return c && c->keyType() == d_func()->m_keyType;
135 }
136 
137 uint ListType::hash() const
138 {
139  return StructureType::hash() + (contentType().abstractType() ? contentType().abstractType()->hash() : 1);
140 }
141 
142 uint MapType::hash() const
143 {
144  return ListType::hash() + (keyType().abstractType() ? keyType().abstractType()->hash() : 1);
145 }
146 } // namespace KDevelop
KDevelop::MapType
Represents a hashmap-like object which can have a key and a content type.
Definition: containertypes.h:180
KDevelop::ListTypeData
Definition: containertypes.h:30
KDevelop::ListType
Represents a list-like object which can have a content type.
Definition: containertypes.h:83
KDevelop::MapType::hash
uint hash() const override
Definition: containertypes.cpp:142
KDevelop::StructureType::hash
uint hash() const override
Definition: structuretype.cpp:93
KDevelop::ListType::replaceContentType
void replaceContentType(const AbstractType::Ptr &newType)
Replaces this list's content type by newType.
Definition: containertypes.cpp:51
KDevelop::StructureTypeData
Private data structure for StructureType.
Definition: typesystemdata.h:198
KDevelop::MapType::keyType
IndexedType keyType() const
Get this map's key type.
Definition: containertypes.cpp:66
KDevelop::TypePtr< AbstractType >
KDevelop::REGISTER_TYPE
REGISTER_TYPE(ArrayType)
KDevelop::MapType::equals
bool equals(const AbstractType *rhs) const override
Definition: containertypes.cpp:127
typeutils.h
KDevelop::ListType::hash
uint hash() const override
Definition: containertypes.cpp:137
KDevelop::MapType::replaceKeyType
void replaceKeyType(const AbstractType::Ptr &newType)
Set this map's key type to newType.
Definition: containertypes.cpp:56
QString
KDevelop::ListType::equals
bool equals(const AbstractType *rhs) const override
Definition: containertypes.cpp:109
KDevelop::IndexedType::abstractType
AbstractType::Ptr abstractType() const
Access the type.
Definition: indexedtype.cpp:63
KDevelop::MapType::clone
AbstractType * clone() const override
Definition: containertypes.cpp:76
KDevelop::StructureType::toString
QString toString() const override
Definition: structuretype.cpp:78
KDevelop::ListType::containerToString
QString containerToString() const
Return only the container type, not the content type in a string.
Definition: containertypes.cpp:104
typeregister.h
KDevelop::ListType::clone
AbstractType * clone() const override
Definition: containertypes.cpp:71
KDevelop::StructureType::equals
bool equals(const AbstractType *rhs) const override
Definition: structuretype.cpp:46
KDevelop::MapType::MapType
MapType()
Definition: containertypes.cpp:42
KDevelop::IndexedType
Indexed type pointer.
Definition: indexedtype.h:36
KDevelop
Definition: abstractfunctiondeclaration.cpp:27
KDevelop::MapType::toString
QString toString() const override
Formats this type (base type and key+content type) in a string.
Definition: containertypes.cpp:91
containertypes.h
KDevelop::ListType::contentType
IndexedType contentType() const
Get this lists's content type.
Definition: containertypes.cpp:61
KDevelop::ListType::ListType
ListType()
Definition: containertypes.cpp:33
KDevelop::ListType::toString
QString toString() const override
Formats this type (base type and content type) in a string.
Definition: containertypes.cpp:81
KDevelop::StructureType
A type representing structure types.
Definition: structuretype.h:38
KDevelop::AbstractType
Base class for all types.
Definition: abstracttype.h:87
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:30:10 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevplatform/language/duchain

Skip menu "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