blob: 8f033197e4442ab2bb8356fc32b7b12bd6113cce [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 Gregoreb11cd02009-01-14 22:20:51 +000021#include "clang/AST/DeclBase.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000022#include "clang/Parse/Action.h"
Chris Lattner500d3292009-01-29 05:15:15 +000023#include "clang/Sema/SemaDiagnostic.h"
Anders Carlssonc1fcb772007-07-22 07:07:56 +000024#include "llvm/ADT/SmallVector.h"
Fariborz Jahanian85ff2642007-10-05 18:00:57 +000025#include "llvm/ADT/DenseSet.h"
Chris Lattnerf3876682007-10-07 01:13:46 +000026#include "llvm/ADT/SmallPtrSet.h"
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +000027#include "llvm/ADT/OwningPtr.h"
Steve Naroff61d68522009-03-05 15:22:01 +000028#include "clang/AST/DeclObjC.h"
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +000029#include <string>
Douglas Gregor94b1dd22008-10-24 04:54:22 +000030#include <vector>
Reid Spencer5f016e22007-07-11 17:01:13 +000031
Chris Lattnerf4021e72007-08-23 05:46:52 +000032namespace llvm {
33 class APSInt;
34}
35
Reid Spencer5f016e22007-07-11 17:01:13 +000036namespace clang {
37 class ASTContext;
Chris Lattner2ae34ed2008-02-06 00:46:58 +000038 class ASTConsumer;
Reid Spencer5f016e22007-07-11 17:01:13 +000039 class Preprocessor;
40 class Decl;
Chris Lattnerb048c982008-04-06 04:47:34 +000041 class DeclContext;
Daniel Dunbar12bc6922008-08-11 03:27:53 +000042 class DeclSpec;
Steve Naroffe8043c32008-04-01 23:04:06 +000043 class NamedDecl;
Sebastian Redl798d1192008-12-13 16:23:55 +000044 class Stmt;
Reid Spencer5f016e22007-07-11 17:01:13 +000045 class Expr;
Steve Naroff6f9f3072007-09-02 15:34:30 +000046 class InitListExpr;
Douglas Gregor05c13a32009-01-22 00:58:24 +000047 class DesignatedInitExpr;
Chris Lattner925e60d2007-12-28 05:29:59 +000048 class CallExpr;
Douglas Gregor1a49af92009-01-06 05:10:23 +000049 class DeclRefExpr;
Reid Spencer5f016e22007-07-11 17:01:13 +000050 class VarDecl;
51 class ParmVarDecl;
52 class TypedefDecl;
53 class FunctionDecl;
54 class QualType;
Sebastian Redl43af76e2009-03-07 12:16:37 +000055 class LangOptions;
Chris Lattnerd2177732007-07-20 16:59:19 +000056 class Token;
Reid Spencer5f016e22007-07-11 17:01:13 +000057 class IntegerLiteral;
Steve Naroffa49e1fa2008-01-22 00:55:40 +000058 class StringLiteral;
Reid Spencer5f016e22007-07-11 17:01:13 +000059 class ArrayType;
60 class LabelStmt;
Anders Carlssonc1fcb772007-07-22 07:07:56 +000061 class SwitchStmt;
Nate Begeman213541a2008-04-18 23:10:10 +000062 class ExtVectorType;
Steve Naroffbea0b342007-07-29 16:33:31 +000063 class TypedefDecl;
Douglas Gregoraaba5e32009-02-04 19:02:06 +000064 class TemplateDecl;
Douglas Gregor3e00bad2009-02-17 01:05:43 +000065 class TemplateArgument;
Douglas Gregorddc29e12009-02-06 22:42:48 +000066 class TemplateParameterList;
Douglas Gregorc15cb382009-02-09 23:23:08 +000067 class TemplateTemplateParmDecl;
Douglas Gregor88b70942009-02-25 22:02:03 +000068 class ClassTemplateDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000069 class ObjCInterfaceDecl;
Steve Naroffe8043c32008-04-01 23:04:06 +000070 class ObjCCompatibleAliasDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000071 class ObjCProtocolDecl;
Chris Lattnercddc8882009-03-01 00:56:52 +000072 class ObjCImplDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000073 class ObjCImplementationDecl;
74 class ObjCCategoryImplDecl;
75 class ObjCCategoryDecl;
76 class ObjCIvarDecl;
77 class ObjCMethodDecl;
Fariborz Jahanian02edb982008-05-01 00:03:38 +000078 class ObjCPropertyDecl;
Steve Naroff0701bbb2009-01-08 17:28:14 +000079 class ObjCContainerDecl;
Steve Naroff4eb206b2008-09-03 18:15:37 +000080 struct BlockSemaInfo;
Douglas Gregor94b1dd22008-10-24 04:54:22 +000081 class BasePaths;
Sebastian Redl43af76e2009-03-07 12:16:37 +000082 struct MemberLookupCriteria;
Steve Naroffbea0b342007-07-29 16:33:31 +000083
Reid Spencer5f016e22007-07-11 17:01:13 +000084/// Sema - This implements semantic analysis and AST building for C.
85class Sema : public Action {
Chris Lattnerf50adff2009-02-17 00:58:30 +000086 Sema(const Sema&); // DO NOT IMPLEMENT
87 void operator=(const Sema&); // DO NOT IMPLEMENT
Chris Lattner0b2f4da2008-06-29 00:28:59 +000088public:
Chris Lattner53ebff32009-01-22 19:21:44 +000089 const LangOptions &LangOpts;
Reid Spencer5f016e22007-07-11 17:01:13 +000090 Preprocessor &PP;
Reid Spencer5f016e22007-07-11 17:01:13 +000091 ASTContext &Context;
Chris Lattner2ae34ed2008-02-06 00:46:58 +000092 ASTConsumer &Consumer;
Chris Lattner3cfa9282008-11-22 08:28:49 +000093 Diagnostic &Diags;
94 SourceManager &SourceMgr;
Steve Naroff03300712007-11-12 13:56:41 +000095
Argyrios Kyrtzidis53d0ea52008-06-28 06:07:14 +000096 /// CurContext - This is the current declaration context of parsing.
Chris Lattnerb048c982008-04-06 04:47:34 +000097 DeclContext *CurContext;
Chris Lattner0ed844b2008-04-04 06:12:32 +000098
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000099 /// PreDeclaratorDC - Keeps the declaration context before switching to the
100 /// context of a declarator's nested-name-specifier.
101 DeclContext *PreDeclaratorDC;
102
Steve Naroff4eb206b2008-09-03 18:15:37 +0000103 /// CurBlock - If inside of a block definition, this contains a pointer to
104 /// the active block object that represents it.
105 BlockSemaInfo *CurBlock;
106
Steve Narofff3cf8972009-02-28 16:48:43 +0000107 /// ActiveScope - If inside of a function, method, or block definition,
108 /// this contains a pointer to the active scope that represents it.
109 Scope *ActiveScope;
110
Daniel Dunbar4cde9272008-10-14 05:35:18 +0000111 /// PackContext - Manages the stack for #pragma pack. An alignment
112 /// of 0 indicates default alignment.
Chris Lattner574aa402009-02-17 01:09:29 +0000113 void *PackContext; // Really a "PragmaPackStack*"
Daniel Dunbar4cde9272008-10-14 05:35:18 +0000114
Anders Carlssonc1fcb772007-07-22 07:07:56 +0000115 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffbea0b342007-07-29 16:33:31 +0000116
Nate Begeman213541a2008-04-18 23:10:10 +0000117 /// ExtVectorDecls - This is a list all the extended vector types. This allows
118 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroffbea0b342007-07-29 16:33:31 +0000119 /// This is only necessary for issuing pretty diagnostics.
Nate Begeman213541a2008-04-18 23:10:10 +0000120 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattner59907c42007-08-10 20:18:51 +0000121
Steve Naroffe84a8642008-09-28 14:55:53 +0000122 /// ObjCImplementations - Keep track of all class @implementations
123 /// so we can emit errors on duplicates.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000124 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattnerf3876682007-10-07 01:13:46 +0000125
Steve Naroffe84a8642008-09-28 14:55:53 +0000126 /// ObjCCategoryImpls - Maintain a list of category implementations so
127 /// we can check for duplicates and find local method declarations.
128 llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
129
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000130 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanian05672a02007-10-09 18:03:53 +0000131 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner4de884d2007-10-09 18:18:24 +0000132 /// find the declarations when needed.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000133 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff31102512008-04-02 18:30:49 +0000134
135 /// ObjCInterfaceDecls - Keep track of all class declarations declared
136 /// with @interface, so that we can emit errors on duplicates and
137 /// find the declarations when needed.
138 typedef llvm::DenseMap<const IdentifierInfo*,
139 ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
140 ObjCInterfaceDeclsTy ObjCInterfaceDecls;
141
Steve Naroffe8043c32008-04-01 23:04:06 +0000142 /// ObjCAliasDecls - Keep track of all class declarations declared
143 /// with @compatibility_alias, so that we can emit errors on duplicates and
144 /// find the declarations when needed. This construct is ancient and will
145 /// likely never be seen. Nevertheless, it is here for compatibility.
Steve Naroffc822ff42008-04-02 00:39:51 +0000146 typedef llvm::DenseMap<const IdentifierInfo*,
147 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroffe8043c32008-04-01 23:04:06 +0000148 ObjCAliasTy ObjCAliasDecls;
Steve Naroff31102512008-04-02 18:30:49 +0000149
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000150 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
151 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
152
Douglas Gregor63935192009-03-02 00:19:53 +0000153 /// \brief A mapping from external names to the most recent
154 /// locally-scoped external declaration with that name.
155 ///
156 /// This map contains external declarations introduced in local
157 /// scoped, e.g.,
158 ///
159 /// \code
160 /// void f() {
161 /// void foo(int, int);
162 /// }
163 /// \endcode
164 ///
165 /// Here, the name "foo" will be associated with the declaration on
166 /// "foo" within f. This name is not visible outside of
167 /// "f". However, we still find it in two cases:
168 ///
169 /// - If we are declaring another external with the name "foo", we
170 /// can find "foo" as a previous declaration, so that the types
171 /// of this external declaration can be checked for
172 /// compatibility.
173 ///
174 /// - If we would implicitly declare "foo" (e.g., due to a call to
175 /// "foo" in C when no prototype or definition is visible), then
176 /// we find this declaration of "foo" and complain that it is
177 /// not visible.
178 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
179
Chris Lattner7f925cc2008-04-11 07:00:53 +0000180 IdentifierResolver IdResolver;
181
Chris Lattner59907c42007-08-10 20:18:51 +0000182 // Enum values used by KnownFunctionIDs (see below).
183 enum {
Ted Kremenek7ff22b22008-06-16 18:00:42 +0000184 id_NSLog,
Douglas Gregor3c385e52009-02-14 18:57:46 +0000185 id_NSLogv,
Daniel Dunbarde454282008-10-02 18:44:07 +0000186 id_asprintf,
Chris Lattner59907c42007-08-10 20:18:51 +0000187 id_vasprintf,
Chris Lattner59907c42007-08-10 20:18:51 +0000188 id_num_known_functions
189 };
190
191 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
192 /// of known functions used by the semantic analysis to do various
193 /// kinds of checking (e.g. checking format string errors in printf calls).
194 /// This list is populated upon the creation of a Sema object.
Chris Lattner06f54852008-08-23 02:00:52 +0000195 IdentifierInfo* KnownFunctionIDs[id_num_known_functions];
Daniel Dunbar662e8b52008-08-14 22:04:54 +0000196
Steve Naroffe440eb82007-10-10 17:32:04 +0000197 /// Translation Unit Scope - useful to Objective-C actions that need
198 /// to lookup file scope declarations in the "ordinary" C decl namespace.
199 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroffb216c882007-10-09 22:01:59 +0000200 Scope *TUScope;
Sebastian Redlc42e1182008-11-11 11:37:55 +0000201
202 /// The C++ "std" namespace, where the standard library resides. Cached here
203 /// by GetStdNamespace
204 NamespaceDecl *StdNamespace;
Sebastian Redlb5a57a62008-12-03 20:26:15 +0000205
206 /// A flag to remember whether the implicit forms of operator new and delete
207 /// have been declared.
208 bool GlobalNewDeleteDeclared;
Steve Naroff3b950172007-10-10 21:53:07 +0000209
Steve Naroff58ff9e82007-10-14 00:58:41 +0000210 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000211 struct ObjCMethodList {
212 ObjCMethodDecl *Method;
213 ObjCMethodList *Next;
Steve Naroff58ff9e82007-10-14 00:58:41 +0000214
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000215 ObjCMethodList() {
Steve Naroff58ff9e82007-10-14 00:58:41 +0000216 Method = 0;
217 Next = 0;
218 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000219 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff58ff9e82007-10-14 00:58:41 +0000220 Method = M;
221 Next = C;
222 }
223 };
224 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
225 /// messages to "id". We need to maintain a list, since selectors can have
226 /// differing signatures across classes. In Cocoa, this happens to be
227 /// extremely uncommon (only 1% of selectors are "overloaded").
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000228 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
229 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Steve Naroff6b9dfd42009-03-04 15:11:40 +0000230
231 /// Private Helper predicate to check for 'self'.
232 bool isSelfExpr(Expr *RExpr);
Reid Spencer5f016e22007-07-11 17:01:13 +0000233public:
Chris Lattner2ae34ed2008-02-06 00:46:58 +0000234 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
Chris Lattner574aa402009-02-17 01:09:29 +0000235 ~Sema() {
236 if (PackContext) FreePackedContext();
237 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000238
Chris Lattner53ebff32009-01-22 19:21:44 +0000239 const LangOptions &getLangOptions() const { return LangOpts; }
Chris Lattner3cfa9282008-11-22 08:28:49 +0000240 Diagnostic &getDiagnostics() const { return Diags; }
241 SourceManager &getSourceManager() const { return SourceMgr; }
242
Chris Lattnerebf5ddf2008-11-18 21:53:24 +0000243 /// The primitive diagnostic helpers.
Chris Lattner3cfa9282008-11-22 08:28:49 +0000244 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
Douglas Gregoree1828a2009-03-10 18:03:33 +0000245 DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
Douglas Gregor27b152f2009-03-10 18:52:44 +0000246 if (!Diags.isBuiltinNote(DiagID) &&
247 !ActiveTemplateInstantiations.empty() &&
Douglas Gregordf667e72009-03-10 20:44:00 +0000248 ActiveTemplateInstantiations.back()
Douglas Gregor27b152f2009-03-10 18:52:44 +0000249 != LastTemplateInstantiationErrorContext)
Douglas Gregoree1828a2009-03-10 18:03:33 +0000250 DB << PostDiagnosticHook(PrintInstantiationStackHook, this);
251 return DB;
Chris Lattner3cfa9282008-11-22 08:28:49 +0000252 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000253
Chris Lattner394a3fd2007-08-31 04:53:24 +0000254 virtual void DeleteExpr(ExprTy *E);
255 virtual void DeleteStmt(StmtTy *S);
256
Sebastian Redl798d1192008-12-13 16:23:55 +0000257 OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); }
Sebastian Redl0eb23302009-01-19 00:08:26 +0000258 OwningExprResult Owned(ExprResult R) {
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000259 if (R.isInvalid())
Steve Naroff872b9ac2009-01-21 22:32:33 +0000260 return ExprError();
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000261 return OwningExprResult(*this, R.get());
Sebastian Redl0eb23302009-01-19 00:08:26 +0000262 }
Sebastian Redl798d1192008-12-13 16:23:55 +0000263 OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
264
Chris Lattner9299f3f2008-08-23 03:19:52 +0000265 virtual void ActOnEndOfTranslationUnit();
Sebastian Redlb8a6aca2009-01-19 22:31:54 +0000266
Reid Spencer5f016e22007-07-11 17:01:13 +0000267 //===--------------------------------------------------------------------===//
268 // Type Analysis / Processing: SemaType.cpp.
269 //
Chris Lattnerfca0ddd2008-06-26 06:27:57 +0000270 QualType ConvertDeclSpecToType(const DeclSpec &DS);
Chris Lattnerc9b346d2008-06-29 00:50:08 +0000271 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Douglas Gregorcd281c32009-02-28 00:25:32 +0000272 QualType BuildPointerType(QualType T, unsigned Quals,
273 SourceLocation Loc, DeclarationName Entity);
274 QualType BuildReferenceType(QualType T, unsigned Quals,
275 SourceLocation Loc, DeclarationName Entity);
276 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
277 Expr *ArraySize, unsigned Quals,
278 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor724651c2009-02-28 01:04:19 +0000279 QualType BuildFunctionType(QualType T,
280 QualType *ParamTypes, unsigned NumParamTypes,
281 bool Variadic, unsigned Quals,
282 SourceLocation Loc, DeclarationName Entity);
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000283 QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0);
Douglas Gregor10bd3682008-11-17 22:58:34 +0000284 DeclarationName GetNameForDeclarator(Declarator &D);
285
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000286 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahanian306d68f2007-11-08 23:49:49 +0000287
Douglas Gregor57373262008-10-22 14:17:15 +0000288 bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
289
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000290 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Sebastian Redl37d6de32008-11-08 13:00:26 +0000291
Douglas Gregor86447ec2009-03-09 16:13:40 +0000292 bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned diag,
Douglas Gregor4ec339f2009-01-19 19:26:10 +0000293 SourceRange Range1 = SourceRange(),
294 SourceRange Range2 = SourceRange(),
295 QualType PrintType = QualType());
296
Reid Spencer5f016e22007-07-11 17:01:13 +0000297 //===--------------------------------------------------------------------===//
298 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
299 //
Chris Lattner21ff9c92009-03-05 01:25:28 +0000300
301 /// getDeclName - Return a pretty name for the specified decl if possible, or
302 /// an empty string if not. This is used for pretty crash reporting.
303 virtual std::string getDeclName(DeclTy *D);
304
Douglas Gregor1a51b4a2009-02-09 15:09:02 +0000305 virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Douglas Gregorb696ea32009-02-04 17:00:24 +0000306 Scope *S, const CXXScopeSpec *SS);
Chris Lattner76a642f2009-02-15 22:43:40 +0000307 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){
Douglas Gregor584049d2008-12-15 23:53:10 +0000308 return ActOnDeclarator(S, D, LastInGroup, false);
309 }
310 DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
311 bool IsFunctionDefinition);
Douglas Gregor63935192009-03-02 00:19:53 +0000312 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl,
313 Scope *S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000314 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
315 QualType R, Decl* LastDeclarator,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000316 Decl* PrevDecl, bool& InvalidDecl,
317 bool &Redeclaration);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000318 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000319 QualType R, Decl* LastDeclarator,
Douglas Gregor8f301052009-02-24 19:23:27 +0000320 NamedDecl* PrevDecl, bool& InvalidDecl,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000321 bool &Redeclaration);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000322 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
323 QualType R, Decl *LastDeclarator,
Douglas Gregor04495c82009-02-24 01:23:02 +0000324 NamedDecl* PrevDecl,
325 bool IsFunctionDefinition,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000326 bool& InvalidDecl, bool &Redeclaration);
Chris Lattner04421082008-04-08 04:40:51 +0000327 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
328 virtual void ActOnParamDefaultArgument(DeclTy *param,
329 SourceLocation EqualLoc,
330 ExprTy *defarg);
Douglas Gregor61366e92008-12-24 00:01:03 +0000331 virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
332 SourceLocation EqualLoc);
Douglas Gregor72b505b2008-12-16 21:30:33 +0000333 virtual void ActOnParamDefaultArgumentError(DeclTy *param);
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000334 virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
335 void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit);
Douglas Gregor27c8dc02008-10-29 00:13:59 +0000336 void ActOnUninitializedDecl(DeclTy *dcl);
Reid Spencer5f016e22007-07-11 17:01:13 +0000337 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
338
Douglas Gregorbe109b32009-01-23 16:23:13 +0000339 virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D);
Chris Lattnerb652cea2007-10-09 17:14:05 +0000340 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000341 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Steve Naroffebf64432009-02-28 16:59:13 +0000342 virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D);
Sebastian Redlb8a6aca2009-01-19 22:31:54 +0000343
Sebastian Redl798d1192008-12-13 16:23:55 +0000344 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
Sebastian Redl798d1192008-12-13 16:23:55 +0000345 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000346
Steve Naroffb216c882007-10-09 22:01:59 +0000347 /// Scope actions.
348 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
349 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000350
351 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
352 /// no declarator (e.g. "struct foo;") is parsed.
Sebastian Redla4ed0d82008-12-28 15:28:59 +0000353 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Reid Spencer5f016e22007-07-11 17:01:13 +0000354
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000355 bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
356 RecordDecl *AnonRecord);
357 virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
358 RecordDecl *Record);
359
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000360 virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000361 SourceLocation KWLoc, const CXXScopeSpec &SS,
362 IdentifierInfo *Name, SourceLocation NameLoc,
Douglas Gregorddc29e12009-02-06 22:42:48 +0000363 AttributeList *Attr);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000364
Douglas Gregor44b43212008-12-11 16:49:14 +0000365 virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner06f54852008-08-23 02:00:52 +0000366 IdentifierInfo *ClassName,
367 llvm::SmallVectorImpl<DeclTy*> &Decls);
Douglas Gregor44b43212008-12-11 16:49:14 +0000368 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Reid Spencer5f016e22007-07-11 17:01:13 +0000369 Declarator &D, ExprTy *BitfieldWidth);
Chris Lattner24793662009-03-05 22:45:59 +0000370
371 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
Douglas Gregor4dd55f52009-03-11 20:50:30 +0000372 Declarator &D, Expr *BitfieldWidth,
373 AccessSpecifier AS);
Chris Lattner24793662009-03-05 22:45:59 +0000374
Douglas Gregor3cf538d2009-03-11 18:59:21 +0000375 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
376 RecordDecl *Record, SourceLocation Loc,
377 bool Mutable, Expr *BitfieldWidth,
Douglas Gregor4dd55f52009-03-11 20:50:30 +0000378 AccessSpecifier AS, NamedDecl *PrevDecl,
Douglas Gregor3cf538d2009-03-11 18:59:21 +0000379 Declarator *D = 0);
Fariborz Jahanian1d78cc42008-04-10 23:32:45 +0000380
381 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
382 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian45bc03f2008-04-11 16:55:42 +0000383 tok::ObjCKeywordKind visibility);
Fariborz Jahanian1d78cc42008-04-10 23:32:45 +0000384
Steve Narofff13271f2007-09-14 23:09:53 +0000385 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian9d048ff2007-09-29 00:54:24 +0000386 virtual void ActOnFields(Scope* S,
Steve Naroff60fccee2007-10-29 21:38:07 +0000387 SourceLocation RecLoc, DeclTy *TagDecl,
388 DeclTy **Fields, unsigned NumFields,
Daniel Dunbar1bfe1c22008-10-03 02:03:53 +0000389 SourceLocation LBrac, SourceLocation RBrac,
390 AttributeList *AttrList);
Douglas Gregor72de6672009-01-08 20:45:30 +0000391
392 /// ActOnTagStartDefinition - Invoked when we have entered the
393 /// scope of a tag's definition (e.g., for an enumeration, class,
394 /// struct, or union).
395 virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl);
396
397 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
398 /// the definition of a tag (enumeration, class, struct, or union).
399 virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl);
400
Steve Naroff08d92e42007-09-15 18:49:24 +0000401 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Reid Spencer5f016e22007-07-11 17:01:13 +0000402 DeclTy *LastEnumConstant,
403 SourceLocation IdLoc, IdentifierInfo *Id,
404 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff08d92e42007-09-15 18:49:24 +0000405 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Reid Spencer5f016e22007-07-11 17:01:13 +0000406 DeclTy **Elements, unsigned NumElements);
Sebastian Redl37d6de32008-11-08 13:00:26 +0000407
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +0000408 DeclContext *getContainingDC(DeclContext *DC);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000409
Chris Lattner0ed844b2008-04-04 06:12:32 +0000410 /// Set the current declaration context until it gets popped.
Douglas Gregor44b43212008-12-11 16:49:14 +0000411 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattnerb048c982008-04-06 04:47:34 +0000412 void PopDeclContext();
Argyrios Kyrtzidis53d0ea52008-06-28 06:07:14 +0000413
Chris Lattner371f2582008-12-04 23:50:19 +0000414 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
415 /// to the function decl for the function being parsed. If we're currently
416 /// in a 'block', this returns the containing context.
417 FunctionDecl *getCurFunctionDecl();
418
419 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
420 /// the method decl for the method being parsed. If we're currently
421 /// in a 'block', this returns the containing context.
Daniel Dunbarc4a1dea2008-08-11 05:35:13 +0000422 ObjCMethodDecl *getCurMethodDecl();
Chris Lattner0ed844b2008-04-04 06:12:32 +0000423
Chris Lattner371f2582008-12-04 23:50:19 +0000424 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
425 /// or C function we're in, otherwise return null. If we're currently
426 /// in a 'block', this returns the containing context.
427 NamedDecl *getCurFunctionOrMethodDecl();
428
Argyrios Kyrtzidis87f3ff02008-04-12 00:47:19 +0000429 /// Add this decl to the scope shadowed decl chains.
430 void PushOnScopeChains(NamedDecl *D, Scope *S);
431
Argyrios Kyrtzidis15a12d02008-09-09 21:18:04 +0000432 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
433 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
434 /// true if 'D' belongs to the given declaration context.
435 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
Douglas Gregor44b43212008-12-11 16:49:14 +0000436 return IdResolver.isDeclInScope(D, Ctx, Context, S);
Argyrios Kyrtzidis15a12d02008-09-09 21:18:04 +0000437 }
438
Eli Friedman8f17b662009-02-28 05:41:13 +0000439
440 void RecursiveCalcJumpScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
441 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
442 llvm::DenseMap<Stmt*, void*>& GotoScopeMap,
443 std::vector<void*>& ScopeStack,
444 Stmt* CurStmt);
445
446 void RecursiveCalcLabelScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
447 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
448 std::vector<void*>& ScopeStack,
449 Stmt* CurStmt,
450 Stmt* ParentCompoundStmt);
451
Chris Lattnerf1d705c2008-02-21 01:07:18 +0000452 /// Subroutines of ActOnDeclarator().
Chris Lattner41af0932007-11-14 06:34:38 +0000453 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000454 Decl *LastDecl);
Douglas Gregorcda9c672009-02-16 17:45:42 +0000455 bool MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
456 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
Douglas Gregor04495c82009-02-24 01:23:02 +0000457 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregorcda9c672009-02-16 17:45:42 +0000458 bool MergeVarDecl(VarDecl *New, Decl *Old);
459 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000460
461 /// C++ Overloading.
462 bool IsOverload(FunctionDecl *New, Decl* OldD,
463 OverloadedFunctionDecl::function_iterator &MatchedDecl);
Douglas Gregor225c41e2008-11-03 19:09:14 +0000464 ImplicitConversionSequence
465 TryImplicitConversion(Expr* From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000466 bool SuppressUserConversions = false,
467 bool AllowExplicit = false);
Douglas Gregor60d62c22008-10-31 16:23:19 +0000468 bool IsStandardConversion(Expr *From, QualType ToType,
469 StandardConversionSequence& SCS);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000470 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
471 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
Douglas Gregor5cdf8212009-02-12 00:15:05 +0000472 bool IsComplexPromotion(QualType FromType, QualType ToType);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000473 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregor45920e82008-12-19 17:40:08 +0000474 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregorc7887512008-12-19 19:13:09 +0000475 bool isObjCPointerConversion(QualType FromType, QualType ToType,
476 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregor94b1dd22008-10-24 04:54:22 +0000477 bool CheckPointerConversion(Expr *From, QualType ToType);
Sebastian Redl4433aaf2009-01-25 19:43:20 +0000478 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
479 QualType &ConvertedType);
480 bool CheckMemberPointerConversion(Expr *From, QualType ToType);
Douglas Gregor98cd5992008-10-21 23:43:52 +0000481 bool IsQualificationConversion(QualType FromType, QualType ToType);
Douglas Gregor60d62c22008-10-31 16:23:19 +0000482 bool IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000483 UserDefinedConversionSequence& User,
Douglas Gregor734d9862009-01-30 23:27:23 +0000484 bool AllowConversionFunctions,
485 bool AllowExplicit);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000486
487 ImplicitConversionSequence::CompareKind
488 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
489 const ImplicitConversionSequence& ICS2);
490
491 ImplicitConversionSequence::CompareKind
492 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
493 const StandardConversionSequence& SCS2);
494
Douglas Gregor57373262008-10-22 14:17:15 +0000495 ImplicitConversionSequence::CompareKind
496 CompareQualificationConversions(const StandardConversionSequence& SCS1,
497 const StandardConversionSequence& SCS2);
498
Douglas Gregorbc0805a2008-10-23 00:40:37 +0000499 ImplicitConversionSequence::CompareKind
500 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
501 const StandardConversionSequence& SCS2);
502
Douglas Gregor225c41e2008-11-03 19:09:14 +0000503 ImplicitConversionSequence
504 TryCopyInitialization(Expr* From, QualType ToType,
505 bool SuppressUserConversions = false);
Douglas Gregor27c8dc02008-10-29 00:13:59 +0000506 bool PerformCopyInitialization(Expr *&From, QualType ToType,
507 const char *Flavor);
508
Douglas Gregor96176b32008-11-18 23:14:02 +0000509 ImplicitConversionSequence
510 TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method);
511 bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method);
512
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000513 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
514 bool PerformContextuallyConvertToBool(Expr *&From);
515
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000516 /// OverloadingResult - Capture the result of performing overload
517 /// resolution.
518 enum OverloadingResult {
519 OR_Success, ///< Overload resolution succeeded.
520 OR_No_Viable_Function, ///< No viable function found.
Douglas Gregor48f3bb92009-02-18 21:56:37 +0000521 OR_Ambiguous, ///< Ambiguous candidates found.
522 OR_Deleted ///< Overload resoltuion refers to a deleted function.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000523 };
524
525 void AddOverloadCandidate(FunctionDecl *Function,
526 Expr **Args, unsigned NumArgs,
Douglas Gregor225c41e2008-11-03 19:09:14 +0000527 OverloadCandidateSet& CandidateSet,
528 bool SuppressUserConversions = false);
Douglas Gregor96176b32008-11-18 23:14:02 +0000529 void AddMethodCandidate(CXXMethodDecl *Method,
530 Expr *Object, Expr **Args, unsigned NumArgs,
531 OverloadCandidateSet& CandidateSet,
Douglas Gregor88a35142008-12-22 05:46:06 +0000532 bool SuppressUserConversions = false);
Douglas Gregorf1991ea2008-11-07 22:36:19 +0000533 void AddConversionCandidate(CXXConversionDecl *Conversion,
534 Expr *From, QualType ToType,
535 OverloadCandidateSet& CandidateSet);
Douglas Gregor106c6eb2008-11-19 22:57:39 +0000536 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
Douglas Gregor72564e72009-02-26 23:50:07 +0000537 const FunctionProtoType *Proto,
Douglas Gregor106c6eb2008-11-19 22:57:39 +0000538 Expr *Object, Expr **Args, unsigned NumArgs,
539 OverloadCandidateSet& CandidateSet);
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000540 bool AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
541 SourceLocation OpLoc,
Douglas Gregor96176b32008-11-18 23:14:02 +0000542 Expr **Args, unsigned NumArgs,
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000543 OverloadCandidateSet& CandidateSet,
544 SourceRange OpRange = SourceRange());
Douglas Gregoreb8f3062008-11-12 17:17:38 +0000545 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
546 Expr **Args, unsigned NumArgs,
Douglas Gregor88b4bf22009-01-13 00:52:54 +0000547 OverloadCandidateSet& CandidateSet,
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000548 bool IsAssignmentOperator = false,
549 unsigned NumContextualBoolArguments = 0);
Douglas Gregor74253732008-11-19 15:42:04 +0000550 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
551 Expr **Args, unsigned NumArgs,
552 OverloadCandidateSet& CandidateSet);
Douglas Gregorfa047642009-02-04 00:32:51 +0000553 void AddArgumentDependentLookupCandidates(DeclarationName Name,
554 Expr **Args, unsigned NumArgs,
555 OverloadCandidateSet& CandidateSet);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000556 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
557 const OverloadCandidate& Cand2);
558 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
559 OverloadCandidateSet::iterator& Best);
560 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
561 bool OnlyViable);
562
Douglas Gregor904eed32008-11-10 20:40:00 +0000563 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
564 bool Complain);
565 void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
566
Douglas Gregor17330012009-02-04 15:01:18 +0000567 FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee,
568 DeclarationName UnqualifiedName,
Douglas Gregor0a396682008-11-26 06:01:48 +0000569 SourceLocation LParenLoc,
570 Expr **Args, unsigned NumArgs,
571 SourceLocation *CommaLocs,
Douglas Gregorfa047642009-02-04 00:32:51 +0000572 SourceLocation RParenLoc,
Douglas Gregor17330012009-02-04 15:01:18 +0000573 bool &ArgumentDependentLookup);
Douglas Gregor88a35142008-12-22 05:46:06 +0000574 ExprResult
575 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
576 SourceLocation LParenLoc, Expr **Args,
577 unsigned NumArgs, SourceLocation *CommaLocs,
578 SourceLocation RParenLoc);
Douglas Gregorf9eb9052008-11-19 21:05:33 +0000579 ExprResult
Douglas Gregor5c37de72008-12-06 00:22:45 +0000580 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregorf9eb9052008-11-19 21:05:33 +0000581 Expr **Args, unsigned NumArgs,
582 SourceLocation *CommaLocs,
583 SourceLocation RParenLoc);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000584
Douglas Gregor3fc749d2008-12-23 00:26:44 +0000585 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
Douglas Gregor8ba10742008-11-20 16:27:02 +0000586 SourceLocation MemberLoc,
587 IdentifierInfo &Member);
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000588
Chris Lattner823c44e2009-01-06 07:27:21 +0000589 /// Helpers for dealing with function parameters.
Chris Lattner04421082008-04-08 04:40:51 +0000590 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattner04421082008-04-08 04:40:51 +0000591 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregor6d6eb572008-05-07 04:49:29 +0000592 void CheckExtraCXXDefaultArguments(Declarator &D);
Reid Spencer5f016e22007-07-11 17:01:13 +0000593
Douglas Gregor1a0d31a2009-01-12 18:45:55 +0000594 Scope *getNonFieldDeclScope(Scope *S);
595
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000596 /// \name Name lookup
597 ///
598 /// These routines provide name lookup that is used during semantic
599 /// analysis to resolve the various kinds of names (identifiers,
600 /// overloaded operator names, constructor names, etc.) into zero or
601 /// more declarations within a particular scope. The major entry
602 /// points are LookupName, which performs unqualified name lookup,
603 /// and LookupQualifiedName, which performs qualified name lookup.
604 ///
605 /// All name lookup is performed based on some specific criteria,
606 /// which specify what names will be visible to name lookup and how
607 /// far name lookup should work. These criteria are important both
608 /// for capturing language semantics (certain lookups will ignore
609 /// certain names, for example) and for performance, since name
610 /// lookup is often a bottleneck in the compilation of C++. Name
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000611 /// lookup criteria is specified via the LookupCriteria enumeration.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000612 ///
613 /// The results of name lookup can vary based on the kind of name
614 /// lookup performed, the current language, and the translation
615 /// unit. In C, for example, name lookup will either return nothing
616 /// (no entity found) or a single declaration. In C++, name lookup
617 /// can additionally refer to a set of overloaded functions or
618 /// result in an ambiguity. All of the possible results of name
619 /// lookup are captured by the LookupResult class, which provides
620 /// the ability to distinguish among them.
621 //@{
Douglas Gregorf780abc2008-12-30 03:27:21 +0000622
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000623 /// @brief Describes the kind of name lookup to perform.
624 enum LookupNameKind {
625 /// Ordinary name lookup, which finds ordinary names (functions,
626 /// variables, typedefs, etc.) in C and most kinds of names
627 /// (functions, variables, members, types, etc.) in C++.
628 LookupOrdinaryName = 0,
629 /// Tag name lookup, which finds the names of enums, classes,
630 /// structs, and unions.
631 LookupTagName,
632 /// Member name lookup, which finds the names of
633 /// class/struct/union members.
634 LookupMemberName,
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000635 // Look up of an operator name (e.g., operator+) for use with
636 // operator overloading. This lookup is similar to ordinary name
637 // lookup, but will ignore any declarations that are class
638 // members.
639 LookupOperatorName,
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000640 /// Look up of a name that precedes the '::' scope resolution
641 /// operator in C++. This lookup completely ignores operator,
642 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
643 LookupNestedNameSpecifierName,
644 /// Look up a namespace name within a C++ using directive or
645 /// namespace alias definition, ignoring non-namespace names (C++
646 /// [basic.lookup.udir]p1).
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000647 LookupNamespaceName,
648 // Look up an ordinary name that is going to be redeclared as a
649 // name with linkage. This lookup ignores any declarations that
650 // are outside of the current scope unless they have linkage. See
651 // C99 6.2.2p4-5 and C++ [basic.link]p6.
652 LookupRedeclarationWithLinkage
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000653 };
654
655 /// @brief Represents the results of name lookup.
656 ///
657 /// An instance of the LookupResult class captures the results of a
658 /// single name lookup, which can return no result (nothing found),
659 /// a single declaration, a set of overloaded functions, or an
660 /// ambiguity. Use the getKind() method to determine which of these
661 /// results occurred for a given lookup.
662 ///
663 /// Any non-ambiguous lookup can be converted into a single
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000664 /// (possibly NULL) @c NamedDecl* via a conversion function or the
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000665 /// getAsDecl() method. This conversion permits the common-case
666 /// usage in C and Objective-C where name lookup will always return
667 /// a single declaration.
Douglas Gregor69d993a2009-01-17 01:13:24 +0000668 struct LookupResult {
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000669 /// The kind of entity that is actually stored within the
670 /// LookupResult object.
Douglas Gregor69d993a2009-01-17 01:13:24 +0000671 enum {
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000672 /// First is a single declaration (a NamedDecl*), which may be NULL.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000673 SingleDecl,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000674
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000675 /// First is a single declaration (an OverloadedFunctionDecl*).
676 OverloadedDeclSingleDecl,
677
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000678 /// [First, Last) is an iterator range represented as opaque
679 /// pointers used to reconstruct IdentifierResolver::iterators.
680 OverloadedDeclFromIdResolver,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000681
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000682 /// [First, Last) is an iterator range represented as opaque
683 /// pointers used to reconstruct DeclContext::lookup_iterators.
684 OverloadedDeclFromDeclContext,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000685
686 /// First is a pointer to a BasePaths structure, which is owned
687 /// by the LookupResult. Last is non-zero to indicate that the
688 /// ambiguity is caused by two names found in base class
689 /// subobjects of different types.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000690 AmbiguousLookupStoresBasePaths,
691
692 /// [First, Last) is an iterator range represented as opaque
693 /// pointers used to reconstruct new'ed Decl*[] array containing
694 /// found ambiguous decls. LookupResult is owner of this array.
695 AmbiguousLookupStoresDecls
696
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000697 } StoredKind;
698
699 /// The first lookup result, whose contents depend on the kind of
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000700 /// lookup result. This may be a NamedDecl* (if StoredKind ==
701 /// SingleDecl), OverloadedFunctionDecl* (if StoredKind ==
702 /// OverloadedDeclSingleDecl), the opaque pointer from an
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000703 /// IdentifierResolver::iterator (if StoredKind ==
Douglas Gregor7176fff2009-01-15 00:26:24 +0000704 /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator
705 /// (if StoredKind == OverloadedDeclFromDeclContext), or a
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000706 /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000707 mutable uintptr_t First;
708
709 /// The last lookup result, whose contents depend on the kind of
710 /// lookup result. This may be unused (if StoredKind ==
Douglas Gregor7176fff2009-01-15 00:26:24 +0000711 /// SingleDecl), it may have the same type as First (for
712 /// overloaded function declarations), or is may be used as a
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000713 /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000714 mutable uintptr_t Last;
715
716 /// Context - The context in which we will build any
717 /// OverloadedFunctionDecl nodes needed by the conversion to
718 /// Decl*.
719 ASTContext *Context;
720
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000721 /// @brief The kind of entity found by name lookup.
722 enum LookupKind {
723 /// @brief No entity found met the criteria.
724 NotFound = 0,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000725
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000726 /// @brief Name lookup found a single declaration that met the
Douglas Gregor7176fff2009-01-15 00:26:24 +0000727 /// criteria. getAsDecl will return this declaration.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000728 Found,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000729
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000730 /// @brief Name lookup found a set of overloaded functions that
Douglas Gregor7176fff2009-01-15 00:26:24 +0000731 /// met the criteria. getAsDecl will turn this set of overloaded
732 /// functions into an OverloadedFunctionDecl.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000733 FoundOverloaded,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000734
735 /// Name lookup results in an ambiguity because multiple
736 /// entities that meet the lookup criteria were found in
737 /// subobjects of different types. For example:
738 /// @code
739 /// struct A { void f(int); }
740 /// struct B { void f(double); }
741 /// struct C : A, B { };
742 /// void test(C c) {
743 /// c.f(0); // error: A::f and B::f come from subobjects of different
744 /// // types. overload resolution is not performed.
745 /// }
746 /// @endcode
747 AmbiguousBaseSubobjectTypes,
748
749 /// Name lookup results in an ambiguity because multiple
750 /// nonstatic entities that meet the lookup criteria were found
751 /// in different subobjects of the same type. For example:
752 /// @code
753 /// struct A { int x; };
754 /// struct B : A { };
755 /// struct C : A { };
756 /// struct D : B, C { };
757 /// int test(D d) {
758 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
759 /// }
760 /// @endcode
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000761 AmbiguousBaseSubobjects,
762
763 /// Name lookup results in an ambiguity because multiple definitions
764 /// of entity that meet the lookup criteria were found in different
765 /// declaration contexts.
766 /// @code
767 /// namespace A {
768 /// int i;
769 /// namespace B { int i; }
770 /// int test() {
771 /// using namespace B;
772 /// return i; // error 'i' is found in namespace A and A::B
773 /// }
774 /// }
775 /// @endcode
776 AmbiguousReference
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000777 };
778
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000779 static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D);
Douglas Gregor4bb64e72009-01-15 02:19:31 +0000780
Douglas Gregor69d993a2009-01-17 01:13:24 +0000781 static LookupResult CreateLookupResult(ASTContext &Context,
782 IdentifierResolver::iterator F,
783 IdentifierResolver::iterator L);
Douglas Gregor7176fff2009-01-15 00:26:24 +0000784
Douglas Gregor69d993a2009-01-17 01:13:24 +0000785 static LookupResult CreateLookupResult(ASTContext &Context,
786 DeclContext::lookup_iterator F,
787 DeclContext::lookup_iterator L);
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000788
Douglas Gregor69d993a2009-01-17 01:13:24 +0000789 static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths,
790 bool DifferentSubobjectTypes) {
791 LookupResult Result;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000792 Result.StoredKind = AmbiguousLookupStoresBasePaths;
Douglas Gregor69d993a2009-01-17 01:13:24 +0000793 Result.First = reinterpret_cast<uintptr_t>(Paths);
794 Result.Last = DifferentSubobjectTypes? 1 : 0;
795 Result.Context = &Context;
796 return Result;
797 }
Douglas Gregor4bb64e72009-01-15 02:19:31 +0000798
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000799 template <typename Iterator>
800 static LookupResult CreateLookupResult(ASTContext &Context,
801 Iterator B, std::size_t Len) {
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000802 NamedDecl ** Array = new NamedDecl*[Len];
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000803 for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B)
804 Array[Idx] = *B;
805 LookupResult Result;
806 Result.StoredKind = AmbiguousLookupStoresDecls;
807 Result.First = reinterpret_cast<uintptr_t>(Array);
808 Result.Last = reinterpret_cast<uintptr_t>(Array + Len);
809 Result.Context = &Context;
810 return Result;
811 }
812
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000813 LookupKind getKind() const;
814
815 /// @brief Determine whether name look found something.
816 operator bool() const { return getKind() != NotFound; }
817
Douglas Gregor7176fff2009-01-15 00:26:24 +0000818 /// @brief Determines whether the lookup resulted in an ambiguity.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000819 bool isAmbiguous() const {
820 return StoredKind == AmbiguousLookupStoresBasePaths ||
821 StoredKind == AmbiguousLookupStoresDecls;
822 }
Douglas Gregor7176fff2009-01-15 00:26:24 +0000823
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000824 /// @brief Allows conversion of a lookup result into a
825 /// declaration, with the same behavior as getAsDecl.
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000826 operator NamedDecl*() const { return getAsDecl(); }
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000827
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000828 NamedDecl* getAsDecl() const;
Douglas Gregor7176fff2009-01-15 00:26:24 +0000829
830 BasePaths *getBasePaths() const;
Douglas Gregord8635172009-02-02 21:35:47 +0000831
832 /// \brief Iterate over the results of name lookup.
833 ///
834 /// The @c iterator class provides iteration over the results of a
835 /// non-ambiguous name lookup.
836 class iterator {
837 /// The LookupResult structure we're iterating through.
838 LookupResult *Result;
839
840 /// The current position of this iterator within the sequence of
841 /// results. This value will have the same representation as the
842 /// @c First field in the LookupResult structure.
843 mutable uintptr_t Current;
844
845 public:
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000846 typedef NamedDecl * value_type;
847 typedef NamedDecl * reference;
848 typedef NamedDecl * pointer;
Douglas Gregord8635172009-02-02 21:35:47 +0000849 typedef std::ptrdiff_t difference_type;
850 typedef std::forward_iterator_tag iterator_category;
851
852 iterator() : Result(0), Current(0) { }
853
854 iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { }
855
856 reference operator*() const;
857
858 pointer operator->() const { return **this; }
859
860 iterator &operator++();
861
862 iterator operator++(int) {
863 iterator tmp(*this);
864 ++(*this);
865 return tmp;
866 }
867
868 friend inline bool operator==(iterator const& x, iterator const& y) {
869 return x.Current == y.Current;
870 }
871
872 friend inline bool operator!=(iterator const& x, iterator const& y) {
873 return x.Current != y.Current;
874 }
875 };
876 friend class iterator;
877
878 iterator begin();
879 iterator end();
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000880 };
881
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000882private:
883 typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy;
884
885 std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name,
886 LookupNameKind NameKind,
887 bool RedeclarationOnly);
888
889public:
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000890 /// Determines whether D is a suitable lookup result according to the
891 /// lookup criteria.
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000892 static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind,
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000893 unsigned IDNS) {
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000894 switch (NameKind) {
895 case Sema::LookupOrdinaryName:
896 case Sema::LookupTagName:
897 case Sema::LookupMemberName:
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000898 case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000899 return D->isInIdentifierNamespace(IDNS);
900
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000901 case Sema::LookupOperatorName:
902 return D->isInIdentifierNamespace(IDNS) &&
903 !D->getDeclContext()->isRecord();
904
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000905 case Sema::LookupNestedNameSpecifierName:
906 return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag);
907
908 case Sema::LookupNamespaceName:
909 return isa<NamespaceDecl>(D);
910 }
911
912 assert(false &&
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000913 "isAcceptableLookupResult always returns before this point");
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000914 return false;
915 }
Douglas Gregor7176fff2009-01-15 00:26:24 +0000916
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000917 LookupResult LookupName(Scope *S, DeclarationName Name,
918 LookupNameKind NameKind,
Douglas Gregor3e41d602009-02-13 23:20:09 +0000919 bool RedeclarationOnly = false,
920 bool AllowBuiltinCreation = true,
921 SourceLocation Loc = SourceLocation());
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000922 LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name,
923 LookupNameKind NameKind,
924 bool RedeclarationOnly = false);
925 LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS,
926 DeclarationName Name,
927 LookupNameKind NameKind,
Douglas Gregor3e41d602009-02-13 23:20:09 +0000928 bool RedeclarationOnly = false,
929 bool AllowBuiltinCreation = true,
930 SourceLocation Loc = SourceLocation());
Douglas Gregorfa047642009-02-04 00:32:51 +0000931
932 typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet;
933 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
934
935 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
936 AssociatedNamespaceSet &AssociatedNamespaces,
937 AssociatedClassSet &AssociatedClasses);
938
Douglas Gregor7176fff2009-01-15 00:26:24 +0000939 bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
940 SourceLocation NameLoc,
941 SourceRange LookupRange = SourceRange());
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000942 //@}
943
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000944 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000945 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Douglas Gregor3e41d602009-02-13 23:20:09 +0000946 Scope *S, bool ForRedeclaration,
947 SourceLocation Loc);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000948 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
949 Scope *S);
Douglas Gregor3c385e52009-02-14 18:57:46 +0000950 void AddKnownFunctionAttributes(FunctionDecl *FD);
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000951
952 // More parsing and symbol table subroutines.
953
Reid Spencer5f016e22007-07-11 17:01:13 +0000954 // Decl attributes - this routine is the top level dispatcher.
Chris Lattnere5c5ee12008-06-29 00:16:31 +0000955 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnerf2e4bd52008-06-28 23:58:55 +0000956 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lambebb97e92008-02-04 02:31:56 +0000957
Steve Naroff3c2eb662008-02-10 21:38:56 +0000958 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
959 bool &IncompleteImpl);
Fariborz Jahanian8daab972008-12-05 18:18:52 +0000960 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
961 ObjCMethodDecl *IntfMethod);
Sebastian Redlc42e1182008-11-11 11:37:55 +0000962
963 NamespaceDecl *GetStdNamespace();
Fariborz Jahaniand1fa6442009-01-12 19:55:42 +0000964
965 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
Steve Naroff22dc0b02009-02-26 19:11:32 +0000966 ObjCInterfaceDecl *IDecl);
Steve Naroff3c2eb662008-02-10 21:38:56 +0000967
Chris Lattner823c44e2009-01-06 07:27:21 +0000968 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000969 /// methods declared in protocol, and those referenced by it.
970 /// \param IDecl - Used for checking for methods which may have been
971 /// inherited.
Steve Naroffefe7f362008-02-08 22:06:17 +0000972 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
973 ObjCProtocolDecl *PDecl,
Fariborz Jahanianca3adf72007-10-02 20:06:01 +0000974 bool& IncompleteImpl,
Steve Naroffeefc4182007-10-08 21:05:34 +0000975 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000976 const llvm::DenseSet<Selector> &ClsMap,
977 ObjCInterfaceDecl *IDecl);
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000978
Steve Naroffa5997c42007-10-02 21:43:37 +0000979 /// CheckImplementationIvars - This routine checks if the instance variables
980 /// listed in the implelementation match those listed in the interface.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000981 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
982 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff3c2eb662008-02-10 21:38:56 +0000983 SourceLocation Loc);
Steve Naroffa5997c42007-10-02 21:43:37 +0000984
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000985 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
Chris Lattnercddc8882009-03-01 00:56:52 +0000986 /// remains unimplemented in the class or category @implementation.
987 void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl,
988 ObjCContainerDecl* IDecl,
989 bool IncompleteImpl = false);
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000990
Fariborz Jahanian85ff2642007-10-05 18:00:57 +0000991 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
992 /// true, or false, accordingly.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000993 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Narofffe6b0dc2008-10-21 10:37:50 +0000994 const ObjCMethodDecl *PrevMethod,
995 bool matchBasedOnSizeAndAlignment = false);
Steve Naroff3b950172007-10-10 21:53:07 +0000996
Steve Naroff58ff9e82007-10-14 00:58:41 +0000997 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
998 /// unit are added to a global pool. This allows us to efficiently associate
999 /// a selector with a method declaraation for purposes of typechecking
1000 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001001 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff58ff9e82007-10-14 00:58:41 +00001002
Steve Naroff037cda52008-09-30 14:38:43 +00001003 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
1004 /// there are multiple signatures.
1005 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
1006
Steve Naroff58ff9e82007-10-14 00:58:41 +00001007 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001008 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Reid Spencer5f016e22007-07-11 17:01:13 +00001009 //===--------------------------------------------------------------------===//
1010 // Statement Parsing Callbacks: SemaStmt.cpp.
1011public:
Sebastian Redla60528c2008-12-21 12:04:03 +00001012 virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
1013
1014 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
1015 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1016 MultiStmtArg Elts,
1017 bool isStmtExpr);
1018 virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
1019 SourceLocation EndLoc);
Sebastian Redl117054a2008-12-28 16:13:43 +00001020 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
1021 SourceLocation DotDotDotLoc, ExprArg RHSVal,
Chris Lattner24e1e702009-03-04 04:23:07 +00001022 SourceLocation ColonLoc);
1023 virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt);
1024
Sebastian Redl117054a2008-12-28 16:13:43 +00001025 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1026 SourceLocation ColonLoc,
1027 StmtArg SubStmt, Scope *CurScope);
Sebastian Redlde307472009-01-11 00:38:46 +00001028 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
1029 IdentifierInfo *II,
1030 SourceLocation ColonLoc,
1031 StmtArg SubStmt);
1032 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
1033 StmtArg ThenVal, SourceLocation ElseLoc,
1034 StmtArg ElseVal);
1035 virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
1036 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1037 StmtArg Switch, StmtArg Body);
Sebastian Redlf05b1522009-01-16 23:28:06 +00001038 virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
1039 StmtArg Body);
1040 virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
1041 SourceLocation WhileLoc, ExprArg Cond);
1042
1043 virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
1044 SourceLocation LParenLoc,
1045 StmtArg First, ExprArg Second,
1046 ExprArg Third, SourceLocation RParenLoc,
1047 StmtArg Body);
1048 virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1049 SourceLocation LParenLoc,
1050 StmtArg First, ExprArg Second,
1051 SourceLocation RParenLoc, StmtArg Body);
Sebastian Redl4cffe2f2009-01-18 13:19:59 +00001052
1053 virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1054 SourceLocation LabelLoc,
1055 IdentifierInfo *LabelII);
1056 virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1057 SourceLocation StarLoc,
1058 ExprArg DestExp);
1059 virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
1060 Scope *CurScope);
1061 virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
1062 Scope *CurScope);
1063
1064 virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
1065 ExprArg RetValExp);
1066 OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
1067 Expr *RetValExp);
1068
Sebastian Redl3037ed02009-01-18 16:53:17 +00001069 virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1070 bool IsSimple,
1071 bool IsVolatile,
1072 unsigned NumOutputs,
1073 unsigned NumInputs,
1074 std::string *Names,
1075 MultiExprArg Constraints,
1076 MultiExprArg Exprs,
1077 ExprArg AsmString,
1078 MultiExprArg Clobbers,
1079 SourceLocation RParenLoc);
Sebastian Redl431e90e2009-01-18 17:43:11 +00001080
1081 virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
1082 SourceLocation RParen,
Steve Naroff7ba138a2009-03-03 19:52:17 +00001083 DeclTy *Parm, StmtArg Body,
Sebastian Redl431e90e2009-01-18 17:43:11 +00001084 StmtArg CatchList);
1085
1086 virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
1087 StmtArg Body);
1088
1089 virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
1090 StmtArg Try,
1091 StmtArg Catch, StmtArg Finally);
1092
1093 virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Steve Naroffe21dd6f2009-02-11 20:05:44 +00001094 ExprArg Throw,
1095 Scope *CurScope);
Sebastian Redl431e90e2009-01-18 17:43:11 +00001096 virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1097 ExprArg SynchExpr,
1098 StmtArg SynchBody);
Sebastian Redla0fd8652008-12-21 16:41:36 +00001099
Sebastian Redl4b07b292008-12-22 19:15:10 +00001100 virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D);
1101 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
1102 DeclTy *ExDecl,
1103 StmtArg HandlerBlock);
Sebastian Redl8351da02008-12-22 21:35:02 +00001104 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
1105 StmtArg TryBlock,
1106 MultiStmtArg Handlers);
Sebastian Redla0fd8652008-12-21 16:41:36 +00001107
Reid Spencer5f016e22007-07-11 17:01:13 +00001108 //===--------------------------------------------------------------------===//
1109 // Expression Parsing Callbacks: SemaExpr.cpp.
1110
Douglas Gregor48f3bb92009-02-18 21:56:37 +00001111 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
Chris Lattner76a642f2009-02-15 22:43:40 +00001112
Reid Spencer5f016e22007-07-11 17:01:13 +00001113 // Primary Expressions.
Douglas Gregor4b2d3f72009-02-26 21:00:50 +00001114 virtual SourceRange getExprRange(ExprTy *E) const;
1115
Sebastian Redlcd965b92009-01-18 18:53:16 +00001116 virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
1117 IdentifierInfo &II,
1118 bool HasTrailingLParen,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001119 const CXXScopeSpec *SS = 0,
1120 bool isAddressOfOperand = false);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001121 virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S,
Douglas Gregor487a75a2008-11-19 19:09:45 +00001122 SourceLocation OperatorLoc,
1123 OverloadedOperatorKind Op,
1124 bool HasTrailingLParen,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001125 const CXXScopeSpec &SS,
1126 bool isAddressOfOperand);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001127 virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S,
Douglas Gregor487a75a2008-11-19 19:09:45 +00001128 SourceLocation OperatorLoc,
1129 TypeTy *Ty,
1130 bool HasTrailingLParen,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001131 const CXXScopeSpec &SS,
1132 bool isAddressOfOperand);
Douglas Gregor1a49af92009-01-06 05:10:23 +00001133 DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
1134 bool TypeDependent, bool ValueDependent,
1135 const CXXScopeSpec *SS = 0);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001136 OwningExprResult
Douglas Gregorbcbffc42009-01-07 00:43:41 +00001137 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1138 FieldDecl *Field,
1139 Expr *BaseObjectExpr = 0,
1140 SourceLocation OpLoc = SourceLocation());
Sebastian Redlcd965b92009-01-18 18:53:16 +00001141 OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
1142 DeclarationName Name,
1143 bool HasTrailingLParen,
1144 const CXXScopeSpec *SS,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001145 bool isAddressOfOperand = false);
Douglas Gregor10c42622008-11-18 15:03:34 +00001146
Sebastian Redlcd965b92009-01-18 18:53:16 +00001147 virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
1148 tok::TokenKind Kind);
1149 virtual OwningExprResult ActOnNumericConstant(const Token &);
1150 virtual OwningExprResult ActOnCharacterConstant(const Token &);
1151 virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
1152 ExprArg Val);
Reid Spencer5f016e22007-07-11 17:01:13 +00001153
Steve Narofff69936d2007-09-16 03:34:24 +00001154 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Reid Spencer5f016e22007-07-11 17:01:13 +00001155 /// fragments (e.g. "foo" "bar" L"baz").
Sebastian Redl0eb23302009-01-19 00:08:26 +00001156 virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
1157 unsigned NumToks);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001158
Reid Spencer5f016e22007-07-11 17:01:13 +00001159 // Binary/Unary Operators. 'Tok' is the token for the operator.
Sebastian Redl0eb23302009-01-19 00:08:26 +00001160 virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1161 tok::TokenKind Op, ExprArg Input);
1162 virtual OwningExprResult
Sebastian Redl05189992008-11-11 17:56:53 +00001163 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1164 void *TyOrEx, const SourceRange &ArgRange);
1165
Chris Lattner31e21e02009-01-24 20:17:12 +00001166 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R);
Sebastian Redl05189992008-11-11 17:56:53 +00001167 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1168 const SourceRange &R, bool isSizeof);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001169
1170 virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1171 tok::TokenKind Kind,
1172 ExprArg Input);
1173
1174 virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
1175 SourceLocation LLoc,
1176 ExprArg Idx,
1177 SourceLocation RLoc);
1178 virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base,
1179 SourceLocation OpLoc,
1180 tok::TokenKind OpKind,
1181 SourceLocation MemberLoc,
Fariborz Jahaniana6e3ac52009-03-04 22:30:12 +00001182 IdentifierInfo &Member,
1183 DeclTy *ImplDecl=0);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001184 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
Douglas Gregor88a35142008-12-22 05:46:06 +00001185 FunctionDecl *FDecl,
Douglas Gregor72564e72009-02-26 23:50:07 +00001186 const FunctionProtoType *Proto,
Douglas Gregor88a35142008-12-22 05:46:06 +00001187 Expr **Args, unsigned NumArgs,
1188 SourceLocation RParenLoc);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001189
Steve Narofff69936d2007-09-16 03:34:24 +00001190 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Reid Spencer5f016e22007-07-11 17:01:13 +00001191 /// This provides the location of the left/right parens and a list of comma
1192 /// locations.
Sebastian Redl0eb23302009-01-19 00:08:26 +00001193 virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn,
1194 SourceLocation LParenLoc,
1195 MultiExprArg Args,
1196 SourceLocation *CommaLocs,
1197 SourceLocation RParenLoc);
1198
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001199 virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
1200 SourceLocation RParenLoc, ExprArg Op);
1201
1202 virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1203 TypeTy *Ty,
1204 SourceLocation RParenLoc,
1205 ExprArg Op);
1206
1207 virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
1208 MultiExprArg InitList,
1209 InitListDesignations &Designators,
1210 SourceLocation RParenLoc);
1211
Douglas Gregor05c13a32009-01-22 00:58:24 +00001212 virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
1213 SourceLocation Loc,
1214 bool UsedColonSyntax,
1215 OwningExprResult Init);
1216
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001217 virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1218 tok::TokenKind Kind,
1219 ExprArg LHS, ExprArg RHS);
1220 OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1221 unsigned Opc, Expr *lhs, Expr *rhs);
Douglas Gregoreaebc752008-11-06 23:29:22 +00001222
Steve Narofff69936d2007-09-16 03:34:24 +00001223 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Reid Spencer5f016e22007-07-11 17:01:13 +00001224 /// in the case of a the GNU conditional expr extension.
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001225 virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1226 SourceLocation ColonLoc,
1227 ExprArg Cond, ExprArg LHS,
1228 ExprArg RHS);
Reid Spencer5f016e22007-07-11 17:01:13 +00001229
Steve Naroff1b273c42007-09-16 14:56:35 +00001230 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1231 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +00001232 IdentifierInfo *LabelII);
1233
Steve Naroff1b273c42007-09-16 14:56:35 +00001234 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattnerab18c4c2007-07-24 16:58:17 +00001235 SourceLocation RPLoc); // "({..})"
Chris Lattner73d0d4f2007-08-30 17:45:32 +00001236
1237 /// __builtin_offsetof(type, a.b[123][456].c)
Douglas Gregor3fc749d2008-12-23 00:26:44 +00001238 virtual ExprResult ActOnBuiltinOffsetOf(Scope *S,
1239 SourceLocation BuiltinLoc,
Chris Lattner73d0d4f2007-08-30 17:45:32 +00001240 SourceLocation TypeLoc, TypeTy *Arg1,
1241 OffsetOfComponent *CompPtr,
1242 unsigned NumComponents,
1243 SourceLocation RParenLoc);
1244
Steve Naroffd34e9152007-08-01 22:05:33 +00001245 // __builtin_types_compatible_p(type1, type2)
Steve Naroff1b273c42007-09-16 14:56:35 +00001246 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroffd34e9152007-08-01 22:05:33 +00001247 TypeTy *arg1, TypeTy *arg2,
1248 SourceLocation RPLoc);
Steve Naroffd04fdd52007-08-03 21:21:27 +00001249
1250 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff1b273c42007-09-16 14:56:35 +00001251 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroffd04fdd52007-08-03 21:21:27 +00001252 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
1253 SourceLocation RPLoc);
Chris Lattnerab18c4c2007-07-24 16:58:17 +00001254
Anders Carlsson7c50aca2007-10-15 20:28:48 +00001255 // __builtin_va_arg(expr, type)
1256 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1257 ExprTy *expr, TypeTy *type,
1258 SourceLocation RPLoc);
Steve Naroff4eb206b2008-09-03 18:15:37 +00001259
Douglas Gregor2d8b2732008-11-29 04:51:27 +00001260 // __null
1261 virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1262
Steve Naroff4eb206b2008-09-03 18:15:37 +00001263 //===------------------------- "Block" Extension ------------------------===//
1264
1265 /// ActOnBlockStart - This callback is invoked when a block literal is
1266 /// started.
Steve Naroff090276f2008-10-10 01:28:17 +00001267 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1268
1269 /// ActOnBlockArguments - This callback allows processing of block arguments.
1270 /// If there are no arguments, this is still invoked.
Mike Stump98eb8a72009-02-04 22:31:32 +00001271 virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
Steve Naroff4eb206b2008-09-03 18:15:37 +00001272
1273 /// ActOnBlockError - If there is an error parsing a block, this callback
1274 /// is invoked to pop the information about the block from the action impl.
1275 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1276
1277 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1278 /// literal was successfully completed. ^(int x){...}
1279 virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
1280 Scope *CurScope);
1281
Chris Lattner76a642f2009-02-15 22:43:40 +00001282 //===---------------------------- C++ Features --------------------------===//
1283
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +00001284 // Act on C++ namespaces
1285 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
1286 IdentifierInfo *Ident,
1287 SourceLocation LBrace);
1288 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
1289
Douglas Gregorf780abc2008-12-30 03:27:21 +00001290 virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
1291 SourceLocation UsingLoc,
1292 SourceLocation NamespcLoc,
1293 const CXXScopeSpec &SS,
1294 SourceLocation IdentLoc,
1295 IdentifierInfo *NamespcName,
1296 AttributeList *AttrList);
1297
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001298 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
1299
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +00001300 /// AddCXXDirectInitializerToDecl - This action is called immediately after
1301 /// ActOnDeclarator, when a C++ direct initializer is present.
1302 /// e.g: "int x(1);"
1303 virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
1304 SourceLocation LParenLoc,
1305 ExprTy **Exprs, unsigned NumExprs,
1306 SourceLocation *CommaLocs,
1307 SourceLocation RParenLoc);
1308
Douglas Gregorf03d7c72008-11-05 15:29:30 +00001309 /// InitializationKind - Represents which kind of C++ initialization
1310 /// [dcl.init] a routine is to perform.
1311 enum InitializationKind {
1312 IK_Direct, ///< Direct initialization
1313 IK_Copy, ///< Copy initialization
1314 IK_Default ///< Default initialization
1315 };
1316
Douglas Gregor18fe5682008-11-03 20:45:27 +00001317 CXXConstructorDecl *
Douglas Gregorf03d7c72008-11-05 15:29:30 +00001318 PerformInitializationByConstructor(QualType ClassType,
1319 Expr **Args, unsigned NumArgs,
1320 SourceLocation Loc, SourceRange Range,
Chris Lattnerd9d22dd2008-11-24 05:29:24 +00001321 DeclarationName InitEntity,
Douglas Gregorf03d7c72008-11-05 15:29:30 +00001322 InitializationKind Kind);
Douglas Gregor18fe5682008-11-03 20:45:27 +00001323
Douglas Gregor49badde2008-10-27 19:41:14 +00001324 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
1325 virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
1326 SourceLocation LAngleBracketLoc, TypeTy *Ty,
1327 SourceLocation RAngleBracketLoc,
1328 SourceLocation LParenLoc, ExprTy *E,
1329 SourceLocation RParenLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001330
Sebastian Redlc42e1182008-11-11 11:37:55 +00001331 /// ActOnCXXTypeidOfType - Parse typeid( type-id ).
1332 virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
1333 SourceLocation LParenLoc, bool isType,
1334 void *TyOrExpr, SourceLocation RParenLoc);
1335
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00001336 //// ActOnCXXThis - Parse 'this' pointer.
1337 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
1338
Steve Naroff1b273c42007-09-16 14:56:35 +00001339 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
1340 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +00001341 tok::TokenKind Kind);
Anders Carlsson55085182007-08-21 17:43:55 +00001342
Chris Lattner50dd2892008-02-26 00:51:44 +00001343 //// ActOnCXXThrow - Parse throw expressions.
1344 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
1345 ExprTy *expr);
1346
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00001347 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
1348 /// Can be interpreted either as function-style casting ("int(x)")
1349 /// or class type construction ("ClassType(x,y,z)")
1350 /// or creation of a value-initialized type ("int()").
1351 virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
1352 TypeTy *TypeRep,
1353 SourceLocation LParenLoc,
1354 ExprTy **Exprs,
1355 unsigned NumExprs,
1356 SourceLocation *CommaLocs,
1357 SourceLocation RParenLoc);
1358
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001359 /// ActOnCXXNew - Parsed a C++ 'new' expression.
1360 virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1361 SourceLocation PlacementLParen,
1362 ExprTy **PlacementArgs, unsigned NumPlaceArgs,
1363 SourceLocation PlacementRParen,
Sebastian Redlcee63fb2008-12-02 14:43:59 +00001364 bool ParenTypeId, Declarator &D,
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001365 SourceLocation ConstructorLParen,
1366 ExprTy **ConstructorArgs, unsigned NumConsArgs,
1367 SourceLocation ConstructorRParen);
Sebastian Redlcee63fb2008-12-02 14:43:59 +00001368 bool CheckAllocatedType(QualType AllocType, const Declarator &D);
Sebastian Redl00e68e22009-02-09 18:24:27 +00001369 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
1370 bool UseGlobal, QualType AllocType, bool IsArray,
Sebastian Redlb5a57a62008-12-03 20:26:15 +00001371 Expr **PlaceArgs, unsigned NumPlaceArgs,
1372 FunctionDecl *&OperatorNew,
1373 FunctionDecl *&OperatorDelete);
Sebastian Redl00e68e22009-02-09 18:24:27 +00001374 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
1375 DeclarationName Name, Expr** Args,
1376 unsigned NumArgs, DeclContext *Ctx,
Sebastian Redl7f662392008-12-04 22:20:51 +00001377 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlb5a57a62008-12-03 20:26:15 +00001378 void DeclareGlobalNewDelete();
1379 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
1380 QualType Argument);
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001381
1382 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
1383 virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
1384 bool ArrayForm, ExprTy *Operand);
1385
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00001386 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
1387 /// C++ if/switch/while/for statement.
1388 /// e.g: "if (int x = f()) {...}"
1389 virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
1390 SourceLocation StartLoc,
1391 Declarator &D,
1392 SourceLocation EqualLoc,
1393 ExprTy *AssignExprVal);
1394
Sebastian Redl64b45f72009-01-05 20:52:13 +00001395 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
1396 /// pseudo-functions.
1397 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
1398 SourceLocation KWLoc,
1399 SourceLocation LParen,
1400 TypeTy *Ty,
1401 SourceLocation RParen);
1402
Douglas Gregor4fdf1fa2009-03-11 16:48:53 +00001403 bool RequireCompleteDeclContext(const CXXScopeSpec &SS);
1404
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001405 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
1406 /// global scope ('::').
1407 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
1408 SourceLocation CCLoc);
1409
1410 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1411 /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now
1412 /// we want to resolve "bar::". 'SS' is empty or the previously parsed
1413 /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar',
1414 /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'.
1415 /// Returns a CXXScopeTy* object representing the C++ scope.
1416 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1417 const CXXScopeSpec &SS,
1418 SourceLocation IdLoc,
1419 SourceLocation CCLoc,
Douglas Gregor2def4832008-11-17 20:34:05 +00001420 IdentifierInfo &II);
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001421
Douglas Gregor39a8de12009-02-25 19:37:18 +00001422 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1423 /// nested-name-specifier that involves a template-id, e.g.,
1424 /// "foo::bar<int, float>::", and now we need to build a scope
1425 /// specifier. \p SS is empty or the previously parsed nested-name
1426 /// part ("foo::"), \p Type is the already-parsed class template
1427 /// specialization (or other template-id that names a type), \p
1428 /// TypeRange is the source range where the type is located, and \p
1429 /// CCLoc is the location of the trailing '::'.
1430 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1431 const CXXScopeSpec &SS,
1432 TypeTy *Type,
1433 SourceRange TypeRange,
1434 SourceLocation CCLoc);
1435
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001436 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1437 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1438 /// After this method is called, according to [C++ 3.4.3p3], names should be
1439 /// looked up in the declarator-id's scope, until the declarator is parsed and
1440 /// ActOnCXXExitDeclaratorScope is called.
1441 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1442 virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
1443
1444 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1445 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1446 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1447 /// Used to indicate that names should revert to being looked up in the
1448 /// defining scope.
Douglas Gregor0a59acb2008-12-16 00:38:16 +00001449 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001450
Anders Carlsson55085182007-08-21 17:43:55 +00001451 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00001452 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
1453 ExprTy **Strings,
1454 unsigned NumStrings);
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001455 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner674af952007-10-16 22:51:17 +00001456 SourceLocation EncodeLoc,
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001457 SourceLocation LParenLoc,
1458 TypeTy *Ty,
1459 SourceLocation RParenLoc);
1460
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001461 // ParseObjCSelectorExpression - Build selector expression for @selector
1462 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
1463 SourceLocation AtLoc,
Fariborz Jahanian2a35fa92007-10-16 23:21:02 +00001464 SourceLocation SelLoc,
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001465 SourceLocation LParenLoc,
1466 SourceLocation RParenLoc);
1467
Fariborz Jahanian390d50a2007-10-17 16:58:11 +00001468 // ParseObjCProtocolExpression - Build protocol expression for @protocol
1469 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
1470 SourceLocation AtLoc,
1471 SourceLocation ProtoLoc,
1472 SourceLocation LParenLoc,
1473 SourceLocation RParenLoc);
Douglas Gregore37ac4f2008-04-13 21:30:24 +00001474
1475 //===--------------------------------------------------------------------===//
Douglas Gregor074149e2009-01-05 19:45:36 +00001476 // C++ Declarations
1477 //
1478 virtual DeclTy *ActOnStartLinkageSpecification(Scope *S,
1479 SourceLocation ExternLoc,
1480 SourceLocation LangLoc,
1481 const char *Lang,
1482 unsigned StrSize,
1483 SourceLocation LBraceLoc);
1484 virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S,
1485 DeclTy *LinkageSpec,
1486 SourceLocation RBraceLoc);
1487
1488
1489 //===--------------------------------------------------------------------===//
Douglas Gregore37ac4f2008-04-13 21:30:24 +00001490 // C++ Classes
1491 //
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001492 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
1493 const CXXScopeSpec *SS);
Douglas Gregorb48fe382008-10-31 09:07:45 +00001494
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00001495 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
1496 Declarator &D, ExprTy *BitfieldWidth,
1497 ExprTy *Init, DeclTy *LastInGroup);
1498
Douglas Gregor7ad83902008-11-05 04:29:56 +00001499 virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD,
1500 Scope *S,
1501 IdentifierInfo *MemberOrBase,
1502 SourceLocation IdLoc,
1503 SourceLocation LParenLoc,
1504 ExprTy **Args, unsigned NumArgs,
1505 SourceLocation *CommaLocs,
1506 SourceLocation RParenLoc);
1507
Douglas Gregor396b7cd2008-11-03 17:51:48 +00001508 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
1509
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00001510 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
1511 DeclTy *TagDecl,
1512 SourceLocation LBrac,
1513 SourceLocation RBrac);
1514
Douglas Gregor72b505b2008-12-16 21:30:33 +00001515 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1516 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param);
1517 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1518
Douglas Gregor42a552f2008-11-05 20:51:48 +00001519 bool CheckConstructorDeclarator(Declarator &D, QualType &R,
1520 FunctionDecl::StorageClass& SC);
Douglas Gregor72b505b2008-12-16 21:30:33 +00001521 bool CheckConstructor(CXXConstructorDecl *Constructor);
Douglas Gregor42a552f2008-11-05 20:51:48 +00001522 bool CheckDestructorDeclarator(Declarator &D, QualType &R,
1523 FunctionDecl::StorageClass& SC);
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001524 bool CheckConversionDeclarator(Declarator &D, QualType &R,
1525 FunctionDecl::StorageClass& SC);
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001526 DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregorb48fe382008-10-31 09:07:45 +00001527
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001528 //===--------------------------------------------------------------------===//
1529 // C++ Derived Classes
1530 //
1531
1532 /// ActOnBaseSpecifier - Parsed a base specifier
Douglas Gregor2943aed2009-03-03 04:44:36 +00001533 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
1534 SourceRange SpecifierRange,
1535 bool Virtual, AccessSpecifier Access,
1536 QualType BaseType,
1537 SourceLocation BaseLoc);
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001538 virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl,
1539 SourceRange SpecifierRange,
1540 bool Virtual, AccessSpecifier Access,
Douglas Gregor2943aed2009-03-03 04:44:36 +00001541 TypeTy *basetype, SourceLocation
1542 BaseLoc);
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001543
Douglas Gregor2943aed2009-03-03 04:44:36 +00001544 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
1545 unsigned NumBases);
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001546 virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
1547 unsigned NumBases);
1548
1549 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00001550 bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
Douglas Gregor7176fff2009-01-15 00:26:24 +00001551 bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria,
1552 BasePaths &Paths);
Douglas Gregor0575d4a2008-10-24 16:17:19 +00001553 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
1554 SourceLocation Loc, SourceRange Range);
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +00001555 std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
Douglas Gregore37ac4f2008-04-13 21:30:24 +00001556
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +00001557 //===--------------------------------------------------------------------===//
1558 // C++ Overloaded Operators [C++ 13.5]
1559 //
1560
1561 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
1562
Douglas Gregor72c3f312008-12-05 18:15:24 +00001563 //===--------------------------------------------------------------------===//
1564 // C++ Templates [C++ 14]
1565 //
Douglas Gregor55f6b142009-02-09 18:46:07 +00001566 virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S,
1567 DeclTy *&TemplateDecl,
1568 const CXXScopeSpec *SS = 0);
Douglas Gregor72c3f312008-12-05 18:15:24 +00001569 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001570 TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl);
1571
1572 virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename,
1573 SourceLocation KeyLoc,
1574 IdentifierInfo *ParamName,
1575 SourceLocation ParamNameLoc,
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001576 unsigned Depth, unsigned Position);
Douglas Gregord684b002009-02-10 19:49:53 +00001577 virtual void ActOnTypeParameterDefault(DeclTy *TypeParam,
1578 SourceLocation EqualLoc,
1579 SourceLocation DefaultLoc,
1580 TypeTy *Default);
1581
Douglas Gregor2943aed2009-03-03 04:44:36 +00001582 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001583 virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001584 unsigned Depth,
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001585 unsigned Position);
Douglas Gregord684b002009-02-10 19:49:53 +00001586 virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam,
1587 SourceLocation EqualLoc,
1588 ExprArg Default);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001589 virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S,
1590 SourceLocation TmpLoc,
1591 TemplateParamsTy *Params,
1592 IdentifierInfo *ParamName,
1593 SourceLocation ParamNameLoc,
1594 unsigned Depth,
1595 unsigned Position);
Douglas Gregord684b002009-02-10 19:49:53 +00001596 virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam,
1597 SourceLocation EqualLoc,
1598 ExprArg Default);
1599
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001600 virtual TemplateParamsTy *
1601 ActOnTemplateParameterList(unsigned Depth,
1602 SourceLocation ExportLoc,
1603 SourceLocation TemplateLoc,
1604 SourceLocation LAngleLoc,
1605 DeclTy **Params, unsigned NumParams,
1606 SourceLocation RAngleLoc);
Douglas Gregord684b002009-02-10 19:49:53 +00001607 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
1608 TemplateParameterList *OldParams);
1609
Douglas Gregorddc29e12009-02-06 22:42:48 +00001610 virtual DeclTy *
1611 ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK,
1612 SourceLocation KWLoc, const CXXScopeSpec &SS,
1613 IdentifierInfo *Name, SourceLocation NameLoc,
1614 AttributeList *Attr,
1615 MultiTemplateParamsArg TemplateParameterLists);
1616
Douglas Gregor40808ce2009-03-09 23:48:35 +00001617 QualType CheckClassTemplateId(ClassTemplateDecl *ClassTemplate,
1618 SourceLocation TemplateLoc,
1619 SourceLocation LAngleLoc,
1620 const TemplateArgument *TemplateArgs,
1621 unsigned NumTemplateArgs,
1622 SourceLocation RAngleLoc);
1623
Douglas Gregorcc636682009-02-17 23:15:12 +00001624 virtual TypeResult
1625 ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc,
1626 SourceLocation LAngleLoc,
1627 ASTTemplateArgsPtr TemplateArgs,
1628 SourceLocation *TemplateArgLocs,
1629 SourceLocation RAngleLoc,
1630 const CXXScopeSpec *SS);
1631
Douglas Gregor88b70942009-02-25 22:02:03 +00001632 bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate,
1633 ClassTemplateSpecializationDecl *PrevDecl,
1634 SourceLocation TemplateNameLoc,
1635 SourceRange ScopeSpecifierRange);
1636
Douglas Gregorcc636682009-02-17 23:15:12 +00001637 virtual DeclTy *
1638 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
1639 SourceLocation KWLoc,
1640 const CXXScopeSpec &SS,
1641 DeclTy *Template,
1642 SourceLocation TemplateNameLoc,
Douglas Gregor55f6b142009-02-09 18:46:07 +00001643 SourceLocation LAngleLoc,
Douglas Gregor5908e9f2009-02-09 19:34:22 +00001644 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregorc15cb382009-02-09 23:23:08 +00001645 SourceLocation *TemplateArgLocs,
Douglas Gregor55f6b142009-02-09 18:46:07 +00001646 SourceLocation RAngleLoc,
Douglas Gregorcc636682009-02-17 23:15:12 +00001647 AttributeList *Attr,
1648 MultiTemplateParamsArg TemplateParameterLists);
Douglas Gregor55f6b142009-02-09 18:46:07 +00001649
Douglas Gregorc15cb382009-02-09 23:23:08 +00001650 bool CheckTemplateArgumentList(TemplateDecl *Template,
1651 SourceLocation TemplateLoc,
1652 SourceLocation LAngleLoc,
Douglas Gregor40808ce2009-03-09 23:48:35 +00001653 const TemplateArgument *TemplateArgs,
1654 unsigned NumTemplateArgs,
Douglas Gregor3e00bad2009-02-17 01:05:43 +00001655 SourceLocation RAngleLoc,
1656 llvm::SmallVectorImpl<TemplateArgument> &Converted);
Douglas Gregorc15cb382009-02-09 23:23:08 +00001657
1658 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg,
1659 SourceLocation ArgLoc);
Douglas Gregor3e00bad2009-02-17 01:05:43 +00001660 bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,
1661 NamedDecl *&Entity);
1662 bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member);
Douglas Gregor2943aed2009-03-03 04:44:36 +00001663 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
1664 QualType InstantiatedParamType, Expr *&Arg,
Douglas Gregor3e00bad2009-02-17 01:05:43 +00001665 llvm::SmallVectorImpl<TemplateArgument> *Converted = 0);
Douglas Gregorc15cb382009-02-09 23:23:08 +00001666 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg);
Douglas Gregorddc29e12009-02-06 22:42:48 +00001667 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
1668 TemplateParameterList *Old,
1669 bool Complain,
Douglas Gregordd0574e2009-02-10 00:24:35 +00001670 bool IsTemplateTemplateParm = false,
1671 SourceLocation TemplateArgLoc
1672 = SourceLocation());
Douglas Gregorddc29e12009-02-06 22:42:48 +00001673
1674 bool CheckTemplateDeclScope(Scope *S,
1675 MultiTemplateParamsArg &TemplateParameterLists);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001676
Douglas Gregor99ebf652009-02-27 19:31:52 +00001677 //===--------------------------------------------------------------------===//
1678 // C++ Template Instantiation
1679 //
Douglas Gregor26dce442009-03-10 00:06:19 +00001680
1681 /// \brief A template instantiation that is currently in progress.
1682 struct ActiveTemplateInstantiation {
Douglas Gregordf667e72009-03-10 20:44:00 +00001683 /// \brief The kind of template instantiation we are performing
1684 enum {
1685 /// We are instantiating a template declaration. The entity is
1686 /// the declaration we're instantiation (e.g., a
1687 /// ClassTemplateSpecializationDecl).
1688 TemplateInstantiation,
1689
1690 /// We are instantiating a default argument for a template
1691 /// parameter. The Entity is the template, and
1692 /// TemplateArgs/NumTemplateArguments provides the template
1693 /// arguments as specified.
1694 DefaultTemplateArgumentInstantiation
1695 } Kind;
1696
Douglas Gregor26dce442009-03-10 00:06:19 +00001697 /// \brief The point of instantiation within the source code.
1698 SourceLocation PointOfInstantiation;
1699
1700 /// \brief The entity that is being instantiated.
Douglas Gregordf667e72009-03-10 20:44:00 +00001701 uintptr_t Entity;
1702
1703 // \brief If this the instantiation of a default template
1704 // argument, the list of tempalte arguments.
1705 const TemplateArgument *TemplateArgs;
1706
1707 /// \brief The number of template arguments in TemplateArgs.
1708 unsigned NumTemplateArgs;
Douglas Gregor26dce442009-03-10 00:06:19 +00001709
1710 /// \brief The source range that covers the construct that cause
1711 /// the instantiation, e.g., the template-id that causes a class
1712 /// template instantiation.
1713 SourceRange InstantiationRange;
Douglas Gregordf667e72009-03-10 20:44:00 +00001714
1715 friend bool operator==(const ActiveTemplateInstantiation &X,
1716 const ActiveTemplateInstantiation &Y) {
1717 if (X.Kind != Y.Kind)
1718 return false;
1719
1720 if (X.Entity != Y.Entity)
1721 return false;
1722
1723 switch (X.Kind) {
1724 case TemplateInstantiation:
1725 return true;
1726
1727 case DefaultTemplateArgumentInstantiation:
1728 return X.TemplateArgs == Y.TemplateArgs;
1729 }
1730
1731 return true;
1732 }
1733
1734 friend bool operator!=(const ActiveTemplateInstantiation &X,
1735 const ActiveTemplateInstantiation &Y) {
1736 return !(X == Y);
1737 }
Douglas Gregor26dce442009-03-10 00:06:19 +00001738 };
1739
1740 /// \brief List of active template instantiations.
1741 ///
1742 /// This vector is treated as a stack. As one template instantiation
1743 /// requires another template instantiation, additional
1744 /// instantiations are pushed onto the stack up to a
1745 /// user-configurable limit LangOptions::InstantiationDepth.
1746 llvm::SmallVector<ActiveTemplateInstantiation, 16>
1747 ActiveTemplateInstantiations;
1748
Douglas Gregor27b152f2009-03-10 18:52:44 +00001749 /// \brief The last template from which a template instantiation
1750 /// error or warning was produced.
1751 ///
1752 /// This value is used to suppress printing of redundant template
1753 /// instantiation backtraces when there are multiple errors in the
1754 /// same instantiation. FIXME: Does this belong in Sema? It's tough
1755 /// to implement it anywhere else.
Douglas Gregordf667e72009-03-10 20:44:00 +00001756 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
Douglas Gregor27b152f2009-03-10 18:52:44 +00001757
Douglas Gregor26dce442009-03-10 00:06:19 +00001758 /// \brief A stack object to be created when performing template
1759 /// instantiation.
1760 ///
1761 /// Construction of an object of type \c InstantiatingTemplate
1762 /// pushes the current instantiation onto the stack of active
1763 /// instantiations. If the size of this stack exceeds the maximum
1764 /// number of recursive template instantiations, construction
1765 /// produces an error and evaluates true.
1766 ///
1767 /// Destruction of this object will pop the named instantiation off
1768 /// the stack.
1769 struct InstantiatingTemplate {
Douglas Gregordf667e72009-03-10 20:44:00 +00001770 /// \brief Note that we are instantiating a class template.
Douglas Gregor26dce442009-03-10 00:06:19 +00001771 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
1772 ClassTemplateSpecializationDecl *Entity,
1773 SourceRange InstantiationRange = SourceRange());
Douglas Gregordf667e72009-03-10 20:44:00 +00001774
1775 /// \brief Note that we are instantiating a default argument in a
1776 /// template-id.
1777 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
1778 TemplateDecl *Template,
1779 const TemplateArgument *TemplateArgs,
1780 unsigned NumTemplateArgs,
1781 SourceRange InstantiationRange = SourceRange());
1782
Douglas Gregor26dce442009-03-10 00:06:19 +00001783 ~InstantiatingTemplate();
1784
1785 /// \brief Determines whether we have exceeded the maximum
1786 /// recursive template instantiations.
1787 operator bool() const { return Invalid; }
1788
1789 private:
1790 Sema &SemaRef;
1791 bool Invalid;
1792
Douglas Gregordf667e72009-03-10 20:44:00 +00001793 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
1794 SourceRange InstantiationRange);
1795
Douglas Gregor26dce442009-03-10 00:06:19 +00001796 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
1797
1798 InstantiatingTemplate&
1799 operator=(const InstantiatingTemplate&); // not implemented
1800 };
1801
Douglas Gregoree1828a2009-03-10 18:03:33 +00001802 static void PrintInstantiationStackHook(unsigned DiagID, void *Cookie);
1803 void PrintInstantiationStack();
1804
Douglas Gregor99ebf652009-02-27 19:31:52 +00001805 QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
1806 unsigned NumTemplateArgs,
1807 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor2943aed2009-03-03 04:44:36 +00001808 bool
1809 InstantiateBaseSpecifiers(ClassTemplateSpecializationDecl *ClassTemplateSpec,
1810 ClassTemplateDecl *ClassTemplate);
1811 bool
1812 InstantiateClassTemplateSpecialization(
1813 ClassTemplateSpecializationDecl *ClassTemplateSpec,
1814 bool ExplicitInstantiation);
Douglas Gregor99ebf652009-02-27 19:31:52 +00001815
Steve Naroff3536b442007-09-06 21:24:23 +00001816 // Objective-C declarations.
Chris Lattner06036d32008-07-26 04:13:19 +00001817 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
1818 IdentifierInfo *ClassName,
1819 SourceLocation ClassLoc,
1820 IdentifierInfo *SuperName,
1821 SourceLocation SuperLoc,
1822 DeclTy * const *ProtoRefs,
1823 unsigned NumProtoRefs,
1824 SourceLocation EndProtoLoc,
1825 AttributeList *AttrList);
Fariborz Jahanian243b64b2007-10-11 23:42:27 +00001826
1827 virtual DeclTy *ActOnCompatiblityAlias(
1828 SourceLocation AtCompatibilityAliasLoc,
1829 IdentifierInfo *AliasName, SourceLocation AliasLocation,
1830 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff61d68522009-03-05 15:22:01 +00001831
1832 void CheckForwardProtocolDeclarationForCircularDependency(
1833 IdentifierInfo *PName,
1834 SourceLocation &PLoc, SourceLocation PrevLoc,
1835 const ObjCList<ObjCProtocolDecl> &PList);
Steve Naroff3536b442007-09-06 21:24:23 +00001836
Steve Naroffe440eb82007-10-10 17:32:04 +00001837 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman1abc7f62008-02-20 22:57:40 +00001838 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian25e077d2007-09-17 21:07:36 +00001839 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattnere13b9592008-07-26 04:03:38 +00001840 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar246e70f2008-09-26 04:48:09 +00001841 SourceLocation EndProtoLoc,
1842 AttributeList *AttrList);
Fariborz Jahanian25e077d2007-09-17 21:07:36 +00001843
Chris Lattner6bd6d0b2008-07-26 04:07:02 +00001844 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
1845 IdentifierInfo *ClassName,
1846 SourceLocation ClassLoc,
1847 IdentifierInfo *CategoryName,
1848 SourceLocation CategoryLoc,
1849 DeclTy * const *ProtoRefs,
1850 unsigned NumProtoRefs,
1851 SourceLocation EndProtoLoc);
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +00001852
Steve Naroffe440eb82007-10-10 17:32:04 +00001853 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman1abc7f62008-02-20 22:57:40 +00001854 SourceLocation AtClassImplLoc,
Fariborz Jahanianccb4f312007-09-25 18:38:09 +00001855 IdentifierInfo *ClassName, SourceLocation ClassLoc,
1856 IdentifierInfo *SuperClassname,
1857 SourceLocation SuperClassLoc);
1858
Steve Naroffe440eb82007-10-10 17:32:04 +00001859 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +00001860 SourceLocation AtCatImplLoc,
1861 IdentifierInfo *ClassName,
1862 SourceLocation ClassLoc,
1863 IdentifierInfo *CatName,
1864 SourceLocation CatLoc);
1865
Steve Naroffe440eb82007-10-10 17:32:04 +00001866 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroff37e58d12007-10-02 22:39:18 +00001867 IdentifierInfo **IdentList,
1868 unsigned NumElts);
Fariborz Jahanian894c57f2007-09-21 15:40:54 +00001869
Steve Naroffe440eb82007-10-10 17:32:04 +00001870 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattner7caeabd2008-07-21 22:17:28 +00001871 const IdentifierLocPair *IdentList,
Fariborz Jahanianbc1c8772008-12-17 01:07:27 +00001872 unsigned NumElts,
1873 AttributeList *attrList);
Fariborz Jahanian245f92a2007-10-05 21:01:53 +00001874
Chris Lattnere13b9592008-07-26 04:03:38 +00001875 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattner7caeabd2008-07-21 22:17:28 +00001876 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001877 unsigned NumProtocols,
Chris Lattner7caeabd2008-07-21 22:17:28 +00001878 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanian02edb982008-05-01 00:03:38 +00001879
Daniel Dunbar95e61fb2008-09-23 21:53:23 +00001880 /// Ensure attributes are consistent with type.
1881 /// \param [in, out] Attributes The attributes to check; they will
1882 /// be modified to be consistent with \arg PropertyTy.
1883 void CheckObjCPropertyAttributes(QualType PropertyTy,
1884 SourceLocation Loc,
1885 unsigned &Attributes);
Steve Naroff0701bbb2009-01-08 17:28:14 +00001886 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Fariborz Jahanian02edb982008-05-01 00:03:38 +00001887 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1888 ObjCPropertyDecl *SuperProperty,
Chris Lattner8ec03f52008-11-24 03:54:41 +00001889 const IdentifierInfo *Name);
Fariborz Jahanian02edb982008-05-01 00:03:38 +00001890 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanianb5e02242008-04-24 19:58:34 +00001891
Fariborz Jahanian1ac2bc42008-12-06 23:03:39 +00001892 void MergeProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanianaebf0cb2008-05-02 19:17:30 +00001893 DeclTy *MergeProtocols);
1894
Fariborz Jahanianb7f95f52009-03-02 19:05:07 +00001895 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
1896 ObjCInterfaceDecl *ID);
1897
Fariborz Jahanian1ac2bc42008-12-06 23:03:39 +00001898 void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanianaebf0cb2008-05-02 19:17:30 +00001899 ObjCProtocolDecl *PDecl);
1900
Steve Naroff0416fb92007-11-11 17:19:15 +00001901 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
1902 DeclTy **allMethods = 0, unsigned allNum = 0,
1903 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +00001904
Fariborz Jahanian1de1e742008-04-14 23:36:35 +00001905 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian46b55e52008-05-05 18:51:55 +00001906 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanian5251e132008-05-06 18:09:04 +00001907 Selector GetterSel, Selector SetterSel,
Fariborz Jahanian8cf0bb32008-11-26 20:01:34 +00001908 DeclTy *ClassCategory, bool *OverridingProperty,
Fariborz Jahanian46b55e52008-05-05 18:51:55 +00001909 tok::ObjCKeywordKind MethodImplKind);
1910
Fariborz Jahanianf624f812008-04-18 00:19:30 +00001911 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
1912 SourceLocation PropertyLoc,
1913 bool ImplKind, DeclTy *ClassImplDecl,
1914 IdentifierInfo *PropertyId,
1915 IdentifierInfo *PropertyIvar);
1916
Steve Naroffbef11852007-10-26 20:53:56 +00001917 virtual DeclTy *ActOnMethodDeclaration(
1918 SourceLocation BeginLoc, // location of the + or -.
1919 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanian1f7b6f82007-11-09 19:52:12 +00001920 tok::TokenKind MethodType,
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001921 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanianf1de0ca2007-10-31 23:53:01 +00001922 Selector Sel,
Steve Naroff68d331a2007-09-27 14:38:14 +00001923 // optional arguments. The number of types/arguments is obtained
1924 // from the Sel.getNumArgs().
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001925 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Fariborz Jahanian439c6582009-01-09 00:38:19 +00001926 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroff335eafa2007-11-15 12:35:21 +00001927 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
1928 bool isVariadic = false);
Steve Naroff81bfde92007-10-16 23:12:48 +00001929
Steve Narofff1afaf62009-02-26 15:55:06 +00001930 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
1931 // Will search "local" class/category implementations for a method decl.
Fariborz Jahanian175ba1e2009-03-04 18:15:57 +00001932 // Will also search in class's root looking for instance method.
Steve Narofff1afaf62009-02-26 15:55:06 +00001933 // Returns 0 if no method is found.
Steve Naroff5609ec02009-03-08 18:56:13 +00001934 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
1935 ObjCInterfaceDecl *CDecl);
1936 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
1937 ObjCInterfaceDecl *ClassDecl);
Steve Narofff1afaf62009-02-26 15:55:06 +00001938
Steve Naroff61f72cb2009-03-09 21:12:44 +00001939 virtual OwningExprResult ActOnClassPropertyRefExpr(
1940 IdentifierInfo &receiverName,
1941 IdentifierInfo &propertyName,
1942 SourceLocation &receiverNameLoc,
1943 SourceLocation &propertyNameLoc);
1944
Steve Naroff68d331a2007-09-27 14:38:14 +00001945 // ActOnClassMessage - used for both unary and keyword messages.
1946 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff49f109c2007-11-15 13:05:42 +00001947 // is obtained from NumArgs.
Steve Naroff68d331a2007-09-27 14:38:14 +00001948 virtual ExprResult ActOnClassMessage(
Fariborz Jahanian0523aaf2007-11-12 20:13:27 +00001949 Scope *S,
Anders Carlssonff975cf2009-02-14 18:21:46 +00001950 IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,
1951 SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac,
Steve Naroff49f109c2007-11-15 13:05:42 +00001952 ExprTy **ArgExprs, unsigned NumArgs);
Steve Naroff68d331a2007-09-27 14:38:14 +00001953
1954 // ActOnInstanceMessage - used for both unary and keyword messages.
1955 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff49f109c2007-11-15 13:05:42 +00001956 // is obtained from NumArgs.
Steve Naroff68d331a2007-09-27 14:38:14 +00001957 virtual ExprResult ActOnInstanceMessage(
Steve Naroffbcfb06a2007-09-28 22:22:11 +00001958 ExprTy *receiver, Selector Sel,
Anders Carlssonff975cf2009-02-14 18:21:46 +00001959 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroff49f109c2007-11-15 13:05:42 +00001960 ExprTy **ArgExprs, unsigned NumArgs);
Daniel Dunbar4cde9272008-10-14 05:35:18 +00001961
1962 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
1963 virtual void ActOnPragmaPack(PragmaPackKind Kind,
1964 IdentifierInfo *Name,
1965 ExprTy *Alignment,
1966 SourceLocation PragmaLoc,
1967 SourceLocation LParenLoc,
1968 SourceLocation RParenLoc);
Chris Lattner574aa402009-02-17 01:09:29 +00001969
1970 /// getPragmaPackAlignment() - Return the current alignment as specified by
1971 /// the current #pragma pack directive, or 0 if none is currently active.
1972 unsigned getPragmaPackAlignment() const;
1973
1974 /// FreePackedContext - Deallocate and null out PackContext.
1975 void FreePackedContext();
Daniel Dunbar4cde9272008-10-14 05:35:18 +00001976
Chris Lattner1e0a3902008-01-16 19:17:22 +00001977 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
1978 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregoreb8f3062008-11-12 17:17:38 +00001979 /// If isLvalue, the result of the cast is an lvalue.
1980 void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
Chris Lattner1e0a3902008-01-16 19:17:22 +00001981
Reid Spencer5f016e22007-07-11 17:01:13 +00001982 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner925e60d2007-12-28 05:29:59 +00001983 // functions and arrays to their respective pointers (C99 6.3.2.1).
1984 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3c0eb162008-05-27 03:33:27 +00001985
Steve Naroffc80b4ee2007-07-16 21:54:35 +00001986 // DefaultFunctionArrayConversion - converts functions and arrays
1987 // to their respective pointers (C99 6.3.2.1).
1988 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroff90045e82007-07-13 23:32:42 +00001989
Steve Naroffb291ab62007-08-28 23:30:39 +00001990 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
1991 // do not have a prototype. Integer promotions are performed on each
1992 // argument, and arguments that have type float are promoted to double.
Chris Lattner925e60d2007-12-28 05:29:59 +00001993 void DefaultArgumentPromotion(Expr *&Expr);
Anders Carlssondce5e2c2009-01-16 16:48:51 +00001994
1995 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
1996 enum VariadicCallType {
1997 VariadicFunction,
1998 VariadicBlock,
1999 VariadicMethod
2000 };
2001
2002 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
2003 // will warn if the resulting type is not a POD type.
2004 void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
Steve Naroffb291ab62007-08-28 23:30:39 +00002005
Reid Spencer5f016e22007-07-11 17:01:13 +00002006 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
2007 // operands and then handles various conversions that are common to binary
2008 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
2009 // routine returns the first non-arithmetic type found. The client is
2010 // responsible for emitting appropriate error diagnostics.
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00002011 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
2012 bool isCompAssign = false);
Chris Lattnerb7b61152008-01-04 18:22:42 +00002013
Douglas Gregoreb8f3062008-11-12 17:17:38 +00002014 /// UsualArithmeticConversionsType - handles the various conversions
2015 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
2016 /// and returns the result type of that conversion.
2017 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
2018
2019
Chris Lattnerb7b61152008-01-04 18:22:42 +00002020 /// AssignConvertType - All of the 'assignment' semantic checks return this
2021 /// enum to indicate whether the assignment was allowed. These checks are
2022 /// done for simple assignments, as well as initialization, return from
2023 /// function, argument passing, etc. The query is phrased in terms of a
2024 /// source and destination type.
Chris Lattner5cf216b2008-01-04 18:04:52 +00002025 enum AssignConvertType {
Chris Lattnerb7b61152008-01-04 18:22:42 +00002026 /// Compatible - the types are compatible according to the standard.
Reid Spencer5f016e22007-07-11 17:01:13 +00002027 Compatible,
Chris Lattnerb7b61152008-01-04 18:22:42 +00002028
2029 /// PointerToInt - The assignment converts a pointer to an int, which we
2030 /// accept as an extension.
2031 PointerToInt,
2032
2033 /// IntToPointer - The assignment converts an int to a pointer, which we
2034 /// accept as an extension.
2035 IntToPointer,
2036
2037 /// FunctionVoidPointer - The assignment is between a function pointer and
2038 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattnerbfe639e2008-01-03 22:56:36 +00002039 FunctionVoidPointer,
Chris Lattnerb7b61152008-01-04 18:22:42 +00002040
2041 /// IncompatiblePointer - The assignment is between two pointers types that
2042 /// are not compatible, but we accept them as an extension.
Reid Spencer5f016e22007-07-11 17:01:13 +00002043 IncompatiblePointer,
Chris Lattnerb7b61152008-01-04 18:22:42 +00002044
2045 /// CompatiblePointerDiscardsQualifiers - The assignment discards
2046 /// c/v/r qualifiers, which we accept as an extension.
2047 CompatiblePointerDiscardsQualifiers,
Steve Naroff1c7d0672008-09-04 15:10:53 +00002048
Anders Carlssonb0f90cc2009-01-30 23:17:46 +00002049 /// IncompatibleVectors - The assignment is between two vector types that
2050 /// have the same size, which we accept as an extension.
2051 IncompatibleVectors,
2052
Steve Naroffbfdcae62008-09-04 15:31:07 +00002053 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff1c7d0672008-09-04 15:10:53 +00002054 /// pointer. We disallow this.
2055 IntToBlockPointer,
2056
Steve Naroffbfdcae62008-09-04 15:31:07 +00002057 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff1c7d0672008-09-04 15:10:53 +00002058 /// pointers types that are not compatible.
2059 IncompatibleBlockPointer,
2060
Steve Naroff39579072008-10-14 22:18:38 +00002061 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
2062 /// id type and something else (that is incompatible with it). For example,
2063 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
2064 IncompatibleObjCQualifiedId,
2065
Chris Lattnerb7b61152008-01-04 18:22:42 +00002066 /// Incompatible - We reject this conversion outright, it is invalid to
2067 /// represent it in the AST.
2068 Incompatible
Reid Spencer5f016e22007-07-11 17:01:13 +00002069 };
Chris Lattner5cf216b2008-01-04 18:04:52 +00002070
2071 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
2072 /// assignment conversion type specified by ConvTy. This returns true if the
2073 /// conversion was invalid or false if the conversion was accepted.
2074 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
2075 SourceLocation Loc,
2076 QualType DstType, QualType SrcType,
2077 Expr *SrcExpr, const char *Flavor);
2078
2079 /// CheckAssignmentConstraints - Perform type checking for assignment,
2080 /// argument passing, variable initialization, and function return values.
2081 /// This routine is only used by the following two methods. C99 6.5.16.
2082 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroff90045e82007-07-13 23:32:42 +00002083
Steve Narofff69936d2007-09-16 03:34:24 +00002084 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff1b273c42007-09-16 14:56:35 +00002085 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroff90045e82007-07-13 23:32:42 +00002086 // this routine performs the default function/array converions.
Chris Lattner5cf216b2008-01-04 18:04:52 +00002087 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
2088 Expr *&rExpr);
Steve Naroff90045e82007-07-13 23:32:42 +00002089 // CheckCompoundAssignmentConstraints - Type check without performing any
2090 // conversions. For compound assignments, the "Check...Operands" methods
2091 // perform the necessary conversions.
Chris Lattner5cf216b2008-01-04 18:04:52 +00002092 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
2093 QualType rhs);
Steve Naroff90045e82007-07-13 23:32:42 +00002094
Reid Spencer5f016e22007-07-11 17:01:13 +00002095 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner5cf216b2008-01-04 18:04:52 +00002096 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
2097 QualType rhsType);
Steve Naroff1c7d0672008-09-04 15:10:53 +00002098
2099 // Helper function for CheckAssignmentConstraints involving two
2100 // blcok pointer types.
2101 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
2102 QualType rhsType);
Douglas Gregor77a52232008-09-12 00:47:35 +00002103
2104 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00002105
Douglas Gregor45920e82008-12-19 17:40:08 +00002106 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00002107 const char *Flavor, bool AllowExplicit = false);
2108 bool PerformImplicitConversion(Expr *&From, QualType ToType,
2109 const ImplicitConversionSequence& ICS,
Douglas Gregor45920e82008-12-19 17:40:08 +00002110 const char *Flavor);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00002111 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor45920e82008-12-19 17:40:08 +00002112 const StandardConversionSequence& SCS,
2113 const char *Flavor);
Sebastian Redl22460502009-02-07 00:15:38 +00002114
Reid Spencer5f016e22007-07-11 17:01:13 +00002115 /// the following "Check" methods will return a valid/converted QualType
2116 /// or a null QualType (indicating an error diagnostic was issued).
Sebastian Redl22460502009-02-07 00:15:38 +00002117
2118 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
Chris Lattnerca5eede2007-12-12 05:47:28 +00002119 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Sebastian Redl7c8bd602009-02-07 20:10:22 +00002120 QualType CheckPointerToMemberOperands( // C++ 5.5
Sebastian Redl22460502009-02-07 00:15:38 +00002121 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
Reid Spencer5f016e22007-07-11 17:01:13 +00002122 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Sebastian Redl22460502009-02-07 00:15:38 +00002123 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002124 inline QualType CheckRemainderOperands( // C99 6.5.5
Sebastian Redl22460502009-02-07 00:15:38 +00002125 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002126 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00002127 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002128 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00002129 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002130 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00002131 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnera5937dd2007-08-26 01:18:55 +00002132 inline QualType CheckCompareOperands( // C99 6.5.8/9
2133 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Reid Spencer5f016e22007-07-11 17:01:13 +00002134 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Sebastian Redl22460502009-02-07 00:15:38 +00002135 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002136 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff49b45262007-07-13 16:58:59 +00002137 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002138 // CheckAssignmentOperands is used for both simple and compound assignment.
2139 // For simple assignment, pass both expressions and a null converted type.
2140 // For compound assignment, pass both expressions and the converted type.
2141 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Narofff1120de2007-08-24 22:33:52 +00002142 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Reid Spencer5f016e22007-07-11 17:01:13 +00002143 inline QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner29a1cfb2008-11-18 01:30:42 +00002144 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002145 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff49b45262007-07-13 16:58:59 +00002146 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begemanbe2341d2008-07-14 18:02:46 +00002147
2148 /// type checking for vector binary operators.
2149 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
2150 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
2151 SourceLocation l, bool isRel);
Reid Spencer5f016e22007-07-11 17:01:13 +00002152
Steve Narofff69936d2007-09-16 03:34:24 +00002153 /// type checking unary operators (subroutines of ActOnUnaryOp).
Reid Spencer5f016e22007-07-11 17:01:13 +00002154 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redle6d5a4a2008-12-20 09:35:34 +00002155 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
2156 bool isInc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002157 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
2158 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattnerba27e2a2009-02-17 08:12:06 +00002159 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
Steve Naroffe1b31fe2007-07-27 22:15:19 +00002160
2161 /// type checking primary expressions.
Nate Begeman213541a2008-04-18 23:10:10 +00002162 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Naroffe1b31fe2007-07-27 22:15:19 +00002163 IdentifierInfo &Comp, SourceLocation CmpLoc);
2164
Steve Narofff0090632007-09-02 02:04:30 +00002165 /// type checking declaration initializers (C99 6.7.8)
Douglas Gregorf03d7c72008-11-05 15:29:30 +00002166 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00002167 SourceLocation InitLoc,DeclarationName InitEntity,
2168 bool DirectInit);
Douglas Gregorc34ee5e2009-01-29 00:45:39 +00002169 bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
Steve Naroffd0091aa2008-01-10 22:15:12 +00002170 bool CheckForConstantInitializer(Expr *e, QualType t);
Steve Naroff2fdc3742007-12-10 22:44:33 +00002171
Douglas Gregor87fd7032009-02-02 17:43:21 +00002172 bool CheckValueInitialization(QualType Type, SourceLocation Loc);
Argyrios Kyrtzidis6c2dc4d2008-08-16 20:27:34 +00002173
Douglas Gregor27c8dc02008-10-29 00:13:59 +00002174 // type checking C++ declaration initializers (C++ [dcl.init]).
2175
2176 /// ReferenceCompareResult - Expresses the result of comparing two
2177 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
2178 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
2179 enum ReferenceCompareResult {
2180 /// Ref_Incompatible - The two types are incompatible, so direct
2181 /// reference binding is not possible.
2182 Ref_Incompatible = 0,
2183 /// Ref_Related - The two types are reference-related, which means
2184 /// that their unqualified forms (T1 and T2) are either the same
2185 /// or T1 is a base class of T2.
2186 Ref_Related,
2187 /// Ref_Compatible_With_Added_Qualification - The two types are
2188 /// reference-compatible with added qualification, meaning that
2189 /// they are reference-compatible and the qualifiers on T1 (cv1)
2190 /// are greater than the qualifiers on T2 (cv2).
2191 Ref_Compatible_With_Added_Qualification,
2192 /// Ref_Compatible - The two types are reference-compatible and
2193 /// have equivalent qualifiers (cv1 == cv2).
2194 Ref_Compatible
2195 };
2196
Douglas Gregor15da57e2008-10-29 02:00:59 +00002197 ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
2198 bool& DerivedToBase);
Douglas Gregor27c8dc02008-10-29 00:13:59 +00002199
2200 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor225c41e2008-11-03 19:09:14 +00002201 ImplicitConversionSequence *ICS = 0,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00002202 bool SuppressUserConversions = false,
2203 bool AllowExplicit = false);
Douglas Gregor27c8dc02008-10-29 00:13:59 +00002204
Argyrios Kyrtzidis6c2dc4d2008-08-16 20:27:34 +00002205 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar58d5ebb2008-08-20 03:55:42 +00002206 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroffa49e1fa2008-01-22 00:55:40 +00002207
Anders Carlsson584b2472007-11-27 07:16:40 +00002208 // CheckVectorCast - check type constraints for vectors.
2209 // Since vectors are an extension, there are no C standard reference for this.
2210 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssona64db8f2007-11-27 05:51:55 +00002211 // returns true if the cast is invalid
2212 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
2213
Daniel Dunbar637cebb2008-09-11 00:01:56 +00002214 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
2215 /// \param Method - May be null.
2216 /// \param [out] ReturnType - The return type of the send.
2217 /// \return true iff there were any incompatible types.
Daniel Dunbar91e19b22008-09-11 00:50:25 +00002218 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattner077bf5e2008-11-24 03:33:13 +00002219 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbar637cebb2008-09-11 00:01:56 +00002220 SourceLocation lbrac, SourceLocation rbrac,
2221 QualType &ReturnType);
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00002222
2223 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
2224 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff81bfde92007-10-16 23:12:48 +00002225
Chris Lattnerf4021e72007-08-23 05:46:52 +00002226 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
2227 /// the specified width and sign. If an overflow occurs, detect it and emit
2228 /// the specified diagnostic.
2229 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
2230 unsigned NewWidth, bool NewSign,
2231 SourceLocation Loc, unsigned DiagID);
2232
Chris Lattnereca7be62008-04-07 05:30:13 +00002233 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
2234 bool ForCompare);
2235
Anders Carlsson15281452008-11-04 16:57:32 +00002236 /// Checks that the Objective-C declaration is declared in the global scope.
2237 /// Emits an error and marks the declaration as invalid if it's not declared
2238 /// in the global scope.
2239 bool CheckObjCDeclScope(Decl *D);
2240
Anders Carlsson7c50aca2007-10-15 20:28:48 +00002241 void InitBuiltinVaListType();
Eli Friedman1b76ada2008-06-03 21:01:11 +00002242
Anders Carlssone21555e2008-11-30 19:50:32 +00002243 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
2244 /// and reports the appropriate diagnostics. Returns false on success.
2245 /// Can optionally return the value of the expression.
Anders Carlsson9f1e5722008-12-06 20:33:04 +00002246 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson4000ea62008-12-01 02:17:22 +00002247
Anders Carlsson9f1e5722008-12-06 20:33:04 +00002248 /// VerifyBitField - verifies that a bit field expression is an ICE and has
2249 /// the correct width, and that the field type is valid.
2250 /// Returns false on success.
2251 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
2252 QualType FieldTy, const Expr *BitWidth);
Sebastian Redl0eb23302009-01-19 00:08:26 +00002253
Chris Lattner59907c42007-08-10 20:18:51 +00002254 //===--------------------------------------------------------------------===//
2255 // Extra semantic analysis beyond the C type system
Chris Lattner925e60d2007-12-28 05:29:59 +00002256private:
Sebastian Redl0eb23302009-01-19 00:08:26 +00002257 Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl,
2258 CallExpr *TheCall);
Chris Lattner60800082009-02-18 17:49:48 +00002259 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
2260 unsigned ByteNo) const;
Chris Lattner69039812009-02-18 06:01:06 +00002261 bool CheckObjCString(Expr *Arg);
Chris Lattner925e60d2007-12-28 05:29:59 +00002262 bool SemaBuiltinVAStart(CallExpr *TheCall);
2263 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedman6cfda232008-05-20 08:23:37 +00002264 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Sebastian Redl0eb23302009-01-19 00:08:26 +00002265 Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbar4493f792008-07-21 22:59:13 +00002266 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbard5f8a4f2008-09-03 21:13:56 +00002267 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Ted Kremenekd30ef872009-01-12 23:09:09 +00002268 bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg,
Douglas Gregor3c385e52009-02-14 18:57:46 +00002269 unsigned format_idx, unsigned firstDataArg);
Ted Kremenekd30ef872009-01-12 23:09:09 +00002270 void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr,
2271 CallExpr *TheCall, bool HasVAListArg,
Douglas Gregor3c385e52009-02-14 18:57:46 +00002272 unsigned format_idx, unsigned firstDataArg);
2273 void CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
2274 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek06de2762007-08-17 16:46:58 +00002275 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
2276 SourceLocation ReturnLoc);
Ted Kremenek588e5eb2007-11-25 00:58:00 +00002277 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Reid Spencer5f016e22007-07-11 17:01:13 +00002278};
2279
Steve Naroff4eb206b2008-09-03 18:15:37 +00002280/// BlockSemaInfo - When a block is being parsed, this contains information
2281/// about the block. It is pointed to from Sema::CurBlock.
2282struct BlockSemaInfo {
2283 llvm::SmallVector<ParmVarDecl*, 8> Params;
Steve Naroff4eb206b2008-09-03 18:15:37 +00002284 bool hasPrototype;
2285 bool isVariadic;
Mike Stumpb83d2872009-02-19 22:01:56 +00002286 bool hasBlockDeclRefExprs;
2287
Steve Naroff1c90bfc2008-10-08 18:44:00 +00002288 BlockDecl *TheDecl;
2289
Chris Lattnerda425eb2009-02-18 07:09:44 +00002290 /// TheScope - This is the scope for the block itself, which contains
Steve Naroff4eb206b2008-09-03 18:15:37 +00002291 /// arguments etc.
2292 Scope *TheScope;
2293
2294 /// ReturnType - This will get set to block result type, by looking at
2295 /// return types, if any, in the block body.
2296 Type *ReturnType;
2297
2298 /// PrevBlockInfo - If this is nested inside another block, this points
2299 /// to the outer block.
2300 BlockSemaInfo *PrevBlockInfo;
2301};
Ted Kremenek8189cde2009-02-07 01:47:29 +00002302
2303//===--------------------------------------------------------------------===//
2304// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
2305template <typename T>
2306class ExprOwningPtr : public Action::ExprArg {
2307public:
2308 ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {};
2309
2310 void reset(T* p) { Action::ExprArg::operator=(p); }
2311 T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
2312 T* take() { return static_cast<T*>(Action::ExprArg::take()); }
2313 T* release() { return take(); }
2314
2315 T& operator*() const { return *get(); }
2316 T* operator->() const { return get(); }
2317};
2318
Reid Spencer5f016e22007-07-11 17:01:13 +00002319} // end namespace clang
2320
2321#endif