|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
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 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com> |
|
42 // |
|
43 // Permission is hereby granted, free of charge, to any person obtaining a copy |
|
44 // of this software and associated documentation files (the "Software"), to deal |
|
45 // in the Software without restriction, including without limitation the rights |
|
46 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
47 // copies of the Software, and to permit persons to whom the Software is |
|
48 // furnished to do so, subject to the following conditions: |
|
49 // |
|
50 // The above copyright notice and this permission notice shall be included in |
|
51 // all copies or substantial portions of the Software. |
|
52 // |
|
53 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
54 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
55 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
56 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
57 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
58 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
59 // THE SOFTWARE. |
|
60 |
|
61 #include "Symbols.h" |
|
62 #include "Names.h" |
|
63 #include "TypeVisitor.h" |
|
64 #include "SymbolVisitor.h" |
|
65 #include "TypeMatcher.h" |
|
66 #include "Scope.h" |
|
67 |
|
68 using namespace CPlusPlus; |
|
69 |
|
70 TemplateParameters::TemplateParameters(Scope *scope) |
|
71 : _previous(0), _scope(scope) |
|
72 { } |
|
73 |
|
74 TemplateParameters::TemplateParameters(TemplateParameters *previous, Scope *scope) |
|
75 : _previous(previous), _scope(scope) |
|
76 { } |
|
77 |
|
78 TemplateParameters::~TemplateParameters() |
|
79 { |
|
80 delete _previous; |
|
81 delete _scope; |
|
82 } |
|
83 |
|
84 TemplateParameters *TemplateParameters::previous() const |
|
85 { return _previous; } |
|
86 |
|
87 Scope *TemplateParameters::scope() const |
|
88 { return _scope; } |
|
89 |
|
90 UsingNamespaceDirective::UsingNamespaceDirective(TranslationUnit *translationUnit, |
|
91 unsigned sourceLocation, const Name *name) |
|
92 : Symbol(translationUnit, sourceLocation, name) |
|
93 { } |
|
94 |
|
95 UsingNamespaceDirective::~UsingNamespaceDirective() |
|
96 { } |
|
97 |
|
98 FullySpecifiedType UsingNamespaceDirective::type() const |
|
99 { return FullySpecifiedType(); } |
|
100 |
|
101 void UsingNamespaceDirective::visitSymbol0(SymbolVisitor *visitor) |
|
102 { visitor->visit(this); } |
|
103 |
|
104 UsingDeclaration::UsingDeclaration(TranslationUnit *translationUnit, |
|
105 unsigned sourceLocation, const Name *name) |
|
106 : Symbol(translationUnit, sourceLocation, name) |
|
107 { } |
|
108 |
|
109 UsingDeclaration::~UsingDeclaration() |
|
110 { } |
|
111 |
|
112 FullySpecifiedType UsingDeclaration::type() const |
|
113 { return FullySpecifiedType(); } |
|
114 |
|
115 void UsingDeclaration::visitSymbol0(SymbolVisitor *visitor) |
|
116 { visitor->visit(this); } |
|
117 |
|
118 Declaration::Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
119 : Symbol(translationUnit, sourceLocation, name), |
|
120 _templateParameters(0) |
|
121 { } |
|
122 |
|
123 Declaration::~Declaration() |
|
124 { delete _templateParameters; } |
|
125 |
|
126 TemplateParameters *Declaration::templateParameters() const |
|
127 { return _templateParameters; } |
|
128 |
|
129 void Declaration::setTemplateParameters(TemplateParameters *templateParameters) |
|
130 { _templateParameters = templateParameters; } |
|
131 |
|
132 void Declaration::setType(const FullySpecifiedType &type) |
|
133 { _type = type; } |
|
134 |
|
135 FullySpecifiedType Declaration::type() const |
|
136 { return _type; } |
|
137 |
|
138 void Declaration::visitSymbol0(SymbolVisitor *visitor) |
|
139 { visitor->visit(this); } |
|
140 |
|
141 Argument::Argument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
142 : Symbol(translationUnit, sourceLocation, name), |
|
143 _initializer(0) |
|
144 { } |
|
145 |
|
146 Argument::~Argument() |
|
147 { } |
|
148 |
|
149 bool Argument::hasInitializer() const |
|
150 { return _initializer != 0; } |
|
151 |
|
152 const StringLiteral *Argument::initializer() const |
|
153 { return _initializer; } |
|
154 |
|
155 void Argument::setInitializer(const StringLiteral *initializer) |
|
156 { _initializer = initializer; } |
|
157 |
|
158 void Argument::setType(const FullySpecifiedType &type) |
|
159 { _type = type; } |
|
160 |
|
161 FullySpecifiedType Argument::type() const |
|
162 { return _type; } |
|
163 |
|
164 void Argument::visitSymbol0(SymbolVisitor *visitor) |
|
165 { visitor->visit(this); } |
|
166 |
|
167 TypenameArgument::TypenameArgument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
168 : Symbol(translationUnit, sourceLocation, name) |
|
169 { } |
|
170 |
|
171 TypenameArgument::~TypenameArgument() |
|
172 { } |
|
173 |
|
174 void TypenameArgument::setType(const FullySpecifiedType &type) |
|
175 { _type = type; } |
|
176 |
|
177 FullySpecifiedType TypenameArgument::type() const |
|
178 { return _type; } |
|
179 |
|
180 void TypenameArgument::visitSymbol0(SymbolVisitor *visitor) |
|
181 { visitor->visit(this); } |
|
182 |
|
183 Function::Function(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
184 : ScopedSymbol(translationUnit, sourceLocation, name), |
|
185 _templateParameters(0), |
|
186 _flags(0) |
|
187 { _arguments = new Scope(this); } |
|
188 |
|
189 Function::~Function() |
|
190 { |
|
191 delete _templateParameters; |
|
192 delete _arguments; |
|
193 } |
|
194 |
|
195 bool Function::isNormal() const |
|
196 { return f._methodKey == NormalMethod; } |
|
197 |
|
198 bool Function::isSignal() const |
|
199 { return f._methodKey == SignalMethod; } |
|
200 |
|
201 bool Function::isSlot() const |
|
202 { return f._methodKey == SlotMethod; } |
|
203 |
|
204 int Function::methodKey() const |
|
205 { return f._methodKey; } |
|
206 |
|
207 void Function::setMethodKey(int key) |
|
208 { f._methodKey = key; } |
|
209 |
|
210 unsigned Function::templateParameterCount() const |
|
211 { |
|
212 if (! _templateParameters) |
|
213 return 0; |
|
214 |
|
215 return _templateParameters->scope()->symbolCount(); |
|
216 } |
|
217 |
|
218 Symbol *Function::templateParameterAt(unsigned index) const |
|
219 { return _templateParameters->scope()->symbolAt(index); } |
|
220 |
|
221 TemplateParameters *Function::templateParameters() const |
|
222 { return _templateParameters; } |
|
223 |
|
224 void Function::setTemplateParameters(TemplateParameters *templateParameters) |
|
225 { _templateParameters = templateParameters; } |
|
226 |
|
227 bool Function::isEqualTo(const Type *other) const |
|
228 { |
|
229 const Function *o = other->asFunctionType(); |
|
230 if (! o) |
|
231 return false; |
|
232 else if (isConst() != o->isConst()) |
|
233 return false; |
|
234 else if (isVolatile() != o->isVolatile()) |
|
235 return false; |
|
236 #ifdef ICHECK_BUILD |
|
237 else if (isInvokable() != o->isInvokable()) |
|
238 return false; |
|
239 else if (isSignal() != o->isSignal()) |
|
240 return false; |
|
241 #endif |
|
242 |
|
243 const Name *l = identity(); |
|
244 const Name *r = o->identity(); |
|
245 if (l == r || (l && l->isEqualTo(r))) { |
|
246 if (_arguments->symbolCount() != o->_arguments->symbolCount()) |
|
247 return false; |
|
248 else if (! _returnType.isEqualTo(o->_returnType)) |
|
249 return false; |
|
250 for (unsigned i = 0; i < _arguments->symbolCount(); ++i) { |
|
251 Symbol *l = _arguments->symbolAt(i); |
|
252 Symbol *r = o->_arguments->symbolAt(i); |
|
253 if (! l->type().isEqualTo(r->type())) |
|
254 return false; |
|
255 } |
|
256 return true; |
|
257 } |
|
258 return false; |
|
259 } |
|
260 |
|
261 #ifdef ICHECK_BUILD |
|
262 bool Function::isEqualTo(const Function* fct, bool ignoreName/* = false*/) const |
|
263 { |
|
264 if(!ignoreName) |
|
265 return isEqualTo((Type*)fct); |
|
266 |
|
267 if (! fct) |
|
268 return false; |
|
269 else if (isConst() != fct->isConst()) |
|
270 return false; |
|
271 else if (isVolatile() != fct->isVolatile()) |
|
272 return false; |
|
273 else if (isInvokable() != fct->isInvokable()) |
|
274 return false; |
|
275 else if (isSignal() != fct->isSignal()) |
|
276 return false; |
|
277 |
|
278 if (_arguments->symbolCount() != fct->_arguments->symbolCount()) |
|
279 return false; |
|
280 else if (! _returnType.isEqualTo(fct->_returnType)) |
|
281 return false; |
|
282 for (unsigned i = 0; i < _arguments->symbolCount(); ++i) { |
|
283 Symbol *l = _arguments->symbolAt(i); |
|
284 Symbol *r = fct->_arguments->symbolAt(i); |
|
285 if (! l->type().isEqualTo(r->type())) |
|
286 return false; |
|
287 } |
|
288 return true; |
|
289 } |
|
290 #endif |
|
291 |
|
292 void Function::accept0(TypeVisitor *visitor) |
|
293 { visitor->visit(this); } |
|
294 |
|
295 bool Function::matchType0(const Type *otherType, TypeMatcher *matcher) const |
|
296 { |
|
297 if (const Function *otherTy = otherType->asFunctionType()) |
|
298 return matcher->match(this, otherTy); |
|
299 |
|
300 return false; |
|
301 } |
|
302 |
|
303 FullySpecifiedType Function::type() const |
|
304 { return FullySpecifiedType(const_cast<Function *>(this)); } |
|
305 |
|
306 FullySpecifiedType Function::returnType() const |
|
307 { return _returnType; } |
|
308 |
|
309 void Function::setReturnType(const FullySpecifiedType &returnType) |
|
310 { _returnType = returnType; } |
|
311 |
|
312 bool Function::hasReturnType() const |
|
313 { |
|
314 const FullySpecifiedType ty = returnType(); |
|
315 return ty.isValid() || ty.isSigned() || ty.isUnsigned(); |
|
316 } |
|
317 |
|
318 unsigned Function::argumentCount() const |
|
319 { |
|
320 if (! _arguments) |
|
321 return 0; |
|
322 |
|
323 return _arguments->symbolCount(); |
|
324 } |
|
325 |
|
326 Symbol *Function::argumentAt(unsigned index) const |
|
327 { return _arguments->symbolAt(index); } |
|
328 |
|
329 Scope *Function::arguments() const |
|
330 { return _arguments; } |
|
331 |
|
332 bool Function::hasArguments() const |
|
333 { |
|
334 return ! (argumentCount() == 0 || |
|
335 (argumentCount() == 1 && argumentAt(0)->type()->isVoidType())); |
|
336 } |
|
337 |
|
338 bool Function::isVirtual() const |
|
339 { return f._isVirtual; } |
|
340 |
|
341 void Function::setVirtual(bool isVirtual) |
|
342 { f._isVirtual = isVirtual; } |
|
343 |
|
344 bool Function::isVariadic() const |
|
345 { return f._isVariadic; } |
|
346 |
|
347 void Function::setVariadic(bool isVariadic) |
|
348 { f._isVariadic = isVariadic; } |
|
349 |
|
350 bool Function::isConst() const |
|
351 { return f._isConst; } |
|
352 |
|
353 void Function::setConst(bool isConst) |
|
354 { f._isConst = isConst; } |
|
355 |
|
356 bool Function::isVolatile() const |
|
357 { return f._isVolatile; } |
|
358 |
|
359 void Function::setVolatile(bool isVolatile) |
|
360 { f._isVolatile = isVolatile; } |
|
361 |
|
362 bool Function::isPureVirtual() const |
|
363 { return f._isPureVirtual; } |
|
364 |
|
365 void Function::setPureVirtual(bool isPureVirtual) |
|
366 { f._isPureVirtual = isPureVirtual; } |
|
367 |
|
368 #ifdef ICHECK_BUILD |
|
369 |
|
370 bool Function::isInvokable() const |
|
371 { return f._isInvokable == 1; } |
|
372 |
|
373 void Function::setInvokable(bool isInvokable) |
|
374 { f._isInvokable = isInvokable; } |
|
375 |
|
376 #endif |
|
377 |
|
378 bool Function::isAmbiguous() const |
|
379 { return f._isAmbiguous; } |
|
380 |
|
381 void Function::setAmbiguous(bool isAmbiguous) |
|
382 { f._isAmbiguous = isAmbiguous; } |
|
383 |
|
384 void Function::visitSymbol0(SymbolVisitor *visitor) |
|
385 { |
|
386 if (visitor->visit(this)) { |
|
387 for (unsigned i = 0; i < _arguments->symbolCount(); ++i) { |
|
388 visitSymbol(_arguments->symbolAt(i), visitor); |
|
389 } |
|
390 for (unsigned i = 0; i < memberCount(); ++i) { |
|
391 visitSymbol(memberAt(i), visitor); |
|
392 } |
|
393 } |
|
394 } |
|
395 |
|
396 ScopedSymbol::ScopedSymbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
397 : Symbol(translationUnit, sourceLocation, name) |
|
398 { _members = new Scope(this); } |
|
399 |
|
400 ScopedSymbol::~ScopedSymbol() |
|
401 { delete _members; } |
|
402 |
|
403 unsigned ScopedSymbol::memberCount() const |
|
404 { |
|
405 if (! _members) |
|
406 return 0; |
|
407 return _members->symbolCount(); |
|
408 } |
|
409 |
|
410 Symbol *ScopedSymbol::memberAt(unsigned index) const |
|
411 { |
|
412 if (! _members) |
|
413 return 0; |
|
414 return _members->symbolAt(index); |
|
415 } |
|
416 |
|
417 Scope *ScopedSymbol::members() const |
|
418 { return _members; } |
|
419 |
|
420 void ScopedSymbol::addMember(Symbol *member) |
|
421 { _members->enterSymbol(member); } |
|
422 |
|
423 Block::Block(TranslationUnit *translationUnit, unsigned sourceLocation) |
|
424 : ScopedSymbol(translationUnit, sourceLocation, /*name = */ 0) |
|
425 { } |
|
426 |
|
427 Block::~Block() |
|
428 { } |
|
429 |
|
430 FullySpecifiedType Block::type() const |
|
431 { return FullySpecifiedType(); } |
|
432 |
|
433 void Block::visitSymbol0(SymbolVisitor *visitor) |
|
434 { |
|
435 if (visitor->visit(this)) { |
|
436 for (unsigned i = 0; i < memberCount(); ++i) { |
|
437 visitSymbol(memberAt(i), visitor); |
|
438 } |
|
439 } |
|
440 } |
|
441 |
|
442 Enum::Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
443 : ScopedSymbol(translationUnit, sourceLocation, name) |
|
444 { } |
|
445 |
|
446 Enum::~Enum() |
|
447 { } |
|
448 |
|
449 FullySpecifiedType Enum::type() const |
|
450 { return FullySpecifiedType(const_cast<Enum *>(this)); } |
|
451 |
|
452 bool Enum::isEqualTo(const Type *other) const |
|
453 { |
|
454 const Enum *o = other->asEnumType(); |
|
455 if (! o) |
|
456 return false; |
|
457 const Name *l = identity(); |
|
458 const Name *r = o->identity(); |
|
459 if (l == r) |
|
460 return true; |
|
461 else if (! l) |
|
462 return false; |
|
463 return l->isEqualTo(r); |
|
464 } |
|
465 |
|
466 void Enum::accept0(TypeVisitor *visitor) |
|
467 { visitor->visit(this); } |
|
468 |
|
469 bool Enum::matchType0(const Type *otherType, TypeMatcher *matcher) const |
|
470 { |
|
471 if (const Enum *otherTy = otherType->asEnumType()) |
|
472 return matcher->match(this, otherTy); |
|
473 |
|
474 return false; |
|
475 } |
|
476 |
|
477 void Enum::visitSymbol0(SymbolVisitor *visitor) |
|
478 { |
|
479 if (visitor->visit(this)) { |
|
480 for (unsigned i = 0; i < memberCount(); ++i) { |
|
481 visitSymbol(memberAt(i), visitor); |
|
482 } |
|
483 } |
|
484 } |
|
485 |
|
486 Namespace::Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
487 : ScopedSymbol(translationUnit, sourceLocation, name) |
|
488 { } |
|
489 |
|
490 Namespace::~Namespace() |
|
491 { } |
|
492 |
|
493 bool Namespace::isEqualTo(const Type *other) const |
|
494 { |
|
495 const Namespace *o = other->asNamespaceType(); |
|
496 if (! o) |
|
497 return false; |
|
498 const Name *l = identity(); |
|
499 const Name *r = o->identity(); |
|
500 if (l == r || (l && l->isEqualTo(r))) |
|
501 return true; |
|
502 return false; |
|
503 } |
|
504 |
|
505 void Namespace::accept0(TypeVisitor *visitor) |
|
506 { visitor->visit(this); } |
|
507 |
|
508 bool Namespace::matchType0(const Type *otherType, TypeMatcher *matcher) const |
|
509 { |
|
510 if (const Namespace *otherTy = otherType->asNamespaceType()) |
|
511 return matcher->match(this, otherTy); |
|
512 |
|
513 return false; |
|
514 } |
|
515 |
|
516 void Namespace::visitSymbol0(SymbolVisitor *visitor) |
|
517 { |
|
518 if (visitor->visit(this)) { |
|
519 for (unsigned i = 0; i < memberCount(); ++i) { |
|
520 visitSymbol(memberAt(i), visitor); |
|
521 } |
|
522 } |
|
523 } |
|
524 |
|
525 FullySpecifiedType Namespace::type() const |
|
526 { return FullySpecifiedType(const_cast<Namespace *>(this)); } |
|
527 |
|
528 BaseClass::BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
529 : Symbol(translationUnit, sourceLocation, name), |
|
530 _isVirtual(false) |
|
531 { } |
|
532 |
|
533 BaseClass::~BaseClass() |
|
534 { } |
|
535 |
|
536 FullySpecifiedType BaseClass::type() const |
|
537 { return _type; } |
|
538 |
|
539 void BaseClass::setType(const FullySpecifiedType &type) |
|
540 { _type = type; } |
|
541 |
|
542 bool BaseClass::isVirtual() const |
|
543 { return _isVirtual; } |
|
544 |
|
545 void BaseClass::setVirtual(bool isVirtual) |
|
546 { _isVirtual = isVirtual; } |
|
547 |
|
548 void BaseClass::visitSymbol0(SymbolVisitor *visitor) |
|
549 { visitor->visit(this); } |
|
550 |
|
551 ForwardClassDeclaration::ForwardClassDeclaration(TranslationUnit *translationUnit, |
|
552 unsigned sourceLocation, const Name *name) |
|
553 : Symbol(translationUnit, sourceLocation, name), |
|
554 _templateParameters(0) |
|
555 { } |
|
556 |
|
557 ForwardClassDeclaration::~ForwardClassDeclaration() |
|
558 { delete _templateParameters; } |
|
559 |
|
560 TemplateParameters *ForwardClassDeclaration::templateParameters() const |
|
561 { return _templateParameters; } |
|
562 |
|
563 void ForwardClassDeclaration::setTemplateParameters(TemplateParameters *templateParameters) |
|
564 { _templateParameters = templateParameters; } |
|
565 |
|
566 FullySpecifiedType ForwardClassDeclaration::type() const |
|
567 { return FullySpecifiedType(const_cast<ForwardClassDeclaration *>(this)); } |
|
568 |
|
569 bool ForwardClassDeclaration::isEqualTo(const Type *other) const |
|
570 { |
|
571 if (const ForwardClassDeclaration *otherClassFwdTy = other->asForwardClassDeclarationType()) { |
|
572 if (name() == otherClassFwdTy->name()) |
|
573 return true; |
|
574 else if (name() && otherClassFwdTy->name()) |
|
575 return name()->isEqualTo(otherClassFwdTy->name()); |
|
576 |
|
577 return false; |
|
578 } |
|
579 return false; |
|
580 } |
|
581 |
|
582 void ForwardClassDeclaration::visitSymbol0(SymbolVisitor *visitor) |
|
583 { visitor->visit(this); } |
|
584 |
|
585 void ForwardClassDeclaration::accept0(TypeVisitor *visitor) |
|
586 { visitor->visit(this); } |
|
587 |
|
588 bool ForwardClassDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const |
|
589 { |
|
590 if (const ForwardClassDeclaration *otherTy = otherType->asForwardClassDeclarationType()) |
|
591 return matcher->match(this, otherTy); |
|
592 |
|
593 return false; |
|
594 } |
|
595 |
|
596 Class::Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
597 : ScopedSymbol(translationUnit, sourceLocation, name), |
|
598 _key(ClassKey), |
|
599 _templateParameters(0) |
|
600 { } |
|
601 |
|
602 Class::~Class() |
|
603 { delete _templateParameters; } |
|
604 |
|
605 bool Class::isClass() const |
|
606 { return _key == ClassKey; } |
|
607 |
|
608 bool Class::isStruct() const |
|
609 { return _key == StructKey; } |
|
610 |
|
611 bool Class::isUnion() const |
|
612 { return _key == UnionKey; } |
|
613 |
|
614 Class::Key Class::classKey() const |
|
615 { return _key; } |
|
616 |
|
617 void Class::setClassKey(Key key) |
|
618 { _key = key; } |
|
619 |
|
620 unsigned Class::templateParameterCount() const |
|
621 { |
|
622 if (! _templateParameters) |
|
623 return 0; |
|
624 |
|
625 return _templateParameters->scope()->symbolCount(); |
|
626 } |
|
627 |
|
628 Symbol *Class::templateParameterAt(unsigned index) const |
|
629 { return _templateParameters->scope()->symbolAt(index); } |
|
630 |
|
631 TemplateParameters *Class::templateParameters() const |
|
632 { return _templateParameters; } |
|
633 |
|
634 void Class::setTemplateParameters(TemplateParameters *templateParameters) |
|
635 { _templateParameters = templateParameters; } |
|
636 |
|
637 void Class::accept0(TypeVisitor *visitor) |
|
638 { visitor->visit(this); } |
|
639 |
|
640 bool Class::matchType0(const Type *otherType, TypeMatcher *matcher) const |
|
641 { |
|
642 if (const Class *otherTy = otherType->asClassType()) |
|
643 return matcher->match(this, otherTy); |
|
644 |
|
645 return false; |
|
646 } |
|
647 |
|
648 unsigned Class::baseClassCount() const |
|
649 { return _baseClasses.count(); } |
|
650 |
|
651 BaseClass *Class::baseClassAt(unsigned index) const |
|
652 { return _baseClasses.at(index); } |
|
653 |
|
654 void Class::addBaseClass(BaseClass *baseClass) |
|
655 { _baseClasses.push_back(baseClass); } |
|
656 |
|
657 FullySpecifiedType Class::type() const |
|
658 { return FullySpecifiedType(const_cast<Class *>(this)); } |
|
659 |
|
660 bool Class::isEqualTo(const Type *other) const |
|
661 { |
|
662 const Class *o = other->asClassType(); |
|
663 if (! o) |
|
664 return false; |
|
665 const Name *l = identity(); |
|
666 const Name *r = o->identity(); |
|
667 if (l == r || (l && l->isEqualTo(r))) |
|
668 return true; |
|
669 else |
|
670 return false; |
|
671 } |
|
672 |
|
673 void Class::visitSymbol0(SymbolVisitor *visitor) |
|
674 { |
|
675 if (visitor->visit(this)) { |
|
676 for (unsigned i = 0; i < _baseClasses.size(); ++i) { |
|
677 visitSymbol(_baseClasses.at(i), visitor); |
|
678 } |
|
679 for (unsigned i = 0; i < memberCount(); ++i) { |
|
680 visitSymbol(memberAt(i), visitor); |
|
681 } |
|
682 } |
|
683 } |
|
684 |
|
685 ObjCBaseClass::ObjCBaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
686 : Symbol(translationUnit, sourceLocation, name) |
|
687 { } |
|
688 |
|
689 ObjCBaseClass::~ObjCBaseClass() |
|
690 { } |
|
691 |
|
692 FullySpecifiedType ObjCBaseClass::type() const |
|
693 { return FullySpecifiedType(); } |
|
694 |
|
695 void ObjCBaseClass::visitSymbol0(SymbolVisitor *visitor) |
|
696 { visitor->visit(this); } |
|
697 |
|
698 ObjCBaseProtocol::ObjCBaseProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
699 : Symbol(translationUnit, sourceLocation, name) |
|
700 { } |
|
701 |
|
702 ObjCBaseProtocol::~ObjCBaseProtocol() |
|
703 { } |
|
704 |
|
705 FullySpecifiedType ObjCBaseProtocol::type() const |
|
706 { return FullySpecifiedType(); } |
|
707 |
|
708 void ObjCBaseProtocol::visitSymbol0(SymbolVisitor *visitor) |
|
709 { visitor->visit(this); } |
|
710 |
|
711 ObjCClass::ObjCClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name): |
|
712 ScopedSymbol(translationUnit, sourceLocation, name), |
|
713 _isInterface(false), |
|
714 _categoryName(0), |
|
715 _baseClass(0) |
|
716 { |
|
717 } |
|
718 |
|
719 ObjCClass::~ObjCClass() |
|
720 {} |
|
721 |
|
722 FullySpecifiedType ObjCClass::type() const |
|
723 { return FullySpecifiedType(const_cast<ObjCClass *>(this)); } |
|
724 |
|
725 bool ObjCClass::isEqualTo(const Type *other) const |
|
726 { |
|
727 const ObjCClass *o = other->asObjCClassType(); |
|
728 if (!o) |
|
729 return false; |
|
730 |
|
731 const Name *l = identity(); |
|
732 const Name *r = o->identity(); |
|
733 if (l == r || (l && l->isEqualTo(r))) |
|
734 return true; |
|
735 else |
|
736 return false; |
|
737 } |
|
738 |
|
739 void ObjCClass::visitSymbol0(SymbolVisitor *visitor) |
|
740 { |
|
741 if (visitor->visit(this)) { |
|
742 if (_baseClass) |
|
743 visitSymbol(_baseClass, visitor); |
|
744 |
|
745 for (unsigned i = 0; i < _protocols.size(); ++i) |
|
746 visitSymbol(_protocols.at(i), visitor); |
|
747 |
|
748 for (unsigned i = 0; i < memberCount(); ++i) |
|
749 visitSymbol(memberAt(i), visitor); |
|
750 } |
|
751 } |
|
752 |
|
753 void ObjCClass::accept0(TypeVisitor *visitor) |
|
754 { visitor->visit(this); } |
|
755 |
|
756 bool ObjCClass::matchType0(const Type *otherType, TypeMatcher *matcher) const |
|
757 { |
|
758 if (const ObjCClass *otherTy = otherType->asObjCClassType()) |
|
759 return matcher->match(this, otherTy); |
|
760 |
|
761 return false; |
|
762 } |
|
763 |
|
764 ObjCProtocol::ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name): |
|
765 ScopedSymbol(translationUnit, sourceLocation, name) |
|
766 { |
|
767 } |
|
768 |
|
769 ObjCProtocol::~ObjCProtocol() |
|
770 {} |
|
771 |
|
772 FullySpecifiedType ObjCProtocol::type() const |
|
773 { return FullySpecifiedType(const_cast<ObjCProtocol *>(this)); } |
|
774 |
|
775 bool ObjCProtocol::isEqualTo(const Type *other) const |
|
776 { |
|
777 const ObjCProtocol *o = other->asObjCProtocolType(); |
|
778 if (!o) |
|
779 return false; |
|
780 |
|
781 const Name *l = identity(); |
|
782 const Name *r = o->identity(); |
|
783 if (l == r || (l && l->isEqualTo(r))) |
|
784 return true; |
|
785 else |
|
786 return false; |
|
787 } |
|
788 |
|
789 void ObjCProtocol::visitSymbol0(SymbolVisitor *visitor) |
|
790 { |
|
791 if (visitor->visit(this)) { |
|
792 for (unsigned i = 0; i < _protocols.size(); ++i) |
|
793 visitSymbol(_protocols.at(i), visitor); |
|
794 } |
|
795 } |
|
796 |
|
797 void ObjCProtocol::accept0(TypeVisitor *visitor) |
|
798 { visitor->visit(this); } |
|
799 |
|
800 bool ObjCProtocol::matchType0(const Type *otherType, TypeMatcher *matcher) const |
|
801 { |
|
802 if (const ObjCProtocol *otherTy = otherType->asObjCProtocolType()) |
|
803 return matcher->match(this, otherTy); |
|
804 |
|
805 return false; |
|
806 } |
|
807 |
|
808 ObjCForwardClassDeclaration::ObjCForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, |
|
809 const Name *name): |
|
810 Symbol(translationUnit, sourceLocation, name) |
|
811 { |
|
812 } |
|
813 |
|
814 ObjCForwardClassDeclaration::~ObjCForwardClassDeclaration() |
|
815 {} |
|
816 |
|
817 FullySpecifiedType ObjCForwardClassDeclaration::type() const |
|
818 { return FullySpecifiedType(); } |
|
819 |
|
820 bool ObjCForwardClassDeclaration::isEqualTo(const Type *other) const |
|
821 { |
|
822 if (const ObjCForwardClassDeclaration *otherFwdClass = other->asObjCForwardClassDeclarationType()) { |
|
823 if (name() == otherFwdClass->name()) |
|
824 return true; |
|
825 else if (name() && otherFwdClass->name()) |
|
826 return name()->isEqualTo(otherFwdClass->name()); |
|
827 else |
|
828 return false; |
|
829 } |
|
830 |
|
831 return false; |
|
832 } |
|
833 |
|
834 void ObjCForwardClassDeclaration::visitSymbol0(SymbolVisitor *visitor) |
|
835 { visitor->visit(this); } |
|
836 |
|
837 void ObjCForwardClassDeclaration::accept0(TypeVisitor *visitor) |
|
838 { visitor->visit(this); } |
|
839 |
|
840 bool ObjCForwardClassDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const |
|
841 { |
|
842 if (const ObjCForwardClassDeclaration *otherTy = otherType->asObjCForwardClassDeclarationType()) |
|
843 return matcher->match(this, otherTy); |
|
844 |
|
845 return false; |
|
846 } |
|
847 |
|
848 ObjCForwardProtocolDeclaration::ObjCForwardProtocolDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, |
|
849 const Name *name): |
|
850 Symbol(translationUnit, sourceLocation, name) |
|
851 { |
|
852 } |
|
853 |
|
854 ObjCForwardProtocolDeclaration::~ObjCForwardProtocolDeclaration() |
|
855 {} |
|
856 |
|
857 FullySpecifiedType ObjCForwardProtocolDeclaration::type() const |
|
858 { return FullySpecifiedType(); } |
|
859 |
|
860 bool ObjCForwardProtocolDeclaration::isEqualTo(const Type *other) const |
|
861 { |
|
862 if (const ObjCForwardProtocolDeclaration *otherFwdProtocol = other->asObjCForwardProtocolDeclarationType()) { |
|
863 if (name() == otherFwdProtocol->name()) |
|
864 return true; |
|
865 else if (name() && otherFwdProtocol->name()) |
|
866 return name()->isEqualTo(otherFwdProtocol->name()); |
|
867 else |
|
868 return false; |
|
869 } |
|
870 |
|
871 return false; |
|
872 } |
|
873 |
|
874 void ObjCForwardProtocolDeclaration::visitSymbol0(SymbolVisitor *visitor) |
|
875 { visitor->visit(this); } |
|
876 |
|
877 void ObjCForwardProtocolDeclaration::accept0(TypeVisitor *visitor) |
|
878 { visitor->visit(this); } |
|
879 |
|
880 bool ObjCForwardProtocolDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const |
|
881 { |
|
882 if (const ObjCForwardProtocolDeclaration *otherTy = otherType->asObjCForwardProtocolDeclarationType()) |
|
883 return matcher->match(this, otherTy); |
|
884 |
|
885 return false; |
|
886 } |
|
887 |
|
888 ObjCMethod::ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) |
|
889 : ScopedSymbol(translationUnit, sourceLocation, name), |
|
890 _flags(0) |
|
891 { _arguments = new Scope(this); } |
|
892 |
|
893 ObjCMethod::~ObjCMethod() |
|
894 { |
|
895 delete _arguments; |
|
896 } |
|
897 |
|
898 bool ObjCMethod::isEqualTo(const Type *other) const |
|
899 { |
|
900 const ObjCMethod *o = other->asObjCMethodType(); |
|
901 if (! o) |
|
902 return false; |
|
903 |
|
904 const Name *l = identity(); |
|
905 const Name *r = o->identity(); |
|
906 if (l == r || (l && l->isEqualTo(r))) { |
|
907 if (_arguments->symbolCount() != o->_arguments->symbolCount()) |
|
908 return false; |
|
909 else if (! _returnType.isEqualTo(o->_returnType)) |
|
910 return false; |
|
911 for (unsigned i = 0; i < _arguments->symbolCount(); ++i) { |
|
912 Symbol *l = _arguments->symbolAt(i); |
|
913 Symbol *r = o->_arguments->symbolAt(i); |
|
914 if (! l->type().isEqualTo(r->type())) |
|
915 return false; |
|
916 } |
|
917 return true; |
|
918 } |
|
919 return false; |
|
920 } |
|
921 |
|
922 void ObjCMethod::accept0(TypeVisitor *visitor) |
|
923 { visitor->visit(this); } |
|
924 |
|
925 bool ObjCMethod::matchType0(const Type *otherType, TypeMatcher *matcher) const |
|
926 { |
|
927 if (const ObjCMethod *otherTy = otherType->asObjCMethodType()) |
|
928 return matcher->match(this, otherTy); |
|
929 |
|
930 return false; |
|
931 } |
|
932 |
|
933 FullySpecifiedType ObjCMethod::type() const |
|
934 { return FullySpecifiedType(const_cast<ObjCMethod *>(this)); } |
|
935 |
|
936 FullySpecifiedType ObjCMethod::returnType() const |
|
937 { return _returnType; } |
|
938 |
|
939 void ObjCMethod::setReturnType(const FullySpecifiedType &returnType) |
|
940 { _returnType = returnType; } |
|
941 |
|
942 bool ObjCMethod::hasReturnType() const |
|
943 { |
|
944 const FullySpecifiedType ty = returnType(); |
|
945 return ty.isValid() || ty.isSigned() || ty.isUnsigned(); |
|
946 } |
|
947 |
|
948 unsigned ObjCMethod::argumentCount() const |
|
949 { |
|
950 if (! _arguments) |
|
951 return 0; |
|
952 |
|
953 return _arguments->symbolCount(); |
|
954 } |
|
955 |
|
956 Symbol *ObjCMethod::argumentAt(unsigned index) const |
|
957 { return _arguments->symbolAt(index); } |
|
958 |
|
959 Scope *ObjCMethod::arguments() const |
|
960 { return _arguments; } |
|
961 |
|
962 bool ObjCMethod::hasArguments() const |
|
963 { |
|
964 return ! (argumentCount() == 0 || |
|
965 (argumentCount() == 1 && argumentAt(0)->type()->isVoidType())); |
|
966 } |
|
967 |
|
968 bool ObjCMethod::isVariadic() const |
|
969 { return f._isVariadic; } |
|
970 |
|
971 void ObjCMethod::setVariadic(bool isVariadic) |
|
972 { f._isVariadic = isVariadic; } |
|
973 |
|
974 void ObjCMethod::visitSymbol0(SymbolVisitor *visitor) |
|
975 { |
|
976 if (visitor->visit(this)) { |
|
977 for (unsigned i = 0; i < _arguments->symbolCount(); ++i) { |
|
978 visitSymbol(_arguments->symbolAt(i), visitor); |
|
979 } |
|
980 for (unsigned i = 0; i < memberCount(); ++i) { |
|
981 visitSymbol(memberAt(i), visitor); |
|
982 } |
|
983 } |
|
984 } |
|
985 |
|
986 ObjCPropertyDeclaration::ObjCPropertyDeclaration(TranslationUnit *translationUnit, |
|
987 unsigned sourceLocation, |
|
988 const Name *name): |
|
989 Symbol(translationUnit, sourceLocation, name), |
|
990 _propertyAttributes(None), |
|
991 _getterName(0), |
|
992 _setterName(0) |
|
993 {} |
|
994 |
|
995 ObjCPropertyDeclaration::~ObjCPropertyDeclaration() |
|
996 {} |
|
997 |
|
998 FullySpecifiedType ObjCPropertyDeclaration::type() const |
|
999 { return _type; } |
|
1000 |
|
1001 void ObjCPropertyDeclaration::visitSymbol0(SymbolVisitor *visitor) |
|
1002 { |
|
1003 if (visitor->visit(this)) { |
|
1004 } |
|
1005 } |