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/UnresolvedSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/SmallPtrSet.h"
26 class ClassTemplateDecl;
27 class ClassTemplateSpecializationDecl;
30 class CXXConstructorDecl;
31 class CXXConversionDecl;
32 class CXXDestructorDecl;
35 class CXXMemberLookupCriteria;
36 class CXXFinalOverriderMap;
39 /// \brief Represents any kind of function declaration, whether it is a
40 /// concrete function or a function template.
41 class AnyFunctionDecl {
44 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
47 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
48 AnyFunctionDecl(FunctionTemplateDecl *FTD);
50 /// \brief Implicily converts any function or function template into a
51 /// named declaration.
52 operator NamedDecl *() const { return Function; }
54 /// \brief Retrieve the underlying function or function template.
55 NamedDecl *get() const { return Function; }
57 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
58 return AnyFunctionDecl(ND);
62 } // end namespace clang
65 /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from
66 /// AnyFunctionDecl to any function or function template declaration.
67 template<> struct simplify_type<const ::clang::AnyFunctionDecl> {
68 typedef ::clang::NamedDecl* SimpleType;
69 static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) {
73 template<> struct simplify_type< ::clang::AnyFunctionDecl>
74 : public simplify_type<const ::clang::AnyFunctionDecl> {};
76 // Provide PointerLikeTypeTraits for non-cvr pointers.
78 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
80 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
83 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
84 return ::clang::AnyFunctionDecl::getFromNamedDecl(
85 static_cast< ::clang::NamedDecl*>(P));
88 enum { NumLowBitsAvailable = 2 };
91 } // end namespace llvm
95 /// CXXBaseSpecifier - A base class of a C++ class.
97 /// Each CXXBaseSpecifier represents a single, direct base class (or
98 /// struct) of a C++ class (or struct). It specifies the type of that
99 /// base class, whether it is a virtual or non-virtual base, and what
100 /// level of access (public, protected, private) is used for the
101 /// derivation. For example:
106 /// class C : public virtual A, protected B { };
109 /// In this code, C will have two CXXBaseSpecifiers, one for "public
110 /// virtual A" and the other for "protected B".
111 class CXXBaseSpecifier {
112 /// Range - The source code range that covers the full base
113 /// specifier, including the "virtual" (if present) and access
114 /// specifier (if present).
115 // FIXME: Move over to a TypeLoc!
118 /// Virtual - Whether this is a virtual base class or not.
121 /// BaseOfClass - Whether this is the base of a class (true) or of a
122 /// struct (false). This determines the mapping from the access
123 /// specifier as written in the source code to the access specifier
124 /// used for semantic analysis.
125 bool BaseOfClass : 1;
127 /// Access - Access specifier as written in the source code (which
128 /// may be AS_none). The actual type of data stored here is an
129 /// AccessSpecifier, but we use "unsigned" here to work around a
133 /// BaseType - The type of the base class. This will be a class or
134 /// struct (or a typedef of such).
138 CXXBaseSpecifier() { }
140 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, QualType T)
141 : Range(R), Virtual(V), BaseOfClass(BC), Access(A), BaseType(T) { }
143 /// getSourceRange - Retrieves the source range that contains the
144 /// entire base specifier.
145 SourceRange getSourceRange() const { return Range; }
147 /// isVirtual - Determines whether the base class is a virtual base
149 bool isVirtual() const { return Virtual; }
151 /// \brief Determine whether this base class if a base of a class declared
152 /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
153 bool isBaseOfClass() const { return BaseOfClass; }
155 /// getAccessSpecifier - Returns the access specifier for this base
156 /// specifier. This is the actual base specifier as used for
157 /// semantic analysis, so the result can never be AS_none. To
158 /// retrieve the access specifier as written in the source code, use
159 /// getAccessSpecifierAsWritten().
160 AccessSpecifier getAccessSpecifier() const {
161 if ((AccessSpecifier)Access == AS_none)
162 return BaseOfClass? AS_private : AS_public;
164 return (AccessSpecifier)Access;
167 /// getAccessSpecifierAsWritten - Retrieves the access specifier as
168 /// written in the source code (which may mean that no access
169 /// specifier was explicitly written). Use getAccessSpecifier() to
170 /// retrieve the access specifier for use in semantic analysis.
171 AccessSpecifier getAccessSpecifierAsWritten() const {
172 return (AccessSpecifier)Access;
175 /// getType - Retrieves the type of the base class. This type will
176 /// always be an unqualified class type.
177 QualType getType() const { return BaseType; }
180 /// CXXRecordDecl - Represents a C++ struct/union/class.
181 /// FIXME: This class will disappear once we've properly taught RecordDecl
182 /// to deal with C++-specific things.
183 class CXXRecordDecl : public RecordDecl {
185 friend void TagDecl::startDefinition();
187 struct DefinitionData {
188 DefinitionData(CXXRecordDecl *D);
190 /// UserDeclaredConstructor - True when this class has a
191 /// user-declared constructor.
192 bool UserDeclaredConstructor : 1;
194 /// UserDeclaredCopyConstructor - True when this class has a
195 /// user-declared copy constructor.
196 bool UserDeclaredCopyConstructor : 1;
198 /// UserDeclaredCopyAssignment - True when this class has a
199 /// user-declared copy assignment operator.
200 bool UserDeclaredCopyAssignment : 1;
202 /// UserDeclaredDestructor - True when this class has a
203 /// user-declared destructor.
204 bool UserDeclaredDestructor : 1;
206 /// Aggregate - True when this class is an aggregate.
209 /// PlainOldData - True when this class is a POD-type.
210 bool PlainOldData : 1;
212 /// Empty - true when this class is empty for traits purposes,
213 /// i.e. has no data members other than 0-width bit-fields, has no
214 /// virtual function/base, and doesn't inherit from a non-empty
215 /// class. Doesn't take union-ness into account.
218 /// Polymorphic - True when this class is polymorphic, i.e. has at
219 /// least one virtual member or derives from a polymorphic class.
220 bool Polymorphic : 1;
222 /// Abstract - True when this class is abstract, i.e. has at least
223 /// one pure virtual function, (that can come from a base class).
226 /// HasTrivialConstructor - True when this class has a trivial constructor.
228 /// C++ [class.ctor]p5. A constructor is trivial if it is an
229 /// implicitly-declared default constructor and if:
230 /// * its class has no virtual functions and no virtual base classes, and
231 /// * all the direct base classes of its class have trivial constructors, and
232 /// * for all the nonstatic data members of its class that are of class type
233 /// (or array thereof), each such class has a trivial constructor.
234 bool HasTrivialConstructor : 1;
236 /// HasTrivialCopyConstructor - True when this class has a trivial copy
239 /// C++ [class.copy]p6. A copy constructor for class X is trivial
240 /// if it is implicitly declared and if
241 /// * class X has no virtual functions and no virtual base classes, and
242 /// * each direct base class of X has a trivial copy constructor, and
243 /// * for all the nonstatic data members of X that are of class type (or
244 /// array thereof), each such class type has a trivial copy constructor;
245 /// otherwise the copy constructor is non-trivial.
246 bool HasTrivialCopyConstructor : 1;
248 /// HasTrivialCopyAssignment - True when this class has a trivial copy
249 /// assignment operator.
251 /// C++ [class.copy]p11. A copy assignment operator for class X is
252 /// trivial if it is implicitly declared and if
253 /// * class X has no virtual functions and no virtual base classes, and
254 /// * each direct base class of X has a trivial copy assignment operator, and
255 /// * for all the nonstatic data members of X that are of class type (or
256 /// array thereof), each such class type has a trivial copy assignment
258 /// otherwise the copy assignment operator is non-trivial.
259 bool HasTrivialCopyAssignment : 1;
261 /// HasTrivialDestructor - True when this class has a trivial destructor.
263 /// C++ [class.dtor]p3. A destructor is trivial if it is an
264 /// implicitly-declared destructor and if:
265 /// * all of the direct base classes of its class have trivial destructors
267 /// * for all of the non-static data members of its class that are of class
268 /// type (or array thereof), each such class has a trivial destructor.
269 bool HasTrivialDestructor : 1;
271 /// ComputedVisibleConversions - True when visible conversion functions are
272 /// already computed and are available.
273 bool ComputedVisibleConversions : 1;
275 /// Bases - Base classes of this class.
276 /// FIXME: This is wasted space for a union.
277 CXXBaseSpecifier *Bases;
279 /// NumBases - The number of base class specifiers in Bases.
282 /// VBases - direct and indirect virtual base classes of this class.
283 CXXBaseSpecifier *VBases;
285 /// NumVBases - The number of virtual base class specifiers in VBases.
288 /// Conversions - Overload set containing the conversion functions
289 /// of this C++ class (but not its inherited conversion
290 /// functions). Each of the entries in this overload set is a
291 /// CXXConversionDecl.
292 UnresolvedSet<4> Conversions;
294 /// VisibleConversions - Overload set containing the conversion
295 /// functions of this C++ class and all those inherited conversion
296 /// functions that are visible in this class. Each of the entries
297 /// in this overload set is a CXXConversionDecl or a
298 /// FunctionTemplateDecl.
299 UnresolvedSet<4> VisibleConversions;
301 /// Definition - The declaration which defines this record.
302 CXXRecordDecl *Definition;
304 /// FirstFriend - The first friend declaration in this class, or
305 /// null if there aren't any. This is actually currently stored
306 /// in reverse order.
307 FriendDecl *FirstFriend;
311 struct DefinitionData &data() {
312 assert(DefinitionData && "queried property of class with no definition");
313 return *DefinitionData;
316 const struct DefinitionData &data() const {
317 assert(DefinitionData && "queried property of class with no definition");
318 return *DefinitionData;
321 /// \brief The template or declaration that this declaration
322 /// describes or was instantiated from, respectively.
324 /// For non-templates, this value will be NULL. For record
325 /// declarations that describe a class template, this will be a
326 /// pointer to a ClassTemplateDecl. For member
327 /// classes of class template specializations, this will be the
328 /// MemberSpecializationInfo referring to the member class that was
329 /// instantiated or specialized.
330 llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
331 TemplateOrInstantiation;
334 void CheckConversionFunction(NamedDecl *D);
338 CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
339 SourceLocation L, IdentifierInfo *Id,
340 CXXRecordDecl *PrevDecl,
341 SourceLocation TKL = SourceLocation());
346 /// base_class_iterator - Iterator that traverses the base classes
348 typedef CXXBaseSpecifier* base_class_iterator;
350 /// base_class_const_iterator - Iterator that traverses the base
351 /// classes of a class.
352 typedef const CXXBaseSpecifier* base_class_const_iterator;
354 /// reverse_base_class_iterator = Iterator that traverses the base classes
355 /// of a class in reverse order.
356 typedef std::reverse_iterator<base_class_iterator>
357 reverse_base_class_iterator;
359 /// reverse_base_class_iterator = Iterator that traverses the base classes
360 /// of a class in reverse order.
361 typedef std::reverse_iterator<base_class_const_iterator>
362 reverse_base_class_const_iterator;
364 virtual CXXRecordDecl *getCanonicalDecl() {
365 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
367 virtual const CXXRecordDecl *getCanonicalDecl() const {
368 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
371 CXXRecordDecl *getDefinition() const {
372 if (!DefinitionData) return 0;
373 return data().Definition;
376 bool hasDefinition() const { return DefinitionData != 0; }
378 static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
379 SourceLocation L, IdentifierInfo *Id,
380 SourceLocation TKL = SourceLocation(),
381 CXXRecordDecl* PrevDecl=0,
382 bool DelayTypeCreation = false);
384 virtual void Destroy(ASTContext& C);
386 bool isDynamicClass() const {
387 return data().Polymorphic || data().NumVBases != 0;
390 /// setBases - Sets the base classes of this struct or class.
391 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
393 /// getNumBases - Retrieves the number of base classes of this
395 unsigned getNumBases() const { return data().NumBases; }
397 base_class_iterator bases_begin() { return data().Bases; }
398 base_class_const_iterator bases_begin() const { return data().Bases; }
399 base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
400 base_class_const_iterator bases_end() const {
401 return bases_begin() + data().NumBases;
403 reverse_base_class_iterator bases_rbegin() {
404 return reverse_base_class_iterator(bases_end());
406 reverse_base_class_const_iterator bases_rbegin() const {
407 return reverse_base_class_const_iterator(bases_end());
409 reverse_base_class_iterator bases_rend() {
410 return reverse_base_class_iterator(bases_begin());
412 reverse_base_class_const_iterator bases_rend() const {
413 return reverse_base_class_const_iterator(bases_begin());
416 /// getNumVBases - Retrieves the number of virtual base classes of this
418 unsigned getNumVBases() const { return data().NumVBases; }
420 base_class_iterator vbases_begin() { return data().VBases; }
421 base_class_const_iterator vbases_begin() const { return data().VBases; }
422 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
423 base_class_const_iterator vbases_end() const {
424 return vbases_begin() + data().NumVBases;
426 reverse_base_class_iterator vbases_rbegin() {
427 return reverse_base_class_iterator(vbases_end());
429 reverse_base_class_const_iterator vbases_rbegin() const {
430 return reverse_base_class_const_iterator(vbases_end());
432 reverse_base_class_iterator vbases_rend() {
433 return reverse_base_class_iterator(vbases_begin());
435 reverse_base_class_const_iterator vbases_rend() const {
436 return reverse_base_class_const_iterator(vbases_begin());
439 /// \brief Determine whether this class has any dependent base classes.
440 bool hasAnyDependentBases() const;
442 /// Iterator access to method members. The method iterator visits
443 /// all method members of the class, including non-instance methods,
444 /// special methods, etc.
445 typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
447 /// method_begin - Method begin iterator. Iterates in the order the methods
449 method_iterator method_begin() const {
450 return method_iterator(decls_begin());
452 /// method_end - Method end iterator.
453 method_iterator method_end() const {
454 return method_iterator(decls_end());
457 /// Iterator access to constructor members.
458 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
460 ctor_iterator ctor_begin() const {
461 return ctor_iterator(decls_begin());
463 ctor_iterator ctor_end() const {
464 return ctor_iterator(decls_end());
467 /// An iterator over friend declarations. All of these are defined
469 class friend_iterator;
470 friend_iterator friend_begin() const;
471 friend_iterator friend_end() const;
472 void pushFriendDecl(FriendDecl *FD);
474 /// Determines whether this record has any friends.
475 bool hasFriends() const {
476 return data().FirstFriend != 0;
479 /// hasConstCopyConstructor - Determines whether this class has a
480 /// copy constructor that accepts a const-qualified argument.
481 bool hasConstCopyConstructor(ASTContext &Context) const;
483 /// getCopyConstructor - Returns the copy constructor for this class
484 CXXConstructorDecl *getCopyConstructor(ASTContext &Context,
485 unsigned TypeQuals) const;
487 /// hasConstCopyAssignment - Determines whether this class has a
488 /// copy assignment operator that accepts a const-qualified argument.
489 /// It returns its decl in MD if found.
490 bool hasConstCopyAssignment(ASTContext &Context,
491 const CXXMethodDecl *&MD) const;
493 /// addedConstructor - Notify the class that another constructor has
494 /// been added. This routine helps maintain information about the
495 /// class based on which constructors have been added.
496 void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
498 /// hasUserDeclaredConstructor - Whether this class has any
499 /// user-declared constructors. When true, a default constructor
500 /// will not be implicitly declared.
501 bool hasUserDeclaredConstructor() const {
502 return data().UserDeclaredConstructor;
505 /// hasUserDeclaredCopyConstructor - Whether this class has a
506 /// user-declared copy constructor. When false, a copy constructor
507 /// will be implicitly declared.
508 bool hasUserDeclaredCopyConstructor() const {
509 return data().UserDeclaredCopyConstructor;
512 /// addedAssignmentOperator - Notify the class that another assignment
513 /// operator has been added. This routine helps maintain information about the
514 /// class based on which operators have been added.
515 void addedAssignmentOperator(ASTContext &Context, CXXMethodDecl *OpDecl);
517 /// hasUserDeclaredCopyAssignment - Whether this class has a
518 /// user-declared copy assignment operator. When false, a copy
519 /// assigment operator will be implicitly declared.
520 bool hasUserDeclaredCopyAssignment() const {
521 return data().UserDeclaredCopyAssignment;
524 /// hasUserDeclaredDestructor - Whether this class has a
525 /// user-declared destructor. When false, a destructor will be
526 /// implicitly declared.
527 bool hasUserDeclaredDestructor() const {
528 return data().UserDeclaredDestructor;
531 /// setUserDeclaredDestructor - Set whether this class has a
532 /// user-declared destructor. If not set by the time the class is
533 /// fully defined, a destructor will be implicitly declared.
534 void setUserDeclaredDestructor(bool UCD) {
535 data().UserDeclaredDestructor = UCD;
538 /// getConversions - Retrieve the overload set containing all of the
539 /// conversion functions in this class.
540 UnresolvedSetImpl *getConversionFunctions() {
541 return &data().Conversions;
543 const UnresolvedSetImpl *getConversionFunctions() const {
544 return &data().Conversions;
547 typedef UnresolvedSetImpl::iterator conversion_iterator;
548 conversion_iterator conversion_begin() const {
549 return getConversionFunctions()->begin();
551 conversion_iterator conversion_end() const {
552 return getConversionFunctions()->end();
555 /// Replaces a conversion function with a new declaration.
557 /// Returns true if the old conversion was found.
558 bool replaceConversion(const NamedDecl* Old, NamedDecl *New) {
559 return getConversionFunctions()->replace(Old, New);
562 /// Removes a conversion function from this class. The conversion
563 /// function must currently be a member of this class. Furthermore,
564 /// this class must currently be in the process of being defined.
565 void removeConversion(const NamedDecl *Old);
567 /// getVisibleConversionFunctions - get all conversion functions visible
568 /// in current class; including conversion function templates.
569 const UnresolvedSetImpl *getVisibleConversionFunctions();
571 /// addConversionFunction - Registers a conversion function which
572 /// this class declares directly.
573 void addConversionFunction(NamedDecl *Decl) {
575 CheckConversionFunction(Decl);
578 // We intentionally don't use the decl's access here because it
579 // hasn't been set yet. That's really just a misdesign in Sema.
580 data().Conversions.addDecl(Decl);
583 /// isAggregate - Whether this class is an aggregate (C++
584 /// [dcl.init.aggr]), which is a class with no user-declared
585 /// constructors, no private or protected non-static data members,
586 /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1).
587 bool isAggregate() const { return data().Aggregate; }
589 /// setAggregate - Set whether this class is an aggregate (C++
590 /// [dcl.init.aggr]).
591 void setAggregate(bool Agg) { data().Aggregate = Agg; }
593 /// setMethodAsVirtual - Make input method virtual and set the necesssary
594 /// special function bits and other bits accordingly.
595 void setMethodAsVirtual(FunctionDecl *Method);
597 /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class
598 /// that is an aggregate that has no non-static non-POD data members, no
599 /// reference data members, no user-defined copy assignment operator and no
600 /// user-defined destructor.
601 bool isPOD() const { return data().PlainOldData; }
603 /// setPOD - Set whether this class is a POD-type (C++ [class]p4).
604 void setPOD(bool POD) { data().PlainOldData = POD; }
606 /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which
607 /// means it has a virtual function, virtual base, data member (other than
608 /// 0-width bit-field) or inherits from a non-empty class. Does NOT include
609 /// a check for union-ness.
610 bool isEmpty() const { return data().Empty; }
612 /// Set whether this class is empty (C++0x [meta.unary.prop])
613 void setEmpty(bool Emp) { data().Empty = Emp; }
615 /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]),
616 /// which means that the class contains or inherits a virtual function.
617 bool isPolymorphic() const { return data().Polymorphic; }
619 /// setPolymorphic - Set whether this class is polymorphic (C++
620 /// [class.virtual]).
621 void setPolymorphic(bool Poly) { data().Polymorphic = Poly; }
623 /// isAbstract - Whether this class is abstract (C++ [class.abstract]),
624 /// which means that the class contains or inherits a pure virtual function.
625 bool isAbstract() const { return data().Abstract; }
627 /// setAbstract - Set whether this class is abstract (C++ [class.abstract])
628 void setAbstract(bool Abs) { data().Abstract = Abs; }
630 // hasTrivialConstructor - Whether this class has a trivial constructor
631 // (C++ [class.ctor]p5)
632 bool hasTrivialConstructor() const { return data().HasTrivialConstructor; }
634 // setHasTrivialConstructor - Set whether this class has a trivial constructor
635 // (C++ [class.ctor]p5)
636 void setHasTrivialConstructor(bool TC) { data().HasTrivialConstructor = TC; }
638 // hasTrivialCopyConstructor - Whether this class has a trivial copy
639 // constructor (C++ [class.copy]p6)
640 bool hasTrivialCopyConstructor() const {
641 return data().HasTrivialCopyConstructor;
644 // setHasTrivialCopyConstructor - Set whether this class has a trivial
645 // copy constructor (C++ [class.copy]p6)
646 void setHasTrivialCopyConstructor(bool TC) {
647 data().HasTrivialCopyConstructor = TC;
650 // hasTrivialCopyAssignment - Whether this class has a trivial copy
651 // assignment operator (C++ [class.copy]p11)
652 bool hasTrivialCopyAssignment() const {
653 return data().HasTrivialCopyAssignment;
656 // setHasTrivialCopyAssignment - Set whether this class has a
657 // trivial copy assignment operator (C++ [class.copy]p11)
658 void setHasTrivialCopyAssignment(bool TC) {
659 data().HasTrivialCopyAssignment = TC;
662 // hasTrivialDestructor - Whether this class has a trivial destructor
663 // (C++ [class.dtor]p3)
664 bool hasTrivialDestructor() const { return data().HasTrivialDestructor; }
666 // setHasTrivialDestructor - Set whether this class has a trivial destructor
667 // (C++ [class.dtor]p3)
668 void setHasTrivialDestructor(bool TC) { data().HasTrivialDestructor = TC; }
670 /// \brief If this record is an instantiation of a member class,
671 /// retrieves the member class from which it was instantiated.
673 /// This routine will return non-NULL for (non-templated) member
674 /// classes of class templates. For example, given:
677 /// template<typename T>
683 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
684 /// whose parent is the class template specialization X<int>. For
685 /// this declaration, getInstantiatedFromMemberClass() will return
686 /// the CXXRecordDecl X<T>::A. When a complete definition of
687 /// X<int>::A is required, it will be instantiated from the
688 /// declaration returned by getInstantiatedFromMemberClass().
689 CXXRecordDecl *getInstantiatedFromMemberClass() const;
691 /// \brief If this class is an instantiation of a member class of a
692 /// class template specialization, retrieves the member specialization
694 MemberSpecializationInfo *getMemberSpecializationInfo() const;
696 /// \brief Specify that this record is an instantiation of the
698 void setInstantiationOfMemberClass(CXXRecordDecl *RD,
699 TemplateSpecializationKind TSK);
701 /// \brief Retrieves the class template that is described by this
702 /// class declaration.
704 /// Every class template is represented as a ClassTemplateDecl and a
705 /// CXXRecordDecl. The former contains template properties (such as
706 /// the template parameter lists) while the latter contains the
707 /// actual description of the template's
708 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
709 /// CXXRecordDecl that from a ClassTemplateDecl, while
710 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
712 ClassTemplateDecl *getDescribedClassTemplate() const {
713 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
716 void setDescribedClassTemplate(ClassTemplateDecl *Template) {
717 TemplateOrInstantiation = Template;
720 /// \brief Determine whether this particular class is a specialization or
721 /// instantiation of a class template or member class of a class template,
722 /// and how it was instantiated or specialized.
723 TemplateSpecializationKind getTemplateSpecializationKind() const;
725 /// \brief Set the kind of specialization or template instantiation this is.
726 void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
728 /// getDefaultConstructor - Returns the default constructor for this class
729 CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
731 /// getDestructor - Returns the destructor decl for this class.
732 CXXDestructorDecl *getDestructor(ASTContext &Context) const;
734 /// isLocalClass - If the class is a local class [class.local], returns
735 /// the enclosing function declaration.
736 const FunctionDecl *isLocalClass() const {
737 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
738 return RD->isLocalClass();
740 return dyn_cast<FunctionDecl>(getDeclContext());
743 /// \brief Determine whether this class is derived from the class \p Base.
745 /// This routine only determines whether this class is derived from \p Base,
746 /// but does not account for factors that may make a Derived -> Base class
747 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
748 /// base class subobjects.
750 /// \param Base the base class we are searching for.
752 /// \returns true if this class is derived from Base, false otherwise.
753 bool isDerivedFrom(CXXRecordDecl *Base) const;
755 /// \brief Determine whether this class is derived from the type \p Base.
757 /// This routine only determines whether this class is derived from \p Base,
758 /// but does not account for factors that may make a Derived -> Base class
759 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
760 /// base class subobjects.
762 /// \param Base the base class we are searching for.
764 /// \param Paths will contain the paths taken from the current class to the
765 /// given \p Base class.
767 /// \returns true if this class is derived from Base, false otherwise.
769 /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than
770 /// tangling input and output in \p Paths
771 bool isDerivedFrom(CXXRecordDecl *Base, CXXBasePaths &Paths) const;
773 /// \brief Determine whether this class is virtually derived from
774 /// the class \p Base.
776 /// This routine only determines whether this class is virtually
777 /// derived from \p Base, but does not account for factors that may
778 /// make a Derived -> Base class ill-formed, such as
779 /// private/protected inheritance or multiple, ambiguous base class
782 /// \param Base the base class we are searching for.
784 /// \returns true if this class is virtually derived from Base,
786 bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const;
788 /// \brief Determine whether this class is provably not derived from
789 /// the type \p Base.
790 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
792 /// \brief Function type used by forallBases() as a callback.
794 /// \param Base the definition of the base class
796 /// \returns true if this base matched the search criteria
797 typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition,
800 /// \brief Determines if the given callback holds for all the direct
801 /// or indirect base classes of this type.
803 /// The class itself does not count as a base class. This routine
804 /// returns false if the class has non-computable base classes.
806 /// \param AllowShortCircuit if false, forces the callback to be called
807 /// for every base class, even if a dependent or non-matching base was
809 bool forallBases(ForallBasesCallback *BaseMatches, void *UserData,
810 bool AllowShortCircuit = true) const;
812 /// \brief Function type used by lookupInBases() to determine whether a
813 /// specific base class subobject matches the lookup criteria.
815 /// \param Specifier the base-class specifier that describes the inheritance
816 /// from the base class we are trying to match.
818 /// \param Path the current path, from the most-derived class down to the
819 /// base named by the \p Specifier.
821 /// \param UserData a single pointer to user-specified data, provided to
824 /// \returns true if this base matched the search criteria, false otherwise.
825 typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier,
829 /// \brief Look for entities within the base classes of this C++ class,
830 /// transitively searching all base class subobjects.
832 /// This routine uses the callback function \p BaseMatches to find base
833 /// classes meeting some search criteria, walking all base class subobjects
834 /// and populating the given \p Paths structure with the paths through the
835 /// inheritance hierarchy that resulted in a match. On a successful search,
836 /// the \p Paths structure can be queried to retrieve the matching paths and
837 /// to determine if there were any ambiguities.
839 /// \param BaseMatches callback function used to determine whether a given
840 /// base matches the user-defined search criteria.
842 /// \param UserData user data pointer that will be provided to \p BaseMatches.
844 /// \param Paths used to record the paths from this class to its base class
845 /// subobjects that match the search criteria.
847 /// \returns true if there exists any path from this class to a base class
848 /// subobject that matches the search criteria.
849 bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData,
850 CXXBasePaths &Paths) const;
852 /// \brief Base-class lookup callback that determines whether the given
853 /// base class specifier refers to a specific class declaration.
855 /// This callback can be used with \c lookupInBases() to determine whether
856 /// a given derived class has is a base class subobject of a particular type.
857 /// The user data pointer should refer to the canonical CXXRecordDecl of the
858 /// base class that we are searching for.
859 static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
860 CXXBasePath &Path, void *BaseRecord);
862 /// \brief Base-class lookup callback that determines whether the
863 /// given base class specifier refers to a specific class
864 /// declaration and describes virtual derivation.
866 /// This callback can be used with \c lookupInBases() to determine
867 /// whether a given derived class has is a virtual base class
868 /// subobject of a particular type. The user data pointer should
869 /// refer to the canonical CXXRecordDecl of the base class that we
870 /// are searching for.
871 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
872 CXXBasePath &Path, void *BaseRecord);
874 /// \brief Base-class lookup callback that determines whether there exists
875 /// a tag with the given name.
877 /// This callback can be used with \c lookupInBases() to find tag members
878 /// of the given name within a C++ class hierarchy. The user data pointer
879 /// is an opaque \c DeclarationName pointer.
880 static bool FindTagMember(const CXXBaseSpecifier *Specifier,
881 CXXBasePath &Path, void *Name);
883 /// \brief Base-class lookup callback that determines whether there exists
884 /// a member with the given name.
886 /// This callback can be used with \c lookupInBases() to find members
887 /// of the given name within a C++ class hierarchy. The user data pointer
888 /// is an opaque \c DeclarationName pointer.
889 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
890 CXXBasePath &Path, void *Name);
892 /// \brief Base-class lookup callback that determines whether there exists
893 /// a member with the given name that can be used in a nested-name-specifier.
895 /// This callback can be used with \c lookupInBases() to find membes of
896 /// the given name within a C++ class hierarchy that can occur within
897 /// nested-name-specifiers.
898 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
902 /// \brief Retrieve the final overriders for each virtual member
903 /// function in the class hierarchy where this class is the
904 /// most-derived class in the class hierarchy.
905 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
907 /// viewInheritance - Renders and displays an inheritance diagram
908 /// for this C++ class and all of its base classes (transitively) using
910 void viewInheritance(ASTContext& Context) const;
912 /// MergeAccess - Calculates the access of a decl that is reached
914 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
915 AccessSpecifier DeclAccess) {
916 assert(DeclAccess != AS_none);
917 if (DeclAccess == AS_private) return AS_none;
918 return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
921 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
922 static bool classofKind(Kind K) {
923 return K == CXXRecord ||
924 K == ClassTemplateSpecialization ||
925 K == ClassTemplatePartialSpecialization;
927 static bool classof(const CXXRecordDecl *D) { return true; }
928 static bool classof(const ClassTemplateSpecializationDecl *D) {
933 /// CXXMethodDecl - Represents a static or instance method of a
934 /// struct/union/class.
935 class CXXMethodDecl : public FunctionDecl {
937 CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
938 DeclarationName N, QualType T, TypeSourceInfo *TInfo,
939 bool isStatic, StorageClass SCAsWritten, bool isInline)
940 : FunctionDecl(DK, RD, L, N, T, TInfo, (isStatic ? Static : None),
941 SCAsWritten, isInline) {}
944 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
945 SourceLocation L, DeclarationName N,
946 QualType T, TypeSourceInfo *TInfo,
947 bool isStatic = false,
948 StorageClass SCAsWritten = FunctionDecl::None,
949 bool isInline = false);
951 bool isStatic() const { return getStorageClass() == Static; }
952 bool isInstance() const { return !isStatic(); }
954 bool isVirtual() const {
956 cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
958 if (CD->isVirtualAsWritten())
961 return (CD->begin_overridden_methods() != CD->end_overridden_methods());
964 /// \brief Determine whether this is a usual deallocation function
965 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
966 /// delete or delete[] operator with a particular signature.
967 bool isUsualDeallocationFunction() const;
969 /// \brief Determine whether this is a copy-assignment operator, regardless
970 /// of whether it was declared implicitly or explicitly.
971 bool isCopyAssignmentOperator() const;
973 const CXXMethodDecl *getCanonicalDecl() const {
974 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
976 CXXMethodDecl *getCanonicalDecl() {
977 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
981 void addOverriddenMethod(const CXXMethodDecl *MD);
983 typedef const CXXMethodDecl ** method_iterator;
985 method_iterator begin_overridden_methods() const;
986 method_iterator end_overridden_methods() const;
988 /// getParent - Returns the parent of this method declaration, which
989 /// is the class in which this method is defined.
990 const CXXRecordDecl *getParent() const {
991 return cast<CXXRecordDecl>(FunctionDecl::getParent());
994 /// getParent - Returns the parent of this method declaration, which
995 /// is the class in which this method is defined.
996 CXXRecordDecl *getParent() {
997 return const_cast<CXXRecordDecl *>(
998 cast<CXXRecordDecl>(FunctionDecl::getParent()));
1001 /// getThisType - Returns the type of 'this' pointer.
1002 /// Should only be called for instance methods.
1003 QualType getThisType(ASTContext &C) const;
1005 unsigned getTypeQualifiers() const {
1006 return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1009 bool hasInlineBody() const;
1011 // Implement isa/cast/dyncast/etc.
1012 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1013 static bool classof(const CXXMethodDecl *D) { return true; }
1014 static bool classofKind(Kind K) {
1015 return K >= CXXMethod && K <= CXXConversion;
1019 /// CXXBaseOrMemberInitializer - Represents a C++ base or member
1020 /// initializer, which is part of a constructor initializer that
1021 /// initializes one non-static member variable or one base class. For
1022 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1027 /// class B : public A {
1030 /// B(A& a) : A(a), f(3.14159) { }
1033 class CXXBaseOrMemberInitializer {
1034 /// \brief Either the base class name (stored as a TypeSourceInfo*) or the
1035 /// field being initialized.
1036 llvm::PointerUnion<TypeSourceInfo *, FieldDecl *> BaseOrMember;
1038 /// \brief The source location for the field name.
1039 SourceLocation MemberLocation;
1041 /// \brief The argument used to initialize the base or member, which may
1042 /// end up constructing an object (when multiple arguments are involved).
1045 /// \brief Stores either the constructor to call to initialize this base or
1046 /// member (a CXXConstructorDecl pointer), or stores the anonymous union of
1047 /// which the initialized value is a member.
1049 /// When the value is a FieldDecl pointer, 'BaseOrMember' is class's
1050 /// anonymous union data member, this field holds the FieldDecl for the
1051 /// member of the anonymous union being initialized.
1054 /// X() : au_i1(123) {}
1061 /// In above example, BaseOrMember holds the field decl. for anonymous union
1062 /// and AnonUnionMember holds field decl for au_i1.
1063 FieldDecl *AnonUnionMember;
1065 /// LParenLoc - Location of the left paren of the ctor-initializer.
1066 SourceLocation LParenLoc;
1068 /// RParenLoc - Location of the right paren of the ctor-initializer.
1069 SourceLocation RParenLoc;
1071 /// IsVirtual - If the initializer is a base initializer, this keeps track
1072 /// of whether the base is virtual or not.
1075 /// IsWritten - Whether or not the initializer is explicitly written
1078 /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this
1079 /// number keeps track of the textual order of this initializer in the
1080 /// original sources, counting from 0; otherwise, if IsWritten is false,
1081 /// it stores the number of array index variables stored after this
1082 /// object in memory.
1083 unsigned SourceOrderOrNumArrayIndices : 14;
1085 CXXBaseOrMemberInitializer(ASTContext &Context,
1086 FieldDecl *Member, SourceLocation MemberLoc,
1091 unsigned NumIndices);
1094 /// CXXBaseOrMemberInitializer - Creates a new base-class initializer.
1096 CXXBaseOrMemberInitializer(ASTContext &Context,
1097 TypeSourceInfo *TInfo, bool IsVirtual,
1102 /// CXXBaseOrMemberInitializer - Creates a new member initializer.
1104 CXXBaseOrMemberInitializer(ASTContext &Context,
1105 FieldDecl *Member, SourceLocation MemberLoc,
1110 /// \brief Creates a new member initializer that optionally contains
1111 /// array indices used to describe an elementwise initialization.
1112 static CXXBaseOrMemberInitializer *Create(ASTContext &Context,
1114 SourceLocation MemberLoc,
1119 unsigned NumIndices);
1121 /// \brief Destroy the base or member initializer.
1122 void Destroy(ASTContext &Context);
1124 /// isBaseInitializer - Returns true when this initializer is
1125 /// initializing a base class.
1126 bool isBaseInitializer() const { return BaseOrMember.is<TypeSourceInfo*>(); }
1128 /// isMemberInitializer - Returns true when this initializer is
1129 /// initializing a non-static data member.
1130 bool isMemberInitializer() const { return BaseOrMember.is<FieldDecl*>(); }
1132 /// If this is a base class initializer, returns the type of the
1133 /// base class with location information. Otherwise, returns an NULL
1135 TypeLoc getBaseClassLoc() const;
1137 /// If this is a base class initializer, returns the type of the base class.
1138 /// Otherwise, returns NULL.
1139 const Type *getBaseClass() const;
1140 Type *getBaseClass();
1142 /// Returns whether the base is virtual or not.
1143 bool isBaseVirtual() const {
1144 assert(isBaseInitializer() && "Must call this on base initializer!");
1149 /// \brief Returns the declarator information for a base class initializer.
1150 TypeSourceInfo *getBaseClassInfo() const {
1151 return BaseOrMember.dyn_cast<TypeSourceInfo *>();
1154 /// getMember - If this is a member initializer, returns the
1155 /// declaration of the non-static data member being
1156 /// initialized. Otherwise, returns NULL.
1157 FieldDecl *getMember() {
1158 if (isMemberInitializer())
1159 return BaseOrMember.get<FieldDecl*>();
1164 SourceLocation getMemberLocation() const {
1165 return MemberLocation;
1168 void setMember(FieldDecl *Member) {
1169 assert(isMemberInitializer());
1170 BaseOrMember = Member;
1173 /// \brief Determine the source location of the initializer.
1174 SourceLocation getSourceLocation() const;
1176 /// \brief Determine the source range covering the entire initializer.
1177 SourceRange getSourceRange() const;
1179 /// isWritten - Returns true if this initializer is explicitly written
1180 /// in the source code.
1181 bool isWritten() const { return IsWritten; }
1183 /// \brief Return the source position of the initializer, counting from 0.
1184 /// If the initializer was implicit, -1 is returned.
1185 int getSourceOrder() const {
1186 return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1;
1189 /// \brief Set the source order of this initializer. This method can only
1190 /// be called once for each initializer; it cannot be called on an
1191 /// initializer having a positive number of (implicit) array indices.
1192 void setSourceOrder(int pos) {
1193 assert(!IsWritten &&
1194 "calling twice setSourceOrder() on the same initializer");
1195 assert(SourceOrderOrNumArrayIndices == 0 &&
1196 "setSourceOrder() used when there are implicit array indices");
1198 "setSourceOrder() used to make an initializer implicit");
1200 SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos);
1203 FieldDecl *getAnonUnionMember() const {
1204 return AnonUnionMember;
1206 void setAnonUnionMember(FieldDecl *anonMember) {
1207 AnonUnionMember = anonMember;
1211 SourceLocation getLParenLoc() const { return LParenLoc; }
1212 SourceLocation getRParenLoc() const { return RParenLoc; }
1214 /// \brief Determine the number of implicit array indices used while
1215 /// described an array member initialization.
1216 unsigned getNumArrayIndices() const {
1217 return IsWritten ? 0 : SourceOrderOrNumArrayIndices;
1220 /// \brief Retrieve a particular array index variable used to
1221 /// describe an array member initialization.
1222 VarDecl *getArrayIndex(unsigned I) {
1223 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1224 return reinterpret_cast<VarDecl **>(this + 1)[I];
1226 const VarDecl *getArrayIndex(unsigned I) const {
1227 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1228 return reinterpret_cast<const VarDecl * const *>(this + 1)[I];
1230 void setArrayIndex(unsigned I, VarDecl *Index) {
1231 assert(I < getNumArrayIndices() && "Out of bounds member array index");
1232 reinterpret_cast<VarDecl **>(this + 1)[I] = Index;
1235 Expr *getInit() { return static_cast<Expr *>(Init); }
1238 /// CXXConstructorDecl - Represents a C++ constructor within a
1239 /// class. For example:
1244 /// explicit X(int); // represented by a CXXConstructorDecl.
1247 class CXXConstructorDecl : public CXXMethodDecl {
1248 /// IsExplicitSpecified - Whether this constructor declaration has the
1249 /// 'explicit' keyword specified.
1250 bool IsExplicitSpecified : 1;
1252 /// ImplicitlyDefined - Whether this constructor was implicitly
1253 /// defined by the compiler. When false, the constructor was defined
1254 /// by the user. In C++03, this flag will have the same value as
1255 /// Implicit. In C++0x, however, a constructor that is
1256 /// explicitly defaulted (i.e., defined with " = default") will have
1257 /// @c !Implicit && ImplicitlyDefined.
1258 bool ImplicitlyDefined : 1;
1260 /// Support for base and member initializers.
1261 /// BaseOrMemberInitializers - The arguments used to initialize the base
1263 CXXBaseOrMemberInitializer **BaseOrMemberInitializers;
1264 unsigned NumBaseOrMemberInitializers;
1266 CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
1267 DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1268 bool isExplicitSpecified, bool isInline,
1269 bool isImplicitlyDeclared)
1270 : CXXMethodDecl(CXXConstructor, RD, L, N, T, TInfo, false,
1271 FunctionDecl::None, isInline),
1272 IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false),
1273 BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) {
1274 setImplicit(isImplicitlyDeclared);
1276 virtual void Destroy(ASTContext& C);
1279 static CXXConstructorDecl *Create(ASTContext &C, EmptyShell Empty);
1280 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1281 SourceLocation L, DeclarationName N,
1282 QualType T, TypeSourceInfo *TInfo,
1284 bool isInline, bool isImplicitlyDeclared);
1286 /// isExplicitSpecified - Whether this constructor declaration has the
1287 /// 'explicit' keyword specified.
1288 bool isExplicitSpecified() const { return IsExplicitSpecified; }
1290 /// isExplicit - Whether this constructor was marked "explicit" or not.
1291 bool isExplicit() const {
1292 return cast<CXXConstructorDecl>(getFirstDeclaration())
1293 ->isExplicitSpecified();
1296 /// isImplicitlyDefined - Whether this constructor was implicitly
1297 /// defined. If false, then this constructor was defined by the
1298 /// user. This operation can only be invoked if the constructor has
1299 /// already been defined.
1300 bool isImplicitlyDefined() const {
1301 assert(isThisDeclarationADefinition() &&
1302 "Can only get the implicit-definition flag once the "
1303 "constructor has been defined");
1304 return ImplicitlyDefined;
1307 /// setImplicitlyDefined - Set whether this constructor was
1308 /// implicitly defined or not.
1309 void setImplicitlyDefined(bool ID) {
1310 assert(isThisDeclarationADefinition() &&
1311 "Can only set the implicit-definition flag once the constructor "
1312 "has been defined");
1313 ImplicitlyDefined = ID;
1316 /// init_iterator - Iterates through the member/base initializer list.
1317 typedef CXXBaseOrMemberInitializer **init_iterator;
1319 /// init_const_iterator - Iterates through the memberbase initializer list.
1320 typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
1322 /// init_begin() - Retrieve an iterator to the first initializer.
1323 init_iterator init_begin() { return BaseOrMemberInitializers; }
1324 /// begin() - Retrieve an iterator to the first initializer.
1325 init_const_iterator init_begin() const { return BaseOrMemberInitializers; }
1327 /// init_end() - Retrieve an iterator past the last initializer.
1328 init_iterator init_end() {
1329 return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1331 /// end() - Retrieve an iterator past the last initializer.
1332 init_const_iterator init_end() const {
1333 return BaseOrMemberInitializers + NumBaseOrMemberInitializers;
1336 /// getNumArgs - Determine the number of arguments used to
1337 /// initialize the member or base.
1338 unsigned getNumBaseOrMemberInitializers() const {
1339 return NumBaseOrMemberInitializers;
1342 void setNumBaseOrMemberInitializers(unsigned numBaseOrMemberInitializers) {
1343 NumBaseOrMemberInitializers = numBaseOrMemberInitializers;
1346 void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer ** initializers) {
1347 BaseOrMemberInitializers = initializers;
1349 /// isDefaultConstructor - Whether this constructor is a default
1350 /// constructor (C++ [class.ctor]p5), which can be used to
1351 /// default-initialize a class of this type.
1352 bool isDefaultConstructor() const;
1354 /// isCopyConstructor - Whether this constructor is a copy
1355 /// constructor (C++ [class.copy]p2, which can be used to copy the
1356 /// class. @p TypeQuals will be set to the qualifiers on the
1357 /// argument type. For example, @p TypeQuals would be set to @c
1358 /// QualType::Const for the following copy constructor:
1366 bool isCopyConstructor(unsigned &TypeQuals) const;
1368 /// isCopyConstructor - Whether this constructor is a copy
1369 /// constructor (C++ [class.copy]p2, which can be used to copy the
1371 bool isCopyConstructor() const {
1372 unsigned TypeQuals = 0;
1373 return isCopyConstructor(TypeQuals);
1376 /// isConvertingConstructor - Whether this constructor is a
1377 /// converting constructor (C++ [class.conv.ctor]), which can be
1378 /// used for user-defined conversions.
1379 bool isConvertingConstructor(bool AllowExplicit) const;
1381 /// \brief Determine whether this is a member template specialization that
1382 /// looks like a copy constructor. Such constructors are never used to copy
1384 bool isCopyConstructorLikeSpecialization() const;
1386 // Implement isa/cast/dyncast/etc.
1387 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1388 static bool classof(const CXXConstructorDecl *D) { return true; }
1389 static bool classofKind(Kind K) { return K == CXXConstructor; }
1392 /// CXXDestructorDecl - Represents a C++ destructor within a
1393 /// class. For example:
1398 /// ~X(); // represented by a CXXDestructorDecl.
1401 class CXXDestructorDecl : public CXXMethodDecl {
1402 /// ImplicitlyDefined - Whether this destructor was implicitly
1403 /// defined by the compiler. When false, the destructor was defined
1404 /// by the user. In C++03, this flag will have the same value as
1405 /// Implicit. In C++0x, however, a destructor that is
1406 /// explicitly defaulted (i.e., defined with " = default") will have
1407 /// @c !Implicit && ImplicitlyDefined.
1408 bool ImplicitlyDefined : 1;
1410 FunctionDecl *OperatorDelete;
1412 CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
1413 DeclarationName N, QualType T,
1414 bool isInline, bool isImplicitlyDeclared)
1415 : CXXMethodDecl(CXXDestructor, RD, L, N, T, /*TInfo=*/0, false,
1416 FunctionDecl::None, isInline),
1417 ImplicitlyDefined(false), OperatorDelete(0) {
1418 setImplicit(isImplicitlyDeclared);
1422 static CXXDestructorDecl *Create(ASTContext& C, EmptyShell Empty);
1423 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1424 SourceLocation L, DeclarationName N,
1425 QualType T, bool isInline,
1426 bool isImplicitlyDeclared);
1428 /// isImplicitlyDefined - Whether this destructor was implicitly
1429 /// defined. If false, then this destructor was defined by the
1430 /// user. This operation can only be invoked if the destructor has
1431 /// already been defined.
1432 bool isImplicitlyDefined() const {
1433 assert(isThisDeclarationADefinition() &&
1434 "Can only get the implicit-definition flag once the destructor has been defined");
1435 return ImplicitlyDefined;
1438 /// setImplicitlyDefined - Set whether this destructor was
1439 /// implicitly defined or not.
1440 void setImplicitlyDefined(bool ID) {
1441 assert(isThisDeclarationADefinition() &&
1442 "Can only set the implicit-definition flag once the destructor has been defined");
1443 ImplicitlyDefined = ID;
1446 void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; }
1447 const FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1449 // Implement isa/cast/dyncast/etc.
1450 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1451 static bool classof(const CXXDestructorDecl *D) { return true; }
1452 static bool classofKind(Kind K) { return K == CXXDestructor; }
1455 /// CXXConversionDecl - Represents a C++ conversion function within a
1456 /// class. For example:
1461 /// operator bool();
1464 class CXXConversionDecl : public CXXMethodDecl {
1465 /// IsExplicitSpecified - Whether this conversion function declaration is
1466 /// marked "explicit", meaning that it can only be applied when the user
1467 /// explicitly wrote a cast. This is a C++0x feature.
1468 bool IsExplicitSpecified : 1;
1470 CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
1471 DeclarationName N, QualType T, TypeSourceInfo *TInfo,
1472 bool isInline, bool isExplicitSpecified)
1473 : CXXMethodDecl(CXXConversion, RD, L, N, T, TInfo, false,
1474 FunctionDecl::None, isInline),
1475 IsExplicitSpecified(isExplicitSpecified) { }
1478 static CXXConversionDecl *Create(ASTContext &C, EmptyShell Empty);
1479 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1480 SourceLocation L, DeclarationName N,
1481 QualType T, TypeSourceInfo *TInfo,
1482 bool isInline, bool isExplicit);
1484 /// IsExplicitSpecified - Whether this conversion function declaration is
1485 /// marked "explicit", meaning that it can only be applied when the user
1486 /// explicitly wrote a cast. This is a C++0x feature.
1487 bool isExplicitSpecified() const { return IsExplicitSpecified; }
1489 /// isExplicit - Whether this is an explicit conversion operator
1490 /// (C++0x only). Explicit conversion operators are only considered
1491 /// when the user has explicitly written a cast.
1492 bool isExplicit() const {
1493 return cast<CXXConversionDecl>(getFirstDeclaration())
1494 ->isExplicitSpecified();
1497 /// getConversionType - Returns the type that this conversion
1498 /// function is converting to.
1499 QualType getConversionType() const {
1500 return getType()->getAs<FunctionType>()->getResultType();
1503 // Implement isa/cast/dyncast/etc.
1504 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1505 static bool classof(const CXXConversionDecl *D) { return true; }
1506 static bool classofKind(Kind K) { return K == CXXConversion; }
1509 /// LinkageSpecDecl - This represents a linkage specification. For example:
1510 /// extern "C" void foo();
1512 class LinkageSpecDecl : public Decl, public DeclContext {
1514 /// LanguageIDs - Used to represent the language in a linkage
1515 /// specification. The values are part of the serialization abi for
1516 /// ASTs and cannot be changed without altering that abi. To help
1517 /// ensure a stable abi for this, we choose the DW_LANG_ encodings
1518 /// from the dwarf standard.
1520 lang_c = /* DW_LANG_C */ 0x0002,
1521 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
1524 /// Language - The language for this linkage specification.
1525 LanguageIDs Language;
1527 /// HadBraces - Whether this linkage specification had curly braces or not.
1530 LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
1532 : Decl(LinkageSpec, DC, L),
1533 DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
1536 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
1537 SourceLocation L, LanguageIDs Lang,
1540 /// \brief Return the language specified by this linkage specification.
1541 LanguageIDs getLanguage() const { return Language; }
1543 /// \brief Set the language specified by this linkage specification.
1544 void setLanguage(LanguageIDs L) { Language = L; }
1546 /// \brief Determines whether this linkage specification had braces in
1547 /// its syntactic form.
1548 bool hasBraces() const { return HadBraces; }
1550 /// \brief Set whether this linkage specification has braces in its
1552 void setHasBraces(bool B) { HadBraces = B; }
1554 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1555 static bool classof(const LinkageSpecDecl *D) { return true; }
1556 static bool classofKind(Kind K) { return K == LinkageSpec; }
1557 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
1558 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
1560 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
1561 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
1565 /// UsingDirectiveDecl - Represents C++ using-directive. For example:
1567 /// using namespace std;
1569 // NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide
1570 // artificial name, for all using-directives in order to store
1571 // them in DeclContext effectively.
1572 class UsingDirectiveDecl : public NamedDecl {
1574 /// SourceLocation - Location of 'namespace' token.
1575 SourceLocation NamespaceLoc;
1577 /// \brief The source range that covers the nested-name-specifier
1578 /// preceding the namespace name.
1579 SourceRange QualifierRange;
1581 /// \brief The nested-name-specifier that precedes the namespace
1583 NestedNameSpecifier *Qualifier;
1585 /// IdentLoc - Location of nominated namespace-name identifier.
1586 // FIXME: We don't store location of scope specifier.
1587 SourceLocation IdentLoc;
1589 /// NominatedNamespace - Namespace nominated by using-directive.
1590 NamedDecl *NominatedNamespace;
1592 /// Enclosing context containing both using-directive and nominated
1594 DeclContext *CommonAncestor;
1596 /// getUsingDirectiveName - Returns special DeclarationName used by
1597 /// using-directives. This is only used by DeclContext for storing
1598 /// UsingDirectiveDecls in its lookup structure.
1599 static DeclarationName getName() {
1600 return DeclarationName::getUsingDirectiveName();
1603 UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
1604 SourceLocation NamespcLoc,
1605 SourceRange QualifierRange,
1606 NestedNameSpecifier *Qualifier,
1607 SourceLocation IdentLoc,
1608 NamedDecl *Nominated,
1609 DeclContext *CommonAncestor)
1610 : NamedDecl(Decl::UsingDirective, DC, L, getName()),
1611 NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange),
1612 Qualifier(Qualifier), IdentLoc(IdentLoc),
1613 NominatedNamespace(Nominated),
1614 CommonAncestor(CommonAncestor) {
1618 /// \brief Retrieve the source range of the nested-name-specifier
1619 /// that qualifies the namespace name.
1620 SourceRange getQualifierRange() const { return QualifierRange; }
1622 /// \brief Set the source range of the nested-name-specifier that
1623 /// qualifies the namespace name.
1624 void setQualifierRange(SourceRange R) { QualifierRange = R; }
1626 /// \brief Retrieve the nested-name-specifier that qualifies the
1627 /// name of the namespace.
1628 NestedNameSpecifier *getQualifier() const { return Qualifier; }
1630 /// \brief Set the nested-name-specifier that qualifes the name of the
1632 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1634 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
1635 const NamedDecl *getNominatedNamespaceAsWritten() const {
1636 return NominatedNamespace;
1639 /// getNominatedNamespace - Returns namespace nominated by using-directive.
1640 NamespaceDecl *getNominatedNamespace();
1642 const NamespaceDecl *getNominatedNamespace() const {
1643 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
1646 /// setNominatedNamespace - Set the namespace nominataed by the
1647 /// using-directive.
1648 void setNominatedNamespace(NamedDecl* NS);
1650 /// \brief Returns the common ancestor context of this using-directive and
1651 /// its nominated namespace.
1652 DeclContext *getCommonAncestor() { return CommonAncestor; }
1653 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
1655 /// \brief Set the common ancestor context of this using-directive and its
1656 /// nominated namespace.
1657 void setCommonAncestor(DeclContext* Cxt) { CommonAncestor = Cxt; }
1659 // FIXME: Could omit 'Key' in name.
1660 /// getNamespaceKeyLocation - Returns location of namespace keyword.
1661 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
1663 /// setNamespaceKeyLocation - Set the the location of the namespacekeyword.
1664 void setNamespaceKeyLocation(SourceLocation L) { NamespaceLoc = L; }
1666 /// getIdentLocation - Returns location of identifier.
1667 SourceLocation getIdentLocation() const { return IdentLoc; }
1669 /// setIdentLocation - set the location of the identifier.
1670 void setIdentLocation(SourceLocation L) { IdentLoc = L; }
1672 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
1674 SourceLocation NamespaceLoc,
1675 SourceRange QualifierRange,
1676 NestedNameSpecifier *Qualifier,
1677 SourceLocation IdentLoc,
1678 NamedDecl *Nominated,
1679 DeclContext *CommonAncestor);
1681 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1682 static bool classof(const UsingDirectiveDecl *D) { return true; }
1683 static bool classofKind(Kind K) { return K == Decl::UsingDirective; }
1685 // Friend for getUsingDirectiveName.
1686 friend class DeclContext;
1689 /// NamespaceAliasDecl - Represents a C++ namespace alias. For example:
1692 /// namespace Foo = Bar;
1694 class NamespaceAliasDecl : public NamedDecl {
1695 SourceLocation AliasLoc;
1697 /// \brief The source range that covers the nested-name-specifier
1698 /// preceding the namespace name.
1699 SourceRange QualifierRange;
1701 /// \brief The nested-name-specifier that precedes the namespace
1703 NestedNameSpecifier *Qualifier;
1705 /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc.
1706 SourceLocation IdentLoc;
1708 /// Namespace - The Decl that this alias points to. Can either be a
1709 /// NamespaceDecl or a NamespaceAliasDecl.
1710 NamedDecl *Namespace;
1712 NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
1713 SourceLocation AliasLoc, IdentifierInfo *Alias,
1714 SourceRange QualifierRange,
1715 NestedNameSpecifier *Qualifier,
1716 SourceLocation IdentLoc, NamedDecl *Namespace)
1717 : NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
1718 QualifierRange(QualifierRange), Qualifier(Qualifier),
1719 IdentLoc(IdentLoc), Namespace(Namespace) { }
1722 /// \brief Retrieve the source range of the nested-name-specifier
1723 /// that qualifiers the namespace name.
1724 SourceRange getQualifierRange() const { return QualifierRange; }
1726 /// \brief Set the source range of the nested-name-specifier that qualifies
1727 /// the namespace name.
1728 void setQualifierRange(SourceRange R) { QualifierRange = R; }
1730 /// \brief Retrieve the nested-name-specifier that qualifies the
1731 /// name of the namespace.
1732 NestedNameSpecifier *getQualifier() const { return Qualifier; }
1734 /// \brief Set the nested-name-specifier that qualifies the name of the
1736 void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1738 /// \brief Retrieve the namespace declaration aliased by this directive.
1739 NamespaceDecl *getNamespace() {
1740 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
1741 return AD->getNamespace();
1743 return cast<NamespaceDecl>(Namespace);
1746 const NamespaceDecl *getNamespace() const {
1747 return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
1750 /// Returns the location of the alias name, i.e. 'foo' in
1751 /// "namespace foo = ns::bar;".
1752 SourceLocation getAliasLoc() const { return AliasLoc; }
1754 /// Set the location o;f the alias name, e.e., 'foo' in
1755 /// "namespace foo = ns::bar;".
1756 void setAliasLoc(SourceLocation L) { AliasLoc = L; }
1758 /// Returns the location of the 'namespace' keyword.
1759 SourceLocation getNamespaceLoc() const { return getLocation(); }
1761 /// Returns the location of the identifier in the named namespace.
1762 SourceLocation getTargetNameLoc() const { return IdentLoc; }
1764 /// Set the location of the identifier in the named namespace.
1765 void setTargetNameLoc(SourceLocation L) { IdentLoc = L; }
1767 /// \brief Retrieve the namespace that this alias refers to, which
1768 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
1769 NamedDecl *getAliasedNamespace() const { return Namespace; }
1771 /// \brief Set the namespace or namespace alias pointed to by this
1773 void setAliasedNamespace(NamedDecl *ND) {
1774 assert((isa<NamespaceAliasDecl>(ND) || isa<NamespaceDecl>(ND)) &&
1775 "expecting namespace or namespace alias decl");
1779 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
1780 SourceLocation L, SourceLocation AliasLoc,
1781 IdentifierInfo *Alias,
1782 SourceRange QualifierRange,
1783 NestedNameSpecifier *Qualifier,
1784 SourceLocation IdentLoc,
1785 NamedDecl *Namespace);
1787 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1788 static bool classof(const NamespaceAliasDecl *D) { return true; }
1789 static bool classofKind(Kind K) { return K == Decl::NamespaceAlias; }
1792 /// UsingShadowDecl - Represents a shadow declaration introduced into
1793 /// a scope by a (resolved) using declaration. For example,
1799 /// using A::foo(); // <- a UsingDecl
1800 /// // Also creates a UsingShadowDecl for A::foo in B
1803 class UsingShadowDecl : public NamedDecl {
1804 /// The referenced declaration.
1805 NamedDecl *Underlying;
1807 /// The using declaration which introduced this decl.
1810 UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
1812 : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()),
1813 Underlying(Target), Using(Using) {
1814 IdentifierNamespace = Target->getIdentifierNamespace();
1819 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
1820 SourceLocation Loc, UsingDecl *Using,
1821 NamedDecl *Target) {
1822 return new (C) UsingShadowDecl(DC, Loc, Using, Target);
1825 /// \brief Gets the underlying declaration which has been brought into the
1827 NamedDecl *getTargetDecl() const { return Underlying; }
1829 /// \brief Sets the underlying declaration which has been brought into the
1831 void setTargetDecl(NamedDecl* ND) { Underlying = ND; }
1833 /// \brief Gets the using declaration to which this declaration is tied.
1834 UsingDecl *getUsingDecl() const { return Using; }
1836 /// \brief Sets the using declaration that introduces this target
1838 void setUsingDecl(UsingDecl* UD) { Using = UD; }
1840 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1841 static bool classof(const UsingShadowDecl *D) { return true; }
1842 static bool classofKind(Kind K) { return K == Decl::UsingShadow; }
1845 /// UsingDecl - Represents a C++ using-declaration. For example:
1846 /// using someNameSpace::someIdentifier;
1847 class UsingDecl : public NamedDecl {
1848 /// \brief The source range that covers the nested-name-specifier
1849 /// preceding the declaration name.
1850 SourceRange NestedNameRange;
1852 /// \brief The source location of the "using" location itself.
1853 SourceLocation UsingLocation;
1855 /// \brief Target nested name specifier.
1856 NestedNameSpecifier* TargetNestedName;
1858 /// \brief The collection of shadow declarations associated with
1859 /// this using declaration. This set can change as a class is
1861 llvm::SmallPtrSet<UsingShadowDecl*, 8> Shadows;
1863 // \brief Has 'typename' keyword.
1866 UsingDecl(DeclContext *DC, SourceLocation L, SourceRange NNR,
1867 SourceLocation UL, NestedNameSpecifier* TargetNNS,
1868 DeclarationName Name, bool IsTypeNameArg)
1869 : NamedDecl(Decl::Using, DC, L, Name),
1870 NestedNameRange(NNR), UsingLocation(UL), TargetNestedName(TargetNNS),
1871 IsTypeName(IsTypeNameArg) {
1875 // FIXME: Should be const?
1876 /// \brief Returns the source range that covers the nested-name-specifier
1877 /// preceding the namespace name.
1878 SourceRange getNestedNameRange() { return NestedNameRange; }
1880 /// \brief Set the source range of the nested-name-specifier.
1881 void setNestedNameRange(SourceRange R) { NestedNameRange = R; }
1883 // FIXME; Should be const?
1884 // FIXME: Naming is inconsistent with other get*Loc functions.
1885 /// \brief Returns the source location of the "using" keyword.
1886 SourceLocation getUsingLocation() { return UsingLocation; }
1888 /// \brief Set the source location of the 'using' keyword.
1889 void setUsingLocation(SourceLocation L) { UsingLocation = L; }
1892 /// \brief Get the target nested name declaration.
1893 NestedNameSpecifier* getTargetNestedNameDecl() {
1894 return TargetNestedName;
1897 /// \brief Set the target nested name declaration.
1898 void setTargetNestedNameDecl(NestedNameSpecifier *NNS) {
1899 TargetNestedName = NNS;
1902 /// \brief Return true if the using declaration has 'typename'.
1903 bool isTypeName() const { return IsTypeName; }
1905 /// \brief Sets whether the using declaration has 'typename'.
1906 void setTypeName(bool TN) { IsTypeName = TN; }
1908 typedef llvm::SmallPtrSet<UsingShadowDecl*,8>::const_iterator shadow_iterator;
1909 shadow_iterator shadow_begin() const { return Shadows.begin(); }
1910 shadow_iterator shadow_end() const { return Shadows.end(); }
1912 void addShadowDecl(UsingShadowDecl *S) {
1913 assert(S->getUsingDecl() == this);
1914 if (!Shadows.insert(S)) {
1915 assert(false && "declaration already in set");
1918 void removeShadowDecl(UsingShadowDecl *S) {
1919 assert(S->getUsingDecl() == this);
1920 if (!Shadows.erase(S)) {
1921 assert(false && "declaration not in set");
1925 /// \brief Return the number of shadowed declarations associated with this
1926 /// using declaration.
1927 unsigned getNumShadowDecls() const {
1928 return Shadows.size();
1931 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
1932 SourceLocation IdentL, SourceRange NNR, SourceLocation UsingL,
1933 NestedNameSpecifier* TargetNNS, DeclarationName Name, bool IsTypeNameArg);
1935 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1936 static bool classof(const UsingDecl *D) { return true; }
1937 static bool classofKind(Kind K) { return K == Decl::Using; }
1940 /// UnresolvedUsingValueDecl - Represents a dependent using
1941 /// declaration which was not marked with 'typename'. Unlike
1942 /// non-dependent using declarations, these *only* bring through
1943 /// non-types; otherwise they would break two-phase lookup.
1945 /// template <class T> class A : public Base<T> {
1946 /// using Base<T>::foo;
1948 class UnresolvedUsingValueDecl : public ValueDecl {
1949 /// \brief The source range that covers the nested-name-specifier
1950 /// preceding the declaration name.
1951 SourceRange TargetNestedNameRange;
1953 /// \brief The source location of the 'using' keyword
1954 SourceLocation UsingLocation;
1956 NestedNameSpecifier *TargetNestedNameSpecifier;
1958 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
1959 SourceLocation UsingLoc, SourceRange TargetNNR,
1960 NestedNameSpecifier *TargetNNS,
1961 SourceLocation TargetNameLoc,
1962 DeclarationName TargetName)
1963 : ValueDecl(Decl::UnresolvedUsingValue, DC, TargetNameLoc, TargetName, Ty),
1964 TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
1965 TargetNestedNameSpecifier(TargetNNS)
1969 /// \brief Returns the source range that covers the nested-name-specifier
1970 /// preceding the namespace name.
1971 SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
1973 /// \brief Set the source range coverting the nested-name-specifier preceding
1974 /// the namespace name.
1975 void setTargetNestedNameRange(SourceRange R) { TargetNestedNameRange = R; }
1977 /// \brief Get target nested name declaration.
1978 NestedNameSpecifier* getTargetNestedNameSpecifier() {
1979 return TargetNestedNameSpecifier;
1982 /// \brief Set the nested name declaration.
1983 void setTargetNestedNameSpecifier(NestedNameSpecifier* NNS) {
1984 TargetNestedNameSpecifier = NNS;
1987 /// \brief Returns the source location of the 'using' keyword.
1988 SourceLocation getUsingLoc() const { return UsingLocation; }
1990 /// \brief Set the source location of the 'using' keyword.
1991 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
1993 static UnresolvedUsingValueDecl *
1994 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
1995 SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
1996 SourceLocation TargetNameLoc, DeclarationName TargetName);
1998 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1999 static bool classof(const UnresolvedUsingValueDecl *D) { return true; }
2000 static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingValue; }
2003 /// UnresolvedUsingTypenameDecl - Represents a dependent using
2004 /// declaration which was marked with 'typename'.
2006 /// template <class T> class A : public Base<T> {
2007 /// using typename Base<T>::foo;
2010 /// The type associated with a unresolved using typename decl is
2011 /// currently always a typename type.
2012 class UnresolvedUsingTypenameDecl : public TypeDecl {
2013 /// \brief The source range that covers the nested-name-specifier
2014 /// preceding the declaration name.
2015 SourceRange TargetNestedNameRange;
2017 /// \brief The source location of the 'using' keyword
2018 SourceLocation UsingLocation;
2020 /// \brief The source location of the 'typename' keyword
2021 SourceLocation TypenameLocation;
2023 NestedNameSpecifier *TargetNestedNameSpecifier;
2025 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
2026 SourceLocation TypenameLoc,
2027 SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
2028 SourceLocation TargetNameLoc, IdentifierInfo *TargetName)
2029 : TypeDecl(Decl::UnresolvedUsingTypename, DC, TargetNameLoc, TargetName),
2030 TargetNestedNameRange(TargetNNR), UsingLocation(UsingLoc),
2031 TypenameLocation(TypenameLoc), TargetNestedNameSpecifier(TargetNNS)
2035 /// \brief Returns the source range that covers the nested-name-specifier
2036 /// preceding the namespace name.
2037 SourceRange getTargetNestedNameRange() const { return TargetNestedNameRange; }
2039 /// \brief Set the source range coverting the nested-name-specifier preceding
2040 /// the namespace name.
2041 void setTargetNestedNameRange(SourceRange R) { TargetNestedNameRange = R; }
2043 /// \brief Get target nested name declaration.
2044 NestedNameSpecifier* getTargetNestedNameSpecifier() {
2045 return TargetNestedNameSpecifier;
2048 /// \brief Set the nested name declaration.
2049 void setTargetNestedNameSpecifier(NestedNameSpecifier* NNS) {
2050 TargetNestedNameSpecifier = NNS;
2053 /// \brief Returns the source location of the 'using' keyword.
2054 SourceLocation getUsingLoc() const { return UsingLocation; }
2056 /// \brief Set the source location of the 'using' keyword.
2057 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
2059 /// \brief Returns the source location of the 'typename' keyword.
2060 SourceLocation getTypenameLoc() const { return TypenameLocation; }
2062 /// \brief Set the source location of the 'typename' keyword.
2063 void setTypenameLoc(SourceLocation L) { TypenameLocation = L; }
2065 static UnresolvedUsingTypenameDecl *
2066 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
2067 SourceLocation TypenameLoc,
2068 SourceRange TargetNNR, NestedNameSpecifier *TargetNNS,
2069 SourceLocation TargetNameLoc, DeclarationName TargetName);
2071 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2072 static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; }
2073 static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingTypename; }
2076 /// StaticAssertDecl - Represents a C++0x static_assert declaration.
2077 class StaticAssertDecl : public Decl {
2079 StringLiteral *Message;
2081 StaticAssertDecl(DeclContext *DC, SourceLocation L,
2082 Expr *assertexpr, StringLiteral *message)
2083 : Decl(StaticAssert, DC, L), AssertExpr(assertexpr), Message(message) { }
2086 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
2087 SourceLocation L, Expr *AssertExpr,
2088 StringLiteral *Message);
2090 Expr *getAssertExpr() { return AssertExpr; }
2091 const Expr *getAssertExpr() const { return AssertExpr; }
2093 StringLiteral *getMessage() { return Message; }
2094 const StringLiteral *getMessage() const { return Message; }
2096 virtual ~StaticAssertDecl();
2097 virtual void Destroy(ASTContext& C);
2099 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2100 static bool classof(StaticAssertDecl *D) { return true; }
2101 static bool classofKind(Kind K) { return K == Decl::StaticAssert; }
2104 /// Insertion operator for diagnostics. This allows sending AccessSpecifier's
2105 /// into a diagnostic with <<.
2106 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2107 AccessSpecifier AS);
2109 } // end namespace clang