• 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
typeutils.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2007 David Nolden <[email protected]>
3  Copyright 2014 Sven Brauch <[email protected]>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 
20 #include "typeutils.h"
21 #include "referencetype.h"
22 #include "pointertype.h"
23 #include "typealiastype.h"
24 #include "unsuretype.h"
25 #include "integraltype.h"
26 
27 namespace TypeUtils {
28 using namespace KDevelop;
29 
30 TypePtr<KDevelop::AbstractType> unAliasedType(const TypePtr<KDevelop::AbstractType>& _type)
31 {
32  TypePtr<KDevelop::AbstractType> type = _type;
33 
34  TypePtr<KDevelop::TypeAliasType> alias = type.cast<KDevelop::TypeAliasType>();
35 
36  int depth = 0; //Prevent endless recursion
37  while (alias && depth < 20) {
38  uint hadModifiers = alias->modifiers();
39 
40  type = alias->type();
41 
42  if (hadModifiers && type)
43  type->setModifiers(type->modifiers() | hadModifiers);
44 
45  alias = type.cast<KDevelop::TypeAliasType>();
46  ++depth;
47  }
48 
49  return type;
50 }
51 
53 AbstractType::Ptr targetType(const AbstractType::Ptr& _base, const TopDUContext* /*topContext*/, bool* /*constant*/)
54 {
55  AbstractType::Ptr base(_base);
56 
57  ReferenceType::Ptr ref = base.cast<ReferenceType>();
58  PointerType::Ptr pnt = base.cast<PointerType>();
59  TypeAliasType::Ptr alias = base.cast<TypeAliasType>();
60 
61  while (ref || pnt || alias) {
62  uint hadModifiers = base->modifiers();
63 
64  if (ref) {
65  base = ref->baseType();
66  } else if (pnt) {
67  base = pnt->baseType();
68  } else {
69  base = alias->type();
70  }
71  if ((alias || ref) && hadModifiers && base)
72  base->setModifiers(base->modifiers() | hadModifiers);
73 
74  ref = base.cast<ReferenceType>();
75  pnt = base.cast<PointerType>();
76  alias = base.cast<TypeAliasType>();
77  }
78 
79  return base;
80 }
81 
82 AbstractType::Ptr targetTypeKeepAliases(const AbstractType::Ptr& _base, const TopDUContext* /*topContext*/,
83  bool* /*constant*/)
84 {
85  AbstractType::Ptr base(_base);
86 
87  ReferenceType::Ptr ref = base.cast<ReferenceType>();
88  PointerType::Ptr pnt = base.cast<PointerType>();
89 
90  while (ref || pnt) {
91  if (ref) {
92  uint hadModifiers = ref->modifiers();
93  base = ref->baseType();
94  if (hadModifiers && base)
95  base->setModifiers(base->modifiers() | hadModifiers);
96  } else if (pnt) {
97  base = pnt->baseType();
98  }
99  ref = base.cast<ReferenceType>();
100  pnt = base.cast<PointerType>();
101  }
102 
103  return base;
104 }
105 
106 AbstractType::Ptr resolveAliasType(const AbstractType::Ptr& eventualAlias)
107 {
108  if (eventualAlias && eventualAlias->whichType() == KDevelop::AbstractType::TypeAlias) {
109  return eventualAlias.cast<TypeAliasType>()->type();
110  }
111  return eventualAlias;
112 }
113 
114 bool isUsefulType(AbstractType::Ptr type)
115 {
116  type = resolveAliasType(type);
117  if (!type) {
118  return false;
119  }
120  if (type->whichType() != AbstractType::TypeIntegral) {
121  return true;
122  }
123  auto dtype = type.cast<IntegralType>()->dataType();
124  if (dtype != IntegralType::TypeMixed && dtype != IntegralType::TypeNull) {
125  return true;
126  }
127  return false;
128 }
129 } // namespace TypeUtils
KDevelop::TypeAliasType
Definition: typealiastype.h:32
integraltype.h
referencetype.h
KDevelop::AbstractType::modifiers
quint32 modifiers() const
Access the type modifiers.
Definition: abstracttype.cpp:49
pointertype.h
TypeUtils::targetTypeKeepAliases
AbstractType::Ptr targetTypeKeepAliases(const AbstractType::Ptr &_base, const TopDUContext *, bool *)
Same as targetType(..), ecept that it does not un-aliases TypeAliasTypes Modifiers of aliases ore ref...
Definition: typeutils.cpp:82
KDevelop::TypeAliasType::type
KDevelop::AbstractType::Ptr type() const
Definition: typealiastype.cpp:52
KDevelop::TypePtr
QExplicitlySharedDataPointer wrapper with convenience functions attached.
Definition: typepointer.h:39
KDevelop::PointerType
A type representing pointer types.
Definition: pointertype.h:35
typeutils.h
TypeUtils::targetType
AbstractType::Ptr targetType(const AbstractType::Ptr &_base, const TopDUContext *, bool *)
Returns the completely dereferenced and un-aliased type, pointers are also dereferenced(example: Refe...
Definition: typeutils.cpp:53
typealiastype.h
KDevelop::IntegralType::TypeNull
Definition: integraltype.h:49
KDevelop::TopDUContext
The top context in a definition-use chain for one source file.
Definition: topducontext.h:113
TypeUtils::isUsefulType
bool isUsefulType(AbstractType::Ptr type)
Check whether the passed type is a null or mixed type.
Definition: typeutils.cpp:114
TypeUtils::unAliasedType
TypePtr< KDevelop::AbstractType > unAliasedType(const TypePtr< KDevelop::AbstractType > &_type)
Definition: typeutils.cpp:30
KDevelop::IntegralType
A type representing inbuilt data types.
Definition: integraltype.h:35
TypeUtils::resolveAliasType
AbstractType::Ptr resolveAliasType(const AbstractType::Ptr &eventualAlias)
If eventualAlias is an AliasType, return its aliasedType(), otherwise return eventualAlias.
Definition: typeutils.cpp:106
KDevelop::ReferenceType
A type representing reference types.
Definition: referencetype.h:35
TypeUtils
Definition: typeutils.cpp:27
KDevelop::TypePtr::cast
TypePtr< U > cast(U *=nullptr) const
Uses dynamic_cast to cast this pointer to the given type.
Definition: typepointer.h:56
KDevelop
Definition: abstractfunctiondeclaration.cpp:27
unsuretype.h
KDevelop::AbstractType::TypeAlias
a type-alias type
Definition: abstracttype.h:225
KDevelop::IntegralType::TypeMixed
Definition: integraltype.h:61
KDevelop::AbstractType::TypeIntegral
an integral
Definition: abstracttype.h:216
KDevelop::AbstractType::setModifiers
void setModifiers(quint32 modifiers)
Set the type's modifiers.
Definition: abstracttype.cpp:54
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jan 20 2021 23:38:35 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