1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
33 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
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:
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
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
53 #include "CoreTypes.h"
54 #include "TypeVisitor.h"
55 #include "TypeMatcher.h"
59 using namespace CPlusPlus;
61 bool UndefinedType::isEqualTo(const Type *other) const
63 if (other->isUndefinedType())
69 void UndefinedType::accept0(TypeVisitor *visitor)
70 { visitor->visit(this); }
72 bool UndefinedType::matchType0(const Type *otherType, TypeMatcher *matcher) const
74 if (const UndefinedType *otherUndefinedTy = otherType->asUndefinedType())
75 return matcher->match(this, otherUndefinedTy);
80 bool VoidType::isEqualTo(const Type *other) const
82 const VoidType *o = other->asVoidType();
86 void VoidType::accept0(TypeVisitor *visitor)
87 { visitor->visit(this); }
89 bool VoidType::matchType0(const Type *otherType, TypeMatcher *matcher) const
91 if (const VoidType *otherVoidTy = otherType->asVoidType())
92 return matcher->match(this, otherVoidTy);
97 PointerToMemberType::PointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
98 : _memberName(memberName),
99 _elementType(elementType)
102 PointerToMemberType::~PointerToMemberType()
105 const Name *PointerToMemberType::memberName() const
106 { return _memberName; }
108 FullySpecifiedType PointerToMemberType::elementType() const
109 { return _elementType; }
111 bool PointerToMemberType::isEqualTo(const Type *other) const
113 const PointerToMemberType *o = other->asPointerToMemberType();
116 else if (! _memberName->isEqualTo(o->_memberName))
118 return _elementType.isEqualTo(o->_elementType);
121 void PointerToMemberType::accept0(TypeVisitor *visitor)
122 { visitor->visit(this); }
124 bool PointerToMemberType::matchType0(const Type *otherType, TypeMatcher *matcher) const
126 if (const PointerToMemberType *otherTy = otherType->asPointerToMemberType())
127 return matcher->match(this, otherTy);
132 PointerType::PointerType(const FullySpecifiedType &elementType)
133 : _elementType(elementType)
136 PointerType::~PointerType()
139 bool PointerType::isEqualTo(const Type *other) const
141 const PointerType *o = other->asPointerType();
144 return _elementType.isEqualTo(o->_elementType);
147 void PointerType::accept0(TypeVisitor *visitor)
148 { visitor->visit(this); }
150 bool PointerType::matchType0(const Type *otherType, TypeMatcher *matcher) const
152 if (const PointerType *otherTy = otherType->asPointerType())
153 return matcher->match(this, otherTy);
158 FullySpecifiedType PointerType::elementType() const
159 { return _elementType; }
161 ReferenceType::ReferenceType(const FullySpecifiedType &elementType, bool rvalueRef)
162 : _elementType(elementType), _rvalueReference(rvalueRef)
165 ReferenceType::~ReferenceType()
168 bool ReferenceType::isEqualTo(const Type *other) const
170 const ReferenceType *o = other->asReferenceType();
173 else if (isRvalueReference() != o->isRvalueReference())
175 return _elementType.isEqualTo(o->_elementType);
178 void ReferenceType::accept0(TypeVisitor *visitor)
179 { visitor->visit(this); }
181 bool ReferenceType::matchType0(const Type *otherType, TypeMatcher *matcher) const
183 if (const ReferenceType *otherTy = otherType->asReferenceType())
184 return matcher->match(this, otherTy);
189 FullySpecifiedType ReferenceType::elementType() const
190 { return _elementType; }
192 bool ReferenceType::isRvalueReference() const
193 { return _rvalueReference; }
195 IntegerType::IntegerType(int kind)
199 IntegerType::~IntegerType()
202 bool IntegerType::isEqualTo(const Type *other) const
204 const IntegerType *o = other->asIntegerType();
207 return _kind == o->_kind;
210 void IntegerType::accept0(TypeVisitor *visitor)
211 { visitor->visit(this); }
213 bool IntegerType::matchType0(const Type *otherType, TypeMatcher *matcher) const
215 if (const IntegerType *otherTy = otherType->asIntegerType())
216 return matcher->match(this, otherTy);
221 int IntegerType::kind() const
224 FloatType::FloatType(int kind)
228 FloatType::~FloatType()
231 void FloatType::accept0(TypeVisitor *visitor)
232 { visitor->visit(this); }
234 bool FloatType::matchType0(const Type *otherType, TypeMatcher *matcher) const
236 if (const FloatType *otherTy = otherType->asFloatType())
237 return matcher->match(this, otherTy);
242 int FloatType::kind() const
245 bool FloatType::isEqualTo(const Type *other) const
247 const FloatType *o = other->asFloatType();
250 return _kind == o->_kind;
253 ArrayType::ArrayType(const FullySpecifiedType &elementType, unsigned size)
254 : _elementType(elementType), _size(size)
257 ArrayType::~ArrayType()
260 bool ArrayType::isEqualTo(const Type *other) const
262 const ArrayType *o = other->asArrayType();
265 else if (_size != o->_size)
267 return _elementType.isEqualTo(o->_elementType);
270 void ArrayType::accept0(TypeVisitor *visitor)
271 { visitor->visit(this); }
273 bool ArrayType::matchType0(const Type *otherType, TypeMatcher *matcher) const
275 if (const ArrayType *otherTy = otherType->asArrayType())
276 return matcher->match(this, otherTy);
281 FullySpecifiedType ArrayType::elementType() const
282 { return _elementType; }
284 unsigned ArrayType::size() const
287 NamedType::NamedType(const Name *name)
291 NamedType::~NamedType()
294 const Name *NamedType::name() const
297 bool NamedType::isEqualTo(const Type *other) const
299 const NamedType *o = other->asNamedType();
303 const Name *name = _name;
304 if (const QualifiedNameId *q = name->asQualifiedNameId())
307 const Name *otherName = o->name();
308 if (const QualifiedNameId *q = otherName->asQualifiedNameId())
309 otherName = q->name();
311 return name->isEqualTo(otherName);
314 void NamedType::accept0(TypeVisitor *visitor)
315 { visitor->visit(this); }
317 bool NamedType::matchType0(const Type *otherType, TypeMatcher *matcher) const
319 if (const NamedType *otherTy = otherType->asNamedType())
320 return matcher->match(this, otherTy);