1 //===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the C++ Decl subclasses, other than those for
11 // templates (in DeclTemplate.h) and friends (in DeclFriend.h).
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_DECLCXX_H
16 #define LLVM_CLANG_AST_DECLCXX_H
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/Decl.h"
20 #include "clang/AST/TypeLoc.h"
21 #include "clang/AST/UnresolvedSet.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/SmallPtrSet.h"
27 class ClassTemplateDecl;
28 class ClassTemplateSpecializationDecl;
31 class CXXConstructorDecl;
32 class CXXConversionDecl;
33 class CXXDestructorDecl;
36 class CXXMemberLookupCriteria;
37 class CXXFinalOverriderMap;
40 /// \brief Represents any kind of function declaration, whether it is a
41 /// concrete function or a function template.
42 class AnyFunctionDecl {
45 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
48 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
49 AnyFunctionDecl(FunctionTemplateDecl *FTD);
51 /// \brief Implicily converts any function or function template into a
52 /// named declaration.
53 operator NamedDecl *() const { return Function; }
55 /// \brief Retrieve the underlying function or function template.
56 NamedDecl *get() const { return Function; }
58 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
59 return AnyFunctionDecl(ND);
63 } // end namespace clang
66 /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
67 /// AnyFunctionDecl to any function or function template declaration.
68 template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
69 typedef ::clang::NamedDecl* SimpleType;
70 static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
74 template<> struct simplify_type< ::clang::AnyFunctionDecl>
75 : public simplify_type<const ::clang::AnyFunctionDecl> {};
77 // Provide PointerLikeTypeTraits for non-cvr pointers.
79 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
81 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
84 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
85 return ::clang::AnyFunctionDecl::getFromNamedDecl(
86 static_cast< ::clang::NamedDecl*>(P));
89 enum { NumLowBitsAvailable = 2 };
92 } // end namespace llvm
96 /// AccessSpecDecl - An access specifier followed by colon ':'.
98 /// An objects of this class represents sugar for the syntactic occurrence
99 /// of an access specifier followed by a colon in the list of member
100 /// specifiers of a C++ class definition.
102 /// Note that they do not represent other uses of access specifiers,
103 /// such as those occurring in a list of base specifiers.
104 /// Also note that this class has nothing to do with so-called
105 /// "access declarations" (C++98 11.3 [class.access.dcl]).
106 class AccessSpecDecl : public Decl {
107 /// ColonLoc - The location of the ':'.
108 SourceLocation ColonLoc;
110 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
111 SourceLocation ASLoc, SourceLocation ColonLoc)
112 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
116 /// getAccessSpecifierLoc - The location of the access specifier.
117 SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
118 /// setAccessSpecifierLoc - Sets the location of the access specifier.
119 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
121 /// getColonLoc - The location of the colon following the access specifier.
122 SourceLocation getColonLoc() const { return ColonLoc; }
123 /// setColonLoc - Sets the location of the colon.
124 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
126 SourceRange getSourceRange() const {
127 return SourceRange(getAccessSpecifierLoc(), getColonLoc());
130 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
131 DeclContext *DC, SourceLocation ASLoc,
132 SourceLocation ColonLoc) {
133 return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
136 // Implement isa/cast/dyncast/etc.
137 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
138 static bool classof(const AccessSpecDecl *D) { return true; }
139 static bool classofKind(Kind K) { return K == AccessSpec; }
143 /// CXXBaseSpecifier - A base class of a C++ class.
145 /// Each CXXBaseSpecifier represents a single, direct base class (or
146 /// struct) of a C++ class (or struct). It specifies the type of that
147 /// base class, whether it is a virtual or non-virtual base, and what
148 /// level of access (public, protected, private) is used for the
149 /// derivation. For example:
154 /// class C : public virtual A, protected B { };
157 /// In this code, C will have two CXXBaseSpecifiers, one for "public
158 /// virtual A" and the other for "protected B".
159 class CXXBaseSpecifier {
160 /// Range - The source code range that covers the full base
161 /// specifier, including the "virtual" (if present) and access
162 /// specifier (if present).
165 /// Virtual - Whether this is a virtual base class or not.
168 /// BaseOfClass - Whether this is the base of a class (true) or of a
169 /// struct (false). This determines the mapping from the access
170 /// specifier as written in the source code to the access specifier
171 /// used for semantic analysis.
172 bool BaseOfClass : 1;
174 /// Access - Access specifier as written in the source code (which
175 /// may be AS_none). The actual type of data stored here is an
176 /// AccessSpecifier, but we use "unsigned" here to work around a
180 /// BaseTypeInfo - The type of the base class. This will be a class or struct
181 /// (or a typedef of such). The source code range does not include the
182 /// "virtual" or access specifier.
183 TypeSourceInfo *BaseTypeInfo;
186 CXXBaseSpecifier() { }
188 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
189 TypeSourceInfo *TInfo)
190 : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseTypeInfo(TInfo) { }
192 /// getSourceRange - Retrieves the source range that contains the
193 /// entire base specifier.
194 SourceRange getSourceRange() const { return Range; }
196 /// isVirtual - Determines whether the base class is a virtual base
198 bool isVirtual() const { return Virtual; }
200 /// \brief Determine whether this base class is a base of a class declared
201 /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
202 bool isBaseOfClass() const { return BaseOfClass; }
204 /// getAccessSpecifier - Returns the access specifier for this base
205 /// specifier. This is the actual base specifier as used for
206 /// semantic analysis, so the result can never be AS_none. To
207 /// retrieve the access specifier as written in the source code, use
208 /// getAccessSpecifierAsWritten().
209 AccessSpecifier getAccessSpecifier() const {
210 if ((AccessSpecifier)Access == AS_none)
211 return BaseOfClass? AS_private : AS_public;
213 return (AccessSpecifier)Access;
216 /// getAccessSpecifierAsWritten - Retrieves the access specifier as
217 /// written in the source code (which may mean that no access
218 /// specifier was explicitly written). Use getAccessSpecifier() to
219 /// retrieve the access specifier for use in semantic analysis.
220 AccessSpecifier getAccessSpecifierAsWritten() const {
221 return (AccessSpecifier)Access;
224 /// getType - Retrieves the type of the base class. This type will
225 /// always be an unqualified class type.
226 QualType getType() const { return BaseTypeInfo->getType(); }
228 /// getTypeLoc - Retrieves the type and source location of the base class.
229 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
232 /// CXXRecordDecl - Represents a C++ struct/union/class.
233 /// FIXME: This class will disappear once we've properly taught RecordDecl
234 /// to deal with C++-specific things.
235 class CXXRecordDecl : public RecordDecl {
237 friend void TagDecl::startDefinition();
239 struct DefinitionData {
240 DefinitionData(CXXRecordDecl *D);
242 /// UserDeclaredConstructor - True when this class has a
243 /// user-declared constructor.
244 bool UserDeclaredConstructor : 1;
246 /// UserDeclaredCopyConstructor - True when this class has a
247 /// user-declared copy constructor.
248 bool UserDeclaredCopyConstructor : 1;
250 /// UserDeclaredCopyAssignment - True when this class has a
251 /// user-declared copy assignment operator.
252 bool UserDeclaredCopyAssignment : 1;
254 /// UserDeclaredDestructor - True when this class has a
255 /// user-declared destructor.
256 bool UserDeclaredDestructor : 1;
258 /// Aggregate - True when this class is an aggregate.
261 /// PlainOldData - True when this class is a POD-type.
262 bool PlainOldData : 1;
264 /// Empty - true when this class is empty for traits purposes,
265 /// i.e. has no data members other than 0-width bit-fields, has no
266 /// virtual function/base, and doesn't inherit from a non-empty
267 /// class. Doesn't take union-ness into account.
270 /// Polymorphic - True when this class is polymorphic, i.e. has at
271 /// least one virtual member or derives from a polymorphic class.
272 bool Polymorphic : 1;
274 /// Abstract - True when this class is abstract, i.e. has at least
275 /// one pure virtual function, (that can come from a base class).
278 /// HasTrivialConstructor - True when this class has a trivial constructor.
280 /// C++ [class.ctor]p5. A constructor is trivial if it is an
281 /// implicitly-declared default constructor and if:
282 /// * its class has no virtual functions and no virtual base classes, and
283 /// * all the direct base classes of its class have trivial constructors, and
284 /// * for all the nonstatic data members of its class that are of class type
285 /// (or array thereof), each such class has a trivial constructor.
286 bool HasTrivialConstructor : 1;
288 /// HasTrivialCopyConstructor - True when this class has a trivial copy
291 /// C++ [class.copy]p6. A copy constructor for class X is trivial
292 /// if it is implicitly declared and if
293 /// * class X has no virtual functions and no virtual base classes, and
294 /// * each direct base class of X has a trivial copy constructor, and
295 /// * for all the nonstatic data members of X that are of class type (or
296 /// array thereof), each such class type has a trivial copy constructor;
297 /// otherwise the copy constructor is non-trivial.
298 bool HasTrivialCopyConstructor : 1;
300 /// HasTrivialCopyAssignment - True when this class has a trivial copy
301 /// assignment operator.
303 /// C++ [class.copy]p11. A copy assignment operator for class X is
304 /// trivial if it is implicitly declared and if
305 /// * class X has no virtual functions and no virtual base classes, and
306 /// * each direct base class of X has a trivial copy assignment operator, and
307 /// * for all the nonstatic data members of X that are of class type (or
308 /// array thereof), each such class type has a trivial copy assignment
310 /// otherwise the copy assignment operator is non-trivial.
311 bool HasTrivialCopyAssignment : 1;
313 /// HasTrivialDestructor - True when this class has a trivial destructor.
315 /// C++ [class.dtor]p3. A destructor is trivial if it is an
316 /// implicitly-declared destructor and if:
317 /// * all of the direct base classes of its class have trivial destructors
319 /// * for all of the non-static data members of its class that are of class
320 /// type (or array thereof), each such class has a trivial destructor.
321 bool HasTrivialDestructor : 1;
323 /// ComputedVisibleConversions - True when visible conversion functions are
324 /// already computed and are available.
325 bool ComputedVisibleConversions : 1;
327 /// \brief Whether we have already declared the default constructor or
328 /// do not need to have one declared.
329 bool DeclaredDefaultConstructor : 1;
331 /// \brief Whether we have already declared the copy constructor.
332 bool DeclaredCopyConstructor : 1;
334 /// \brief Whether we have already declared the copy-assignment operator.
335 bool DeclaredCopyAssignment : 1;
337 /// \brief Whether we have already declared a destructor within the class.
338 bool DeclaredDestructor : 1;
340 /// Bases - Base classes of this class.
341 /// FIXME: This is wasted space for a union.
342 CXXBaseSpecifier *Bases;
344 /// NumBases - The number of base class specifiers in Bases.
347 /// VBases - direct and indirect virtual base classes of this class.
348 CXXBaseSpecifier *VBases;
350 /// NumVBases - The number of virtual base class specifiers in VBases.
353 /// Conversions - Overload set containing the conversion functions
354 /// of this C++ class (but not its inherited conversion
355 /// functions). Each of the entries in this overload set is a
356 /// CXXConversionDecl.
357 UnresolvedSet<4> Conversions;
359 /// VisibleConversions - Overload set containing the conversion
360 /// functions of this C++ class and all those inherited conversion
361 /// functions that are visible in this class. Each of the entries
362 /// in this overload set is a CXXConversionDecl or a
363 /// FunctionTemplateDecl.
364 UnresolvedSet<4> VisibleConversions;
366 /// Definition - The declaration which defines this record.
367 CXXRecordDecl *Definition;
369 /// FirstFriend - The first friend declaration in this class, or
370 /// null if there aren't any. This is actually currently stored
371 /// in reverse order.
372 FriendDecl *FirstFriend;
376 struct DefinitionData &data() {
377 assert(DefinitionData && "queried property of class with no definition");
378 return *DefinitionData;
381 const struct DefinitionData &data() const {
382 assert(DefinitionData && "queried property of class with no definition");
383 return *DefinitionData;
386 /// \brief The template or declaration that this declaration
387 /// describes or was instantiated from, respectively.
389 /// For non-templates, this value will be NULL. For record
390 /// declarations that describe a class template, this will be a
391 /// pointer to a ClassTemplateDecl. For member
392 /// classes of class template specializations, this will be the
393 /// MemberSpecializationInfo referring to the member class that was
394 /// instantiated or specialized.
395 llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
396 TemplateOrInstantiation;
399 void CheckConversionFunction(NamedDecl *D);
403 CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
404 SourceLocation L, IdentifierInfo *Id,
405 CXXRecordDecl *PrevDecl,
406 SourceLocation TKL = SourceLocation());
409 /// base_class_iterator - Iterator that traverses the base classes
411 typedef CXXBaseSpecifier* base_class_iterator;
413 /// base_class_const_iterator - Iterator that traverses the base
414 /// classes of a class.
415 typedef const CXXBaseSpecifier* base_class_const_iterator;
417 /// reverse_base_class_iterator = Iterator that traverses the base classes
418 /// of a class in reverse order.
419 typedef std::reverse_iterator<base_class_iterator>
420 reverse_base_class_iterator;
422 /// reverse_base_class_iterator = Iterator that traverses the base classes
423 /// of a class in reverse order.
424 typedef std::reverse_iterator<base_class_const_iterator>
425 reverse_base_class_const_iterator;
427 virtual CXXRecordDecl *getCanonicalDecl() {
428 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
430 virtual const CXXRecordDecl *getCanonicalDecl() const {
431 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
434 const CXXRecordDecl *getPreviousDeclaration() const {
435 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration());
437 CXXRecordDecl *getPreviousDeclaration() {
438 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDeclaration());
441 CXXRecordDecl *getDefinition() const {
442 if (!DefinitionData) return 0;
443 return data().Definition;
446 bool hasDefinition() const { return DefinitionData != 0; }
448 static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
449 SourceLocation L, IdentifierInfo *Id,
450 SourceLocation TKL = SourceLocation(),
451 CXXRecordDecl* PrevDecl=0,
452 bool DelayTypeCreation = false);
453 static CXXRecordDecl *Create(ASTContext &C, EmptyShell Empty);
455 bool isDynamicClass() const {
456 return data().Polymorphic || data().NumVBases != 0;
459 /// setBases - Sets the base classes of this struct or class.
460 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
462 /// getNumBases - Retrieves the number of base classes of this
464 unsigned getNumBases() const { return data().NumBases; }
466 base_class_iterator bases_begin() { return data().Bases; }
467 base_class_const_iterator bases_begin() const { return data().Bases; }
468 base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
469 base_class_const_iterator bases_end() const {
470 return bases_begin() + data().NumBases;
472 reverse_base_class_iterator bases_rbegin() {
473 return reverse_base_class_iterator(bases_end());
475 reverse_base_class_const_iterator bases_rbegin() const {
476 return reverse_base_class_const_iterator(bases_end());
478 reverse_base_class_iterator bases_rend() {
479 return reverse_base_class_iterator(bases_begin());
481 reverse_base_class_const_iterator bases_rend() const {
482 return reverse_base_class_const_iterator(bases_begin());
485 /// getNumVBases - Retrieves the number of virtual base classes of this
487 unsigned getNumVBases() const { return data().NumVBases; }
489 base_class_iterator vbases_begin() { return data().VBases; }
490 base_class_const_iterator vbases_begin() const { return data().VBases; }
491 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
492 base_class_const_iterator vbases_end() const {
493 return vbases_begin() + data().NumVBases;
495 reverse_base_class_iterator vbases_rbegin() {
496 return reverse_base_class_iterator(vbases_end());
498 reverse_base_class_const_iterator vbases_rbegin() const {
499 return reverse_base_class_const_iterator(vbases_end());
501 reverse_base_class_iterator vbases_rend() {
502 return reverse_base_class_iterator(vbases_begin());
504 reverse_base_class_const_iterator vbases_rend() const {
505 return reverse_base_class_const_iterator(vbases_begin());
508 /// \brief Determine whether this class has any dependent base classes.
509 bool hasAnyDependentBases() const;
511 /// Iterator access to method members. The method iterator visits
512 /// all method members of the class, including non-instance methods,
513 /// special methods, etc.
514 typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
516 /// method_begin - Method begin iterator. Iterates in the order the methods
518 method_iterator method_begin() const {
519 return method_iterator(decls_begin());
521 /// method_end - Method end iterator.
522 method_iterator method_end() const {
523 return method_iterator(decls_end());
526 /// Iterator access to constructor members.
527 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
529 ctor_iterator ctor_begin() const {
530 return ctor_iterator(decls_begin());
532 ctor_iterator ctor_end() const {
533 return ctor_iterator(decls_end());
536 /// An iterator over friend declarations. All of these are defined
538 class friend_iterator;
539 friend_iterator friend_begin() const;
540 friend_iterator friend_end() const;
541 void pushFriendDecl(FriendDecl *FD);
543 /// Determines whether this record has any friends.
544 bool hasFriends() const {
545 return data().FirstFriend != 0;
548 /// \brief Determine whether this class has had its default constructor
549 /// declared implicitly or does not need one declared implicitly.
551 /// This value is used for lazy creation of default constructors.
552 bool hasDeclaredDefaultConstructor() const {
553 return data().DeclaredDefaultConstructor;
556 /// \brief Note whether this class has already had its default constructor
557 /// implicitly declared or doesn't need one.
558 void setDeclaredDefaultConstructor(bool DDC) {
559 data().DeclaredDefaultConstructor = DDC;
562 /// hasConstCopyConstructor - Determines whether this class has a
563 /// copy constructor that accepts a const-qualified argument.
564 bool hasConstCopyConstructor(ASTContext &Context) const;
566 /// getCopyConstructor - Returns the copy constructor for this class
567 CXXConstructorDecl *getCopyConstructor(ASTContext &Context,
568 unsigned TypeQuals) const;
570 /// \brief Retrieve the copy-assignment operator for this class, if available.
572 /// This routine attempts to find the copy-assignment operator for this
573 /// class, using a simplistic form of overload resolution.
575 /// \param ArgIsConst Whether the argument to the copy-assignment operator
576 /// is const-qualified.
578 /// \returns The copy-assignment operator that can be invoked, or NULL if
579 /// a unique copy-assignment operator could not be found.
580 CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const;
582 /// addedConstructor - Notify the class that another constructor has
583 /// been added. This routine helps maintain information about the
584 /// class based on which constructors have been added.
585 void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
587 /// hasUserDeclaredConstructor - Whether this class has any
588 /// user-declared constructors. When true, a default constructor
589 /// will not be implicitly declared.
590 bool hasUserDeclaredConstructor() const {
591 return data().UserDeclaredConstructor;
594 /// hasUserDeclaredCopyConstructor - Whether this class has a
595 /// user-declared copy constructor. When false, a copy constructor
596 /// will be implicitly declared.
597 bool hasUserDeclaredCopyConstructor() const {
598 return data().UserDeclaredCopyConstructor;
601 /// \brief Determine whether this class has had its copy constructor
602 /// declared, either via the user or via an implicit declaration.
604 /// This value is used for lazy creation of copy constructors.
605 bool hasDeclaredCopyConstructor() const {
606 return data().DeclaredCopyConstructor;
609 /// \brief Note whether this class has already had its copy constructor
611 void setDeclaredCopyConstructor(bool DCC) {
612 data().DeclaredCopyConstructor = DCC;
615 /// addedAssignmentOperator - Notify the class that another assignment
616 /// operator has been added. This routine helps maintain information about the
617 /// class based on which operators have been added.
618 void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);
620 /// hasUserDeclaredCopyAssignment - Whether this class has a
621 /// user-declared copy assignment operator. When false, a copy
622 /// assigment operator will be implicitly declared.
623 bool hasUserDeclaredCopyAssignment() const {
624 return data().UserDeclaredCopyAssignment;
627 /// \brief Determine whether this class has had its copy assignment operator
628 /// declared, either via the user or via an implicit declaration.
630 /// This value is used for lazy creation of copy assignment operators.
631 bool hasDeclaredCopyAssignment() const {
632 return data().DeclaredCopyAssignment;
635 /// \brief Note whether this class has already had its copy assignment
636 /// operator declared.
637 void setDeclaredCopyAssignment(bool DCA) {
638 data().DeclaredCopyAssignment = DCA;
641 /// hasUserDeclaredDestructor - Whether this class has a
642 /// user-declared destructor. When false, a destructor will be
643 /// implicitly declared.
644 bool hasUserDeclaredDestructor() const {
645 return data().UserDeclaredDestructor;
648 /// setUserDeclaredDestructor - Set whether this class has a
649 /// user-declared destructor. If not set by the time the class is
650 /// fully defined, a destructor will be implicitly declared.
651 void setUserDeclaredDestructor(bool UCD) {
652 data().UserDeclaredDestructor = UCD;
654 data().DeclaredDestructor = true;
657 /// \brief Determine whether this class has had its destructor declared,
658 /// either via the user or via an implicit declaration.
660 /// This value is used for lazy creation of destructors.
661 bool hasDeclaredDestructor() const { return data().DeclaredDestructor; }
663 /// \brief Note whether this class has already had its destructor declared.
664 void setDeclaredDestructor(bool DD) {
665 data().DeclaredDestructor = DD;
668 /// getConversions - Retrieve the overload set containing all of the
669 /// conversion functions in this class.
670 UnresolvedSetImpl *getConversionFunctions() {
671 return &data().Conversions;
673 const UnresolvedSetImpl *getConversionFunctions() const {
674 return &data().Conversions;
677 typedef UnresolvedSetImpl::iterator conversion_iterator;
678 conversion_iterator conversion_begin() const {
679 return getConversionFunctions()->begin();
681 conversion_iterator conversion_end() const {
682 return getConversionFunctions()->end();
685 /// Replaces a conversion function with a new declaration.
687 /// Returns true if the old conversion was found.
688 bool replaceConversion(const NamedDecl* Old, NamedDecl *New) {
689 return getConversionFunctions()->replace(Old, New);
692 /// Removes a conversion function from this class. The conversion
693 /// function must currently be a member of this class. Furthermore,
694 /// this class must currently be in the process of being defined.
695 void removeConversion(const NamedDecl *Old);
697 /// getVisibleConversionFunctions - get all conversion functions visible
698 /// in current class; including conversion function templates.
699 const UnresolvedSetImpl *getVisibleConversionFunctions();
701 /// addConversionFunction - Registers a conversion function which
702 /// this class declares directly.
703 void addConversionFunction(NamedDecl *Decl) {
705 CheckConversionFunction(Decl);
708 // We intentionally don't use the decl's access here because it
709 // hasn't been set yet. That's really just a misdesign in Sema.
710 data().Conversions.addDecl(Decl);
713 /// isAggregate - Whether this class is an aggregate (C++
714 /// [dcl.init.aggr]), which is a class with no user-declared
715 /// constructors, no private or protected non-static data members,
716 /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
717 bool isAggregate() const { return data().Aggregate; }
719 /// setAggregate - Set whether this class is an aggregate (C++
720 /// [dcl.init.aggr]).
721 void setAggregate(bool Agg) { data().Aggregate = Agg; }
723 /// setMethodAsVirtual - Make input method virtual and set the necesssary
724 /// special function bits and other bits accordingly.
725 void setMethodAsVirtual(FunctionDecl *Method);
727 /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
728 /// that is an aggregate that has no non-static non-POD data members, no
729 /// reference data members, no user-defined copy assignment operator and no
730 /// user-defined destructor.
731 bool isPOD() const { return data().PlainOldData; }
733 /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
734 void setPOD(bool POD) { data().PlainOldData = POD; }
736 /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
737 /// means it has a virtual function, virtual base, data member (other than
738 /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
739 /// a check for union-ness.
740 bool isEmpty() const { return data().Empty; }
742 /// Set whether this class is empty (C++0x [meta.unary.prop])
743 void setEmpty(bool Emp) { data().Empty = Emp; }
745 /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
746 /// which means that the class contains or inherits a virtual function.
747 bool isPolymorphic() const { return data().Polymorphic; }
749 /// setPolymorphic - Set whether this class is polymorphic (C++
750 /// [class.virtual]).
751 void setPolymorphic(bool Poly) { data().Polymorphic = Poly; }
753 /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
754 /// which means that the class contains or inherits a pure virtual function.
755 bool isAbstract() const { return data().Abstract; }
757 /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
758 void setAbstract(bool Abs) { data().Abstract = Abs; }
760 // hasTrivialConstructor - Whether this class has a trivial constructor
761 // (C++ [class.ctor]p5)
762 bool hasTrivialConstructor() const { return data().HasTrivialConstructor; }
764 // setHasTrivialConstructor - Set whether this class has a trivial constructor
765 // (C++ [class.ctor]p5)
766 void setHasTrivialConstructor(bool TC) { data().HasTrivialConstructor = TC; }
768 // hasTrivialCopyConstructor - Whether this class has a trivial copy
769 // constructor (C++ [class.copy]p6)
770 bool hasTrivialCopyConstructor() const {
771 return data().HasTrivialCopyConstructor;
774 // setHasTrivialCopyConstructor - Set whether this class has a trivial
775 // copy constructor (C++ [class.copy]p6)
776 void setHasTrivialCopyConstructor(bool TC) {
777 data().HasTrivialCopyConstructor = TC;
780 // hasTrivialCopyAssignment - Whether this class has a trivial copy
781 // assignment operator (C++ [class.copy]p11)
782 bool hasTrivialCopyAssignment() const {
783 return data().HasTrivialCopyAssignment;
786 // setHasTrivialCopyAssignment - Set whether this class has a
787 // trivial copy assignment operator (C++ [class.copy]p11)
788 void setHasTrivialCopyAssignment(bool TC) {
789 data().HasTrivialCopyAssignment = TC;
792 // hasTrivialDestructor - Whether this class has a trivial destructor
793 // (C++ [class.dtor]p3)
794 bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
796 // setHasTrivialDestructor - Set whether this class has a trivial destructor
797 // (C++ [class.dtor]p3)
798 void setHasTrivialDestructor(bool TC) { data().HasTrivialDestructor = TC; }
800 /// \brief If this record is an instantiation of a member class,
801 /// retrieves the member class from which it was instantiated.
803 /// This routine will return non-NULL for (non-templated) member
804 /// classes of class templates. For example, given:
807 /// template<typename T>
813 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
814 /// whose parent is the class template specialization X<int>. For
815 /// this declaration, getInstantiatedFromMemberClass() will return
816 /// the CXXRecordDecl X<T>::A. When a complete definition of
817 /// X<int>::A is required, it will be instantiated from the
818 /// declaration returned by getInstantiatedFromMemberClass().
819 CXXRecordDecl *getInstantiatedFromMemberClass() const;
821 /// \brief If this class is an instantiation of a member class of a
822 /// class template specialization, retrieves the member specialization
824 MemberSpecializationInfo *getMemberSpecializationInfo() const;
826 /// \brief Specify that this record is an instantiation of the
828 void setInstantiationOfMemberClass(CXXRecordDecl *RD,
829 TemplateSpecializationKind TSK);
831 /// \brief Retrieves the class template that is described by this
832 /// class declaration.
834 /// Every class template is represented as a ClassTemplateDecl and a
835 /// CXXRecordDecl. The former contains template properties (such as
836 /// the template parameter lists) while the latter contains the
837 /// actual description of the template's
838 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
839 /// CXXRecordDecl that from a ClassTemplateDecl, while
840 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
842 ClassTemplateDecl *getDescribedClassTemplate() const {
843 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
846 void setDescribedClassTemplate(ClassTemplateDecl *Template) {
847 TemplateOrInstantiation = Template;
850 /// \brief Determine whether this particular class is a specialization or
851 /// instantiation of a class template or member class of a class template,
852 /// and how it was instantiated or specialized.
853 TemplateSpecializationKind getTemplateSpecializationKind() const;
855 /// \brief Set the kind of specialization or template instantiation this is.
856 void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
858 /// getDefaultConstructor - Returns the default constructor for this class
859 CXXConstructorDecl *getDefaultConstructor();
861 /// getDestructor - Returns the destructor decl for this class.
862 CXXDestructorDecl *getDestructor() const;
864 /// isLocalClass - If the class is a local class [class.local], returns
865 /// the enclosing function declaration.
866 const FunctionDecl *isLocalClass() const {
867 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
868 return RD->isLocalClass();
870 return dyn_cast<FunctionDecl>(getDeclContext());
873 /// \brief Determine whether this class is derived from the class \p Base.
875 /// This routine only determines whether this class is derived from \p Base,
876 /// but does not account for factors that may make a Derived -> Base class
877 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
878 /// base class subobjects.
880 /// \param Base the base class we are searching for.
882 /// \returns true if this class is derived from Base, false otherwise.
883 bool isDerivedFrom(CXXRecordDecl *Base) const;
885 /// \brief Determine whether this class is derived from the type \p Base.
887 /// This routine only determines whether this class is derived from \p Base,
888 /// but does not account for factors that may make a Derived -> Base class
889 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
890 /// base class subobjects.
892 /// \param Base the base class we are searching for.
894 /// \param Paths will contain the paths taken from the current class to the
895 /// given \p Base class.
897 /// \returns true if this class is derived from Base, false otherwise.
899 /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
900 /// tangling input and output in \p Paths
901 bool isDerivedFrom(CXXRecordDecl *Base, CXXBasePaths &Paths) const;
903 /// \brief Determine whether this class is virtually derived from
904 /// the class \p Base.
906 /// This routine only determines whether this class is virtually
907 /// derived from \p Base, but does not account for factors that may
908 /// make a Derived -> Base class ill-formed, such as
909 /// private/protected inheritance or multiple, ambiguous base class
912 /// \param Base the base class we are searching for.
914 /// \returns true if this class is virtually derived from Base,
916 bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const;
918 /// \brief Determine whether this class is provably not derived from
919 /// the type \p Base.
920 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
922 /// \brief Function type used by forallBases() as a callback.
924 /// \param Base the definition of the base class
926 /// \returns true if this base matched the search criteria
927 typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
930 /// \brief Determines if the given callback holds for all the direct
931 /// or indirect base classes of this type.
933 /// The class itself does not count as a base class. This routine
934 /// returns false if the class has non-computable base classes.
936 /// \param AllowShortCircuit if false, forces the callback to be called
937 /// for every base class, even if a dependent or non-matching base was
939 bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
940 bool AllowShortCircuit = true) const;
942 /// \brief Function type used by lookupInBases() to determine whether a
943 /// specific base class subobject matches the lookup criteria.
945 /// \param Specifier the base-class specifier that describes the inheritance
946 /// from the base class we are trying to match.
948 /// \param Path the current path, from the most-derived class down to the
949 /// base named by the \p Specifier.
951 /// \param UserData a single pointer to user-specified data, provided to
954 /// \returns true if this base matched the search criteria, false otherwise.
955 typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
959 /// \brief Look for entities within the base classes of this C++ class,
960 /// transitively searching all base class subobjects.
962 /// This routine uses the callback function \p BaseMatches to find base
963 /// classes meeting some search criteria, walking all base class subobjects
964 /// and populating the given \p Paths structure with the paths through the
965 /// inheritance hierarchy that resulted in a match. On a successful search,
966 /// the \p Paths structure can be queried to retrieve the matching paths and
967 /// to determine if there were any ambiguities.
969 /// \param BaseMatches callback function used to determine whether a given
970 /// base matches the user-defined search criteria.
972 /// \param UserData user data pointer that will be provided to \p BaseMatches.
974 /// \param Paths used to record the paths from this class to its base class
975 /// subobjects that match the search criteria.
977 /// \returns true if there exists any path from this class to a base class
978 /// subobject that matches the search criteria.
979 bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
980 CXXBasePaths &Paths) const;
982 /// \brief Base-class lookup callback that determines whether the given
983 /// base class specifier refers to a specific class declaration.
985 /// This callback can be used with \c lookupInBases() to determine whether
986 /// a given derived class has is a base class subobject of a particular type.
987 /// The user data pointer should refer to the canonical CXXRecordDecl of the
988 /// base class that we are searching for.
989 static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
990 CXXBasePath &Path, void *BaseRecord);
992 /// \brief Base-class lookup callback that determines whether the
993 /// given base class specifier refers to a specific class
994 /// declaration and describes virtual derivation.
996 /// This callback can be used with \c lookupInBases() to determine
997 /// whether a given derived class has is a virtual base class
998 /// subobject of a particular type. The user data pointer should
999 /// refer to the canonical CXXRecordDecl of the base class that we
1000 /// are searching for.
1001 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1002 CXXBasePath &Path, void *BaseRecord);
1004 /// \brief Base-class lookup callback that determines whether there exists
1005 /// a tag with the given name.
1007 /// This callback can be used with \c lookupInBases() to find tag members
1008 /// of the given name within a C++ class hierarchy. The user data pointer
1009 /// is an opaque \c DeclarationName pointer.
1010 static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1011 CXXBasePath &Path, void *Name);
1013 /// \brief Base-class lookup callback that determines whether there exists
1014 /// a member with the given name.
1016 /// This callback can be used with \c lookupInBases() to find members
1017 /// of the given name within a C++ class hierarchy. The user data pointer
1018 /// is an opaque \c DeclarationName pointer.
1019 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1020 CXXBasePath &Path, void *Name);
1022 /// \brief Base-class lookup callback that determines whether there exists
1023 /// a member with the given name that can be used in a nested-name-specifier.
1025 /// This callback can be used with \c lookupInBases() to find membes of
1026 /// the given name within a C++ class hierarchy that can occur within
1027 /// nested-name-specifiers.
1028 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1032 /// \brief Retrieve the final overriders for each virtual member
1033 /// function in the class hierarchy where this class is the
1034 /// most-derived class in the class hierarchy.
1035 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1037 /// viewInheritance - Renders and displays an inheritance diagram
1038 /// for this C++ class and all of its base classes (transitively) using
1040 void viewInheritance(ASTContext& Context) const;
1042 /// MergeAccess - Calculates the access of a decl that is reached
1044 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1045 AccessSpecifier DeclAccess) {
1046 assert(DeclAccess != AS_none);
1047 if (DeclAccess == AS_private) return AS_none;
1048 return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1051 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1052 static bool classofKind(Kind K) {
1053 return K >= firstCXXRecord && K <= lastCXXRecord;
1055 static bool classof(const CXXRecordDecl *D) { return true; }
1056 static bool classof(const ClassTemplateSpecializationDecl *D) {
1060 friend class ASTDeclReader;
1061 friend class ASTDeclWriter;
1064 /// CXXMethodDecl - Represents a static or instance method of a
1065 /// struct/union/class.
1066 class CXXMethodDecl : public FunctionDecl {
1068 CXXMethodDecl(Kind DK, CXXRecordDecl *RD,
1069 const DeclarationNameInfo &NameInfo,
1070 QualType T, TypeSourceInfo *TInfo,
1071 bool isStatic, StorageClass SCAsWritten, bool isInline)
1072 : FunctionDecl(DK, RD, NameInfo, T, TInfo, (isStatic ? SC_Static : SC_None),
1073 SCAsWritten, isInline) {}
1076 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1077 const DeclarationNameInfo &NameInfo,
1078 QualType T, TypeSourceInfo *TInfo,
1079 bool isStatic = false,
1080 StorageClass SCAsWritten = SC_None,
1081 bool isInline = false);
1083 bool isStatic() const { return getStorageClass() == SC_Static; }
1084 bool isInstance() const { return !isStatic(); }
1086 bool isVirtual() const {
1088 cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1090 if (CD->isVirtualAsWritten())
1093 return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1096 /// \brief Determine whether this is a usual deallocation function
1097 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1098 /// delete or delete[] operator with a particular signature.
1099 bool isUsualDeallocationFunction() const;
1101 /// \brief Determine whether this is a copy-assignment operator, regardless
1102 /// of whether it was declared implicitly or explicitly.
1103 bool isCopyAssignmentOperator() const;
1105 const CXXMethodDecl *getCanonicalDecl() const {
1106 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1108 CXXMethodDecl *getCanonicalDecl() {
1109 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1113 void addOverriddenMethod(const CXXMethodDecl *MD);
1115 typedef const CXXMethodDecl ** method_iterator;
1117 method_iterator begin_overridden_methods() const;
1118 method_iterator end_overridden_methods() const;
1119 unsigned size_overridden_methods() const;
1121 /// getParent - Returns the parent of this method declaration, which
1122 /// is the class in which this method is defined.
1123 const CXXRecordDecl *getParent() const {
1124 return cast<CXXRecordDecl>(FunctionDecl::getParent());
1127 /// getParent - Returns the parent of this method declaration, which
1128 /// is the class in which this method is defined.
1129 CXXRecordDecl *getParent() {
1130 return const_cast<CXXRecordDecl *>(
1131 cast<CXXRecordDecl>(FunctionDecl::getParent()));
1134 /// getThisType - Returns the type of 'this' pointer.
1135 /// Should only be called for instance methods.
1136 QualType getThisType(ASTContext &C) const;
1138 unsigned getTypeQualifiers() const {
1139 return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1142 bool hasInlineBody() const;
1144 // Implement isa/cast/dyncast/etc.
1145 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1146 static bool classof(const CXXMethodDecl *D) { return true; }
1147 static bool classofKind(Kind K) {
1148 return K >= firstCXXMethod && K <= lastCXXMethod;
1152 /// CXXBaseOrMemberInitializer - Represents a C++ base or member
1153 /// initializer, which is part of a constructor initializer that
1154 /// initializes one non-static member variable or one base class. For
1155 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1160 /// class B : public A {
1163 /// B(A& a) : A(a), f(3.14159) { }
1166 class CXXBaseOrMemberInitializer {
1167 /// \brief Either the base class name (stored as a TypeSourceInfo*) or the
1168 /// field being initialized.
1169 llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember;
1171 /// \brief The source location for the field name.
1172 SourceLocation MemberLocation;
1174 /// \brief The argument used to initialize the base or member, which may
1175 /// end up constructing an object (when multiple arguments are involved).
1178 /// \brief Stores either the constructor to call to initialize this base or
1179 /// member (a CXXConstructorDecl pointer), or stores the anonymous union of
1180 /// which the initialized value is a member.
1182 /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's
1183 /// anonymous union data member, this field holds the FieldDecl for the
1184 /// member of the anonymous union being initialized.
1187 /// X() : au_i1(123) {}
1194 /// In above example, BaseOrMember holds the field decl. for anonymous union
1195 /// and AnonUnionMember holds field decl for au_i1.
1196 FieldDecl *AnonUnionMember;
1198 /// LParenLoc - Location of the left paren of the ctor-initializer.
1199 SourceLocation LParenLoc;
1201 /// RParenLoc - Location of the right paren of the ctor-initializer.
1202 SourceLocation RParenLoc;
1204 /// IsVirtual - If the initializer is a base initializer, this keeps track
1205 /// of whether the base is virtual or not.
1208 /// IsWritten - Whether or not the initializer is explicitly written
1211 /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this
1212 /// number keeps track of the textual order of this initializer in the
1213 /// original sources, counting from 0; otherwise, if IsWritten is false,
1214 /// it stores the number of array index variables stored after this
1215 /// object in memory.
1216 unsigned SourceOrderOrNumArrayIndices : 14;
1218 CXXBaseOrMemberInitializer(ASTContext &Context,
1219 FieldDecl *Member, SourceLocation MemberLoc,
1224 unsigned NumIndices);
1227 /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
1229 CXXBaseOrMemberInitializer(ASTContext &Context,
1230 TypeSourceInfo *TInfo, bool IsVirtual,
1235 /// CXXBaseOrMemberInitializer - Creates a new member initializer.
1237 CXXBaseOrMemberInitializer(ASTContext &Context,
1238 FieldDecl *Member, SourceLocation MemberLoc,
1243 /// \brief Creates a new member initializer that optionally contains
1244 /// array indices used to describe an elementwise initialization.
1245 static CXXBaseOrMemberInitializer *Create(ASTContext &Context,
1247 SourceLocation MemberLoc,
1252 unsigned NumIndices);
1254 /// isBaseInitializer - Returns true when this initializer is
1255 /// initializing a base class.
1256 bool isBaseInitializer() const { return BaseOrMember.is<TypeSourceInfo*>(); }
1258 /// isMemberInitializer - Returns true when this initializer is
1259 /// initializing a non-static data member.
1260 bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); }
1262 /// If this is a base class initializer, returns the type of the
1263 /// base class with location information. Otherwise, returns an NULL
1265 TypeLoc getBaseClassLoc() const;
1267 /// If this is a base class initializer, returns the type of the base class.
1268 /// Otherwise, returns NULL.
1269 const Type *getBaseClass() const;
1270 Type *getBaseClass();
1272 /// Returns whether the base is virtual or not.
1273 bool isBaseVirtual() const {
1274 assert(isBaseInitializer() && "Must call this on base initializer!");
1279 /// \brief Returns the declarator information for a base class initializer.
1280 TypeSourceInfo *getBaseClassInfo() const {
1281 return BaseOrMember.dyn_cast<TypeSourceInfo *>();
1284 /// getMember - If this is a member initializer, returns the
1285 /// declaration of the non-static data member being
1286 /// initialized. Otherwise, returns NULL.
1287 FieldDecl *getMember() const {
1288 if (isMemberInitializer())
1289 return BaseOrMember.get<FieldDecl*>();
1294 SourceLocation getMemberLocation() const {
1295 return MemberLocation;
1298 void setMember(FieldDecl *Member) {
1299 assert(isMemberInitializer());
1300 BaseOrMember = Member;
1303 /// \brief Determine the source location of the initializer.
1304 SourceLocation getSourceLocation() const;
1306 /// \brief Determine the source range covering the entire initializer.
1307 SourceRange getSourceRange() const;
1309 /// isWritten - Returns true if this initializer is explicitly written
1310 /// in the source code.
1311 bool isWritten() const { return IsWritten; }
1313 /// \brief Return the source position of the initializer, counting from 0.
1314 /// If the initializer was implicit, -1 is returned.
1315 int getSourceOrder() const {
1316 return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
1319 /// \brief Set the source order of this initializer. This method can only
1320 /// be called once for each initializer; it cannot be called on an
1321 /// initializer having a positive number of (implicit) array indices.
1322 void setSourceOrder(int pos) {
1323 assert(!IsWritten &&
1324 "calling twice setSourceOrder() on the same initializer");
1325 assert(SourceOrderOrNumArrayIndices == 0 &&
1326 "setSourceOrder() used when there are implicit array indices");
1328 "setSourceOrder() used to make an initializer implicit");
1330 SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
1333 FieldDecl *getAnonUnionMember() const {
1334 return AnonUnionMember;
1336 void setAnonUnionMember(FieldDecl *anonMember) {
1337 AnonUnionMember = anonMember;
1341 SourceLocation getLParenLoc() const { return LParenLoc; }
1342 SourceLocation getRParenLoc() const { return RParenLoc; }
1344 /// \brief Determine the number of implicit array indices used while
1345 /// described an array member initialization.
1346 unsigned getNumArrayIndices() const {
1347 return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
1350 /// \brief Retrieve a particular array index variable used to
1351 /// describe an array member initialization.
1352 VarDecl *getArrayIndex(unsigned I) {
1353 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1354 return reinterpret_cast<VarDecl **>(this + 1)[I];
1356 const VarDecl *getArrayIndex(unsigned I) const {
1357 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1358 return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
1360 void setArrayIndex(unsigned I, VarDecl *Index) {
1361 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1362 reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
1365 Expr *getInit() const { return static_cast<Expr *>(Init); }
1368 /// CXXConstructorDecl - Represents a C++ constructor within a
1369 /// class. For example:
1374 /// explicit X(int); // represented by a CXXConstructorDecl.
1377 class CXXConstructorDecl : public CXXMethodDecl {
1378 /// IsExplicitSpecified - Whether this constructor declaration has the
1379 /// 'explicit' keyword specified.
1380 bool IsExplicitSpecified : 1;
1382 /// ImplicitlyDefined - Whether this constructor was implicitly
1383 /// defined by the compiler. When false, the constructor was defined
1384 /// by the user. In C++03, this flag will have the same value as
1385 /// Implicit. In C++0x, however, a constructor that is
1386 /// explicitly defaulted (i.e., defined with " = default") will have
1387 /// @c !Implicit && ImplicitlyDefined.
1388 bool ImplicitlyDefined : 1;
1390 /// Support for base and member initializers.
1391 /// BaseOrMemberInitializers - The arguments used to initialize the base
1393 CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
1394 unsigned NumBaseOrMemberInitializers;
1396 CXXConstructorDecl(CXXRecordDecl *RD, const DeclarationNameInfo &NameInfo,
1397 QualType T, TypeSourceInfo *TInfo,
1398 bool isExplicitSpecified, bool isInline,
1399 bool isImplicitlyDeclared)
1400 : CXXMethodDecl(CXXConstructor, RD, NameInfo, T, TInfo, false,
1402 IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1403 BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
1404 setImplicit(isImplicitlyDeclared);
1408 static CXXConstructorDecl *Create(ASTContext &C, EmptyShell Empty);
1409 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1410 const DeclarationNameInfo &NameInfo,
1411 QualType T, TypeSourceInfo *TInfo,
1413 bool isInline, bool isImplicitlyDeclared);
1415 /// isExplicitSpecified - Whether this constructor declaration has the
1416 /// 'explicit' keyword specified.
1417 bool isExplicitSpecified() const { return IsExplicitSpecified; }
1419 /// isExplicit - Whether this constructor was marked "explicit" or not.
1420 bool isExplicit() const {
1421 return cast<CXXConstructorDecl>(getFirstDeclaration())
1422 ->isExplicitSpecified();
1425 /// isImplicitlyDefined - Whether this constructor was implicitly
1426 /// defined. If false, then this constructor was defined by the
1427 /// user. This operation can only be invoked if the constructor has
1428 /// already been defined.
1429 bool isImplicitlyDefined() const {
1430 assert(isThisDeclarationADefinition() &&
1431 "Can only get the implicit-definition flag once the "
1432 "constructor has been defined");
1433 return ImplicitlyDefined;
1436 /// setImplicitlyDefined - Set whether this constructor was
1437 /// implicitly defined or not.
1438 void setImplicitlyDefined(bool ID) {
1439 assert(isThisDeclarationADefinition() &&
1440 "Can only set the implicit-definition flag once the constructor "
1441 "has been defined");
1442 ImplicitlyDefined = ID;
1445 /// init_iterator - Iterates through the member/base initializer list.
1446 typedef CXXBaseOrMemberInitializer **init_iterator;
1448 /// init_const_iterator - Iterates through the memberbase initializer list.
1449 typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
1451 /// init_begin() - Retrieve an iterator to the first initializer.
1452 init_iterator init_begin() { return BaseOrMemberInitializers; }
1453 /// begin() - Retrieve an iterator to the first initializer.
1454 init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
1456 /// init_end() - Retrieve an iterator past the last initializer.
1457 init_iterator init_end() {
1458 return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1460 /// end() - Retrieve an iterator past the last initializer.
1461 init_const_iterator init_end() const {
1462 return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1465 /// getNumArgs - Determine the number of arguments used to
1466 /// initialize the member or base.
1467 unsigned getNumBaseOrMemberInitializers() const {
1468 return NumBaseOrMemberInitializers;
1471 void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) {
1472 NumBaseOrMemberInitializers = numBaseOrMemberInitializers;
1475 void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) {
1476 BaseOrMemberInitializers = initializers;
1478 /// isDefaultConstructor - Whether this constructor is a default
1479 /// constructor (C++ [class.ctor]p5), which can be used to
1480 /// default-initialize a class of this type.
1481 bool isDefaultConstructor() const;
1483 /// isCopyConstructor - Whether this constructor is a copy
1484 /// constructor (C++ [class.copy]p2, which can be used to copy the
1485 /// class. @p TypeQuals will be set to the qualifiers on the
1486 /// argument type. For example, @p TypeQuals would be set to @c
1487 /// QualType::Const for the following copy constructor:
1495 bool isCopyConstructor(unsigned &TypeQuals) const;
1497 /// isCopyConstructor - Whether this constructor is a copy
1498 /// constructor (C++ [class.copy]p2, which can be used to copy the
1500 bool isCopyConstructor() const {
1501 unsigned TypeQuals = 0;
1502 return isCopyConstructor(TypeQuals);
1505 /// isConvertingConstructor - Whether this constructor is a
1506 /// converting constructor (C++ [class.conv.ctor]), which can be
1507 /// used for user-defined conversions.
1508 bool isConvertingConstructor(bool AllowExplicit) const;
1510 /// \brief Determine whether this is a member template specialization that
1511 /// looks like a copy constructor. Such constructors are never used to copy
1513 bool isCopyConstructorLikeSpecialization() const;
1515 // Implement isa/cast/dyncast/etc.
1516 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1517 static bool classof(const CXXConstructorDecl *D) { return true; }
1518 static bool classofKind(Kind K) { return K == CXXConstructor; }
1520 friend class ASTDeclReader;
1521 friend class ASTDeclWriter;
1524 /// CXXDestructorDecl - Represents a C++ destructor within a
1525 /// class. For example:
1530 /// ~X(); // represented by a CXXDestructorDecl.
1533 class CXXDestructorDecl : public CXXMethodDecl {
1534 /// ImplicitlyDefined - Whether this destructor was implicitly
1535 /// defined by the compiler. When false, the destructor was defined
1536 /// by the user. In C++03, this flag will have the same value as
1537 /// Implicit. In C++0x, however, a destructor that is
1538 /// explicitly defaulted (i.e., defined with " = default") will have
1539 /// @c !Implicit && ImplicitlyDefined.
1540 bool ImplicitlyDefined : 1;
1542 FunctionDecl *OperatorDelete;
1544 CXXDestructorDecl(CXXRecordDecl *RD, const DeclarationNameInfo &NameInfo,
1545 QualType T, bool isInline, bool isImplicitlyDeclared)
1546 : CXXMethodDecl(CXXDestructor, RD, NameInfo, T, /*TInfo=*/0, false,
1548 ImplicitlyDefined(false), OperatorDelete(0) {
1549 setImplicit(isImplicitlyDeclared);
1553 static CXXDestructorDecl *Create(ASTContext& C, EmptyShell Empty);
1554 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1555 const DeclarationNameInfo &NameInfo,
1556 QualType T, bool isInline,
1557 bool isImplicitlyDeclared);
1559 /// isImplicitlyDefined - Whether this destructor was implicitly
1560 /// defined. If false, then this destructor was defined by the
1561 /// user. This operation can only be invoked if the destructor has
1562 /// already been defined.
1563 bool isImplicitlyDefined() const {
1564 assert(isThisDeclarationADefinition() &&
1565 "Can only get the implicit-definition flag once the destructor has been defined");
1566 return ImplicitlyDefined;
1569 /// setImplicitlyDefined - Set whether this destructor was
1570 /// implicitly defined or not.
1571 void setImplicitlyDefined(bool ID) {
1572 assert(isThisDeclarationADefinition() &&
1573 "Can only set the implicit-definition flag once the destructor has been defined");
1574 ImplicitlyDefined = ID;
1577 void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
1578 const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1580 // Implement isa/cast/dyncast/etc.
1581 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1582 static bool classof(const CXXDestructorDecl *D) { return true; }
1583 static bool classofKind(Kind K) { return K == CXXDestructor; }
1585 friend class ASTDeclReader;
1586 friend class ASTDeclWriter;
1589 /// CXXConversionDecl - Represents a C++ conversion function within a
1590 /// class. For example:
1595 /// operator bool();
1598 class CXXConversionDecl : public CXXMethodDecl {
1599 /// IsExplicitSpecified - Whether this conversion function declaration is
1600 /// marked "explicit", meaning that it can only be applied when the user
1601 /// explicitly wrote a cast. This is a C++0x feature.
1602 bool IsExplicitSpecified : 1;
1604 CXXConversionDecl(CXXRecordDecl *RD, const DeclarationNameInfo &NameInfo,
1605 QualType T, TypeSourceInfo *TInfo,
1606 bool isInline, bool isExplicitSpecified)
1607 : CXXMethodDecl(CXXConversion, RD, NameInfo, T, TInfo, false,
1609 IsExplicitSpecified(isExplicitSpecified) { }
1612 static CXXConversionDecl *Create(ASTContext &C, EmptyShell Empty);
1613 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1614 const DeclarationNameInfo &NameInfo,
1615 QualType T, TypeSourceInfo *TInfo,
1616 bool isInline, bool isExplicit);
1618 /// IsExplicitSpecified - Whether this conversion function declaration is
1619 /// marked "explicit", meaning that it can only be applied when the user
1620 /// explicitly wrote a cast. This is a C++0x feature.
1621 bool isExplicitSpecified() const { return IsExplicitSpecified; }
1623 /// isExplicit - Whether this is an explicit conversion operator
1624 /// (C++0x only). Explicit conversion operators are only considered
1625 /// when the user has explicitly written a cast.
1626 bool isExplicit() const {
1627 return cast<CXXConversionDecl>(getFirstDeclaration())
1628 ->isExplicitSpecified();
1631 /// getConversionType - Returns the type that this conversion
1632 /// function is converting to.
1633 QualType getConversionType() const {
1634 return getType()->getAs<FunctionType>()->getResultType();
1637 // Implement isa/cast/dyncast/etc.
1638 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1639 static bool classof(const CXXConversionDecl *D) { return true; }
1640 static bool classofKind(Kind K) { return K == CXXConversion; }
1642 friend class ASTDeclReader;
1643 friend class ASTDeclWriter;
1646 /// LinkageSpecDecl - This represents a linkage specification. For example:
1647 /// extern "C" void foo();
1649 class LinkageSpecDecl : public Decl, public DeclContext {
1651 /// LanguageIDs - Used to represent the language in a linkage
1652 /// specification. The values are part of the serialization abi for
1653 /// ASTs and cannot be changed without altering that abi. To help
1654 /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1655 /// from the dwarf standard.
1657 lang_c = /* DW_LANG_C */ 0x0002,
1658 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
1661 /// Language - The language for this linkage specification.
1662 LanguageIDs Language;
1664 /// HadBraces - Whether this linkage specification had curly braces or not.
1667 LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1669 : Decl(LinkageSpec, DC, L),
1670 DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1673 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1674 SourceLocation L, LanguageIDs Lang,
1677 /// \brief Return the language specified by this linkage specification.
1678 LanguageIDs getLanguage() const { return Language; }
1680 /// \brief Set the language specified by this linkage specification.
1681 void setLanguage(LanguageIDs L) { Language = L; }
1683 /// \brief Determines whether this linkage specification had braces in
1684 /// its syntactic form.
1685 bool hasBraces() const { return HadBraces; }
1687 /// \brief Set whether this linkage specification has braces in its
1689 void setHasBraces(bool B) { HadBraces = B; }
1691 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1692 static bool classof(const LinkageSpecDecl *D) { return true; }
1693 static bool classofKind(Kind K) { return K == LinkageSpec; }
1694 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1695 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1697 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1698 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1702 /// UsingDirectiveDecl - Represents C++ using-directive. For example:
1704 /// using namespace std;
1706 // NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1707 // artificial name, for all using-directives in order to store
1708 // them in DeclContext effectively.
1709 class UsingDirectiveDecl : public NamedDecl {
1710 /// \brief The location of the "using" keyword.
1711 SourceLocation UsingLoc;
1713 /// SourceLocation - Location of 'namespace' token.
1714 SourceLocation NamespaceLoc;
1716 /// \brief The source range that covers the nested-name-specifier
1717 /// preceding the namespace name.
1718 SourceRange QualifierRange;
1720 /// \brief The nested-name-specifier that precedes the namespace
1722 NestedNameSpecifier *Qualifier;
1724 /// NominatedNamespace - Namespace nominated by using-directive.
1725 NamedDecl *NominatedNamespace;
1727 /// Enclosing context containing both using-directive and nominated
1729 DeclContext *CommonAncestor;
1731 /// getUsingDirectiveName - Returns special DeclarationName used by
1732 /// using-directives. This is only used by DeclContext for storing
1733 /// UsingDirectiveDecls in its lookup structure.
1734 static DeclarationName getName() {
1735 return DeclarationName::getUsingDirectiveName();
1738 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
1739 SourceLocation NamespcLoc,
1740 SourceRange QualifierRange,
1741 NestedNameSpecifier *Qualifier,
1742 SourceLocation IdentLoc,
1743 NamedDecl *Nominated,
1744 DeclContext *CommonAncestor)
1745 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
1746 NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1747 Qualifier(Qualifier), NominatedNamespace(Nominated),
1748 CommonAncestor(CommonAncestor) {
1752 /// \brief Retrieve the source range of the nested-name-specifier
1753 /// that qualifies the namespace name.
1754 SourceRange getQualifierRange() const { return QualifierRange; }
1756 /// \brief Retrieve the nested-name-specifier that qualifies the
1757 /// name of the namespace.
1758 NestedNameSpecifier *getQualifier() const { return Qualifier; }
1760 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
1761 const NamedDecl *getNominatedNamespaceAsWritten() const {
1762 return NominatedNamespace;
1765 /// getNominatedNamespace - Returns namespace nominated by using-directive.
1766 NamespaceDecl *getNominatedNamespace();
1768 const NamespaceDecl *getNominatedNamespace() const {
1769 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1772 /// \brief Returns the common ancestor context of this using-directive and
1773 /// its nominated namespace.
1774 DeclContext *getCommonAncestor() { return CommonAncestor; }
1775 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1777 /// \brief Return the location of the "using" keyword.
1778 SourceLocation getUsingLoc() const { return UsingLoc; }
1780 // FIXME: Could omit 'Key' in name.
1781 /// getNamespaceKeyLocation - Returns location of namespace keyword.
1782 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1784 /// getIdentLocation - Returns location of identifier.
1785 SourceLocation getIdentLocation() const { return getLocation(); }
1787 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1788 SourceLocation UsingLoc,
1789 SourceLocation NamespaceLoc,
1790 SourceRange QualifierRange,
1791 NestedNameSpecifier *Qualifier,
1792 SourceLocation IdentLoc,
1793 NamedDecl *Nominated,
1794 DeclContext *CommonAncestor);
1796 SourceRange getSourceRange() const {
1797 return SourceRange(UsingLoc, getLocation());
1800 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1801 static bool classof(const UsingDirectiveDecl *D) { return true; }
1802 static bool classofKind(Kind K) { return K == UsingDirective; }
1804 // Friend for getUsingDirectiveName.
1805 friend class DeclContext;
1807 friend class ASTDeclReader;
1810 /// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1813 /// namespace Foo = Bar;
1815 class NamespaceAliasDecl : public NamedDecl {
1816 /// \brief The location of the "namespace" keyword.
1817 SourceLocation NamespaceLoc;
1819 /// \brief The source range that covers the nested-name-specifier
1820 /// preceding the namespace name.
1821 SourceRange QualifierRange;
1823 /// \brief The nested-name-specifier that precedes the namespace
1825 NestedNameSpecifier *Qualifier;
1827 /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
1828 SourceLocation IdentLoc;
1830 /// Namespace - The Decl that this alias points to. Can either be a
1831 /// NamespaceDecl or a NamespaceAliasDecl.
1832 NamedDecl *Namespace;
1834 NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc,
1835 SourceLocation AliasLoc, IdentifierInfo *Alias,
1836 SourceRange QualifierRange,
1837 NestedNameSpecifier *Qualifier,
1838 SourceLocation IdentLoc, NamedDecl *Namespace)
1839 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias),
1840 NamespaceLoc(NamespaceLoc), QualifierRange(QualifierRange),
1841 Qualifier(Qualifier), IdentLoc(IdentLoc), Namespace(Namespace) { }
1843 friend class ASTDeclReader;
1846 /// \brief Retrieve the source range of the nested-name-specifier
1847 /// that qualifiers the namespace name.
1848 SourceRange getQualifierRange() const { return QualifierRange; }
1850 /// \brief Set the source range of the nested-name-specifier that qualifies
1851 /// the namespace name.
1852 void setQualifierRange(SourceRange R) { QualifierRange = R; }
1854 /// \brief Retrieve the nested-name-specifier that qualifies the
1855 /// name of the namespace.
1856 NestedNameSpecifier *getQualifier() const { return Qualifier; }
1858 /// \brief Set the nested-name-specifier that qualifies the name of the
1860 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1862 /// \brief Retrieve the namespace declaration aliased by this directive.
1863 NamespaceDecl *getNamespace() {
1864 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1865 return AD->getNamespace();
1867 return cast<NamespaceDecl>(Namespace);
1870 const NamespaceDecl *getNamespace() const {
1871 return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1874 /// Returns the location of the alias name, i.e. 'foo' in
1875 /// "namespace foo = ns::bar;".
1876 SourceLocation getAliasLoc() const { return getLocation(); }
1878 /// Returns the location of the 'namespace' keyword.
1879 SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
1881 /// Returns the location of the identifier in the named namespace.
1882 SourceLocation getTargetNameLoc() const { return IdentLoc; }
1884 /// \brief Retrieve the namespace that this alias refers to, which
1885 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1886 NamedDecl *getAliasedNamespace() const { return Namespace; }
1888 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1889 SourceLocation NamespaceLoc,
1890 SourceLocation AliasLoc,
1891 IdentifierInfo *Alias,
1892 SourceRange QualifierRange,
1893 NestedNameSpecifier *Qualifier,
1894 SourceLocation IdentLoc,
1895 NamedDecl *Namespace);
1897 virtual SourceRange getSourceRange() const {
1898 return SourceRange(NamespaceLoc, IdentLoc);
1901 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1902 static bool classof(const NamespaceAliasDecl *D) { return true; }
1903 static bool classofKind(Kind K) { return K == NamespaceAlias; }
1906 /// UsingShadowDecl - Represents a shadow declaration introduced into
1907 /// a scope by a (resolved) using declaration. For example,
1913 /// using A::foo(); // <- a UsingDecl
1914 /// // Also creates a UsingShadowDecl for A::foo in B
1917 class UsingShadowDecl : public NamedDecl {
1918 /// The referenced declaration.
1919 NamedDecl *Underlying;
1921 /// The using declaration which introduced this decl.
1924 UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
1926 : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
1927 Underlying(Target), Using(Using) {
1929 setDeclName(Target->getDeclName());
1930 IdentifierNamespace = Target->getIdentifierNamespace();
1936 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
1937 SourceLocation Loc, UsingDecl *Using,
1938 NamedDecl *Target) {
1939 return new (C) UsingShadowDecl(DC, Loc, Using, Target);
1942 /// \brief Gets the underlying declaration which has been brought into the
1944 NamedDecl *getTargetDecl() const { return Underlying; }
1946 /// \brief Sets the underlying declaration which has been brought into the
1948 void setTargetDecl(NamedDecl* ND) {
1949 assert(ND && "Target decl is null!");
1951 IdentifierNamespace = ND->getIdentifierNamespace();
1954 /// \brief Gets the using declaration to which this declaration is tied.
1955 UsingDecl *getUsingDecl() const { return Using; }
1957 /// \brief Sets the using declaration that introduces this target
1959 void setUsingDecl(UsingDecl* UD) { Using = UD; }
1961 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1962 static bool classof(const UsingShadowDecl *D) { return true; }
1963 static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
1966 /// UsingDecl - Represents a C++ using-declaration. For example:
1967 /// using someNameSpace::someIdentifier;
1968 class UsingDecl : public NamedDecl {
1969 /// \brief The source range that covers the nested-name-specifier
1970 /// preceding the declaration name.
1971 SourceRange NestedNameRange;
1973 /// \brief The source location of the "using" location itself.
1974 SourceLocation UsingLocation;
1976 /// \brief Target nested name specifier.
1977 NestedNameSpecifier* TargetNestedName;
1979 /// DNLoc - Provides source/type location info for the
1980 /// declaration name embedded in the ValueDecl base class.
1981 DeclarationNameLoc DNLoc;
1983 /// \brief The collection of shadow declarations associated with
1984 /// this using declaration. This set can change as a class is
1986 llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows;
1988 // \brief Has 'typename' keyword.
1991 UsingDecl(DeclContext *DC, SourceRange NNR,
1992 SourceLocation UL, NestedNameSpecifier* TargetNNS,
1993 const DeclarationNameInfo &NameInfo, bool IsTypeNameArg)
1994 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
1995 NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS),
1996 DNLoc(NameInfo.getInfo()), IsTypeName(IsTypeNameArg) {
2000 /// \brief Returns the source range that covers the nested-name-specifier
2001 /// preceding the namespace name.
2002 SourceRange getNestedNameRange() const { return NestedNameRange; }
2004 /// \brief Set the source range of the nested-name-specifier.
2005 void setNestedNameRange(SourceRange R) { NestedNameRange = R; }
2007 // FIXME: Naming is inconsistent with other get*Loc functions.
2008 /// \brief Returns the source location of the "using" keyword.
2009 SourceLocation getUsingLocation() const { return UsingLocation; }
2011 /// \brief Set the source location of the 'using' keyword.
2012 void setUsingLocation(SourceLocation L) { UsingLocation = L; }
2014 /// \brief Get the target nested name declaration.
2015 NestedNameSpecifier* getTargetNestedNameDecl() const {
2016 return TargetNestedName;
2019 /// \brief Set the target nested name declaration.
2020 void setTargetNestedNameDecl(NestedNameSpecifier *NNS) {
2021 TargetNestedName = NNS;
2024 DeclarationNameInfo getNameInfo() const {
2025 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2028 /// \brief Return true if the using declaration has 'typename'.
2029 bool isTypeName() const { return IsTypeName; }
2031 /// \brief Sets whether the using declaration has 'typename'.
2032 void setTypeName(bool TN) { IsTypeName = TN; }
2034 typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator;
2035 shadow_iterator shadow_begin() const { return Shadows.begin(); }
2036 shadow_iterator shadow_end() const { return Shadows.end(); }
2038 void addShadowDecl(UsingShadowDecl *S) {
2039 assert(S->getUsingDecl() == this);
2040 if (!Shadows.insert(S)) {
2041 assert(false && "declaration already in set");
2044 void removeShadowDecl(UsingShadowDecl *S) {
2045 assert(S->getUsingDecl() == this);
2046 if (!Shadows.erase(S)) {
2047 assert(false && "declaration not in set");
2051 /// \brief Return the number of shadowed declarations associated with this
2052 /// using declaration.
2053 unsigned getNumShadowDecls() const {
2054 return Shadows.size();
2057 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
2058 SourceRange NNR, SourceLocation UsingL,
2059 NestedNameSpecifier* TargetNNS,
2060 const DeclarationNameInfo &NameInfo,
2061 bool IsTypeNameArg);
2063 SourceRange getSourceRange() const {
2064 return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2067 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2068 static bool classof(const UsingDecl *D) { return true; }
2069 static bool classofKind(Kind K) { return K == Using; }
2071 friend class ASTDeclReader;
2072 friend class ASTDeclWriter;
2075 /// UnresolvedUsingValueDecl - Represents a dependent using
2076 /// declaration which was not marked with 'typename'. Unlike
2077 /// non-dependent using declarations, these *only* bring through
2078 /// non-types; otherwise they would break two-phase lookup.
2080 /// template <class T> class A : public Base<T> {
2081 /// using Base<T>::foo;
2083 class UnresolvedUsingValueDecl : public ValueDecl {
2084 /// \brief The source range that covers the nested-name-specifier
2085 /// preceding the declaration name.
2086 SourceRange TargetNestedNameRange;
2088 /// \brief The source location of the 'using' keyword
2089 SourceLocation UsingLocation;
2091 NestedNameSpecifier *TargetNestedNameSpecifier;
2093 /// DNLoc - Provides source/type location info for the
2094 /// declaration name embedded in the ValueDecl base class.
2095 DeclarationNameLoc DNLoc;
2097 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
2098 SourceLocation UsingLoc, SourceRange TargetNNR,
2099 NestedNameSpecifier *TargetNNS,
2100 const DeclarationNameInfo &NameInfo)
2101 : ValueDecl(UnresolvedUsingValue, DC,
2102 NameInfo.getLoc(), NameInfo.getName(), Ty),
2103 TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
2104 TargetNestedNameSpecifier(TargetNNS), DNLoc(NameInfo.getInfo())
2108 /// \brief Returns the source range that covers the nested-name-specifier
2109 /// preceding the namespace name.
2110 SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
2112 /// \brief Set the source range coverting the nested-name-specifier preceding
2113 /// the namespace name.
2114 void setTargetNestedNameRange(SourceRange R) { TargetNestedNameRange = R; }
2116 /// \brief Get target nested name declaration.
2117 NestedNameSpecifier* getTargetNestedNameSpecifier() const {
2118 return TargetNestedNameSpecifier;
2121 /// \brief Set the nested name declaration.
2122 void setTargetNestedNameSpecifier(NestedNameSpecifier* NNS) {
2123 TargetNestedNameSpecifier = NNS;
2126 /// \brief Returns the source location of the 'using' keyword.
2127 SourceLocation getUsingLoc() const { return UsingLocation; }
2129 /// \brief Set the source location of the 'using' keyword.
2130 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2132 DeclarationNameInfo getNameInfo() const {
2133 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2136 static UnresolvedUsingValueDecl *
2137 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2138 SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
2139 const DeclarationNameInfo &NameInfo);
2141 SourceRange getSourceRange() const {
2142 return SourceRange(UsingLocation, getNameInfo().getEndLoc());
2145 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2146 static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
2147 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
2150 /// UnresolvedUsingTypenameDecl - Represents a dependent using
2151 /// declaration which was marked with 'typename'.
2153 /// template <class T> class A : public Base<T> {
2154 /// using typename Base<T>::foo;
2157 /// The type associated with a unresolved using typename decl is
2158 /// currently always a typename type.
2159 class UnresolvedUsingTypenameDecl : public TypeDecl {
2160 /// \brief The source range that covers the nested-name-specifier
2161 /// preceding the declaration name.
2162 SourceRange TargetNestedNameRange;
2164 /// \brief The source location of the 'using' keyword
2165 SourceLocation UsingLocation;
2167 /// \brief The source location of the 'typename' keyword
2168 SourceLocation TypenameLocation;
2170 NestedNameSpecifier *TargetNestedNameSpecifier;
2172 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2173 SourceLocation TypenameLoc,
2174 SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
2175 SourceLocation TargetNameLoc, IdentifierInfo *TargetName)
2176 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName),
2177 TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
2178 TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS)
2181 friend class ASTDeclReader;
2184 /// \brief Returns the source range that covers the nested-name-specifier
2185 /// preceding the namespace name.
2186 SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
2188 /// \brief Get target nested name declaration.
2189 NestedNameSpecifier* getTargetNestedNameSpecifier() {
2190 return TargetNestedNameSpecifier;
2193 /// \brief Returns the source location of the 'using' keyword.
2194 SourceLocation getUsingLoc() const { return UsingLocation; }
2196 /// \brief Returns the source location of the 'typename' keyword.
2197 SourceLocation getTypenameLoc() const { return TypenameLocation; }
2199 static UnresolvedUsingTypenameDecl *
2200 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2201 SourceLocation TypenameLoc,
2202 SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
2203 SourceLocation TargetNameLoc, DeclarationName TargetName);
2205 SourceRange getSourceRange() const {
2206 return SourceRange(UsingLocation, getLocation());
2209 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2210 static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
2211 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
2214 /// StaticAssertDecl - Represents a C++0x static_assert declaration.
2215 class StaticAssertDecl : public Decl {
2217 StringLiteral *Message;
2219 StaticAssertDecl(DeclContext *DC, SourceLocation L,
2220 Expr *assertexpr, StringLiteral *message)
2221 : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
2224 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
2225 SourceLocation L, Expr *AssertExpr,
2226 StringLiteral *Message);
2228 Expr *getAssertExpr() { return AssertExpr; }
2229 const Expr *getAssertExpr() const { return AssertExpr; }
2231 StringLiteral *getMessage() { return Message; }
2232 const StringLiteral *getMessage() const { return Message; }
2234 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2235 static bool classof(StaticAssertDecl *D) { return true; }
2236 static bool classofKind(Kind K) { return K == StaticAssert; }
2238 friend class ASTDeclReader;
2241 /// Insertion operator for diagnostics. This allows sending AccessSpecifier's
2242 /// into a diagnostic with <<.
2243 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2244 AccessSpecifier AS);
2246 } // end namespace clang