File: cpptypes.cpp

package info (click to toggle)
kdevelop 4%3A4.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 18,844 kB
  • sloc: cpp: 91,758; python: 1,095; lex: 422; ruby: 120; sh: 114; xml: 42; makefile: 38
file content (107 lines) | stat: -rw-r--r-- 3,802 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* This file is part of KDevelop
    Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
    Copyright 2006 Adam Treat <treat@kde.org>
    Copyright 2006 Hamish Rodda <rodda@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "cpptypes.h"

#include <language/duchain/classfunctiondeclaration.h>
#include <language/duchain/abstractfunctiondeclaration.h>
#include <language/duchain/indexedstring.h>
#include <language/duchain/types/typeregister.h>
#include "templateparameterdeclaration.h"
#include <language/duchain/ducontext.h> //Only for FOREACH_ARRAY
#include "templatedeclaration.h"

using namespace KDevelop;

//Because all these classes have no d-pointers, shallow copies are perfectly fine

REGISTER_TYPE(CppClassType);
REGISTER_TYPE(CppTemplateParameterType);

AbstractType* CppClassType::clone() const {
  return new CppClassType(*this);
}

CppClassType::CppClassType() : KDevelop::StructureType(createData<CppClassType>()) {
}

uint CppClassType::hash() const
{
  return 3 * StructureType::hash();
}

QString CppClassType::toString() const
{
  QualifiedIdentifier id = qualifiedIdentifier();
  if (!id.isEmpty()) {
    if(declarationId().specialization().index())
      return AbstractType::toString() + Cpp::IndexedInstantiationInformation(declarationId().specialization()).information().applyToIdentifier(id).toString();
    else
    return AbstractType::toString() + id.toString();
  }

  //This path usually is not taken
  QString type = "class";

  return QString("<%1>%2").arg(type).arg(AbstractType::toString(true));
}


bool moreExpressiveThan(IntegralType* lhs, IntegralType* rhs) {
  bool ret = lhs->dataType() > rhs->dataType() && !((rhs->modifiers() & AbstractType::SignedModifier) && !(lhs->modifiers() & AbstractType::SignedModifier));
  if((rhs->modifiers() & AbstractType::LongLongModifier) && !(lhs->modifiers() & AbstractType::LongLongModifier))
    ret = false;
  if((rhs->modifiers() & AbstractType::LongModifier) && !(lhs->modifiers() & AbstractType::LongLongModifier) && !(lhs->modifiers() & AbstractType::LongModifier))
    ret = false;
  return ret;
}

AbstractType* CppTemplateParameterType::clone() const {
  return new CppTemplateParameterType(*this);
}

bool CppTemplateParameterType::equals(const AbstractType* _rhs) const
{
  if( !fastCast<const CppTemplateParameterType*>(_rhs))
    return false;
  const CppTemplateParameterType* rhs = static_cast<const CppTemplateParameterType*>(_rhs);

  if( this == rhs )
    return true;

  return IdentifiedType::equals(rhs) && AbstractType::equals(rhs);
}

TemplateParameterDeclaration* CppTemplateParameterType::declaration(const TopDUContext* top) const {
  return static_cast<TemplateParameterDeclaration*>(IdentifiedType::declaration(top));
}

QString CppTemplateParameterType::toString() const {
  return AbstractType::toString(false) + "<template> " + IdentifiedType::qualifiedIdentifier().toString();
}

void CppTemplateParameterType::accept0 (KDevelop::TypeVisitor *v) const {
    v->visit(this);
/*    v->endVisit(this);*/
}

uint CppTemplateParameterType::hash() const {
  return 41*IdentifiedType::hash() + AbstractType::hash();
}