1 //===--- Sema.h - Semantic Analysis & AST Building --------------*- 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 Sema class, which performs semantic analysis and
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_SEMA_SEMA_H
16 #define LLVM_CLANG_SEMA_SEMA_H
18 #include "clang/Sema/Ownership.h"
19 #include "clang/Sema/AnalysisBasedWarnings.h"
20 #include "clang/Sema/IdentifierResolver.h"
21 #include "clang/Sema/ObjCMethodList.h"
22 #include "clang/Sema/DeclSpec.h"
23 #include "clang/AST/OperationKinds.h"
24 #include "clang/AST/DeclarationName.h"
25 #include "clang/AST/ExternalASTSource.h"
26 #include "clang/Basic/Specifiers.h"
27 #include "clang/Basic/TemplateKinds.h"
28 #include "clang/Basic/TypeTraits.h"
29 #include "llvm/ADT/OwningPtr.h"
30 #include "llvm/ADT/SmallPtrSet.h"
31 #include "llvm/ADT/SmallVector.h"
37 template <typename ValueT
> struct DenseMapInfo
;
38 template <typename ValueT
, typename ValueInfoT
> class DenseSet
;
50 typedef llvm::SmallVector
<CXXBaseSpecifier
*, 4> CXXCastPath
;
51 class CXXConstructorDecl
;
52 class CXXConversionDecl
;
53 class CXXDestructorDecl
;
54 class CXXFieldCollector
;
55 class CXXMemberCallExpr
;
61 class ClassTemplateDecl
;
62 class ClassTemplatePartialSpecializationDecl
;
63 class ClassTemplateSpecializationDecl
;
64 class CodeCompleteConsumer
;
65 class CodeCompletionResult
;
71 class DeducedTemplateArgument
;
72 class DependentDiagnostic
;
73 class DesignatedInitExpr
;
75 class EnumConstantDecl
;
78 class ExternalSemaSource
;
82 class FunctionProtoType
;
83 class FunctionTemplateDecl
;
84 class ImplicitConversionSequence
;
86 class InitializationKind
;
87 class InitializationSequence
;
88 class InitializedEntity
;
92 class LocalInstantiationScope
;
95 class MultiLevelTemplateArgumentList
;
98 class ObjCCategoryDecl
;
99 class ObjCCategoryImplDecl
;
100 class ObjCCompatibleAliasDecl
;
101 class ObjCContainerDecl
;
103 class ObjCImplementationDecl
;
104 class ObjCInterfaceDecl
;
106 template <class T
> class ObjCList
;
107 class ObjCMethodDecl
;
108 class ObjCPropertyDecl
;
109 class ObjCProtocolDecl
;
110 class OverloadCandidateSet
;
114 class PseudoDestructorTypeStorage
;
116 class StandardConversionSequence
;
120 class TargetAttributesSema
;
121 class TemplateArgument
;
122 class TemplateArgumentList
;
123 class TemplateArgumentLoc
;
125 class TemplateParameterList
;
126 class TemplatePartialOrderingContext
;
127 class TemplateTemplateParmDecl
;
131 class UnresolvedLookupExpr
;
132 class UnresolvedMemberExpr
;
133 class UnresolvedSetImpl
;
134 class UnresolvedSetIterator
;
136 class UsingShadowDecl
;
139 class VisibilityAttr
;
140 class VisibleDeclConsumer
;
141 class IndirectFieldDecl
;
144 class AccessedEntity
;
145 class BlockScopeInfo
;
146 class DelayedDiagnostic
;
147 class FunctionScopeInfo
;
148 class TemplateDeductionInfo
;
151 /// \brief Holds a QualType and a TypeSourceInfo* that came out of a declarator
154 /// LocInfoType is a "transient" type, only needed for passing to/from Parser
155 /// and Sema, when we want to preserve type source info for a parsed type.
156 /// It will not participate in the type system semantics in any way.
157 class LocInfoType
: public Type
{
159 // The last number that can fit in Type's TC.
160 // Avoids conflict with an existing Type class.
161 LocInfo
= Type::TypeLast
+ 1
164 TypeSourceInfo
*DeclInfo
;
166 LocInfoType(QualType ty
, TypeSourceInfo
*TInfo
)
167 : Type((TypeClass
)LocInfo
, ty
, ty
->isDependentType(),
168 ty
->isVariablyModifiedType(),
169 ty
->containsUnexpandedParameterPack()),
171 assert(getTypeClass() == (TypeClass
)LocInfo
&& "LocInfo didn't fit in TC?");
176 QualType
getType() const { return getCanonicalTypeInternal(); }
177 TypeSourceInfo
*getTypeSourceInfo() const { return DeclInfo
; }
179 void getAsStringInternal(std::string
&Str
,
180 const PrintingPolicy
&Policy
) const;
182 static bool classof(const Type
*T
) {
183 return T
->getTypeClass() == (TypeClass
)LocInfo
;
185 static bool classof(const LocInfoType
*) { return true; }
188 // FIXME: No way to easily map from TemplateTypeParmTypes to
189 // TemplateTypeParmDecls, so we have this horrible PointerUnion.
190 typedef std::pair
<llvm::PointerUnion
<const TemplateTypeParmType
*, NamedDecl
*>,
191 SourceLocation
> UnexpandedParameterPack
;
193 /// Sema - This implements semantic analysis and AST building for C.
195 Sema(const Sema
&); // DO NOT IMPLEMENT
196 void operator=(const Sema
&); // DO NOT IMPLEMENT
197 mutable const TargetAttributesSema
* TheTargetAttributesSema
;
199 typedef OpaquePtr
<DeclGroupRef
> DeclGroupPtrTy
;
200 typedef OpaquePtr
<TemplateName
> TemplateTy
;
201 typedef OpaquePtr
<QualType
> TypeTy
;
203 typedef CXXBaseSpecifier BaseTy
;
204 typedef CXXBaseOrMemberInitializer MemInitTy
;
207 typedef TemplateParameterList TemplateParamsTy
;
208 typedef NestedNameSpecifier CXXScopeTy
;
210 const LangOptions
&LangOpts
;
213 ASTConsumer
&Consumer
;
215 SourceManager
&SourceMgr
;
217 /// \brief Source of additional semantic information.
218 ExternalSemaSource
*ExternalSource
;
220 /// \brief Code-completion consumer.
221 CodeCompleteConsumer
*CodeCompleter
;
223 /// CurContext - This is the current declaration context of parsing.
224 DeclContext
*CurContext
;
226 /// VAListTagName - The declaration name corresponding to __va_list_tag.
227 /// This is used as part of a hack to omit that class from ADL results.
228 DeclarationName VAListTagName
;
230 /// A RAII object to temporarily push a declaration context.
234 DeclContext
*SavedContext
;
237 ContextRAII(Sema
&S
, DeclContext
*ContextToPush
)
238 : S(S
), SavedContext(S
.CurContext
) {
239 assert(ContextToPush
&& "pushing null context");
240 S
.CurContext
= ContextToPush
;
244 if (!SavedContext
) return;
245 S
.CurContext
= SavedContext
;
254 /// PackContext - Manages the stack for #pragma pack. An alignment
255 /// of 0 indicates default alignment.
256 void *PackContext
; // Really a "PragmaPackStack*"
258 /// VisContext - Manages the stack for #pragma GCC visibility.
259 void *VisContext
; // Really a "PragmaVisStack*"
261 /// \brief Stack containing information about each of the nested
262 /// function, block, and method scopes that are currently active.
264 /// This array is never empty. Clients should ignore the first
265 /// element, which is used to cache a single FunctionScopeInfo
266 /// that's used to parse every top-level function.
267 llvm::SmallVector
<sema::FunctionScopeInfo
*, 4> FunctionScopes
;
269 /// ExprTemporaries - This is the stack of temporaries that are created by
270 /// the current full expression.
271 llvm::SmallVector
<CXXTemporary
*, 8> ExprTemporaries
;
273 /// ExtVectorDecls - This is a list all the extended vector types. This allows
274 /// us to associate a raw vector type with one of the ext_vector type names.
275 /// This is only necessary for issuing pretty diagnostics.
276 llvm::SmallVector
<TypedefDecl
*, 24> ExtVectorDecls
;
278 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
279 llvm::OwningPtr
<CXXFieldCollector
> FieldCollector
;
281 typedef llvm::SmallPtrSet
<const CXXRecordDecl
*, 8> RecordDeclSetTy
;
283 /// PureVirtualClassDiagSet - a set of class declarations which we have
284 /// emitted a list of pure virtual functions. Used to prevent emitting the
285 /// same list more than once.
286 llvm::OwningPtr
<RecordDeclSetTy
> PureVirtualClassDiagSet
;
288 /// \brief A mapping from external names to the most recent
289 /// locally-scoped external declaration with that name.
291 /// This map contains external declarations introduced in local
296 /// void foo(int, int);
300 /// Here, the name "foo" will be associated with the declaration on
301 /// "foo" within f. This name is not visible outside of
302 /// "f". However, we still find it in two cases:
304 /// - If we are declaring another external with the name "foo", we
305 /// can find "foo" as a previous declaration, so that the types
306 /// of this external declaration can be checked for
309 /// - If we would implicitly declare "foo" (e.g., due to a call to
310 /// "foo" in C when no prototype or definition is visible), then
311 /// we find this declaration of "foo" and complain that it is
313 llvm::DenseMap
<DeclarationName
, NamedDecl
*> LocallyScopedExternalDecls
;
315 /// \brief All the tentative definitions encountered in the TU.
316 llvm::SmallVector
<VarDecl
*, 2> TentativeDefinitions
;
318 /// \brief The set of file scoped decls seen so far that have not been used
319 /// and must warn if not used. Only contains the first declaration.
320 llvm::SmallVector
<const DeclaratorDecl
*, 4> UnusedFileScopedDecls
;
322 /// \brief The stack of diagnostics that were delayed due to being
323 /// produced during the parsing of a declaration.
324 llvm::SmallVector
<sema::DelayedDiagnostic
, 0> DelayedDiagnostics
;
326 /// \brief The depth of the current ParsingDeclaration stack.
327 /// If nonzero, we are currently parsing a declaration (and
328 /// hence should delay deprecation warnings).
329 unsigned ParsingDeclDepth
;
331 /// WeakUndeclaredIdentifiers - Identifiers contained in
332 /// #pragma weak before declared. rare. may alias another
333 /// identifier, declared or undeclared
335 IdentifierInfo
*alias
; // alias (optional)
336 SourceLocation loc
; // for diagnostics
337 bool used
; // identifier later declared?
340 : alias(0), loc(SourceLocation()), used(false) {}
341 WeakInfo(IdentifierInfo
*Alias
, SourceLocation Loc
)
342 : alias(Alias
), loc(Loc
), used(false) {}
343 inline IdentifierInfo
* getAlias() const { return alias
; }
344 inline SourceLocation
getLocation() const { return loc
; }
345 void setUsed(bool Used
=true) { used
= Used
; }
346 inline bool getUsed() { return used
; }
347 bool operator==(WeakInfo RHS
) const {
348 return alias
== RHS
.getAlias() && loc
== RHS
.getLocation();
350 bool operator!=(WeakInfo RHS
) const { return !(*this == RHS
); }
352 llvm::DenseMap
<IdentifierInfo
*,WeakInfo
> WeakUndeclaredIdentifiers
;
354 /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
355 /// #pragma weak during processing of other Decls.
356 /// I couldn't figure out a clean way to generate these in-line, so
357 /// we store them here and handle separately -- which is a hack.
358 /// It would be best to refactor this.
359 llvm::SmallVector
<Decl
*,2> WeakTopLevelDecl
;
361 IdentifierResolver IdResolver
;
363 /// Translation Unit Scope - useful to Objective-C actions that need
364 /// to lookup file scope declarations in the "ordinary" C decl namespace.
365 /// For example, user-defined classes, built-in "id" type, etc.
368 /// \brief The C++ "std" namespace, where the standard library resides.
369 LazyDeclPtr StdNamespace
;
371 /// \brief The C++ "std::bad_alloc" class, which is defined by the C++
372 /// standard library.
373 LazyDeclPtr StdBadAlloc
;
375 /// \brief The C++ "type_info" declaration, which is defined in <typeinfo>.
376 RecordDecl
*CXXTypeInfoDecl
;
378 /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files.
379 RecordDecl
*MSVCGuidDecl
;
381 /// A flag to remember whether the implicit forms of operator new and delete
382 /// have been declared.
383 bool GlobalNewDeleteDeclared
;
385 /// \brief The set of declarations that have been referenced within
386 /// a potentially evaluated expression.
387 typedef llvm::SmallVector
<std::pair
<SourceLocation
, Decl
*>, 10>
388 PotentiallyReferencedDecls
;
390 /// \brief A set of diagnostics that may be emitted.
391 typedef llvm::SmallVector
<std::pair
<SourceLocation
, PartialDiagnostic
>, 10>
392 PotentiallyEmittedDiagnostics
;
394 /// \brief Describes how the expressions currently being parsed are
395 /// evaluated at run-time, if at all.
396 enum ExpressionEvaluationContext
{
397 /// \brief The current expression and its subexpressions occur within an
398 /// unevaluated operand (C++0x [expr]p8), such as a constant expression
399 /// or the subexpression of \c sizeof, where the type or the value of the
400 /// expression may be significant but no code will be generated to evaluate
401 /// the value of the expression at run time.
404 /// \brief The current expression is potentially evaluated at run time,
405 /// which means that code may be generated to evaluate the value of the
406 /// expression at run time.
407 PotentiallyEvaluated
,
409 /// \brief The current expression may be potentially evaluated or it may
410 /// be unevaluated, but it is impossible to tell from the lexical context.
411 /// This evaluation context is used primary for the operand of the C++
412 /// \c typeid expression, whose argument is potentially evaluated only when
413 /// it is an lvalue of polymorphic class type (C++ [basic.def.odr]p2).
414 PotentiallyPotentiallyEvaluated
,
416 /// \brief The current expression is potentially evaluated, but any
417 /// declarations referenced inside that expression are only used if
418 /// in fact the current expression is used.
420 /// This value is used when parsing default function arguments, for which
421 /// we would like to provide diagnostics (e.g., passing non-POD arguments
422 /// through varargs) but do not want to mark declarations as "referenced"
423 /// until the default argument is used.
424 PotentiallyEvaluatedIfUsed
427 /// \brief Data structure used to record current or nested
428 /// expression evaluation contexts.
429 struct ExpressionEvaluationContextRecord
{
430 /// \brief The expression evaluation context.
431 ExpressionEvaluationContext Context
;
433 /// \brief The number of temporaries that were active when we
434 /// entered this expression evaluation context.
435 unsigned NumTemporaries
;
437 /// \brief The set of declarations referenced within a
438 /// potentially potentially-evaluated context.
440 /// When leaving a potentially potentially-evaluated context, each
441 /// of these elements will be as referenced if the corresponding
442 /// potentially potentially evaluated expression is potentially
444 PotentiallyReferencedDecls
*PotentiallyReferenced
;
446 /// \brief The set of diagnostics to emit should this potentially
447 /// potentially-evaluated context become evaluated.
448 PotentiallyEmittedDiagnostics
*PotentiallyDiagnosed
;
450 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context
,
451 unsigned NumTemporaries
)
452 : Context(Context
), NumTemporaries(NumTemporaries
),
453 PotentiallyReferenced(0), PotentiallyDiagnosed(0) { }
455 void addReferencedDecl(SourceLocation Loc
, Decl
*Decl
) {
456 if (!PotentiallyReferenced
)
457 PotentiallyReferenced
= new PotentiallyReferencedDecls
;
458 PotentiallyReferenced
->push_back(std::make_pair(Loc
, Decl
));
461 void addDiagnostic(SourceLocation Loc
, const PartialDiagnostic
&PD
) {
462 if (!PotentiallyDiagnosed
)
463 PotentiallyDiagnosed
= new PotentiallyEmittedDiagnostics
;
464 PotentiallyDiagnosed
->push_back(std::make_pair(Loc
, PD
));
468 delete PotentiallyReferenced
;
469 delete PotentiallyDiagnosed
;
470 PotentiallyReferenced
= 0;
471 PotentiallyDiagnosed
= 0;
475 /// A stack of expression evaluation contexts.
476 llvm::SmallVector
<ExpressionEvaluationContextRecord
, 8> ExprEvalContexts
;
478 /// \brief Whether the code handled by Sema should be considered a
479 /// complete translation unit or not.
481 /// When true (which is generally the case), Sema will perform
482 /// end-of-translation-unit semantic tasks (such as creating
483 /// initializers for tentative definitions in C) once parsing has
484 /// completed. This flag will be false when building PCH files,
485 /// since a PCH file is by definition not a complete translation
487 bool CompleteTranslationUnit
;
489 llvm::BumpPtrAllocator BumpAlloc
;
491 /// \brief The number of SFINAE diagnostics that have been trapped.
492 unsigned NumSFINAEErrors
;
494 typedef llvm::DenseMap
<ParmVarDecl
*, llvm::SmallVector
<ParmVarDecl
*, 1> >
495 UnparsedDefaultArgInstantiationsMap
;
497 /// \brief A mapping from parameters with unparsed default arguments to the
498 /// set of instantiations of each parameter.
500 /// This mapping is a temporary data structure used when parsing
501 /// nested class templates or nested classes of class templates,
502 /// where we might end up instantiating an inner class before the
503 /// default arguments of its methods have been parsed.
504 UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations
;
506 // Contains the locations of the beginning of unparsed default
507 // argument locations.
508 llvm::DenseMap
<ParmVarDecl
*,SourceLocation
> UnparsedDefaultArgLocs
;
510 typedef std::pair
<ObjCMethodList
, ObjCMethodList
> GlobalMethods
;
511 typedef llvm::DenseMap
<Selector
, GlobalMethods
> GlobalMethodPool
;
513 /// Method Pool - allows efficient lookup when typechecking messages to "id".
514 /// We need to maintain a list, since selectors can have differing signatures
515 /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
516 /// of selectors are "overloaded").
517 GlobalMethodPool MethodPool
;
519 /// Method selectors used in a @selector expression. Used for implementation
521 llvm::DenseMap
<Selector
, SourceLocation
> ReferencedSelectors
;
523 GlobalMethodPool::iterator
ReadMethodPool(Selector Sel
);
525 /// Private Helper predicate to check for 'self'.
526 bool isSelfExpr(Expr
*RExpr
);
528 Sema(Preprocessor
&pp
, ASTContext
&ctxt
, ASTConsumer
&consumer
,
529 bool CompleteTranslationUnit
= true,
530 CodeCompleteConsumer
*CompletionConsumer
= 0);
533 /// \brief Perform initialization that occurs after the parser has been
534 /// initialized but before it parses anything.
537 const LangOptions
&getLangOptions() const { return LangOpts
; }
538 Diagnostic
&getDiagnostics() const { return Diags
; }
539 SourceManager
&getSourceManager() const { return SourceMgr
; }
540 const TargetAttributesSema
&getTargetAttributesSema() const;
541 Preprocessor
&getPreprocessor() const { return PP
; }
542 ASTContext
&getASTContext() const { return Context
; }
543 ASTConsumer
&getASTConsumer() const { return Consumer
; }
545 /// \brief Helper class that creates diagnostics with optional
546 /// template instantiation stacks.
548 /// This class provides a wrapper around the basic DiagnosticBuilder
549 /// class that emits diagnostics. SemaDiagnosticBuilder is
550 /// responsible for emitting the diagnostic (as DiagnosticBuilder
551 /// does) and, if the diagnostic comes from inside a template
552 /// instantiation, printing the template instantiation stack as
554 class SemaDiagnosticBuilder
: public DiagnosticBuilder
{
559 SemaDiagnosticBuilder(DiagnosticBuilder
&DB
, Sema
&SemaRef
, unsigned DiagID
)
560 : DiagnosticBuilder(DB
), SemaRef(SemaRef
), DiagID(DiagID
) { }
562 explicit SemaDiagnosticBuilder(Sema
&SemaRef
)
563 : DiagnosticBuilder(DiagnosticBuilder::Suppress
), SemaRef(SemaRef
) { }
565 ~SemaDiagnosticBuilder();
568 /// \brief Emit a diagnostic.
569 SemaDiagnosticBuilder
Diag(SourceLocation Loc
, unsigned DiagID
);
571 /// \brief Emit a partial diagnostic.
572 SemaDiagnosticBuilder
Diag(SourceLocation Loc
, const PartialDiagnostic
& PD
);
574 /// \brief Build a partial diagnostic.
575 PartialDiagnostic
PDiag(unsigned DiagID
= 0); // in SemaInternal.h
577 ExprResult
Owned(Expr
* E
) { return E
; }
578 ExprResult
Owned(ExprResult R
) { return R
; }
579 StmtResult
Owned(Stmt
* S
) { return S
; }
581 void ActOnEndOfTranslationUnit();
583 Scope
*getScopeForContext(DeclContext
*Ctx
);
585 void PushFunctionScope();
586 void PushBlockScope(Scope
*BlockScope
, BlockDecl
*Block
);
587 void PopFunctionOrBlockScope();
589 sema::FunctionScopeInfo
*getCurFunction() const {
590 return FunctionScopes
.back();
593 bool hasAnyErrorsInThisFunction() const;
595 /// \brief Retrieve the current block, if any.
596 sema::BlockScopeInfo
*getCurBlock();
598 /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls
599 llvm::SmallVector
<Decl
*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl
; }
601 //===--------------------------------------------------------------------===//
602 // Type Analysis / Processing: SemaType.cpp.
605 QualType
adjustParameterType(QualType T
);
606 QualType
BuildQualifiedType(QualType T
, SourceLocation Loc
, Qualifiers Qs
);
607 QualType
BuildQualifiedType(QualType T
, SourceLocation Loc
, unsigned CVR
) {
608 return BuildQualifiedType(T
, Loc
, Qualifiers::fromCVRMask(CVR
));
610 QualType
BuildPointerType(QualType T
,
611 SourceLocation Loc
, DeclarationName Entity
);
612 QualType
BuildReferenceType(QualType T
, bool LValueRef
,
613 SourceLocation Loc
, DeclarationName Entity
);
614 QualType
BuildArrayType(QualType T
, ArrayType::ArraySizeModifier ASM
,
615 Expr
*ArraySize
, unsigned Quals
,
616 SourceRange Brackets
, DeclarationName Entity
);
617 QualType
BuildExtVectorType(QualType T
, Expr
*ArraySize
,
618 SourceLocation AttrLoc
);
619 QualType
BuildFunctionType(QualType T
,
620 QualType
*ParamTypes
, unsigned NumParamTypes
,
621 bool Variadic
, unsigned Quals
,
622 SourceLocation Loc
, DeclarationName Entity
,
623 FunctionType::ExtInfo Info
);
624 QualType
BuildMemberPointerType(QualType T
, QualType Class
,
626 DeclarationName Entity
);
627 QualType
BuildBlockPointerType(QualType T
,
628 SourceLocation Loc
, DeclarationName Entity
);
629 QualType
BuildParenType(QualType T
);
631 TypeSourceInfo
*GetTypeForDeclarator(Declarator
&D
, Scope
*S
,
632 TagDecl
**OwnedDecl
= 0);
633 TypeSourceInfo
*GetTypeSourceInfoForDeclarator(Declarator
&D
, QualType T
,
634 TypeSourceInfo
*ReturnTypeInfo
);
635 /// \brief Package the given type and TSI into a ParsedType.
636 ParsedType
CreateParsedType(QualType T
, TypeSourceInfo
*TInfo
);
637 DeclarationNameInfo
GetNameForDeclarator(Declarator
&D
);
638 DeclarationNameInfo
GetNameFromUnqualifiedId(const UnqualifiedId
&Name
);
639 static QualType
GetTypeFromParser(ParsedType Ty
, TypeSourceInfo
**TInfo
= 0);
640 bool CheckSpecifiedExceptionType(QualType T
, const SourceRange
&Range
);
641 bool CheckDistantExceptionSpec(QualType T
);
642 bool CheckEquivalentExceptionSpec(FunctionDecl
*Old
, FunctionDecl
*New
);
643 bool CheckEquivalentExceptionSpec(
644 const FunctionProtoType
*Old
, SourceLocation OldLoc
,
645 const FunctionProtoType
*New
, SourceLocation NewLoc
);
646 bool CheckEquivalentExceptionSpec(
647 const PartialDiagnostic
&DiagID
, const PartialDiagnostic
& NoteID
,
648 const FunctionProtoType
*Old
, SourceLocation OldLoc
,
649 const FunctionProtoType
*New
, SourceLocation NewLoc
,
650 bool *MissingExceptionSpecification
= 0,
651 bool *MissingEmptyExceptionSpecification
= 0);
652 bool CheckExceptionSpecSubset(
653 const PartialDiagnostic
&DiagID
, const PartialDiagnostic
& NoteID
,
654 const FunctionProtoType
*Superset
, SourceLocation SuperLoc
,
655 const FunctionProtoType
*Subset
, SourceLocation SubLoc
);
656 bool CheckParamExceptionSpec(const PartialDiagnostic
& NoteID
,
657 const FunctionProtoType
*Target
, SourceLocation TargetLoc
,
658 const FunctionProtoType
*Source
, SourceLocation SourceLoc
);
660 TypeResult
ActOnTypeName(Scope
*S
, Declarator
&D
);
662 bool RequireCompleteType(SourceLocation Loc
, QualType T
,
663 const PartialDiagnostic
&PD
,
664 std::pair
<SourceLocation
, PartialDiagnostic
> Note
);
665 bool RequireCompleteType(SourceLocation Loc
, QualType T
,
666 const PartialDiagnostic
&PD
);
667 bool RequireCompleteType(SourceLocation Loc
, QualType T
,
670 QualType
getElaboratedType(ElaboratedTypeKeyword Keyword
,
671 const CXXScopeSpec
&SS
, QualType T
);
673 QualType
BuildTypeofExprType(Expr
*E
, SourceLocation Loc
);
674 QualType
BuildDecltypeType(Expr
*E
, SourceLocation Loc
);
676 //===--------------------------------------------------------------------===//
677 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
680 DeclGroupPtrTy
ConvertDeclToDeclGroup(Decl
*Ptr
);
682 void DiagnoseUseOfUnimplementedSelectors();
684 ParsedType
getTypeName(IdentifierInfo
&II
, SourceLocation NameLoc
,
685 Scope
*S
, CXXScopeSpec
*SS
= 0,
686 bool isClassName
= false,
687 ParsedType ObjectType
= ParsedType());
688 TypeSpecifierType
isTagName(IdentifierInfo
&II
, Scope
*S
);
689 bool DiagnoseUnknownTypeName(const IdentifierInfo
&II
,
690 SourceLocation IILoc
,
693 ParsedType
&SuggestedType
);
695 Decl
*ActOnDeclarator(Scope
*S
, Declarator
&D
);
697 Decl
*HandleDeclarator(Scope
*S
, Declarator
&D
,
698 MultiTemplateParamsArg TemplateParameterLists
,
699 bool IsFunctionDefinition
);
700 void RegisterLocallyScopedExternCDecl(NamedDecl
*ND
,
701 const LookupResult
&Previous
,
703 void DiagnoseFunctionSpecifiers(Declarator
& D
);
704 void CheckShadow(Scope
*S
, VarDecl
*D
, const LookupResult
& R
);
705 void CheckShadow(Scope
*S
, VarDecl
*D
);
706 void CheckCastAlign(Expr
*Op
, QualType T
, SourceRange TRange
);
707 NamedDecl
* ActOnTypedefDeclarator(Scope
* S
, Declarator
& D
, DeclContext
* DC
,
708 QualType R
, TypeSourceInfo
*TInfo
,
709 LookupResult
&Previous
, bool &Redeclaration
);
710 NamedDecl
* ActOnVariableDeclarator(Scope
* S
, Declarator
& D
, DeclContext
* DC
,
711 QualType R
, TypeSourceInfo
*TInfo
,
712 LookupResult
&Previous
,
713 MultiTemplateParamsArg TemplateParamLists
,
714 bool &Redeclaration
);
715 void CheckVariableDeclaration(VarDecl
*NewVD
, LookupResult
&Previous
,
716 bool &Redeclaration
);
717 NamedDecl
* ActOnFunctionDeclarator(Scope
* S
, Declarator
& D
, DeclContext
* DC
,
718 QualType R
, TypeSourceInfo
*TInfo
,
719 LookupResult
&Previous
,
720 MultiTemplateParamsArg TemplateParamLists
,
721 bool IsFunctionDefinition
,
722 bool &Redeclaration
);
723 bool AddOverriddenMethods(CXXRecordDecl
*DC
, CXXMethodDecl
*MD
);
724 void CheckFunctionDeclaration(Scope
*S
,
725 FunctionDecl
*NewFD
, LookupResult
&Previous
,
726 bool IsExplicitSpecialization
,
728 bool &OverloadableAttrRequired
);
729 void CheckMain(FunctionDecl
*FD
);
730 Decl
*ActOnParamDeclarator(Scope
*S
, Declarator
&D
);
731 ParmVarDecl
*BuildParmVarDeclForTypedef(DeclContext
*DC
,
734 ParmVarDecl
*CheckParameter(DeclContext
*DC
,
735 TypeSourceInfo
*TSInfo
, QualType T
,
736 IdentifierInfo
*Name
,
737 SourceLocation NameLoc
,
739 StorageClass SCAsWritten
);
740 void ActOnParamDefaultArgument(Decl
*param
,
741 SourceLocation EqualLoc
,
743 void ActOnParamUnparsedDefaultArgument(Decl
*param
,
744 SourceLocation EqualLoc
,
745 SourceLocation ArgLoc
);
746 void ActOnParamDefaultArgumentError(Decl
*param
);
747 bool SetParamDefaultArgument(ParmVarDecl
*Param
, Expr
*DefaultArg
,
748 SourceLocation EqualLoc
);
750 void AddInitializerToDecl(Decl
*dcl
, Expr
*init
);
751 void AddInitializerToDecl(Decl
*dcl
, Expr
*init
, bool DirectInit
);
752 void ActOnUninitializedDecl(Decl
*dcl
, bool TypeContainsUndeducedAuto
);
753 void ActOnInitializerError(Decl
*Dcl
);
754 void SetDeclDeleted(Decl
*dcl
, SourceLocation DelLoc
);
755 DeclGroupPtrTy
FinalizeDeclaratorGroup(Scope
*S
, const DeclSpec
&DS
,
758 void ActOnFinishKNRParamDeclarations(Scope
*S
, Declarator
&D
,
759 SourceLocation LocAfterDecls
);
760 Decl
*ActOnStartOfFunctionDef(Scope
*S
, Declarator
&D
);
761 Decl
*ActOnStartOfFunctionDef(Scope
*S
, Decl
*D
);
762 void ActOnStartOfObjCMethodDef(Scope
*S
, Decl
*D
);
764 Decl
*ActOnFinishFunctionBody(Decl
*Decl
, Stmt
*Body
);
765 Decl
*ActOnFinishFunctionBody(Decl
*Decl
, Stmt
*Body
, bool IsInstantiation
);
767 /// \brief Diagnose any unused parameters in the given sequence of
768 /// ParmVarDecl pointers.
769 void DiagnoseUnusedParameters(ParmVarDecl
* const *Begin
,
770 ParmVarDecl
* const *End
);
772 /// \brief Diagnose whether the size of parameters or return value of a
773 /// function or obj-c method definition is pass-by-value and larger than a
774 /// specified threshold.
775 void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl
* const *Begin
,
776 ParmVarDecl
* const *End
,
780 void DiagnoseInvalidJumps(Stmt
*Body
);
781 Decl
*ActOnFileScopeAsmDecl(SourceLocation Loc
, Expr
*expr
);
784 void ActOnPopScope(SourceLocation Loc
, Scope
*S
);
785 void ActOnTranslationUnitScope(Scope
*S
);
787 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
788 /// no declarator (e.g. "struct foo;") is parsed.
789 Decl
*ParsedFreeStandingDeclSpec(Scope
*S
, AccessSpecifier AS
,
792 StmtResult
ActOnVlaStmt(const DeclSpec
&DS
);
794 Decl
*BuildAnonymousStructOrUnion(Scope
*S
, DeclSpec
&DS
,
798 Decl
*BuildMicrosoftCAnonymousStruct(Scope
*S
, DeclSpec
&DS
,
801 bool isAcceptableTagRedeclaration(const TagDecl
*Previous
,
803 SourceLocation NewTagLoc
,
804 const IdentifierInfo
&Name
);
807 TUK_Reference
, // Reference to a tag: 'struct foo *X;'
808 TUK_Declaration
, // Fwd decl of a tag: 'struct foo;'
809 TUK_Definition
, // Definition of a tag: 'struct foo { int X; } Y;'
810 TUK_Friend
// Friend declaration: 'friend struct foo;'
813 Decl
*ActOnTag(Scope
*S
, unsigned TagSpec
, TagUseKind TUK
,
814 SourceLocation KWLoc
, CXXScopeSpec
&SS
,
815 IdentifierInfo
*Name
, SourceLocation NameLoc
,
816 AttributeList
*Attr
, AccessSpecifier AS
,
817 MultiTemplateParamsArg TemplateParameterLists
,
818 bool &OwnedDecl
, bool &IsDependent
, bool ScopedEnum
,
819 bool ScopedEnumUsesClassTag
, TypeResult UnderlyingType
);
821 Decl
*ActOnTemplatedFriendTag(Scope
*S
, SourceLocation FriendLoc
,
822 unsigned TagSpec
, SourceLocation TagLoc
,
824 IdentifierInfo
*Name
, SourceLocation NameLoc
,
826 MultiTemplateParamsArg TempParamLists
);
828 TypeResult
ActOnDependentTag(Scope
*S
,
831 const CXXScopeSpec
&SS
,
832 IdentifierInfo
*Name
,
833 SourceLocation TagLoc
,
834 SourceLocation NameLoc
);
836 void ActOnDefs(Scope
*S
, Decl
*TagD
, SourceLocation DeclStart
,
837 IdentifierInfo
*ClassName
,
838 llvm::SmallVectorImpl
<Decl
*> &Decls
);
839 Decl
*ActOnField(Scope
*S
, Decl
*TagD
, SourceLocation DeclStart
,
840 Declarator
&D
, Expr
*BitfieldWidth
);
842 FieldDecl
*HandleField(Scope
*S
, RecordDecl
*TagD
, SourceLocation DeclStart
,
843 Declarator
&D
, Expr
*BitfieldWidth
,
846 FieldDecl
*CheckFieldDecl(DeclarationName Name
, QualType T
,
847 TypeSourceInfo
*TInfo
,
848 RecordDecl
*Record
, SourceLocation Loc
,
849 bool Mutable
, Expr
*BitfieldWidth
,
851 AccessSpecifier AS
, NamedDecl
*PrevDecl
,
854 enum CXXSpecialMember
{
857 CXXCopyConstructor
= 1,
858 CXXCopyAssignment
= 2,
861 bool CheckNontrivialField(FieldDecl
*FD
);
862 void DiagnoseNontrivial(const RecordType
* Record
, CXXSpecialMember mem
);
863 CXXSpecialMember
getSpecialMember(const CXXMethodDecl
*MD
);
864 void ActOnLastBitfield(SourceLocation DeclStart
, Decl
*IntfDecl
,
865 llvm::SmallVectorImpl
<Decl
*> &AllIvarDecls
);
866 Decl
*ActOnIvar(Scope
*S
, SourceLocation DeclStart
, Decl
*IntfDecl
,
867 Declarator
&D
, Expr
*BitfieldWidth
,
868 tok::ObjCKeywordKind visibility
);
870 // This is used for both record definitions and ObjC interface declarations.
871 void ActOnFields(Scope
* S
, SourceLocation RecLoc
, Decl
*TagDecl
,
872 Decl
**Fields
, unsigned NumFields
,
873 SourceLocation LBrac
, SourceLocation RBrac
,
874 AttributeList
*AttrList
);
876 /// ActOnTagStartDefinition - Invoked when we have entered the
877 /// scope of a tag's definition (e.g., for an enumeration, class,
878 /// struct, or union).
879 void ActOnTagStartDefinition(Scope
*S
, Decl
*TagDecl
);
881 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
882 /// C++ record definition's base-specifiers clause and are starting its
883 /// member declarations.
884 void ActOnStartCXXMemberDeclarations(Scope
*S
, Decl
*TagDecl
,
885 SourceLocation LBraceLoc
);
887 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
888 /// the definition of a tag (enumeration, class, struct, or union).
889 void ActOnTagFinishDefinition(Scope
*S
, Decl
*TagDecl
,
890 SourceLocation RBraceLoc
);
892 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
893 /// error parsing the definition of a tag.
894 void ActOnTagDefinitionError(Scope
*S
, Decl
*TagDecl
);
896 EnumConstantDecl
*CheckEnumConstant(EnumDecl
*Enum
,
897 EnumConstantDecl
*LastEnumConst
,
898 SourceLocation IdLoc
,
902 Decl
*ActOnEnumConstant(Scope
*S
, Decl
*EnumDecl
, Decl
*LastEnumConstant
,
903 SourceLocation IdLoc
, IdentifierInfo
*Id
,
904 AttributeList
*Attrs
,
905 SourceLocation EqualLoc
, Expr
*Val
);
906 void ActOnEnumBody(SourceLocation EnumLoc
, SourceLocation LBraceLoc
,
907 SourceLocation RBraceLoc
, Decl
*EnumDecl
,
908 Decl
**Elements
, unsigned NumElements
,
909 Scope
*S
, AttributeList
*Attr
);
911 DeclContext
*getContainingDC(DeclContext
*DC
);
913 /// Set the current declaration context until it gets popped.
914 void PushDeclContext(Scope
*S
, DeclContext
*DC
);
915 void PopDeclContext();
917 /// EnterDeclaratorContext - Used when we must lookup names in the context
918 /// of a declarator's nested name specifier.
919 void EnterDeclaratorContext(Scope
*S
, DeclContext
*DC
);
920 void ExitDeclaratorContext(Scope
*S
);
922 DeclContext
*getFunctionLevelDeclContext();
924 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
925 /// to the function decl for the function being parsed. If we're currently
926 /// in a 'block', this returns the containing context.
927 FunctionDecl
*getCurFunctionDecl();
929 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
930 /// the method decl for the method being parsed. If we're currently
931 /// in a 'block', this returns the containing context.
932 ObjCMethodDecl
*getCurMethodDecl();
934 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
935 /// or C function we're in, otherwise return null. If we're currently
936 /// in a 'block', this returns the containing context.
937 NamedDecl
*getCurFunctionOrMethodDecl();
939 /// Add this decl to the scope shadowed decl chains.
940 void PushOnScopeChains(NamedDecl
*D
, Scope
*S
, bool AddToContext
= true);
942 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
943 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
944 /// true if 'D' belongs to the given declaration context.
945 bool isDeclInScope(NamedDecl
*&D
, DeclContext
*Ctx
, Scope
*S
= 0);
947 /// Finds the scope corresponding to the given decl context, if it
948 /// happens to be an enclosing scope. Otherwise return NULL.
949 static Scope
*getScopeForDeclContext(Scope
*S
, DeclContext
*DC
);
951 /// Subroutines of ActOnDeclarator().
952 TypedefDecl
*ParseTypedefDecl(Scope
*S
, Declarator
&D
, QualType T
,
953 TypeSourceInfo
*TInfo
);
954 void MergeTypeDefDecl(TypedefDecl
*New
, LookupResult
&OldDecls
);
955 bool MergeFunctionDecl(FunctionDecl
*New
, Decl
*Old
);
956 bool MergeCompatibleFunctionDecls(FunctionDecl
*New
, FunctionDecl
*Old
);
957 void MergeVarDecl(VarDecl
*New
, LookupResult
&OldDecls
);
958 bool MergeCXXFunctionDecl(FunctionDecl
*New
, FunctionDecl
*Old
);
960 // AssignmentAction - This is used by all the assignment diagnostic functions
961 // to represent what is actually causing the operation
962 enum AssignmentAction
{
974 /// This is a legitimate overload: the existing declarations are
975 /// functions or function templates with different signatures.
978 /// This is not an overload because the signature exactly matches
979 /// an existing declaration.
982 /// This is not an overload because the lookup results contain a
986 OverloadKind
CheckOverload(Scope
*S
,
988 const LookupResult
&OldDecls
,
990 bool IsForUsingDecl
);
991 bool IsOverload(FunctionDecl
*New
, FunctionDecl
*Old
, bool IsForUsingDecl
);
993 bool TryImplicitConversion(InitializationSequence
&Sequence
,
994 const InitializedEntity
&Entity
,
996 bool SuppressUserConversions
,
998 bool InOverloadResolution
);
1000 bool IsIntegralPromotion(Expr
*From
, QualType FromType
, QualType ToType
);
1001 bool IsFloatingPointPromotion(QualType FromType
, QualType ToType
);
1002 bool IsComplexPromotion(QualType FromType
, QualType ToType
);
1003 bool IsPointerConversion(Expr
*From
, QualType FromType
, QualType ToType
,
1004 bool InOverloadResolution
,
1005 QualType
& ConvertedType
, bool &IncompatibleObjC
);
1006 bool isObjCPointerConversion(QualType FromType
, QualType ToType
,
1007 QualType
& ConvertedType
, bool &IncompatibleObjC
);
1008 bool FunctionArgTypesAreEqual (FunctionProtoType
* OldType
,
1009 FunctionProtoType
* NewType
);
1011 bool CheckPointerConversion(Expr
*From
, QualType ToType
,
1013 CXXCastPath
& BasePath
,
1014 bool IgnoreBaseAccess
);
1015 bool IsMemberPointerConversion(Expr
*From
, QualType FromType
, QualType ToType
,
1016 bool InOverloadResolution
,
1017 QualType
&ConvertedType
);
1018 bool CheckMemberPointerConversion(Expr
*From
, QualType ToType
,
1020 CXXCastPath
&BasePath
,
1021 bool IgnoreBaseAccess
);
1022 bool IsQualificationConversion(QualType FromType
, QualType ToType
);
1023 bool DiagnoseMultipleUserDefinedConversion(Expr
*From
, QualType ToType
);
1026 ExprResult
PerformCopyInitialization(const InitializedEntity
&Entity
,
1027 SourceLocation EqualLoc
,
1029 bool PerformObjectArgumentInitialization(Expr
*&From
,
1030 NestedNameSpecifier
*Qualifier
,
1031 NamedDecl
*FoundDecl
,
1032 CXXMethodDecl
*Method
);
1034 bool PerformContextuallyConvertToBool(Expr
*&From
);
1035 bool PerformContextuallyConvertToObjCId(Expr
*&From
);
1038 ConvertToIntegralOrEnumerationType(SourceLocation Loc
, Expr
*FromE
,
1039 const PartialDiagnostic
&NotIntDiag
,
1040 const PartialDiagnostic
&IncompleteDiag
,
1041 const PartialDiagnostic
&ExplicitConvDiag
,
1042 const PartialDiagnostic
&ExplicitConvNote
,
1043 const PartialDiagnostic
&AmbigDiag
,
1044 const PartialDiagnostic
&AmbigNote
,
1045 const PartialDiagnostic
&ConvDiag
);
1047 bool PerformObjectMemberConversion(Expr
*&From
,
1048 NestedNameSpecifier
*Qualifier
,
1049 NamedDecl
*FoundDecl
,
1052 // Members have to be NamespaceDecl* or TranslationUnitDecl*.
1053 // TODO: make this is a typesafe union.
1054 typedef llvm::SmallPtrSet
<DeclContext
*, 16> AssociatedNamespaceSet
;
1055 typedef llvm::SmallPtrSet
<CXXRecordDecl
*, 16> AssociatedClassSet
;
1057 void AddOverloadCandidate(NamedDecl
*Function
,
1058 DeclAccessPair FoundDecl
,
1059 Expr
**Args
, unsigned NumArgs
,
1060 OverloadCandidateSet
&CandidateSet
);
1062 void AddOverloadCandidate(FunctionDecl
*Function
,
1063 DeclAccessPair FoundDecl
,
1064 Expr
**Args
, unsigned NumArgs
,
1065 OverloadCandidateSet
& CandidateSet
,
1066 bool SuppressUserConversions
= false,
1067 bool PartialOverloading
= false);
1068 void AddFunctionCandidates(const UnresolvedSetImpl
&Functions
,
1069 Expr
**Args
, unsigned NumArgs
,
1070 OverloadCandidateSet
& CandidateSet
,
1071 bool SuppressUserConversions
= false);
1072 void AddMethodCandidate(DeclAccessPair FoundDecl
,
1073 QualType ObjectType
,
1074 Expr
**Args
, unsigned NumArgs
,
1075 OverloadCandidateSet
& CandidateSet
,
1076 bool SuppressUserConversion
= false);
1077 void AddMethodCandidate(CXXMethodDecl
*Method
,
1078 DeclAccessPair FoundDecl
,
1079 CXXRecordDecl
*ActingContext
, QualType ObjectType
,
1080 Expr
**Args
, unsigned NumArgs
,
1081 OverloadCandidateSet
& CandidateSet
,
1082 bool SuppressUserConversions
= false);
1083 void AddMethodTemplateCandidate(FunctionTemplateDecl
*MethodTmpl
,
1084 DeclAccessPair FoundDecl
,
1085 CXXRecordDecl
*ActingContext
,
1086 const TemplateArgumentListInfo
*ExplicitTemplateArgs
,
1087 QualType ObjectType
,
1088 Expr
**Args
, unsigned NumArgs
,
1089 OverloadCandidateSet
& CandidateSet
,
1090 bool SuppressUserConversions
= false);
1091 void AddTemplateOverloadCandidate(FunctionTemplateDecl
*FunctionTemplate
,
1092 DeclAccessPair FoundDecl
,
1093 const TemplateArgumentListInfo
*ExplicitTemplateArgs
,
1094 Expr
**Args
, unsigned NumArgs
,
1095 OverloadCandidateSet
& CandidateSet
,
1096 bool SuppressUserConversions
= false);
1097 void AddConversionCandidate(CXXConversionDecl
*Conversion
,
1098 DeclAccessPair FoundDecl
,
1099 CXXRecordDecl
*ActingContext
,
1100 Expr
*From
, QualType ToType
,
1101 OverloadCandidateSet
& CandidateSet
);
1102 void AddTemplateConversionCandidate(FunctionTemplateDecl
*FunctionTemplate
,
1103 DeclAccessPair FoundDecl
,
1104 CXXRecordDecl
*ActingContext
,
1105 Expr
*From
, QualType ToType
,
1106 OverloadCandidateSet
&CandidateSet
);
1107 void AddSurrogateCandidate(CXXConversionDecl
*Conversion
,
1108 DeclAccessPair FoundDecl
,
1109 CXXRecordDecl
*ActingContext
,
1110 const FunctionProtoType
*Proto
,
1111 QualType ObjectTy
, Expr
**Args
, unsigned NumArgs
,
1112 OverloadCandidateSet
& CandidateSet
);
1113 void AddMemberOperatorCandidates(OverloadedOperatorKind Op
,
1114 SourceLocation OpLoc
,
1115 Expr
**Args
, unsigned NumArgs
,
1116 OverloadCandidateSet
& CandidateSet
,
1117 SourceRange OpRange
= SourceRange());
1118 void AddBuiltinCandidate(QualType ResultTy
, QualType
*ParamTys
,
1119 Expr
**Args
, unsigned NumArgs
,
1120 OverloadCandidateSet
& CandidateSet
,
1121 bool IsAssignmentOperator
= false,
1122 unsigned NumContextualBoolArguments
= 0);
1123 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op
,
1124 SourceLocation OpLoc
,
1125 Expr
**Args
, unsigned NumArgs
,
1126 OverloadCandidateSet
& CandidateSet
);
1127 void AddArgumentDependentLookupCandidates(DeclarationName Name
,
1129 Expr
**Args
, unsigned NumArgs
,
1130 const TemplateArgumentListInfo
*ExplicitTemplateArgs
,
1131 OverloadCandidateSet
& CandidateSet
,
1132 bool PartialOverloading
= false);
1134 void NoteOverloadCandidate(FunctionDecl
*Fn
);
1136 FunctionDecl
*ResolveAddressOfOverloadedFunction(Expr
*From
, QualType ToType
,
1138 DeclAccessPair
&Found
);
1139 FunctionDecl
*ResolveSingleFunctionTemplateSpecialization(Expr
*From
);
1141 Expr
*FixOverloadedFunctionReference(Expr
*E
,
1142 DeclAccessPair FoundDecl
,
1144 ExprResult
FixOverloadedFunctionReference(ExprResult
,
1145 DeclAccessPair FoundDecl
,
1148 void AddOverloadedCallCandidates(UnresolvedLookupExpr
*ULE
,
1149 Expr
**Args
, unsigned NumArgs
,
1150 OverloadCandidateSet
&CandidateSet
,
1151 bool PartialOverloading
= false);
1153 ExprResult
BuildOverloadedCallExpr(Scope
*S
, Expr
*Fn
,
1154 UnresolvedLookupExpr
*ULE
,
1155 SourceLocation LParenLoc
,
1156 Expr
**Args
, unsigned NumArgs
,
1157 SourceLocation RParenLoc
);
1159 ExprResult
CreateOverloadedUnaryOp(SourceLocation OpLoc
,
1161 const UnresolvedSetImpl
&Fns
,
1164 ExprResult
CreateOverloadedBinOp(SourceLocation OpLoc
,
1166 const UnresolvedSetImpl
&Fns
,
1167 Expr
*LHS
, Expr
*RHS
);
1169 ExprResult
CreateOverloadedArraySubscriptExpr(SourceLocation LLoc
,
1170 SourceLocation RLoc
,
1171 Expr
*Base
,Expr
*Idx
);
1174 BuildCallToMemberFunction(Scope
*S
, Expr
*MemExpr
,
1175 SourceLocation LParenLoc
, Expr
**Args
,
1176 unsigned NumArgs
, SourceLocation RParenLoc
);
1178 BuildCallToObjectOfClassType(Scope
*S
, Expr
*Object
, SourceLocation LParenLoc
,
1179 Expr
**Args
, unsigned NumArgs
,
1180 SourceLocation RParenLoc
);
1182 ExprResult
BuildOverloadedArrowExpr(Scope
*S
, Expr
*Base
,
1183 SourceLocation OpLoc
);
1185 /// CheckCallReturnType - Checks that a call expression's return type is
1186 /// complete. Returns true on failure. The location passed in is the location
1187 /// that best represents the call.
1188 bool CheckCallReturnType(QualType ReturnType
, SourceLocation Loc
,
1189 CallExpr
*CE
, FunctionDecl
*FD
);
1191 /// Helpers for dealing with blocks and functions.
1192 bool CheckParmsForFunctionDef(ParmVarDecl
**Param
, ParmVarDecl
**ParamEnd
,
1193 bool CheckParameterNames
);
1194 void CheckCXXDefaultArguments(FunctionDecl
*FD
);
1195 void CheckExtraCXXDefaultArguments(Declarator
&D
);
1196 Scope
*getNonFieldDeclScope(Scope
*S
);
1198 /// \name Name lookup
1200 /// These routines provide name lookup that is used during semantic
1201 /// analysis to resolve the various kinds of names (identifiers,
1202 /// overloaded operator names, constructor names, etc.) into zero or
1203 /// more declarations within a particular scope. The major entry
1204 /// points are LookupName, which performs unqualified name lookup,
1205 /// and LookupQualifiedName, which performs qualified name lookup.
1207 /// All name lookup is performed based on some specific criteria,
1208 /// which specify what names will be visible to name lookup and how
1209 /// far name lookup should work. These criteria are important both
1210 /// for capturing language semantics (certain lookups will ignore
1211 /// certain names, for example) and for performance, since name
1212 /// lookup is often a bottleneck in the compilation of C++. Name
1213 /// lookup criteria is specified via the LookupCriteria enumeration.
1215 /// The results of name lookup can vary based on the kind of name
1216 /// lookup performed, the current language, and the translation
1217 /// unit. In C, for example, name lookup will either return nothing
1218 /// (no entity found) or a single declaration. In C++, name lookup
1219 /// can additionally refer to a set of overloaded functions or
1220 /// result in an ambiguity. All of the possible results of name
1221 /// lookup are captured by the LookupResult class, which provides
1222 /// the ability to distinguish among them.
1225 /// @brief Describes the kind of name lookup to perform.
1226 enum LookupNameKind
{
1227 /// Ordinary name lookup, which finds ordinary names (functions,
1228 /// variables, typedefs, etc.) in C and most kinds of names
1229 /// (functions, variables, members, types, etc.) in C++.
1230 LookupOrdinaryName
= 0,
1231 /// Tag name lookup, which finds the names of enums, classes,
1232 /// structs, and unions.
1234 /// Member name lookup, which finds the names of
1235 /// class/struct/union members.
1237 /// Look up of an operator name (e.g., operator+) for use with
1238 /// operator overloading. This lookup is similar to ordinary name
1239 /// lookup, but will ignore any declarations that are class members.
1241 /// Look up of a name that precedes the '::' scope resolution
1242 /// operator in C++. This lookup completely ignores operator, object,
1243 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
1244 LookupNestedNameSpecifierName
,
1245 /// Look up a namespace name within a C++ using directive or
1246 /// namespace alias definition, ignoring non-namespace names (C++
1247 /// [basic.lookup.udir]p1).
1248 LookupNamespaceName
,
1249 /// Look up all declarations in a scope with the given name,
1250 /// including resolved using declarations. This is appropriate
1251 /// for checking redeclarations for a using declaration.
1252 LookupUsingDeclName
,
1253 /// Look up an ordinary name that is going to be redeclared as a
1254 /// name with linkage. This lookup ignores any declarations that
1255 /// are outside of the current scope unless they have linkage. See
1256 /// C99 6.2.2p4-5 and C++ [basic.link]p6.
1257 LookupRedeclarationWithLinkage
,
1258 /// Look up the name of an Objective-C protocol.
1259 LookupObjCProtocolName
,
1260 /// \brief Look up any declaration with any name.
1264 /// \brief Specifies whether (or how) name lookup is being performed for a
1265 /// redeclaration (vs. a reference).
1266 enum RedeclarationKind
{
1267 /// \brief The lookup is a reference to this name that is not for the
1268 /// purpose of redeclaring the name.
1269 NotForRedeclaration
= 0,
1270 /// \brief The lookup results will be used for redeclaration of a name,
1271 /// if an entity by that name already exists.
1276 bool CppLookupName(LookupResult
&R
, Scope
*S
);
1279 /// \brief Look up a name, looking for a single declaration. Return
1280 /// null if the results were absent, ambiguous, or overloaded.
1282 /// It is preferable to use the elaborated form and explicitly handle
1283 /// ambiguity and overloaded.
1284 NamedDecl
*LookupSingleName(Scope
*S
, DeclarationName Name
,
1286 LookupNameKind NameKind
,
1287 RedeclarationKind Redecl
1288 = NotForRedeclaration
);
1289 bool LookupName(LookupResult
&R
, Scope
*S
,
1290 bool AllowBuiltinCreation
= false);
1291 bool LookupQualifiedName(LookupResult
&R
, DeclContext
*LookupCtx
,
1292 bool InUnqualifiedLookup
= false);
1293 bool LookupParsedName(LookupResult
&R
, Scope
*S
, CXXScopeSpec
*SS
,
1294 bool AllowBuiltinCreation
= false,
1295 bool EnteringContext
= false);
1296 ObjCProtocolDecl
*LookupProtocol(IdentifierInfo
*II
, SourceLocation IdLoc
);
1298 void LookupOverloadedOperatorName(OverloadedOperatorKind Op
, Scope
*S
,
1299 QualType T1
, QualType T2
,
1300 UnresolvedSetImpl
&Functions
);
1302 DeclContextLookupResult
LookupConstructors(CXXRecordDecl
*Class
);
1303 CXXDestructorDecl
*LookupDestructor(CXXRecordDecl
*Class
);
1305 void ArgumentDependentLookup(DeclarationName Name
, bool Operator
,
1306 Expr
**Args
, unsigned NumArgs
,
1307 ADLResult
&Functions
);
1309 void LookupVisibleDecls(Scope
*S
, LookupNameKind Kind
,
1310 VisibleDeclConsumer
&Consumer
,
1311 bool IncludeGlobalScope
= true);
1312 void LookupVisibleDecls(DeclContext
*Ctx
, LookupNameKind Kind
,
1313 VisibleDeclConsumer
&Consumer
,
1314 bool IncludeGlobalScope
= true);
1316 /// \brief The context in which typo-correction occurs.
1318 /// The typo-correction context affects which keywords (if any) are
1319 /// considered when trying to correct for typos.
1320 enum CorrectTypoContext
{
1321 /// \brief An unknown context, where any keyword might be valid.
1323 /// \brief A context where no keywords are used (e.g. we expect an actual
1326 /// \brief A context where we're correcting a type name.
1328 /// \brief An expression context.
1330 /// \brief A type cast, or anything else that can be followed by a '<'.
1332 /// \brief A member lookup context.
1334 /// \brief An Objective-C ivar lookup context (e.g., self->ivar).
1336 /// \brief An Objective-C property lookup context (e.g., self.prop).
1337 CTC_ObjCPropertyLookup
,
1338 /// \brief The receiver of an Objective-C message send within an
1339 /// Objective-C method where 'super' is a valid keyword.
1340 CTC_ObjCMessageReceiver
1343 DeclarationName
CorrectTypo(LookupResult
&R
, Scope
*S
, CXXScopeSpec
*SS
,
1344 DeclContext
*MemberContext
= 0,
1345 bool EnteringContext
= false,
1346 CorrectTypoContext CTC
= CTC_Unknown
,
1347 const ObjCObjectPointerType
*OPT
= 0);
1349 void FindAssociatedClassesAndNamespaces(Expr
**Args
, unsigned NumArgs
,
1350 AssociatedNamespaceSet
&AssociatedNamespaces
,
1351 AssociatedClassSet
&AssociatedClasses
);
1353 bool DiagnoseAmbiguousLookup(LookupResult
&Result
);
1356 ObjCInterfaceDecl
*getObjCInterfaceDecl(IdentifierInfo
*&Id
,
1357 SourceLocation IdLoc
,
1358 bool TypoCorrection
= false);
1359 NamedDecl
*LazilyCreateBuiltin(IdentifierInfo
*II
, unsigned ID
,
1360 Scope
*S
, bool ForRedeclaration
,
1361 SourceLocation Loc
);
1362 NamedDecl
*ImplicitlyDefineFunction(SourceLocation Loc
, IdentifierInfo
&II
,
1364 void AddKnownFunctionAttributes(FunctionDecl
*FD
);
1366 // More parsing and symbol table subroutines.
1368 // Decl attributes - this routine is the top level dispatcher.
1369 void ProcessDeclAttributes(Scope
*S
, Decl
*D
, const Declarator
&PD
);
1370 void ProcessDeclAttributeList(Scope
*S
, Decl
*D
, const AttributeList
*AL
);
1372 void WarnUndefinedMethod(SourceLocation ImpLoc
, ObjCMethodDecl
*method
,
1373 bool &IncompleteImpl
, unsigned DiagID
);
1374 void WarnConflictingTypedMethods(ObjCMethodDecl
*ImpMethod
,
1375 ObjCMethodDecl
*IntfMethod
);
1377 bool isPropertyReadonly(ObjCPropertyDecl
*PropertyDecl
,
1378 ObjCInterfaceDecl
*IDecl
);
1380 typedef llvm::DenseSet
<Selector
, llvm::DenseMapInfo
<Selector
> > SelectorSet
;
1382 /// CheckProtocolMethodDefs - This routine checks unimplemented
1383 /// methods declared in protocol, and those referenced by it.
1384 /// \param IDecl - Used for checking for methods which may have been
1386 void CheckProtocolMethodDefs(SourceLocation ImpLoc
,
1387 ObjCProtocolDecl
*PDecl
,
1388 bool& IncompleteImpl
,
1389 const SelectorSet
&InsMap
,
1390 const SelectorSet
&ClsMap
,
1391 ObjCContainerDecl
*CDecl
);
1393 /// CheckImplementationIvars - This routine checks if the instance variables
1394 /// listed in the implelementation match those listed in the interface.
1395 void CheckImplementationIvars(ObjCImplementationDecl
*ImpDecl
,
1396 ObjCIvarDecl
**Fields
, unsigned nIvars
,
1397 SourceLocation Loc
);
1399 /// \brief Determine whether we can synthesize a provisional ivar for the
1401 ObjCPropertyDecl
*canSynthesizeProvisionalIvar(IdentifierInfo
*II
);
1403 /// \brief Determine whether we can synthesize a provisional ivar for the
1405 bool canSynthesizeProvisionalIvar(ObjCPropertyDecl
*Property
);
1407 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
1408 /// remains unimplemented in the class or category @implementation.
1409 void ImplMethodsVsClassMethods(Scope
*S
, ObjCImplDecl
* IMPDecl
,
1410 ObjCContainerDecl
* IDecl
,
1411 bool IncompleteImpl
= false);
1413 /// DiagnoseUnimplementedProperties - This routine warns on those properties
1414 /// which must be implemented by this implementation.
1415 void DiagnoseUnimplementedProperties(Scope
*S
, ObjCImplDecl
* IMPDecl
,
1416 ObjCContainerDecl
*CDecl
,
1417 const SelectorSet
&InsMap
);
1419 /// DefaultSynthesizeProperties - This routine default synthesizes all
1420 /// properties which must be synthesized in class's @implementation.
1421 void DefaultSynthesizeProperties (Scope
*S
, ObjCImplDecl
* IMPDecl
,
1422 ObjCInterfaceDecl
*IDecl
);
1424 /// CollectImmediateProperties - This routine collects all properties in
1425 /// the class and its conforming protocols; but not those it its super class.
1426 void CollectImmediateProperties(ObjCContainerDecl
*CDecl
,
1427 llvm::DenseMap
<IdentifierInfo
*, ObjCPropertyDecl
*>& PropMap
,
1428 llvm::DenseMap
<IdentifierInfo
*, ObjCPropertyDecl
*>& SuperPropMap
);
1431 /// LookupPropertyDecl - Looks up a property in the current class and all
1433 ObjCPropertyDecl
*LookupPropertyDecl(const ObjCContainerDecl
*CDecl
,
1434 IdentifierInfo
*II
);
1436 /// Called by ActOnProperty to handle @property declarations in
1437 //// class extensions.
1438 Decl
*HandlePropertyInClassExtension(Scope
*S
,
1439 ObjCCategoryDecl
*CDecl
,
1440 SourceLocation AtLoc
,
1441 FieldDeclarator
&FD
,
1444 const bool isAssign
,
1445 const bool isReadWrite
,
1446 const unsigned Attributes
,
1447 bool *isOverridingProperty
,
1449 tok::ObjCKeywordKind MethodImplKind
);
1451 /// Called by ActOnProperty and HandlePropertyInClassExtension to
1452 /// handle creating the ObjcPropertyDecl for a category or @interface.
1453 ObjCPropertyDecl
*CreatePropertyDecl(Scope
*S
,
1454 ObjCContainerDecl
*CDecl
,
1455 SourceLocation AtLoc
,
1456 FieldDeclarator
&FD
,
1459 const bool isAssign
,
1460 const bool isReadWrite
,
1461 const unsigned Attributes
,
1463 tok::ObjCKeywordKind MethodImplKind
,
1464 DeclContext
*lexicalDC
= 0);
1466 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
1467 /// warning) when atomic property has one but not the other user-declared
1468 /// setter or getter.
1469 void AtomicPropertySetterGetterRules(ObjCImplDecl
* IMPDecl
,
1470 ObjCContainerDecl
* IDecl
);
1472 void DiagnoseDuplicateIvars(ObjCInterfaceDecl
*ID
, ObjCInterfaceDecl
*SID
);
1474 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
1475 /// true, or false, accordingly.
1476 bool MatchTwoMethodDeclarations(const ObjCMethodDecl
*Method
,
1477 const ObjCMethodDecl
*PrevMethod
,
1478 bool matchBasedOnSizeAndAlignment
= false,
1479 bool matchBasedOnStrictEqulity
= false);
1481 /// MatchAllMethodDeclarations - Check methods declaraed in interface or
1482 /// or protocol against those declared in their implementations.
1483 void MatchAllMethodDeclarations(const SelectorSet
&InsMap
,
1484 const SelectorSet
&ClsMap
,
1485 SelectorSet
&InsMapSeen
,
1486 SelectorSet
&ClsMapSeen
,
1487 ObjCImplDecl
* IMPDecl
,
1488 ObjCContainerDecl
* IDecl
,
1489 bool &IncompleteImpl
,
1490 bool ImmediateClass
);
1493 /// AddMethodToGlobalPool - Add an instance or factory method to the global
1494 /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
1495 void AddMethodToGlobalPool(ObjCMethodDecl
*Method
, bool impl
, bool instance
);
1497 /// LookupMethodInGlobalPool - Returns the instance or factory method and
1498 /// optionally warns if there are multiple signatures.
1499 ObjCMethodDecl
*LookupMethodInGlobalPool(Selector Sel
, SourceRange R
,
1500 bool receiverIdOrClass
,
1501 bool warn
, bool instance
);
1504 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
1505 /// unit are added to a global pool. This allows us to efficiently associate
1506 /// a selector with a method declaraation for purposes of typechecking
1507 /// messages sent to "id" (where the class of the object is unknown).
1508 void AddInstanceMethodToGlobalPool(ObjCMethodDecl
*Method
, bool impl
=false) {
1509 AddMethodToGlobalPool(Method
, impl
, /*instance*/true);
1512 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
1513 void AddFactoryMethodToGlobalPool(ObjCMethodDecl
*Method
, bool impl
=false) {
1514 AddMethodToGlobalPool(Method
, impl
, /*instance*/false);
1517 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
1518 /// there are multiple signatures.
1519 ObjCMethodDecl
*LookupInstanceMethodInGlobalPool(Selector Sel
, SourceRange R
,
1520 bool receiverIdOrClass
=false,
1522 return LookupMethodInGlobalPool(Sel
, R
, receiverIdOrClass
,
1523 warn
, /*instance*/true);
1526 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
1527 /// there are multiple signatures.
1528 ObjCMethodDecl
*LookupFactoryMethodInGlobalPool(Selector Sel
, SourceRange R
,
1529 bool receiverIdOrClass
=false,
1531 return LookupMethodInGlobalPool(Sel
, R
, receiverIdOrClass
,
1532 warn
, /*instance*/false);
1535 /// LookupImplementedMethodInGlobalPool - Returns the method which has an
1537 ObjCMethodDecl
*LookupImplementedMethodInGlobalPool(Selector Sel
);
1539 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
1541 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl
*OI
,
1542 llvm::SmallVectorImpl
<ObjCIvarDecl
*> &Ivars
);
1543 //===--------------------------------------------------------------------===//
1544 // Statement Parsing Callbacks: SemaStmt.cpp.
1548 FullExprArg(Sema
&actions
) : E(0) { }
1550 // FIXME: The const_cast here is ugly. RValue references would make this
1551 // much nicer (or we could duplicate a bunch of the move semantics
1552 // emulation code from Ownership.h).
1553 FullExprArg(const FullExprArg
& Other
) : E(Other
.E
) {}
1555 ExprResult
release() {
1559 Expr
*get() const { return E
; }
1561 Expr
*operator->() {
1566 // FIXME: No need to make the entire Sema class a friend when it's just
1567 // Sema::MakeFullExpr that needs access to the constructor below.
1570 explicit FullExprArg(Expr
*expr
) : E(expr
) {}
1575 FullExprArg
MakeFullExpr(Expr
*Arg
) {
1576 return FullExprArg(ActOnFinishFullExpr(Arg
).release());
1579 StmtResult
ActOnExprStmt(FullExprArg Expr
);
1581 StmtResult
ActOnNullStmt(SourceLocation SemiLoc
,
1582 bool LeadingEmptyMacro
= false);
1583 StmtResult
ActOnCompoundStmt(SourceLocation L
, SourceLocation R
,
1586 StmtResult
ActOnDeclStmt(DeclGroupPtrTy Decl
,
1587 SourceLocation StartLoc
,
1588 SourceLocation EndLoc
);
1589 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl
);
1590 StmtResult
ActOnForEachLValueExpr(Expr
*E
);
1591 StmtResult
ActOnCaseStmt(SourceLocation CaseLoc
, Expr
*LHSVal
,
1592 SourceLocation DotDotDotLoc
, Expr
*RHSVal
,
1593 SourceLocation ColonLoc
);
1594 void ActOnCaseStmtBody(Stmt
*CaseStmt
, Stmt
*SubStmt
);
1596 StmtResult
ActOnDefaultStmt(SourceLocation DefaultLoc
,
1597 SourceLocation ColonLoc
,
1598 Stmt
*SubStmt
, Scope
*CurScope
);
1599 StmtResult
ActOnLabelStmt(SourceLocation IdentLoc
, IdentifierInfo
*II
,
1600 SourceLocation ColonLoc
, Stmt
*SubStmt
,
1601 const AttributeList
*Attr
);
1602 StmtResult
ActOnLabelStmt(SourceLocation IdentLoc
, IdentifierInfo
*II
,
1603 SourceLocation ColonLoc
, Stmt
*SubStmt
,
1604 bool HasUnusedAttr
);
1605 StmtResult
ActOnIfStmt(SourceLocation IfLoc
,
1606 FullExprArg CondVal
, Decl
*CondVar
,
1608 SourceLocation ElseLoc
, Stmt
*ElseVal
);
1609 StmtResult
ActOnStartOfSwitchStmt(SourceLocation SwitchLoc
,
1612 StmtResult
ActOnFinishSwitchStmt(SourceLocation SwitchLoc
,
1613 Stmt
*Switch
, Stmt
*Body
);
1614 StmtResult
ActOnWhileStmt(SourceLocation WhileLoc
,
1616 Decl
*CondVar
, Stmt
*Body
);
1617 StmtResult
ActOnDoStmt(SourceLocation DoLoc
, Stmt
*Body
,
1618 SourceLocation WhileLoc
,
1619 SourceLocation CondLParen
, Expr
*Cond
,
1620 SourceLocation CondRParen
);
1622 StmtResult
ActOnForStmt(SourceLocation ForLoc
,
1623 SourceLocation LParenLoc
,
1624 Stmt
*First
, FullExprArg Second
,
1627 SourceLocation RParenLoc
,
1629 StmtResult
ActOnObjCForCollectionStmt(SourceLocation ForColLoc
,
1630 SourceLocation LParenLoc
,
1631 Stmt
*First
, Expr
*Second
,
1632 SourceLocation RParenLoc
, Stmt
*Body
);
1634 StmtResult
ActOnGotoStmt(SourceLocation GotoLoc
,
1635 SourceLocation LabelLoc
,
1636 IdentifierInfo
*LabelII
);
1637 StmtResult
ActOnIndirectGotoStmt(SourceLocation GotoLoc
,
1638 SourceLocation StarLoc
,
1640 StmtResult
ActOnContinueStmt(SourceLocation ContinueLoc
, Scope
*CurScope
);
1641 StmtResult
ActOnBreakStmt(SourceLocation GotoLoc
, Scope
*CurScope
);
1643 StmtResult
ActOnReturnStmt(SourceLocation ReturnLoc
, Expr
*RetValExp
);
1644 StmtResult
ActOnBlockReturnStmt(SourceLocation ReturnLoc
, Expr
*RetValExp
);
1646 StmtResult
ActOnAsmStmt(SourceLocation AsmLoc
,
1647 bool IsSimple
, bool IsVolatile
,
1648 unsigned NumOutputs
, unsigned NumInputs
,
1649 IdentifierInfo
**Names
,
1650 MultiExprArg Constraints
,
1653 MultiExprArg Clobbers
,
1654 SourceLocation RParenLoc
,
1655 bool MSAsm
= false);
1658 VarDecl
*BuildObjCExceptionDecl(TypeSourceInfo
*TInfo
, QualType ExceptionType
,
1659 IdentifierInfo
*Name
, SourceLocation NameLoc
,
1660 bool Invalid
= false);
1662 Decl
*ActOnObjCExceptionDecl(Scope
*S
, Declarator
&D
);
1664 StmtResult
ActOnObjCAtCatchStmt(SourceLocation AtLoc
, SourceLocation RParen
,
1665 Decl
*Parm
, Stmt
*Body
);
1667 StmtResult
ActOnObjCAtFinallyStmt(SourceLocation AtLoc
, Stmt
*Body
);
1669 StmtResult
ActOnObjCAtTryStmt(SourceLocation AtLoc
, Stmt
*Try
,
1670 MultiStmtArg Catch
, Stmt
*Finally
);
1672 StmtResult
BuildObjCAtThrowStmt(SourceLocation AtLoc
, Expr
*Throw
);
1673 StmtResult
ActOnObjCAtThrowStmt(SourceLocation AtLoc
, Expr
*Throw
,
1675 StmtResult
ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc
,
1679 VarDecl
*BuildExceptionDeclaration(Scope
*S
,
1680 TypeSourceInfo
*TInfo
,
1681 IdentifierInfo
*Name
,
1682 SourceLocation Loc
);
1683 Decl
*ActOnExceptionDeclarator(Scope
*S
, Declarator
&D
);
1685 StmtResult
ActOnCXXCatchBlock(SourceLocation CatchLoc
,
1686 Decl
*ExDecl
, Stmt
*HandlerBlock
);
1687 StmtResult
ActOnCXXTryBlock(SourceLocation TryLoc
, Stmt
*TryBlock
,
1688 MultiStmtArg Handlers
);
1689 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt
*TryBlock
);
1691 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl
*D
) const;
1693 /// \brief If it's a file scoped decl that must warn if not used, keep track
1695 void MarkUnusedFileScopedDecl(const DeclaratorDecl
*D
);
1697 /// DiagnoseUnusedExprResult - If the statement passed in is an expression
1698 /// whose result is unused, warn.
1699 void DiagnoseUnusedExprResult(const Stmt
*S
);
1700 void DiagnoseUnusedDecl(const NamedDecl
*ND
);
1702 typedef uintptr_t ParsingDeclStackState
;
1704 ParsingDeclStackState
PushParsingDeclaration();
1705 void PopParsingDeclaration(ParsingDeclStackState S
, Decl
*D
);
1706 void EmitDeprecationWarning(NamedDecl
*D
, llvm::StringRef Message
,
1707 SourceLocation Loc
, bool UnkownObjCClass
=false);
1709 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic
&DD
, Decl
*Ctx
);
1711 //===--------------------------------------------------------------------===//
1712 // Expression Parsing Callbacks: SemaExpr.cpp.
1714 bool DiagnoseUseOfDecl(NamedDecl
*D
, SourceLocation Loc
,
1715 bool UnkownObjCClass
=false);
1716 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl
*PD
,
1717 ObjCMethodDecl
*Getter
,
1718 SourceLocation Loc
);
1719 void DiagnoseSentinelCalls(NamedDecl
*D
, SourceLocation Loc
,
1720 Expr
**Args
, unsigned NumArgs
);
1722 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext
);
1724 void PopExpressionEvaluationContext();
1726 void MarkDeclarationReferenced(SourceLocation Loc
, Decl
*D
);
1727 void MarkDeclarationsReferencedInType(SourceLocation Loc
, QualType T
);
1728 void MarkDeclarationsReferencedInExpr(Expr
*E
);
1729 bool DiagRuntimeBehavior(SourceLocation Loc
, const PartialDiagnostic
&PD
);
1731 // Primary Expressions.
1732 SourceRange
getExprRange(Expr
*E
) const;
1734 ExprResult
ActOnIdExpression(Scope
*S
, CXXScopeSpec
&SS
, UnqualifiedId
&Name
,
1735 bool HasTrailingLParen
, bool IsAddressOfOperand
);
1737 bool DiagnoseEmptyLookup(Scope
*S
, CXXScopeSpec
&SS
, LookupResult
&R
,
1738 CorrectTypoContext CTC
= CTC_Unknown
);
1740 ExprResult
LookupInObjCMethod(LookupResult
&R
, Scope
*S
, IdentifierInfo
*II
,
1741 bool AllowBuiltinCreation
=false);
1743 ExprResult
ActOnDependentIdExpression(const CXXScopeSpec
&SS
,
1744 const DeclarationNameInfo
&NameInfo
,
1745 bool isAddressOfOperand
,
1746 const TemplateArgumentListInfo
*TemplateArgs
);
1748 ExprResult
BuildDeclRefExpr(ValueDecl
*D
, QualType Ty
,
1751 const CXXScopeSpec
*SS
= 0);
1752 ExprResult
BuildDeclRefExpr(ValueDecl
*D
, QualType Ty
,
1754 const DeclarationNameInfo
&NameInfo
,
1755 const CXXScopeSpec
*SS
= 0);
1757 BuildAnonymousStructUnionMemberReference(SourceLocation Loc
,
1758 IndirectFieldDecl
*IndirectField
,
1759 Expr
*BaseObjectExpr
= 0,
1760 SourceLocation OpLoc
= SourceLocation());
1761 ExprResult
BuildPossibleImplicitMemberExpr(const CXXScopeSpec
&SS
,
1763 const TemplateArgumentListInfo
*TemplateArgs
);
1764 ExprResult
BuildImplicitMemberExpr(const CXXScopeSpec
&SS
,
1766 const TemplateArgumentListInfo
*TemplateArgs
,
1767 bool IsDefiniteInstance
);
1768 bool UseArgumentDependentLookup(const CXXScopeSpec
&SS
,
1769 const LookupResult
&R
,
1770 bool HasTrailingLParen
);
1772 ExprResult
BuildQualifiedDeclarationNameExpr(CXXScopeSpec
&SS
,
1773 const DeclarationNameInfo
&NameInfo
);
1774 ExprResult
BuildDependentDeclRefExpr(const CXXScopeSpec
&SS
,
1775 const DeclarationNameInfo
&NameInfo
,
1776 const TemplateArgumentListInfo
*TemplateArgs
);
1778 ExprResult
BuildDeclarationNameExpr(const CXXScopeSpec
&SS
,
1781 ExprResult
BuildDeclarationNameExpr(const CXXScopeSpec
&SS
,
1782 const DeclarationNameInfo
&NameInfo
,
1785 ExprResult
ActOnPredefinedExpr(SourceLocation Loc
, tok::TokenKind Kind
);
1786 ExprResult
ActOnNumericConstant(const Token
&);
1787 ExprResult
ActOnCharacterConstant(const Token
&);
1788 ExprResult
ActOnParenExpr(SourceLocation L
, SourceLocation R
, Expr
*Val
);
1789 ExprResult
ActOnParenOrParenListExpr(SourceLocation L
,
1792 ParsedType TypeOfCast
= ParsedType());
1794 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
1795 /// fragments (e.g. "foo" "bar" L"baz").
1796 ExprResult
ActOnStringLiteral(const Token
*Toks
, unsigned NumToks
);
1798 // Binary/Unary Operators. 'Tok' is the token for the operator.
1799 ExprResult
CreateBuiltinUnaryOp(SourceLocation OpLoc
, unsigned OpcIn
,
1801 ExprResult
BuildUnaryOp(Scope
*S
, SourceLocation OpLoc
,
1802 UnaryOperatorKind Opc
, Expr
*input
);
1803 ExprResult
ActOnUnaryOp(Scope
*S
, SourceLocation OpLoc
,
1804 tok::TokenKind Op
, Expr
*Input
);
1806 ExprResult
CreateSizeOfAlignOfExpr(TypeSourceInfo
*T
,
1807 SourceLocation OpLoc
,
1808 bool isSizeOf
, SourceRange R
);
1809 ExprResult
CreateSizeOfAlignOfExpr(Expr
*E
, SourceLocation OpLoc
,
1810 bool isSizeOf
, SourceRange R
);
1812 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc
, bool isSizeof
, bool isType
,
1813 void *TyOrEx
, const SourceRange
&ArgRange
);
1815 ExprResult
CheckPlaceholderExpr(Expr
*E
, SourceLocation Loc
);
1817 bool CheckSizeOfAlignOfOperand(QualType type
, SourceLocation OpLoc
,
1818 SourceRange R
, bool isSizeof
);
1820 ExprResult
ActOnPostfixUnaryOp(Scope
*S
, SourceLocation OpLoc
,
1821 tok::TokenKind Kind
, Expr
*Input
);
1823 ExprResult
ActOnArraySubscriptExpr(Scope
*S
, Expr
*Base
, SourceLocation LLoc
,
1824 Expr
*Idx
, SourceLocation RLoc
);
1825 ExprResult
CreateBuiltinArraySubscriptExpr(Expr
*Base
, SourceLocation LLoc
,
1826 Expr
*Idx
, SourceLocation RLoc
);
1828 ExprResult
BuildMemberReferenceExpr(Expr
*Base
, QualType BaseType
,
1829 SourceLocation OpLoc
, bool IsArrow
,
1831 NamedDecl
*FirstQualifierInScope
,
1832 const DeclarationNameInfo
&NameInfo
,
1833 const TemplateArgumentListInfo
*TemplateArgs
);
1835 ExprResult
BuildMemberReferenceExpr(Expr
*Base
, QualType BaseType
,
1836 SourceLocation OpLoc
, bool IsArrow
,
1837 const CXXScopeSpec
&SS
,
1838 NamedDecl
*FirstQualifierInScope
,
1840 const TemplateArgumentListInfo
*TemplateArgs
,
1841 bool SuppressQualifierCheck
= false);
1843 ExprResult
LookupMemberExpr(LookupResult
&R
, Expr
*&Base
,
1844 bool &IsArrow
, SourceLocation OpLoc
,
1847 bool HasTemplateArgs
);
1849 bool CheckQualifiedMemberReference(Expr
*BaseExpr
, QualType BaseType
,
1850 const CXXScopeSpec
&SS
,
1851 const LookupResult
&R
);
1853 ExprResult
ActOnDependentMemberExpr(Expr
*Base
, QualType BaseType
,
1854 bool IsArrow
, SourceLocation OpLoc
,
1855 const CXXScopeSpec
&SS
,
1856 NamedDecl
*FirstQualifierInScope
,
1857 const DeclarationNameInfo
&NameInfo
,
1858 const TemplateArgumentListInfo
*TemplateArgs
);
1860 ExprResult
ActOnMemberAccessExpr(Scope
*S
, Expr
*Base
,
1861 SourceLocation OpLoc
,
1862 tok::TokenKind OpKind
,
1864 UnqualifiedId
&Member
,
1866 bool HasTrailingLParen
);
1868 void ActOnDefaultCtorInitializers(Decl
*CDtorDecl
);
1869 bool ConvertArgumentsForCall(CallExpr
*Call
, Expr
*Fn
,
1870 FunctionDecl
*FDecl
,
1871 const FunctionProtoType
*Proto
,
1872 Expr
**Args
, unsigned NumArgs
,
1873 SourceLocation RParenLoc
);
1875 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
1876 /// This provides the location of the left/right parens and a list of comma
1878 ExprResult
ActOnCallExpr(Scope
*S
, Expr
*Fn
, SourceLocation LParenLoc
,
1879 MultiExprArg Args
, SourceLocation RParenLoc
);
1880 ExprResult
BuildResolvedCallExpr(Expr
*Fn
, NamedDecl
*NDecl
,
1881 SourceLocation LParenLoc
,
1882 Expr
**Args
, unsigned NumArgs
,
1883 SourceLocation RParenLoc
);
1885 ExprResult
ActOnCastExpr(Scope
*S
, SourceLocation LParenLoc
,
1886 ParsedType Ty
, SourceLocation RParenLoc
,
1888 ExprResult
BuildCStyleCastExpr(SourceLocation LParenLoc
,
1890 SourceLocation RParenLoc
,
1893 bool TypeIsVectorType(ParsedType Ty
) {
1894 return GetTypeFromParser(Ty
)->isVectorType();
1897 ExprResult
MaybeConvertParenListExprToParenExpr(Scope
*S
, Expr
*ME
);
1898 ExprResult
ActOnCastOfParenListExpr(Scope
*S
, SourceLocation LParenLoc
,
1899 SourceLocation RParenLoc
, Expr
*E
,
1900 TypeSourceInfo
*TInfo
);
1902 ExprResult
ActOnCompoundLiteral(SourceLocation LParenLoc
,
1904 SourceLocation RParenLoc
,
1907 ExprResult
BuildCompoundLiteralExpr(SourceLocation LParenLoc
,
1908 TypeSourceInfo
*TInfo
,
1909 SourceLocation RParenLoc
,
1912 ExprResult
ActOnInitList(SourceLocation LParenLoc
,
1913 MultiExprArg InitList
,
1914 SourceLocation RParenLoc
);
1916 ExprResult
ActOnDesignatedInitializer(Designation
&Desig
,
1921 ExprResult
ActOnBinOp(Scope
*S
, SourceLocation TokLoc
,
1922 tok::TokenKind Kind
, Expr
*LHS
, Expr
*RHS
);
1923 ExprResult
BuildBinOp(Scope
*S
, SourceLocation OpLoc
,
1924 BinaryOperatorKind Opc
, Expr
*lhs
, Expr
*rhs
);
1925 ExprResult
CreateBuiltinBinOp(SourceLocation TokLoc
,
1926 unsigned Opc
, Expr
*lhs
, Expr
*rhs
);
1928 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
1929 /// in the case of a the GNU conditional expr extension.
1930 ExprResult
ActOnConditionalOp(SourceLocation QuestionLoc
,
1931 SourceLocation ColonLoc
,
1932 Expr
*Cond
, Expr
*LHS
, Expr
*RHS
);
1934 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1935 ExprResult
ActOnAddrLabel(SourceLocation OpLoc
,
1936 SourceLocation LabLoc
,
1937 IdentifierInfo
*LabelII
);
1939 ExprResult
ActOnStmtExpr(SourceLocation LPLoc
, Stmt
*SubStmt
,
1940 SourceLocation RPLoc
); // "({..})"
1942 // __builtin_offsetof(type, identifier(.identifier|[expr])*)
1943 struct OffsetOfComponent
{
1944 SourceLocation LocStart
, LocEnd
;
1945 bool isBrackets
; // true if [expr], false if .ident
1947 IdentifierInfo
*IdentInfo
;
1952 /// __builtin_offsetof(type, a.b[123][456].c)
1953 ExprResult
BuildBuiltinOffsetOf(SourceLocation BuiltinLoc
,
1954 TypeSourceInfo
*TInfo
,
1955 OffsetOfComponent
*CompPtr
,
1956 unsigned NumComponents
,
1957 SourceLocation RParenLoc
);
1958 ExprResult
ActOnBuiltinOffsetOf(Scope
*S
,
1959 SourceLocation BuiltinLoc
,
1960 SourceLocation TypeLoc
,
1962 OffsetOfComponent
*CompPtr
,
1963 unsigned NumComponents
,
1964 SourceLocation RParenLoc
);
1966 // __builtin_choose_expr(constExpr, expr1, expr2)
1967 ExprResult
ActOnChooseExpr(SourceLocation BuiltinLoc
,
1968 Expr
*cond
, Expr
*expr1
,
1969 Expr
*expr2
, SourceLocation RPLoc
);
1971 // __builtin_va_arg(expr, type)
1972 ExprResult
ActOnVAArg(SourceLocation BuiltinLoc
,
1973 Expr
*expr
, ParsedType type
,
1974 SourceLocation RPLoc
);
1975 ExprResult
BuildVAArgExpr(SourceLocation BuiltinLoc
,
1976 Expr
*expr
, TypeSourceInfo
*TInfo
,
1977 SourceLocation RPLoc
);
1980 ExprResult
ActOnGNUNullExpr(SourceLocation TokenLoc
);
1982 //===------------------------- "Block" Extension ------------------------===//
1984 /// ActOnBlockStart - This callback is invoked when a block literal is
1986 void ActOnBlockStart(SourceLocation CaretLoc
, Scope
*CurScope
);
1988 /// ActOnBlockArguments - This callback allows processing of block arguments.
1989 /// If there are no arguments, this is still invoked.
1990 void ActOnBlockArguments(Declarator
&ParamInfo
, Scope
*CurScope
);
1992 /// ActOnBlockError - If there is an error parsing a block, this callback
1993 /// is invoked to pop the information about the block from the action impl.
1994 void ActOnBlockError(SourceLocation CaretLoc
, Scope
*CurScope
);
1996 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1997 /// literal was successfully completed. ^(int x){...}
1998 ExprResult
ActOnBlockStmtExpr(SourceLocation CaretLoc
,
1999 Stmt
*Body
, Scope
*CurScope
);
2001 //===---------------------------- C++ Features --------------------------===//
2003 // Act on C++ namespaces
2004 Decl
*ActOnStartNamespaceDef(Scope
*S
, SourceLocation InlineLoc
,
2005 SourceLocation IdentLoc
,
2006 IdentifierInfo
*Ident
,
2007 SourceLocation LBrace
,
2008 AttributeList
*AttrList
);
2009 void ActOnFinishNamespaceDef(Decl
*Dcl
, SourceLocation RBrace
);
2011 NamespaceDecl
*getStdNamespace() const;
2012 NamespaceDecl
*getOrCreateStdNamespace();
2014 CXXRecordDecl
*getStdBadAlloc() const;
2016 Decl
*ActOnUsingDirective(Scope
*CurScope
,
2017 SourceLocation UsingLoc
,
2018 SourceLocation NamespcLoc
,
2020 SourceLocation IdentLoc
,
2021 IdentifierInfo
*NamespcName
,
2022 AttributeList
*AttrList
);
2024 void PushUsingDirective(Scope
*S
, UsingDirectiveDecl
*UDir
);
2026 Decl
*ActOnNamespaceAliasDef(Scope
*CurScope
,
2027 SourceLocation NamespaceLoc
,
2028 SourceLocation AliasLoc
,
2029 IdentifierInfo
*Alias
,
2031 SourceLocation IdentLoc
,
2032 IdentifierInfo
*Ident
);
2034 void HideUsingShadowDecl(Scope
*S
, UsingShadowDecl
*Shadow
);
2035 bool CheckUsingShadowDecl(UsingDecl
*UD
, NamedDecl
*Target
,
2036 const LookupResult
&PreviousDecls
);
2037 UsingShadowDecl
*BuildUsingShadowDecl(Scope
*S
, UsingDecl
*UD
,
2040 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc
,
2042 const CXXScopeSpec
&SS
,
2043 SourceLocation NameLoc
,
2044 const LookupResult
&Previous
);
2045 bool CheckUsingDeclQualifier(SourceLocation UsingLoc
,
2046 const CXXScopeSpec
&SS
,
2047 SourceLocation NameLoc
);
2049 NamedDecl
*BuildUsingDeclaration(Scope
*S
, AccessSpecifier AS
,
2050 SourceLocation UsingLoc
,
2052 const DeclarationNameInfo
&NameInfo
,
2053 AttributeList
*AttrList
,
2054 bool IsInstantiation
,
2056 SourceLocation TypenameLoc
);
2058 Decl
*ActOnUsingDeclaration(Scope
*CurScope
,
2060 bool HasUsingKeyword
,
2061 SourceLocation UsingLoc
,
2063 UnqualifiedId
&Name
,
2064 AttributeList
*AttrList
,
2066 SourceLocation TypenameLoc
);
2068 /// AddCXXDirectInitializerToDecl - This action is called immediately after
2069 /// ActOnDeclarator, when a C++ direct initializer is present.
2070 /// e.g: "int x(1);"
2071 void AddCXXDirectInitializerToDecl(Decl
*Dcl
,
2072 SourceLocation LParenLoc
,
2074 SourceLocation RParenLoc
);
2076 /// InitializeVarWithConstructor - Creates an CXXConstructExpr
2077 /// and sets it as the initializer for the the passed in VarDecl.
2078 bool InitializeVarWithConstructor(VarDecl
*VD
,
2079 CXXConstructorDecl
*Constructor
,
2080 MultiExprArg Exprs
);
2082 /// BuildCXXConstructExpr - Creates a complete call to a constructor,
2083 /// including handling of its default argument expressions.
2085 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
2087 BuildCXXConstructExpr(SourceLocation ConstructLoc
, QualType DeclInitType
,
2088 CXXConstructorDecl
*Constructor
, MultiExprArg Exprs
,
2089 bool RequiresZeroInit
, unsigned ConstructKind
,
2090 SourceRange ParenRange
);
2092 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
2093 // the constructor can be elidable?
2095 BuildCXXConstructExpr(SourceLocation ConstructLoc
, QualType DeclInitType
,
2096 CXXConstructorDecl
*Constructor
, bool Elidable
,
2097 MultiExprArg Exprs
, bool RequiresZeroInit
,
2098 unsigned ConstructKind
,
2099 SourceRange ParenRange
);
2101 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
2102 /// the default expr if needed.
2103 ExprResult
BuildCXXDefaultArgExpr(SourceLocation CallLoc
,
2105 ParmVarDecl
*Param
);
2107 /// FinalizeVarWithDestructor - Prepare for calling destructor on the
2108 /// constructed variable.
2109 void FinalizeVarWithDestructor(VarDecl
*VD
, const RecordType
*DeclInitType
);
2111 /// \brief Declare the implicit default constructor for the given class.
2113 /// \param ClassDecl The class declaration into which the implicit
2114 /// default constructor will be added.
2116 /// \returns The implicitly-declared default constructor.
2117 CXXConstructorDecl
*DeclareImplicitDefaultConstructor(
2118 CXXRecordDecl
*ClassDecl
);
2120 /// DefineImplicitDefaultConstructor - Checks for feasibility of
2121 /// defining this constructor as the default constructor.
2122 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation
,
2123 CXXConstructorDecl
*Constructor
);
2125 /// \brief Declare the implicit destructor for the given class.
2127 /// \param ClassDecl The class declaration into which the implicit
2128 /// destructor will be added.
2130 /// \returns The implicitly-declared destructor.
2131 CXXDestructorDecl
*DeclareImplicitDestructor(CXXRecordDecl
*ClassDecl
);
2133 /// DefineImplicitDestructor - Checks for feasibility of
2134 /// defining this destructor as the default destructor.
2135 void DefineImplicitDestructor(SourceLocation CurrentLocation
,
2136 CXXDestructorDecl
*Destructor
);
2138 /// \brief Declare the implicit copy constructor for the given class.
2140 /// \param S The scope of the class, which may be NULL if this is a
2141 /// template instantiation.
2143 /// \param ClassDecl The class declaration into which the implicit
2144 /// copy constructor will be added.
2146 /// \returns The implicitly-declared copy constructor.
2147 CXXConstructorDecl
*DeclareImplicitCopyConstructor(CXXRecordDecl
*ClassDecl
);
2149 /// DefineImplicitCopyConstructor - Checks for feasibility of
2150 /// defining this constructor as the copy constructor.
2151 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation
,
2152 CXXConstructorDecl
*Constructor
,
2153 unsigned TypeQuals
);
2155 /// \brief Declare the implicit copy assignment operator for the given class.
2157 /// \param S The scope of the class, which may be NULL if this is a
2158 /// template instantiation.
2160 /// \param ClassDecl The class declaration into which the implicit
2161 /// copy-assignment operator will be added.
2163 /// \returns The implicitly-declared copy assignment operator.
2164 CXXMethodDecl
*DeclareImplicitCopyAssignment(CXXRecordDecl
*ClassDecl
);
2166 /// \brief Defined an implicitly-declared copy assignment operator.
2167 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation
,
2168 CXXMethodDecl
*MethodDecl
);
2170 /// \brief Force the declaration of any implicitly-declared members of this
2172 void ForceDeclarationOfImplicitMembers(CXXRecordDecl
*Class
);
2174 /// MaybeBindToTemporary - If the passed in expression has a record type with
2175 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
2176 /// it simply returns the passed in expression.
2177 ExprResult
MaybeBindToTemporary(Expr
*E
);
2179 bool CompleteConstructorCall(CXXConstructorDecl
*Constructor
,
2180 MultiExprArg ArgsPtr
,
2182 ASTOwningVector
<Expr
*> &ConvertedArgs
);
2184 ParsedType
getDestructorName(SourceLocation TildeLoc
,
2185 IdentifierInfo
&II
, SourceLocation NameLoc
,
2186 Scope
*S
, CXXScopeSpec
&SS
,
2187 ParsedType ObjectType
,
2188 bool EnteringContext
);
2190 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
2191 ExprResult
ActOnCXXNamedCast(SourceLocation OpLoc
,
2192 tok::TokenKind Kind
,
2193 SourceLocation LAngleBracketLoc
,
2195 SourceLocation RAngleBracketLoc
,
2196 SourceLocation LParenLoc
,
2198 SourceLocation RParenLoc
);
2200 ExprResult
BuildCXXNamedCast(SourceLocation OpLoc
,
2201 tok::TokenKind Kind
,
2204 SourceRange AngleBrackets
,
2205 SourceRange Parens
);
2207 ExprResult
BuildCXXTypeId(QualType TypeInfoType
,
2208 SourceLocation TypeidLoc
,
2209 TypeSourceInfo
*Operand
,
2210 SourceLocation RParenLoc
);
2211 ExprResult
BuildCXXTypeId(QualType TypeInfoType
,
2212 SourceLocation TypeidLoc
,
2214 SourceLocation RParenLoc
);
2216 /// ActOnCXXTypeid - Parse typeid( something ).
2217 ExprResult
ActOnCXXTypeid(SourceLocation OpLoc
,
2218 SourceLocation LParenLoc
, bool isType
,
2220 SourceLocation RParenLoc
);
2222 ExprResult
BuildCXXUuidof(QualType TypeInfoType
,
2223 SourceLocation TypeidLoc
,
2224 TypeSourceInfo
*Operand
,
2225 SourceLocation RParenLoc
);
2226 ExprResult
BuildCXXUuidof(QualType TypeInfoType
,
2227 SourceLocation TypeidLoc
,
2229 SourceLocation RParenLoc
);
2231 /// ActOnCXXUuidof - Parse __uuidof( something ).
2232 ExprResult
ActOnCXXUuidof(SourceLocation OpLoc
,
2233 SourceLocation LParenLoc
, bool isType
,
2235 SourceLocation RParenLoc
);
2238 //// ActOnCXXThis - Parse 'this' pointer.
2239 ExprResult
ActOnCXXThis(SourceLocation ThisLoc
);
2241 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
2242 ExprResult
ActOnCXXBoolLiteral(SourceLocation OpLoc
, tok::TokenKind Kind
);
2244 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
2245 ExprResult
ActOnCXXNullPtrLiteral(SourceLocation Loc
);
2247 //// ActOnCXXThrow - Parse throw expressions.
2248 ExprResult
ActOnCXXThrow(SourceLocation OpLoc
, Expr
*expr
);
2249 bool CheckCXXThrowOperand(SourceLocation ThrowLoc
, Expr
*&E
);
2251 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
2252 /// Can be interpreted either as function-style casting ("int(x)")
2253 /// or class type construction ("ClassType(x,y,z)")
2254 /// or creation of a value-initialized type ("int()").
2255 ExprResult
ActOnCXXTypeConstructExpr(ParsedType TypeRep
,
2256 SourceLocation LParenLoc
,
2258 SourceLocation RParenLoc
);
2260 ExprResult
BuildCXXTypeConstructExpr(TypeSourceInfo
*Type
,
2261 SourceLocation LParenLoc
,
2263 SourceLocation RParenLoc
);
2265 /// ActOnCXXNew - Parsed a C++ 'new' expression.
2266 ExprResult
ActOnCXXNew(SourceLocation StartLoc
, bool UseGlobal
,
2267 SourceLocation PlacementLParen
,
2268 MultiExprArg PlacementArgs
,
2269 SourceLocation PlacementRParen
,
2270 SourceRange TypeIdParens
, Declarator
&D
,
2271 SourceLocation ConstructorLParen
,
2272 MultiExprArg ConstructorArgs
,
2273 SourceLocation ConstructorRParen
);
2274 ExprResult
BuildCXXNew(SourceLocation StartLoc
, bool UseGlobal
,
2275 SourceLocation PlacementLParen
,
2276 MultiExprArg PlacementArgs
,
2277 SourceLocation PlacementRParen
,
2278 SourceRange TypeIdParens
,
2280 TypeSourceInfo
*AllocTypeInfo
,
2282 SourceLocation ConstructorLParen
,
2283 MultiExprArg ConstructorArgs
,
2284 SourceLocation ConstructorRParen
);
2286 bool CheckAllocatedType(QualType AllocType
, SourceLocation Loc
,
2288 bool FindAllocationFunctions(SourceLocation StartLoc
, SourceRange Range
,
2289 bool UseGlobal
, QualType AllocType
, bool IsArray
,
2290 Expr
**PlaceArgs
, unsigned NumPlaceArgs
,
2291 FunctionDecl
*&OperatorNew
,
2292 FunctionDecl
*&OperatorDelete
);
2293 bool FindAllocationOverload(SourceLocation StartLoc
, SourceRange Range
,
2294 DeclarationName Name
, Expr
** Args
,
2295 unsigned NumArgs
, DeclContext
*Ctx
,
2296 bool AllowMissing
, FunctionDecl
*&Operator
);
2297 void DeclareGlobalNewDelete();
2298 void DeclareGlobalAllocationFunction(DeclarationName Name
, QualType Return
,
2300 bool addMallocAttr
= false);
2302 bool FindDeallocationFunction(SourceLocation StartLoc
, CXXRecordDecl
*RD
,
2303 DeclarationName Name
, FunctionDecl
* &Operator
);
2305 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
2306 ExprResult
ActOnCXXDelete(SourceLocation StartLoc
,
2307 bool UseGlobal
, bool ArrayForm
,
2310 DeclResult
ActOnCXXConditionDeclaration(Scope
*S
, Declarator
&D
);
2311 ExprResult
CheckConditionVariable(VarDecl
*ConditionVar
,
2312 SourceLocation StmtLoc
,
2313 bool ConvertToBoolean
);
2315 ExprResult
ActOnNoexceptExpr(SourceLocation KeyLoc
, SourceLocation LParen
,
2316 Expr
*Operand
, SourceLocation RParen
);
2317 ExprResult
BuildCXXNoexceptExpr(SourceLocation KeyLoc
, Expr
*Operand
,
2318 SourceLocation RParen
);
2320 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
2321 /// pseudo-functions.
2322 ExprResult
ActOnUnaryTypeTrait(UnaryTypeTrait OTT
,
2323 SourceLocation KWLoc
,
2325 SourceLocation RParen
);
2327 ExprResult
BuildUnaryTypeTrait(UnaryTypeTrait OTT
,
2328 SourceLocation KWLoc
,
2330 SourceLocation RParen
);
2332 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support
2333 /// pseudo-functions.
2334 ExprResult
ActOnBinaryTypeTrait(BinaryTypeTrait OTT
,
2335 SourceLocation KWLoc
,
2338 SourceLocation RParen
);
2340 ExprResult
BuildBinaryTypeTrait(BinaryTypeTrait BTT
,
2341 SourceLocation KWLoc
,
2342 TypeSourceInfo
*LhsT
,
2343 TypeSourceInfo
*RhsT
,
2344 SourceLocation RParen
);
2346 ExprResult
ActOnStartCXXMemberReference(Scope
*S
,
2348 SourceLocation OpLoc
,
2349 tok::TokenKind OpKind
,
2350 ParsedType
&ObjectType
,
2351 bool &MayBePseudoDestructor
);
2353 ExprResult
DiagnoseDtorReference(SourceLocation NameLoc
, Expr
*MemExpr
);
2355 ExprResult
BuildPseudoDestructorExpr(Expr
*Base
,
2356 SourceLocation OpLoc
,
2357 tok::TokenKind OpKind
,
2358 const CXXScopeSpec
&SS
,
2359 TypeSourceInfo
*ScopeType
,
2360 SourceLocation CCLoc
,
2361 SourceLocation TildeLoc
,
2362 PseudoDestructorTypeStorage DestroyedType
,
2363 bool HasTrailingLParen
);
2365 ExprResult
ActOnPseudoDestructorExpr(Scope
*S
, Expr
*Base
,
2366 SourceLocation OpLoc
,
2367 tok::TokenKind OpKind
,
2369 UnqualifiedId
&FirstTypeName
,
2370 SourceLocation CCLoc
,
2371 SourceLocation TildeLoc
,
2372 UnqualifiedId
&SecondTypeName
,
2373 bool HasTrailingLParen
);
2375 /// MaybeCreateExprWithCleanups - If the current full-expression
2376 /// requires any cleanups, surround it with a ExprWithCleanups node.
2377 /// Otherwise, just returns the passed-in expression.
2378 Expr
*MaybeCreateExprWithCleanups(Expr
*SubExpr
);
2379 Stmt
*MaybeCreateStmtWithCleanups(Stmt
*SubStmt
);
2380 ExprResult
MaybeCreateExprWithCleanups(ExprResult SubExpr
);
2382 ExprResult
ActOnFinishFullExpr(Expr
*Expr
);
2383 StmtResult
ActOnFinishFullStmt(Stmt
*Stmt
);
2385 // Marks SS invalid if it represents an incomplete type.
2386 bool RequireCompleteDeclContext(CXXScopeSpec
&SS
, DeclContext
*DC
);
2388 DeclContext
*computeDeclContext(QualType T
);
2389 DeclContext
*computeDeclContext(const CXXScopeSpec
&SS
,
2390 bool EnteringContext
= false);
2391 bool isDependentScopeSpecifier(const CXXScopeSpec
&SS
);
2392 CXXRecordDecl
*getCurrentInstantiationOf(NestedNameSpecifier
*NNS
);
2393 bool isUnknownSpecialization(const CXXScopeSpec
&SS
);
2395 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
2396 /// global scope ('::').
2397 NestedNameSpecifier
*
2398 ActOnCXXGlobalScopeSpecifier(Scope
*S
, SourceLocation CCLoc
);
2400 bool isAcceptableNestedNameSpecifier(NamedDecl
*SD
);
2401 NamedDecl
*FindFirstQualifierInScope(Scope
*S
, NestedNameSpecifier
*NNS
);
2403 bool isNonTypeNestedNameSpecifier(Scope
*S
, CXXScopeSpec
&SS
,
2404 SourceLocation IdLoc
,
2406 ParsedType ObjectType
);
2408 NestedNameSpecifier
*BuildCXXNestedNameSpecifier(Scope
*S
,
2410 SourceLocation IdLoc
,
2411 SourceLocation CCLoc
,
2413 QualType ObjectType
,
2414 NamedDecl
*ScopeLookupResult
,
2415 bool EnteringContext
,
2416 bool ErrorRecoveryLookup
);
2418 NestedNameSpecifier
*ActOnCXXNestedNameSpecifier(Scope
*S
,
2420 SourceLocation IdLoc
,
2421 SourceLocation CCLoc
,
2423 ParsedType ObjectType
,
2424 bool EnteringContext
);
2426 bool IsInvalidUnlessNestedName(Scope
*S
, CXXScopeSpec
&SS
,
2428 ParsedType ObjectType
,
2429 bool EnteringContext
);
2431 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
2432 /// nested-name-specifier that involves a template-id, e.g.,
2433 /// "foo::bar<int, float>::", and now we need to build a scope
2434 /// specifier. \p SS is empty or the previously parsed nested-name
2435 /// part ("foo::"), \p Type is the already-parsed class template
2436 /// specialization (or other template-id that names a type), \p
2437 /// TypeRange is the source range where the type is located, and \p
2438 /// CCLoc is the location of the trailing '::'.
2439 CXXScopeTy
*ActOnCXXNestedNameSpecifier(Scope
*S
,
2440 const CXXScopeSpec
&SS
,
2442 SourceRange TypeRange
,
2443 SourceLocation CCLoc
);
2445 bool ShouldEnterDeclaratorScope(Scope
*S
, const CXXScopeSpec
&SS
);
2447 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
2448 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
2449 /// After this method is called, according to [C++ 3.4.3p3], names should be
2450 /// looked up in the declarator-id's scope, until the declarator is parsed and
2451 /// ActOnCXXExitDeclaratorScope is called.
2452 /// The 'SS' should be a non-empty valid CXXScopeSpec.
2453 bool ActOnCXXEnterDeclaratorScope(Scope
*S
, CXXScopeSpec
&SS
);
2455 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
2456 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
2457 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
2458 /// Used to indicate that names should revert to being looked up in the
2460 void ActOnCXXExitDeclaratorScope(Scope
*S
, const CXXScopeSpec
&SS
);
2462 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
2463 /// initializer for the declaration 'Dcl'.
2464 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
2465 /// static data member of class X, names should be looked up in the scope of
2467 void ActOnCXXEnterDeclInitializer(Scope
*S
, Decl
*Dcl
);
2469 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
2470 /// initializer for the declaration 'Dcl'.
2471 void ActOnCXXExitDeclInitializer(Scope
*S
, Decl
*Dcl
);
2473 // ParseObjCStringLiteral - Parse Objective-C string literals.
2474 ExprResult
ParseObjCStringLiteral(SourceLocation
*AtLocs
,
2476 unsigned NumStrings
);
2478 Expr
*BuildObjCEncodeExpression(SourceLocation AtLoc
,
2479 TypeSourceInfo
*EncodedTypeInfo
,
2480 SourceLocation RParenLoc
);
2481 CXXMemberCallExpr
*BuildCXXMemberCallExpr(Expr
*Exp
,
2482 NamedDecl
*FoundDecl
,
2483 CXXMethodDecl
*Method
);
2485 ExprResult
ParseObjCEncodeExpression(SourceLocation AtLoc
,
2486 SourceLocation EncodeLoc
,
2487 SourceLocation LParenLoc
,
2489 SourceLocation RParenLoc
);
2491 // ParseObjCSelectorExpression - Build selector expression for @selector
2492 ExprResult
ParseObjCSelectorExpression(Selector Sel
,
2493 SourceLocation AtLoc
,
2494 SourceLocation SelLoc
,
2495 SourceLocation LParenLoc
,
2496 SourceLocation RParenLoc
);
2498 // ParseObjCProtocolExpression - Build protocol expression for @protocol
2499 ExprResult
ParseObjCProtocolExpression(IdentifierInfo
* ProtocolName
,
2500 SourceLocation AtLoc
,
2501 SourceLocation ProtoLoc
,
2502 SourceLocation LParenLoc
,
2503 SourceLocation RParenLoc
);
2505 //===--------------------------------------------------------------------===//
2508 Decl
*ActOnStartLinkageSpecification(Scope
*S
,
2509 SourceLocation ExternLoc
,
2510 SourceLocation LangLoc
,
2511 llvm::StringRef Lang
,
2512 SourceLocation LBraceLoc
);
2513 Decl
*ActOnFinishLinkageSpecification(Scope
*S
,
2515 SourceLocation RBraceLoc
);
2518 //===--------------------------------------------------------------------===//
2521 bool isCurrentClassName(const IdentifierInfo
&II
, Scope
*S
,
2522 const CXXScopeSpec
*SS
= 0);
2524 Decl
*ActOnAccessSpecifier(AccessSpecifier Access
,
2525 SourceLocation ASLoc
,
2526 SourceLocation ColonLoc
);
2528 Decl
*ActOnCXXMemberDeclarator(Scope
*S
, AccessSpecifier AS
,
2530 MultiTemplateParamsArg TemplateParameterLists
,
2531 Expr
*BitfieldWidth
,
2532 Expr
*Init
, bool IsDefinition
,
2533 bool Deleted
= false);
2535 MemInitResult
ActOnMemInitializer(Decl
*ConstructorD
,
2538 IdentifierInfo
*MemberOrBase
,
2539 ParsedType TemplateTypeTy
,
2540 SourceLocation IdLoc
,
2541 SourceLocation LParenLoc
,
2542 Expr
**Args
, unsigned NumArgs
,
2543 SourceLocation RParenLoc
);
2545 MemInitResult
BuildMemberInitializer(ValueDecl
*Member
, Expr
**Args
,
2546 unsigned NumArgs
, SourceLocation IdLoc
,
2547 SourceLocation LParenLoc
,
2548 SourceLocation RParenLoc
);
2550 MemInitResult
BuildBaseInitializer(QualType BaseType
,
2551 TypeSourceInfo
*BaseTInfo
,
2552 Expr
**Args
, unsigned NumArgs
,
2553 SourceLocation LParenLoc
,
2554 SourceLocation RParenLoc
,
2555 CXXRecordDecl
*ClassDecl
);
2557 bool SetBaseOrMemberInitializers(CXXConstructorDecl
*Constructor
,
2558 CXXBaseOrMemberInitializer
**Initializers
,
2559 unsigned NumInitializers
, bool AnyErrors
);
2561 void SetIvarInitializers(ObjCImplementationDecl
*ObjCImplementation
);
2564 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
2565 /// mark all the non-trivial destructors of its members and bases as
2567 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc
,
2568 CXXRecordDecl
*Record
);
2570 /// \brief The list of classes whose vtables have been used within
2571 /// this translation unit, and the source locations at which the
2572 /// first use occurred.
2573 typedef std::pair
<CXXRecordDecl
*, SourceLocation
> VTableUse
;
2575 /// \brief The list of vtables that are required but have not yet been
2577 llvm::SmallVector
<VTableUse
, 16> VTableUses
;
2579 /// \brief The set of classes whose vtables have been used within
2580 /// this translation unit, and a bit that will be true if the vtable is
2581 /// required to be emitted (otherwise, it should be emitted only if needed
2582 /// by code generation).
2583 llvm::DenseMap
<CXXRecordDecl
*, bool> VTablesUsed
;
2585 /// \brief A list of all of the dynamic classes in this translation
2587 llvm::SmallVector
<CXXRecordDecl
*, 16> DynamicClasses
;
2589 /// \brief Note that the vtable for the given class was used at the
2591 void MarkVTableUsed(SourceLocation Loc
, CXXRecordDecl
*Class
,
2592 bool DefinitionRequired
= false);
2594 /// MarkVirtualMembersReferenced - Will mark all members of the given
2595 /// CXXRecordDecl referenced.
2596 void MarkVirtualMembersReferenced(SourceLocation Loc
,
2597 const CXXRecordDecl
*RD
);
2599 /// \brief Define all of the vtables that have been used in this
2600 /// translation unit and reference any virtual members used by those
2603 /// \returns true if any work was done, false otherwise.
2604 bool DefineUsedVTables();
2606 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl
*ClassDecl
);
2608 void ActOnMemInitializers(Decl
*ConstructorDecl
,
2609 SourceLocation ColonLoc
,
2610 MemInitTy
**MemInits
, unsigned NumMemInits
,
2613 void CheckCompletedCXXClass(CXXRecordDecl
*Record
);
2614 void ActOnFinishCXXMemberSpecification(Scope
* S
, SourceLocation RLoc
,
2616 SourceLocation LBrac
,
2617 SourceLocation RBrac
,
2618 AttributeList
*AttrList
);
2620 void ActOnReenterTemplateScope(Scope
*S
, Decl
*Template
);
2621 void ActOnStartDelayedMemberDeclarations(Scope
*S
, Decl
*Record
);
2622 void ActOnStartDelayedCXXMethodDeclaration(Scope
*S
, Decl
*Method
);
2623 void ActOnDelayedCXXMethodParameter(Scope
*S
, Decl
*Param
);
2624 void ActOnFinishDelayedCXXMethodDeclaration(Scope
*S
, Decl
*Method
);
2625 void ActOnFinishDelayedMemberDeclarations(Scope
*S
, Decl
*Record
);
2627 Decl
*ActOnStaticAssertDeclaration(SourceLocation AssertLoc
,
2629 Expr
*AssertMessageExpr
);
2631 FriendDecl
*CheckFriendTypeDecl(SourceLocation FriendLoc
,
2632 TypeSourceInfo
*TSInfo
);
2633 Decl
*ActOnFriendTypeDecl(Scope
*S
, const DeclSpec
&DS
,
2634 MultiTemplateParamsArg TemplateParams
);
2635 Decl
*ActOnFriendFunctionDecl(Scope
*S
, Declarator
&D
, bool IsDefinition
,
2636 MultiTemplateParamsArg TemplateParams
);
2638 QualType
CheckConstructorDeclarator(Declarator
&D
, QualType R
,
2640 void CheckConstructor(CXXConstructorDecl
*Constructor
);
2641 QualType
CheckDestructorDeclarator(Declarator
&D
, QualType R
,
2643 bool CheckDestructor(CXXDestructorDecl
*Destructor
);
2644 void CheckConversionDeclarator(Declarator
&D
, QualType
&R
,
2646 Decl
*ActOnConversionDeclarator(CXXConversionDecl
*Conversion
);
2648 //===--------------------------------------------------------------------===//
2649 // C++ Derived Classes
2652 /// ActOnBaseSpecifier - Parsed a base specifier
2653 CXXBaseSpecifier
*CheckBaseSpecifier(CXXRecordDecl
*Class
,
2654 SourceRange SpecifierRange
,
2655 bool Virtual
, AccessSpecifier Access
,
2656 TypeSourceInfo
*TInfo
);
2658 BaseResult
ActOnBaseSpecifier(Decl
*classdecl
,
2659 SourceRange SpecifierRange
,
2660 bool Virtual
, AccessSpecifier Access
,
2661 ParsedType basetype
, SourceLocation
2664 bool AttachBaseSpecifiers(CXXRecordDecl
*Class
, CXXBaseSpecifier
**Bases
,
2666 void ActOnBaseSpecifiers(Decl
*ClassDecl
, BaseTy
**Bases
, unsigned NumBases
);
2668 bool IsDerivedFrom(QualType Derived
, QualType Base
);
2669 bool IsDerivedFrom(QualType Derived
, QualType Base
, CXXBasePaths
&Paths
);
2671 // FIXME: I don't like this name.
2672 void BuildBasePathArray(const CXXBasePaths
&Paths
, CXXCastPath
&BasePath
);
2674 bool BasePathInvolvesVirtualBase(const CXXCastPath
&BasePath
);
2676 bool CheckDerivedToBaseConversion(QualType Derived
, QualType Base
,
2677 SourceLocation Loc
, SourceRange Range
,
2678 CXXCastPath
*BasePath
= 0,
2679 bool IgnoreAccess
= false);
2680 bool CheckDerivedToBaseConversion(QualType Derived
, QualType Base
,
2681 unsigned InaccessibleBaseID
,
2682 unsigned AmbigiousBaseConvID
,
2683 SourceLocation Loc
, SourceRange Range
,
2684 DeclarationName Name
,
2685 CXXCastPath
*BasePath
);
2687 std::string
getAmbiguousPathsDisplayString(CXXBasePaths
&Paths
);
2689 /// CheckOverridingFunctionReturnType - Checks whether the return types are
2690 /// covariant, according to C++ [class.virtual]p5.
2691 bool CheckOverridingFunctionReturnType(const CXXMethodDecl
*New
,
2692 const CXXMethodDecl
*Old
);
2694 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
2695 /// spec is a subset of base spec.
2696 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl
*New
,
2697 const CXXMethodDecl
*Old
);
2699 /// CheckOverridingFunctionAttributes - Checks whether attributes are
2700 /// incompatible or prevent overriding.
2701 bool CheckOverridingFunctionAttributes(const CXXMethodDecl
*New
,
2702 const CXXMethodDecl
*Old
);
2704 bool CheckPureMethod(CXXMethodDecl
*Method
, SourceRange InitRange
);
2706 //===--------------------------------------------------------------------===//
2707 // C++ Access Control
2717 bool SetMemberAccessSpecifier(NamedDecl
*MemberDecl
,
2718 NamedDecl
*PrevMemberDecl
,
2719 AccessSpecifier LexicalAS
);
2721 AccessResult
CheckUnresolvedMemberAccess(UnresolvedMemberExpr
*E
,
2722 DeclAccessPair FoundDecl
);
2723 AccessResult
CheckUnresolvedLookupAccess(UnresolvedLookupExpr
*E
,
2724 DeclAccessPair FoundDecl
);
2725 AccessResult
CheckAllocationAccess(SourceLocation OperatorLoc
,
2726 SourceRange PlacementRange
,
2727 CXXRecordDecl
*NamingClass
,
2728 DeclAccessPair FoundDecl
);
2729 AccessResult
CheckConstructorAccess(SourceLocation Loc
,
2730 CXXConstructorDecl
*D
,
2731 const InitializedEntity
&Entity
,
2732 AccessSpecifier Access
,
2733 bool IsCopyBindingRefToTemp
= false);
2734 AccessResult
CheckDestructorAccess(SourceLocation Loc
,
2735 CXXDestructorDecl
*Dtor
,
2736 const PartialDiagnostic
&PDiag
);
2737 AccessResult
CheckDirectMemberAccess(SourceLocation Loc
,
2739 const PartialDiagnostic
&PDiag
);
2740 AccessResult
CheckMemberOperatorAccess(SourceLocation Loc
,
2743 DeclAccessPair FoundDecl
);
2744 AccessResult
CheckAddressOfMemberAccess(Expr
*OvlExpr
,
2745 DeclAccessPair FoundDecl
);
2746 AccessResult
CheckBaseClassAccess(SourceLocation AccessLoc
,
2747 QualType Base
, QualType Derived
,
2748 const CXXBasePath
&Path
,
2750 bool ForceCheck
= false,
2751 bool ForceUnprivileged
= false);
2752 void CheckLookupAccess(const LookupResult
&R
);
2754 void HandleDependentAccessCheck(const DependentDiagnostic
&DD
,
2755 const MultiLevelTemplateArgumentList
&TemplateArgs
);
2756 void PerformDependentDiagnostics(const DeclContext
*Pattern
,
2757 const MultiLevelTemplateArgumentList
&TemplateArgs
);
2759 void HandleDelayedAccessCheck(sema::DelayedDiagnostic
&DD
, Decl
*Ctx
);
2761 /// A flag to suppress access checking.
2762 bool SuppressAccessChecking
;
2764 void ActOnStartSuppressingAccessChecks();
2765 void ActOnStopSuppressingAccessChecks();
2767 enum AbstractDiagSelID
{
2771 AbstractVariableType
,
2776 bool RequireNonAbstractType(SourceLocation Loc
, QualType T
,
2777 const PartialDiagnostic
&PD
);
2778 void DiagnoseAbstractType(const CXXRecordDecl
*RD
);
2780 bool RequireNonAbstractType(SourceLocation Loc
, QualType T
, unsigned DiagID
,
2781 AbstractDiagSelID SelID
= AbstractNone
);
2783 //===--------------------------------------------------------------------===//
2784 // C++ Overloaded Operators [C++ 13.5]
2787 bool CheckOverloadedOperatorDeclaration(FunctionDecl
*FnDecl
);
2789 bool CheckLiteralOperatorDeclaration(FunctionDecl
*FnDecl
);
2791 //===--------------------------------------------------------------------===//
2792 // C++ Templates [C++ 14]
2794 void LookupTemplateName(LookupResult
&R
, Scope
*S
, CXXScopeSpec
&SS
,
2795 QualType ObjectType
, bool EnteringContext
,
2796 bool &MemberOfUnknownSpecialization
);
2798 TemplateNameKind
isTemplateName(Scope
*S
,
2800 bool hasTemplateKeyword
,
2801 UnqualifiedId
&Name
,
2802 ParsedType ObjectType
,
2803 bool EnteringContext
,
2804 TemplateTy
&Template
,
2805 bool &MemberOfUnknownSpecialization
);
2807 bool DiagnoseUnknownTemplateName(const IdentifierInfo
&II
,
2808 SourceLocation IILoc
,
2810 const CXXScopeSpec
*SS
,
2811 TemplateTy
&SuggestedTemplate
,
2812 TemplateNameKind
&SuggestedKind
);
2814 bool DiagnoseTemplateParameterShadow(SourceLocation Loc
, Decl
*PrevDecl
);
2815 TemplateDecl
*AdjustDeclIfTemplate(Decl
*&Decl
);
2817 Decl
*ActOnTypeParameter(Scope
*S
, bool Typename
, bool Ellipsis
,
2818 SourceLocation EllipsisLoc
,
2819 SourceLocation KeyLoc
,
2820 IdentifierInfo
*ParamName
,
2821 SourceLocation ParamNameLoc
,
2822 unsigned Depth
, unsigned Position
,
2823 SourceLocation EqualLoc
,
2824 ParsedType DefaultArg
);
2826 QualType
CheckNonTypeTemplateParameterType(QualType T
, SourceLocation Loc
);
2827 Decl
*ActOnNonTypeTemplateParameter(Scope
*S
, Declarator
&D
,
2830 SourceLocation EqualLoc
,
2832 Decl
*ActOnTemplateTemplateParameter(Scope
*S
,
2833 SourceLocation TmpLoc
,
2834 TemplateParamsTy
*Params
,
2835 IdentifierInfo
*ParamName
,
2836 SourceLocation ParamNameLoc
,
2839 SourceLocation EqualLoc
,
2840 const ParsedTemplateArgument
&DefaultArg
);
2843 ActOnTemplateParameterList(unsigned Depth
,
2844 SourceLocation ExportLoc
,
2845 SourceLocation TemplateLoc
,
2846 SourceLocation LAngleLoc
,
2847 Decl
**Params
, unsigned NumParams
,
2848 SourceLocation RAngleLoc
);
2850 /// \brief The context in which we are checking a template parameter
2852 enum TemplateParamListContext
{
2854 TPC_FunctionTemplate
,
2855 TPC_ClassTemplateMember
,
2856 TPC_FriendFunctionTemplate
2859 bool CheckTemplateParameterList(TemplateParameterList
*NewParams
,
2860 TemplateParameterList
*OldParams
,
2861 TemplateParamListContext TPC
);
2862 TemplateParameterList
*
2863 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc
,
2864 const CXXScopeSpec
&SS
,
2865 TemplateParameterList
**ParamLists
,
2866 unsigned NumParamLists
,
2868 bool &IsExplicitSpecialization
,
2871 DeclResult
CheckClassTemplate(Scope
*S
, unsigned TagSpec
, TagUseKind TUK
,
2872 SourceLocation KWLoc
, CXXScopeSpec
&SS
,
2873 IdentifierInfo
*Name
, SourceLocation NameLoc
,
2874 AttributeList
*Attr
,
2875 TemplateParameterList
*TemplateParams
,
2876 AccessSpecifier AS
);
2878 void translateTemplateArguments(const ASTTemplateArgsPtr
&In
,
2879 TemplateArgumentListInfo
&Out
);
2881 QualType
CheckTemplateIdType(TemplateName Template
,
2882 SourceLocation TemplateLoc
,
2883 const TemplateArgumentListInfo
&TemplateArgs
);
2886 ActOnTemplateIdType(TemplateTy Template
, SourceLocation TemplateLoc
,
2887 SourceLocation LAngleLoc
,
2888 ASTTemplateArgsPtr TemplateArgs
,
2889 SourceLocation RAngleLoc
);
2891 TypeResult
ActOnTagTemplateIdType(CXXScopeSpec
&SS
,
2894 TypeSpecifierType TagSpec
,
2895 SourceLocation TagLoc
);
2897 ExprResult
BuildTemplateIdExpr(const CXXScopeSpec
&SS
,
2900 const TemplateArgumentListInfo
&TemplateArgs
);
2901 ExprResult
BuildQualifiedTemplateIdExpr(CXXScopeSpec
&SS
,
2902 const DeclarationNameInfo
&NameInfo
,
2903 const TemplateArgumentListInfo
&TemplateArgs
);
2905 TemplateNameKind
ActOnDependentTemplateName(Scope
*S
,
2906 SourceLocation TemplateKWLoc
,
2908 UnqualifiedId
&Name
,
2909 ParsedType ObjectType
,
2910 bool EnteringContext
,
2911 TemplateTy
&Template
);
2913 bool CheckClassTemplatePartialSpecializationArgs(
2914 TemplateParameterList
*TemplateParams
,
2915 llvm::SmallVectorImpl
<TemplateArgument
> &TemplateArgs
);
2918 ActOnClassTemplateSpecialization(Scope
*S
, unsigned TagSpec
, TagUseKind TUK
,
2919 SourceLocation KWLoc
,
2921 TemplateTy Template
,
2922 SourceLocation TemplateNameLoc
,
2923 SourceLocation LAngleLoc
,
2924 ASTTemplateArgsPtr TemplateArgs
,
2925 SourceLocation RAngleLoc
,
2926 AttributeList
*Attr
,
2927 MultiTemplateParamsArg TemplateParameterLists
);
2929 Decl
*ActOnTemplateDeclarator(Scope
*S
,
2930 MultiTemplateParamsArg TemplateParameterLists
,
2933 Decl
*ActOnStartOfFunctionTemplateDef(Scope
*FnBodyScope
,
2934 MultiTemplateParamsArg TemplateParameterLists
,
2938 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc
,
2939 TemplateSpecializationKind NewTSK
,
2940 NamedDecl
*PrevDecl
,
2941 TemplateSpecializationKind PrevTSK
,
2942 SourceLocation PrevPtOfInstantiation
,
2945 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl
*FD
,
2946 const TemplateArgumentListInfo
&ExplicitTemplateArgs
,
2947 LookupResult
&Previous
);
2949 bool CheckFunctionTemplateSpecialization(FunctionDecl
*FD
,
2950 const TemplateArgumentListInfo
*ExplicitTemplateArgs
,
2951 LookupResult
&Previous
);
2952 bool CheckMemberSpecialization(NamedDecl
*Member
, LookupResult
&Previous
);
2955 ActOnExplicitInstantiation(Scope
*S
,
2956 SourceLocation ExternLoc
,
2957 SourceLocation TemplateLoc
,
2959 SourceLocation KWLoc
,
2960 const CXXScopeSpec
&SS
,
2961 TemplateTy Template
,
2962 SourceLocation TemplateNameLoc
,
2963 SourceLocation LAngleLoc
,
2964 ASTTemplateArgsPtr TemplateArgs
,
2965 SourceLocation RAngleLoc
,
2966 AttributeList
*Attr
);
2969 ActOnExplicitInstantiation(Scope
*S
,
2970 SourceLocation ExternLoc
,
2971 SourceLocation TemplateLoc
,
2973 SourceLocation KWLoc
,
2975 IdentifierInfo
*Name
,
2976 SourceLocation NameLoc
,
2977 AttributeList
*Attr
);
2979 DeclResult
ActOnExplicitInstantiation(Scope
*S
,
2980 SourceLocation ExternLoc
,
2981 SourceLocation TemplateLoc
,
2985 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl
*Template
,
2986 SourceLocation TemplateLoc
,
2987 SourceLocation RAngleLoc
,
2989 llvm::SmallVectorImpl
<TemplateArgument
> &Converted
);
2991 /// \brief Specifies the context in which a particular template
2992 /// argument is being checked.
2993 enum CheckTemplateArgumentKind
{
2994 /// \brief The template argument was specified in the code or was
2995 /// instantiated with some deduced template arguments.
2998 /// \brief The template argument was deduced via template argument
3002 /// \brief The template argument was deduced from an array bound
3003 /// via template argument deduction.
3004 CTAK_DeducedFromArrayBound
3007 bool CheckTemplateArgument(NamedDecl
*Param
,
3008 const TemplateArgumentLoc
&Arg
,
3009 TemplateDecl
*Template
,
3010 SourceLocation TemplateLoc
,
3011 SourceLocation RAngleLoc
,
3012 llvm::SmallVectorImpl
<TemplateArgument
> &Converted
,
3013 CheckTemplateArgumentKind CTAK
= CTAK_Specified
);
3015 bool CheckTemplateArgumentList(TemplateDecl
*Template
,
3016 SourceLocation TemplateLoc
,
3017 const TemplateArgumentListInfo
&TemplateArgs
,
3018 bool PartialTemplateArgs
,
3019 llvm::SmallVectorImpl
<TemplateArgument
> &Converted
);
3021 bool CheckTemplateTypeArgument(TemplateTypeParmDecl
*Param
,
3022 const TemplateArgumentLoc
&Arg
,
3023 llvm::SmallVectorImpl
<TemplateArgument
> &Converted
);
3025 bool CheckTemplateArgument(TemplateTypeParmDecl
*Param
,
3026 TypeSourceInfo
*Arg
);
3027 bool CheckTemplateArgumentPointerToMember(Expr
*Arg
,
3028 TemplateArgument
&Converted
);
3029 bool CheckTemplateArgument(NonTypeTemplateParmDecl
*Param
,
3030 QualType InstantiatedParamType
, Expr
*&Arg
,
3031 TemplateArgument
&Converted
,
3032 CheckTemplateArgumentKind CTAK
= CTAK_Specified
);
3033 bool CheckTemplateArgument(TemplateTemplateParmDecl
*Param
,
3034 const TemplateArgumentLoc
&Arg
);
3037 BuildExpressionFromDeclTemplateArgument(const TemplateArgument
&Arg
,
3039 SourceLocation Loc
);
3041 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument
&Arg
,
3042 SourceLocation Loc
);
3044 /// \brief Enumeration describing how template parameter lists are compared
3046 enum TemplateParameterListEqualKind
{
3047 /// \brief We are matching the template parameter lists of two templates
3048 /// that might be redeclarations.
3051 /// template<typename T> struct X;
3052 /// template<typename T> struct X;
3056 /// \brief We are matching the template parameter lists of two template
3057 /// template parameters as part of matching the template parameter lists
3058 /// of two templates that might be redeclarations.
3061 /// template<template<int I> class TT> struct X;
3062 /// template<template<int Value> class Other> struct X;
3064 TPL_TemplateTemplateParmMatch
,
3066 /// \brief We are matching the template parameter lists of a template
3067 /// template argument against the template parameter lists of a template
3068 /// template parameter.
3071 /// template<template<int Value> class Metafun> struct X;
3072 /// template<int Value> struct integer_c;
3073 /// X<integer_c> xic;
3075 TPL_TemplateTemplateArgumentMatch
3078 bool TemplateParameterListsAreEqual(TemplateParameterList
*New
,
3079 TemplateParameterList
*Old
,
3081 TemplateParameterListEqualKind Kind
,
3082 SourceLocation TemplateArgLoc
3083 = SourceLocation());
3085 bool CheckTemplateDeclScope(Scope
*S
, TemplateParameterList
*TemplateParams
);
3087 /// \brief Called when the parser has parsed a C++ typename
3088 /// specifier, e.g., "typename T::type".
3090 /// \param S The scope in which this typename type occurs.
3091 /// \param TypenameLoc the location of the 'typename' keyword
3092 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
3093 /// \param II the identifier we're retrieving (e.g., 'type' in the example).
3094 /// \param IdLoc the location of the identifier.
3096 ActOnTypenameType(Scope
*S
, SourceLocation TypenameLoc
,
3097 const CXXScopeSpec
&SS
, const IdentifierInfo
&II
,
3098 SourceLocation IdLoc
);
3100 /// \brief Called when the parser has parsed a C++ typename
3101 /// specifier that ends in a template-id, e.g.,
3102 /// "typename MetaFun::template apply<T1, T2>".
3104 /// \param S The scope in which this typename type occurs.
3105 /// \param TypenameLoc the location of the 'typename' keyword
3106 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
3107 /// \param TemplateLoc the location of the 'template' keyword, if any.
3108 /// \param Ty the type that the typename specifier refers to.
3110 ActOnTypenameType(Scope
*S
, SourceLocation TypenameLoc
,
3111 const CXXScopeSpec
&SS
, SourceLocation TemplateLoc
,
3114 QualType
CheckTypenameType(ElaboratedTypeKeyword Keyword
,
3115 NestedNameSpecifier
*NNS
,
3116 const IdentifierInfo
&II
,
3117 SourceLocation KeywordLoc
,
3118 SourceRange NNSRange
,
3119 SourceLocation IILoc
);
3121 TypeSourceInfo
*RebuildTypeInCurrentInstantiation(TypeSourceInfo
*T
,
3123 DeclarationName Name
);
3124 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec
&SS
);
3126 ExprResult
RebuildExprInCurrentInstantiation(Expr
*E
);
3129 getTemplateArgumentBindingsText(const TemplateParameterList
*Params
,
3130 const TemplateArgumentList
&Args
);
3133 getTemplateArgumentBindingsText(const TemplateParameterList
*Params
,
3134 const TemplateArgument
*Args
,
3137 //===--------------------------------------------------------------------===//
3138 // C++ Variadic Templates (C++0x [temp.variadic])
3139 //===--------------------------------------------------------------------===//
3141 /// \brief The context in which an unexpanded parameter pack is
3142 /// being diagnosed.
3144 /// Note that the values of this enumeration line up with the first
3145 /// argument to the \c err_unexpanded_parameter_pack diagnostic.
3146 enum UnexpandedParameterPackContext
{
3147 /// \brief An arbitrary expression.
3148 UPPC_Expression
= 0,
3150 /// \brief The base type of a class type.
3153 /// \brief The type of an arbitrary declaration.
3154 UPPC_DeclarationType
,
3156 /// \brief The type of a data member.
3157 UPPC_DataMemberType
,
3159 /// \brief The size of a bit-field.
3162 /// \brief The expression in a static assertion.
3163 UPPC_StaticAssertExpression
,
3165 /// \brief The fixed underlying type of an enumeration.
3166 UPPC_FixedUnderlyingType
,
3168 /// \brief The enumerator value.
3169 UPPC_EnumeratorValue
,
3171 /// \brief A using declaration.
3172 UPPC_UsingDeclaration
,
3174 /// \brief A friend declaration.
3175 UPPC_FriendDeclaration
,
3177 /// \brief A declaration qualifier.
3178 UPPC_DeclarationQualifier
,
3180 /// \brief An initializer.
3183 /// \brief A default argument.
3184 UPPC_DefaultArgument
,
3186 /// \brief The type of a non-type template parameter.
3187 UPPC_NonTypeTemplateParameterType
,
3189 /// \brief The type of an exception.
3193 /// \brief If the given type contains an unexpanded parameter pack,
3194 /// diagnose the error.
3196 /// \param Loc The source location where a diagnostc should be emitted.
3198 /// \param T The type that is being checked for unexpanded parameter
3201 /// \returns true if an error ocurred, false otherwise.
3202 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc
, TypeSourceInfo
*T
,
3203 UnexpandedParameterPackContext UPPC
);
3205 /// \brief If the given expression contains an unexpanded parameter
3206 /// pack, diagnose the error.
3208 /// \param E The expression that is being checked for unexpanded
3209 /// parameter packs.
3211 /// \returns true if an error ocurred, false otherwise.
3212 bool DiagnoseUnexpandedParameterPack(Expr
*E
,
3213 UnexpandedParameterPackContext UPPC
= UPPC_Expression
);
3215 /// \brief If the given nested-name-specifier contains an unexpanded
3216 /// parameter pack, diagnose the error.
3218 /// \param SS The nested-name-specifier that is being checked for
3219 /// unexpanded parameter packs.
3221 /// \returns true if an error ocurred, false otherwise.
3222 bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec
&SS
,
3223 UnexpandedParameterPackContext UPPC
);
3225 /// \brief If the given name contains an unexpanded parameter pack,
3226 /// diagnose the error.
3228 /// \param NameInfo The name (with source location information) that
3229 /// is being checked for unexpanded parameter packs.
3231 /// \returns true if an error ocurred, false otherwise.
3232 bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo
&NameInfo
,
3233 UnexpandedParameterPackContext UPPC
);
3235 /// \brief If the given template name contains an unexpanded parameter pack,
3236 /// diagnose the error.
3238 /// \param Loc The location of the template name.
3240 /// \param Template The template name that is being checked for unexpanded
3241 /// parameter packs.
3243 /// \returns true if an error ocurred, false otherwise.
3244 bool DiagnoseUnexpandedParameterPack(SourceLocation Loc
,
3245 TemplateName Template
,
3246 UnexpandedParameterPackContext UPPC
);
3248 /// \brief Collect the set of unexpanded parameter packs within the given
3249 /// template argument.
3251 /// \param Arg The template argument that will be traversed to find
3252 /// unexpanded parameter packs.
3253 void collectUnexpandedParameterPacks(TemplateArgument Arg
,
3254 llvm::SmallVectorImpl
<UnexpandedParameterPack
> &Unexpanded
);
3256 /// \brief Collect the set of unexpanded parameter packs within the given
3257 /// template argument.
3259 /// \param Arg The template argument that will be traversed to find
3260 /// unexpanded parameter packs.
3261 void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg
,
3262 llvm::SmallVectorImpl
<UnexpandedParameterPack
> &Unexpanded
);
3264 /// \brief Collect the set of unexpanded parameter packs within the given
3267 /// \param Arg The template argument that will be traversed to find
3268 /// unexpanded parameter packs.
3269 void collectUnexpandedParameterPacks(QualType T
,
3270 llvm::SmallVectorImpl
<UnexpandedParameterPack
> &Unexpanded
);
3272 /// \brief Invoked when parsing a template argument followed by an
3273 /// ellipsis, which creates a pack expansion.
3275 /// \param Arg The template argument preceding the ellipsis, which
3276 /// may already be invalid.
3278 /// \param EllipsisLoc The location of the ellipsis.
3279 ParsedTemplateArgument
ActOnPackExpansion(const ParsedTemplateArgument
&Arg
,
3280 SourceLocation EllipsisLoc
);
3282 /// \brief Invoked when parsing a type follows by an ellipsis, which
3283 /// creates a pack expansion.
3285 /// \param Type The type preceding the ellipsis, which will become
3286 /// the pattern of the pack expansion.
3288 /// \param EllipsisLoc The location of the ellipsis.
3289 TypeResult
ActOnPackExpansion(ParsedType Type
, SourceLocation EllipsisLoc
);
3291 /// \brief Construct a pack expansion type from the pattern of the pack
3293 TypeSourceInfo
*CheckPackExpansion(TypeSourceInfo
*Pattern
,
3294 SourceLocation EllipsisLoc
);
3296 /// \brief Determine whether we could expand a pack expansion with the
3297 /// given set of parameter packs into separate arguments by repeatedly
3298 /// transforming the pattern.
3300 /// \param EllipsisLoc The location of the ellipsis that identifies the
3303 /// \param PatternRange The source range that covers the entire pattern of
3304 /// the pack expansion.
3306 /// \param Unexpanded The set of unexpanded parameter packs within the
3309 /// \param NumUnexpanded The number of unexpanded parameter packs in
3312 /// \param ShouldExpand Will be set to \c true if the transformer should
3313 /// expand the corresponding pack expansions into separate arguments. When
3314 /// set, \c NumExpansions must also be set.
3316 /// \param NumExpansions The number of separate arguments that will be in
3317 /// the expanded form of the corresponding pack expansion. Must be set when
3318 /// \c ShouldExpand is \c true.
3320 /// \returns true if an error occurred (e.g., because the parameter packs
3321 /// are to be instantiated with arguments of different lengths), false
3322 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
3324 bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc
,
3325 SourceRange PatternRange
,
3326 const UnexpandedParameterPack
*Unexpanded
,
3327 unsigned NumUnexpanded
,
3328 const MultiLevelTemplateArgumentList
&TemplateArgs
,
3330 unsigned &NumExpansions
);
3332 /// \brief Determine whether the given declarator contains any unexpanded
3333 /// parameter packs.
3335 /// This routine is used by the parser to disambiguate function declarators
3336 /// with an ellipsis prior to the ')', e.g.,
3342 /// To determine whether we have an (unnamed) function parameter pack or
3343 /// a variadic function.
3345 /// \returns true if the declarator contains any unexpanded parameter packs,
3346 /// false otherwise.
3347 bool containsUnexpandedParameterPacks(Declarator
&D
);
3349 //===--------------------------------------------------------------------===//
3350 // C++ Template Argument Deduction (C++ [temp.deduct])
3351 //===--------------------------------------------------------------------===//
3353 /// \brief Describes the result of template argument deduction.
3355 /// The TemplateDeductionResult enumeration describes the result of
3356 /// template argument deduction, as returned from
3357 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
3358 /// structure provides additional information about the results of
3359 /// template argument deduction, e.g., the deduced template argument
3360 /// list (if successful) or the specific template parameters or
3361 /// deduced arguments that were involved in the failure.
3362 enum TemplateDeductionResult
{
3363 /// \brief Template argument deduction was successful.
3365 /// \brief Template argument deduction exceeded the maximum template
3366 /// instantiation depth (which has already been diagnosed).
3367 TDK_InstantiationDepth
,
3368 /// \brief Template argument deduction did not deduce a value
3369 /// for every template parameter.
3371 /// \brief Template argument deduction produced inconsistent
3372 /// deduced values for the given template parameter.
3374 /// \brief Template argument deduction failed due to inconsistent
3375 /// cv-qualifiers on a template parameter type that would
3376 /// otherwise be deduced, e.g., we tried to deduce T in "const T"
3377 /// but were given a non-const "X".
3379 /// \brief Substitution of the deduced template argument values
3380 /// resulted in an error.
3381 TDK_SubstitutionFailure
,
3382 /// \brief Substitution of the deduced template argument values
3383 /// into a non-deduced context produced a type or value that
3384 /// produces a type that does not match the original template
3385 /// arguments provided.
3386 TDK_NonDeducedMismatch
,
3387 /// \brief When performing template argument deduction for a function
3388 /// template, there were too many call arguments.
3389 TDK_TooManyArguments
,
3390 /// \brief When performing template argument deduction for a function
3391 /// template, there were too few call arguments.
3392 TDK_TooFewArguments
,
3393 /// \brief The explicitly-specified template arguments were not valid
3394 /// template arguments for the given template.
3395 TDK_InvalidExplicitArguments
,
3396 /// \brief The arguments included an overloaded function name that could
3397 /// not be resolved to a suitable function.
3398 TDK_FailedOverloadResolution
3401 TemplateDeductionResult
3402 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl
*Partial
,
3403 const TemplateArgumentList
&TemplateArgs
,
3404 sema::TemplateDeductionInfo
&Info
);
3406 TemplateDeductionResult
3407 SubstituteExplicitTemplateArguments(FunctionTemplateDecl
*FunctionTemplate
,
3408 const TemplateArgumentListInfo
&ExplicitTemplateArgs
,
3409 llvm::SmallVectorImpl
<DeducedTemplateArgument
> &Deduced
,
3410 llvm::SmallVectorImpl
<QualType
> &ParamTypes
,
3411 QualType
*FunctionType
,
3412 sema::TemplateDeductionInfo
&Info
);
3414 TemplateDeductionResult
3415 FinishTemplateArgumentDeduction(FunctionTemplateDecl
*FunctionTemplate
,
3416 llvm::SmallVectorImpl
<DeducedTemplateArgument
> &Deduced
,
3417 unsigned NumExplicitlySpecified
,
3418 FunctionDecl
*&Specialization
,
3419 sema::TemplateDeductionInfo
&Info
);
3421 TemplateDeductionResult
3422 DeduceTemplateArguments(FunctionTemplateDecl
*FunctionTemplate
,
3423 const TemplateArgumentListInfo
*ExplicitTemplateArgs
,
3424 Expr
**Args
, unsigned NumArgs
,
3425 FunctionDecl
*&Specialization
,
3426 sema::TemplateDeductionInfo
&Info
);
3428 TemplateDeductionResult
3429 DeduceTemplateArguments(FunctionTemplateDecl
*FunctionTemplate
,
3430 const TemplateArgumentListInfo
*ExplicitTemplateArgs
,
3431 QualType ArgFunctionType
,
3432 FunctionDecl
*&Specialization
,
3433 sema::TemplateDeductionInfo
&Info
);
3435 TemplateDeductionResult
3436 DeduceTemplateArguments(FunctionTemplateDecl
*FunctionTemplate
,
3438 CXXConversionDecl
*&Specialization
,
3439 sema::TemplateDeductionInfo
&Info
);
3441 TemplateDeductionResult
3442 DeduceTemplateArguments(FunctionTemplateDecl
*FunctionTemplate
,
3443 const TemplateArgumentListInfo
*ExplicitTemplateArgs
,
3444 FunctionDecl
*&Specialization
,
3445 sema::TemplateDeductionInfo
&Info
);
3447 FunctionTemplateDecl
*getMoreSpecializedTemplate(FunctionTemplateDecl
*FT1
,
3448 FunctionTemplateDecl
*FT2
,
3450 TemplatePartialOrderingContext TPOC
);
3451 UnresolvedSetIterator
getMostSpecialized(UnresolvedSetIterator SBegin
,
3452 UnresolvedSetIterator SEnd
,
3453 TemplatePartialOrderingContext TPOC
,
3455 const PartialDiagnostic
&NoneDiag
,
3456 const PartialDiagnostic
&AmbigDiag
,
3457 const PartialDiagnostic
&CandidateDiag
);
3459 ClassTemplatePartialSpecializationDecl
*
3460 getMoreSpecializedPartialSpecialization(
3461 ClassTemplatePartialSpecializationDecl
*PS1
,
3462 ClassTemplatePartialSpecializationDecl
*PS2
,
3463 SourceLocation Loc
);
3465 void MarkUsedTemplateParameters(const TemplateArgumentList
&TemplateArgs
,
3468 llvm::SmallVectorImpl
<bool> &Used
);
3469 void MarkDeducedTemplateParameters(FunctionTemplateDecl
*FunctionTemplate
,
3470 llvm::SmallVectorImpl
<bool> &Deduced
);
3472 //===--------------------------------------------------------------------===//
3473 // C++ Template Instantiation
3476 MultiLevelTemplateArgumentList
getTemplateInstantiationArgs(NamedDecl
*D
,
3477 const TemplateArgumentList
*Innermost
= 0,
3478 bool RelativeToPrimary
= false,
3479 const FunctionDecl
*Pattern
= 0);
3481 /// \brief A template instantiation that is currently in progress.
3482 struct ActiveTemplateInstantiation
{
3483 /// \brief The kind of template instantiation we are performing
3484 enum InstantiationKind
{
3485 /// We are instantiating a template declaration. The entity is
3486 /// the declaration we're instantiating (e.g., a CXXRecordDecl).
3487 TemplateInstantiation
,
3489 /// We are instantiating a default argument for a template
3490 /// parameter. The Entity is the template, and
3491 /// TemplateArgs/NumTemplateArguments provides the template
3492 /// arguments as specified.
3493 /// FIXME: Use a TemplateArgumentList
3494 DefaultTemplateArgumentInstantiation
,
3496 /// We are instantiating a default argument for a function.
3497 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
3498 /// provides the template arguments as specified.
3499 DefaultFunctionArgumentInstantiation
,
3501 /// We are substituting explicit template arguments provided for
3502 /// a function template. The entity is a FunctionTemplateDecl.
3503 ExplicitTemplateArgumentSubstitution
,
3505 /// We are substituting template argument determined as part of
3506 /// template argument deduction for either a class template
3507 /// partial specialization or a function template. The
3508 /// Entity is either a ClassTemplatePartialSpecializationDecl or
3509 /// a FunctionTemplateDecl.
3510 DeducedTemplateArgumentSubstitution
,
3512 /// We are substituting prior template arguments into a new
3513 /// template parameter. The template parameter itself is either a
3514 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
3515 PriorTemplateArgumentSubstitution
,
3517 /// We are checking the validity of a default template argument that
3518 /// has been used when naming a template-id.
3519 DefaultTemplateArgumentChecking
3522 /// \brief The point of instantiation within the source code.
3523 SourceLocation PointOfInstantiation
;
3525 /// \brief The template in which we are performing the instantiation,
3526 /// for substitutions of prior template arguments.
3527 TemplateDecl
*Template
;
3529 /// \brief The entity that is being instantiated.
3532 /// \brief The list of template arguments we are substituting, if they
3533 /// are not part of the entity.
3534 const TemplateArgument
*TemplateArgs
;
3536 /// \brief The number of template arguments in TemplateArgs.
3537 unsigned NumTemplateArgs
;
3539 /// \brief The template deduction info object associated with the
3540 /// substitution or checking of explicit or deduced template arguments.
3541 sema::TemplateDeductionInfo
*DeductionInfo
;
3543 /// \brief The source range that covers the construct that cause
3544 /// the instantiation, e.g., the template-id that causes a class
3545 /// template instantiation.
3546 SourceRange InstantiationRange
;
3548 ActiveTemplateInstantiation()
3549 : Kind(TemplateInstantiation
), Template(0), Entity(0), TemplateArgs(0),
3550 NumTemplateArgs(0), DeductionInfo(0) {}
3552 /// \brief Determines whether this template is an actual instantiation
3553 /// that should be counted toward the maximum instantiation depth.
3554 bool isInstantiationRecord() const;
3556 friend bool operator==(const ActiveTemplateInstantiation
&X
,
3557 const ActiveTemplateInstantiation
&Y
) {
3558 if (X
.Kind
!= Y
.Kind
)
3561 if (X
.Entity
!= Y
.Entity
)
3565 case TemplateInstantiation
:
3568 case PriorTemplateArgumentSubstitution
:
3569 case DefaultTemplateArgumentChecking
:
3570 if (X
.Template
!= Y
.Template
)
3575 case DefaultTemplateArgumentInstantiation
:
3576 case ExplicitTemplateArgumentSubstitution
:
3577 case DeducedTemplateArgumentSubstitution
:
3578 case DefaultFunctionArgumentInstantiation
:
3579 return X
.TemplateArgs
== Y
.TemplateArgs
;
3586 friend bool operator!=(const ActiveTemplateInstantiation
&X
,
3587 const ActiveTemplateInstantiation
&Y
) {
3592 /// \brief List of active template instantiations.
3594 /// This vector is treated as a stack. As one template instantiation
3595 /// requires another template instantiation, additional
3596 /// instantiations are pushed onto the stack up to a
3597 /// user-configurable limit LangOptions::InstantiationDepth.
3598 llvm::SmallVector
<ActiveTemplateInstantiation
, 16>
3599 ActiveTemplateInstantiations
;
3601 /// \brief The number of ActiveTemplateInstantiation entries in
3602 /// \c ActiveTemplateInstantiations that are not actual instantiations and,
3603 /// therefore, should not be counted as part of the instantiation depth.
3604 unsigned NonInstantiationEntries
;
3606 /// \brief The last template from which a template instantiation
3607 /// error or warning was produced.
3609 /// This value is used to suppress printing of redundant template
3610 /// instantiation backtraces when there are multiple errors in the
3611 /// same instantiation. FIXME: Does this belong in Sema? It's tough
3612 /// to implement it anywhere else.
3613 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext
;
3615 /// \brief The current index into pack expansion arguments that will be
3616 /// used for substitution of parameter packs.
3618 /// The pack expansion index will be -1 to indicate that parameter packs
3619 /// should be instantiated as themselves. Otherwise, the index specifies
3620 /// which argument within the parameter pack will be used for substitution.
3621 int ArgumentPackSubstitutionIndex
;
3623 /// \brief RAII object used to change the argument pack substitution index
3624 /// within a \c Sema object.
3626 /// See \c ArgumentPackSubstitutionIndex for more information.
3627 class ArgumentPackSubstitutionIndexRAII
{
3629 int OldSubstitutionIndex
;
3632 ArgumentPackSubstitutionIndexRAII(Sema
&Self
, int NewSubstitutionIndex
)
3633 : Self(Self
), OldSubstitutionIndex(Self
.ArgumentPackSubstitutionIndex
) {
3634 Self
.ArgumentPackSubstitutionIndex
= NewSubstitutionIndex
;
3637 ~ArgumentPackSubstitutionIndexRAII() {
3638 Self
.ArgumentPackSubstitutionIndex
= OldSubstitutionIndex
;
3642 friend class ArgumentPackSubstitutionRAII
;
3644 /// \brief The stack of calls expression undergoing template instantiation.
3646 /// The top of this stack is used by a fixit instantiating unresolved
3647 /// function calls to fix the AST to match the textual change it prints.
3648 llvm::SmallVector
<CallExpr
*, 8> CallsUndergoingInstantiation
;
3650 /// \brief For each declaration that involved template argument deduction, the
3651 /// set of diagnostics that were suppressed during that template argument
3654 /// FIXME: Serialize this structure to the AST file.
3655 llvm::DenseMap
<Decl
*, llvm::SmallVector
<PartialDiagnosticAt
, 1> >
3656 SuppressedDiagnostics
;
3658 /// \brief A stack object to be created when performing template
3661 /// Construction of an object of type \c InstantiatingTemplate
3662 /// pushes the current instantiation onto the stack of active
3663 /// instantiations. If the size of this stack exceeds the maximum
3664 /// number of recursive template instantiations, construction
3665 /// produces an error and evaluates true.
3667 /// Destruction of this object will pop the named instantiation off
3669 struct InstantiatingTemplate
{
3670 /// \brief Note that we are instantiating a class template,
3671 /// function template, or a member thereof.
3672 InstantiatingTemplate(Sema
&SemaRef
, SourceLocation PointOfInstantiation
,
3674 SourceRange InstantiationRange
= SourceRange());
3676 /// \brief Note that we are instantiating a default argument in a
3678 InstantiatingTemplate(Sema
&SemaRef
, SourceLocation PointOfInstantiation
,
3679 TemplateDecl
*Template
,
3680 const TemplateArgument
*TemplateArgs
,
3681 unsigned NumTemplateArgs
,
3682 SourceRange InstantiationRange
= SourceRange());
3684 /// \brief Note that we are instantiating a default argument in a
3686 InstantiatingTemplate(Sema
&SemaRef
, SourceLocation PointOfInstantiation
,
3687 FunctionTemplateDecl
*FunctionTemplate
,
3688 const TemplateArgument
*TemplateArgs
,
3689 unsigned NumTemplateArgs
,
3690 ActiveTemplateInstantiation::InstantiationKind Kind
,
3691 sema::TemplateDeductionInfo
&DeductionInfo
,
3692 SourceRange InstantiationRange
= SourceRange());
3694 /// \brief Note that we are instantiating as part of template
3695 /// argument deduction for a class template partial
3697 InstantiatingTemplate(Sema
&SemaRef
, SourceLocation PointOfInstantiation
,
3698 ClassTemplatePartialSpecializationDecl
*PartialSpec
,
3699 const TemplateArgument
*TemplateArgs
,
3700 unsigned NumTemplateArgs
,
3701 sema::TemplateDeductionInfo
&DeductionInfo
,
3702 SourceRange InstantiationRange
= SourceRange());
3704 InstantiatingTemplate(Sema
&SemaRef
, SourceLocation PointOfInstantiation
,
3706 const TemplateArgument
*TemplateArgs
,
3707 unsigned NumTemplateArgs
,
3708 SourceRange InstantiationRange
= SourceRange());
3710 /// \brief Note that we are substituting prior template arguments into a
3711 /// non-type or template template parameter.
3712 InstantiatingTemplate(Sema
&SemaRef
, SourceLocation PointOfInstantiation
,
3713 TemplateDecl
*Template
,
3714 NonTypeTemplateParmDecl
*Param
,
3715 const TemplateArgument
*TemplateArgs
,
3716 unsigned NumTemplateArgs
,
3717 SourceRange InstantiationRange
);
3719 InstantiatingTemplate(Sema
&SemaRef
, SourceLocation PointOfInstantiation
,
3720 TemplateDecl
*Template
,
3721 TemplateTemplateParmDecl
*Param
,
3722 const TemplateArgument
*TemplateArgs
,
3723 unsigned NumTemplateArgs
,
3724 SourceRange InstantiationRange
);
3726 /// \brief Note that we are checking the default template argument
3727 /// against the template parameter for a given template-id.
3728 InstantiatingTemplate(Sema
&SemaRef
, SourceLocation PointOfInstantiation
,
3729 TemplateDecl
*Template
,
3731 const TemplateArgument
*TemplateArgs
,
3732 unsigned NumTemplateArgs
,
3733 SourceRange InstantiationRange
);
3736 /// \brief Note that we have finished instantiating this template.
3739 ~InstantiatingTemplate() { Clear(); }
3741 /// \brief Determines whether we have exceeded the maximum
3742 /// recursive template instantiations.
3743 operator bool() const { return Invalid
; }
3748 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation
,
3749 SourceRange InstantiationRange
);
3751 InstantiatingTemplate(const InstantiatingTemplate
&); // not implemented
3753 InstantiatingTemplate
&
3754 operator=(const InstantiatingTemplate
&); // not implemented
3757 void PrintInstantiationStack();
3759 /// \brief Determines whether we are currently in a context where
3760 /// template argument substitution failures are not considered
3763 /// \returns The nearest template-deduction context object, if we are in a
3764 /// SFINAE context, which can be used to capture diagnostics that will be
3765 /// suppressed. Otherwise, returns NULL to indicate that we are not within a
3767 sema::TemplateDeductionInfo
*isSFINAEContext() const;
3769 /// \brief RAII class used to determine whether SFINAE has
3770 /// trapped any errors that occur during template argument
3774 unsigned PrevSFINAEErrors
;
3776 explicit SFINAETrap(Sema
&SemaRef
)
3777 : SemaRef(SemaRef
), PrevSFINAEErrors(SemaRef
.NumSFINAEErrors
) { }
3779 ~SFINAETrap() { SemaRef
.NumSFINAEErrors
= PrevSFINAEErrors
; }
3781 /// \brief Determine whether any SFINAE errors have been trapped.
3782 bool hasErrorOccurred() const {
3783 return SemaRef
.NumSFINAEErrors
> PrevSFINAEErrors
;
3787 /// \brief The current instantiation scope used to store local
3789 LocalInstantiationScope
*CurrentInstantiationScope
;
3791 /// \brief The number of typos corrected by CorrectTypo.
3792 unsigned TyposCorrected
;
3794 typedef llvm::DenseMap
<IdentifierInfo
*, std::pair
<llvm::StringRef
, bool> >
3795 UnqualifiedTyposCorrectedMap
;
3797 /// \brief A cache containing the results of typo correction for unqualified
3800 /// The string is the string that we corrected to (which may be empty, if
3801 /// there was no correction), while the boolean will be true when the
3802 /// string represents a keyword.
3803 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected
;
3805 /// \brief Worker object for performing CFG-based warnings.
3806 sema::AnalysisBasedWarnings AnalysisWarnings
;
3808 /// \brief An entity for which implicit template instantiation is required.
3810 /// The source location associated with the declaration is the first place in
3811 /// the source code where the declaration was "used". It is not necessarily
3812 /// the point of instantiation (which will be either before or after the
3813 /// namespace-scope declaration that triggered this implicit instantiation),
3814 /// However, it is the location that diagnostics should generally refer to,
3815 /// because users will need to know what code triggered the instantiation.
3816 typedef std::pair
<ValueDecl
*, SourceLocation
> PendingImplicitInstantiation
;
3818 /// \brief The queue of implicit template instantiations that are required
3819 /// but have not yet been performed.
3820 std::deque
<PendingImplicitInstantiation
> PendingInstantiations
;
3822 /// \brief The queue of implicit template instantiations that are required
3823 /// and must be performed within the current local scope.
3825 /// This queue is only used for member functions of local classes in
3826 /// templates, which must be instantiated in the same scope as their
3827 /// enclosing function, so that they can reference function-local
3828 /// types, static variables, enumerators, etc.
3829 std::deque
<PendingImplicitInstantiation
> PendingLocalImplicitInstantiations
;
3831 void PerformPendingInstantiations(bool LocalOnly
= false);
3833 TypeSourceInfo
*SubstType(TypeSourceInfo
*T
,
3834 const MultiLevelTemplateArgumentList
&TemplateArgs
,
3835 SourceLocation Loc
, DeclarationName Entity
);
3837 QualType
SubstType(QualType T
,
3838 const MultiLevelTemplateArgumentList
&TemplateArgs
,
3839 SourceLocation Loc
, DeclarationName Entity
);
3841 TypeSourceInfo
*SubstFunctionDeclType(TypeSourceInfo
*T
,
3842 const MultiLevelTemplateArgumentList
&TemplateArgs
,
3844 DeclarationName Entity
);
3845 ParmVarDecl
*SubstParmVarDecl(ParmVarDecl
*D
,
3846 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3847 ExprResult
SubstExpr(Expr
*E
,
3848 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3850 StmtResult
SubstStmt(Stmt
*S
,
3851 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3853 Decl
*SubstDecl(Decl
*D
, DeclContext
*Owner
,
3854 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3857 SubstBaseSpecifiers(CXXRecordDecl
*Instantiation
,
3858 CXXRecordDecl
*Pattern
,
3859 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3862 InstantiateClass(SourceLocation PointOfInstantiation
,
3863 CXXRecordDecl
*Instantiation
, CXXRecordDecl
*Pattern
,
3864 const MultiLevelTemplateArgumentList
&TemplateArgs
,
3865 TemplateSpecializationKind TSK
,
3866 bool Complain
= true);
3868 void InstantiateAttrs(const MultiLevelTemplateArgumentList
&TemplateArgs
,
3869 Decl
*Pattern
, Decl
*Inst
);
3872 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation
,
3873 ClassTemplateSpecializationDecl
*ClassTemplateSpec
,
3874 TemplateSpecializationKind TSK
,
3875 bool Complain
= true);
3877 void InstantiateClassMembers(SourceLocation PointOfInstantiation
,
3878 CXXRecordDecl
*Instantiation
,
3879 const MultiLevelTemplateArgumentList
&TemplateArgs
,
3880 TemplateSpecializationKind TSK
);
3882 void InstantiateClassTemplateSpecializationMembers(
3883 SourceLocation PointOfInstantiation
,
3884 ClassTemplateSpecializationDecl
*ClassTemplateSpec
,
3885 TemplateSpecializationKind TSK
);
3887 NestedNameSpecifier
*
3888 SubstNestedNameSpecifier(NestedNameSpecifier
*NNS
,
3890 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3892 SubstDeclarationNameInfo(const DeclarationNameInfo
&NameInfo
,
3893 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3895 SubstTemplateName(TemplateName Name
, SourceLocation Loc
,
3896 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3897 bool Subst(const TemplateArgumentLoc
*Args
, unsigned NumArgs
,
3898 TemplateArgumentListInfo
&Result
,
3899 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3901 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation
,
3902 FunctionDecl
*Function
,
3903 bool Recursive
= false,
3904 bool DefinitionRequired
= false);
3905 void InstantiateStaticDataMemberDefinition(
3906 SourceLocation PointOfInstantiation
,
3908 bool Recursive
= false,
3909 bool DefinitionRequired
= false);
3911 void InstantiateMemInitializers(CXXConstructorDecl
*New
,
3912 const CXXConstructorDecl
*Tmpl
,
3913 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3915 NamedDecl
*FindInstantiatedDecl(SourceLocation Loc
, NamedDecl
*D
,
3916 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3917 DeclContext
*FindInstantiatedContext(SourceLocation Loc
, DeclContext
*DC
,
3918 const MultiLevelTemplateArgumentList
&TemplateArgs
);
3920 // Objective-C declarations.
3921 Decl
*ActOnStartClassInterface(SourceLocation AtInterfaceLoc
,
3922 IdentifierInfo
*ClassName
,
3923 SourceLocation ClassLoc
,
3924 IdentifierInfo
*SuperName
,
3925 SourceLocation SuperLoc
,
3926 Decl
* const *ProtoRefs
,
3927 unsigned NumProtoRefs
,
3928 const SourceLocation
*ProtoLocs
,
3929 SourceLocation EndProtoLoc
,
3930 AttributeList
*AttrList
);
3932 Decl
*ActOnCompatiblityAlias(
3933 SourceLocation AtCompatibilityAliasLoc
,
3934 IdentifierInfo
*AliasName
, SourceLocation AliasLocation
,
3935 IdentifierInfo
*ClassName
, SourceLocation ClassLocation
);
3937 void CheckForwardProtocolDeclarationForCircularDependency(
3938 IdentifierInfo
*PName
,
3939 SourceLocation
&PLoc
, SourceLocation PrevLoc
,
3940 const ObjCList
<ObjCProtocolDecl
> &PList
);
3942 Decl
*ActOnStartProtocolInterface(
3943 SourceLocation AtProtoInterfaceLoc
,
3944 IdentifierInfo
*ProtocolName
, SourceLocation ProtocolLoc
,
3945 Decl
* const *ProtoRefNames
, unsigned NumProtoRefs
,
3946 const SourceLocation
*ProtoLocs
,
3947 SourceLocation EndProtoLoc
,
3948 AttributeList
*AttrList
);
3950 Decl
*ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc
,
3951 IdentifierInfo
*ClassName
,
3952 SourceLocation ClassLoc
,
3953 IdentifierInfo
*CategoryName
,
3954 SourceLocation CategoryLoc
,
3955 Decl
* const *ProtoRefs
,
3956 unsigned NumProtoRefs
,
3957 const SourceLocation
*ProtoLocs
,
3958 SourceLocation EndProtoLoc
);
3960 Decl
*ActOnStartClassImplementation(
3961 SourceLocation AtClassImplLoc
,
3962 IdentifierInfo
*ClassName
, SourceLocation ClassLoc
,
3963 IdentifierInfo
*SuperClassname
,
3964 SourceLocation SuperClassLoc
);
3966 Decl
*ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc
,
3967 IdentifierInfo
*ClassName
,
3968 SourceLocation ClassLoc
,
3969 IdentifierInfo
*CatName
,
3970 SourceLocation CatLoc
);
3972 Decl
*ActOnForwardClassDeclaration(SourceLocation Loc
,
3973 IdentifierInfo
**IdentList
,
3974 SourceLocation
*IdentLocs
,
3977 Decl
*ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc
,
3978 const IdentifierLocPair
*IdentList
,
3980 AttributeList
*attrList
);
3982 void FindProtocolDeclaration(bool WarnOnDeclarations
,
3983 const IdentifierLocPair
*ProtocolId
,
3984 unsigned NumProtocols
,
3985 llvm::SmallVectorImpl
<Decl
*> &Protocols
);
3987 /// Ensure attributes are consistent with type.
3988 /// \param [in, out] Attributes The attributes to check; they will
3989 /// be modified to be consistent with \arg PropertyTy.
3990 void CheckObjCPropertyAttributes(Decl
*PropertyPtrTy
,
3992 unsigned &Attributes
);
3994 /// Process the specified property declaration and create decls for the
3995 /// setters and getters as needed.
3996 /// \param property The property declaration being processed
3997 /// \param DC The semantic container for the property
3998 /// \param redeclaredProperty Declaration for property if redeclared
3999 /// in class extension.
4000 /// \param lexicalDC Container for redeclaredProperty.
4001 void ProcessPropertyDecl(ObjCPropertyDecl
*property
,
4002 ObjCContainerDecl
*DC
,
4003 ObjCPropertyDecl
*redeclaredProperty
= 0,
4004 ObjCContainerDecl
*lexicalDC
= 0);
4006 void DiagnosePropertyMismatch(ObjCPropertyDecl
*Property
,
4007 ObjCPropertyDecl
*SuperProperty
,
4008 const IdentifierInfo
*Name
);
4009 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl
*IDecl
);
4011 void CompareMethodParamsInBaseAndSuper(Decl
*IDecl
,
4012 ObjCMethodDecl
*MethodDecl
,
4015 void CompareProperties(Decl
*CDecl
, Decl
*MergeProtocols
);
4017 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl
*CAT
,
4018 ObjCInterfaceDecl
*ID
);
4020 void MatchOneProtocolPropertiesInClass(Decl
*CDecl
,
4021 ObjCProtocolDecl
*PDecl
);
4023 void ActOnAtEnd(Scope
*S
, SourceRange AtEnd
, Decl
*classDecl
,
4024 Decl
**allMethods
= 0, unsigned allNum
= 0,
4025 Decl
**allProperties
= 0, unsigned pNum
= 0,
4026 DeclGroupPtrTy
*allTUVars
= 0, unsigned tuvNum
= 0);
4028 Decl
*ActOnProperty(Scope
*S
, SourceLocation AtLoc
,
4029 FieldDeclarator
&FD
, ObjCDeclSpec
&ODS
,
4030 Selector GetterSel
, Selector SetterSel
,
4031 Decl
*ClassCategory
,
4032 bool *OverridingProperty
,
4033 tok::ObjCKeywordKind MethodImplKind
,
4034 DeclContext
*lexicalDC
= 0);
4036 Decl
*ActOnPropertyImplDecl(Scope
*S
,
4037 SourceLocation AtLoc
,
4038 SourceLocation PropertyLoc
,
4039 bool ImplKind
,Decl
*ClassImplDecl
,
4040 IdentifierInfo
*PropertyId
,
4041 IdentifierInfo
*PropertyIvar
,
4042 SourceLocation PropertyIvarLoc
);
4044 struct ObjCArgInfo
{
4045 IdentifierInfo
*Name
;
4046 SourceLocation NameLoc
;
4047 // The Type is null if no type was specified, and the DeclSpec is invalid
4050 ObjCDeclSpec DeclSpec
;
4052 /// ArgAttrs - Attribute list for this argument.
4053 AttributeList
*ArgAttrs
;
4056 Decl
*ActOnMethodDeclaration(
4057 SourceLocation BeginLoc
, // location of the + or -.
4058 SourceLocation EndLoc
, // location of the ; or {.
4059 tok::TokenKind MethodType
,
4060 Decl
*ClassDecl
, ObjCDeclSpec
&ReturnQT
, ParsedType ReturnType
,
4062 // optional arguments. The number of types/arguments is obtained
4063 // from the Sel.getNumArgs().
4064 ObjCArgInfo
*ArgInfo
,
4065 DeclaratorChunk::ParamInfo
*CParamInfo
, unsigned CNumArgs
, // c-style args
4066 AttributeList
*AttrList
, tok::ObjCKeywordKind MethodImplKind
,
4067 bool isVariadic
= false);
4069 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
4070 // Will search "local" class/category implementations for a method decl.
4071 // Will also search in class's root looking for instance method.
4072 // Returns 0 if no method is found.
4073 ObjCMethodDecl
*LookupPrivateClassMethod(Selector Sel
,
4074 ObjCInterfaceDecl
*CDecl
);
4075 ObjCMethodDecl
*LookupPrivateInstanceMethod(Selector Sel
,
4076 ObjCInterfaceDecl
*ClassDecl
);
4079 HandleExprPropertyRefExpr(const ObjCObjectPointerType
*OPT
,
4081 DeclarationName MemberName
,
4082 SourceLocation MemberLoc
,
4083 SourceLocation SuperLoc
, QualType SuperType
,
4087 ActOnClassPropertyRefExpr(IdentifierInfo
&receiverName
,
4088 IdentifierInfo
&propertyName
,
4089 SourceLocation receiverNameLoc
,
4090 SourceLocation propertyNameLoc
);
4092 /// \brief Describes the kind of message expression indicated by a message
4093 /// send that starts with an identifier.
4094 enum ObjCMessageKind
{
4095 /// \brief The message is sent to 'super'.
4097 /// \brief The message is an instance message.
4098 ObjCInstanceMessage
,
4099 /// \brief The message is a class message, and the identifier is a type
4104 ObjCMessageKind
getObjCMessageKind(Scope
*S
,
4105 IdentifierInfo
*Name
,
4106 SourceLocation NameLoc
,
4108 bool HasTrailingDot
,
4109 ParsedType
&ReceiverType
);
4111 ExprResult
ActOnSuperMessage(Scope
*S
, SourceLocation SuperLoc
,
4113 SourceLocation LBracLoc
,
4114 SourceLocation SelectorLoc
,
4115 SourceLocation RBracLoc
,
4118 ExprResult
BuildClassMessage(TypeSourceInfo
*ReceiverTypeInfo
,
4119 QualType ReceiverType
,
4120 SourceLocation SuperLoc
,
4122 ObjCMethodDecl
*Method
,
4123 SourceLocation LBracLoc
,
4124 SourceLocation SelectorLoc
,
4125 SourceLocation RBracLoc
,
4128 ExprResult
ActOnClassMessage(Scope
*S
,
4129 ParsedType Receiver
,
4131 SourceLocation LBracLoc
,
4132 SourceLocation SelectorLoc
,
4133 SourceLocation RBracLoc
,
4136 ExprResult
BuildInstanceMessage(Expr
*Receiver
,
4137 QualType ReceiverType
,
4138 SourceLocation SuperLoc
,
4140 ObjCMethodDecl
*Method
,
4141 SourceLocation LBracLoc
,
4142 SourceLocation SelectorLoc
,
4143 SourceLocation RBracLoc
,
4146 ExprResult
ActOnInstanceMessage(Scope
*S
,
4149 SourceLocation LBracLoc
,
4150 SourceLocation SelectorLoc
,
4151 SourceLocation RBracLoc
,
4155 enum PragmaOptionsAlignKind
{
4156 POAK_Native
, // #pragma options align=native
4157 POAK_Natural
, // #pragma options align=natural
4158 POAK_Packed
, // #pragma options align=packed
4159 POAK_Power
, // #pragma options align=power
4160 POAK_Mac68k
, // #pragma options align=mac68k
4161 POAK_Reset
// #pragma options align=reset
4164 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
4165 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind
,
4166 SourceLocation PragmaLoc
,
4167 SourceLocation KindLoc
);
4169 enum PragmaPackKind
{
4170 PPK_Default
, // #pragma pack([n])
4171 PPK_Show
, // #pragma pack(show), only supported by MSVC.
4172 PPK_Push
, // #pragma pack(push, [identifier], [n])
4173 PPK_Pop
// #pragma pack(pop, [identifier], [n])
4176 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
4177 void ActOnPragmaPack(PragmaPackKind Kind
,
4178 IdentifierInfo
*Name
,
4180 SourceLocation PragmaLoc
,
4181 SourceLocation LParenLoc
,
4182 SourceLocation RParenLoc
);
4184 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
4185 void ActOnPragmaUnused(const Token
*Identifiers
,
4186 unsigned NumIdentifiers
, Scope
*curScope
,
4187 SourceLocation PragmaLoc
,
4188 SourceLocation LParenLoc
,
4189 SourceLocation RParenLoc
);
4191 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
4192 void ActOnPragmaVisibility(bool IsPush
, const IdentifierInfo
* VisType
,
4193 SourceLocation PragmaLoc
);
4195 NamedDecl
*DeclClonePragmaWeak(NamedDecl
*ND
, IdentifierInfo
*II
);
4196 void DeclApplyPragmaWeak(Scope
*S
, NamedDecl
*ND
, WeakInfo
&W
);
4198 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident.
4199 void ActOnPragmaWeakID(IdentifierInfo
* WeakName
,
4200 SourceLocation PragmaLoc
,
4201 SourceLocation WeakNameLoc
);
4203 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
4204 void ActOnPragmaWeakAlias(IdentifierInfo
* WeakName
,
4205 IdentifierInfo
* AliasName
,
4206 SourceLocation PragmaLoc
,
4207 SourceLocation WeakNameLoc
,
4208 SourceLocation AliasNameLoc
);
4210 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
4211 /// a the record decl, to handle '#pragma pack' and '#pragma options align'.
4212 void AddAlignmentAttributesForRecord(RecordDecl
*RD
);
4214 /// FreePackedContext - Deallocate and null out PackContext.
4215 void FreePackedContext();
4217 /// PushNamespaceVisibilityAttr - Note that we've entered a
4218 /// namespace with a visibility attribute.
4219 void PushNamespaceVisibilityAttr(const VisibilityAttr
*Attr
);
4221 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used,
4222 /// add an appropriate visibility attribute.
4223 void AddPushedVisibilityAttribute(Decl
*RD
);
4225 /// PopPragmaVisibility - Pop the top element of the visibility stack; used
4226 /// for '#pragma GCC visibility' and visibility attributes on namespaces.
4227 void PopPragmaVisibility();
4229 /// FreeVisContext - Deallocate and null out VisContext.
4230 void FreeVisContext();
4232 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
4233 void AddAlignedAttr(SourceLocation AttrLoc
, Decl
*D
, Expr
*E
);
4234 void AddAlignedAttr(SourceLocation AttrLoc
, Decl
*D
, TypeSourceInfo
*T
);
4236 /// CastCategory - Get the correct forwarded implicit cast result category
4237 /// from the inner expression.
4238 ExprValueKind
CastCategory(Expr
*E
);
4240 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
4241 /// cast. If there is already an implicit cast, merge into the existing one.
4242 /// If isLvalue, the result of the cast is an lvalue.
4243 void ImpCastExprToType(Expr
*&Expr
, QualType Type
, CastKind CK
,
4244 ExprValueKind VK
= VK_RValue
,
4245 const CXXCastPath
*BasePath
= 0);
4247 /// IgnoredValueConversions - Given that an expression's result is
4248 /// syntactically ignored, perform any conversions that are
4250 void IgnoredValueConversions(Expr
*&expr
);
4252 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
4253 // functions and arrays to their respective pointers (C99 6.3.2.1).
4254 Expr
*UsualUnaryConversions(Expr
*&expr
);
4256 // DefaultFunctionArrayConversion - converts functions and arrays
4257 // to their respective pointers (C99 6.3.2.1).
4258 void DefaultFunctionArrayConversion(Expr
*&expr
);
4260 // DefaultFunctionArrayLvalueConversion - converts functions and
4261 // arrays to their respective pointers and performs the
4262 // lvalue-to-rvalue conversion.
4263 void DefaultFunctionArrayLvalueConversion(Expr
*&expr
);
4265 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
4266 // the operand. This is DefaultFunctionArrayLvalueConversion,
4267 // except that it assumes the operand isn't of function or array
4269 void DefaultLvalueConversion(Expr
*&expr
);
4271 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
4272 // do not have a prototype. Integer promotions are performed on each
4273 // argument, and arguments that have type float are promoted to double.
4274 void DefaultArgumentPromotion(Expr
*&Expr
);
4276 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
4277 enum VariadicCallType
{
4281 VariadicConstructor
,
4282 VariadicDoesNotApply
4285 /// GatherArgumentsForCall - Collector argument expressions for various
4286 /// form of call prototypes.
4287 bool GatherArgumentsForCall(SourceLocation CallLoc
,
4288 FunctionDecl
*FDecl
,
4289 const FunctionProtoType
*Proto
,
4290 unsigned FirstProtoArg
,
4291 Expr
**Args
, unsigned NumArgs
,
4292 llvm::SmallVector
<Expr
*, 8> &AllArgs
,
4293 VariadicCallType CallType
= VariadicDoesNotApply
);
4295 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
4296 // will warn if the resulting type is not a POD type.
4297 bool DefaultVariadicArgumentPromotion(Expr
*&Expr
, VariadicCallType CT
,
4298 FunctionDecl
*FDecl
);
4300 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
4301 // operands and then handles various conversions that are common to binary
4302 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
4303 // routine returns the first non-arithmetic type found. The client is
4304 // responsible for emitting appropriate error diagnostics.
4305 QualType
UsualArithmeticConversions(Expr
*&lExpr
, Expr
*&rExpr
,
4306 bool isCompAssign
= false);
4308 /// AssignConvertType - All of the 'assignment' semantic checks return this
4309 /// enum to indicate whether the assignment was allowed. These checks are
4310 /// done for simple assignments, as well as initialization, return from
4311 /// function, argument passing, etc. The query is phrased in terms of a
4312 /// source and destination type.
4313 enum AssignConvertType
{
4314 /// Compatible - the types are compatible according to the standard.
4317 /// PointerToInt - The assignment converts a pointer to an int, which we
4318 /// accept as an extension.
4321 /// IntToPointer - The assignment converts an int to a pointer, which we
4322 /// accept as an extension.
4325 /// FunctionVoidPointer - The assignment is between a function pointer and
4326 /// void*, which the standard doesn't allow, but we accept as an extension.
4327 FunctionVoidPointer
,
4329 /// IncompatiblePointer - The assignment is between two pointers types that
4330 /// are not compatible, but we accept them as an extension.
4331 IncompatiblePointer
,
4333 /// IncompatiblePointer - The assignment is between two pointers types which
4334 /// point to integers which have a different sign, but are otherwise identical.
4335 /// This is a subset of the above, but broken out because it's by far the most
4336 /// common case of incompatible pointers.
4337 IncompatiblePointerSign
,
4339 /// CompatiblePointerDiscardsQualifiers - The assignment discards
4340 /// c/v/r qualifiers, which we accept as an extension.
4341 CompatiblePointerDiscardsQualifiers
,
4343 /// IncompatibleNestedPointerQualifiers - The assignment is between two
4344 /// nested pointer types, and the qualifiers other than the first two
4345 /// levels differ e.g. char ** -> const char **, but we accept them as an
4347 IncompatibleNestedPointerQualifiers
,
4349 /// IncompatibleVectors - The assignment is between two vector types that
4350 /// have the same size, which we accept as an extension.
4351 IncompatibleVectors
,
4353 /// IntToBlockPointer - The assignment converts an int to a block
4354 /// pointer. We disallow this.
4357 /// IncompatibleBlockPointer - The assignment is between two block
4358 /// pointers types that are not compatible.
4359 IncompatibleBlockPointer
,
4361 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
4362 /// id type and something else (that is incompatible with it). For example,
4363 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
4364 IncompatibleObjCQualifiedId
,
4366 /// Incompatible - We reject this conversion outright, it is invalid to
4367 /// represent it in the AST.
4371 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
4372 /// assignment conversion type specified by ConvTy. This returns true if the
4373 /// conversion was invalid or false if the conversion was accepted.
4374 bool DiagnoseAssignmentResult(AssignConvertType ConvTy
,
4376 QualType DstType
, QualType SrcType
,
4377 Expr
*SrcExpr
, AssignmentAction Action
,
4378 bool *Complained
= 0);
4380 /// CheckAssignmentConstraints - Perform type checking for assignment,
4381 /// argument passing, variable initialization, and function return values.
4383 AssignConvertType
CheckAssignmentConstraints(QualType lhs
, QualType rhs
);
4385 /// Check assignment constraints and prepare for a conversion of the
4386 /// RHS to the LHS type.
4387 AssignConvertType
CheckAssignmentConstraints(QualType lhs
, Expr
*&rhs
,
4390 // CheckSingleAssignmentConstraints - Currently used by
4391 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
4392 // this routine performs the default function/array converions.
4393 AssignConvertType
CheckSingleAssignmentConstraints(QualType lhs
,
4396 // \brief If the lhs type is a transparent union, check whether we
4397 // can initialize the transparent union with the given expression.
4398 AssignConvertType
CheckTransparentUnionArgumentConstraints(QualType lhs
,
4401 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
4402 AssignConvertType
CheckPointerTypesForAssignment(QualType lhsType
,
4405 AssignConvertType
CheckObjCPointerTypesForAssignment(QualType lhsType
,
4408 // Helper function for CheckAssignmentConstraints involving two
4409 // block pointer types.
4410 AssignConvertType
CheckBlockPointerTypesForAssignment(QualType lhsType
,
4413 bool IsStringLiteralToNonConstPointerConversion(Expr
*From
, QualType ToType
);
4415 bool CheckExceptionSpecCompatibility(Expr
*From
, QualType ToType
);
4417 bool PerformImplicitConversion(Expr
*&From
, QualType ToType
,
4418 AssignmentAction Action
,
4419 bool AllowExplicit
= false);
4420 bool PerformImplicitConversion(Expr
*&From
, QualType ToType
,
4421 AssignmentAction Action
,
4423 ImplicitConversionSequence
& ICS
);
4424 bool PerformImplicitConversion(Expr
*&From
, QualType ToType
,
4425 const ImplicitConversionSequence
& ICS
,
4426 AssignmentAction Action
,
4427 bool IgnoreBaseAccess
= false);
4428 bool PerformImplicitConversion(Expr
*&From
, QualType ToType
,
4429 const StandardConversionSequence
& SCS
,
4430 AssignmentAction Action
,bool IgnoreBaseAccess
);
4432 /// the following "Check" methods will return a valid/converted QualType
4433 /// or a null QualType (indicating an error diagnostic was issued).
4435 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
4436 QualType
InvalidOperands(SourceLocation l
, Expr
*&lex
, Expr
*&rex
);
4437 QualType
CheckPointerToMemberOperands( // C++ 5.5
4438 Expr
*&lex
, Expr
*&rex
, ExprValueKind
&VK
,
4439 SourceLocation OpLoc
, bool isIndirect
);
4440 QualType
CheckMultiplyDivideOperands( // C99 6.5.5
4441 Expr
*&lex
, Expr
*&rex
, SourceLocation OpLoc
, bool isCompAssign
,
4443 QualType
CheckRemainderOperands( // C99 6.5.5
4444 Expr
*&lex
, Expr
*&rex
, SourceLocation OpLoc
, bool isCompAssign
= false);
4445 QualType
CheckAdditionOperands( // C99 6.5.6
4446 Expr
*&lex
, Expr
*&rex
, SourceLocation OpLoc
, QualType
* CompLHSTy
= 0);
4447 QualType
CheckSubtractionOperands( // C99 6.5.6
4448 Expr
*&lex
, Expr
*&rex
, SourceLocation OpLoc
, QualType
* CompLHSTy
= 0);
4449 QualType
CheckShiftOperands( // C99 6.5.7
4450 Expr
*&lex
, Expr
*&rex
, SourceLocation OpLoc
, bool isCompAssign
= false);
4451 QualType
CheckCompareOperands( // C99 6.5.8/9
4452 Expr
*&lex
, Expr
*&rex
, SourceLocation OpLoc
, unsigned Opc
,
4454 QualType
CheckBitwiseOperands( // C99 6.5.[10...12]
4455 Expr
*&lex
, Expr
*&rex
, SourceLocation OpLoc
, bool isCompAssign
= false);
4456 QualType
CheckLogicalOperands( // C99 6.5.[13,14]
4457 Expr
*&lex
, Expr
*&rex
, SourceLocation OpLoc
, unsigned Opc
);
4458 // CheckAssignmentOperands is used for both simple and compound assignment.
4459 // For simple assignment, pass both expressions and a null converted type.
4460 // For compound assignment, pass both expressions and the converted type.
4461 QualType
CheckAssignmentOperands( // C99 6.5.16.[1,2]
4462 Expr
*lex
, Expr
*&rex
, SourceLocation OpLoc
, QualType convertedType
);
4464 void ConvertPropertyForRValue(Expr
*&E
);
4465 void ConvertPropertyForLValue(Expr
*&LHS
, Expr
*&RHS
, QualType
& LHSTy
);
4467 QualType
CheckConditionalOperands( // C99 6.5.15
4468 Expr
*&cond
, Expr
*&lhs
, Expr
*&rhs
, Expr
*&save
,
4469 ExprValueKind
&VK
, ExprObjectKind
&OK
, SourceLocation questionLoc
);
4470 QualType
CXXCheckConditionalOperands( // C++ 5.16
4471 Expr
*&cond
, Expr
*&lhs
, Expr
*&rhs
, Expr
*&save
,
4472 ExprValueKind
&VK
, ExprObjectKind
&OK
, SourceLocation questionLoc
);
4473 QualType
FindCompositePointerType(SourceLocation Loc
, Expr
*&E1
, Expr
*&E2
,
4474 bool *NonStandardCompositeType
= 0);
4476 QualType
FindCompositeObjCPointerType(Expr
*&LHS
, Expr
*&RHS
,
4477 SourceLocation questionLoc
);
4479 /// type checking for vector binary operators.
4480 QualType
CheckVectorOperands(SourceLocation l
, Expr
*&lex
, Expr
*&rex
);
4481 QualType
CheckVectorCompareOperands(Expr
*&lex
, Expr
*&rx
,
4482 SourceLocation l
, bool isRel
);
4484 /// type checking declaration initializers (C99 6.7.8)
4485 bool CheckInitList(const InitializedEntity
&Entity
,
4486 InitListExpr
*&InitList
, QualType
&DeclType
);
4487 bool CheckForConstantInitializer(Expr
*e
, QualType t
);
4489 // type checking C++ declaration initializers (C++ [dcl.init]).
4491 /// ReferenceCompareResult - Expresses the result of comparing two
4492 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
4493 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
4494 enum ReferenceCompareResult
{
4495 /// Ref_Incompatible - The two types are incompatible, so direct
4496 /// reference binding is not possible.
4497 Ref_Incompatible
= 0,
4498 /// Ref_Related - The two types are reference-related, which means
4499 /// that their unqualified forms (T1 and T2) are either the same
4500 /// or T1 is a base class of T2.
4502 /// Ref_Compatible_With_Added_Qualification - The two types are
4503 /// reference-compatible with added qualification, meaning that
4504 /// they are reference-compatible and the qualifiers on T1 (cv1)
4505 /// are greater than the qualifiers on T2 (cv2).
4506 Ref_Compatible_With_Added_Qualification
,
4507 /// Ref_Compatible - The two types are reference-compatible and
4508 /// have equivalent qualifiers (cv1 == cv2).
4512 ReferenceCompareResult
CompareReferenceRelationship(SourceLocation Loc
,
4513 QualType T1
, QualType T2
,
4514 bool &DerivedToBase
,
4515 bool &ObjCConversion
);
4517 /// CheckCastTypes - Check type constraints for casting between types under
4518 /// C semantics, or forward to CXXCheckCStyleCast in C++.
4519 bool CheckCastTypes(SourceRange TyRange
, QualType CastTy
, Expr
*&CastExpr
,
4520 CastKind
&Kind
, ExprValueKind
&VK
, CXXCastPath
&BasePath
,
4521 bool FunctionalStyle
= false);
4523 // CheckVectorCast - check type constraints for vectors.
4524 // Since vectors are an extension, there are no C standard reference for this.
4525 // We allow casting between vectors and integer datatypes of the same size.
4526 // returns true if the cast is invalid
4527 bool CheckVectorCast(SourceRange R
, QualType VectorTy
, QualType Ty
,
4530 // CheckExtVectorCast - check type constraints for extended vectors.
4531 // Since vectors are an extension, there are no C standard reference for this.
4532 // We allow casting between vectors and integer datatypes of the same size,
4533 // or vectors and the element type of that vector.
4534 // returns true if the cast is invalid
4535 bool CheckExtVectorCast(SourceRange R
, QualType VectorTy
, Expr
*&CastExpr
,
4538 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style
4539 /// cast under C++ semantics.
4540 bool CXXCheckCStyleCast(SourceRange R
, QualType CastTy
, ExprValueKind
&VK
,
4541 Expr
*&CastExpr
, CastKind
&Kind
,
4542 CXXCastPath
&BasePath
, bool FunctionalStyle
);
4544 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
4545 /// \param Method - May be null.
4546 /// \param [out] ReturnType - The return type of the send.
4547 /// \return true iff there were any incompatible types.
4548 bool CheckMessageArgumentTypes(Expr
**Args
, unsigned NumArgs
, Selector Sel
,
4549 ObjCMethodDecl
*Method
, bool isClassMessage
,
4550 SourceLocation lbrac
, SourceLocation rbrac
,
4551 QualType
&ReturnType
, ExprValueKind
&VK
);
4553 /// CheckBooleanCondition - Diagnose problems involving the use of
4554 /// the given expression as a boolean condition (e.g. in an if
4555 /// statement). Also performs the standard function and array
4556 /// decays, possibly changing the input variable.
4558 /// \param Loc - A location associated with the condition, e.g. the
4560 /// \return true iff there were any errors
4561 bool CheckBooleanCondition(Expr
*&CondExpr
, SourceLocation Loc
);
4563 ExprResult
ActOnBooleanCondition(Scope
*S
, SourceLocation Loc
,
4566 /// DiagnoseAssignmentAsCondition - Given that an expression is
4567 /// being used as a boolean condition, warn if it's an assignment.
4568 void DiagnoseAssignmentAsCondition(Expr
*E
);
4570 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
4571 bool CheckCXXBooleanCondition(Expr
*&CondExpr
);
4573 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
4574 /// the specified width and sign. If an overflow occurs, detect it and emit
4575 /// the specified diagnostic.
4576 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt
&OldVal
,
4577 unsigned NewWidth
, bool NewSign
,
4578 SourceLocation Loc
, unsigned DiagID
);
4580 /// Checks that the Objective-C declaration is declared in the global scope.
4581 /// Emits an error and marks the declaration as invalid if it's not declared
4582 /// in the global scope.
4583 bool CheckObjCDeclScope(Decl
*D
);
4585 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
4586 /// and reports the appropriate diagnostics. Returns false on success.
4587 /// Can optionally return the value of the expression.
4588 bool VerifyIntegerConstantExpression(const Expr
*E
, llvm::APSInt
*Result
= 0);
4590 /// VerifyBitField - verifies that a bit field expression is an ICE and has
4591 /// the correct width, and that the field type is valid.
4592 /// Returns false on success.
4593 /// Can optionally return whether the bit-field is of width 0
4594 bool VerifyBitField(SourceLocation FieldLoc
, IdentifierInfo
*FieldName
,
4595 QualType FieldTy
, const Expr
*BitWidth
,
4596 bool *ZeroWidth
= 0);
4598 /// \name Code completion
4600 /// \brief Describes the context in which code completion occurs.
4601 enum ParserCompletionContext
{
4602 /// \brief Code completion occurs at top-level or namespace context.
4604 /// \brief Code completion occurs within a class, struct, or union.
4606 /// \brief Code completion occurs within an Objective-C interface, protocol,
4609 /// \brief Code completion occurs within an Objective-C implementation or
4610 /// category implementation
4611 PCC_ObjCImplementation
,
4612 /// \brief Code completion occurs within the list of instance variables
4613 /// in an Objective-C interface, protocol, category, or implementation.
4614 PCC_ObjCInstanceVariableList
,
4615 /// \brief Code completion occurs following one or more template
4618 /// \brief Code completion occurs following one or more template
4619 /// headers within a class.
4621 /// \brief Code completion occurs within an expression.
4623 /// \brief Code completion occurs within a statement, which may
4624 /// also be an expression or a declaration.
4626 /// \brief Code completion occurs at the beginning of the
4627 /// initialization statement (or expression) in a for loop.
4629 /// \brief Code completion occurs within the condition of an if,
4630 /// while, switch, or for statement.
4632 /// \brief Code completion occurs within the body of a function on a
4633 /// recovery path, where we do not have a specific handle on our position
4635 PCC_RecoveryInFunction
,
4636 /// \brief Code completion occurs where only a type is permitted.
4638 /// \brief Code completion occurs in a parenthesized expression, which
4639 /// might also be a type cast.
4640 PCC_ParenthesizedExpression
4643 void CodeCompleteOrdinaryName(Scope
*S
,
4644 ParserCompletionContext CompletionContext
);
4645 void CodeCompleteDeclSpec(Scope
*S
, DeclSpec
&DS
,
4646 bool AllowNonIdentifiers
,
4647 bool AllowNestedNameSpecifiers
);
4649 struct CodeCompleteExpressionData
;
4650 void CodeCompleteExpression(Scope
*S
,
4651 const CodeCompleteExpressionData
&Data
);
4652 void CodeCompleteMemberReferenceExpr(Scope
*S
, Expr
*Base
,
4653 SourceLocation OpLoc
,
4655 void CodeCompletePostfixExpression(Scope
*S
, ExprResult LHS
);
4656 void CodeCompleteTag(Scope
*S
, unsigned TagSpec
);
4657 void CodeCompleteTypeQualifiers(DeclSpec
&DS
);
4658 void CodeCompleteCase(Scope
*S
);
4659 void CodeCompleteCall(Scope
*S
, Expr
*Fn
, Expr
**Args
, unsigned NumArgs
);
4660 void CodeCompleteInitializer(Scope
*S
, Decl
*D
);
4661 void CodeCompleteReturn(Scope
*S
);
4662 void CodeCompleteAssignmentRHS(Scope
*S
, Expr
*LHS
);
4664 void CodeCompleteQualifiedId(Scope
*S
, CXXScopeSpec
&SS
,
4665 bool EnteringContext
);
4666 void CodeCompleteUsing(Scope
*S
);
4667 void CodeCompleteUsingDirective(Scope
*S
);
4668 void CodeCompleteNamespaceDecl(Scope
*S
);
4669 void CodeCompleteNamespaceAliasDecl(Scope
*S
);
4670 void CodeCompleteOperatorName(Scope
*S
);
4671 void CodeCompleteConstructorInitializer(Decl
*Constructor
,
4672 CXXBaseOrMemberInitializer
** Initializers
,
4673 unsigned NumInitializers
);
4675 void CodeCompleteObjCAtDirective(Scope
*S
, Decl
*ObjCImpDecl
,
4677 void CodeCompleteObjCAtVisibility(Scope
*S
);
4678 void CodeCompleteObjCAtStatement(Scope
*S
);
4679 void CodeCompleteObjCAtExpression(Scope
*S
);
4680 void CodeCompleteObjCPropertyFlags(Scope
*S
, ObjCDeclSpec
&ODS
);
4681 void CodeCompleteObjCPropertyGetter(Scope
*S
, Decl
*ClassDecl
);
4682 void CodeCompleteObjCPropertySetter(Scope
*S
, Decl
*ClassDecl
);
4683 void CodeCompleteObjCPassingType(Scope
*S
, ObjCDeclSpec
&DS
);
4684 void CodeCompleteObjCMessageReceiver(Scope
*S
);
4685 void CodeCompleteObjCSuperMessage(Scope
*S
, SourceLocation SuperLoc
,
4686 IdentifierInfo
**SelIdents
,
4687 unsigned NumSelIdents
,
4688 bool AtArgumentExpression
);
4689 void CodeCompleteObjCClassMessage(Scope
*S
, ParsedType Receiver
,
4690 IdentifierInfo
**SelIdents
,
4691 unsigned NumSelIdents
,
4692 bool AtArgumentExpression
,
4693 bool IsSuper
= false);
4694 void CodeCompleteObjCInstanceMessage(Scope
*S
, ExprTy
*Receiver
,
4695 IdentifierInfo
**SelIdents
,
4696 unsigned NumSelIdents
,
4697 bool AtArgumentExpression
,
4698 ObjCInterfaceDecl
*Super
= 0);
4699 void CodeCompleteObjCForCollection(Scope
*S
,
4700 DeclGroupPtrTy IterationVar
);
4701 void CodeCompleteObjCSelector(Scope
*S
,
4702 IdentifierInfo
**SelIdents
,
4703 unsigned NumSelIdents
);
4704 void CodeCompleteObjCProtocolReferences(IdentifierLocPair
*Protocols
,
4705 unsigned NumProtocols
);
4706 void CodeCompleteObjCProtocolDecl(Scope
*S
);
4707 void CodeCompleteObjCInterfaceDecl(Scope
*S
);
4708 void CodeCompleteObjCSuperclass(Scope
*S
,
4709 IdentifierInfo
*ClassName
,
4710 SourceLocation ClassNameLoc
);
4711 void CodeCompleteObjCImplementationDecl(Scope
*S
);
4712 void CodeCompleteObjCInterfaceCategory(Scope
*S
,
4713 IdentifierInfo
*ClassName
,
4714 SourceLocation ClassNameLoc
);
4715 void CodeCompleteObjCImplementationCategory(Scope
*S
,
4716 IdentifierInfo
*ClassName
,
4717 SourceLocation ClassNameLoc
);
4718 void CodeCompleteObjCPropertyDefinition(Scope
*S
, Decl
*ObjCImpDecl
);
4719 void CodeCompleteObjCPropertySynthesizeIvar(Scope
*S
,
4720 IdentifierInfo
*PropertyName
,
4722 void CodeCompleteObjCMethodDecl(Scope
*S
,
4723 bool IsInstanceMethod
,
4724 ParsedType ReturnType
,
4726 void CodeCompleteObjCMethodDeclSelector(Scope
*S
,
4727 bool IsInstanceMethod
,
4728 bool AtParameterName
,
4729 ParsedType ReturnType
,
4730 IdentifierInfo
**SelIdents
,
4731 unsigned NumSelIdents
);
4732 void CodeCompletePreprocessorDirective(bool InConditional
);
4733 void CodeCompleteInPreprocessorConditionalExclusion(Scope
*S
);
4734 void CodeCompletePreprocessorMacroName(bool IsDefinition
);
4735 void CodeCompletePreprocessorExpression();
4736 void CodeCompletePreprocessorMacroArgument(Scope
*S
,
4737 IdentifierInfo
*Macro
,
4738 MacroInfo
*MacroInfo
,
4740 void CodeCompleteNaturalLanguage();
4741 void GatherGlobalCodeCompletions(
4742 llvm::SmallVectorImpl
<CodeCompletionResult
> &Results
);
4745 void PrintStats() const {}
4747 //===--------------------------------------------------------------------===//
4748 // Extra semantic analysis beyond the C type system
4751 SourceLocation
getLocationOfStringLiteralByte(const StringLiteral
*SL
,
4752 unsigned ByteNo
) const;
4755 bool CheckFunctionCall(FunctionDecl
*FDecl
, CallExpr
*TheCall
);
4756 bool CheckBlockCall(NamedDecl
*NDecl
, CallExpr
*TheCall
);
4758 bool CheckablePrintfAttr(const FormatAttr
*Format
, CallExpr
*TheCall
);
4759 bool CheckObjCString(Expr
*Arg
);
4761 ExprResult
CheckBuiltinFunctionCall(unsigned BuiltinID
, CallExpr
*TheCall
);
4762 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID
, CallExpr
*TheCall
);
4764 bool SemaBuiltinVAStart(CallExpr
*TheCall
);
4765 bool SemaBuiltinUnorderedCompare(CallExpr
*TheCall
);
4766 bool SemaBuiltinFPClassification(CallExpr
*TheCall
, unsigned NumArgs
);
4769 // Used by C++ template instantiation.
4770 ExprResult
SemaBuiltinShuffleVector(CallExpr
*TheCall
);
4773 bool SemaBuiltinPrefetch(CallExpr
*TheCall
);
4774 bool SemaBuiltinObjectSize(CallExpr
*TheCall
);
4775 bool SemaBuiltinLongjmp(CallExpr
*TheCall
);
4776 ExprResult
SemaBuiltinAtomicOverloaded(ExprResult TheCallResult
);
4777 bool SemaBuiltinConstantArg(CallExpr
*TheCall
, int ArgNum
,
4778 llvm::APSInt
&Result
);
4780 bool SemaCheckStringLiteral(const Expr
*E
, const CallExpr
*TheCall
,
4781 bool HasVAListArg
, unsigned format_idx
,
4782 unsigned firstDataArg
, bool isPrintf
);
4784 void CheckFormatString(const StringLiteral
*FExpr
, const Expr
*OrigFormatExpr
,
4785 const CallExpr
*TheCall
, bool HasVAListArg
,
4786 unsigned format_idx
, unsigned firstDataArg
,
4789 void CheckNonNullArguments(const NonNullAttr
*NonNull
,
4790 const CallExpr
*TheCall
);
4792 void CheckPrintfScanfArguments(const CallExpr
*TheCall
, bool HasVAListArg
,
4793 unsigned format_idx
, unsigned firstDataArg
,
4796 void CheckReturnStackAddr(Expr
*RetValExp
, QualType lhsType
,
4797 SourceLocation ReturnLoc
);
4798 void CheckFloatComparison(SourceLocation loc
, Expr
* lex
, Expr
* rex
);
4799 void CheckImplicitConversions(Expr
*E
, SourceLocation CC
= SourceLocation());
4801 void CheckBitFieldInitialization(SourceLocation InitLoc
, FieldDecl
*Field
,
4804 /// \brief The parser's current scope.
4806 /// The parser maintains this state here.
4810 friend class Parser
;
4811 friend class InitializationSequence
;
4813 /// \brief Retrieve the parser's current scope.
4814 Scope
*getCurScope() const { return CurScope
; }
4817 /// \brief RAII object that enters a new expression evaluation context.
4818 class EnterExpressionEvaluationContext
{
4822 EnterExpressionEvaluationContext(Sema
&Actions
,
4823 Sema::ExpressionEvaluationContext NewContext
)
4824 : Actions(Actions
) {
4825 Actions
.PushExpressionEvaluationContext(NewContext
);
4828 ~EnterExpressionEvaluationContext() {
4829 Actions
.PopExpressionEvaluationContext();
4833 } // end namespace clang