Don't warn for empty 'if' body if there is a macro that expands to nothing, e.g:
[clang.git] / include / clang / Sema / Sema.h
blob8294ffd784a45d3441982905f2c600da4a3bffb3
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, bool MacroExpandedInThenStmt,
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 ExprValueKind VK,
1735 SourceLocation Loc,
1736 const CXXScopeSpec *SS = 0);
1737 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
1738 ExprValueKind VK,
1739 const DeclarationNameInfo &NameInfo,
1740 const CXXScopeSpec *SS = 0);
1741 VarDecl *BuildAnonymousStructUnionMemberPath(FieldDecl *Field,
1742 llvm::SmallVectorImpl<FieldDecl *> &Path);
1743 ExprResult
1744 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1745 FieldDecl *Field,
1746 Expr *BaseObjectExpr = 0,
1747 SourceLocation OpLoc = SourceLocation());
1748 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
1749 LookupResult &R,
1750 const TemplateArgumentListInfo *TemplateArgs);
1751 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
1752 LookupResult &R,
1753 const TemplateArgumentListInfo *TemplateArgs,
1754 bool IsDefiniteInstance);
1755 bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
1756 const LookupResult &R,
1757 bool HasTrailingLParen);
1759 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
1760 const DeclarationNameInfo &NameInfo);
1761 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
1762 const DeclarationNameInfo &NameInfo,
1763 const TemplateArgumentListInfo *TemplateArgs);
1765 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
1766 LookupResult &R,
1767 bool ADL);
1768 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
1769 const DeclarationNameInfo &NameInfo,
1770 NamedDecl *D);
1772 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
1773 ExprResult ActOnNumericConstant(const Token &);
1774 ExprResult ActOnCharacterConstant(const Token &);
1775 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *Val);
1776 ExprResult ActOnParenOrParenListExpr(SourceLocation L,
1777 SourceLocation R,
1778 MultiExprArg Val,
1779 ParsedType TypeOfCast = ParsedType());
1781 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
1782 /// fragments (e.g. "foo" "bar" L"baz").
1783 ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
1785 // Binary/Unary Operators. 'Tok' is the token for the operator.
1786 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, unsigned OpcIn,
1787 Expr *InputArg);
1788 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
1789 UnaryOperatorKind Opc, Expr *input);
1790 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1791 tok::TokenKind Op, Expr *Input);
1793 ExprResult CreateSizeOfAlignOfExpr(TypeSourceInfo *T,
1794 SourceLocation OpLoc,
1795 bool isSizeOf, SourceRange R);
1796 ExprResult CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc,
1797 bool isSizeOf, SourceRange R);
1798 ExprResult
1799 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1800 void *TyOrEx, const SourceRange &ArgRange);
1802 ExprResult CheckPlaceholderExpr(Expr *E, SourceLocation Loc);
1804 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1805 SourceRange R, bool isSizeof);
1807 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1808 tok::TokenKind Kind, Expr *Input);
1810 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
1811 Expr *Idx, SourceLocation RLoc);
1812 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
1813 Expr *Idx, SourceLocation RLoc);
1815 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
1816 SourceLocation OpLoc, bool IsArrow,
1817 CXXScopeSpec &SS,
1818 NamedDecl *FirstQualifierInScope,
1819 const DeclarationNameInfo &NameInfo,
1820 const TemplateArgumentListInfo *TemplateArgs);
1822 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
1823 SourceLocation OpLoc, bool IsArrow,
1824 const CXXScopeSpec &SS,
1825 NamedDecl *FirstQualifierInScope,
1826 LookupResult &R,
1827 const TemplateArgumentListInfo *TemplateArgs,
1828 bool SuppressQualifierCheck = false);
1830 ExprResult LookupMemberExpr(LookupResult &R, Expr *&Base,
1831 bool &IsArrow, SourceLocation OpLoc,
1832 CXXScopeSpec &SS,
1833 Decl *ObjCImpDecl,
1834 bool HasTemplateArgs);
1836 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
1837 const CXXScopeSpec &SS,
1838 const LookupResult &R);
1840 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
1841 bool IsArrow, SourceLocation OpLoc,
1842 const CXXScopeSpec &SS,
1843 NamedDecl *FirstQualifierInScope,
1844 const DeclarationNameInfo &NameInfo,
1845 const TemplateArgumentListInfo *TemplateArgs);
1847 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
1848 SourceLocation OpLoc,
1849 tok::TokenKind OpKind,
1850 CXXScopeSpec &SS,
1851 UnqualifiedId &Member,
1852 Decl *ObjCImpDecl,
1853 bool HasTrailingLParen);
1855 void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
1856 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
1857 FunctionDecl *FDecl,
1858 const FunctionProtoType *Proto,
1859 Expr **Args, unsigned NumArgs,
1860 SourceLocation RParenLoc);
1862 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
1863 /// This provides the location of the left/right parens and a list of comma
1864 /// locations.
1865 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
1866 MultiExprArg Args, SourceLocation RParenLoc);
1867 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
1868 SourceLocation LParenLoc,
1869 Expr **Args, unsigned NumArgs,
1870 SourceLocation RParenLoc);
1872 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
1873 ParsedType Ty, SourceLocation RParenLoc,
1874 Expr *Op);
1875 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
1876 TypeSourceInfo *Ty,
1877 SourceLocation RParenLoc,
1878 Expr *Op);
1880 bool TypeIsVectorType(ParsedType Ty) {
1881 return GetTypeFromParser(Ty)->isVectorType();
1884 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
1885 ExprResult ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc,
1886 SourceLocation RParenLoc, Expr *E,
1887 TypeSourceInfo *TInfo);
1889 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1890 ParsedType Ty,
1891 SourceLocation RParenLoc,
1892 Expr *Op);
1894 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
1895 TypeSourceInfo *TInfo,
1896 SourceLocation RParenLoc,
1897 Expr *InitExpr);
1899 ExprResult ActOnInitList(SourceLocation LParenLoc,
1900 MultiExprArg InitList,
1901 SourceLocation RParenLoc);
1903 ExprResult ActOnDesignatedInitializer(Designation &Desig,
1904 SourceLocation Loc,
1905 bool GNUSyntax,
1906 ExprResult Init);
1908 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1909 tok::TokenKind Kind, Expr *LHS, Expr *RHS);
1910 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
1911 BinaryOperatorKind Opc, Expr *lhs, Expr *rhs);
1912 ExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1913 unsigned Opc, Expr *lhs, Expr *rhs);
1915 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
1916 /// in the case of a the GNU conditional expr extension.
1917 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1918 SourceLocation ColonLoc,
1919 Expr *Cond, Expr *LHS, Expr *RHS);
1921 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1922 ExprResult ActOnAddrLabel(SourceLocation OpLoc,
1923 SourceLocation LabLoc,
1924 IdentifierInfo *LabelII);
1926 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
1927 SourceLocation RPLoc); // "({..})"
1929 // __builtin_offsetof(type, identifier(.identifier|[expr])*)
1930 struct OffsetOfComponent {
1931 SourceLocation LocStart, LocEnd;
1932 bool isBrackets; // true if [expr], false if .ident
1933 union {
1934 IdentifierInfo *IdentInfo;
1935 ExprTy *E;
1936 } U;
1939 /// __builtin_offsetof(type, a.b[123][456].c)
1940 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
1941 TypeSourceInfo *TInfo,
1942 OffsetOfComponent *CompPtr,
1943 unsigned NumComponents,
1944 SourceLocation RParenLoc);
1945 ExprResult ActOnBuiltinOffsetOf(Scope *S,
1946 SourceLocation BuiltinLoc,
1947 SourceLocation TypeLoc,
1948 ParsedType Arg1,
1949 OffsetOfComponent *CompPtr,
1950 unsigned NumComponents,
1951 SourceLocation RParenLoc);
1953 // __builtin_types_compatible_p(type1, type2)
1954 ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
1955 ParsedType arg1,
1956 ParsedType arg2,
1957 SourceLocation RPLoc);
1958 ExprResult BuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1959 TypeSourceInfo *argTInfo1,
1960 TypeSourceInfo *argTInfo2,
1961 SourceLocation RPLoc);
1963 // __builtin_choose_expr(constExpr, expr1, expr2)
1964 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
1965 Expr *cond, Expr *expr1,
1966 Expr *expr2, SourceLocation RPLoc);
1968 // __builtin_va_arg(expr, type)
1969 ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1970 Expr *expr, ParsedType type,
1971 SourceLocation RPLoc);
1972 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc,
1973 Expr *expr, TypeSourceInfo *TInfo,
1974 SourceLocation RPLoc);
1976 // __null
1977 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1979 //===------------------------- "Block" Extension ------------------------===//
1981 /// ActOnBlockStart - This callback is invoked when a block literal is
1982 /// started.
1983 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1985 /// ActOnBlockArguments - This callback allows processing of block arguments.
1986 /// If there are no arguments, this is still invoked.
1987 void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
1989 /// ActOnBlockError - If there is an error parsing a block, this callback
1990 /// is invoked to pop the information about the block from the action impl.
1991 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1993 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1994 /// literal was successfully completed. ^(int x){...}
1995 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc,
1996 Stmt *Body, Scope *CurScope);
1998 //===---------------------------- C++ Features --------------------------===//
2000 // Act on C++ namespaces
2001 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
2002 SourceLocation IdentLoc,
2003 IdentifierInfo *Ident,
2004 SourceLocation LBrace,
2005 AttributeList *AttrList);
2006 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
2008 NamespaceDecl *getStdNamespace() const;
2009 NamespaceDecl *getOrCreateStdNamespace();
2011 CXXRecordDecl *getStdBadAlloc() const;
2013 Decl *ActOnUsingDirective(Scope *CurScope,
2014 SourceLocation UsingLoc,
2015 SourceLocation NamespcLoc,
2016 CXXScopeSpec &SS,
2017 SourceLocation IdentLoc,
2018 IdentifierInfo *NamespcName,
2019 AttributeList *AttrList);
2021 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
2023 Decl *ActOnNamespaceAliasDef(Scope *CurScope,
2024 SourceLocation NamespaceLoc,
2025 SourceLocation AliasLoc,
2026 IdentifierInfo *Alias,
2027 CXXScopeSpec &SS,
2028 SourceLocation IdentLoc,
2029 IdentifierInfo *Ident);
2031 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
2032 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
2033 const LookupResult &PreviousDecls);
2034 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
2035 NamedDecl *Target);
2037 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
2038 bool isTypeName,
2039 const CXXScopeSpec &SS,
2040 SourceLocation NameLoc,
2041 const LookupResult &Previous);
2042 bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
2043 const CXXScopeSpec &SS,
2044 SourceLocation NameLoc);
2046 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
2047 SourceLocation UsingLoc,
2048 CXXScopeSpec &SS,
2049 const DeclarationNameInfo &NameInfo,
2050 AttributeList *AttrList,
2051 bool IsInstantiation,
2052 bool IsTypeName,
2053 SourceLocation TypenameLoc);
2055 Decl *ActOnUsingDeclaration(Scope *CurScope,
2056 AccessSpecifier AS,
2057 bool HasUsingKeyword,
2058 SourceLocation UsingLoc,
2059 CXXScopeSpec &SS,
2060 UnqualifiedId &Name,
2061 AttributeList *AttrList,
2062 bool IsTypeName,
2063 SourceLocation TypenameLoc);
2065 /// AddCXXDirectInitializerToDecl - This action is called immediately after
2066 /// ActOnDeclarator, when a C++ direct initializer is present.
2067 /// e.g: "int x(1);"
2068 void AddCXXDirectInitializerToDecl(Decl *Dcl,
2069 SourceLocation LParenLoc,
2070 MultiExprArg Exprs,
2071 SourceLocation RParenLoc);
2073 /// InitializeVarWithConstructor - Creates an CXXConstructExpr
2074 /// and sets it as the initializer for the the passed in VarDecl.
2075 bool InitializeVarWithConstructor(VarDecl *VD,
2076 CXXConstructorDecl *Constructor,
2077 MultiExprArg Exprs);
2079 /// BuildCXXConstructExpr - Creates a complete call to a constructor,
2080 /// including handling of its default argument expressions.
2082 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
2083 ExprResult
2084 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2085 CXXConstructorDecl *Constructor, MultiExprArg Exprs,
2086 bool RequiresZeroInit, unsigned ConstructKind,
2087 SourceRange ParenRange);
2089 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
2090 // the constructor can be elidable?
2091 ExprResult
2092 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2093 CXXConstructorDecl *Constructor, bool Elidable,
2094 MultiExprArg Exprs, bool RequiresZeroInit,
2095 unsigned ConstructKind,
2096 SourceRange ParenRange);
2098 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
2099 /// the default expr if needed.
2100 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
2101 FunctionDecl *FD,
2102 ParmVarDecl *Param);
2104 /// FinalizeVarWithDestructor - Prepare for calling destructor on the
2105 /// constructed variable.
2106 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
2108 /// \brief Declare the implicit default constructor for the given class.
2110 /// \param ClassDecl The class declaration into which the implicit
2111 /// default constructor will be added.
2113 /// \returns The implicitly-declared default constructor.
2114 CXXConstructorDecl *DeclareImplicitDefaultConstructor(
2115 CXXRecordDecl *ClassDecl);
2117 /// DefineImplicitDefaultConstructor - Checks for feasibility of
2118 /// defining this constructor as the default constructor.
2119 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
2120 CXXConstructorDecl *Constructor);
2122 /// \brief Declare the implicit destructor for the given class.
2124 /// \param ClassDecl The class declaration into which the implicit
2125 /// destructor will be added.
2127 /// \returns The implicitly-declared destructor.
2128 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
2130 /// DefineImplicitDestructor - Checks for feasibility of
2131 /// defining this destructor as the default destructor.
2132 void DefineImplicitDestructor(SourceLocation CurrentLocation,
2133 CXXDestructorDecl *Destructor);
2135 /// \brief Declare the implicit copy constructor for the given class.
2137 /// \param S The scope of the class, which may be NULL if this is a
2138 /// template instantiation.
2140 /// \param ClassDecl The class declaration into which the implicit
2141 /// copy constructor will be added.
2143 /// \returns The implicitly-declared copy constructor.
2144 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
2146 /// DefineImplicitCopyConstructor - Checks for feasibility of
2147 /// defining this constructor as the copy constructor.
2148 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
2149 CXXConstructorDecl *Constructor,
2150 unsigned TypeQuals);
2152 /// \brief Declare the implicit copy assignment operator for the given class.
2154 /// \param S The scope of the class, which may be NULL if this is a
2155 /// template instantiation.
2157 /// \param ClassDecl The class declaration into which the implicit
2158 /// copy-assignment operator will be added.
2160 /// \returns The implicitly-declared copy assignment operator.
2161 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
2163 /// \brief Defined an implicitly-declared copy assignment operator.
2164 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
2165 CXXMethodDecl *MethodDecl);
2167 /// \brief Force the declaration of any implicitly-declared members of this
2168 /// class.
2169 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
2171 /// MaybeBindToTemporary - If the passed in expression has a record type with
2172 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
2173 /// it simply returns the passed in expression.
2174 ExprResult MaybeBindToTemporary(Expr *E);
2176 bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
2177 MultiExprArg ArgsPtr,
2178 SourceLocation Loc,
2179 ASTOwningVector<Expr*> &ConvertedArgs);
2181 ParsedType getDestructorName(SourceLocation TildeLoc,
2182 IdentifierInfo &II, SourceLocation NameLoc,
2183 Scope *S, CXXScopeSpec &SS,
2184 ParsedType ObjectType,
2185 bool EnteringContext);
2187 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
2188 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
2189 tok::TokenKind Kind,
2190 SourceLocation LAngleBracketLoc,
2191 ParsedType Ty,
2192 SourceLocation RAngleBracketLoc,
2193 SourceLocation LParenLoc,
2194 Expr *E,
2195 SourceLocation RParenLoc);
2197 ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
2198 tok::TokenKind Kind,
2199 TypeSourceInfo *Ty,
2200 Expr *E,
2201 SourceRange AngleBrackets,
2202 SourceRange Parens);
2204 ExprResult BuildCXXTypeId(QualType TypeInfoType,
2205 SourceLocation TypeidLoc,
2206 TypeSourceInfo *Operand,
2207 SourceLocation RParenLoc);
2208 ExprResult BuildCXXTypeId(QualType TypeInfoType,
2209 SourceLocation TypeidLoc,
2210 Expr *Operand,
2211 SourceLocation RParenLoc);
2213 /// ActOnCXXTypeid - Parse typeid( something ).
2214 ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
2215 SourceLocation LParenLoc, bool isType,
2216 void *TyOrExpr,
2217 SourceLocation RParenLoc);
2219 ExprResult BuildCXXUuidof(QualType TypeInfoType,
2220 SourceLocation TypeidLoc,
2221 TypeSourceInfo *Operand,
2222 SourceLocation RParenLoc);
2223 ExprResult BuildCXXUuidof(QualType TypeInfoType,
2224 SourceLocation TypeidLoc,
2225 Expr *Operand,
2226 SourceLocation RParenLoc);
2228 /// ActOnCXXUuidof - Parse __uuidof( something ).
2229 ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
2230 SourceLocation LParenLoc, bool isType,
2231 void *TyOrExpr,
2232 SourceLocation RParenLoc);
2235 //// ActOnCXXThis - Parse 'this' pointer.
2236 ExprResult ActOnCXXThis(SourceLocation ThisLoc);
2238 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
2239 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
2241 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
2242 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
2244 //// ActOnCXXThrow - Parse throw expressions.
2245 ExprResult ActOnCXXThrow(SourceLocation OpLoc, Expr *expr);
2246 bool CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E);
2248 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
2249 /// Can be interpreted either as function-style casting ("int(x)")
2250 /// or class type construction ("ClassType(x,y,z)")
2251 /// or creation of a value-initialized type ("int()").
2252 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
2253 SourceLocation LParenLoc,
2254 MultiExprArg Exprs,
2255 SourceLocation RParenLoc);
2257 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
2258 SourceLocation LParenLoc,
2259 MultiExprArg Exprs,
2260 SourceLocation RParenLoc);
2262 /// ActOnCXXNew - Parsed a C++ 'new' expression.
2263 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
2264 SourceLocation PlacementLParen,
2265 MultiExprArg PlacementArgs,
2266 SourceLocation PlacementRParen,
2267 SourceRange TypeIdParens, Declarator &D,
2268 SourceLocation ConstructorLParen,
2269 MultiExprArg ConstructorArgs,
2270 SourceLocation ConstructorRParen);
2271 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
2272 SourceLocation PlacementLParen,
2273 MultiExprArg PlacementArgs,
2274 SourceLocation PlacementRParen,
2275 SourceRange TypeIdParens,
2276 QualType AllocType,
2277 TypeSourceInfo *AllocTypeInfo,
2278 Expr *ArraySize,
2279 SourceLocation ConstructorLParen,
2280 MultiExprArg ConstructorArgs,
2281 SourceLocation ConstructorRParen);
2283 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
2284 SourceRange R);
2285 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
2286 bool UseGlobal, QualType AllocType, bool IsArray,
2287 Expr **PlaceArgs, unsigned NumPlaceArgs,
2288 FunctionDecl *&OperatorNew,
2289 FunctionDecl *&OperatorDelete);
2290 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
2291 DeclarationName Name, Expr** Args,
2292 unsigned NumArgs, DeclContext *Ctx,
2293 bool AllowMissing, FunctionDecl *&Operator);
2294 void DeclareGlobalNewDelete();
2295 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
2296 QualType Argument,
2297 bool addMallocAttr = false);
2299 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
2300 DeclarationName Name, FunctionDecl* &Operator);
2302 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
2303 ExprResult ActOnCXXDelete(SourceLocation StartLoc,
2304 bool UseGlobal, bool ArrayForm,
2305 Expr *Operand);
2307 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
2308 ExprResult CheckConditionVariable(VarDecl *ConditionVar,
2309 SourceLocation StmtLoc,
2310 bool ConvertToBoolean);
2312 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
2313 Expr *Operand, SourceLocation RParen);
2314 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
2315 SourceLocation RParen);
2317 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
2318 /// pseudo-functions.
2319 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
2320 SourceLocation KWLoc,
2321 ParsedType Ty,
2322 SourceLocation RParen);
2324 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT,
2325 SourceLocation KWLoc,
2326 TypeSourceInfo *T,
2327 SourceLocation RParen);
2329 ExprResult ActOnStartCXXMemberReference(Scope *S,
2330 Expr *Base,
2331 SourceLocation OpLoc,
2332 tok::TokenKind OpKind,
2333 ParsedType &ObjectType,
2334 bool &MayBePseudoDestructor);
2336 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr);
2338 ExprResult BuildPseudoDestructorExpr(Expr *Base,
2339 SourceLocation OpLoc,
2340 tok::TokenKind OpKind,
2341 const CXXScopeSpec &SS,
2342 TypeSourceInfo *ScopeType,
2343 SourceLocation CCLoc,
2344 SourceLocation TildeLoc,
2345 PseudoDestructorTypeStorage DestroyedType,
2346 bool HasTrailingLParen);
2348 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
2349 SourceLocation OpLoc,
2350 tok::TokenKind OpKind,
2351 CXXScopeSpec &SS,
2352 UnqualifiedId &FirstTypeName,
2353 SourceLocation CCLoc,
2354 SourceLocation TildeLoc,
2355 UnqualifiedId &SecondTypeName,
2356 bool HasTrailingLParen);
2358 /// MaybeCreateCXXExprWithTemporaries - If the list of temporaries is
2359 /// non-empty, will create a new CXXExprWithTemporaries expression.
2360 /// Otherwise, just returs the passed in expression.
2361 Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr);
2362 Stmt *MaybeCreateCXXStmtWithTemporaries(Stmt *SubStmt);
2363 ExprResult MaybeCreateCXXExprWithTemporaries(ExprResult SubExpr);
2364 FullExpr CreateFullExpr(Expr *SubExpr);
2366 ExprResult ActOnFinishFullExpr(Expr *Expr);
2367 StmtResult ActOnFinishFullStmt(Stmt *Stmt);
2369 // Marks SS invalid if it represents an incomplete type.
2370 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
2372 DeclContext *computeDeclContext(QualType T);
2373 DeclContext *computeDeclContext(const CXXScopeSpec &SS,
2374 bool EnteringContext = false);
2375 bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
2376 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
2377 bool isUnknownSpecialization(const CXXScopeSpec &SS);
2379 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
2380 /// global scope ('::').
2381 NestedNameSpecifier *
2382 ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc);
2384 bool isAcceptableNestedNameSpecifier(NamedDecl *SD);
2385 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
2387 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
2388 SourceLocation IdLoc,
2389 IdentifierInfo &II,
2390 ParsedType ObjectType);
2392 NestedNameSpecifier *BuildCXXNestedNameSpecifier(Scope *S,
2393 CXXScopeSpec &SS,
2394 SourceLocation IdLoc,
2395 SourceLocation CCLoc,
2396 IdentifierInfo &II,
2397 QualType ObjectType,
2398 NamedDecl *ScopeLookupResult,
2399 bool EnteringContext,
2400 bool ErrorRecoveryLookup);
2402 NestedNameSpecifier *ActOnCXXNestedNameSpecifier(Scope *S,
2403 CXXScopeSpec &SS,
2404 SourceLocation IdLoc,
2405 SourceLocation CCLoc,
2406 IdentifierInfo &II,
2407 ParsedType ObjectType,
2408 bool EnteringContext);
2410 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
2411 IdentifierInfo &II,
2412 ParsedType ObjectType,
2413 bool EnteringContext);
2415 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
2416 /// nested-name-specifier that involves a template-id, e.g.,
2417 /// "foo::bar<int, float>::", and now we need to build a scope
2418 /// specifier. \p SS is empty or the previously parsed nested-name
2419 /// part ("foo::"), \p Type is the already-parsed class template
2420 /// specialization (or other template-id that names a type), \p
2421 /// TypeRange is the source range where the type is located, and \p
2422 /// CCLoc is the location of the trailing '::'.
2423 CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
2424 const CXXScopeSpec &SS,
2425 ParsedType Type,
2426 SourceRange TypeRange,
2427 SourceLocation CCLoc);
2429 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
2431 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
2432 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
2433 /// After this method is called, according to [C++ 3.4.3p3], names should be
2434 /// looked up in the declarator-id's scope, until the declarator is parsed and
2435 /// ActOnCXXExitDeclaratorScope is called.
2436 /// The 'SS' should be a non-empty valid CXXScopeSpec.
2437 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
2439 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
2440 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
2441 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
2442 /// Used to indicate that names should revert to being looked up in the
2443 /// defining scope.
2444 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
2446 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
2447 /// initializer for the declaration 'Dcl'.
2448 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
2449 /// static data member of class X, names should be looked up in the scope of
2450 /// class X.
2451 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
2453 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
2454 /// initializer for the declaration 'Dcl'.
2455 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
2457 // ParseObjCStringLiteral - Parse Objective-C string literals.
2458 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
2459 Expr **Strings,
2460 unsigned NumStrings);
2462 Expr *BuildObjCEncodeExpression(SourceLocation AtLoc,
2463 TypeSourceInfo *EncodedTypeInfo,
2464 SourceLocation RParenLoc);
2465 CXXMemberCallExpr *BuildCXXMemberCallExpr(Expr *Exp,
2466 NamedDecl *FoundDecl,
2467 CXXMethodDecl *Method);
2469 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
2470 SourceLocation EncodeLoc,
2471 SourceLocation LParenLoc,
2472 ParsedType Ty,
2473 SourceLocation RParenLoc);
2475 // ParseObjCSelectorExpression - Build selector expression for @selector
2476 ExprResult ParseObjCSelectorExpression(Selector Sel,
2477 SourceLocation AtLoc,
2478 SourceLocation SelLoc,
2479 SourceLocation LParenLoc,
2480 SourceLocation RParenLoc);
2482 // ParseObjCProtocolExpression - Build protocol expression for @protocol
2483 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
2484 SourceLocation AtLoc,
2485 SourceLocation ProtoLoc,
2486 SourceLocation LParenLoc,
2487 SourceLocation RParenLoc);
2489 //===--------------------------------------------------------------------===//
2490 // C++ Declarations
2492 Decl *ActOnStartLinkageSpecification(Scope *S,
2493 SourceLocation ExternLoc,
2494 SourceLocation LangLoc,
2495 llvm::StringRef Lang,
2496 SourceLocation LBraceLoc);
2497 Decl *ActOnFinishLinkageSpecification(Scope *S,
2498 Decl *LinkageSpec,
2499 SourceLocation RBraceLoc);
2502 //===--------------------------------------------------------------------===//
2503 // C++ Classes
2505 bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
2506 const CXXScopeSpec *SS = 0);
2508 Decl *ActOnAccessSpecifier(AccessSpecifier Access,
2509 SourceLocation ASLoc,
2510 SourceLocation ColonLoc);
2512 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
2513 Declarator &D,
2514 MultiTemplateParamsArg TemplateParameterLists,
2515 Expr *BitfieldWidth,
2516 Expr *Init, bool IsDefinition,
2517 bool Deleted = false);
2519 MemInitResult ActOnMemInitializer(Decl *ConstructorD,
2520 Scope *S,
2521 CXXScopeSpec &SS,
2522 IdentifierInfo *MemberOrBase,
2523 ParsedType TemplateTypeTy,
2524 SourceLocation IdLoc,
2525 SourceLocation LParenLoc,
2526 Expr **Args, unsigned NumArgs,
2527 SourceLocation RParenLoc);
2529 MemInitResult BuildMemberInitializer(FieldDecl *Member, Expr **Args,
2530 unsigned NumArgs, SourceLocation IdLoc,
2531 SourceLocation LParenLoc,
2532 SourceLocation RParenLoc);
2534 MemInitResult BuildBaseInitializer(QualType BaseType,
2535 TypeSourceInfo *BaseTInfo,
2536 Expr **Args, unsigned NumArgs,
2537 SourceLocation LParenLoc,
2538 SourceLocation RParenLoc,
2539 CXXRecordDecl *ClassDecl);
2541 bool SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor,
2542 CXXBaseOrMemberInitializer **Initializers,
2543 unsigned NumInitializers, bool AnyErrors);
2545 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
2548 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
2549 /// mark all the non-trivial destructors of its members and bases as
2550 /// referenced.
2551 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
2552 CXXRecordDecl *Record);
2554 /// \brief The list of classes whose vtables have been used within
2555 /// this translation unit, and the source locations at which the
2556 /// first use occurred.
2557 llvm::SmallVector<std::pair<CXXRecordDecl *, SourceLocation>, 16>
2558 VTableUses;
2560 /// \brief The set of classes whose vtables have been used within
2561 /// this translation unit, and a bit that will be true if the vtable is
2562 /// required to be emitted (otherwise, it should be emitted only if needed
2563 /// by code generation).
2564 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
2566 /// \brief A list of all of the dynamic classes in this translation
2567 /// unit.
2568 llvm::SmallVector<CXXRecordDecl *, 16> DynamicClasses;
2570 /// \brief Note that the vtable for the given class was used at the
2571 /// given location.
2572 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
2573 bool DefinitionRequired = false);
2575 /// MarkVirtualMembersReferenced - Will mark all members of the given
2576 /// CXXRecordDecl referenced.
2577 void MarkVirtualMembersReferenced(SourceLocation Loc,
2578 const CXXRecordDecl *RD);
2580 /// \brief Define all of the vtables that have been used in this
2581 /// translation unit and reference any virtual members used by those
2582 /// vtables.
2584 /// \returns true if any work was done, false otherwise.
2585 bool DefineUsedVTables();
2587 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
2589 void ActOnMemInitializers(Decl *ConstructorDecl,
2590 SourceLocation ColonLoc,
2591 MemInitTy **MemInits, unsigned NumMemInits,
2592 bool AnyErrors);
2594 void CheckCompletedCXXClass(CXXRecordDecl *Record);
2595 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
2596 Decl *TagDecl,
2597 SourceLocation LBrac,
2598 SourceLocation RBrac,
2599 AttributeList *AttrList);
2601 void ActOnReenterTemplateScope(Scope *S, Decl *Template);
2602 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
2603 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
2604 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
2605 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
2606 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
2608 Decl *ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
2609 Expr *AssertExpr,
2610 Expr *AssertMessageExpr);
2612 FriendDecl *CheckFriendTypeDecl(SourceLocation FriendLoc,
2613 TypeSourceInfo *TSInfo);
2614 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
2615 MultiTemplateParamsArg TemplateParams);
2616 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition,
2617 MultiTemplateParamsArg TemplateParams);
2619 QualType CheckConstructorDeclarator(Declarator &D, QualType R,
2620 StorageClass& SC);
2621 void CheckConstructor(CXXConstructorDecl *Constructor);
2622 QualType CheckDestructorDeclarator(Declarator &D, QualType R,
2623 StorageClass& SC);
2624 bool CheckDestructor(CXXDestructorDecl *Destructor);
2625 void CheckConversionDeclarator(Declarator &D, QualType &R,
2626 StorageClass& SC);
2627 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
2629 //===--------------------------------------------------------------------===//
2630 // C++ Derived Classes
2633 /// ActOnBaseSpecifier - Parsed a base specifier
2634 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
2635 SourceRange SpecifierRange,
2636 bool Virtual, AccessSpecifier Access,
2637 TypeSourceInfo *TInfo);
2639 BaseResult ActOnBaseSpecifier(Decl *classdecl,
2640 SourceRange SpecifierRange,
2641 bool Virtual, AccessSpecifier Access,
2642 ParsedType basetype, SourceLocation
2643 BaseLoc);
2645 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
2646 unsigned NumBases);
2647 void ActOnBaseSpecifiers(Decl *ClassDecl, BaseTy **Bases, unsigned NumBases);
2649 bool IsDerivedFrom(QualType Derived, QualType Base);
2650 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths);
2652 // FIXME: I don't like this name.
2653 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
2655 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath);
2657 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
2658 SourceLocation Loc, SourceRange Range,
2659 CXXCastPath *BasePath = 0,
2660 bool IgnoreAccess = false);
2661 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
2662 unsigned InaccessibleBaseID,
2663 unsigned AmbigiousBaseConvID,
2664 SourceLocation Loc, SourceRange Range,
2665 DeclarationName Name,
2666 CXXCastPath *BasePath);
2668 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
2670 /// CheckOverridingFunctionReturnType - Checks whether the return types are
2671 /// covariant, according to C++ [class.virtual]p5.
2672 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
2673 const CXXMethodDecl *Old);
2675 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
2676 /// spec is a subset of base spec.
2677 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
2678 const CXXMethodDecl *Old);
2680 /// CheckOverridingFunctionAttributes - Checks whether attributes are
2681 /// incompatible or prevent overriding.
2682 bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
2683 const CXXMethodDecl *Old);
2685 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
2687 //===--------------------------------------------------------------------===//
2688 // C++ Access Control
2691 enum AccessResult {
2692 AR_accessible,
2693 AR_inaccessible,
2694 AR_dependent,
2695 AR_delayed
2698 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
2699 NamedDecl *PrevMemberDecl,
2700 AccessSpecifier LexicalAS);
2702 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
2703 DeclAccessPair FoundDecl);
2704 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
2705 DeclAccessPair FoundDecl);
2706 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
2707 SourceRange PlacementRange,
2708 CXXRecordDecl *NamingClass,
2709 DeclAccessPair FoundDecl);
2710 AccessResult CheckConstructorAccess(SourceLocation Loc,
2711 CXXConstructorDecl *D,
2712 const InitializedEntity &Entity,
2713 AccessSpecifier Access,
2714 bool IsCopyBindingRefToTemp = false);
2715 AccessResult CheckDestructorAccess(SourceLocation Loc,
2716 CXXDestructorDecl *Dtor,
2717 const PartialDiagnostic &PDiag);
2718 AccessResult CheckDirectMemberAccess(SourceLocation Loc,
2719 NamedDecl *D,
2720 const PartialDiagnostic &PDiag);
2721 AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
2722 Expr *ObjectExpr,
2723 Expr *ArgExpr,
2724 DeclAccessPair FoundDecl);
2725 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
2726 DeclAccessPair FoundDecl);
2727 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
2728 QualType Base, QualType Derived,
2729 const CXXBasePath &Path,
2730 unsigned DiagID,
2731 bool ForceCheck = false,
2732 bool ForceUnprivileged = false);
2733 void CheckLookupAccess(const LookupResult &R);
2735 void HandleDependentAccessCheck(const DependentDiagnostic &DD,
2736 const MultiLevelTemplateArgumentList &TemplateArgs);
2737 void PerformDependentDiagnostics(const DeclContext *Pattern,
2738 const MultiLevelTemplateArgumentList &TemplateArgs);
2740 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
2742 /// A flag to suppress access checking.
2743 bool SuppressAccessChecking;
2745 void ActOnStartSuppressingAccessChecks();
2746 void ActOnStopSuppressingAccessChecks();
2748 enum AbstractDiagSelID {
2749 AbstractNone = -1,
2750 AbstractReturnType,
2751 AbstractParamType,
2752 AbstractVariableType,
2753 AbstractFieldType,
2754 AbstractArrayType
2757 bool RequireNonAbstractType(SourceLocation Loc, QualType T,
2758 const PartialDiagnostic &PD);
2759 void DiagnoseAbstractType(const CXXRecordDecl *RD);
2761 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
2762 AbstractDiagSelID SelID = AbstractNone);
2764 //===--------------------------------------------------------------------===//
2765 // C++ Overloaded Operators [C++ 13.5]
2768 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
2770 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
2772 //===--------------------------------------------------------------------===//
2773 // C++ Templates [C++ 14]
2775 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
2776 QualType ObjectType, bool EnteringContext,
2777 bool &MemberOfUnknownSpecialization);
2779 TemplateNameKind isTemplateName(Scope *S,
2780 CXXScopeSpec &SS,
2781 bool hasTemplateKeyword,
2782 UnqualifiedId &Name,
2783 ParsedType ObjectType,
2784 bool EnteringContext,
2785 TemplateTy &Template,
2786 bool &MemberOfUnknownSpecialization);
2788 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
2789 SourceLocation IILoc,
2790 Scope *S,
2791 const CXXScopeSpec *SS,
2792 TemplateTy &SuggestedTemplate,
2793 TemplateNameKind &SuggestedKind);
2795 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
2796 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
2798 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
2799 SourceLocation EllipsisLoc,
2800 SourceLocation KeyLoc,
2801 IdentifierInfo *ParamName,
2802 SourceLocation ParamNameLoc,
2803 unsigned Depth, unsigned Position,
2804 SourceLocation EqualLoc,
2805 ParsedType DefaultArg);
2807 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
2808 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
2809 unsigned Depth,
2810 unsigned Position,
2811 SourceLocation EqualLoc,
2812 Expr *DefaultArg);
2813 Decl *ActOnTemplateTemplateParameter(Scope *S,
2814 SourceLocation TmpLoc,
2815 TemplateParamsTy *Params,
2816 IdentifierInfo *ParamName,
2817 SourceLocation ParamNameLoc,
2818 unsigned Depth,
2819 unsigned Position,
2820 SourceLocation EqualLoc,
2821 const ParsedTemplateArgument &DefaultArg);
2823 TemplateParamsTy *
2824 ActOnTemplateParameterList(unsigned Depth,
2825 SourceLocation ExportLoc,
2826 SourceLocation TemplateLoc,
2827 SourceLocation LAngleLoc,
2828 Decl **Params, unsigned NumParams,
2829 SourceLocation RAngleLoc);
2831 /// \brief The context in which we are checking a template parameter
2832 /// list.
2833 enum TemplateParamListContext {
2834 TPC_ClassTemplate,
2835 TPC_FunctionTemplate,
2836 TPC_ClassTemplateMember,
2837 TPC_FriendFunctionTemplate
2840 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
2841 TemplateParameterList *OldParams,
2842 TemplateParamListContext TPC);
2843 TemplateParameterList *
2844 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
2845 const CXXScopeSpec &SS,
2846 TemplateParameterList **ParamLists,
2847 unsigned NumParamLists,
2848 bool IsFriend,
2849 bool &IsExplicitSpecialization,
2850 bool &Invalid);
2852 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
2853 SourceLocation KWLoc, CXXScopeSpec &SS,
2854 IdentifierInfo *Name, SourceLocation NameLoc,
2855 AttributeList *Attr,
2856 TemplateParameterList *TemplateParams,
2857 AccessSpecifier AS);
2859 void translateTemplateArguments(const ASTTemplateArgsPtr &In,
2860 TemplateArgumentListInfo &Out);
2862 QualType CheckTemplateIdType(TemplateName Template,
2863 SourceLocation TemplateLoc,
2864 const TemplateArgumentListInfo &TemplateArgs);
2866 TypeResult
2867 ActOnTemplateIdType(TemplateTy Template, SourceLocation TemplateLoc,
2868 SourceLocation LAngleLoc,
2869 ASTTemplateArgsPtr TemplateArgs,
2870 SourceLocation RAngleLoc);
2872 TypeResult ActOnTagTemplateIdType(CXXScopeSpec &SS,
2873 TypeResult Type,
2874 TagUseKind TUK,
2875 TypeSpecifierType TagSpec,
2876 SourceLocation TagLoc);
2878 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
2879 LookupResult &R,
2880 bool RequiresADL,
2881 const TemplateArgumentListInfo &TemplateArgs);
2882 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
2883 const DeclarationNameInfo &NameInfo,
2884 const TemplateArgumentListInfo &TemplateArgs);
2886 TemplateNameKind ActOnDependentTemplateName(Scope *S,
2887 SourceLocation TemplateKWLoc,
2888 CXXScopeSpec &SS,
2889 UnqualifiedId &Name,
2890 ParsedType ObjectType,
2891 bool EnteringContext,
2892 TemplateTy &Template);
2894 bool CheckClassTemplatePartialSpecializationArgs(
2895 TemplateParameterList *TemplateParams,
2896 llvm::SmallVectorImpl<TemplateArgument> &TemplateArgs,
2897 bool &MirrorsPrimaryTemplate);
2899 DeclResult
2900 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
2901 SourceLocation KWLoc,
2902 CXXScopeSpec &SS,
2903 TemplateTy Template,
2904 SourceLocation TemplateNameLoc,
2905 SourceLocation LAngleLoc,
2906 ASTTemplateArgsPtr TemplateArgs,
2907 SourceLocation RAngleLoc,
2908 AttributeList *Attr,
2909 MultiTemplateParamsArg TemplateParameterLists);
2911 Decl *ActOnTemplateDeclarator(Scope *S,
2912 MultiTemplateParamsArg TemplateParameterLists,
2913 Declarator &D);
2915 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope,
2916 MultiTemplateParamsArg TemplateParameterLists,
2917 Declarator &D);
2919 bool
2920 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
2921 TemplateSpecializationKind NewTSK,
2922 NamedDecl *PrevDecl,
2923 TemplateSpecializationKind PrevTSK,
2924 SourceLocation PrevPtOfInstantiation,
2925 bool &SuppressNew);
2927 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
2928 const TemplateArgumentListInfo &ExplicitTemplateArgs,
2929 LookupResult &Previous);
2931 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
2932 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2933 LookupResult &Previous);
2934 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
2936 DeclResult
2937 ActOnExplicitInstantiation(Scope *S,
2938 SourceLocation ExternLoc,
2939 SourceLocation TemplateLoc,
2940 unsigned TagSpec,
2941 SourceLocation KWLoc,
2942 const CXXScopeSpec &SS,
2943 TemplateTy Template,
2944 SourceLocation TemplateNameLoc,
2945 SourceLocation LAngleLoc,
2946 ASTTemplateArgsPtr TemplateArgs,
2947 SourceLocation RAngleLoc,
2948 AttributeList *Attr);
2950 DeclResult
2951 ActOnExplicitInstantiation(Scope *S,
2952 SourceLocation ExternLoc,
2953 SourceLocation TemplateLoc,
2954 unsigned TagSpec,
2955 SourceLocation KWLoc,
2956 CXXScopeSpec &SS,
2957 IdentifierInfo *Name,
2958 SourceLocation NameLoc,
2959 AttributeList *Attr);
2961 DeclResult ActOnExplicitInstantiation(Scope *S,
2962 SourceLocation ExternLoc,
2963 SourceLocation TemplateLoc,
2964 Declarator &D);
2966 TemplateArgumentLoc
2967 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
2968 SourceLocation TemplateLoc,
2969 SourceLocation RAngleLoc,
2970 Decl *Param,
2971 llvm::SmallVectorImpl<TemplateArgument> &Converted);
2973 /// \brief Specifies the context in which a particular template
2974 /// argument is being checked.
2975 enum CheckTemplateArgumentKind {
2976 /// \brief The template argument was specified in the code or was
2977 /// instantiated with some deduced template arguments.
2978 CTAK_Specified,
2980 /// \brief The template argument was deduced via template argument
2981 /// deduction.
2982 CTAK_Deduced,
2984 /// \brief The template argument was deduced from an array bound
2985 /// via template argument deduction.
2986 CTAK_DeducedFromArrayBound
2989 bool CheckTemplateArgument(NamedDecl *Param,
2990 const TemplateArgumentLoc &Arg,
2991 TemplateDecl *Template,
2992 SourceLocation TemplateLoc,
2993 SourceLocation RAngleLoc,
2994 llvm::SmallVectorImpl<TemplateArgument> &Converted,
2995 CheckTemplateArgumentKind CTAK = CTAK_Specified);
2997 bool CheckTemplateArgumentList(TemplateDecl *Template,
2998 SourceLocation TemplateLoc,
2999 const TemplateArgumentListInfo &TemplateArgs,
3000 bool PartialTemplateArgs,
3001 llvm::SmallVectorImpl<TemplateArgument> &Converted);
3003 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
3004 const TemplateArgumentLoc &Arg,
3005 llvm::SmallVectorImpl<TemplateArgument> &Converted);
3007 bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
3008 TypeSourceInfo *Arg);
3009 bool CheckTemplateArgumentPointerToMember(Expr *Arg,
3010 TemplateArgument &Converted);
3011 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
3012 QualType InstantiatedParamType, Expr *&Arg,
3013 TemplateArgument &Converted,
3014 CheckTemplateArgumentKind CTAK = CTAK_Specified);
3015 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
3016 const TemplateArgumentLoc &Arg);
3018 ExprResult
3019 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
3020 QualType ParamType,
3021 SourceLocation Loc);
3022 ExprResult
3023 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
3024 SourceLocation Loc);
3026 /// \brief Enumeration describing how template parameter lists are compared
3027 /// for equality.
3028 enum TemplateParameterListEqualKind {
3029 /// \brief We are matching the template parameter lists of two templates
3030 /// that might be redeclarations.
3032 /// \code
3033 /// template<typename T> struct X;
3034 /// template<typename T> struct X;
3035 /// \endcode
3036 TPL_TemplateMatch,
3038 /// \brief We are matching the template parameter lists of two template
3039 /// template parameters as part of matching the template parameter lists
3040 /// of two templates that might be redeclarations.
3042 /// \code
3043 /// template<template<int I> class TT> struct X;
3044 /// template<template<int Value> class Other> struct X;
3045 /// \endcode
3046 TPL_TemplateTemplateParmMatch,
3048 /// \brief We are matching the template parameter lists of a template
3049 /// template argument against the template parameter lists of a template
3050 /// template parameter.
3052 /// \code
3053 /// template<template<int Value> class Metafun> struct X;
3054 /// template<int Value> struct integer_c;
3055 /// X<integer_c> xic;
3056 /// \endcode
3057 TPL_TemplateTemplateArgumentMatch
3060 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
3061 TemplateParameterList *Old,
3062 bool Complain,
3063 TemplateParameterListEqualKind Kind,
3064 SourceLocation TemplateArgLoc
3065 = SourceLocation());
3067 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
3069 /// \brief Called when the parser has parsed a C++ typename
3070 /// specifier, e.g., "typename T::type".
3072 /// \param S The scope in which this typename type occurs.
3073 /// \param TypenameLoc the location of the 'typename' keyword
3074 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
3075 /// \param II the identifier we're retrieving (e.g., 'type' in the example).
3076 /// \param IdLoc the location of the identifier.
3077 TypeResult
3078 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
3079 const CXXScopeSpec &SS, const IdentifierInfo &II,
3080 SourceLocation IdLoc);
3082 /// \brief Called when the parser has parsed a C++ typename
3083 /// specifier that ends in a template-id, e.g.,
3084 /// "typename MetaFun::template apply<T1, T2>".
3086 /// \param S The scope in which this typename type occurs.
3087 /// \param TypenameLoc the location of the 'typename' keyword
3088 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
3089 /// \param TemplateLoc the location of the 'template' keyword, if any.
3090 /// \param Ty the type that the typename specifier refers to.
3091 TypeResult
3092 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
3093 const CXXScopeSpec &SS, SourceLocation TemplateLoc,
3094 ParsedType Ty);
3096 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
3097 NestedNameSpecifier *NNS,
3098 const IdentifierInfo &II,
3099 SourceLocation KeywordLoc,
3100 SourceRange NNSRange,
3101 SourceLocation IILoc);
3103 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
3104 SourceLocation Loc,
3105 DeclarationName Name);
3106 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
3108 ExprResult RebuildExprInCurrentInstantiation(Expr *E);
3110 std::string
3111 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
3112 const TemplateArgumentList &Args);
3114 std::string
3115 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
3116 const TemplateArgument *Args,
3117 unsigned NumArgs);
3119 /// \brief Describes the result of template argument deduction.
3121 /// The TemplateDeductionResult enumeration describes the result of
3122 /// template argument deduction, as returned from
3123 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
3124 /// structure provides additional information about the results of
3125 /// template argument deduction, e.g., the deduced template argument
3126 /// list (if successful) or the specific template parameters or
3127 /// deduced arguments that were involved in the failure.
3128 enum TemplateDeductionResult {
3129 /// \brief Template argument deduction was successful.
3130 TDK_Success = 0,
3131 /// \brief Template argument deduction exceeded the maximum template
3132 /// instantiation depth (which has already been diagnosed).
3133 TDK_InstantiationDepth,
3134 /// \brief Template argument deduction did not deduce a value
3135 /// for every template parameter.
3136 TDK_Incomplete,
3137 /// \brief Template argument deduction produced inconsistent
3138 /// deduced values for the given template parameter.
3139 TDK_Inconsistent,
3140 /// \brief Template argument deduction failed due to inconsistent
3141 /// cv-qualifiers on a template parameter type that would
3142 /// otherwise be deduced, e.g., we tried to deduce T in "const T"
3143 /// but were given a non-const "X".
3144 TDK_Underqualified,
3145 /// \brief Substitution of the deduced template argument values
3146 /// resulted in an error.
3147 TDK_SubstitutionFailure,
3148 /// \brief Substitution of the deduced template argument values
3149 /// into a non-deduced context produced a type or value that
3150 /// produces a type that does not match the original template
3151 /// arguments provided.
3152 TDK_NonDeducedMismatch,
3153 /// \brief When performing template argument deduction for a function
3154 /// template, there were too many call arguments.
3155 TDK_TooManyArguments,
3156 /// \brief When performing template argument deduction for a function
3157 /// template, there were too few call arguments.
3158 TDK_TooFewArguments,
3159 /// \brief The explicitly-specified template arguments were not valid
3160 /// template arguments for the given template.
3161 TDK_InvalidExplicitArguments,
3162 /// \brief The arguments included an overloaded function name that could
3163 /// not be resolved to a suitable function.
3164 TDK_FailedOverloadResolution
3167 TemplateDeductionResult
3168 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
3169 const TemplateArgumentList &TemplateArgs,
3170 sema::TemplateDeductionInfo &Info);
3172 TemplateDeductionResult
3173 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3174 const TemplateArgumentListInfo &ExplicitTemplateArgs,
3175 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3176 llvm::SmallVectorImpl<QualType> &ParamTypes,
3177 QualType *FunctionType,
3178 sema::TemplateDeductionInfo &Info);
3180 TemplateDeductionResult
3181 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
3182 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3183 unsigned NumExplicitlySpecified,
3184 FunctionDecl *&Specialization,
3185 sema::TemplateDeductionInfo &Info);
3187 TemplateDeductionResult
3188 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3189 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3190 Expr **Args, unsigned NumArgs,
3191 FunctionDecl *&Specialization,
3192 sema::TemplateDeductionInfo &Info);
3194 TemplateDeductionResult
3195 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3196 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3197 QualType ArgFunctionType,
3198 FunctionDecl *&Specialization,
3199 sema::TemplateDeductionInfo &Info);
3201 TemplateDeductionResult
3202 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3203 QualType ToType,
3204 CXXConversionDecl *&Specialization,
3205 sema::TemplateDeductionInfo &Info);
3207 TemplateDeductionResult
3208 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3209 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3210 FunctionDecl *&Specialization,
3211 sema::TemplateDeductionInfo &Info);
3213 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
3214 FunctionTemplateDecl *FT2,
3215 SourceLocation Loc,
3216 TemplatePartialOrderingContext TPOC);
3217 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin,
3218 UnresolvedSetIterator SEnd,
3219 TemplatePartialOrderingContext TPOC,
3220 SourceLocation Loc,
3221 const PartialDiagnostic &NoneDiag,
3222 const PartialDiagnostic &AmbigDiag,
3223 const PartialDiagnostic &CandidateDiag);
3225 ClassTemplatePartialSpecializationDecl *
3226 getMoreSpecializedPartialSpecialization(
3227 ClassTemplatePartialSpecializationDecl *PS1,
3228 ClassTemplatePartialSpecializationDecl *PS2,
3229 SourceLocation Loc);
3231 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
3232 bool OnlyDeduced,
3233 unsigned Depth,
3234 llvm::SmallVectorImpl<bool> &Used);
3235 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate,
3236 llvm::SmallVectorImpl<bool> &Deduced);
3238 //===--------------------------------------------------------------------===//
3239 // C++ Template Instantiation
3242 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D,
3243 const TemplateArgumentList *Innermost = 0,
3244 bool RelativeToPrimary = false,
3245 const FunctionDecl *Pattern = 0);
3247 /// \brief A template instantiation that is currently in progress.
3248 struct ActiveTemplateInstantiation {
3249 /// \brief The kind of template instantiation we are performing
3250 enum InstantiationKind {
3251 /// We are instantiating a template declaration. The entity is
3252 /// the declaration we're instantiating (e.g., a CXXRecordDecl).
3253 TemplateInstantiation,
3255 /// We are instantiating a default argument for a template
3256 /// parameter. The Entity is the template, and
3257 /// TemplateArgs/NumTemplateArguments provides the template
3258 /// arguments as specified.
3259 /// FIXME: Use a TemplateArgumentList
3260 DefaultTemplateArgumentInstantiation,
3262 /// We are instantiating a default argument for a function.
3263 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
3264 /// provides the template arguments as specified.
3265 DefaultFunctionArgumentInstantiation,
3267 /// We are substituting explicit template arguments provided for
3268 /// a function template. The entity is a FunctionTemplateDecl.
3269 ExplicitTemplateArgumentSubstitution,
3271 /// We are substituting template argument determined as part of
3272 /// template argument deduction for either a class template
3273 /// partial specialization or a function template. The
3274 /// Entity is either a ClassTemplatePartialSpecializationDecl or
3275 /// a FunctionTemplateDecl.
3276 DeducedTemplateArgumentSubstitution,
3278 /// We are substituting prior template arguments into a new
3279 /// template parameter. The template parameter itself is either a
3280 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
3281 PriorTemplateArgumentSubstitution,
3283 /// We are checking the validity of a default template argument that
3284 /// has been used when naming a template-id.
3285 DefaultTemplateArgumentChecking
3286 } Kind;
3288 /// \brief The point of instantiation within the source code.
3289 SourceLocation PointOfInstantiation;
3291 /// \brief The template in which we are performing the instantiation,
3292 /// for substitutions of prior template arguments.
3293 TemplateDecl *Template;
3295 /// \brief The entity that is being instantiated.
3296 uintptr_t Entity;
3298 /// \brief The list of template arguments we are substituting, if they
3299 /// are not part of the entity.
3300 const TemplateArgument *TemplateArgs;
3302 /// \brief The number of template arguments in TemplateArgs.
3303 unsigned NumTemplateArgs;
3305 /// \brief The template deduction info object associated with the
3306 /// substitution or checking of explicit or deduced template arguments.
3307 sema::TemplateDeductionInfo *DeductionInfo;
3309 /// \brief The source range that covers the construct that cause
3310 /// the instantiation, e.g., the template-id that causes a class
3311 /// template instantiation.
3312 SourceRange InstantiationRange;
3314 ActiveTemplateInstantiation()
3315 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0),
3316 NumTemplateArgs(0), DeductionInfo(0) {}
3318 /// \brief Determines whether this template is an actual instantiation
3319 /// that should be counted toward the maximum instantiation depth.
3320 bool isInstantiationRecord() const;
3322 friend bool operator==(const ActiveTemplateInstantiation &X,
3323 const ActiveTemplateInstantiation &Y) {
3324 if (X.Kind != Y.Kind)
3325 return false;
3327 if (X.Entity != Y.Entity)
3328 return false;
3330 switch (X.Kind) {
3331 case TemplateInstantiation:
3332 return true;
3334 case PriorTemplateArgumentSubstitution:
3335 case DefaultTemplateArgumentChecking:
3336 if (X.Template != Y.Template)
3337 return false;
3339 // Fall through
3341 case DefaultTemplateArgumentInstantiation:
3342 case ExplicitTemplateArgumentSubstitution:
3343 case DeducedTemplateArgumentSubstitution:
3344 case DefaultFunctionArgumentInstantiation:
3345 return X.TemplateArgs == Y.TemplateArgs;
3349 return true;
3352 friend bool operator!=(const ActiveTemplateInstantiation &X,
3353 const ActiveTemplateInstantiation &Y) {
3354 return !(X == Y);
3358 /// \brief List of active template instantiations.
3360 /// This vector is treated as a stack. As one template instantiation
3361 /// requires another template instantiation, additional
3362 /// instantiations are pushed onto the stack up to a
3363 /// user-configurable limit LangOptions::InstantiationDepth.
3364 llvm::SmallVector<ActiveTemplateInstantiation, 16>
3365 ActiveTemplateInstantiations;
3367 /// \brief The number of ActiveTemplateInstantiation entries in
3368 /// \c ActiveTemplateInstantiations that are not actual instantiations and,
3369 /// therefore, should not be counted as part of the instantiation depth.
3370 unsigned NonInstantiationEntries;
3372 /// \brief The last template from which a template instantiation
3373 /// error or warning was produced.
3375 /// This value is used to suppress printing of redundant template
3376 /// instantiation backtraces when there are multiple errors in the
3377 /// same instantiation. FIXME: Does this belong in Sema? It's tough
3378 /// to implement it anywhere else.
3379 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
3381 /// \brief The stack of calls expression undergoing template instantiation.
3383 /// The top of this stack is used by a fixit instantiating unresolved
3384 /// function calls to fix the AST to match the textual change it prints.
3385 llvm::SmallVector<CallExpr *, 8> CallsUndergoingInstantiation;
3387 /// \brief For each declaration that involved template argument deduction, the
3388 /// set of diagnostics that were suppressed during that template argument
3389 /// deduction.
3391 /// FIXME: Serialize this structure to the AST file.
3392 llvm::DenseMap<Decl *, llvm::SmallVector<PartialDiagnosticAt, 1> >
3393 SuppressedDiagnostics;
3395 /// \brief A stack object to be created when performing template
3396 /// instantiation.
3398 /// Construction of an object of type \c InstantiatingTemplate
3399 /// pushes the current instantiation onto the stack of active
3400 /// instantiations. If the size of this stack exceeds the maximum
3401 /// number of recursive template instantiations, construction
3402 /// produces an error and evaluates true.
3404 /// Destruction of this object will pop the named instantiation off
3405 /// the stack.
3406 struct InstantiatingTemplate {
3407 /// \brief Note that we are instantiating a class template,
3408 /// function template, or a member thereof.
3409 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3410 Decl *Entity,
3411 SourceRange InstantiationRange = SourceRange());
3413 /// \brief Note that we are instantiating a default argument in a
3414 /// template-id.
3415 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3416 TemplateDecl *Template,
3417 const TemplateArgument *TemplateArgs,
3418 unsigned NumTemplateArgs,
3419 SourceRange InstantiationRange = SourceRange());
3421 /// \brief Note that we are instantiating a default argument in a
3422 /// template-id.
3423 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3424 FunctionTemplateDecl *FunctionTemplate,
3425 const TemplateArgument *TemplateArgs,
3426 unsigned NumTemplateArgs,
3427 ActiveTemplateInstantiation::InstantiationKind Kind,
3428 sema::TemplateDeductionInfo &DeductionInfo,
3429 SourceRange InstantiationRange = SourceRange());
3431 /// \brief Note that we are instantiating as part of template
3432 /// argument deduction for a class template partial
3433 /// specialization.
3434 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3435 ClassTemplatePartialSpecializationDecl *PartialSpec,
3436 const TemplateArgument *TemplateArgs,
3437 unsigned NumTemplateArgs,
3438 sema::TemplateDeductionInfo &DeductionInfo,
3439 SourceRange InstantiationRange = SourceRange());
3441 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3442 ParmVarDecl *Param,
3443 const TemplateArgument *TemplateArgs,
3444 unsigned NumTemplateArgs,
3445 SourceRange InstantiationRange = SourceRange());
3447 /// \brief Note that we are substituting prior template arguments into a
3448 /// non-type or template template parameter.
3449 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3450 TemplateDecl *Template,
3451 NonTypeTemplateParmDecl *Param,
3452 const TemplateArgument *TemplateArgs,
3453 unsigned NumTemplateArgs,
3454 SourceRange InstantiationRange);
3456 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3457 TemplateDecl *Template,
3458 TemplateTemplateParmDecl *Param,
3459 const TemplateArgument *TemplateArgs,
3460 unsigned NumTemplateArgs,
3461 SourceRange InstantiationRange);
3463 /// \brief Note that we are checking the default template argument
3464 /// against the template parameter for a given template-id.
3465 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3466 TemplateDecl *Template,
3467 NamedDecl *Param,
3468 const TemplateArgument *TemplateArgs,
3469 unsigned NumTemplateArgs,
3470 SourceRange InstantiationRange);
3473 /// \brief Note that we have finished instantiating this template.
3474 void Clear();
3476 ~InstantiatingTemplate() { Clear(); }
3478 /// \brief Determines whether we have exceeded the maximum
3479 /// recursive template instantiations.
3480 operator bool() const { return Invalid; }
3482 private:
3483 Sema &SemaRef;
3484 bool Invalid;
3485 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
3486 SourceRange InstantiationRange);
3488 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
3490 InstantiatingTemplate&
3491 operator=(const InstantiatingTemplate&); // not implemented
3494 void PrintInstantiationStack();
3496 /// \brief Determines whether we are currently in a context where
3497 /// template argument substitution failures are not considered
3498 /// errors.
3500 /// \returns The nearest template-deduction context object, if we are in a
3501 /// SFINAE context, which can be used to capture diagnostics that will be
3502 /// suppressed. Otherwise, returns NULL to indicate that we are not within a
3503 /// SFINAE context.
3504 sema::TemplateDeductionInfo *isSFINAEContext() const;
3506 /// \brief RAII class used to determine whether SFINAE has
3507 /// trapped any errors that occur during template argument
3508 /// deduction.
3509 class SFINAETrap {
3510 Sema &SemaRef;
3511 unsigned PrevSFINAEErrors;
3512 public:
3513 explicit SFINAETrap(Sema &SemaRef)
3514 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors) { }
3516 ~SFINAETrap() { SemaRef.NumSFINAEErrors = PrevSFINAEErrors; }
3518 /// \brief Determine whether any SFINAE errors have been trapped.
3519 bool hasErrorOccurred() const {
3520 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
3524 /// \brief The current instantiation scope used to store local
3525 /// variables.
3526 LocalInstantiationScope *CurrentInstantiationScope;
3528 /// \brief The number of typos corrected by CorrectTypo.
3529 unsigned TyposCorrected;
3531 typedef llvm::DenseMap<IdentifierInfo *, std::pair<llvm::StringRef, bool> >
3532 UnqualifiedTyposCorrectedMap;
3534 /// \brief A cache containing the results of typo correction for unqualified
3535 /// name lookup.
3537 /// The string is the string that we corrected to (which may be empty, if
3538 /// there was no correction), while the boolean will be true when the
3539 /// string represents a keyword.
3540 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected;
3542 /// \brief Worker object for performing CFG-based warnings.
3543 sema::AnalysisBasedWarnings AnalysisWarnings;
3545 /// \brief An entity for which implicit template instantiation is required.
3547 /// The source location associated with the declaration is the first place in
3548 /// the source code where the declaration was "used". It is not necessarily
3549 /// the point of instantiation (which will be either before or after the
3550 /// namespace-scope declaration that triggered this implicit instantiation),
3551 /// However, it is the location that diagnostics should generally refer to,
3552 /// because users will need to know what code triggered the instantiation.
3553 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
3555 /// \brief The queue of implicit template instantiations that are required
3556 /// but have not yet been performed.
3557 std::deque<PendingImplicitInstantiation> PendingInstantiations;
3559 /// \brief The queue of implicit template instantiations that are required
3560 /// and must be performed within the current local scope.
3562 /// This queue is only used for member functions of local classes in
3563 /// templates, which must be instantiated in the same scope as their
3564 /// enclosing function, so that they can reference function-local
3565 /// types, static variables, enumerators, etc.
3566 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
3568 void PerformPendingInstantiations(bool LocalOnly = false);
3570 TypeSourceInfo *SubstType(TypeSourceInfo *T,
3571 const MultiLevelTemplateArgumentList &TemplateArgs,
3572 SourceLocation Loc, DeclarationName Entity);
3574 QualType SubstType(QualType T,
3575 const MultiLevelTemplateArgumentList &TemplateArgs,
3576 SourceLocation Loc, DeclarationName Entity);
3578 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
3579 const MultiLevelTemplateArgumentList &TemplateArgs,
3580 SourceLocation Loc,
3581 DeclarationName Entity);
3582 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
3583 const MultiLevelTemplateArgumentList &TemplateArgs);
3584 ExprResult SubstExpr(Expr *E,
3585 const MultiLevelTemplateArgumentList &TemplateArgs);
3587 StmtResult SubstStmt(Stmt *S,
3588 const MultiLevelTemplateArgumentList &TemplateArgs);
3590 Decl *SubstDecl(Decl *D, DeclContext *Owner,
3591 const MultiLevelTemplateArgumentList &TemplateArgs);
3593 bool
3594 SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
3595 CXXRecordDecl *Pattern,
3596 const MultiLevelTemplateArgumentList &TemplateArgs);
3598 bool
3599 InstantiateClass(SourceLocation PointOfInstantiation,
3600 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
3601 const MultiLevelTemplateArgumentList &TemplateArgs,
3602 TemplateSpecializationKind TSK,
3603 bool Complain = true);
3605 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
3606 Decl *Pattern, Decl *Inst);
3608 bool
3609 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
3610 ClassTemplateSpecializationDecl *ClassTemplateSpec,
3611 TemplateSpecializationKind TSK,
3612 bool Complain = true);
3614 void InstantiateClassMembers(SourceLocation PointOfInstantiation,
3615 CXXRecordDecl *Instantiation,
3616 const MultiLevelTemplateArgumentList &TemplateArgs,
3617 TemplateSpecializationKind TSK);
3619 void InstantiateClassTemplateSpecializationMembers(
3620 SourceLocation PointOfInstantiation,
3621 ClassTemplateSpecializationDecl *ClassTemplateSpec,
3622 TemplateSpecializationKind TSK);
3624 NestedNameSpecifier *
3625 SubstNestedNameSpecifier(NestedNameSpecifier *NNS,
3626 SourceRange Range,
3627 const MultiLevelTemplateArgumentList &TemplateArgs);
3628 DeclarationNameInfo
3629 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
3630 const MultiLevelTemplateArgumentList &TemplateArgs);
3631 TemplateName
3632 SubstTemplateName(TemplateName Name, SourceLocation Loc,
3633 const MultiLevelTemplateArgumentList &TemplateArgs);
3634 bool Subst(const TemplateArgumentLoc &Arg, TemplateArgumentLoc &Result,
3635 const MultiLevelTemplateArgumentList &TemplateArgs);
3637 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
3638 FunctionDecl *Function,
3639 bool Recursive = false,
3640 bool DefinitionRequired = false);
3641 void InstantiateStaticDataMemberDefinition(
3642 SourceLocation PointOfInstantiation,
3643 VarDecl *Var,
3644 bool Recursive = false,
3645 bool DefinitionRequired = false);
3647 void InstantiateMemInitializers(CXXConstructorDecl *New,
3648 const CXXConstructorDecl *Tmpl,
3649 const MultiLevelTemplateArgumentList &TemplateArgs);
3651 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
3652 const MultiLevelTemplateArgumentList &TemplateArgs);
3653 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
3654 const MultiLevelTemplateArgumentList &TemplateArgs);
3656 // Objective-C declarations.
3657 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
3658 IdentifierInfo *ClassName,
3659 SourceLocation ClassLoc,
3660 IdentifierInfo *SuperName,
3661 SourceLocation SuperLoc,
3662 Decl * const *ProtoRefs,
3663 unsigned NumProtoRefs,
3664 const SourceLocation *ProtoLocs,
3665 SourceLocation EndProtoLoc,
3666 AttributeList *AttrList);
3668 Decl *ActOnCompatiblityAlias(
3669 SourceLocation AtCompatibilityAliasLoc,
3670 IdentifierInfo *AliasName, SourceLocation AliasLocation,
3671 IdentifierInfo *ClassName, SourceLocation ClassLocation);
3673 void CheckForwardProtocolDeclarationForCircularDependency(
3674 IdentifierInfo *PName,
3675 SourceLocation &PLoc, SourceLocation PrevLoc,
3676 const ObjCList<ObjCProtocolDecl> &PList);
3678 Decl *ActOnStartProtocolInterface(
3679 SourceLocation AtProtoInterfaceLoc,
3680 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
3681 Decl * const *ProtoRefNames, unsigned NumProtoRefs,
3682 const SourceLocation *ProtoLocs,
3683 SourceLocation EndProtoLoc,
3684 AttributeList *AttrList);
3686 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
3687 IdentifierInfo *ClassName,
3688 SourceLocation ClassLoc,
3689 IdentifierInfo *CategoryName,
3690 SourceLocation CategoryLoc,
3691 Decl * const *ProtoRefs,
3692 unsigned NumProtoRefs,
3693 const SourceLocation *ProtoLocs,
3694 SourceLocation EndProtoLoc);
3696 Decl *ActOnStartClassImplementation(
3697 SourceLocation AtClassImplLoc,
3698 IdentifierInfo *ClassName, SourceLocation ClassLoc,
3699 IdentifierInfo *SuperClassname,
3700 SourceLocation SuperClassLoc);
3702 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
3703 IdentifierInfo *ClassName,
3704 SourceLocation ClassLoc,
3705 IdentifierInfo *CatName,
3706 SourceLocation CatLoc);
3708 Decl *ActOnForwardClassDeclaration(SourceLocation Loc,
3709 IdentifierInfo **IdentList,
3710 SourceLocation *IdentLocs,
3711 unsigned NumElts);
3713 Decl *ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
3714 const IdentifierLocPair *IdentList,
3715 unsigned NumElts,
3716 AttributeList *attrList);
3718 void FindProtocolDeclaration(bool WarnOnDeclarations,
3719 const IdentifierLocPair *ProtocolId,
3720 unsigned NumProtocols,
3721 llvm::SmallVectorImpl<Decl *> &Protocols);
3723 /// Ensure attributes are consistent with type.
3724 /// \param [in, out] Attributes The attributes to check; they will
3725 /// be modified to be consistent with \arg PropertyTy.
3726 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy,
3727 SourceLocation Loc,
3728 unsigned &Attributes);
3730 /// Process the specified property declaration and create decls for the
3731 /// setters and getters as needed.
3732 /// \param property The property declaration being processed
3733 /// \param DC The semantic container for the property
3734 /// \param redeclaredProperty Declaration for property if redeclared
3735 /// in class extension.
3736 /// \param lexicalDC Container for redeclaredProperty.
3737 void ProcessPropertyDecl(ObjCPropertyDecl *property,
3738 ObjCContainerDecl *DC,
3739 ObjCPropertyDecl *redeclaredProperty = 0,
3740 ObjCContainerDecl *lexicalDC = 0);
3742 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
3743 ObjCPropertyDecl *SuperProperty,
3744 const IdentifierInfo *Name);
3745 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
3747 void CompareMethodParamsInBaseAndSuper(Decl *IDecl,
3748 ObjCMethodDecl *MethodDecl,
3749 bool IsInstance);
3751 void CompareProperties(Decl *CDecl, Decl *MergeProtocols);
3753 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
3754 ObjCInterfaceDecl *ID);
3756 void MatchOneProtocolPropertiesInClass(Decl *CDecl,
3757 ObjCProtocolDecl *PDecl);
3759 void ActOnAtEnd(Scope *S, SourceRange AtEnd, Decl *classDecl,
3760 Decl **allMethods = 0, unsigned allNum = 0,
3761 Decl **allProperties = 0, unsigned pNum = 0,
3762 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0);
3764 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc,
3765 FieldDeclarator &FD, ObjCDeclSpec &ODS,
3766 Selector GetterSel, Selector SetterSel,
3767 Decl *ClassCategory,
3768 bool *OverridingProperty,
3769 tok::ObjCKeywordKind MethodImplKind,
3770 DeclContext *lexicalDC = 0);
3772 Decl *ActOnPropertyImplDecl(Scope *S,
3773 SourceLocation AtLoc,
3774 SourceLocation PropertyLoc,
3775 bool ImplKind,Decl *ClassImplDecl,
3776 IdentifierInfo *PropertyId,
3777 IdentifierInfo *PropertyIvar,
3778 SourceLocation PropertyIvarLoc);
3780 struct ObjCArgInfo {
3781 IdentifierInfo *Name;
3782 SourceLocation NameLoc;
3783 // The Type is null if no type was specified, and the DeclSpec is invalid
3784 // in this case.
3785 ParsedType Type;
3786 ObjCDeclSpec DeclSpec;
3788 /// ArgAttrs - Attribute list for this argument.
3789 AttributeList *ArgAttrs;
3792 Decl *ActOnMethodDeclaration(
3793 SourceLocation BeginLoc, // location of the + or -.
3794 SourceLocation EndLoc, // location of the ; or {.
3795 tok::TokenKind MethodType,
3796 Decl *ClassDecl, ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
3797 Selector Sel,
3798 // optional arguments. The number of types/arguments is obtained
3799 // from the Sel.getNumArgs().
3800 ObjCArgInfo *ArgInfo,
3801 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
3802 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
3803 bool isVariadic = false);
3805 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
3806 // Will search "local" class/category implementations for a method decl.
3807 // Will also search in class's root looking for instance method.
3808 // Returns 0 if no method is found.
3809 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
3810 ObjCInterfaceDecl *CDecl);
3811 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
3812 ObjCInterfaceDecl *ClassDecl);
3814 ExprResult
3815 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
3816 Expr *BaseExpr,
3817 DeclarationName MemberName,
3818 SourceLocation MemberLoc,
3819 SourceLocation SuperLoc, QualType SuperType,
3820 bool Super);
3822 ExprResult
3823 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
3824 IdentifierInfo &propertyName,
3825 SourceLocation receiverNameLoc,
3826 SourceLocation propertyNameLoc);
3828 /// \brief Describes the kind of message expression indicated by a message
3829 /// send that starts with an identifier.
3830 enum ObjCMessageKind {
3831 /// \brief The message is sent to 'super'.
3832 ObjCSuperMessage,
3833 /// \brief The message is an instance message.
3834 ObjCInstanceMessage,
3835 /// \brief The message is a class message, and the identifier is a type
3836 /// name.
3837 ObjCClassMessage
3840 ObjCMessageKind getObjCMessageKind(Scope *S,
3841 IdentifierInfo *Name,
3842 SourceLocation NameLoc,
3843 bool IsSuper,
3844 bool HasTrailingDot,
3845 ParsedType &ReceiverType);
3847 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
3848 Selector Sel,
3849 SourceLocation LBracLoc,
3850 SourceLocation SelectorLoc,
3851 SourceLocation RBracLoc,
3852 MultiExprArg Args);
3854 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
3855 QualType ReceiverType,
3856 SourceLocation SuperLoc,
3857 Selector Sel,
3858 ObjCMethodDecl *Method,
3859 SourceLocation LBracLoc,
3860 SourceLocation RBracLoc,
3861 MultiExprArg Args);
3863 ExprResult ActOnClassMessage(Scope *S,
3864 ParsedType Receiver,
3865 Selector Sel,
3866 SourceLocation LBracLoc,
3867 SourceLocation SelectorLoc,
3868 SourceLocation RBracLoc,
3869 MultiExprArg Args);
3871 ExprResult BuildInstanceMessage(Expr *Receiver,
3872 QualType ReceiverType,
3873 SourceLocation SuperLoc,
3874 Selector Sel,
3875 ObjCMethodDecl *Method,
3876 SourceLocation LBracLoc,
3877 SourceLocation RBracLoc,
3878 MultiExprArg Args);
3880 ExprResult ActOnInstanceMessage(Scope *S,
3881 Expr *Receiver,
3882 Selector Sel,
3883 SourceLocation LBracLoc,
3884 SourceLocation SelectorLoc,
3885 SourceLocation RBracLoc,
3886 MultiExprArg Args);
3889 enum PragmaOptionsAlignKind {
3890 POAK_Native, // #pragma options align=native
3891 POAK_Natural, // #pragma options align=natural
3892 POAK_Packed, // #pragma options align=packed
3893 POAK_Power, // #pragma options align=power
3894 POAK_Mac68k, // #pragma options align=mac68k
3895 POAK_Reset // #pragma options align=reset
3898 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
3899 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
3900 SourceLocation PragmaLoc,
3901 SourceLocation KindLoc);
3903 enum PragmaPackKind {
3904 PPK_Default, // #pragma pack([n])
3905 PPK_Show, // #pragma pack(show), only supported by MSVC.
3906 PPK_Push, // #pragma pack(push, [identifier], [n])
3907 PPK_Pop // #pragma pack(pop, [identifier], [n])
3910 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
3911 void ActOnPragmaPack(PragmaPackKind Kind,
3912 IdentifierInfo *Name,
3913 Expr *Alignment,
3914 SourceLocation PragmaLoc,
3915 SourceLocation LParenLoc,
3916 SourceLocation RParenLoc);
3918 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
3919 void ActOnPragmaUnused(const Token *Identifiers,
3920 unsigned NumIdentifiers, Scope *curScope,
3921 SourceLocation PragmaLoc,
3922 SourceLocation LParenLoc,
3923 SourceLocation RParenLoc);
3925 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
3926 void ActOnPragmaVisibility(bool IsPush, const IdentifierInfo* VisType,
3927 SourceLocation PragmaLoc);
3929 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II);
3930 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
3932 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident.
3933 void ActOnPragmaWeakID(IdentifierInfo* WeakName,
3934 SourceLocation PragmaLoc,
3935 SourceLocation WeakNameLoc);
3937 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
3938 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
3939 IdentifierInfo* AliasName,
3940 SourceLocation PragmaLoc,
3941 SourceLocation WeakNameLoc,
3942 SourceLocation AliasNameLoc);
3944 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
3945 /// a the record decl, to handle '#pragma pack' and '#pragma options align'.
3946 void AddAlignmentAttributesForRecord(RecordDecl *RD);
3948 /// FreePackedContext - Deallocate and null out PackContext.
3949 void FreePackedContext();
3951 /// PushVisibilityAttr - Note that we've entered a context with a
3952 /// visibility attribute.
3953 void PushVisibilityAttr(const VisibilityAttr *Attr);
3955 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used,
3956 /// add an appropriate visibility attribute.
3957 void AddPushedVisibilityAttribute(Decl *RD);
3959 /// PopPragmaVisibility - Pop the top element of the visibility stack; used
3960 /// for '#pragma GCC visibility' and visibility attributes on namespaces.
3961 void PopPragmaVisibility();
3963 /// FreeVisContext - Deallocate and null out VisContext.
3964 void FreeVisContext();
3966 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
3967 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E);
3968 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *T);
3970 /// CastCategory - Get the correct forwarded implicit cast result category
3971 /// from the inner expression.
3972 ExprValueKind CastCategory(Expr *E);
3974 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
3975 /// cast. If there is already an implicit cast, merge into the existing one.
3976 /// If isLvalue, the result of the cast is an lvalue.
3977 void ImpCastExprToType(Expr *&Expr, QualType Type, CastKind CK,
3978 ExprValueKind VK = VK_RValue,
3979 const CXXCastPath *BasePath = 0);
3981 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
3982 // functions and arrays to their respective pointers (C99 6.3.2.1).
3983 Expr *UsualUnaryConversions(Expr *&expr);
3985 // DefaultFunctionArrayConversion - converts functions and arrays
3986 // to their respective pointers (C99 6.3.2.1).
3987 void DefaultFunctionArrayConversion(Expr *&expr);
3989 // DefaultFunctionArrayLvalueConversion - converts functions and
3990 // arrays to their respective pointers and performs the
3991 // lvalue-to-rvalue conversion.
3992 void DefaultFunctionArrayLvalueConversion(Expr *&expr);
3994 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
3995 // do not have a prototype. Integer promotions are performed on each
3996 // argument, and arguments that have type float are promoted to double.
3997 void DefaultArgumentPromotion(Expr *&Expr);
3999 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
4000 enum VariadicCallType {
4001 VariadicFunction,
4002 VariadicBlock,
4003 VariadicMethod,
4004 VariadicConstructor,
4005 VariadicDoesNotApply
4008 /// GatherArgumentsForCall - Collector argument expressions for various
4009 /// form of call prototypes.
4010 bool GatherArgumentsForCall(SourceLocation CallLoc,
4011 FunctionDecl *FDecl,
4012 const FunctionProtoType *Proto,
4013 unsigned FirstProtoArg,
4014 Expr **Args, unsigned NumArgs,
4015 llvm::SmallVector<Expr *, 8> &AllArgs,
4016 VariadicCallType CallType = VariadicDoesNotApply);
4018 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
4019 // will warn if the resulting type is not a POD type.
4020 bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT,
4021 FunctionDecl *FDecl);
4023 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
4024 // operands and then handles various conversions that are common to binary
4025 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
4026 // routine returns the first non-arithmetic type found. The client is
4027 // responsible for emitting appropriate error diagnostics.
4028 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
4029 bool isCompAssign = false);
4031 /// AssignConvertType - All of the 'assignment' semantic checks return this
4032 /// enum to indicate whether the assignment was allowed. These checks are
4033 /// done for simple assignments, as well as initialization, return from
4034 /// function, argument passing, etc. The query is phrased in terms of a
4035 /// source and destination type.
4036 enum AssignConvertType {
4037 /// Compatible - the types are compatible according to the standard.
4038 Compatible,
4040 /// PointerToInt - The assignment converts a pointer to an int, which we
4041 /// accept as an extension.
4042 PointerToInt,
4044 /// IntToPointer - The assignment converts an int to a pointer, which we
4045 /// accept as an extension.
4046 IntToPointer,
4048 /// FunctionVoidPointer - The assignment is between a function pointer and
4049 /// void*, which the standard doesn't allow, but we accept as an extension.
4050 FunctionVoidPointer,
4052 /// IncompatiblePointer - The assignment is between two pointers types that
4053 /// are not compatible, but we accept them as an extension.
4054 IncompatiblePointer,
4056 /// IncompatiblePointer - The assignment is between two pointers types which
4057 /// point to integers which have a different sign, but are otherwise identical.
4058 /// This is a subset of the above, but broken out because it's by far the most
4059 /// common case of incompatible pointers.
4060 IncompatiblePointerSign,
4062 /// CompatiblePointerDiscardsQualifiers - The assignment discards
4063 /// c/v/r qualifiers, which we accept as an extension.
4064 CompatiblePointerDiscardsQualifiers,
4066 /// IncompatibleNestedPointerQualifiers - The assignment is between two
4067 /// nested pointer types, and the qualifiers other than the first two
4068 /// levels differ e.g. char ** -> const char **, but we accept them as an
4069 /// extension.
4070 IncompatibleNestedPointerQualifiers,
4072 /// IncompatibleVectors - The assignment is between two vector types that
4073 /// have the same size, which we accept as an extension.
4074 IncompatibleVectors,
4076 /// IntToBlockPointer - The assignment converts an int to a block
4077 /// pointer. We disallow this.
4078 IntToBlockPointer,
4080 /// IncompatibleBlockPointer - The assignment is between two block
4081 /// pointers types that are not compatible.
4082 IncompatibleBlockPointer,
4084 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
4085 /// id type and something else (that is incompatible with it). For example,
4086 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
4087 IncompatibleObjCQualifiedId,
4089 /// Incompatible - We reject this conversion outright, it is invalid to
4090 /// represent it in the AST.
4091 Incompatible
4094 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
4095 /// assignment conversion type specified by ConvTy. This returns true if the
4096 /// conversion was invalid or false if the conversion was accepted.
4097 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
4098 SourceLocation Loc,
4099 QualType DstType, QualType SrcType,
4100 Expr *SrcExpr, AssignmentAction Action,
4101 bool *Complained = 0);
4103 /// CheckAssignmentConstraints - Perform type checking for assignment,
4104 /// argument passing, variable initialization, and function return values.
4105 /// C99 6.5.16.
4106 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
4108 /// Check assignment constraints and prepare for a conversion of the
4109 /// RHS to the LHS type.
4110 AssignConvertType CheckAssignmentConstraints(QualType lhs, Expr *&rhs,
4111 CastKind &Kind);
4113 // CheckSingleAssignmentConstraints - Currently used by
4114 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
4115 // this routine performs the default function/array converions.
4116 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
4117 Expr *&rExpr);
4119 // \brief If the lhs type is a transparent union, check whether we
4120 // can initialize the transparent union with the given expression.
4121 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs,
4122 Expr *&rExpr);
4124 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
4125 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
4126 QualType rhsType);
4128 AssignConvertType CheckObjCPointerTypesForAssignment(QualType lhsType,
4129 QualType rhsType);
4131 // Helper function for CheckAssignmentConstraints involving two
4132 // block pointer types.
4133 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
4134 QualType rhsType);
4136 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
4138 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
4140 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4141 AssignmentAction Action,
4142 bool AllowExplicit = false);
4143 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4144 AssignmentAction Action,
4145 bool AllowExplicit,
4146 ImplicitConversionSequence& ICS);
4147 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4148 const ImplicitConversionSequence& ICS,
4149 AssignmentAction Action,
4150 bool IgnoreBaseAccess = false);
4151 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4152 const StandardConversionSequence& SCS,
4153 AssignmentAction Action,bool IgnoreBaseAccess);
4155 /// the following "Check" methods will return a valid/converted QualType
4156 /// or a null QualType (indicating an error diagnostic was issued).
4158 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
4159 QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
4160 QualType CheckPointerToMemberOperands( // C++ 5.5
4161 Expr *&lex, Expr *&rex, ExprValueKind &VK,
4162 SourceLocation OpLoc, bool isIndirect);
4163 QualType CheckMultiplyDivideOperands( // C99 6.5.5
4164 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign,
4165 bool isDivide);
4166 QualType CheckRemainderOperands( // C99 6.5.5
4167 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
4168 QualType CheckAdditionOperands( // C99 6.5.6
4169 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
4170 QualType CheckSubtractionOperands( // C99 6.5.6
4171 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
4172 QualType CheckShiftOperands( // C99 6.5.7
4173 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
4174 QualType CheckCompareOperands( // C99 6.5.8/9
4175 Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc,
4176 bool isRelational);
4177 QualType CheckBitwiseOperands( // C99 6.5.[10...12]
4178 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
4179 QualType CheckLogicalOperands( // C99 6.5.[13,14]
4180 Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc);
4181 // CheckAssignmentOperands is used for both simple and compound assignment.
4182 // For simple assignment, pass both expressions and a null converted type.
4183 // For compound assignment, pass both expressions and the converted type.
4184 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
4185 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
4187 void ConvertPropertyAssignment(Expr *LHS, Expr *&RHS, QualType& LHSTy);
4189 QualType CheckConditionalOperands( // C99 6.5.15
4190 Expr *&cond, Expr *&lhs, Expr *&rhs, Expr *&save,
4191 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
4192 QualType CXXCheckConditionalOperands( // C++ 5.16
4193 Expr *&cond, Expr *&lhs, Expr *&rhs, Expr *&save,
4194 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
4195 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
4196 bool *NonStandardCompositeType = 0);
4198 QualType FindCompositeObjCPointerType(Expr *&LHS, Expr *&RHS,
4199 SourceLocation questionLoc);
4201 /// type checking for vector binary operators.
4202 QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
4203 QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
4204 SourceLocation l, bool isRel);
4206 /// type checking declaration initializers (C99 6.7.8)
4207 bool CheckInitList(const InitializedEntity &Entity,
4208 InitListExpr *&InitList, QualType &DeclType);
4209 bool CheckForConstantInitializer(Expr *e, QualType t);
4211 // type checking C++ declaration initializers (C++ [dcl.init]).
4213 /// ReferenceCompareResult - Expresses the result of comparing two
4214 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
4215 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
4216 enum ReferenceCompareResult {
4217 /// Ref_Incompatible - The two types are incompatible, so direct
4218 /// reference binding is not possible.
4219 Ref_Incompatible = 0,
4220 /// Ref_Related - The two types are reference-related, which means
4221 /// that their unqualified forms (T1 and T2) are either the same
4222 /// or T1 is a base class of T2.
4223 Ref_Related,
4224 /// Ref_Compatible_With_Added_Qualification - The two types are
4225 /// reference-compatible with added qualification, meaning that
4226 /// they are reference-compatible and the qualifiers on T1 (cv1)
4227 /// are greater than the qualifiers on T2 (cv2).
4228 Ref_Compatible_With_Added_Qualification,
4229 /// Ref_Compatible - The two types are reference-compatible and
4230 /// have equivalent qualifiers (cv1 == cv2).
4231 Ref_Compatible
4234 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
4235 QualType T1, QualType T2,
4236 bool &DerivedToBase,
4237 bool &ObjCConversion);
4239 /// CheckCastTypes - Check type constraints for casting between types under
4240 /// C semantics, or forward to CXXCheckCStyleCast in C++.
4241 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr,
4242 CastKind &Kind, ExprValueKind &VK, CXXCastPath &BasePath,
4243 bool FunctionalStyle = false);
4245 // CheckVectorCast - check type constraints for vectors.
4246 // Since vectors are an extension, there are no C standard reference for this.
4247 // We allow casting between vectors and integer datatypes of the same size.
4248 // returns true if the cast is invalid
4249 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
4250 CastKind &Kind);
4252 // CheckExtVectorCast - check type constraints for extended vectors.
4253 // Since vectors are an extension, there are no C standard reference for this.
4254 // We allow casting between vectors and integer datatypes of the same size,
4255 // or vectors and the element type of that vector.
4256 // returns true if the cast is invalid
4257 bool CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *&CastExpr,
4258 CastKind &Kind);
4260 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style
4261 /// cast under C++ semantics.
4262 bool CXXCheckCStyleCast(SourceRange R, QualType CastTy, ExprValueKind &VK,
4263 Expr *&CastExpr, CastKind &Kind,
4264 CXXCastPath &BasePath, bool FunctionalStyle);
4266 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
4267 /// \param Method - May be null.
4268 /// \param [out] ReturnType - The return type of the send.
4269 /// \return true iff there were any incompatible types.
4270 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
4271 ObjCMethodDecl *Method, bool isClassMessage,
4272 SourceLocation lbrac, SourceLocation rbrac,
4273 QualType &ReturnType, ExprValueKind &VK);
4275 /// CheckBooleanCondition - Diagnose problems involving the use of
4276 /// the given expression as a boolean condition (e.g. in an if
4277 /// statement). Also performs the standard function and array
4278 /// decays, possibly changing the input variable.
4280 /// \param Loc - A location associated with the condition, e.g. the
4281 /// 'if' keyword.
4282 /// \return true iff there were any errors
4283 bool CheckBooleanCondition(Expr *&CondExpr, SourceLocation Loc);
4285 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
4286 Expr *SubExpr);
4288 /// DiagnoseAssignmentAsCondition - Given that an expression is
4289 /// being used as a boolean condition, warn if it's an assignment.
4290 void DiagnoseAssignmentAsCondition(Expr *E);
4292 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
4293 bool CheckCXXBooleanCondition(Expr *&CondExpr);
4295 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
4296 /// the specified width and sign. If an overflow occurs, detect it and emit
4297 /// the specified diagnostic.
4298 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
4299 unsigned NewWidth, bool NewSign,
4300 SourceLocation Loc, unsigned DiagID);
4302 /// Checks that the Objective-C declaration is declared in the global scope.
4303 /// Emits an error and marks the declaration as invalid if it's not declared
4304 /// in the global scope.
4305 bool CheckObjCDeclScope(Decl *D);
4307 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
4308 /// and reports the appropriate diagnostics. Returns false on success.
4309 /// Can optionally return the value of the expression.
4310 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
4312 /// VerifyBitField - verifies that a bit field expression is an ICE and has
4313 /// the correct width, and that the field type is valid.
4314 /// Returns false on success.
4315 /// Can optionally return whether the bit-field is of width 0
4316 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
4317 QualType FieldTy, const Expr *BitWidth,
4318 bool *ZeroWidth = 0);
4320 /// \name Code completion
4321 //@{
4322 /// \brief Describes the context in which code completion occurs.
4323 enum ParserCompletionContext {
4324 /// \brief Code completion occurs at top-level or namespace context.
4325 PCC_Namespace,
4326 /// \brief Code completion occurs within a class, struct, or union.
4327 PCC_Class,
4328 /// \brief Code completion occurs within an Objective-C interface, protocol,
4329 /// or category.
4330 PCC_ObjCInterface,
4331 /// \brief Code completion occurs within an Objective-C implementation or
4332 /// category implementation
4333 PCC_ObjCImplementation,
4334 /// \brief Code completion occurs within the list of instance variables
4335 /// in an Objective-C interface, protocol, category, or implementation.
4336 PCC_ObjCInstanceVariableList,
4337 /// \brief Code completion occurs following one or more template
4338 /// headers.
4339 PCC_Template,
4340 /// \brief Code completion occurs following one or more template
4341 /// headers within a class.
4342 PCC_MemberTemplate,
4343 /// \brief Code completion occurs within an expression.
4344 PCC_Expression,
4345 /// \brief Code completion occurs within a statement, which may
4346 /// also be an expression or a declaration.
4347 PCC_Statement,
4348 /// \brief Code completion occurs at the beginning of the
4349 /// initialization statement (or expression) in a for loop.
4350 PCC_ForInit,
4351 /// \brief Code completion occurs within the condition of an if,
4352 /// while, switch, or for statement.
4353 PCC_Condition,
4354 /// \brief Code completion occurs within the body of a function on a
4355 /// recovery path, where we do not have a specific handle on our position
4356 /// in the grammar.
4357 PCC_RecoveryInFunction,
4358 /// \brief Code completion occurs where only a type is permitted.
4359 PCC_Type,
4360 /// \brief Code completion occurs in a parenthesized expression, which
4361 /// might also be a type cast.
4362 PCC_ParenthesizedExpression
4365 void CodeCompleteOrdinaryName(Scope *S,
4366 ParserCompletionContext CompletionContext);
4367 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
4368 bool AllowNonIdentifiers,
4369 bool AllowNestedNameSpecifiers);
4371 struct CodeCompleteExpressionData;
4372 void CodeCompleteExpression(Scope *S,
4373 const CodeCompleteExpressionData &Data);
4374 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
4375 SourceLocation OpLoc,
4376 bool IsArrow);
4377 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
4378 void CodeCompleteTag(Scope *S, unsigned TagSpec);
4379 void CodeCompleteTypeQualifiers(DeclSpec &DS);
4380 void CodeCompleteCase(Scope *S);
4381 void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs);
4382 void CodeCompleteInitializer(Scope *S, Decl *D);
4383 void CodeCompleteReturn(Scope *S);
4384 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
4386 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
4387 bool EnteringContext);
4388 void CodeCompleteUsing(Scope *S);
4389 void CodeCompleteUsingDirective(Scope *S);
4390 void CodeCompleteNamespaceDecl(Scope *S);
4391 void CodeCompleteNamespaceAliasDecl(Scope *S);
4392 void CodeCompleteOperatorName(Scope *S);
4393 void CodeCompleteConstructorInitializer(Decl *Constructor,
4394 CXXBaseOrMemberInitializer** Initializers,
4395 unsigned NumInitializers);
4397 void CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl,
4398 bool InInterface);
4399 void CodeCompleteObjCAtVisibility(Scope *S);
4400 void CodeCompleteObjCAtStatement(Scope *S);
4401 void CodeCompleteObjCAtExpression(Scope *S);
4402 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
4403 void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl,
4404 Decl **Methods,
4405 unsigned NumMethods);
4406 void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl,
4407 Decl **Methods,
4408 unsigned NumMethods);
4409 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS);
4410 void CodeCompleteObjCMessageReceiver(Scope *S);
4411 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
4412 IdentifierInfo **SelIdents,
4413 unsigned NumSelIdents,
4414 bool AtArgumentExpression);
4415 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
4416 IdentifierInfo **SelIdents,
4417 unsigned NumSelIdents,
4418 bool AtArgumentExpression,
4419 bool IsSuper = false);
4420 void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver,
4421 IdentifierInfo **SelIdents,
4422 unsigned NumSelIdents,
4423 bool AtArgumentExpression,
4424 ObjCInterfaceDecl *Super = 0);
4425 void CodeCompleteObjCForCollection(Scope *S,
4426 DeclGroupPtrTy IterationVar);
4427 void CodeCompleteObjCSelector(Scope *S,
4428 IdentifierInfo **SelIdents,
4429 unsigned NumSelIdents);
4430 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
4431 unsigned NumProtocols);
4432 void CodeCompleteObjCProtocolDecl(Scope *S);
4433 void CodeCompleteObjCInterfaceDecl(Scope *S);
4434 void CodeCompleteObjCSuperclass(Scope *S,
4435 IdentifierInfo *ClassName,
4436 SourceLocation ClassNameLoc);
4437 void CodeCompleteObjCImplementationDecl(Scope *S);
4438 void CodeCompleteObjCInterfaceCategory(Scope *S,
4439 IdentifierInfo *ClassName,
4440 SourceLocation ClassNameLoc);
4441 void CodeCompleteObjCImplementationCategory(Scope *S,
4442 IdentifierInfo *ClassName,
4443 SourceLocation ClassNameLoc);
4444 void CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl);
4445 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
4446 IdentifierInfo *PropertyName,
4447 Decl *ObjCImpDecl);
4448 void CodeCompleteObjCMethodDecl(Scope *S,
4449 bool IsInstanceMethod,
4450 ParsedType ReturnType,
4451 Decl *IDecl);
4452 void CodeCompleteObjCMethodDeclSelector(Scope *S,
4453 bool IsInstanceMethod,
4454 bool AtParameterName,
4455 ParsedType ReturnType,
4456 IdentifierInfo **SelIdents,
4457 unsigned NumSelIdents);
4458 void CodeCompletePreprocessorDirective(bool InConditional);
4459 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
4460 void CodeCompletePreprocessorMacroName(bool IsDefinition);
4461 void CodeCompletePreprocessorExpression();
4462 void CodeCompletePreprocessorMacroArgument(Scope *S,
4463 IdentifierInfo *Macro,
4464 MacroInfo *MacroInfo,
4465 unsigned Argument);
4466 void CodeCompleteNaturalLanguage();
4467 void GatherGlobalCodeCompletions(
4468 llvm::SmallVectorImpl<CodeCompletionResult> &Results);
4469 //@}
4471 void PrintStats() const {}
4473 //===--------------------------------------------------------------------===//
4474 // Extra semantic analysis beyond the C type system
4476 public:
4477 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
4478 unsigned ByteNo) const;
4480 private:
4481 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
4482 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall);
4484 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall);
4485 bool CheckObjCString(Expr *Arg);
4487 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
4488 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
4490 bool SemaBuiltinVAStart(CallExpr *TheCall);
4491 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
4492 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
4494 public:
4495 // Used by C++ template instantiation.
4496 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
4498 private:
4499 bool SemaBuiltinPrefetch(CallExpr *TheCall);
4500 bool SemaBuiltinObjectSize(CallExpr *TheCall);
4501 bool SemaBuiltinLongjmp(CallExpr *TheCall);
4502 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
4503 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
4504 llvm::APSInt &Result);
4506 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall,
4507 bool HasVAListArg, unsigned format_idx,
4508 unsigned firstDataArg, bool isPrintf);
4510 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
4511 const CallExpr *TheCall, bool HasVAListArg,
4512 unsigned format_idx, unsigned firstDataArg,
4513 bool isPrintf);
4515 void CheckNonNullArguments(const NonNullAttr *NonNull,
4516 const CallExpr *TheCall);
4518 void CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg,
4519 unsigned format_idx, unsigned firstDataArg,
4520 bool isPrintf);
4522 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
4523 SourceLocation ReturnLoc);
4524 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
4525 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
4527 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
4528 Expr *Init);
4530 /// \brief The parser's current scope.
4532 /// The parser maintains this state here.
4533 Scope *CurScope;
4535 protected:
4536 friend class Parser;
4537 friend class InitializationSequence;
4539 /// \brief Retrieve the parser's current scope.
4540 Scope *getCurScope() const { return CurScope; }
4543 /// \brief RAII object that enters a new expression evaluation context.
4544 class EnterExpressionEvaluationContext {
4545 Sema &Actions;
4547 public:
4548 EnterExpressionEvaluationContext(Sema &Actions,
4549 Sema::ExpressionEvaluationContext NewContext)
4550 : Actions(Actions) {
4551 Actions.PushExpressionEvaluationContext(NewContext);
4554 ~EnterExpressionEvaluationContext() {
4555 Actions.PopExpressionEvaluationContext();
4559 } // end namespace clang
4561 #endif