blob: 747fd889786f3e2d500f47aac71d76b757476e3e [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the Sema class, which performs semantic analysis and
11// builds ASTs.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_SEMA_H
16#define LLVM_CLANG_AST_SEMA_H
17
Chris Lattner7f925cc2008-04-11 07:00:53 +000018#include "IdentifierResolver.h"
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +000019#include "CXXFieldCollector.h"
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000020#include "SemaOverload.h"
Douglas Gregord1102432009-08-28 17:37:35 +000021#include "SemaTemplate.h"
Douglas Gregore0762c92009-06-19 23:52:42 +000022#include "clang/AST/Attr.h"
Douglas Gregoreb11cd02009-01-14 22:20:51 +000023#include "clang/AST/DeclBase.h"
Douglas Gregore0762c92009-06-19 23:52:42 +000024#include "clang/AST/Decl.h"
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +000025#include "clang/AST/DeclObjC.h"
Anders Carlsson1c5976e2009-06-05 03:43:12 +000026#include "clang/AST/DeclTemplate.h"
Anders Carlsson5ee56e92009-12-16 02:09:40 +000027#include "clang/AST/FullExpr.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000028#include "clang/Parse/Action.h"
Chris Lattner500d3292009-01-29 05:15:15 +000029#include "clang/Sema/SemaDiagnostic.h"
Anders Carlssonc1fcb772007-07-22 07:07:56 +000030#include "llvm/ADT/SmallVector.h"
Fariborz Jahanian85ff2642007-10-05 18:00:57 +000031#include "llvm/ADT/DenseSet.h"
Chris Lattnerf3876682007-10-07 01:13:46 +000032#include "llvm/ADT/SmallPtrSet.h"
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +000033#include "llvm/ADT/OwningPtr.h"
Douglas Gregorb33fe2f2009-06-30 17:20:14 +000034#include <deque>
Douglas Gregorac7610d2009-06-22 20:57:11 +000035#include <list>
Anders Carlssond6a637f2009-12-07 08:24:59 +000036#include <map>
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +000037#include <string>
Douglas Gregor94b1dd22008-10-24 04:54:22 +000038#include <vector>
Reid Spencer5f016e22007-07-11 17:01:13 +000039
Chris Lattnerf4021e72007-08-23 05:46:52 +000040namespace llvm {
41 class APSInt;
42}
43
Reid Spencer5f016e22007-07-11 17:01:13 +000044namespace clang {
Mike Stumpfa6ef182010-01-13 02:59:54 +000045 class AnalysisContext;
Reid Spencer5f016e22007-07-11 17:01:13 +000046 class ASTContext;
Chris Lattner2ae34ed2008-02-06 00:46:58 +000047 class ASTConsumer;
Douglas Gregor81b747b2009-09-17 21:32:03 +000048 class CodeCompleteConsumer;
Reid Spencer5f016e22007-07-11 17:01:13 +000049 class Preprocessor;
50 class Decl;
Chris Lattnerb048c982008-04-06 04:47:34 +000051 class DeclContext;
Daniel Dunbar12bc6922008-08-11 03:27:53 +000052 class DeclSpec;
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +000053 class ExternalSemaSource;
Steve Naroffe8043c32008-04-01 23:04:06 +000054 class NamedDecl;
Sebastian Redl798d1192008-12-13 16:23:55 +000055 class Stmt;
Reid Spencer5f016e22007-07-11 17:01:13 +000056 class Expr;
Steve Naroff6f9f3072007-09-02 15:34:30 +000057 class InitListExpr;
Nate Begeman2ef13e52009-08-10 23:49:36 +000058 class ParenListExpr;
Douglas Gregor05c13a32009-01-22 00:58:24 +000059 class DesignatedInitExpr;
Chris Lattner925e60d2007-12-28 05:29:59 +000060 class CallExpr;
Douglas Gregor1a49af92009-01-06 05:10:23 +000061 class DeclRefExpr;
John McCall3b4294e2009-12-16 12:17:52 +000062 class UnresolvedLookupExpr;
John McCallc373d482010-01-27 01:50:18 +000063 class UnresolvedMemberExpr;
Reid Spencer5f016e22007-07-11 17:01:13 +000064 class VarDecl;
65 class ParmVarDecl;
66 class TypedefDecl;
67 class FunctionDecl;
68 class QualType;
Sebastian Redl43af76e2009-03-07 12:16:37 +000069 class LangOptions;
Chris Lattnerd2177732007-07-20 16:59:19 +000070 class Token;
Reid Spencer5f016e22007-07-11 17:01:13 +000071 class IntegerLiteral;
Steve Naroffa49e1fa2008-01-22 00:55:40 +000072 class StringLiteral;
Reid Spencer5f016e22007-07-11 17:01:13 +000073 class ArrayType;
74 class LabelStmt;
Anders Carlssonc1fcb772007-07-22 07:07:56 +000075 class SwitchStmt;
Sebastian Redl13e88542009-04-27 21:33:24 +000076 class CXXTryStmt;
Nate Begeman213541a2008-04-18 23:10:10 +000077 class ExtVectorType;
Steve Naroffbea0b342007-07-29 16:33:31 +000078 class TypedefDecl;
Douglas Gregoraaba5e32009-02-04 19:02:06 +000079 class TemplateDecl;
Douglas Gregor3e00bad2009-02-17 01:05:43 +000080 class TemplateArgument;
John McCall833ca992009-10-29 08:12:44 +000081 class TemplateArgumentLoc;
Douglas Gregor7e063902009-05-11 23:53:27 +000082 class TemplateArgumentList;
Douglas Gregorddc29e12009-02-06 22:42:48 +000083 class TemplateParameterList;
Douglas Gregorc15cb382009-02-09 23:23:08 +000084 class TemplateTemplateParmDecl;
Douglas Gregorc8ab2562009-05-31 09:31:02 +000085 class ClassTemplatePartialSpecializationDecl;
Douglas Gregor88b70942009-02-25 22:02:03 +000086 class ClassTemplateDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000087 class ObjCInterfaceDecl;
Steve Naroffe8043c32008-04-01 23:04:06 +000088 class ObjCCompatibleAliasDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000089 class ObjCProtocolDecl;
Chris Lattnercddc8882009-03-01 00:56:52 +000090 class ObjCImplDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000091 class ObjCImplementationDecl;
92 class ObjCCategoryImplDecl;
93 class ObjCCategoryDecl;
94 class ObjCIvarDecl;
95 class ObjCMethodDecl;
Fariborz Jahanian02edb982008-05-01 00:03:38 +000096 class ObjCPropertyDecl;
Steve Naroff0701bbb2009-01-08 17:28:14 +000097 class ObjCContainerDecl;
Douglas Gregora2e7dd22010-02-25 01:56:36 +000098 class PseudoDestructorTypeStorage;
Sebastian Redl4994d2d2009-07-04 11:39:00 +000099 class FunctionProtoType;
John McCall6b2accb2010-02-10 09:31:12 +0000100 class CXXBasePath;
Douglas Gregora8f32e02009-10-06 17:59:45 +0000101 class CXXBasePaths;
Anders Carlssonff6b3d62009-05-30 21:05:25 +0000102 class CXXTemporary;
John McCall7d384dd2009-11-18 07:57:50 +0000103 class LookupResult;
Douglas Gregor20093b42009-12-09 23:02:17 +0000104 class InitializedEntity;
105 class InitializationKind;
106 class InitializationSequence;
Douglas Gregor546be3c2009-12-30 17:04:44 +0000107 class VisibleDeclConsumer;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000108 class TargetAttributesSema;
John McCall7edb5fd2010-01-26 07:16:45 +0000109 class ADLResult;
Douglas Gregor546be3c2009-12-30 17:04:44 +0000110
Douglas Gregor076ceb02010-03-01 20:44:28 +0000111/// \brief Retains information about a function, method, or block that is
112/// currently being parsed.
113struct FunctionScopeInfo {
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000114 /// \brief Whether this scope information structure defined information for
115 /// a block.
116 bool IsBlockInfo;
117
118 /// \brief Set true when a function, method contains a VLA or ObjC try block,
119 /// which introduce scopes that need to be checked for goto conditions. If a
120 /// function does not contain this, then it need not have the jump checker run on it.
121 bool NeedsScopeChecking;
122
123 /// \brief The number of errors that had occurred before starting this
124 /// function or block.
125 unsigned NumErrorsAtStartOfFunction;
126
Douglas Gregor076ceb02010-03-01 20:44:28 +0000127 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
128 /// it (which acts like the label decl in some ways). Forward referenced
129 /// labels have a LabelStmt created for them with a null location & SubStmt.
130 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
131
132 /// SwitchStack - This is the current set of active switch statements in the
133 /// block.
134 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
135
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000136 FunctionScopeInfo(unsigned NumErrors)
137 : IsBlockInfo(false), NeedsScopeChecking(false),
138 NumErrorsAtStartOfFunction(NumErrors) { }
139
140 virtual ~FunctionScopeInfo();
141
142 /// \brief Clear out the information in this function scope, making it
143 /// suitable for reuse.
144 void Clear(unsigned NumErrors);
Douglas Gregor076ceb02010-03-01 20:44:28 +0000145
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000146 static bool classof(const FunctionScopeInfo *FSI) { return true; }
Douglas Gregor076ceb02010-03-01 20:44:28 +0000147};
148
149
150/// \brief Retains information about a block that is currently being parsed.
151struct BlockScopeInfo : FunctionScopeInfo {
Chris Lattnerea29a3a2009-04-18 20:01:55 +0000152 llvm::SmallVector<ParmVarDecl*, 8> Params;
153 bool hasPrototype;
154 bool isVariadic;
155 bool hasBlockDeclRefExprs;
Mike Stump1eb44332009-09-09 15:08:12 +0000156
Chris Lattnerea29a3a2009-04-18 20:01:55 +0000157 BlockDecl *TheDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000158
Chris Lattnerea29a3a2009-04-18 20:01:55 +0000159 /// TheScope - This is the scope for the block itself, which contains
160 /// arguments etc.
161 Scope *TheScope;
Mike Stump1eb44332009-09-09 15:08:12 +0000162
Chris Lattnerea29a3a2009-04-18 20:01:55 +0000163 /// ReturnType - This will get set to block result type, by looking at
164 /// return types, if any, in the block body.
Fariborz Jahanian7d5c74e2009-06-19 23:37:08 +0000165 QualType ReturnType;
Mike Stump1eb44332009-09-09 15:08:12 +0000166
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000167 BlockScopeInfo(unsigned NumErrors, Scope *BlockScope, BlockDecl *Block)
168 : FunctionScopeInfo(NumErrors), hasPrototype(false), isVariadic(false),
169 hasBlockDeclRefExprs(false), TheDecl(Block), TheScope(BlockScope)
170 {
171 IsBlockInfo = true;
172 }
Mike Stump1eb44332009-09-09 15:08:12 +0000173
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000174 virtual ~BlockScopeInfo();
175
Douglas Gregor076ceb02010-03-01 20:44:28 +0000176 static bool classof(const FunctionScopeInfo *FSI) { return FSI->IsBlockInfo; }
177 static bool classof(const BlockScopeInfo *BSI) { return true; }
Chris Lattnerea29a3a2009-04-18 20:01:55 +0000178};
179
John McCalla93c9342009-12-07 02:54:59 +0000180/// \brief Holds a QualType and a TypeSourceInfo* that came out of a declarator
Argyrios Kyrtzidis1bb8a452009-08-19 01:28:17 +0000181/// parsing.
182///
183/// LocInfoType is a "transient" type, only needed for passing to/from Parser
184/// and Sema, when we want to preserve type source info for a parsed type.
185/// It will not participate in the type system semantics in any way.
186class LocInfoType : public Type {
187 enum {
188 // The last number that can fit in Type's TC.
Mike Stump1eb44332009-09-09 15:08:12 +0000189 // Avoids conflict with an existing Type class.
John McCall27935ee2010-02-12 03:41:30 +0000190 LocInfo = Type::TypeLast + 1
Argyrios Kyrtzidis1bb8a452009-08-19 01:28:17 +0000191 };
192
John McCalla93c9342009-12-07 02:54:59 +0000193 TypeSourceInfo *DeclInfo;
Argyrios Kyrtzidis1bb8a452009-08-19 01:28:17 +0000194
John McCalla93c9342009-12-07 02:54:59 +0000195 LocInfoType(QualType ty, TypeSourceInfo *TInfo)
196 : Type((TypeClass)LocInfo, ty, ty->isDependentType()), DeclInfo(TInfo) {
Argyrios Kyrtzidis1bb8a452009-08-19 01:28:17 +0000197 assert(getTypeClass() == (TypeClass)LocInfo && "LocInfo didn't fit in TC?");
198 }
199 friend class Sema;
200
201public:
202 QualType getType() const { return getCanonicalTypeInternal(); }
John McCalla93c9342009-12-07 02:54:59 +0000203 TypeSourceInfo *getTypeSourceInfo() const { return DeclInfo; }
Argyrios Kyrtzidis1bb8a452009-08-19 01:28:17 +0000204
205 virtual void getAsStringInternal(std::string &Str,
206 const PrintingPolicy &Policy) const;
207
208 static bool classof(const Type *T) {
209 return T->getTypeClass() == (TypeClass)LocInfo;
210 }
211 static bool classof(const LocInfoType *) { return true; }
212};
213
Reid Spencer5f016e22007-07-11 17:01:13 +0000214/// Sema - This implements semantic analysis and AST building for C.
215class Sema : public Action {
Chris Lattnerf50adff2009-02-17 00:58:30 +0000216 Sema(const Sema&); // DO NOT IMPLEMENT
217 void operator=(const Sema&); // DO NOT IMPLEMENT
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000218 mutable const TargetAttributesSema* TheTargetAttributesSema;
Chris Lattner0b2f4da2008-06-29 00:28:59 +0000219public:
Chris Lattner53ebff32009-01-22 19:21:44 +0000220 const LangOptions &LangOpts;
Reid Spencer5f016e22007-07-11 17:01:13 +0000221 Preprocessor &PP;
Reid Spencer5f016e22007-07-11 17:01:13 +0000222 ASTContext &Context;
Chris Lattner2ae34ed2008-02-06 00:46:58 +0000223 ASTConsumer &Consumer;
Chris Lattner3cfa9282008-11-22 08:28:49 +0000224 Diagnostic &Diags;
225 SourceManager &SourceMgr;
Steve Naroff03300712007-11-12 13:56:41 +0000226
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +0000227 /// \brief Source of additional semantic information.
228 ExternalSemaSource *ExternalSource;
229
Douglas Gregor81b747b2009-09-17 21:32:03 +0000230 /// \brief Code-completion consumer.
231 CodeCompleteConsumer *CodeCompleter;
232
Argyrios Kyrtzidis53d0ea52008-06-28 06:07:14 +0000233 /// CurContext - This is the current declaration context of parsing.
Chris Lattnerb048c982008-04-06 04:47:34 +0000234 DeclContext *CurContext;
Chris Lattner0ed844b2008-04-04 06:12:32 +0000235
Daniel Dunbar4cde9272008-10-14 05:35:18 +0000236 /// PackContext - Manages the stack for #pragma pack. An alignment
237 /// of 0 indicates default alignment.
Chris Lattner574aa402009-02-17 01:09:29 +0000238 void *PackContext; // Really a "PragmaPackStack*"
Daniel Dunbar4cde9272008-10-14 05:35:18 +0000239
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000240 /// \brief Stack containing information about each of the nested function,
241 /// block, and method scopes that are currently active.
242 llvm::SmallVector<FunctionScopeInfo *, 4> FunctionScopes;
243
244 /// \brief Cached function scope object used for the top function scope
245 /// and when there is no function scope (in error cases).
Chris Lattnerea29a3a2009-04-18 20:01:55 +0000246 ///
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000247 /// This should never be accessed directly; rather, it's address will be
248 /// pushed into \c FunctionScopes when we want to re-use it.
249 FunctionScopeInfo TopFunctionScope;
250
Mike Stump1eb44332009-09-09 15:08:12 +0000251 /// ExprTemporaries - This is the stack of temporaries that are created by
Anders Carlsson165a0a02009-05-17 18:41:29 +0000252 /// the current full expression.
Anders Carlssonff6b3d62009-05-30 21:05:25 +0000253 llvm::SmallVector<CXXTemporary*, 8> ExprTemporaries;
Anders Carlsson165a0a02009-05-17 18:41:29 +0000254
Nate Begeman213541a2008-04-18 23:10:10 +0000255 /// ExtVectorDecls - This is a list all the extended vector types. This allows
256 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroffbea0b342007-07-29 16:33:31 +0000257 /// This is only necessary for issuing pretty diagnostics.
Nate Begeman213541a2008-04-18 23:10:10 +0000258 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Mike Stump1eb44332009-09-09 15:08:12 +0000259
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000260 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
261 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
262
Anders Carlsson4681ebd2009-03-22 20:18:17 +0000263 typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
Mike Stump1eb44332009-09-09 15:08:12 +0000264
265 /// PureVirtualClassDiagSet - a set of class declarations which we have
Anders Carlsson4681ebd2009-03-22 20:18:17 +0000266 /// emitted a list of pure virtual functions. Used to prevent emitting the
267 /// same list more than once.
268 llvm::OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet;
Mike Stump1eb44332009-09-09 15:08:12 +0000269
Douglas Gregor63935192009-03-02 00:19:53 +0000270 /// \brief A mapping from external names to the most recent
271 /// locally-scoped external declaration with that name.
272 ///
273 /// This map contains external declarations introduced in local
274 /// scoped, e.g.,
275 ///
276 /// \code
277 /// void f() {
278 /// void foo(int, int);
279 /// }
280 /// \endcode
281 ///
282 /// Here, the name "foo" will be associated with the declaration on
283 /// "foo" within f. This name is not visible outside of
284 /// "f". However, we still find it in two cases:
285 ///
286 /// - If we are declaring another external with the name "foo", we
287 /// can find "foo" as a previous declaration, so that the types
288 /// of this external declaration can be checked for
289 /// compatibility.
290 ///
291 /// - If we would implicitly declare "foo" (e.g., due to a call to
292 /// "foo" in C when no prototype or definition is visible), then
293 /// we find this declaration of "foo" and complain that it is
294 /// not visible.
295 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
296
Sebastian Redle9d12b62010-01-31 22:27:38 +0000297 /// \brief All the tentative definitions encountered in the TU.
298 std::vector<VarDecl *> TentativeDefinitions;
Douglas Gregorb6c8c8b2009-04-21 17:11:58 +0000299
Tanya Lattnere6bbc012010-02-12 00:07:30 +0000300 /// \brief The set of static functions seen so far that have not been used.
301 std::vector<FunctionDecl*> UnusedStaticFuncs;
302
John McCall6b2accb2010-02-10 09:31:12 +0000303 class AccessedEntity {
304 public:
John McCall58e6f342010-03-16 05:22:47 +0000305 /// A member declaration found through lookup. The target is the
306 /// member.
307 enum MemberNonce { Member };
John McCall6b2accb2010-02-10 09:31:12 +0000308
John McCall58e6f342010-03-16 05:22:47 +0000309 /// A hierarchy (base-to-derived or derived-to-base) conversion.
310 /// The target is the base class.
311 enum BaseNonce { Base };
John McCall6b2accb2010-02-10 09:31:12 +0000312
John McCall58e6f342010-03-16 05:22:47 +0000313 bool isMemberAccess() const { return IsMember; }
John McCall6b2accb2010-02-10 09:31:12 +0000314
John McCall58e6f342010-03-16 05:22:47 +0000315 AccessedEntity(MemberNonce _,
316 CXXRecordDecl *NamingClass,
317 AccessSpecifier Access,
318 NamedDecl *Target)
319 : Access(Access), IsMember(true),
320 Target(Target), NamingClass(NamingClass),
321 Diag(0) {
John McCall6b2accb2010-02-10 09:31:12 +0000322 }
323
John McCall9aa472c2010-03-19 07:35:19 +0000324 AccessedEntity(MemberNonce _,
325 CXXRecordDecl *NamingClass,
326 DeclAccessPair FoundDecl)
327 : Access(FoundDecl.getAccess()), IsMember(true),
328 Target(FoundDecl.getDecl()), NamingClass(NamingClass),
329 Diag(0) {
330 }
331
John McCall58e6f342010-03-16 05:22:47 +0000332 AccessedEntity(BaseNonce _,
333 CXXRecordDecl *BaseClass,
334 CXXRecordDecl *DerivedClass,
335 AccessSpecifier Access)
336 : Access(Access), IsMember(false),
337 Target(BaseClass), NamingClass(DerivedClass),
338 Diag(0) {
John McCall6b2accb2010-02-10 09:31:12 +0000339 }
340
John McCall58e6f342010-03-16 05:22:47 +0000341 bool isQuiet() const { return Diag.getDiagID() == 0; }
342
John McCall6b2accb2010-02-10 09:31:12 +0000343 AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
344
345 // These apply to member decls...
346 NamedDecl *getTargetDecl() const { return Target; }
347 CXXRecordDecl *getNamingClass() const { return NamingClass; }
348
349 // ...and these apply to hierarchy conversions.
350 CXXRecordDecl *getBaseClass() const { return cast<CXXRecordDecl>(Target); }
351 CXXRecordDecl *getDerivedClass() const { return NamingClass; }
352
John McCall58e6f342010-03-16 05:22:47 +0000353 /// Sets a diagnostic to be performed. The diagnostic is given
354 /// four (additional) arguments:
355 /// %0 - 0 if the entity was private, 1 if protected
356 /// %1 - the DeclarationName of the entity
357 /// %2 - the TypeDecl type of the naming class
358 /// %3 - the TypeDecl type of the declaring class
359 void setDiag(const PartialDiagnostic &PDiag) {
360 assert(isQuiet() && "partial diagnostic already defined");
361 Diag = PDiag;
362 }
363 PartialDiagnostic &setDiag(unsigned DiagID) {
364 assert(isQuiet() && "partial diagnostic already defined");
365 assert(DiagID && "creating null diagnostic");
366 Diag = PartialDiagnostic(DiagID);
367 return Diag;
368 }
369 const PartialDiagnostic &getDiag() const {
370 return Diag;
371 }
372
John McCall6b2accb2010-02-10 09:31:12 +0000373 private:
John McCall6b2accb2010-02-10 09:31:12 +0000374 unsigned Access : 2;
John McCall58e6f342010-03-16 05:22:47 +0000375 bool IsMember;
John McCall6b2accb2010-02-10 09:31:12 +0000376 NamedDecl *Target;
377 CXXRecordDecl *NamingClass;
John McCall58e6f342010-03-16 05:22:47 +0000378 PartialDiagnostic Diag;
John McCall6b2accb2010-02-10 09:31:12 +0000379 };
380
John McCall2f514482010-01-27 03:50:35 +0000381 struct DelayedDiagnostic {
382 enum DDKind { Deprecation, Access };
383
384 unsigned char Kind; // actually a DDKind
385 bool Triggered;
386
387 SourceLocation Loc;
388
389 union {
390 /// Deprecation.
391 struct { NamedDecl *Decl; } DeprecationData;
392
393 /// Access control.
John McCall58e6f342010-03-16 05:22:47 +0000394 char AccessData[sizeof(AccessedEntity)];
John McCall2f514482010-01-27 03:50:35 +0000395 };
396
John McCall58e6f342010-03-16 05:22:47 +0000397 void destroy() {
398 switch (Kind) {
399 case Access: getAccessData().~AccessedEntity(); break;
400 case Deprecation: break;
401 }
402 }
403
John McCall2f514482010-01-27 03:50:35 +0000404 static DelayedDiagnostic makeDeprecation(SourceLocation Loc,
405 NamedDecl *D) {
406 DelayedDiagnostic DD;
407 DD.Kind = Deprecation;
408 DD.Triggered = false;
409 DD.Loc = Loc;
410 DD.DeprecationData.Decl = D;
411 return DD;
412 }
413
414 static DelayedDiagnostic makeAccess(SourceLocation Loc,
John McCall6b2accb2010-02-10 09:31:12 +0000415 const AccessedEntity &Entity) {
John McCall2f514482010-01-27 03:50:35 +0000416 DelayedDiagnostic DD;
417 DD.Kind = Access;
418 DD.Triggered = false;
419 DD.Loc = Loc;
John McCall58e6f342010-03-16 05:22:47 +0000420 new (&DD.getAccessData()) AccessedEntity(Entity);
John McCall2f514482010-01-27 03:50:35 +0000421 return DD;
422 }
423
John McCall58e6f342010-03-16 05:22:47 +0000424 AccessedEntity &getAccessData() {
425 return *reinterpret_cast<AccessedEntity*>(AccessData);
426 }
427 const AccessedEntity &getAccessData() const {
428 return *reinterpret_cast<const AccessedEntity*>(AccessData);
429 }
John McCall2f514482010-01-27 03:50:35 +0000430 };
431
432 /// \brief The stack of diagnostics that were delayed due to being
433 /// produced during the parsing of a declaration.
434 llvm::SmallVector<DelayedDiagnostic, 8> DelayedDiagnostics;
John McCall54abf7d2009-11-04 02:18:39 +0000435
436 /// \brief The depth of the current ParsingDeclaration stack.
437 /// If nonzero, we are currently parsing a declaration (and
438 /// hence should delay deprecation warnings).
439 unsigned ParsingDeclDepth;
440
Ryan Flynne25ff832009-07-30 03:15:39 +0000441 /// WeakUndeclaredIdentifiers - Identifiers contained in
442 /// #pragma weak before declared. rare. may alias another
443 /// identifier, declared or undeclared
444 class WeakInfo {
445 IdentifierInfo *alias; // alias (optional)
446 SourceLocation loc; // for diagnostics
447 bool used; // identifier later declared?
448 public:
449 WeakInfo()
450 : alias(0), loc(SourceLocation()), used(false) {}
451 WeakInfo(IdentifierInfo *Alias, SourceLocation Loc)
452 : alias(Alias), loc(Loc), used(false) {}
453 inline IdentifierInfo * getAlias() const { return alias; }
454 inline SourceLocation getLocation() const { return loc; }
455 void setUsed(bool Used=true) { used = Used; }
456 inline bool getUsed() { return used; }
457 bool operator==(WeakInfo RHS) const {
458 return alias == RHS.getAlias() && loc == RHS.getLocation();
459 }
460 bool operator!=(WeakInfo RHS) const { return !(*this == RHS); }
461 };
462 llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
463
Ryan Flynn7b1fdbd2009-07-31 02:52:19 +0000464 /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
465 /// #pragma weak during processing of other Decls.
466 /// I couldn't figure out a clean way to generate these in-line, so
467 /// we store them here and handle separately -- which is a hack.
468 /// It would be best to refactor this.
469 llvm::SmallVector<Decl*,2> WeakTopLevelDecl;
470
Chris Lattner7f925cc2008-04-11 07:00:53 +0000471 IdentifierResolver IdResolver;
472
Steve Naroffe440eb82007-10-10 17:32:04 +0000473 /// Translation Unit Scope - useful to Objective-C actions that need
474 /// to lookup file scope declarations in the "ordinary" C decl namespace.
475 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroffb216c882007-10-09 22:01:59 +0000476 Scope *TUScope;
Sebastian Redlc42e1182008-11-11 11:37:55 +0000477
Douglas Gregor7adb10f2009-09-15 22:30:29 +0000478 /// \brief The C++ "std" namespace, where the standard library resides.
Sebastian Redlc42e1182008-11-11 11:37:55 +0000479 NamespaceDecl *StdNamespace;
Sebastian Redlb5a57a62008-12-03 20:26:15 +0000480
Douglas Gregor7adb10f2009-09-15 22:30:29 +0000481 /// \brief The C++ "std::bad_alloc" class, which is defined by the C++
482 /// standard library.
483 CXXRecordDecl *StdBadAlloc;
484
Sebastian Redlb5a57a62008-12-03 20:26:15 +0000485 /// A flag to remember whether the implicit forms of operator new and delete
486 /// have been declared.
487 bool GlobalNewDeleteDeclared;
Douglas Gregorf807fe02009-04-14 16:27:31 +0000488
Douglas Gregor2afce722009-11-26 00:44:06 +0000489 /// \brief The set of declarations that have been referenced within
490 /// a potentially evaluated expression.
491 typedef std::vector<std::pair<SourceLocation, Decl *> >
Douglas Gregorac7610d2009-06-22 20:57:11 +0000492 PotentiallyReferencedDecls;
Mike Stump1eb44332009-09-09 15:08:12 +0000493
Douglas Gregor06d33692009-12-12 07:57:52 +0000494 /// \brief A set of diagnostics that may be emitted.
495 typedef std::vector<std::pair<SourceLocation, PartialDiagnostic> >
496 PotentiallyEmittedDiagnostics;
497
Douglas Gregor2afce722009-11-26 00:44:06 +0000498 /// \brief Data structure used to record current or nested
499 /// expression evaluation contexts.
500 struct ExpressionEvaluationContextRecord {
501 /// \brief The expression evaluation context.
502 ExpressionEvaluationContext Context;
503
504 /// \brief The number of temporaries that were active when we
505 /// entered this expression evaluation context.
506 unsigned NumTemporaries;
507
508 /// \brief The set of declarations referenced within a
509 /// potentially potentially-evaluated context.
510 ///
511 /// When leaving a potentially potentially-evaluated context, each
512 /// of these elements will be as referenced if the corresponding
513 /// potentially potentially evaluated expression is potentially
514 /// evaluated.
515 PotentiallyReferencedDecls *PotentiallyReferenced;
516
Douglas Gregor06d33692009-12-12 07:57:52 +0000517 /// \brief The set of diagnostics to emit should this potentially
518 /// potentially-evaluated context become evaluated.
519 PotentiallyEmittedDiagnostics *PotentiallyDiagnosed;
520
Douglas Gregor2afce722009-11-26 00:44:06 +0000521 ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
522 unsigned NumTemporaries)
523 : Context(Context), NumTemporaries(NumTemporaries),
Douglas Gregor06d33692009-12-12 07:57:52 +0000524 PotentiallyReferenced(0), PotentiallyDiagnosed(0) { }
Douglas Gregor2afce722009-11-26 00:44:06 +0000525
526 void addReferencedDecl(SourceLocation Loc, Decl *Decl) {
527 if (!PotentiallyReferenced)
528 PotentiallyReferenced = new PotentiallyReferencedDecls;
529 PotentiallyReferenced->push_back(std::make_pair(Loc, Decl));
530 }
531
Douglas Gregor06d33692009-12-12 07:57:52 +0000532 void addDiagnostic(SourceLocation Loc, const PartialDiagnostic &PD) {
533 if (!PotentiallyDiagnosed)
534 PotentiallyDiagnosed = new PotentiallyEmittedDiagnostics;
535 PotentiallyDiagnosed->push_back(std::make_pair(Loc, PD));
536 }
537
Douglas Gregor2afce722009-11-26 00:44:06 +0000538 void Destroy() {
539 delete PotentiallyReferenced;
Douglas Gregor06d33692009-12-12 07:57:52 +0000540 delete PotentiallyDiagnosed;
Douglas Gregor2afce722009-11-26 00:44:06 +0000541 PotentiallyReferenced = 0;
Douglas Gregor06d33692009-12-12 07:57:52 +0000542 PotentiallyDiagnosed = 0;
Douglas Gregor2afce722009-11-26 00:44:06 +0000543 }
544 };
545
546 /// A stack of expression evaluation contexts.
547 llvm::SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
Mike Stump1eb44332009-09-09 15:08:12 +0000548
Douglas Gregorf807fe02009-04-14 16:27:31 +0000549 /// \brief Whether the code handled by Sema should be considered a
550 /// complete translation unit or not.
551 ///
552 /// When true (which is generally the case), Sema will perform
553 /// end-of-translation-unit semantic tasks (such as creating
554 /// initializers for tentative definitions in C) once parsing has
555 /// completed. This flag will be false when building PCH files,
556 /// since a PCH file is by definition not a complete translation
557 /// unit.
558 bool CompleteTranslationUnit;
559
Argyrios Kyrtzidis1bb8a452009-08-19 01:28:17 +0000560 llvm::BumpPtrAllocator BumpAlloc;
561
Douglas Gregorbb260412009-06-14 08:02:22 +0000562 /// \brief The number of SFINAE diagnostics that have been trapped.
563 unsigned NumSFINAEErrors;
564
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +0000565 typedef llvm::DenseMap<Selector, ObjCMethodList> MethodPool;
566
Steve Naroff58ff9e82007-10-14 00:58:41 +0000567 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
568 /// messages to "id". We need to maintain a list, since selectors can have
Mike Stump1eb44332009-09-09 15:08:12 +0000569 /// differing signatures across classes. In Cocoa, this happens to be
Steve Naroff58ff9e82007-10-14 00:58:41 +0000570 /// extremely uncommon (only 1% of selectors are "overloaded").
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +0000571 MethodPool InstanceMethodPool;
572 MethodPool FactoryMethodPool;
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +0000574 MethodPool::iterator ReadMethodPool(Selector Sel, bool isInstance);
575
Steve Naroff6b9dfd42009-03-04 15:11:40 +0000576 /// Private Helper predicate to check for 'self'.
577 bool isSelfExpr(Expr *RExpr);
Reid Spencer5f016e22007-07-11 17:01:13 +0000578public:
Douglas Gregorf807fe02009-04-14 16:27:31 +0000579 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
Daniel Dunbar3a2838d2009-11-13 08:58:20 +0000580 bool CompleteTranslationUnit = true,
581 CodeCompleteConsumer *CompletionConsumer = 0);
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000582 ~Sema();
Mike Stump1eb44332009-09-09 15:08:12 +0000583
Chris Lattner53ebff32009-01-22 19:21:44 +0000584 const LangOptions &getLangOptions() const { return LangOpts; }
Chris Lattner3cfa9282008-11-22 08:28:49 +0000585 Diagnostic &getDiagnostics() const { return Diags; }
586 SourceManager &getSourceManager() const { return SourceMgr; }
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000587 const TargetAttributesSema &getTargetAttributesSema() const;
Chris Lattner3cfa9282008-11-22 08:28:49 +0000588
Douglas Gregor25a88bb2009-03-20 22:48:49 +0000589 /// \brief Helper class that creates diagnostics with optional
590 /// template instantiation stacks.
591 ///
592 /// This class provides a wrapper around the basic DiagnosticBuilder
593 /// class that emits diagnostics. SemaDiagnosticBuilder is
594 /// responsible for emitting the diagnostic (as DiagnosticBuilder
595 /// does) and, if the diagnostic comes from inside a template
596 /// instantiation, printing the template instantiation stack as
597 /// well.
598 class SemaDiagnosticBuilder : public DiagnosticBuilder {
599 Sema &SemaRef;
600 unsigned DiagID;
601
602 public:
603 SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
604 : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
605
Mike Stump1eb44332009-09-09 15:08:12 +0000606 explicit SemaDiagnosticBuilder(Sema &SemaRef)
Douglas Gregor5e9f35c2009-06-14 07:33:30 +0000607 : DiagnosticBuilder(DiagnosticBuilder::Suppress), SemaRef(SemaRef) { }
608
Douglas Gregor25a88bb2009-03-20 22:48:49 +0000609 ~SemaDiagnosticBuilder();
610 };
611
612 /// \brief Emit a diagnostic.
613 SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
Douglas Gregor5e9f35c2009-06-14 07:33:30 +0000614 if (isSFINAEContext() && Diagnostic::isBuiltinSFINAEDiag(DiagID)) {
615 // If we encountered an error during template argument
616 // deduction, and that error is one of the SFINAE errors,
Douglas Gregorbb260412009-06-14 08:02:22 +0000617 // suppress the diagnostic.
Douglas Gregor8439fac2009-06-15 16:52:15 +0000618 ++NumSFINAEErrors;
Douglas Gregor0b60d9e2009-09-25 23:53:26 +0000619 Diags.setLastDiagnosticIgnored();
Douglas Gregor8439fac2009-06-15 16:52:15 +0000620 return SemaDiagnosticBuilder(*this);
Douglas Gregor5e9f35c2009-06-14 07:33:30 +0000621 }
622
Douglas Gregoree1828a2009-03-10 18:03:33 +0000623 DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
Douglas Gregor25a88bb2009-03-20 22:48:49 +0000624 return SemaDiagnosticBuilder(DB, *this, DiagID);
Chris Lattner3cfa9282008-11-22 08:28:49 +0000625 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000626
Anders Carlsson91a0cc92009-08-26 22:33:56 +0000627 /// \brief Emit a partial diagnostic.
628 SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD);
629
Chris Lattner394a3fd2007-08-31 04:53:24 +0000630 virtual void DeleteExpr(ExprTy *E);
631 virtual void DeleteStmt(StmtTy *S);
632
John McCall129e2df2009-11-30 22:42:35 +0000633 OwningExprResult Owned(Expr* E) {
634 assert(!E || E->isRetained());
635 return OwningExprResult(*this, E);
636 }
Sebastian Redl0eb23302009-01-19 00:08:26 +0000637 OwningExprResult Owned(ExprResult R) {
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000638 if (R.isInvalid())
Steve Naroff872b9ac2009-01-21 22:32:33 +0000639 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +0000640 assert(!R.get() || ((Expr*) R.get())->isRetained());
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000641 return OwningExprResult(*this, R.get());
Sebastian Redl0eb23302009-01-19 00:08:26 +0000642 }
John McCall129e2df2009-11-30 22:42:35 +0000643 OwningStmtResult Owned(Stmt* S) {
644 assert(!S || S->isRetained());
645 return OwningStmtResult(*this, S);
646 }
Sebastian Redl798d1192008-12-13 16:23:55 +0000647
Chris Lattner9299f3f2008-08-23 03:19:52 +0000648 virtual void ActOnEndOfTranslationUnit();
Sebastian Redlb8a6aca2009-01-19 22:31:54 +0000649
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000650 void PushFunctionScope();
651 void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
652 void PopFunctionOrBlockScope();
653
Chris Lattnerea29a3a2009-04-18 20:01:55 +0000654 /// getLabelMap() - Return the current label map. If we're in a block, we
655 /// return it.
656 llvm::DenseMap<IdentifierInfo*, LabelStmt*> &getLabelMap() {
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000657 if (FunctionScopes.empty())
658 return TopFunctionScope.LabelMap;
659
660 return FunctionScopes.back()->LabelMap;
Chris Lattnerea29a3a2009-04-18 20:01:55 +0000661 }
Mike Stump1eb44332009-09-09 15:08:12 +0000662
Chris Lattnerbcfce662009-04-18 20:10:59 +0000663 /// getSwitchStack - This is returns the switch stack for the current block or
664 /// function.
665 llvm::SmallVector<SwitchStmt*,8> &getSwitchStack() {
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000666 if (FunctionScopes.empty())
667 return TopFunctionScope.SwitchStack;
668
669 return FunctionScopes.back()->SwitchStack;
Chris Lattnerbcfce662009-04-18 20:10:59 +0000670 }
Ryan Flynn7b1fdbd2009-07-31 02:52:19 +0000671
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +0000672 /// \brief Determine whether the current function or block needs scope
673 /// checking.
674 bool &FunctionNeedsScopeChecking() {
675 if (FunctionScopes.empty())
676 return TopFunctionScope.NeedsScopeChecking;
677
678 return FunctionScopes.back()->NeedsScopeChecking;
679 }
680
681 bool hasAnyErrorsInThisFunction() const;
682
683 /// \brief Retrieve the current block, if any.
684 BlockScopeInfo *getCurBlock();
685
Ryan Flynn7b1fdbd2009-07-31 02:52:19 +0000686 /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls
687 llvm::SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
Mike Stump1eb44332009-09-09 15:08:12 +0000688
Douglas Gregor2e222532009-07-02 17:08:52 +0000689 virtual void ActOnComment(SourceRange Comment);
690
Reid Spencer5f016e22007-07-11 17:01:13 +0000691 //===--------------------------------------------------------------------===//
692 // Type Analysis / Processing: SemaType.cpp.
693 //
John McCall04a67a62010-02-05 21:31:56 +0000694
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000695 QualType adjustParameterType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000696 QualType BuildPointerType(QualType T, unsigned Quals,
Douglas Gregorcd281c32009-02-28 00:25:32 +0000697 SourceLocation Loc, DeclarationName Entity);
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000698 QualType BuildReferenceType(QualType T, bool LValueRef, unsigned Quals,
Douglas Gregorcd281c32009-02-28 00:25:32 +0000699 SourceLocation Loc, DeclarationName Entity);
700 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
701 Expr *ArraySize, unsigned Quals,
Douglas Gregor7e7eb3d2009-07-06 15:59:29 +0000702 SourceRange Brackets, DeclarationName Entity);
Mike Stump1eb44332009-09-09 15:08:12 +0000703 QualType BuildExtVectorType(QualType T, ExprArg ArraySize,
Douglas Gregor9cdda0c2009-06-17 21:51:59 +0000704 SourceLocation AttrLoc);
Douglas Gregor724651c2009-02-28 01:04:19 +0000705 QualType BuildFunctionType(QualType T,
706 QualType *ParamTypes, unsigned NumParamTypes,
707 bool Variadic, unsigned Quals,
708 SourceLocation Loc, DeclarationName Entity);
Mike Stump1eb44332009-09-09 15:08:12 +0000709 QualType BuildMemberPointerType(QualType T, QualType Class,
710 unsigned Quals, SourceLocation Loc,
Douglas Gregor949bf692009-06-09 22:17:39 +0000711 DeclarationName Entity);
Anders Carlsson9a917e42009-06-12 22:56:54 +0000712 QualType BuildBlockPointerType(QualType T, unsigned Quals,
713 SourceLocation Loc, DeclarationName Entity);
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000714 QualType GetTypeForDeclarator(Declarator &D, Scope *S,
John McCalla93c9342009-12-07 02:54:59 +0000715 TypeSourceInfo **TInfo = 0,
Sebastian Redl8ce35b02009-10-25 21:45:37 +0000716 TagDecl **OwnedDecl = 0);
John McCalla93c9342009-12-07 02:54:59 +0000717 TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T);
718 /// \brief Create a LocInfoType to hold the given QualType and TypeSourceInfo.
719 QualType CreateLocInfoType(QualType T, TypeSourceInfo *TInfo);
Douglas Gregor10bd3682008-11-17 22:58:34 +0000720 DeclarationName GetNameForDeclarator(Declarator &D);
John McCall129e2df2009-11-30 22:42:35 +0000721 DeclarationName GetNameFromUnqualifiedId(const UnqualifiedId &Name);
John McCalla93c9342009-12-07 02:54:59 +0000722 static QualType GetTypeFromParser(TypeTy *Ty, TypeSourceInfo **TInfo = 0);
Sebastian Redlef65f062009-05-29 18:02:33 +0000723 bool CheckSpecifiedExceptionType(QualType T, const SourceRange &Range);
Sebastian Redl6a7330c2009-05-29 15:01:05 +0000724 bool CheckDistantExceptionSpec(QualType T);
Douglas Gregore13ad832010-02-12 07:32:17 +0000725 bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New);
Sebastian Redl4994d2d2009-07-04 11:39:00 +0000726 bool CheckEquivalentExceptionSpec(
727 const FunctionProtoType *Old, SourceLocation OldLoc,
728 const FunctionProtoType *New, SourceLocation NewLoc);
Sebastian Redl37c38ec2009-10-14 16:09:29 +0000729 bool CheckEquivalentExceptionSpec(
730 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
Sebastian Redldced2262009-10-11 09:03:14 +0000731 const FunctionProtoType *Old, SourceLocation OldLoc,
Douglas Gregore13ad832010-02-12 07:32:17 +0000732 const FunctionProtoType *New, SourceLocation NewLoc,
733 bool *MissingEmptyExceptionSpecification = 0);
Sebastian Redl37c38ec2009-10-14 16:09:29 +0000734 bool CheckExceptionSpecSubset(
735 const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
Sebastian Redl23c7d062009-07-07 20:29:57 +0000736 const FunctionProtoType *Superset, SourceLocation SuperLoc,
737 const FunctionProtoType *Subset, SourceLocation SubLoc);
Sebastian Redl37c38ec2009-10-14 16:09:29 +0000738 bool CheckParamExceptionSpec(const PartialDiagnostic & NoteID,
Sebastian Redldced2262009-10-11 09:03:14 +0000739 const FunctionProtoType *Target, SourceLocation TargetLoc,
740 const FunctionProtoType *Source, SourceLocation SourceLoc);
Douglas Gregor10bd3682008-11-17 22:58:34 +0000741
Douglas Gregor57373262008-10-22 14:17:15 +0000742 bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
743
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000744 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Sebastian Redl37d6de32008-11-08 13:00:26 +0000745
Anders Carlsson91a0cc92009-08-26 22:33:56 +0000746 bool RequireCompleteType(SourceLocation Loc, QualType T,
Anders Carlsson8c8d9192009-10-09 23:51:55 +0000747 const PartialDiagnostic &PD,
748 std::pair<SourceLocation,
749 PartialDiagnostic> Note =
750 std::make_pair(SourceLocation(), PDiag()));
Mike Stump1eb44332009-09-09 15:08:12 +0000751
Douglas Gregore6258932009-03-19 00:39:20 +0000752 QualType getQualifiedNameType(const CXXScopeSpec &SS, QualType T);
753
Anders Carlssonaf017e62009-06-29 22:58:55 +0000754 QualType BuildTypeofExprType(Expr *E);
755 QualType BuildDecltypeType(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000756
Reid Spencer5f016e22007-07-11 17:01:13 +0000757 //===--------------------------------------------------------------------===//
758 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
759 //
Chris Lattner21ff9c92009-03-05 01:25:28 +0000760
761 /// getDeclName - Return a pretty name for the specified decl if possible, or
Mike Stump1eb44332009-09-09 15:08:12 +0000762 /// an empty string if not. This is used for pretty crash reporting.
Chris Lattnerb28317a2009-03-28 19:18:32 +0000763 virtual std::string getDeclName(DeclPtrTy D);
Mike Stump1eb44332009-09-09 15:08:12 +0000764
Chris Lattner682bf922009-03-29 16:50:03 +0000765 DeclGroupPtrTy ConvertDeclToDeclGroup(DeclPtrTy Ptr);
766
Mike Stump1eb44332009-09-09 15:08:12 +0000767 virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Douglas Gregor42c39f32009-08-26 18:27:52 +0000768 Scope *S, const CXXScopeSpec *SS,
Douglas Gregorf6e6fc82009-11-20 22:03:38 +0000769 bool isClassName = false,
770 TypeTy *ObjectType = 0);
Chris Lattner4c97d762009-04-12 21:49:30 +0000771 virtual DeclSpec::TST isTagName(IdentifierInfo &II, Scope *S);
Douglas Gregora786fdb2009-10-13 23:27:22 +0000772 virtual bool DiagnoseUnknownTypeName(const IdentifierInfo &II,
773 SourceLocation IILoc,
774 Scope *S,
775 const CXXScopeSpec *SS,
776 TypeTy *&SuggestedType);
777
Chris Lattner682bf922009-03-29 16:50:03 +0000778 virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D) {
Douglas Gregore542c862009-06-23 23:11:28 +0000779 return HandleDeclarator(S, D, MultiTemplateParamsArg(*this), false);
Douglas Gregor584049d2008-12-15 23:53:10 +0000780 }
Mike Stump1eb44332009-09-09 15:08:12 +0000781
782 DeclPtrTy HandleDeclarator(Scope *S, Declarator &D,
Douglas Gregore542c862009-06-23 23:11:28 +0000783 MultiTemplateParamsArg TemplateParameterLists,
784 bool IsFunctionDefinition);
John McCall68263142009-11-18 22:49:29 +0000785 void RegisterLocallyScopedExternCDecl(NamedDecl *ND,
786 const LookupResult &Previous,
Douglas Gregor63935192009-03-02 00:19:53 +0000787 Scope *S);
Eli Friedman85a53192009-04-07 19:37:57 +0000788 void DiagnoseFunctionSpecifiers(Declarator& D);
John McCall8472af42010-03-16 21:48:18 +0000789 void DiagnoseShadow(NamedDecl* D, const LookupResult& R);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000790 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
John McCalla93c9342009-12-07 02:54:59 +0000791 QualType R, TypeSourceInfo *TInfo,
John McCall68263142009-11-18 22:49:29 +0000792 LookupResult &Previous, bool &Redeclaration);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000793 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
John McCalla93c9342009-12-07 02:54:59 +0000794 QualType R, TypeSourceInfo *TInfo,
John McCall68263142009-11-18 22:49:29 +0000795 LookupResult &Previous,
Douglas Gregordfe3f2d2009-07-22 17:18:37 +0000796 MultiTemplateParamsArg TemplateParamLists,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000797 bool &Redeclaration);
John McCall68263142009-11-18 22:49:29 +0000798 void CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous,
Douglas Gregor3d7a12a2009-03-25 23:32:15 +0000799 bool &Redeclaration);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000800 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
John McCalla93c9342009-12-07 02:54:59 +0000801 QualType R, TypeSourceInfo *TInfo,
John McCall68263142009-11-18 22:49:29 +0000802 LookupResult &Previous,
Douglas Gregore542c862009-06-23 23:11:28 +0000803 MultiTemplateParamsArg TemplateParamLists,
Douglas Gregor04495c82009-02-24 01:23:02 +0000804 bool IsFunctionDefinition,
Chris Lattnereaaebc72009-04-25 08:06:05 +0000805 bool &Redeclaration);
Sebastian Redla165da02009-11-18 21:51:29 +0000806 void AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD);
John McCall9f54ad42009-12-10 09:41:52 +0000807 void CheckFunctionDeclaration(Scope *S,
808 FunctionDecl *NewFD, LookupResult &Previous,
Douglas Gregorfd056bc2009-10-13 16:30:37 +0000809 bool IsExplicitSpecialization,
Mike Stump1eb44332009-09-09 15:08:12 +0000810 bool &Redeclaration,
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000811 bool &OverloadableAttrRequired);
John McCall8c4859a2009-07-24 03:03:21 +0000812 void CheckMain(FunctionDecl *FD);
Chris Lattnerb28317a2009-03-28 19:18:32 +0000813 virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D);
Fariborz Jahanian2f764f12010-02-03 00:01:43 +0000814 virtual void ActOnObjCCatchParam(DeclPtrTy D);
Chris Lattnerb28317a2009-03-28 19:18:32 +0000815 virtual void ActOnParamDefaultArgument(DeclPtrTy param,
Chris Lattner04421082008-04-08 04:40:51 +0000816 SourceLocation EqualLoc,
Sebastian Redlf53597f2009-03-15 17:47:39 +0000817 ExprArg defarg);
Mike Stump1eb44332009-09-09 15:08:12 +0000818 virtual void ActOnParamUnparsedDefaultArgument(DeclPtrTy param,
Anders Carlsson5e300d12009-06-12 16:51:40 +0000819 SourceLocation EqualLoc,
820 SourceLocation ArgLoc);
Chris Lattnerb28317a2009-03-28 19:18:32 +0000821 virtual void ActOnParamDefaultArgumentError(DeclPtrTy param);
Anders Carlssoned961f92009-08-25 02:29:20 +0000822 bool SetParamDefaultArgument(ParmVarDecl *Param, ExprArg DefaultArg,
823 SourceLocation EqualLoc);
824
Mike Stump1eb44332009-09-09 15:08:12 +0000825
Anders Carlsson5e300d12009-06-12 16:51:40 +0000826 // Contains the locations of the beginning of unparsed default
827 // argument locations.
828 llvm::DenseMap<ParmVarDecl *,SourceLocation> UnparsedDefaultArgLocs;
829
Anders Carlsson9abf2ae2009-08-16 05:13:48 +0000830 virtual void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init);
Chris Lattnerb28317a2009-03-28 19:18:32 +0000831 void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit);
Anders Carlsson6a75cd92009-07-11 00:34:39 +0000832 void ActOnUninitializedDecl(DeclPtrTy dcl, bool TypeContainsUndeducedAuto);
Chris Lattnerb28317a2009-03-28 19:18:32 +0000833 virtual void SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc);
Eli Friedmanc1dc6532009-05-29 01:49:24 +0000834 virtual DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
835 DeclPtrTy *Group,
Chris Lattner682bf922009-03-29 16:50:03 +0000836 unsigned NumDecls);
Douglas Gregora3a83512009-04-01 23:51:29 +0000837 virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
838 SourceLocation LocAfterDecls);
Chris Lattnerb28317a2009-03-28 19:18:32 +0000839 virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *S, Declarator &D);
840 virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *S, DeclPtrTy D);
841 virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclPtrTy D);
Sebastian Redlb8a6aca2009-01-19 22:31:54 +0000842
Chris Lattnerb28317a2009-03-28 19:18:32 +0000843 virtual DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body);
Douglas Gregore2c31ff2009-05-15 17:59:04 +0000844 DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body,
845 bool IsInstantiation);
Mike Stump1eb44332009-09-09 15:08:12 +0000846
Douglas Gregore0762c92009-06-19 23:52:42 +0000847 /// \brief Diagnose any unused parameters in the given sequence of
848 /// ParmVarDecl pointers.
849 template<typename InputIterator>
850 void DiagnoseUnusedParameters(InputIterator Param, InputIterator ParamEnd) {
851 for (; Param != ParamEnd; ++Param) {
Mike Stump1eb44332009-09-09 15:08:12 +0000852 if (!(*Param)->isUsed() && (*Param)->getDeclName() &&
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000853 !(*Param)->template hasAttr<UnusedAttr>())
Douglas Gregore0762c92009-06-19 23:52:42 +0000854 Diag((*Param)->getLocation(), diag::warn_unused_parameter)
855 << (*Param)->getDeclName();
856 }
857 }
Mike Stump1eb44332009-09-09 15:08:12 +0000858
Chris Lattner5af280c2009-04-19 04:46:21 +0000859 void DiagnoseInvalidJumps(Stmt *Body);
Chris Lattnerb28317a2009-03-28 19:18:32 +0000860 virtual DeclPtrTy ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000861
Steve Naroffb216c882007-10-09 22:01:59 +0000862 /// Scope actions.
863 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
864 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000865
866 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
867 /// no declarator (e.g. "struct foo;") is parsed.
Chris Lattnerb28317a2009-03-28 19:18:32 +0000868 virtual DeclPtrTy ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Mike Stump1eb44332009-09-09 15:08:12 +0000869
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000870 bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
871 RecordDecl *AnonRecord);
Mike Stump1eb44332009-09-09 15:08:12 +0000872 virtual DeclPtrTy BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
Chris Lattnerb28317a2009-03-28 19:18:32 +0000873 RecordDecl *Record);
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000874
Mike Stump1eb44332009-09-09 15:08:12 +0000875 bool isAcceptableTagRedeclaration(const TagDecl *Previous,
Douglas Gregor501c5ce2009-05-14 16:41:31 +0000876 TagDecl::TagKind NewTag,
877 SourceLocation NewTagLoc,
878 const IdentifierInfo &Name);
Douglas Gregored4ec8f2009-05-03 17:18:57 +0000879
John McCall0f434ec2009-07-31 02:45:11 +0000880 virtual DeclPtrTy ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
Chris Lattnerb28317a2009-03-28 19:18:32 +0000881 SourceLocation KWLoc, const CXXScopeSpec &SS,
882 IdentifierInfo *Name, SourceLocation NameLoc,
Douglas Gregor402abb52009-05-28 23:31:59 +0000883 AttributeList *Attr, AccessSpecifier AS,
Douglas Gregor7cdbc582009-07-22 23:48:44 +0000884 MultiTemplateParamsArg TemplateParameterLists,
John McCallc4e70192009-09-11 04:59:25 +0000885 bool &OwnedDecl, bool &IsDependent);
886
887 virtual TypeResult ActOnDependentTag(Scope *S,
888 unsigned TagSpec,
889 TagUseKind TUK,
890 const CXXScopeSpec &SS,
891 IdentifierInfo *Name,
892 SourceLocation TagLoc,
893 SourceLocation NameLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000894
Chris Lattnerb28317a2009-03-28 19:18:32 +0000895 virtual void ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart,
Chris Lattner06f54852008-08-23 02:00:52 +0000896 IdentifierInfo *ClassName,
Chris Lattnerb28317a2009-03-28 19:18:32 +0000897 llvm::SmallVectorImpl<DeclPtrTy> &Decls);
898 virtual DeclPtrTy ActOnField(Scope *S, DeclPtrTy TagD,
899 SourceLocation DeclStart,
900 Declarator &D, ExprTy *BitfieldWidth);
Chris Lattner24793662009-03-05 22:45:59 +0000901
902 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
Douglas Gregor4dd55f52009-03-11 20:50:30 +0000903 Declarator &D, Expr *BitfieldWidth,
904 AccessSpecifier AS);
Chris Lattner24793662009-03-05 22:45:59 +0000905
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +0000906 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000907 TypeSourceInfo *TInfo,
Douglas Gregor3cf538d2009-03-11 18:59:21 +0000908 RecordDecl *Record, SourceLocation Loc,
909 bool Mutable, Expr *BitfieldWidth,
Steve Naroffea218b82009-07-14 14:58:18 +0000910 SourceLocation TSSL,
Douglas Gregor4dd55f52009-03-11 20:50:30 +0000911 AccessSpecifier AS, NamedDecl *PrevDecl,
Douglas Gregor3cf538d2009-03-11 18:59:21 +0000912 Declarator *D = 0);
Douglas Gregor1f2023a2009-07-22 18:25:24 +0000913
914 enum CXXSpecialMember {
915 CXXDefaultConstructor = 0,
916 CXXCopyConstructor = 1,
917 CXXCopyAssignment = 2,
918 CXXDestructor = 3
919 };
920 void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem);
Mike Stump1eb44332009-09-09 15:08:12 +0000921
Chris Lattnerb28317a2009-03-28 19:18:32 +0000922 virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart,
Fariborz Jahanian496b5a82009-06-05 18:16:35 +0000923 DeclPtrTy IntfDecl,
Chris Lattnerb28317a2009-03-28 19:18:32 +0000924 Declarator &D, ExprTy *BitfieldWidth,
925 tok::ObjCKeywordKind visibility);
Fariborz Jahanian1d78cc42008-04-10 23:32:45 +0000926
Steve Narofff13271f2007-09-14 23:09:53 +0000927 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian9d048ff2007-09-29 00:54:24 +0000928 virtual void ActOnFields(Scope* S,
Chris Lattnerb28317a2009-03-28 19:18:32 +0000929 SourceLocation RecLoc, DeclPtrTy TagDecl,
930 DeclPtrTy *Fields, unsigned NumFields,
Daniel Dunbar1bfe1c22008-10-03 02:03:53 +0000931 SourceLocation LBrac, SourceLocation RBrac,
932 AttributeList *AttrList);
Douglas Gregor72de6672009-01-08 20:45:30 +0000933
934 /// ActOnTagStartDefinition - Invoked when we have entered the
935 /// scope of a tag's definition (e.g., for an enumeration, class,
936 /// struct, or union).
Chris Lattnerb28317a2009-03-28 19:18:32 +0000937 virtual void ActOnTagStartDefinition(Scope *S, DeclPtrTy TagDecl);
Douglas Gregor72de6672009-01-08 20:45:30 +0000938
John McCallf9368152009-12-20 07:58:13 +0000939 /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a
940 /// C++ record definition's base-specifiers clause and are starting its
941 /// member declarations.
942 virtual void ActOnStartCXXMemberDeclarations(Scope *S, DeclPtrTy TagDecl,
943 SourceLocation LBraceLoc);
944
Douglas Gregor72de6672009-01-08 20:45:30 +0000945 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
946 /// the definition of a tag (enumeration, class, struct, or union).
Argyrios Kyrtzidis07a5b282009-07-14 03:17:52 +0000947 virtual void ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagDecl,
948 SourceLocation RBraceLoc);
Douglas Gregor72de6672009-01-08 20:45:30 +0000949
John McCalldb7bb4a2010-03-17 00:38:33 +0000950 /// ActOnTagDefinitionError - Invoked when there was an unrecoverable
951 /// error parsing the definition of a tag.
952 virtual void ActOnTagDefinitionError(Scope *S, DeclPtrTy TagDecl);
953
Douglas Gregor879fd492009-03-17 19:05:46 +0000954 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
955 EnumConstantDecl *LastEnumConst,
956 SourceLocation IdLoc,
957 IdentifierInfo *Id,
958 ExprArg val);
959
Chris Lattnerb28317a2009-03-28 19:18:32 +0000960 virtual DeclPtrTy ActOnEnumConstant(Scope *S, DeclPtrTy EnumDecl,
961 DeclPtrTy LastEnumConstant,
962 SourceLocation IdLoc, IdentifierInfo *Id,
963 SourceLocation EqualLoc, ExprTy *Val);
Mike Stumpc6e35aa2009-05-16 07:06:02 +0000964 virtual void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
965 SourceLocation RBraceLoc, DeclPtrTy EnumDecl,
Edward O'Callaghanfee13812009-08-08 14:36:57 +0000966 DeclPtrTy *Elements, unsigned NumElements,
967 Scope *S, AttributeList *Attr);
Sebastian Redl37d6de32008-11-08 13:00:26 +0000968
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +0000969 DeclContext *getContainingDC(DeclContext *DC);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000970
Chris Lattner0ed844b2008-04-04 06:12:32 +0000971 /// Set the current declaration context until it gets popped.
Douglas Gregor44b43212008-12-11 16:49:14 +0000972 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattnerb048c982008-04-06 04:47:34 +0000973 void PopDeclContext();
Mike Stump1eb44332009-09-09 15:08:12 +0000974
Argyrios Kyrtzidis1d175532009-06-17 23:15:40 +0000975 /// EnterDeclaratorContext - Used when we must lookup names in the context
976 /// of a declarator's nested name specifier.
977 void EnterDeclaratorContext(Scope *S, DeclContext *DC);
978 void ExitDeclaratorContext(Scope *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000979
Anders Carlsson8517d9b2009-08-08 17:45:02 +0000980 DeclContext *getFunctionLevelDeclContext();
Mike Stump1eb44332009-09-09 15:08:12 +0000981
Chris Lattner371f2582008-12-04 23:50:19 +0000982 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
983 /// to the function decl for the function being parsed. If we're currently
984 /// in a 'block', this returns the containing context.
985 FunctionDecl *getCurFunctionDecl();
Mike Stump1eb44332009-09-09 15:08:12 +0000986
Chris Lattner371f2582008-12-04 23:50:19 +0000987 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
988 /// the method decl for the method being parsed. If we're currently
989 /// in a 'block', this returns the containing context.
Daniel Dunbarc4a1dea2008-08-11 05:35:13 +0000990 ObjCMethodDecl *getCurMethodDecl();
Chris Lattner0ed844b2008-04-04 06:12:32 +0000991
Chris Lattner371f2582008-12-04 23:50:19 +0000992 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
993 /// or C function we're in, otherwise return null. If we're currently
994 /// in a 'block', this returns the containing context.
995 NamedDecl *getCurFunctionOrMethodDecl();
996
Argyrios Kyrtzidis87f3ff02008-04-12 00:47:19 +0000997 /// Add this decl to the scope shadowed decl chains.
John McCallab88d972009-08-31 22:39:49 +0000998 void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true);
Argyrios Kyrtzidis87f3ff02008-04-12 00:47:19 +0000999
Argyrios Kyrtzidis15a12d02008-09-09 21:18:04 +00001000 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
1001 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
1002 /// true if 'D' belongs to the given declaration context.
Douglas Gregor2531c2d2009-09-28 00:47:05 +00001003 bool isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S = 0);
Argyrios Kyrtzidis15a12d02008-09-09 21:18:04 +00001004
John McCallab88d972009-08-31 22:39:49 +00001005 /// Finds the scope corresponding to the given decl context, if it
1006 /// happens to be an enclosing scope. Otherwise return NULL.
1007 Scope *getScopeForDeclContext(Scope *S, DeclContext *DC) {
John McCall1a26c272009-09-02 01:07:03 +00001008 DeclContext *TargetDC = DC->getPrimaryContext();
John McCallab88d972009-08-31 22:39:49 +00001009 do {
John McCall1a26c272009-09-02 01:07:03 +00001010 if (DeclContext *ScopeDC = (DeclContext*) S->getEntity())
1011 if (ScopeDC->getPrimaryContext() == TargetDC)
1012 return S;
John McCallab88d972009-08-31 22:39:49 +00001013 } while ((S = S->getParent()));
1014
1015 return NULL;
1016 }
1017
Chris Lattnerf1d705c2008-02-21 01:07:18 +00001018 /// Subroutines of ActOnDeclarator().
John McCallba6a9bd2009-10-24 08:00:42 +00001019 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
John McCalla93c9342009-12-07 02:54:59 +00001020 TypeSourceInfo *TInfo);
John McCall68263142009-11-18 22:49:29 +00001021 void MergeTypeDefDecl(TypedefDecl *New, LookupResult &OldDecls);
Douglas Gregorcda9c672009-02-16 17:45:42 +00001022 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
Douglas Gregor04495c82009-02-24 01:23:02 +00001023 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
John McCall68263142009-11-18 22:49:29 +00001024 void MergeVarDecl(VarDecl *New, LookupResult &OldDecls);
Douglas Gregorcda9c672009-02-16 17:45:42 +00001025 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001026
Douglas Gregor68647482009-12-16 03:45:30 +00001027 // AssignmentAction - This is used by all the assignment diagnostic functions
1028 // to represent what is actually causing the operation
1029 enum AssignmentAction {
1030 AA_Assigning,
1031 AA_Passing,
1032 AA_Returning,
1033 AA_Converting,
1034 AA_Initializing,
1035 AA_Sending,
1036 AA_Casting
1037 };
1038
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001039 /// C++ Overloading.
John McCall871b2e72009-12-09 03:35:25 +00001040 enum OverloadKind {
1041 /// This is a legitimate overload: the existing declarations are
1042 /// functions or function templates with different signatures.
1043 Ovl_Overload,
1044
1045 /// This is not an overload because the signature exactly matches
1046 /// an existing declaration.
1047 Ovl_Match,
1048
1049 /// This is not an overload because the lookup results contain a
1050 /// non-function.
1051 Ovl_NonFunction
1052 };
1053 OverloadKind CheckOverload(FunctionDecl *New,
John McCall9f54ad42009-12-10 09:41:52 +00001054 const LookupResult &OldDecls,
John McCall871b2e72009-12-09 03:35:25 +00001055 NamedDecl *&OldDecl);
John McCall68263142009-11-18 22:49:29 +00001056 bool IsOverload(FunctionDecl *New, FunctionDecl *Old);
1057
Mike Stump1eb44332009-09-09 15:08:12 +00001058 ImplicitConversionSequence
Anders Carlsson2974b5c2009-08-27 17:14:02 +00001059 TryImplicitConversion(Expr* From, QualType ToType,
Anders Carlssonda7a18b2009-08-27 17:24:15 +00001060 bool SuppressUserConversions,
1061 bool AllowExplicit,
Anders Carlsson08972922009-08-28 15:33:32 +00001062 bool ForceRValue,
Fariborz Jahanian249cead2009-10-01 20:39:51 +00001063 bool InOverloadResolution,
1064 bool UserCast = false);
Anders Carlsson08972922009-08-28 15:33:32 +00001065 bool IsStandardConversion(Expr *From, QualType ToType,
1066 bool InOverloadResolution,
Douglas Gregor60d62c22008-10-31 16:23:19 +00001067 StandardConversionSequence& SCS);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001068 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
1069 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
Douglas Gregor5cdf8212009-02-12 00:15:05 +00001070 bool IsComplexPromotion(QualType FromType, QualType ToType);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001071 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Anders Carlsson08972922009-08-28 15:33:32 +00001072 bool InOverloadResolution,
Douglas Gregor45920e82008-12-19 17:40:08 +00001073 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregorc7887512008-12-19 19:13:09 +00001074 bool isObjCPointerConversion(QualType FromType, QualType ToType,
1075 QualType& ConvertedType, bool &IncompatibleObjC);
Sebastian Redla82e4ae2009-11-14 21:15:49 +00001076 bool CheckPointerConversion(Expr *From, QualType ToType,
1077 CastExpr::CastKind &Kind,
1078 bool IgnoreBaseAccess);
Sebastian Redl4433aaf2009-01-25 19:43:20 +00001079 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregorce940492009-09-25 04:25:58 +00001080 bool InOverloadResolution,
Sebastian Redl4433aaf2009-01-25 19:43:20 +00001081 QualType &ConvertedType);
Anders Carlsson27a5b9b2009-08-22 23:33:40 +00001082 bool CheckMemberPointerConversion(Expr *From, QualType ToType,
Sebastian Redla82e4ae2009-11-14 21:15:49 +00001083 CastExpr::CastKind &Kind,
1084 bool IgnoreBaseAccess);
Douglas Gregor98cd5992008-10-21 23:43:52 +00001085 bool IsQualificationConversion(QualType FromType, QualType ToType);
Fariborz Jahanian34acd3e2009-09-15 19:12:21 +00001086 OverloadingResult IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00001087 UserDefinedConversionSequence& User,
Fariborz Jahanian78cf9a22009-09-15 00:10:11 +00001088 OverloadCandidateSet& Conversions,
Douglas Gregor734d9862009-01-30 23:27:23 +00001089 bool AllowConversionFunctions,
Fariborz Jahanian249cead2009-10-01 20:39:51 +00001090 bool AllowExplicit, bool ForceRValue,
1091 bool UserCast = false);
Fariborz Jahaniancc5306a2009-11-18 18:26:29 +00001092 bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
Fariborz Jahanian17c7a5d2009-09-22 20:24:30 +00001093
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001094
Mike Stump1eb44332009-09-09 15:08:12 +00001095 ImplicitConversionSequence::CompareKind
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001096 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
1097 const ImplicitConversionSequence& ICS2);
1098
Mike Stump1eb44332009-09-09 15:08:12 +00001099 ImplicitConversionSequence::CompareKind
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001100 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
1101 const StandardConversionSequence& SCS2);
1102
Mike Stump1eb44332009-09-09 15:08:12 +00001103 ImplicitConversionSequence::CompareKind
Douglas Gregor57373262008-10-22 14:17:15 +00001104 CompareQualificationConversions(const StandardConversionSequence& SCS1,
1105 const StandardConversionSequence& SCS2);
1106
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001107 ImplicitConversionSequence::CompareKind
1108 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
1109 const StandardConversionSequence& SCS2);
1110
Mike Stump1eb44332009-09-09 15:08:12 +00001111 ImplicitConversionSequence
Douglas Gregor225c41e2008-11-03 19:09:14 +00001112 TryCopyInitialization(Expr* From, QualType ToType,
Anders Carlsson7b361b52009-08-27 17:37:39 +00001113 bool SuppressUserConversions, bool ForceRValue,
1114 bool InOverloadResolution);
Douglas Gregor68647482009-12-16 03:45:30 +00001115
Mike Stump1eb44332009-09-09 15:08:12 +00001116 bool PerformCopyInitialization(Expr *&From, QualType ToType,
Douglas Gregor68647482009-12-16 03:45:30 +00001117 AssignmentAction Action, bool Elidable = false);
Douglas Gregor27c8dc02008-10-29 00:13:59 +00001118
Douglas Gregor18ef5e22009-12-18 05:02:21 +00001119 OwningExprResult PerformCopyInitialization(const InitializedEntity &Entity,
1120 SourceLocation EqualLoc,
1121 OwningExprResult Init);
Douglas Gregor96176b32008-11-18 23:14:02 +00001122 ImplicitConversionSequence
John McCall701c89e2009-12-03 04:06:58 +00001123 TryObjectArgumentInitialization(QualType FromType, CXXMethodDecl *Method,
1124 CXXRecordDecl *ActingContext);
Douglas Gregor5fccd362010-03-03 23:55:11 +00001125 bool PerformObjectArgumentInitialization(Expr *&From,
1126 NestedNameSpecifier *Qualifier,
1127 CXXMethodDecl *Method);
Douglas Gregor96176b32008-11-18 23:14:02 +00001128
Douglas Gregor09f41cf2009-01-14 15:45:31 +00001129 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
1130 bool PerformContextuallyConvertToBool(Expr *&From);
Mike Stump1eb44332009-09-09 15:08:12 +00001131
Douglas Gregor5fccd362010-03-03 23:55:11 +00001132 bool PerformObjectMemberConversion(Expr *&From,
1133 NestedNameSpecifier *Qualifier,
1134 NamedDecl *Member);
Douglas Gregor09f41cf2009-01-14 15:45:31 +00001135
John McCall6ff07852009-08-07 22:18:02 +00001136 // Members have to be NamespaceDecl* or TranslationUnitDecl*.
1137 // TODO: make this is a typesafe union.
1138 typedef llvm::SmallPtrSet<DeclContext *, 16> AssociatedNamespaceSet;
Douglas Gregor063daf62009-03-13 18:40:31 +00001139 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
1140
John McCall6e266892010-01-26 03:27:55 +00001141 void AddOverloadCandidate(NamedDecl *Function,
John McCall9aa472c2010-03-19 07:35:19 +00001142 DeclAccessPair FoundDecl,
John McCall6e266892010-01-26 03:27:55 +00001143 Expr **Args, unsigned NumArgs,
1144 OverloadCandidateSet &CandidateSet);
1145
Mike Stump1eb44332009-09-09 15:08:12 +00001146 void AddOverloadCandidate(FunctionDecl *Function,
John McCall9aa472c2010-03-19 07:35:19 +00001147 DeclAccessPair FoundDecl,
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001148 Expr **Args, unsigned NumArgs,
Douglas Gregor225c41e2008-11-03 19:09:14 +00001149 OverloadCandidateSet& CandidateSet,
Sebastian Redle2b68332009-04-12 17:16:29 +00001150 bool SuppressUserConversions = false,
Douglas Gregor9c6a0e92009-09-22 15:41:20 +00001151 bool ForceRValue = false,
1152 bool PartialOverloading = false);
John McCall6e266892010-01-26 03:27:55 +00001153 void AddFunctionCandidates(const UnresolvedSetImpl &Functions,
Douglas Gregor063daf62009-03-13 18:40:31 +00001154 Expr **Args, unsigned NumArgs,
1155 OverloadCandidateSet& CandidateSet,
1156 bool SuppressUserConversions = false);
John McCall9aa472c2010-03-19 07:35:19 +00001157 void AddMethodCandidate(DeclAccessPair FoundDecl,
John McCall86820f52010-01-26 01:37:31 +00001158 QualType ObjectType,
1159 Expr **Args, unsigned NumArgs,
John McCall314be4e2009-11-17 07:50:12 +00001160 OverloadCandidateSet& CandidateSet,
1161 bool SuppressUserConversion = false,
1162 bool ForceRValue = false);
John McCall9aa472c2010-03-19 07:35:19 +00001163 void AddMethodCandidate(CXXMethodDecl *Method,
1164 DeclAccessPair FoundDecl,
John McCall86820f52010-01-26 01:37:31 +00001165 CXXRecordDecl *ActingContext, QualType ObjectType,
1166 Expr **Args, unsigned NumArgs,
Douglas Gregor96176b32008-11-18 23:14:02 +00001167 OverloadCandidateSet& CandidateSet,
Sebastian Redle2b68332009-04-12 17:16:29 +00001168 bool SuppressUserConversions = false,
1169 bool ForceRValue = false);
Douglas Gregor6b906862009-08-21 00:16:32 +00001170 void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
John McCall9aa472c2010-03-19 07:35:19 +00001171 DeclAccessPair FoundDecl,
John McCall701c89e2009-12-03 04:06:58 +00001172 CXXRecordDecl *ActingContext,
John McCalld5532b62009-11-23 01:53:49 +00001173 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall701c89e2009-12-03 04:06:58 +00001174 QualType ObjectType,
1175 Expr **Args, unsigned NumArgs,
Douglas Gregor6b906862009-08-21 00:16:32 +00001176 OverloadCandidateSet& CandidateSet,
1177 bool SuppressUserConversions = false,
1178 bool ForceRValue = false);
Douglas Gregore53060f2009-06-25 22:08:12 +00001179 void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
John McCall9aa472c2010-03-19 07:35:19 +00001180 DeclAccessPair FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001181 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregore53060f2009-06-25 22:08:12 +00001182 Expr **Args, unsigned NumArgs,
1183 OverloadCandidateSet& CandidateSet,
1184 bool SuppressUserConversions = false,
1185 bool ForceRValue = false);
Douglas Gregorf1991ea2008-11-07 22:36:19 +00001186 void AddConversionCandidate(CXXConversionDecl *Conversion,
John McCall9aa472c2010-03-19 07:35:19 +00001187 DeclAccessPair FoundDecl,
John McCall701c89e2009-12-03 04:06:58 +00001188 CXXRecordDecl *ActingContext,
Douglas Gregorf1991ea2008-11-07 22:36:19 +00001189 Expr *From, QualType ToType,
1190 OverloadCandidateSet& CandidateSet);
Douglas Gregor65ec1fd2009-08-21 23:19:43 +00001191 void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
John McCall9aa472c2010-03-19 07:35:19 +00001192 DeclAccessPair FoundDecl,
John McCall701c89e2009-12-03 04:06:58 +00001193 CXXRecordDecl *ActingContext,
Douglas Gregor65ec1fd2009-08-21 23:19:43 +00001194 Expr *From, QualType ToType,
1195 OverloadCandidateSet &CandidateSet);
Douglas Gregor106c6eb2008-11-19 22:57:39 +00001196 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
John McCall9aa472c2010-03-19 07:35:19 +00001197 DeclAccessPair FoundDecl,
John McCall701c89e2009-12-03 04:06:58 +00001198 CXXRecordDecl *ActingContext,
Douglas Gregor72564e72009-02-26 23:50:07 +00001199 const FunctionProtoType *Proto,
John McCall701c89e2009-12-03 04:06:58 +00001200 QualType ObjectTy, Expr **Args, unsigned NumArgs,
Douglas Gregor106c6eb2008-11-19 22:57:39 +00001201 OverloadCandidateSet& CandidateSet);
Douglas Gregor063daf62009-03-13 18:40:31 +00001202 void AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
Douglas Gregorf680a0f2009-02-04 16:44:47 +00001203 SourceLocation OpLoc,
Douglas Gregor96176b32008-11-18 23:14:02 +00001204 Expr **Args, unsigned NumArgs,
Douglas Gregorf680a0f2009-02-04 16:44:47 +00001205 OverloadCandidateSet& CandidateSet,
1206 SourceRange OpRange = SourceRange());
Douglas Gregor063daf62009-03-13 18:40:31 +00001207 void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
1208 SourceLocation OpLoc,
1209 Expr **Args, unsigned NumArgs,
1210 OverloadCandidateSet& CandidateSet,
1211 SourceRange OpRange = SourceRange());
Mike Stump1eb44332009-09-09 15:08:12 +00001212 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
Douglas Gregoreb8f3062008-11-12 17:17:38 +00001213 Expr **Args, unsigned NumArgs,
Douglas Gregor88b4bf22009-01-13 00:52:54 +00001214 OverloadCandidateSet& CandidateSet,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00001215 bool IsAssignmentOperator = false,
1216 unsigned NumContextualBoolArguments = 0);
Mike Stump1eb44332009-09-09 15:08:12 +00001217 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
Douglas Gregor573d9c32009-10-21 23:19:44 +00001218 SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001219 Expr **Args, unsigned NumArgs,
Douglas Gregor74253732008-11-19 15:42:04 +00001220 OverloadCandidateSet& CandidateSet);
Douglas Gregorfa047642009-02-04 00:32:51 +00001221 void AddArgumentDependentLookupCandidates(DeclarationName Name,
John McCall6e266892010-01-26 03:27:55 +00001222 bool Operator,
Douglas Gregorfa047642009-02-04 00:32:51 +00001223 Expr **Args, unsigned NumArgs,
John McCalld5532b62009-11-23 01:53:49 +00001224 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor9c6a0e92009-09-22 15:41:20 +00001225 OverloadCandidateSet& CandidateSet,
1226 bool PartialOverloading = false);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001227 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
John McCall5769d612010-02-08 23:07:23 +00001228 const OverloadCandidate& Cand2,
1229 SourceLocation Loc);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001230 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
Douglas Gregore0762c92009-06-19 23:52:42 +00001231 SourceLocation Loc,
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001232 OverloadCandidateSet::iterator& Best);
John McCall81201622010-01-08 04:41:39 +00001233
1234 enum OverloadCandidateDisplayKind {
1235 /// Requests that all candidates be shown. Viable candidates will
1236 /// be printed first.
1237 OCD_AllCandidates,
1238
1239 /// Requests that only viable candidates be shown.
1240 OCD_ViableCandidates
1241 };
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001242 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
John McCall81201622010-01-08 04:41:39 +00001243 OverloadCandidateDisplayKind OCD,
John McCallcbce6062010-01-12 07:18:19 +00001244 Expr **Args, unsigned NumArgs,
John McCall81201622010-01-08 04:41:39 +00001245 const char *Opc = 0,
1246 SourceLocation Loc = SourceLocation());
1247
John McCallb1622a12010-01-06 09:43:14 +00001248 void NoteOverloadCandidate(FunctionDecl *Fn);
John McCall1d318332010-01-12 00:44:57 +00001249 void DiagnoseAmbiguousConversion(const ImplicitConversionSequence &ICS,
1250 SourceLocation CaretLoc,
1251 const PartialDiagnostic &PDiag);
Mike Stump1eb44332009-09-09 15:08:12 +00001252
Douglas Gregor904eed32008-11-10 20:40:00 +00001253 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
1254 bool Complain);
Douglas Gregor4b52e252009-12-21 23:17:24 +00001255 FunctionDecl *ResolveSingleFunctionTemplateSpecialization(Expr *From);
1256
Anders Carlsson96ad5332009-10-21 17:16:23 +00001257 Expr *FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
Douglas Gregor20093b42009-12-09 23:02:17 +00001258 OwningExprResult FixOverloadedFunctionReference(OwningExprResult,
1259 FunctionDecl *Fn);
Douglas Gregor904eed32008-11-10 20:40:00 +00001260
John McCall3b4294e2009-12-16 12:17:52 +00001261 void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE,
Douglas Gregor9c6a0e92009-09-22 15:41:20 +00001262 Expr **Args, unsigned NumArgs,
1263 OverloadCandidateSet &CandidateSet,
1264 bool PartialOverloading = false);
1265
John McCall3b4294e2009-12-16 12:17:52 +00001266 OwningExprResult BuildOverloadedCallExpr(Expr *Fn,
Nuno Lopes9a84ac22009-12-16 14:20:08 +00001267 UnresolvedLookupExpr *ULE,
John McCall3b4294e2009-12-16 12:17:52 +00001268 SourceLocation LParenLoc,
1269 Expr **Args, unsigned NumArgs,
1270 SourceLocation *CommaLocs,
1271 SourceLocation RParenLoc);
Douglas Gregor063daf62009-03-13 18:40:31 +00001272
Douglas Gregorbc736fc2009-03-13 23:49:33 +00001273 OwningExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
1274 unsigned Opc,
John McCall6e266892010-01-26 03:27:55 +00001275 const UnresolvedSetImpl &Fns,
Douglas Gregorbc736fc2009-03-13 23:49:33 +00001276 ExprArg input);
1277
Douglas Gregor063daf62009-03-13 18:40:31 +00001278 OwningExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
1279 unsigned Opc,
John McCall6e266892010-01-26 03:27:55 +00001280 const UnresolvedSetImpl &Fns,
Douglas Gregor063daf62009-03-13 18:40:31 +00001281 Expr *LHS, Expr *RHS);
1282
Sebastian Redlf322ed62009-10-29 20:17:01 +00001283 OwningExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
1284 SourceLocation RLoc,
1285 ExprArg Base,ExprArg Idx);
1286
John McCallaa81e162009-12-01 22:10:20 +00001287 OwningExprResult
Douglas Gregor88a35142008-12-22 05:46:06 +00001288 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
Mike Stump1eb44332009-09-09 15:08:12 +00001289 SourceLocation LParenLoc, Expr **Args,
Douglas Gregor88a35142008-12-22 05:46:06 +00001290 unsigned NumArgs, SourceLocation *CommaLocs,
1291 SourceLocation RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001292 ExprResult
Douglas Gregor5c37de72008-12-06 00:22:45 +00001293 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregorf9eb9052008-11-19 21:05:33 +00001294 Expr **Args, unsigned NumArgs,
Mike Stump1eb44332009-09-09 15:08:12 +00001295 SourceLocation *CommaLocs,
Douglas Gregorf9eb9052008-11-19 21:05:33 +00001296 SourceLocation RParenLoc);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +00001297
Douglas Gregorfe85ced2009-08-06 03:17:00 +00001298 OwningExprResult BuildOverloadedArrowExpr(Scope *S, ExprArg Base,
1299 SourceLocation OpLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001300
Mike Stumpfa6ef182010-01-13 02:59:54 +00001301 /// CheckUnreachable - Check for unreachable code.
1302 void CheckUnreachable(AnalysisContext &);
1303
Anders Carlsson8c8d9192009-10-09 23:51:55 +00001304 /// CheckCallReturnType - Checks that a call expression's return type is
1305 /// complete. Returns true on failure. The location passed in is the location
1306 /// that best represents the call.
1307 bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
1308 CallExpr *CE, FunctionDecl *FD);
1309
Mike Stump56925862009-07-28 22:04:01 +00001310 /// Helpers for dealing with blocks and functions.
Mike Stumpfa6ef182010-01-13 02:59:54 +00001311 void CheckFallThroughForFunctionDef(Decl *D, Stmt *Body, AnalysisContext &);
1312 void CheckFallThroughForBlock(QualType BlockTy, Stmt *, AnalysisContext &);
Chris Lattner04421082008-04-08 04:40:51 +00001313 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattner04421082008-04-08 04:40:51 +00001314 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregor6d6eb572008-05-07 04:49:29 +00001315 void CheckExtraCXXDefaultArguments(Declarator &D);
Mike Stumpb1682c52009-07-22 23:56:57 +00001316 enum ControlFlowKind { NeverFallThrough = 0, MaybeFallThrough = 1,
Mike Stump1d7e7672009-10-27 01:59:05 +00001317 AlwaysFallThrough = 2, NeverFallThroughOrReturn = 3 };
Mike Stumpfa6ef182010-01-13 02:59:54 +00001318 ControlFlowKind CheckFallThrough(AnalysisContext &);
Reid Spencer5f016e22007-07-11 17:01:13 +00001319
Douglas Gregor1a0d31a2009-01-12 18:45:55 +00001320 Scope *getNonFieldDeclScope(Scope *S);
1321
Douglas Gregoreb11cd02009-01-14 22:20:51 +00001322 /// \name Name lookup
1323 ///
1324 /// These routines provide name lookup that is used during semantic
1325 /// analysis to resolve the various kinds of names (identifiers,
1326 /// overloaded operator names, constructor names, etc.) into zero or
1327 /// more declarations within a particular scope. The major entry
1328 /// points are LookupName, which performs unqualified name lookup,
Mike Stump1eb44332009-09-09 15:08:12 +00001329 /// and LookupQualifiedName, which performs qualified name lookup.
Douglas Gregoreb11cd02009-01-14 22:20:51 +00001330 ///
1331 /// All name lookup is performed based on some specific criteria,
1332 /// which specify what names will be visible to name lookup and how
1333 /// far name lookup should work. These criteria are important both
1334 /// for capturing language semantics (certain lookups will ignore
1335 /// certain names, for example) and for performance, since name
1336 /// lookup is often a bottleneck in the compilation of C++. Name
Douglas Gregor4c921ae2009-01-30 01:04:22 +00001337 /// lookup criteria is specified via the LookupCriteria enumeration.
Douglas Gregoreb11cd02009-01-14 22:20:51 +00001338 ///
1339 /// The results of name lookup can vary based on the kind of name
1340 /// lookup performed, the current language, and the translation
1341 /// unit. In C, for example, name lookup will either return nothing
1342 /// (no entity found) or a single declaration. In C++, name lookup
1343 /// can additionally refer to a set of overloaded functions or
1344 /// result in an ambiguity. All of the possible results of name
1345 /// lookup are captured by the LookupResult class, which provides
1346 /// the ability to distinguish among them.
1347 //@{
Douglas Gregorf780abc2008-12-30 03:27:21 +00001348
Douglas Gregor4c921ae2009-01-30 01:04:22 +00001349 /// @brief Describes the kind of name lookup to perform.
1350 enum LookupNameKind {
1351 /// Ordinary name lookup, which finds ordinary names (functions,
1352 /// variables, typedefs, etc.) in C and most kinds of names
1353 /// (functions, variables, members, types, etc.) in C++.
1354 LookupOrdinaryName = 0,
1355 /// Tag name lookup, which finds the names of enums, classes,
1356 /// structs, and unions.
1357 LookupTagName,
1358 /// Member name lookup, which finds the names of
1359 /// class/struct/union members.
1360 LookupMemberName,
Douglas Gregorf680a0f2009-02-04 16:44:47 +00001361 // Look up of an operator name (e.g., operator+) for use with
1362 // operator overloading. This lookup is similar to ordinary name
1363 // lookup, but will ignore any declarations that are class
1364 // members.
1365 LookupOperatorName,
Douglas Gregor4c921ae2009-01-30 01:04:22 +00001366 /// Look up of a name that precedes the '::' scope resolution
Eli Friedmanb1df3332009-12-21 01:26:45 +00001367 /// operator in C++. This lookup completely ignores operator, object,
Douglas Gregor4c921ae2009-01-30 01:04:22 +00001368 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
1369 LookupNestedNameSpecifierName,
1370 /// Look up a namespace name within a C++ using directive or
1371 /// namespace alias definition, ignoring non-namespace names (C++
1372 /// [basic.lookup.udir]p1).
Douglas Gregord6f7e9d2009-02-24 20:03:32 +00001373 LookupNamespaceName,
John McCall9f54ad42009-12-10 09:41:52 +00001374 /// Look up all declarations in a scope with the given name,
1375 /// including resolved using declarations. This is appropriate
1376 /// for checking redeclarations for a using declaration.
1377 LookupUsingDeclName,
Douglas Gregor6e378de2009-04-23 23:18:26 +00001378 /// Look up an ordinary name that is going to be redeclared as a
1379 /// name with linkage. This lookup ignores any declarations that
Mike Stump1eb44332009-09-09 15:08:12 +00001380 /// are outside of the current scope unless they have linkage. See
Douglas Gregor6e378de2009-04-23 23:18:26 +00001381 /// C99 6.2.2p4-5 and C++ [basic.link]p6.
1382 LookupRedeclarationWithLinkage,
1383 /// Look up the name of an Objective-C protocol.
Douglas Gregor8fc463a2009-04-24 00:11:27 +00001384 LookupObjCProtocolName,
1385 /// Look up the name of an Objective-C implementation
Fariborz Jahanian737061f2009-12-11 00:26:36 +00001386 LookupObjCImplementationName
Douglas Gregoreb11cd02009-01-14 22:20:51 +00001387 };
1388
Douglas Gregor48026d22010-01-11 18:40:55 +00001389 /// \brief Specifies whether (or how) name lookup is being performed for a
1390 /// redeclaration (vs. a reference).
John McCall7d384dd2009-11-18 07:57:50 +00001391 enum RedeclarationKind {
Douglas Gregor48026d22010-01-11 18:40:55 +00001392 /// \brief The lookup is a reference to this name that is not for the
1393 /// purpose of redeclaring the name.
1394 NotForRedeclaration = 0,
1395 /// \brief The lookup results will be used for redeclaration of a name,
1396 /// if an entity by that name already exists.
John McCall7d384dd2009-11-18 07:57:50 +00001397 ForRedeclaration
Douglas Gregoreb11cd02009-01-14 22:20:51 +00001398 };
1399
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001400private:
John McCalla24dc2e2009-11-17 02:14:36 +00001401 bool CppLookupName(LookupResult &R, Scope *S);
1402
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001403public:
John McCallf36e02d2009-10-09 21:13:30 +00001404 /// \brief Look up a name, looking for a single declaration. Return
John McCall1bcee0a2009-12-02 08:25:40 +00001405 /// null if the results were absent, ambiguous, or overloaded.
John McCallf36e02d2009-10-09 21:13:30 +00001406 ///
1407 /// It is preferable to use the elaborated form and explicitly handle
1408 /// ambiguity and overloaded.
1409 NamedDecl *LookupSingleName(Scope *S, DeclarationName Name,
1410 LookupNameKind NameKind,
John McCall7d384dd2009-11-18 07:57:50 +00001411 RedeclarationKind Redecl
1412 = NotForRedeclaration);
John McCallf36e02d2009-10-09 21:13:30 +00001413 bool LookupName(LookupResult &R, Scope *S,
John McCalla24dc2e2009-11-17 02:14:36 +00001414 bool AllowBuiltinCreation = false);
Douglas Gregor7d3f5762010-01-15 01:44:47 +00001415 bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
1416 bool InUnqualifiedLookup = false);
John McCallf36e02d2009-10-09 21:13:30 +00001417 bool LookupParsedName(LookupResult &R, Scope *S, const CXXScopeSpec *SS,
John McCallf36e02d2009-10-09 21:13:30 +00001418 bool AllowBuiltinCreation = false,
John McCallf36e02d2009-10-09 21:13:30 +00001419 bool EnteringContext = false);
Douglas Gregor6e378de2009-04-23 23:18:26 +00001420 ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II);
1421
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001422 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
Mike Stump1eb44332009-09-09 15:08:12 +00001423 QualType T1, QualType T2,
John McCall6e266892010-01-26 03:27:55 +00001424 UnresolvedSetImpl &Functions);
Douglas Gregor546be3c2009-12-30 17:04:44 +00001425
Sebastian Redl644be852009-10-23 19:23:15 +00001426 void ArgumentDependentLookup(DeclarationName Name, bool Operator,
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001427 Expr **Args, unsigned NumArgs,
John McCall7edb5fd2010-01-26 07:16:45 +00001428 ADLResult &Functions);
Douglas Gregor3fd95ce2009-03-13 00:33:25 +00001429
Douglas Gregor546be3c2009-12-30 17:04:44 +00001430 void LookupVisibleDecls(Scope *S, LookupNameKind Kind,
1431 VisibleDeclConsumer &Consumer);
1432 void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind,
1433 VisibleDeclConsumer &Consumer);
1434
1435 bool CorrectTypo(LookupResult &R, Scope *S, const CXXScopeSpec *SS,
Douglas Gregor2dcc0112009-12-31 07:42:17 +00001436 DeclContext *MemberContext = 0,
Douglas Gregorf06cdae2010-01-03 18:01:57 +00001437 bool EnteringContext = false,
1438 const ObjCObjectPointerType *OPT = 0);
Douglas Gregor546be3c2009-12-30 17:04:44 +00001439
Douglas Gregorfa047642009-02-04 00:32:51 +00001440 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
1441 AssociatedNamespaceSet &AssociatedNamespaces,
John McCall6ff07852009-08-07 22:18:02 +00001442 AssociatedClassSet &AssociatedClasses);
Douglas Gregorfa047642009-02-04 00:32:51 +00001443
John McCalla24dc2e2009-11-17 02:14:36 +00001444 bool DiagnoseAmbiguousLookup(LookupResult &Result);
Douglas Gregoreb11cd02009-01-14 22:20:51 +00001445 //@}
Mike Stump1eb44332009-09-09 15:08:12 +00001446
Douglas Gregorf06cdae2010-01-03 18:01:57 +00001447 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id,
1448 SourceLocation RecoverLoc = SourceLocation());
Mike Stump1eb44332009-09-09 15:08:12 +00001449 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Douglas Gregor3e41d602009-02-13 23:20:09 +00001450 Scope *S, bool ForRedeclaration,
1451 SourceLocation Loc);
Douglas Gregor4afa39d2009-01-20 01:17:11 +00001452 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
1453 Scope *S);
Douglas Gregor3c385e52009-02-14 18:57:46 +00001454 void AddKnownFunctionAttributes(FunctionDecl *FD);
Douglas Gregoreb11cd02009-01-14 22:20:51 +00001455
1456 // More parsing and symbol table subroutines.
1457
Mike Stump1eb44332009-09-09 15:08:12 +00001458 // Decl attributes - this routine is the top level dispatcher.
Douglas Gregor9cdda0c2009-06-17 21:51:59 +00001459 void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD);
1460 void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AttrList);
Christopher Lambebb97e92008-02-04 02:31:56 +00001461
Steve Naroff3c2eb662008-02-10 21:38:56 +00001462 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
1463 bool &IncompleteImpl);
Fariborz Jahanian8daab972008-12-05 18:18:52 +00001464 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
1465 ObjCMethodDecl *IntfMethod);
Sebastian Redlc42e1182008-11-11 11:37:55 +00001466
Fariborz Jahaniand1fa6442009-01-12 19:55:42 +00001467 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
Steve Naroff22dc0b02009-02-26 19:11:32 +00001468 ObjCInterfaceDecl *IDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00001469
Chris Lattner823c44e2009-01-06 07:27:21 +00001470 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +00001471 /// methods declared in protocol, and those referenced by it.
1472 /// \param IDecl - Used for checking for methods which may have been
1473 /// inherited.
Steve Naroffefe7f362008-02-08 22:06:17 +00001474 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
1475 ObjCProtocolDecl *PDecl,
Fariborz Jahanianca3adf72007-10-02 20:06:01 +00001476 bool& IncompleteImpl,
Steve Naroffeefc4182007-10-08 21:05:34 +00001477 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +00001478 const llvm::DenseSet<Selector> &ClsMap,
1479 ObjCInterfaceDecl *IDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00001480
Steve Naroffa5997c42007-10-02 21:43:37 +00001481 /// CheckImplementationIvars - This routine checks if the instance variables
Mike Stump1eb44332009-09-09 15:08:12 +00001482 /// listed in the implelementation match those listed in the interface.
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001483 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
1484 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff3c2eb662008-02-10 21:38:56 +00001485 SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +00001486
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +00001487 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
Chris Lattnercddc8882009-03-01 00:56:52 +00001488 /// remains unimplemented in the class or category @implementation.
Mike Stump1eb44332009-09-09 15:08:12 +00001489 void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl,
1490 ObjCContainerDecl* IDecl,
Chris Lattnercddc8882009-03-01 00:56:52 +00001491 bool IncompleteImpl = false);
Fariborz Jahanian7ca8b062009-11-11 22:40:11 +00001492
Fariborz Jahanian3ac1eda2010-01-20 01:51:55 +00001493 /// DiagnoseUnimplementedProperties - This routine warns on those properties
1494 /// which must be implemented by this implementation.
1495 void DiagnoseUnimplementedProperties(ObjCImplDecl* IMPDecl,
1496 ObjCContainerDecl *CDecl,
1497 const llvm::DenseSet<Selector>& InsMap);
Ted Kremeneke3d67bc2010-03-12 02:31:10 +00001498
Fariborz Jahanian3ac1eda2010-01-20 01:51:55 +00001499 /// CollectImmediateProperties - This routine collects all properties in
1500 /// the class and its conforming protocols; but not those it its super class.
1501 void CollectImmediateProperties(ObjCContainerDecl *CDecl,
1502 llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap);
1503
Fariborz Jahanian412e7982010-02-09 19:31:38 +00001504 /// LookupPropertyDecl - Looks up a property in the current class and all
1505 /// its protocols.
1506 ObjCPropertyDecl *LookupPropertyDecl(const ObjCContainerDecl *CDecl,
1507 IdentifierInfo *II);
1508
Fariborz Jahanian77e2dde2010-02-09 21:49:50 +00001509 ObjCIvarDecl *SynthesizeNewPropertyIvar(ObjCInterfaceDecl *IDecl,
1510 IdentifierInfo *NameII);
Ted Kremeneke3d67bc2010-03-12 02:31:10 +00001511
1512 /// Called by ActOnProperty to handle @property declarations in
1513 //// class extensions.
1514 DeclPtrTy HandlePropertyInClassExtension(Scope *S,
1515 ObjCCategoryDecl *CDecl,
1516 SourceLocation AtLoc,
1517 FieldDeclarator &FD,
1518 Selector GetterSel,
1519 Selector SetterSel,
1520 const bool isAssign,
1521 const bool isReadWrite,
1522 const unsigned Attributes,
1523 bool *isOverridingProperty,
1524 QualType T,
1525 tok::ObjCKeywordKind MethodImplKind);
1526
1527 /// Called by ActOnProperty and HandlePropertyInClassExtension to
1528 /// handle creating the ObjcPropertyDecl for a category or @interface.
1529 ObjCPropertyDecl *CreatePropertyDecl(Scope *S,
1530 ObjCContainerDecl *CDecl,
1531 SourceLocation AtLoc,
1532 FieldDeclarator &FD,
1533 Selector GetterSel,
1534 Selector SetterSel,
1535 const bool isAssign,
1536 const bool isReadWrite,
1537 const unsigned Attributes, QualType T,
1538 tok::ObjCKeywordKind MethodImplKind);
1539
Fariborz Jahanian7ca8b062009-11-11 22:40:11 +00001540 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via
1541 /// warning) when atomic property has one but not the other user-declared
1542 /// setter or getter.
1543 void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl,
1544 ObjCContainerDecl* IDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00001545
Fariborz Jahanianf914b972010-02-23 23:41:11 +00001546 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
1547
Fariborz Jahanian85ff2642007-10-05 18:00:57 +00001548 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
1549 /// true, or false, accordingly.
Mike Stump1eb44332009-09-09 15:08:12 +00001550 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Narofffe6b0dc2008-10-21 10:37:50 +00001551 const ObjCMethodDecl *PrevMethod,
Mike Stump1eb44332009-09-09 15:08:12 +00001552 bool matchBasedOnSizeAndAlignment = false);
Steve Naroff3b950172007-10-10 21:53:07 +00001553
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +00001554 /// MatchAllMethodDeclarations - Check methods declaraed in interface or
1555 /// or protocol against those declared in their implementations.
1556 void MatchAllMethodDeclarations(const llvm::DenseSet<Selector> &InsMap,
1557 const llvm::DenseSet<Selector> &ClsMap,
1558 llvm::DenseSet<Selector> &InsMapSeen,
1559 llvm::DenseSet<Selector> &ClsMapSeen,
1560 ObjCImplDecl* IMPDecl,
1561 ObjCContainerDecl* IDecl,
1562 bool &IncompleteImpl,
1563 bool ImmediateClass);
1564
Steve Naroff58ff9e82007-10-14 00:58:41 +00001565 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
1566 /// unit are added to a global pool. This allows us to efficiently associate
1567 /// a selector with a method declaraation for purposes of typechecking
1568 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001569 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Mike Stump1eb44332009-09-09 15:08:12 +00001570
Steve Naroff037cda52008-09-30 14:38:43 +00001571 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
1572 /// there are multiple signatures.
Fariborz Jahanian835ed7f2009-08-22 21:13:55 +00001573 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
1574 bool warn=true);
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +00001575
1576 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if
1577 /// there are multiple signatures.
1578 ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R);
Mike Stump1eb44332009-09-09 15:08:12 +00001579
Steve Naroff58ff9e82007-10-14 00:58:41 +00001580 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001581 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Reid Spencer5f016e22007-07-11 17:01:13 +00001582 //===--------------------------------------------------------------------===//
1583 // Statement Parsing Callbacks: SemaStmt.cpp.
1584public:
Anders Carlsson6b1d2832009-05-17 21:11:30 +00001585 virtual OwningStmtResult ActOnExprStmt(FullExprArg Expr);
Sebastian Redla60528c2008-12-21 12:04:03 +00001586
1587 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
1588 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1589 MultiStmtArg Elts,
1590 bool isStmtExpr);
Chris Lattner682bf922009-03-29 16:50:03 +00001591 virtual OwningStmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
Chris Lattnerb28317a2009-03-28 19:18:32 +00001592 SourceLocation StartLoc,
Sebastian Redla60528c2008-12-21 12:04:03 +00001593 SourceLocation EndLoc);
Fariborz Jahaniana7cf23a2009-11-19 22:12:37 +00001594 virtual void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
Sebastian Redl117054a2008-12-28 16:13:43 +00001595 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
1596 SourceLocation DotDotDotLoc, ExprArg RHSVal,
Chris Lattner24e1e702009-03-04 04:23:07 +00001597 SourceLocation ColonLoc);
1598 virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt);
Mike Stump1eb44332009-09-09 15:08:12 +00001599
Sebastian Redl117054a2008-12-28 16:13:43 +00001600 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1601 SourceLocation ColonLoc,
1602 StmtArg SubStmt, Scope *CurScope);
Sebastian Redlde307472009-01-11 00:38:46 +00001603 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
1604 IdentifierInfo *II,
1605 SourceLocation ColonLoc,
1606 StmtArg SubStmt);
Mike Stump1eb44332009-09-09 15:08:12 +00001607 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00001608 FullExprArg CondVal, DeclPtrTy CondVar,
1609 StmtArg ThenVal,
Anders Carlssona99fad82009-05-17 18:26:53 +00001610 SourceLocation ElseLoc, StmtArg ElseVal);
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00001611 virtual OwningStmtResult ActOnStartOfSwitchStmt(FullExprArg Cond,
1612 DeclPtrTy CondVar);
Chris Lattner7e52de42010-01-24 01:50:29 +00001613 virtual void ActOnSwitchBodyError(SourceLocation SwitchLoc, StmtArg Switch,
1614 StmtArg Body);
Sebastian Redlde307472009-01-11 00:38:46 +00001615 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1616 StmtArg Switch, StmtArg Body);
Mike Stump1eb44332009-09-09 15:08:12 +00001617 virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00001618 FullExprArg Cond,
1619 DeclPtrTy CondVar, StmtArg Body);
Sebastian Redlf05b1522009-01-16 23:28:06 +00001620 virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
Chris Lattner98913592009-06-12 23:04:47 +00001621 SourceLocation WhileLoc,
1622 SourceLocation CondLParen, ExprArg Cond,
1623 SourceLocation CondRParen);
Sebastian Redlf05b1522009-01-16 23:28:06 +00001624
1625 virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
1626 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00001627 StmtArg First, FullExprArg Second,
1628 DeclPtrTy SecondVar,
1629 FullExprArg Third,
1630 SourceLocation RParenLoc,
Sebastian Redlf05b1522009-01-16 23:28:06 +00001631 StmtArg Body);
1632 virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1633 SourceLocation LParenLoc,
1634 StmtArg First, ExprArg Second,
1635 SourceLocation RParenLoc, StmtArg Body);
Sebastian Redl4cffe2f2009-01-18 13:19:59 +00001636
1637 virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1638 SourceLocation LabelLoc,
1639 IdentifierInfo *LabelII);
1640 virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1641 SourceLocation StarLoc,
1642 ExprArg DestExp);
1643 virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
1644 Scope *CurScope);
1645 virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
1646 Scope *CurScope);
1647
1648 virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
Anders Carlssonf53b4432009-08-18 16:11:00 +00001649 ExprArg RetValExp);
Sebastian Redl4cffe2f2009-01-18 13:19:59 +00001650 OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
1651 Expr *RetValExp);
1652
Sebastian Redl3037ed02009-01-18 16:53:17 +00001653 virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1654 bool IsSimple,
1655 bool IsVolatile,
1656 unsigned NumOutputs,
1657 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001658 IdentifierInfo **Names,
Sebastian Redl3037ed02009-01-18 16:53:17 +00001659 MultiExprArg Constraints,
1660 MultiExprArg Exprs,
1661 ExprArg AsmString,
1662 MultiExprArg Clobbers,
Mike Stump3b11fd32010-01-04 22:37:17 +00001663 SourceLocation RParenLoc,
1664 bool MSAsm = false);
Sebastian Redl431e90e2009-01-18 17:43:11 +00001665
1666 virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
1667 SourceLocation RParen,
Chris Lattnerb28317a2009-03-28 19:18:32 +00001668 DeclPtrTy Parm, StmtArg Body,
Sebastian Redl431e90e2009-01-18 17:43:11 +00001669 StmtArg CatchList);
1670
1671 virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
1672 StmtArg Body);
1673
1674 virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
1675 StmtArg Try,
1676 StmtArg Catch, StmtArg Finally);
1677
1678 virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001679 ExprArg Throw,
Steve Naroffe21dd6f2009-02-11 20:05:44 +00001680 Scope *CurScope);
Sebastian Redl431e90e2009-01-18 17:43:11 +00001681 virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1682 ExprArg SynchExpr,
1683 StmtArg SynchBody);
Sebastian Redla0fd8652008-12-21 16:41:36 +00001684
Douglas Gregord308e622009-05-18 20:51:54 +00001685 VarDecl *BuildExceptionDeclaration(Scope *S, QualType ExDeclType,
John McCalla93c9342009-12-07 02:54:59 +00001686 TypeSourceInfo *TInfo,
Douglas Gregord308e622009-05-18 20:51:54 +00001687 IdentifierInfo *Name,
1688 SourceLocation Loc,
1689 SourceRange Range);
Chris Lattnerb28317a2009-03-28 19:18:32 +00001690 virtual DeclPtrTy ActOnExceptionDeclarator(Scope *S, Declarator &D);
Douglas Gregord308e622009-05-18 20:51:54 +00001691
Sebastian Redl4b07b292008-12-22 19:15:10 +00001692 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
Chris Lattnerb28317a2009-03-28 19:18:32 +00001693 DeclPtrTy ExDecl,
Sebastian Redl4b07b292008-12-22 19:15:10 +00001694 StmtArg HandlerBlock);
Sebastian Redl8351da02008-12-22 21:35:02 +00001695 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
1696 StmtArg TryBlock,
1697 MultiStmtArg Handlers);
Sebastian Redl13e88542009-04-27 21:33:24 +00001698 void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock);
Sebastian Redla0fd8652008-12-21 16:41:36 +00001699
Anders Carlsson636463e2009-07-30 22:17:18 +00001700 /// DiagnoseUnusedExprResult - If the statement passed in is an expression
1701 /// whose result is unused, warn.
1702 void DiagnoseUnusedExprResult(const Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +00001703
John McCall54abf7d2009-11-04 02:18:39 +00001704 ParsingDeclStackState PushParsingDeclaration();
1705 void PopParsingDeclaration(ParsingDeclStackState S, DeclPtrTy D);
1706 void EmitDeprecationWarning(NamedDecl *D, SourceLocation Loc);
1707
John McCall2f514482010-01-27 03:50:35 +00001708 void HandleDelayedDeprecationCheck(DelayedDiagnostic &DD, Decl *Ctx);
1709
Reid Spencer5f016e22007-07-11 17:01:13 +00001710 //===--------------------------------------------------------------------===//
1711 // Expression Parsing Callbacks: SemaExpr.cpp.
1712
John McCall54abf7d2009-11-04 02:18:39 +00001713 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +00001714 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
Fariborz Jahanianc001e892009-05-08 20:20:55 +00001715 ObjCMethodDecl *Getter,
1716 SourceLocation Loc);
Fariborz Jahanian5b530052009-05-13 18:09:35 +00001717 void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
1718 Expr **Args, unsigned NumArgs);
Chris Lattner76a642f2009-02-15 22:43:40 +00001719
Douglas Gregor2afce722009-11-26 00:44:06 +00001720 virtual void
Douglas Gregorac7610d2009-06-22 20:57:11 +00001721 PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext);
Mike Stump1eb44332009-09-09 15:08:12 +00001722
Douglas Gregor2afce722009-11-26 00:44:06 +00001723 virtual void PopExpressionEvaluationContext();
Mike Stump1eb44332009-09-09 15:08:12 +00001724
Douglas Gregore0762c92009-06-19 23:52:42 +00001725 void MarkDeclarationReferenced(SourceLocation Loc, Decl *D);
Douglas Gregor1c7c3fb2009-12-22 01:01:55 +00001726 bool DiagRuntimeBehavior(SourceLocation Loc, const PartialDiagnostic &PD);
1727
Reid Spencer5f016e22007-07-11 17:01:13 +00001728 // Primary Expressions.
Douglas Gregor4b2d3f72009-02-26 21:00:50 +00001729 virtual SourceRange getExprRange(ExprTy *E) const;
1730
Douglas Gregor02a24ee2009-11-03 16:56:39 +00001731 virtual OwningExprResult ActOnIdExpression(Scope *S,
1732 const CXXScopeSpec &SS,
1733 UnqualifiedId &Name,
1734 bool HasTrailingLParen,
1735 bool IsAddressOfOperand);
John McCallf7a1a742009-11-24 19:00:30 +00001736
Douglas Gregorbb092ba2009-12-31 05:20:13 +00001737 bool DiagnoseEmptyLookup(Scope *S, const CXXScopeSpec &SS, LookupResult &R);
John McCall578b69b2009-12-16 08:11:27 +00001738
John McCallf7a1a742009-11-24 19:00:30 +00001739 OwningExprResult LookupInObjCMethod(LookupResult &R,
1740 Scope *S,
Fariborz Jahanian48c2d562010-01-12 23:58:59 +00001741 IdentifierInfo *II,
1742 bool AllowBuiltinCreation=false);
John McCallf7a1a742009-11-24 19:00:30 +00001743
1744 OwningExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS,
1745 DeclarationName Name,
1746 SourceLocation NameLoc,
John McCall2f841ba2009-12-02 03:53:29 +00001747 bool isAddressOfOperand,
John McCallf7a1a742009-11-24 19:00:30 +00001748 const TemplateArgumentListInfo *TemplateArgs);
Douglas Gregor02a24ee2009-11-03 16:56:39 +00001749
John McCalldbd872f2009-12-08 09:08:17 +00001750 OwningExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty,
Douglas Gregor0da76df2009-11-23 11:41:28 +00001751 SourceLocation Loc,
Anders Carlssone41590d2009-06-24 00:10:43 +00001752 const CXXScopeSpec *SS = 0);
Douglas Gregorffb4b6e2009-04-15 06:41:24 +00001753 VarDecl *BuildAnonymousStructUnionMemberPath(FieldDecl *Field,
1754 llvm::SmallVectorImpl<FieldDecl *> &Path);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001755 OwningExprResult
Douglas Gregorbcbffc42009-01-07 00:43:41 +00001756 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1757 FieldDecl *Field,
1758 Expr *BaseObjectExpr = 0,
1759 SourceLocation OpLoc = SourceLocation());
John McCall3b4294e2009-12-16 12:17:52 +00001760 OwningExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
1761 LookupResult &R,
1762 const TemplateArgumentListInfo *TemplateArgs);
John McCallaa81e162009-12-01 22:10:20 +00001763 OwningExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS,
1764 LookupResult &R,
1765 const TemplateArgumentListInfo *TemplateArgs,
1766 bool IsDefiniteInstance);
John McCallf7a1a742009-11-24 19:00:30 +00001767 bool UseArgumentDependentLookup(const CXXScopeSpec &SS,
John McCall5b3f9132009-11-22 01:44:31 +00001768 const LookupResult &R,
1769 bool HasTrailingLParen);
John McCallf7a1a742009-11-24 19:00:30 +00001770
1771 OwningExprResult BuildQualifiedDeclarationNameExpr(const CXXScopeSpec &SS,
1772 DeclarationName Name,
1773 SourceLocation NameLoc);
1774 OwningExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
1775 DeclarationName Name,
1776 SourceLocation NameLoc,
1777 const TemplateArgumentListInfo *TemplateArgs);
1778
1779 OwningExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
1780 LookupResult &R,
1781 bool ADL);
1782 OwningExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallba135432009-11-21 08:51:07 +00001783 SourceLocation Loc,
1784 NamedDecl *D);
Mike Stump1eb44332009-09-09 15:08:12 +00001785
Sebastian Redlcd965b92009-01-18 18:53:16 +00001786 virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
1787 tok::TokenKind Kind);
1788 virtual OwningExprResult ActOnNumericConstant(const Token &);
1789 virtual OwningExprResult ActOnCharacterConstant(const Token &);
1790 virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
1791 ExprArg Val);
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001792 virtual OwningExprResult ActOnParenOrParenListExpr(SourceLocation L,
Nate Begeman2ef13e52009-08-10 23:49:36 +00001793 SourceLocation R,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001794 MultiExprArg Val,
1795 TypeTy *TypeOfCast=0);
Mike Stump1eb44332009-09-09 15:08:12 +00001796
Steve Narofff69936d2007-09-16 03:34:24 +00001797 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Reid Spencer5f016e22007-07-11 17:01:13 +00001798 /// fragments (e.g. "foo" "bar" L"baz").
Sebastian Redl0eb23302009-01-19 00:08:26 +00001799 virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
1800 unsigned NumToks);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001801
Reid Spencer5f016e22007-07-11 17:01:13 +00001802 // Binary/Unary Operators. 'Tok' is the token for the operator.
Douglas Gregorbc736fc2009-03-13 23:49:33 +00001803 OwningExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001804 unsigned OpcIn,
Douglas Gregorbc736fc2009-03-13 23:49:33 +00001805 ExprArg InputArg);
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001806 OwningExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc,
1807 UnaryOperator::Opcode Opc, ExprArg input);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001808 virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1809 tok::TokenKind Op, ExprArg Input);
Sebastian Redl05189992008-11-11 17:56:53 +00001810
John McCalla93c9342009-12-07 02:54:59 +00001811 OwningExprResult CreateSizeOfAlignOfExpr(TypeSourceInfo *T,
John McCall5ab75172009-11-04 07:28:41 +00001812 SourceLocation OpLoc,
Douglas Gregorba498172009-03-13 21:01:28 +00001813 bool isSizeOf, SourceRange R);
Mike Stump1eb44332009-09-09 15:08:12 +00001814 OwningExprResult CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc,
Douglas Gregorba498172009-03-13 21:01:28 +00001815 bool isSizeOf, SourceRange R);
Douglas Gregorbc736fc2009-03-13 23:49:33 +00001816 virtual OwningExprResult
1817 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1818 void *TyOrEx, const SourceRange &ArgRange);
Mike Stump1eb44332009-09-09 15:08:12 +00001819
Chris Lattner31e21e02009-01-24 20:17:12 +00001820 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R);
Sebastian Redl05189992008-11-11 17:56:53 +00001821 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1822 const SourceRange &R, bool isSizeof);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001823
1824 virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1825 tok::TokenKind Kind,
1826 ExprArg Input);
1827
1828 virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
1829 SourceLocation LLoc,
1830 ExprArg Idx,
1831 SourceLocation RLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00001832 OwningExprResult CreateBuiltinArraySubscriptExpr(ExprArg Base,
1833 SourceLocation LLoc,
1834 ExprArg Idx,
1835 SourceLocation RLoc);
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00001836
John McCall129e2df2009-11-30 22:42:35 +00001837 OwningExprResult BuildMemberReferenceExpr(ExprArg Base,
John McCallaa81e162009-12-01 22:10:20 +00001838 QualType BaseType,
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00001839 SourceLocation OpLoc,
John McCall129e2df2009-11-30 22:42:35 +00001840 bool IsArrow,
1841 const CXXScopeSpec &SS,
1842 NamedDecl *FirstQualifierInScope,
1843 DeclarationName Name,
1844 SourceLocation NameLoc,
1845 const TemplateArgumentListInfo *TemplateArgs);
Mike Stump1eb44332009-09-09 15:08:12 +00001846
John McCall129e2df2009-11-30 22:42:35 +00001847 OwningExprResult BuildMemberReferenceExpr(ExprArg Base,
John McCallaa81e162009-12-01 22:10:20 +00001848 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001849 SourceLocation OpLoc, bool IsArrow,
1850 const CXXScopeSpec &SS,
John McCallc2233c52010-01-15 08:34:02 +00001851 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001852 LookupResult &R,
1853 const TemplateArgumentListInfo *TemplateArgs);
1854
1855 OwningExprResult LookupMemberExpr(LookupResult &R, Expr *&Base,
John McCall812c1542009-12-07 22:46:59 +00001856 bool &IsArrow, SourceLocation OpLoc,
John McCall129e2df2009-11-30 22:42:35 +00001857 const CXXScopeSpec &SS,
John McCall129e2df2009-11-30 22:42:35 +00001858 DeclPtrTy ObjCImpDecl);
1859
1860 bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType,
John McCall2f841ba2009-12-02 03:53:29 +00001861 const CXXScopeSpec &SS,
John McCall129e2df2009-11-30 22:42:35 +00001862 const LookupResult &R);
1863
1864 OwningExprResult ActOnDependentMemberExpr(ExprArg Base,
John McCallaa81e162009-12-01 22:10:20 +00001865 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001866 bool IsArrow,
Anders Carlsson8f28f992009-08-26 18:25:21 +00001867 SourceLocation OpLoc,
John McCall129e2df2009-11-30 22:42:35 +00001868 const CXXScopeSpec &SS,
1869 NamedDecl *FirstQualifierInScope,
1870 DeclarationName Name,
1871 SourceLocation NameLoc,
1872 const TemplateArgumentListInfo *TemplateArgs);
Mike Stump1eb44332009-09-09 15:08:12 +00001873
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001874 virtual OwningExprResult ActOnMemberAccessExpr(Scope *S, ExprArg Base,
1875 SourceLocation OpLoc,
1876 tok::TokenKind OpKind,
1877 const CXXScopeSpec &SS,
1878 UnqualifiedId &Member,
1879 DeclPtrTy ObjCImpDecl,
1880 bool HasTrailingLParen);
1881
Fariborz Jahanian393612e2009-07-21 22:36:06 +00001882 virtual void ActOnDefaultCtorInitializers(DeclPtrTy CDtorDecl);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001883 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
Douglas Gregor88a35142008-12-22 05:46:06 +00001884 FunctionDecl *FDecl,
Douglas Gregor72564e72009-02-26 23:50:07 +00001885 const FunctionProtoType *Proto,
Douglas Gregor88a35142008-12-22 05:46:06 +00001886 Expr **Args, unsigned NumArgs,
1887 SourceLocation RParenLoc);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001888
Steve Narofff69936d2007-09-16 03:34:24 +00001889 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Reid Spencer5f016e22007-07-11 17:01:13 +00001890 /// This provides the location of the left/right parens and a list of comma
1891 /// locations.
Sebastian Redl0eb23302009-01-19 00:08:26 +00001892 virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn,
1893 SourceLocation LParenLoc,
1894 MultiExprArg Args,
1895 SourceLocation *CommaLocs,
1896 SourceLocation RParenLoc);
John McCallaa81e162009-12-01 22:10:20 +00001897 OwningExprResult BuildResolvedCallExpr(Expr *Fn,
1898 NamedDecl *NDecl,
1899 SourceLocation LParenLoc,
1900 Expr **Args, unsigned NumArgs,
1901 SourceLocation RParenLoc);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001902
Nate Begeman2ef13e52009-08-10 23:49:36 +00001903 virtual OwningExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc,
1904 TypeTy *Ty, SourceLocation RParenLoc,
1905 ExprArg Op);
John McCallb042fdf2010-01-15 18:56:44 +00001906 OwningExprResult BuildCStyleCastExpr(SourceLocation LParenLoc,
1907 TypeSourceInfo *Ty,
1908 SourceLocation RParenLoc,
1909 ExprArg Op);
1910
Fariborz Jahaniana79f8b32009-11-23 19:51:43 +00001911 virtual bool TypeIsVectorType(TypeTy *Ty) {
1912 return GetTypeFromParser(Ty)->isVectorType();
1913 }
Mike Stump1eb44332009-09-09 15:08:12 +00001914
Nate Begeman2ef13e52009-08-10 23:49:36 +00001915 OwningExprResult MaybeConvertParenListExprToParenExpr(Scope *S, ExprArg ME);
1916 OwningExprResult ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc,
1917 SourceLocation RParenLoc, ExprArg E,
John McCall42f56b52010-01-18 19:35:47 +00001918 TypeSourceInfo *TInfo);
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001919
1920 virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1921 TypeTy *Ty,
1922 SourceLocation RParenLoc,
1923 ExprArg Op);
1924
John McCall42f56b52010-01-18 19:35:47 +00001925 OwningExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc,
1926 TypeSourceInfo *TInfo,
1927 SourceLocation RParenLoc,
1928 ExprArg InitExpr);
1929
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001930 virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
1931 MultiExprArg InitList,
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001932 SourceLocation RParenLoc);
1933
Douglas Gregor05c13a32009-01-22 00:58:24 +00001934 virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
1935 SourceLocation Loc,
Douglas Gregoreeae8f02009-03-28 00:41:23 +00001936 bool GNUSyntax,
Douglas Gregor05c13a32009-01-22 00:58:24 +00001937 OwningExprResult Init);
1938
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001939 virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1940 tok::TokenKind Kind,
1941 ExprArg LHS, ExprArg RHS);
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001942 OwningExprResult BuildBinOp(Scope *S, SourceLocation OpLoc,
1943 BinaryOperator::Opcode Opc,
1944 Expr *lhs, Expr *rhs);
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001945 OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1946 unsigned Opc, Expr *lhs, Expr *rhs);
Douglas Gregoreaebc752008-11-06 23:29:22 +00001947
Steve Narofff69936d2007-09-16 03:34:24 +00001948 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Reid Spencer5f016e22007-07-11 17:01:13 +00001949 /// in the case of a the GNU conditional expr extension.
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001950 virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1951 SourceLocation ColonLoc,
1952 ExprArg Cond, ExprArg LHS,
1953 ExprArg RHS);
Reid Spencer5f016e22007-07-11 17:01:13 +00001954
Steve Naroff1b273c42007-09-16 14:56:35 +00001955 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
Sebastian Redlf53597f2009-03-15 17:47:39 +00001956 virtual OwningExprResult ActOnAddrLabel(SourceLocation OpLoc,
1957 SourceLocation LabLoc,
1958 IdentifierInfo *LabelII);
1959
1960 virtual OwningExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtArg SubStmt,
1961 SourceLocation RPLoc); // "({..})"
Chris Lattner73d0d4f2007-08-30 17:45:32 +00001962
1963 /// __builtin_offsetof(type, a.b[123][456].c)
Sebastian Redlf53597f2009-03-15 17:47:39 +00001964 virtual OwningExprResult ActOnBuiltinOffsetOf(Scope *S,
1965 SourceLocation BuiltinLoc,
1966 SourceLocation TypeLoc,
1967 TypeTy *Arg1,
1968 OffsetOfComponent *CompPtr,
1969 unsigned NumComponents,
1970 SourceLocation RParenLoc);
1971
Steve Naroffd34e9152007-08-01 22:05:33 +00001972 // __builtin_types_compatible_p(type1, type2)
Sebastian Redlf53597f2009-03-15 17:47:39 +00001973 virtual OwningExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
1974 TypeTy *arg1, TypeTy *arg2,
1975 SourceLocation RPLoc);
1976
Steve Naroffd04fdd52007-08-03 21:21:27 +00001977 // __builtin_choose_expr(constExpr, expr1, expr2)
Sebastian Redlf53597f2009-03-15 17:47:39 +00001978 virtual OwningExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
1979 ExprArg cond, ExprArg expr1,
1980 ExprArg expr2, SourceLocation RPLoc);
1981
Anders Carlsson7c50aca2007-10-15 20:28:48 +00001982 // __builtin_va_arg(expr, type)
Sebastian Redlf53597f2009-03-15 17:47:39 +00001983 virtual OwningExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1984 ExprArg expr, TypeTy *type,
1985 SourceLocation RPLoc);
Steve Naroff4eb206b2008-09-03 18:15:37 +00001986
Douglas Gregor2d8b2732008-11-29 04:51:27 +00001987 // __null
Sebastian Redlf53597f2009-03-15 17:47:39 +00001988 virtual OwningExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
Douglas Gregor2d8b2732008-11-29 04:51:27 +00001989
Steve Naroff4eb206b2008-09-03 18:15:37 +00001990 //===------------------------- "Block" Extension ------------------------===//
1991
1992 /// ActOnBlockStart - This callback is invoked when a block literal is
1993 /// started.
Steve Naroff090276f2008-10-10 01:28:17 +00001994 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
Sebastian Redlf53597f2009-03-15 17:47:39 +00001995
Steve Naroff090276f2008-10-10 01:28:17 +00001996 /// ActOnBlockArguments - This callback allows processing of block arguments.
1997 /// If there are no arguments, this is still invoked.
Mike Stump98eb8a72009-02-04 22:31:32 +00001998 virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
Sebastian Redlf53597f2009-03-15 17:47:39 +00001999
Steve Naroff4eb206b2008-09-03 18:15:37 +00002000 /// ActOnBlockError - If there is an error parsing a block, this callback
2001 /// is invoked to pop the information about the block from the action impl.
2002 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
Sebastian Redlf53597f2009-03-15 17:47:39 +00002003
Steve Naroff4eb206b2008-09-03 18:15:37 +00002004 /// ActOnBlockStmtExpr - This is called when the body of a block statement
2005 /// literal was successfully completed. ^(int x){...}
Sebastian Redlf53597f2009-03-15 17:47:39 +00002006 virtual OwningExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc,
2007 StmtArg Body, Scope *CurScope);
Steve Naroff4eb206b2008-09-03 18:15:37 +00002008
Chris Lattner76a642f2009-02-15 22:43:40 +00002009 //===---------------------------- C++ Features --------------------------===//
2010
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +00002011 // Act on C++ namespaces
Chris Lattnerb28317a2009-03-28 19:18:32 +00002012 virtual DeclPtrTy ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
2013 IdentifierInfo *Ident,
Anders Carlsson2a3503d2010-02-07 01:09:23 +00002014 SourceLocation LBrace,
2015 AttributeList *AttrList);
Chris Lattnerb28317a2009-03-28 19:18:32 +00002016 virtual void ActOnFinishNamespaceDef(DeclPtrTy Dcl, SourceLocation RBrace);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +00002017
Chris Lattnerb28317a2009-03-28 19:18:32 +00002018 virtual DeclPtrTy ActOnUsingDirective(Scope *CurScope,
2019 SourceLocation UsingLoc,
2020 SourceLocation NamespcLoc,
2021 const CXXScopeSpec &SS,
2022 SourceLocation IdentLoc,
2023 IdentifierInfo *NamespcName,
2024 AttributeList *AttrList);
Mike Stump1eb44332009-09-09 15:08:12 +00002025
Douglas Gregor2a3009a2009-02-03 19:21:40 +00002026 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
2027
Chris Lattnerb28317a2009-03-28 19:18:32 +00002028 virtual DeclPtrTy ActOnNamespaceAliasDef(Scope *CurScope,
Anders Carlsson03bd5a12009-03-28 22:53:22 +00002029 SourceLocation NamespaceLoc,
Chris Lattnerb28317a2009-03-28 19:18:32 +00002030 SourceLocation AliasLoc,
2031 IdentifierInfo *Alias,
2032 const CXXScopeSpec &SS,
Anders Carlsson03bd5a12009-03-28 22:53:22 +00002033 SourceLocation IdentLoc,
2034 IdentifierInfo *Ident);
Douglas Gregor9cfbe482009-06-20 00:51:54 +00002035
John McCall9f54ad42009-12-10 09:41:52 +00002036 void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow);
2037 bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target,
2038 const LookupResult &PreviousDecls);
2039 UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD,
2040 NamedDecl *Target);
John McCall604e7f12009-12-08 07:46:18 +00002041
John McCall9f54ad42009-12-10 09:41:52 +00002042 bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
2043 bool isTypeName,
2044 const CXXScopeSpec &SS,
2045 SourceLocation NameLoc,
2046 const LookupResult &Previous);
John McCalled976492009-12-04 22:46:56 +00002047 bool CheckUsingDeclQualifier(SourceLocation UsingLoc,
2048 const CXXScopeSpec &SS,
2049 SourceLocation NameLoc);
2050
John McCall9488ea12009-11-17 05:59:44 +00002051 NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
2052 SourceLocation UsingLoc,
Anders Carlssonc72160b2009-08-28 05:40:36 +00002053 const CXXScopeSpec &SS,
2054 SourceLocation IdentLoc,
2055 DeclarationName Name,
2056 AttributeList *AttrList,
John McCall7ba107a2009-11-18 02:36:19 +00002057 bool IsInstantiation,
2058 bool IsTypeName,
2059 SourceLocation TypenameLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002060
Douglas Gregor9cfbe482009-06-20 00:51:54 +00002061 virtual DeclPtrTy ActOnUsingDeclaration(Scope *CurScope,
Anders Carlsson595adc12009-08-29 19:54:19 +00002062 AccessSpecifier AS,
John McCall60fa3cf2009-12-11 02:10:03 +00002063 bool HasUsingKeyword,
Anders Carlssonc72160b2009-08-28 05:40:36 +00002064 SourceLocation UsingLoc,
2065 const CXXScopeSpec &SS,
Douglas Gregor12c118a2009-11-04 16:30:06 +00002066 UnqualifiedId &Name,
Anders Carlssonc72160b2009-08-28 05:40:36 +00002067 AttributeList *AttrList,
John McCall7ba107a2009-11-18 02:36:19 +00002068 bool IsTypeName,
2069 SourceLocation TypenameLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002070
2071 /// AddCXXDirectInitializerToDecl - This action is called immediately after
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +00002072 /// ActOnDeclarator, when a C++ direct initializer is present.
2073 /// e.g: "int x(1);"
Chris Lattnerb28317a2009-03-28 19:18:32 +00002074 virtual void AddCXXDirectInitializerToDecl(DeclPtrTy Dcl,
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +00002075 SourceLocation LParenLoc,
Sebastian Redlf53597f2009-03-15 17:47:39 +00002076 MultiExprArg Exprs,
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +00002077 SourceLocation *CommaLocs,
2078 SourceLocation RParenLoc);
2079
Anders Carlsson49d44012009-04-24 05:16:06 +00002080 /// InitializeVarWithConstructor - Creates an CXXConstructExpr
2081 /// and sets it as the initializer for the the passed in VarDecl.
Mike Stump1eb44332009-09-09 15:08:12 +00002082 bool InitializeVarWithConstructor(VarDecl *VD,
Anders Carlsson930e8d02009-04-16 23:50:50 +00002083 CXXConstructorDecl *Constructor,
Anders Carlssonf47511a2009-09-07 22:23:31 +00002084 MultiExprArg Exprs);
Anders Carlsson9abf2ae2009-08-16 05:13:48 +00002085
Anders Carlssonec8e5ea2009-09-05 07:40:38 +00002086 /// BuildCXXConstructExpr - Creates a complete call to a constructor,
2087 /// including handling of its default argument expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00002088 OwningExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc,
Anders Carlssonec8e5ea2009-09-05 07:40:38 +00002089 QualType DeclInitType,
Anders Carlssonda3f4e22009-08-25 05:12:04 +00002090 CXXConstructorDecl *Constructor,
Douglas Gregor16006c92009-12-16 18:50:27 +00002091 MultiExprArg Exprs,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +00002092 bool RequiresZeroInit = false,
2093 bool BaseInitialization = false);
Anders Carlsson9abf2ae2009-08-16 05:13:48 +00002094
Anders Carlssonec8e5ea2009-09-05 07:40:38 +00002095 // FIXME: Can re remove this and have the above BuildCXXConstructExpr check if
2096 // the constructor can be elidable?
Mike Stump1eb44332009-09-09 15:08:12 +00002097 OwningExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc,
Anders Carlssonec8e5ea2009-09-05 07:40:38 +00002098 QualType DeclInitType,
Anders Carlssonda3f4e22009-08-25 05:12:04 +00002099 CXXConstructorDecl *Constructor,
2100 bool Elidable,
Douglas Gregor16006c92009-12-16 18:50:27 +00002101 MultiExprArg Exprs,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +00002102 bool RequiresZeroInit = false,
2103 bool BaseInitialization = false);
Mike Stump1eb44332009-09-09 15:08:12 +00002104
Anders Carlsson0aebc812009-09-09 21:33:21 +00002105 OwningExprResult BuildCXXCastArgument(SourceLocation CastLoc,
2106 QualType Ty,
2107 CastExpr::CastKind Kind,
2108 CXXMethodDecl *Method,
2109 ExprArg Arg);
2110
Anders Carlsson56c5e332009-08-25 03:49:14 +00002111 /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating
2112 /// the default expr if needed.
2113 OwningExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc,
2114 FunctionDecl *FD,
2115 ParmVarDecl *Param);
Mike Stump1eb44332009-09-09 15:08:12 +00002116
Fariborz Jahaniana83f7ed2009-08-03 19:13:25 +00002117 /// FinalizeVarWithDestructor - Prepare for calling destructor on the
2118 /// constructed variable.
John McCall68c6c9a2010-02-02 09:10:11 +00002119 void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
Mike Stump1eb44332009-09-09 15:08:12 +00002120
2121 /// DefineImplicitDefaultConstructor - Checks for feasibility of
Fariborz Jahanianf8dcb862009-06-19 19:55:27 +00002122 /// defining this constructor as the default constructor.
2123 void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
2124 CXXConstructorDecl *Constructor);
Mike Stump1eb44332009-09-09 15:08:12 +00002125
2126 /// DefineImplicitDestructor - Checks for feasibility of
Fariborz Jahanian8d2b3562009-06-26 23:49:16 +00002127 /// defining this destructor as the default destructor.
2128 void DefineImplicitDestructor(SourceLocation CurrentLocation,
2129 CXXDestructorDecl *Destructor);
Mike Stump1eb44332009-09-09 15:08:12 +00002130
2131 /// DefineImplicitCopyConstructor - Checks for feasibility of
Fariborz Jahanian485f0872009-06-22 23:34:40 +00002132 /// defining this constructor as the copy constructor.
2133 void DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
2134 CXXConstructorDecl *Constructor,
2135 unsigned TypeQuals);
Mike Stump1eb44332009-09-09 15:08:12 +00002136
Fariborz Jahanianc75bc2d2009-06-25 21:45:19 +00002137 /// DefineImplicitOverloadedAssign - Checks for feasibility of
2138 /// defining implicit this overloaded assignment operator.
Mike Stump1eb44332009-09-09 15:08:12 +00002139 void DefineImplicitOverloadedAssign(SourceLocation CurrentLocation,
Fariborz Jahanianc75bc2d2009-06-25 21:45:19 +00002140 CXXMethodDecl *MethodDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00002141
Fariborz Jahanianc75bc2d2009-06-25 21:45:19 +00002142 /// getAssignOperatorMethod - Returns the default copy assignmment operator
2143 /// for the class.
Anders Carlssonb6cc91b2009-12-09 03:01:51 +00002144 CXXMethodDecl *getAssignOperatorMethod(SourceLocation CurrentLocation,
2145 ParmVarDecl *Decl,
Mike Stump1eb44332009-09-09 15:08:12 +00002146 CXXRecordDecl *ClassDecl);
Anders Carlssondef11992009-05-30 20:36:53 +00002147
2148 /// MaybeBindToTemporary - If the passed in expression has a record type with
2149 /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise
2150 /// it simply returns the passed in expression.
2151 OwningExprResult MaybeBindToTemporary(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +00002152
Douglas Gregor18fe5682008-11-03 20:45:27 +00002153 CXXConstructorDecl *
Douglas Gregor19aeac62009-11-14 03:27:21 +00002154 TryInitializationByConstructor(QualType ClassType,
2155 Expr **Args, unsigned NumArgs,
2156 SourceLocation Loc,
2157 InitializationKind Kind);
Douglas Gregor18fe5682008-11-03 20:45:27 +00002158
Douglas Gregor39da0b82009-09-09 23:08:42 +00002159 bool CompleteConstructorCall(CXXConstructorDecl *Constructor,
2160 MultiExprArg ArgsPtr,
2161 SourceLocation Loc,
2162 ASTOwningVector<&ActionBase::DeleteExpr> &ConvertedArgs);
2163
Douglas Gregor124b8782010-02-16 19:09:40 +00002164 virtual TypeTy *getDestructorName(SourceLocation TildeLoc,
2165 IdentifierInfo &II, SourceLocation NameLoc,
2166 Scope *S, const CXXScopeSpec &SS,
2167 TypeTy *ObjectType,
2168 bool EnteringContext);
2169
Douglas Gregor49badde2008-10-27 19:41:14 +00002170 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
Sebastian Redlf53597f2009-03-15 17:47:39 +00002171 virtual OwningExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
2172 tok::TokenKind Kind,
2173 SourceLocation LAngleBracketLoc,
2174 TypeTy *Ty,
2175 SourceLocation RAngleBracketLoc,
2176 SourceLocation LParenLoc,
2177 ExprArg E,
2178 SourceLocation RParenLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002179
John McCallc89724c2010-01-15 19:13:16 +00002180 OwningExprResult BuildCXXNamedCast(SourceLocation OpLoc,
2181 tok::TokenKind Kind,
2182 TypeSourceInfo *Ty,
2183 ExprArg E,
2184 SourceRange AngleBrackets,
2185 SourceRange Parens);
2186
Sebastian Redlf53597f2009-03-15 17:47:39 +00002187 /// ActOnCXXTypeid - Parse typeid( something ).
2188 virtual OwningExprResult ActOnCXXTypeid(SourceLocation OpLoc,
2189 SourceLocation LParenLoc, bool isType,
2190 void *TyOrExpr,
2191 SourceLocation RParenLoc);
Sebastian Redlc42e1182008-11-11 11:37:55 +00002192
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00002193 //// ActOnCXXThis - Parse 'this' pointer.
Sebastian Redlf53597f2009-03-15 17:47:39 +00002194 virtual OwningExprResult ActOnCXXThis(SourceLocation ThisLoc);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00002195
Steve Naroff1b273c42007-09-16 14:56:35 +00002196 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
Sebastian Redlf53597f2009-03-15 17:47:39 +00002197 virtual OwningExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
2198 tok::TokenKind Kind);
2199
Sebastian Redl6e8ed162009-05-10 18:38:11 +00002200 /// ActOnCXXNullPtrLiteral - Parse 'nullptr'.
2201 virtual OwningExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc);
2202
Chris Lattner50dd2892008-02-26 00:51:44 +00002203 //// ActOnCXXThrow - Parse throw expressions.
Sebastian Redlf53597f2009-03-15 17:47:39 +00002204 virtual OwningExprResult ActOnCXXThrow(SourceLocation OpLoc,
2205 ExprArg expr);
Sebastian Redl972041f2009-04-27 20:27:31 +00002206 bool CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E);
Chris Lattner50dd2892008-02-26 00:51:44 +00002207
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00002208 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
2209 /// Can be interpreted either as function-style casting ("int(x)")
2210 /// or class type construction ("ClassType(x,y,z)")
2211 /// or creation of a value-initialized type ("int()").
Sebastian Redlf53597f2009-03-15 17:47:39 +00002212 virtual OwningExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
2213 TypeTy *TypeRep,
2214 SourceLocation LParenLoc,
2215 MultiExprArg Exprs,
2216 SourceLocation *CommaLocs,
2217 SourceLocation RParenLoc);
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00002218
Sebastian Redl4c5d3202008-11-21 19:14:01 +00002219 /// ActOnCXXNew - Parsed a C++ 'new' expression.
Sebastian Redlf53597f2009-03-15 17:47:39 +00002220 virtual OwningExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
2221 SourceLocation PlacementLParen,
2222 MultiExprArg PlacementArgs,
2223 SourceLocation PlacementRParen,
2224 bool ParenTypeId, Declarator &D,
2225 SourceLocation ConstructorLParen,
2226 MultiExprArg ConstructorArgs,
2227 SourceLocation ConstructorRParen);
Douglas Gregor3433cf72009-05-21 00:00:09 +00002228 OwningExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
2229 SourceLocation PlacementLParen,
2230 MultiExprArg PlacementArgs,
2231 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00002232 bool ParenTypeId,
Douglas Gregor3433cf72009-05-21 00:00:09 +00002233 QualType AllocType,
2234 SourceLocation TypeLoc,
2235 SourceRange TypeRange,
2236 ExprArg ArraySize,
2237 SourceLocation ConstructorLParen,
2238 MultiExprArg ConstructorArgs,
2239 SourceLocation ConstructorRParen);
Mike Stump1eb44332009-09-09 15:08:12 +00002240
Douglas Gregor3433cf72009-05-21 00:00:09 +00002241 bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
2242 SourceRange R);
Sebastian Redl00e68e22009-02-09 18:24:27 +00002243 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
2244 bool UseGlobal, QualType AllocType, bool IsArray,
Sebastian Redlb5a57a62008-12-03 20:26:15 +00002245 Expr **PlaceArgs, unsigned NumPlaceArgs,
2246 FunctionDecl *&OperatorNew,
2247 FunctionDecl *&OperatorDelete);
Sebastian Redl00e68e22009-02-09 18:24:27 +00002248 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
2249 DeclarationName Name, Expr** Args,
2250 unsigned NumArgs, DeclContext *Ctx,
Sebastian Redl7f662392008-12-04 22:20:51 +00002251 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlb5a57a62008-12-03 20:26:15 +00002252 void DeclareGlobalNewDelete();
2253 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
Nuno Lopesfc284482009-12-16 16:59:22 +00002254 QualType Argument,
2255 bool addMallocAttr = false);
Sebastian Redl4c5d3202008-11-21 19:14:01 +00002256
Anders Carlsson78f74552009-11-15 18:45:20 +00002257 bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
Anders Carlsson5ec02ae2009-12-02 17:15:43 +00002258 DeclarationName Name, FunctionDecl* &Operator);
Anders Carlsson78f74552009-11-15 18:45:20 +00002259
Sebastian Redl4c5d3202008-11-21 19:14:01 +00002260 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
Sebastian Redlf53597f2009-03-15 17:47:39 +00002261 virtual OwningExprResult ActOnCXXDelete(SourceLocation StartLoc,
2262 bool UseGlobal, bool ArrayForm,
2263 ExprArg Operand);
Sebastian Redl4c5d3202008-11-21 19:14:01 +00002264
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00002265 virtual DeclResult ActOnCXXConditionDeclaration(Scope *S,
2266 Declarator &D);
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00002267 OwningExprResult CheckConditionVariable(VarDecl *ConditionVar);
2268
Sebastian Redl64b45f72009-01-05 20:52:13 +00002269 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
2270 /// pseudo-functions.
2271 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
2272 SourceLocation KWLoc,
2273 SourceLocation LParen,
2274 TypeTy *Ty,
2275 SourceLocation RParen);
Mike Stump1eb44332009-09-09 15:08:12 +00002276
Douglas Gregor2dd078a2009-09-02 22:59:36 +00002277 virtual OwningExprResult ActOnStartCXXMemberReference(Scope *S,
2278 ExprArg Base,
2279 SourceLocation OpLoc,
2280 tok::TokenKind OpKind,
Douglas Gregord4dca082010-02-24 18:44:31 +00002281 TypeTy *&ObjectType,
2282 bool &MayBePseudoDestructor);
2283
Douglas Gregor77549082010-02-24 21:29:12 +00002284 OwningExprResult DiagnoseDtorReference(SourceLocation NameLoc,
2285 ExprArg MemExpr);
2286
Douglas Gregorb57fb492010-02-24 22:38:50 +00002287 OwningExprResult BuildPseudoDestructorExpr(ExprArg Base,
2288 SourceLocation OpLoc,
2289 tok::TokenKind OpKind,
2290 const CXXScopeSpec &SS,
2291 TypeSourceInfo *ScopeType,
2292 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00002293 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00002294 PseudoDestructorTypeStorage DestroyedType,
Douglas Gregorb57fb492010-02-24 22:38:50 +00002295 bool HasTrailingLParen);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00002296
Douglas Gregord4dca082010-02-24 18:44:31 +00002297 virtual OwningExprResult ActOnPseudoDestructorExpr(Scope *S, ExprArg Base,
2298 SourceLocation OpLoc,
2299 tok::TokenKind OpKind,
2300 const CXXScopeSpec &SS,
2301 UnqualifiedId &FirstTypeName,
2302 SourceLocation CCLoc,
2303 SourceLocation TildeLoc,
2304 UnqualifiedId &SecondTypeName,
2305 bool HasTrailingLParen);
Douglas Gregor77549082010-02-24 21:29:12 +00002306
Mike Stump1eb44332009-09-09 15:08:12 +00002307 /// MaybeCreateCXXExprWithTemporaries - If the list of temporaries is
Anders Carlsson99ba36d2009-06-05 15:38:08 +00002308 /// non-empty, will create a new CXXExprWithTemporaries expression.
2309 /// Otherwise, just returs the passed in expression.
Anders Carlsson0ece4912009-12-15 20:51:39 +00002310 Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr);
Douglas Gregor90f93822009-12-22 22:17:25 +00002311 OwningExprResult MaybeCreateCXXExprWithTemporaries(OwningExprResult SubExpr);
Anders Carlsson5ee56e92009-12-16 02:09:40 +00002312 FullExpr CreateFullExpr(Expr *SubExpr);
2313
Anders Carlsson165a0a02009-05-17 18:41:29 +00002314 virtual OwningExprResult ActOnFinishFullExpr(ExprArg Expr);
2315
Douglas Gregor4fdf1fa2009-03-11 16:48:53 +00002316 bool RequireCompleteDeclContext(const CXXScopeSpec &SS);
Mike Stump1eb44332009-09-09 15:08:12 +00002317
Douglas Gregor2dd078a2009-09-02 22:59:36 +00002318 DeclContext *computeDeclContext(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +00002319 DeclContext *computeDeclContext(const CXXScopeSpec &SS,
Douglas Gregorf59a56e2009-07-21 23:53:31 +00002320 bool EnteringContext = false);
Douglas Gregor5953d8b2009-03-19 17:26:29 +00002321 bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
Douglas Gregor42af25f2009-05-11 19:58:34 +00002322 CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS);
2323 bool isUnknownSpecialization(const CXXScopeSpec &SS);
Douglas Gregorca5e77f2009-03-18 00:36:05 +00002324
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00002325 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
2326 /// global scope ('::').
2327 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
2328 SourceLocation CCLoc);
2329
Douglas Gregoredc90502010-02-25 04:46:04 +00002330 bool isAcceptableNestedNameSpecifier(NamedDecl *SD);
Douglas Gregorc68afe22009-09-03 21:38:09 +00002331 NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS);
Mike Stump1eb44332009-09-09 15:08:12 +00002332
Douglas Gregor77549082010-02-24 21:29:12 +00002333 virtual bool isNonTypeNestedNameSpecifier(Scope *S, const CXXScopeSpec &SS,
2334 SourceLocation IdLoc,
2335 IdentifierInfo &II,
2336 TypeTy *ObjectType);
2337
Douglas Gregorc68afe22009-09-03 21:38:09 +00002338 CXXScopeTy *BuildCXXNestedNameSpecifier(Scope *S,
2339 const CXXScopeSpec &SS,
2340 SourceLocation IdLoc,
2341 SourceLocation CCLoc,
2342 IdentifierInfo &II,
2343 QualType ObjectType,
2344 NamedDecl *ScopeLookupResult,
Chris Lattner46646492009-12-07 01:36:53 +00002345 bool EnteringContext,
2346 bool ErrorRecoveryLookup);
Mike Stump1eb44332009-09-09 15:08:12 +00002347
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00002348 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
2349 const CXXScopeSpec &SS,
2350 SourceLocation IdLoc,
2351 SourceLocation CCLoc,
Douglas Gregor495c35d2009-08-25 22:51:20 +00002352 IdentifierInfo &II,
Douglas Gregor2dd078a2009-09-02 22:59:36 +00002353 TypeTy *ObjectType,
Douglas Gregor495c35d2009-08-25 22:51:20 +00002354 bool EnteringContext);
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00002355
Chris Lattner46646492009-12-07 01:36:53 +00002356 virtual bool IsInvalidUnlessNestedName(Scope *S,
2357 const CXXScopeSpec &SS,
2358 IdentifierInfo &II,
2359 TypeTy *ObjectType,
2360 bool EnteringContext);
2361
Douglas Gregor39a8de12009-02-25 19:37:18 +00002362 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
2363 /// nested-name-specifier that involves a template-id, e.g.,
2364 /// "foo::bar<int, float>::", and now we need to build a scope
2365 /// specifier. \p SS is empty or the previously parsed nested-name
2366 /// part ("foo::"), \p Type is the already-parsed class template
2367 /// specialization (or other template-id that names a type), \p
2368 /// TypeRange is the source range where the type is located, and \p
2369 /// CCLoc is the location of the trailing '::'.
2370 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
2371 const CXXScopeSpec &SS,
2372 TypeTy *Type,
2373 SourceRange TypeRange,
Douglas Gregoredc90502010-02-25 04:46:04 +00002374 SourceLocation CCLoc);
Douglas Gregor39a8de12009-02-25 19:37:18 +00002375
John McCalle7e278b2009-12-11 20:04:54 +00002376 virtual bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
2377
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00002378 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
2379 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
2380 /// After this method is called, according to [C++ 3.4.3p3], names should be
2381 /// looked up in the declarator-id's scope, until the declarator is parsed and
2382 /// ActOnCXXExitDeclaratorScope is called.
2383 /// The 'SS' should be a non-empty valid CXXScopeSpec.
Douglas Gregor7dfd0fb2009-09-24 23:39:01 +00002384 virtual bool ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00002385
2386 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
2387 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
2388 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
2389 /// Used to indicate that names should revert to being looked up in the
2390 /// defining scope.
Douglas Gregor0a59acb2008-12-16 00:38:16 +00002391 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00002392
Argyrios Kyrtzidis0ffd9ff2009-06-17 22:50:06 +00002393 /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an
2394 /// initializer for the declaration 'Dcl'.
2395 /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a
2396 /// static data member of class X, names should be looked up in the scope of
2397 /// class X.
2398 virtual void ActOnCXXEnterDeclInitializer(Scope *S, DeclPtrTy Dcl);
2399
2400 /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an
2401 /// initializer for the declaration 'Dcl'.
2402 virtual void ActOnCXXExitDeclInitializer(Scope *S, DeclPtrTy Dcl);
2403
Anders Carlsson55085182007-08-21 17:43:55 +00002404 // ParseObjCStringLiteral - Parse Objective-C string literals.
Mike Stump1eb44332009-09-09 15:08:12 +00002405 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00002406 ExprTy **Strings,
2407 unsigned NumStrings);
Mike Stump1eb44332009-09-09 15:08:12 +00002408
2409 Expr *BuildObjCEncodeExpression(SourceLocation AtLoc,
Anders Carlssonfc0f0212009-06-07 18:45:35 +00002410 QualType EncodedType,
Mike Stump1eb44332009-09-09 15:08:12 +00002411 SourceLocation RParenLoc);
Fariborz Jahanianb7400232009-09-28 23:23:40 +00002412 CXXMemberCallExpr *BuildCXXMemberCallExpr(Expr *Exp, CXXMethodDecl *Method);
2413
Anders Carlssonf9bcf012007-08-22 15:14:15 +00002414 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner674af952007-10-16 22:51:17 +00002415 SourceLocation EncodeLoc,
Anders Carlssonf9bcf012007-08-22 15:14:15 +00002416 SourceLocation LParenLoc,
2417 TypeTy *Ty,
2418 SourceLocation RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002419
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00002420 // ParseObjCSelectorExpression - Build selector expression for @selector
2421 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
2422 SourceLocation AtLoc,
Fariborz Jahanian2a35fa92007-10-16 23:21:02 +00002423 SourceLocation SelLoc,
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00002424 SourceLocation LParenLoc,
2425 SourceLocation RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002426
Fariborz Jahanian390d50a2007-10-17 16:58:11 +00002427 // ParseObjCProtocolExpression - Build protocol expression for @protocol
2428 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
2429 SourceLocation AtLoc,
2430 SourceLocation ProtoLoc,
2431 SourceLocation LParenLoc,
2432 SourceLocation RParenLoc);
Douglas Gregore37ac4f2008-04-13 21:30:24 +00002433
2434 //===--------------------------------------------------------------------===//
Douglas Gregor074149e2009-01-05 19:45:36 +00002435 // C++ Declarations
2436 //
Chris Lattnerb28317a2009-03-28 19:18:32 +00002437 virtual DeclPtrTy ActOnStartLinkageSpecification(Scope *S,
2438 SourceLocation ExternLoc,
2439 SourceLocation LangLoc,
2440 const char *Lang,
2441 unsigned StrSize,
2442 SourceLocation LBraceLoc);
2443 virtual DeclPtrTy ActOnFinishLinkageSpecification(Scope *S,
2444 DeclPtrTy LinkageSpec,
2445 SourceLocation RBraceLoc);
Douglas Gregor074149e2009-01-05 19:45:36 +00002446
2447
2448 //===--------------------------------------------------------------------===//
Douglas Gregore37ac4f2008-04-13 21:30:24 +00002449 // C++ Classes
2450 //
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00002451 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
2452 const CXXScopeSpec *SS);
Sebastian Redle2b68332009-04-12 17:16:29 +00002453
Chris Lattnerb28317a2009-03-28 19:18:32 +00002454 virtual DeclPtrTy ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
2455 Declarator &D,
Douglas Gregor37b372b2009-08-20 22:52:58 +00002456 MultiTemplateParamsArg TemplateParameterLists,
Chris Lattnerb28317a2009-03-28 19:18:32 +00002457 ExprTy *BitfieldWidth,
Sebastian Redld1a78462009-11-24 23:38:44 +00002458 ExprTy *Init, bool IsDefinition,
Sebastian Redle2b68332009-04-12 17:16:29 +00002459 bool Deleted = false);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00002460
Chris Lattnerb28317a2009-03-28 19:18:32 +00002461 virtual MemInitResult ActOnMemInitializer(DeclPtrTy ConstructorD,
Douglas Gregor7ad83902008-11-05 04:29:56 +00002462 Scope *S,
Fariborz Jahanianbcfad542009-06-30 23:26:25 +00002463 const CXXScopeSpec &SS,
Douglas Gregor7ad83902008-11-05 04:29:56 +00002464 IdentifierInfo *MemberOrBase,
Fariborz Jahanian96174332009-07-01 19:21:19 +00002465 TypeTy *TemplateTypeTy,
Douglas Gregor7ad83902008-11-05 04:29:56 +00002466 SourceLocation IdLoc,
2467 SourceLocation LParenLoc,
2468 ExprTy **Args, unsigned NumArgs,
2469 SourceLocation *CommaLocs,
2470 SourceLocation RParenLoc);
2471
Eli Friedman59c04372009-07-29 19:44:27 +00002472 MemInitResult BuildMemberInitializer(FieldDecl *Member, Expr **Args,
2473 unsigned NumArgs, SourceLocation IdLoc,
Douglas Gregor802ab452009-12-02 22:36:29 +00002474 SourceLocation LParenLoc,
Eli Friedman59c04372009-07-29 19:44:27 +00002475 SourceLocation RParenLoc);
2476
Douglas Gregor802ab452009-12-02 22:36:29 +00002477 MemInitResult BuildBaseInitializer(QualType BaseType,
John McCalla93c9342009-12-07 02:54:59 +00002478 TypeSourceInfo *BaseTInfo,
Douglas Gregor802ab452009-12-02 22:36:29 +00002479 Expr **Args, unsigned NumArgs,
2480 SourceLocation LParenLoc,
Eli Friedman59c04372009-07-29 19:44:27 +00002481 SourceLocation RParenLoc,
2482 CXXRecordDecl *ClassDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00002483
Benjamin Kramer3f17a372009-11-09 20:14:44 +00002484 bool SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +00002485 CXXBaseOrMemberInitializer **Initializers,
2486 unsigned NumInitializers,
2487 bool IsImplicitConstructor,
2488 bool AnyErrors);
Mike Stump1eb44332009-09-09 15:08:12 +00002489
John McCallef027fe2010-03-16 21:39:52 +00002490 /// MarkBaseAndMemberDestructorsReferenced - Given a record decl,
2491 /// mark all the non-trivial destructors of its members and bases as
2492 /// referenced.
2493 void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
2494 CXXRecordDecl *Record);
Mike Stump1eb44332009-09-09 15:08:12 +00002495
Anders Carlssond6a637f2009-12-07 08:24:59 +00002496 /// ClassesWithUnmarkedVirtualMembers - Contains record decls whose virtual
Douglas Gregor159ef1e2010-01-06 04:44:19 +00002497 /// members need to be marked as referenced at the end of the translation
2498 /// unit. It will contain polymorphic classes that do not have a key
2499 /// function or have a key function that has been defined.
2500 llvm::SmallVector<std::pair<CXXRecordDecl *, SourceLocation>, 4>
2501 ClassesWithUnmarkedVirtualMembers;
Anders Carlssond6a637f2009-12-07 08:24:59 +00002502
2503 /// MaybeMarkVirtualMembersReferenced - If the passed in method is the
Anders Carlsson5ec02ae2009-12-02 17:15:43 +00002504 /// key function of the record decl, will mark virtual member functions as
2505 /// referenced.
Anders Carlssond6a637f2009-12-07 08:24:59 +00002506 void MaybeMarkVirtualMembersReferenced(SourceLocation Loc, CXXMethodDecl *MD);
2507
2508 /// MarkVirtualMembersReferenced - Will mark all virtual members of the given
2509 /// CXXRecordDecl referenced.
2510 void MarkVirtualMembersReferenced(SourceLocation Loc, CXXRecordDecl *RD);
2511
2512 /// ProcessPendingClassesWithUnmarkedVirtualMembers - Will process classes
2513 /// that might need to have their virtual members marked as referenced.
2514 /// Returns false if no work was done.
2515 bool ProcessPendingClassesWithUnmarkedVirtualMembers();
Anders Carlsson5ec02ae2009-12-02 17:15:43 +00002516
Douglas Gregor396b7cd2008-11-03 17:51:48 +00002517 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
2518
Mike Stump1eb44332009-09-09 15:08:12 +00002519 virtual void ActOnMemInitializers(DeclPtrTy ConstructorDecl,
Anders Carlssona7b35212009-03-25 02:58:17 +00002520 SourceLocation ColonLoc,
Douglas Gregor9db7dbb2010-01-31 09:12:51 +00002521 MemInitTy **MemInits, unsigned NumMemInits,
2522 bool AnyErrors);
Mike Stump1eb44332009-09-09 15:08:12 +00002523
Douglas Gregor1ab537b2009-12-03 18:33:45 +00002524 void CheckCompletedCXXClass(CXXRecordDecl *Record);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00002525 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
Chris Lattnerb28317a2009-03-28 19:18:32 +00002526 DeclPtrTy TagDecl,
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00002527 SourceLocation LBrac,
2528 SourceLocation RBrac);
2529
Douglas Gregor6569d682009-05-27 23:11:45 +00002530 virtual void ActOnReenterTemplateScope(Scope *S, DeclPtrTy Template);
John McCall7a1dc562009-12-19 10:49:29 +00002531 virtual void ActOnStartDelayedMemberDeclarations(Scope *S,
2532 DeclPtrTy Record);
Chris Lattnerb28317a2009-03-28 19:18:32 +00002533 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S,
2534 DeclPtrTy Method);
2535 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy Param);
2536 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S,
2537 DeclPtrTy Method);
John McCall7a1dc562009-12-19 10:49:29 +00002538 virtual void ActOnFinishDelayedMemberDeclarations(Scope *S,
2539 DeclPtrTy Record);
Douglas Gregor72b505b2008-12-16 21:30:33 +00002540
Mike Stump1eb44332009-09-09 15:08:12 +00002541 virtual DeclPtrTy ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
Chris Lattnerb28317a2009-03-28 19:18:32 +00002542 ExprArg AssertExpr,
2543 ExprArg AssertMessageExpr);
Mike Stump1eb44332009-09-09 15:08:12 +00002544
John McCalldd4a3b02009-09-16 22:47:08 +00002545 DeclPtrTy ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS,
2546 MultiTemplateParamsArg TemplateParams);
John McCallbbbcdd92009-09-11 21:02:39 +00002547 DeclPtrTy ActOnFriendFunctionDecl(Scope *S, Declarator &D, bool IsDefinition,
2548 MultiTemplateParamsArg TemplateParams);
Anders Carlsson00338362009-05-11 22:55:49 +00002549
Chris Lattner65401802009-04-25 08:28:21 +00002550 QualType CheckConstructorDeclarator(Declarator &D, QualType R,
2551 FunctionDecl::StorageClass& SC);
Chris Lattner6e475012009-04-25 08:35:12 +00002552 void CheckConstructor(CXXConstructorDecl *Constructor);
Chris Lattner65401802009-04-25 08:28:21 +00002553 QualType CheckDestructorDeclarator(Declarator &D,
2554 FunctionDecl::StorageClass& SC);
Anders Carlsson5ec02ae2009-12-02 17:15:43 +00002555 bool CheckDestructor(CXXDestructorDecl *Destructor);
Chris Lattner6e475012009-04-25 08:35:12 +00002556 void CheckConversionDeclarator(Declarator &D, QualType &R,
Douglas Gregor2f1bc522008-11-07 20:08:42 +00002557 FunctionDecl::StorageClass& SC);
Chris Lattnerb28317a2009-03-28 19:18:32 +00002558 DeclPtrTy ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregore961afb2009-10-22 07:08:30 +00002559
Douglas Gregorbc0805a2008-10-23 00:40:37 +00002560 //===--------------------------------------------------------------------===//
2561 // C++ Derived Classes
2562 //
2563
2564 /// ActOnBaseSpecifier - Parsed a base specifier
Douglas Gregor2943aed2009-03-03 04:44:36 +00002565 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
2566 SourceRange SpecifierRange,
2567 bool Virtual, AccessSpecifier Access,
Mike Stump1eb44332009-09-09 15:08:12 +00002568 QualType BaseType,
Douglas Gregor2943aed2009-03-03 04:44:36 +00002569 SourceLocation BaseLoc);
Anders Carlsson51f94042009-12-03 17:49:57 +00002570
2571 /// SetClassDeclAttributesFromBase - Copies class decl traits
2572 /// (such as whether the class has a trivial constructor,
2573 /// trivial destructor etc) from the given base class.
2574 void SetClassDeclAttributesFromBase(CXXRecordDecl *Class,
2575 const CXXRecordDecl *BaseClass,
2576 bool BaseIsVirtual);
2577
Mike Stump1eb44332009-09-09 15:08:12 +00002578 virtual BaseResult ActOnBaseSpecifier(DeclPtrTy classdecl,
Douglas Gregorbc0805a2008-10-23 00:40:37 +00002579 SourceRange SpecifierRange,
2580 bool Virtual, AccessSpecifier Access,
Mike Stump1eb44332009-09-09 15:08:12 +00002581 TypeTy *basetype, SourceLocation
Douglas Gregor2943aed2009-03-03 04:44:36 +00002582 BaseLoc);
Douglas Gregorbc0805a2008-10-23 00:40:37 +00002583
Douglas Gregor2943aed2009-03-03 04:44:36 +00002584 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
2585 unsigned NumBases);
Mike Stump1eb44332009-09-09 15:08:12 +00002586 virtual void ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases,
Douglas Gregorbc0805a2008-10-23 00:40:37 +00002587 unsigned NumBases);
2588
2589 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregora8f32e02009-10-06 17:59:45 +00002590 bool IsDerivedFrom(QualType Derived, QualType Base, CXXBasePaths &Paths);
2591
Douglas Gregor0575d4a2008-10-24 16:17:19 +00002592 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
Sebastian Redla82e4ae2009-11-14 21:15:49 +00002593 SourceLocation Loc, SourceRange Range,
2594 bool IgnoreAccess = false);
Anders Carlssond8f9cb02009-05-13 21:11:42 +00002595 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
John McCall58e6f342010-03-16 05:22:47 +00002596 unsigned InaccessibleBaseID,
Anders Carlssond8f9cb02009-05-13 21:11:42 +00002597 unsigned AmbigiousBaseConvID,
2598 SourceLocation Loc, SourceRange Range,
2599 DeclarationName Name);
Mike Stump1eb44332009-09-09 15:08:12 +00002600
Douglas Gregora8f32e02009-10-06 17:59:45 +00002601 std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths);
Mike Stump1eb44332009-09-09 15:08:12 +00002602
Sebastian Redl23c7d062009-07-07 20:29:57 +00002603 /// CheckOverridingFunctionReturnType - Checks whether the return types are
2604 /// covariant, according to C++ [class.virtual]p5.
2605 bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New,
Anders Carlssond7ba27d2009-05-14 01:09:04 +00002606 const CXXMethodDecl *Old);
Sebastian Redl23c7d062009-07-07 20:29:57 +00002607
2608 /// CheckOverridingFunctionExceptionSpec - Checks whether the exception
2609 /// spec is a subset of base spec.
2610 bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
2611 const CXXMethodDecl *Old);
Douglas Gregore37ac4f2008-04-13 21:30:24 +00002612
Sean Huntbbd37c62009-11-21 08:43:09 +00002613 /// CheckOverridingFunctionAttributes - Checks whether attributes are
2614 /// incompatible or prevent overriding.
2615 bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
2616 const CXXMethodDecl *Old);
2617
Douglas Gregor4ba31362009-12-01 17:24:26 +00002618 bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
Anders Carlsson29f006b2009-03-27 05:05:05 +00002619 //===--------------------------------------------------------------------===//
2620 // C++ Access Control
2621 //
Sebastian Redl726212f2009-07-18 14:32:15 +00002622
John McCall6b2accb2010-02-10 09:31:12 +00002623 enum AccessResult {
2624 AR_accessible,
2625 AR_inaccessible,
2626 AR_dependent,
2627 AR_delayed
2628 };
2629
Mike Stump1eb44332009-09-09 15:08:12 +00002630 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
Anders Carlsson29f006b2009-03-27 05:05:05 +00002631 NamedDecl *PrevMemberDecl,
2632 AccessSpecifier LexicalAS);
Sebastian Redl726212f2009-07-18 14:32:15 +00002633
John McCall6b2accb2010-02-10 09:31:12 +00002634 AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E,
John McCall9aa472c2010-03-19 07:35:19 +00002635 DeclAccessPair FoundDecl);
John McCall6b2accb2010-02-10 09:31:12 +00002636 AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
John McCall9aa472c2010-03-19 07:35:19 +00002637 DeclAccessPair FoundDecl);
John McCall90c8c572010-03-18 08:19:33 +00002638 AccessResult CheckAllocationAccess(SourceLocation OperatorLoc,
2639 SourceRange PlacementRange,
2640 CXXRecordDecl *NamingClass,
John McCall9aa472c2010-03-19 07:35:19 +00002641 DeclAccessPair FoundDecl);
John McCall6b2accb2010-02-10 09:31:12 +00002642 AccessResult CheckConstructorAccess(SourceLocation Loc,
2643 CXXConstructorDecl *D,
2644 AccessSpecifier Access);
2645 AccessResult CheckDestructorAccess(SourceLocation Loc,
John McCall58e6f342010-03-16 05:22:47 +00002646 CXXDestructorDecl *Dtor,
2647 const PartialDiagnostic &PDiag);
John McCallb0207482010-03-16 06:11:48 +00002648 AccessResult CheckDirectMemberAccess(SourceLocation Loc,
2649 NamedDecl *D,
2650 const PartialDiagnostic &PDiag);
John McCall6b2accb2010-02-10 09:31:12 +00002651 AccessResult CheckMemberOperatorAccess(SourceLocation Loc,
2652 Expr *ObjectExpr,
John McCall58e6f342010-03-16 05:22:47 +00002653 Expr *ArgExpr,
John McCall9aa472c2010-03-19 07:35:19 +00002654 DeclAccessPair FoundDecl);
John McCall6b2accb2010-02-10 09:31:12 +00002655 AccessResult CheckBaseClassAccess(SourceLocation AccessLoc,
John McCall6b2accb2010-02-10 09:31:12 +00002656 QualType Base, QualType Derived,
2657 const CXXBasePath &Path,
John McCall58e6f342010-03-16 05:22:47 +00002658 unsigned DiagID,
John McCall6b2accb2010-02-10 09:31:12 +00002659 bool ForceCheck = false,
John McCall58e6f342010-03-16 05:22:47 +00002660 bool ForceUnprivileged = false);
John McCall6b2accb2010-02-10 09:31:12 +00002661
2662 void CheckLookupAccess(const LookupResult &R);
John McCall92f88312010-01-23 00:46:32 +00002663
John McCall2f514482010-01-27 03:50:35 +00002664 void HandleDelayedAccessCheck(DelayedDiagnostic &DD, Decl *Ctx);
Sebastian Redl726212f2009-07-18 14:32:15 +00002665
Anders Carlsson8211eff2009-03-24 01:19:16 +00002666 enum AbstractDiagSelID {
2667 AbstractNone = -1,
2668 AbstractReturnType,
2669 AbstractParamType,
2670 AbstractVariableType,
2671 AbstractFieldType
2672 };
Mike Stump1eb44332009-09-09 15:08:12 +00002673
Anders Carlssona6ec7ad2009-08-27 00:13:57 +00002674 bool RequireNonAbstractType(SourceLocation Loc, QualType T,
2675 const PartialDiagnostic &PD,
2676 const CXXRecordDecl *CurrentRD = 0);
Mike Stump1eb44332009-09-09 15:08:12 +00002677
2678 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
Anders Carlssone65a3c82009-03-24 17:23:42 +00002679 AbstractDiagSelID SelID = AbstractNone,
2680 const CXXRecordDecl *CurrentRD = 0);
Anders Carlsson4681ebd2009-03-22 20:18:17 +00002681
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +00002682 //===--------------------------------------------------------------------===//
2683 // C++ Overloaded Operators [C++ 13.5]
2684 //
2685
2686 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
2687
Sean Hunta6c058d2010-01-13 09:01:02 +00002688 bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl);
2689
Douglas Gregor72c3f312008-12-05 18:15:24 +00002690 //===--------------------------------------------------------------------===//
2691 // C++ Templates [C++ 14]
2692 //
John McCallf7a1a742009-11-24 19:00:30 +00002693 void LookupTemplateName(LookupResult &R, Scope *S, const CXXScopeSpec &SS,
2694 QualType ObjectType, bool EnteringContext);
2695
Douglas Gregor2dd078a2009-09-02 22:59:36 +00002696 virtual TemplateNameKind isTemplateName(Scope *S,
Douglas Gregor014e88d2009-11-03 23:16:33 +00002697 const CXXScopeSpec &SS,
2698 UnqualifiedId &Name,
Douglas Gregor2dd078a2009-09-02 22:59:36 +00002699 TypeTy *ObjectType,
Douglas Gregor495c35d2009-08-25 22:51:20 +00002700 bool EnteringContext,
2701 TemplateTy &Template);
Douglas Gregor84d0a192010-01-12 21:28:44 +00002702
2703 virtual bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,
2704 SourceLocation IILoc,
2705 Scope *S,
2706 const CXXScopeSpec *SS,
2707 TemplateTy &SuggestedTemplate,
2708 TemplateNameKind &SuggestedKind);
2709
Douglas Gregor72c3f312008-12-05 18:15:24 +00002710 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
Chris Lattnerb28317a2009-03-28 19:18:32 +00002711 TemplateDecl *AdjustDeclIfTemplate(DeclPtrTy &Decl);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00002712
Mike Stump1eb44332009-09-09 15:08:12 +00002713 virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
Anders Carlsson941df7d2009-06-12 19:58:00 +00002714 SourceLocation EllipsisLoc,
Chris Lattnerb28317a2009-03-28 19:18:32 +00002715 SourceLocation KeyLoc,
2716 IdentifierInfo *ParamName,
2717 SourceLocation ParamNameLoc,
2718 unsigned Depth, unsigned Position);
Mike Stump1eb44332009-09-09 15:08:12 +00002719 virtual void ActOnTypeParameterDefault(DeclPtrTy TypeParam,
Douglas Gregord684b002009-02-10 19:49:53 +00002720 SourceLocation EqualLoc,
2721 SourceLocation DefaultLoc,
2722 TypeTy *Default);
2723
Douglas Gregor2943aed2009-03-03 04:44:36 +00002724 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Chris Lattnerb28317a2009-03-28 19:18:32 +00002725 virtual DeclPtrTy ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
2726 unsigned Depth,
2727 unsigned Position);
2728 virtual void ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParam,
Douglas Gregord684b002009-02-10 19:49:53 +00002729 SourceLocation EqualLoc,
2730 ExprArg Default);
Chris Lattnerb28317a2009-03-28 19:18:32 +00002731 virtual DeclPtrTy ActOnTemplateTemplateParameter(Scope *S,
2732 SourceLocation TmpLoc,
2733 TemplateParamsTy *Params,
2734 IdentifierInfo *ParamName,
2735 SourceLocation ParamNameLoc,
2736 unsigned Depth,
2737 unsigned Position);
2738 virtual void ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParam,
Douglas Gregord684b002009-02-10 19:49:53 +00002739 SourceLocation EqualLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002740 const ParsedTemplateArgument &Default);
Douglas Gregord684b002009-02-10 19:49:53 +00002741
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00002742 virtual TemplateParamsTy *
2743 ActOnTemplateParameterList(unsigned Depth,
2744 SourceLocation ExportLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00002745 SourceLocation TemplateLoc,
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00002746 SourceLocation LAngleLoc,
Chris Lattnerb28317a2009-03-28 19:18:32 +00002747 DeclPtrTy *Params, unsigned NumParams,
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00002748 SourceLocation RAngleLoc);
Douglas Gregor5b6d70e2009-11-25 17:50:39 +00002749
2750 /// \brief The context in which we are checking a template parameter
2751 /// list.
2752 enum TemplateParamListContext {
2753 TPC_ClassTemplate,
2754 TPC_FunctionTemplate,
2755 TPC_ClassTemplateMember,
2756 TPC_FriendFunctionTemplate
2757 };
2758
Douglas Gregord684b002009-02-10 19:49:53 +00002759 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
Douglas Gregor5b6d70e2009-11-25 17:50:39 +00002760 TemplateParameterList *OldParams,
2761 TemplateParamListContext TPC);
Douglas Gregorf59a56e2009-07-21 23:53:31 +00002762 TemplateParameterList *
2763 MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
2764 const CXXScopeSpec &SS,
2765 TemplateParameterList **ParamLists,
Douglas Gregor1fef4e62009-10-07 22:35:40 +00002766 unsigned NumParamLists,
2767 bool &IsExplicitSpecialization);
Mike Stump1eb44332009-09-09 15:08:12 +00002768
John McCall0f434ec2009-07-31 02:45:11 +00002769 DeclResult CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
Douglas Gregorbd1099e2009-07-23 16:36:45 +00002770 SourceLocation KWLoc, const CXXScopeSpec &SS,
2771 IdentifierInfo *Name, SourceLocation NameLoc,
2772 AttributeList *Attr,
Douglas Gregor05396e22009-08-25 17:23:04 +00002773 TemplateParameterList *TemplateParams,
Douglas Gregorbd1099e2009-07-23 16:36:45 +00002774 AccessSpecifier AS);
Douglas Gregorddc29e12009-02-06 22:42:48 +00002775
John McCalld5532b62009-11-23 01:53:49 +00002776 void translateTemplateArguments(const ASTTemplateArgsPtr &In,
2777 TemplateArgumentListInfo &Out);
Douglas Gregor0b60d9e2009-09-25 23:53:26 +00002778
Douglas Gregor7532dc62009-03-30 22:58:21 +00002779 QualType CheckTemplateIdType(TemplateName Template,
2780 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +00002781 const TemplateArgumentListInfo &TemplateArgs);
Douglas Gregor40808ce2009-03-09 23:48:35 +00002782
Douglas Gregorcc636682009-02-17 23:15:12 +00002783 virtual TypeResult
Douglas Gregor7532dc62009-03-30 22:58:21 +00002784 ActOnTemplateIdType(TemplateTy Template, SourceLocation TemplateLoc,
2785 SourceLocation LAngleLoc,
2786 ASTTemplateArgsPtr TemplateArgs,
John McCall6b2becf2009-09-08 17:47:29 +00002787 SourceLocation RAngleLoc);
2788
2789 virtual TypeResult ActOnTagTemplateIdType(TypeResult Type,
2790 TagUseKind TUK,
2791 DeclSpec::TST TagSpec,
2792 SourceLocation TagLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002793
John McCallf7a1a742009-11-24 19:00:30 +00002794 OwningExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS,
2795 LookupResult &R,
2796 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00002797 const TemplateArgumentListInfo &TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002798 OwningExprResult BuildQualifiedTemplateIdExpr(const CXXScopeSpec &SS,
2799 DeclarationName Name,
2800 SourceLocation NameLoc,
2801 const TemplateArgumentListInfo &TemplateArgs);
Mike Stump1eb44332009-09-09 15:08:12 +00002802
Douglas Gregorc45c2322009-03-31 00:43:58 +00002803 virtual TemplateTy ActOnDependentTemplateName(SourceLocation TemplateKWLoc,
Douglas Gregor2dd078a2009-09-02 22:59:36 +00002804 const CXXScopeSpec &SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00002805 UnqualifiedId &Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00002806 TypeTy *ObjectType,
2807 bool EnteringContext);
Douglas Gregorc45c2322009-03-31 00:43:58 +00002808
Douglas Gregore94866f2009-06-12 21:21:02 +00002809 bool CheckClassTemplatePartialSpecializationArgs(
2810 TemplateParameterList *TemplateParams,
Anders Carlsson6360be72009-06-13 18:20:51 +00002811 const TemplateArgumentListBuilder &TemplateArgs,
Douglas Gregor6aa75cf2009-06-12 22:08:06 +00002812 bool &MirrorsPrimaryTemplate);
Douglas Gregore94866f2009-06-12 21:21:02 +00002813
Douglas Gregor212e81c2009-03-25 00:13:59 +00002814 virtual DeclResult
John McCall0f434ec2009-07-31 02:45:11 +00002815 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagUseKind TUK,
Mike Stump1eb44332009-09-09 15:08:12 +00002816 SourceLocation KWLoc,
Douglas Gregorcc636682009-02-17 23:15:12 +00002817 const CXXScopeSpec &SS,
Douglas Gregor7532dc62009-03-30 22:58:21 +00002818 TemplateTy Template,
Douglas Gregorcc636682009-02-17 23:15:12 +00002819 SourceLocation TemplateNameLoc,
Douglas Gregor55f6b142009-02-09 18:46:07 +00002820 SourceLocation LAngleLoc,
Douglas Gregor5908e9f2009-02-09 19:34:22 +00002821 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregor55f6b142009-02-09 18:46:07 +00002822 SourceLocation RAngleLoc,
Douglas Gregorcc636682009-02-17 23:15:12 +00002823 AttributeList *Attr,
2824 MultiTemplateParamsArg TemplateParameterLists);
Douglas Gregor55f6b142009-02-09 18:46:07 +00002825
Mike Stump1eb44332009-09-09 15:08:12 +00002826 virtual DeclPtrTy ActOnTemplateDeclarator(Scope *S,
Douglas Gregore542c862009-06-23 23:11:28 +00002827 MultiTemplateParamsArg TemplateParameterLists,
2828 Declarator &D);
Mike Stump1eb44332009-09-09 15:08:12 +00002829
2830 virtual DeclPtrTy ActOnStartOfFunctionTemplateDef(Scope *FnBodyScope,
Douglas Gregor52591bf2009-06-24 00:54:41 +00002831 MultiTemplateParamsArg TemplateParameterLists,
2832 Declarator &D);
Mike Stump1eb44332009-09-09 15:08:12 +00002833
Douglas Gregor0d035142009-10-27 18:42:08 +00002834 bool
2835 CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
2836 TemplateSpecializationKind NewTSK,
2837 NamedDecl *PrevDecl,
2838 TemplateSpecializationKind PrevTSK,
2839 SourceLocation PrevPointOfInstantiation,
2840 bool &SuppressNew);
2841
Douglas Gregorb9aa6b22009-09-24 23:14:47 +00002842 bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
John McCalld5532b62009-11-23 01:53:49 +00002843 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall68263142009-11-18 22:49:29 +00002844 LookupResult &Previous);
2845 bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
Douglas Gregorb9aa6b22009-09-24 23:14:47 +00002846
Douglas Gregor93dfdb12009-05-13 00:25:59 +00002847 virtual DeclResult
Mike Stump1eb44332009-09-09 15:08:12 +00002848 ActOnExplicitInstantiation(Scope *S,
Douglas Gregor45f96552009-09-04 06:33:52 +00002849 SourceLocation ExternLoc,
2850 SourceLocation TemplateLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00002851 unsigned TagSpec,
Douglas Gregor93dfdb12009-05-13 00:25:59 +00002852 SourceLocation KWLoc,
2853 const CXXScopeSpec &SS,
2854 TemplateTy Template,
2855 SourceLocation TemplateNameLoc,
2856 SourceLocation LAngleLoc,
2857 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregor93dfdb12009-05-13 00:25:59 +00002858 SourceLocation RAngleLoc,
2859 AttributeList *Attr);
2860
Douglas Gregor3f5b61c2009-05-14 00:28:11 +00002861 virtual DeclResult
Mike Stump1eb44332009-09-09 15:08:12 +00002862 ActOnExplicitInstantiation(Scope *S,
Douglas Gregor45f96552009-09-04 06:33:52 +00002863 SourceLocation ExternLoc,
2864 SourceLocation TemplateLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00002865 unsigned TagSpec,
Douglas Gregor3f5b61c2009-05-14 00:28:11 +00002866 SourceLocation KWLoc,
2867 const CXXScopeSpec &SS,
2868 IdentifierInfo *Name,
2869 SourceLocation NameLoc,
2870 AttributeList *Attr);
2871
Douglas Gregord5a423b2009-09-25 18:43:00 +00002872 virtual DeclResult ActOnExplicitInstantiation(Scope *S,
2873 SourceLocation ExternLoc,
2874 SourceLocation TemplateLoc,
2875 Declarator &D);
2876
Douglas Gregor51ffb0c2009-11-25 18:55:14 +00002877 TemplateArgumentLoc
2878 SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
2879 SourceLocation TemplateLoc,
2880 SourceLocation RAngleLoc,
2881 Decl *Param,
2882 TemplateArgumentListBuilder &Converted);
2883
Douglas Gregore7526412009-11-11 19:31:23 +00002884 bool CheckTemplateArgument(NamedDecl *Param,
2885 const TemplateArgumentLoc &Arg,
Douglas Gregore7526412009-11-11 19:31:23 +00002886 TemplateDecl *Template,
2887 SourceLocation TemplateLoc,
Douglas Gregore7526412009-11-11 19:31:23 +00002888 SourceLocation RAngleLoc,
2889 TemplateArgumentListBuilder &Converted);
2890
Douglas Gregorc15cb382009-02-09 23:23:08 +00002891 bool CheckTemplateArgumentList(TemplateDecl *Template,
2892 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +00002893 const TemplateArgumentListInfo &TemplateArgs,
Douglas Gregor16134c62009-07-01 00:28:38 +00002894 bool PartialTemplateArgs,
Anders Carlsson1c5976e2009-06-05 03:43:12 +00002895 TemplateArgumentListBuilder &Converted);
Douglas Gregorc15cb382009-02-09 23:23:08 +00002896
Mike Stump1eb44332009-09-09 15:08:12 +00002897 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
John McCall833ca992009-10-29 08:12:44 +00002898 const TemplateArgumentLoc &Arg,
Anders Carlsson436b1562009-06-13 00:33:33 +00002899 TemplateArgumentListBuilder &Converted);
2900
John McCall833ca992009-10-29 08:12:44 +00002901 bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
John McCalla93c9342009-12-07 02:54:59 +00002902 TypeSourceInfo *Arg);
Mike Stump1eb44332009-09-09 15:08:12 +00002903 bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,
Douglas Gregor3e00bad2009-02-17 01:05:43 +00002904 NamedDecl *&Entity);
Douglas Gregorcaddba02009-11-12 18:38:13 +00002905 bool CheckTemplateArgumentPointerToMember(Expr *Arg,
2906 TemplateArgument &Converted);
Mike Stump1eb44332009-09-09 15:08:12 +00002907 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
Douglas Gregor2943aed2009-03-03 04:44:36 +00002908 QualType InstantiatedParamType, Expr *&Arg,
Douglas Gregor02cbbd22009-06-11 18:10:32 +00002909 TemplateArgument &Converted);
Douglas Gregor788cd062009-11-11 01:00:40 +00002910 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param,
2911 const TemplateArgumentLoc &Arg);
Douglas Gregorfb898e12009-11-12 16:20:59 +00002912
2913 /// \brief Enumeration describing how template parameter lists are compared
2914 /// for equality.
2915 enum TemplateParameterListEqualKind {
2916 /// \brief We are matching the template parameter lists of two templates
2917 /// that might be redeclarations.
2918 ///
2919 /// \code
2920 /// template<typename T> struct X;
2921 /// template<typename T> struct X;
2922 /// \endcode
2923 TPL_TemplateMatch,
2924
2925 /// \brief We are matching the template parameter lists of two template
2926 /// template parameters as part of matching the template parameter lists
2927 /// of two templates that might be redeclarations.
2928 ///
2929 /// \code
2930 /// template<template<int I> class TT> struct X;
2931 /// template<template<int Value> class Other> struct X;
2932 /// \endcode
2933 TPL_TemplateTemplateParmMatch,
2934
2935 /// \brief We are matching the template parameter lists of a template
2936 /// template argument against the template parameter lists of a template
2937 /// template parameter.
2938 ///
2939 /// \code
2940 /// template<template<int Value> class Metafun> struct X;
2941 /// template<int Value> struct integer_c;
2942 /// X<integer_c> xic;
2943 /// \endcode
2944 TPL_TemplateTemplateArgumentMatch
2945 };
2946
Douglas Gregorddc29e12009-02-06 22:42:48 +00002947 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
2948 TemplateParameterList *Old,
2949 bool Complain,
Douglas Gregorfb898e12009-11-12 16:20:59 +00002950 TemplateParameterListEqualKind Kind,
Douglas Gregordd0574e2009-02-10 00:24:35 +00002951 SourceLocation TemplateArgLoc
Douglas Gregor788cd062009-11-11 01:00:40 +00002952 = SourceLocation());
Mike Stump1eb44332009-09-09 15:08:12 +00002953
Douglas Gregor05396e22009-08-25 17:23:04 +00002954 bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00002955
Douglas Gregord57959a2009-03-27 23:10:48 +00002956 /// \brief Called when the parser has parsed a C++ typename
2957 /// specifier, e.g., "typename T::type".
2958 ///
2959 /// \param TypenameLoc the location of the 'typename' keyword
2960 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
2961 /// \param II the identifier we're retrieving (e.g., 'type' in the example).
2962 /// \param IdLoc the location of the identifier.
2963 virtual TypeResult
2964 ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS,
2965 const IdentifierInfo &II, SourceLocation IdLoc);
Douglas Gregor17343172009-04-01 00:28:59 +00002966
2967 /// \brief Called when the parser has parsed a C++ typename
Mike Stump1eb44332009-09-09 15:08:12 +00002968 /// specifier that ends in a template-id, e.g.,
Douglas Gregor17343172009-04-01 00:28:59 +00002969 /// "typename MetaFun::template apply<T1, T2>".
2970 ///
2971 /// \param TypenameLoc the location of the 'typename' keyword
2972 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
2973 /// \param TemplateLoc the location of the 'template' keyword, if any.
2974 /// \param Ty the type that the typename specifier refers to.
2975 virtual TypeResult
2976 ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS,
2977 SourceLocation TemplateLoc, TypeTy *Ty);
2978
Douglas Gregord57959a2009-03-27 23:10:48 +00002979 QualType CheckTypenameType(NestedNameSpecifier *NNS,
2980 const IdentifierInfo &II,
2981 SourceRange Range);
Douglas Gregorc8ab2562009-05-31 09:31:02 +00002982
Douglas Gregor4a959d82009-08-06 16:20:37 +00002983 QualType RebuildTypeInCurrentInstantiation(QualType T, SourceLocation Loc,
2984 DeclarationName Name);
2985
Douglas Gregorbf4ea562009-09-15 16:23:51 +00002986 std::string
2987 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
2988 const TemplateArgumentList &Args);
Douglas Gregor9148c3f2009-11-11 19:13:48 +00002989
2990 std::string
2991 getTemplateArgumentBindingsText(const TemplateParameterList *Params,
2992 const TemplateArgument *Args,
2993 unsigned NumArgs);
Douglas Gregorbf4ea562009-09-15 16:23:51 +00002994
Douglas Gregorf67875d2009-06-12 18:26:56 +00002995 /// \brief Describes the result of template argument deduction.
2996 ///
2997 /// The TemplateDeductionResult enumeration describes the result of
2998 /// template argument deduction, as returned from
2999 /// DeduceTemplateArguments(). The separate TemplateDeductionInfo
3000 /// structure provides additional information about the results of
3001 /// template argument deduction, e.g., the deduced template argument
3002 /// list (if successful) or the specific template parameters or
3003 /// deduced arguments that were involved in the failure.
3004 enum TemplateDeductionResult {
3005 /// \brief Template argument deduction was successful.
3006 TDK_Success = 0,
3007 /// \brief Template argument deduction exceeded the maximum template
3008 /// instantiation depth (which has already been diagnosed).
3009 TDK_InstantiationDepth,
3010 /// \brief Template argument deduction did not deduce a value
3011 /// for every template parameter.
3012 TDK_Incomplete,
3013 /// \brief Template argument deduction produced inconsistent
3014 /// deduced values for the given template parameter.
3015 TDK_Inconsistent,
3016 /// \brief Template argument deduction failed due to inconsistent
3017 /// cv-qualifiers on a template parameter type that would
3018 /// otherwise be deduced, e.g., we tried to deduce T in "const T"
3019 /// but were given a non-const "X".
3020 TDK_InconsistentQuals,
3021 /// \brief Substitution of the deduced template argument values
3022 /// resulted in an error.
3023 TDK_SubstitutionFailure,
3024 /// \brief Substitution of the deduced template argument values
3025 /// into a non-deduced context produced a type or value that
3026 /// produces a type that does not match the original template
3027 /// arguments provided.
Douglas Gregore53060f2009-06-25 22:08:12 +00003028 TDK_NonDeducedMismatch,
Mike Stump1eb44332009-09-09 15:08:12 +00003029 /// \brief When performing template argument deduction for a function
Douglas Gregore53060f2009-06-25 22:08:12 +00003030 /// template, there were too many call arguments.
3031 TDK_TooManyArguments,
Mike Stump1eb44332009-09-09 15:08:12 +00003032 /// \brief When performing template argument deduction for a function
Douglas Gregore53060f2009-06-25 22:08:12 +00003033 /// template, there were too few call arguments.
Douglas Gregor6db8ed42009-06-30 23:57:56 +00003034 TDK_TooFewArguments,
3035 /// \brief The explicitly-specified template arguments were not valid
3036 /// template arguments for the given template.
Douglas Gregor4b52e252009-12-21 23:17:24 +00003037 TDK_InvalidExplicitArguments,
3038 /// \brief The arguments included an overloaded function name that could
3039 /// not be resolved to a suitable function.
3040 TDK_FailedOverloadResolution
Douglas Gregorf67875d2009-06-12 18:26:56 +00003041 };
3042
3043 /// \brief Provides information about an attempted template argument
3044 /// deduction, whose success or failure was described by a
3045 /// TemplateDeductionResult value.
3046 class TemplateDeductionInfo {
3047 /// \brief The context in which the template arguments are stored.
3048 ASTContext &Context;
3049
3050 /// \brief The deduced template argument list.
3051 ///
3052 TemplateArgumentList *Deduced;
3053
John McCall5769d612010-02-08 23:07:23 +00003054 /// \brief The source location at which template argument
3055 /// deduction is occurring.
3056 SourceLocation Loc;
3057
Douglas Gregorf67875d2009-06-12 18:26:56 +00003058 // do not implement these
3059 TemplateDeductionInfo(const TemplateDeductionInfo&);
3060 TemplateDeductionInfo &operator=(const TemplateDeductionInfo&);
3061
3062 public:
John McCall5769d612010-02-08 23:07:23 +00003063 TemplateDeductionInfo(ASTContext &Context, SourceLocation Loc)
3064 : Context(Context), Deduced(0), Loc(Loc) { }
Douglas Gregorf67875d2009-06-12 18:26:56 +00003065
3066 ~TemplateDeductionInfo() {
3067 // FIXME: if (Deduced) Deduced->Destroy(Context);
3068 }
3069
John McCall5769d612010-02-08 23:07:23 +00003070 /// \brief Returns the location at which template argument is
3071 /// occuring.
3072 SourceLocation getLocation() const {
3073 return Loc;
3074 }
3075
Douglas Gregorf67875d2009-06-12 18:26:56 +00003076 /// \brief Take ownership of the deduced template argument list.
Mike Stump1eb44332009-09-09 15:08:12 +00003077 TemplateArgumentList *take() {
Douglas Gregorf67875d2009-06-12 18:26:56 +00003078 TemplateArgumentList *Result = Deduced;
3079 Deduced = 0;
3080 return Result;
3081 }
3082
3083 /// \brief Provide a new template argument list that contains the
3084 /// results of template argument deduction.
3085 void reset(TemplateArgumentList *NewDeduced) {
3086 // FIXME: if (Deduced) Deduced->Destroy(Context);
3087 Deduced = NewDeduced;
3088 }
3089
3090 /// \brief The template parameter to which a template argument
3091 /// deduction failure refers.
3092 ///
3093 /// Depending on the result of template argument deduction, this
3094 /// template parameter may have different meanings:
3095 ///
3096 /// TDK_Incomplete: this is the first template parameter whose
3097 /// corresponding template argument was not deduced.
3098 ///
3099 /// TDK_Inconsistent: this is the template parameter for which
3100 /// two different template argument values were deduced.
3101 TemplateParameter Param;
3102
3103 /// \brief The first template argument to which the template
3104 /// argument deduction failure refers.
3105 ///
3106 /// Depending on the result of the template argument deduction,
3107 /// this template argument may have different meanings:
3108 ///
3109 /// TDK_Inconsistent: this argument is the first value deduced
3110 /// for the corresponding template parameter.
3111 ///
3112 /// TDK_SubstitutionFailure: this argument is the template
3113 /// argument we were instantiating when we encountered an error.
3114 ///
3115 /// TDK_NonDeducedMismatch: this is the template argument
3116 /// provided in the source code.
3117 TemplateArgument FirstArg;
3118
3119 /// \brief The second template argument to which the template
3120 /// argument deduction failure refers.
3121 ///
3122 /// FIXME: Finish documenting this.
3123 TemplateArgument SecondArg;
3124 };
3125
3126 TemplateDeductionResult
Douglas Gregor199d9912009-06-05 00:53:49 +00003127 DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
Douglas Gregorf67875d2009-06-12 18:26:56 +00003128 const TemplateArgumentList &TemplateArgs,
3129 TemplateDeductionInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +00003130
Douglas Gregor83314aa2009-07-08 20:55:45 +00003131 TemplateDeductionResult
3132 SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
John McCalld5532b62009-11-23 01:53:49 +00003133 const TemplateArgumentListInfo &ExplicitTemplateArgs,
Douglas Gregor83314aa2009-07-08 20:55:45 +00003134 llvm::SmallVectorImpl<TemplateArgument> &Deduced,
3135 llvm::SmallVectorImpl<QualType> &ParamTypes,
3136 QualType *FunctionType,
3137 TemplateDeductionInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +00003138
3139 TemplateDeductionResult
Douglas Gregor83314aa2009-07-08 20:55:45 +00003140 FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
3141 llvm::SmallVectorImpl<TemplateArgument> &Deduced,
3142 FunctionDecl *&Specialization,
3143 TemplateDeductionInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +00003144
Douglas Gregore53060f2009-06-25 22:08:12 +00003145 TemplateDeductionResult
3146 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
John McCalld5532b62009-11-23 01:53:49 +00003147 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregore53060f2009-06-25 22:08:12 +00003148 Expr **Args, unsigned NumArgs,
3149 FunctionDecl *&Specialization,
3150 TemplateDeductionInfo &Info);
Douglas Gregor83314aa2009-07-08 20:55:45 +00003151
3152 TemplateDeductionResult
3153 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
John McCalld5532b62009-11-23 01:53:49 +00003154 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor83314aa2009-07-08 20:55:45 +00003155 QualType ArgFunctionType,
3156 FunctionDecl *&Specialization,
3157 TemplateDeductionInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +00003158
Douglas Gregor65ec1fd2009-08-21 23:19:43 +00003159 TemplateDeductionResult
3160 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3161 QualType ToType,
3162 CXXConversionDecl *&Specialization,
3163 TemplateDeductionInfo &Info);
3164
Douglas Gregor4b52e252009-12-21 23:17:24 +00003165 TemplateDeductionResult
3166 DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
3167 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3168 FunctionDecl *&Specialization,
3169 TemplateDeductionInfo &Info);
3170
Douglas Gregor65ec1fd2009-08-21 23:19:43 +00003171 FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
3172 FunctionTemplateDecl *FT2,
John McCall5769d612010-02-08 23:07:23 +00003173 SourceLocation Loc,
Douglas Gregor8a514912009-09-14 18:39:43 +00003174 TemplatePartialOrderingContext TPOC);
John McCallc373d482010-01-27 01:50:18 +00003175 UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin,
3176 UnresolvedSetIterator SEnd,
3177 TemplatePartialOrderingContext TPOC,
3178 SourceLocation Loc,
3179 const PartialDiagnostic &NoneDiag,
3180 const PartialDiagnostic &AmbigDiag,
3181 const PartialDiagnostic &CandidateDiag);
Douglas Gregord5a423b2009-09-25 18:43:00 +00003182
Douglas Gregorbf4ea562009-09-15 16:23:51 +00003183 ClassTemplatePartialSpecializationDecl *
3184 getMoreSpecializedPartialSpecialization(
3185 ClassTemplatePartialSpecializationDecl *PS1,
John McCall5769d612010-02-08 23:07:23 +00003186 ClassTemplatePartialSpecializationDecl *PS2,
3187 SourceLocation Loc);
Douglas Gregorbf4ea562009-09-15 16:23:51 +00003188
Douglas Gregore73bb602009-09-14 21:25:05 +00003189 void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs,
3190 bool OnlyDeduced,
Douglas Gregored9c0f92009-10-29 00:04:11 +00003191 unsigned Depth,
Douglas Gregor63f07c52009-09-18 23:21:38 +00003192 llvm::SmallVectorImpl<bool> &Used);
3193 void MarkDeducedTemplateParameters(FunctionTemplateDecl *FunctionTemplate,
3194 llvm::SmallVectorImpl<bool> &Deduced);
3195
Douglas Gregor99ebf652009-02-27 19:31:52 +00003196 //===--------------------------------------------------------------------===//
3197 // C++ Template Instantiation
3198 //
Douglas Gregor26dce442009-03-10 00:06:19 +00003199
Douglas Gregor0f8716b2009-11-09 19:17:50 +00003200 MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D,
Douglas Gregor525f96c2010-02-05 07:33:43 +00003201 const TemplateArgumentList *Innermost = 0,
3202 bool RelativeToPrimary = false);
Douglas Gregor54dabfc2009-05-14 23:26:13 +00003203
Douglas Gregor26dce442009-03-10 00:06:19 +00003204 /// \brief A template instantiation that is currently in progress.
3205 struct ActiveTemplateInstantiation {
Douglas Gregordf667e72009-03-10 20:44:00 +00003206 /// \brief The kind of template instantiation we are performing
Douglas Gregorcca9e962009-07-01 22:01:06 +00003207 enum InstantiationKind {
Douglas Gregordf667e72009-03-10 20:44:00 +00003208 /// We are instantiating a template declaration. The entity is
Douglas Gregorb9f1b8d2009-05-15 00:01:03 +00003209 /// the declaration we're instantiating (e.g., a CXXRecordDecl).
Douglas Gregordf667e72009-03-10 20:44:00 +00003210 TemplateInstantiation,
3211
3212 /// We are instantiating a default argument for a template
3213 /// parameter. The Entity is the template, and
3214 /// TemplateArgs/NumTemplateArguments provides the template
3215 /// arguments as specified.
Douglas Gregor637a4092009-06-10 23:47:09 +00003216 /// FIXME: Use a TemplateArgumentList
3217 DefaultTemplateArgumentInstantiation,
3218
Anders Carlsson25cae7f2009-09-05 05:14:19 +00003219 /// We are instantiating a default argument for a function.
3220 /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
3221 /// provides the template arguments as specified.
3222 DefaultFunctionArgumentInstantiation,
3223
Mike Stump1eb44332009-09-09 15:08:12 +00003224 /// We are substituting explicit template arguments provided for
Douglas Gregorcca9e962009-07-01 22:01:06 +00003225 /// a function template. The entity is a FunctionTemplateDecl.
3226 ExplicitTemplateArgumentSubstitution,
Mike Stump1eb44332009-09-09 15:08:12 +00003227
Douglas Gregorcca9e962009-07-01 22:01:06 +00003228 /// We are substituting template argument determined as part of
3229 /// template argument deduction for either a class template
3230 /// partial specialization or a function template. The
3231 /// Entity is either a ClassTemplatePartialSpecializationDecl or
3232 /// a FunctionTemplateDecl.
Douglas Gregor9148c3f2009-11-11 19:13:48 +00003233 DeducedTemplateArgumentSubstitution,
3234
3235 /// We are substituting prior template arguments into a new
3236 /// template parameter. The template parameter itself is either a
3237 /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl.
Douglas Gregorf35f8282009-11-11 21:54:23 +00003238 PriorTemplateArgumentSubstitution,
3239
3240 /// We are checking the validity of a default template argument that
3241 /// has been used when naming a template-id.
3242 DefaultTemplateArgumentChecking
Douglas Gregordf667e72009-03-10 20:44:00 +00003243 } Kind;
3244
Douglas Gregor26dce442009-03-10 00:06:19 +00003245 /// \brief The point of instantiation within the source code.
3246 SourceLocation PointOfInstantiation;
3247
Douglas Gregor9148c3f2009-11-11 19:13:48 +00003248 /// \brief The template in which we are performing the instantiation,
3249 /// for substitutions of prior template arguments.
3250 TemplateDecl *Template;
3251
Douglas Gregor26dce442009-03-10 00:06:19 +00003252 /// \brief The entity that is being instantiated.
Douglas Gregordf667e72009-03-10 20:44:00 +00003253 uintptr_t Entity;
3254
Douglas Gregor9148c3f2009-11-11 19:13:48 +00003255 /// \brief The list of template arguments we are substituting, if they
3256 /// are not part of the entity.
Douglas Gregordf667e72009-03-10 20:44:00 +00003257 const TemplateArgument *TemplateArgs;
3258
3259 /// \brief The number of template arguments in TemplateArgs.
3260 unsigned NumTemplateArgs;
Douglas Gregor26dce442009-03-10 00:06:19 +00003261
3262 /// \brief The source range that covers the construct that cause
3263 /// the instantiation, e.g., the template-id that causes a class
3264 /// template instantiation.
3265 SourceRange InstantiationRange;
Douglas Gregordf667e72009-03-10 20:44:00 +00003266
Douglas Gregor9148c3f2009-11-11 19:13:48 +00003267 ActiveTemplateInstantiation()
3268 : Kind(TemplateInstantiation), Template(0), Entity(0), TemplateArgs(0),
3269 NumTemplateArgs(0) {}
Eli Friedman2ebcc6b2009-08-15 22:50:33 +00003270
Douglas Gregorf35f8282009-11-11 21:54:23 +00003271 /// \brief Determines whether this template is an actual instantiation
3272 /// that should be counted toward the maximum instantiation depth.
3273 bool isInstantiationRecord() const;
3274
Douglas Gregordf667e72009-03-10 20:44:00 +00003275 friend bool operator==(const ActiveTemplateInstantiation &X,
3276 const ActiveTemplateInstantiation &Y) {
3277 if (X.Kind != Y.Kind)
3278 return false;
3279
3280 if (X.Entity != Y.Entity)
3281 return false;
3282
3283 switch (X.Kind) {
3284 case TemplateInstantiation:
3285 return true;
3286
Douglas Gregor9148c3f2009-11-11 19:13:48 +00003287 case PriorTemplateArgumentSubstitution:
Douglas Gregorf35f8282009-11-11 21:54:23 +00003288 case DefaultTemplateArgumentChecking:
Douglas Gregor9148c3f2009-11-11 19:13:48 +00003289 if (X.Template != Y.Template)
3290 return false;
3291
3292 // Fall through
3293
Douglas Gregordf667e72009-03-10 20:44:00 +00003294 case DefaultTemplateArgumentInstantiation:
Douglas Gregorcca9e962009-07-01 22:01:06 +00003295 case ExplicitTemplateArgumentSubstitution:
3296 case DeducedTemplateArgumentSubstitution:
Anders Carlsson25cae7f2009-09-05 05:14:19 +00003297 case DefaultFunctionArgumentInstantiation:
Douglas Gregordf667e72009-03-10 20:44:00 +00003298 return X.TemplateArgs == Y.TemplateArgs;
Mike Stump1eb44332009-09-09 15:08:12 +00003299
Douglas Gregordf667e72009-03-10 20:44:00 +00003300 }
3301
3302 return true;
3303 }
3304
3305 friend bool operator!=(const ActiveTemplateInstantiation &X,
3306 const ActiveTemplateInstantiation &Y) {
3307 return !(X == Y);
3308 }
Douglas Gregor26dce442009-03-10 00:06:19 +00003309 };
3310
3311 /// \brief List of active template instantiations.
3312 ///
3313 /// This vector is treated as a stack. As one template instantiation
3314 /// requires another template instantiation, additional
3315 /// instantiations are pushed onto the stack up to a
3316 /// user-configurable limit LangOptions::InstantiationDepth.
Mike Stump1eb44332009-09-09 15:08:12 +00003317 llvm::SmallVector<ActiveTemplateInstantiation, 16>
Douglas Gregor26dce442009-03-10 00:06:19 +00003318 ActiveTemplateInstantiations;
3319
Douglas Gregorf35f8282009-11-11 21:54:23 +00003320 /// \brief The number of ActiveTemplateInstantiation entries in
3321 /// \c ActiveTemplateInstantiations that are not actual instantiations and,
3322 /// therefore, should not be counted as part of the instantiation depth.
3323 unsigned NonInstantiationEntries;
3324
Douglas Gregor27b152f2009-03-10 18:52:44 +00003325 /// \brief The last template from which a template instantiation
3326 /// error or warning was produced.
3327 ///
3328 /// This value is used to suppress printing of redundant template
3329 /// instantiation backtraces when there are multiple errors in the
3330 /// same instantiation. FIXME: Does this belong in Sema? It's tough
3331 /// to implement it anywhere else.
Douglas Gregordf667e72009-03-10 20:44:00 +00003332 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
Douglas Gregor27b152f2009-03-10 18:52:44 +00003333
Douglas Gregor26dce442009-03-10 00:06:19 +00003334 /// \brief A stack object to be created when performing template
3335 /// instantiation.
3336 ///
3337 /// Construction of an object of type \c InstantiatingTemplate
3338 /// pushes the current instantiation onto the stack of active
3339 /// instantiations. If the size of this stack exceeds the maximum
3340 /// number of recursive template instantiations, construction
3341 /// produces an error and evaluates true.
3342 ///
3343 /// Destruction of this object will pop the named instantiation off
3344 /// the stack.
3345 struct InstantiatingTemplate {
Douglas Gregorf3e7ce42009-05-18 17:01:57 +00003346 /// \brief Note that we are instantiating a class template,
3347 /// function template, or a member thereof.
Douglas Gregor26dce442009-03-10 00:06:19 +00003348 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
Douglas Gregorf3e7ce42009-05-18 17:01:57 +00003349 Decl *Entity,
Douglas Gregor26dce442009-03-10 00:06:19 +00003350 SourceRange InstantiationRange = SourceRange());
Douglas Gregordf667e72009-03-10 20:44:00 +00003351
3352 /// \brief Note that we are instantiating a default argument in a
3353 /// template-id.
3354 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3355 TemplateDecl *Template,
3356 const TemplateArgument *TemplateArgs,
3357 unsigned NumTemplateArgs,
3358 SourceRange InstantiationRange = SourceRange());
3359
Douglas Gregorcca9e962009-07-01 22:01:06 +00003360 /// \brief Note that we are instantiating a default argument in a
3361 /// template-id.
3362 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3363 FunctionTemplateDecl *FunctionTemplate,
3364 const TemplateArgument *TemplateArgs,
3365 unsigned NumTemplateArgs,
3366 ActiveTemplateInstantiation::InstantiationKind Kind,
3367 SourceRange InstantiationRange = SourceRange());
Mike Stump1eb44332009-09-09 15:08:12 +00003368
Douglas Gregor637a4092009-06-10 23:47:09 +00003369 /// \brief Note that we are instantiating as part of template
3370 /// argument deduction for a class template partial
3371 /// specialization.
3372 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3373 ClassTemplatePartialSpecializationDecl *PartialSpec,
3374 const TemplateArgument *TemplateArgs,
3375 unsigned NumTemplateArgs,
3376 SourceRange InstantiationRange = SourceRange());
3377
Anders Carlsson25cae7f2009-09-05 05:14:19 +00003378 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3379 ParmVarDecl *Param,
3380 const TemplateArgument *TemplateArgs,
3381 unsigned NumTemplateArgs,
3382 SourceRange InstantiationRange = SourceRange());
3383
Douglas Gregor9148c3f2009-11-11 19:13:48 +00003384 /// \brief Note that we are substituting prior template arguments into a
3385 /// non-type or template template parameter.
3386 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3387 TemplateDecl *Template,
3388 NonTypeTemplateParmDecl *Param,
3389 const TemplateArgument *TemplateArgs,
3390 unsigned NumTemplateArgs,
3391 SourceRange InstantiationRange);
3392
3393 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3394 TemplateDecl *Template,
3395 TemplateTemplateParmDecl *Param,
3396 const TemplateArgument *TemplateArgs,
3397 unsigned NumTemplateArgs,
3398 SourceRange InstantiationRange);
3399
Douglas Gregorf35f8282009-11-11 21:54:23 +00003400 /// \brief Note that we are checking the default template argument
3401 /// against the template parameter for a given template-id.
3402 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
3403 TemplateDecl *Template,
3404 NamedDecl *Param,
3405 const TemplateArgument *TemplateArgs,
3406 unsigned NumTemplateArgs,
3407 SourceRange InstantiationRange);
3408
3409
Douglas Gregorf3e7ce42009-05-18 17:01:57 +00003410 /// \brief Note that we have finished instantiating this template.
3411 void Clear();
3412
3413 ~InstantiatingTemplate() { Clear(); }
Douglas Gregor26dce442009-03-10 00:06:19 +00003414
3415 /// \brief Determines whether we have exceeded the maximum
3416 /// recursive template instantiations.
3417 operator bool() const { return Invalid; }
3418
3419 private:
3420 Sema &SemaRef;
3421 bool Invalid;
3422
Douglas Gregordf667e72009-03-10 20:44:00 +00003423 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
3424 SourceRange InstantiationRange);
3425
Douglas Gregor26dce442009-03-10 00:06:19 +00003426 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
3427
Mike Stump1eb44332009-09-09 15:08:12 +00003428 InstantiatingTemplate&
Douglas Gregor26dce442009-03-10 00:06:19 +00003429 operator=(const InstantiatingTemplate&); // not implemented
3430 };
3431
Douglas Gregoree1828a2009-03-10 18:03:33 +00003432 void PrintInstantiationStack();
3433
Douglas Gregor5e9f35c2009-06-14 07:33:30 +00003434 /// \brief Determines whether we are currently in a context where
3435 /// template argument substitution failures are not considered
3436 /// errors.
3437 ///
3438 /// When this routine returns true, the emission of most diagnostics
3439 /// will be suppressed and there will be no local error recovery.
3440 bool isSFINAEContext() const;
3441
Douglas Gregorbb260412009-06-14 08:02:22 +00003442 /// \brief RAII class used to determine whether SFINAE has
3443 /// trapped any errors that occur during template argument
3444 /// deduction.
3445 class SFINAETrap {
3446 Sema &SemaRef;
3447 unsigned PrevSFINAEErrors;
3448 public:
3449 explicit SFINAETrap(Sema &SemaRef)
3450 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors) { }
3451
3452 ~SFINAETrap() { SemaRef.NumSFINAEErrors = PrevSFINAEErrors; }
3453
3454 /// \brief Determine whether any SFINAE errors have been trapped.
Mike Stump1eb44332009-09-09 15:08:12 +00003455 bool hasErrorOccurred() const {
3456 return SemaRef.NumSFINAEErrors > PrevSFINAEErrors;
Douglas Gregorbb260412009-06-14 08:02:22 +00003457 }
3458 };
3459
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003460 /// \brief A stack-allocated class that identifies which local
3461 /// variable declaration instantiations are present in this scope.
3462 ///
3463 /// A new instance of this class type will be created whenever we
3464 /// instantiate a new function declaration, which will have its own
3465 /// set of parameter declarations.
3466 class LocalInstantiationScope {
3467 /// \brief Reference to the semantic analysis that is performing
3468 /// this template instantiation.
3469 Sema &SemaRef;
3470
Douglas Gregor815215d2009-05-27 05:35:12 +00003471 /// \brief A mapping from local declarations that occur
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003472 /// within a template to their instantiations.
3473 ///
3474 /// This mapping is used during instantiation to keep track of,
3475 /// e.g., function parameter and variable declarations. For example,
3476 /// given:
3477 ///
3478 /// \code
3479 /// template<typename T> T add(T x, T y) { return x + y; }
3480 /// \endcode
3481 ///
3482 /// when we instantiate add<int>, we will introduce a mapping from
3483 /// the ParmVarDecl for 'x' that occurs in the template to the
3484 /// instantiated ParmVarDecl for 'x'.
Douglas Gregor815215d2009-05-27 05:35:12 +00003485 llvm::DenseMap<const Decl *, Decl *> LocalDecls;
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003486
3487 /// \brief The outer scope, in which contains local variable
Douglas Gregor550d9b22009-10-31 17:21:17 +00003488 /// definitions from some other instantiation (that may not be
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003489 /// relevant to this particular scope).
3490 LocalInstantiationScope *Outer;
3491
Douglas Gregor60406be2010-01-16 22:29:39 +00003492 /// \brief Whether we have already exited this scope.
3493 bool Exited;
3494
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003495 // This class is non-copyable
3496 LocalInstantiationScope(const LocalInstantiationScope &);
3497 LocalInstantiationScope &operator=(const LocalInstantiationScope &);
3498
3499 public:
Douglas Gregor550d9b22009-10-31 17:21:17 +00003500 LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope = false)
Douglas Gregor60406be2010-01-16 22:29:39 +00003501 : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope),
3502 Exited(false) {
Douglas Gregor550d9b22009-10-31 17:21:17 +00003503 if (!CombineWithOuterScope)
3504 SemaRef.CurrentInstantiationScope = this;
3505 else
3506 assert(SemaRef.CurrentInstantiationScope &&
3507 "No outer instantiation scope?");
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003508 }
3509
3510 ~LocalInstantiationScope() {
Douglas Gregor60406be2010-01-16 22:29:39 +00003511 if (!Exited)
3512 SemaRef.CurrentInstantiationScope = Outer;
3513 }
3514
3515 /// \brief Exit this local instantiation scope early.
3516 void Exit() {
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003517 SemaRef.CurrentInstantiationScope = Outer;
Douglas Gregor60406be2010-01-16 22:29:39 +00003518 LocalDecls.clear();
3519 Exited = true;
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003520 }
3521
Douglas Gregor815215d2009-05-27 05:35:12 +00003522 Decl *getInstantiationOf(const Decl *D) {
3523 Decl *Result = LocalDecls[D];
Douglas Gregor00225542010-03-01 18:27:54 +00003524 assert((Result || D->isInvalidDecl()) &&
3525 "declaration was not instantiated in this scope!");
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003526 return Result;
3527 }
3528
Douglas Gregor815215d2009-05-27 05:35:12 +00003529 VarDecl *getInstantiationOf(const VarDecl *Var) {
3530 return cast<VarDecl>(getInstantiationOf(cast<Decl>(Var)));
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003531 }
3532
Douglas Gregor815215d2009-05-27 05:35:12 +00003533 ParmVarDecl *getInstantiationOf(const ParmVarDecl *Var) {
3534 return cast<ParmVarDecl>(getInstantiationOf(cast<Decl>(Var)));
3535 }
3536
Douglas Gregor550d9b22009-10-31 17:21:17 +00003537 NonTypeTemplateParmDecl *getInstantiationOf(
3538 const NonTypeTemplateParmDecl *Var) {
3539 return cast<NonTypeTemplateParmDecl>(getInstantiationOf(cast<Decl>(Var)));
3540 }
3541
Douglas Gregor815215d2009-05-27 05:35:12 +00003542 void InstantiatedLocal(const Decl *D, Decl *Inst) {
3543 Decl *&Stored = LocalDecls[D];
Douglas Gregor96084f12010-03-01 19:00:07 +00003544 assert((!Stored || Stored == Inst) && "Already instantiated this local");
Douglas Gregor815215d2009-05-27 05:35:12 +00003545 Stored = Inst;
Douglas Gregor48dd19b2009-05-14 21:44:34 +00003546 }
3547 };
3548
3549 /// \brief The current instantiation scope used to store local
3550 /// variables.
3551 LocalInstantiationScope *CurrentInstantiationScope;
3552
Ted Kremenekd0ed4482010-02-02 02:07:01 +00003553 /// \brief The number of typos corrected by CorrectTypo.
3554 unsigned TyposCorrected;
3555
Douglas Gregord7f37bf2009-06-22 23:06:13 +00003556 /// \brief An entity for which implicit template instantiation is required.
3557 ///
Mike Stump1eb44332009-09-09 15:08:12 +00003558 /// The source location associated with the declaration is the first place in
Douglas Gregord7f37bf2009-06-22 23:06:13 +00003559 /// the source code where the declaration was "used". It is not necessarily
Mike Stump1eb44332009-09-09 15:08:12 +00003560 /// the point of instantiation (which will be either before or after the
Douglas Gregord7f37bf2009-06-22 23:06:13 +00003561 /// 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;
Mike Stump1eb44332009-09-09 15:08:12 +00003565
Douglas Gregord7f37bf2009-06-22 23:06:13 +00003566 /// \brief The queue of implicit template instantiations that are required
3567 /// but have not yet been performed.
Douglas Gregorb33fe2f2009-06-30 17:20:14 +00003568 std::deque<PendingImplicitInstantiation> PendingImplicitInstantiations;
Douglas Gregord7f37bf2009-06-22 23:06:13 +00003569
Douglas Gregor60406be2010-01-16 22:29:39 +00003570 /// \brief The queue of implicit template instantiations that are required
3571 /// and must be performed within the current local scope.
3572 ///
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;
3578
3579 void PerformPendingImplicitInstantiations(bool LocalOnly = false);
Mike Stump1eb44332009-09-09 15:08:12 +00003580
John McCalla93c9342009-12-07 02:54:59 +00003581 TypeSourceInfo *SubstType(TypeSourceInfo *T,
John McCallcd7ba1c2009-10-21 00:58:09 +00003582 const MultiLevelTemplateArgumentList &TemplateArgs,
3583 SourceLocation Loc, DeclarationName Entity);
3584
Mike Stump1eb44332009-09-09 15:08:12 +00003585 QualType SubstType(QualType T,
Douglas Gregord6350ae2009-08-28 20:31:08 +00003586 const MultiLevelTemplateArgumentList &TemplateArgs,
John McCallce3ff2b2009-08-25 22:02:44 +00003587 SourceLocation Loc, DeclarationName Entity);
Mike Stump1eb44332009-09-09 15:08:12 +00003588
3589 OwningExprResult SubstExpr(Expr *E,
Douglas Gregord6350ae2009-08-28 20:31:08 +00003590 const MultiLevelTemplateArgumentList &TemplateArgs);
Douglas Gregora0e500d2009-03-12 16:53:44 +00003591
Mike Stump1eb44332009-09-09 15:08:12 +00003592 OwningStmtResult SubstStmt(Stmt *S,
Douglas Gregord6350ae2009-08-28 20:31:08 +00003593 const MultiLevelTemplateArgumentList &TemplateArgs);
Douglas Gregor54dabfc2009-05-14 23:26:13 +00003594
John McCallce3ff2b2009-08-25 22:02:44 +00003595 Decl *SubstDecl(Decl *D, DeclContext *Owner,
Douglas Gregord6350ae2009-08-28 20:31:08 +00003596 const MultiLevelTemplateArgumentList &TemplateArgs);
Douglas Gregor8dbc2692009-03-17 21:15:40 +00003597
Mike Stump1eb44332009-09-09 15:08:12 +00003598 bool
John McCallce3ff2b2009-08-25 22:02:44 +00003599 SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
3600 CXXRecordDecl *Pattern,
Douglas Gregord6350ae2009-08-28 20:31:08 +00003601 const MultiLevelTemplateArgumentList &TemplateArgs);
John McCalle29ba202009-08-20 01:44:21 +00003602
3603 bool
Douglas Gregord475b8d2009-03-25 21:17:03 +00003604 InstantiateClass(SourceLocation PointOfInstantiation,
3605 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
Douglas Gregord6350ae2009-08-28 20:31:08 +00003606 const MultiLevelTemplateArgumentList &TemplateArgs,
Douglas Gregord0e3daf2009-09-04 22:48:11 +00003607 TemplateSpecializationKind TSK,
Douglas Gregor5842ba92009-08-24 15:23:48 +00003608 bool Complain = true);
Douglas Gregord475b8d2009-03-25 21:17:03 +00003609
Mike Stump1eb44332009-09-09 15:08:12 +00003610 bool
Douglas Gregor972e6ce2009-10-27 06:26:26 +00003611 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
Douglas Gregor2943aed2009-03-03 04:44:36 +00003612 ClassTemplateSpecializationDecl *ClassTemplateSpec,
Douglas Gregord0e3daf2009-09-04 22:48:11 +00003613 TemplateSpecializationKind TSK,
3614 bool Complain = true);
Douglas Gregor99ebf652009-02-27 19:31:52 +00003615
Douglas Gregora58861f2009-05-13 20:28:22 +00003616 void InstantiateClassMembers(SourceLocation PointOfInstantiation,
3617 CXXRecordDecl *Instantiation,
Douglas Gregord0e3daf2009-09-04 22:48:11 +00003618 const MultiLevelTemplateArgumentList &TemplateArgs,
3619 TemplateSpecializationKind TSK);
Douglas Gregora58861f2009-05-13 20:28:22 +00003620
3621 void InstantiateClassTemplateSpecializationMembers(
3622 SourceLocation PointOfInstantiation,
Douglas Gregord0e3daf2009-09-04 22:48:11 +00003623 ClassTemplateSpecializationDecl *ClassTemplateSpec,
3624 TemplateSpecializationKind TSK);
Douglas Gregora58861f2009-05-13 20:28:22 +00003625
Douglas Gregorab452ba2009-03-26 23:50:42 +00003626 NestedNameSpecifier *
John McCallce3ff2b2009-08-25 22:02:44 +00003627 SubstNestedNameSpecifier(NestedNameSpecifier *NNS,
3628 SourceRange Range,
Douglas Gregord6350ae2009-08-28 20:31:08 +00003629 const MultiLevelTemplateArgumentList &TemplateArgs);
Douglas Gregor5953d8b2009-03-19 17:26:29 +00003630
Douglas Gregorde650ae2009-03-31 18:38:02 +00003631 TemplateName
John McCallce3ff2b2009-08-25 22:02:44 +00003632 SubstTemplateName(TemplateName Name, SourceLocation Loc,
Douglas Gregord6350ae2009-08-28 20:31:08 +00003633 const MultiLevelTemplateArgumentList &TemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00003634 bool Subst(const TemplateArgumentLoc &Arg, TemplateArgumentLoc &Result,
3635 const MultiLevelTemplateArgumentList &TemplateArgs);
Douglas Gregorde650ae2009-03-31 18:38:02 +00003636
Douglas Gregorf3e7ce42009-05-18 17:01:57 +00003637 void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
Douglas Gregorb33fe2f2009-06-30 17:20:14 +00003638 FunctionDecl *Function,
Douglas Gregore2d3a3d2009-10-15 14:05:49 +00003639 bool Recursive = false,
3640 bool DefinitionRequired = false);
Douglas Gregor7caa6822009-07-24 20:34:43 +00003641 void InstantiateStaticDataMemberDefinition(
John McCallce3ff2b2009-08-25 22:02:44 +00003642 SourceLocation PointOfInstantiation,
3643 VarDecl *Var,
Douglas Gregore2d3a3d2009-10-15 14:05:49 +00003644 bool Recursive = false,
3645 bool DefinitionRequired = false);
Douglas Gregora58861f2009-05-13 20:28:22 +00003646
Anders Carlsson09025312009-08-29 05:16:22 +00003647 void InstantiateMemInitializers(CXXConstructorDecl *New,
3648 const CXXConstructorDecl *Tmpl,
3649 const MultiLevelTemplateArgumentList &TemplateArgs);
Mike Stump1eb44332009-09-09 15:08:12 +00003650
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003651 NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
Douglas Gregore95b4092009-09-16 18:34:49 +00003652 const MultiLevelTemplateArgumentList &TemplateArgs);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003653 DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC,
Douglas Gregore95b4092009-09-16 18:34:49 +00003654 const MultiLevelTemplateArgumentList &TemplateArgs);
Mike Stump1eb44332009-09-09 15:08:12 +00003655
John McCall21ef0fa2010-03-11 09:03:00 +00003656 bool CheckInstantiatedParams(llvm::SmallVectorImpl<ParmVarDecl *> &Params);
3657
Steve Naroff3536b442007-09-06 21:24:23 +00003658 // Objective-C declarations.
Chris Lattnerb28317a2009-03-28 19:18:32 +00003659 virtual DeclPtrTy ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
3660 IdentifierInfo *ClassName,
3661 SourceLocation ClassLoc,
3662 IdentifierInfo *SuperName,
3663 SourceLocation SuperLoc,
3664 const DeclPtrTy *ProtoRefs,
3665 unsigned NumProtoRefs,
Douglas Gregor18df52b2010-01-16 15:02:53 +00003666 const SourceLocation *ProtoLocs,
Chris Lattnerb28317a2009-03-28 19:18:32 +00003667 SourceLocation EndProtoLoc,
3668 AttributeList *AttrList);
Mike Stump1eb44332009-09-09 15:08:12 +00003669
Chris Lattnerb28317a2009-03-28 19:18:32 +00003670 virtual DeclPtrTy ActOnCompatiblityAlias(
Fariborz Jahanian243b64b2007-10-11 23:42:27 +00003671 SourceLocation AtCompatibilityAliasLoc,
3672 IdentifierInfo *AliasName, SourceLocation AliasLocation,
3673 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff61d68522009-03-05 15:22:01 +00003674
3675 void CheckForwardProtocolDeclarationForCircularDependency(
3676 IdentifierInfo *PName,
3677 SourceLocation &PLoc, SourceLocation PrevLoc,
3678 const ObjCList<ObjCProtocolDecl> &PList);
Mike Stump1eb44332009-09-09 15:08:12 +00003679
Chris Lattnerb28317a2009-03-28 19:18:32 +00003680 virtual DeclPtrTy ActOnStartProtocolInterface(
Nate Begeman1abc7f62008-02-20 22:57:40 +00003681 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian25e077d2007-09-17 21:07:36 +00003682 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattnerb28317a2009-03-28 19:18:32 +00003683 const DeclPtrTy *ProtoRefNames, unsigned NumProtoRefs,
Douglas Gregor18df52b2010-01-16 15:02:53 +00003684 const SourceLocation *ProtoLocs,
Daniel Dunbar246e70f2008-09-26 04:48:09 +00003685 SourceLocation EndProtoLoc,
3686 AttributeList *AttrList);
Mike Stump1eb44332009-09-09 15:08:12 +00003687
Chris Lattnerb28317a2009-03-28 19:18:32 +00003688 virtual DeclPtrTy ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
3689 IdentifierInfo *ClassName,
3690 SourceLocation ClassLoc,
3691 IdentifierInfo *CategoryName,
3692 SourceLocation CategoryLoc,
3693 const DeclPtrTy *ProtoRefs,
3694 unsigned NumProtoRefs,
Douglas Gregor18df52b2010-01-16 15:02:53 +00003695 const SourceLocation *ProtoLocs,
Chris Lattnerb28317a2009-03-28 19:18:32 +00003696 SourceLocation EndProtoLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00003697
Chris Lattnerb28317a2009-03-28 19:18:32 +00003698 virtual DeclPtrTy ActOnStartClassImplementation(
Nate Begeman1abc7f62008-02-20 22:57:40 +00003699 SourceLocation AtClassImplLoc,
Fariborz Jahanianccb4f312007-09-25 18:38:09 +00003700 IdentifierInfo *ClassName, SourceLocation ClassLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00003701 IdentifierInfo *SuperClassname,
Fariborz Jahanianccb4f312007-09-25 18:38:09 +00003702 SourceLocation SuperClassLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00003703
Chris Lattnerb28317a2009-03-28 19:18:32 +00003704 virtual DeclPtrTy ActOnStartCategoryImplementation(
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +00003705 SourceLocation AtCatImplLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00003706 IdentifierInfo *ClassName,
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +00003707 SourceLocation ClassLoc,
3708 IdentifierInfo *CatName,
3709 SourceLocation CatLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00003710
Chris Lattnerb28317a2009-03-28 19:18:32 +00003711 virtual DeclPtrTy ActOnForwardClassDeclaration(SourceLocation Loc,
Ted Kremenekc09cba62009-11-17 23:12:20 +00003712 IdentifierInfo **IdentList,
3713 SourceLocation *IdentLocs,
3714 unsigned NumElts);
Mike Stump1eb44332009-09-09 15:08:12 +00003715
Chris Lattnerb28317a2009-03-28 19:18:32 +00003716 virtual DeclPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattner7caeabd2008-07-21 22:17:28 +00003717 const IdentifierLocPair *IdentList,
Fariborz Jahanianbc1c8772008-12-17 01:07:27 +00003718 unsigned NumElts,
3719 AttributeList *attrList);
Mike Stump1eb44332009-09-09 15:08:12 +00003720
Chris Lattnere13b9592008-07-26 04:03:38 +00003721 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattner7caeabd2008-07-21 22:17:28 +00003722 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00003723 unsigned NumProtocols,
Chris Lattnerb28317a2009-03-28 19:18:32 +00003724 llvm::SmallVectorImpl<DeclPtrTy> &Protocols);
Mike Stump1eb44332009-09-09 15:08:12 +00003725
3726 /// Ensure attributes are consistent with type.
Daniel Dunbar95e61fb2008-09-23 21:53:23 +00003727 /// \param [in, out] Attributes The attributes to check; they will
3728 /// be modified to be consistent with \arg PropertyTy.
Mike Stump1eb44332009-09-09 15:08:12 +00003729 void CheckObjCPropertyAttributes(QualType PropertyTy,
Daniel Dunbar95e61fb2008-09-23 21:53:23 +00003730 SourceLocation Loc,
3731 unsigned &Attributes);
Steve Naroff0701bbb2009-01-08 17:28:14 +00003732 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Mike Stump1eb44332009-09-09 15:08:12 +00003733 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
Fariborz Jahanian02edb982008-05-01 00:03:38 +00003734 ObjCPropertyDecl *SuperProperty,
Chris Lattner8ec03f52008-11-24 03:54:41 +00003735 const IdentifierInfo *Name);
Fariborz Jahanian02edb982008-05-01 00:03:38 +00003736 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00003737
3738 void CompareMethodParamsInBaseAndSuper(Decl *IDecl,
Fariborz Jahaniandbdec8b2009-08-04 01:07:16 +00003739 ObjCMethodDecl *MethodDecl,
3740 bool IsInstance);
Mike Stump1eb44332009-09-09 15:08:12 +00003741
Fariborz Jahanian107089f2010-01-18 18:41:16 +00003742 void CompareProperties(Decl *CDecl, DeclPtrTy MergeProtocols);
Mike Stump1eb44332009-09-09 15:08:12 +00003743
3744 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
Fariborz Jahanianb7f95f52009-03-02 19:05:07 +00003745 ObjCInterfaceDecl *ID);
Mike Stump1eb44332009-09-09 15:08:12 +00003746
Fariborz Jahanian107089f2010-01-18 18:41:16 +00003747 void MatchOneProtocolPropertiesInClass(Decl *CDecl,
3748 ObjCProtocolDecl *PDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00003749
Ted Kremenek782f2f52010-01-07 01:20:12 +00003750 virtual void ActOnAtEnd(SourceRange AtEnd,
3751 DeclPtrTy classDecl,
3752 DeclPtrTy *allMethods = 0, unsigned allNum = 0,
3753 DeclPtrTy *allProperties = 0, unsigned pNum = 0,
3754 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0);
Mike Stump1eb44332009-09-09 15:08:12 +00003755
Chris Lattnerb28317a2009-03-28 19:18:32 +00003756 virtual DeclPtrTy ActOnProperty(Scope *S, SourceLocation AtLoc,
3757 FieldDeclarator &FD, ObjCDeclSpec &ODS,
3758 Selector GetterSel, Selector SetterSel,
3759 DeclPtrTy ClassCategory,
3760 bool *OverridingProperty,
3761 tok::ObjCKeywordKind MethodImplKind);
Mike Stump1eb44332009-09-09 15:08:12 +00003762
3763 virtual DeclPtrTy ActOnPropertyImplDecl(SourceLocation AtLoc,
Chris Lattnerb28317a2009-03-28 19:18:32 +00003764 SourceLocation PropertyLoc,
3765 bool ImplKind,DeclPtrTy ClassImplDecl,
3766 IdentifierInfo *PropertyId,
3767 IdentifierInfo *PropertyIvar);
Mike Stump1eb44332009-09-09 15:08:12 +00003768
Chris Lattnerb28317a2009-03-28 19:18:32 +00003769 virtual DeclPtrTy ActOnMethodDeclaration(
Steve Naroffbef11852007-10-26 20:53:56 +00003770 SourceLocation BeginLoc, // location of the + or -.
3771 SourceLocation EndLoc, // location of the ; or {.
Mike Stump1eb44332009-09-09 15:08:12 +00003772 tok::TokenKind MethodType,
3773 DeclPtrTy ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanianf1de0ca2007-10-31 23:53:01 +00003774 Selector Sel,
Steve Naroff68d331a2007-09-27 14:38:14 +00003775 // optional arguments. The number of types/arguments is obtained
3776 // from the Sel.getNumArgs().
Chris Lattnere294d3f2009-04-11 18:57:04 +00003777 ObjCArgInfo *ArgInfo,
Fariborz Jahanian439c6582009-01-09 00:38:19 +00003778 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroff335eafa2007-11-15 12:35:21 +00003779 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
3780 bool isVariadic = false);
Steve Naroff81bfde92007-10-16 23:12:48 +00003781
Steve Narofff1afaf62009-02-26 15:55:06 +00003782 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
3783 // Will search "local" class/category implementations for a method decl.
Fariborz Jahanian175ba1e2009-03-04 18:15:57 +00003784 // Will also search in class's root looking for instance method.
Steve Narofff1afaf62009-02-26 15:55:06 +00003785 // Returns 0 if no method is found.
Mike Stump1eb44332009-09-09 15:08:12 +00003786 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
Steve Naroff5609ec02009-03-08 18:56:13 +00003787 ObjCInterfaceDecl *CDecl);
3788 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
3789 ObjCInterfaceDecl *ClassDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00003790
Steve Naroff61f72cb2009-03-09 21:12:44 +00003791 virtual OwningExprResult ActOnClassPropertyRefExpr(
3792 IdentifierInfo &receiverName,
3793 IdentifierInfo &propertyName,
3794 SourceLocation &receiverNameLoc,
3795 SourceLocation &propertyNameLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00003796
Steve Naroff68d331a2007-09-27 14:38:14 +00003797 // ActOnClassMessage - used for both unary and keyword messages.
3798 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff49f109c2007-11-15 13:05:42 +00003799 // is obtained from NumArgs.
Steve Naroff68d331a2007-09-27 14:38:14 +00003800 virtual ExprResult ActOnClassMessage(
Fariborz Jahanian0523aaf2007-11-12 20:13:27 +00003801 Scope *S,
Mike Stump1eb44332009-09-09 15:08:12 +00003802 IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,
3803 SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac,
Steve Naroff49f109c2007-11-15 13:05:42 +00003804 ExprTy **ArgExprs, unsigned NumArgs);
Steve Naroff68d331a2007-09-27 14:38:14 +00003805
3806 // ActOnInstanceMessage - used for both unary and keyword messages.
3807 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff49f109c2007-11-15 13:05:42 +00003808 // is obtained from NumArgs.
Steve Naroff68d331a2007-09-27 14:38:14 +00003809 virtual ExprResult ActOnInstanceMessage(
Steve Naroffbcfb06a2007-09-28 22:22:11 +00003810 ExprTy *receiver, Selector Sel,
Mike Stump1eb44332009-09-09 15:08:12 +00003811 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroff49f109c2007-11-15 13:05:42 +00003812 ExprTy **ArgExprs, unsigned NumArgs);
Mike Stump1eb44332009-09-09 15:08:12 +00003813
Daniel Dunbar4cde9272008-10-14 05:35:18 +00003814 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
3815 virtual void ActOnPragmaPack(PragmaPackKind Kind,
3816 IdentifierInfo *Name,
3817 ExprTy *Alignment,
Mike Stump1eb44332009-09-09 15:08:12 +00003818 SourceLocation PragmaLoc,
Daniel Dunbar4cde9272008-10-14 05:35:18 +00003819 SourceLocation LParenLoc,
3820 SourceLocation RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00003821
Ted Kremenek4726d032009-03-23 22:28:25 +00003822 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
Ted Kremenek7a02a372009-08-03 23:24:57 +00003823 virtual void ActOnPragmaUnused(const Token *Identifiers,
3824 unsigned NumIdentifiers, Scope *curScope,
Mike Stump1eb44332009-09-09 15:08:12 +00003825 SourceLocation PragmaLoc,
Ted Kremenek4726d032009-03-23 22:28:25 +00003826 SourceLocation LParenLoc,
3827 SourceLocation RParenLoc);
Eli Friedmanc49f19b2009-06-05 02:44:36 +00003828
Ryan Flynn7b1fdbd2009-07-31 02:52:19 +00003829 NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II);
3830 void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
Ryan Flynne25ff832009-07-30 03:15:39 +00003831
Eli Friedmandec7c762009-06-05 06:28:29 +00003832 /// ActOnPragmaWeakID - Called on well formed #pragma weak ident.
Eli Friedmanc49f19b2009-06-05 02:44:36 +00003833 virtual void ActOnPragmaWeakID(IdentifierInfo* WeakName,
3834 SourceLocation PragmaLoc,
3835 SourceLocation WeakNameLoc);
3836
Eli Friedmandec7c762009-06-05 06:28:29 +00003837 /// ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
Eli Friedmanc49f19b2009-06-05 02:44:36 +00003838 virtual void ActOnPragmaWeakAlias(IdentifierInfo* WeakName,
3839 IdentifierInfo* AliasName,
3840 SourceLocation PragmaLoc,
3841 SourceLocation WeakNameLoc,
3842 SourceLocation AliasNameLoc);
3843
Chris Lattner574aa402009-02-17 01:09:29 +00003844 /// getPragmaPackAlignment() - Return the current alignment as specified by
3845 /// the current #pragma pack directive, or 0 if none is currently active.
3846 unsigned getPragmaPackAlignment() const;
Mike Stump1eb44332009-09-09 15:08:12 +00003847
Chris Lattner574aa402009-02-17 01:09:29 +00003848 /// FreePackedContext - Deallocate and null out PackContext.
3849 void FreePackedContext();
Daniel Dunbar4cde9272008-10-14 05:35:18 +00003850
Chris Lattner1e0a3902008-01-16 19:17:22 +00003851 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
3852 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregoreb8f3062008-11-12 17:17:38 +00003853 /// If isLvalue, the result of the cast is an lvalue.
Eli Friedman73c39ab2009-10-20 08:27:19 +00003854 void ImpCastExprToType(Expr *&Expr, QualType Type, CastExpr::CastKind Kind,
Anders Carlsson3503d042009-07-31 01:23:52 +00003855 bool isLvalue = false);
Chris Lattner1e0a3902008-01-16 19:17:22 +00003856
Reid Spencer5f016e22007-07-11 17:01:13 +00003857 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner925e60d2007-12-28 05:29:59 +00003858 // functions and arrays to their respective pointers (C99 6.3.2.1).
Mike Stump1eb44332009-09-09 15:08:12 +00003859 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3c0eb162008-05-27 03:33:27 +00003860
Steve Naroffc80b4ee2007-07-16 21:54:35 +00003861 // DefaultFunctionArrayConversion - converts functions and arrays
Mike Stump1eb44332009-09-09 15:08:12 +00003862 // to their respective pointers (C99 6.3.2.1).
Steve Naroffc80b4ee2007-07-16 21:54:35 +00003863 void DefaultFunctionArrayConversion(Expr *&expr);
Mike Stump1eb44332009-09-09 15:08:12 +00003864
Douglas Gregora873dfc2010-02-03 00:27:59 +00003865 // DefaultFunctionArrayLvalueConversion - converts functions and
3866 // arrays to their respective pointers and performs the
3867 // lvalue-to-rvalue conversion.
3868 void DefaultFunctionArrayLvalueConversion(Expr *&expr);
3869
Steve Naroffb291ab62007-08-28 23:30:39 +00003870 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
Mike Stump1eb44332009-09-09 15:08:12 +00003871 // do not have a prototype. Integer promotions are performed on each
Steve Naroffb291ab62007-08-28 23:30:39 +00003872 // argument, and arguments that have type float are promoted to double.
Chris Lattner925e60d2007-12-28 05:29:59 +00003873 void DefaultArgumentPromotion(Expr *&Expr);
Anders Carlssondce5e2c2009-01-16 16:48:51 +00003874
3875 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
3876 enum VariadicCallType {
3877 VariadicFunction,
3878 VariadicBlock,
Anders Carlssond74d4142009-09-08 01:48:42 +00003879 VariadicMethod,
Fariborz Jahanian4cd1c702009-11-24 19:27:49 +00003880 VariadicConstructor,
3881 VariadicDoesNotApply
Anders Carlssondce5e2c2009-01-16 16:48:51 +00003882 };
Mike Stump1eb44332009-09-09 15:08:12 +00003883
Fariborz Jahanian4cd1c702009-11-24 19:27:49 +00003884 /// GatherArgumentsForCall - Collector argument expressions for various
3885 /// form of call prototypes.
3886 bool GatherArgumentsForCall(SourceLocation CallLoc,
3887 FunctionDecl *FDecl,
3888 const FunctionProtoType *Proto,
3889 unsigned FirstProtoArg,
3890 Expr **Args, unsigned NumArgs,
3891 llvm::SmallVector<Expr *, 8> &AllArgs,
Fariborz Jahanian4cd1c702009-11-24 19:27:49 +00003892 VariadicCallType CallType = VariadicDoesNotApply);
3893
Anders Carlssondce5e2c2009-01-16 16:48:51 +00003894 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
3895 // will warn if the resulting type is not a POD type.
Chris Lattner312531a2009-04-12 08:11:20 +00003896 bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
Mike Stump1eb44332009-09-09 15:08:12 +00003897
Reid Spencer5f016e22007-07-11 17:01:13 +00003898 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
3899 // operands and then handles various conversions that are common to binary
3900 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
Mike Stump1eb44332009-09-09 15:08:12 +00003901 // routine returns the first non-arithmetic type found. The client is
Reid Spencer5f016e22007-07-11 17:01:13 +00003902 // responsible for emitting appropriate error diagnostics.
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00003903 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
3904 bool isCompAssign = false);
Mike Stump1eb44332009-09-09 15:08:12 +00003905
Chris Lattnerb7b61152008-01-04 18:22:42 +00003906 /// AssignConvertType - All of the 'assignment' semantic checks return this
3907 /// enum to indicate whether the assignment was allowed. These checks are
3908 /// done for simple assignments, as well as initialization, return from
3909 /// function, argument passing, etc. The query is phrased in terms of a
3910 /// source and destination type.
Chris Lattner5cf216b2008-01-04 18:04:52 +00003911 enum AssignConvertType {
Chris Lattnerb7b61152008-01-04 18:22:42 +00003912 /// Compatible - the types are compatible according to the standard.
Reid Spencer5f016e22007-07-11 17:01:13 +00003913 Compatible,
Mike Stump1eb44332009-09-09 15:08:12 +00003914
Chris Lattnerb7b61152008-01-04 18:22:42 +00003915 /// PointerToInt - The assignment converts a pointer to an int, which we
3916 /// accept as an extension.
3917 PointerToInt,
Mike Stump1eb44332009-09-09 15:08:12 +00003918
Chris Lattnerb7b61152008-01-04 18:22:42 +00003919 /// IntToPointer - The assignment converts an int to a pointer, which we
3920 /// accept as an extension.
3921 IntToPointer,
Mike Stump1eb44332009-09-09 15:08:12 +00003922
Chris Lattnerb7b61152008-01-04 18:22:42 +00003923 /// FunctionVoidPointer - The assignment is between a function pointer and
3924 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattnerbfe639e2008-01-03 22:56:36 +00003925 FunctionVoidPointer,
Chris Lattnerb7b61152008-01-04 18:22:42 +00003926
3927 /// IncompatiblePointer - The assignment is between two pointers types that
3928 /// are not compatible, but we accept them as an extension.
Reid Spencer5f016e22007-07-11 17:01:13 +00003929 IncompatiblePointer,
Eli Friedmanf05c05d2009-03-22 23:59:44 +00003930
3931 /// IncompatiblePointer - The assignment is between two pointers types which
3932 /// point to integers which have a different sign, but are otherwise identical.
3933 /// This is a subset of the above, but broken out because it's by far the most
3934 /// common case of incompatible pointers.
3935 IncompatiblePointerSign,
3936
Chris Lattnerb7b61152008-01-04 18:22:42 +00003937 /// CompatiblePointerDiscardsQualifiers - The assignment discards
3938 /// c/v/r qualifiers, which we accept as an extension.
3939 CompatiblePointerDiscardsQualifiers,
Fariborz Jahanian36a862f2009-11-07 20:20:40 +00003940
Sean Huntc9132b62009-11-08 07:46:34 +00003941 /// IncompatibleNestedPointerQualifiers - The assignment is between two
3942 /// nested pointer types, and the qualifiers other than the first two
Fariborz Jahaniand288baf2009-11-09 22:28:08 +00003943 /// levels differ e.g. char ** -> const char **, but we accept them as an
3944 /// extension.
Sean Huntc9132b62009-11-08 07:46:34 +00003945 IncompatibleNestedPointerQualifiers,
Steve Naroff1c7d0672008-09-04 15:10:53 +00003946
Anders Carlssonb0f90cc2009-01-30 23:17:46 +00003947 /// IncompatibleVectors - The assignment is between two vector types that
3948 /// have the same size, which we accept as an extension.
3949 IncompatibleVectors,
Mike Stump1eb44332009-09-09 15:08:12 +00003950
3951 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff1c7d0672008-09-04 15:10:53 +00003952 /// pointer. We disallow this.
3953 IntToBlockPointer,
3954
Mike Stump1eb44332009-09-09 15:08:12 +00003955 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff1c7d0672008-09-04 15:10:53 +00003956 /// pointers types that are not compatible.
3957 IncompatibleBlockPointer,
Mike Stump1eb44332009-09-09 15:08:12 +00003958
Steve Naroff39579072008-10-14 22:18:38 +00003959 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
3960 /// id type and something else (that is incompatible with it). For example,
3961 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
3962 IncompatibleObjCQualifiedId,
Mike Stump1eb44332009-09-09 15:08:12 +00003963
Chris Lattnerb7b61152008-01-04 18:22:42 +00003964 /// Incompatible - We reject this conversion outright, it is invalid to
3965 /// represent it in the AST.
3966 Incompatible
Reid Spencer5f016e22007-07-11 17:01:13 +00003967 };
Douglas Gregor68647482009-12-16 03:45:30 +00003968
Chris Lattner5cf216b2008-01-04 18:04:52 +00003969 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
3970 /// assignment conversion type specified by ConvTy. This returns true if the
3971 /// conversion was invalid or false if the conversion was accepted.
3972 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
3973 SourceLocation Loc,
3974 QualType DstType, QualType SrcType,
Douglas Gregor68647482009-12-16 03:45:30 +00003975 Expr *SrcExpr, AssignmentAction Action);
Mike Stump1eb44332009-09-09 15:08:12 +00003976
3977 /// CheckAssignmentConstraints - Perform type checking for assignment,
3978 /// argument passing, variable initialization, and function return values.
Chris Lattner5cf216b2008-01-04 18:04:52 +00003979 /// This routine is only used by the following two methods. C99 6.5.16.
3980 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Mike Stump1eb44332009-09-09 15:08:12 +00003981
3982 // CheckSingleAssignmentConstraints - Currently used by
3983 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroff90045e82007-07-13 23:32:42 +00003984 // this routine performs the default function/array converions.
Mike Stump1eb44332009-09-09 15:08:12 +00003985 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
Chris Lattner5cf216b2008-01-04 18:04:52 +00003986 Expr *&rExpr);
Douglas Gregor0c74e8a2009-04-29 22:16:16 +00003987
3988 // \brief If the lhs type is a transparent union, check whether we
3989 // can initialize the transparent union with the given expression.
Mike Stump1eb44332009-09-09 15:08:12 +00003990 AssignConvertType CheckTransparentUnionArgumentConstraints(QualType lhs,
Douglas Gregor0c74e8a2009-04-29 22:16:16 +00003991 Expr *&rExpr);
Mike Stump1eb44332009-09-09 15:08:12 +00003992
Reid Spencer5f016e22007-07-11 17:01:13 +00003993 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Mike Stump1eb44332009-09-09 15:08:12 +00003994 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
Chris Lattner5cf216b2008-01-04 18:04:52 +00003995 QualType rhsType);
Mike Stump1eb44332009-09-09 15:08:12 +00003996
Fariborz Jahanian52efc3f2009-12-08 18:24:49 +00003997 AssignConvertType CheckObjCPointerTypesForAssignment(QualType lhsType,
3998 QualType rhsType);
3999
Steve Naroff1c7d0672008-09-04 15:10:53 +00004000 // Helper function for CheckAssignmentConstraints involving two
Sebastian Redld1bd7fc2009-04-19 19:26:31 +00004001 // block pointer types.
Mike Stump1eb44332009-09-09 15:08:12 +00004002 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
Steve Naroff1c7d0672008-09-04 15:10:53 +00004003 QualType rhsType);
Douglas Gregor77a52232008-09-12 00:47:35 +00004004
4005 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00004006
Sebastian Redl2c7588f2009-10-10 12:04:10 +00004007 bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType);
4008
Mike Stump1eb44332009-09-09 15:08:12 +00004009 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor68647482009-12-16 03:45:30 +00004010 AssignmentAction Action,
Sebastian Redle2b68332009-04-12 17:16:29 +00004011 bool AllowExplicit = false,
4012 bool Elidable = false);
Mike Stump1eb44332009-09-09 15:08:12 +00004013 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor68647482009-12-16 03:45:30 +00004014 AssignmentAction Action,
Fariborz Jahanian51bebc82009-09-23 20:55:32 +00004015 bool AllowExplicit,
4016 bool Elidable,
4017 ImplicitConversionSequence& ICS);
4018 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00004019 const ImplicitConversionSequence& ICS,
Douglas Gregor68647482009-12-16 03:45:30 +00004020 AssignmentAction Action,
Sebastian Redla82e4ae2009-11-14 21:15:49 +00004021 bool IgnoreBaseAccess = false);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00004022 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor45920e82008-12-19 17:40:08 +00004023 const StandardConversionSequence& SCS,
Douglas Gregor68647482009-12-16 03:45:30 +00004024 AssignmentAction Action, bool IgnoreBaseAccess);
Sebastian Redl22460502009-02-07 00:15:38 +00004025
Reid Spencer5f016e22007-07-11 17:01:13 +00004026 /// the following "Check" methods will return a valid/converted QualType
4027 /// or a null QualType (indicating an error diagnostic was issued).
Sebastian Redl22460502009-02-07 00:15:38 +00004028
4029 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
Douglas Gregordf032512009-03-12 22:46:12 +00004030 QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Sebastian Redl7c8bd602009-02-07 20:10:22 +00004031 QualType CheckPointerToMemberOperands( // C++ 5.5
Sebastian Redl22460502009-02-07 00:15:38 +00004032 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
Douglas Gregordf032512009-03-12 22:46:12 +00004033 QualType CheckMultiplyDivideOperands( // C99 6.5.5
Chris Lattner7ef655a2010-01-12 21:23:57 +00004034 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign,
4035 bool isDivide);
Douglas Gregordf032512009-03-12 22:46:12 +00004036 QualType CheckRemainderOperands( // C99 6.5.5
Sebastian Redl22460502009-02-07 00:15:38 +00004037 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Douglas Gregordf032512009-03-12 22:46:12 +00004038 QualType CheckAdditionOperands( // C99 6.5.6
Eli Friedmanab3a8522009-03-28 01:22:36 +00004039 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
Douglas Gregordf032512009-03-12 22:46:12 +00004040 QualType CheckSubtractionOperands( // C99 6.5.6
Eli Friedmanab3a8522009-03-28 01:22:36 +00004041 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
Douglas Gregordf032512009-03-12 22:46:12 +00004042 QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00004043 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Douglas Gregordf032512009-03-12 22:46:12 +00004044 QualType CheckCompareOperands( // C99 6.5.8/9
Douglas Gregora86b8322009-04-06 18:45:53 +00004045 Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc, bool isRelational);
Douglas Gregordf032512009-03-12 22:46:12 +00004046 QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Sebastian Redl22460502009-02-07 00:15:38 +00004047 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Douglas Gregordf032512009-03-12 22:46:12 +00004048 QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff49b45262007-07-13 16:58:59 +00004049 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00004050 // CheckAssignmentOperands is used for both simple and compound assignment.
4051 // For simple assignment, pass both expressions and a null converted type.
4052 // For compound assignment, pass both expressions and the converted type.
Douglas Gregordf032512009-03-12 22:46:12 +00004053 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Narofff1120de2007-08-24 22:33:52 +00004054 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Douglas Gregordf032512009-03-12 22:46:12 +00004055 QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner29a1cfb2008-11-18 01:30:42 +00004056 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Douglas Gregordf032512009-03-12 22:46:12 +00004057 QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff49b45262007-07-13 16:58:59 +00004058 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Sebastian Redl3201f6b2009-04-16 17:51:27 +00004059 QualType CXXCheckConditionalOperands( // C++ 5.16
4060 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Douglas Gregorb2cb1cb2010-02-25 22:29:57 +00004061 QualType FindCompositePointerType(Expr *&E1, Expr *&E2,
4062 bool *NonStandardCompositeType = 0);
Nate Begemanbe2341d2008-07-14 18:02:46 +00004063
Fariborz Jahanianeebc4752009-12-10 19:47:41 +00004064 QualType FindCompositeObjCPointerType(Expr *&LHS, Expr *&RHS,
4065 SourceLocation questionLoc);
4066
Nate Begemanbe2341d2008-07-14 18:02:46 +00004067 /// type checking for vector binary operators.
4068 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
4069 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
4070 SourceLocation l, bool isRel);
Mike Stump1eb44332009-09-09 15:08:12 +00004071
Steve Narofff69936d2007-09-16 03:34:24 +00004072 /// type checking unary operators (subroutines of ActOnUnaryOp).
Reid Spencer5f016e22007-07-11 17:01:13 +00004073 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redle6d5a4a2008-12-20 09:35:34 +00004074 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
4075 bool isInc);
Reid Spencer5f016e22007-07-11 17:01:13 +00004076 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
4077 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattnerba27e2a2009-02-17 08:12:06 +00004078 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
Mike Stump1eb44332009-09-09 15:08:12 +00004079
Steve Naroffe1b31fe2007-07-27 22:15:19 +00004080 /// type checking primary expressions.
Nate Begeman213541a2008-04-18 23:10:10 +00004081 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00004082 const IdentifierInfo *Comp,
Anders Carlsson8f28f992009-08-26 18:25:21 +00004083 SourceLocation CmpLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00004084
Steve Narofff0090632007-09-02 02:04:30 +00004085 /// type checking declaration initializers (C99 6.7.8)
Douglas Gregorcb57fb92009-12-16 06:35:08 +00004086 bool CheckInitList(const InitializedEntity &Entity,
4087 InitListExpr *&InitList, QualType &DeclType);
Steve Naroffd0091aa2008-01-10 22:15:12 +00004088 bool CheckForConstantInitializer(Expr *e, QualType t);
Mike Stump1eb44332009-09-09 15:08:12 +00004089
Douglas Gregor27c8dc02008-10-29 00:13:59 +00004090 // type checking C++ declaration initializers (C++ [dcl.init]).
4091
4092 /// ReferenceCompareResult - Expresses the result of comparing two
4093 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
4094 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
4095 enum ReferenceCompareResult {
4096 /// Ref_Incompatible - The two types are incompatible, so direct
4097 /// reference binding is not possible.
4098 Ref_Incompatible = 0,
4099 /// Ref_Related - The two types are reference-related, which means
4100 /// that their unqualified forms (T1 and T2) are either the same
4101 /// or T1 is a base class of T2.
4102 Ref_Related,
4103 /// Ref_Compatible_With_Added_Qualification - The two types are
4104 /// reference-compatible with added qualification, meaning that
4105 /// they are reference-compatible and the qualifiers on T1 (cv1)
4106 /// are greater than the qualifiers on T2 (cv2).
4107 Ref_Compatible_With_Added_Qualification,
4108 /// Ref_Compatible - The two types are reference-compatible and
4109 /// have equivalent qualifiers (cv1 == cv2).
4110 Ref_Compatible
4111 };
4112
Douglas Gregor393896f2009-11-05 13:06:35 +00004113 ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
4114 QualType T1, QualType T2,
Douglas Gregor15da57e2008-10-29 02:00:59 +00004115 bool& DerivedToBase);
Douglas Gregor27c8dc02008-10-29 00:13:59 +00004116
Sebastian Redl3201f6b2009-04-16 17:51:27 +00004117 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType declType,
Douglas Gregor739d8282009-09-23 23:04:10 +00004118 SourceLocation DeclLoc,
Anders Carlsson2de3ace2009-08-27 17:30:43 +00004119 bool SuppressUserConversions,
4120 bool AllowExplicit,
4121 bool ForceRValue,
Sebastian Redla82e4ae2009-11-14 21:15:49 +00004122 ImplicitConversionSequence *ICS = 0,
4123 bool IgnoreBaseAccess = false);
Douglas Gregor27c8dc02008-10-29 00:13:59 +00004124
Sebastian Redl9cc11e72009-07-25 15:41:38 +00004125 /// CheckCastTypes - Check type constraints for casting between types under
Sebastian Redlef0cb8e2009-07-29 13:50:23 +00004126 /// C semantics, or forward to CXXCheckCStyleCast in C++.
4127 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr,
Mike Stump1eb44332009-09-09 15:08:12 +00004128 CastExpr::CastKind &Kind,
Fariborz Jahaniane9f42082009-08-26 18:55:36 +00004129 CXXMethodDecl *& ConversionDecl,
4130 bool FunctionalStyle = false);
Sebastian Redl9cc11e72009-07-25 15:41:38 +00004131
Mike Stump1eb44332009-09-09 15:08:12 +00004132 // CheckVectorCast - check type constraints for vectors.
Anders Carlsson584b2472007-11-27 07:16:40 +00004133 // Since vectors are an extension, there are no C standard reference for this.
4134 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssona64db8f2007-11-27 05:51:55 +00004135 // returns true if the cast is invalid
Anders Carlssonc3516322009-10-16 02:48:28 +00004136 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
4137 CastExpr::CastKind &Kind);
Mike Stump1eb44332009-09-09 15:08:12 +00004138
4139 // CheckExtVectorCast - check type constraints for extended vectors.
Nate Begeman58d29a42009-06-26 00:50:28 +00004140 // Since vectors are an extension, there are no C standard reference for this.
4141 // We allow casting between vectors and integer datatypes of the same size,
4142 // or vectors and the element type of that vector.
4143 // returns true if the cast is invalid
Anders Carlsson16a89042009-10-16 05:23:41 +00004144 bool CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *&CastExpr,
4145 CastExpr::CastKind &Kind);
Sebastian Redl9cc11e72009-07-25 15:41:38 +00004146
4147 /// CXXCheckCStyleCast - Check constraints of a C-style or function-style
4148 /// cast under C++ semantics.
Sebastian Redlef0cb8e2009-07-29 13:50:23 +00004149 bool CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr,
Fariborz Jahaniane9f42082009-08-26 18:55:36 +00004150 CastExpr::CastKind &Kind, bool FunctionalStyle,
4151 CXXMethodDecl *&ConversionDecl);
Sebastian Redl9cc11e72009-07-25 15:41:38 +00004152
Mike Stump1eb44332009-09-09 15:08:12 +00004153 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
Daniel Dunbar637cebb2008-09-11 00:01:56 +00004154 /// \param Method - May be null.
4155 /// \param [out] ReturnType - The return type of the send.
4156 /// \return true iff there were any incompatible types.
Daniel Dunbar91e19b22008-09-11 00:50:25 +00004157 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattner077bf5e2008-11-24 03:33:13 +00004158 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbar637cebb2008-09-11 00:01:56 +00004159 SourceLocation lbrac, SourceLocation rbrac,
Mike Stump1eb44332009-09-09 15:08:12 +00004160 QualType &ReturnType);
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00004161
John McCall5a881bb2009-10-12 21:59:07 +00004162 /// CheckBooleanCondition - Diagnose problems involving the use of
4163 /// the given expression as a boolean condition (e.g. in an if
4164 /// statement). Also performs the standard function and array
4165 /// decays, possibly changing the input variable.
4166 ///
4167 /// \param Loc - A location associated with the condition, e.g. the
4168 /// 'if' keyword.
4169 /// \return true iff there were any errors
4170 bool CheckBooleanCondition(Expr *&CondExpr, SourceLocation Loc);
4171
4172 /// DiagnoseAssignmentAsCondition - Given that an expression is
4173 /// being used as a boolean condition, warn if it's an assignment.
4174 void DiagnoseAssignmentAsCondition(Expr *E);
4175
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00004176 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
4177 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Sebastian Redl9cc11e72009-07-25 15:41:38 +00004178
Chris Lattnerf4021e72007-08-23 05:46:52 +00004179 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
4180 /// the specified width and sign. If an overflow occurs, detect it and emit
4181 /// the specified diagnostic.
Mike Stump1eb44332009-09-09 15:08:12 +00004182 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
Chris Lattnerf4021e72007-08-23 05:46:52 +00004183 unsigned NewWidth, bool NewSign,
4184 SourceLocation Loc, unsigned DiagID);
Mike Stump1eb44332009-09-09 15:08:12 +00004185
Anders Carlsson15281452008-11-04 16:57:32 +00004186 /// Checks that the Objective-C declaration is declared in the global scope.
4187 /// Emits an error and marks the declaration as invalid if it's not declared
4188 /// in the global scope.
4189 bool CheckObjCDeclScope(Decl *D);
4190
Anders Carlsson7c50aca2007-10-15 20:28:48 +00004191 void InitBuiltinVaListType();
Eli Friedman1b76ada2008-06-03 21:01:11 +00004192
Anders Carlssone21555e2008-11-30 19:50:32 +00004193 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
4194 /// and reports the appropriate diagnostics. Returns false on success.
4195 /// Can optionally return the value of the expression.
Anders Carlsson9f1e5722008-12-06 20:33:04 +00004196 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson4000ea62008-12-01 02:17:22 +00004197
Anders Carlsson9f1e5722008-12-06 20:33:04 +00004198 /// VerifyBitField - verifies that a bit field expression is an ICE and has
Mike Stump1eb44332009-09-09 15:08:12 +00004199 /// the correct width, and that the field type is valid.
Anders Carlsson9f1e5722008-12-06 20:33:04 +00004200 /// Returns false on success.
Eli Friedman1d954f62009-08-15 21:55:26 +00004201 /// Can optionally return whether the bit-field is of width 0
Mike Stump1eb44332009-09-09 15:08:12 +00004202 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
4203 QualType FieldTy, const Expr *BitWidth,
Eli Friedman1d954f62009-08-15 21:55:26 +00004204 bool *ZeroWidth = 0);
Sebastian Redl0eb23302009-01-19 00:08:26 +00004205
Douglas Gregor81b747b2009-09-17 21:32:03 +00004206 /// \name Code completion
4207 //@{
Douglas Gregor01dfea02010-01-10 23:08:15 +00004208 virtual void CodeCompleteOrdinaryName(Scope *S,
4209 CodeCompletionContext CompletionContext);
Douglas Gregor81b747b2009-09-17 21:32:03 +00004210 virtual void CodeCompleteMemberReferenceExpr(Scope *S, ExprTy *Base,
4211 SourceLocation OpLoc,
4212 bool IsArrow);
Douglas Gregor374929f2009-09-18 15:37:17 +00004213 virtual void CodeCompleteTag(Scope *S, unsigned TagSpec);
Douglas Gregor3e1005f2009-09-21 18:10:23 +00004214 virtual void CodeCompleteCase(Scope *S);
Douglas Gregor9c6a0e92009-09-22 15:41:20 +00004215 virtual void CodeCompleteCall(Scope *S, ExprTy *Fn,
4216 ExprTy **Args, unsigned NumArgs);
Douglas Gregor81b747b2009-09-17 21:32:03 +00004217 virtual void CodeCompleteQualifiedId(Scope *S, const CXXScopeSpec &SS,
4218 bool EnteringContext);
Douglas Gregor49f40bd2009-09-18 19:03:04 +00004219 virtual void CodeCompleteUsing(Scope *S);
4220 virtual void CodeCompleteUsingDirective(Scope *S);
4221 virtual void CodeCompleteNamespaceDecl(Scope *S);
4222 virtual void CodeCompleteNamespaceAliasDecl(Scope *S);
Douglas Gregored8d3222009-09-18 20:05:18 +00004223 virtual void CodeCompleteOperatorName(Scope *S);
Steve Naroffece8e712009-10-08 21:55:05 +00004224
Douglas Gregorc464ae82009-12-07 09:27:33 +00004225 virtual void CodeCompleteObjCAtDirective(Scope *S, DeclPtrTy ObjCImpDecl,
4226 bool InInterface);
Douglas Gregorc38c3e12010-01-13 21:54:15 +00004227 virtual void CodeCompleteObjCAtVisibility(Scope *S);
Douglas Gregor9a0c85e2009-12-07 09:51:25 +00004228 virtual void CodeCompleteObjCAtStatement(Scope *S);
4229 virtual void CodeCompleteObjCAtExpression(Scope *S);
Douglas Gregora93b1082009-11-18 23:08:07 +00004230 virtual void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
Douglas Gregor4ad96852009-11-19 07:41:15 +00004231 virtual void CodeCompleteObjCPropertyGetter(Scope *S, DeclPtrTy ClassDecl,
4232 DeclPtrTy *Methods,
4233 unsigned NumMethods);
4234 virtual void CodeCompleteObjCPropertySetter(Scope *S, DeclPtrTy ClassDecl,
4235 DeclPtrTy *Methods,
4236 unsigned NumMethods);
4237
Douglas Gregor60b01cc2009-11-17 23:31:36 +00004238 virtual void CodeCompleteObjCClassMessage(Scope *S, IdentifierInfo *FName,
Douglas Gregord3c68542009-11-19 01:08:35 +00004239 SourceLocation FNameLoc,
4240 IdentifierInfo **SelIdents,
4241 unsigned NumSelIdents);
4242 virtual void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver,
4243 IdentifierInfo **SelIdents,
4244 unsigned NumSelIdents);
Douglas Gregor55385fe2009-11-18 04:19:12 +00004245 virtual void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols,
4246 unsigned NumProtocols);
Douglas Gregor083128f2009-11-18 04:49:41 +00004247 virtual void CodeCompleteObjCProtocolDecl(Scope *S);
Douglas Gregor3b49aca2009-11-18 16:26:39 +00004248 virtual void CodeCompleteObjCInterfaceDecl(Scope *S);
4249 virtual void CodeCompleteObjCSuperclass(Scope *S,
4250 IdentifierInfo *ClassName);
4251 virtual void CodeCompleteObjCImplementationDecl(Scope *S);
Douglas Gregor33ced0b2009-11-18 19:08:43 +00004252 virtual void CodeCompleteObjCInterfaceCategory(Scope *S,
4253 IdentifierInfo *ClassName);
4254 virtual void CodeCompleteObjCImplementationCategory(Scope *S,
4255 IdentifierInfo *ClassName);
Douglas Gregor424b2a52009-11-18 22:56:13 +00004256 virtual void CodeCompleteObjCPropertyDefinition(Scope *S,
Douglas Gregor322328b2009-11-18 22:32:06 +00004257 DeclPtrTy ObjCImpDecl);
4258 virtual void CodeCompleteObjCPropertySynthesizeIvar(Scope *S,
4259 IdentifierInfo *PropertyName,
4260 DeclPtrTy ObjCImpDecl);
Douglas Gregor3b49aca2009-11-18 16:26:39 +00004261 //@}
Douglas Gregor81b747b2009-09-17 21:32:03 +00004262
Chris Lattner59907c42007-08-10 20:18:51 +00004263 //===--------------------------------------------------------------------===//
4264 // Extra semantic analysis beyond the C type system
Ted Kremeneke0e53132010-01-28 23:39:18 +00004265
4266public:
4267 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
4268 unsigned ByteNo) const;
4269
Chris Lattner925e60d2007-12-28 05:29:59 +00004270private:
Anders Carlssond406bf02009-08-16 01:56:34 +00004271 bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
4272 bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall);
Mike Stump1eb44332009-09-09 15:08:12 +00004273
Ryan Flynn4403a5e2009-08-06 03:00:50 +00004274 bool CheckablePrintfAttr(const FormatAttr *Format, CallExpr *TheCall);
Chris Lattner69039812009-02-18 06:01:06 +00004275 bool CheckObjCString(Expr *Arg);
Anders Carlssond406bf02009-08-16 01:56:34 +00004276
4277 Action::OwningExprResult CheckBuiltinFunctionCall(unsigned BuiltinID,
4278 CallExpr *TheCall);
Chris Lattner925e60d2007-12-28 05:29:59 +00004279 bool SemaBuiltinVAStart(CallExpr *TheCall);
4280 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Benjamin Kramer3b1e26b2010-02-16 10:07:31 +00004281 bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs);
Eli Friedman6cfda232008-05-20 08:23:37 +00004282 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Douglas Gregorcde01732009-05-19 22:10:17 +00004283
4284public:
4285 // Used by C++ template instantiation.
Sebastian Redl0eb23302009-01-19 00:08:26 +00004286 Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Douglas Gregorcde01732009-05-19 22:10:17 +00004287
4288private:
Mike Stump1eb44332009-09-09 15:08:12 +00004289 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Eli Friedmand875fed2009-05-03 04:46:36 +00004290 bool SemaBuiltinObjectSize(CallExpr *TheCall);
4291 bool SemaBuiltinLongjmp(CallExpr *TheCall);
Chris Lattner5caa3702009-05-08 06:58:22 +00004292 bool SemaBuiltinAtomicOverloaded(CallExpr *TheCall);
Chris Lattner21fb98e2009-09-23 06:06:36 +00004293 bool SemaBuiltinEHReturnDataRegNo(CallExpr *TheCall);
Ted Kremenek082d9362009-03-20 21:35:28 +00004294 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall,
4295 bool HasVAListArg, unsigned format_idx,
4296 unsigned firstDataArg);
4297 void CheckPrintfString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
4298 const CallExpr *TheCall, bool HasVAListArg,
Douglas Gregor3c385e52009-02-14 18:57:46 +00004299 unsigned format_idx, unsigned firstDataArg);
Mike Stump1eb44332009-09-09 15:08:12 +00004300 void CheckNonNullArguments(const NonNullAttr *NonNull,
Fariborz Jahaniane898f8a2009-05-21 18:48:51 +00004301 const CallExpr *TheCall);
Mike Stump1eb44332009-09-09 15:08:12 +00004302 void CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg,
Douglas Gregor3c385e52009-02-14 18:57:46 +00004303 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek06de2762007-08-17 16:46:58 +00004304 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
4305 SourceLocation ReturnLoc);
Ted Kremenek588e5eb2007-11-25 00:58:00 +00004306 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
John McCall51313c32010-01-04 23:31:57 +00004307 void CheckSignCompare(Expr *LHS, Expr *RHS, SourceLocation Loc,
John McCalld1b47bf2010-03-11 19:43:18 +00004308 const BinaryOperator::Opcode* BinOpc = 0);
John McCall51313c32010-01-04 23:31:57 +00004309 void CheckImplicitConversion(Expr *E, QualType Target);
Reid Spencer5f016e22007-07-11 17:01:13 +00004310};
4311
Ted Kremenek8189cde2009-02-07 01:47:29 +00004312//===--------------------------------------------------------------------===//
4313// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
4314template <typename T>
4315class ExprOwningPtr : public Action::ExprArg {
4316public:
Douglas Gregora0e500d2009-03-12 16:53:44 +00004317 ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {}
Mike Stump1eb44332009-09-09 15:08:12 +00004318
Ted Kremenek8189cde2009-02-07 01:47:29 +00004319 void reset(T* p) { Action::ExprArg::operator=(p); }
4320 T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
4321 T* take() { return static_cast<T*>(Action::ExprArg::take()); }
4322 T* release() { return take(); }
Mike Stump1eb44332009-09-09 15:08:12 +00004323
Ted Kremenek8189cde2009-02-07 01:47:29 +00004324 T& operator*() const { return *get(); }
4325 T* operator->() const { return get(); }
4326};
Douglas Gregord7e27052009-05-20 22:33:37 +00004327
Reid Spencer5f016e22007-07-11 17:01:13 +00004328} // end namespace clang
4329
4330#endif