-Rename -Wargument-larger-than -> -Wlarge-by-value-copy
[clang.git] / include / clang / Sema / Sema.h
blobaac36bb155815908d86c771ef94a9e7be1388402
1 //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the Sema class, which performs semantic analysis and
11 // builds ASTs.
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"
32 #include <deque>
33 #include <string>
35 namespace llvm {
36 class APSInt;
37 template <typename ValueT> struct DenseMapInfo;
38 template <typename ValueT, typename ValueInfoT> class DenseSet;
41 namespace clang {
42 class ADLResult;
43 class ASTConsumer;
44 class ASTContext;
45 class ArrayType;
46 class AttributeList;
47 class BlockDecl;
48 class CXXBasePath;
49 class CXXBasePaths;
50 typedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
51 class CXXConstructorDecl;
52 class CXXConversionDecl;
53 class CXXDestructorDecl;
54 class CXXFieldCollector;
55 class CXXMemberCallExpr;
56 class CXXMethodDecl;
57 class CXXScopeSpec;
58 class CXXTemporary;
59 class CXXTryStmt;
60 class CallExpr;
61 class ClassTemplateDecl;
62 class ClassTemplatePartialSpecializationDecl;
63 class ClassTemplateSpecializationDecl;
64 class CodeCompleteConsumer;
65 class CodeCompletionResult;
66 class Decl;
67 class DeclAccessPair;
68 class DeclContext;
69 class DeclRefExpr;
70 class DeclaratorDecl;
71 class DeducedTemplateArgument;
72 class DependentDiagnostic;
73 class DesignatedInitExpr;
74 class Designation;
75 class EnumConstantDecl;
76 class Expr;
77 class ExtVectorType;
78 class ExternalSemaSource;
79 class FormatAttr;
80 class FriendDecl;
81 class FullExpr;
82 class FunctionDecl;
83 class FunctionProtoType;
84 class FunctionTemplateDecl;
85 class ImplicitConversionSequence;
86 class InitListExpr;
87 class InitializationKind;
88 class InitializationSequence;
89 class InitializedEntity;
90 class IntegerLiteral;
91 class LabelStmt;
92 class LangOptions;
93 class LocalInstantiationScope;
94 class LookupResult;
95 class MacroInfo;
96 class MultiLevelTemplateArgumentList;
97 class NamedDecl;
98 class NonNullAttr;
99 class ObjCCategoryDecl;
100 class ObjCCategoryImplDecl;
101 class ObjCCompatibleAliasDecl;
102 class ObjCContainerDecl;
103 class ObjCImplDecl;
104 class ObjCImplementationDecl;
105 class ObjCInterfaceDecl;
106 class ObjCIvarDecl;
107 template <class T> class ObjCList;
108 class ObjCMethodDecl;
109 class ObjCPropertyDecl;
110 class ObjCProtocolDecl;
111 class OverloadCandidateSet;
112 class ParenListExpr;
113 class ParmVarDecl;
114 class Preprocessor;
115 class PseudoDestructorTypeStorage;
116 class QualType;
117 class StandardConversionSequence;
118 class Stmt;
119 class StringLiteral;
120 class SwitchStmt;
121 class TargetAttributesSema;
122 class TemplateArgument;
123 class TemplateArgumentList;
124 class TemplateArgumentLoc;
125 class TemplateDecl;
126 class TemplateParameterList;
127 class TemplatePartialOrderingContext;
128 class TemplateTemplateParmDecl;
129 class Token;
130 class TypedefDecl;
131 class UnqualifiedId;
132 class UnresolvedLookupExpr;
133 class UnresolvedMemberExpr;
134 class UnresolvedSetImpl;
135 class UnresolvedSetIterator;
136 class UsingDecl;
137 class UsingShadowDecl;
138 class ValueDecl;
139 class VarDecl;
140 class VisibilityAttr;
141 class VisibleDeclConsumer;
143 namespace sema {
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
152 /// parsing.
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 {
158 enum {
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()), DeclInfo(TInfo) {
169 assert(getTypeClass() == (TypeClass)LocInfo && "LocInfo didn't fit in TC?");
171 friend class Sema;
173 public:
174 QualType getType() const { return getCanonicalTypeInternal(); }
175 TypeSourceInfo *getTypeSourceInfo() const { return DeclInfo; }
177 void getAsStringInternal(std::string &Str,
178 const PrintingPolicy &Policy) const;
180 static bool classof(const Type *T) {
181 return T->getTypeClass() == (TypeClass)LocInfo;
183 static bool classof(const LocInfoType *) { return true; }
186 /// Sema - This implements semantic analysis and AST building for C.
187 class Sema {
188 Sema(const Sema&); // DO NOT IMPLEMENT
189 void operator=(const Sema&); // DO NOT IMPLEMENT
190 mutable const TargetAttributesSema* TheTargetAttributesSema;
191 public:
192 typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
193 typedef OpaquePtr<TemplateName> TemplateTy;
194 typedef OpaquePtr<QualType> TypeTy;
195 typedef Attr AttrTy;
196 typedef CXXBaseSpecifier BaseTy;
197 typedef CXXBaseOrMemberInitializer MemInitTy;
198 typedef Expr ExprTy;
199 typedef Stmt StmtTy;
200 typedef TemplateParameterList TemplateParamsTy;
201 typedef NestedNameSpecifier CXXScopeTy;
203 const LangOptions &LangOpts;
204 Preprocessor &PP;
205 ASTContext &Context;
206 ASTConsumer &Consumer;
207 Diagnostic &Diags;
208 SourceManager &SourceMgr;
210 /// \brief Source of additional semantic information.
211 ExternalSemaSource *ExternalSource;
213 /// \brief Code-completion consumer.
214 CodeCompleteConsumer *CodeCompleter;
216 /// CurContext - This is the current declaration context of parsing.
217 DeclContext *CurContext;
219 /// VAListTagName - The declaration name corresponding to __va_list_tag.
220 /// This is used as part of a hack to omit that class from ADL results.
221 DeclarationName VAListTagName;
223 /// A RAII object to temporarily push a declaration context.
224 class ContextRAII {
225 private:
226 Sema &S;
227 DeclContext *SavedContext;
229 public:
230 ContextRAII(Sema &S, DeclContext *ContextToPush)
231 : S(S), SavedContext(S.CurContext) {
232 assert(ContextToPush && "pushing null context");
233 S.CurContext = ContextToPush;
236 void pop() {
237 if (!SavedContext) return;
238 S.CurContext = SavedContext;
239 SavedContext = 0;
242 ~ContextRAII() {
243 pop();
247 /// PackContext - Manages the stack for #pragma pack. An alignment
248 /// of 0 indicates default alignment.
249 void *PackContext; // Really a "PragmaPackStack*"
251 /// VisContext - Manages the stack for #pragma GCC visibility.
252 void *VisContext; // Really a "PragmaVisStack*"
254 /// \brief Stack containing information about each of the nested
255 /// function, block, and method scopes that are currently active.
257 /// This array is never empty. Clients should ignore the first
258 /// element, which is used to cache a single FunctionScopeInfo
259 /// that's used to parse every top-level function.
260 llvm::SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes;
262 /// ExprTemporaries - This is the stack of temporaries that are created by
263 /// the current full expression.
264 llvm::SmallVector<CXXTemporary*, 8> ExprTemporaries;
266 /// ExtVectorDecls - This is a list all the extended vector types. This allows
267 /// us to associate a raw vector type with one of the ext_vector type names.
268 /// This is only necessary for issuing pretty diagnostics.
269 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
271 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
272 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
274 typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
276 /// PureVirtualClassDiagSet - a set of class declarations which we have
277 /// emitted a list of pure virtual functions. Used to prevent emitting the
278 /// same list more than once.
279 llvm::OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet;
281 /// \brief A mapping from external names to the most recent
282 /// locally-scoped external declaration with that name.
284 /// This map contains external declarations introduced in local
285 /// scoped, e.g.,
287 /// \code
288 /// void f() {
289 /// void foo(int, int);
290 /// }
291 /// \endcode
293 /// Here, the name "foo" will be associated with the declaration on
294 /// "foo" within f. This name is not visible outside of
295 /// "f". However, we still find it in two cases:
297 /// - If we are declaring another external with the name "foo", we
298 /// can find "foo" as a previous declaration, so that the types
299 /// of this external declaration can be checked for
300 /// compatibility.
302 /// - If we would implicitly declare "foo" (e.g., due to a call to
303 /// "foo" in C when no prototype or definition is visible), then
304 /// we find this declaration of "foo" and complain that it is
305 /// not visible.
306 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
308 /// \brief All the tentative definitions encountered in the TU.
309 llvm::SmallVector<VarDecl *, 2> TentativeDefinitions;
311 /// \brief The set of file scoped decls seen so far that have not been used
312 /// and must warn if not used. Only contains the first declaration.
313 llvm::SmallVector<const DeclaratorDecl*, 4> UnusedFileScopedDecls;
315 /// \brief The stack of diagnostics that were delayed due to being
316 /// produced during the parsing of a declaration.
317 llvm::SmallVector<sema::DelayedDiagnostic, 0> DelayedDiagnostics;
319 /// \brief The depth of the current ParsingDeclaration stack.
320 /// If nonzero, we are currently parsing a declaration (and
321 /// hence should delay deprecation warnings).
322 unsigned ParsingDeclDepth;
324 /// WeakUndeclaredIdentifiers - Identifiers contained in
325 /// #pragma weak before declared. rare. may alias another
326 /// identifier, declared or undeclared
327 class WeakInfo {
328 IdentifierInfo *alias; // alias (optional)
329 SourceLocation loc; // for diagnostics
330 bool used; // identifier later declared?
331 public:
332 WeakInfo()
333 : alias(0), loc(SourceLocation()), used(false) {}
334 WeakInfo(IdentifierInfo *Alias, SourceLocation Loc)
335 : alias(Alias), loc(Loc), used(false) {}
336 inline IdentifierInfo * getAlias() const { return alias; }
337 inline SourceLocation getLocation() const { return loc; }
338 void setUsed(bool Used=true) { used = Used; }
339 inline bool getUsed() { return used; }
340 bool operator==(WeakInfo RHS) const {
341 return alias == RHS.getAlias() && loc == RHS.getLocation();
343 bool operator!=(WeakInfo RHS) const { return !(*this == RHS); }
345 llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
347 /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
348 /// #pragma weak during processing of other Decls.
349 /// I couldn't figure out a clean way to generate these in-line, so
350 /// we store them here and handle separately -- which is a hack.
351 /// It would be best to refactor this.
352 llvm::SmallVector<Decl*,2> WeakTopLevelDecl;
354 IdentifierResolver IdResolver;
356 /// Translation Unit Scope - useful to Objective-C actions that need
357 /// to lookup file scope declarations in the "ordinary" C decl namespace.
358 /// For example, user-defined classes, built-in "id" type, etc.
359 Scope *TUScope;
361 /// \brief The C++ "std" namespace, where the standard library resides.
362 LazyDeclPtr StdNamespace;
364 /// \brief The C++ "std::bad_alloc" class, which is defined by the C++
365 /// standard library.
366 LazyDeclPtr StdBadAlloc;
368 /// \brief The C++ "type_info" declaration, which is defined in <typeinfo>.
369 RecordDecl *CXXTypeInfoDecl;
371 /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files.
372 RecordDecl *MSVCGuidDecl;
374 /// A flag to remember whether the implicit forms of operator new and delete
375 /// have been declared.
376 bool GlobalNewDeleteDeclared;
378 /// \brief The set of declarations that have been referenced within
379 /// a potentially evaluated expression.
380 typedef llvm::SmallVector<std::pair<SourceLocation, Decl *>, 10>
381 PotentiallyReferencedDecls;
383 /// \brief A set of diagnostics that may be emitted.
384 typedef llvm::SmallVector<std::pair<SourceLocation, PartialDiagnostic>, 10>
385 PotentiallyEmittedDiagnostics;
387 /// \brief Describes how the expressions currently being parsed are
388 /// evaluated at run-time, if at all.
389 enum ExpressionEvaluationContext {
390 /// \brief The current expression and its subexpressions occur within an
391 /// unevaluated operand (C++0x [expr]p8), such as a constant expression
392 /// or the subexpression of \c sizeof, where the type or the value of the
393 /// expression may be significant but no code will be generated to evaluate
394 /// the value of the expression at run time.
395 Unevaluated,
397 /// \brief The current expression is potentially evaluated at run time,
398 /// which means that code may be generated to evaluate the value of the
399 /// expression at run time.
400 PotentiallyEvaluated,
402 /// \brief The current expression may be potentially evaluated or it may
403 /// be unevaluated, but it is impossible to tell from the lexical context.
404 /// This evaluation context is used primary for the operand of the C++
405 /// \c typeid expression, whose argument is potentially evaluated only when
406 /// it is an lvalue of polymorphic class type (C++ [basic.def.odr]p2).
407 PotentiallyPotentiallyEvaluated,
409 /// \brief The current expression is potentially evaluated, but any
410 /// declarations referenced inside that expression are only used if
411 /// in fact the current expression is used.
413 /// This value is used when parsing default function arguments, for which
414 /// we would like to provide diagnostics (e.g., passing non-POD arguments
415 /// through varargs) but do not want to mark declarations as "referenced"
416 /// until the default argument is used.
417 PotentiallyEvaluatedIfUsed
420 /// \brief Data structure used to record current or nested
421 /// expression evaluation contexts.
422 struct ExpressionEvaluationContextRecord {
423 /// \brief The expression evaluation context.
424 ExpressionEvaluationContext Context;
426 /// \brief The number of temporaries that were active when we
427 /// entered this expression evaluation context.
428 unsigned NumTemporaries;
430 /// \brief The set of declarations referenced within a
431 /// potentially potentially-evaluated context.
433 /// When leaving a potentially potentially-evaluated context, each
434 /// of these elements will be as referenced if the corresponding
435 /// potentially potentially evaluated expression is potentially
436 /// evaluated.
437 PotentiallyReferencedDecls *PotentiallyReferenced;
439 /// \brief The set of diagnostics to emit should this potentially
440 /// potentially-evaluated context become evaluated.
441 PotentiallyEmittedDiagnostics *PotentiallyDiagnosed;
443 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
444 unsigned NumTemporaries)
445 : Context(Context), NumTemporaries(NumTemporaries),
446 PotentiallyReferenced(0), PotentiallyDiagnosed(0) { }
448 void addReferencedDecl(SourceLocation Loc, Decl *Decl) {
449 if (!PotentiallyReferenced)
450 PotentiallyReferenced = new PotentiallyReferencedDecls;
451 PotentiallyReferenced->push_back(std::make_pair(Loc, Decl));
454 void addDiagnostic(SourceLocation Loc, const PartialDiagnostic &PD) {
455 if (!PotentiallyDiagnosed)
456 PotentiallyDiagnosed = new PotentiallyEmittedDiagnostics;
457 PotentiallyDiagnosed->push_back(std::make_pair(Loc, PD));
460 void Destroy() {
461 delete PotentiallyReferenced;
462 delete PotentiallyDiagnosed;
463 PotentiallyReferenced = 0;
464 PotentiallyDiagnosed = 0;
468 /// A stack of expression evaluation contexts.
469 llvm::SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
471 /// \brief Whether the code handled by Sema should be considered a
472 /// complete translation unit or not.
474 /// When true (which is generally the case), Sema will perform
475 /// end-of-translation-unit semantic tasks (such as creating
476 /// initializers for tentative definitions in C) once parsing has
477 /// completed. This flag will be false when building PCH files,
478 /// since a PCH file is by definition not a complete translation
479 /// unit.
480 bool CompleteTranslationUnit;
482 llvm::BumpPtrAllocator BumpAlloc;
484 /// \brief The number of SFINAE diagnostics that have been trapped.
485 unsigned NumSFINAEErrors;
487 typedef llvm::DenseMap<ParmVarDecl *, llvm::SmallVector<ParmVarDecl *, 1> >
488 UnparsedDefaultArgInstantiationsMap;
490 /// \brief A mapping from parameters with unparsed default arguments to the
491 /// set of instantiations of each parameter.
493 /// This mapping is a temporary data structure used when parsing
494 /// nested class templates or nested classes of class templates,
495 /// where we might end up instantiating an inner class before the
496 /// default arguments of its methods have been parsed.
497 UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations;
499 // Contains the locations of the beginning of unparsed default
500 // argument locations.
501 llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs;
503 typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods;
504 typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool;
506 /// Method Pool - allows efficient lookup when typechecking messages to "id".
507 /// We need to maintain a list, since selectors can have differing signatures
508 /// across classes. In Cocoa, this happens to be extremely uncommon (only 1%
509 /// of selectors are "overloaded").
510 GlobalMethodPool MethodPool;
512 /// Method selectors used in a @selector expression. Used for implementation
513 /// of -Wselector.
514 llvm::DenseMap<Selector, SourceLocation> ReferencedSelectors;
516 GlobalMethodPool::iterator ReadMethodPool(Selector Sel);
518 /// Private Helper predicate to check for 'self'.
519 bool isSelfExpr(Expr *RExpr);
520 public:
521 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
522 bool CompleteTranslationUnit = true,
523 CodeCompleteConsumer *CompletionConsumer = 0);
524 ~Sema();
526 /// \brief Perform initialization that occurs after the parser has been
527 /// initialized but before it parses anything.
528 void Initialize();
530 const LangOptions &getLangOptions() const { return LangOpts; }
531 Diagnostic &getDiagnostics() const { return Diags; }
532 SourceManager &getSourceManager() const { return SourceMgr; }
533 const TargetAttributesSema &getTargetAttributesSema() const;
534 Preprocessor &getPreprocessor() const { return PP; }
535 ASTContext &getASTContext() const { return Context; }
536 ASTConsumer &getASTConsumer() const { return Consumer; }
538 /// \brief Helper class that creates diagnostics with optional
539 /// template instantiation stacks.
541 /// This class provides a wrapper around the basic DiagnosticBuilder
542 /// class that emits diagnostics. SemaDiagnosticBuilder is
543 /// responsible for emitting the diagnostic (as DiagnosticBuilder
544 /// does) and, if the diagnostic comes from inside a template
545 /// instantiation, printing the template instantiation stack as
546 /// well.
547 class SemaDiagnosticBuilder : public DiagnosticBuilder {
548 Sema &SemaRef;
549 unsigned DiagID;
551 public:
552 SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
553 : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
555 explicit SemaDiagnosticBuilder(Sema &SemaRef)
556 : DiagnosticBuilder(DiagnosticBuilder::Suppress), SemaRef(SemaRef) { }
558 ~SemaDiagnosticBuilder();
561 /// \brief Emit a diagnostic.
562 SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
564 /// \brief Emit a partial diagnostic.
565 SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD);
567 /// \brief Build a partial diagnostic.
568 PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
570 ExprResult Owned(Expr* E) { return E; }
571 ExprResult Owned(ExprResult R) { return R; }
572 StmtResult Owned(Stmt* S) { return S; }
574 void ActOnEndOfTranslationUnit();
576 Scope *getScopeForContext(DeclContext *Ctx);
578 void PushFunctionScope();
579 void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
580 void PopFunctionOrBlockScope();
582 sema::FunctionScopeInfo *getCurFunction() const {
583 return FunctionScopes.back();
586 bool hasAnyErrorsInThisFunction() const;
588 /// \brief Retrieve the current block, if any.
589 sema::BlockScopeInfo *getCurBlock();
591 /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls
592 llvm::SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
594 //===--------------------------------------------------------------------===//
595 // Type Analysis / Processing: SemaType.cpp.
598 QualType adjustParameterType(QualType T);
599 QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs);
600 QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVR) {
601 return BuildQualifiedType(T, Loc, Qualifiers::fromCVRMask(CVR));
603 QualType BuildPointerType(QualType T,
604 SourceLocation Loc, DeclarationName Entity);
605 QualType BuildReferenceType(QualType T, bool LValueRef,
606 SourceLocation Loc, DeclarationName Entity);
607 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
608 Expr *ArraySize, unsigned Quals,
609 SourceRange Brackets, DeclarationName Entity);
610 QualType BuildExtVectorType(QualType T, Expr *ArraySize,
611 SourceLocation AttrLoc);
612 QualType BuildFunctionType(QualType T,
613 QualType *ParamTypes, unsigned NumParamTypes,
614 bool Variadic, unsigned Quals,
615 SourceLocation Loc, DeclarationName Entity,
616 const FunctionType::ExtInfo &Info);
617 QualType BuildMemberPointerType(QualType T, QualType Class,
618 SourceLocation Loc,
619 DeclarationName Entity);
620 QualType BuildBlockPointerType(QualType T,
621 SourceLocation Loc, DeclarationName Entity);
622 TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S,
623 TagDecl **OwnedDecl = 0);
624 TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
625 TypeSourceInfo *ReturnTypeInfo);
626 /// \brief Package the given type and TSI into a ParsedType.
627 ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
628 DeclarationNameInfo GetNameForDeclarator(Declarator &D);
629 DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
630 static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0);
631 bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range);
632 bool CheckDistantExceptionSpec(QualType T);
633 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
634 bool CheckEquivalentExceptionSpec(
635 const FunctionProtoType *Old, SourceLocation OldLoc,
636 const FunctionProtoType *New, SourceLocation NewLoc);
637 bool CheckEquivalentExceptionSpec(
638 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
639 const FunctionProtoType *Old, SourceLocation OldLoc,
640 const FunctionProtoType *New, SourceLocation NewLoc,
641 bool *MissingExceptionSpecification = 0,
642 bool *MissingEmptyExceptionSpecification = 0);
643 bool CheckExceptionSpecSubset(
644 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
645 const FunctionProtoType *Superset, SourceLocation SuperLoc,
646 const FunctionProtoType *Subset, SourceLocation SubLoc);
647 bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
648 const FunctionProtoType *Target, SourceLocation TargetLoc,
649 const FunctionProtoType *Source, SourceLocation SourceLoc);
651 TypeResult ActOnTypeName(Scope *S, Declarator &D);
653 bool RequireCompleteType(SourceLocation Loc, QualType T,
654 const PartialDiagnostic &PD,
655 std::pair<SourceLocation, PartialDiagnostic> Note);
656 bool RequireCompleteType(SourceLocation Loc, QualType T,
657 const PartialDiagnostic &PD);
658 bool RequireCompleteType(SourceLocation Loc, QualType T,
659 unsigned DiagID);
661 QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
662 const CXXScopeSpec &SS, QualType T);
664 QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
665 QualType BuildDecltypeType(Expr *E, SourceLocation Loc);
667 //===--------------------------------------------------------------------===//
668 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
671 DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr);
673 void DiagnoseUseOfUnimplementedSelectors();
675 ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
676 Scope *S, CXXScopeSpec *SS = 0,
677 bool isClassName = false,
678 ParsedType ObjectType = ParsedType());
679 TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
680 bool DiagnoseUnknownTypeName(const IdentifierInfo &II,
681 SourceLocation IILoc,
682 Scope *S,
683 CXXScopeSpec *SS,
684 ParsedType &SuggestedType);
686 Decl *ActOnDeclarator(Scope *S, Declarator &D);
688 Decl *HandleDeclarator(Scope *S, Declarator &D,
689 MultiTemplateParamsArg TemplateParameterLists,
690 bool IsFunctionDefinition);
691 void RegisterLocallyScopedExternCDecl(NamedDecl *ND,
692 const LookupResult &Previous,
693 Scope *S);
694 void DiagnoseFunctionSpecifiers(Declarator& D);
695 void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R);
696 void CheckShadow(Scope *S, VarDecl *D);
697 void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
698 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
699 QualType R, TypeSourceInfo *TInfo,
700 LookupResult &Previous, bool &Redeclaration);
701 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
702 QualType R, TypeSourceInfo *TInfo,
703 LookupResult &Previous,
704 MultiTemplateParamsArg TemplateParamLists,
705 bool &Redeclaration);
706 void CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous,
707 bool &Redeclaration);
708 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
709 QualType R, TypeSourceInfo *TInfo,
710 LookupResult &Previous,
711 MultiTemplateParamsArg TemplateParamLists,
712 bool IsFunctionDefinition,
713 bool &Redeclaration);
714 bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
715 void CheckFunctionDeclaration(Scope *S,
716 FunctionDecl *NewFD, LookupResult &Previous,
717 bool IsExplicitSpecialization,
718 bool &Redeclaration,
719 bool &OverloadableAttrRequired);
720 void CheckMain(FunctionDecl *FD);
721 Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
722 ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
723 SourceLocation Loc,
724 QualType T);
725 ParmVarDecl *CheckParameter(DeclContext *DC,
726 TypeSourceInfo *TSInfo, QualType T,
727 IdentifierInfo *Name,
728 SourceLocation NameLoc,
729 StorageClass SC,
730 StorageClass SCAsWritten);
731 void ActOnParamDefaultArgument(Decl *param,
732 SourceLocation EqualLoc,
733 Expr *defarg);
734 void ActOnParamUnparsedDefaultArgument(Decl *param,
735 SourceLocation EqualLoc,
736 SourceLocation ArgLoc);
737 void ActOnParamDefaultArgumentError(Decl *param);
738 bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
739 SourceLocation EqualLoc);
741 void AddInitializerToDecl(Decl *dcl, Expr *init);
742 void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit);
743 void ActOnUninitializedDecl(Decl *dcl, bool TypeContainsUndeducedAuto);
744 void ActOnInitializerError(Decl *Dcl);
745 void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
746 DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
747 Decl **Group,
748 unsigned NumDecls);
749 void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
750 SourceLocation LocAfterDecls);
751 Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
752 Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D);
753 void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
755 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
756 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
758 /// \brief Diagnose any unused parameters in the given sequence of
759 /// ParmVarDecl pointers.
760 void DiagnoseUnusedParameters(ParmVarDecl * const *Begin,
761 ParmVarDecl * const *End);
763 /// \brief Diagnose whether the size of parameters or return value of a
764 /// function or obj-c method definition is pass-by-value and larger than a
765 /// specified threshold.
766 void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin,
767 ParmVarDecl * const *End,
768 QualType ReturnTy,
769 NamedDecl *D);
771 void DiagnoseInvalidJumps(Stmt *Body);
772 Decl *ActOnFileScopeAsmDecl(SourceLocation Loc, Expr *expr);
774 /// Scope actions.
775 void ActOnPopScope(SourceLocation Loc, Scope *S);
776 void ActOnTranslationUnitScope(Scope *S);
778 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
779 /// no declarator (e.g. "struct foo;") is parsed.
780 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
781 DeclSpec &DS);
783 StmtResult ActOnVlaStmt(const DeclSpec &DS);
785 Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
786 AccessSpecifier AS,
787 RecordDecl *Record);
789 bool isAcceptableTagRedeclaration(const TagDecl *Previous,
790 TagTypeKind NewTag,
791 SourceLocation NewTagLoc,
792 const IdentifierInfo &Name);
794 enum TagUseKind {
795 TUK_Reference, // Reference to a tag: 'struct foo *X;'
796 TUK_Declaration, // Fwd decl of a tag: 'struct foo;'
797 TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;'
798 TUK_Friend // Friend declaration: 'friend struct foo;'
801 Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
802 SourceLocation KWLoc, CXXScopeSpec &SS,
803 IdentifierInfo *Name, SourceLocation NameLoc,
804 AttributeList *Attr, AccessSpecifier AS,
805 MultiTemplateParamsArg TemplateParameterLists,
806 bool &OwnedDecl, bool &IsDependent, bool ScopedEnum,
807 TypeResult UnderlyingType);
809 Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
810 unsigned TagSpec, SourceLocation TagLoc,
811 CXXScopeSpec &SS,
812 IdentifierInfo *Name, SourceLocation NameLoc,
813 AttributeList *Attr,
814 MultiTemplateParamsArg TempParamLists);
816 TypeResult ActOnDependentTag(Scope *S,
817 unsigned TagSpec,
818 TagUseKind TUK,
819 const CXXScopeSpec &SS,
820 IdentifierInfo *Name,
821 SourceLocation TagLoc,
822 SourceLocation NameLoc);
824 void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
825 IdentifierInfo *ClassName,
826 llvm::SmallVectorImpl<Decl *> &Decls);
827 Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
828 Declarator &D, Expr *BitfieldWidth);
830 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
831 Declarator &D, Expr *BitfieldWidth,
832 AccessSpecifier AS);
834 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
835 TypeSourceInfo *TInfo,
836 RecordDecl *Record, SourceLocation Loc,
837 bool Mutable, Expr *BitfieldWidth,
838 SourceLocation TSSL,
839 AccessSpecifier AS, NamedDecl *PrevDecl,
840 Declarator *D = 0);
842 enum CXXSpecialMember {
843 CXXInvalid = -1,
844 CXXConstructor = 0,
845 CXXCopyConstructor = 1,
846 CXXCopyAssignment = 2,
847 CXXDestructor = 3
849 bool CheckNontrivialField(FieldDecl *FD);
850 void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem);
851 CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
852 void ActOnLastBitfield(SourceLocation DeclStart, Decl *IntfDecl,
853 llvm::SmallVectorImpl<Decl *> &AllIvarDecls);
854 Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, Decl *IntfDecl,
855 Declarator &D, Expr *BitfieldWidth,
856 tok::ObjCKeywordKind visibility);
858 // This is used for both record definitions and ObjC interface declarations.
859 void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl,
860 Decl **Fields, unsigned NumFields,
861 SourceLocation LBrac, SourceLocation RBrac,
862 AttributeList *AttrList);
864 /// ActOnTagStartDefinition - Invoked when we have entered the
865 /// scope of a tag's definition (e.g., for an enumeration, class,
866 /// struct, or union).
867 void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
869 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
870 /// C++ record definition's base-specifiers clause and are starting its
871 /// member declarations.
872 void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
873 SourceLocation LBraceLoc);
875 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
876 /// the definition of a tag (enumeration, class, struct, or union).
877 void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
878 SourceLocation RBraceLoc);
880 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
881 /// error parsing the definition of a tag.
882 void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
884 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
885 EnumConstantDecl *LastEnumConst,
886 SourceLocation IdLoc,
887 IdentifierInfo *Id,
888 Expr *val);
890 Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
891 SourceLocation IdLoc, IdentifierInfo *Id,
892 AttributeList *Attrs,
893 SourceLocation EqualLoc, Expr *Val);
894 void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
895 SourceLocation RBraceLoc, Decl *EnumDecl,
896 Decl **Elements, unsigned NumElements,
897 Scope *S, AttributeList *Attr);
899 DeclContext *getContainingDC(DeclContext *DC);
901 /// Set the current declaration context until it gets popped.
902 void PushDeclContext(Scope *S, DeclContext *DC);
903 void PopDeclContext();
905 /// EnterDeclaratorContext - Used when we must lookup names in the context
906 /// of a declarator's nested name specifier.
907 void EnterDeclaratorContext(Scope *S, DeclContext *DC);
908 void ExitDeclaratorContext(Scope *S);
910 DeclContext *getFunctionLevelDeclContext();
912 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
913 /// to the function decl for the function being parsed. If we're currently
914 /// in a 'block', this returns the containing context.
915 FunctionDecl *getCurFunctionDecl();
917 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
918 /// the method decl for the method being parsed. If we're currently
919 /// in a 'block', this returns the containing context.
920 ObjCMethodDecl *getCurMethodDecl();
922 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
923 /// or C function we're in, otherwise return null. If we're currently
924 /// in a 'block', this returns the containing context.
925 NamedDecl *getCurFunctionOrMethodDecl();
927 /// Add this decl to the scope shadowed decl chains.
928 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
930 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
931 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
932 /// true if 'D' belongs to the given declaration context.
933 bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0);
935 /// Finds the scope corresponding to the given decl context, if it
936 /// happens to be an enclosing scope. Otherwise return NULL.
937 static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
939 /// Subroutines of ActOnDeclarator().
940 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
941 TypeSourceInfo *TInfo);
942 void MergeTypeDefDecl(TypedefDecl *New, LookupResult &OldDecls);
943 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
944 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
945 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls);
946 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
948 // AssignmentAction - This is used by all the assignment diagnostic functions
949 // to represent what is actually causing the operation
950 enum AssignmentAction {
951 AA_Assigning,
952 AA_Passing,
953 AA_Returning,
954 AA_Converting,
955 AA_Initializing,
956 AA_Sending,
957 AA_Casting
960 /// C++ Overloading.
961 enum OverloadKind {
962 /// This is a legitimate overload: the existing declarations are
963 /// functions or function templates with different signatures.
964 Ovl_Overload,
966 /// This is not an overload because the signature exactly matches
967 /// an existing declaration.
968 Ovl_Match,
970 /// This is not an overload because the lookup results contain a
971 /// non-function.
972 Ovl_NonFunction
974 OverloadKind CheckOverload(Scope *S,
975 FunctionDecl *New,
976 const LookupResult &OldDecls,
977 NamedDecl *&OldDecl,
978 bool IsForUsingDecl);
979 bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl);
981 bool TryImplicitConversion(InitializationSequence &Sequence,
982 const InitializedEntity &Entity,
983 Expr *From,
984 bool SuppressUserConversions,
985 bool AllowExplicit,
986 bool InOverloadResolution);
988 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
989 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
990 bool IsComplexPromotion(QualType FromType, QualType ToType);
991 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
992 bool InOverloadResolution,
993 QualType& ConvertedType, bool &IncompatibleObjC);
994 bool isObjCPointerConversion(QualType FromType, QualType ToType,
995 QualType& ConvertedType, bool &IncompatibleObjC);
996 bool FunctionArgTypesAreEqual (FunctionProtoType* OldType,
997 FunctionProtoType* NewType);
999 bool CheckPointerConversion(Expr *From, QualType ToType,
1000 CastKind &Kind,
1001 CXXCastPath& BasePath,
1002 bool IgnoreBaseAccess);
1003 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
1004 bool InOverloadResolution,
1005 QualType &ConvertedType);
1006 bool CheckMemberPointerConversion(Expr *From, QualType ToType,
1007 CastKind &Kind,
1008 CXXCastPath &BasePath,
1009 bool IgnoreBaseAccess);
1010 bool IsQualificationConversion(QualType FromType, QualType ToType);
1011 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
1014 ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
1015 SourceLocation EqualLoc,
1016 ExprResult Init);
1017 bool PerformObjectArgumentInitialization(Expr *&From,
1018 NestedNameSpecifier *Qualifier,
1019 NamedDecl *FoundDecl,
1020 CXXMethodDecl *Method);
1022 bool PerformContextuallyConvertToBool(Expr *&From);
1023 bool PerformContextuallyConvertToObjCId(Expr *&From);
1025 ExprResult
1026 ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE,
1027 const PartialDiagnostic &NotIntDiag,
1028 const PartialDiagnostic &IncompleteDiag,
1029 const PartialDiagnostic &ExplicitConvDiag,
1030 const PartialDiagnostic &ExplicitConvNote,
1031 const PartialDiagnostic &AmbigDiag,
1032 const PartialDiagnostic &AmbigNote,
1033 const PartialDiagnostic &ConvDiag);
1035 bool PerformObjectMemberConversion(Expr *&From,
1036 NestedNameSpecifier *Qualifier,
1037 NamedDecl *FoundDecl,
1038 NamedDecl *Member);
1040 // Members have to be NamespaceDecl* or TranslationUnitDecl*.
1041 // TODO: make this is a typesafe union.
1042 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet;
1043 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
1045 void AddOverloadCandidate(NamedDecl *Function,
1046 DeclAccessPair FoundDecl,
1047 Expr **Args, unsigned NumArgs,
1048 OverloadCandidateSet &CandidateSet);
1050 void AddOverloadCandidate(FunctionDecl *Function,
1051 DeclAccessPair FoundDecl,
1052 Expr **Args, unsigned NumArgs,
1053 OverloadCandidateSet& CandidateSet,
1054 bool SuppressUserConversions = false,
1055 bool PartialOverloading = false);
1056 void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
1057 Expr **Args, unsigned NumArgs,
1058 OverloadCandidateSet& CandidateSet,
1059 bool SuppressUserConversions = false);
1060 void AddMethodCandidate(DeclAccessPair FoundDecl,
1061 QualType ObjectType,
1062 Expr **Args, unsigned NumArgs,
1063 OverloadCandidateSet& CandidateSet,
1064 bool SuppressUserConversion = false);
1065 void AddMethodCandidate(CXXMethodDecl *Method,
1066 DeclAccessPair FoundDecl,
1067 CXXRecordDecl *ActingContext, QualType ObjectType,
1068 Expr **Args, unsigned NumArgs,
1069 OverloadCandidateSet& CandidateSet,
1070 bool SuppressUserConversions = false);
1071 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
1072 DeclAccessPair FoundDecl,
1073 CXXRecordDecl *ActingContext,
1074 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1075 QualType ObjectType,
1076 Expr **Args, unsigned NumArgs,
1077 OverloadCandidateSet& CandidateSet,
1078 bool SuppressUserConversions = false);
1079 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
1080 DeclAccessPair FoundDecl,
1081 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1082 Expr **Args, unsigned NumArgs,
1083 OverloadCandidateSet& CandidateSet,
1084 bool SuppressUserConversions = false);
1085 void AddConversionCandidate(CXXConversionDecl *Conversion,
1086 DeclAccessPair FoundDecl,
1087 CXXRecordDecl *ActingContext,
1088 Expr *From, QualType ToType,
1089 OverloadCandidateSet& CandidateSet);
1090 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
1091 DeclAccessPair FoundDecl,
1092 CXXRecordDecl *ActingContext,
1093 Expr *From, QualType ToType,
1094 OverloadCandidateSet &CandidateSet);
1095 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
1096 DeclAccessPair FoundDecl,
1097 CXXRecordDecl *ActingContext,
1098 const FunctionProtoType *Proto,
1099 QualType ObjectTy, Expr **Args, unsigned NumArgs,
1100 OverloadCandidateSet& CandidateSet);
1101 void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
1102 SourceLocation OpLoc,
1103 Expr **Args, unsigned NumArgs,
1104 OverloadCandidateSet& CandidateSet,
1105 SourceRange OpRange = SourceRange());
1106 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
1107 Expr **Args, unsigned NumArgs,
1108 OverloadCandidateSet& CandidateSet,
1109 bool IsAssignmentOperator = false,
1110 unsigned NumContextualBoolArguments = 0);
1111 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
1112 SourceLocation OpLoc,
1113 Expr **Args, unsigned NumArgs,
1114 OverloadCandidateSet& CandidateSet);
1115 void AddArgumentDependentLookupCandidates(DeclarationName Name,
1116 bool Operator,
1117 Expr **Args, unsigned NumArgs,
1118 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1119 OverloadCandidateSet& CandidateSet,
1120 bool PartialOverloading = false);
1122 void NoteOverloadCandidate(FunctionDecl *Fn);
1124 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
1125 bool Complain,
1126 DeclAccessPair &Found);
1127 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(Expr *From);
1129 Expr *FixOverloadedFunctionReference(Expr *E,
1130 DeclAccessPair FoundDecl,
1131 FunctionDecl *Fn);
1132 ExprResult FixOverloadedFunctionReference(ExprResult,
1133 DeclAccessPair FoundDecl,
1134 FunctionDecl *Fn);
1136 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
1137 Expr **Args, unsigned NumArgs,
1138 OverloadCandidateSet &CandidateSet,
1139 bool PartialOverloading = false);
1141 ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
1142 UnresolvedLookupExpr *ULE,
1143 SourceLocation LParenLoc,
1144 Expr **Args, unsigned NumArgs,
1145 SourceLocation RParenLoc);
1147 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
1148 unsigned Opc,
1149 const UnresolvedSetImpl &Fns,
1150 Expr *input);
1152 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
1153 unsigned Opc,
1154 const UnresolvedSetImpl &Fns,
1155 Expr *LHS, Expr *RHS);
1157 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
1158 SourceLocation RLoc,
1159 Expr *Base,Expr *Idx);
1161 ExprResult
1162 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
1163 SourceLocation LParenLoc, Expr **Args,
1164 unsigned NumArgs, SourceLocation RParenLoc);
1165 ExprResult
1166 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
1167 Expr **Args, unsigned NumArgs,
1168 SourceLocation RParenLoc);
1170 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
1171 SourceLocation OpLoc);
1173 /// CheckCallReturnType - Checks that a call expression's return type is
1174 /// complete. Returns true on failure. The location passed in is the location
1175 /// that best represents the call.
1176 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
1177 CallExpr *CE, FunctionDecl *FD);
1179 /// Helpers for dealing with blocks and functions.
1180 bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd,
1181 bool CheckParameterNames);
1182 void CheckCXXDefaultArguments(FunctionDecl *FD);
1183 void CheckExtraCXXDefaultArguments(Declarator &D);
1184 Scope *getNonFieldDeclScope(Scope *S);
1186 /// \name Name lookup
1188 /// These routines provide name lookup that is used during semantic
1189 /// analysis to resolve the various kinds of names (identifiers,
1190 /// overloaded operator names, constructor names, etc.) into zero or
1191 /// more declarations within a particular scope. The major entry
1192 /// points are LookupName, which performs unqualified name lookup,
1193 /// and LookupQualifiedName, which performs qualified name lookup.
1195 /// All name lookup is performed based on some specific criteria,
1196 /// which specify what names will be visible to name lookup and how
1197 /// far name lookup should work. These criteria are important both
1198 /// for capturing language semantics (certain lookups will ignore
1199 /// certain names, for example) and for performance, since name
1200 /// lookup is often a bottleneck in the compilation of C++. Name
1201 /// lookup criteria is specified via the LookupCriteria enumeration.
1203 /// The results of name lookup can vary based on the kind of name
1204 /// lookup performed, the current language, and the translation
1205 /// unit. In C, for example, name lookup will either return nothing
1206 /// (no entity found) or a single declaration. In C++, name lookup
1207 /// can additionally refer to a set of overloaded functions or
1208 /// result in an ambiguity. All of the possible results of name
1209 /// lookup are captured by the LookupResult class, which provides
1210 /// the ability to distinguish among them.
1211 //@{
1213 /// @brief Describes the kind of name lookup to perform.
1214 enum LookupNameKind {
1215 /// Ordinary name lookup, which finds ordinary names (functions,
1216 /// variables, typedefs, etc.) in C and most kinds of names
1217 /// (functions, variables, members, types, etc.) in C++.
1218 LookupOrdinaryName = 0,
1219 /// Tag name lookup, which finds the names of enums, classes,
1220 /// structs, and unions.
1221 LookupTagName,
1222 /// Member name lookup, which finds the names of
1223 /// class/struct/union members.
1224 LookupMemberName,
1225 /// Look up of an operator name (e.g., operator+) for use with
1226 /// operator overloading. This lookup is similar to ordinary name
1227 /// lookup, but will ignore any declarations that are class members.
1228 LookupOperatorName,
1229 /// Look up of a name that precedes the '::' scope resolution
1230 /// operator in C++. This lookup completely ignores operator, object,
1231 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
1232 LookupNestedNameSpecifierName,
1233 /// Look up a namespace name within a C++ using directive or
1234 /// namespace alias definition, ignoring non-namespace names (C++
1235 /// [basic.lookup.udir]p1).
1236 LookupNamespaceName,
1237 /// Look up all declarations in a scope with the given name,
1238 /// including resolved using declarations. This is appropriate
1239 /// for checking redeclarations for a using declaration.
1240 LookupUsingDeclName,
1241 /// Look up an ordinary name that is going to be redeclared as a
1242 /// name with linkage. This lookup ignores any declarations that
1243 /// are outside of the current scope unless they have linkage. See
1244 /// C99 6.2.2p4-5 and C++ [basic.link]p6.
1245 LookupRedeclarationWithLinkage,
1246 /// Look up the name of an Objective-C protocol.
1247 LookupObjCProtocolName,
1248 /// \brief Look up any declaration with any name.
1249 LookupAnyName
1252 /// \brief Specifies whether (or how) name lookup is being performed for a
1253 /// redeclaration (vs. a reference).
1254 enum RedeclarationKind {
1255 /// \brief The lookup is a reference to this name that is not for the
1256 /// purpose of redeclaring the name.
1257 NotForRedeclaration = 0,
1258 /// \brief The lookup results will be used for redeclaration of a name,
1259 /// if an entity by that name already exists.
1260 ForRedeclaration
1263 private:
1264 bool CppLookupName(LookupResult &R, Scope *S);
1266 public:
1267 /// \brief Look up a name, looking for a single declaration. Return
1268 /// null if the results were absent, ambiguous, or overloaded.
1270 /// It is preferable to use the elaborated form and explicitly handle
1271 /// ambiguity and overloaded.
1272 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
1273 SourceLocation Loc,
1274 LookupNameKind NameKind,
1275 RedeclarationKind Redecl
1276 = NotForRedeclaration);
1277 bool LookupName(LookupResult &R, Scope *S,
1278 bool AllowBuiltinCreation = false);
1279 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
1280 bool InUnqualifiedLookup = false);
1281 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
1282 bool AllowBuiltinCreation = false,
1283 bool EnteringContext = false);
1284 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc);
1286 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
1287 QualType T1, QualType T2,
1288 UnresolvedSetImpl &Functions);
1290 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
1291 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
1293 void ArgumentDependentLookup(DeclarationName Name, bool Operator,
1294 Expr **Args, unsigned NumArgs,
1295 ADLResult &Functions);
1297 void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
1298 VisibleDeclConsumer &Consumer,
1299 bool IncludeGlobalScope = true);
1300 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
1301 VisibleDeclConsumer &Consumer,
1302 bool IncludeGlobalScope = true);
1304 /// \brief The context in which typo-correction occurs.
1306 /// The typo-correction context affects which keywords (if any) are
1307 /// considered when trying to correct for typos.
1308 enum CorrectTypoContext {
1309 /// \brief An unknown context, where any keyword might be valid.
1310 CTC_Unknown,
1311 /// \brief A context where no keywords are used (e.g. we expect an actual
1312 /// name).
1313 CTC_NoKeywords,
1314 /// \brief A context where we're correcting a type name.
1315 CTC_Type,
1316 /// \brief An expression context.
1317 CTC_Expression,
1318 /// \brief A type cast, or anything else that can be followed by a '<'.
1319 CTC_CXXCasts,
1320 /// \brief A member lookup context.
1321 CTC_MemberLookup,
1322 /// \brief An Objective-C ivar lookup context (e.g., self->ivar).
1323 CTC_ObjCIvarLookup,
1324 /// \brief An Objective-C property lookup context (e.g., self.prop).
1325 CTC_ObjCPropertyLookup,
1326 /// \brief The receiver of an Objective-C message send within an
1327 /// Objective-C method where 'super' is a valid keyword.
1328 CTC_ObjCMessageReceiver
1331 DeclarationName CorrectTypo(LookupResult &R, Scope *S, CXXScopeSpec *SS,
1332 DeclContext *MemberContext = 0,
1333 bool EnteringContext = false,
1334 CorrectTypoContext CTC = CTC_Unknown,
1335 const ObjCObjectPointerType *OPT = 0);
1337 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
1338 AssociatedNamespaceSet &AssociatedNamespaces,
1339 AssociatedClassSet &AssociatedClasses);
1341 bool DiagnoseAmbiguousLookup(LookupResult &Result);
1342 //@}
1344 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
1345 SourceLocation IdLoc,
1346 bool TypoCorrection = false);
1347 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
1348 Scope *S, bool ForRedeclaration,
1349 SourceLocation Loc);
1350 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
1351 Scope *S);
1352 void AddKnownFunctionAttributes(FunctionDecl *FD);
1354 // More parsing and symbol table subroutines.
1356 // Decl attributes - this routine is the top level dispatcher.
1357 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD);
1358 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL);
1360 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
1361 bool &IncompleteImpl, unsigned DiagID);
1362 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
1363 ObjCMethodDecl *IntfMethod);
1365 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
1366 ObjCInterfaceDecl *IDecl);
1368 typedef llvm::DenseSet<Selector, llvm::DenseMapInfo<Selector> > SelectorSet;
1370 /// CheckProtocolMethodDefs - This routine checks unimplemented
1371 /// methods declared in protocol, and those referenced by it.
1372 /// \param IDecl - Used for checking for methods which may have been
1373 /// inherited.
1374 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
1375 ObjCProtocolDecl *PDecl,
1376 bool& IncompleteImpl,
1377 const SelectorSet &InsMap,
1378 const SelectorSet &ClsMap,
1379 ObjCContainerDecl *CDecl);
1381 /// CheckImplementationIvars - This routine checks if the instance variables
1382 /// listed in the implelementation match those listed in the interface.
1383 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
1384 ObjCIvarDecl **Fields, unsigned nIvars,
1385 SourceLocation Loc);
1387 /// \brief Determine whether we can synthesize a provisional ivar for the
1388 /// given name.
1389 ObjCPropertyDecl *canSynthesizeProvisionalIvar(IdentifierInfo *II);
1391 /// \brief Determine whether we can synthesize a provisional ivar for the
1392 /// given property.
1393 bool canSynthesizeProvisionalIvar(ObjCPropertyDecl *Property);
1395 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
1396 /// remains unimplemented in the class or category @implementation.
1397 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
1398 ObjCContainerDecl* IDecl,
1399 bool IncompleteImpl = false);
1401 /// DiagnoseUnimplementedProperties - This routine warns on those properties
1402 /// which must be implemented by this implementation.
1403 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
1404 ObjCContainerDecl *CDecl,
1405 const SelectorSet &InsMap);
1407 /// DefaultSynthesizeProperties - This routine default synthesizes all
1408 /// properties which must be synthesized in class's @implementation.
1409 void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
1410 ObjCInterfaceDecl *IDecl);
1412 /// CollectImmediateProperties - This routine collects all properties in
1413 /// the class and its conforming protocols; but not those it its super class.
1414 void CollectImmediateProperties(ObjCContainerDecl *CDecl,
1415 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
1416 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap);
1419 /// LookupPropertyDecl - Looks up a property in the current class and all
1420 /// its protocols.
1421 ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl,
1422 IdentifierInfo *II);
1424 /// Called by ActOnProperty to handle @property declarations in
1425 //// class extensions.
1426 Decl *HandlePropertyInClassExtension(Scope *S,
1427 ObjCCategoryDecl *CDecl,
1428 SourceLocation AtLoc,
1429 FieldDeclarator &FD,
1430 Selector GetterSel,
1431 Selector SetterSel,
1432 const bool isAssign,
1433 const bool isReadWrite,
1434 const unsigned Attributes,
1435 bool *isOverridingProperty,
1436 TypeSourceInfo *T,
1437 tok::ObjCKeywordKind MethodImplKind);
1439 /// Called by ActOnProperty and HandlePropertyInClassExtension to
1440 /// handle creating the ObjcPropertyDecl for a category or @interface.
1441 ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
1442 ObjCContainerDecl *CDecl,
1443 SourceLocation AtLoc,
1444 FieldDeclarator &FD,
1445 Selector GetterSel,
1446 Selector SetterSel,
1447 const bool isAssign,
1448 const bool isReadWrite,
1449 const unsigned Attributes,
1450 TypeSourceInfo *T,
1451 tok::ObjCKeywordKind MethodImplKind,
1452 DeclContext *lexicalDC = 0);
1454 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
1455 /// warning) when atomic property has one but not the other user-declared
1456 /// setter or getter.
1457 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
1458 ObjCContainerDecl* IDecl);
1460 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
1462 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
1463 /// true, or false, accordingly.
1464 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
1465 const ObjCMethodDecl *PrevMethod,
1466 bool matchBasedOnSizeAndAlignment = false,
1467 bool matchBasedOnStrictEqulity = false);
1469 /// MatchAllMethodDeclarations - Check methods declaraed in interface or
1470 /// or protocol against those declared in their implementations.
1471 void MatchAllMethodDeclarations(const SelectorSet &InsMap,
1472 const SelectorSet &ClsMap,
1473 SelectorSet &InsMapSeen,
1474 SelectorSet &ClsMapSeen,
1475 ObjCImplDecl* IMPDecl,
1476 ObjCContainerDecl* IDecl,
1477 bool &IncompleteImpl,
1478 bool ImmediateClass);
1480 private:
1481 /// AddMethodToGlobalPool - Add an instance or factory method to the global
1482 /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
1483 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
1485 /// LookupMethodInGlobalPool - Returns the instance or factory method and
1486 /// optionally warns if there are multiple signatures.
1487 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
1488 bool receiverIdOrClass,
1489 bool warn, bool instance);
1491 public:
1492 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
1493 /// unit are added to a global pool. This allows us to efficiently associate
1494 /// a selector with a method declaraation for purposes of typechecking
1495 /// messages sent to "id" (where the class of the object is unknown).
1496 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
1497 AddMethodToGlobalPool(Method, impl, /*instance*/true);
1500 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
1501 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
1502 AddMethodToGlobalPool(Method, impl, /*instance*/false);
1505 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
1506 /// there are multiple signatures.
1507 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
1508 bool receiverIdOrClass=false,
1509 bool warn=true) {
1510 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
1511 warn, /*instance*/true);
1514 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
1515 /// there are multiple signatures.
1516 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
1517 bool receiverIdOrClass=false,
1518 bool warn=true) {
1519 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
1520 warn, /*instance*/false);
1523 /// LookupImplementedMethodInGlobalPool - Returns the method which has an
1524 /// implementation.
1525 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
1527 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
1528 /// initialization.
1529 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
1530 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
1531 //===--------------------------------------------------------------------===//
1532 // Statement Parsing Callbacks: SemaStmt.cpp.
1533 public:
1534 class FullExprArg {
1535 public:
1536 FullExprArg(Sema &actions) : E(0) { }
1538 // FIXME: The const_cast here is ugly. RValue references would make this
1539 // much nicer (or we could duplicate a bunch of the move semantics
1540 // emulation code from Ownership.h).
1541 FullExprArg(const FullExprArg& Other): E(Other.E) {}
1543 ExprResult release() {
1544 return move(E);
1547 Expr *get() const { return E; }
1549 Expr *operator->() {
1550 return E;
1553 private:
1554 // FIXME: No need to make the entire Sema class a friend when it's just
1555 // Sema::FullExpr that needs access to the constructor below.
1556 friend class Sema;
1558 explicit FullExprArg(Expr *expr) : E(expr) {}
1560 Expr *E;
1563 FullExprArg MakeFullExpr(Expr *Arg) {
1564 return FullExprArg(ActOnFinishFullExpr(Arg).release());
1567 StmtResult ActOnExprStmt(FullExprArg Expr);
1569 StmtResult ActOnNullStmt(SourceLocation SemiLoc);
1570 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1571 MultiStmtArg Elts,
1572 bool isStmtExpr);
1573 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
1574 SourceLocation StartLoc,
1575 SourceLocation EndLoc);
1576 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
1577 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal,
1578 SourceLocation DotDotDotLoc, Expr *RHSVal,
1579 SourceLocation ColonLoc);
1580 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
1582 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1583 SourceLocation ColonLoc,
1584 Stmt *SubStmt, Scope *CurScope);
1585 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
1586 SourceLocation ColonLoc, Stmt *SubStmt,
1587 const AttributeList *Attr);
1588 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
1589 SourceLocation ColonLoc, Stmt *SubStmt,
1590 bool HasUnusedAttr);
1591 StmtResult ActOnIfStmt(SourceLocation IfLoc,
1592 FullExprArg CondVal, Decl *CondVar,
1593 Stmt *ThenVal,
1594 SourceLocation ElseLoc, Stmt *ElseVal);
1595 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
1596 Expr *Cond,
1597 Decl *CondVar);
1598 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1599 Stmt *Switch, Stmt *Body);
1600 StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
1601 FullExprArg Cond,
1602 Decl *CondVar, Stmt *Body);
1603 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
1604 SourceLocation WhileLoc,
1605 SourceLocation CondLParen, Expr *Cond,
1606 SourceLocation CondRParen);
1608 StmtResult ActOnForStmt(SourceLocation ForLoc,
1609 SourceLocation LParenLoc,
1610 Stmt *First, FullExprArg Second,
1611 Decl *SecondVar,
1612 FullExprArg Third,
1613 SourceLocation RParenLoc,
1614 Stmt *Body);
1615 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1616 SourceLocation LParenLoc,
1617 Stmt *First, Expr *Second,
1618 SourceLocation RParenLoc, Stmt *Body);
1620 StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1621 SourceLocation LabelLoc,
1622 IdentifierInfo *LabelII);
1623 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1624 SourceLocation StarLoc,
1625 Expr *DestExp);
1626 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
1627 StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
1629 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
1630 StmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
1632 StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1633 bool IsSimple, bool IsVolatile,
1634 unsigned NumOutputs, unsigned NumInputs,
1635 IdentifierInfo **Names,
1636 MultiExprArg Constraints,
1637 MultiExprArg Exprs,
1638 Expr *AsmString,
1639 MultiExprArg Clobbers,
1640 SourceLocation RParenLoc,
1641 bool MSAsm = false);
1644 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
1645 IdentifierInfo *Name, SourceLocation NameLoc,
1646 bool Invalid = false);
1648 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
1650 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
1651 Decl *Parm, Stmt *Body);
1653 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
1655 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
1656 MultiStmtArg Catch, Stmt *Finally);
1658 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
1659 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
1660 Scope *CurScope);
1661 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1662 Expr *SynchExpr,
1663 Stmt *SynchBody);
1665 VarDecl *BuildExceptionDeclaration(Scope *S,
1666 TypeSourceInfo *TInfo,
1667 IdentifierInfo *Name,
1668 SourceLocation Loc);
1669 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
1671 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
1672 Decl *ExDecl, Stmt *HandlerBlock);
1673 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
1674 MultiStmtArg Handlers);
1675 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
1677 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
1679 /// \brief If it's a file scoped decl that must warn if not used, keep track
1680 /// of it.
1681 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
1683 /// DiagnoseUnusedExprResult - If the statement passed in is an expression
1684 /// whose result is unused, warn.
1685 void DiagnoseUnusedExprResult(const Stmt *S);
1686 void DiagnoseUnusedDecl(const NamedDecl *ND);
1688 typedef uintptr_t ParsingDeclStackState;
1690 ParsingDeclStackState PushParsingDeclaration();
1691 void PopParsingDeclaration(ParsingDeclStackState S, Decl *D);
1692 void EmitDeprecationWarning(NamedDecl *D, llvm::StringRef Message,
1693 SourceLocation Loc);
1695 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
1697 //===--------------------------------------------------------------------===//
1698 // Expression Parsing Callbacks: SemaExpr.cpp.
1700 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
1701 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
1702 ObjCMethodDecl *Getter,
1703 SourceLocation Loc);
1704 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
1705 Expr **Args, unsigned NumArgs);
1707 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext);
1709 void PopExpressionEvaluationContext();
1711 void MarkDeclarationReferenced(SourceLocation Loc, Decl *D);
1712 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
1713 void MarkDeclarationsReferencedInExpr(Expr *E);
1714 bool DiagRuntimeBehavior(SourceLocation Loc, const PartialDiagnostic &PD);
1716 // Primary Expressions.
1717 SourceRange getExprRange(Expr *E) const;
1719 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, UnqualifiedId &Name,
1720 bool HasTrailingLParen, bool IsAddressOfOperand);
1722 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
1723 CorrectTypoContext CTC = CTC_Unknown);
1725 ExprResult LookupInObjCMethod(LookupResult &R, Scope *S, IdentifierInfo *II,
1726 bool AllowBuiltinCreation=false);
1728 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
1729 const DeclarationNameInfo &NameInfo,
1730 bool isAddressOfOperand,
1731 const TemplateArgumentListInfo *TemplateArgs);
1733 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
1734 SourceLocation Loc,
1735 const CXXScopeSpec *SS = 0);
1736 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
1737 const DeclarationNameInfo &NameInfo,
1738 const CXXScopeSpec *SS = 0);
1739 VarDecl *BuildAnonymousStructUnionMemberPath(FieldDecl *Field,
1740 llvm::SmallVectorImpl<FieldDecl *> &Path);
1741 ExprResult
1742 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1743 FieldDecl *Field,
1744 Expr *BaseObjectExpr = 0,
1745 SourceLocation OpLoc = SourceLocation());
1746 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
1747 LookupResult &R,
1748 const TemplateArgumentListInfo *TemplateArgs);
1749 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
1750 LookupResult &R,
1751 const TemplateArgumentListInfo *TemplateArgs,
1752 bool IsDefiniteInstance);
1753 bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
1754 const LookupResult &R,
1755 bool HasTrailingLParen);
1757 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
1758 const DeclarationNameInfo &NameInfo);
1759 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
1760 const DeclarationNameInfo &NameInfo,
1761 const TemplateArgumentListInfo *TemplateArgs);
1763 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
1764 LookupResult &R,
1765 bool ADL);
1766 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
1767 const DeclarationNameInfo &NameInfo,
1768 NamedDecl *D);
1770 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
1771 ExprResult ActOnNumericConstant(const Token &);
1772 ExprResult ActOnCharacterConstant(const Token &);
1773 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *Val);
1774 ExprResult ActOnParenOrParenListExpr(SourceLocation L,
1775 SourceLocation R,
1776 MultiExprArg Val,
1777 ParsedType TypeOfCast = ParsedType());
1779 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
1780 /// fragments (e.g. "foo" "bar" L"baz").
1781 ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
1783 // Binary/Unary Operators. 'Tok' is the token for the operator.
1784 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, unsigned OpcIn,
1785 Expr *InputArg);
1786 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
1787 UnaryOperatorKind Opc, Expr *input);
1788 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1789 tok::TokenKind Op, Expr *Input);
1791 ExprResult CreateSizeOfAlignOfExpr(TypeSourceInfo *T,
1792 SourceLocation OpLoc,
1793 bool isSizeOf, SourceRange R);
1794 ExprResult CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc,
1795 bool isSizeOf, SourceRange R);
1796 ExprResult
1797 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1798 void *TyOrEx, const SourceRange &ArgRange);
1800 ExprResult CheckPlaceholderExpr(Expr *E, SourceLocation Loc);
1802 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1803 SourceRange R, bool isSizeof);
1805 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1806 tok::TokenKind Kind, Expr *Input);
1808 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
1809 Expr *Idx, SourceLocation RLoc);
1810 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
1811 Expr *Idx, SourceLocation RLoc);
1813 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
1814 SourceLocation OpLoc, bool IsArrow,
1815 CXXScopeSpec &SS,
1816 NamedDecl *FirstQualifierInScope,
1817 const DeclarationNameInfo &NameInfo,
1818 const TemplateArgumentListInfo *TemplateArgs);
1820 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
1821 SourceLocation OpLoc, bool IsArrow,
1822 const CXXScopeSpec &SS,
1823 NamedDecl *FirstQualifierInScope,
1824 LookupResult &R,
1825 const TemplateArgumentListInfo *TemplateArgs,
1826 bool SuppressQualifierCheck = false);
1828 ExprResult LookupMemberExpr(LookupResult &R, Expr *&Base,
1829 bool &IsArrow, SourceLocation OpLoc,
1830 CXXScopeSpec &SS,
1831 Decl *ObjCImpDecl,
1832 bool HasTemplateArgs);
1834 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
1835 const CXXScopeSpec &SS,
1836 const LookupResult &R);
1838 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
1839 bool IsArrow, SourceLocation OpLoc,
1840 const CXXScopeSpec &SS,
1841 NamedDecl *FirstQualifierInScope,
1842 const DeclarationNameInfo &NameInfo,
1843 const TemplateArgumentListInfo *TemplateArgs);
1845 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
1846 SourceLocation OpLoc,
1847 tok::TokenKind OpKind,
1848 CXXScopeSpec &SS,
1849 UnqualifiedId &Member,
1850 Decl *ObjCImpDecl,
1851 bool HasTrailingLParen);
1853 void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
1854 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
1855 FunctionDecl *FDecl,
1856 const FunctionProtoType *Proto,
1857 Expr **Args, unsigned NumArgs,
1858 SourceLocation RParenLoc);
1860 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
1861 /// This provides the location of the left/right parens and a list of comma
1862 /// locations.
1863 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
1864 MultiExprArg Args, SourceLocation RParenLoc);
1865 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
1866 SourceLocation LParenLoc,
1867 Expr **Args, unsigned NumArgs,
1868 SourceLocation RParenLoc);
1870 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
1871 ParsedType Ty, SourceLocation RParenLoc,
1872 Expr *Op);
1873 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
1874 TypeSourceInfo *Ty,
1875 SourceLocation RParenLoc,
1876 Expr *Op);
1878 bool TypeIsVectorType(ParsedType Ty) {
1879 return GetTypeFromParser(Ty)->isVectorType();
1882 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
1883 ExprResult ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc,
1884 SourceLocation RParenLoc, Expr *E,
1885 TypeSourceInfo *TInfo);
1887 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1888 ParsedType Ty,
1889 SourceLocation RParenLoc,
1890 Expr *Op);
1892 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
1893 TypeSourceInfo *TInfo,
1894 SourceLocation RParenLoc,
1895 Expr *InitExpr);
1897 ExprResult ActOnInitList(SourceLocation LParenLoc,
1898 MultiExprArg InitList,
1899 SourceLocation RParenLoc);
1901 ExprResult ActOnDesignatedInitializer(Designation &Desig,
1902 SourceLocation Loc,
1903 bool GNUSyntax,
1904 ExprResult Init);
1906 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1907 tok::TokenKind Kind, Expr *LHS, Expr *RHS);
1908 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
1909 BinaryOperatorKind Opc, Expr *lhs, Expr *rhs);
1910 ExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1911 unsigned Opc, Expr *lhs, Expr *rhs);
1913 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
1914 /// in the case of a the GNU conditional expr extension.
1915 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1916 SourceLocation ColonLoc,
1917 Expr *Cond, Expr *LHS, Expr *RHS);
1919 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1920 ExprResult ActOnAddrLabel(SourceLocation OpLoc,
1921 SourceLocation LabLoc,
1922 IdentifierInfo *LabelII);
1924 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
1925 SourceLocation RPLoc); // "({..})"
1927 // __builtin_offsetof(type, identifier(.identifier|[expr])*)
1928 struct OffsetOfComponent {
1929 SourceLocation LocStart, LocEnd;
1930 bool isBrackets; // true if [expr], false if .ident
1931 union {
1932 IdentifierInfo *IdentInfo;
1933 ExprTy *E;
1934 } U;
1937 /// __builtin_offsetof(type, a.b[123][456].c)
1938 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
1939 TypeSourceInfo *TInfo,
1940 OffsetOfComponent *CompPtr,
1941 unsigned NumComponents,
1942 SourceLocation RParenLoc);
1943 ExprResult ActOnBuiltinOffsetOf(Scope *S,
1944 SourceLocation BuiltinLoc,
1945 SourceLocation TypeLoc,
1946 ParsedType Arg1,
1947 OffsetOfComponent *CompPtr,
1948 unsigned NumComponents,
1949 SourceLocation RParenLoc);
1951 // __builtin_types_compatible_p(type1, type2)
1952 ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
1953 ParsedType arg1,
1954 ParsedType arg2,
1955 SourceLocation RPLoc);
1956 ExprResult BuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1957 TypeSourceInfo *argTInfo1,
1958 TypeSourceInfo *argTInfo2,
1959 SourceLocation RPLoc);
1961 // __builtin_choose_expr(constExpr, expr1, expr2)
1962 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
1963 Expr *cond, Expr *expr1,
1964 Expr *expr2, SourceLocation RPLoc);
1966 // __builtin_va_arg(expr, type)
1967 ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1968 Expr *expr, ParsedType type,
1969 SourceLocation RPLoc);
1970 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc,
1971 Expr *expr, TypeSourceInfo *TInfo,
1972 SourceLocation RPLoc);
1974 // __null
1975 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1977 //===------------------------- "Block" Extension ------------------------===//
1979 /// ActOnBlockStart - This callback is invoked when a block literal is
1980 /// started.
1981 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1983 /// ActOnBlockArguments - This callback allows processing of block arguments.
1984 /// If there are no arguments, this is still invoked.
1985 void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
1987 /// ActOnBlockError - If there is an error parsing a block, this callback
1988 /// is invoked to pop the information about the block from the action impl.
1989 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1991 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1992 /// literal was successfully completed. ^(int x){...}
1993 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc,
1994 Stmt *Body, Scope *CurScope);
1996 //===---------------------------- C++ Features --------------------------===//
1998 // Act on C++ namespaces
1999 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
2000 SourceLocation IdentLoc,
2001 IdentifierInfo *Ident,
2002 SourceLocation LBrace,
2003 AttributeList *AttrList);
2004 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
2006 NamespaceDecl *getStdNamespace() const;
2007 NamespaceDecl *getOrCreateStdNamespace();
2009 CXXRecordDecl *getStdBadAlloc() const;
2011 Decl *ActOnUsingDirective(Scope *CurScope,
2012 SourceLocation UsingLoc,
2013 SourceLocation NamespcLoc,
2014 CXXScopeSpec &SS,
2015 SourceLocation IdentLoc,
2016 IdentifierInfo *NamespcName,
2017 AttributeList *AttrList);
2019 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
2021 Decl *ActOnNamespaceAliasDef(Scope *CurScope,
2022 SourceLocation NamespaceLoc,
2023 SourceLocation AliasLoc,
2024 IdentifierInfo *Alias,
2025 CXXScopeSpec &SS,
2026 SourceLocation IdentLoc,
2027 IdentifierInfo *Ident);
2029 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
2030 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
2031 const LookupResult &PreviousDecls);
2032 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
2033 NamedDecl *Target);
2035 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
2036 bool isTypeName,
2037 const CXXScopeSpec &SS,
2038 SourceLocation NameLoc,
2039 const LookupResult &Previous);
2040 bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
2041 const CXXScopeSpec &SS,
2042 SourceLocation NameLoc);
2044 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
2045 SourceLocation UsingLoc,
2046 CXXScopeSpec &SS,
2047 const DeclarationNameInfo &NameInfo,
2048 AttributeList *AttrList,
2049 bool IsInstantiation,
2050 bool IsTypeName,
2051 SourceLocation TypenameLoc);
2053 Decl *ActOnUsingDeclaration(Scope *CurScope,
2054 AccessSpecifier AS,
2055 bool HasUsingKeyword,
2056 SourceLocation UsingLoc,
2057 CXXScopeSpec &SS,
2058 UnqualifiedId &Name,
2059 AttributeList *AttrList,
2060 bool IsTypeName,
2061 SourceLocation TypenameLoc);
2063 /// AddCXXDirectInitializerToDecl - This action is called immediately after
2064 /// ActOnDeclarator, when a C++ direct initializer is present.
2065 /// e.g: "int x(1);"
2066 void AddCXXDirectInitializerToDecl(Decl *Dcl,
2067 SourceLocation LParenLoc,
2068 MultiExprArg Exprs,
2069 SourceLocation RParenLoc);
2071 /// InitializeVarWithConstructor - Creates an CXXConstructExpr
2072 /// and sets it as the initializer for the the passed in VarDecl.
2073 bool InitializeVarWithConstructor(VarDecl *VD,
2074 CXXConstructorDecl *Constructor,
2075 MultiExprArg Exprs);
2077 /// BuildCXXConstructExpr - Creates a complete call to a constructor,
2078 /// including handling of its default argument expressions.
2080 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
2081 ExprResult
2082 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2083 CXXConstructorDecl *Constructor, MultiExprArg Exprs,
2084 bool RequiresZeroInit, unsigned ConstructKind,
2085 SourceRange ParenRange);
2087 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
2088 // the constructor can be elidable?
2089 ExprResult
2090 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2091 CXXConstructorDecl *Constructor, bool Elidable,
2092 MultiExprArg Exprs, bool RequiresZeroInit,
2093 unsigned ConstructKind,
2094 SourceRange ParenRange);
2096 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
2097 /// the default expr if needed.
2098 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
2099 FunctionDecl *FD,
2100 ParmVarDecl *Param);
2102 /// FinalizeVarWithDestructor - Prepare for calling destructor on the
2103 /// constructed variable.
2104 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
2106 /// \brief Declare the implicit default constructor for the given class.
2108 /// \param ClassDecl The class declaration into which the implicit
2109 /// default constructor will be added.
2111 /// \returns The implicitly-declared default constructor.
2112 CXXConstructorDecl *DeclareImplicitDefaultConstructor(
2113 CXXRecordDecl *ClassDecl);
2115 /// DefineImplicitDefaultConstructor - Checks for feasibility of
2116 /// defining this constructor as the default constructor.
2117 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
2118 CXXConstructorDecl *Constructor);
2120 /// \brief Declare the implicit destructor for the given class.
2122 /// \param ClassDecl The class declaration into which the implicit
2123 /// destructor will be added.
2125 /// \returns The implicitly-declared destructor.
2126 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
2128 /// DefineImplicitDestructor - Checks for feasibility of
2129 /// defining this destructor as the default destructor.
2130 void DefineImplicitDestructor(SourceLocation CurrentLocation,
2131 CXXDestructorDecl *Destructor);
2133 /// \brief Declare the implicit copy constructor for the given class.
2135 /// \param S The scope of the class, which may be NULL if this is a
2136 /// template instantiation.
2138 /// \param ClassDecl The class declaration into which the implicit
2139 /// copy constructor will be added.
2141 /// \returns The implicitly-declared copy constructor.
2142 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
2144 /// DefineImplicitCopyConstructor - Checks for feasibility of
2145 /// defining this constructor as the copy constructor.
2146 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
2147 CXXConstructorDecl *Constructor,
2148 unsigned TypeQuals);
2150 /// \brief Declare the implicit copy assignment operator for the given class.
2152 /// \param S The scope of the class, which may be NULL if this is a
2153 /// template instantiation.
2155 /// \param ClassDecl The class declaration into which the implicit
2156 /// copy-assignment operator will be added.
2158 /// \returns The implicitly-declared copy assignment operator.
2159 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
2161 /// \brief Defined an implicitly-declared copy assignment operator.
2162 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
2163 CXXMethodDecl *MethodDecl);
2165 /// \brief Force the declaration of any implicitly-declared members of this
2166 /// class.
2167 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
2169 /// MaybeBindToTemporary - If the passed in expression has a record type with
2170 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
2171 /// it simply returns the passed in expression.
2172 ExprResult MaybeBindToTemporary(Expr *E);
2174 bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
2175 MultiExprArg ArgsPtr,
2176 SourceLocation Loc,
2177 ASTOwningVector<Expr*> &ConvertedArgs);
2179 ParsedType getDestructorName(SourceLocation TildeLoc,
2180 IdentifierInfo &II, SourceLocation NameLoc,
2181 Scope *S, CXXScopeSpec &SS,
2182 ParsedType ObjectType,
2183 bool EnteringContext);
2185 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
2186 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
2187 tok::TokenKind Kind,
2188 SourceLocation LAngleBracketLoc,
2189 ParsedType Ty,
2190 SourceLocation RAngleBracketLoc,
2191 SourceLocation LParenLoc,
2192 Expr *E,
2193 SourceLocation RParenLoc);
2195 ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
2196 tok::TokenKind Kind,
2197 TypeSourceInfo *Ty,
2198 Expr *E,
2199 SourceRange AngleBrackets,
2200 SourceRange Parens);
2202 ExprResult BuildCXXTypeId(QualType TypeInfoType,
2203 SourceLocation TypeidLoc,
2204 TypeSourceInfo *Operand,
2205 SourceLocation RParenLoc);
2206 ExprResult BuildCXXTypeId(QualType TypeInfoType,
2207 SourceLocation TypeidLoc,
2208 Expr *Operand,
2209 SourceLocation RParenLoc);
2211 /// ActOnCXXTypeid - Parse typeid( something ).
2212 ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
2213 SourceLocation LParenLoc, bool isType,
2214 void *TyOrExpr,
2215 SourceLocation RParenLoc);
2217 ExprResult BuildCXXUuidof(QualType TypeInfoType,
2218 SourceLocation TypeidLoc,
2219 TypeSourceInfo *Operand,
2220 SourceLocation RParenLoc);
2221 ExprResult BuildCXXUuidof(QualType TypeInfoType,
2222 SourceLocation TypeidLoc,
2223 Expr *Operand,
2224 SourceLocation RParenLoc);
2226 /// ActOnCXXUuidof - Parse __uuidof( something ).
2227 ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
2228 SourceLocation LParenLoc, bool isType,
2229 void *TyOrExpr,
2230 SourceLocation RParenLoc);
2233 //// ActOnCXXThis - Parse 'this' pointer.
2234 ExprResult ActOnCXXThis(SourceLocation ThisLoc);
2236 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
2237 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
2239 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
2240 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
2242 //// ActOnCXXThrow - Parse throw expressions.
2243 ExprResult ActOnCXXThrow(SourceLocation OpLoc, Expr *expr);
2244 bool CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E);
2246 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
2247 /// Can be interpreted either as function-style casting ("int(x)")
2248 /// or class type construction ("ClassType(x,y,z)")
2249 /// or creation of a value-initialized type ("int()").
2250 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
2251 SourceLocation LParenLoc,
2252 MultiExprArg Exprs,
2253 SourceLocation RParenLoc);
2255 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
2256 SourceLocation LParenLoc,
2257 MultiExprArg Exprs,
2258 SourceLocation RParenLoc);
2260 /// ActOnCXXNew - Parsed a C++ 'new' expression.
2261 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
2262 SourceLocation PlacementLParen,
2263 MultiExprArg PlacementArgs,
2264 SourceLocation PlacementRParen,
2265 SourceRange TypeIdParens, Declarator &D,
2266 SourceLocation ConstructorLParen,
2267 MultiExprArg ConstructorArgs,
2268 SourceLocation ConstructorRParen);
2269 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
2270 SourceLocation PlacementLParen,
2271 MultiExprArg PlacementArgs,
2272 SourceLocation PlacementRParen,
2273 SourceRange TypeIdParens,
2274 QualType AllocType,
2275 TypeSourceInfo *AllocTypeInfo,
2276 Expr *ArraySize,
2277 SourceLocation ConstructorLParen,
2278 MultiExprArg ConstructorArgs,
2279 SourceLocation ConstructorRParen);
2281 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
2282 SourceRange R);
2283 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
2284 bool UseGlobal, QualType AllocType, bool IsArray,
2285 Expr **PlaceArgs, unsigned NumPlaceArgs,
2286 FunctionDecl *&OperatorNew,
2287 FunctionDecl *&OperatorDelete);
2288 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
2289 DeclarationName Name, Expr** Args,
2290 unsigned NumArgs, DeclContext *Ctx,
2291 bool AllowMissing, FunctionDecl *&Operator);
2292 void DeclareGlobalNewDelete();
2293 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
2294 QualType Argument,
2295 bool addMallocAttr = false);
2297 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
2298 DeclarationName Name, FunctionDecl* &Operator);
2300 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
2301 ExprResult ActOnCXXDelete(SourceLocation StartLoc,
2302 bool UseGlobal, bool ArrayForm,
2303 Expr *Operand);
2305 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
2306 ExprResult CheckConditionVariable(VarDecl *ConditionVar,
2307 SourceLocation StmtLoc,
2308 bool ConvertToBoolean);
2310 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
2311 Expr *Operand, SourceLocation RParen);
2312 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
2313 SourceLocation RParen);
2315 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
2316 /// pseudo-functions.
2317 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
2318 SourceLocation KWLoc,
2319 ParsedType Ty,
2320 SourceLocation RParen);
2322 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT,
2323 SourceLocation KWLoc,
2324 TypeSourceInfo *T,
2325 SourceLocation RParen);
2327 ExprResult ActOnStartCXXMemberReference(Scope *S,
2328 Expr *Base,
2329 SourceLocation OpLoc,
2330 tok::TokenKind OpKind,
2331 ParsedType &ObjectType,
2332 bool &MayBePseudoDestructor);
2334 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr);
2336 ExprResult BuildPseudoDestructorExpr(Expr *Base,
2337 SourceLocation OpLoc,
2338 tok::TokenKind OpKind,
2339 const CXXScopeSpec &SS,
2340 TypeSourceInfo *ScopeType,
2341 SourceLocation CCLoc,
2342 SourceLocation TildeLoc,
2343 PseudoDestructorTypeStorage DestroyedType,
2344 bool HasTrailingLParen);
2346 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
2347 SourceLocation OpLoc,
2348 tok::TokenKind OpKind,
2349 CXXScopeSpec &SS,
2350 UnqualifiedId &FirstTypeName,
2351 SourceLocation CCLoc,
2352 SourceLocation TildeLoc,
2353 UnqualifiedId &SecondTypeName,
2354 bool HasTrailingLParen);
2356 /// MaybeCreateCXXExprWithTemporaries - If the list of temporaries is
2357 /// non-empty, will create a new CXXExprWithTemporaries expression.
2358 /// Otherwise, just returs the passed in expression.
2359 Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr);
2360 Stmt *MaybeCreateCXXStmtWithTemporaries(Stmt *SubStmt);
2361 ExprResult MaybeCreateCXXExprWithTemporaries(ExprResult SubExpr);
2362 FullExpr CreateFullExpr(Expr *SubExpr);
2364 ExprResult ActOnFinishFullExpr(Expr *Expr);
2365 StmtResult ActOnFinishFullStmt(Stmt *Stmt);
2367 // Marks SS invalid if it represents an incomplete type.
2368 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
2370 DeclContext *computeDeclContext(QualType T);
2371 DeclContext *computeDeclContext(const CXXScopeSpec &SS,
2372 bool EnteringContext = false);
2373 bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
2374 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
2375 bool isUnknownSpecialization(const CXXScopeSpec &SS);
2377 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
2378 /// global scope ('::').
2379 NestedNameSpecifier *
2380 ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc);
2382 bool isAcceptableNestedNameSpecifier(NamedDecl *SD);
2383 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
2385 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
2386 SourceLocation IdLoc,
2387 IdentifierInfo &II,
2388 ParsedType ObjectType);
2390 NestedNameSpecifier *BuildCXXNestedNameSpecifier(Scope *S,
2391 CXXScopeSpec &SS,
2392 SourceLocation IdLoc,
2393 SourceLocation CCLoc,
2394 IdentifierInfo &II,
2395 QualType ObjectType,
2396 NamedDecl *ScopeLookupResult,
2397 bool EnteringContext,
2398 bool ErrorRecoveryLookup);
2400 NestedNameSpecifier *ActOnCXXNestedNameSpecifier(Scope *S,
2401 CXXScopeSpec &SS,
2402 SourceLocation IdLoc,
2403 SourceLocation CCLoc,
2404 IdentifierInfo &II,
2405 ParsedType ObjectType,
2406 bool EnteringContext);
2408 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
2409 IdentifierInfo &II,
2410 ParsedType ObjectType,
2411 bool EnteringContext);
2413 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
2414 /// nested-name-specifier that involves a template-id, e.g.,
2415 /// "foo::bar<int, float>::", and now we need to build a scope
2416 /// specifier. \p SS is empty or the previously parsed nested-name
2417 /// part ("foo::"), \p Type is the already-parsed class template
2418 /// specialization (or other template-id that names a type), \p
2419 /// TypeRange is the source range where the type is located, and \p
2420 /// CCLoc is the location of the trailing '::'.
2421 CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
2422 const CXXScopeSpec &SS,
2423 ParsedType Type,
2424 SourceRange TypeRange,
2425 SourceLocation CCLoc);
2427 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
2429 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
2430 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
2431 /// After this method is called, according to [C++ 3.4.3p3], names should be
2432 /// looked up in the declarator-id's scope, until the declarator is parsed and
2433 /// ActOnCXXExitDeclaratorScope is called.
2434 /// The 'SS' should be a non-empty valid CXXScopeSpec.
2435 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
2437 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
2438 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
2439 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
2440 /// Used to indicate that names should revert to being looked up in the
2441 /// defining scope.
2442 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
2444 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
2445 /// initializer for the declaration 'Dcl'.
2446 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
2447 /// static data member of class X, names should be looked up in the scope of
2448 /// class X.
2449 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
2451 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
2452 /// initializer for the declaration 'Dcl'.
2453 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
2455 // ParseObjCStringLiteral - Parse Objective-C string literals.
2456 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
2457 Expr **Strings,
2458 unsigned NumStrings);
2460 Expr *BuildObjCEncodeExpression(SourceLocation AtLoc,
2461 TypeSourceInfo *EncodedTypeInfo,
2462 SourceLocation RParenLoc);
2463 CXXMemberCallExpr *BuildCXXMemberCallExpr(Expr *Exp,
2464 NamedDecl *FoundDecl,
2465 CXXMethodDecl *Method);
2467 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
2468 SourceLocation EncodeLoc,
2469 SourceLocation LParenLoc,
2470 ParsedType Ty,
2471 SourceLocation RParenLoc);
2473 // ParseObjCSelectorExpression - Build selector expression for @selector
2474 ExprResult ParseObjCSelectorExpression(Selector Sel,
2475 SourceLocation AtLoc,
2476 SourceLocation SelLoc,
2477 SourceLocation LParenLoc,
2478 SourceLocation RParenLoc);
2480 // ParseObjCProtocolExpression - Build protocol expression for @protocol
2481 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
2482 SourceLocation AtLoc,
2483 SourceLocation ProtoLoc,
2484 SourceLocation LParenLoc,
2485 SourceLocation RParenLoc);
2487 //===--------------------------------------------------------------------===//
2488 // C++ Declarations
2490 Decl *ActOnStartLinkageSpecification(Scope *S,
2491 SourceLocation ExternLoc,
2492 SourceLocation LangLoc,
2493 llvm::StringRef Lang,
2494 SourceLocation LBraceLoc);
2495 Decl *ActOnFinishLinkageSpecification(Scope *S,
2496 Decl *LinkageSpec,
2497 SourceLocation RBraceLoc);
2500 //===--------------------------------------------------------------------===//
2501 // C++ Classes
2503 bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
2504 const CXXScopeSpec *SS = 0);
2506 Decl *ActOnAccessSpecifier(AccessSpecifier Access,
2507 SourceLocation ASLoc,
2508 SourceLocation ColonLoc);
2510 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
2511 Declarator &D,
2512 MultiTemplateParamsArg TemplateParameterLists,
2513 Expr *BitfieldWidth,
2514 Expr *Init, bool IsDefinition,
2515 bool Deleted = false);
2517 MemInitResult ActOnMemInitializer(Decl *ConstructorD,
2518 Scope *S,
2519 CXXScopeSpec &SS,
2520 IdentifierInfo *MemberOrBase,
2521 ParsedType TemplateTypeTy,
2522 SourceLocation IdLoc,
2523 SourceLocation LParenLoc,
2524 Expr **Args, unsigned NumArgs,
2525 SourceLocation RParenLoc);
2527 MemInitResult BuildMemberInitializer(FieldDecl *Member, Expr **Args,
2528 unsigned NumArgs, SourceLocation IdLoc,
2529 SourceLocation LParenLoc,
2530 SourceLocation RParenLoc);
2532 MemInitResult BuildBaseInitializer(QualType BaseType,
2533 TypeSourceInfo *BaseTInfo,
2534 Expr **Args, unsigned NumArgs,
2535 SourceLocation LParenLoc,
2536 SourceLocation RParenLoc,
2537 CXXRecordDecl *ClassDecl);
2539 bool SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor,
2540 CXXBaseOrMemberInitializer **Initializers,
2541 unsigned NumInitializers, bool AnyErrors);
2543 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
2546 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
2547 /// mark all the non-trivial destructors of its members and bases as
2548 /// referenced.
2549 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
2550 CXXRecordDecl *Record);
2552 /// \brief The list of classes whose vtables have been used within
2553 /// this translation unit, and the source locations at which the
2554 /// first use occurred.
2555 llvm::SmallVector<std::pair<CXXRecordDecl *, SourceLocation>, 16>
2556 VTableUses;
2558 /// \brief The set of classes whose vtables have been used within
2559 /// this translation unit, and a bit that will be true if the vtable is
2560 /// required to be emitted (otherwise, it should be emitted only if needed
2561 /// by code generation).
2562 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
2564 /// \brief A list of all of the dynamic classes in this translation
2565 /// unit.
2566 llvm::SmallVector<CXXRecordDecl *, 16> DynamicClasses;
2568 /// \brief Note that the vtable for the given class was used at the
2569 /// given location.
2570 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
2571 bool DefinitionRequired = false);
2573 /// MarkVirtualMembersReferenced - Will mark all members of the given
2574 /// CXXRecordDecl referenced.
2575 void MarkVirtualMembersReferenced(SourceLocation Loc,
2576 const CXXRecordDecl *RD);
2578 /// \brief Define all of the vtables that have been used in this
2579 /// translation unit and reference any virtual members used by those
2580 /// vtables.
2582 /// \returns true if any work was done, false otherwise.
2583 bool DefineUsedVTables();
2585 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
2587 void ActOnMemInitializers(Decl *ConstructorDecl,
2588 SourceLocation ColonLoc,
2589 MemInitTy **MemInits, unsigned NumMemInits,
2590 bool AnyErrors);
2592 void CheckCompletedCXXClass(CXXRecordDecl *Record);
2593 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
2594 Decl *TagDecl,
2595 SourceLocation LBrac,
2596 SourceLocation RBrac,
2597 AttributeList *AttrList);
2599 void ActOnReenterTemplateScope(Scope *S, Decl *Template);
2600 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
2601 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
2602 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
2603 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
2604 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
2606 Decl *ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
2607 Expr *AssertExpr,
2608 Expr *AssertMessageExpr);
2610 FriendDecl *CheckFriendTypeDecl(SourceLocation FriendLoc,
2611 TypeSourceInfo *TSInfo);
2612 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
2613 MultiTemplateParamsArg TemplateParams);
2614 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition,
2615 MultiTemplateParamsArg TemplateParams);
2617 QualType CheckConstructorDeclarator(Declarator &D, QualType R,
2618 StorageClass& SC);
2619 void CheckConstructor(CXXConstructorDecl *Constructor);
2620 QualType CheckDestructorDeclarator(Declarator &D, QualType R,
2621 StorageClass& SC);
2622 bool CheckDestructor(CXXDestructorDecl *Destructor);
2623 void CheckConversionDeclarator(Declarator &D, QualType &R,
2624 StorageClass& SC);
2625 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
2627 //===--------------------------------------------------------------------===//
2628 // C++ Derived Classes
2631 /// ActOnBaseSpecifier - Parsed a base specifier
2632 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
2633 SourceRange SpecifierRange,
2634 bool Virtual, AccessSpecifier Access,
2635 TypeSourceInfo *TInfo);
2637 BaseResult ActOnBaseSpecifier(Decl *classdecl,
2638 SourceRange SpecifierRange,
2639 bool Virtual, AccessSpecifier Access,
2640 ParsedType basetype, SourceLocation
2641 BaseLoc);
2643 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
2644 unsigned NumBases);
2645 void ActOnBaseSpecifiers(Decl *ClassDecl, BaseTy **Bases, unsigned NumBases);
2647 bool IsDerivedFrom(QualType Derived, QualType Base);
2648 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths);
2650 // FIXME: I don't like this name.
2651 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
2653 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath);
2655 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
2656 SourceLocation Loc, SourceRange Range,
2657 CXXCastPath *BasePath = 0,
2658 bool IgnoreAccess = false);
2659 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
2660 unsigned InaccessibleBaseID,
2661 unsigned AmbigiousBaseConvID,
2662 SourceLocation Loc, SourceRange Range,
2663 DeclarationName Name,
2664 CXXCastPath *BasePath);
2666 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
2668 /// CheckOverridingFunctionReturnType - Checks whether the return types are
2669 /// covariant, according to C++ [class.virtual]p5.
2670 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
2671 const CXXMethodDecl *Old);
2673 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
2674 /// spec is a subset of base spec.
2675 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
2676 const CXXMethodDecl *Old);
2678 /// CheckOverridingFunctionAttributes - Checks whether attributes are
2679 /// incompatible or prevent overriding.
2680 bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
2681 const CXXMethodDecl *Old);
2683 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
2685 //===--------------------------------------------------------------------===//
2686 // C++ Access Control
2689 enum AccessResult {
2690 AR_accessible,
2691 AR_inaccessible,
2692 AR_dependent,
2693 AR_delayed
2696 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
2697 NamedDecl *PrevMemberDecl,
2698 AccessSpecifier LexicalAS);
2700 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
2701 DeclAccessPair FoundDecl);
2702 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
2703 DeclAccessPair FoundDecl);
2704 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
2705 SourceRange PlacementRange,
2706 CXXRecordDecl *NamingClass,
2707 DeclAccessPair FoundDecl);
2708 AccessResult CheckConstructorAccess(SourceLocation Loc,
2709 CXXConstructorDecl *D,
2710 const InitializedEntity &Entity,
2711 AccessSpecifier Access,
2712 bool IsCopyBindingRefToTemp = false);
2713 AccessResult CheckDestructorAccess(SourceLocation Loc,
2714 CXXDestructorDecl *Dtor,
2715 const PartialDiagnostic &PDiag);
2716 AccessResult CheckDirectMemberAccess(SourceLocation Loc,
2717 NamedDecl *D,
2718 const PartialDiagnostic &PDiag);
2719 AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
2720 Expr *ObjectExpr,
2721 Expr *ArgExpr,
2722 DeclAccessPair FoundDecl);
2723 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
2724 DeclAccessPair FoundDecl);
2725 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
2726 QualType Base, QualType Derived,
2727 const CXXBasePath &Path,
2728 unsigned DiagID,
2729 bool ForceCheck = false,
2730 bool ForceUnprivileged = false);
2731 void CheckLookupAccess(const LookupResult &R);
2733 void HandleDependentAccessCheck(const DependentDiagnostic &DD,
2734 const MultiLevelTemplateArgumentList &TemplateArgs);
2735 void PerformDependentDiagnostics(const DeclContext *Pattern,
2736 const MultiLevelTemplateArgumentList &TemplateArgs);
2738 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
2740 /// A flag to suppress access checking.
2741 bool SuppressAccessChecking;
2743 void ActOnStartSuppressingAccessChecks();
2744 void ActOnStopSuppressingAccessChecks();
2746 enum AbstractDiagSelID {
2747 AbstractNone = -1,
2748 AbstractReturnType,
2749 AbstractParamType,
2750 AbstractVariableType,
2751 AbstractFieldType,
2752 AbstractArrayType
2755 bool RequireNonAbstractType(SourceLocation Loc, QualType T,
2756 const PartialDiagnostic &PD);
2757 void DiagnoseAbstractType(const CXXRecordDecl *RD);
2759 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
2760 AbstractDiagSelID SelID = AbstractNone);
2762 //===--------------------------------------------------------------------===//
2763 // C++ Overloaded Operators [C++ 13.5]
2766 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
2768 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
2770 //===--------------------------------------------------------------------===//
2771 // C++ Templates [C++ 14]
2773 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
2774 QualType ObjectType, bool EnteringContext,
2775 bool &MemberOfUnknownSpecialization);
2777 TemplateNameKind isTemplateName(Scope *S,
2778 CXXScopeSpec &SS,
2779 bool hasTemplateKeyword,
2780 UnqualifiedId &Name,
2781 ParsedType ObjectType,
2782 bool EnteringContext,
2783 TemplateTy &Template,
2784 bool &MemberOfUnknownSpecialization);
2786 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
2787 SourceLocation IILoc,
2788 Scope *S,
2789 const CXXScopeSpec *SS,
2790 TemplateTy &SuggestedTemplate,
2791 TemplateNameKind &SuggestedKind);
2793 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
2794 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
2796 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
2797 SourceLocation EllipsisLoc,
2798 SourceLocation KeyLoc,
2799 IdentifierInfo *ParamName,
2800 SourceLocation ParamNameLoc,
2801 unsigned Depth, unsigned Position,
2802 SourceLocation EqualLoc,
2803 ParsedType DefaultArg);
2805 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
2806 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
2807 unsigned Depth,
2808 unsigned Position,
2809 SourceLocation EqualLoc,
2810 Expr *DefaultArg);
2811 Decl *ActOnTemplateTemplateParameter(Scope *S,
2812 SourceLocation TmpLoc,
2813 TemplateParamsTy *Params,
2814 IdentifierInfo *ParamName,
2815 SourceLocation ParamNameLoc,
2816 unsigned Depth,
2817 unsigned Position,
2818 SourceLocation EqualLoc,
2819 const ParsedTemplateArgument &DefaultArg);
2821 TemplateParamsTy *
2822 ActOnTemplateParameterList(unsigned Depth,
2823 SourceLocation ExportLoc,
2824 SourceLocation TemplateLoc,
2825 SourceLocation LAngleLoc,
2826 Decl **Params, unsigned NumParams,
2827 SourceLocation RAngleLoc);
2829 /// \brief The context in which we are checking a template parameter
2830 /// list.
2831 enum TemplateParamListContext {
2832 TPC_ClassTemplate,
2833 TPC_FunctionTemplate,
2834 TPC_ClassTemplateMember,
2835 TPC_FriendFunctionTemplate
2838 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
2839 TemplateParameterList *OldParams,
2840 TemplateParamListContext TPC);
2841 TemplateParameterList *
2842 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
2843 const CXXScopeSpec &SS,
2844 TemplateParameterList **ParamLists,
2845 unsigned NumParamLists,
2846 bool IsFriend,
2847 bool &IsExplicitSpecialization,
2848 bool &Invalid);
2850 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
2851 SourceLocation KWLoc, CXXScopeSpec &SS,
2852 IdentifierInfo *Name, SourceLocation NameLoc,
2853 AttributeList *Attr,
2854 TemplateParameterList *TemplateParams,
2855 AccessSpecifier AS);
2857 void translateTemplateArguments(const ASTTemplateArgsPtr &In,
2858 TemplateArgumentListInfo &Out);
2860 QualType CheckTemplateIdType(TemplateName Template,
2861 SourceLocation TemplateLoc,
2862 const TemplateArgumentListInfo &TemplateArgs);
2864 TypeResult
2865 ActOnTemplateIdType(TemplateTy Template, SourceLocation TemplateLoc,
2866 SourceLocation LAngleLoc,
2867 ASTTemplateArgsPtr TemplateArgs,
2868 SourceLocation RAngleLoc);
2870 TypeResult ActOnTagTemplateIdType(TypeResult Type,
2871 TagUseKind TUK,
2872 TypeSpecifierType TagSpec,
2873 SourceLocation TagLoc);
2875 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
2876 LookupResult &R,
2877 bool RequiresADL,
2878 const TemplateArgumentListInfo &TemplateArgs);
2879 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
2880 const DeclarationNameInfo &NameInfo,
2881 const TemplateArgumentListInfo &TemplateArgs);
2883 TemplateNameKind ActOnDependentTemplateName(Scope *S,
2884 SourceLocation TemplateKWLoc,
2885 CXXScopeSpec &SS,
2886 UnqualifiedId &Name,
2887 ParsedType ObjectType,
2888 bool EnteringContext,
2889 TemplateTy &Template);
2891 bool CheckClassTemplatePartialSpecializationArgs(
2892 TemplateParameterList *TemplateParams,
2893 llvm::SmallVectorImpl<TemplateArgument> &TemplateArgs,
2894 bool &MirrorsPrimaryTemplate);
2896 DeclResult
2897 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
2898 SourceLocation KWLoc,
2899 CXXScopeSpec &SS,
2900 TemplateTy Template,
2901 SourceLocation TemplateNameLoc,
2902 SourceLocation LAngleLoc,
2903 ASTTemplateArgsPtr TemplateArgs,
2904 SourceLocation RAngleLoc,
2905 AttributeList *Attr,
2906 MultiTemplateParamsArg TemplateParameterLists);
2908 Decl *ActOnTemplateDeclarator(Scope *S,
2909 MultiTemplateParamsArg TemplateParameterLists,
2910 Declarator &D);
2912 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope,
2913 MultiTemplateParamsArg TemplateParameterLists,
2914 Declarator &D);
2916 bool
2917 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
2918 TemplateSpecializationKind NewTSK,
2919 NamedDecl *PrevDecl,
2920 TemplateSpecializationKind PrevTSK,
2921 SourceLocation PrevPtOfInstantiation,
2922 bool &SuppressNew);
2924 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
2925 const TemplateArgumentListInfo &ExplicitTemplateArgs,
2926 LookupResult &Previous);
2928 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
2929 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2930 LookupResult &Previous);
2931 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
2933 DeclResult
2934 ActOnExplicitInstantiation(Scope *S,
2935 SourceLocation ExternLoc,
2936 SourceLocation TemplateLoc,
2937 unsigned TagSpec,
2938 SourceLocation KWLoc,
2939 const CXXScopeSpec &SS,
2940 TemplateTy Template,
2941 SourceLocation TemplateNameLoc,
2942 SourceLocation LAngleLoc,
2943 ASTTemplateArgsPtr TemplateArgs,
2944 SourceLocation RAngleLoc,
2945 AttributeList *Attr);
2947 DeclResult
2948 ActOnExplicitInstantiation(Scope *S,
2949 SourceLocation ExternLoc,
2950 SourceLocation TemplateLoc,
2951 unsigned TagSpec,
2952 SourceLocation KWLoc,
2953 CXXScopeSpec &SS,
2954 IdentifierInfo *Name,
2955 SourceLocation NameLoc,
2956 AttributeList *Attr);
2958 DeclResult ActOnExplicitInstantiation(Scope *S,
2959 SourceLocation ExternLoc,
2960 SourceLocation TemplateLoc,
2961 Declarator &D);
2963 TemplateArgumentLoc
2964 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
2965 SourceLocation TemplateLoc,
2966 SourceLocation RAngleLoc,
2967 Decl *Param,
2968 llvm::SmallVectorImpl<TemplateArgument> &Converted);
2970 /// \brief Specifies the context in which a particular template
2971 /// argument is being checked.
2972 enum CheckTemplateArgumentKind {
2973 /// \brief The template argument was specified in the code or was
2974 /// instantiated with some deduced template arguments.
2975 CTAK_Specified,
2977 /// \brief The template argument was deduced via template argument
2978 /// deduction.
2979 CTAK_Deduced,
2981 /// \brief The template argument was deduced from an array bound
2982 /// via template argument deduction.
2983 CTAK_DeducedFromArrayBound
2986 bool CheckTemplateArgument(NamedDecl *Param,
2987 const TemplateArgumentLoc &Arg,
2988 TemplateDecl *Template,
2989 SourceLocation TemplateLoc,
2990 SourceLocation RAngleLoc,
2991 llvm::SmallVectorImpl<TemplateArgument> &Converted,
2992 CheckTemplateArgumentKind CTAK = CTAK_Specified);
2994 bool CheckTemplateArgumentList(TemplateDecl *Template,
2995 SourceLocation TemplateLoc,
2996 const TemplateArgumentListInfo &TemplateArgs,
2997 bool PartialTemplateArgs,
2998 llvm::SmallVectorImpl<TemplateArgument> &Converted);
3000 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
3001 const TemplateArgumentLoc &Arg,
3002 llvm::SmallVectorImpl<TemplateArgument> &Converted);
3004 bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
3005 TypeSourceInfo *Arg);
3006 bool CheckTemplateArgumentPointerToMember(Expr *Arg,
3007 TemplateArgument &Converted);
3008 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
3009 QualType InstantiatedParamType, Expr *&Arg,
3010 TemplateArgument &Converted,
3011 CheckTemplateArgumentKind CTAK = CTAK_Specified);
3012 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
3013 const TemplateArgumentLoc &Arg);
3015 ExprResult
3016 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
3017 QualType ParamType,
3018 SourceLocation Loc);
3019 ExprResult
3020 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
3021 SourceLocation Loc);
3023 /// \brief Enumeration describing how template parameter lists are compared
3024 /// for equality.
3025 enum TemplateParameterListEqualKind {
3026 /// \brief We are matching the template parameter lists of two templates
3027 /// that might be redeclarations.
3029 /// \code
3030 /// template<typename T> struct X;
3031 /// template<typename T> struct X;
3032 /// \endcode
3033 TPL_TemplateMatch,
3035 /// \brief We are matching the template parameter lists of two template
3036 /// template parameters as part of matching the template parameter lists
3037 /// of two templates that might be redeclarations.
3039 /// \code
3040 /// template<template<int I> class TT> struct X;
3041 /// template<template<int Value> class Other> struct X;
3042 /// \endcode
3043 TPL_TemplateTemplateParmMatch,
3045 /// \brief We are matching the template parameter lists of a template
3046 /// template argument against the template parameter lists of a template
3047 /// template parameter.
3049 /// \code
3050 /// template<template<int Value> class Metafun> struct X;
3051 /// template<int Value> struct integer_c;
3052 /// X<integer_c> xic;
3053 /// \endcode
3054 TPL_TemplateTemplateArgumentMatch
3057 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
3058 TemplateParameterList *Old,
3059 bool Complain,
3060 TemplateParameterListEqualKind Kind,
3061 SourceLocation TemplateArgLoc
3062 = SourceLocation());
3064 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
3066 /// \brief Called when the parser has parsed a C++ typename
3067 /// specifier, e.g., "typename T::type".
3069 /// \param S The scope in which this typename type occurs.
3070 /// \param TypenameLoc the location of the 'typename' keyword
3071 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
3072 /// \param II the identifier we're retrieving (e.g., 'type' in the example).
3073 /// \param IdLoc the location of the identifier.
3074 TypeResult
3075 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
3076 const CXXScopeSpec &SS, const IdentifierInfo &II,
3077 SourceLocation IdLoc);
3079 /// \brief Called when the parser has parsed a C++ typename
3080 /// specifier that ends in a template-id, e.g.,
3081 /// "typename MetaFun::template apply<T1, T2>".
3083 /// \param S The scope in which this typename type occurs.
3084 /// \param TypenameLoc the location of the 'typename' keyword
3085 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
3086 /// \param TemplateLoc the location of the 'template' keyword, if any.
3087 /// \param Ty the type that the typename specifier refers to.
3088 TypeResult
3089 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
3090 const CXXScopeSpec &SS, SourceLocation TemplateLoc,
3091 ParsedType Ty);
3093 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
3094 NestedNameSpecifier *NNS,
3095 const IdentifierInfo &II,
3096 SourceLocation KeywordLoc,
3097 SourceRange NNSRange,
3098 SourceLocation IILoc);
3100 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
3101 SourceLocation Loc,
3102 DeclarationName Name);
3103 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
3105 ExprResult RebuildExprInCurrentInstantiation(Expr *E);
3107 std::string
3108 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
3109 const TemplateArgumentList &Args);
3111 std::string
3112 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
3113 const TemplateArgument *Args,
3114 unsigned NumArgs);
3116 /// \brief Describes the result of template argument deduction.
3118 /// The TemplateDeductionResult enumeration describes the result of
3119 /// template argument deduction, as returned from
3120 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
3121 /// structure provides additional information about the results of
3122 /// template argument deduction, e.g., the deduced template argument
3123 /// list (if successful) or the specific template parameters or
3124 /// deduced arguments that were involved in the failure.
3125 enum TemplateDeductionResult {
3126 /// \brief Template argument deduction was successful.
3127 TDK_Success = 0,
3128 /// \brief Template argument deduction exceeded the maximum template
3129 /// instantiation depth (which has already been diagnosed).
3130 TDK_InstantiationDepth,
3131 /// \brief Template argument deduction did not deduce a value
3132 /// for every template parameter.
3133 TDK_Incomplete,
3134 /// \brief Template argument deduction produced inconsistent
3135 /// deduced values for the given template parameter.
3136 TDK_Inconsistent,
3137 /// \brief Template argument deduction failed due to inconsistent
3138 /// cv-qualifiers on a template parameter type that would
3139 /// otherwise be deduced, e.g., we tried to deduce T in "const T"
3140 /// but were given a non-const "X".
3141 TDK_Underqualified,
3142 /// \brief Substitution of the deduced template argument values
3143 /// resulted in an error.
3144 TDK_SubstitutionFailure,
3145 /// \brief Substitution of the deduced template argument values
3146 /// into a non-deduced context produced a type or value that
3147 /// produces a type that does not match the original template
3148 /// arguments provided.
3149 TDK_NonDeducedMismatch,
3150 /// \brief When performing template argument deduction for a function
3151 /// template, there were too many call arguments.
3152 TDK_TooManyArguments,
3153 /// \brief When performing template argument deduction for a function
3154 /// template, there were too few call arguments.
3155 TDK_TooFewArguments,
3156 /// \brief The explicitly-specified template arguments were not valid
3157 /// template arguments for the given template.
3158 TDK_InvalidExplicitArguments,
3159 /// \brief The arguments included an overloaded function name that could
3160 /// not be resolved to a suitable function.
3161 TDK_FailedOverloadResolution
3164 TemplateDeductionResult
3165 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
3166 const TemplateArgumentList &TemplateArgs,
3167 sema::TemplateDeductionInfo &Info);
3169 TemplateDeductionResult
3170 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3171 const TemplateArgumentListInfo &ExplicitTemplateArgs,
3172 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3173 llvm::SmallVectorImpl<QualType> &ParamTypes,
3174 QualType *FunctionType,
3175 sema::TemplateDeductionInfo &Info);
3177 TemplateDeductionResult
3178 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
3179 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3180 unsigned NumExplicitlySpecified,
3181 FunctionDecl *&Specialization,
3182 sema::TemplateDeductionInfo &Info);
3184 TemplateDeductionResult
3185 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3186 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3187 Expr **Args, unsigned NumArgs,
3188 FunctionDecl *&Specialization,
3189 sema::TemplateDeductionInfo &Info);
3191 TemplateDeductionResult
3192 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3193 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3194 QualType ArgFunctionType,
3195 FunctionDecl *&Specialization,
3196 sema::TemplateDeductionInfo &Info);
3198 TemplateDeductionResult
3199 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3200 QualType ToType,
3201 CXXConversionDecl *&Specialization,
3202 sema::TemplateDeductionInfo &Info);
3204 TemplateDeductionResult
3205 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3206 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3207 FunctionDecl *&Specialization,
3208 sema::TemplateDeductionInfo &Info);
3210 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
3211 FunctionTemplateDecl *FT2,
3212 SourceLocation Loc,
3213 TemplatePartialOrderingContext TPOC);
3214 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin,
3215 UnresolvedSetIterator SEnd,
3216 TemplatePartialOrderingContext TPOC,
3217 SourceLocation Loc,
3218 const PartialDiagnostic &NoneDiag,
3219 const PartialDiagnostic &AmbigDiag,
3220 const PartialDiagnostic &CandidateDiag);
3222 ClassTemplatePartialSpecializationDecl *
3223 getMoreSpecializedPartialSpecialization(
3224 ClassTemplatePartialSpecializationDecl *PS1,
3225 ClassTemplatePartialSpecializationDecl *PS2,
3226 SourceLocation Loc);
3228 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
3229 bool OnlyDeduced,
3230 unsigned Depth,
3231 llvm::SmallVectorImpl<bool> &Used);
3232 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate,
3233 llvm::SmallVectorImpl<bool> &Deduced);
3235 //===--------------------------------------------------------------------===//
3236 // C++ Template Instantiation
3239 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D,
3240 const TemplateArgumentList *Innermost = 0,
3241 bool RelativeToPrimary = false,
3242 const FunctionDecl *Pattern = 0);
3244 /// \brief A template instantiation that is currently in progress.
3245 struct ActiveTemplateInstantiation {
3246 /// \brief The kind of template instantiation we are performing
3247 enum InstantiationKind {
3248 /// We are instantiating a template declaration. The entity is
3249 /// the declaration we're instantiating (e.g., a CXXRecordDecl).
3250 TemplateInstantiation,
3252 /// We are instantiating a default argument for a template
3253 /// parameter. The Entity is the template, and
3254 /// TemplateArgs/NumTemplateArguments provides the template
3255 /// arguments as specified.
3256 /// FIXME: Use a TemplateArgumentList
3257 DefaultTemplateArgumentInstantiation,
3259 /// We are instantiating a default argument for a function.
3260 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
3261 /// provides the template arguments as specified.
3262 DefaultFunctionArgumentInstantiation,
3264 /// We are substituting explicit template arguments provided for
3265 /// a function template. The entity is a FunctionTemplateDecl.
3266 ExplicitTemplateArgumentSubstitution,
3268 /// We are substituting template argument determined as part of
3269 /// template argument deduction for either a class template
3270 /// partial specialization or a function template. The
3271 /// Entity is either a ClassTemplatePartialSpecializationDecl or
3272 /// a FunctionTemplateDecl.
3273 DeducedTemplateArgumentSubstitution,
3275 /// We are substituting prior template arguments into a new
3276 /// template parameter. The template parameter itself is either a
3277 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
3278 PriorTemplateArgumentSubstitution,
3280 /// We are checking the validity of a default template argument that
3281 /// has been used when naming a template-id.
3282 DefaultTemplateArgumentChecking
3283 } Kind;
3285 /// \brief The point of instantiation within the source code.
3286 SourceLocation PointOfInstantiation;
3288 /// \brief The template in which we are performing the instantiation,
3289 /// for substitutions of prior template arguments.
3290 TemplateDecl *Template;
3292 /// \brief The entity that is being instantiated.
3293 uintptr_t Entity;
3295 /// \brief The list of template arguments we are substituting, if they
3296 /// are not part of the entity.
3297 const TemplateArgument *TemplateArgs;
3299 /// \brief The number of template arguments in TemplateArgs.
3300 unsigned NumTemplateArgs;
3302 /// \brief The template deduction info object associated with the
3303 /// substitution or checking of explicit or deduced template arguments.
3304 sema::TemplateDeductionInfo *DeductionInfo;
3306 /// \brief The source range that covers the construct that cause
3307 /// the instantiation, e.g., the template-id that causes a class
3308 /// template instantiation.
3309 SourceRange InstantiationRange;
3311 ActiveTemplateInstantiation()
3312 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0),
3313 NumTemplateArgs(0), DeductionInfo(0) {}
3315 /// \brief Determines whether this template is an actual instantiation
3316 /// that should be counted toward the maximum instantiation depth.
3317 bool isInstantiationRecord() const;
3319 friend bool operator==(const ActiveTemplateInstantiation &X,
3320 const ActiveTemplateInstantiation &Y) {
3321 if (X.Kind != Y.Kind)
3322 return false;
3324 if (X.Entity != Y.Entity)
3325 return false;
3327 switch (X.Kind) {
3328 case TemplateInstantiation:
3329 return true;
3331 case PriorTemplateArgumentSubstitution:
3332 case DefaultTemplateArgumentChecking:
3333 if (X.Template != Y.Template)
3334 return false;
3336 // Fall through
3338 case DefaultTemplateArgumentInstantiation:
3339 case ExplicitTemplateArgumentSubstitution:
3340 case DeducedTemplateArgumentSubstitution:
3341 case DefaultFunctionArgumentInstantiation:
3342 return X.TemplateArgs == Y.TemplateArgs;
3346 return true;
3349 friend bool operator!=(const ActiveTemplateInstantiation &X,
3350 const ActiveTemplateInstantiation &Y) {
3351 return !(X == Y);
3355 /// \brief List of active template instantiations.
3357 /// This vector is treated as a stack. As one template instantiation
3358 /// requires another template instantiation, additional
3359 /// instantiations are pushed onto the stack up to a
3360 /// user-configurable limit LangOptions::InstantiationDepth.
3361 llvm::SmallVector<ActiveTemplateInstantiation, 16>
3362 ActiveTemplateInstantiations;
3364 /// \brief The number of ActiveTemplateInstantiation entries in
3365 /// \c ActiveTemplateInstantiations that are not actual instantiations and,
3366 /// therefore, should not be counted as part of the instantiation depth.
3367 unsigned NonInstantiationEntries;
3369 /// \brief The last template from which a template instantiation
3370 /// error or warning was produced.
3372 /// This value is used to suppress printing of redundant template
3373 /// instantiation backtraces when there are multiple errors in the
3374 /// same instantiation. FIXME: Does this belong in Sema? It's tough
3375 /// to implement it anywhere else.
3376 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
3378 /// \brief The stack of calls expression undergoing template instantiation.
3380 /// The top of this stack is used by a fixit instantiating unresolved
3381 /// function calls to fix the AST to match the textual change it prints.
3382 llvm::SmallVector<CallExpr *, 8> CallsUndergoingInstantiation;
3384 /// \brief For each declaration that involved template argument deduction, the
3385 /// set of diagnostics that were suppressed during that template argument
3386 /// deduction.
3388 /// FIXME: Serialize this structure to the AST file.
3389 llvm::DenseMap<Decl *, llvm::SmallVector<PartialDiagnosticAt, 1> >
3390 SuppressedDiagnostics;
3392 /// \brief A stack object to be created when performing template
3393 /// instantiation.
3395 /// Construction of an object of type \c InstantiatingTemplate
3396 /// pushes the current instantiation onto the stack of active
3397 /// instantiations. If the size of this stack exceeds the maximum
3398 /// number of recursive template instantiations, construction
3399 /// produces an error and evaluates true.
3401 /// Destruction of this object will pop the named instantiation off
3402 /// the stack.
3403 struct InstantiatingTemplate {
3404 /// \brief Note that we are instantiating a class template,
3405 /// function template, or a member thereof.
3406 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3407 Decl *Entity,
3408 SourceRange InstantiationRange = SourceRange());
3410 /// \brief Note that we are instantiating a default argument in a
3411 /// template-id.
3412 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3413 TemplateDecl *Template,
3414 const TemplateArgument *TemplateArgs,
3415 unsigned NumTemplateArgs,
3416 SourceRange InstantiationRange = SourceRange());
3418 /// \brief Note that we are instantiating a default argument in a
3419 /// template-id.
3420 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3421 FunctionTemplateDecl *FunctionTemplate,
3422 const TemplateArgument *TemplateArgs,
3423 unsigned NumTemplateArgs,
3424 ActiveTemplateInstantiation::InstantiationKind Kind,
3425 sema::TemplateDeductionInfo &DeductionInfo,
3426 SourceRange InstantiationRange = SourceRange());
3428 /// \brief Note that we are instantiating as part of template
3429 /// argument deduction for a class template partial
3430 /// specialization.
3431 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3432 ClassTemplatePartialSpecializationDecl *PartialSpec,
3433 const TemplateArgument *TemplateArgs,
3434 unsigned NumTemplateArgs,
3435 sema::TemplateDeductionInfo &DeductionInfo,
3436 SourceRange InstantiationRange = SourceRange());
3438 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3439 ParmVarDecl *Param,
3440 const TemplateArgument *TemplateArgs,
3441 unsigned NumTemplateArgs,
3442 SourceRange InstantiationRange = SourceRange());
3444 /// \brief Note that we are substituting prior template arguments into a
3445 /// non-type or template template parameter.
3446 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3447 TemplateDecl *Template,
3448 NonTypeTemplateParmDecl *Param,
3449 const TemplateArgument *TemplateArgs,
3450 unsigned NumTemplateArgs,
3451 SourceRange InstantiationRange);
3453 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3454 TemplateDecl *Template,
3455 TemplateTemplateParmDecl *Param,
3456 const TemplateArgument *TemplateArgs,
3457 unsigned NumTemplateArgs,
3458 SourceRange InstantiationRange);
3460 /// \brief Note that we are checking the default template argument
3461 /// against the template parameter for a given template-id.
3462 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3463 TemplateDecl *Template,
3464 NamedDecl *Param,
3465 const TemplateArgument *TemplateArgs,
3466 unsigned NumTemplateArgs,
3467 SourceRange InstantiationRange);
3470 /// \brief Note that we have finished instantiating this template.
3471 void Clear();
3473 ~InstantiatingTemplate() { Clear(); }
3475 /// \brief Determines whether we have exceeded the maximum
3476 /// recursive template instantiations.
3477 operator bool() const { return Invalid; }
3479 private:
3480 Sema &SemaRef;
3481 bool Invalid;
3482 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
3483 SourceRange InstantiationRange);
3485 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
3487 InstantiatingTemplate&
3488 operator=(const InstantiatingTemplate&); // not implemented
3491 void PrintInstantiationStack();
3493 /// \brief Determines whether we are currently in a context where
3494 /// template argument substitution failures are not considered
3495 /// errors.
3497 /// \returns The nearest template-deduction context object, if we are in a
3498 /// SFINAE context, which can be used to capture diagnostics that will be
3499 /// suppressed. Otherwise, returns NULL to indicate that we are not within a
3500 /// SFINAE context.
3501 sema::TemplateDeductionInfo *isSFINAEContext() const;
3503 /// \brief RAII class used to determine whether SFINAE has
3504 /// trapped any errors that occur during template argument
3505 /// deduction.
3506 class SFINAETrap {
3507 Sema &SemaRef;
3508 unsigned PrevSFINAEErrors;
3509 public:
3510 explicit SFINAETrap(Sema &SemaRef)
3511 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors) { }
3513 ~SFINAETrap() { SemaRef.NumSFINAEErrors = PrevSFINAEErrors; }
3515 /// \brief Determine whether any SFINAE errors have been trapped.
3516 bool hasErrorOccurred() const {
3517 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
3521 /// \brief RAII class that determines when any errors have occurred
3522 /// between the time the instance was created and the time it was
3523 /// queried.
3524 class ErrorTrap {
3525 Sema &SemaRef;
3526 unsigned PrevErrors;
3528 public:
3529 explicit ErrorTrap(Sema &SemaRef)
3530 : SemaRef(SemaRef), PrevErrors(SemaRef.getDiagnostics().getNumErrors()) {}
3532 /// \brief Determine whether any errors have occurred since this
3533 /// object instance was created.
3534 bool hasErrorOccurred() const {
3535 return SemaRef.getDiagnostics().getNumErrors() > PrevErrors;
3539 /// \brief The current instantiation scope used to store local
3540 /// variables.
3541 LocalInstantiationScope *CurrentInstantiationScope;
3543 /// \brief The number of typos corrected by CorrectTypo.
3544 unsigned TyposCorrected;
3546 typedef llvm::DenseMap<IdentifierInfo *, std::pair<llvm::StringRef, bool> >
3547 UnqualifiedTyposCorrectedMap;
3549 /// \brief A cache containing the results of typo correction for unqualified
3550 /// name lookup.
3552 /// The string is the string that we corrected to (which may be empty, if
3553 /// there was no correction), while the boolean will be true when the
3554 /// string represents a keyword.
3555 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected;
3557 /// \brief Worker object for performing CFG-based warnings.
3558 sema::AnalysisBasedWarnings AnalysisWarnings;
3560 /// \brief An entity for which implicit template instantiation is required.
3562 /// The source location associated with the declaration is the first place in
3563 /// the source code where the declaration was "used". It is not necessarily
3564 /// the point of instantiation (which will be either before or after the
3565 /// namespace-scope declaration that triggered this implicit instantiation),
3566 /// However, it is the location that diagnostics should generally refer to,
3567 /// because users will need to know what code triggered the instantiation.
3568 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
3570 /// \brief The queue of implicit template instantiations that are required
3571 /// but have not yet been performed.
3572 std::deque<PendingImplicitInstantiation> PendingInstantiations;
3574 /// \brief The queue of implicit template instantiations that are required
3575 /// and must be performed within the current local scope.
3577 /// This queue is only used for member functions of local classes in
3578 /// templates, which must be instantiated in the same scope as their
3579 /// enclosing function, so that they can reference function-local
3580 /// types, static variables, enumerators, etc.
3581 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
3583 void PerformPendingInstantiations(bool LocalOnly = false);
3585 TypeSourceInfo *SubstType(TypeSourceInfo *T,
3586 const MultiLevelTemplateArgumentList &TemplateArgs,
3587 SourceLocation Loc, DeclarationName Entity);
3589 QualType SubstType(QualType T,
3590 const MultiLevelTemplateArgumentList &TemplateArgs,
3591 SourceLocation Loc, DeclarationName Entity);
3593 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
3594 const MultiLevelTemplateArgumentList &TemplateArgs,
3595 SourceLocation Loc,
3596 DeclarationName Entity);
3597 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
3598 const MultiLevelTemplateArgumentList &TemplateArgs);
3599 ExprResult SubstExpr(Expr *E,
3600 const MultiLevelTemplateArgumentList &TemplateArgs);
3602 StmtResult SubstStmt(Stmt *S,
3603 const MultiLevelTemplateArgumentList &TemplateArgs);
3605 Decl *SubstDecl(Decl *D, DeclContext *Owner,
3606 const MultiLevelTemplateArgumentList &TemplateArgs);
3608 bool
3609 SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
3610 CXXRecordDecl *Pattern,
3611 const MultiLevelTemplateArgumentList &TemplateArgs);
3613 bool
3614 InstantiateClass(SourceLocation PointOfInstantiation,
3615 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
3616 const MultiLevelTemplateArgumentList &TemplateArgs,
3617 TemplateSpecializationKind TSK,
3618 bool Complain = true);
3620 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
3621 Decl *Pattern, Decl *Inst);
3623 bool
3624 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
3625 ClassTemplateSpecializationDecl *ClassTemplateSpec,
3626 TemplateSpecializationKind TSK,
3627 bool Complain = true);
3629 void InstantiateClassMembers(SourceLocation PointOfInstantiation,
3630 CXXRecordDecl *Instantiation,
3631 const MultiLevelTemplateArgumentList &TemplateArgs,
3632 TemplateSpecializationKind TSK);
3634 void InstantiateClassTemplateSpecializationMembers(
3635 SourceLocation PointOfInstantiation,
3636 ClassTemplateSpecializationDecl *ClassTemplateSpec,
3637 TemplateSpecializationKind TSK);
3639 NestedNameSpecifier *
3640 SubstNestedNameSpecifier(NestedNameSpecifier *NNS,
3641 SourceRange Range,
3642 const MultiLevelTemplateArgumentList &TemplateArgs);
3643 DeclarationNameInfo
3644 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
3645 const MultiLevelTemplateArgumentList &TemplateArgs);
3646 TemplateName
3647 SubstTemplateName(TemplateName Name, SourceLocation Loc,
3648 const MultiLevelTemplateArgumentList &TemplateArgs);
3649 bool Subst(const TemplateArgumentLoc &Arg, TemplateArgumentLoc &Result,
3650 const MultiLevelTemplateArgumentList &TemplateArgs);
3652 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
3653 FunctionDecl *Function,
3654 bool Recursive = false,
3655 bool DefinitionRequired = false);
3656 void InstantiateStaticDataMemberDefinition(
3657 SourceLocation PointOfInstantiation,
3658 VarDecl *Var,
3659 bool Recursive = false,
3660 bool DefinitionRequired = false);
3662 void InstantiateMemInitializers(CXXConstructorDecl *New,
3663 const CXXConstructorDecl *Tmpl,
3664 const MultiLevelTemplateArgumentList &TemplateArgs);
3666 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
3667 const MultiLevelTemplateArgumentList &TemplateArgs);
3668 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
3669 const MultiLevelTemplateArgumentList &TemplateArgs);
3671 // Objective-C declarations.
3672 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
3673 IdentifierInfo *ClassName,
3674 SourceLocation ClassLoc,
3675 IdentifierInfo *SuperName,
3676 SourceLocation SuperLoc,
3677 Decl * const *ProtoRefs,
3678 unsigned NumProtoRefs,
3679 const SourceLocation *ProtoLocs,
3680 SourceLocation EndProtoLoc,
3681 AttributeList *AttrList);
3683 Decl *ActOnCompatiblityAlias(
3684 SourceLocation AtCompatibilityAliasLoc,
3685 IdentifierInfo *AliasName, SourceLocation AliasLocation,
3686 IdentifierInfo *ClassName, SourceLocation ClassLocation);
3688 void CheckForwardProtocolDeclarationForCircularDependency(
3689 IdentifierInfo *PName,
3690 SourceLocation &PLoc, SourceLocation PrevLoc,
3691 const ObjCList<ObjCProtocolDecl> &PList);
3693 Decl *ActOnStartProtocolInterface(
3694 SourceLocation AtProtoInterfaceLoc,
3695 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
3696 Decl * const *ProtoRefNames, unsigned NumProtoRefs,
3697 const SourceLocation *ProtoLocs,
3698 SourceLocation EndProtoLoc,
3699 AttributeList *AttrList);
3701 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
3702 IdentifierInfo *ClassName,
3703 SourceLocation ClassLoc,
3704 IdentifierInfo *CategoryName,
3705 SourceLocation CategoryLoc,
3706 Decl * const *ProtoRefs,
3707 unsigned NumProtoRefs,
3708 const SourceLocation *ProtoLocs,
3709 SourceLocation EndProtoLoc);
3711 Decl *ActOnStartClassImplementation(
3712 SourceLocation AtClassImplLoc,
3713 IdentifierInfo *ClassName, SourceLocation ClassLoc,
3714 IdentifierInfo *SuperClassname,
3715 SourceLocation SuperClassLoc);
3717 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
3718 IdentifierInfo *ClassName,
3719 SourceLocation ClassLoc,
3720 IdentifierInfo *CatName,
3721 SourceLocation CatLoc);
3723 Decl *ActOnForwardClassDeclaration(SourceLocation Loc,
3724 IdentifierInfo **IdentList,
3725 SourceLocation *IdentLocs,
3726 unsigned NumElts);
3728 Decl *ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
3729 const IdentifierLocPair *IdentList,
3730 unsigned NumElts,
3731 AttributeList *attrList);
3733 void FindProtocolDeclaration(bool WarnOnDeclarations,
3734 const IdentifierLocPair *ProtocolId,
3735 unsigned NumProtocols,
3736 llvm::SmallVectorImpl<Decl *> &Protocols);
3738 /// Ensure attributes are consistent with type.
3739 /// \param [in, out] Attributes The attributes to check; they will
3740 /// be modified to be consistent with \arg PropertyTy.
3741 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy,
3742 SourceLocation Loc,
3743 unsigned &Attributes);
3745 /// Process the specified property declaration and create decls for the
3746 /// setters and getters as needed.
3747 /// \param property The property declaration being processed
3748 /// \param DC The semantic container for the property
3749 /// \param redeclaredProperty Declaration for property if redeclared
3750 /// in class extension.
3751 /// \param lexicalDC Container for redeclaredProperty.
3752 void ProcessPropertyDecl(ObjCPropertyDecl *property,
3753 ObjCContainerDecl *DC,
3754 ObjCPropertyDecl *redeclaredProperty = 0,
3755 ObjCContainerDecl *lexicalDC = 0);
3757 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
3758 ObjCPropertyDecl *SuperProperty,
3759 const IdentifierInfo *Name);
3760 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
3762 void CompareMethodParamsInBaseAndSuper(Decl *IDecl,
3763 ObjCMethodDecl *MethodDecl,
3764 bool IsInstance);
3766 void CompareProperties(Decl *CDecl, Decl *MergeProtocols);
3768 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
3769 ObjCInterfaceDecl *ID);
3771 void MatchOneProtocolPropertiesInClass(Decl *CDecl,
3772 ObjCProtocolDecl *PDecl);
3774 void ActOnAtEnd(Scope *S, SourceRange AtEnd, Decl *classDecl,
3775 Decl **allMethods = 0, unsigned allNum = 0,
3776 Decl **allProperties = 0, unsigned pNum = 0,
3777 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0);
3779 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc,
3780 FieldDeclarator &FD, ObjCDeclSpec &ODS,
3781 Selector GetterSel, Selector SetterSel,
3782 Decl *ClassCategory,
3783 bool *OverridingProperty,
3784 tok::ObjCKeywordKind MethodImplKind,
3785 DeclContext *lexicalDC = 0);
3787 Decl *ActOnPropertyImplDecl(Scope *S,
3788 SourceLocation AtLoc,
3789 SourceLocation PropertyLoc,
3790 bool ImplKind,Decl *ClassImplDecl,
3791 IdentifierInfo *PropertyId,
3792 IdentifierInfo *PropertyIvar,
3793 SourceLocation PropertyIvarLoc);
3795 struct ObjCArgInfo {
3796 IdentifierInfo *Name;
3797 SourceLocation NameLoc;
3798 // The Type is null if no type was specified, and the DeclSpec is invalid
3799 // in this case.
3800 ParsedType Type;
3801 ObjCDeclSpec DeclSpec;
3803 /// ArgAttrs - Attribute list for this argument.
3804 AttributeList *ArgAttrs;
3807 Decl *ActOnMethodDeclaration(
3808 SourceLocation BeginLoc, // location of the + or -.
3809 SourceLocation EndLoc, // location of the ; or {.
3810 tok::TokenKind MethodType,
3811 Decl *ClassDecl, ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
3812 Selector Sel,
3813 // optional arguments. The number of types/arguments is obtained
3814 // from the Sel.getNumArgs().
3815 ObjCArgInfo *ArgInfo,
3816 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
3817 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
3818 bool isVariadic = false);
3820 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
3821 // Will search "local" class/category implementations for a method decl.
3822 // Will also search in class's root looking for instance method.
3823 // Returns 0 if no method is found.
3824 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
3825 ObjCInterfaceDecl *CDecl);
3826 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
3827 ObjCInterfaceDecl *ClassDecl);
3829 ExprResult
3830 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
3831 Expr *BaseExpr,
3832 DeclarationName MemberName,
3833 SourceLocation MemberLoc,
3834 SourceLocation SuperLoc, QualType SuperType,
3835 bool Super);
3837 ExprResult
3838 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
3839 IdentifierInfo &propertyName,
3840 SourceLocation receiverNameLoc,
3841 SourceLocation propertyNameLoc);
3843 /// \brief Describes the kind of message expression indicated by a message
3844 /// send that starts with an identifier.
3845 enum ObjCMessageKind {
3846 /// \brief The message is sent to 'super'.
3847 ObjCSuperMessage,
3848 /// \brief The message is an instance message.
3849 ObjCInstanceMessage,
3850 /// \brief The message is a class message, and the identifier is a type
3851 /// name.
3852 ObjCClassMessage
3855 ObjCMessageKind getObjCMessageKind(Scope *S,
3856 IdentifierInfo *Name,
3857 SourceLocation NameLoc,
3858 bool IsSuper,
3859 bool HasTrailingDot,
3860 ParsedType &ReceiverType);
3862 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
3863 Selector Sel,
3864 SourceLocation LBracLoc,
3865 SourceLocation SelectorLoc,
3866 SourceLocation RBracLoc,
3867 MultiExprArg Args);
3869 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
3870 QualType ReceiverType,
3871 SourceLocation SuperLoc,
3872 Selector Sel,
3873 ObjCMethodDecl *Method,
3874 SourceLocation LBracLoc,
3875 SourceLocation RBracLoc,
3876 MultiExprArg Args);
3878 ExprResult ActOnClassMessage(Scope *S,
3879 ParsedType Receiver,
3880 Selector Sel,
3881 SourceLocation LBracLoc,
3882 SourceLocation SelectorLoc,
3883 SourceLocation RBracLoc,
3884 MultiExprArg Args);
3886 ExprResult BuildInstanceMessage(Expr *Receiver,
3887 QualType ReceiverType,
3888 SourceLocation SuperLoc,
3889 Selector Sel,
3890 ObjCMethodDecl *Method,
3891 SourceLocation LBracLoc,
3892 SourceLocation RBracLoc,
3893 MultiExprArg Args);
3895 ExprResult ActOnInstanceMessage(Scope *S,
3896 Expr *Receiver,
3897 Selector Sel,
3898 SourceLocation LBracLoc,
3899 SourceLocation SelectorLoc,
3900 SourceLocation RBracLoc,
3901 MultiExprArg Args);
3904 enum PragmaOptionsAlignKind {
3905 POAK_Native, // #pragma options align=native
3906 POAK_Natural, // #pragma options align=natural
3907 POAK_Packed, // #pragma options align=packed
3908 POAK_Power, // #pragma options align=power
3909 POAK_Mac68k, // #pragma options align=mac68k
3910 POAK_Reset // #pragma options align=reset
3913 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
3914 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
3915 SourceLocation PragmaLoc,
3916 SourceLocation KindLoc);
3918 enum PragmaPackKind {
3919 PPK_Default, // #pragma pack([n])
3920 PPK_Show, // #pragma pack(show), only supported by MSVC.
3921 PPK_Push, // #pragma pack(push, [identifier], [n])
3922 PPK_Pop // #pragma pack(pop, [identifier], [n])
3925 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
3926 void ActOnPragmaPack(PragmaPackKind Kind,
3927 IdentifierInfo *Name,
3928 Expr *Alignment,
3929 SourceLocation PragmaLoc,
3930 SourceLocation LParenLoc,
3931 SourceLocation RParenLoc);
3933 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
3934 void ActOnPragmaUnused(const Token *Identifiers,
3935 unsigned NumIdentifiers, Scope *curScope,
3936 SourceLocation PragmaLoc,
3937 SourceLocation LParenLoc,
3938 SourceLocation RParenLoc);
3940 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
3941 void ActOnPragmaVisibility(bool IsPush, const IdentifierInfo* VisType,
3942 SourceLocation PragmaLoc);
3944 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II);
3945 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
3947 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident.
3948 void ActOnPragmaWeakID(IdentifierInfo* WeakName,
3949 SourceLocation PragmaLoc,
3950 SourceLocation WeakNameLoc);
3952 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
3953 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
3954 IdentifierInfo* AliasName,
3955 SourceLocation PragmaLoc,
3956 SourceLocation WeakNameLoc,
3957 SourceLocation AliasNameLoc);
3959 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
3960 /// a the record decl, to handle '#pragma pack' and '#pragma options align'.
3961 void AddAlignmentAttributesForRecord(RecordDecl *RD);
3963 /// FreePackedContext - Deallocate and null out PackContext.
3964 void FreePackedContext();
3966 /// PushVisibilityAttr - Note that we've entered a context with a
3967 /// visibility attribute.
3968 void PushVisibilityAttr(const VisibilityAttr *Attr);
3970 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used,
3971 /// add an appropriate visibility attribute.
3972 void AddPushedVisibilityAttribute(Decl *RD);
3974 /// PopPragmaVisibility - Pop the top element of the visibility stack; used
3975 /// for '#pragma GCC visibility' and visibility attributes on namespaces.
3976 void PopPragmaVisibility();
3978 /// FreeVisContext - Deallocate and null out VisContext.
3979 void FreeVisContext();
3981 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
3982 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E);
3983 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *T);
3985 /// CastCategory - Get the correct forwarded implicit cast result category
3986 /// from the inner expression.
3987 ExprValueKind CastCategory(Expr *E);
3989 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
3990 /// cast. If there is already an implicit cast, merge into the existing one.
3991 /// If isLvalue, the result of the cast is an lvalue.
3992 void ImpCastExprToType(Expr *&Expr, QualType Type, CastKind CK,
3993 ExprValueKind VK = VK_RValue,
3994 const CXXCastPath *BasePath = 0);
3996 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
3997 // functions and arrays to their respective pointers (C99 6.3.2.1).
3998 Expr *UsualUnaryConversions(Expr *&expr);
4000 // DefaultFunctionArrayConversion - converts functions and arrays
4001 // to their respective pointers (C99 6.3.2.1).
4002 void DefaultFunctionArrayConversion(Expr *&expr);
4004 // DefaultFunctionArrayLvalueConversion - converts functions and
4005 // arrays to their respective pointers and performs the
4006 // lvalue-to-rvalue conversion.
4007 void DefaultFunctionArrayLvalueConversion(Expr *&expr);
4009 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
4010 // do not have a prototype. Integer promotions are performed on each
4011 // argument, and arguments that have type float are promoted to double.
4012 void DefaultArgumentPromotion(Expr *&Expr);
4014 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
4015 enum VariadicCallType {
4016 VariadicFunction,
4017 VariadicBlock,
4018 VariadicMethod,
4019 VariadicConstructor,
4020 VariadicDoesNotApply
4023 /// GatherArgumentsForCall - Collector argument expressions for various
4024 /// form of call prototypes.
4025 bool GatherArgumentsForCall(SourceLocation CallLoc,
4026 FunctionDecl *FDecl,
4027 const FunctionProtoType *Proto,
4028 unsigned FirstProtoArg,
4029 Expr **Args, unsigned NumArgs,
4030 llvm::SmallVector<Expr *, 8> &AllArgs,
4031 VariadicCallType CallType = VariadicDoesNotApply);
4033 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
4034 // will warn if the resulting type is not a POD type.
4035 bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT,
4036 FunctionDecl *FDecl);
4038 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
4039 // operands and then handles various conversions that are common to binary
4040 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
4041 // routine returns the first non-arithmetic type found. The client is
4042 // responsible for emitting appropriate error diagnostics.
4043 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
4044 bool isCompAssign = false);
4046 /// AssignConvertType - All of the 'assignment' semantic checks return this
4047 /// enum to indicate whether the assignment was allowed. These checks are
4048 /// done for simple assignments, as well as initialization, return from
4049 /// function, argument passing, etc. The query is phrased in terms of a
4050 /// source and destination type.
4051 enum AssignConvertType {
4052 /// Compatible - the types are compatible according to the standard.
4053 Compatible,
4055 /// PointerToInt - The assignment converts a pointer to an int, which we
4056 /// accept as an extension.
4057 PointerToInt,
4059 /// IntToPointer - The assignment converts an int to a pointer, which we
4060 /// accept as an extension.
4061 IntToPointer,
4063 /// FunctionVoidPointer - The assignment is between a function pointer and
4064 /// void*, which the standard doesn't allow, but we accept as an extension.
4065 FunctionVoidPointer,
4067 /// IncompatiblePointer - The assignment is between two pointers types that
4068 /// are not compatible, but we accept them as an extension.
4069 IncompatiblePointer,
4071 /// IncompatiblePointer - The assignment is between two pointers types which
4072 /// point to integers which have a different sign, but are otherwise identical.
4073 /// This is a subset of the above, but broken out because it's by far the most
4074 /// common case of incompatible pointers.
4075 IncompatiblePointerSign,
4077 /// CompatiblePointerDiscardsQualifiers - The assignment discards
4078 /// c/v/r qualifiers, which we accept as an extension.
4079 CompatiblePointerDiscardsQualifiers,
4081 /// IncompatibleNestedPointerQualifiers - The assignment is between two
4082 /// nested pointer types, and the qualifiers other than the first two
4083 /// levels differ e.g. char ** -> const char **, but we accept them as an
4084 /// extension.
4085 IncompatibleNestedPointerQualifiers,
4087 /// IncompatibleVectors - The assignment is between two vector types that
4088 /// have the same size, which we accept as an extension.
4089 IncompatibleVectors,
4091 /// IntToBlockPointer - The assignment converts an int to a block
4092 /// pointer. We disallow this.
4093 IntToBlockPointer,
4095 /// IncompatibleBlockPointer - The assignment is between two block
4096 /// pointers types that are not compatible.
4097 IncompatibleBlockPointer,
4099 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
4100 /// id type and something else (that is incompatible with it). For example,
4101 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
4102 IncompatibleObjCQualifiedId,
4104 /// Incompatible - We reject this conversion outright, it is invalid to
4105 /// represent it in the AST.
4106 Incompatible
4109 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
4110 /// assignment conversion type specified by ConvTy. This returns true if the
4111 /// conversion was invalid or false if the conversion was accepted.
4112 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
4113 SourceLocation Loc,
4114 QualType DstType, QualType SrcType,
4115 Expr *SrcExpr, AssignmentAction Action,
4116 bool *Complained = 0);
4118 /// CheckAssignmentConstraints - Perform type checking for assignment,
4119 /// argument passing, variable initialization, and function return values.
4120 /// C99 6.5.16.
4121 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
4123 /// Check assignment constraints and prepare for a conversion of the
4124 /// RHS to the LHS type.
4125 AssignConvertType CheckAssignmentConstraints(QualType lhs, Expr *&rhs,
4126 CastKind &Kind);
4128 // CheckSingleAssignmentConstraints - Currently used by
4129 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
4130 // this routine performs the default function/array converions.
4131 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
4132 Expr *&rExpr);
4134 // \brief If the lhs type is a transparent union, check whether we
4135 // can initialize the transparent union with the given expression.
4136 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs,
4137 Expr *&rExpr);
4139 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
4140 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
4141 QualType rhsType);
4143 AssignConvertType CheckObjCPointerTypesForAssignment(QualType lhsType,
4144 QualType rhsType);
4146 // Helper function for CheckAssignmentConstraints involving two
4147 // block pointer types.
4148 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
4149 QualType rhsType);
4151 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
4153 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
4155 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4156 AssignmentAction Action,
4157 bool AllowExplicit = false);
4158 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4159 AssignmentAction Action,
4160 bool AllowExplicit,
4161 ImplicitConversionSequence& ICS);
4162 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4163 const ImplicitConversionSequence& ICS,
4164 AssignmentAction Action,
4165 bool IgnoreBaseAccess = false);
4166 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4167 const StandardConversionSequence& SCS,
4168 AssignmentAction Action,bool IgnoreBaseAccess);
4170 /// the following "Check" methods will return a valid/converted QualType
4171 /// or a null QualType (indicating an error diagnostic was issued).
4173 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
4174 QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
4175 QualType CheckPointerToMemberOperands( // C++ 5.5
4176 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
4177 QualType CheckMultiplyDivideOperands( // C99 6.5.5
4178 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign,
4179 bool isDivide);
4180 QualType CheckRemainderOperands( // C99 6.5.5
4181 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
4182 QualType CheckAdditionOperands( // C99 6.5.6
4183 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
4184 QualType CheckSubtractionOperands( // C99 6.5.6
4185 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
4186 QualType CheckShiftOperands( // C99 6.5.7
4187 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
4188 QualType CheckCompareOperands( // C99 6.5.8/9
4189 Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc,
4190 bool isRelational);
4191 QualType CheckBitwiseOperands( // C99 6.5.[10...12]
4192 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
4193 QualType CheckLogicalOperands( // C99 6.5.[13,14]
4194 Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc);
4195 // CheckAssignmentOperands is used for both simple and compound assignment.
4196 // For simple assignment, pass both expressions and a null converted type.
4197 // For compound assignment, pass both expressions and the converted type.
4198 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
4199 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
4201 void ConvertPropertyAssignment(Expr *LHS, Expr *&RHS, QualType& LHSTy);
4203 QualType CheckCommaOperands( // C99 6.5.17
4204 Expr *lex, Expr *&rex, SourceLocation OpLoc);
4205 QualType CheckConditionalOperands( // C99 6.5.15
4206 Expr *&cond, Expr *&lhs, Expr *&rhs, Expr *&save,
4207 SourceLocation questionLoc);
4208 QualType CXXCheckConditionalOperands( // C++ 5.16
4209 Expr *&cond, Expr *&lhs, Expr *&rhs, Expr *&save,
4210 SourceLocation questionLoc);
4211 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
4212 bool *NonStandardCompositeType = 0);
4214 QualType FindCompositeObjCPointerType(Expr *&LHS, Expr *&RHS,
4215 SourceLocation questionLoc);
4217 /// type checking for vector binary operators.
4218 QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
4219 QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
4220 SourceLocation l, bool isRel);
4222 /// type checking unary operators (subroutines of ActOnUnaryOp).
4223 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
4224 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
4225 bool isInc, bool isPrefix);
4226 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
4227 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
4228 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
4230 /// type checking primary expressions.
4231 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
4232 const IdentifierInfo *Comp,
4233 SourceLocation CmpLoc);
4235 /// type checking declaration initializers (C99 6.7.8)
4236 bool CheckInitList(const InitializedEntity &Entity,
4237 InitListExpr *&InitList, QualType &DeclType);
4238 bool CheckForConstantInitializer(Expr *e, QualType t);
4240 // type checking C++ declaration initializers (C++ [dcl.init]).
4242 /// ReferenceCompareResult - Expresses the result of comparing two
4243 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
4244 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
4245 enum ReferenceCompareResult {
4246 /// Ref_Incompatible - The two types are incompatible, so direct
4247 /// reference binding is not possible.
4248 Ref_Incompatible = 0,
4249 /// Ref_Related - The two types are reference-related, which means
4250 /// that their unqualified forms (T1 and T2) are either the same
4251 /// or T1 is a base class of T2.
4252 Ref_Related,
4253 /// Ref_Compatible_With_Added_Qualification - The two types are
4254 /// reference-compatible with added qualification, meaning that
4255 /// they are reference-compatible and the qualifiers on T1 (cv1)
4256 /// are greater than the qualifiers on T2 (cv2).
4257 Ref_Compatible_With_Added_Qualification,
4258 /// Ref_Compatible - The two types are reference-compatible and
4259 /// have equivalent qualifiers (cv1 == cv2).
4260 Ref_Compatible
4263 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
4264 QualType T1, QualType T2,
4265 bool &DerivedToBase,
4266 bool &ObjCConversion);
4268 /// CheckCastTypes - Check type constraints for casting between types under
4269 /// C semantics, or forward to CXXCheckCStyleCast in C++.
4270 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr,
4271 CastKind &Kind, CXXCastPath &BasePath,
4272 bool FunctionalStyle = false);
4274 // CheckVectorCast - check type constraints for vectors.
4275 // Since vectors are an extension, there are no C standard reference for this.
4276 // We allow casting between vectors and integer datatypes of the same size.
4277 // returns true if the cast is invalid
4278 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
4279 CastKind &Kind);
4281 // CheckExtVectorCast - check type constraints for extended vectors.
4282 // Since vectors are an extension, there are no C standard reference for this.
4283 // We allow casting between vectors and integer datatypes of the same size,
4284 // or vectors and the element type of that vector.
4285 // returns true if the cast is invalid
4286 bool CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *&CastExpr,
4287 CastKind &Kind);
4289 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style
4290 /// cast under C++ semantics.
4291 bool CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr,
4292 CastKind &Kind, CXXCastPath &BasePath,
4293 bool FunctionalStyle);
4295 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
4296 /// \param Method - May be null.
4297 /// \param [out] ReturnType - The return type of the send.
4298 /// \return true iff there were any incompatible types.
4299 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
4300 ObjCMethodDecl *Method, bool isClassMessage,
4301 SourceLocation lbrac, SourceLocation rbrac,
4302 QualType &ReturnType);
4304 /// CheckBooleanCondition - Diagnose problems involving the use of
4305 /// the given expression as a boolean condition (e.g. in an if
4306 /// statement). Also performs the standard function and array
4307 /// decays, possibly changing the input variable.
4309 /// \param Loc - A location associated with the condition, e.g. the
4310 /// 'if' keyword.
4311 /// \return true iff there were any errors
4312 bool CheckBooleanCondition(Expr *&CondExpr, SourceLocation Loc);
4314 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
4315 Expr *SubExpr);
4317 /// DiagnoseAssignmentAsCondition - Given that an expression is
4318 /// being used as a boolean condition, warn if it's an assignment.
4319 void DiagnoseAssignmentAsCondition(Expr *E);
4321 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
4322 bool CheckCXXBooleanCondition(Expr *&CondExpr);
4324 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
4325 /// the specified width and sign. If an overflow occurs, detect it and emit
4326 /// the specified diagnostic.
4327 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
4328 unsigned NewWidth, bool NewSign,
4329 SourceLocation Loc, unsigned DiagID);
4331 /// Checks that the Objective-C declaration is declared in the global scope.
4332 /// Emits an error and marks the declaration as invalid if it's not declared
4333 /// in the global scope.
4334 bool CheckObjCDeclScope(Decl *D);
4336 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
4337 /// and reports the appropriate diagnostics. Returns false on success.
4338 /// Can optionally return the value of the expression.
4339 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
4341 /// VerifyBitField - verifies that a bit field expression is an ICE and has
4342 /// the correct width, and that the field type is valid.
4343 /// Returns false on success.
4344 /// Can optionally return whether the bit-field is of width 0
4345 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
4346 QualType FieldTy, const Expr *BitWidth,
4347 bool *ZeroWidth = 0);
4349 /// \name Code completion
4350 //@{
4351 /// \brief Describes the context in which code completion occurs.
4352 enum ParserCompletionContext {
4353 /// \brief Code completion occurs at top-level or namespace context.
4354 PCC_Namespace,
4355 /// \brief Code completion occurs within a class, struct, or union.
4356 PCC_Class,
4357 /// \brief Code completion occurs within an Objective-C interface, protocol,
4358 /// or category.
4359 PCC_ObjCInterface,
4360 /// \brief Code completion occurs within an Objective-C implementation or
4361 /// category implementation
4362 PCC_ObjCImplementation,
4363 /// \brief Code completion occurs within the list of instance variables
4364 /// in an Objective-C interface, protocol, category, or implementation.
4365 PCC_ObjCInstanceVariableList,
4366 /// \brief Code completion occurs following one or more template
4367 /// headers.
4368 PCC_Template,
4369 /// \brief Code completion occurs following one or more template
4370 /// headers within a class.
4371 PCC_MemberTemplate,
4372 /// \brief Code completion occurs within an expression.
4373 PCC_Expression,
4374 /// \brief Code completion occurs within a statement, which may
4375 /// also be an expression or a declaration.
4376 PCC_Statement,
4377 /// \brief Code completion occurs at the beginning of the
4378 /// initialization statement (or expression) in a for loop.
4379 PCC_ForInit,
4380 /// \brief Code completion occurs within the condition of an if,
4381 /// while, switch, or for statement.
4382 PCC_Condition,
4383 /// \brief Code completion occurs within the body of a function on a
4384 /// recovery path, where we do not have a specific handle on our position
4385 /// in the grammar.
4386 PCC_RecoveryInFunction,
4387 /// \brief Code completion occurs where only a type is permitted.
4388 PCC_Type,
4389 /// \brief Code completion occurs in a parenthesized expression, which
4390 /// might also be a type cast.
4391 PCC_ParenthesizedExpression
4394 void CodeCompleteOrdinaryName(Scope *S,
4395 ParserCompletionContext CompletionContext);
4396 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
4397 bool AllowNonIdentifiers,
4398 bool AllowNestedNameSpecifiers);
4400 struct CodeCompleteExpressionData;
4401 void CodeCompleteExpression(Scope *S,
4402 const CodeCompleteExpressionData &Data);
4403 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
4404 SourceLocation OpLoc,
4405 bool IsArrow);
4406 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
4407 void CodeCompleteTag(Scope *S, unsigned TagSpec);
4408 void CodeCompleteTypeQualifiers(DeclSpec &DS);
4409 void CodeCompleteCase(Scope *S);
4410 void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs);
4411 void CodeCompleteInitializer(Scope *S, Decl *D);
4412 void CodeCompleteReturn(Scope *S);
4413 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
4415 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
4416 bool EnteringContext);
4417 void CodeCompleteUsing(Scope *S);
4418 void CodeCompleteUsingDirective(Scope *S);
4419 void CodeCompleteNamespaceDecl(Scope *S);
4420 void CodeCompleteNamespaceAliasDecl(Scope *S);
4421 void CodeCompleteOperatorName(Scope *S);
4422 void CodeCompleteConstructorInitializer(Decl *Constructor,
4423 CXXBaseOrMemberInitializer** Initializers,
4424 unsigned NumInitializers);
4426 void CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl,
4427 bool InInterface);
4428 void CodeCompleteObjCAtVisibility(Scope *S);
4429 void CodeCompleteObjCAtStatement(Scope *S);
4430 void CodeCompleteObjCAtExpression(Scope *S);
4431 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
4432 void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl,
4433 Decl **Methods,
4434 unsigned NumMethods);
4435 void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl,
4436 Decl **Methods,
4437 unsigned NumMethods);
4438 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS);
4439 void CodeCompleteObjCMessageReceiver(Scope *S);
4440 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
4441 IdentifierInfo **SelIdents,
4442 unsigned NumSelIdents,
4443 bool AtArgumentExpression);
4444 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
4445 IdentifierInfo **SelIdents,
4446 unsigned NumSelIdents,
4447 bool AtArgumentExpression,
4448 bool IsSuper = false);
4449 void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver,
4450 IdentifierInfo **SelIdents,
4451 unsigned NumSelIdents,
4452 bool AtArgumentExpression,
4453 ObjCInterfaceDecl *Super = 0);
4454 void CodeCompleteObjCForCollection(Scope *S,
4455 DeclGroupPtrTy IterationVar);
4456 void CodeCompleteObjCSelector(Scope *S,
4457 IdentifierInfo **SelIdents,
4458 unsigned NumSelIdents);
4459 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
4460 unsigned NumProtocols);
4461 void CodeCompleteObjCProtocolDecl(Scope *S);
4462 void CodeCompleteObjCInterfaceDecl(Scope *S);
4463 void CodeCompleteObjCSuperclass(Scope *S,
4464 IdentifierInfo *ClassName,
4465 SourceLocation ClassNameLoc);
4466 void CodeCompleteObjCImplementationDecl(Scope *S);
4467 void CodeCompleteObjCInterfaceCategory(Scope *S,
4468 IdentifierInfo *ClassName,
4469 SourceLocation ClassNameLoc);
4470 void CodeCompleteObjCImplementationCategory(Scope *S,
4471 IdentifierInfo *ClassName,
4472 SourceLocation ClassNameLoc);
4473 void CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl);
4474 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
4475 IdentifierInfo *PropertyName,
4476 Decl *ObjCImpDecl);
4477 void CodeCompleteObjCMethodDecl(Scope *S,
4478 bool IsInstanceMethod,
4479 ParsedType ReturnType,
4480 Decl *IDecl);
4481 void CodeCompleteObjCMethodDeclSelector(Scope *S,
4482 bool IsInstanceMethod,
4483 bool AtParameterName,
4484 ParsedType ReturnType,
4485 IdentifierInfo **SelIdents,
4486 unsigned NumSelIdents);
4487 void CodeCompletePreprocessorDirective(bool InConditional);
4488 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
4489 void CodeCompletePreprocessorMacroName(bool IsDefinition);
4490 void CodeCompletePreprocessorExpression();
4491 void CodeCompletePreprocessorMacroArgument(Scope *S,
4492 IdentifierInfo *Macro,
4493 MacroInfo *MacroInfo,
4494 unsigned Argument);
4495 void CodeCompleteNaturalLanguage();
4496 void GatherGlobalCodeCompletions(
4497 llvm::SmallVectorImpl<CodeCompletionResult> &Results);
4498 //@}
4500 void PrintStats() const {}
4502 //===--------------------------------------------------------------------===//
4503 // Extra semantic analysis beyond the C type system
4505 public:
4506 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
4507 unsigned ByteNo) const;
4509 private:
4510 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
4511 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall);
4513 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall);
4514 bool CheckObjCString(Expr *Arg);
4516 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
4517 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
4519 bool SemaBuiltinVAStart(CallExpr *TheCall);
4520 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
4521 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
4523 public:
4524 // Used by C++ template instantiation.
4525 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
4527 private:
4528 bool SemaBuiltinPrefetch(CallExpr *TheCall);
4529 bool SemaBuiltinObjectSize(CallExpr *TheCall);
4530 bool SemaBuiltinLongjmp(CallExpr *TheCall);
4531 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
4532 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
4533 llvm::APSInt &Result);
4535 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall,
4536 bool HasVAListArg, unsigned format_idx,
4537 unsigned firstDataArg, bool isPrintf);
4539 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
4540 const CallExpr *TheCall, bool HasVAListArg,
4541 unsigned format_idx, unsigned firstDataArg,
4542 bool isPrintf);
4544 void CheckNonNullArguments(const NonNullAttr *NonNull,
4545 const CallExpr *TheCall);
4547 void CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg,
4548 unsigned format_idx, unsigned firstDataArg,
4549 bool isPrintf);
4551 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
4552 SourceLocation ReturnLoc);
4553 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
4554 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
4556 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
4557 Expr *Init);
4559 /// \brief The parser's current scope.
4561 /// The parser maintains this state here.
4562 Scope *CurScope;
4564 protected:
4565 friend class Parser;
4566 friend class InitializationSequence;
4568 /// \brief Retrieve the parser's current scope.
4569 Scope *getCurScope() const { return CurScope; }
4572 /// \brief RAII object that enters a new expression evaluation context.
4573 class EnterExpressionEvaluationContext {
4574 Sema &Actions;
4576 public:
4577 EnterExpressionEvaluationContext(Sema &Actions,
4578 Sema::ExpressionEvaluationContext NewContext)
4579 : Actions(Actions) {
4580 Actions.PushExpressionEvaluationContext(NewContext);
4583 ~EnterExpressionEvaluationContext() {
4584 Actions.PopExpressionEvaluationContext();
4588 } // end namespace clang
4590 #endif