• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

constantintegraltype.cpp

00001 /* This file is part of KDevelop
00002     Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
00003     Copyright 2006 Adam Treat <treat@kde.org>
00004     Copyright 2006-2008 Hamish Rodda <rodda@kde.org>
00005     Copyright 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License version 2 as published by the Free Software Foundation.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "constantintegraltype.h"
00023 
00024 #include "typesystemdata.h"
00025 #include "typeregister.h"
00026 
00027 namespace KDevelop {
00028 
00029 REGISTER_TYPE(ConstantIntegralType);
00030 
00031 ConstantIntegralType::ConstantIntegralType(const ConstantIntegralType& rhs)
00032   : IntegralType(copyData<ConstantIntegralType>(*rhs.d_func()))
00033 {
00034 }
00035 
00036 ConstantIntegralType::ConstantIntegralType(ConstantIntegralTypeData& data)
00037   : IntegralType(data)
00038 {
00039 }
00040 
00041 ConstantIntegralType::ConstantIntegralType(uint type)
00042   : IntegralType(createData<ConstantIntegralType>())
00043 {
00044   setDataType(type);
00045   setModifiers(ConstModifier);
00046 }
00047 
00048 qint64 ConstantIntegralType::plainValue() const
00049 {
00050   return d_func()->m_value;
00051 }
00052 
00053 AbstractType* ConstantIntegralType::clone() const
00054 {
00055   return new ConstantIntegralType(*this);
00056 }
00057 
00058 bool ConstantIntegralType::equals(const AbstractType* _rhs) const
00059 {
00060   if( this == _rhs )
00061     return true;
00062 
00063   if (!IntegralType::equals(_rhs))
00064     return false;
00065 
00066   Q_ASSERT(fastCast<const ConstantIntegralType*>(_rhs));
00067 
00068   const ConstantIntegralType* rhs = static_cast<const ConstantIntegralType*>(_rhs);
00069 
00070   return d_func()->m_value == rhs->d_func()->m_value;
00071 }
00072 
00073 QString ConstantIntegralType::toString() const
00074 {
00075   QString ret;
00076 
00077   switch(dataType()) {
00078     case TypeNone:
00079       ret += "none";
00080       break;
00081     case TypeChar:
00082       ret += QString("%1").arg((char)d_func()->m_value);
00083       break;
00084     case TypeWchar_t:
00085       ret += QString("%1").arg((wchar_t)d_func()->m_value);
00086       break;
00087     case TypeBoolean:
00088       ret += d_func()->m_value ? "true" : "false";
00089       break;
00090     case TypeInt:
00091       ret += (modifiers() & UnsignedModifier) ? QString("%1u").arg((uint)d_func()->m_value) : QString("%1").arg((int)d_func()->m_value);
00092       break;
00093     case TypeFloat:
00094       ret += QString("%1").arg( value<float>() );
00095       break;
00096     case TypeDouble:
00097       ret += QString("%1").arg( value<double>() );
00098       break;
00099     case TypeVoid:
00100       ret += "void";
00101       break;
00102     default:
00103       ret += "<unknown_value>";
00104       break;
00105   }
00106 
00107   return ret;
00108 }
00109 
00110 uint ConstantIntegralType::hash() const
00111 {
00112   uint ret = IntegralType::hash();
00113   ret += 47 * (uint)d_func()->m_value;
00114   return ret;
00115 }
00116 
00117 template<>
00118 KDEVPLATFORMLANGUAGE_EXPORT
00119 void ConstantIntegralType::setValueInternal<qint64>(qint64 value) {
00120   if((modifiers() & UnsignedModifier)) {
00121     kDebug() << "setValue(signed) called on unsigned type";
00122   }
00123   d_func_dynamic()->m_value = value;
00124 }
00125 
00126 template<>
00127 KDEVPLATFORMLANGUAGE_EXPORT
00128 void ConstantIntegralType::setValueInternal<quint64>(quint64 value) {
00129   if(!(modifiers() & UnsignedModifier)) {
00130     kDebug() << "setValue(unsigned) called on not unsigned type";
00131   }
00132   d_func_dynamic()->m_value = (qint64)value;
00133 }
00134 
00135 template<>
00136 KDEVPLATFORMLANGUAGE_EXPORT
00137 void ConstantIntegralType::setValueInternal<float>(float value) {
00138   if(dataType() != TypeFloat) {
00139     kDebug() << "setValue(float) called on non-float type";
00140   }
00141   memcpy(&d_func_dynamic()->m_value, &value, sizeof(float));
00142 }
00143 
00144 template<>
00145 KDEVPLATFORMLANGUAGE_EXPORT
00146 void ConstantIntegralType::setValueInternal<double>(double value) {
00147   if(dataType() != TypeDouble) {
00148     kDebug() << "setValue(double) called on non-double type";
00149   }
00150   memcpy(&d_func_dynamic()->m_value, &value, sizeof(double));
00151 }
00152 
00153 }

language/duchain

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

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal