Keep the source location of the selector in ObjCMessageExpr.
[clang.git] / include / clang / Sema / Sema.h
blob4df4b7b53542115ae4abe565eb63ea8395919431
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 FunctionDecl;
82 class FunctionProtoType;
83 class FunctionTemplateDecl;
84 class ImplicitConversionSequence;
85 class InitListExpr;
86 class InitializationKind;
87 class InitializationSequence;
88 class InitializedEntity;
89 class IntegerLiteral;
90 class LabelStmt;
91 class LangOptions;
92 class LocalInstantiationScope;
93 class LookupResult;
94 class MacroInfo;
95 class MultiLevelTemplateArgumentList;
96 class NamedDecl;
97 class NonNullAttr;
98 class ObjCCategoryDecl;
99 class ObjCCategoryImplDecl;
100 class ObjCCompatibleAliasDecl;
101 class ObjCContainerDecl;
102 class ObjCImplDecl;
103 class ObjCImplementationDecl;
104 class ObjCInterfaceDecl;
105 class ObjCIvarDecl;
106 template <class T> class ObjCList;
107 class ObjCMethodDecl;
108 class ObjCPropertyDecl;
109 class ObjCProtocolDecl;
110 class OverloadCandidateSet;
111 class ParenListExpr;
112 class ParmVarDecl;
113 class Preprocessor;
114 class PseudoDestructorTypeStorage;
115 class QualType;
116 class StandardConversionSequence;
117 class Stmt;
118 class StringLiteral;
119 class SwitchStmt;
120 class TargetAttributesSema;
121 class TemplateArgument;
122 class TemplateArgumentList;
123 class TemplateArgumentLoc;
124 class TemplateDecl;
125 class TemplateParameterList;
126 class TemplatePartialOrderingContext;
127 class TemplateTemplateParmDecl;
128 class Token;
129 class TypedefDecl;
130 class UnqualifiedId;
131 class UnresolvedLookupExpr;
132 class UnresolvedMemberExpr;
133 class UnresolvedSetImpl;
134 class UnresolvedSetIterator;
135 class UsingDecl;
136 class UsingShadowDecl;
137 class ValueDecl;
138 class VarDecl;
139 class VisibilityAttr;
140 class VisibleDeclConsumer;
141 class IndirectFieldDecl;
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 QualType BuildParenType(QualType T);
624 TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S,
625 TagDecl **OwnedDecl = 0);
626 TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
627 TypeSourceInfo *ReturnTypeInfo);
628 /// \brief Package the given type and TSI into a ParsedType.
629 ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo);
630 DeclarationNameInfo GetNameForDeclarator(Declarator &D);
631 DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name);
632 static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo = 0);
633 bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range);
634 bool CheckDistantExceptionSpec(QualType T);
635 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
636 bool CheckEquivalentExceptionSpec(
637 const FunctionProtoType *Old, SourceLocation OldLoc,
638 const FunctionProtoType *New, SourceLocation NewLoc);
639 bool CheckEquivalentExceptionSpec(
640 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
641 const FunctionProtoType *Old, SourceLocation OldLoc,
642 const FunctionProtoType *New, SourceLocation NewLoc,
643 bool *MissingExceptionSpecification = 0,
644 bool *MissingEmptyExceptionSpecification = 0);
645 bool CheckExceptionSpecSubset(
646 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
647 const FunctionProtoType *Superset, SourceLocation SuperLoc,
648 const FunctionProtoType *Subset, SourceLocation SubLoc);
649 bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
650 const FunctionProtoType *Target, SourceLocation TargetLoc,
651 const FunctionProtoType *Source, SourceLocation SourceLoc);
653 TypeResult ActOnTypeName(Scope *S, Declarator &D);
655 bool RequireCompleteType(SourceLocation Loc, QualType T,
656 const PartialDiagnostic &PD,
657 std::pair<SourceLocation, PartialDiagnostic> Note);
658 bool RequireCompleteType(SourceLocation Loc, QualType T,
659 const PartialDiagnostic &PD);
660 bool RequireCompleteType(SourceLocation Loc, QualType T,
661 unsigned DiagID);
663 QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
664 const CXXScopeSpec &SS, QualType T);
666 QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
667 QualType BuildDecltypeType(Expr *E, SourceLocation Loc);
669 //===--------------------------------------------------------------------===//
670 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
673 DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr);
675 void DiagnoseUseOfUnimplementedSelectors();
677 ParsedType getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
678 Scope *S, CXXScopeSpec *SS = 0,
679 bool isClassName = false,
680 ParsedType ObjectType = ParsedType());
681 TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S);
682 bool DiagnoseUnknownTypeName(const IdentifierInfo &II,
683 SourceLocation IILoc,
684 Scope *S,
685 CXXScopeSpec *SS,
686 ParsedType &SuggestedType);
688 Decl *ActOnDeclarator(Scope *S, Declarator &D);
690 Decl *HandleDeclarator(Scope *S, Declarator &D,
691 MultiTemplateParamsArg TemplateParameterLists,
692 bool IsFunctionDefinition);
693 void RegisterLocallyScopedExternCDecl(NamedDecl *ND,
694 const LookupResult &Previous,
695 Scope *S);
696 void DiagnoseFunctionSpecifiers(Declarator& D);
697 void CheckShadow(Scope *S, VarDecl *D, const LookupResult& R);
698 void CheckShadow(Scope *S, VarDecl *D);
699 void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange);
700 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
701 QualType R, TypeSourceInfo *TInfo,
702 LookupResult &Previous, bool &Redeclaration);
703 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
704 QualType R, TypeSourceInfo *TInfo,
705 LookupResult &Previous,
706 MultiTemplateParamsArg TemplateParamLists,
707 bool &Redeclaration);
708 void CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous,
709 bool &Redeclaration);
710 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
711 QualType R, TypeSourceInfo *TInfo,
712 LookupResult &Previous,
713 MultiTemplateParamsArg TemplateParamLists,
714 bool IsFunctionDefinition,
715 bool &Redeclaration);
716 bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
717 void CheckFunctionDeclaration(Scope *S,
718 FunctionDecl *NewFD, LookupResult &Previous,
719 bool IsExplicitSpecialization,
720 bool &Redeclaration,
721 bool &OverloadableAttrRequired);
722 void CheckMain(FunctionDecl *FD);
723 Decl *ActOnParamDeclarator(Scope *S, Declarator &D);
724 ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC,
725 SourceLocation Loc,
726 QualType T);
727 ParmVarDecl *CheckParameter(DeclContext *DC,
728 TypeSourceInfo *TSInfo, QualType T,
729 IdentifierInfo *Name,
730 SourceLocation NameLoc,
731 StorageClass SC,
732 StorageClass SCAsWritten);
733 void ActOnParamDefaultArgument(Decl *param,
734 SourceLocation EqualLoc,
735 Expr *defarg);
736 void ActOnParamUnparsedDefaultArgument(Decl *param,
737 SourceLocation EqualLoc,
738 SourceLocation ArgLoc);
739 void ActOnParamDefaultArgumentError(Decl *param);
740 bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
741 SourceLocation EqualLoc);
743 void AddInitializerToDecl(Decl *dcl, Expr *init);
744 void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit);
745 void ActOnUninitializedDecl(Decl *dcl, bool TypeContainsUndeducedAuto);
746 void ActOnInitializerError(Decl *Dcl);
747 void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc);
748 DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
749 Decl **Group,
750 unsigned NumDecls);
751 void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
752 SourceLocation LocAfterDecls);
753 Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
754 Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D);
755 void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
757 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body);
758 Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation);
760 /// \brief Diagnose any unused parameters in the given sequence of
761 /// ParmVarDecl pointers.
762 void DiagnoseUnusedParameters(ParmVarDecl * const *Begin,
763 ParmVarDecl * const *End);
765 /// \brief Diagnose whether the size of parameters or return value of a
766 /// function or obj-c method definition is pass-by-value and larger than a
767 /// specified threshold.
768 void DiagnoseSizeOfParametersAndReturnValue(ParmVarDecl * const *Begin,
769 ParmVarDecl * const *End,
770 QualType ReturnTy,
771 NamedDecl *D);
773 void DiagnoseInvalidJumps(Stmt *Body);
774 Decl *ActOnFileScopeAsmDecl(SourceLocation Loc, Expr *expr);
776 /// Scope actions.
777 void ActOnPopScope(SourceLocation Loc, Scope *S);
778 void ActOnTranslationUnitScope(Scope *S);
780 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
781 /// no declarator (e.g. "struct foo;") is parsed.
782 Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
783 DeclSpec &DS);
785 StmtResult ActOnVlaStmt(const DeclSpec &DS);
787 Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
788 AccessSpecifier AS,
789 RecordDecl *Record);
791 Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
792 RecordDecl *Record);
794 bool isAcceptableTagRedeclaration(const TagDecl *Previous,
795 TagTypeKind NewTag,
796 SourceLocation NewTagLoc,
797 const IdentifierInfo &Name);
799 enum TagUseKind {
800 TUK_Reference, // Reference to a tag: 'struct foo *X;'
801 TUK_Declaration, // Fwd decl of a tag: 'struct foo;'
802 TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;'
803 TUK_Friend // Friend declaration: 'friend struct foo;'
806 Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
807 SourceLocation KWLoc, CXXScopeSpec &SS,
808 IdentifierInfo *Name, SourceLocation NameLoc,
809 AttributeList *Attr, AccessSpecifier AS,
810 MultiTemplateParamsArg TemplateParameterLists,
811 bool &OwnedDecl, bool &IsDependent, bool ScopedEnum,
812 bool ScopedEnumUsesClassTag, TypeResult UnderlyingType);
814 Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc,
815 unsigned TagSpec, SourceLocation TagLoc,
816 CXXScopeSpec &SS,
817 IdentifierInfo *Name, SourceLocation NameLoc,
818 AttributeList *Attr,
819 MultiTemplateParamsArg TempParamLists);
821 TypeResult ActOnDependentTag(Scope *S,
822 unsigned TagSpec,
823 TagUseKind TUK,
824 const CXXScopeSpec &SS,
825 IdentifierInfo *Name,
826 SourceLocation TagLoc,
827 SourceLocation NameLoc);
829 void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
830 IdentifierInfo *ClassName,
831 llvm::SmallVectorImpl<Decl *> &Decls);
832 Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart,
833 Declarator &D, Expr *BitfieldWidth);
835 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
836 Declarator &D, Expr *BitfieldWidth,
837 AccessSpecifier AS);
839 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
840 TypeSourceInfo *TInfo,
841 RecordDecl *Record, SourceLocation Loc,
842 bool Mutable, Expr *BitfieldWidth,
843 SourceLocation TSSL,
844 AccessSpecifier AS, NamedDecl *PrevDecl,
845 Declarator *D = 0);
847 enum CXXSpecialMember {
848 CXXInvalid = -1,
849 CXXConstructor = 0,
850 CXXCopyConstructor = 1,
851 CXXCopyAssignment = 2,
852 CXXDestructor = 3
854 bool CheckNontrivialField(FieldDecl *FD);
855 void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem);
856 CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
857 void ActOnLastBitfield(SourceLocation DeclStart, Decl *IntfDecl,
858 llvm::SmallVectorImpl<Decl *> &AllIvarDecls);
859 Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, Decl *IntfDecl,
860 Declarator &D, Expr *BitfieldWidth,
861 tok::ObjCKeywordKind visibility);
863 // This is used for both record definitions and ObjC interface declarations.
864 void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl,
865 Decl **Fields, unsigned NumFields,
866 SourceLocation LBrac, SourceLocation RBrac,
867 AttributeList *AttrList);
869 /// ActOnTagStartDefinition - Invoked when we have entered the
870 /// scope of a tag's definition (e.g., for an enumeration, class,
871 /// struct, or union).
872 void ActOnTagStartDefinition(Scope *S, Decl *TagDecl);
874 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
875 /// C++ record definition's base-specifiers clause and are starting its
876 /// member declarations.
877 void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
878 SourceLocation LBraceLoc);
880 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
881 /// the definition of a tag (enumeration, class, struct, or union).
882 void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl,
883 SourceLocation RBraceLoc);
885 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
886 /// error parsing the definition of a tag.
887 void ActOnTagDefinitionError(Scope *S, Decl *TagDecl);
889 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
890 EnumConstantDecl *LastEnumConst,
891 SourceLocation IdLoc,
892 IdentifierInfo *Id,
893 Expr *val);
895 Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
896 SourceLocation IdLoc, IdentifierInfo *Id,
897 AttributeList *Attrs,
898 SourceLocation EqualLoc, Expr *Val);
899 void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
900 SourceLocation RBraceLoc, Decl *EnumDecl,
901 Decl **Elements, unsigned NumElements,
902 Scope *S, AttributeList *Attr);
904 DeclContext *getContainingDC(DeclContext *DC);
906 /// Set the current declaration context until it gets popped.
907 void PushDeclContext(Scope *S, DeclContext *DC);
908 void PopDeclContext();
910 /// EnterDeclaratorContext - Used when we must lookup names in the context
911 /// of a declarator's nested name specifier.
912 void EnterDeclaratorContext(Scope *S, DeclContext *DC);
913 void ExitDeclaratorContext(Scope *S);
915 DeclContext *getFunctionLevelDeclContext();
917 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
918 /// to the function decl for the function being parsed. If we're currently
919 /// in a 'block', this returns the containing context.
920 FunctionDecl *getCurFunctionDecl();
922 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
923 /// the method decl for the method being parsed. If we're currently
924 /// in a 'block', this returns the containing context.
925 ObjCMethodDecl *getCurMethodDecl();
927 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
928 /// or C function we're in, otherwise return null. If we're currently
929 /// in a 'block', this returns the containing context.
930 NamedDecl *getCurFunctionOrMethodDecl();
932 /// Add this decl to the scope shadowed decl chains.
933 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
935 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
936 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
937 /// true if 'D' belongs to the given declaration context.
938 bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0);
940 /// Finds the scope corresponding to the given decl context, if it
941 /// happens to be an enclosing scope. Otherwise return NULL.
942 static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC);
944 /// Subroutines of ActOnDeclarator().
945 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
946 TypeSourceInfo *TInfo);
947 void MergeTypeDefDecl(TypedefDecl *New, LookupResult &OldDecls);
948 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
949 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
950 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls);
951 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
953 // AssignmentAction - This is used by all the assignment diagnostic functions
954 // to represent what is actually causing the operation
955 enum AssignmentAction {
956 AA_Assigning,
957 AA_Passing,
958 AA_Returning,
959 AA_Converting,
960 AA_Initializing,
961 AA_Sending,
962 AA_Casting
965 /// C++ Overloading.
966 enum OverloadKind {
967 /// This is a legitimate overload: the existing declarations are
968 /// functions or function templates with different signatures.
969 Ovl_Overload,
971 /// This is not an overload because the signature exactly matches
972 /// an existing declaration.
973 Ovl_Match,
975 /// This is not an overload because the lookup results contain a
976 /// non-function.
977 Ovl_NonFunction
979 OverloadKind CheckOverload(Scope *S,
980 FunctionDecl *New,
981 const LookupResult &OldDecls,
982 NamedDecl *&OldDecl,
983 bool IsForUsingDecl);
984 bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl);
986 bool TryImplicitConversion(InitializationSequence &Sequence,
987 const InitializedEntity &Entity,
988 Expr *From,
989 bool SuppressUserConversions,
990 bool AllowExplicit,
991 bool InOverloadResolution);
993 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
994 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
995 bool IsComplexPromotion(QualType FromType, QualType ToType);
996 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
997 bool InOverloadResolution,
998 QualType& ConvertedType, bool &IncompatibleObjC);
999 bool isObjCPointerConversion(QualType FromType, QualType ToType,
1000 QualType& ConvertedType, bool &IncompatibleObjC);
1001 bool FunctionArgTypesAreEqual (FunctionProtoType* OldType,
1002 FunctionProtoType* NewType);
1004 bool CheckPointerConversion(Expr *From, QualType ToType,
1005 CastKind &Kind,
1006 CXXCastPath& BasePath,
1007 bool IgnoreBaseAccess);
1008 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
1009 bool InOverloadResolution,
1010 QualType &ConvertedType);
1011 bool CheckMemberPointerConversion(Expr *From, QualType ToType,
1012 CastKind &Kind,
1013 CXXCastPath &BasePath,
1014 bool IgnoreBaseAccess);
1015 bool IsQualificationConversion(QualType FromType, QualType ToType);
1016 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
1019 ExprResult PerformCopyInitialization(const InitializedEntity &Entity,
1020 SourceLocation EqualLoc,
1021 ExprResult Init);
1022 bool PerformObjectArgumentInitialization(Expr *&From,
1023 NestedNameSpecifier *Qualifier,
1024 NamedDecl *FoundDecl,
1025 CXXMethodDecl *Method);
1027 bool PerformContextuallyConvertToBool(Expr *&From);
1028 bool PerformContextuallyConvertToObjCId(Expr *&From);
1030 ExprResult
1031 ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *FromE,
1032 const PartialDiagnostic &NotIntDiag,
1033 const PartialDiagnostic &IncompleteDiag,
1034 const PartialDiagnostic &ExplicitConvDiag,
1035 const PartialDiagnostic &ExplicitConvNote,
1036 const PartialDiagnostic &AmbigDiag,
1037 const PartialDiagnostic &AmbigNote,
1038 const PartialDiagnostic &ConvDiag);
1040 bool PerformObjectMemberConversion(Expr *&From,
1041 NestedNameSpecifier *Qualifier,
1042 NamedDecl *FoundDecl,
1043 NamedDecl *Member);
1045 // Members have to be NamespaceDecl* or TranslationUnitDecl*.
1046 // TODO: make this is a typesafe union.
1047 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet;
1048 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
1050 void AddOverloadCandidate(NamedDecl *Function,
1051 DeclAccessPair FoundDecl,
1052 Expr **Args, unsigned NumArgs,
1053 OverloadCandidateSet &CandidateSet);
1055 void AddOverloadCandidate(FunctionDecl *Function,
1056 DeclAccessPair FoundDecl,
1057 Expr **Args, unsigned NumArgs,
1058 OverloadCandidateSet& CandidateSet,
1059 bool SuppressUserConversions = false,
1060 bool PartialOverloading = false);
1061 void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
1062 Expr **Args, unsigned NumArgs,
1063 OverloadCandidateSet& CandidateSet,
1064 bool SuppressUserConversions = false);
1065 void AddMethodCandidate(DeclAccessPair FoundDecl,
1066 QualType ObjectType,
1067 Expr **Args, unsigned NumArgs,
1068 OverloadCandidateSet& CandidateSet,
1069 bool SuppressUserConversion = false);
1070 void AddMethodCandidate(CXXMethodDecl *Method,
1071 DeclAccessPair FoundDecl,
1072 CXXRecordDecl *ActingContext, QualType ObjectType,
1073 Expr **Args, unsigned NumArgs,
1074 OverloadCandidateSet& CandidateSet,
1075 bool SuppressUserConversions = false);
1076 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
1077 DeclAccessPair FoundDecl,
1078 CXXRecordDecl *ActingContext,
1079 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1080 QualType ObjectType,
1081 Expr **Args, unsigned NumArgs,
1082 OverloadCandidateSet& CandidateSet,
1083 bool SuppressUserConversions = false);
1084 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
1085 DeclAccessPair FoundDecl,
1086 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1087 Expr **Args, unsigned NumArgs,
1088 OverloadCandidateSet& CandidateSet,
1089 bool SuppressUserConversions = false);
1090 void AddConversionCandidate(CXXConversionDecl *Conversion,
1091 DeclAccessPair FoundDecl,
1092 CXXRecordDecl *ActingContext,
1093 Expr *From, QualType ToType,
1094 OverloadCandidateSet& CandidateSet);
1095 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
1096 DeclAccessPair FoundDecl,
1097 CXXRecordDecl *ActingContext,
1098 Expr *From, QualType ToType,
1099 OverloadCandidateSet &CandidateSet);
1100 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
1101 DeclAccessPair FoundDecl,
1102 CXXRecordDecl *ActingContext,
1103 const FunctionProtoType *Proto,
1104 QualType ObjectTy, Expr **Args, unsigned NumArgs,
1105 OverloadCandidateSet& CandidateSet);
1106 void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
1107 SourceLocation OpLoc,
1108 Expr **Args, unsigned NumArgs,
1109 OverloadCandidateSet& CandidateSet,
1110 SourceRange OpRange = SourceRange());
1111 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
1112 Expr **Args, unsigned NumArgs,
1113 OverloadCandidateSet& CandidateSet,
1114 bool IsAssignmentOperator = false,
1115 unsigned NumContextualBoolArguments = 0);
1116 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
1117 SourceLocation OpLoc,
1118 Expr **Args, unsigned NumArgs,
1119 OverloadCandidateSet& CandidateSet);
1120 void AddArgumentDependentLookupCandidates(DeclarationName Name,
1121 bool Operator,
1122 Expr **Args, unsigned NumArgs,
1123 const TemplateArgumentListInfo *ExplicitTemplateArgs,
1124 OverloadCandidateSet& CandidateSet,
1125 bool PartialOverloading = false);
1127 void NoteOverloadCandidate(FunctionDecl *Fn);
1129 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
1130 bool Complain,
1131 DeclAccessPair &Found);
1132 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(Expr *From);
1134 Expr *FixOverloadedFunctionReference(Expr *E,
1135 DeclAccessPair FoundDecl,
1136 FunctionDecl *Fn);
1137 ExprResult FixOverloadedFunctionReference(ExprResult,
1138 DeclAccessPair FoundDecl,
1139 FunctionDecl *Fn);
1141 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
1142 Expr **Args, unsigned NumArgs,
1143 OverloadCandidateSet &CandidateSet,
1144 bool PartialOverloading = false);
1146 ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn,
1147 UnresolvedLookupExpr *ULE,
1148 SourceLocation LParenLoc,
1149 Expr **Args, unsigned NumArgs,
1150 SourceLocation RParenLoc);
1152 ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
1153 unsigned Opc,
1154 const UnresolvedSetImpl &Fns,
1155 Expr *input);
1157 ExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
1158 unsigned Opc,
1159 const UnresolvedSetImpl &Fns,
1160 Expr *LHS, Expr *RHS);
1162 ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
1163 SourceLocation RLoc,
1164 Expr *Base,Expr *Idx);
1166 ExprResult
1167 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
1168 SourceLocation LParenLoc, Expr **Args,
1169 unsigned NumArgs, SourceLocation RParenLoc);
1170 ExprResult
1171 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
1172 Expr **Args, unsigned NumArgs,
1173 SourceLocation RParenLoc);
1175 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base,
1176 SourceLocation OpLoc);
1178 /// CheckCallReturnType - Checks that a call expression's return type is
1179 /// complete. Returns true on failure. The location passed in is the location
1180 /// that best represents the call.
1181 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
1182 CallExpr *CE, FunctionDecl *FD);
1184 /// Helpers for dealing with blocks and functions.
1185 bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd,
1186 bool CheckParameterNames);
1187 void CheckCXXDefaultArguments(FunctionDecl *FD);
1188 void CheckExtraCXXDefaultArguments(Declarator &D);
1189 Scope *getNonFieldDeclScope(Scope *S);
1191 /// \name Name lookup
1193 /// These routines provide name lookup that is used during semantic
1194 /// analysis to resolve the various kinds of names (identifiers,
1195 /// overloaded operator names, constructor names, etc.) into zero or
1196 /// more declarations within a particular scope. The major entry
1197 /// points are LookupName, which performs unqualified name lookup,
1198 /// and LookupQualifiedName, which performs qualified name lookup.
1200 /// All name lookup is performed based on some specific criteria,
1201 /// which specify what names will be visible to name lookup and how
1202 /// far name lookup should work. These criteria are important both
1203 /// for capturing language semantics (certain lookups will ignore
1204 /// certain names, for example) and for performance, since name
1205 /// lookup is often a bottleneck in the compilation of C++. Name
1206 /// lookup criteria is specified via the LookupCriteria enumeration.
1208 /// The results of name lookup can vary based on the kind of name
1209 /// lookup performed, the current language, and the translation
1210 /// unit. In C, for example, name lookup will either return nothing
1211 /// (no entity found) or a single declaration. In C++, name lookup
1212 /// can additionally refer to a set of overloaded functions or
1213 /// result in an ambiguity. All of the possible results of name
1214 /// lookup are captured by the LookupResult class, which provides
1215 /// the ability to distinguish among them.
1216 //@{
1218 /// @brief Describes the kind of name lookup to perform.
1219 enum LookupNameKind {
1220 /// Ordinary name lookup, which finds ordinary names (functions,
1221 /// variables, typedefs, etc.) in C and most kinds of names
1222 /// (functions, variables, members, types, etc.) in C++.
1223 LookupOrdinaryName = 0,
1224 /// Tag name lookup, which finds the names of enums, classes,
1225 /// structs, and unions.
1226 LookupTagName,
1227 /// Member name lookup, which finds the names of
1228 /// class/struct/union members.
1229 LookupMemberName,
1230 /// Look up of an operator name (e.g., operator+) for use with
1231 /// operator overloading. This lookup is similar to ordinary name
1232 /// lookup, but will ignore any declarations that are class members.
1233 LookupOperatorName,
1234 /// Look up of a name that precedes the '::' scope resolution
1235 /// operator in C++. This lookup completely ignores operator, object,
1236 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
1237 LookupNestedNameSpecifierName,
1238 /// Look up a namespace name within a C++ using directive or
1239 /// namespace alias definition, ignoring non-namespace names (C++
1240 /// [basic.lookup.udir]p1).
1241 LookupNamespaceName,
1242 /// Look up all declarations in a scope with the given name,
1243 /// including resolved using declarations. This is appropriate
1244 /// for checking redeclarations for a using declaration.
1245 LookupUsingDeclName,
1246 /// Look up an ordinary name that is going to be redeclared as a
1247 /// name with linkage. This lookup ignores any declarations that
1248 /// are outside of the current scope unless they have linkage. See
1249 /// C99 6.2.2p4-5 and C++ [basic.link]p6.
1250 LookupRedeclarationWithLinkage,
1251 /// Look up the name of an Objective-C protocol.
1252 LookupObjCProtocolName,
1253 /// \brief Look up any declaration with any name.
1254 LookupAnyName
1257 /// \brief Specifies whether (or how) name lookup is being performed for a
1258 /// redeclaration (vs. a reference).
1259 enum RedeclarationKind {
1260 /// \brief The lookup is a reference to this name that is not for the
1261 /// purpose of redeclaring the name.
1262 NotForRedeclaration = 0,
1263 /// \brief The lookup results will be used for redeclaration of a name,
1264 /// if an entity by that name already exists.
1265 ForRedeclaration
1268 private:
1269 bool CppLookupName(LookupResult &R, Scope *S);
1271 public:
1272 /// \brief Look up a name, looking for a single declaration. Return
1273 /// null if the results were absent, ambiguous, or overloaded.
1275 /// It is preferable to use the elaborated form and explicitly handle
1276 /// ambiguity and overloaded.
1277 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
1278 SourceLocation Loc,
1279 LookupNameKind NameKind,
1280 RedeclarationKind Redecl
1281 = NotForRedeclaration);
1282 bool LookupName(LookupResult &R, Scope *S,
1283 bool AllowBuiltinCreation = false);
1284 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
1285 bool InUnqualifiedLookup = false);
1286 bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
1287 bool AllowBuiltinCreation = false,
1288 bool EnteringContext = false);
1289 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc);
1291 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
1292 QualType T1, QualType T2,
1293 UnresolvedSetImpl &Functions);
1295 DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
1296 CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
1298 void ArgumentDependentLookup(DeclarationName Name, bool Operator,
1299 Expr **Args, unsigned NumArgs,
1300 ADLResult &Functions);
1302 void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
1303 VisibleDeclConsumer &Consumer,
1304 bool IncludeGlobalScope = true);
1305 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
1306 VisibleDeclConsumer &Consumer,
1307 bool IncludeGlobalScope = true);
1309 /// \brief The context in which typo-correction occurs.
1311 /// The typo-correction context affects which keywords (if any) are
1312 /// considered when trying to correct for typos.
1313 enum CorrectTypoContext {
1314 /// \brief An unknown context, where any keyword might be valid.
1315 CTC_Unknown,
1316 /// \brief A context where no keywords are used (e.g. we expect an actual
1317 /// name).
1318 CTC_NoKeywords,
1319 /// \brief A context where we're correcting a type name.
1320 CTC_Type,
1321 /// \brief An expression context.
1322 CTC_Expression,
1323 /// \brief A type cast, or anything else that can be followed by a '<'.
1324 CTC_CXXCasts,
1325 /// \brief A member lookup context.
1326 CTC_MemberLookup,
1327 /// \brief An Objective-C ivar lookup context (e.g., self->ivar).
1328 CTC_ObjCIvarLookup,
1329 /// \brief An Objective-C property lookup context (e.g., self.prop).
1330 CTC_ObjCPropertyLookup,
1331 /// \brief The receiver of an Objective-C message send within an
1332 /// Objective-C method where 'super' is a valid keyword.
1333 CTC_ObjCMessageReceiver
1336 DeclarationName CorrectTypo(LookupResult &R, Scope *S, CXXScopeSpec *SS,
1337 DeclContext *MemberContext = 0,
1338 bool EnteringContext = false,
1339 CorrectTypoContext CTC = CTC_Unknown,
1340 const ObjCObjectPointerType *OPT = 0);
1342 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
1343 AssociatedNamespaceSet &AssociatedNamespaces,
1344 AssociatedClassSet &AssociatedClasses);
1346 bool DiagnoseAmbiguousLookup(LookupResult &Result);
1347 //@}
1349 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
1350 SourceLocation IdLoc,
1351 bool TypoCorrection = false);
1352 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
1353 Scope *S, bool ForRedeclaration,
1354 SourceLocation Loc);
1355 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
1356 Scope *S);
1357 void AddKnownFunctionAttributes(FunctionDecl *FD);
1359 // More parsing and symbol table subroutines.
1361 // Decl attributes - this routine is the top level dispatcher.
1362 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD);
1363 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL);
1365 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
1366 bool &IncompleteImpl, unsigned DiagID);
1367 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
1368 ObjCMethodDecl *IntfMethod);
1370 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
1371 ObjCInterfaceDecl *IDecl);
1373 typedef llvm::DenseSet<Selector, llvm::DenseMapInfo<Selector> > SelectorSet;
1375 /// CheckProtocolMethodDefs - This routine checks unimplemented
1376 /// methods declared in protocol, and those referenced by it.
1377 /// \param IDecl - Used for checking for methods which may have been
1378 /// inherited.
1379 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
1380 ObjCProtocolDecl *PDecl,
1381 bool& IncompleteImpl,
1382 const SelectorSet &InsMap,
1383 const SelectorSet &ClsMap,
1384 ObjCContainerDecl *CDecl);
1386 /// CheckImplementationIvars - This routine checks if the instance variables
1387 /// listed in the implelementation match those listed in the interface.
1388 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
1389 ObjCIvarDecl **Fields, unsigned nIvars,
1390 SourceLocation Loc);
1392 /// \brief Determine whether we can synthesize a provisional ivar for the
1393 /// given name.
1394 ObjCPropertyDecl *canSynthesizeProvisionalIvar(IdentifierInfo *II);
1396 /// \brief Determine whether we can synthesize a provisional ivar for the
1397 /// given property.
1398 bool canSynthesizeProvisionalIvar(ObjCPropertyDecl *Property);
1400 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
1401 /// remains unimplemented in the class or category @implementation.
1402 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
1403 ObjCContainerDecl* IDecl,
1404 bool IncompleteImpl = false);
1406 /// DiagnoseUnimplementedProperties - This routine warns on those properties
1407 /// which must be implemented by this implementation.
1408 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
1409 ObjCContainerDecl *CDecl,
1410 const SelectorSet &InsMap);
1412 /// DefaultSynthesizeProperties - This routine default synthesizes all
1413 /// properties which must be synthesized in class's @implementation.
1414 void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
1415 ObjCInterfaceDecl *IDecl);
1417 /// CollectImmediateProperties - This routine collects all properties in
1418 /// the class and its conforming protocols; but not those it its super class.
1419 void CollectImmediateProperties(ObjCContainerDecl *CDecl,
1420 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap,
1421 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& SuperPropMap);
1424 /// LookupPropertyDecl - Looks up a property in the current class and all
1425 /// its protocols.
1426 ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl,
1427 IdentifierInfo *II);
1429 /// Called by ActOnProperty to handle @property declarations in
1430 //// class extensions.
1431 Decl *HandlePropertyInClassExtension(Scope *S,
1432 ObjCCategoryDecl *CDecl,
1433 SourceLocation AtLoc,
1434 FieldDeclarator &FD,
1435 Selector GetterSel,
1436 Selector SetterSel,
1437 const bool isAssign,
1438 const bool isReadWrite,
1439 const unsigned Attributes,
1440 bool *isOverridingProperty,
1441 TypeSourceInfo *T,
1442 tok::ObjCKeywordKind MethodImplKind);
1444 /// Called by ActOnProperty and HandlePropertyInClassExtension to
1445 /// handle creating the ObjcPropertyDecl for a category or @interface.
1446 ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
1447 ObjCContainerDecl *CDecl,
1448 SourceLocation AtLoc,
1449 FieldDeclarator &FD,
1450 Selector GetterSel,
1451 Selector SetterSel,
1452 const bool isAssign,
1453 const bool isReadWrite,
1454 const unsigned Attributes,
1455 TypeSourceInfo *T,
1456 tok::ObjCKeywordKind MethodImplKind,
1457 DeclContext *lexicalDC = 0);
1459 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
1460 /// warning) when atomic property has one but not the other user-declared
1461 /// setter or getter.
1462 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
1463 ObjCContainerDecl* IDecl);
1465 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
1467 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
1468 /// true, or false, accordingly.
1469 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
1470 const ObjCMethodDecl *PrevMethod,
1471 bool matchBasedOnSizeAndAlignment = false,
1472 bool matchBasedOnStrictEqulity = false);
1474 /// MatchAllMethodDeclarations - Check methods declaraed in interface or
1475 /// or protocol against those declared in their implementations.
1476 void MatchAllMethodDeclarations(const SelectorSet &InsMap,
1477 const SelectorSet &ClsMap,
1478 SelectorSet &InsMapSeen,
1479 SelectorSet &ClsMapSeen,
1480 ObjCImplDecl* IMPDecl,
1481 ObjCContainerDecl* IDecl,
1482 bool &IncompleteImpl,
1483 bool ImmediateClass);
1485 private:
1486 /// AddMethodToGlobalPool - Add an instance or factory method to the global
1487 /// pool. See descriptoin of AddInstanceMethodToGlobalPool.
1488 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
1490 /// LookupMethodInGlobalPool - Returns the instance or factory method and
1491 /// optionally warns if there are multiple signatures.
1492 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
1493 bool receiverIdOrClass,
1494 bool warn, bool instance);
1496 public:
1497 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
1498 /// unit are added to a global pool. This allows us to efficiently associate
1499 /// a selector with a method declaraation for purposes of typechecking
1500 /// messages sent to "id" (where the class of the object is unknown).
1501 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
1502 AddMethodToGlobalPool(Method, impl, /*instance*/true);
1505 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
1506 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) {
1507 AddMethodToGlobalPool(Method, impl, /*instance*/false);
1510 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
1511 /// there are multiple signatures.
1512 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
1513 bool receiverIdOrClass=false,
1514 bool warn=true) {
1515 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
1516 warn, /*instance*/true);
1519 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
1520 /// there are multiple signatures.
1521 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
1522 bool receiverIdOrClass=false,
1523 bool warn=true) {
1524 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
1525 warn, /*instance*/false);
1528 /// LookupImplementedMethodInGlobalPool - Returns the method which has an
1529 /// implementation.
1530 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
1532 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
1533 /// initialization.
1534 void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
1535 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
1536 //===--------------------------------------------------------------------===//
1537 // Statement Parsing Callbacks: SemaStmt.cpp.
1538 public:
1539 class FullExprArg {
1540 public:
1541 FullExprArg(Sema &actions) : E(0) { }
1543 // FIXME: The const_cast here is ugly. RValue references would make this
1544 // much nicer (or we could duplicate a bunch of the move semantics
1545 // emulation code from Ownership.h).
1546 FullExprArg(const FullExprArg& Other) : E(Other.E) {}
1548 ExprResult release() {
1549 return move(E);
1552 Expr *get() const { return E; }
1554 Expr *operator->() {
1555 return E;
1558 private:
1559 // FIXME: No need to make the entire Sema class a friend when it's just
1560 // Sema::MakeFullExpr that needs access to the constructor below.
1561 friend class Sema;
1563 explicit FullExprArg(Expr *expr) : E(expr) {}
1565 Expr *E;
1568 FullExprArg MakeFullExpr(Expr *Arg) {
1569 return FullExprArg(ActOnFinishFullExpr(Arg).release());
1572 StmtResult ActOnExprStmt(FullExprArg Expr);
1574 StmtResult ActOnNullStmt(SourceLocation SemiLoc,
1575 bool LeadingEmptyMacro = false);
1576 StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1577 MultiStmtArg Elts,
1578 bool isStmtExpr);
1579 StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
1580 SourceLocation StartLoc,
1581 SourceLocation EndLoc);
1582 void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
1583 StmtResult ActOnForEachLValueExpr(Expr *E);
1584 StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal,
1585 SourceLocation DotDotDotLoc, Expr *RHSVal,
1586 SourceLocation ColonLoc);
1587 void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt);
1589 StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1590 SourceLocation ColonLoc,
1591 Stmt *SubStmt, Scope *CurScope);
1592 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
1593 SourceLocation ColonLoc, Stmt *SubStmt,
1594 const AttributeList *Attr);
1595 StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
1596 SourceLocation ColonLoc, Stmt *SubStmt,
1597 bool HasUnusedAttr);
1598 StmtResult ActOnIfStmt(SourceLocation IfLoc,
1599 FullExprArg CondVal, Decl *CondVar,
1600 Stmt *ThenVal,
1601 SourceLocation ElseLoc, Stmt *ElseVal);
1602 StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc,
1603 Expr *Cond,
1604 Decl *CondVar);
1605 StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1606 Stmt *Switch, Stmt *Body);
1607 StmtResult ActOnWhileStmt(SourceLocation WhileLoc,
1608 FullExprArg Cond,
1609 Decl *CondVar, Stmt *Body);
1610 StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
1611 SourceLocation WhileLoc,
1612 SourceLocation CondLParen, Expr *Cond,
1613 SourceLocation CondRParen);
1615 StmtResult ActOnForStmt(SourceLocation ForLoc,
1616 SourceLocation LParenLoc,
1617 Stmt *First, FullExprArg Second,
1618 Decl *SecondVar,
1619 FullExprArg Third,
1620 SourceLocation RParenLoc,
1621 Stmt *Body);
1622 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1623 SourceLocation LParenLoc,
1624 Stmt *First, Expr *Second,
1625 SourceLocation RParenLoc, Stmt *Body);
1627 StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1628 SourceLocation LabelLoc,
1629 IdentifierInfo *LabelII);
1630 StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1631 SourceLocation StarLoc,
1632 Expr *DestExp);
1633 StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope);
1634 StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
1636 StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
1637 StmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
1639 StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1640 bool IsSimple, bool IsVolatile,
1641 unsigned NumOutputs, unsigned NumInputs,
1642 IdentifierInfo **Names,
1643 MultiExprArg Constraints,
1644 MultiExprArg Exprs,
1645 Expr *AsmString,
1646 MultiExprArg Clobbers,
1647 SourceLocation RParenLoc,
1648 bool MSAsm = false);
1651 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType,
1652 IdentifierInfo *Name, SourceLocation NameLoc,
1653 bool Invalid = false);
1655 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D);
1657 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen,
1658 Decl *Parm, Stmt *Body);
1660 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body);
1662 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try,
1663 MultiStmtArg Catch, Stmt *Finally);
1665 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw);
1666 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw,
1667 Scope *CurScope);
1668 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1669 Expr *SynchExpr,
1670 Stmt *SynchBody);
1672 VarDecl *BuildExceptionDeclaration(Scope *S,
1673 TypeSourceInfo *TInfo,
1674 IdentifierInfo *Name,
1675 SourceLocation Loc);
1676 Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D);
1678 StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
1679 Decl *ExDecl, Stmt *HandlerBlock);
1680 StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
1681 MultiStmtArg Handlers);
1682 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
1684 bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const;
1686 /// \brief If it's a file scoped decl that must warn if not used, keep track
1687 /// of it.
1688 void MarkUnusedFileScopedDecl(const DeclaratorDecl *D);
1690 /// DiagnoseUnusedExprResult - If the statement passed in is an expression
1691 /// whose result is unused, warn.
1692 void DiagnoseUnusedExprResult(const Stmt *S);
1693 void DiagnoseUnusedDecl(const NamedDecl *ND);
1695 typedef uintptr_t ParsingDeclStackState;
1697 ParsingDeclStackState PushParsingDeclaration();
1698 void PopParsingDeclaration(ParsingDeclStackState S, Decl *D);
1699 void EmitDeprecationWarning(NamedDecl *D, llvm::StringRef Message,
1700 SourceLocation Loc);
1702 void HandleDelayedDeprecationCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
1704 //===--------------------------------------------------------------------===//
1705 // Expression Parsing Callbacks: SemaExpr.cpp.
1707 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
1708 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
1709 ObjCMethodDecl *Getter,
1710 SourceLocation Loc);
1711 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
1712 Expr **Args, unsigned NumArgs);
1714 void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext);
1716 void PopExpressionEvaluationContext();
1718 void MarkDeclarationReferenced(SourceLocation Loc, Decl *D);
1719 void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T);
1720 void MarkDeclarationsReferencedInExpr(Expr *E);
1721 bool DiagRuntimeBehavior(SourceLocation Loc, const PartialDiagnostic &PD);
1723 // Primary Expressions.
1724 SourceRange getExprRange(Expr *E) const;
1726 ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, UnqualifiedId &Name,
1727 bool HasTrailingLParen, bool IsAddressOfOperand);
1729 bool DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
1730 CorrectTypoContext CTC = CTC_Unknown);
1732 ExprResult LookupInObjCMethod(LookupResult &R, Scope *S, IdentifierInfo *II,
1733 bool AllowBuiltinCreation=false);
1735 ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
1736 const DeclarationNameInfo &NameInfo,
1737 bool isAddressOfOperand,
1738 const TemplateArgumentListInfo *TemplateArgs);
1740 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
1741 ExprValueKind VK,
1742 SourceLocation Loc,
1743 const CXXScopeSpec *SS = 0);
1744 ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
1745 ExprValueKind VK,
1746 const DeclarationNameInfo &NameInfo,
1747 const CXXScopeSpec *SS = 0);
1748 ExprResult
1749 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1750 IndirectFieldDecl *IndirectField,
1751 Expr *BaseObjectExpr = 0,
1752 SourceLocation OpLoc = SourceLocation());
1753 ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
1754 LookupResult &R,
1755 const TemplateArgumentListInfo *TemplateArgs);
1756 ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
1757 LookupResult &R,
1758 const TemplateArgumentListInfo *TemplateArgs,
1759 bool IsDefiniteInstance);
1760 bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
1761 const LookupResult &R,
1762 bool HasTrailingLParen);
1764 ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
1765 const DeclarationNameInfo &NameInfo);
1766 ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
1767 const DeclarationNameInfo &NameInfo,
1768 const TemplateArgumentListInfo *TemplateArgs);
1770 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
1771 LookupResult &R,
1772 bool ADL);
1773 ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
1774 const DeclarationNameInfo &NameInfo,
1775 NamedDecl *D);
1777 ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
1778 ExprResult ActOnNumericConstant(const Token &);
1779 ExprResult ActOnCharacterConstant(const Token &);
1780 ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *Val);
1781 ExprResult ActOnParenOrParenListExpr(SourceLocation L,
1782 SourceLocation R,
1783 MultiExprArg Val,
1784 ParsedType TypeOfCast = ParsedType());
1786 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
1787 /// fragments (e.g. "foo" "bar" L"baz").
1788 ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
1790 // Binary/Unary Operators. 'Tok' is the token for the operator.
1791 ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, unsigned OpcIn,
1792 Expr *InputArg);
1793 ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
1794 UnaryOperatorKind Opc, Expr *input);
1795 ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1796 tok::TokenKind Op, Expr *Input);
1798 ExprResult CreateSizeOfAlignOfExpr(TypeSourceInfo *T,
1799 SourceLocation OpLoc,
1800 bool isSizeOf, SourceRange R);
1801 ExprResult CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc,
1802 bool isSizeOf, SourceRange R);
1803 ExprResult
1804 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1805 void *TyOrEx, const SourceRange &ArgRange);
1807 ExprResult CheckPlaceholderExpr(Expr *E, SourceLocation Loc);
1809 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1810 SourceRange R, bool isSizeof);
1812 ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1813 tok::TokenKind Kind, Expr *Input);
1815 ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc,
1816 Expr *Idx, SourceLocation RLoc);
1817 ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
1818 Expr *Idx, SourceLocation RLoc);
1820 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
1821 SourceLocation OpLoc, bool IsArrow,
1822 CXXScopeSpec &SS,
1823 NamedDecl *FirstQualifierInScope,
1824 const DeclarationNameInfo &NameInfo,
1825 const TemplateArgumentListInfo *TemplateArgs);
1827 ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
1828 SourceLocation OpLoc, bool IsArrow,
1829 const CXXScopeSpec &SS,
1830 NamedDecl *FirstQualifierInScope,
1831 LookupResult &R,
1832 const TemplateArgumentListInfo *TemplateArgs,
1833 bool SuppressQualifierCheck = false);
1835 ExprResult LookupMemberExpr(LookupResult &R, Expr *&Base,
1836 bool &IsArrow, SourceLocation OpLoc,
1837 CXXScopeSpec &SS,
1838 Decl *ObjCImpDecl,
1839 bool HasTemplateArgs);
1841 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
1842 const CXXScopeSpec &SS,
1843 const LookupResult &R);
1845 ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType,
1846 bool IsArrow, SourceLocation OpLoc,
1847 const CXXScopeSpec &SS,
1848 NamedDecl *FirstQualifierInScope,
1849 const DeclarationNameInfo &NameInfo,
1850 const TemplateArgumentListInfo *TemplateArgs);
1852 ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base,
1853 SourceLocation OpLoc,
1854 tok::TokenKind OpKind,
1855 CXXScopeSpec &SS,
1856 UnqualifiedId &Member,
1857 Decl *ObjCImpDecl,
1858 bool HasTrailingLParen);
1860 void ActOnDefaultCtorInitializers(Decl *CDtorDecl);
1861 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
1862 FunctionDecl *FDecl,
1863 const FunctionProtoType *Proto,
1864 Expr **Args, unsigned NumArgs,
1865 SourceLocation RParenLoc);
1867 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
1868 /// This provides the location of the left/right parens and a list of comma
1869 /// locations.
1870 ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc,
1871 MultiExprArg Args, SourceLocation RParenLoc);
1872 ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
1873 SourceLocation LParenLoc,
1874 Expr **Args, unsigned NumArgs,
1875 SourceLocation RParenLoc);
1877 ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
1878 ParsedType Ty, SourceLocation RParenLoc,
1879 Expr *Op);
1880 ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
1881 TypeSourceInfo *Ty,
1882 SourceLocation RParenLoc,
1883 Expr *Op);
1885 bool TypeIsVectorType(ParsedType Ty) {
1886 return GetTypeFromParser(Ty)->isVectorType();
1889 ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME);
1890 ExprResult ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc,
1891 SourceLocation RParenLoc, Expr *E,
1892 TypeSourceInfo *TInfo);
1894 ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1895 ParsedType Ty,
1896 SourceLocation RParenLoc,
1897 Expr *Op);
1899 ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
1900 TypeSourceInfo *TInfo,
1901 SourceLocation RParenLoc,
1902 Expr *InitExpr);
1904 ExprResult ActOnInitList(SourceLocation LParenLoc,
1905 MultiExprArg InitList,
1906 SourceLocation RParenLoc);
1908 ExprResult ActOnDesignatedInitializer(Designation &Desig,
1909 SourceLocation Loc,
1910 bool GNUSyntax,
1911 ExprResult Init);
1913 ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1914 tok::TokenKind Kind, Expr *LHS, Expr *RHS);
1915 ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
1916 BinaryOperatorKind Opc, Expr *lhs, Expr *rhs);
1917 ExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1918 unsigned Opc, Expr *lhs, Expr *rhs);
1920 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
1921 /// in the case of a the GNU conditional expr extension.
1922 ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1923 SourceLocation ColonLoc,
1924 Expr *Cond, Expr *LHS, Expr *RHS);
1926 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1927 ExprResult ActOnAddrLabel(SourceLocation OpLoc,
1928 SourceLocation LabLoc,
1929 IdentifierInfo *LabelII);
1931 ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
1932 SourceLocation RPLoc); // "({..})"
1934 // __builtin_offsetof(type, identifier(.identifier|[expr])*)
1935 struct OffsetOfComponent {
1936 SourceLocation LocStart, LocEnd;
1937 bool isBrackets; // true if [expr], false if .ident
1938 union {
1939 IdentifierInfo *IdentInfo;
1940 ExprTy *E;
1941 } U;
1944 /// __builtin_offsetof(type, a.b[123][456].c)
1945 ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc,
1946 TypeSourceInfo *TInfo,
1947 OffsetOfComponent *CompPtr,
1948 unsigned NumComponents,
1949 SourceLocation RParenLoc);
1950 ExprResult ActOnBuiltinOffsetOf(Scope *S,
1951 SourceLocation BuiltinLoc,
1952 SourceLocation TypeLoc,
1953 ParsedType Arg1,
1954 OffsetOfComponent *CompPtr,
1955 unsigned NumComponents,
1956 SourceLocation RParenLoc);
1958 // __builtin_choose_expr(constExpr, expr1, expr2)
1959 ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
1960 Expr *cond, Expr *expr1,
1961 Expr *expr2, SourceLocation RPLoc);
1963 // __builtin_va_arg(expr, type)
1964 ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1965 Expr *expr, ParsedType type,
1966 SourceLocation RPLoc);
1967 ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc,
1968 Expr *expr, TypeSourceInfo *TInfo,
1969 SourceLocation RPLoc);
1971 // __null
1972 ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1974 //===------------------------- "Block" Extension ------------------------===//
1976 /// ActOnBlockStart - This callback is invoked when a block literal is
1977 /// started.
1978 void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1980 /// ActOnBlockArguments - This callback allows processing of block arguments.
1981 /// If there are no arguments, this is still invoked.
1982 void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
1984 /// ActOnBlockError - If there is an error parsing a block, this callback
1985 /// is invoked to pop the information about the block from the action impl.
1986 void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1988 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1989 /// literal was successfully completed. ^(int x){...}
1990 ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc,
1991 Stmt *Body, Scope *CurScope);
1993 //===---------------------------- C++ Features --------------------------===//
1995 // Act on C++ namespaces
1996 Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc,
1997 SourceLocation IdentLoc,
1998 IdentifierInfo *Ident,
1999 SourceLocation LBrace,
2000 AttributeList *AttrList);
2001 void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);
2003 NamespaceDecl *getStdNamespace() const;
2004 NamespaceDecl *getOrCreateStdNamespace();
2006 CXXRecordDecl *getStdBadAlloc() const;
2008 Decl *ActOnUsingDirective(Scope *CurScope,
2009 SourceLocation UsingLoc,
2010 SourceLocation NamespcLoc,
2011 CXXScopeSpec &SS,
2012 SourceLocation IdentLoc,
2013 IdentifierInfo *NamespcName,
2014 AttributeList *AttrList);
2016 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
2018 Decl *ActOnNamespaceAliasDef(Scope *CurScope,
2019 SourceLocation NamespaceLoc,
2020 SourceLocation AliasLoc,
2021 IdentifierInfo *Alias,
2022 CXXScopeSpec &SS,
2023 SourceLocation IdentLoc,
2024 IdentifierInfo *Ident);
2026 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
2027 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
2028 const LookupResult &PreviousDecls);
2029 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
2030 NamedDecl *Target);
2032 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
2033 bool isTypeName,
2034 const CXXScopeSpec &SS,
2035 SourceLocation NameLoc,
2036 const LookupResult &Previous);
2037 bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
2038 const CXXScopeSpec &SS,
2039 SourceLocation NameLoc);
2041 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
2042 SourceLocation UsingLoc,
2043 CXXScopeSpec &SS,
2044 const DeclarationNameInfo &NameInfo,
2045 AttributeList *AttrList,
2046 bool IsInstantiation,
2047 bool IsTypeName,
2048 SourceLocation TypenameLoc);
2050 Decl *ActOnUsingDeclaration(Scope *CurScope,
2051 AccessSpecifier AS,
2052 bool HasUsingKeyword,
2053 SourceLocation UsingLoc,
2054 CXXScopeSpec &SS,
2055 UnqualifiedId &Name,
2056 AttributeList *AttrList,
2057 bool IsTypeName,
2058 SourceLocation TypenameLoc);
2060 /// AddCXXDirectInitializerToDecl - This action is called immediately after
2061 /// ActOnDeclarator, when a C++ direct initializer is present.
2062 /// e.g: "int x(1);"
2063 void AddCXXDirectInitializerToDecl(Decl *Dcl,
2064 SourceLocation LParenLoc,
2065 MultiExprArg Exprs,
2066 SourceLocation RParenLoc);
2068 /// InitializeVarWithConstructor - Creates an CXXConstructExpr
2069 /// and sets it as the initializer for the the passed in VarDecl.
2070 bool InitializeVarWithConstructor(VarDecl *VD,
2071 CXXConstructorDecl *Constructor,
2072 MultiExprArg Exprs);
2074 /// BuildCXXConstructExpr - Creates a complete call to a constructor,
2075 /// including handling of its default argument expressions.
2077 /// \param ConstructKind - a CXXConstructExpr::ConstructionKind
2078 ExprResult
2079 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2080 CXXConstructorDecl *Constructor, MultiExprArg Exprs,
2081 bool RequiresZeroInit, unsigned ConstructKind,
2082 SourceRange ParenRange);
2084 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
2085 // the constructor can be elidable?
2086 ExprResult
2087 BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
2088 CXXConstructorDecl *Constructor, bool Elidable,
2089 MultiExprArg Exprs, bool RequiresZeroInit,
2090 unsigned ConstructKind,
2091 SourceRange ParenRange);
2093 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
2094 /// the default expr if needed.
2095 ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
2096 FunctionDecl *FD,
2097 ParmVarDecl *Param);
2099 /// FinalizeVarWithDestructor - Prepare for calling destructor on the
2100 /// constructed variable.
2101 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
2103 /// \brief Declare the implicit default constructor for the given class.
2105 /// \param ClassDecl The class declaration into which the implicit
2106 /// default constructor will be added.
2108 /// \returns The implicitly-declared default constructor.
2109 CXXConstructorDecl *DeclareImplicitDefaultConstructor(
2110 CXXRecordDecl *ClassDecl);
2112 /// DefineImplicitDefaultConstructor - Checks for feasibility of
2113 /// defining this constructor as the default constructor.
2114 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
2115 CXXConstructorDecl *Constructor);
2117 /// \brief Declare the implicit destructor for the given class.
2119 /// \param ClassDecl The class declaration into which the implicit
2120 /// destructor will be added.
2122 /// \returns The implicitly-declared destructor.
2123 CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl);
2125 /// DefineImplicitDestructor - Checks for feasibility of
2126 /// defining this destructor as the default destructor.
2127 void DefineImplicitDestructor(SourceLocation CurrentLocation,
2128 CXXDestructorDecl *Destructor);
2130 /// \brief Declare the implicit copy constructor for the given class.
2132 /// \param S The scope of the class, which may be NULL if this is a
2133 /// template instantiation.
2135 /// \param ClassDecl The class declaration into which the implicit
2136 /// copy constructor will be added.
2138 /// \returns The implicitly-declared copy constructor.
2139 CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl);
2141 /// DefineImplicitCopyConstructor - Checks for feasibility of
2142 /// defining this constructor as the copy constructor.
2143 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
2144 CXXConstructorDecl *Constructor,
2145 unsigned TypeQuals);
2147 /// \brief Declare the implicit copy assignment operator for the given class.
2149 /// \param S The scope of the class, which may be NULL if this is a
2150 /// template instantiation.
2152 /// \param ClassDecl The class declaration into which the implicit
2153 /// copy-assignment operator will be added.
2155 /// \returns The implicitly-declared copy assignment operator.
2156 CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl);
2158 /// \brief Defined an implicitly-declared copy assignment operator.
2159 void DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
2160 CXXMethodDecl *MethodDecl);
2162 /// \brief Force the declaration of any implicitly-declared members of this
2163 /// class.
2164 void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class);
2166 /// MaybeBindToTemporary - If the passed in expression has a record type with
2167 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
2168 /// it simply returns the passed in expression.
2169 ExprResult MaybeBindToTemporary(Expr *E);
2171 bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
2172 MultiExprArg ArgsPtr,
2173 SourceLocation Loc,
2174 ASTOwningVector<Expr*> &ConvertedArgs);
2176 ParsedType getDestructorName(SourceLocation TildeLoc,
2177 IdentifierInfo &II, SourceLocation NameLoc,
2178 Scope *S, CXXScopeSpec &SS,
2179 ParsedType ObjectType,
2180 bool EnteringContext);
2182 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
2183 ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
2184 tok::TokenKind Kind,
2185 SourceLocation LAngleBracketLoc,
2186 ParsedType Ty,
2187 SourceLocation RAngleBracketLoc,
2188 SourceLocation LParenLoc,
2189 Expr *E,
2190 SourceLocation RParenLoc);
2192 ExprResult BuildCXXNamedCast(SourceLocation OpLoc,
2193 tok::TokenKind Kind,
2194 TypeSourceInfo *Ty,
2195 Expr *E,
2196 SourceRange AngleBrackets,
2197 SourceRange Parens);
2199 ExprResult BuildCXXTypeId(QualType TypeInfoType,
2200 SourceLocation TypeidLoc,
2201 TypeSourceInfo *Operand,
2202 SourceLocation RParenLoc);
2203 ExprResult BuildCXXTypeId(QualType TypeInfoType,
2204 SourceLocation TypeidLoc,
2205 Expr *Operand,
2206 SourceLocation RParenLoc);
2208 /// ActOnCXXTypeid - Parse typeid( something ).
2209 ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
2210 SourceLocation LParenLoc, bool isType,
2211 void *TyOrExpr,
2212 SourceLocation RParenLoc);
2214 ExprResult BuildCXXUuidof(QualType TypeInfoType,
2215 SourceLocation TypeidLoc,
2216 TypeSourceInfo *Operand,
2217 SourceLocation RParenLoc);
2218 ExprResult BuildCXXUuidof(QualType TypeInfoType,
2219 SourceLocation TypeidLoc,
2220 Expr *Operand,
2221 SourceLocation RParenLoc);
2223 /// ActOnCXXUuidof - Parse __uuidof( something ).
2224 ExprResult ActOnCXXUuidof(SourceLocation OpLoc,
2225 SourceLocation LParenLoc, bool isType,
2226 void *TyOrExpr,
2227 SourceLocation RParenLoc);
2230 //// ActOnCXXThis - Parse 'this' pointer.
2231 ExprResult ActOnCXXThis(SourceLocation ThisLoc);
2233 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
2234 ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
2236 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
2237 ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
2239 //// ActOnCXXThrow - Parse throw expressions.
2240 ExprResult ActOnCXXThrow(SourceLocation OpLoc, Expr *expr);
2241 bool CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E);
2243 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
2244 /// Can be interpreted either as function-style casting ("int(x)")
2245 /// or class type construction ("ClassType(x,y,z)")
2246 /// or creation of a value-initialized type ("int()").
2247 ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep,
2248 SourceLocation LParenLoc,
2249 MultiExprArg Exprs,
2250 SourceLocation RParenLoc);
2252 ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type,
2253 SourceLocation LParenLoc,
2254 MultiExprArg Exprs,
2255 SourceLocation RParenLoc);
2257 /// ActOnCXXNew - Parsed a C++ 'new' expression.
2258 ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
2259 SourceLocation PlacementLParen,
2260 MultiExprArg PlacementArgs,
2261 SourceLocation PlacementRParen,
2262 SourceRange TypeIdParens, Declarator &D,
2263 SourceLocation ConstructorLParen,
2264 MultiExprArg ConstructorArgs,
2265 SourceLocation ConstructorRParen);
2266 ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
2267 SourceLocation PlacementLParen,
2268 MultiExprArg PlacementArgs,
2269 SourceLocation PlacementRParen,
2270 SourceRange TypeIdParens,
2271 QualType AllocType,
2272 TypeSourceInfo *AllocTypeInfo,
2273 Expr *ArraySize,
2274 SourceLocation ConstructorLParen,
2275 MultiExprArg ConstructorArgs,
2276 SourceLocation ConstructorRParen);
2278 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
2279 SourceRange R);
2280 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
2281 bool UseGlobal, QualType AllocType, bool IsArray,
2282 Expr **PlaceArgs, unsigned NumPlaceArgs,
2283 FunctionDecl *&OperatorNew,
2284 FunctionDecl *&OperatorDelete);
2285 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
2286 DeclarationName Name, Expr** Args,
2287 unsigned NumArgs, DeclContext *Ctx,
2288 bool AllowMissing, FunctionDecl *&Operator);
2289 void DeclareGlobalNewDelete();
2290 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
2291 QualType Argument,
2292 bool addMallocAttr = false);
2294 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
2295 DeclarationName Name, FunctionDecl* &Operator);
2297 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
2298 ExprResult ActOnCXXDelete(SourceLocation StartLoc,
2299 bool UseGlobal, bool ArrayForm,
2300 Expr *Operand);
2302 DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D);
2303 ExprResult CheckConditionVariable(VarDecl *ConditionVar,
2304 SourceLocation StmtLoc,
2305 bool ConvertToBoolean);
2307 ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen,
2308 Expr *Operand, SourceLocation RParen);
2309 ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
2310 SourceLocation RParen);
2312 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
2313 /// pseudo-functions.
2314 ExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
2315 SourceLocation KWLoc,
2316 ParsedType Ty,
2317 SourceLocation RParen);
2319 ExprResult BuildUnaryTypeTrait(UnaryTypeTrait OTT,
2320 SourceLocation KWLoc,
2321 TypeSourceInfo *T,
2322 SourceLocation RParen);
2324 /// ActOnBinaryTypeTrait - Parsed one of the bianry type trait support
2325 /// pseudo-functions.
2326 ExprResult ActOnBinaryTypeTrait(BinaryTypeTrait OTT,
2327 SourceLocation KWLoc,
2328 ParsedType LhsTy,
2329 ParsedType RhsTy,
2330 SourceLocation RParen);
2332 ExprResult BuildBinaryTypeTrait(BinaryTypeTrait BTT,
2333 SourceLocation KWLoc,
2334 TypeSourceInfo *LhsT,
2335 TypeSourceInfo *RhsT,
2336 SourceLocation RParen);
2338 ExprResult ActOnStartCXXMemberReference(Scope *S,
2339 Expr *Base,
2340 SourceLocation OpLoc,
2341 tok::TokenKind OpKind,
2342 ParsedType &ObjectType,
2343 bool &MayBePseudoDestructor);
2345 ExprResult DiagnoseDtorReference(SourceLocation NameLoc, Expr *MemExpr);
2347 ExprResult BuildPseudoDestructorExpr(Expr *Base,
2348 SourceLocation OpLoc,
2349 tok::TokenKind OpKind,
2350 const CXXScopeSpec &SS,
2351 TypeSourceInfo *ScopeType,
2352 SourceLocation CCLoc,
2353 SourceLocation TildeLoc,
2354 PseudoDestructorTypeStorage DestroyedType,
2355 bool HasTrailingLParen);
2357 ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
2358 SourceLocation OpLoc,
2359 tok::TokenKind OpKind,
2360 CXXScopeSpec &SS,
2361 UnqualifiedId &FirstTypeName,
2362 SourceLocation CCLoc,
2363 SourceLocation TildeLoc,
2364 UnqualifiedId &SecondTypeName,
2365 bool HasTrailingLParen);
2367 /// MaybeCreateExprWithCleanups - If the current full-expression
2368 /// requires any cleanups, surround it with a ExprWithCleanups node.
2369 /// Otherwise, just returns the passed-in expression.
2370 Expr *MaybeCreateExprWithCleanups(Expr *SubExpr);
2371 Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt);
2372 ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr);
2374 ExprResult ActOnFinishFullExpr(Expr *Expr);
2375 StmtResult ActOnFinishFullStmt(Stmt *Stmt);
2377 // Marks SS invalid if it represents an incomplete type.
2378 bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC);
2380 DeclContext *computeDeclContext(QualType T);
2381 DeclContext *computeDeclContext(const CXXScopeSpec &SS,
2382 bool EnteringContext = false);
2383 bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
2384 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
2385 bool isUnknownSpecialization(const CXXScopeSpec &SS);
2387 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
2388 /// global scope ('::').
2389 NestedNameSpecifier *
2390 ActOnCXXGlobalScopeSpecifier(Scope *S, SourceLocation CCLoc);
2392 bool isAcceptableNestedNameSpecifier(NamedDecl *SD);
2393 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
2395 bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS,
2396 SourceLocation IdLoc,
2397 IdentifierInfo &II,
2398 ParsedType ObjectType);
2400 NestedNameSpecifier *BuildCXXNestedNameSpecifier(Scope *S,
2401 CXXScopeSpec &SS,
2402 SourceLocation IdLoc,
2403 SourceLocation CCLoc,
2404 IdentifierInfo &II,
2405 QualType ObjectType,
2406 NamedDecl *ScopeLookupResult,
2407 bool EnteringContext,
2408 bool ErrorRecoveryLookup);
2410 NestedNameSpecifier *ActOnCXXNestedNameSpecifier(Scope *S,
2411 CXXScopeSpec &SS,
2412 SourceLocation IdLoc,
2413 SourceLocation CCLoc,
2414 IdentifierInfo &II,
2415 ParsedType ObjectType,
2416 bool EnteringContext);
2418 bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS,
2419 IdentifierInfo &II,
2420 ParsedType ObjectType,
2421 bool EnteringContext);
2423 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
2424 /// nested-name-specifier that involves a template-id, e.g.,
2425 /// "foo::bar<int, float>::", and now we need to build a scope
2426 /// specifier. \p SS is empty or the previously parsed nested-name
2427 /// part ("foo::"), \p Type is the already-parsed class template
2428 /// specialization (or other template-id that names a type), \p
2429 /// TypeRange is the source range where the type is located, and \p
2430 /// CCLoc is the location of the trailing '::'.
2431 CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
2432 const CXXScopeSpec &SS,
2433 ParsedType Type,
2434 SourceRange TypeRange,
2435 SourceLocation CCLoc);
2437 bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
2439 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
2440 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
2441 /// After this method is called, according to [C++ 3.4.3p3], names should be
2442 /// looked up in the declarator-id's scope, until the declarator is parsed and
2443 /// ActOnCXXExitDeclaratorScope is called.
2444 /// The 'SS' should be a non-empty valid CXXScopeSpec.
2445 bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS);
2447 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
2448 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
2449 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
2450 /// Used to indicate that names should revert to being looked up in the
2451 /// defining scope.
2452 void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
2454 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
2455 /// initializer for the declaration 'Dcl'.
2456 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
2457 /// static data member of class X, names should be looked up in the scope of
2458 /// class X.
2459 void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl);
2461 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
2462 /// initializer for the declaration 'Dcl'.
2463 void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl);
2465 // ParseObjCStringLiteral - Parse Objective-C string literals.
2466 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
2467 Expr **Strings,
2468 unsigned NumStrings);
2470 Expr *BuildObjCEncodeExpression(SourceLocation AtLoc,
2471 TypeSourceInfo *EncodedTypeInfo,
2472 SourceLocation RParenLoc);
2473 CXXMemberCallExpr *BuildCXXMemberCallExpr(Expr *Exp,
2474 NamedDecl *FoundDecl,
2475 CXXMethodDecl *Method);
2477 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
2478 SourceLocation EncodeLoc,
2479 SourceLocation LParenLoc,
2480 ParsedType Ty,
2481 SourceLocation RParenLoc);
2483 // ParseObjCSelectorExpression - Build selector expression for @selector
2484 ExprResult ParseObjCSelectorExpression(Selector Sel,
2485 SourceLocation AtLoc,
2486 SourceLocation SelLoc,
2487 SourceLocation LParenLoc,
2488 SourceLocation RParenLoc);
2490 // ParseObjCProtocolExpression - Build protocol expression for @protocol
2491 ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
2492 SourceLocation AtLoc,
2493 SourceLocation ProtoLoc,
2494 SourceLocation LParenLoc,
2495 SourceLocation RParenLoc);
2497 //===--------------------------------------------------------------------===//
2498 // C++ Declarations
2500 Decl *ActOnStartLinkageSpecification(Scope *S,
2501 SourceLocation ExternLoc,
2502 SourceLocation LangLoc,
2503 llvm::StringRef Lang,
2504 SourceLocation LBraceLoc);
2505 Decl *ActOnFinishLinkageSpecification(Scope *S,
2506 Decl *LinkageSpec,
2507 SourceLocation RBraceLoc);
2510 //===--------------------------------------------------------------------===//
2511 // C++ Classes
2513 bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
2514 const CXXScopeSpec *SS = 0);
2516 Decl *ActOnAccessSpecifier(AccessSpecifier Access,
2517 SourceLocation ASLoc,
2518 SourceLocation ColonLoc);
2520 Decl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
2521 Declarator &D,
2522 MultiTemplateParamsArg TemplateParameterLists,
2523 Expr *BitfieldWidth,
2524 Expr *Init, bool IsDefinition,
2525 bool Deleted = false);
2527 MemInitResult ActOnMemInitializer(Decl *ConstructorD,
2528 Scope *S,
2529 CXXScopeSpec &SS,
2530 IdentifierInfo *MemberOrBase,
2531 ParsedType TemplateTypeTy,
2532 SourceLocation IdLoc,
2533 SourceLocation LParenLoc,
2534 Expr **Args, unsigned NumArgs,
2535 SourceLocation RParenLoc);
2537 MemInitResult BuildMemberInitializer(ValueDecl *Member, Expr **Args,
2538 unsigned NumArgs, SourceLocation IdLoc,
2539 SourceLocation LParenLoc,
2540 SourceLocation RParenLoc);
2542 MemInitResult BuildBaseInitializer(QualType BaseType,
2543 TypeSourceInfo *BaseTInfo,
2544 Expr **Args, unsigned NumArgs,
2545 SourceLocation LParenLoc,
2546 SourceLocation RParenLoc,
2547 CXXRecordDecl *ClassDecl);
2549 bool SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor,
2550 CXXBaseOrMemberInitializer **Initializers,
2551 unsigned NumInitializers, bool AnyErrors);
2553 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation);
2556 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
2557 /// mark all the non-trivial destructors of its members and bases as
2558 /// referenced.
2559 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
2560 CXXRecordDecl *Record);
2562 /// \brief The list of classes whose vtables have been used within
2563 /// this translation unit, and the source locations at which the
2564 /// first use occurred.
2565 typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse;
2567 /// \brief The list of vtables that are required but have not yet been
2568 /// materialized.
2569 llvm::SmallVector<VTableUse, 16> VTableUses;
2571 /// \brief The set of classes whose vtables have been used within
2572 /// this translation unit, and a bit that will be true if the vtable is
2573 /// required to be emitted (otherwise, it should be emitted only if needed
2574 /// by code generation).
2575 llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
2577 /// \brief A list of all of the dynamic classes in this translation
2578 /// unit.
2579 llvm::SmallVector<CXXRecordDecl *, 16> DynamicClasses;
2581 /// \brief Note that the vtable for the given class was used at the
2582 /// given location.
2583 void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
2584 bool DefinitionRequired = false);
2586 /// MarkVirtualMembersReferenced - Will mark all members of the given
2587 /// CXXRecordDecl referenced.
2588 void MarkVirtualMembersReferenced(SourceLocation Loc,
2589 const CXXRecordDecl *RD);
2591 /// \brief Define all of the vtables that have been used in this
2592 /// translation unit and reference any virtual members used by those
2593 /// vtables.
2595 /// \returns true if any work was done, false otherwise.
2596 bool DefineUsedVTables();
2598 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
2600 void ActOnMemInitializers(Decl *ConstructorDecl,
2601 SourceLocation ColonLoc,
2602 MemInitTy **MemInits, unsigned NumMemInits,
2603 bool AnyErrors);
2605 void CheckCompletedCXXClass(CXXRecordDecl *Record);
2606 void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
2607 Decl *TagDecl,
2608 SourceLocation LBrac,
2609 SourceLocation RBrac,
2610 AttributeList *AttrList);
2612 void ActOnReenterTemplateScope(Scope *S, Decl *Template);
2613 void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record);
2614 void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
2615 void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param);
2616 void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method);
2617 void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record);
2619 Decl *ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
2620 Expr *AssertExpr,
2621 Expr *AssertMessageExpr);
2623 FriendDecl *CheckFriendTypeDecl(SourceLocation FriendLoc,
2624 TypeSourceInfo *TSInfo);
2625 Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
2626 MultiTemplateParamsArg TemplateParams);
2627 Decl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition,
2628 MultiTemplateParamsArg TemplateParams);
2630 QualType CheckConstructorDeclarator(Declarator &D, QualType R,
2631 StorageClass& SC);
2632 void CheckConstructor(CXXConstructorDecl *Constructor);
2633 QualType CheckDestructorDeclarator(Declarator &D, QualType R,
2634 StorageClass& SC);
2635 bool CheckDestructor(CXXDestructorDecl *Destructor);
2636 void CheckConversionDeclarator(Declarator &D, QualType &R,
2637 StorageClass& SC);
2638 Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
2640 //===--------------------------------------------------------------------===//
2641 // C++ Derived Classes
2644 /// ActOnBaseSpecifier - Parsed a base specifier
2645 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
2646 SourceRange SpecifierRange,
2647 bool Virtual, AccessSpecifier Access,
2648 TypeSourceInfo *TInfo);
2650 BaseResult ActOnBaseSpecifier(Decl *classdecl,
2651 SourceRange SpecifierRange,
2652 bool Virtual, AccessSpecifier Access,
2653 ParsedType basetype, SourceLocation
2654 BaseLoc);
2656 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
2657 unsigned NumBases);
2658 void ActOnBaseSpecifiers(Decl *ClassDecl, BaseTy **Bases, unsigned NumBases);
2660 bool IsDerivedFrom(QualType Derived, QualType Base);
2661 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths);
2663 // FIXME: I don't like this name.
2664 void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath);
2666 bool BasePathInvolvesVirtualBase(const CXXCastPath &BasePath);
2668 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
2669 SourceLocation Loc, SourceRange Range,
2670 CXXCastPath *BasePath = 0,
2671 bool IgnoreAccess = false);
2672 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
2673 unsigned InaccessibleBaseID,
2674 unsigned AmbigiousBaseConvID,
2675 SourceLocation Loc, SourceRange Range,
2676 DeclarationName Name,
2677 CXXCastPath *BasePath);
2679 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
2681 /// CheckOverridingFunctionReturnType - Checks whether the return types are
2682 /// covariant, according to C++ [class.virtual]p5.
2683 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
2684 const CXXMethodDecl *Old);
2686 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
2687 /// spec is a subset of base spec.
2688 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
2689 const CXXMethodDecl *Old);
2691 /// CheckOverridingFunctionAttributes - Checks whether attributes are
2692 /// incompatible or prevent overriding.
2693 bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
2694 const CXXMethodDecl *Old);
2696 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
2698 //===--------------------------------------------------------------------===//
2699 // C++ Access Control
2702 enum AccessResult {
2703 AR_accessible,
2704 AR_inaccessible,
2705 AR_dependent,
2706 AR_delayed
2709 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
2710 NamedDecl *PrevMemberDecl,
2711 AccessSpecifier LexicalAS);
2713 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
2714 DeclAccessPair FoundDecl);
2715 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
2716 DeclAccessPair FoundDecl);
2717 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
2718 SourceRange PlacementRange,
2719 CXXRecordDecl *NamingClass,
2720 DeclAccessPair FoundDecl);
2721 AccessResult CheckConstructorAccess(SourceLocation Loc,
2722 CXXConstructorDecl *D,
2723 const InitializedEntity &Entity,
2724 AccessSpecifier Access,
2725 bool IsCopyBindingRefToTemp = false);
2726 AccessResult CheckDestructorAccess(SourceLocation Loc,
2727 CXXDestructorDecl *Dtor,
2728 const PartialDiagnostic &PDiag);
2729 AccessResult CheckDirectMemberAccess(SourceLocation Loc,
2730 NamedDecl *D,
2731 const PartialDiagnostic &PDiag);
2732 AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
2733 Expr *ObjectExpr,
2734 Expr *ArgExpr,
2735 DeclAccessPair FoundDecl);
2736 AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr,
2737 DeclAccessPair FoundDecl);
2738 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
2739 QualType Base, QualType Derived,
2740 const CXXBasePath &Path,
2741 unsigned DiagID,
2742 bool ForceCheck = false,
2743 bool ForceUnprivileged = false);
2744 void CheckLookupAccess(const LookupResult &R);
2746 void HandleDependentAccessCheck(const DependentDiagnostic &DD,
2747 const MultiLevelTemplateArgumentList &TemplateArgs);
2748 void PerformDependentDiagnostics(const DeclContext *Pattern,
2749 const MultiLevelTemplateArgumentList &TemplateArgs);
2751 void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx);
2753 /// A flag to suppress access checking.
2754 bool SuppressAccessChecking;
2756 void ActOnStartSuppressingAccessChecks();
2757 void ActOnStopSuppressingAccessChecks();
2759 enum AbstractDiagSelID {
2760 AbstractNone = -1,
2761 AbstractReturnType,
2762 AbstractParamType,
2763 AbstractVariableType,
2764 AbstractFieldType,
2765 AbstractArrayType
2768 bool RequireNonAbstractType(SourceLocation Loc, QualType T,
2769 const PartialDiagnostic &PD);
2770 void DiagnoseAbstractType(const CXXRecordDecl *RD);
2772 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
2773 AbstractDiagSelID SelID = AbstractNone);
2775 //===--------------------------------------------------------------------===//
2776 // C++ Overloaded Operators [C++ 13.5]
2779 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
2781 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
2783 //===--------------------------------------------------------------------===//
2784 // C++ Templates [C++ 14]
2786 void LookupTemplateName(LookupResult &R, Scope *S, CXXScopeSpec &SS,
2787 QualType ObjectType, bool EnteringContext,
2788 bool &MemberOfUnknownSpecialization);
2790 TemplateNameKind isTemplateName(Scope *S,
2791 CXXScopeSpec &SS,
2792 bool hasTemplateKeyword,
2793 UnqualifiedId &Name,
2794 ParsedType ObjectType,
2795 bool EnteringContext,
2796 TemplateTy &Template,
2797 bool &MemberOfUnknownSpecialization);
2799 bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
2800 SourceLocation IILoc,
2801 Scope *S,
2802 const CXXScopeSpec *SS,
2803 TemplateTy &SuggestedTemplate,
2804 TemplateNameKind &SuggestedKind);
2806 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
2807 TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
2809 Decl *ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
2810 SourceLocation EllipsisLoc,
2811 SourceLocation KeyLoc,
2812 IdentifierInfo *ParamName,
2813 SourceLocation ParamNameLoc,
2814 unsigned Depth, unsigned Position,
2815 SourceLocation EqualLoc,
2816 ParsedType DefaultArg);
2818 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
2819 Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
2820 unsigned Depth,
2821 unsigned Position,
2822 SourceLocation EqualLoc,
2823 Expr *DefaultArg);
2824 Decl *ActOnTemplateTemplateParameter(Scope *S,
2825 SourceLocation TmpLoc,
2826 TemplateParamsTy *Params,
2827 IdentifierInfo *ParamName,
2828 SourceLocation ParamNameLoc,
2829 unsigned Depth,
2830 unsigned Position,
2831 SourceLocation EqualLoc,
2832 const ParsedTemplateArgument &DefaultArg);
2834 TemplateParamsTy *
2835 ActOnTemplateParameterList(unsigned Depth,
2836 SourceLocation ExportLoc,
2837 SourceLocation TemplateLoc,
2838 SourceLocation LAngleLoc,
2839 Decl **Params, unsigned NumParams,
2840 SourceLocation RAngleLoc);
2842 /// \brief The context in which we are checking a template parameter
2843 /// list.
2844 enum TemplateParamListContext {
2845 TPC_ClassTemplate,
2846 TPC_FunctionTemplate,
2847 TPC_ClassTemplateMember,
2848 TPC_FriendFunctionTemplate
2851 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
2852 TemplateParameterList *OldParams,
2853 TemplateParamListContext TPC);
2854 TemplateParameterList *
2855 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
2856 const CXXScopeSpec &SS,
2857 TemplateParameterList **ParamLists,
2858 unsigned NumParamLists,
2859 bool IsFriend,
2860 bool &IsExplicitSpecialization,
2861 bool &Invalid);
2863 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
2864 SourceLocation KWLoc, CXXScopeSpec &SS,
2865 IdentifierInfo *Name, SourceLocation NameLoc,
2866 AttributeList *Attr,
2867 TemplateParameterList *TemplateParams,
2868 AccessSpecifier AS);
2870 void translateTemplateArguments(const ASTTemplateArgsPtr &In,
2871 TemplateArgumentListInfo &Out);
2873 QualType CheckTemplateIdType(TemplateName Template,
2874 SourceLocation TemplateLoc,
2875 const TemplateArgumentListInfo &TemplateArgs);
2877 TypeResult
2878 ActOnTemplateIdType(TemplateTy Template, SourceLocation TemplateLoc,
2879 SourceLocation LAngleLoc,
2880 ASTTemplateArgsPtr TemplateArgs,
2881 SourceLocation RAngleLoc);
2883 TypeResult ActOnTagTemplateIdType(CXXScopeSpec &SS,
2884 TypeResult Type,
2885 TagUseKind TUK,
2886 TypeSpecifierType TagSpec,
2887 SourceLocation TagLoc);
2889 ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
2890 LookupResult &R,
2891 bool RequiresADL,
2892 const TemplateArgumentListInfo &TemplateArgs);
2893 ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
2894 const DeclarationNameInfo &NameInfo,
2895 const TemplateArgumentListInfo &TemplateArgs);
2897 TemplateNameKind ActOnDependentTemplateName(Scope *S,
2898 SourceLocation TemplateKWLoc,
2899 CXXScopeSpec &SS,
2900 UnqualifiedId &Name,
2901 ParsedType ObjectType,
2902 bool EnteringContext,
2903 TemplateTy &Template);
2905 bool CheckClassTemplatePartialSpecializationArgs(
2906 TemplateParameterList *TemplateParams,
2907 llvm::SmallVectorImpl<TemplateArgument> &TemplateArgs,
2908 bool &MirrorsPrimaryTemplate);
2910 DeclResult
2911 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
2912 SourceLocation KWLoc,
2913 CXXScopeSpec &SS,
2914 TemplateTy Template,
2915 SourceLocation TemplateNameLoc,
2916 SourceLocation LAngleLoc,
2917 ASTTemplateArgsPtr TemplateArgs,
2918 SourceLocation RAngleLoc,
2919 AttributeList *Attr,
2920 MultiTemplateParamsArg TemplateParameterLists);
2922 Decl *ActOnTemplateDeclarator(Scope *S,
2923 MultiTemplateParamsArg TemplateParameterLists,
2924 Declarator &D);
2926 Decl *ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope,
2927 MultiTemplateParamsArg TemplateParameterLists,
2928 Declarator &D);
2930 bool
2931 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
2932 TemplateSpecializationKind NewTSK,
2933 NamedDecl *PrevDecl,
2934 TemplateSpecializationKind PrevTSK,
2935 SourceLocation PrevPtOfInstantiation,
2936 bool &SuppressNew);
2938 bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD,
2939 const TemplateArgumentListInfo &ExplicitTemplateArgs,
2940 LookupResult &Previous);
2942 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
2943 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2944 LookupResult &Previous);
2945 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
2947 DeclResult
2948 ActOnExplicitInstantiation(Scope *S,
2949 SourceLocation ExternLoc,
2950 SourceLocation TemplateLoc,
2951 unsigned TagSpec,
2952 SourceLocation KWLoc,
2953 const CXXScopeSpec &SS,
2954 TemplateTy Template,
2955 SourceLocation TemplateNameLoc,
2956 SourceLocation LAngleLoc,
2957 ASTTemplateArgsPtr TemplateArgs,
2958 SourceLocation RAngleLoc,
2959 AttributeList *Attr);
2961 DeclResult
2962 ActOnExplicitInstantiation(Scope *S,
2963 SourceLocation ExternLoc,
2964 SourceLocation TemplateLoc,
2965 unsigned TagSpec,
2966 SourceLocation KWLoc,
2967 CXXScopeSpec &SS,
2968 IdentifierInfo *Name,
2969 SourceLocation NameLoc,
2970 AttributeList *Attr);
2972 DeclResult ActOnExplicitInstantiation(Scope *S,
2973 SourceLocation ExternLoc,
2974 SourceLocation TemplateLoc,
2975 Declarator &D);
2977 TemplateArgumentLoc
2978 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
2979 SourceLocation TemplateLoc,
2980 SourceLocation RAngleLoc,
2981 Decl *Param,
2982 llvm::SmallVectorImpl<TemplateArgument> &Converted);
2984 /// \brief Specifies the context in which a particular template
2985 /// argument is being checked.
2986 enum CheckTemplateArgumentKind {
2987 /// \brief The template argument was specified in the code or was
2988 /// instantiated with some deduced template arguments.
2989 CTAK_Specified,
2991 /// \brief The template argument was deduced via template argument
2992 /// deduction.
2993 CTAK_Deduced,
2995 /// \brief The template argument was deduced from an array bound
2996 /// via template argument deduction.
2997 CTAK_DeducedFromArrayBound
3000 bool CheckTemplateArgument(NamedDecl *Param,
3001 const TemplateArgumentLoc &Arg,
3002 TemplateDecl *Template,
3003 SourceLocation TemplateLoc,
3004 SourceLocation RAngleLoc,
3005 llvm::SmallVectorImpl<TemplateArgument> &Converted,
3006 CheckTemplateArgumentKind CTAK = CTAK_Specified);
3008 bool CheckTemplateArgumentList(TemplateDecl *Template,
3009 SourceLocation TemplateLoc,
3010 const TemplateArgumentListInfo &TemplateArgs,
3011 bool PartialTemplateArgs,
3012 llvm::SmallVectorImpl<TemplateArgument> &Converted);
3014 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
3015 const TemplateArgumentLoc &Arg,
3016 llvm::SmallVectorImpl<TemplateArgument> &Converted);
3018 bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
3019 TypeSourceInfo *Arg);
3020 bool CheckTemplateArgumentPointerToMember(Expr *Arg,
3021 TemplateArgument &Converted);
3022 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
3023 QualType InstantiatedParamType, Expr *&Arg,
3024 TemplateArgument &Converted,
3025 CheckTemplateArgumentKind CTAK = CTAK_Specified);
3026 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
3027 const TemplateArgumentLoc &Arg);
3029 ExprResult
3030 BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
3031 QualType ParamType,
3032 SourceLocation Loc);
3033 ExprResult
3034 BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
3035 SourceLocation Loc);
3037 /// \brief Enumeration describing how template parameter lists are compared
3038 /// for equality.
3039 enum TemplateParameterListEqualKind {
3040 /// \brief We are matching the template parameter lists of two templates
3041 /// that might be redeclarations.
3043 /// \code
3044 /// template<typename T> struct X;
3045 /// template<typename T> struct X;
3046 /// \endcode
3047 TPL_TemplateMatch,
3049 /// \brief We are matching the template parameter lists of two template
3050 /// template parameters as part of matching the template parameter lists
3051 /// of two templates that might be redeclarations.
3053 /// \code
3054 /// template<template<int I> class TT> struct X;
3055 /// template<template<int Value> class Other> struct X;
3056 /// \endcode
3057 TPL_TemplateTemplateParmMatch,
3059 /// \brief We are matching the template parameter lists of a template
3060 /// template argument against the template parameter lists of a template
3061 /// template parameter.
3063 /// \code
3064 /// template<template<int Value> class Metafun> struct X;
3065 /// template<int Value> struct integer_c;
3066 /// X<integer_c> xic;
3067 /// \endcode
3068 TPL_TemplateTemplateArgumentMatch
3071 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
3072 TemplateParameterList *Old,
3073 bool Complain,
3074 TemplateParameterListEqualKind Kind,
3075 SourceLocation TemplateArgLoc
3076 = SourceLocation());
3078 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
3080 /// \brief Called when the parser has parsed a C++ typename
3081 /// specifier, e.g., "typename T::type".
3083 /// \param S The scope in which this typename type occurs.
3084 /// \param TypenameLoc the location of the 'typename' keyword
3085 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
3086 /// \param II the identifier we're retrieving (e.g., 'type' in the example).
3087 /// \param IdLoc the location of the identifier.
3088 TypeResult
3089 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
3090 const CXXScopeSpec &SS, const IdentifierInfo &II,
3091 SourceLocation IdLoc);
3093 /// \brief Called when the parser has parsed a C++ typename
3094 /// specifier that ends in a template-id, e.g.,
3095 /// "typename MetaFun::template apply<T1, T2>".
3097 /// \param S The scope in which this typename type occurs.
3098 /// \param TypenameLoc the location of the 'typename' keyword
3099 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
3100 /// \param TemplateLoc the location of the 'template' keyword, if any.
3101 /// \param Ty the type that the typename specifier refers to.
3102 TypeResult
3103 ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
3104 const CXXScopeSpec &SS, SourceLocation TemplateLoc,
3105 ParsedType Ty);
3107 QualType CheckTypenameType(ElaboratedTypeKeyword Keyword,
3108 NestedNameSpecifier *NNS,
3109 const IdentifierInfo &II,
3110 SourceLocation KeywordLoc,
3111 SourceRange NNSRange,
3112 SourceLocation IILoc);
3114 TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
3115 SourceLocation Loc,
3116 DeclarationName Name);
3117 bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS);
3119 ExprResult RebuildExprInCurrentInstantiation(Expr *E);
3121 std::string
3122 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
3123 const TemplateArgumentList &Args);
3125 std::string
3126 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
3127 const TemplateArgument *Args,
3128 unsigned NumArgs);
3130 /// \brief Describes the result of template argument deduction.
3132 /// The TemplateDeductionResult enumeration describes the result of
3133 /// template argument deduction, as returned from
3134 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
3135 /// structure provides additional information about the results of
3136 /// template argument deduction, e.g., the deduced template argument
3137 /// list (if successful) or the specific template parameters or
3138 /// deduced arguments that were involved in the failure.
3139 enum TemplateDeductionResult {
3140 /// \brief Template argument deduction was successful.
3141 TDK_Success = 0,
3142 /// \brief Template argument deduction exceeded the maximum template
3143 /// instantiation depth (which has already been diagnosed).
3144 TDK_InstantiationDepth,
3145 /// \brief Template argument deduction did not deduce a value
3146 /// for every template parameter.
3147 TDK_Incomplete,
3148 /// \brief Template argument deduction produced inconsistent
3149 /// deduced values for the given template parameter.
3150 TDK_Inconsistent,
3151 /// \brief Template argument deduction failed due to inconsistent
3152 /// cv-qualifiers on a template parameter type that would
3153 /// otherwise be deduced, e.g., we tried to deduce T in "const T"
3154 /// but were given a non-const "X".
3155 TDK_Underqualified,
3156 /// \brief Substitution of the deduced template argument values
3157 /// resulted in an error.
3158 TDK_SubstitutionFailure,
3159 /// \brief Substitution of the deduced template argument values
3160 /// into a non-deduced context produced a type or value that
3161 /// produces a type that does not match the original template
3162 /// arguments provided.
3163 TDK_NonDeducedMismatch,
3164 /// \brief When performing template argument deduction for a function
3165 /// template, there were too many call arguments.
3166 TDK_TooManyArguments,
3167 /// \brief When performing template argument deduction for a function
3168 /// template, there were too few call arguments.
3169 TDK_TooFewArguments,
3170 /// \brief The explicitly-specified template arguments were not valid
3171 /// template arguments for the given template.
3172 TDK_InvalidExplicitArguments,
3173 /// \brief The arguments included an overloaded function name that could
3174 /// not be resolved to a suitable function.
3175 TDK_FailedOverloadResolution
3178 TemplateDeductionResult
3179 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
3180 const TemplateArgumentList &TemplateArgs,
3181 sema::TemplateDeductionInfo &Info);
3183 TemplateDeductionResult
3184 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3185 const TemplateArgumentListInfo &ExplicitTemplateArgs,
3186 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3187 llvm::SmallVectorImpl<QualType> &ParamTypes,
3188 QualType *FunctionType,
3189 sema::TemplateDeductionInfo &Info);
3191 TemplateDeductionResult
3192 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
3193 llvm::SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3194 unsigned NumExplicitlySpecified,
3195 FunctionDecl *&Specialization,
3196 sema::TemplateDeductionInfo &Info);
3198 TemplateDeductionResult
3199 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3200 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3201 Expr **Args, unsigned NumArgs,
3202 FunctionDecl *&Specialization,
3203 sema::TemplateDeductionInfo &Info);
3205 TemplateDeductionResult
3206 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3207 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3208 QualType ArgFunctionType,
3209 FunctionDecl *&Specialization,
3210 sema::TemplateDeductionInfo &Info);
3212 TemplateDeductionResult
3213 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3214 QualType ToType,
3215 CXXConversionDecl *&Specialization,
3216 sema::TemplateDeductionInfo &Info);
3218 TemplateDeductionResult
3219 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3220 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3221 FunctionDecl *&Specialization,
3222 sema::TemplateDeductionInfo &Info);
3224 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
3225 FunctionTemplateDecl *FT2,
3226 SourceLocation Loc,
3227 TemplatePartialOrderingContext TPOC);
3228 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin,
3229 UnresolvedSetIterator SEnd,
3230 TemplatePartialOrderingContext TPOC,
3231 SourceLocation Loc,
3232 const PartialDiagnostic &NoneDiag,
3233 const PartialDiagnostic &AmbigDiag,
3234 const PartialDiagnostic &CandidateDiag);
3236 ClassTemplatePartialSpecializationDecl *
3237 getMoreSpecializedPartialSpecialization(
3238 ClassTemplatePartialSpecializationDecl *PS1,
3239 ClassTemplatePartialSpecializationDecl *PS2,
3240 SourceLocation Loc);
3242 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
3243 bool OnlyDeduced,
3244 unsigned Depth,
3245 llvm::SmallVectorImpl<bool> &Used);
3246 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate,
3247 llvm::SmallVectorImpl<bool> &Deduced);
3249 //===--------------------------------------------------------------------===//
3250 // C++ Template Instantiation
3253 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D,
3254 const TemplateArgumentList *Innermost = 0,
3255 bool RelativeToPrimary = false,
3256 const FunctionDecl *Pattern = 0);
3258 /// \brief A template instantiation that is currently in progress.
3259 struct ActiveTemplateInstantiation {
3260 /// \brief The kind of template instantiation we are performing
3261 enum InstantiationKind {
3262 /// We are instantiating a template declaration. The entity is
3263 /// the declaration we're instantiating (e.g., a CXXRecordDecl).
3264 TemplateInstantiation,
3266 /// We are instantiating a default argument for a template
3267 /// parameter. The Entity is the template, and
3268 /// TemplateArgs/NumTemplateArguments provides the template
3269 /// arguments as specified.
3270 /// FIXME: Use a TemplateArgumentList
3271 DefaultTemplateArgumentInstantiation,
3273 /// We are instantiating a default argument for a function.
3274 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
3275 /// provides the template arguments as specified.
3276 DefaultFunctionArgumentInstantiation,
3278 /// We are substituting explicit template arguments provided for
3279 /// a function template. The entity is a FunctionTemplateDecl.
3280 ExplicitTemplateArgumentSubstitution,
3282 /// We are substituting template argument determined as part of
3283 /// template argument deduction for either a class template
3284 /// partial specialization or a function template. The
3285 /// Entity is either a ClassTemplatePartialSpecializationDecl or
3286 /// a FunctionTemplateDecl.
3287 DeducedTemplateArgumentSubstitution,
3289 /// We are substituting prior template arguments into a new
3290 /// template parameter. The template parameter itself is either a
3291 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
3292 PriorTemplateArgumentSubstitution,
3294 /// We are checking the validity of a default template argument that
3295 /// has been used when naming a template-id.
3296 DefaultTemplateArgumentChecking
3297 } Kind;
3299 /// \brief The point of instantiation within the source code.
3300 SourceLocation PointOfInstantiation;
3302 /// \brief The template in which we are performing the instantiation,
3303 /// for substitutions of prior template arguments.
3304 TemplateDecl *Template;
3306 /// \brief The entity that is being instantiated.
3307 uintptr_t Entity;
3309 /// \brief The list of template arguments we are substituting, if they
3310 /// are not part of the entity.
3311 const TemplateArgument *TemplateArgs;
3313 /// \brief The number of template arguments in TemplateArgs.
3314 unsigned NumTemplateArgs;
3316 /// \brief The template deduction info object associated with the
3317 /// substitution or checking of explicit or deduced template arguments.
3318 sema::TemplateDeductionInfo *DeductionInfo;
3320 /// \brief The source range that covers the construct that cause
3321 /// the instantiation, e.g., the template-id that causes a class
3322 /// template instantiation.
3323 SourceRange InstantiationRange;
3325 ActiveTemplateInstantiation()
3326 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0),
3327 NumTemplateArgs(0), DeductionInfo(0) {}
3329 /// \brief Determines whether this template is an actual instantiation
3330 /// that should be counted toward the maximum instantiation depth.
3331 bool isInstantiationRecord() const;
3333 friend bool operator==(const ActiveTemplateInstantiation &X,
3334 const ActiveTemplateInstantiation &Y) {
3335 if (X.Kind != Y.Kind)
3336 return false;
3338 if (X.Entity != Y.Entity)
3339 return false;
3341 switch (X.Kind) {
3342 case TemplateInstantiation:
3343 return true;
3345 case PriorTemplateArgumentSubstitution:
3346 case DefaultTemplateArgumentChecking:
3347 if (X.Template != Y.Template)
3348 return false;
3350 // Fall through
3352 case DefaultTemplateArgumentInstantiation:
3353 case ExplicitTemplateArgumentSubstitution:
3354 case DeducedTemplateArgumentSubstitution:
3355 case DefaultFunctionArgumentInstantiation:
3356 return X.TemplateArgs == Y.TemplateArgs;
3360 return true;
3363 friend bool operator!=(const ActiveTemplateInstantiation &X,
3364 const ActiveTemplateInstantiation &Y) {
3365 return !(X == Y);
3369 /// \brief List of active template instantiations.
3371 /// This vector is treated as a stack. As one template instantiation
3372 /// requires another template instantiation, additional
3373 /// instantiations are pushed onto the stack up to a
3374 /// user-configurable limit LangOptions::InstantiationDepth.
3375 llvm::SmallVector<ActiveTemplateInstantiation, 16>
3376 ActiveTemplateInstantiations;
3378 /// \brief The number of ActiveTemplateInstantiation entries in
3379 /// \c ActiveTemplateInstantiations that are not actual instantiations and,
3380 /// therefore, should not be counted as part of the instantiation depth.
3381 unsigned NonInstantiationEntries;
3383 /// \brief The last template from which a template instantiation
3384 /// error or warning was produced.
3386 /// This value is used to suppress printing of redundant template
3387 /// instantiation backtraces when there are multiple errors in the
3388 /// same instantiation. FIXME: Does this belong in Sema? It's tough
3389 /// to implement it anywhere else.
3390 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
3392 /// \brief The stack of calls expression undergoing template instantiation.
3394 /// The top of this stack is used by a fixit instantiating unresolved
3395 /// function calls to fix the AST to match the textual change it prints.
3396 llvm::SmallVector<CallExpr *, 8> CallsUndergoingInstantiation;
3398 /// \brief For each declaration that involved template argument deduction, the
3399 /// set of diagnostics that were suppressed during that template argument
3400 /// deduction.
3402 /// FIXME: Serialize this structure to the AST file.
3403 llvm::DenseMap<Decl *, llvm::SmallVector<PartialDiagnosticAt, 1> >
3404 SuppressedDiagnostics;
3406 /// \brief A stack object to be created when performing template
3407 /// instantiation.
3409 /// Construction of an object of type \c InstantiatingTemplate
3410 /// pushes the current instantiation onto the stack of active
3411 /// instantiations. If the size of this stack exceeds the maximum
3412 /// number of recursive template instantiations, construction
3413 /// produces an error and evaluates true.
3415 /// Destruction of this object will pop the named instantiation off
3416 /// the stack.
3417 struct InstantiatingTemplate {
3418 /// \brief Note that we are instantiating a class template,
3419 /// function template, or a member thereof.
3420 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3421 Decl *Entity,
3422 SourceRange InstantiationRange = SourceRange());
3424 /// \brief Note that we are instantiating a default argument in a
3425 /// template-id.
3426 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3427 TemplateDecl *Template,
3428 const TemplateArgument *TemplateArgs,
3429 unsigned NumTemplateArgs,
3430 SourceRange InstantiationRange = SourceRange());
3432 /// \brief Note that we are instantiating a default argument in a
3433 /// template-id.
3434 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3435 FunctionTemplateDecl *FunctionTemplate,
3436 const TemplateArgument *TemplateArgs,
3437 unsigned NumTemplateArgs,
3438 ActiveTemplateInstantiation::InstantiationKind Kind,
3439 sema::TemplateDeductionInfo &DeductionInfo,
3440 SourceRange InstantiationRange = SourceRange());
3442 /// \brief Note that we are instantiating as part of template
3443 /// argument deduction for a class template partial
3444 /// specialization.
3445 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3446 ClassTemplatePartialSpecializationDecl *PartialSpec,
3447 const TemplateArgument *TemplateArgs,
3448 unsigned NumTemplateArgs,
3449 sema::TemplateDeductionInfo &DeductionInfo,
3450 SourceRange InstantiationRange = SourceRange());
3452 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3453 ParmVarDecl *Param,
3454 const TemplateArgument *TemplateArgs,
3455 unsigned NumTemplateArgs,
3456 SourceRange InstantiationRange = SourceRange());
3458 /// \brief Note that we are substituting prior template arguments into a
3459 /// non-type or template template parameter.
3460 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3461 TemplateDecl *Template,
3462 NonTypeTemplateParmDecl *Param,
3463 const TemplateArgument *TemplateArgs,
3464 unsigned NumTemplateArgs,
3465 SourceRange InstantiationRange);
3467 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3468 TemplateDecl *Template,
3469 TemplateTemplateParmDecl *Param,
3470 const TemplateArgument *TemplateArgs,
3471 unsigned NumTemplateArgs,
3472 SourceRange InstantiationRange);
3474 /// \brief Note that we are checking the default template argument
3475 /// against the template parameter for a given template-id.
3476 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3477 TemplateDecl *Template,
3478 NamedDecl *Param,
3479 const TemplateArgument *TemplateArgs,
3480 unsigned NumTemplateArgs,
3481 SourceRange InstantiationRange);
3484 /// \brief Note that we have finished instantiating this template.
3485 void Clear();
3487 ~InstantiatingTemplate() { Clear(); }
3489 /// \brief Determines whether we have exceeded the maximum
3490 /// recursive template instantiations.
3491 operator bool() const { return Invalid; }
3493 private:
3494 Sema &SemaRef;
3495 bool Invalid;
3496 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
3497 SourceRange InstantiationRange);
3499 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
3501 InstantiatingTemplate&
3502 operator=(const InstantiatingTemplate&); // not implemented
3505 void PrintInstantiationStack();
3507 /// \brief Determines whether we are currently in a context where
3508 /// template argument substitution failures are not considered
3509 /// errors.
3511 /// \returns The nearest template-deduction context object, if we are in a
3512 /// SFINAE context, which can be used to capture diagnostics that will be
3513 /// suppressed. Otherwise, returns NULL to indicate that we are not within a
3514 /// SFINAE context.
3515 sema::TemplateDeductionInfo *isSFINAEContext() const;
3517 /// \brief RAII class used to determine whether SFINAE has
3518 /// trapped any errors that occur during template argument
3519 /// deduction.
3520 class SFINAETrap {
3521 Sema &SemaRef;
3522 unsigned PrevSFINAEErrors;
3523 public:
3524 explicit SFINAETrap(Sema &SemaRef)
3525 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors) { }
3527 ~SFINAETrap() { SemaRef.NumSFINAEErrors = PrevSFINAEErrors; }
3529 /// \brief Determine whether any SFINAE errors have been trapped.
3530 bool hasErrorOccurred() const {
3531 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
3535 /// \brief The current instantiation scope used to store local
3536 /// variables.
3537 LocalInstantiationScope *CurrentInstantiationScope;
3539 /// \brief The number of typos corrected by CorrectTypo.
3540 unsigned TyposCorrected;
3542 typedef llvm::DenseMap<IdentifierInfo *, std::pair<llvm::StringRef, bool> >
3543 UnqualifiedTyposCorrectedMap;
3545 /// \brief A cache containing the results of typo correction for unqualified
3546 /// name lookup.
3548 /// The string is the string that we corrected to (which may be empty, if
3549 /// there was no correction), while the boolean will be true when the
3550 /// string represents a keyword.
3551 UnqualifiedTyposCorrectedMap UnqualifiedTyposCorrected;
3553 /// \brief Worker object for performing CFG-based warnings.
3554 sema::AnalysisBasedWarnings AnalysisWarnings;
3556 /// \brief An entity for which implicit template instantiation is required.
3558 /// The source location associated with the declaration is the first place in
3559 /// the source code where the declaration was "used". It is not necessarily
3560 /// the point of instantiation (which will be either before or after the
3561 /// namespace-scope declaration that triggered this implicit instantiation),
3562 /// However, it is the location that diagnostics should generally refer to,
3563 /// because users will need to know what code triggered the instantiation.
3564 typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation;
3566 /// \brief The queue of implicit template instantiations that are required
3567 /// but have not yet been performed.
3568 std::deque<PendingImplicitInstantiation> PendingInstantiations;
3570 /// \brief The queue of implicit template instantiations that are required
3571 /// and must be performed within the current local scope.
3573 /// This queue is only used for member functions of local classes in
3574 /// templates, which must be instantiated in the same scope as their
3575 /// enclosing function, so that they can reference function-local
3576 /// types, static variables, enumerators, etc.
3577 std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations;
3579 void PerformPendingInstantiations(bool LocalOnly = false);
3581 TypeSourceInfo *SubstType(TypeSourceInfo *T,
3582 const MultiLevelTemplateArgumentList &TemplateArgs,
3583 SourceLocation Loc, DeclarationName Entity);
3585 QualType SubstType(QualType T,
3586 const MultiLevelTemplateArgumentList &TemplateArgs,
3587 SourceLocation Loc, DeclarationName Entity);
3589 TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
3590 const MultiLevelTemplateArgumentList &TemplateArgs,
3591 SourceLocation Loc,
3592 DeclarationName Entity);
3593 ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
3594 const MultiLevelTemplateArgumentList &TemplateArgs);
3595 ExprResult SubstExpr(Expr *E,
3596 const MultiLevelTemplateArgumentList &TemplateArgs);
3598 StmtResult SubstStmt(Stmt *S,
3599 const MultiLevelTemplateArgumentList &TemplateArgs);
3601 Decl *SubstDecl(Decl *D, DeclContext *Owner,
3602 const MultiLevelTemplateArgumentList &TemplateArgs);
3604 bool
3605 SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
3606 CXXRecordDecl *Pattern,
3607 const MultiLevelTemplateArgumentList &TemplateArgs);
3609 bool
3610 InstantiateClass(SourceLocation PointOfInstantiation,
3611 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
3612 const MultiLevelTemplateArgumentList &TemplateArgs,
3613 TemplateSpecializationKind TSK,
3614 bool Complain = true);
3616 void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
3617 Decl *Pattern, Decl *Inst);
3619 bool
3620 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
3621 ClassTemplateSpecializationDecl *ClassTemplateSpec,
3622 TemplateSpecializationKind TSK,
3623 bool Complain = true);
3625 void InstantiateClassMembers(SourceLocation PointOfInstantiation,
3626 CXXRecordDecl *Instantiation,
3627 const MultiLevelTemplateArgumentList &TemplateArgs,
3628 TemplateSpecializationKind TSK);
3630 void InstantiateClassTemplateSpecializationMembers(
3631 SourceLocation PointOfInstantiation,
3632 ClassTemplateSpecializationDecl *ClassTemplateSpec,
3633 TemplateSpecializationKind TSK);
3635 NestedNameSpecifier *
3636 SubstNestedNameSpecifier(NestedNameSpecifier *NNS,
3637 SourceRange Range,
3638 const MultiLevelTemplateArgumentList &TemplateArgs);
3639 DeclarationNameInfo
3640 SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
3641 const MultiLevelTemplateArgumentList &TemplateArgs);
3642 TemplateName
3643 SubstTemplateName(TemplateName Name, SourceLocation Loc,
3644 const MultiLevelTemplateArgumentList &TemplateArgs);
3645 bool Subst(const TemplateArgumentLoc &Arg, TemplateArgumentLoc &Result,
3646 const MultiLevelTemplateArgumentList &TemplateArgs);
3648 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
3649 FunctionDecl *Function,
3650 bool Recursive = false,
3651 bool DefinitionRequired = false);
3652 void InstantiateStaticDataMemberDefinition(
3653 SourceLocation PointOfInstantiation,
3654 VarDecl *Var,
3655 bool Recursive = false,
3656 bool DefinitionRequired = false);
3658 void InstantiateMemInitializers(CXXConstructorDecl *New,
3659 const CXXConstructorDecl *Tmpl,
3660 const MultiLevelTemplateArgumentList &TemplateArgs);
3662 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
3663 const MultiLevelTemplateArgumentList &TemplateArgs);
3664 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
3665 const MultiLevelTemplateArgumentList &TemplateArgs);
3667 // Objective-C declarations.
3668 Decl *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
3669 IdentifierInfo *ClassName,
3670 SourceLocation ClassLoc,
3671 IdentifierInfo *SuperName,
3672 SourceLocation SuperLoc,
3673 Decl * const *ProtoRefs,
3674 unsigned NumProtoRefs,
3675 const SourceLocation *ProtoLocs,
3676 SourceLocation EndProtoLoc,
3677 AttributeList *AttrList);
3679 Decl *ActOnCompatiblityAlias(
3680 SourceLocation AtCompatibilityAliasLoc,
3681 IdentifierInfo *AliasName, SourceLocation AliasLocation,
3682 IdentifierInfo *ClassName, SourceLocation ClassLocation);
3684 void CheckForwardProtocolDeclarationForCircularDependency(
3685 IdentifierInfo *PName,
3686 SourceLocation &PLoc, SourceLocation PrevLoc,
3687 const ObjCList<ObjCProtocolDecl> &PList);
3689 Decl *ActOnStartProtocolInterface(
3690 SourceLocation AtProtoInterfaceLoc,
3691 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
3692 Decl * const *ProtoRefNames, unsigned NumProtoRefs,
3693 const SourceLocation *ProtoLocs,
3694 SourceLocation EndProtoLoc,
3695 AttributeList *AttrList);
3697 Decl *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
3698 IdentifierInfo *ClassName,
3699 SourceLocation ClassLoc,
3700 IdentifierInfo *CategoryName,
3701 SourceLocation CategoryLoc,
3702 Decl * const *ProtoRefs,
3703 unsigned NumProtoRefs,
3704 const SourceLocation *ProtoLocs,
3705 SourceLocation EndProtoLoc);
3707 Decl *ActOnStartClassImplementation(
3708 SourceLocation AtClassImplLoc,
3709 IdentifierInfo *ClassName, SourceLocation ClassLoc,
3710 IdentifierInfo *SuperClassname,
3711 SourceLocation SuperClassLoc);
3713 Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc,
3714 IdentifierInfo *ClassName,
3715 SourceLocation ClassLoc,
3716 IdentifierInfo *CatName,
3717 SourceLocation CatLoc);
3719 Decl *ActOnForwardClassDeclaration(SourceLocation Loc,
3720 IdentifierInfo **IdentList,
3721 SourceLocation *IdentLocs,
3722 unsigned NumElts);
3724 Decl *ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
3725 const IdentifierLocPair *IdentList,
3726 unsigned NumElts,
3727 AttributeList *attrList);
3729 void FindProtocolDeclaration(bool WarnOnDeclarations,
3730 const IdentifierLocPair *ProtocolId,
3731 unsigned NumProtocols,
3732 llvm::SmallVectorImpl<Decl *> &Protocols);
3734 /// Ensure attributes are consistent with type.
3735 /// \param [in, out] Attributes The attributes to check; they will
3736 /// be modified to be consistent with \arg PropertyTy.
3737 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy,
3738 SourceLocation Loc,
3739 unsigned &Attributes);
3741 /// Process the specified property declaration and create decls for the
3742 /// setters and getters as needed.
3743 /// \param property The property declaration being processed
3744 /// \param DC The semantic container for the property
3745 /// \param redeclaredProperty Declaration for property if redeclared
3746 /// in class extension.
3747 /// \param lexicalDC Container for redeclaredProperty.
3748 void ProcessPropertyDecl(ObjCPropertyDecl *property,
3749 ObjCContainerDecl *DC,
3750 ObjCPropertyDecl *redeclaredProperty = 0,
3751 ObjCContainerDecl *lexicalDC = 0);
3753 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
3754 ObjCPropertyDecl *SuperProperty,
3755 const IdentifierInfo *Name);
3756 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
3758 void CompareMethodParamsInBaseAndSuper(Decl *IDecl,
3759 ObjCMethodDecl *MethodDecl,
3760 bool IsInstance);
3762 void CompareProperties(Decl *CDecl, Decl *MergeProtocols);
3764 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
3765 ObjCInterfaceDecl *ID);
3767 void MatchOneProtocolPropertiesInClass(Decl *CDecl,
3768 ObjCProtocolDecl *PDecl);
3770 void ActOnAtEnd(Scope *S, SourceRange AtEnd, Decl *classDecl,
3771 Decl **allMethods = 0, unsigned allNum = 0,
3772 Decl **allProperties = 0, unsigned pNum = 0,
3773 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0);
3775 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc,
3776 FieldDeclarator &FD, ObjCDeclSpec &ODS,
3777 Selector GetterSel, Selector SetterSel,
3778 Decl *ClassCategory,
3779 bool *OverridingProperty,
3780 tok::ObjCKeywordKind MethodImplKind,
3781 DeclContext *lexicalDC = 0);
3783 Decl *ActOnPropertyImplDecl(Scope *S,
3784 SourceLocation AtLoc,
3785 SourceLocation PropertyLoc,
3786 bool ImplKind,Decl *ClassImplDecl,
3787 IdentifierInfo *PropertyId,
3788 IdentifierInfo *PropertyIvar,
3789 SourceLocation PropertyIvarLoc);
3791 struct ObjCArgInfo {
3792 IdentifierInfo *Name;
3793 SourceLocation NameLoc;
3794 // The Type is null if no type was specified, and the DeclSpec is invalid
3795 // in this case.
3796 ParsedType Type;
3797 ObjCDeclSpec DeclSpec;
3799 /// ArgAttrs - Attribute list for this argument.
3800 AttributeList *ArgAttrs;
3803 Decl *ActOnMethodDeclaration(
3804 SourceLocation BeginLoc, // location of the + or -.
3805 SourceLocation EndLoc, // location of the ; or {.
3806 tok::TokenKind MethodType,
3807 Decl *ClassDecl, ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
3808 Selector Sel,
3809 // optional arguments. The number of types/arguments is obtained
3810 // from the Sel.getNumArgs().
3811 ObjCArgInfo *ArgInfo,
3812 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
3813 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
3814 bool isVariadic = false);
3816 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
3817 // Will search "local" class/category implementations for a method decl.
3818 // Will also search in class's root looking for instance method.
3819 // Returns 0 if no method is found.
3820 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
3821 ObjCInterfaceDecl *CDecl);
3822 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
3823 ObjCInterfaceDecl *ClassDecl);
3825 ExprResult
3826 HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
3827 Expr *BaseExpr,
3828 DeclarationName MemberName,
3829 SourceLocation MemberLoc,
3830 SourceLocation SuperLoc, QualType SuperType,
3831 bool Super);
3833 ExprResult
3834 ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
3835 IdentifierInfo &propertyName,
3836 SourceLocation receiverNameLoc,
3837 SourceLocation propertyNameLoc);
3839 /// \brief Describes the kind of message expression indicated by a message
3840 /// send that starts with an identifier.
3841 enum ObjCMessageKind {
3842 /// \brief The message is sent to 'super'.
3843 ObjCSuperMessage,
3844 /// \brief The message is an instance message.
3845 ObjCInstanceMessage,
3846 /// \brief The message is a class message, and the identifier is a type
3847 /// name.
3848 ObjCClassMessage
3851 ObjCMessageKind getObjCMessageKind(Scope *S,
3852 IdentifierInfo *Name,
3853 SourceLocation NameLoc,
3854 bool IsSuper,
3855 bool HasTrailingDot,
3856 ParsedType &ReceiverType);
3858 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc,
3859 Selector Sel,
3860 SourceLocation LBracLoc,
3861 SourceLocation SelectorLoc,
3862 SourceLocation RBracLoc,
3863 MultiExprArg Args);
3865 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo,
3866 QualType ReceiverType,
3867 SourceLocation SuperLoc,
3868 Selector Sel,
3869 ObjCMethodDecl *Method,
3870 SourceLocation LBracLoc,
3871 SourceLocation SelectorLoc,
3872 SourceLocation RBracLoc,
3873 MultiExprArg Args);
3875 ExprResult ActOnClassMessage(Scope *S,
3876 ParsedType Receiver,
3877 Selector Sel,
3878 SourceLocation LBracLoc,
3879 SourceLocation SelectorLoc,
3880 SourceLocation RBracLoc,
3881 MultiExprArg Args);
3883 ExprResult BuildInstanceMessage(Expr *Receiver,
3884 QualType ReceiverType,
3885 SourceLocation SuperLoc,
3886 Selector Sel,
3887 ObjCMethodDecl *Method,
3888 SourceLocation LBracLoc,
3889 SourceLocation SelectorLoc,
3890 SourceLocation RBracLoc,
3891 MultiExprArg Args);
3893 ExprResult ActOnInstanceMessage(Scope *S,
3894 Expr *Receiver,
3895 Selector Sel,
3896 SourceLocation LBracLoc,
3897 SourceLocation SelectorLoc,
3898 SourceLocation RBracLoc,
3899 MultiExprArg Args);
3902 enum PragmaOptionsAlignKind {
3903 POAK_Native, // #pragma options align=native
3904 POAK_Natural, // #pragma options align=natural
3905 POAK_Packed, // #pragma options align=packed
3906 POAK_Power, // #pragma options align=power
3907 POAK_Mac68k, // #pragma options align=mac68k
3908 POAK_Reset // #pragma options align=reset
3911 /// ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
3912 void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
3913 SourceLocation PragmaLoc,
3914 SourceLocation KindLoc);
3916 enum PragmaPackKind {
3917 PPK_Default, // #pragma pack([n])
3918 PPK_Show, // #pragma pack(show), only supported by MSVC.
3919 PPK_Push, // #pragma pack(push, [identifier], [n])
3920 PPK_Pop // #pragma pack(pop, [identifier], [n])
3923 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
3924 void ActOnPragmaPack(PragmaPackKind Kind,
3925 IdentifierInfo *Name,
3926 Expr *Alignment,
3927 SourceLocation PragmaLoc,
3928 SourceLocation LParenLoc,
3929 SourceLocation RParenLoc);
3931 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
3932 void ActOnPragmaUnused(const Token *Identifiers,
3933 unsigned NumIdentifiers, Scope *curScope,
3934 SourceLocation PragmaLoc,
3935 SourceLocation LParenLoc,
3936 SourceLocation RParenLoc);
3938 /// ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
3939 void ActOnPragmaVisibility(bool IsPush, const IdentifierInfo* VisType,
3940 SourceLocation PragmaLoc);
3942 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II);
3943 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
3945 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident.
3946 void ActOnPragmaWeakID(IdentifierInfo* WeakName,
3947 SourceLocation PragmaLoc,
3948 SourceLocation WeakNameLoc);
3950 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
3951 void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
3952 IdentifierInfo* AliasName,
3953 SourceLocation PragmaLoc,
3954 SourceLocation WeakNameLoc,
3955 SourceLocation AliasNameLoc);
3957 /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
3958 /// a the record decl, to handle '#pragma pack' and '#pragma options align'.
3959 void AddAlignmentAttributesForRecord(RecordDecl *RD);
3961 /// FreePackedContext - Deallocate and null out PackContext.
3962 void FreePackedContext();
3964 /// PushNamespaceVisibilityAttr - Note that we've entered a
3965 /// namespace with a visibility attribute.
3966 void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr);
3968 /// AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used,
3969 /// add an appropriate visibility attribute.
3970 void AddPushedVisibilityAttribute(Decl *RD);
3972 /// PopPragmaVisibility - Pop the top element of the visibility stack; used
3973 /// for '#pragma GCC visibility' and visibility attributes on namespaces.
3974 void PopPragmaVisibility();
3976 /// FreeVisContext - Deallocate and null out VisContext.
3977 void FreeVisContext();
3979 /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
3980 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, Expr *E);
3981 void AddAlignedAttr(SourceLocation AttrLoc, Decl *D, TypeSourceInfo *T);
3983 /// CastCategory - Get the correct forwarded implicit cast result category
3984 /// from the inner expression.
3985 ExprValueKind CastCategory(Expr *E);
3987 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
3988 /// cast. If there is already an implicit cast, merge into the existing one.
3989 /// If isLvalue, the result of the cast is an lvalue.
3990 void ImpCastExprToType(Expr *&Expr, QualType Type, CastKind CK,
3991 ExprValueKind VK = VK_RValue,
3992 const CXXCastPath *BasePath = 0);
3994 /// IgnoredValueConversions - Given that an expression's result is
3995 /// syntactically ignored, perform any conversions that are
3996 /// required.
3997 void IgnoredValueConversions(Expr *&expr);
3999 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
4000 // functions and arrays to their respective pointers (C99 6.3.2.1).
4001 Expr *UsualUnaryConversions(Expr *&expr);
4003 // DefaultFunctionArrayConversion - converts functions and arrays
4004 // to their respective pointers (C99 6.3.2.1).
4005 void DefaultFunctionArrayConversion(Expr *&expr);
4007 // DefaultFunctionArrayLvalueConversion - converts functions and
4008 // arrays to their respective pointers and performs the
4009 // lvalue-to-rvalue conversion.
4010 void DefaultFunctionArrayLvalueConversion(Expr *&expr);
4012 // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on
4013 // the operand. This is DefaultFunctionArrayLvalueConversion,
4014 // except that it assumes the operand isn't of function or array
4015 // type.
4016 void DefaultLvalueConversion(Expr *&expr);
4018 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
4019 // do not have a prototype. Integer promotions are performed on each
4020 // argument, and arguments that have type float are promoted to double.
4021 void DefaultArgumentPromotion(Expr *&Expr);
4023 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
4024 enum VariadicCallType {
4025 VariadicFunction,
4026 VariadicBlock,
4027 VariadicMethod,
4028 VariadicConstructor,
4029 VariadicDoesNotApply
4032 /// GatherArgumentsForCall - Collector argument expressions for various
4033 /// form of call prototypes.
4034 bool GatherArgumentsForCall(SourceLocation CallLoc,
4035 FunctionDecl *FDecl,
4036 const FunctionProtoType *Proto,
4037 unsigned FirstProtoArg,
4038 Expr **Args, unsigned NumArgs,
4039 llvm::SmallVector<Expr *, 8> &AllArgs,
4040 VariadicCallType CallType = VariadicDoesNotApply);
4042 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
4043 // will warn if the resulting type is not a POD type.
4044 bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT,
4045 FunctionDecl *FDecl);
4047 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
4048 // operands and then handles various conversions that are common to binary
4049 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
4050 // routine returns the first non-arithmetic type found. The client is
4051 // responsible for emitting appropriate error diagnostics.
4052 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
4053 bool isCompAssign = false);
4055 /// AssignConvertType - All of the 'assignment' semantic checks return this
4056 /// enum to indicate whether the assignment was allowed. These checks are
4057 /// done for simple assignments, as well as initialization, return from
4058 /// function, argument passing, etc. The query is phrased in terms of a
4059 /// source and destination type.
4060 enum AssignConvertType {
4061 /// Compatible - the types are compatible according to the standard.
4062 Compatible,
4064 /// PointerToInt - The assignment converts a pointer to an int, which we
4065 /// accept as an extension.
4066 PointerToInt,
4068 /// IntToPointer - The assignment converts an int to a pointer, which we
4069 /// accept as an extension.
4070 IntToPointer,
4072 /// FunctionVoidPointer - The assignment is between a function pointer and
4073 /// void*, which the standard doesn't allow, but we accept as an extension.
4074 FunctionVoidPointer,
4076 /// IncompatiblePointer - The assignment is between two pointers types that
4077 /// are not compatible, but we accept them as an extension.
4078 IncompatiblePointer,
4080 /// IncompatiblePointer - The assignment is between two pointers types which
4081 /// point to integers which have a different sign, but are otherwise identical.
4082 /// This is a subset of the above, but broken out because it's by far the most
4083 /// common case of incompatible pointers.
4084 IncompatiblePointerSign,
4086 /// CompatiblePointerDiscardsQualifiers - The assignment discards
4087 /// c/v/r qualifiers, which we accept as an extension.
4088 CompatiblePointerDiscardsQualifiers,
4090 /// IncompatibleNestedPointerQualifiers - The assignment is between two
4091 /// nested pointer types, and the qualifiers other than the first two
4092 /// levels differ e.g. char ** -> const char **, but we accept them as an
4093 /// extension.
4094 IncompatibleNestedPointerQualifiers,
4096 /// IncompatibleVectors - The assignment is between two vector types that
4097 /// have the same size, which we accept as an extension.
4098 IncompatibleVectors,
4100 /// IntToBlockPointer - The assignment converts an int to a block
4101 /// pointer. We disallow this.
4102 IntToBlockPointer,
4104 /// IncompatibleBlockPointer - The assignment is between two block
4105 /// pointers types that are not compatible.
4106 IncompatibleBlockPointer,
4108 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
4109 /// id type and something else (that is incompatible with it). For example,
4110 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
4111 IncompatibleObjCQualifiedId,
4113 /// Incompatible - We reject this conversion outright, it is invalid to
4114 /// represent it in the AST.
4115 Incompatible
4118 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
4119 /// assignment conversion type specified by ConvTy. This returns true if the
4120 /// conversion was invalid or false if the conversion was accepted.
4121 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
4122 SourceLocation Loc,
4123 QualType DstType, QualType SrcType,
4124 Expr *SrcExpr, AssignmentAction Action,
4125 bool *Complained = 0);
4127 /// CheckAssignmentConstraints - Perform type checking for assignment,
4128 /// argument passing, variable initialization, and function return values.
4129 /// C99 6.5.16.
4130 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
4132 /// Check assignment constraints and prepare for a conversion of the
4133 /// RHS to the LHS type.
4134 AssignConvertType CheckAssignmentConstraints(QualType lhs, Expr *&rhs,
4135 CastKind &Kind);
4137 // CheckSingleAssignmentConstraints - Currently used by
4138 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
4139 // this routine performs the default function/array converions.
4140 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
4141 Expr *&rExpr);
4143 // \brief If the lhs type is a transparent union, check whether we
4144 // can initialize the transparent union with the given expression.
4145 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs,
4146 Expr *&rExpr);
4148 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
4149 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
4150 QualType rhsType);
4152 AssignConvertType CheckObjCPointerTypesForAssignment(QualType lhsType,
4153 QualType rhsType);
4155 // Helper function for CheckAssignmentConstraints involving two
4156 // block pointer types.
4157 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
4158 QualType rhsType);
4160 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
4162 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
4164 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4165 AssignmentAction Action,
4166 bool AllowExplicit = false);
4167 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4168 AssignmentAction Action,
4169 bool AllowExplicit,
4170 ImplicitConversionSequence& ICS);
4171 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4172 const ImplicitConversionSequence& ICS,
4173 AssignmentAction Action,
4174 bool IgnoreBaseAccess = false);
4175 bool PerformImplicitConversion(Expr *&From, QualType ToType,
4176 const StandardConversionSequence& SCS,
4177 AssignmentAction Action,bool IgnoreBaseAccess);
4179 /// the following "Check" methods will return a valid/converted QualType
4180 /// or a null QualType (indicating an error diagnostic was issued).
4182 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
4183 QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
4184 QualType CheckPointerToMemberOperands( // C++ 5.5
4185 Expr *&lex, Expr *&rex, ExprValueKind &VK,
4186 SourceLocation OpLoc, bool isIndirect);
4187 QualType CheckMultiplyDivideOperands( // C99 6.5.5
4188 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign,
4189 bool isDivide);
4190 QualType CheckRemainderOperands( // C99 6.5.5
4191 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
4192 QualType CheckAdditionOperands( // C99 6.5.6
4193 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
4194 QualType CheckSubtractionOperands( // C99 6.5.6
4195 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
4196 QualType CheckShiftOperands( // C99 6.5.7
4197 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
4198 QualType CheckCompareOperands( // C99 6.5.8/9
4199 Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc,
4200 bool isRelational);
4201 QualType CheckBitwiseOperands( // C99 6.5.[10...12]
4202 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
4203 QualType CheckLogicalOperands( // C99 6.5.[13,14]
4204 Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc);
4205 // CheckAssignmentOperands is used for both simple and compound assignment.
4206 // For simple assignment, pass both expressions and a null converted type.
4207 // For compound assignment, pass both expressions and the converted type.
4208 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
4209 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
4211 void ConvertPropertyForRValue(Expr *&E);
4212 void ConvertPropertyForLValue(Expr *&LHS, Expr *&RHS, QualType& LHSTy);
4214 QualType CheckConditionalOperands( // C99 6.5.15
4215 Expr *&cond, Expr *&lhs, Expr *&rhs, Expr *&save,
4216 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
4217 QualType CXXCheckConditionalOperands( // C++ 5.16
4218 Expr *&cond, Expr *&lhs, Expr *&rhs, Expr *&save,
4219 ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc);
4220 QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2,
4221 bool *NonStandardCompositeType = 0);
4223 QualType FindCompositeObjCPointerType(Expr *&LHS, Expr *&RHS,
4224 SourceLocation questionLoc);
4226 /// type checking for vector binary operators.
4227 QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
4228 QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
4229 SourceLocation l, bool isRel);
4231 /// type checking declaration initializers (C99 6.7.8)
4232 bool CheckInitList(const InitializedEntity &Entity,
4233 InitListExpr *&InitList, QualType &DeclType);
4234 bool CheckForConstantInitializer(Expr *e, QualType t);
4236 // type checking C++ declaration initializers (C++ [dcl.init]).
4238 /// ReferenceCompareResult - Expresses the result of comparing two
4239 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
4240 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
4241 enum ReferenceCompareResult {
4242 /// Ref_Incompatible - The two types are incompatible, so direct
4243 /// reference binding is not possible.
4244 Ref_Incompatible = 0,
4245 /// Ref_Related - The two types are reference-related, which means
4246 /// that their unqualified forms (T1 and T2) are either the same
4247 /// or T1 is a base class of T2.
4248 Ref_Related,
4249 /// Ref_Compatible_With_Added_Qualification - The two types are
4250 /// reference-compatible with added qualification, meaning that
4251 /// they are reference-compatible and the qualifiers on T1 (cv1)
4252 /// are greater than the qualifiers on T2 (cv2).
4253 Ref_Compatible_With_Added_Qualification,
4254 /// Ref_Compatible - The two types are reference-compatible and
4255 /// have equivalent qualifiers (cv1 == cv2).
4256 Ref_Compatible
4259 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
4260 QualType T1, QualType T2,
4261 bool &DerivedToBase,
4262 bool &ObjCConversion);
4264 /// CheckCastTypes - Check type constraints for casting between types under
4265 /// C semantics, or forward to CXXCheckCStyleCast in C++.
4266 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr,
4267 CastKind &Kind, ExprValueKind &VK, CXXCastPath &BasePath,
4268 bool FunctionalStyle = false);
4270 // CheckVectorCast - check type constraints for vectors.
4271 // Since vectors are an extension, there are no C standard reference for this.
4272 // We allow casting between vectors and integer datatypes of the same size.
4273 // returns true if the cast is invalid
4274 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
4275 CastKind &Kind);
4277 // CheckExtVectorCast - check type constraints for extended vectors.
4278 // Since vectors are an extension, there are no C standard reference for this.
4279 // We allow casting between vectors and integer datatypes of the same size,
4280 // or vectors and the element type of that vector.
4281 // returns true if the cast is invalid
4282 bool CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *&CastExpr,
4283 CastKind &Kind);
4285 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style
4286 /// cast under C++ semantics.
4287 bool CXXCheckCStyleCast(SourceRange R, QualType CastTy, ExprValueKind &VK,
4288 Expr *&CastExpr, CastKind &Kind,
4289 CXXCastPath &BasePath, bool FunctionalStyle);
4291 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
4292 /// \param Method - May be null.
4293 /// \param [out] ReturnType - The return type of the send.
4294 /// \return true iff there were any incompatible types.
4295 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
4296 ObjCMethodDecl *Method, bool isClassMessage,
4297 SourceLocation lbrac, SourceLocation rbrac,
4298 QualType &ReturnType, ExprValueKind &VK);
4300 /// CheckBooleanCondition - Diagnose problems involving the use of
4301 /// the given expression as a boolean condition (e.g. in an if
4302 /// statement). Also performs the standard function and array
4303 /// decays, possibly changing the input variable.
4305 /// \param Loc - A location associated with the condition, e.g. the
4306 /// 'if' keyword.
4307 /// \return true iff there were any errors
4308 bool CheckBooleanCondition(Expr *&CondExpr, SourceLocation Loc);
4310 ExprResult ActOnBooleanCondition(Scope *S, SourceLocation Loc,
4311 Expr *SubExpr);
4313 /// DiagnoseAssignmentAsCondition - Given that an expression is
4314 /// being used as a boolean condition, warn if it's an assignment.
4315 void DiagnoseAssignmentAsCondition(Expr *E);
4317 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
4318 bool CheckCXXBooleanCondition(Expr *&CondExpr);
4320 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
4321 /// the specified width and sign. If an overflow occurs, detect it and emit
4322 /// the specified diagnostic.
4323 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
4324 unsigned NewWidth, bool NewSign,
4325 SourceLocation Loc, unsigned DiagID);
4327 /// Checks that the Objective-C declaration is declared in the global scope.
4328 /// Emits an error and marks the declaration as invalid if it's not declared
4329 /// in the global scope.
4330 bool CheckObjCDeclScope(Decl *D);
4332 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
4333 /// and reports the appropriate diagnostics. Returns false on success.
4334 /// Can optionally return the value of the expression.
4335 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
4337 /// VerifyBitField - verifies that a bit field expression is an ICE and has
4338 /// the correct width, and that the field type is valid.
4339 /// Returns false on success.
4340 /// Can optionally return whether the bit-field is of width 0
4341 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
4342 QualType FieldTy, const Expr *BitWidth,
4343 bool *ZeroWidth = 0);
4345 /// \name Code completion
4346 //@{
4347 /// \brief Describes the context in which code completion occurs.
4348 enum ParserCompletionContext {
4349 /// \brief Code completion occurs at top-level or namespace context.
4350 PCC_Namespace,
4351 /// \brief Code completion occurs within a class, struct, or union.
4352 PCC_Class,
4353 /// \brief Code completion occurs within an Objective-C interface, protocol,
4354 /// or category.
4355 PCC_ObjCInterface,
4356 /// \brief Code completion occurs within an Objective-C implementation or
4357 /// category implementation
4358 PCC_ObjCImplementation,
4359 /// \brief Code completion occurs within the list of instance variables
4360 /// in an Objective-C interface, protocol, category, or implementation.
4361 PCC_ObjCInstanceVariableList,
4362 /// \brief Code completion occurs following one or more template
4363 /// headers.
4364 PCC_Template,
4365 /// \brief Code completion occurs following one or more template
4366 /// headers within a class.
4367 PCC_MemberTemplate,
4368 /// \brief Code completion occurs within an expression.
4369 PCC_Expression,
4370 /// \brief Code completion occurs within a statement, which may
4371 /// also be an expression or a declaration.
4372 PCC_Statement,
4373 /// \brief Code completion occurs at the beginning of the
4374 /// initialization statement (or expression) in a for loop.
4375 PCC_ForInit,
4376 /// \brief Code completion occurs within the condition of an if,
4377 /// while, switch, or for statement.
4378 PCC_Condition,
4379 /// \brief Code completion occurs within the body of a function on a
4380 /// recovery path, where we do not have a specific handle on our position
4381 /// in the grammar.
4382 PCC_RecoveryInFunction,
4383 /// \brief Code completion occurs where only a type is permitted.
4384 PCC_Type,
4385 /// \brief Code completion occurs in a parenthesized expression, which
4386 /// might also be a type cast.
4387 PCC_ParenthesizedExpression
4390 void CodeCompleteOrdinaryName(Scope *S,
4391 ParserCompletionContext CompletionContext);
4392 void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS,
4393 bool AllowNonIdentifiers,
4394 bool AllowNestedNameSpecifiers);
4396 struct CodeCompleteExpressionData;
4397 void CodeCompleteExpression(Scope *S,
4398 const CodeCompleteExpressionData &Data);
4399 void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
4400 SourceLocation OpLoc,
4401 bool IsArrow);
4402 void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
4403 void CodeCompleteTag(Scope *S, unsigned TagSpec);
4404 void CodeCompleteTypeQualifiers(DeclSpec &DS);
4405 void CodeCompleteCase(Scope *S);
4406 void CodeCompleteCall(Scope *S, Expr *Fn, Expr **Args, unsigned NumArgs);
4407 void CodeCompleteInitializer(Scope *S, Decl *D);
4408 void CodeCompleteReturn(Scope *S);
4409 void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS);
4411 void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
4412 bool EnteringContext);
4413 void CodeCompleteUsing(Scope *S);
4414 void CodeCompleteUsingDirective(Scope *S);
4415 void CodeCompleteNamespaceDecl(Scope *S);
4416 void CodeCompleteNamespaceAliasDecl(Scope *S);
4417 void CodeCompleteOperatorName(Scope *S);
4418 void CodeCompleteConstructorInitializer(Decl *Constructor,
4419 CXXBaseOrMemberInitializer** Initializers,
4420 unsigned NumInitializers);
4422 void CodeCompleteObjCAtDirective(Scope *S, Decl *ObjCImpDecl,
4423 bool InInterface);
4424 void CodeCompleteObjCAtVisibility(Scope *S);
4425 void CodeCompleteObjCAtStatement(Scope *S);
4426 void CodeCompleteObjCAtExpression(Scope *S);
4427 void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
4428 void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl,
4429 Decl **Methods,
4430 unsigned NumMethods);
4431 void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl,
4432 Decl **Methods,
4433 unsigned NumMethods);
4434 void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS);
4435 void CodeCompleteObjCMessageReceiver(Scope *S);
4436 void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
4437 IdentifierInfo **SelIdents,
4438 unsigned NumSelIdents,
4439 bool AtArgumentExpression);
4440 void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver,
4441 IdentifierInfo **SelIdents,
4442 unsigned NumSelIdents,
4443 bool AtArgumentExpression,
4444 bool IsSuper = false);
4445 void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver,
4446 IdentifierInfo **SelIdents,
4447 unsigned NumSelIdents,
4448 bool AtArgumentExpression,
4449 ObjCInterfaceDecl *Super = 0);
4450 void CodeCompleteObjCForCollection(Scope *S,
4451 DeclGroupPtrTy IterationVar);
4452 void CodeCompleteObjCSelector(Scope *S,
4453 IdentifierInfo **SelIdents,
4454 unsigned NumSelIdents);
4455 void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
4456 unsigned NumProtocols);
4457 void CodeCompleteObjCProtocolDecl(Scope *S);
4458 void CodeCompleteObjCInterfaceDecl(Scope *S);
4459 void CodeCompleteObjCSuperclass(Scope *S,
4460 IdentifierInfo *ClassName,
4461 SourceLocation ClassNameLoc);
4462 void CodeCompleteObjCImplementationDecl(Scope *S);
4463 void CodeCompleteObjCInterfaceCategory(Scope *S,
4464 IdentifierInfo *ClassName,
4465 SourceLocation ClassNameLoc);
4466 void CodeCompleteObjCImplementationCategory(Scope *S,
4467 IdentifierInfo *ClassName,
4468 SourceLocation ClassNameLoc);
4469 void CodeCompleteObjCPropertyDefinition(Scope *S, Decl *ObjCImpDecl);
4470 void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
4471 IdentifierInfo *PropertyName,
4472 Decl *ObjCImpDecl);
4473 void CodeCompleteObjCMethodDecl(Scope *S,
4474 bool IsInstanceMethod,
4475 ParsedType ReturnType,
4476 Decl *IDecl);
4477 void CodeCompleteObjCMethodDeclSelector(Scope *S,
4478 bool IsInstanceMethod,
4479 bool AtParameterName,
4480 ParsedType ReturnType,
4481 IdentifierInfo **SelIdents,
4482 unsigned NumSelIdents);
4483 void CodeCompletePreprocessorDirective(bool InConditional);
4484 void CodeCompleteInPreprocessorConditionalExclusion(Scope *S);
4485 void CodeCompletePreprocessorMacroName(bool IsDefinition);
4486 void CodeCompletePreprocessorExpression();
4487 void CodeCompletePreprocessorMacroArgument(Scope *S,
4488 IdentifierInfo *Macro,
4489 MacroInfo *MacroInfo,
4490 unsigned Argument);
4491 void CodeCompleteNaturalLanguage();
4492 void GatherGlobalCodeCompletions(
4493 llvm::SmallVectorImpl<CodeCompletionResult> &Results);
4494 //@}
4496 void PrintStats() const {}
4498 //===--------------------------------------------------------------------===//
4499 // Extra semantic analysis beyond the C type system
4501 public:
4502 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
4503 unsigned ByteNo) const;
4505 private:
4506 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
4507 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall);
4509 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall);
4510 bool CheckObjCString(Expr *Arg);
4512 ExprResult CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
4513 bool CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
4515 bool SemaBuiltinVAStart(CallExpr *TheCall);
4516 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
4517 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
4519 public:
4520 // Used by C++ template instantiation.
4521 ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
4523 private:
4524 bool SemaBuiltinPrefetch(CallExpr *TheCall);
4525 bool SemaBuiltinObjectSize(CallExpr *TheCall);
4526 bool SemaBuiltinLongjmp(CallExpr *TheCall);
4527 ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult);
4528 bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum,
4529 llvm::APSInt &Result);
4531 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall,
4532 bool HasVAListArg, unsigned format_idx,
4533 unsigned firstDataArg, bool isPrintf);
4535 void CheckFormatString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
4536 const CallExpr *TheCall, bool HasVAListArg,
4537 unsigned format_idx, unsigned firstDataArg,
4538 bool isPrintf);
4540 void CheckNonNullArguments(const NonNullAttr *NonNull,
4541 const CallExpr *TheCall);
4543 void CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg,
4544 unsigned format_idx, unsigned firstDataArg,
4545 bool isPrintf);
4547 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
4548 SourceLocation ReturnLoc);
4549 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
4550 void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
4552 void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field,
4553 Expr *Init);
4555 /// \brief The parser's current scope.
4557 /// The parser maintains this state here.
4558 Scope *CurScope;
4560 protected:
4561 friend class Parser;
4562 friend class InitializationSequence;
4564 /// \brief Retrieve the parser's current scope.
4565 Scope *getCurScope() const { return CurScope; }
4568 /// \brief RAII object that enters a new expression evaluation context.
4569 class EnterExpressionEvaluationContext {
4570 Sema &Actions;
4572 public:
4573 EnterExpressionEvaluationContext(Sema &Actions,
4574 Sema::ExpressionEvaluationContext NewContext)
4575 : Actions(Actions) {
4576 Actions.PushExpressionEvaluationContext(NewContext);
4579 ~EnterExpressionEvaluationContext() {
4580 Actions.PopExpressionEvaluationContext();
4584 } // end namespace clang
4586 #endif