~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/cppduchain/cpptypes.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of KDevelop
 
2
    Copyright 2002-2005 Roberto Raggi <roberto@kdevelop.org>
 
3
    Copyright 2006 Adam Treat <treat@kde.org>
 
4
    Copyright 2006 Hamish Rodda <rodda@kde.org>
 
5
 
 
6
   This library is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU Library General Public
 
8
   License version 2 as published by the Free Software Foundation.
 
9
 
 
10
   This library 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 GNU
 
13
   Library 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 library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
   Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#include "cpptypes.h"
 
22
 
 
23
#include <language/duchain/classfunctiondeclaration.h>
 
24
#include <language/duchain/abstractfunctiondeclaration.h>
 
25
#include <language/duchain/indexedstring.h>
 
26
#include <language/duchain/types/typeregister.h>
 
27
#include "templateparameterdeclaration.h"
 
28
#include <language/duchain/ducontext.h> //Only for FOREACH_ARRAY
 
29
#include "templatedeclaration.h"
 
30
 
 
31
using namespace KDevelop;
 
32
 
 
33
//Because all these classes have no d-pointers, shallow copies are perfectly fine
 
34
 
 
35
REGISTER_TYPE(CppClassType);
 
36
REGISTER_TYPE(CppTemplateParameterType);
 
37
 
 
38
AbstractType* CppClassType::clone() const {
 
39
  return new CppClassType(*this);
 
40
}
 
41
 
 
42
CppClassType::CppClassType() : KDevelop::StructureType(createData<CppClassType>()) {
 
43
}
 
44
 
 
45
uint CppClassType::hash() const
 
46
{
 
47
  return 3 * StructureType::hash();
 
48
}
 
49
 
 
50
QString CppClassType::toString() const
 
51
{
 
52
  QualifiedIdentifier id = qualifiedIdentifier();
 
53
  if (!id.isEmpty()) {
 
54
    if(declarationId().specialization().index())
 
55
      return AbstractType::toString() + Cpp::IndexedInstantiationInformation(declarationId().specialization()).information().applyToIdentifier(id).toString();
 
56
    else
 
57
    return AbstractType::toString() + id.toString();
 
58
  }
 
59
 
 
60
  //This path usually is not taken
 
61
  QString type = "class";
 
62
 
 
63
  return QString("<%1>%2").arg(type).arg(AbstractType::toString(true));
 
64
}
 
65
 
 
66
 
 
67
bool moreExpressiveThan(IntegralType* lhs, IntegralType* rhs) {
 
68
  bool ret = lhs->dataType() > rhs->dataType() && !((rhs->modifiers() & AbstractType::SignedModifier) && !(lhs->modifiers() & AbstractType::SignedModifier));
 
69
  if((rhs->modifiers() & AbstractType::LongLongModifier) && !(lhs->modifiers() & AbstractType::LongLongModifier))
 
70
    ret = false;
 
71
  if((rhs->modifiers() & AbstractType::LongModifier) && !(lhs->modifiers() & AbstractType::LongLongModifier) && !(lhs->modifiers() & AbstractType::LongModifier))
 
72
    ret = false;
 
73
  return ret;
 
74
}
 
75
 
 
76
AbstractType* CppTemplateParameterType::clone() const {
 
77
  return new CppTemplateParameterType(*this);
 
78
}
 
79
 
 
80
bool CppTemplateParameterType::equals(const AbstractType* _rhs) const
 
81
{
 
82
  if( !fastCast<const CppTemplateParameterType*>(_rhs))
 
83
    return false;
 
84
  const CppTemplateParameterType* rhs = static_cast<const CppTemplateParameterType*>(_rhs);
 
85
 
 
86
  if( this == rhs )
 
87
    return true;
 
88
 
 
89
  return IdentifiedType::equals(rhs) && AbstractType::equals(rhs);
 
90
}
 
91
 
 
92
TemplateParameterDeclaration* CppTemplateParameterType::declaration(const TopDUContext* top) const {
 
93
  return static_cast<TemplateParameterDeclaration*>(IdentifiedType::declaration(top));
 
94
}
 
95
 
 
96
QString CppTemplateParameterType::toString() const {
 
97
  return AbstractType::toString(false) + "<template> " + IdentifiedType::qualifiedIdentifier().toString();
 
98
}
 
99
 
 
100
void CppTemplateParameterType::accept0 (KDevelop::TypeVisitor *v) const {
 
101
    v->visit(this);
 
102
/*    v->endVisit(this);*/
 
103
}
 
104
 
 
105
uint CppTemplateParameterType::hash() const {
 
106
  return 41*IdentifiedType::hash() + AbstractType::hash();
 
107
}