OSDN Git Service

d3e0a3fd893b9d8b3ef40479f36faaf16a5c2519
[qt-creator-jp/qt-creator-jp.git] / src / shared / cplusplus / TypeMatcher.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
34 #include "TypeMatcher.h"
35 #include "CoreTypes.h"
36 #include "Symbols.h"
37 #include "Names.h"
38 #include "Literals.h"
39
40 using namespace CPlusPlus;
41
42 TypeMatcher::TypeMatcher()
43 {
44 }
45
46 TypeMatcher::~TypeMatcher()
47 {
48 }
49
50 bool TypeMatcher::isEqualTo(const Name *name, const Name *otherName) const
51 {
52     if (name == otherName)
53         return true;
54
55     else if (! name || ! otherName)
56         return false;
57
58     return name->isEqualTo(otherName);
59 }
60
61 bool TypeMatcher::match(const UndefinedType *, const UndefinedType *)
62 {
63     return true;
64 }
65
66 bool TypeMatcher::match(const VoidType *, const VoidType *)
67 {
68     return true;
69 }
70
71 bool TypeMatcher::match(const IntegerType *type, const IntegerType *otherType)
72 {
73     if (type == otherType)
74         return true;
75
76     else if (type->kind() != otherType->kind())
77         return false;
78
79     return true;
80 }
81
82 bool TypeMatcher::match(const FloatType *type, const FloatType *otherType)
83 {
84     if (type == otherType)
85         return true;
86
87     else if (type->kind() != otherType->kind())
88         return false;
89
90     return true;
91 }
92
93 bool TypeMatcher::match(const PointerToMemberType *type, const PointerToMemberType *otherType)
94 {
95     if (type == otherType)
96         return true;
97
98     else if (! isEqualTo(type->memberName(), otherType->memberName()))
99         return false;
100
101     else if (! type->elementType().match(otherType->elementType(), this))
102         return false;
103
104     return true;
105 }
106
107 bool TypeMatcher::match(const PointerType *type, const PointerType *otherType)
108 {
109     if (type == otherType)
110         return true;
111
112     else if (! type->elementType().match(otherType->elementType(), this))
113         return false;
114
115     return true;
116 }
117
118 bool TypeMatcher::match(const ReferenceType *type, const ReferenceType *otherType)
119 {
120     if (type == otherType)
121         return true;
122
123     else if (type->isRvalueReference() != otherType->isRvalueReference())
124         return false;
125
126     else if (! type->elementType().match(otherType->elementType(), this))
127         return false;
128
129     return true;
130 }
131
132 bool TypeMatcher::match(const ArrayType *type, const ArrayType *otherType)
133 {
134     if (type == otherType)
135         return true;
136
137     else if (type->size() != otherType->size())
138         return false;
139
140     else if (! type->elementType().match(otherType->elementType(), this))
141         return false;
142
143     return true;
144 }
145
146 bool TypeMatcher::match(const NamedType *type, const NamedType *otherType)
147 {
148     if (type == otherType)
149         return true;
150
151     else if (! isEqualTo(type->name(), otherType->name()))
152         return false;
153
154     return true;
155 }
156
157 bool TypeMatcher::match(const Function *type, const Function *otherType)
158 {
159     if (type != otherType)
160         return false;
161
162     return true;
163 }
164
165 bool TypeMatcher::match(const Enum *type, const Enum *otherType)
166 {
167     if (type != otherType)
168         return false;
169
170     return true;
171 }
172
173 bool TypeMatcher::match(const Namespace *type, const Namespace *otherType)
174 {
175     if (type != otherType)
176         return false;
177
178     return true;
179 }
180
181 bool TypeMatcher::match(const Template *type, const Template *otherType)
182 {
183     if (type != otherType)
184         return false;
185
186     return true;
187 }
188
189 bool TypeMatcher::match(const ForwardClassDeclaration *type, const ForwardClassDeclaration *otherType)
190 {
191     if (type != otherType)
192         return false;
193
194     return true;
195 }
196
197 bool TypeMatcher::match(const Class *type, const Class *otherType)
198 {
199     if (type != otherType)
200         return false;
201
202     return true;
203 }
204
205 bool TypeMatcher::match(const ObjCClass *type, const ObjCClass *otherType)
206 {
207     if (type != otherType)
208         return false;
209
210     return true;
211 }
212
213 bool TypeMatcher::match(const ObjCProtocol *type, const ObjCProtocol *otherType)
214 {
215     if (type != otherType)
216         return false;
217
218     return true;
219 }
220
221 bool TypeMatcher::match(const ObjCForwardClassDeclaration *type, const ObjCForwardClassDeclaration *otherType)
222 {
223     if (type != otherType)
224         return false;
225
226     return true;
227 }
228
229 bool TypeMatcher::match(const ObjCForwardProtocolDeclaration *type, const ObjCForwardProtocolDeclaration *otherType)
230 {
231     if (type != otherType)
232         return false;
233
234     return true;
235 }
236
237 bool TypeMatcher::match(const ObjCMethod *type, const ObjCMethod *otherType)
238 {
239     if (type != otherType)
240         return false;
241
242     return true;
243 }