OSDN Git Service

747187a6faf51de2d930c1b5b7c1ec8b6fd6ae82
[qt-creator-jp/qt-creator-jp.git] / src / shared / cplusplus / CoreTypes.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining a copy
36 // of this software and associated documentation files (the "Software"), to deal
37 // in the Software without restriction, including without limitation the rights
38 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39 // copies of the Software, and to permit persons to whom the Software is
40 // furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
51 // THE SOFTWARE.
52
53 #include "CoreTypes.h"
54 #include "TypeVisitor.h"
55 #include "TypeMatcher.h"
56 #include "Names.h"
57 #include <algorithm>
58
59 using namespace CPlusPlus;
60
61 bool UndefinedType::isEqualTo(const Type *other) const
62 {
63     if (other->isUndefinedType())
64         return true;
65
66     return false;
67 }
68
69 void UndefinedType::accept0(TypeVisitor *visitor)
70 { visitor->visit(this); }
71
72 bool UndefinedType::matchType0(const Type *otherType, TypeMatcher *matcher) const
73 {
74     if (const UndefinedType *otherUndefinedTy = otherType->asUndefinedType())
75         return matcher->match(this, otherUndefinedTy);
76
77     return false;
78 }
79
80 bool VoidType::isEqualTo(const Type *other) const
81 {
82     const VoidType *o = other->asVoidType();
83     return o != 0;
84 }
85
86 void VoidType::accept0(TypeVisitor *visitor)
87 { visitor->visit(this); }
88
89 bool VoidType::matchType0(const Type *otherType, TypeMatcher *matcher) const
90 {
91     if (const VoidType *otherVoidTy = otherType->asVoidType())
92         return matcher->match(this, otherVoidTy);
93
94     return false;
95 }
96
97 PointerToMemberType::PointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
98     : _memberName(memberName),
99       _elementType(elementType)
100 { }
101
102 PointerToMemberType::~PointerToMemberType()
103 { }
104
105 const Name *PointerToMemberType::memberName() const
106 { return _memberName; }
107
108 FullySpecifiedType PointerToMemberType::elementType() const
109 { return _elementType; }
110
111 bool PointerToMemberType::isEqualTo(const Type *other) const
112 {
113     const PointerToMemberType *o = other->asPointerToMemberType();
114     if (! o)
115         return false;
116     else if (! _memberName->isEqualTo(o->_memberName))
117         return false;
118     return _elementType.isEqualTo(o->_elementType);
119 }
120
121 void PointerToMemberType::accept0(TypeVisitor *visitor)
122 { visitor->visit(this); }
123
124 bool PointerToMemberType::matchType0(const Type *otherType, TypeMatcher *matcher) const
125 {
126     if (const PointerToMemberType *otherTy = otherType->asPointerToMemberType())
127         return matcher->match(this, otherTy);
128
129     return false;
130 }
131
132 PointerType::PointerType(const FullySpecifiedType &elementType)
133     : _elementType(elementType)
134 { }
135
136 PointerType::~PointerType()
137 { }
138
139 bool PointerType::isEqualTo(const Type *other) const
140 {
141     const PointerType *o = other->asPointerType();
142     if (! o)
143         return false;
144     return _elementType.isEqualTo(o->_elementType);
145 }
146
147 void PointerType::accept0(TypeVisitor *visitor)
148 { visitor->visit(this); }
149
150 bool PointerType::matchType0(const Type *otherType, TypeMatcher *matcher) const
151 {
152     if (const PointerType *otherTy = otherType->asPointerType())
153         return matcher->match(this, otherTy);
154
155     return false;
156 }
157
158 FullySpecifiedType PointerType::elementType() const
159 { return _elementType; }
160
161 ReferenceType::ReferenceType(const FullySpecifiedType &elementType, bool rvalueRef)
162     : _elementType(elementType), _rvalueReference(rvalueRef)
163 { }
164
165 ReferenceType::~ReferenceType()
166 { }
167
168 bool ReferenceType::isEqualTo(const Type *other) const
169 {
170     const ReferenceType *o = other->asReferenceType();
171     if (! o)
172         return false;
173     else if (isRvalueReference() != o->isRvalueReference())
174         return false;
175     return _elementType.isEqualTo(o->_elementType);
176 }
177
178 void ReferenceType::accept0(TypeVisitor *visitor)
179 { visitor->visit(this); }
180
181 bool ReferenceType::matchType0(const Type *otherType, TypeMatcher *matcher) const
182 {
183     if (const ReferenceType *otherTy = otherType->asReferenceType())
184         return matcher->match(this, otherTy);
185
186     return false;
187 }
188
189 FullySpecifiedType ReferenceType::elementType() const
190 { return _elementType; }
191
192 bool ReferenceType::isRvalueReference() const
193 { return _rvalueReference; }
194
195 IntegerType::IntegerType(int kind)
196     : _kind(kind)
197 { }
198
199 IntegerType::~IntegerType()
200 { }
201
202 bool IntegerType::isEqualTo(const Type *other) const
203 {
204     const IntegerType *o = other->asIntegerType();
205     if (! o)
206         return false;
207     return _kind == o->_kind;
208 }
209
210 void IntegerType::accept0(TypeVisitor *visitor)
211 { visitor->visit(this); }
212
213 bool IntegerType::matchType0(const Type *otherType, TypeMatcher *matcher) const
214 {
215     if (const IntegerType *otherTy = otherType->asIntegerType())
216         return matcher->match(this, otherTy);
217
218     return false;
219 }
220
221 int IntegerType::kind() const
222 { return _kind; }
223
224 FloatType::FloatType(int kind)
225     : _kind(kind)
226 { }
227
228 FloatType::~FloatType()
229 { }
230
231 void FloatType::accept0(TypeVisitor *visitor)
232 { visitor->visit(this); }
233
234 bool FloatType::matchType0(const Type *otherType, TypeMatcher *matcher) const
235 {
236     if (const FloatType *otherTy = otherType->asFloatType())
237         return matcher->match(this, otherTy);
238
239     return false;
240 }
241
242 int FloatType::kind() const
243 { return _kind; }
244
245 bool FloatType::isEqualTo(const Type *other) const
246 {
247     const FloatType *o = other->asFloatType();
248     if (! o)
249         return false;
250     return _kind == o->_kind;
251 }
252
253 ArrayType::ArrayType(const FullySpecifiedType &elementType, unsigned size)
254     : _elementType(elementType), _size(size)
255 { }
256
257 ArrayType::~ArrayType()
258 { }
259
260 bool ArrayType::isEqualTo(const Type *other) const
261 {
262     const ArrayType *o = other->asArrayType();
263     if (! o)
264         return false;
265     else if (_size != o->_size)
266         return false;
267     return _elementType.isEqualTo(o->_elementType);
268 }
269
270 void ArrayType::accept0(TypeVisitor *visitor)
271 { visitor->visit(this); }
272
273 bool ArrayType::matchType0(const Type *otherType, TypeMatcher *matcher) const
274 {
275     if (const ArrayType *otherTy = otherType->asArrayType())
276         return matcher->match(this, otherTy);
277
278     return false;
279 }
280
281 FullySpecifiedType ArrayType::elementType() const
282 { return _elementType; }
283
284 unsigned ArrayType::size() const
285 { return _size; }
286
287 NamedType::NamedType(const Name *name)
288     : _name(name)
289 { }
290
291 NamedType::~NamedType()
292 { }
293
294 const Name *NamedType::name() const
295 { return _name; }
296
297 bool NamedType::isEqualTo(const Type *other) const
298 {
299     const NamedType *o = other->asNamedType();
300     if (! o)
301         return false;
302
303     const Name *name = _name;
304     if (const QualifiedNameId *q = name->asQualifiedNameId())
305         name = q->name();
306
307     const Name *otherName = o->name();
308     if (const QualifiedNameId *q = otherName->asQualifiedNameId())
309         otherName = q->name();
310
311     return name->isEqualTo(otherName);
312 }
313
314 void NamedType::accept0(TypeVisitor *visitor)
315 { visitor->visit(this); }
316
317 bool NamedType::matchType0(const Type *otherType, TypeMatcher *matcher) const
318 {
319     if (const NamedType *otherTy = otherType->asNamedType())
320         return matcher->match(this, otherTy);
321
322     return false;
323 }