blob: 1a66cc032420d450efff1d44053374931154b0a1 [file] [log] [blame]
Chris Lattnercc67ec12006-11-09 06:54:47 +00001//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
Chris Lattner7cee11f2006-11-03 06:42:29 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner7cee11f2006-11-03 06:42:29 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattnercc67ec12006-11-09 06:54:47 +000010// This file defines the Sema class, which performs semantic analysis and
11// builds ASTs.
Chris Lattner7cee11f2006-11-03 06:42:29 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattnercc67ec12006-11-09 06:54:47 +000015#ifndef LLVM_CLANG_AST_SEMA_H
16#define LLVM_CLANG_AST_SEMA_H
Chris Lattner7cee11f2006-11-03 06:42:29 +000017
Chris Lattnerc5c95b52008-04-11 07:00:53 +000018#include "IdentifierResolver.h"
Argyrios Kyrtzidised983422008-07-01 10:37:29 +000019#include "CXXFieldCollector.h"
Douglas Gregor5251f1b2008-10-21 16:13:35 +000020#include "SemaOverload.h"
Douglas Gregor34074322009-01-14 22:20:51 +000021#include "clang/AST/DeclBase.h"
Chris Lattner7cee11f2006-11-03 06:42:29 +000022#include "clang/Parse/Action.h"
Chris Lattner60f36222009-01-29 05:15:15 +000023#include "clang/Sema/SemaDiagnostic.h"
Anders Carlsson51873c22007-07-22 07:07:56 +000024#include "llvm/ADT/SmallVector.h"
Fariborz Jahanian458f7112007-10-05 18:00:57 +000025#include "llvm/ADT/DenseSet.h"
Chris Lattneree2d8412007-10-07 01:13:46 +000026#include "llvm/ADT/SmallPtrSet.h"
Argyrios Kyrtzidised983422008-07-01 10:37:29 +000027#include "llvm/ADT/OwningPtr.h"
Steve Naroff41d09ad2009-03-05 15:22:01 +000028#include "clang/AST/DeclObjC.h"
Douglas Gregor1c846b02009-01-16 00:38:09 +000029#include <string>
Douglas Gregor39c16d42008-10-24 04:54:22 +000030#include <vector>
Chris Lattner7cee11f2006-11-03 06:42:29 +000031
Chris Lattnerfc1c44a2007-08-23 05:46:52 +000032namespace llvm {
33 class APSInt;
34}
35
Chris Lattner7cee11f2006-11-03 06:42:29 +000036namespace clang {
Chris Lattnercb6a3822006-11-10 06:20:45 +000037 class ASTContext;
Chris Lattnerfe0e0af2008-02-06 00:46:58 +000038 class ASTConsumer;
Chris Lattner7cee11f2006-11-03 06:42:29 +000039 class Preprocessor;
40 class Decl;
Chris Lattner0a5ff0d2008-04-06 04:47:34 +000041 class DeclContext;
Daniel Dunbar34fb6722008-08-11 03:27:53 +000042 class DeclSpec;
Steve Naroff257520b2008-04-01 23:04:06 +000043 class NamedDecl;
Sebastian Redlc675bab2008-12-13 16:23:55 +000044 class Stmt;
Steve Naroff78403362007-04-02 22:55:05 +000045 class Expr;
Steve Narofff33527a2007-09-02 15:34:30 +000046 class InitListExpr;
Douglas Gregore4a0bb72009-01-22 00:58:24 +000047 class DesignatedInitExpr;
Chris Lattner08464942007-12-28 05:29:59 +000048 class CallExpr;
Douglas Gregorc7acfdf2009-01-06 05:10:23 +000049 class DeclRefExpr;
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +000050 class VarDecl;
Chris Lattner53621a52007-06-13 20:44:40 +000051 class ParmVarDecl;
Chris Lattner01564d92007-01-27 19:27:06 +000052 class TypedefDecl;
53 class FunctionDecl;
Steve Naroffe5aa9be2007-04-05 22:36:20 +000054 class QualType;
Sebastian Redl7dce7722009-03-07 12:16:37 +000055 class LangOptions;
Chris Lattner146762e2007-07-20 16:59:19 +000056 class Token;
Steve Naroff35d85152007-05-07 00:24:15 +000057 class IntegerLiteral;
Steve Naroffaf2a0222008-01-22 00:55:40 +000058 class StringLiteral;
Steve Naroff8eeeb132007-05-08 21:09:37 +000059 class ArrayType;
Chris Lattnere2473062007-05-28 06:28:18 +000060 class LabelStmt;
Anders Carlsson51873c22007-07-22 07:07:56 +000061 class SwitchStmt;
Nate Begemance4d7fc2008-04-18 23:10:10 +000062 class ExtVectorType;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000063 class TypedefDecl;
Douglas Gregorded2d7b2009-02-04 19:02:06 +000064 class TemplateDecl;
Douglas Gregor264ec4f2009-02-17 01:05:43 +000065 class TemplateArgument;
Douglas Gregorcd72ba92009-02-06 22:42:48 +000066 class TemplateParameterList;
Douglas Gregord32e0282009-02-09 23:23:08 +000067 class TemplateTemplateParmDecl;
Douglas Gregorf47b9112009-02-25 22:02:03 +000068 class ClassTemplateDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000069 class ObjCInterfaceDecl;
Steve Naroff257520b2008-04-01 23:04:06 +000070 class ObjCCompatibleAliasDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000071 class ObjCProtocolDecl;
Chris Lattner9ef10f42009-03-01 00:56:52 +000072 class ObjCImplDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000073 class ObjCImplementationDecl;
74 class ObjCCategoryImplDecl;
75 class ObjCCategoryDecl;
76 class ObjCIvarDecl;
77 class ObjCMethodDecl;
Fariborz Jahanian7cf18862008-05-01 00:03:38 +000078 class ObjCPropertyDecl;
Steve Naroff35c62ae2009-01-08 17:28:14 +000079 class ObjCContainerDecl;
Steve Naroffc540d662008-09-03 18:15:37 +000080 struct BlockSemaInfo;
Douglas Gregor39c16d42008-10-24 04:54:22 +000081 class BasePaths;
Sebastian Redl7dce7722009-03-07 12:16:37 +000082 struct MemberLookupCriteria;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000083
Chris Lattnercc67ec12006-11-09 06:54:47 +000084/// Sema - This implements semantic analysis and AST building for C.
85class Sema : public Action {
Chris Lattner01c3d232009-02-17 00:58:30 +000086 Sema(const Sema&); // DO NOT IMPLEMENT
87 void operator=(const Sema&); // DO NOT IMPLEMENT
Chris Lattnera663a0a2008-06-29 00:28:59 +000088public:
Chris Lattner4da04a4e2009-01-22 19:21:44 +000089 const LangOptions &LangOpts;
Steve Naroff38d31b42007-02-28 01:22:02 +000090 Preprocessor &PP;
Chris Lattnercb6a3822006-11-10 06:20:45 +000091 ASTContext &Context;
Chris Lattnerfe0e0af2008-02-06 00:46:58 +000092 ASTConsumer &Consumer;
Chris Lattnerbc495d72008-11-22 08:28:49 +000093 Diagnostic &Diags;
94 SourceManager &SourceMgr;
Steve Naroffe3d1ab22007-11-12 13:56:41 +000095
Argyrios Kyrtzidis853fbea2008-06-28 06:07:14 +000096 /// CurContext - This is the current declaration context of parsing.
Chris Lattner0a5ff0d2008-04-06 04:47:34 +000097 DeclContext *CurContext;
Chris Lattnerc5ffed42008-04-04 06:12:32 +000098
Argyrios Kyrtzidis16ac9be2008-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 Naroffc540d662008-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 Naroffd123bd02009-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 Dunbar54603742008-10-14 05:35:18 +0000111 /// PackContext - Manages the stack for #pragma pack. An alignment
112 /// of 0 indicates default alignment.
Chris Lattner31180bb2009-02-17 01:09:29 +0000113 void *PackContext; // Really a "PragmaPackStack*"
Daniel Dunbar54603742008-10-14 05:35:18 +0000114
Anders Carlsson51873c22007-07-22 07:07:56 +0000115 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffddf5a1d2007-07-29 16:33:31 +0000116
Nate Begemance4d7fc2008-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 Naroffddf5a1d2007-07-29 16:33:31 +0000119 /// This is only necessary for issuing pretty diagnostics.
Nate Begemance4d7fc2008-04-18 23:10:10 +0000120 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000121
Steve Naroff8edb5732008-09-28 14:55:53 +0000122 /// ObjCImplementations - Keep track of all class @implementations
123 /// so we can emit errors on duplicates.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000124 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattneree2d8412007-10-07 01:13:46 +0000125
Steve Naroff8edb5732008-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 Kremenek1b0ea822008-01-07 19:49:32 +0000130 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanian06f84f52007-10-09 18:03:53 +0000131 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner516ca702007-10-09 18:18:24 +0000132 /// find the declarations when needed.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000133 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff77892752008-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 Naroff257520b2008-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 Naroff9b94b172008-04-02 00:39:51 +0000146 typedef llvm::DenseMap<const IdentifierInfo*,
147 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroff257520b2008-04-01 23:04:06 +0000148 ObjCAliasTy ObjCAliasDecls;
Steve Naroff77892752008-04-02 18:30:49 +0000149
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000150 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
151 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
152
Douglas Gregor5a80bd12009-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 Lattnerc5c95b52008-04-11 07:00:53 +0000180 IdentifierResolver IdResolver;
181
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000182 // Enum values used by KnownFunctionIDs (see below).
183 enum {
Ted Kremenek34f664d2008-06-16 18:00:42 +0000184 id_NSLog,
Douglas Gregore711f702009-02-14 18:57:46 +0000185 id_NSLogv,
Daniel Dunbardd9b2d12008-10-02 18:44:07 +0000186 id_asprintf,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000187 id_vasprintf,
Chris Lattnerb87b1b32007-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 Lattner2cc35ae2008-08-23 02:00:52 +0000195 IdentifierInfo* KnownFunctionIDs[id_num_known_functions];
Daniel Dunbar12c9ddc2008-08-14 22:04:54 +0000196
Steve Naroff93eb5f12007-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 Naroffc62adb62007-10-09 22:01:59 +0000200 Scope *TUScope;
Sebastian Redlc4704762008-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 Redlfaf68082008-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 Naroff7f549f12007-10-10 21:53:07 +0000209
Steve Naroff5811baf2007-10-14 00:58:41 +0000210 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000211 struct ObjCMethodList {
212 ObjCMethodDecl *Method;
213 ObjCMethodList *Next;
Steve Naroff5811baf2007-10-14 00:58:41 +0000214
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000215 ObjCMethodList() {
Steve Naroff5811baf2007-10-14 00:58:41 +0000216 Method = 0;
217 Next = 0;
218 }
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000219 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff5811baf2007-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 Kremenek1b0ea822008-01-07 19:49:32 +0000228 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
229 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Steve Naroff3f49fee2009-03-04 15:11:40 +0000230
231 /// Private Helper predicate to check for 'self'.
232 bool isSelfExpr(Expr *RExpr);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000233public:
Chris Lattnerfe0e0af2008-02-06 00:46:58 +0000234 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
Chris Lattner31180bb2009-02-17 01:09:29 +0000235 ~Sema() {
236 if (PackContext) FreePackedContext();
237 }
Chris Lattner7cee11f2006-11-03 06:42:29 +0000238
Chris Lattner4da04a4e2009-01-22 19:21:44 +0000239 const LangOptions &getLangOptions() const { return LangOpts; }
Chris Lattnerbc495d72008-11-22 08:28:49 +0000240 Diagnostic &getDiagnostics() const { return Diags; }
241 SourceManager &getSourceManager() const { return SourceMgr; }
242
Chris Lattner84f1ee32008-11-18 21:53:24 +0000243 /// The primitive diagnostic helpers.
Chris Lattnerbc495d72008-11-22 08:28:49 +0000244 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
Douglas Gregor4ea568f2009-03-10 18:03:33 +0000245 DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
Douglas Gregor2a72edd2009-03-10 18:52:44 +0000246 if (!Diags.isBuiltinNote(DiagID) &&
247 !ActiveTemplateInstantiations.empty() &&
Douglas Gregor79cf6032009-03-10 20:44:00 +0000248 ActiveTemplateInstantiations.back()
Douglas Gregor2a72edd2009-03-10 18:52:44 +0000249 != LastTemplateInstantiationErrorContext)
Douglas Gregor4ea568f2009-03-10 18:03:33 +0000250 DB << PostDiagnosticHook(PrintInstantiationStackHook, this);
251 return DB;
Chris Lattnerbc495d72008-11-22 08:28:49 +0000252 }
Steve Naroff71ce2e02007-05-18 22:53:50 +0000253
Chris Lattner57c523f2007-08-31 04:53:24 +0000254 virtual void DeleteExpr(ExprTy *E);
255 virtual void DeleteStmt(StmtTy *S);
256
Sebastian Redlc675bab2008-12-13 16:23:55 +0000257 OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); }
Sebastian Redlc215cfc2009-01-19 00:08:26 +0000258 OwningExprResult Owned(ExprResult R) {
Douglas Gregorf8298252009-01-26 22:44:13 +0000259 if (R.isInvalid())
Steve Naroffd5129562009-01-21 22:32:33 +0000260 return ExprError();
Douglas Gregorf8298252009-01-26 22:44:13 +0000261 return OwningExprResult(*this, R.get());
Sebastian Redlc215cfc2009-01-19 00:08:26 +0000262 }
Sebastian Redlc675bab2008-12-13 16:23:55 +0000263 OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
264
Chris Lattnerf4404402008-08-23 03:19:52 +0000265 virtual void ActOnEndOfTranslationUnit();
Sebastian Redlb5d49352009-01-19 22:31:54 +0000266
Chris Lattner7cee11f2006-11-03 06:42:29 +0000267 //===--------------------------------------------------------------------===//
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000268 // Type Analysis / Processing: SemaType.cpp.
269 //
Chris Lattner4b413ea2008-06-26 06:27:57 +0000270 QualType ConvertDeclSpecToType(const DeclSpec &DS);
Chris Lattnera7e619c2008-06-29 00:50:08 +0000271 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Douglas Gregor17c0d7b2009-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 Gregor6eaaf302009-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 Redl351bb782008-12-02 14:43:59 +0000283 QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0);
Douglas Gregor92751d42008-11-17 22:58:34 +0000284 DeclarationName GetNameForDeclarator(Declarator &D);
285
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000286 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahanian56ff1462007-11-08 23:49:49 +0000287
Douglas Gregore1eb9d82008-10-22 14:17:15 +0000288 bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
289
Sebastian Redl351bb782008-12-02 14:43:59 +0000290 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Sebastian Redl842ef522008-11-08 13:00:26 +0000291
Douglas Gregored0cfbd2009-03-09 16:13:40 +0000292 bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned diag,
Douglas Gregordd430f72009-01-19 19:26:10 +0000293 SourceRange Range1 = SourceRange(),
294 SourceRange Range2 = SourceRange(),
295 QualType PrintType = QualType());
296
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000297 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000298 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000299 //
Chris Lattner03b53942009-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 Gregor9817f4a2009-02-09 15:09:02 +0000305 virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Douglas Gregor8a6be5e2009-02-04 17:00:24 +0000306 Scope *S, const CXXScopeSpec *SS);
Chris Lattner4bf74fd2009-02-15 22:43:40 +0000307 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){
Douglas Gregorad590502008-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 Gregor5a80bd12009-03-02 00:19:53 +0000312 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl,
313 Scope *S);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000314 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
315 QualType R, Decl* LastDeclarator,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000316 Decl* PrevDecl, bool& InvalidDecl,
317 bool &Redeclaration);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000318 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000319 QualType R, Decl* LastDeclarator,
Douglas Gregor5d68a202009-02-24 19:23:27 +0000320 NamedDecl* PrevDecl, bool& InvalidDecl,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000321 bool &Redeclaration);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000322 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
323 QualType R, Decl *LastDeclarator,
Douglas Gregore62c0a42009-02-24 01:23:02 +0000324 NamedDecl* PrevDecl,
325 bool IsFunctionDefinition,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000326 bool& InvalidDecl, bool &Redeclaration);
Chris Lattneraa9c7ae2008-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 Gregor58354032008-12-24 00:01:03 +0000331 virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
332 SourceLocation EqualLoc);
Douglas Gregor4d87df52008-12-16 21:30:33 +0000333 virtual void ActOnParamDefaultArgumentError(DeclTy *param);
Douglas Gregor5fb53972009-01-14 15:45:31 +0000334 virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
335 void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit);
Douglas Gregor8e1cf602008-10-29 00:13:59 +0000336 void ActOnUninitializedDecl(DeclTy *dcl);
Chris Lattner776fac82007-06-09 00:53:06 +0000337 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
338
Douglas Gregor9aa89042009-01-23 16:23:13 +0000339 virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D);
Chris Lattnera55a2cc2007-10-09 17:14:05 +0000340 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000341 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Steve Naroff70f41d62009-02-28 16:59:13 +0000342 virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D);
Sebastian Redlb5d49352009-01-19 22:31:54 +0000343
Sebastian Redlc675bab2008-12-13 16:23:55 +0000344 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
Sebastian Redlc675bab2008-12-13 16:23:55 +0000345 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlsson5c6c0592008-02-08 00:33:21 +0000346
Steve Naroffc62adb62007-10-09 22:01:59 +0000347 /// Scope actions.
348 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
349 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Chris Lattner01564d92007-01-27 19:27:06 +0000350
Chris Lattner200bdc32006-11-19 02:43:37 +0000351 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
352 /// no declarator (e.g. "struct foo;") is parsed.
Sebastian Redla2b5e312008-12-28 15:28:59 +0000353 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Chris Lattner200bdc32006-11-19 02:43:37 +0000354
Douglas Gregor9ac7a072009-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 Gregordee1be82009-01-17 00:42:38 +0000360 virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
Argyrios Kyrtzidis32a03792008-11-08 16:45:02 +0000361 SourceLocation KWLoc, const CXXScopeSpec &SS,
362 IdentifierInfo *Name, SourceLocation NameLoc,
Douglas Gregorcd72ba92009-02-06 22:42:48 +0000363 AttributeList *Attr);
Ted Kremenek21475702008-09-05 17:16:31 +0000364
Douglas Gregor91f84212008-12-11 16:49:14 +0000365 virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner2cc35ae2008-08-23 02:00:52 +0000366 IdentifierInfo *ClassName,
367 llvm::SmallVectorImpl<DeclTy*> &Decls);
Douglas Gregor91f84212008-12-11 16:49:14 +0000368 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner1300fb92007-01-23 23:42:53 +0000369 Declarator &D, ExprTy *BitfieldWidth);
Chris Lattner73bf7b42009-03-05 22:45:59 +0000370
371 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
372 Declarator &D, Expr *BitfieldWidth);
373
Douglas Gregor1efa4372009-03-11 18:59:21 +0000374 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
375 RecordDecl *Record, SourceLocation Loc,
376 bool Mutable, Expr *BitfieldWidth,
377 NamedDecl *PrevDecl,
378 Declarator *D = 0);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000379
380 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
381 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian96376742008-04-11 16:55:42 +0000382 tok::ObjCKeywordKind visibility);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000383
Steve Naroff2e688fd2007-09-14 23:09:53 +0000384 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian343f7092007-09-29 00:54:24 +0000385 virtual void ActOnFields(Scope* S,
Steve Naroff33a1e802007-10-29 21:38:07 +0000386 SourceLocation RecLoc, DeclTy *TagDecl,
387 DeclTy **Fields, unsigned NumFields,
Daniel Dunbar15619c72008-10-03 02:03:53 +0000388 SourceLocation LBrac, SourceLocation RBrac,
389 AttributeList *AttrList);
Douglas Gregor82ac25e2009-01-08 20:45:30 +0000390
391 /// ActOnTagStartDefinition - Invoked when we have entered the
392 /// scope of a tag's definition (e.g., for an enumeration, class,
393 /// struct, or union).
394 virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl);
395
396 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
397 /// the definition of a tag (enumeration, class, struct, or union).
398 virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl);
399
Steve Naroff30d242c2007-09-15 18:49:24 +0000400 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4ef40012007-06-11 01:28:17 +0000401 DeclTy *LastEnumConstant,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000402 SourceLocation IdLoc, IdentifierInfo *Id,
403 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff30d242c2007-09-15 18:49:24 +0000404 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000405 DeclTy **Elements, unsigned NumElements);
Sebastian Redl842ef522008-11-08 13:00:26 +0000406
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +0000407 DeclContext *getContainingDC(DeclContext *DC);
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000408
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000409 /// Set the current declaration context until it gets popped.
Douglas Gregor91f84212008-12-11 16:49:14 +0000410 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattner0a5ff0d2008-04-06 04:47:34 +0000411 void PopDeclContext();
Argyrios Kyrtzidis853fbea2008-06-28 06:07:14 +0000412
Chris Lattner79413952008-12-04 23:50:19 +0000413 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
414 /// to the function decl for the function being parsed. If we're currently
415 /// in a 'block', this returns the containing context.
416 FunctionDecl *getCurFunctionDecl();
417
418 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
419 /// the method decl for the method being parsed. If we're currently
420 /// in a 'block', this returns the containing context.
Daniel Dunbar6e8aa532008-08-11 05:35:13 +0000421 ObjCMethodDecl *getCurMethodDecl();
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000422
Chris Lattner79413952008-12-04 23:50:19 +0000423 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
424 /// or C function we're in, otherwise return null. If we're currently
425 /// in a 'block', this returns the containing context.
426 NamedDecl *getCurFunctionOrMethodDecl();
427
Argyrios Kyrtzidisb8a49202008-04-12 00:47:19 +0000428 /// Add this decl to the scope shadowed decl chains.
429 void PushOnScopeChains(NamedDecl *D, Scope *S);
430
Argyrios Kyrtzidis5b144d52008-09-09 21:18:04 +0000431 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
432 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
433 /// true if 'D' belongs to the given declaration context.
434 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
Douglas Gregor91f84212008-12-11 16:49:14 +0000435 return IdResolver.isDeclInScope(D, Ctx, Context, S);
Argyrios Kyrtzidis5b144d52008-09-09 21:18:04 +0000436 }
437
Eli Friedmanf69d09b2009-02-28 05:41:13 +0000438
439 void RecursiveCalcJumpScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
440 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
441 llvm::DenseMap<Stmt*, void*>& GotoScopeMap,
442 std::vector<void*>& ScopeStack,
443 Stmt* CurStmt);
444
445 void RecursiveCalcLabelScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
446 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
447 std::vector<void*>& ScopeStack,
448 Stmt* CurStmt,
449 Stmt* ParentCompoundStmt);
450
Chris Lattnerefedd9e2008-02-21 01:07:18 +0000451 /// Subroutines of ActOnDeclarator().
Chris Lattner07b201d2007-11-14 06:34:38 +0000452 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000453 Decl *LastDecl);
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000454 bool MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
455 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
Douglas Gregore62c0a42009-02-24 01:23:02 +0000456 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000457 bool MergeVarDecl(VarDecl *New, Decl *Old);
458 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000459
460 /// C++ Overloading.
461 bool IsOverload(FunctionDecl *New, Decl* OldD,
462 OverloadedFunctionDecl::function_iterator &MatchedDecl);
Douglas Gregor2fe98832008-11-03 19:09:14 +0000463 ImplicitConversionSequence
464 TryImplicitConversion(Expr* From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000465 bool SuppressUserConversions = false,
466 bool AllowExplicit = false);
Douglas Gregor26bee0b2008-10-31 16:23:19 +0000467 bool IsStandardConversion(Expr *From, QualType ToType,
468 StandardConversionSequence& SCS);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000469 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
470 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
Douglas Gregor78ca74d2009-02-12 00:15:05 +0000471 bool IsComplexPromotion(QualType FromType, QualType ToType);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000472 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregor47d3f272008-12-19 17:40:08 +0000473 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregora119f102008-12-19 19:13:09 +0000474 bool isObjCPointerConversion(QualType FromType, QualType ToType,
475 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregor39c16d42008-10-24 04:54:22 +0000476 bool CheckPointerConversion(Expr *From, QualType ToType);
Sebastian Redl72b597d2009-01-25 19:43:20 +0000477 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
478 QualType &ConvertedType);
479 bool CheckMemberPointerConversion(Expr *From, QualType ToType);
Douglas Gregor9a657932008-10-21 23:43:52 +0000480 bool IsQualificationConversion(QualType FromType, QualType ToType);
Douglas Gregor26bee0b2008-10-31 16:23:19 +0000481 bool IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000482 UserDefinedConversionSequence& User,
Douglas Gregor576e98c2009-01-30 23:27:23 +0000483 bool AllowConversionFunctions,
484 bool AllowExplicit);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000485
486 ImplicitConversionSequence::CompareKind
487 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
488 const ImplicitConversionSequence& ICS2);
489
490 ImplicitConversionSequence::CompareKind
491 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
492 const StandardConversionSequence& SCS2);
493
Douglas Gregore1eb9d82008-10-22 14:17:15 +0000494 ImplicitConversionSequence::CompareKind
495 CompareQualificationConversions(const StandardConversionSequence& SCS1,
496 const StandardConversionSequence& SCS2);
497
Douglas Gregor5c407d92008-10-23 00:40:37 +0000498 ImplicitConversionSequence::CompareKind
499 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
500 const StandardConversionSequence& SCS2);
501
Douglas Gregor2fe98832008-11-03 19:09:14 +0000502 ImplicitConversionSequence
503 TryCopyInitialization(Expr* From, QualType ToType,
504 bool SuppressUserConversions = false);
Douglas Gregor8e1cf602008-10-29 00:13:59 +0000505 bool PerformCopyInitialization(Expr *&From, QualType ToType,
506 const char *Flavor);
507
Douglas Gregor436424c2008-11-18 23:14:02 +0000508 ImplicitConversionSequence
509 TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method);
510 bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method);
511
Douglas Gregor5fb53972009-01-14 15:45:31 +0000512 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
513 bool PerformContextuallyConvertToBool(Expr *&From);
514
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000515 /// OverloadingResult - Capture the result of performing overload
516 /// resolution.
517 enum OverloadingResult {
518 OR_Success, ///< Overload resolution succeeded.
519 OR_No_Viable_Function, ///< No viable function found.
Douglas Gregor171c45a2009-02-18 21:56:37 +0000520 OR_Ambiguous, ///< Ambiguous candidates found.
521 OR_Deleted ///< Overload resoltuion refers to a deleted function.
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000522 };
523
524 void AddOverloadCandidate(FunctionDecl *Function,
525 Expr **Args, unsigned NumArgs,
Douglas Gregor2fe98832008-11-03 19:09:14 +0000526 OverloadCandidateSet& CandidateSet,
527 bool SuppressUserConversions = false);
Douglas Gregor436424c2008-11-18 23:14:02 +0000528 void AddMethodCandidate(CXXMethodDecl *Method,
529 Expr *Object, Expr **Args, unsigned NumArgs,
530 OverloadCandidateSet& CandidateSet,
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000531 bool SuppressUserConversions = false);
Douglas Gregora1f013e2008-11-07 22:36:19 +0000532 void AddConversionCandidate(CXXConversionDecl *Conversion,
533 Expr *From, QualType ToType,
534 OverloadCandidateSet& CandidateSet);
Douglas Gregorab7897a2008-11-19 22:57:39 +0000535 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
Douglas Gregordeaad8c2009-02-26 23:50:07 +0000536 const FunctionProtoType *Proto,
Douglas Gregorab7897a2008-11-19 22:57:39 +0000537 Expr *Object, Expr **Args, unsigned NumArgs,
538 OverloadCandidateSet& CandidateSet);
Douglas Gregor94eabf32009-02-04 16:44:47 +0000539 bool AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
540 SourceLocation OpLoc,
Douglas Gregor436424c2008-11-18 23:14:02 +0000541 Expr **Args, unsigned NumArgs,
Douglas Gregor94eabf32009-02-04 16:44:47 +0000542 OverloadCandidateSet& CandidateSet,
543 SourceRange OpRange = SourceRange());
Douglas Gregora11693b2008-11-12 17:17:38 +0000544 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
545 Expr **Args, unsigned NumArgs,
Douglas Gregorc5e61072009-01-13 00:52:54 +0000546 OverloadCandidateSet& CandidateSet,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000547 bool IsAssignmentOperator = false,
548 unsigned NumContextualBoolArguments = 0);
Douglas Gregord08452f2008-11-19 15:42:04 +0000549 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
550 Expr **Args, unsigned NumArgs,
551 OverloadCandidateSet& CandidateSet);
Douglas Gregore254f902009-02-04 00:32:51 +0000552 void AddArgumentDependentLookupCandidates(DeclarationName Name,
553 Expr **Args, unsigned NumArgs,
554 OverloadCandidateSet& CandidateSet);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000555 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
556 const OverloadCandidate& Cand2);
557 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
558 OverloadCandidateSet::iterator& Best);
559 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
560 bool OnlyViable);
561
Douglas Gregorcd695e52008-11-10 20:40:00 +0000562 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
563 bool Complain);
564 void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
565
Douglas Gregorb8a9a412009-02-04 15:01:18 +0000566 FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee,
567 DeclarationName UnqualifiedName,
Douglas Gregora60a6912008-11-26 06:01:48 +0000568 SourceLocation LParenLoc,
569 Expr **Args, unsigned NumArgs,
570 SourceLocation *CommaLocs,
Douglas Gregore254f902009-02-04 00:32:51 +0000571 SourceLocation RParenLoc,
Douglas Gregorb8a9a412009-02-04 15:01:18 +0000572 bool &ArgumentDependentLookup);
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000573 ExprResult
574 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
575 SourceLocation LParenLoc, Expr **Args,
576 unsigned NumArgs, SourceLocation *CommaLocs,
577 SourceLocation RParenLoc);
Douglas Gregor91cea0a2008-11-19 21:05:33 +0000578 ExprResult
Douglas Gregorb0846b02008-12-06 00:22:45 +0000579 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregor91cea0a2008-11-19 21:05:33 +0000580 Expr **Args, unsigned NumArgs,
581 SourceLocation *CommaLocs,
582 SourceLocation RParenLoc);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000583
Douglas Gregor55297ac2008-12-23 00:26:44 +0000584 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
Douglas Gregore0e79bd2008-11-20 16:27:02 +0000585 SourceLocation MemberLoc,
586 IdentifierInfo &Member);
Douglas Gregor5fb53972009-01-14 15:45:31 +0000587
Chris Lattnerce1da2c2009-01-06 07:27:21 +0000588 /// Helpers for dealing with function parameters.
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000589 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000590 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregorcaa8ace2008-05-07 04:49:29 +0000591 void CheckExtraCXXDefaultArguments(Declarator &D);
Steve Naroff6fbf0dc2007-03-16 00:33:25 +0000592
Douglas Gregor45a33ec2009-01-12 18:45:55 +0000593 Scope *getNonFieldDeclScope(Scope *S);
594
Douglas Gregor34074322009-01-14 22:20:51 +0000595 /// \name Name lookup
596 ///
597 /// These routines provide name lookup that is used during semantic
598 /// analysis to resolve the various kinds of names (identifiers,
599 /// overloaded operator names, constructor names, etc.) into zero or
600 /// more declarations within a particular scope. The major entry
601 /// points are LookupName, which performs unqualified name lookup,
602 /// and LookupQualifiedName, which performs qualified name lookup.
603 ///
604 /// All name lookup is performed based on some specific criteria,
605 /// which specify what names will be visible to name lookup and how
606 /// far name lookup should work. These criteria are important both
607 /// for capturing language semantics (certain lookups will ignore
608 /// certain names, for example) and for performance, since name
609 /// lookup is often a bottleneck in the compilation of C++. Name
Douglas Gregored8f2882009-01-30 01:04:22 +0000610 /// lookup criteria is specified via the LookupCriteria enumeration.
Douglas Gregor34074322009-01-14 22:20:51 +0000611 ///
612 /// The results of name lookup can vary based on the kind of name
613 /// lookup performed, the current language, and the translation
614 /// unit. In C, for example, name lookup will either return nothing
615 /// (no entity found) or a single declaration. In C++, name lookup
616 /// can additionally refer to a set of overloaded functions or
617 /// result in an ambiguity. All of the possible results of name
618 /// lookup are captured by the LookupResult class, which provides
619 /// the ability to distinguish among them.
620 //@{
Douglas Gregord7c4d982008-12-30 03:27:21 +0000621
Douglas Gregored8f2882009-01-30 01:04:22 +0000622 /// @brief Describes the kind of name lookup to perform.
623 enum LookupNameKind {
624 /// Ordinary name lookup, which finds ordinary names (functions,
625 /// variables, typedefs, etc.) in C and most kinds of names
626 /// (functions, variables, members, types, etc.) in C++.
627 LookupOrdinaryName = 0,
628 /// Tag name lookup, which finds the names of enums, classes,
629 /// structs, and unions.
630 LookupTagName,
631 /// Member name lookup, which finds the names of
632 /// class/struct/union members.
633 LookupMemberName,
Douglas Gregor94eabf32009-02-04 16:44:47 +0000634 // Look up of an operator name (e.g., operator+) for use with
635 // operator overloading. This lookup is similar to ordinary name
636 // lookup, but will ignore any declarations that are class
637 // members.
638 LookupOperatorName,
Douglas Gregored8f2882009-01-30 01:04:22 +0000639 /// Look up of a name that precedes the '::' scope resolution
640 /// operator in C++. This lookup completely ignores operator,
641 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
642 LookupNestedNameSpecifierName,
643 /// Look up a namespace name within a C++ using directive or
644 /// namespace alias definition, ignoring non-namespace names (C++
645 /// [basic.lookup.udir]p1).
Douglas Gregoreddf4332009-02-24 20:03:32 +0000646 LookupNamespaceName,
647 // Look up an ordinary name that is going to be redeclared as a
648 // name with linkage. This lookup ignores any declarations that
649 // are outside of the current scope unless they have linkage. See
650 // C99 6.2.2p4-5 and C++ [basic.link]p6.
651 LookupRedeclarationWithLinkage
Douglas Gregor34074322009-01-14 22:20:51 +0000652 };
653
654 /// @brief Represents the results of name lookup.
655 ///
656 /// An instance of the LookupResult class captures the results of a
657 /// single name lookup, which can return no result (nothing found),
658 /// a single declaration, a set of overloaded functions, or an
659 /// ambiguity. Use the getKind() method to determine which of these
660 /// results occurred for a given lookup.
661 ///
662 /// Any non-ambiguous lookup can be converted into a single
Douglas Gregor2ada0482009-02-04 17:27:36 +0000663 /// (possibly NULL) @c NamedDecl* via a conversion function or the
Douglas Gregor34074322009-01-14 22:20:51 +0000664 /// getAsDecl() method. This conversion permits the common-case
665 /// usage in C and Objective-C where name lookup will always return
666 /// a single declaration.
Douglas Gregorf23311d2009-01-17 01:13:24 +0000667 struct LookupResult {
Douglas Gregor34074322009-01-14 22:20:51 +0000668 /// The kind of entity that is actually stored within the
669 /// LookupResult object.
Douglas Gregorf23311d2009-01-17 01:13:24 +0000670 enum {
Douglas Gregor2ada0482009-02-04 17:27:36 +0000671 /// First is a single declaration (a NamedDecl*), which may be NULL.
Douglas Gregor34074322009-01-14 22:20:51 +0000672 SingleDecl,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000673
Douglas Gregor889ceb72009-02-03 19:21:40 +0000674 /// First is a single declaration (an OverloadedFunctionDecl*).
675 OverloadedDeclSingleDecl,
676
Douglas Gregor34074322009-01-14 22:20:51 +0000677 /// [First, Last) is an iterator range represented as opaque
678 /// pointers used to reconstruct IdentifierResolver::iterators.
679 OverloadedDeclFromIdResolver,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000680
Douglas Gregor34074322009-01-14 22:20:51 +0000681 /// [First, Last) is an iterator range represented as opaque
682 /// pointers used to reconstruct DeclContext::lookup_iterators.
683 OverloadedDeclFromDeclContext,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000684
685 /// First is a pointer to a BasePaths structure, which is owned
686 /// by the LookupResult. Last is non-zero to indicate that the
687 /// ambiguity is caused by two names found in base class
688 /// subobjects of different types.
Douglas Gregor889ceb72009-02-03 19:21:40 +0000689 AmbiguousLookupStoresBasePaths,
690
691 /// [First, Last) is an iterator range represented as opaque
692 /// pointers used to reconstruct new'ed Decl*[] array containing
693 /// found ambiguous decls. LookupResult is owner of this array.
694 AmbiguousLookupStoresDecls
695
Douglas Gregor34074322009-01-14 22:20:51 +0000696 } StoredKind;
697
698 /// The first lookup result, whose contents depend on the kind of
Douglas Gregor2ada0482009-02-04 17:27:36 +0000699 /// lookup result. This may be a NamedDecl* (if StoredKind ==
700 /// SingleDecl), OverloadedFunctionDecl* (if StoredKind ==
701 /// OverloadedDeclSingleDecl), the opaque pointer from an
Douglas Gregor34074322009-01-14 22:20:51 +0000702 /// IdentifierResolver::iterator (if StoredKind ==
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000703 /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator
704 /// (if StoredKind == OverloadedDeclFromDeclContext), or a
Douglas Gregor889ceb72009-02-03 19:21:40 +0000705 /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor34074322009-01-14 22:20:51 +0000706 mutable uintptr_t First;
707
708 /// The last lookup result, whose contents depend on the kind of
709 /// lookup result. This may be unused (if StoredKind ==
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000710 /// SingleDecl), it may have the same type as First (for
711 /// overloaded function declarations), or is may be used as a
Douglas Gregor889ceb72009-02-03 19:21:40 +0000712 /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor34074322009-01-14 22:20:51 +0000713 mutable uintptr_t Last;
714
715 /// Context - The context in which we will build any
716 /// OverloadedFunctionDecl nodes needed by the conversion to
717 /// Decl*.
718 ASTContext *Context;
719
Douglas Gregor34074322009-01-14 22:20:51 +0000720 /// @brief The kind of entity found by name lookup.
721 enum LookupKind {
722 /// @brief No entity found met the criteria.
723 NotFound = 0,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000724
Douglas Gregor34074322009-01-14 22:20:51 +0000725 /// @brief Name lookup found a single declaration that met the
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000726 /// criteria. getAsDecl will return this declaration.
Douglas Gregor34074322009-01-14 22:20:51 +0000727 Found,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000728
Douglas Gregor34074322009-01-14 22:20:51 +0000729 /// @brief Name lookup found a set of overloaded functions that
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000730 /// met the criteria. getAsDecl will turn this set of overloaded
731 /// functions into an OverloadedFunctionDecl.
Douglas Gregor34074322009-01-14 22:20:51 +0000732 FoundOverloaded,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000733
734 /// Name lookup results in an ambiguity because multiple
735 /// entities that meet the lookup criteria were found in
736 /// subobjects of different types. For example:
737 /// @code
738 /// struct A { void f(int); }
739 /// struct B { void f(double); }
740 /// struct C : A, B { };
741 /// void test(C c) {
742 /// c.f(0); // error: A::f and B::f come from subobjects of different
743 /// // types. overload resolution is not performed.
744 /// }
745 /// @endcode
746 AmbiguousBaseSubobjectTypes,
747
748 /// Name lookup results in an ambiguity because multiple
749 /// nonstatic entities that meet the lookup criteria were found
750 /// in different subobjects of the same type. For example:
751 /// @code
752 /// struct A { int x; };
753 /// struct B : A { };
754 /// struct C : A { };
755 /// struct D : B, C { };
756 /// int test(D d) {
757 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
758 /// }
759 /// @endcode
Douglas Gregor889ceb72009-02-03 19:21:40 +0000760 AmbiguousBaseSubobjects,
761
762 /// Name lookup results in an ambiguity because multiple definitions
763 /// of entity that meet the lookup criteria were found in different
764 /// declaration contexts.
765 /// @code
766 /// namespace A {
767 /// int i;
768 /// namespace B { int i; }
769 /// int test() {
770 /// using namespace B;
771 /// return i; // error 'i' is found in namespace A and A::B
772 /// }
773 /// }
774 /// @endcode
775 AmbiguousReference
Douglas Gregor34074322009-01-14 22:20:51 +0000776 };
777
Douglas Gregor2ada0482009-02-04 17:27:36 +0000778 static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D);
Douglas Gregor41c8ba82009-01-15 02:19:31 +0000779
Douglas Gregorf23311d2009-01-17 01:13:24 +0000780 static LookupResult CreateLookupResult(ASTContext &Context,
781 IdentifierResolver::iterator F,
782 IdentifierResolver::iterator L);
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000783
Douglas Gregorf23311d2009-01-17 01:13:24 +0000784 static LookupResult CreateLookupResult(ASTContext &Context,
785 DeclContext::lookup_iterator F,
786 DeclContext::lookup_iterator L);
Douglas Gregor34074322009-01-14 22:20:51 +0000787
Douglas Gregorf23311d2009-01-17 01:13:24 +0000788 static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths,
789 bool DifferentSubobjectTypes) {
790 LookupResult Result;
Douglas Gregor889ceb72009-02-03 19:21:40 +0000791 Result.StoredKind = AmbiguousLookupStoresBasePaths;
Douglas Gregorf23311d2009-01-17 01:13:24 +0000792 Result.First = reinterpret_cast<uintptr_t>(Paths);
793 Result.Last = DifferentSubobjectTypes? 1 : 0;
794 Result.Context = &Context;
795 return Result;
796 }
Douglas Gregor41c8ba82009-01-15 02:19:31 +0000797
Douglas Gregor889ceb72009-02-03 19:21:40 +0000798 template <typename Iterator>
799 static LookupResult CreateLookupResult(ASTContext &Context,
800 Iterator B, std::size_t Len) {
Douglas Gregor2ada0482009-02-04 17:27:36 +0000801 NamedDecl ** Array = new NamedDecl*[Len];
Douglas Gregor889ceb72009-02-03 19:21:40 +0000802 for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B)
803 Array[Idx] = *B;
804 LookupResult Result;
805 Result.StoredKind = AmbiguousLookupStoresDecls;
806 Result.First = reinterpret_cast<uintptr_t>(Array);
807 Result.Last = reinterpret_cast<uintptr_t>(Array + Len);
808 Result.Context = &Context;
809 return Result;
810 }
811
Douglas Gregor34074322009-01-14 22:20:51 +0000812 LookupKind getKind() const;
813
814 /// @brief Determine whether name look found something.
815 operator bool() const { return getKind() != NotFound; }
816
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000817 /// @brief Determines whether the lookup resulted in an ambiguity.
Douglas Gregor889ceb72009-02-03 19:21:40 +0000818 bool isAmbiguous() const {
819 return StoredKind == AmbiguousLookupStoresBasePaths ||
820 StoredKind == AmbiguousLookupStoresDecls;
821 }
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000822
Douglas Gregor34074322009-01-14 22:20:51 +0000823 /// @brief Allows conversion of a lookup result into a
824 /// declaration, with the same behavior as getAsDecl.
Douglas Gregor2ada0482009-02-04 17:27:36 +0000825 operator NamedDecl*() const { return getAsDecl(); }
Douglas Gregor34074322009-01-14 22:20:51 +0000826
Douglas Gregor2ada0482009-02-04 17:27:36 +0000827 NamedDecl* getAsDecl() const;
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000828
829 BasePaths *getBasePaths() const;
Douglas Gregor0e8fc3c2009-02-02 21:35:47 +0000830
831 /// \brief Iterate over the results of name lookup.
832 ///
833 /// The @c iterator class provides iteration over the results of a
834 /// non-ambiguous name lookup.
835 class iterator {
836 /// The LookupResult structure we're iterating through.
837 LookupResult *Result;
838
839 /// The current position of this iterator within the sequence of
840 /// results. This value will have the same representation as the
841 /// @c First field in the LookupResult structure.
842 mutable uintptr_t Current;
843
844 public:
Douglas Gregor2ada0482009-02-04 17:27:36 +0000845 typedef NamedDecl * value_type;
846 typedef NamedDecl * reference;
847 typedef NamedDecl * pointer;
Douglas Gregor0e8fc3c2009-02-02 21:35:47 +0000848 typedef std::ptrdiff_t difference_type;
849 typedef std::forward_iterator_tag iterator_category;
850
851 iterator() : Result(0), Current(0) { }
852
853 iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { }
854
855 reference operator*() const;
856
857 pointer operator->() const { return **this; }
858
859 iterator &operator++();
860
861 iterator operator++(int) {
862 iterator tmp(*this);
863 ++(*this);
864 return tmp;
865 }
866
867 friend inline bool operator==(iterator const& x, iterator const& y) {
868 return x.Current == y.Current;
869 }
870
871 friend inline bool operator!=(iterator const& x, iterator const& y) {
872 return x.Current != y.Current;
873 }
874 };
875 friend class iterator;
876
877 iterator begin();
878 iterator end();
Douglas Gregor34074322009-01-14 22:20:51 +0000879 };
880
Douglas Gregor889ceb72009-02-03 19:21:40 +0000881private:
882 typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy;
883
884 std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name,
885 LookupNameKind NameKind,
886 bool RedeclarationOnly);
887
888public:
Douglas Gregored8f2882009-01-30 01:04:22 +0000889 /// Determines whether D is a suitable lookup result according to the
890 /// lookup criteria.
Douglas Gregoreddf4332009-02-24 20:03:32 +0000891 static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind,
Douglas Gregor700792c2009-02-05 19:25:20 +0000892 unsigned IDNS) {
Douglas Gregored8f2882009-01-30 01:04:22 +0000893 switch (NameKind) {
894 case Sema::LookupOrdinaryName:
895 case Sema::LookupTagName:
896 case Sema::LookupMemberName:
Douglas Gregoreddf4332009-02-24 20:03:32 +0000897 case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
Douglas Gregored8f2882009-01-30 01:04:22 +0000898 return D->isInIdentifierNamespace(IDNS);
899
Douglas Gregor94eabf32009-02-04 16:44:47 +0000900 case Sema::LookupOperatorName:
901 return D->isInIdentifierNamespace(IDNS) &&
902 !D->getDeclContext()->isRecord();
903
Douglas Gregored8f2882009-01-30 01:04:22 +0000904 case Sema::LookupNestedNameSpecifierName:
905 return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag);
906
907 case Sema::LookupNamespaceName:
908 return isa<NamespaceDecl>(D);
909 }
910
911 assert(false &&
Douglas Gregor700792c2009-02-05 19:25:20 +0000912 "isAcceptableLookupResult always returns before this point");
Douglas Gregored8f2882009-01-30 01:04:22 +0000913 return false;
914 }
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000915
Douglas Gregored8f2882009-01-30 01:04:22 +0000916 LookupResult LookupName(Scope *S, DeclarationName Name,
917 LookupNameKind NameKind,
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000918 bool RedeclarationOnly = false,
919 bool AllowBuiltinCreation = true,
920 SourceLocation Loc = SourceLocation());
Douglas Gregored8f2882009-01-30 01:04:22 +0000921 LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name,
922 LookupNameKind NameKind,
923 bool RedeclarationOnly = false);
924 LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS,
925 DeclarationName Name,
926 LookupNameKind NameKind,
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000927 bool RedeclarationOnly = false,
928 bool AllowBuiltinCreation = true,
929 SourceLocation Loc = SourceLocation());
Douglas Gregore254f902009-02-04 00:32:51 +0000930
931 typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet;
932 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
933
934 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
935 AssociatedNamespaceSet &AssociatedNamespaces,
936 AssociatedClassSet &AssociatedClasses);
937
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000938 bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
939 SourceLocation NameLoc,
940 SourceRange LookupRange = SourceRange());
Douglas Gregor34074322009-01-14 22:20:51 +0000941 //@}
942
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000943 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000944 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000945 Scope *S, bool ForRedeclaration,
946 SourceLocation Loc);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000947 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
948 Scope *S);
Douglas Gregore711f702009-02-14 18:57:46 +0000949 void AddKnownFunctionAttributes(FunctionDecl *FD);
Douglas Gregor34074322009-01-14 22:20:51 +0000950
951 // More parsing and symbol table subroutines.
952
Steve Naroffa8fd9732007-06-11 00:35:03 +0000953 // Decl attributes - this routine is the top level dispatcher.
Chris Lattner58418ff2008-06-29 00:16:31 +0000954 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnera5741542008-06-28 23:58:55 +0000955 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lamb025b5fb2008-02-04 02:31:56 +0000956
Steve Naroff15833ed2008-02-10 21:38:56 +0000957 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
958 bool &IncompleteImpl);
Fariborz Jahanian7988d7d2008-12-05 18:18:52 +0000959 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
960 ObjCMethodDecl *IntfMethod);
Sebastian Redlc4704762008-11-11 11:37:55 +0000961
962 NamespaceDecl *GetStdNamespace();
Fariborz Jahanian8e1555c2009-01-12 19:55:42 +0000963
964 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
Steve Naroffde680012009-02-26 19:11:32 +0000965 ObjCInterfaceDecl *IDecl);
Steve Naroff15833ed2008-02-10 21:38:56 +0000966
Chris Lattnerce1da2c2009-01-06 07:27:21 +0000967 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbarc7dfbfd2008-09-04 20:01:15 +0000968 /// methods declared in protocol, and those referenced by it.
969 /// \param IDecl - Used for checking for methods which may have been
970 /// inherited.
Steve Naroffa36992242008-02-08 22:06:17 +0000971 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
972 ObjCProtocolDecl *PDecl,
Fariborz Jahanianadf84f32007-10-02 20:06:01 +0000973 bool& IncompleteImpl,
Steve Naroff71c3c1c2007-10-08 21:05:34 +0000974 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbarc7dfbfd2008-09-04 20:01:15 +0000975 const llvm::DenseSet<Selector> &ClsMap,
976 ObjCInterfaceDecl *IDecl);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000977
Steve Naroffd1741552007-10-02 21:43:37 +0000978 /// CheckImplementationIvars - This routine checks if the instance variables
979 /// listed in the implelementation match those listed in the interface.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000980 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
981 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff15833ed2008-02-10 21:38:56 +0000982 SourceLocation Loc);
Steve Naroffd1741552007-10-02 21:43:37 +0000983
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000984 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
Chris Lattner9ef10f42009-03-01 00:56:52 +0000985 /// remains unimplemented in the class or category @implementation.
986 void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl,
987 ObjCContainerDecl* IDecl,
988 bool IncompleteImpl = false);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000989
Fariborz Jahanian458f7112007-10-05 18:00:57 +0000990 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
991 /// true, or false, accordingly.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000992 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Naroffa0ed1652008-10-21 10:37:50 +0000993 const ObjCMethodDecl *PrevMethod,
994 bool matchBasedOnSizeAndAlignment = false);
Steve Naroff7f549f12007-10-10 21:53:07 +0000995
Steve Naroff5811baf2007-10-14 00:58:41 +0000996 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
997 /// unit are added to a global pool. This allows us to efficiently associate
998 /// a selector with a method declaraation for purposes of typechecking
999 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001000 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff5811baf2007-10-14 00:58:41 +00001001
Steve Naroff4a82d812008-09-30 14:38:43 +00001002 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
1003 /// there are multiple signatures.
1004 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
1005
Steve Naroff5811baf2007-10-14 00:58:41 +00001006 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001007 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Chris Lattner7cee11f2006-11-03 06:42:29 +00001008 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +00001009 // Statement Parsing Callbacks: SemaStmt.cpp.
Steve Naroff3273c222007-03-14 21:52:03 +00001010public:
Sebastian Redl52f03ba2008-12-21 12:04:03 +00001011 virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
1012
1013 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
1014 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1015 MultiStmtArg Elts,
1016 bool isStmtExpr);
1017 virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
1018 SourceLocation EndLoc);
Sebastian Redl1cbb59182008-12-28 16:13:43 +00001019 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
1020 SourceLocation DotDotDotLoc, ExprArg RHSVal,
Chris Lattner34a22092009-03-04 04:23:07 +00001021 SourceLocation ColonLoc);
1022 virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt);
1023
Sebastian Redl1cbb59182008-12-28 16:13:43 +00001024 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1025 SourceLocation ColonLoc,
1026 StmtArg SubStmt, Scope *CurScope);
Sebastian Redl6a8002e2009-01-11 00:38:46 +00001027 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
1028 IdentifierInfo *II,
1029 SourceLocation ColonLoc,
1030 StmtArg SubStmt);
1031 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
1032 StmtArg ThenVal, SourceLocation ElseLoc,
1033 StmtArg ElseVal);
1034 virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
1035 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1036 StmtArg Switch, StmtArg Body);
Sebastian Redlfbfaafc2009-01-16 23:28:06 +00001037 virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
1038 StmtArg Body);
1039 virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
1040 SourceLocation WhileLoc, ExprArg Cond);
1041
1042 virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
1043 SourceLocation LParenLoc,
1044 StmtArg First, ExprArg Second,
1045 ExprArg Third, SourceLocation RParenLoc,
1046 StmtArg Body);
1047 virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1048 SourceLocation LParenLoc,
1049 StmtArg First, ExprArg Second,
1050 SourceLocation RParenLoc, StmtArg Body);
Sebastian Redl573feed2009-01-18 13:19:59 +00001051
1052 virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1053 SourceLocation LabelLoc,
1054 IdentifierInfo *LabelII);
1055 virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1056 SourceLocation StarLoc,
1057 ExprArg DestExp);
1058 virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
1059 Scope *CurScope);
1060 virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
1061 Scope *CurScope);
1062
1063 virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
1064 ExprArg RetValExp);
1065 OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
1066 Expr *RetValExp);
1067
Sebastian Redl24b8e152009-01-18 16:53:17 +00001068 virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1069 bool IsSimple,
1070 bool IsVolatile,
1071 unsigned NumOutputs,
1072 unsigned NumInputs,
1073 std::string *Names,
1074 MultiExprArg Constraints,
1075 MultiExprArg Exprs,
1076 ExprArg AsmString,
1077 MultiExprArg Clobbers,
1078 SourceLocation RParenLoc);
Sebastian Redl481bf3f2009-01-18 17:43:11 +00001079
1080 virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
1081 SourceLocation RParen,
Steve Naroff371b8fb2009-03-03 19:52:17 +00001082 DeclTy *Parm, StmtArg Body,
Sebastian Redl481bf3f2009-01-18 17:43:11 +00001083 StmtArg CatchList);
1084
1085 virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
1086 StmtArg Body);
1087
1088 virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
1089 StmtArg Try,
1090 StmtArg Catch, StmtArg Finally);
1091
1092 virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Steve Naroff5ee2c022009-02-11 20:05:44 +00001093 ExprArg Throw,
1094 Scope *CurScope);
Sebastian Redl481bf3f2009-01-18 17:43:11 +00001095 virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1096 ExprArg SynchExpr,
1097 StmtArg SynchBody);
Sebastian Redlb219c902008-12-21 16:41:36 +00001098
Sebastian Redl54c04d42008-12-22 19:15:10 +00001099 virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D);
1100 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
1101 DeclTy *ExDecl,
1102 StmtArg HandlerBlock);
Sebastian Redl9b244a82008-12-22 21:35:02 +00001103 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
1104 StmtArg TryBlock,
1105 MultiStmtArg Handlers);
Sebastian Redlb219c902008-12-21 16:41:36 +00001106
Chris Lattner7cee11f2006-11-03 06:42:29 +00001107 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +00001108 // Expression Parsing Callbacks: SemaExpr.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +00001109
Douglas Gregor171c45a2009-02-18 21:56:37 +00001110 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
Chris Lattner4bf74fd2009-02-15 22:43:40 +00001111
Chris Lattner7cee11f2006-11-03 06:42:29 +00001112 // Primary Expressions.
Douglas Gregor87f95b02009-02-26 21:00:50 +00001113 virtual SourceRange getExprRange(ExprTy *E) const;
1114
Sebastian Redlffbcf962009-01-18 18:53:16 +00001115 virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
1116 IdentifierInfo &II,
1117 bool HasTrailingLParen,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001118 const CXXScopeSpec *SS = 0,
1119 bool isAddressOfOperand = false);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001120 virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S,
Douglas Gregor7911b372008-11-19 19:09:45 +00001121 SourceLocation OperatorLoc,
1122 OverloadedOperatorKind Op,
1123 bool HasTrailingLParen,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001124 const CXXScopeSpec &SS,
1125 bool isAddressOfOperand);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001126 virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S,
Douglas Gregor7911b372008-11-19 19:09:45 +00001127 SourceLocation OperatorLoc,
1128 TypeTy *Ty,
1129 bool HasTrailingLParen,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001130 const CXXScopeSpec &SS,
1131 bool isAddressOfOperand);
Douglas Gregorc7acfdf2009-01-06 05:10:23 +00001132 DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
1133 bool TypeDependent, bool ValueDependent,
1134 const CXXScopeSpec *SS = 0);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001135 OwningExprResult
Douglas Gregor9ac7a072009-01-07 00:43:41 +00001136 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1137 FieldDecl *Field,
1138 Expr *BaseObjectExpr = 0,
1139 SourceLocation OpLoc = SourceLocation());
Sebastian Redlffbcf962009-01-18 18:53:16 +00001140 OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
1141 DeclarationName Name,
1142 bool HasTrailingLParen,
1143 const CXXScopeSpec *SS,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001144 bool isAddressOfOperand = false);
Douglas Gregor4ea80432008-11-18 15:03:34 +00001145
Sebastian Redlffbcf962009-01-18 18:53:16 +00001146 virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
1147 tok::TokenKind Kind);
1148 virtual OwningExprResult ActOnNumericConstant(const Token &);
1149 virtual OwningExprResult ActOnCharacterConstant(const Token &);
1150 virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
1151 ExprArg Val);
Chris Lattner697e5d62006-11-09 06:32:27 +00001152
Steve Naroff83895f72007-09-16 03:34:24 +00001153 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner697e5d62006-11-09 06:32:27 +00001154 /// fragments (e.g. "foo" "bar" L"baz").
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001155 virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
1156 unsigned NumToks);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001157
Chris Lattner7cee11f2006-11-03 06:42:29 +00001158 // Binary/Unary Operators. 'Tok' is the token for the operator.
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001159 virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1160 tok::TokenKind Op, ExprArg Input);
1161 virtual OwningExprResult
Sebastian Redl6f282892008-11-11 17:56:53 +00001162 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1163 void *TyOrEx, const SourceRange &ArgRange);
1164
Chris Lattner8dff0172009-01-24 20:17:12 +00001165 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R);
Sebastian Redl6f282892008-11-11 17:56:53 +00001166 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1167 const SourceRange &R, bool isSizeof);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001168
1169 virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1170 tok::TokenKind Kind,
1171 ExprArg Input);
1172
1173 virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
1174 SourceLocation LLoc,
1175 ExprArg Idx,
1176 SourceLocation RLoc);
1177 virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base,
1178 SourceLocation OpLoc,
1179 tok::TokenKind OpKind,
1180 SourceLocation MemberLoc,
Fariborz Jahanianb8d091c2009-03-04 22:30:12 +00001181 IdentifierInfo &Member,
1182 DeclTy *ImplDecl=0);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001183 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
Douglas Gregor97fd6e22008-12-22 05:46:06 +00001184 FunctionDecl *FDecl,
Douglas Gregordeaad8c2009-02-26 23:50:07 +00001185 const FunctionProtoType *Proto,
Douglas Gregor97fd6e22008-12-22 05:46:06 +00001186 Expr **Args, unsigned NumArgs,
1187 SourceLocation RParenLoc);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001188
Steve Naroff83895f72007-09-16 03:34:24 +00001189 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner7cee11f2006-11-03 06:42:29 +00001190 /// This provides the location of the left/right parens and a list of comma
1191 /// locations.
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001192 virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn,
1193 SourceLocation LParenLoc,
1194 MultiExprArg Args,
1195 SourceLocation *CommaLocs,
1196 SourceLocation RParenLoc);
1197
Sebastian Redlb5d49352009-01-19 22:31:54 +00001198 virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
1199 SourceLocation RParenLoc, ExprArg Op);
1200
1201 virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1202 TypeTy *Ty,
1203 SourceLocation RParenLoc,
1204 ExprArg Op);
1205
1206 virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
1207 MultiExprArg InitList,
1208 InitListDesignations &Designators,
1209 SourceLocation RParenLoc);
1210
Douglas Gregore4a0bb72009-01-22 00:58:24 +00001211 virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
1212 SourceLocation Loc,
1213 bool UsedColonSyntax,
1214 OwningExprResult Init);
1215
Sebastian Redlb5d49352009-01-19 22:31:54 +00001216 virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1217 tok::TokenKind Kind,
1218 ExprArg LHS, ExprArg RHS);
1219 OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1220 unsigned Opc, Expr *lhs, Expr *rhs);
Douglas Gregor7d5fc7e2008-11-06 23:29:22 +00001221
Steve Naroff83895f72007-09-16 03:34:24 +00001222 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner7cee11f2006-11-03 06:42:29 +00001223 /// in the case of a the GNU conditional expr extension.
Sebastian Redlb5d49352009-01-19 22:31:54 +00001224 virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1225 SourceLocation ColonLoc,
1226 ExprArg Cond, ExprArg LHS,
1227 ExprArg RHS);
Chris Lattner29375652006-12-04 18:06:35 +00001228
Steve Naroff66356bd2007-09-16 14:56:35 +00001229 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1230 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Chris Lattnereefa10e2007-05-28 06:56:27 +00001231 IdentifierInfo *LabelII);
1232
Steve Naroff66356bd2007-09-16 14:56:35 +00001233 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattner366727f2007-07-24 16:58:17 +00001234 SourceLocation RPLoc); // "({..})"
Chris Lattnerf17bd422007-08-30 17:45:32 +00001235
1236 /// __builtin_offsetof(type, a.b[123][456].c)
Douglas Gregor55297ac2008-12-23 00:26:44 +00001237 virtual ExprResult ActOnBuiltinOffsetOf(Scope *S,
1238 SourceLocation BuiltinLoc,
Chris Lattnerf17bd422007-08-30 17:45:32 +00001239 SourceLocation TypeLoc, TypeTy *Arg1,
1240 OffsetOfComponent *CompPtr,
1241 unsigned NumComponents,
1242 SourceLocation RParenLoc);
1243
Steve Naroff78864672007-08-01 22:05:33 +00001244 // __builtin_types_compatible_p(type1, type2)
Steve Naroff66356bd2007-09-16 14:56:35 +00001245 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff78864672007-08-01 22:05:33 +00001246 TypeTy *arg1, TypeTy *arg2,
1247 SourceLocation RPLoc);
Steve Naroff9efdabc2007-08-03 21:21:27 +00001248
1249 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff66356bd2007-09-16 14:56:35 +00001250 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroff9efdabc2007-08-03 21:21:27 +00001251 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
1252 SourceLocation RPLoc);
Chris Lattner366727f2007-07-24 16:58:17 +00001253
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001254 // __builtin_va_arg(expr, type)
1255 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1256 ExprTy *expr, TypeTy *type,
1257 SourceLocation RPLoc);
Steve Naroffc540d662008-09-03 18:15:37 +00001258
Douglas Gregor3be4b122008-11-29 04:51:27 +00001259 // __null
1260 virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1261
Steve Naroffc540d662008-09-03 18:15:37 +00001262 //===------------------------- "Block" Extension ------------------------===//
1263
1264 /// ActOnBlockStart - This callback is invoked when a block literal is
1265 /// started.
Steve Naroff1d95e5a2008-10-10 01:28:17 +00001266 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1267
1268 /// ActOnBlockArguments - This callback allows processing of block arguments.
1269 /// If there are no arguments, this is still invoked.
Mike Stump82f071f2009-02-04 22:31:32 +00001270 virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
Steve Naroffc540d662008-09-03 18:15:37 +00001271
1272 /// ActOnBlockError - If there is an error parsing a block, this callback
1273 /// is invoked to pop the information about the block from the action impl.
1274 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1275
1276 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1277 /// literal was successfully completed. ^(int x){...}
1278 virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
1279 Scope *CurScope);
1280
Chris Lattner4bf74fd2009-02-15 22:43:40 +00001281 //===---------------------------- C++ Features --------------------------===//
1282
Argyrios Kyrtzidis08114892008-04-27 13:50:30 +00001283 // Act on C++ namespaces
1284 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
1285 IdentifierInfo *Ident,
1286 SourceLocation LBrace);
1287 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
1288
Douglas Gregord7c4d982008-12-30 03:27:21 +00001289 virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
1290 SourceLocation UsingLoc,
1291 SourceLocation NamespcLoc,
1292 const CXXScopeSpec &SS,
1293 SourceLocation IdentLoc,
1294 IdentifierInfo *NamespcName,
1295 AttributeList *AttrList);
1296
Douglas Gregor889ceb72009-02-03 19:21:40 +00001297 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
1298
Argyrios Kyrtzidis9a1191c2008-10-06 17:10:33 +00001299 /// AddCXXDirectInitializerToDecl - This action is called immediately after
1300 /// ActOnDeclarator, when a C++ direct initializer is present.
1301 /// e.g: "int x(1);"
1302 virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
1303 SourceLocation LParenLoc,
1304 ExprTy **Exprs, unsigned NumExprs,
1305 SourceLocation *CommaLocs,
1306 SourceLocation RParenLoc);
1307
Douglas Gregor6f543152008-11-05 15:29:30 +00001308 /// InitializationKind - Represents which kind of C++ initialization
1309 /// [dcl.init] a routine is to perform.
1310 enum InitializationKind {
1311 IK_Direct, ///< Direct initialization
1312 IK_Copy, ///< Copy initialization
1313 IK_Default ///< Default initialization
1314 };
1315
Douglas Gregorc28b57d2008-11-03 20:45:27 +00001316 CXXConstructorDecl *
Douglas Gregor6f543152008-11-05 15:29:30 +00001317 PerformInitializationByConstructor(QualType ClassType,
1318 Expr **Args, unsigned NumArgs,
1319 SourceLocation Loc, SourceRange Range,
Chris Lattnerf3d3fae2008-11-24 05:29:24 +00001320 DeclarationName InitEntity,
Douglas Gregor6f543152008-11-05 15:29:30 +00001321 InitializationKind Kind);
Douglas Gregorc28b57d2008-11-03 20:45:27 +00001322
Douglas Gregore200adc2008-10-27 19:41:14 +00001323 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
1324 virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
1325 SourceLocation LAngleBracketLoc, TypeTy *Ty,
1326 SourceLocation RAngleBracketLoc,
1327 SourceLocation LParenLoc, ExprTy *E,
1328 SourceLocation RParenLoc);
Bill Wendling4073ed52007-02-13 01:51:42 +00001329
Sebastian Redlc4704762008-11-11 11:37:55 +00001330 /// ActOnCXXTypeidOfType - Parse typeid( type-id ).
1331 virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
1332 SourceLocation LParenLoc, bool isType,
1333 void *TyOrExpr, SourceLocation RParenLoc);
1334
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001335 //// ActOnCXXThis - Parse 'this' pointer.
1336 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
1337
Steve Naroff66356bd2007-09-16 14:56:35 +00001338 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
1339 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Bill Wendlingbf313b02007-02-13 20:09:46 +00001340 tok::TokenKind Kind);
Anders Carlsson76f4a902007-08-21 17:43:55 +00001341
Chris Lattnerb7e656b2008-02-26 00:51:44 +00001342 //// ActOnCXXThrow - Parse throw expressions.
1343 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
1344 ExprTy *expr);
1345
Argyrios Kyrtzidis857fcc22008-08-22 15:38:55 +00001346 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
1347 /// Can be interpreted either as function-style casting ("int(x)")
1348 /// or class type construction ("ClassType(x,y,z)")
1349 /// or creation of a value-initialized type ("int()").
1350 virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
1351 TypeTy *TypeRep,
1352 SourceLocation LParenLoc,
1353 ExprTy **Exprs,
1354 unsigned NumExprs,
1355 SourceLocation *CommaLocs,
1356 SourceLocation RParenLoc);
1357
Sebastian Redlbd150f42008-11-21 19:14:01 +00001358 /// ActOnCXXNew - Parsed a C++ 'new' expression.
1359 virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1360 SourceLocation PlacementLParen,
1361 ExprTy **PlacementArgs, unsigned NumPlaceArgs,
1362 SourceLocation PlacementRParen,
Sebastian Redl351bb782008-12-02 14:43:59 +00001363 bool ParenTypeId, Declarator &D,
Sebastian Redlbd150f42008-11-21 19:14:01 +00001364 SourceLocation ConstructorLParen,
1365 ExprTy **ConstructorArgs, unsigned NumConsArgs,
1366 SourceLocation ConstructorRParen);
Sebastian Redl351bb782008-12-02 14:43:59 +00001367 bool CheckAllocatedType(QualType AllocType, const Declarator &D);
Sebastian Redl1df2bbe2009-02-09 18:24:27 +00001368 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
1369 bool UseGlobal, QualType AllocType, bool IsArray,
Sebastian Redlfaf68082008-12-03 20:26:15 +00001370 Expr **PlaceArgs, unsigned NumPlaceArgs,
1371 FunctionDecl *&OperatorNew,
1372 FunctionDecl *&OperatorDelete);
Sebastian Redl1df2bbe2009-02-09 18:24:27 +00001373 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
1374 DeclarationName Name, Expr** Args,
1375 unsigned NumArgs, DeclContext *Ctx,
Sebastian Redl33a31012008-12-04 22:20:51 +00001376 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlfaf68082008-12-03 20:26:15 +00001377 void DeclareGlobalNewDelete();
1378 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
1379 QualType Argument);
Sebastian Redlbd150f42008-11-21 19:14:01 +00001380
1381 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
1382 virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
1383 bool ArrayForm, ExprTy *Operand);
1384
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +00001385 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
1386 /// C++ if/switch/while/for statement.
1387 /// e.g: "if (int x = f()) {...}"
1388 virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
1389 SourceLocation StartLoc,
1390 Declarator &D,
1391 SourceLocation EqualLoc,
1392 ExprTy *AssignExprVal);
1393
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001394 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
1395 /// pseudo-functions.
1396 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
1397 SourceLocation KWLoc,
1398 SourceLocation LParen,
1399 TypeTy *Ty,
1400 SourceLocation RParen);
1401
Douglas Gregor26897462009-03-11 16:48:53 +00001402 bool RequireCompleteDeclContext(const CXXScopeSpec &SS);
1403
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001404 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
1405 /// global scope ('::').
1406 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
1407 SourceLocation CCLoc);
1408
1409 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1410 /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now
1411 /// we want to resolve "bar::". 'SS' is empty or the previously parsed
1412 /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar',
1413 /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'.
1414 /// Returns a CXXScopeTy* object representing the C++ scope.
1415 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1416 const CXXScopeSpec &SS,
1417 SourceLocation IdLoc,
1418 SourceLocation CCLoc,
Douglas Gregorae2fbad2008-11-17 20:34:05 +00001419 IdentifierInfo &II);
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001420
Douglas Gregor7f741122009-02-25 19:37:18 +00001421 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1422 /// nested-name-specifier that involves a template-id, e.g.,
1423 /// "foo::bar<int, float>::", and now we need to build a scope
1424 /// specifier. \p SS is empty or the previously parsed nested-name
1425 /// part ("foo::"), \p Type is the already-parsed class template
1426 /// specialization (or other template-id that names a type), \p
1427 /// TypeRange is the source range where the type is located, and \p
1428 /// CCLoc is the location of the trailing '::'.
1429 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1430 const CXXScopeSpec &SS,
1431 TypeTy *Type,
1432 SourceRange TypeRange,
1433 SourceLocation CCLoc);
1434
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001435 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1436 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1437 /// After this method is called, according to [C++ 3.4.3p3], names should be
1438 /// looked up in the declarator-id's scope, until the declarator is parsed and
1439 /// ActOnCXXExitDeclaratorScope is called.
1440 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1441 virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
1442
1443 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1444 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1445 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1446 /// Used to indicate that names should revert to being looked up in the
1447 /// defining scope.
Douglas Gregor29e174c2008-12-16 00:38:16 +00001448 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001449
Anders Carlsson76f4a902007-08-21 17:43:55 +00001450 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnere002fbe2007-12-12 01:04:12 +00001451 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
1452 ExprTy **Strings,
1453 unsigned NumStrings);
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001454 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner37390be2007-10-16 22:51:17 +00001455 SourceLocation EncodeLoc,
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001456 SourceLocation LParenLoc,
1457 TypeTy *Ty,
1458 SourceLocation RParenLoc);
1459
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001460 // ParseObjCSelectorExpression - Build selector expression for @selector
1461 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
1462 SourceLocation AtLoc,
Fariborz Jahanian6bd1d612007-10-16 23:21:02 +00001463 SourceLocation SelLoc,
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001464 SourceLocation LParenLoc,
1465 SourceLocation RParenLoc);
1466
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001467 // ParseObjCProtocolExpression - Build protocol expression for @protocol
1468 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
1469 SourceLocation AtLoc,
1470 SourceLocation ProtoLoc,
1471 SourceLocation LParenLoc,
1472 SourceLocation RParenLoc);
Douglas Gregor556877c2008-04-13 21:30:24 +00001473
1474 //===--------------------------------------------------------------------===//
Douglas Gregor07665a62009-01-05 19:45:36 +00001475 // C++ Declarations
1476 //
1477 virtual DeclTy *ActOnStartLinkageSpecification(Scope *S,
1478 SourceLocation ExternLoc,
1479 SourceLocation LangLoc,
1480 const char *Lang,
1481 unsigned StrSize,
1482 SourceLocation LBraceLoc);
1483 virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S,
1484 DeclTy *LinkageSpec,
1485 SourceLocation RBraceLoc);
1486
1487
1488 //===--------------------------------------------------------------------===//
Douglas Gregor556877c2008-04-13 21:30:24 +00001489 // C++ Classes
1490 //
Argyrios Kyrtzidis32a03792008-11-08 16:45:02 +00001491 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
1492 const CXXScopeSpec *SS);
Douglas Gregor61956c42008-10-31 09:07:45 +00001493
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001494 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
1495 Declarator &D, ExprTy *BitfieldWidth,
1496 ExprTy *Init, DeclTy *LastInGroup);
1497
Douglas Gregore8381c02008-11-05 04:29:56 +00001498 virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD,
1499 Scope *S,
1500 IdentifierInfo *MemberOrBase,
1501 SourceLocation IdLoc,
1502 SourceLocation LParenLoc,
1503 ExprTy **Args, unsigned NumArgs,
1504 SourceLocation *CommaLocs,
1505 SourceLocation RParenLoc);
1506
Douglas Gregor05379422008-11-03 17:51:48 +00001507 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
1508
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001509 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
1510 DeclTy *TagDecl,
1511 SourceLocation LBrac,
1512 SourceLocation RBrac);
1513
Douglas Gregor4d87df52008-12-16 21:30:33 +00001514 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1515 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param);
1516 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1517
Douglas Gregor831c93f2008-11-05 20:51:48 +00001518 bool CheckConstructorDeclarator(Declarator &D, QualType &R,
1519 FunctionDecl::StorageClass& SC);
Douglas Gregor4d87df52008-12-16 21:30:33 +00001520 bool CheckConstructor(CXXConstructorDecl *Constructor);
Douglas Gregor831c93f2008-11-05 20:51:48 +00001521 bool CheckDestructorDeclarator(Declarator &D, QualType &R,
1522 FunctionDecl::StorageClass& SC);
Douglas Gregordbc5daf2008-11-07 20:08:42 +00001523 bool CheckConversionDeclarator(Declarator &D, QualType &R,
1524 FunctionDecl::StorageClass& SC);
Douglas Gregordbc5daf2008-11-07 20:08:42 +00001525 DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregor61956c42008-10-31 09:07:45 +00001526
Douglas Gregor5c407d92008-10-23 00:40:37 +00001527 //===--------------------------------------------------------------------===//
1528 // C++ Derived Classes
1529 //
1530
1531 /// ActOnBaseSpecifier - Parsed a base specifier
Douglas Gregor463421d2009-03-03 04:44:36 +00001532 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
1533 SourceRange SpecifierRange,
1534 bool Virtual, AccessSpecifier Access,
1535 QualType BaseType,
1536 SourceLocation BaseLoc);
Douglas Gregor5c407d92008-10-23 00:40:37 +00001537 virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl,
1538 SourceRange SpecifierRange,
1539 bool Virtual, AccessSpecifier Access,
Douglas Gregor463421d2009-03-03 04:44:36 +00001540 TypeTy *basetype, SourceLocation
1541 BaseLoc);
Douglas Gregor5c407d92008-10-23 00:40:37 +00001542
Douglas Gregor463421d2009-03-03 04:44:36 +00001543 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
1544 unsigned NumBases);
Douglas Gregor5c407d92008-10-23 00:40:37 +00001545 virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
1546 unsigned NumBases);
1547
1548 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregor39c16d42008-10-24 04:54:22 +00001549 bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
Douglas Gregor960b5bc2009-01-15 00:26:24 +00001550 bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria,
1551 BasePaths &Paths);
Douglas Gregorcea4e7432008-10-24 16:17:19 +00001552 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
1553 SourceLocation Loc, SourceRange Range);
Douglas Gregor1c846b02009-01-16 00:38:09 +00001554 std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
Douglas Gregor556877c2008-04-13 21:30:24 +00001555
Douglas Gregor11d0c4c2008-11-06 22:13:31 +00001556 //===--------------------------------------------------------------------===//
1557 // C++ Overloaded Operators [C++ 13.5]
1558 //
1559
1560 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
1561
Douglas Gregor5101c242008-12-05 18:15:24 +00001562 //===--------------------------------------------------------------------===//
1563 // C++ Templates [C++ 14]
1564 //
Douglas Gregor8bf42052009-02-09 18:46:07 +00001565 virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S,
1566 DeclTy *&TemplateDecl,
1567 const CXXScopeSpec *SS = 0);
Douglas Gregor5101c242008-12-05 18:15:24 +00001568 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001569 TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl);
1570
1571 virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename,
1572 SourceLocation KeyLoc,
1573 IdentifierInfo *ParamName,
1574 SourceLocation ParamNameLoc,
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001575 unsigned Depth, unsigned Position);
Douglas Gregordba32632009-02-10 19:49:53 +00001576 virtual void ActOnTypeParameterDefault(DeclTy *TypeParam,
1577 SourceLocation EqualLoc,
1578 SourceLocation DefaultLoc,
1579 TypeTy *Default);
1580
Douglas Gregor463421d2009-03-03 04:44:36 +00001581 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001582 virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001583 unsigned Depth,
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001584 unsigned Position);
Douglas Gregordba32632009-02-10 19:49:53 +00001585 virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam,
1586 SourceLocation EqualLoc,
1587 ExprArg Default);
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001588 virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S,
1589 SourceLocation TmpLoc,
1590 TemplateParamsTy *Params,
1591 IdentifierInfo *ParamName,
1592 SourceLocation ParamNameLoc,
1593 unsigned Depth,
1594 unsigned Position);
Douglas Gregordba32632009-02-10 19:49:53 +00001595 virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam,
1596 SourceLocation EqualLoc,
1597 ExprArg Default);
1598
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001599 virtual TemplateParamsTy *
1600 ActOnTemplateParameterList(unsigned Depth,
1601 SourceLocation ExportLoc,
1602 SourceLocation TemplateLoc,
1603 SourceLocation LAngleLoc,
1604 DeclTy **Params, unsigned NumParams,
1605 SourceLocation RAngleLoc);
Douglas Gregordba32632009-02-10 19:49:53 +00001606 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
1607 TemplateParameterList *OldParams);
1608
Douglas Gregorcd72ba92009-02-06 22:42:48 +00001609 virtual DeclTy *
1610 ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK,
1611 SourceLocation KWLoc, const CXXScopeSpec &SS,
1612 IdentifierInfo *Name, SourceLocation NameLoc,
1613 AttributeList *Attr,
1614 MultiTemplateParamsArg TemplateParameterLists);
1615
Douglas Gregorc40290e2009-03-09 23:48:35 +00001616 QualType CheckClassTemplateId(ClassTemplateDecl *ClassTemplate,
1617 SourceLocation TemplateLoc,
1618 SourceLocation LAngleLoc,
1619 const TemplateArgument *TemplateArgs,
1620 unsigned NumTemplateArgs,
1621 SourceLocation RAngleLoc);
1622
Douglas Gregor67a65642009-02-17 23:15:12 +00001623 virtual TypeResult
1624 ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc,
1625 SourceLocation LAngleLoc,
1626 ASTTemplateArgsPtr TemplateArgs,
1627 SourceLocation *TemplateArgLocs,
1628 SourceLocation RAngleLoc,
1629 const CXXScopeSpec *SS);
1630
Douglas Gregorf47b9112009-02-25 22:02:03 +00001631 bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate,
1632 ClassTemplateSpecializationDecl *PrevDecl,
1633 SourceLocation TemplateNameLoc,
1634 SourceRange ScopeSpecifierRange);
1635
Douglas Gregor67a65642009-02-17 23:15:12 +00001636 virtual DeclTy *
1637 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
1638 SourceLocation KWLoc,
1639 const CXXScopeSpec &SS,
1640 DeclTy *Template,
1641 SourceLocation TemplateNameLoc,
Douglas Gregor8bf42052009-02-09 18:46:07 +00001642 SourceLocation LAngleLoc,
Douglas Gregor67b556a2009-02-09 19:34:22 +00001643 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregord32e0282009-02-09 23:23:08 +00001644 SourceLocation *TemplateArgLocs,
Douglas Gregor8bf42052009-02-09 18:46:07 +00001645 SourceLocation RAngleLoc,
Douglas Gregor67a65642009-02-17 23:15:12 +00001646 AttributeList *Attr,
1647 MultiTemplateParamsArg TemplateParameterLists);
Douglas Gregor8bf42052009-02-09 18:46:07 +00001648
Douglas Gregord32e0282009-02-09 23:23:08 +00001649 bool CheckTemplateArgumentList(TemplateDecl *Template,
1650 SourceLocation TemplateLoc,
1651 SourceLocation LAngleLoc,
Douglas Gregorc40290e2009-03-09 23:48:35 +00001652 const TemplateArgument *TemplateArgs,
1653 unsigned NumTemplateArgs,
Douglas Gregor264ec4f2009-02-17 01:05:43 +00001654 SourceLocation RAngleLoc,
1655 llvm::SmallVectorImpl<TemplateArgument> &Converted);
Douglas Gregord32e0282009-02-09 23:23:08 +00001656
1657 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg,
1658 SourceLocation ArgLoc);
Douglas Gregor264ec4f2009-02-17 01:05:43 +00001659 bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,
1660 NamedDecl *&Entity);
1661 bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member);
Douglas Gregor463421d2009-03-03 04:44:36 +00001662 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
1663 QualType InstantiatedParamType, Expr *&Arg,
Douglas Gregor264ec4f2009-02-17 01:05:43 +00001664 llvm::SmallVectorImpl<TemplateArgument> *Converted = 0);
Douglas Gregord32e0282009-02-09 23:23:08 +00001665 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg);
Douglas Gregorcd72ba92009-02-06 22:42:48 +00001666 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
1667 TemplateParameterList *Old,
1668 bool Complain,
Douglas Gregor85e0f662009-02-10 00:24:35 +00001669 bool IsTemplateTemplateParm = false,
1670 SourceLocation TemplateArgLoc
1671 = SourceLocation());
Douglas Gregorcd72ba92009-02-06 22:42:48 +00001672
1673 bool CheckTemplateDeclScope(Scope *S,
1674 MultiTemplateParamsArg &TemplateParameterLists);
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001675
Douglas Gregorfe1e1102009-02-27 19:31:52 +00001676 //===--------------------------------------------------------------------===//
1677 // C++ Template Instantiation
1678 //
Douglas Gregorfcd5db32009-03-10 00:06:19 +00001679
1680 /// \brief A template instantiation that is currently in progress.
1681 struct ActiveTemplateInstantiation {
Douglas Gregor79cf6032009-03-10 20:44:00 +00001682 /// \brief The kind of template instantiation we are performing
1683 enum {
1684 /// We are instantiating a template declaration. The entity is
1685 /// the declaration we're instantiation (e.g., a
1686 /// ClassTemplateSpecializationDecl).
1687 TemplateInstantiation,
1688
1689 /// We are instantiating a default argument for a template
1690 /// parameter. The Entity is the template, and
1691 /// TemplateArgs/NumTemplateArguments provides the template
1692 /// arguments as specified.
1693 DefaultTemplateArgumentInstantiation
1694 } Kind;
1695
Douglas Gregorfcd5db32009-03-10 00:06:19 +00001696 /// \brief The point of instantiation within the source code.
1697 SourceLocation PointOfInstantiation;
1698
1699 /// \brief The entity that is being instantiated.
Douglas Gregor79cf6032009-03-10 20:44:00 +00001700 uintptr_t Entity;
1701
1702 // \brief If this the instantiation of a default template
1703 // argument, the list of tempalte arguments.
1704 const TemplateArgument *TemplateArgs;
1705
1706 /// \brief The number of template arguments in TemplateArgs.
1707 unsigned NumTemplateArgs;
Douglas Gregorfcd5db32009-03-10 00:06:19 +00001708
1709 /// \brief The source range that covers the construct that cause
1710 /// the instantiation, e.g., the template-id that causes a class
1711 /// template instantiation.
1712 SourceRange InstantiationRange;
Douglas Gregor79cf6032009-03-10 20:44:00 +00001713
1714 friend bool operator==(const ActiveTemplateInstantiation &X,
1715 const ActiveTemplateInstantiation &Y) {
1716 if (X.Kind != Y.Kind)
1717 return false;
1718
1719 if (X.Entity != Y.Entity)
1720 return false;
1721
1722 switch (X.Kind) {
1723 case TemplateInstantiation:
1724 return true;
1725
1726 case DefaultTemplateArgumentInstantiation:
1727 return X.TemplateArgs == Y.TemplateArgs;
1728 }
1729
1730 return true;
1731 }
1732
1733 friend bool operator!=(const ActiveTemplateInstantiation &X,
1734 const ActiveTemplateInstantiation &Y) {
1735 return !(X == Y);
1736 }
Douglas Gregorfcd5db32009-03-10 00:06:19 +00001737 };
1738
1739 /// \brief List of active template instantiations.
1740 ///
1741 /// This vector is treated as a stack. As one template instantiation
1742 /// requires another template instantiation, additional
1743 /// instantiations are pushed onto the stack up to a
1744 /// user-configurable limit LangOptions::InstantiationDepth.
1745 llvm::SmallVector<ActiveTemplateInstantiation, 16>
1746 ActiveTemplateInstantiations;
1747
Douglas Gregor2a72edd2009-03-10 18:52:44 +00001748 /// \brief The last template from which a template instantiation
1749 /// error or warning was produced.
1750 ///
1751 /// This value is used to suppress printing of redundant template
1752 /// instantiation backtraces when there are multiple errors in the
1753 /// same instantiation. FIXME: Does this belong in Sema? It's tough
1754 /// to implement it anywhere else.
Douglas Gregor79cf6032009-03-10 20:44:00 +00001755 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
Douglas Gregor2a72edd2009-03-10 18:52:44 +00001756
Douglas Gregorfcd5db32009-03-10 00:06:19 +00001757 /// \brief A stack object to be created when performing template
1758 /// instantiation.
1759 ///
1760 /// Construction of an object of type \c InstantiatingTemplate
1761 /// pushes the current instantiation onto the stack of active
1762 /// instantiations. If the size of this stack exceeds the maximum
1763 /// number of recursive template instantiations, construction
1764 /// produces an error and evaluates true.
1765 ///
1766 /// Destruction of this object will pop the named instantiation off
1767 /// the stack.
1768 struct InstantiatingTemplate {
Douglas Gregor79cf6032009-03-10 20:44:00 +00001769 /// \brief Note that we are instantiating a class template.
Douglas Gregorfcd5db32009-03-10 00:06:19 +00001770 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
1771 ClassTemplateSpecializationDecl *Entity,
1772 SourceRange InstantiationRange = SourceRange());
Douglas Gregor79cf6032009-03-10 20:44:00 +00001773
1774 /// \brief Note that we are instantiating a default argument in a
1775 /// template-id.
1776 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
1777 TemplateDecl *Template,
1778 const TemplateArgument *TemplateArgs,
1779 unsigned NumTemplateArgs,
1780 SourceRange InstantiationRange = SourceRange());
1781
Douglas Gregorfcd5db32009-03-10 00:06:19 +00001782 ~InstantiatingTemplate();
1783
1784 /// \brief Determines whether we have exceeded the maximum
1785 /// recursive template instantiations.
1786 operator bool() const { return Invalid; }
1787
1788 private:
1789 Sema &SemaRef;
1790 bool Invalid;
1791
Douglas Gregor79cf6032009-03-10 20:44:00 +00001792 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
1793 SourceRange InstantiationRange);
1794
Douglas Gregorfcd5db32009-03-10 00:06:19 +00001795 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
1796
1797 InstantiatingTemplate&
1798 operator=(const InstantiatingTemplate&); // not implemented
1799 };
1800
Douglas Gregor4ea568f2009-03-10 18:03:33 +00001801 static void PrintInstantiationStackHook(unsigned DiagID, void *Cookie);
1802 void PrintInstantiationStack();
1803
Douglas Gregorfe1e1102009-02-27 19:31:52 +00001804 QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
1805 unsigned NumTemplateArgs,
1806 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor463421d2009-03-03 04:44:36 +00001807 bool
1808 InstantiateBaseSpecifiers(ClassTemplateSpecializationDecl *ClassTemplateSpec,
1809 ClassTemplateDecl *ClassTemplate);
1810 bool
1811 InstantiateClassTemplateSpecialization(
1812 ClassTemplateSpecializationDecl *ClassTemplateSpec,
1813 bool ExplicitInstantiation);
Douglas Gregorfe1e1102009-02-27 19:31:52 +00001814
Steve Naroff09bf8152007-09-06 21:24:23 +00001815 // Objective-C declarations.
Chris Lattnerdf59f5a2008-07-26 04:13:19 +00001816 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
1817 IdentifierInfo *ClassName,
1818 SourceLocation ClassLoc,
1819 IdentifierInfo *SuperName,
1820 SourceLocation SuperLoc,
1821 DeclTy * const *ProtoRefs,
1822 unsigned NumProtoRefs,
1823 SourceLocation EndProtoLoc,
1824 AttributeList *AttrList);
Fariborz Jahanian49c64252007-10-11 23:42:27 +00001825
1826 virtual DeclTy *ActOnCompatiblityAlias(
1827 SourceLocation AtCompatibilityAliasLoc,
1828 IdentifierInfo *AliasName, SourceLocation AliasLocation,
1829 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff41d09ad2009-03-05 15:22:01 +00001830
1831 void CheckForwardProtocolDeclarationForCircularDependency(
1832 IdentifierInfo *PName,
1833 SourceLocation &PLoc, SourceLocation PrevLoc,
1834 const ObjCList<ObjCProtocolDecl> &PList);
Steve Naroff09bf8152007-09-06 21:24:23 +00001835
Steve Naroff93eb5f12007-10-10 17:32:04 +00001836 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman7dd8e722008-02-20 22:57:40 +00001837 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian39d641f2007-09-17 21:07:36 +00001838 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattner3bbae002008-07-26 04:03:38 +00001839 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar26e2ab42008-09-26 04:48:09 +00001840 SourceLocation EndProtoLoc,
1841 AttributeList *AttrList);
Fariborz Jahanian39d641f2007-09-17 21:07:36 +00001842
Chris Lattnerb1f3c942008-07-26 04:07:02 +00001843 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
1844 IdentifierInfo *ClassName,
1845 SourceLocation ClassLoc,
1846 IdentifierInfo *CategoryName,
1847 SourceLocation CategoryLoc,
1848 DeclTy * const *ProtoRefs,
1849 unsigned NumProtoRefs,
1850 SourceLocation EndProtoLoc);
Fariborz Jahanian867a7eb2007-09-18 20:26:58 +00001851
Steve Naroff93eb5f12007-10-10 17:32:04 +00001852 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman7dd8e722008-02-20 22:57:40 +00001853 SourceLocation AtClassImplLoc,
Fariborz Jahanianbfe13c52007-09-25 18:38:09 +00001854 IdentifierInfo *ClassName, SourceLocation ClassLoc,
1855 IdentifierInfo *SuperClassname,
1856 SourceLocation SuperClassLoc);
1857
Steve Naroff93eb5f12007-10-10 17:32:04 +00001858 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahanian89b8ef92007-10-02 16:38:50 +00001859 SourceLocation AtCatImplLoc,
1860 IdentifierInfo *ClassName,
1861 SourceLocation ClassLoc,
1862 IdentifierInfo *CatName,
1863 SourceLocation CatLoc);
1864
Steve Naroff93eb5f12007-10-10 17:32:04 +00001865 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroff0c37b0c2007-10-02 22:39:18 +00001866 IdentifierInfo **IdentList,
1867 unsigned NumElts);
Fariborz Jahanian876e27d2007-09-21 15:40:54 +00001868
Steve Naroff93eb5f12007-10-10 17:32:04 +00001869 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001870 const IdentifierLocPair *IdentList,
Fariborz Jahanian1470e932008-12-17 01:07:27 +00001871 unsigned NumElts,
1872 AttributeList *attrList);
Fariborz Jahanianea7a98d2007-10-05 21:01:53 +00001873
Chris Lattner3bbae002008-07-26 04:03:38 +00001874 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001875 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian70e8f102007-10-11 00:55:41 +00001876 unsigned NumProtocols,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001877 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001878
Daniel Dunbare8a06e62008-09-23 21:53:23 +00001879 /// Ensure attributes are consistent with type.
1880 /// \param [in, out] Attributes The attributes to check; they will
1881 /// be modified to be consistent with \arg PropertyTy.
1882 void CheckObjCPropertyAttributes(QualType PropertyTy,
1883 SourceLocation Loc,
1884 unsigned &Attributes);
Steve Naroff35c62ae2009-01-08 17:28:14 +00001885 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001886 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1887 ObjCPropertyDecl *SuperProperty,
Chris Lattner86d7d912008-11-24 03:54:41 +00001888 const IdentifierInfo *Name);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001889 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanian0a070ff2008-04-24 19:58:34 +00001890
Fariborz Jahaniand2c2ad52008-12-06 23:03:39 +00001891 void MergeProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +00001892 DeclTy *MergeProtocols);
1893
Fariborz Jahanian33afd772009-03-02 19:05:07 +00001894 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
1895 ObjCInterfaceDecl *ID);
1896
Fariborz Jahaniand2c2ad52008-12-06 23:03:39 +00001897 void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +00001898 ObjCProtocolDecl *PDecl);
1899
Steve Naroffcac26f42007-11-11 17:19:15 +00001900 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
1901 DeclTy **allMethods = 0, unsigned allNum = 0,
1902 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahanian2a4dd312007-09-26 18:27:25 +00001903
Fariborz Jahanian0152a1a2008-04-14 23:36:35 +00001904 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian8d916862008-05-05 18:51:55 +00001905 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanian09367d62008-05-06 18:09:04 +00001906 Selector GetterSel, Selector SetterSel,
Fariborz Jahanianf8ef9f32008-11-26 20:01:34 +00001907 DeclTy *ClassCategory, bool *OverridingProperty,
Fariborz Jahanian8d916862008-05-05 18:51:55 +00001908 tok::ObjCKeywordKind MethodImplKind);
1909
Fariborz Jahanianffe97a32008-04-18 00:19:30 +00001910 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
1911 SourceLocation PropertyLoc,
1912 bool ImplKind, DeclTy *ClassImplDecl,
1913 IdentifierInfo *PropertyId,
1914 IdentifierInfo *PropertyIvar);
1915
Steve Naroff161a92b2007-10-26 20:53:56 +00001916 virtual DeclTy *ActOnMethodDeclaration(
1917 SourceLocation BeginLoc, // location of the + or -.
1918 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanianb5605172007-11-09 19:52:12 +00001919 tok::TokenKind MethodType,
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001920 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanian7a9c4742007-10-31 23:53:01 +00001921 Selector Sel,
Steve Narofff73590d2007-09-27 14:38:14 +00001922 // optional arguments. The number of types/arguments is obtained
1923 // from the Sel.getNumArgs().
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001924 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Fariborz Jahaniane84858c2009-01-09 00:38:19 +00001925 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroffd8ea1ac2007-11-15 12:35:21 +00001926 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
1927 bool isVariadic = false);
Steve Naroff077c83b2007-10-16 23:12:48 +00001928
Steve Naroffb162f172009-02-26 15:55:06 +00001929 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
1930 // Will search "local" class/category implementations for a method decl.
Fariborz Jahanian4f4de6c2009-03-04 18:15:57 +00001931 // Will also search in class's root looking for instance method.
Steve Naroffb162f172009-02-26 15:55:06 +00001932 // Returns 0 if no method is found.
Steve Naroffed031702009-03-08 18:56:13 +00001933 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
1934 ObjCInterfaceDecl *CDecl);
1935 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
1936 ObjCInterfaceDecl *ClassDecl);
Steve Naroffb162f172009-02-26 15:55:06 +00001937
Steve Naroff9527bbf2009-03-09 21:12:44 +00001938 virtual OwningExprResult ActOnClassPropertyRefExpr(
1939 IdentifierInfo &receiverName,
1940 IdentifierInfo &propertyName,
1941 SourceLocation &receiverNameLoc,
1942 SourceLocation &propertyNameLoc);
1943
Steve Narofff73590d2007-09-27 14:38:14 +00001944 // ActOnClassMessage - used for both unary and keyword messages.
1945 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001946 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +00001947 virtual ExprResult ActOnClassMessage(
Fariborz Jahaniand98a7342007-11-12 20:13:27 +00001948 Scope *S,
Anders Carlsson978f08d2009-02-14 18:21:46 +00001949 IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,
1950 SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001951 ExprTy **ArgExprs, unsigned NumArgs);
Steve Narofff73590d2007-09-27 14:38:14 +00001952
1953 // ActOnInstanceMessage - used for both unary and keyword messages.
1954 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001955 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +00001956 virtual ExprResult ActOnInstanceMessage(
Steve Naroff80175062007-09-28 22:22:11 +00001957 ExprTy *receiver, Selector Sel,
Anders Carlsson978f08d2009-02-14 18:21:46 +00001958 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001959 ExprTy **ArgExprs, unsigned NumArgs);
Daniel Dunbar54603742008-10-14 05:35:18 +00001960
1961 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
1962 virtual void ActOnPragmaPack(PragmaPackKind Kind,
1963 IdentifierInfo *Name,
1964 ExprTy *Alignment,
1965 SourceLocation PragmaLoc,
1966 SourceLocation LParenLoc,
1967 SourceLocation RParenLoc);
Chris Lattner31180bb2009-02-17 01:09:29 +00001968
1969 /// getPragmaPackAlignment() - Return the current alignment as specified by
1970 /// the current #pragma pack directive, or 0 if none is currently active.
1971 unsigned getPragmaPackAlignment() const;
1972
1973 /// FreePackedContext - Deallocate and null out PackContext.
1974 void FreePackedContext();
Daniel Dunbar54603742008-10-14 05:35:18 +00001975
Chris Lattnera65e1f32008-01-16 19:17:22 +00001976 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
1977 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregora11693b2008-11-12 17:17:38 +00001978 /// If isLvalue, the result of the cast is an lvalue.
1979 void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
Chris Lattnera65e1f32008-01-16 19:17:22 +00001980
Steve Naroff71b59a92007-06-04 22:22:31 +00001981 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner08464942007-12-28 05:29:59 +00001982 // functions and arrays to their respective pointers (C99 6.3.2.1).
1983 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3e113402008-05-27 03:33:27 +00001984
Steve Naroff31090012007-07-16 21:54:35 +00001985 // DefaultFunctionArrayConversion - converts functions and arrays
1986 // to their respective pointers (C99 6.3.2.1).
1987 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001988
Steve Naroff0b661582007-08-28 23:30:39 +00001989 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
1990 // do not have a prototype. Integer promotions are performed on each
1991 // argument, and arguments that have type float are promoted to double.
Chris Lattner08464942007-12-28 05:29:59 +00001992 void DefaultArgumentPromotion(Expr *&Expr);
Anders Carlssona7d069d2009-01-16 16:48:51 +00001993
1994 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
1995 enum VariadicCallType {
1996 VariadicFunction,
1997 VariadicBlock,
1998 VariadicMethod
1999 };
2000
2001 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
2002 // will warn if the resulting type is not a POD type.
2003 void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
Steve Naroff0b661582007-08-28 23:30:39 +00002004
Steve Naroff71b59a92007-06-04 22:22:31 +00002005 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
2006 // operands and then handles various conversions that are common to binary
2007 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
2008 // routine returns the first non-arithmetic type found. The client is
2009 // responsible for emitting appropriate error diagnostics.
Steve Naroffbe4c4d12007-08-24 19:07:16 +00002010 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
2011 bool isCompAssign = false);
Chris Lattner940cfeb2008-01-04 18:22:42 +00002012
Douglas Gregora11693b2008-11-12 17:17:38 +00002013 /// UsualArithmeticConversionsType - handles the various conversions
2014 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
2015 /// and returns the result type of that conversion.
2016 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
2017
2018
Chris Lattner940cfeb2008-01-04 18:22:42 +00002019 /// AssignConvertType - All of the 'assignment' semantic checks return this
2020 /// enum to indicate whether the assignment was allowed. These checks are
2021 /// done for simple assignments, as well as initialization, return from
2022 /// function, argument passing, etc. The query is phrased in terms of a
2023 /// source and destination type.
Chris Lattner9bad62c2008-01-04 18:04:52 +00002024 enum AssignConvertType {
Chris Lattner940cfeb2008-01-04 18:22:42 +00002025 /// Compatible - the types are compatible according to the standard.
Steve Naroff17f76e02007-05-03 21:03:48 +00002026 Compatible,
Chris Lattner940cfeb2008-01-04 18:22:42 +00002027
2028 /// PointerToInt - The assignment converts a pointer to an int, which we
2029 /// accept as an extension.
2030 PointerToInt,
2031
2032 /// IntToPointer - The assignment converts an int to a pointer, which we
2033 /// accept as an extension.
2034 IntToPointer,
2035
2036 /// FunctionVoidPointer - The assignment is between a function pointer and
2037 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattner0a788432008-01-03 22:56:36 +00002038 FunctionVoidPointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +00002039
2040 /// IncompatiblePointer - The assignment is between two pointers types that
2041 /// are not compatible, but we accept them as an extension.
Steve Naroff1f4d7272007-05-11 04:00:31 +00002042 IncompatiblePointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +00002043
2044 /// CompatiblePointerDiscardsQualifiers - The assignment discards
2045 /// c/v/r qualifiers, which we accept as an extension.
2046 CompatiblePointerDiscardsQualifiers,
Steve Naroff081c7422008-09-04 15:10:53 +00002047
Anders Carlssondb5a9b62009-01-30 23:17:46 +00002048 /// IncompatibleVectors - The assignment is between two vector types that
2049 /// have the same size, which we accept as an extension.
2050 IncompatibleVectors,
2051
Steve Naroff991e99d2008-09-04 15:31:07 +00002052 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff081c7422008-09-04 15:10:53 +00002053 /// pointer. We disallow this.
2054 IntToBlockPointer,
2055
Steve Naroff991e99d2008-09-04 15:31:07 +00002056 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff081c7422008-09-04 15:10:53 +00002057 /// pointers types that are not compatible.
2058 IncompatibleBlockPointer,
2059
Steve Naroff8afa9892008-10-14 22:18:38 +00002060 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
2061 /// id type and something else (that is incompatible with it). For example,
2062 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
2063 IncompatibleObjCQualifiedId,
2064
Chris Lattner940cfeb2008-01-04 18:22:42 +00002065 /// Incompatible - We reject this conversion outright, it is invalid to
2066 /// represent it in the AST.
2067 Incompatible
Steve Naroff17f76e02007-05-03 21:03:48 +00002068 };
Chris Lattner9bad62c2008-01-04 18:04:52 +00002069
2070 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
2071 /// assignment conversion type specified by ConvTy. This returns true if the
2072 /// conversion was invalid or false if the conversion was accepted.
2073 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
2074 SourceLocation Loc,
2075 QualType DstType, QualType SrcType,
2076 Expr *SrcExpr, const char *Flavor);
2077
2078 /// CheckAssignmentConstraints - Perform type checking for assignment,
2079 /// argument passing, variable initialization, and function return values.
2080 /// This routine is only used by the following two methods. C99 6.5.16.
2081 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00002082
Steve Naroff83895f72007-09-16 03:34:24 +00002083 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff66356bd2007-09-16 14:56:35 +00002084 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00002085 // this routine performs the default function/array converions.
Chris Lattner9bad62c2008-01-04 18:04:52 +00002086 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
2087 Expr *&rExpr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00002088 // CheckCompoundAssignmentConstraints - Type check without performing any
2089 // conversions. For compound assignments, the "Check...Operands" methods
2090 // perform the necessary conversions.
Chris Lattner9bad62c2008-01-04 18:04:52 +00002091 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
2092 QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00002093
Steve Naroff98cf3e92007-06-06 18:38:38 +00002094 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner9bad62c2008-01-04 18:04:52 +00002095 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
2096 QualType rhsType);
Steve Naroff081c7422008-09-04 15:10:53 +00002097
2098 // Helper function for CheckAssignmentConstraints involving two
2099 // blcok pointer types.
2100 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
2101 QualType rhsType);
Douglas Gregoraa1e21d2008-09-12 00:47:35 +00002102
2103 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregor39c16d42008-10-24 04:54:22 +00002104
Douglas Gregor47d3f272008-12-19 17:40:08 +00002105 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +00002106 const char *Flavor, bool AllowExplicit = false);
2107 bool PerformImplicitConversion(Expr *&From, QualType ToType,
2108 const ImplicitConversionSequence& ICS,
Douglas Gregor47d3f272008-12-19 17:40:08 +00002109 const char *Flavor);
Douglas Gregor39c16d42008-10-24 04:54:22 +00002110 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor47d3f272008-12-19 17:40:08 +00002111 const StandardConversionSequence& SCS,
2112 const char *Flavor);
Sebastian Redl112a97662009-02-07 00:15:38 +00002113
Steve Naroff8eeeb132007-05-08 21:09:37 +00002114 /// the following "Check" methods will return a valid/converted QualType
2115 /// or a null QualType (indicating an error diagnostic was issued).
Sebastian Redl112a97662009-02-07 00:15:38 +00002116
2117 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
Chris Lattner5c11c412007-12-12 05:47:28 +00002118 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Sebastian Redl5822f082009-02-07 20:10:22 +00002119 QualType CheckPointerToMemberOperands( // C++ 5.5
Sebastian Redl112a97662009-02-07 00:15:38 +00002120 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
Steve Naroff218bc2b2007-05-04 21:54:46 +00002121 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Sebastian Redl112a97662009-02-07 00:15:38 +00002122 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00002123 inline QualType CheckRemainderOperands( // C99 6.5.5
Sebastian Redl112a97662009-02-07 00:15:38 +00002124 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00002125 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +00002126 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00002127 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +00002128 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00002129 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroffbe4c4d12007-08-24 19:07:16 +00002130 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnerb620c342007-08-26 01:18:55 +00002131 inline QualType CheckCompareOperands( // C99 6.5.8/9
2132 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Steve Naroff218bc2b2007-05-04 21:54:46 +00002133 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Sebastian Redl112a97662009-02-07 00:15:38 +00002134 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00002135 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff7a5af782007-07-13 16:58:59 +00002136 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Naroff35d85152007-05-07 00:24:15 +00002137 // CheckAssignmentOperands is used for both simple and compound assignment.
2138 // For simple assignment, pass both expressions and a null converted type.
2139 // For compound assignment, pass both expressions and the converted type.
2140 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0c1c7ed2007-08-24 22:33:52 +00002141 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Steve Naroff218bc2b2007-05-04 21:54:46 +00002142 inline QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner326f7572008-11-18 01:30:42 +00002143 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Steve Narofff8a28c52007-05-15 20:29:32 +00002144 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff7a5af782007-07-13 16:58:59 +00002145 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begeman191a6b12008-07-14 18:02:46 +00002146
2147 /// type checking for vector binary operators.
2148 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
2149 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
2150 SourceLocation l, bool isRel);
Steve Naroff95af0132007-03-30 23:47:58 +00002151
Steve Naroff83895f72007-09-16 03:34:24 +00002152 /// type checking unary operators (subroutines of ActOnUnaryOp).
Steve Naroff9358c712007-05-27 23:58:33 +00002153 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redle10c2c32008-12-20 09:35:34 +00002154 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
2155 bool isInc);
Steve Naroff71ce2e02007-05-18 22:53:50 +00002156 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
2157 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattner709322b2009-02-17 08:12:06 +00002158 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
Steve Narofff8fd09e2007-07-27 22:15:19 +00002159
2160 /// type checking primary expressions.
Nate Begemance4d7fc2008-04-18 23:10:10 +00002161 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Narofff8fd09e2007-07-27 22:15:19 +00002162 IdentifierInfo &Comp, SourceLocation CmpLoc);
2163
Steve Naroff2fea1392007-09-02 02:04:30 +00002164 /// type checking declaration initializers (C99 6.7.8)
Douglas Gregor6f543152008-11-05 15:29:30 +00002165 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor5fb53972009-01-14 15:45:31 +00002166 SourceLocation InitLoc,DeclarationName InitEntity,
2167 bool DirectInit);
Douglas Gregor85df8d82009-01-29 00:45:39 +00002168 bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
Steve Naroff98f72032008-01-10 22:15:12 +00002169 bool CheckForConstantInitializer(Expr *e, QualType t);
Steve Naroff91f78082007-12-10 22:44:33 +00002170
Douglas Gregora5c9e1a2009-02-02 17:43:21 +00002171 bool CheckValueInitialization(QualType Type, SourceLocation Loc);
Argyrios Kyrtzidis2ade3902008-08-16 20:27:34 +00002172
Douglas Gregor8e1cf602008-10-29 00:13:59 +00002173 // type checking C++ declaration initializers (C++ [dcl.init]).
2174
2175 /// ReferenceCompareResult - Expresses the result of comparing two
2176 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
2177 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
2178 enum ReferenceCompareResult {
2179 /// Ref_Incompatible - The two types are incompatible, so direct
2180 /// reference binding is not possible.
2181 Ref_Incompatible = 0,
2182 /// Ref_Related - The two types are reference-related, which means
2183 /// that their unqualified forms (T1 and T2) are either the same
2184 /// or T1 is a base class of T2.
2185 Ref_Related,
2186 /// Ref_Compatible_With_Added_Qualification - The two types are
2187 /// reference-compatible with added qualification, meaning that
2188 /// they are reference-compatible and the qualifiers on T1 (cv1)
2189 /// are greater than the qualifiers on T2 (cv2).
2190 Ref_Compatible_With_Added_Qualification,
2191 /// Ref_Compatible - The two types are reference-compatible and
2192 /// have equivalent qualifiers (cv1 == cv2).
2193 Ref_Compatible
2194 };
2195
Douglas Gregor786ab212008-10-29 02:00:59 +00002196 ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
2197 bool& DerivedToBase);
Douglas Gregor8e1cf602008-10-29 00:13:59 +00002198
2199 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor2fe98832008-11-03 19:09:14 +00002200 ImplicitConversionSequence *ICS = 0,
Douglas Gregor5fb53972009-01-14 15:45:31 +00002201 bool SuppressUserConversions = false,
2202 bool AllowExplicit = false);
Douglas Gregor8e1cf602008-10-29 00:13:59 +00002203
Argyrios Kyrtzidis2ade3902008-08-16 20:27:34 +00002204 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar94834d82008-08-20 03:55:42 +00002205 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroffaf2a0222008-01-22 00:55:40 +00002206
Anders Carlsson24c59952007-11-27 07:16:40 +00002207 // CheckVectorCast - check type constraints for vectors.
2208 // Since vectors are an extension, there are no C standard reference for this.
2209 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssonde71adf2007-11-27 05:51:55 +00002210 // returns true if the cast is invalid
2211 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
2212
Daniel Dunbaraa9326c2008-09-11 00:01:56 +00002213 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
2214 /// \param Method - May be null.
2215 /// \param [out] ReturnType - The return type of the send.
2216 /// \return true iff there were any incompatible types.
Daniel Dunbarce05c8e2008-09-11 00:50:25 +00002217 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattnere4b95692008-11-24 03:33:13 +00002218 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbaraa9326c2008-09-11 00:01:56 +00002219 SourceLocation lbrac, SourceLocation rbrac,
2220 QualType &ReturnType);
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +00002221
2222 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
2223 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff077c83b2007-10-16 23:12:48 +00002224
Chris Lattnerfc1c44a2007-08-23 05:46:52 +00002225 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
2226 /// the specified width and sign. If an overflow occurs, detect it and emit
2227 /// the specified diagnostic.
2228 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
2229 unsigned NewWidth, bool NewSign,
2230 SourceLocation Loc, unsigned DiagID);
2231
Chris Lattner2a3569b2008-04-07 05:30:13 +00002232 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
2233 bool ForCompare);
2234
Anders Carlssona6b508a2008-11-04 16:57:32 +00002235 /// Checks that the Objective-C declaration is declared in the global scope.
2236 /// Emits an error and marks the declaration as invalid if it's not declared
2237 /// in the global scope.
2238 bool CheckObjCDeclScope(Decl *D);
2239
Anders Carlsson7e13ab82007-10-15 20:28:48 +00002240 void InitBuiltinVaListType();
Eli Friedman149614b2008-06-03 21:01:11 +00002241
Anders Carlssone54e8a12008-11-30 19:50:32 +00002242 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
2243 /// and reports the appropriate diagnostics. Returns false on success.
2244 /// Can optionally return the value of the expression.
Anders Carlsson5df391e2008-12-06 20:33:04 +00002245 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson1dbffc62008-12-01 02:17:22 +00002246
Anders Carlsson5df391e2008-12-06 20:33:04 +00002247 /// VerifyBitField - verifies that a bit field expression is an ICE and has
2248 /// the correct width, and that the field type is valid.
2249 /// Returns false on success.
2250 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
2251 QualType FieldTy, const Expr *BitWidth);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00002252
Chris Lattnerb87b1b32007-08-10 20:18:51 +00002253 //===--------------------------------------------------------------------===//
2254 // Extra semantic analysis beyond the C type system
Chris Lattner08464942007-12-28 05:29:59 +00002255private:
Sebastian Redlc215cfc2009-01-19 00:08:26 +00002256 Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl,
2257 CallExpr *TheCall);
Chris Lattnera26fb342009-02-18 17:49:48 +00002258 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
2259 unsigned ByteNo) const;
Chris Lattner6436fb62009-02-18 06:01:06 +00002260 bool CheckObjCString(Expr *Arg);
Chris Lattner08464942007-12-28 05:29:59 +00002261 bool SemaBuiltinVAStart(CallExpr *TheCall);
2262 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedmanf8353032008-05-20 08:23:37 +00002263 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00002264 Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbarb7257262008-07-21 22:59:13 +00002265 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbarb0d34c82008-09-03 21:13:56 +00002266 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Ted Kremenek6dfeb552009-01-12 23:09:09 +00002267 bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg,
Douglas Gregore711f702009-02-14 18:57:46 +00002268 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek6dfeb552009-01-12 23:09:09 +00002269 void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr,
2270 CallExpr *TheCall, bool HasVAListArg,
Douglas Gregore711f702009-02-14 18:57:46 +00002271 unsigned format_idx, unsigned firstDataArg);
2272 void CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
2273 unsigned format_idx, unsigned firstDataArg);
Ted Kremenekcff94fa2007-08-17 16:46:58 +00002274 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
2275 SourceLocation ReturnLoc);
Ted Kremenek43fb8b02007-11-25 00:58:00 +00002276 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Chris Lattner7cee11f2006-11-03 06:42:29 +00002277};
2278
Steve Naroffc540d662008-09-03 18:15:37 +00002279/// BlockSemaInfo - When a block is being parsed, this contains information
2280/// about the block. It is pointed to from Sema::CurBlock.
2281struct BlockSemaInfo {
2282 llvm::SmallVector<ParmVarDecl*, 8> Params;
Steve Naroffc540d662008-09-03 18:15:37 +00002283 bool hasPrototype;
2284 bool isVariadic;
Mike Stumpa6703322009-02-19 22:01:56 +00002285 bool hasBlockDeclRefExprs;
2286
Steve Naroff44078b92008-10-08 18:44:00 +00002287 BlockDecl *TheDecl;
2288
Chris Lattner1fa74d92009-02-18 07:09:44 +00002289 /// TheScope - This is the scope for the block itself, which contains
Steve Naroffc540d662008-09-03 18:15:37 +00002290 /// arguments etc.
2291 Scope *TheScope;
2292
2293 /// ReturnType - This will get set to block result type, by looking at
2294 /// return types, if any, in the block body.
2295 Type *ReturnType;
2296
2297 /// PrevBlockInfo - If this is nested inside another block, this points
2298 /// to the outer block.
2299 BlockSemaInfo *PrevBlockInfo;
2300};
Ted Kremenek5a201952009-02-07 01:47:29 +00002301
2302//===--------------------------------------------------------------------===//
2303// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
2304template <typename T>
2305class ExprOwningPtr : public Action::ExprArg {
2306public:
2307 ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {};
2308
2309 void reset(T* p) { Action::ExprArg::operator=(p); }
2310 T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
2311 T* take() { return static_cast<T*>(Action::ExprArg::take()); }
2312 T* release() { return take(); }
2313
2314 T& operator*() const { return *get(); }
2315 T* operator->() const { return get(); }
2316};
2317
Chris Lattner7cee11f2006-11-03 06:42:29 +00002318} // end namespace clang
Chris Lattner7cee11f2006-11-03 06:42:29 +00002319
2320#endif