• 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.h
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 #ifndef KDEVPLATFORM_TYPEUTILS_H
21 #define KDEVPLATFORM_TYPEUTILS_H
22 
23 #include <language/languageexport.h>
24 #include "abstracttype.h"
25 #include "unsuretype.h"
26 #include "integraltype.h"
27 
28 #include <type_traits>
29 
30 namespace KDevelop {
31 class TopDUContext;
32 }
33 
34 namespace TypeUtils {
43 KDEVPLATFORMLANGUAGE_EXPORT KDevelop::AbstractType::Ptr targetType(const KDevelop::AbstractType::Ptr& type,
44  const KDevelop::TopDUContext* topContext,
45  bool* constant = nullptr);
50 KDEVPLATFORMLANGUAGE_EXPORT KDevelop::AbstractType::Ptr targetTypeKeepAliases(const KDevelop::AbstractType::Ptr& type,
51  const KDevelop::TopDUContext* topContext,
52  bool* constant = nullptr);
57 KDEVPLATFORMLANGUAGE_EXPORT KDevelop::AbstractType::Ptr unAliasedType(const KDevelop::AbstractType::Ptr& type);
58 
62 KDEVPLATFORMLANGUAGE_EXPORT KDevelop::AbstractType::Ptr resolveAliasType(
63  const KDevelop::AbstractType::Ptr& eventualAlias);
64 
69 KDEVPLATFORMLANGUAGE_EXPORT bool isUsefulType(KDevelop::AbstractType::Ptr type);
70 
88 template <typename LanguageUnsureType = KDevelop::UnsureType>
89 KDevelop::AbstractType::Ptr mergeTypes(KDevelop::AbstractType::Ptr type, const KDevelop::AbstractType::Ptr& newType)
90 {
91  static_assert(std::is_base_of<KDevelop::UnsureType, LanguageUnsureType>::value,
92  "LanguageUnsureType must inherit from KDevelop::UnsureType");
93 
94  auto unsure = LanguageUnsureType::Ptr::dynamicCast(type);
95  auto newUnsure = LanguageUnsureType::Ptr::dynamicCast(newType);
96  typename LanguageUnsureType::Ptr ret;
97 
98  // both types are unsure, so join the list of possible types.
99  if (unsure && newUnsure) {
100  int len = newUnsure->typesSize();
101  for (int i = 0; i < len; i++) {
102  unsure->addType(newUnsure->types()[i]);
103  }
104 
105  ret = unsure;
106  }
107  // one of them is unsure, use that and add the other one
108  else if (unsure) {
109  if (isUsefulType(newType)) {
110  unsure->addType(newType->indexed());
111  }
112  ret = unsure;
113  } else if (newUnsure) {
114  KDevelop::UnsureType::Ptr createdUnsureType(static_cast<KDevelop::UnsureType*>(newUnsure->clone()));
115  if (isUsefulType(type)) {
116  createdUnsureType->addType(type->indexed());
117  }
118  ret = LanguageUnsureType::Ptr::staticCast(createdUnsureType);
119  } else {
120  unsure = typename LanguageUnsureType::Ptr(new LanguageUnsureType());
121  if (isUsefulType(type)) {
122  unsure->addType(type->indexed());
123  }
124  if (isUsefulType(newType)) {
125  unsure->addType(newType->indexed());
126  }
127  if (!unsure->typesSize()) {
128  return KDevelop::AbstractType::Ptr(new KDevelop::IntegralType(KDevelop::IntegralType::TypeMixed));
129  }
130  ret = unsure;
131  }
132  if (ret->typesSize() == 1) {
133  return ret->types()[0].abstractType();
134  } else {
135  return KDevelop::AbstractType::Ptr::staticCast(ret);
136  }
137 }
138 }
139 
140 #endif
integraltype.h
KDevelop::AbstractType::Ptr
TypePtr< AbstractType > Ptr
Definition: abstracttype.h:91
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::TypePtr< AbstractType >
KDevelop::TypePtr< AbstractType >::staticCast
static TypePtr< AbstractType > staticCast(const TypePtr< U > &o)
Convert TypePtr to TypePtr<T>, using a static_cast.
Definition: typepointer.h:72
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
TypeUtils::mergeTypes
KDevelop::AbstractType::Ptr mergeTypes(KDevelop::AbstractType::Ptr type, const KDevelop::AbstractType::Ptr &newType)
Merge the second type into the first one.
Definition: typeutils.h:89
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
TypeUtils
Definition: typeutils.cpp:27
abstracttype.h
KDevelop
Definition: abstractfunctiondeclaration.cpp:27
unsuretype.h
KDevelop::IntegralType::TypeMixed
Definition: integraltype.h:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 9 2021 23:29:59 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