 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
87.2% |
34 / 39 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
100.0% |
39 / 39 |
| |
|
Line Coverage: |
95.0% |
305 / 321 |
| |
 |
|
 |
1 : //===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file defines the C++ Decl subclasses.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #ifndef LLVM_CLANG_AST_DECLCXX_H
15 : #define LLVM_CLANG_AST_DECLCXX_H
16 :
17 : #include "clang/AST/Expr.h"
18 : #include "clang/AST/Decl.h"
19 : #include "clang/AST/UnresolvedSet.h"
20 : #include "llvm/ADT/SmallVector.h"
21 : #include "llvm/ADT/SmallPtrSet.h"
22 :
23 : namespace clang {
24 :
25 : class ClassTemplateDecl;
26 : class ClassTemplateSpecializationDecl;
27 : class CXXBasePath;
28 : class CXXBasePaths;
29 : class CXXConstructorDecl;
30 : class CXXConversionDecl;
31 : class CXXDestructorDecl;
32 : class CXXMethodDecl;
33 : class CXXRecordDecl;
34 : class CXXMemberLookupCriteria;
35 :
36 : /// \brief Represents any kind of function declaration, whether it is a
37 : /// concrete function or a function template.
38 : class AnyFunctionDecl {
39 : NamedDecl *Function;
40 :
41 : AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
42 :
43 : public:
44 : AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
45 : AnyFunctionDecl(FunctionTemplateDecl *FTD);
46 :
47 : /// \brief Implicily converts any function or function template into a
48 : /// named declaration.
49 : operator NamedDecl *() const { return Function; }
50 :
51 : /// \brief Retrieve the underlying function or function template.
52 : NamedDecl *get() const { return Function; }
53 :
54 : static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
55 : return AnyFunctionDecl(ND);
56 : }
57 : };
58 :
59 : } // end namespace clang
60 :
61 : namespace llvm {
62 : /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
63 : /// AnyFunctionDecl to any function or function template declaration.
64 : template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
65 : typedef ::clang::NamedDecl* SimpleType;
66 : static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
67 : return Val;
68 : }
69 : };
70 : template<> struct simplify_type< ::clang::AnyFunctionDecl>
71 : : public simplify_type<const ::clang::AnyFunctionDecl> {};
72 :
73 : // Provide PointerLikeTypeTraits for non-cvr pointers.
74 : template<>
75 : class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
76 : public:
77 : static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
78 : return F.get();
79 : }
80 : static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
81 : return ::clang::AnyFunctionDecl::getFromNamedDecl(
82 : static_cast< ::clang::NamedDecl*>(P));
83 : }
84 :
85 : enum { NumLowBitsAvailable = 2 };
86 : };
87 :
88 : } // end namespace llvm
89 :
90 : namespace clang {
91 :
92 : /// CXXBaseSpecifier - A base class of a C++ class.
93 : ///
94 : /// Each CXXBaseSpecifier represents a single, direct base class (or
95 : /// struct) of a C++ class (or struct). It specifies the type of that
96 : /// base class, whether it is a virtual or non-virtual base, and what
97 : /// level of access (public, protected, private) is used for the
98 : /// derivation. For example:
99 : ///
100 : /// @code
101 : /// class A { };
102 : /// class B { };
103 : /// class C : public virtual A, protected B { };
104 : /// @endcode
105 : ///
106 : /// In this code, C will have two CXXBaseSpecifiers, one for "public
107 : /// virtual A" and the other for "protected B".
108 : class CXXBaseSpecifier {
109 : /// Range - The source code range that covers the full base
110 : /// specifier, including the "virtual" (if present) and access
111 : /// specifier (if present).
112 : // FIXME: Move over to a TypeLoc!
113 : SourceRange Range;
114 :
115 : /// Virtual - Whether this is a virtual base class or not.
116 : bool Virtual : 1;
117 :
118 : /// BaseOfClass - Whether this is the base of a class (true) or of a
119 : /// struct (false). This determines the mapping from the access
120 : /// specifier as written in the source code to the access specifier
121 : /// used for semantic analysis.
122 : bool BaseOfClass : 1;
123 :
124 : /// Access - Access specifier as written in the source code (which
125 : /// may be AS_none). The actual type of data stored here is an
126 : /// AccessSpecifier, but we use "unsigned" here to work around a
127 : /// VC++ bug.
128 : unsigned Access : 2;
129 :
130 : /// BaseType - The type of the base class. This will be a class or
131 : /// struct (or a typedef of such).
132 : QualType BaseType;
133 :
134 : public:
135 1332: CXXBaseSpecifier() { }
136 :
137 1306: CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T)
138 1306: : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { }
139 :
140 : /// getSourceRange - Retrieves the source range that contains the
141 : /// entire base specifier.
142 252: SourceRange getSourceRange() const { return Range; }
143 :
144 : /// isVirtual - Determines whether the base class is a virtual base
145 : /// class (or not).
146 35279: bool isVirtual() const { return Virtual; }
147 :
148 : /// getAccessSpecifier - Returns the access specifier for this base
149 : /// specifier. This is the actual base specifier as used for
150 : /// semantic analysis, so the result can never be AS_none. To
151 : /// retrieve the access specifier as written in the source code, use
152 : /// getAccessSpecifierAsWritten().
153 8390: AccessSpecifier getAccessSpecifier() const {
5799: branch 0 taken
2591: branch 1 taken
154 8390: if ((AccessSpecifier)Access == AS_none)
366: branch 0 taken
5433: branch 1 taken
155 5799: return BaseOfClass? AS_private : AS_public;
156 : else
157 2591: return (AccessSpecifier)Access;
158 : }
159 :
160 : /// getAccessSpecifierAsWritten - Retrieves the access specifier as
161 : /// written in the source code (which may mean that no access
162 : /// specifier was explicitly written). Use getAccessSpecifier() to
163 : /// retrieve the access specifier for use in semantic analysis.
164 95: AccessSpecifier getAccessSpecifierAsWritten() const {
165 95: return (AccessSpecifier)Access;
166 : }
167 :
168 : /// getType - Retrieves the type of the base class. This type will
169 : /// always be an unqualified class type.
170 52096: QualType getType() const { return BaseType; }
171 : };
172 :
173 : /// CXXRecordDecl - Represents a C++ struct/union/class.
174 : /// FIXME: This class will disappear once we've properly taught RecordDecl
175 : /// to deal with C++-specific things.
176 : class CXXRecordDecl : public RecordDecl {
177 :
178 : friend void TagDecl::startDefinition();
179 :
180 : struct DefinitionData {
181 : DefinitionData(CXXRecordDecl *D);
182 :
183 : /// UserDeclaredConstructor - True when this class has a
184 : /// user-declared constructor.
185 : bool UserDeclaredConstructor : 1;
186 :
187 : /// UserDeclaredCopyConstructor - True when this class has a
188 : /// user-declared copy constructor.
189 : bool UserDeclaredCopyConstructor : 1;
190 :
191 : /// UserDeclaredCopyAssignment - True when this class has a
192 : /// user-declared copy assignment operator.
193 : bool UserDeclaredCopyAssignment : 1;
194 :
195 : /// UserDeclaredDestructor - True when this class has a
196 : /// user-declared destructor.
197 : bool UserDeclaredDestructor : 1;
198 :
199 : /// Aggregate - True when this class is an aggregate.
200 : bool Aggregate : 1;
201 :
202 : /// PlainOldData - True when this class is a POD-type.
203 : bool PlainOldData : 1;
204 :
205 : /// Empty - true when this class is empty for traits purposes,
206 : /// i.e. has no data members other than 0-width bit-fields, has no
207 : /// virtual function/base, and doesn't inherit from a non-empty
208 : /// class. Doesn't take union-ness into account.
209 : bool Empty : 1;
210 :
211 : /// Polymorphic - True when this class is polymorphic, i.e. has at
212 : /// least one virtual member or derives from a polymorphic class.
213 : bool Polymorphic : 1;
214 :
215 : /// Abstract - True when this class is abstract, i.e. has at least
216 : /// one pure virtual function, (that can come from a base class).
217 : bool Abstract : 1;
218 :
219 : /// HasTrivialConstructor - True when this class has a trivial constructor.
220 : ///
221 : /// C++ [class.ctor]p5. A constructor is trivial if it is an
222 : /// implicitly-declared default constructor and if:
223 : /// * its class has no virtual functions and no virtual base classes, and
224 : /// * all the direct base classes of its class have trivial constructors, and
225 : /// * for all the nonstatic data members of its class that are of class type
226 : /// (or array thereof), each such class has a trivial constructor.
227 : bool HasTrivialConstructor : 1;
228 :
229 : /// HasTrivialCopyConstructor - True when this class has a trivial copy
230 : /// constructor.
231 : ///
232 : /// C++ [class.copy]p6. A copy constructor for class X is trivial
233 : /// if it is implicitly declared and if
234 : /// * class X has no virtual functions and no virtual base classes, and
235 : /// * each direct base class of X has a trivial copy constructor, and
236 : /// * for all the nonstatic data members of X that are of class type (or
237 : /// array thereof), each such class type has a trivial copy constructor;
238 : /// otherwise the copy constructor is non-trivial.
239 : bool HasTrivialCopyConstructor : 1;
240 :
241 : /// HasTrivialCopyAssignment - True when this class has a trivial copy
242 : /// assignment operator.
243 : ///
244 : /// C++ [class.copy]p11. A copy assignment operator for class X is
245 : /// trivial if it is implicitly declared and if
246 : /// * class X has no virtual functions and no virtual base classes, and
247 : /// * each direct base class of X has a trivial copy assignment operator, and
248 : /// * for all the nonstatic data members of X that are of class type (or
249 : /// array thereof), each such class type has a trivial copy assignment
250 : /// operator;
251 : /// otherwise the copy assignment operator is non-trivial.
252 : bool HasTrivialCopyAssignment : 1;
253 :
254 : /// HasTrivialDestructor - True when this class has a trivial destructor.
255 : ///
256 : /// C++ [class.dtor]p3. A destructor is trivial if it is an
257 : /// implicitly-declared destructor and if:
258 : /// * all of the direct base classes of its class have trivial destructors
259 : /// and
260 : /// * for all of the non-static data members of its class that are of class
261 : /// type (or array thereof), each such class has a trivial destructor.
262 : bool HasTrivialDestructor : 1;
263 :
264 : /// ComputedVisibleConversions - True when visible conversion functions are
265 : /// already computed and are available.
266 : bool ComputedVisibleConversions : 1;
267 :
268 : /// Bases - Base classes of this class.
269 : /// FIXME: This is wasted space for a union.
270 : CXXBaseSpecifier *Bases;
271 :
272 : /// NumBases - The number of base class specifiers in Bases.
273 : unsigned NumBases;
274 :
275 : /// VBases - direct and indirect virtual base classes of this class.
276 : CXXBaseSpecifier *VBases;
277 :
278 : /// NumVBases - The number of virtual base class specifiers in VBases.
279 : unsigned NumVBases;
280 :
281 : /// Conversions - Overload set containing the conversion functions
282 : /// of this C++ class (but not its inherited conversion
283 : /// functions). Each of the entries in this overload set is a
284 : /// CXXConversionDecl.
285 : UnresolvedSet<4> Conversions;
286 :
287 : /// VisibleConversions - Overload set containing the conversion
288 : /// functions of this C++ class and all those inherited conversion
289 : /// functions that are visible in this class. Each of the entries
290 : /// in this overload set is a CXXConversionDecl or a
291 : /// FunctionTemplateDecl.
292 : UnresolvedSet<4> VisibleConversions;
293 :
294 : /// Definition - The declaration which defines this record.
295 : CXXRecordDecl *Definition;
296 :
297 : } *DefinitionData;
298 :
299 144565: struct DefinitionData &data() {
0: branch 0 not taken
144565: branch 1 taken
300 144565: assert(DefinitionData && "queried property of class with no definition");
301 144565: return *DefinitionData;
302 : }
303 :
304 258816: const struct DefinitionData &data() const {
0: branch 0 not taken
258816: branch 1 taken
305 258816: assert(DefinitionData && "queried property of class with no definition");
306 258816: return *DefinitionData;
307 : }
308 :
309 : /// \brief The template or declaration that this declaration
310 : /// describes or was instantiated from, respectively.
311 : ///
312 : /// For non-templates, this value will be NULL. For record
313 : /// declarations that describe a class template, this will be a
314 : /// pointer to a ClassTemplateDecl. For member
315 : /// classes of class template specializations, this will be the
316 : /// MemberSpecializationInfo referring to the member class that was
317 : /// instantiated or specialized.
318 : llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
319 : TemplateOrInstantiation;
320 :
321 : void getNestedVisibleConversionFunctions(CXXRecordDecl *RD,
322 : const llvm::SmallPtrSet<CanQualType, 8> &TopConversionsTypeSet,
323 : const llvm::SmallPtrSet<CanQualType, 8> &HiddenConversionTypes);
324 : void collectConversionFunctions(
325 : llvm::SmallPtrSet<CanQualType, 8>& ConversionsTypeSet) const;
326 :
327 : protected:
328 : CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
329 : SourceLocation L, IdentifierInfo *Id,
330 : CXXRecordDecl *PrevDecl,
331 : SourceLocation TKL = SourceLocation());
332 :
333 : ~CXXRecordDecl();
334 :
335 : public:
336 : /// base_class_iterator - Iterator that traverses the base classes
337 : /// of a class.
338 : typedef CXXBaseSpecifier* base_class_iterator;
339 :
340 : /// base_class_const_iterator - Iterator that traverses the base
341 : /// classes of a class.
342 : typedef const CXXBaseSpecifier* base_class_const_iterator;
343 :
344 : /// reverse_base_class_iterator = Iterator that traverses the base classes
345 : /// of a class in reverse order.
346 : typedef std::reverse_iterator<base_class_iterator>
347 : reverse_base_class_iterator;
348 :
349 : /// reverse_base_class_iterator = Iterator that traverses the base classes
350 : /// of a class in reverse order.
351 : typedef std::reverse_iterator<base_class_const_iterator>
352 : reverse_base_class_const_iterator;
353 :
354 44060: virtual CXXRecordDecl *getCanonicalDecl() {
355 44060: return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
356 : }
357 3729: virtual const CXXRecordDecl *getCanonicalDecl() const {
358 3729: return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
359 : }
360 :
361 6998: CXXRecordDecl *getDefinition(ASTContext& C) const {
572: branch 1 taken
6426: branch 1 taken
362 6998: if (!DefinitionData) return 0;
363 6426: return data().Definition;
364 : }
365 :
366 10378: bool hasDefinition() const { return DefinitionData != 0; }
367 :
368 : static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
369 : SourceLocation L, IdentifierInfo *Id,
370 : SourceLocation TKL = SourceLocation(),
371 : CXXRecordDecl* PrevDecl=0,
372 : bool DelayTypeCreation = false);
373 :
374 : virtual void Destroy(ASTContext& C);
375 :
376 20042: bool isDynamicClass() const {
11686: branch 2 taken
649: branch 4 taken
7707: branch 5 taken
377 20042: return data().Polymorphic || data().NumVBases != 0;
378 : }
379 :
380 : /// setBases - Sets the base classes of this struct or class.
381 : void setBases(ASTContext &C,
382 : CXXBaseSpecifier const * const *Bases, unsigned NumBases);
383 :
384 : /// getNumBases - Retrieves the number of base classes of this
385 : /// class.
386 1278: unsigned getNumBases() const { return data().NumBases; }
387 :
388 62307: base_class_iterator bases_begin() { return data().Bases; }
389 101440: base_class_const_iterator bases_begin() const { return data().Bases; }
390 32041: base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
391 50639: base_class_const_iterator bases_end() const {
392 50639: return bases_begin() + data().NumBases;
393 : }
394 : reverse_base_class_iterator bases_rbegin() {
395 : return reverse_base_class_iterator(bases_end());
396 : }
397 105: reverse_base_class_const_iterator bases_rbegin() const {
398 105: return reverse_base_class_const_iterator(bases_end());
399 : }
400 : reverse_base_class_iterator bases_rend() {
401 : return reverse_base_class_iterator(bases_begin());
402 : }
403 105: reverse_base_class_const_iterator bases_rend() const {
404 105: return reverse_base_class_const_iterator(bases_begin());
405 : }
406 :
407 : /// getNumVBases - Retrieves the number of virtual base classes of this
408 : /// class.
409 8159: unsigned getNumVBases() const { return data().NumVBases; }
410 :
411 4268: base_class_iterator vbases_begin() { return data().VBases; }
412 1706: base_class_const_iterator vbases_begin() const { return data().VBases; }
413 2134: base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
414 853: base_class_const_iterator vbases_end() const {
415 853: return vbases_begin() + data().NumVBases;
416 : }
417 : reverse_base_class_iterator vbases_rbegin() {
418 : return reverse_base_class_iterator(vbases_end());
419 : }
420 79: reverse_base_class_const_iterator vbases_rbegin() const {
421 79: return reverse_base_class_const_iterator(vbases_end());
422 : }
423 : reverse_base_class_iterator vbases_rend() {
424 : return reverse_base_class_iterator(vbases_begin());
425 : }
426 79: reverse_base_class_const_iterator vbases_rend() const {
427 79: return reverse_base_class_const_iterator(vbases_begin());
428 : }
429 :
430 : /// \brief Determine whether this class has any dependent base classes.
431 : bool hasAnyDependentBases() const;
432 :
433 : /// Iterator access to method members. The method iterator visits
434 : /// all method members of the class, including non-instance methods,
435 : /// special methods, etc.
436 : typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
437 :
438 : /// method_begin - Method begin iterator. Iterates in the order the methods
439 : /// were declared.
440 7377: method_iterator method_begin() const {
441 7377: return method_iterator(decls_begin());
442 : }
443 : /// method_end - Method end iterator.
444 7377: method_iterator method_end() const {
445 7377: return method_iterator(decls_end());
446 : }
447 :
448 : /// Iterator access to constructor members.
449 : typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
450 :
451 6: ctor_iterator ctor_begin() const {
452 6: return ctor_iterator(decls_begin());
453 : }
454 6: ctor_iterator ctor_end() const {
455 6: return ctor_iterator(decls_end());
456 : }
457 :
458 : /// hasConstCopyConstructor - Determines whether this class has a
459 : /// copy constructor that accepts a const-qualified argument.
460 : bool hasConstCopyConstructor(ASTContext &Context) const;
461 :
462 : /// getCopyConstructor - Returns the copy constructor for this class
463 : CXXConstructorDecl *getCopyConstructor(ASTContext &Context,
464 : unsigned TypeQuals) const;
465 :
466 : /// hasConstCopyAssignment - Determines whether this class has a
467 : /// copy assignment operator that accepts a const-qualified argument.
468 : /// It returns its decl in MD if found.
469 : bool hasConstCopyAssignment(ASTContext &Context,
470 : const CXXMethodDecl *&MD) const;
471 :
472 : /// addedConstructor - Notify the class that another constructor has
473 : /// been added. This routine helps maintain information about the
474 : /// class based on which constructors have been added.
475 : void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
476 :
477 : /// hasUserDeclaredConstructor - Whether this class has any
478 : /// user-declared constructors. When true, a default constructor
479 : /// will not be implicitly declared.
480 4294: bool hasUserDeclaredConstructor() const {
481 4294: return data().UserDeclaredConstructor;
482 : }
483 :
484 : /// hasUserDeclaredCopyConstructor - Whether this class has a
485 : /// user-declared copy constructor. When false, a copy constructor
486 : /// will be implicitly declared.
487 3904: bool hasUserDeclaredCopyConstructor() const {
488 3904: return data().UserDeclaredCopyConstructor;
489 : }
490 :
491 : /// addedAssignmentOperator - Notify the class that another assignment
492 : /// operator has been added. This routine helps maintain information about the
493 : /// class based on which operators have been added.
494 : void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);
495 :
496 : /// hasUserDeclaredCopyAssignment - Whether this class has a
497 : /// user-declared copy assignment operator. When false, a copy
498 : /// assigment operator will be implicitly declared.
499 3907: bool hasUserDeclaredCopyAssignment() const {
500 3907: return data().UserDeclaredCopyAssignment;
501 : }
502 :
503 : /// hasUserDeclaredDestructor - Whether this class has a
504 : /// user-declared destructor. When false, a destructor will be
505 : /// implicitly declared.
506 3918: bool hasUserDeclaredDestructor() const {
507 3918: return data().UserDeclaredDestructor;
508 : }
509 :
510 : /// setUserDeclaredDestructor - Set whether this class has a
511 : /// user-declared destructor. If not set by the time the class is
512 : /// fully defined, a destructor will be implicitly declared.
513 204: void setUserDeclaredDestructor(bool UCD) {
514 204: data().UserDeclaredDestructor = UCD;
515 204: }
516 :
517 : /// getConversions - Retrieve the overload set containing all of the
518 : /// conversion functions in this class.
519 5021: UnresolvedSetImpl *getConversionFunctions() {
520 5021: return &data().Conversions;
521 : }
522 145: const UnresolvedSetImpl *getConversionFunctions() const {
523 145: return &data().Conversions;
524 : }
525 :
526 : typedef UnresolvedSetImpl::iterator conversion_iterator;
527 : conversion_iterator conversion_begin() const {
528 : return getConversionFunctions()->begin();
529 : }
530 : conversion_iterator conversion_end() const {
531 : return getConversionFunctions()->end();
532 : }
533 :
534 : /// Replaces a conversion function with a new declaration.
535 : ///
536 : /// Returns true if the old conversion was found.
537 11: bool replaceConversion(const NamedDecl* Old, NamedDecl *New) {
538 11: return getConversionFunctions()->replace(Old, New);
539 : }
540 :
541 : /// getVisibleConversionFunctions - get all conversion functions visible
542 : /// in current class; including conversion function templates.
543 : const UnresolvedSetImpl *getVisibleConversionFunctions();
544 :
545 : /// addVisibleConversionFunction - Add a new conversion function to the
546 : /// list of visible conversion functions.
547 : void addVisibleConversionFunction(CXXConversionDecl *ConvDecl);
548 :
549 : /// \brief Add a new conversion function template to the list of visible
550 : /// conversion functions.
551 : void addVisibleConversionFunction(FunctionTemplateDecl *ConvDecl);
552 :
553 : /// addConversionFunction - Add a new conversion function to the
554 : /// list of conversion functions.
555 : void addConversionFunction(CXXConversionDecl *ConvDecl);
556 :
557 : /// \brief Add a new conversion function template to the list of conversion
558 : /// functions.
559 : void addConversionFunction(FunctionTemplateDecl *ConvDecl);
560 :
561 : /// isAggregate - Whether this class is an aggregate (C++
562 : /// [dcl.init.aggr]), which is a class with no user-declared
563 : /// constructors, no private or protected non-static data members,
564 : /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
565 111: bool isAggregate() const { return data().Aggregate; }
566 :
567 : /// setAggregate - Set whether this class is an aggregate (C++
568 : /// [dcl.init.aggr]).
569 1616: void setAggregate(bool Agg) { data().Aggregate = Agg; }
570 :
571 : /// setMethodAsVirtual - Make input method virtual and set the necesssary
572 : /// special function bits and other bits accordingly.
573 : void setMethodAsVirtual(FunctionDecl *Method);
574 :
575 : /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
576 : /// that is an aggregate that has no non-static non-POD data members, no
577 : /// reference data members, no user-defined copy assignment operator and no
578 : /// user-defined destructor.
579 1410: bool isPOD() const { return data().PlainOldData; }
580 :
581 : /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
582 2059: void setPOD(bool POD) { data().PlainOldData = POD; }
583 :
584 : /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
585 : /// means it has a virtual function, virtual base, data member (other than
586 : /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
587 : /// a check for union-ness.
588 3025: bool isEmpty() const { return data().Empty; }
589 :
590 : /// Set whether this class is empty (C++0x [meta.unary.prop])
591 2950: void setEmpty(bool Emp) { data().Empty = Emp; }
592 :
593 : /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
594 : /// which means that the class contains or inherits a virtual function.
595 3300: bool isPolymorphic() const { return data().Polymorphic; }
596 :
597 : /// setPolymorphic - Set whether this class is polymorphic (C++
598 : /// [class.virtual]).
599 872: void setPolymorphic(bool Poly) { data().Polymorphic = Poly; }
600 :
601 : /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
602 : /// which means that the class contains or inherits a pure virtual function.
603 12572: bool isAbstract() const { return data().Abstract; }
604 :
605 : /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
606 38: void setAbstract(bool Abs) { data().Abstract = Abs; }
607 :
608 : // hasTrivialConstructor - Whether this class has a trivial constructor
609 : // (C++ [class.ctor]p5)
610 5728: bool hasTrivialConstructor() const { return data().HasTrivialConstructor; }
611 :
612 : // setHasTrivialConstructor - Set whether this class has a trivial constructor
613 : // (C++ [class.ctor]p5)
614 1199: void setHasTrivialConstructor(bool TC) { data().HasTrivialConstructor = TC; }
615 :
616 : // hasTrivialCopyConstructor - Whether this class has a trivial copy
617 : // constructor (C++ [class.copy]p6)
618 4955: bool hasTrivialCopyConstructor() const {
619 4955: return data().HasTrivialCopyConstructor;
620 : }
621 :
622 : // setHasTrivialCopyConstructor - Set whether this class has a trivial
623 : // copy constructor (C++ [class.copy]p6)
624 1021: void setHasTrivialCopyConstructor(bool TC) {
625 1021: data().HasTrivialCopyConstructor = TC;
626 1021: }
627 :
628 : // hasTrivialCopyAssignment - Whether this class has a trivial copy
629 : // assignment operator (C++ [class.copy]p11)
630 4819: bool hasTrivialCopyAssignment() const {
631 4819: return data().HasTrivialCopyAssignment;
632 : }
633 :
634 : // setHasTrivialCopyAssignment - Set whether this class has a
635 : // trivial copy assignment operator (C++ [class.copy]p11)
636 1022: void setHasTrivialCopyAssignment(bool TC) {
637 1022: data().HasTrivialCopyAssignment = TC;
638 1022: }
639 :
640 : // hasTrivialDestructor - Whether this class has a trivial destructor
641 : // (C++ [class.dtor]p3)
642 7829: bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
643 :
644 : // setHasTrivialDestructor - Set whether this class has a trivial destructor
645 : // (C++ [class.dtor]p3)
646 268: void setHasTrivialDestructor(bool TC) { data().HasTrivialDestructor = TC; }
647 :
648 : /// \brief If this record is an instantiation of a member class,
649 : /// retrieves the member class from which it was instantiated.
650 : ///
651 : /// This routine will return non-NULL for (non-templated) member
652 : /// classes of class templates. For example, given:
653 : ///
654 : /// \code
655 : /// template<typename T>
656 : /// struct X {
657 : /// struct A { };
658 : /// };
659 : /// \endcode
660 : ///
661 : /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
662 : /// whose parent is the class template specialization X<int>. For
663 : /// this declaration, getInstantiatedFromMemberClass() will return
664 : /// the CXXRecordDecl X<T>::A. When a complete definition of
665 : /// X<int>::A is required, it will be instantiated from the
666 : /// declaration returned by getInstantiatedFromMemberClass().
667 : CXXRecordDecl *getInstantiatedFromMemberClass() const;
668 :
669 : /// \brief If this class is an instantiation of a member class of a
670 : /// class template specialization, retrieves the member specialization
671 : /// information.
672 : MemberSpecializationInfo *getMemberSpecializationInfo() const;
673 :
674 : /// \brief Specify that this record is an instantiation of the
675 : /// member class RD.
676 : void setInstantiationOfMemberClass(CXXRecordDecl *RD,
677 : TemplateSpecializationKind TSK);
678 :
679 : /// \brief Retrieves the class template that is described by this
680 : /// class declaration.
681 : ///
682 : /// Every class template is represented as a ClassTemplateDecl and a
683 : /// CXXRecordDecl. The former contains template properties (such as
684 : /// the template parameter lists) while the latter contains the
685 : /// actual description of the template's
686 : /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
687 : /// CXXRecordDecl that from a ClassTemplateDecl, while
688 : /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
689 : /// a CXXRecordDecl.
690 72129: ClassTemplateDecl *getDescribedClassTemplate() const {
691 72129: return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
692 : }
693 :
694 1801: void setDescribedClassTemplate(ClassTemplateDecl *Template) {
695 1801: TemplateOrInstantiation = Template;
696 1801: }
697 :
698 : /// \brief Determine whether this particular class is a specialization or
699 : /// instantiation of a class template or member class of a class template,
700 : /// and how it was instantiated or specialized.
701 : TemplateSpecializationKind getTemplateSpecializationKind() const;
702 :
703 : /// \brief Set the kind of specialization or template instantiation this is.
704 : void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
705 :
706 : /// getDefaultConstructor - Returns the default constructor for this class
707 : CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
708 :
709 : /// getDestructor - Returns the destructor decl for this class.
710 : CXXDestructorDecl *getDestructor(ASTContext &Context);
711 :
712 : /// isLocalClass - If the class is a local class [class.local], returns
713 : /// the enclosing function declaration.
714 2275: const FunctionDecl *isLocalClass() const {
195: branch 2 taken
2080: branch 3 taken
715 2275: if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
716 195: return RD->isLocalClass();
717 :
718 2080: return dyn_cast<FunctionDecl>(getDeclContext());
719 : }
720 :
721 : /// \brief Determine whether this class is derived from the class \p Base.
722 : ///
723 : /// This routine only determines whether this class is derived from \p Base,
724 : /// but does not account for factors that may make a Derived -> Base class
725 : /// ill-formed, such as private/protected inheritance or multiple, ambiguous
726 : /// base class subobjects.
727 : ///
728 : /// \param Base the base class we are searching for.
729 : ///
730 : /// \returns true if this class is derived from Base, false otherwise.
731 : bool isDerivedFrom(CXXRecordDecl *Base) const;
732 :
733 : /// \brief Determine whether this class is derived from the type \p Base.
734 : ///
735 : /// This routine only determines whether this class is derived from \p Base,
736 : /// but does not account for factors that may make a Derived -> Base class
737 : /// ill-formed, such as private/protected inheritance or multiple, ambiguous
738 : /// base class subobjects.
739 : ///
740 : /// \param Base the base class we are searching for.
741 : ///
742 : /// \param Paths will contain the paths taken from the current class to the
743 : /// given \p Base class.
744 : ///
745 : /// \returns true if this class is derived from Base, false otherwise.
746 : ///
747 : /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
748 : /// tangling input and output in \p Paths
749 : bool isDerivedFrom(CXXRecordDecl *Base, CXXBasePaths &Paths) const;
750 :
751 : /// \brief Determine whether this class is provably not derived from
752 : /// the type \p Base.
753 : bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
754 :
755 : /// \brief Function type used by forallBases() as a callback.
756 : ///
757 : /// \param Base the definition of the base class
758 : ///
759 : /// \returns true if this base matched the search criteria
760 : typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
761 : void *UserData);
762 :
763 : /// \brief Determines if the given callback holds for all the direct
764 : /// or indirect base classes of this type.
765 : ///
766 : /// The class itself does not count as a base class. This routine
767 : /// returns false if the class has non-computable base classes.
768 : ///
769 : /// \param AllowShortCircuit if false, forces the callback to be called
770 : /// for every base class, even if a dependent or non-matching base was
771 : /// found.
772 : bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
773 : bool AllowShortCircuit = true) const;
774 :
775 : /// \brief Function type used by lookupInBases() to determine whether a
776 : /// specific base class subobject matches the lookup criteria.
777 : ///
778 : /// \param Specifier the base-class specifier that describes the inheritance
779 : /// from the base class we are trying to match.
780 : ///
781 : /// \param Path the current path, from the most-derived class down to the
782 : /// base named by the \p Specifier.
783 : ///
784 : /// \param UserData a single pointer to user-specified data, provided to
785 : /// lookupInBases().
786 : ///
787 : /// \returns true if this base matched the search criteria, false otherwise.
788 : typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
789 : CXXBasePath &Path,
790 : void *UserData);
791 :
792 : /// \brief Look for entities within the base classes of this C++ class,
793 : /// transitively searching all base class subobjects.
794 : ///
795 : /// This routine uses the callback function \p BaseMatches to find base
796 : /// classes meeting some search criteria, walking all base class subobjects
797 : /// and populating the given \p Paths structure with the paths through the
798 : /// inheritance hierarchy that resulted in a match. On a successful search,
799 : /// the \p Paths structure can be queried to retrieve the matching paths and
800 : /// to determine if there were any ambiguities.
801 : ///
802 : /// \param BaseMatches callback function used to determine whether a given
803 : /// base matches the user-defined search criteria.
804 : ///
805 : /// \param UserData user data pointer that will be provided to \p BaseMatches.
806 : ///
807 : /// \param Paths used to record the paths from this class to its base class
808 : /// subobjects that match the search criteria.
809 : ///
810 : /// \returns true if there exists any path from this class to a base class
811 : /// subobject that matches the search criteria.
812 : bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
813 : CXXBasePaths &Paths) const;
814 :
815 : /// \brief Base-class lookup callback that determines whether the given
816 : /// base class specifier refers to a specific class declaration.
817 : ///
818 : /// This callback can be used with \c lookupInBases() to determine whether
819 : /// a given derived class has is a base class subobject of a particular type.
820 : /// The user data pointer should refer to the canonical CXXRecordDecl of the
821 : /// base class that we are searching for.
822 : static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
823 : CXXBasePath &Path, void *BaseRecord);
824 :
825 : /// \brief Base-class lookup callback that determines whether there exists
826 : /// a tag with the given name.
827 : ///
828 : /// This callback can be used with \c lookupInBases() to find tag members
829 : /// of the given name within a C++ class hierarchy. The user data pointer
830 : /// is an opaque \c DeclarationName pointer.
831 : static bool FindTagMember(const CXXBaseSpecifier *Specifier,
832 : CXXBasePath &Path, void *Name);
833 :
834 : /// \brief Base-class lookup callback that determines whether there exists
835 : /// a member with the given name.
836 : ///
837 : /// This callback can be used with \c lookupInBases() to find members
838 : /// of the given name within a C++ class hierarchy. The user data pointer
839 : /// is an opaque \c DeclarationName pointer.
840 : static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
841 : CXXBasePath &Path, void *Name);
842 :
843 : /// \brief Base-class lookup callback that determines whether there exists
844 : /// a member with the given name that can be used in a nested-name-specifier.
845 : ///
846 : /// This callback can be used with \c lookupInBases() to find membes of
847 : /// the given name within a C++ class hierarchy that can occur within
848 : /// nested-name-specifiers.
849 : static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
850 : CXXBasePath &Path,
851 : void *UserData);
852 :
853 : /// viewInheritance - Renders and displays an inheritance diagram
854 : /// for this C++ class and all of its base classes (transitively) using
855 : /// GraphViz.
856 : void viewInheritance(ASTContext& Context) const;
857 :
858 : /// MergeAccess - Calculates the access of a decl that is reached
859 : /// along a path.
860 : static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
861 2697: AccessSpecifier DeclAccess) {
0: branch 0 not taken
2697: branch 1 taken
862 2697: assert(DeclAccess != AS_none);
122: branch 0 taken
2575: branch 1 taken
863 2697: if (DeclAccess == AS_private) return AS_none;
161: branch 0 taken
2414: branch 1 taken
864 2575: return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
865 : }
866 :
867 245245: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
868 679429: static bool classofKind(Kind K) {
869 : return K == CXXRecord ||
870 : K == ClassTemplateSpecialization ||
286975: branch 0 taken
392454: branch 1 taken
212982: branch 2 taken
73993: branch 3 taken
2528: branch 4 taken
210454: branch 5 taken
871 679429: K == ClassTemplatePartialSpecialization;
872 : }
873 5377: static bool classof(const CXXRecordDecl *D) { return true; }
874 : static bool classof(const ClassTemplateSpecializationDecl *D) {
875 : return true;
876 : }
877 : };
878 :
879 : /// CXXMethodDecl - Represents a static or instance method of a
880 : /// struct/union/class.
881 0: class CXXMethodDecl : public FunctionDecl {
882 : protected:
883 : CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
884 : DeclarationName N, QualType T, TypeSourceInfo *TInfo,
885 18581: bool isStatic, bool isInline)
886 : : FunctionDecl(DK, RD, L, N, T, TInfo, (isStatic ? Static : None),
12232: branch 2 taken
0: branch 3 not taken
129: branch 5 taken
6220: branch 6 taken
6349: branch 7 taken
0: branch 8 not taken
887 18581: isInline) {}
888 :
889 : public:
890 : static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
891 : SourceLocation L, DeclarationName N,
892 : QualType T, TypeSourceInfo *TInfo,
893 : bool isStatic = false,
894 : bool isInline = false);
895 :
896 25272: bool isStatic() const { return getStorageClass() == Static; }
897 17811: bool isInstance() const { return !isStatic(); }
898 :
899 42760: bool isVirtual() const {
900 : CXXMethodDecl *CD =
901 42760: cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
902 :
11056: branch 1 taken
31704: branch 2 taken
903 42760: if (CD->isVirtualAsWritten())
904 11056: return true;
905 :
906 31704: return (CD->begin_overridden_methods() != CD->end_overridden_methods());
907 : }
908 :
909 : /// \brief Determine whether this is a usual deallocation function
910 : /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
911 : /// delete or delete[] operator with a particular signature.
912 : bool isUsualDeallocationFunction() const;
913 :
914 1133: const CXXMethodDecl *getCanonicalDecl() const {
915 1133: return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
916 : }
917 59882: CXXMethodDecl *getCanonicalDecl() {
918 59882: return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
919 : }
920 :
921 : ///
922 : void addOverriddenMethod(const CXXMethodDecl *MD);
923 :
924 : typedef const CXXMethodDecl ** method_iterator;
925 :
926 : method_iterator begin_overridden_methods() const;
927 : method_iterator end_overridden_methods() const;
928 :
929 : /// getParent - Returns the parent of this method declaration, which
930 : /// is the class in which this method is defined.
931 31202: const CXXRecordDecl *getParent() const {
932 31202: return cast<CXXRecordDecl>(FunctionDecl::getParent());
933 : }
934 :
935 : /// getParent - Returns the parent of this method declaration, which
936 : /// is the class in which this method is defined.
937 14720: CXXRecordDecl *getParent() {
938 : return const_cast<CXXRecordDecl *>(
939 14720: cast<CXXRecordDecl>(FunctionDecl::getParent()));
940 : }
941 :
942 : /// getThisType - Returns the type of 'this' pointer.
943 : /// Should only be called for instance methods.
944 : QualType getThisType(ASTContext &C) const;
945 :
946 27463: unsigned getTypeQualifiers() const {
947 27463: return getType()->getAs<FunctionProtoType>()->getTypeQuals();
948 : }
949 :
950 : bool hasInlineBody() const;
951 :
952 : // Implement isa/cast/dyncast/etc.
953 376948: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
954 42760: static bool classof(const CXXMethodDecl *D) { return true; }
955 403155: static bool classofKind(Kind K) {
92177: branch 1 taken
277978: branch 2 taken
33008: branch 3 taken
31: branch 3 taken
956 403155: return K >= CXXMethod && K <= CXXConversion;
957 : }
958 : };
959 :
960 : /// CXXBaseOrMemberInitializer - Represents a C++ base or member
961 : /// initializer, which is part of a constructor initializer that
962 : /// initializes one non-static member variable or one base class. For
963 : /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
964 : /// initializers:
965 : ///
966 : /// @code
967 : /// class A { };
968 : /// class B : public A {
969 : /// float f;
970 : /// public:
971 : /// B(A& a) : A(a), f(3.14159) { }
972 : /// };
973 : /// @endcode
974 0: class CXXBaseOrMemberInitializer {
975 : /// \brief Either the base class name (stored as a TypeSourceInfo*) or the
976 : /// field being initialized.
977 : llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember;
978 :
979 : /// \brief The source location for the field name.
980 : SourceLocation MemberLocation;
981 :
982 : /// \brief The argument used to initialize the base or member, which may
983 : /// end up constructing an object (when multiple arguments are involved).
984 : Stmt *Init;
985 :
986 : /// \brief Stores either the constructor to call to initialize this base or
987 : /// member (a CXXConstructorDecl pointer), or stores the anonymous union of
988 : /// which the initialized value is a member.
989 : ///
990 : /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's
991 : /// anonymous union data member, this field holds the FieldDecl for the
992 : /// member of the anonymous union being initialized.
993 : /// @code
994 : /// struct X {
995 : /// X() : au_i1(123) {}
996 : /// union {
997 : /// int au_i1;
998 : /// float au_f1;
999 : /// };
1000 : /// };
1001 : /// @endcode
1002 : /// In above example, BaseOrMember holds the field decl. for anonymous union
1003 : /// and AnonUnionMember holds field decl for au_i1.
1004 : FieldDecl *AnonUnionMember;
1005 :
1006 : /// LParenLoc - Location of the left paren of the ctor-initializer.
1007 : SourceLocation LParenLoc;
1008 :
1009 : /// RParenLoc - Location of the right paren of the ctor-initializer.
1010 : SourceLocation RParenLoc;
1011 :
1012 : public:
1013 : /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
1014 : explicit
1015 : CXXBaseOrMemberInitializer(ASTContext &Context,
1016 : TypeSourceInfo *TInfo,
1017 : SourceLocation L,
1018 : Expr *Init,
1019 : SourceLocation R);
1020 :
1021 : /// CXXBaseOrMemberInitializer - Creates a new member initializer.
1022 : explicit
1023 : CXXBaseOrMemberInitializer(ASTContext &Context,
1024 : FieldDecl *Member, SourceLocation MemberLoc,
1025 : SourceLocation L,
1026 : Expr *Init,
1027 : SourceLocation R);
1028 :
1029 : /// \brief Destroy the base or member initializer.
1030 : void Destroy(ASTContext &Context);
1031 :
1032 : /// isBaseInitializer - Returns true when this initializer is
1033 : /// initializing a base class.
1034 2101: bool isBaseInitializer() const { return BaseOrMember.is<TypeSourceInfo*>(); }
1035 :
1036 : /// isMemberInitializer - Returns true when this initializer is
1037 : /// initializing a non-static data member.
1038 1390: bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); }
1039 :
1040 : /// If this is a base class initializer, returns the type of the
1041 : /// base class with location information. Otherwise, returns an NULL
1042 : /// type location.
1043 : TypeLoc getBaseClassLoc() const;
1044 :
1045 : /// If this is a base class initializer, returns the type of the base class.
1046 : /// Otherwise, returns NULL.
1047 : const Type *getBaseClass() const;
1048 : Type *getBaseClass();
1049 :
1050 : /// \brief Returns the declarator information for a base class initializer.
1051 8: TypeSourceInfo *getBaseClassInfo() const {
1052 8: return BaseOrMember.dyn_cast<TypeSourceInfo *>();
1053 : }
1054 :
1055 : /// getMember - If this is a member initializer, returns the
1056 : /// declaration of the non-static data member being
1057 : /// initialized. Otherwise, returns NULL.
1058 747: FieldDecl *getMember() {
1059 747: if (isMemberInitializer())
1060 738: return BaseOrMember.get<FieldDecl*>();
1061 : else
1062 9: return 0;
1063 : }
1064 :
1065 25: SourceLocation getMemberLocation() const {
1066 25: return MemberLocation;
1067 : }
1068 :
1069 24: void setMember(FieldDecl *Member) {
1070 24: assert(isMemberInitializer());
1071 24: BaseOrMember = Member;
1072 24: }
1073 :
1074 : /// \brief Determine the source location of the initializer.
1075 : SourceLocation getSourceLocation() const;
1076 :
1077 : /// \brief Determine the source range covering the entire initializer.
1078 : SourceRange getSourceRange() const;
1079 :
1080 264: FieldDecl *getAnonUnionMember() const {
1081 264: return AnonUnionMember;
1082 : }
1083 24: void setAnonUnionMember(FieldDecl *anonMember) {
1084 24: AnonUnionMember = anonMember;
1085 24: }
1086 :
1087 21: SourceLocation getLParenLoc() const { return LParenLoc; }
1088 24: SourceLocation getRParenLoc() const { return RParenLoc; }
1089 :
1090 634: Expr *getInit() { return static_cast<Expr *>(Init); }
1091 : };
1092 :
1093 : /// CXXConstructorDecl - Represents a C++ constructor within a
1094 : /// class. For example:
1095 : ///
1096 : /// @code
1097 : /// class X {
1098 : /// public:
1099 : /// explicit X(int); // represented by a CXXConstructorDecl.
1100 : /// };
1101 : /// @endcode
1102 0: class CXXConstructorDecl : public CXXMethodDecl {
1103 : /// IsExplicitSpecified - Whether this constructor declaration has the
1104 : /// 'explicit' keyword specified.
1105 : bool IsExplicitSpecified : 1;
1106 :
1107 : /// ImplicitlyDefined - Whether this constructor was implicitly
1108 : /// defined by the compiler. When false, the constructor was defined
1109 : /// by the user. In C++03, this flag will have the same value as
1110 : /// Implicit. In C++0x, however, a constructor that is
1111 : /// explicitly defaulted (i.e., defined with " = default") will have
1112 : /// @c !Implicit && ImplicitlyDefined.
1113 : bool ImplicitlyDefined : 1;
1114 :
1115 : /// Support for base and member initializers.
1116 : /// BaseOrMemberInitializers - The arguments used to initialize the base
1117 : /// or member.
1118 : CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
1119 : unsigned NumBaseOrMemberInitializers;
1120 :
1121 : CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
1122 : DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1123 : bool isExplicitSpecified, bool isInline,
1124 7995: bool isImplicitlyDeclared)
1125 : : CXXMethodDecl(CXXConstructor, RD, L, N, T, TInfo, false, isInline),
1126 : IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1127 7995: BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
1128 7995: setImplicit(isImplicitlyDeclared);
1129 7995: }
1130 : virtual void Destroy(ASTContext& C);
1131 :
1132 : public:
1133 : static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1134 : SourceLocation L, DeclarationName N,
1135 : QualType T, TypeSourceInfo *TInfo,
1136 : bool isExplicit,
1137 : bool isInline, bool isImplicitlyDeclared);
1138 :
1139 : /// isExplicitSpecified - Whether this constructor declaration has the
1140 : /// 'explicit' keyword specified.
1141 3089: bool isExplicitSpecified() const { return IsExplicitSpecified; }
1142 :
1143 : /// isExplicit - Whether this constructor was marked "explicit" or not.
1144 3089: bool isExplicit() const {
1145 : return cast<CXXConstructorDecl>(getFirstDeclaration())
1146 3089: ->isExplicitSpecified();
1147 : }
1148 :
1149 : /// isImplicitlyDefined - Whether this constructor was implicitly
1150 : /// defined. If false, then this constructor was defined by the
1151 : /// user. This operation can only be invoked if the constructor has
1152 : /// already been defined.
1153 3: bool isImplicitlyDefined(ASTContext &C) const {
1154 : assert(isThisDeclarationADefinition() &&
1155 : "Can only get the implicit-definition flag once the "
1156 3: "constructor has been defined");
1157 3: return ImplicitlyDefined;
1158 : }
1159 :
1160 : /// setImplicitlyDefined - Set whether this constructor was
1161 : /// implicitly defined or not.
1162 : void setImplicitlyDefined(bool ID) {
1163 : assert(isThisDeclarationADefinition() &&
1164 : "Can only set the implicit-definition flag once the constructor "
1165 : "has been defined");
1166 : ImplicitlyDefined = ID;
1167 : }
1168 :
1169 : /// init_iterator - Iterates through the member/base initializer list.
1170 : typedef CXXBaseOrMemberInitializer **init_iterator;
1171 :
1172 : /// init_const_iterator - Iterates through the memberbase initializer list.
1173 : typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
1174 :
1175 : /// init_begin() - Retrieve an iterator to the first initializer.
1176 2: init_iterator init_begin() { return BaseOrMemberInitializers; }
1177 : /// begin() - Retrieve an iterator to the first initializer.
1178 526: init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
1179 :
1180 : /// init_end() - Retrieve an iterator past the last initializer.
1181 1: init_iterator init_end() {
1182 1: return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1183 : }
1184 : /// end() - Retrieve an iterator past the last initializer.
1185 526: init_const_iterator init_end() const {
1186 526: return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1187 : }
1188 :
1189 : /// getNumArgs - Determine the number of arguments used to
1190 : /// initialize the member or base.
1191 12: unsigned getNumBaseOrMemberInitializers() const {
1192 12: return NumBaseOrMemberInitializers;
1193 : }
1194 :
1195 425: void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) {
1196 425: NumBaseOrMemberInitializers = numBaseOrMemberInitializers;
1197 425: }
1198 :
1199 425: void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) {
1200 425: BaseOrMemberInitializers = initializers;
1201 425: }
1202 : /// isDefaultConstructor - Whether this constructor is a default
1203 : /// constructor (C++ [class.ctor]p5), which can be used to
1204 : /// default-initialize a class of this type.
1205 : bool isDefaultConstructor() const;
1206 :
1207 : /// isCopyConstructor - Whether this constructor is a copy
1208 : /// constructor (C++ [class.copy]p2, which can be used to copy the
1209 : /// class. @p TypeQuals will be set to the qualifiers on the
1210 : /// argument type. For example, @p TypeQuals would be set to @c
1211 : /// QualType::Const for the following copy constructor:
1212 : ///
1213 : /// @code
1214 : /// class X {
1215 : /// public:
1216 : /// X(const X&);
1217 : /// };
1218 : /// @endcode
1219 : bool isCopyConstructor(unsigned &TypeQuals) const;
1220 :
1221 : /// isCopyConstructor - Whether this constructor is a copy
1222 : /// constructor (C++ [class.copy]p2, which can be used to copy the
1223 : /// class.
1224 4545: bool isCopyConstructor() const {
1225 4545: unsigned TypeQuals = 0;
1226 4545: return isCopyConstructor(TypeQuals);
1227 : }
1228 :
1229 : /// isConvertingConstructor - Whether this constructor is a
1230 : /// converting constructor (C++ [class.conv.ctor]), which can be
1231 : /// used for user-defined conversions.
1232 : bool isConvertingConstructor(bool AllowExplicit) const;
1233 :
1234 : /// \brief Determine whether this is a member template specialization that
1235 : /// looks like a copy constructor. Such constructors are never used to copy
1236 : /// an object.
1237 : bool isCopyConstructorLikeSpecialization() const;
1238 :
1239 : // Implement isa/cast/dyncast/etc.
1240 146647: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1241 13: static bool classof(const CXXConstructorDecl *D) { return true; }
1242 146667: static bool classofKind(Kind K) { return K == CXXConstructor; }
1243 : };
1244 :
1245 : /// CXXDestructorDecl - Represents a C++ destructor within a
1246 : /// class. For example:
1247 : ///
1248 : /// @code
1249 : /// class X {
1250 : /// public:
1251 : /// ~X(); // represented by a CXXDestructorDecl.
1252 : /// };
1253 : /// @endcode
1254 0: class CXXDestructorDecl : public CXXMethodDecl {
1255 : /// ImplicitlyDefined - Whether this destructor was implicitly
1256 : /// defined by the compiler. When false, the destructor was defined
1257 : /// by the user. In C++03, this flag will have the same value as
1258 : /// Implicit. In C++0x, however, a destructor that is
1259 : /// explicitly defaulted (i.e., defined with " = default") will have
1260 : /// @c !Implicit && ImplicitlyDefined.
1261 : bool ImplicitlyDefined : 1;
1262 :
1263 : FunctionDecl *OperatorDelete;
1264 :
1265 : CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
1266 : DeclarationName N, QualType T,
1267 3932: bool isInline, bool isImplicitlyDeclared)
1268 : : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*TInfo=*/0, false, isInline),
1269 3932: ImplicitlyDefined(false), OperatorDelete(0) {
1270 3932: setImplicit(isImplicitlyDeclared);
1271 3932: }
1272 :
1273 : public:
1274 : static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1275 : SourceLocation L, DeclarationName N,
1276 : QualType T, bool isInline,
1277 : bool isImplicitlyDeclared);
1278 :
1279 : /// isImplicitlyDefined - Whether this destructor was implicitly
1280 : /// defined. If false, then this destructor was defined by the
1281 : /// user. This operation can only be invoked if the destructor has
1282 : /// already been defined.
1283 : bool isImplicitlyDefined() const {
1284 : assert(isThisDeclarationADefinition() &&
1285 : "Can only get the implicit-definition flag once the destructor has been defined");
1286 : return ImplicitlyDefined;
1287 : }
1288 :
1289 : /// setImplicitlyDefined - Set whether this destructor was
1290 : /// implicitly defined or not.
1291 : void setImplicitlyDefined(bool ID) {
1292 : assert(isThisDeclarationADefinition() &&
1293 : "Can only set the implicit-definition flag once the destructor has been defined");
1294 : ImplicitlyDefined = ID;
1295 : }
1296 :
1297 58: void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
1298 42: const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1299 :
1300 : // Implement isa/cast/dyncast/etc.
1301 97433: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1302 : static bool classof(const CXXDestructorDecl *D) { return true; }
1303 97436: static bool classofKind(Kind K) { return K == CXXDestructor; }
1304 : };
1305 :
1306 : /// CXXConversionDecl - Represents a C++ conversion function within a
1307 : /// class. For example:
1308 : ///
1309 : /// @code
1310 : /// class X {
1311 : /// public:
1312 : /// operator bool();
1313 : /// };
1314 : /// @endcode
1315 0: class CXXConversionDecl : public CXXMethodDecl {
1316 : /// IsExplicitSpecified - Whether this conversion function declaration is
1317 : /// marked "explicit", meaning that it can only be applied when the user
1318 : /// explicitly wrote a cast. This is a C++0x feature.
1319 : bool IsExplicitSpecified : 1;
1320 :
1321 : CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
1322 : DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1323 305: bool isInline, bool isExplicitSpecified)
1324 : : CXXMethodDecl(CXXConversion, RD, L, N, T, TInfo, false, isInline),
1325 305: IsExplicitSpecified(isExplicitSpecified) { }
1326 :
1327 : public:
1328 : static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1329 : SourceLocation L, DeclarationName N,
1330 : QualType T, TypeSourceInfo *TInfo,
1331 : bool isInline, bool isExplicit);
1332 :
1333 : /// IsExplicitSpecified - Whether this conversion function declaration is
1334 : /// marked "explicit", meaning that it can only be applied when the user
1335 : /// explicitly wrote a cast. This is a C++0x feature.
1336 9348: bool isExplicitSpecified() const { return IsExplicitSpecified; }
1337 :
1338 : /// isExplicit - Whether this is an explicit conversion operator
1339 : /// (C++0x only). Explicit conversion operators are only considered
1340 : /// when the user has explicitly written a cast.
1341 9348: bool isExplicit() const {
1342 : return cast<CXXConversionDecl>(getFirstDeclaration())
1343 9348: ->isExplicitSpecified();
1344 : }
1345 :
1346 : /// getConversionType - Returns the type that this conversion
1347 : /// function is converting to.
1348 20800: QualType getConversionType() const {
1349 20800: return getType()->getAs<FunctionType>()->getResultType();
1350 : }
1351 :
1352 : // Implement isa/cast/dyncast/etc.
1353 45887: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1354 : static bool classof(const CXXConversionDecl *D) { return true; }
1355 45887: static bool classofKind(Kind K) { return K == CXXConversion; }
1356 : };
1357 :
1358 : /// FriendDecl - Represents the declaration of a friend entity,
1359 : /// which can be a function, a type, or a templated function or type.
1360 : // For example:
1361 : ///
1362 : /// @code
1363 : /// template <typename T> class A {
1364 : /// friend int foo(T);
1365 : /// friend class B;
1366 : /// friend T; // only in C++0x
1367 : /// template <typename U> friend class C;
1368 : /// template <typename U> friend A& operator+=(A&, const U&) { ... }
1369 : /// };
1370 : /// @endcode
1371 : ///
1372 : /// The semantic context of a friend decl is its declaring class.
1373 0: class FriendDecl : public Decl {
1374 : public:
1375 : typedef llvm::PointerUnion<NamedDecl*,Type*> FriendUnion;
1376 :
1377 : private:
1378 : // The declaration that's a friend of this class.
1379 : FriendUnion Friend;
1380 :
1381 : // Location of the 'friend' specifier.
1382 : SourceLocation FriendLoc;
1383 :
1384 : // FIXME: Hack to keep track of whether this was a friend function
1385 : // template specialization.
1386 : bool WasSpecialization;
1387 :
1388 : FriendDecl(DeclContext *DC, SourceLocation L, FriendUnion Friend,
1389 96: SourceLocation FriendL)
1390 : : Decl(Decl::Friend, DC, L),
1391 : Friend(Friend),
1392 : FriendLoc(FriendL),
1393 96: WasSpecialization(false) {
1394 96: }
1395 :
1396 : public:
1397 : static FriendDecl *Create(ASTContext &C, DeclContext *DC,
1398 : SourceLocation L, FriendUnion Friend_,
1399 : SourceLocation FriendL);
1400 :
1401 : /// If this friend declaration names an (untemplated but
1402 : /// possibly dependent) type, return the type; otherwise
1403 : /// return null. This is used only for C++0x's unelaborated
1404 : /// friend type declarations.
1405 16: Type *getFriendType() const {
1406 16: return Friend.dyn_cast<Type*>();
1407 : }
1408 :
1409 : /// If this friend declaration doesn't name an unelaborated
1410 : /// type, return the inner declaration.
1411 13: NamedDecl *getFriendDecl() const {
1412 13: return Friend.dyn_cast<NamedDecl*>();
1413 : }
1414 :
1415 : /// Retrieves the location of the 'friend' keyword.
1416 14: SourceLocation getFriendLoc() const {
1417 14: return FriendLoc;
1418 : }
1419 :
1420 11: bool wasSpecialization() const { return WasSpecialization; }
1421 2: void setSpecialization(bool WS) { WasSpecialization = WS; }
1422 :
1423 : // Implement isa/cast/dyncast/etc.
1424 449: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1425 : static bool classof(const FriendDecl *D) { return true; }
1426 449: static bool classofKind(Kind K) { return K == Decl::Friend; }
1427 : };
1428 :
1429 : /// LinkageSpecDecl - This represents a linkage specification. For example:
1430 : /// extern "C" void foo();
1431 : ///
1432 0: class LinkageSpecDecl : public Decl, public DeclContext {
1433 : public:
1434 : /// LanguageIDs - Used to represent the language in a linkage
1435 : /// specification. The values are part of the serialization abi for
1436 : /// ASTs and cannot be changed without altering that abi. To help
1437 : /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1438 : /// from the dwarf standard.
1439 : enum LanguageIDs { lang_c = /* DW_LANG_C */ 0x0002,
1440 : lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 };
1441 : private:
1442 : /// Language - The language for this linkage specification.
1443 : LanguageIDs Language;
1444 :
1445 : /// HadBraces - Whether this linkage specification had curly braces or not.
1446 : bool HadBraces : 1;
1447 :
1448 : LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1449 111: bool Braces)
1450 : : Decl(LinkageSpec, DC, L),
1451 111: DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1452 :
1453 : public:
1454 : static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1455 : SourceLocation L, LanguageIDs Lang,
1456 : bool Braces);
1457 :
1458 1833: LanguageIDs getLanguage() const { return Language; }
1459 :
1460 : /// hasBraces - Determines whether this linkage specification had
1461 : /// braces in its syntactic form.
1462 0: bool hasBraces() const { return HadBraces; }
1463 :
1464 524: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1465 : static bool classof(const LinkageSpecDecl *D) { return true; }
1466 41667: static bool classofKind(Kind K) { return K == LinkageSpec; }
1467 : static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1468 : return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1469 : }
1470 : static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1471 : return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1472 : }
1473 : };
1474 :
1475 : /// UsingDirectiveDecl - Represents C++ using-directive. For example:
1476 : ///
1477 : /// using namespace std;
1478 : ///
1479 : // NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1480 : // artificial name, for all using-directives in order to store
1481 : // them in DeclContext effectively.
1482 0: class UsingDirectiveDecl : public NamedDecl {
1483 :
1484 : /// SourceLocation - Location of 'namespace' token.
1485 : SourceLocation NamespaceLoc;
1486 :
1487 : /// \brief The source range that covers the nested-name-specifier
1488 : /// preceding the namespace name.
1489 : SourceRange QualifierRange;
1490 :
1491 : /// \brief The nested-name-specifier that precedes the namespace
1492 : /// name, if any.
1493 : NestedNameSpecifier *Qualifier;
1494 :
1495 : /// IdentLoc - Location of nominated namespace-name identifier.
1496 : // FIXME: We don't store location of scope specifier.
1497 : SourceLocation IdentLoc;
1498 :
1499 : /// NominatedNamespace - Namespace nominated by using-directive.
1500 : NamedDecl *NominatedNamespace;
1501 :
1502 : /// Enclosing context containing both using-directive and nominated
1503 : /// namespace.
1504 : DeclContext *CommonAncestor;
1505 :
1506 : /// getUsingDirectiveName - Returns special DeclarationName used by
1507 : /// using-directives. This is only used by DeclContext for storing
1508 : /// UsingDirectiveDecls in its lookup structure.
1509 68125: static DeclarationName getName() {
1510 68125: return DeclarationName::getUsingDirectiveName();
1511 : }
1512 :
1513 : UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
1514 : SourceLocation NamespcLoc,
1515 : SourceRange QualifierRange,
1516 : NestedNameSpecifier *Qualifier,
1517 : SourceLocation IdentLoc,
1518 : NamedDecl *Nominated,
1519 100: DeclContext *CommonAncestor)
1520 : : NamedDecl(Decl::UsingDirective, DC, L, getName()),
1521 : NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1522 : Qualifier(Qualifier), IdentLoc(IdentLoc),
1523 : NominatedNamespace(Nominated),
1524 100: CommonAncestor(CommonAncestor) {
1525 100: }
1526 :
1527 : public:
1528 : /// \brief Retrieve the source range of the nested-name-specifier
1529 : /// that qualifiers the namespace name.
1530 1: SourceRange getQualifierRange() const { return QualifierRange; }
1531 :
1532 : /// \brief Retrieve the nested-name-specifier that qualifies the
1533 : /// name of the namespace.
1534 7: NestedNameSpecifier *getQualifier() const { return Qualifier; }
1535 :
1536 4: NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
1537 : const NamedDecl *getNominatedNamespaceAsWritten() const {
1538 : return NominatedNamespace;
1539 : }
1540 :
1541 : /// getNominatedNamespace - Returns namespace nominated by using-directive.
1542 : NamespaceDecl *getNominatedNamespace();
1543 :
1544 34: const NamespaceDecl *getNominatedNamespace() const {
1545 34: return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1546 : }
1547 :
1548 : /// getCommonAncestor - returns common ancestor context of using-directive,
1549 : /// and nominated by it namespace.
1550 1: DeclContext *getCommonAncestor() { return CommonAncestor; }
1551 : const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1552 :
1553 : /// getNamespaceKeyLocation - Returns location of namespace keyword.
1554 1: SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1555 :
1556 : /// getIdentLocation - Returns location of identifier.
1557 1: SourceLocation getIdentLocation() const { return IdentLoc; }
1558 :
1559 : static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1560 : SourceLocation L,
1561 : SourceLocation NamespaceLoc,
1562 : SourceRange QualifierRange,
1563 : NestedNameSpecifier *Qualifier,
1564 : SourceLocation IdentLoc,
1565 : NamedDecl *Nominated,
1566 : DeclContext *CommonAncestor);
1567 :
1568 68: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1569 : static bool classof(const UsingDirectiveDecl *D) { return true; }
1570 68: static bool classofKind(Kind K) { return K == Decl::UsingDirective; }
1571 :
1572 : // Friend for getUsingDirectiveName.
1573 : friend class DeclContext;
1574 : };
1575 :
1576 : /// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1577 : ///
1578 : /// @code
1579 : /// namespace Foo = Bar;
1580 : /// @endcode
1581 0: class NamespaceAliasDecl : public NamedDecl {
1582 : SourceLocation AliasLoc;
1583 :
1584 : /// \brief The source range that covers the nested-name-specifier
1585 : /// preceding the namespace name.
1586 : SourceRange QualifierRange;
1587 :
1588 : /// \brief The nested-name-specifier that precedes the namespace
1589 : /// name, if any.
1590 : NestedNameSpecifier *Qualifier;
1591 :
1592 : /// IdentLoc - Location of namespace identifier.
1593 : SourceLocation IdentLoc;
1594 :
1595 : /// Namespace - The Decl that this alias points to. Can either be a
1596 : /// NamespaceDecl or a NamespaceAliasDecl.
1597 : NamedDecl *Namespace;
1598 :
1599 : NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1600 : SourceLocation AliasLoc, IdentifierInfo *Alias,
1601 : SourceRange QualifierRange,
1602 : NestedNameSpecifier *Qualifier,
1603 22: SourceLocation IdentLoc, NamedDecl *Namespace)
1604 : : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1605 : QualifierRange(QualifierRange), Qualifier(Qualifier),
1606 22: IdentLoc(IdentLoc), Namespace(Namespace) { }
1607 :
1608 : public:
1609 : /// \brief Retrieve the source range of the nested-name-specifier
1610 : /// that qualifiers the namespace name.
1611 : SourceRange getQualifierRange() const { return QualifierRange; }
1612 :
1613 : /// \brief Retrieve the nested-name-specifier that qualifies the
1614 : /// name of the namespace.
1615 4: NestedNameSpecifier *getQualifier() const { return Qualifier; }
1616 :
1617 56: NamespaceDecl *getNamespace() {
1618 56: if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1619 1: return AD->getNamespace();
1620 :
1621 55: return cast<NamespaceDecl>(Namespace);
1622 : }
1623 :
1624 : const NamespaceDecl *getNamespace() const {
1625 : return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1626 : }
1627 :
1628 : /// \brief Retrieve the namespace that this alias refers to, which
1629 : /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1630 2: NamedDecl *getAliasedNamespace() const { return Namespace; }
1631 :
1632 : static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1633 : SourceLocation L, SourceLocation AliasLoc,
1634 : IdentifierInfo *Alias,
1635 : SourceRange QualifierRange,
1636 : NestedNameSpecifier *Qualifier,
1637 : SourceLocation IdentLoc,
1638 : NamedDecl *Namespace);
1639 :
1640 5927: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1641 : static bool classof(const NamespaceAliasDecl *D) { return true; }
1642 5927: static bool classofKind(Kind K) { return K == Decl::NamespaceAlias; }
1643 : };
1644 :
1645 : /// UsingShadowDecl - Represents a shadow declaration introduced into
1646 : /// a scope by a (resolved) using declaration. For example,
1647 : ///
1648 : /// namespace A {
1649 : /// void foo();
1650 : /// }
1651 : /// namespace B {
1652 : /// using A::foo(); // <- a UsingDecl
1653 : /// // Also creates a UsingShadowDecl for A::foo in B
1654 : /// }
1655 : ///
1656 0: class UsingShadowDecl : public NamedDecl {
1657 : /// The referenced declaration.
1658 : NamedDecl *Underlying;
1659 :
1660 : /// The using declaration which introduced this decl.
1661 : UsingDecl *Using;
1662 :
1663 : UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
1664 117: NamedDecl *Target)
1665 : : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()),
1666 117: Underlying(Target), Using(Using) {
1667 117: IdentifierNamespace = Target->getIdentifierNamespace();
1668 117: setImplicit();
1669 117: }
1670 :
1671 : public:
1672 : static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
1673 : SourceLocation Loc, UsingDecl *Using,
1674 117: NamedDecl *Target) {
1675 117: return new (C) UsingShadowDecl(DC, Loc, Using, Target);
1676 : }
1677 :
1678 : /// Gets the underlying declaration which has been brought into the
1679 : /// local scope.
1680 873: NamedDecl *getTargetDecl() const {
1681 873: return Underlying;
1682 : }
1683 :
1684 : /// Gets the using declaration to which this declaration is tied.
1685 128: UsingDecl *getUsingDecl() const {
1686 128: return Using;
1687 : }
1688 :
1689 214607: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1690 : static bool classof(const UsingShadowDecl *D) { return true; }
1691 214607: static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
1692 : };
1693 :
1694 : /// UsingDecl - Represents a C++ using-declaration. For example:
1695 : /// using someNameSpace::someIdentifier;
1696 0: class UsingDecl : public NamedDecl {
1697 : /// \brief The source range that covers the nested-name-specifier
1698 : /// preceding the declaration name.
1699 : SourceRange NestedNameRange;
1700 :
1701 : /// \brief The source location of the "using" location itself.
1702 : SourceLocation UsingLocation;
1703 :
1704 : /// \brief Target nested name specifier.
1705 : NestedNameSpecifier* TargetNestedName;
1706 :
1707 : /// \brief The collection of shadow declarations associated with
1708 : /// this using declaration. This set can change as a class is
1709 : /// processed.
1710 : llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows;
1711 :
1712 : // \brief Has 'typename' keyword.
1713 : bool IsTypeName;
1714 :
1715 : UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1716 : SourceLocation UL, NestedNameSpecifier* TargetNNS,
1717 114: DeclarationName Name, bool IsTypeNameArg)
1718 : : NamedDecl(Decl::Using, DC, L, Name),
1719 : NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS),
1720 114: IsTypeName(IsTypeNameArg) {
1721 114: }
1722 :
1723 : public:
1724 : /// \brief Returns the source range that covers the nested-name-specifier
1725 : /// preceding the namespace name.
1726 15: SourceRange getNestedNameRange() { return NestedNameRange; }
1727 :
1728 : /// \brief Returns the source location of the "using" location itself.
1729 18: SourceLocation getUsingLocation() { return UsingLocation; }
1730 :
1731 : /// \brief Get target nested name declaration.
1732 18: NestedNameSpecifier* getTargetNestedNameDecl() {
1733 18: return TargetNestedName;
1734 : }
1735 :
1736 : /// isTypeName - Return true if using decl has 'typename'.
1737 16: bool isTypeName() const { return IsTypeName; }
1738 :
1739 : typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator;
1740 11: shadow_iterator shadow_begin() const { return Shadows.begin(); }
1741 10: shadow_iterator shadow_end() const { return Shadows.end(); }
1742 :
1743 117: void addShadowDecl(UsingShadowDecl *S) {
1744 117: assert(S->getUsingDecl() == this);
1745 117: if (!Shadows.insert(S)) {
1746 0: assert(false && "declaration already in set");
1747 : }
1748 117: }
1749 3: void removeShadowDecl(UsingShadowDecl *S) {
1750 3: assert(S->getUsingDecl() == this);
1751 3: if (!Shadows.erase(S)) {
1752 0: assert(false && "declaration not in set");
1753 : }
1754 3: }
1755 :
1756 : static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1757 : SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL,
1758 : NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg);
1759 :
1760 872: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1761 : static bool classof(const UsingDecl *D) { return true; }
1762 872: static bool classofKind(Kind K) { return K == Decl::Using; }
1763 : };
1764 :
1765 : /// UnresolvedUsingValueDecl - Represents a dependent using
1766 : /// declaration which was not marked with 'typename'. Unlike
1767 : /// non-dependent using declarations, these *only* bring through
1768 : /// non-types; otherwise they would break two-phase lookup.
1769 : ///
1770 : /// template <class T> class A : public Base<T> {
1771 : /// using Base<T>::foo;
1772 : /// };
1773 0: class UnresolvedUsingValueDecl : public ValueDecl {
1774 : /// \brief The source range that covers the nested-name-specifier
1775 : /// preceding the declaration name.
1776 : SourceRange TargetNestedNameRange;
1777 :
1778 : /// \brief The source location of the 'using' keyword
1779 : SourceLocation UsingLocation;
1780 :
1781 : NestedNameSpecifier *TargetNestedNameSpecifier;
1782 :
1783 : UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
1784 : SourceLocation UsingLoc, SourceRange TargetNNR,
1785 : NestedNameSpecifier *TargetNNS,
1786 : SourceLocation TargetNameLoc,
1787 16: DeclarationName TargetName)
1788 : : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty),
1789 : TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1790 16: TargetNestedNameSpecifier(TargetNNS)
1791 16: { }
1792 :
1793 : public:
1794 : /// \brief Returns the source range that covers the nested-name-specifier
1795 : /// preceding the namespace name.
1796 24: SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1797 :
1798 : /// \brief Get target nested name declaration.
1799 14: NestedNameSpecifier* getTargetNestedNameSpecifier() {
1800 14: return TargetNestedNameSpecifier;
1801 : }
1802 :
1803 : /// \brief Returns the source location of the 'using' keyword.
1804 12: SourceLocation getUsingLoc() const { return UsingLocation; }
1805 :
1806 : static UnresolvedUsingValueDecl *
1807 : Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1808 : SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1809 : SourceLocation TargetNameLoc, DeclarationName TargetName);
1810 :
1811 94905: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1812 : static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
1813 94905: static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingValue; }
1814 : };
1815 :
1816 : /// UnresolvedUsingTypenameDecl - Represents a dependent using
1817 : /// declaration which was marked with 'typename'.
1818 : ///
1819 : /// template <class T> class A : public Base<T> {
1820 : /// using typename Base<T>::foo;
1821 : /// };
1822 : ///
1823 : /// The type associated with a unresolved using typename decl is
1824 : /// currently always a typename type.
1825 0: class UnresolvedUsingTypenameDecl : public TypeDecl {
1826 : /// \brief The source range that covers the nested-name-specifier
1827 : /// preceding the declaration name.
1828 : SourceRange TargetNestedNameRange;
1829 :
1830 : /// \brief The source location of the 'using' keyword
1831 : SourceLocation UsingLocation;
1832 :
1833 : /// \brief The source location of the 'typename' keyword
1834 : SourceLocation TypenameLocation;
1835 :
1836 : NestedNameSpecifier *TargetNestedNameSpecifier;
1837 :
1838 : UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
1839 : SourceLocation TypenameLoc,
1840 : SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1841 4: SourceLocation TargetNameLoc, IdentifierInfo *TargetName)
1842 : : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName),
1843 : TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1844 4: TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS)
1845 4: { }
1846 :
1847 : public:
1848 : /// \brief Returns the source range that covers the nested-name-specifier
1849 : /// preceding the namespace name.
1850 8: SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1851 :
1852 : /// \brief Get target nested name declaration.
1853 4: NestedNameSpecifier* getTargetNestedNameSpecifier() {
1854 4: return TargetNestedNameSpecifier;
1855 : }
1856 :
1857 : /// \brief Returns the source location of the 'using' keyword.
1858 4: SourceLocation getUsingLoc() const { return UsingLocation; }
1859 :
1860 : /// \brief Returns the source location of the 'typename' keyword.
1861 4: SourceLocation getTypenameLoc() const { return TypenameLocation; }
1862 :
1863 : static UnresolvedUsingTypenameDecl *
1864 : Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1865 : SourceLocation TypenameLoc,
1866 : SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1867 : SourceLocation TargetNameLoc, DeclarationName TargetName);
1868 :
1869 9662: static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1870 : static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
1871 9662: static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingTypename; }
1872 : };
1873 :
1874 : /// StaticAssertDecl - Represents a C++0x static_assert declaration.
1875 : class StaticAssertDecl : public Decl {
1876 : Expr *AssertExpr;
1877 : StringLiteral *Message;
1878 :
1879 : StaticAssertDecl(DeclContext *DC, SourceLocation L,
1880 64: Expr *assertexpr, StringLiteral *message)
1881 64: : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
1882 :
1883 : public:
1884 : static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
1885 : SourceLocation L, Expr *AssertExpr,
1886 : StringLiteral *Message);
1887 :
1888 4: Expr *getAssertExpr() { return AssertExpr; }
1889 : const Expr *getAssertExpr() const { return AssertExpr; }
1890 :
1891 8: StringLiteral *getMessage() { return Message; }
1892 : const StringLiteral *getMessage() const { return Message; }
1893 :
1894 : virtual ~StaticAssertDecl();
1895 : virtual void Destroy(ASTContext& C);
1896 :
1897 : static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1898 : static bool classof(StaticAssertDecl *D) { return true; }
1899 : static bool classofKind(Kind K) { return K == Decl::StaticAssert; }
1900 : };
1901 :
1902 : /// Insertion operator for diagnostics. This allows sending AccessSpecifier's
1903 : /// into a diagnostic with <<.
1904 : const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1905 : AccessSpecifier AS);
1906 :
1907 : } // end namespace clang
1908 :
1909 : #endif
Generated: 2010-02-10 01:31 by zcov