blob: 83be895909077c47ec25d3b073d808d2fae86bb2 [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) {
245 return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
246 }
Steve Naroff71ce2e02007-05-18 22:53:50 +0000247
Chris Lattner57c523f2007-08-31 04:53:24 +0000248 virtual void DeleteExpr(ExprTy *E);
249 virtual void DeleteStmt(StmtTy *S);
250
Sebastian Redlc675bab2008-12-13 16:23:55 +0000251 OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); }
Sebastian Redlc215cfc2009-01-19 00:08:26 +0000252 OwningExprResult Owned(ExprResult R) {
Douglas Gregorf8298252009-01-26 22:44:13 +0000253 if (R.isInvalid())
Steve Naroffd5129562009-01-21 22:32:33 +0000254 return ExprError();
Douglas Gregorf8298252009-01-26 22:44:13 +0000255 return OwningExprResult(*this, R.get());
Sebastian Redlc215cfc2009-01-19 00:08:26 +0000256 }
Sebastian Redlc675bab2008-12-13 16:23:55 +0000257 OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
258
Chris Lattnerf4404402008-08-23 03:19:52 +0000259 virtual void ActOnEndOfTranslationUnit();
Sebastian Redlb5d49352009-01-19 22:31:54 +0000260
Chris Lattner7cee11f2006-11-03 06:42:29 +0000261 //===--------------------------------------------------------------------===//
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000262 // Type Analysis / Processing: SemaType.cpp.
263 //
Chris Lattner4b413ea2008-06-26 06:27:57 +0000264 QualType ConvertDeclSpecToType(const DeclSpec &DS);
Chris Lattnera7e619c2008-06-29 00:50:08 +0000265 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Douglas Gregor17c0d7b2009-02-28 00:25:32 +0000266 QualType BuildPointerType(QualType T, unsigned Quals,
267 SourceLocation Loc, DeclarationName Entity);
268 QualType BuildReferenceType(QualType T, unsigned Quals,
269 SourceLocation Loc, DeclarationName Entity);
270 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
271 Expr *ArraySize, unsigned Quals,
272 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor6eaaf302009-02-28 01:04:19 +0000273 QualType BuildFunctionType(QualType T,
274 QualType *ParamTypes, unsigned NumParamTypes,
275 bool Variadic, unsigned Quals,
276 SourceLocation Loc, DeclarationName Entity);
Sebastian Redl351bb782008-12-02 14:43:59 +0000277 QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0);
Douglas Gregor92751d42008-11-17 22:58:34 +0000278 DeclarationName GetNameForDeclarator(Declarator &D);
279
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000280 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahanian56ff1462007-11-08 23:49:49 +0000281
Douglas Gregore1eb9d82008-10-22 14:17:15 +0000282 bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
283
Sebastian Redl351bb782008-12-02 14:43:59 +0000284 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Sebastian Redl842ef522008-11-08 13:00:26 +0000285
Douglas Gregored0cfbd2009-03-09 16:13:40 +0000286 bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned diag,
Douglas Gregordd430f72009-01-19 19:26:10 +0000287 SourceRange Range1 = SourceRange(),
288 SourceRange Range2 = SourceRange(),
289 QualType PrintType = QualType());
290
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000291 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000292 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000293 //
Chris Lattner03b53942009-03-05 01:25:28 +0000294
295 /// getDeclName - Return a pretty name for the specified decl if possible, or
296 /// an empty string if not. This is used for pretty crash reporting.
297 virtual std::string getDeclName(DeclTy *D);
298
Douglas Gregor9817f4a2009-02-09 15:09:02 +0000299 virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Douglas Gregor8a6be5e2009-02-04 17:00:24 +0000300 Scope *S, const CXXScopeSpec *SS);
Chris Lattner4bf74fd2009-02-15 22:43:40 +0000301 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){
Douglas Gregorad590502008-12-15 23:53:10 +0000302 return ActOnDeclarator(S, D, LastInGroup, false);
303 }
304 DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
305 bool IsFunctionDefinition);
Douglas Gregor5a80bd12009-03-02 00:19:53 +0000306 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl,
307 Scope *S);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000308 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
309 QualType R, Decl* LastDeclarator,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000310 Decl* PrevDecl, bool& InvalidDecl,
311 bool &Redeclaration);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000312 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000313 QualType R, Decl* LastDeclarator,
Douglas Gregor5d68a202009-02-24 19:23:27 +0000314 NamedDecl* PrevDecl, bool& InvalidDecl,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000315 bool &Redeclaration);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000316 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
317 QualType R, Decl *LastDeclarator,
Douglas Gregore62c0a42009-02-24 01:23:02 +0000318 NamedDecl* PrevDecl,
319 bool IsFunctionDefinition,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000320 bool& InvalidDecl, bool &Redeclaration);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000321 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
322 virtual void ActOnParamDefaultArgument(DeclTy *param,
323 SourceLocation EqualLoc,
324 ExprTy *defarg);
Douglas Gregor58354032008-12-24 00:01:03 +0000325 virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
326 SourceLocation EqualLoc);
Douglas Gregor4d87df52008-12-16 21:30:33 +0000327 virtual void ActOnParamDefaultArgumentError(DeclTy *param);
Douglas Gregor5fb53972009-01-14 15:45:31 +0000328 virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
329 void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit);
Douglas Gregor8e1cf602008-10-29 00:13:59 +0000330 void ActOnUninitializedDecl(DeclTy *dcl);
Chris Lattner776fac82007-06-09 00:53:06 +0000331 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
332
Douglas Gregor9aa89042009-01-23 16:23:13 +0000333 virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D);
Chris Lattnera55a2cc2007-10-09 17:14:05 +0000334 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000335 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Steve Naroff70f41d62009-02-28 16:59:13 +0000336 virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D);
Sebastian Redlb5d49352009-01-19 22:31:54 +0000337
Sebastian Redlc675bab2008-12-13 16:23:55 +0000338 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
Sebastian Redlc675bab2008-12-13 16:23:55 +0000339 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlsson5c6c0592008-02-08 00:33:21 +0000340
Steve Naroffc62adb62007-10-09 22:01:59 +0000341 /// Scope actions.
342 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
343 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Chris Lattner01564d92007-01-27 19:27:06 +0000344
Chris Lattner200bdc32006-11-19 02:43:37 +0000345 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
346 /// no declarator (e.g. "struct foo;") is parsed.
Sebastian Redla2b5e312008-12-28 15:28:59 +0000347 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Chris Lattner200bdc32006-11-19 02:43:37 +0000348
Douglas Gregor9ac7a072009-01-07 00:43:41 +0000349 bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
350 RecordDecl *AnonRecord);
351 virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
352 RecordDecl *Record);
353
Douglas Gregordee1be82009-01-17 00:42:38 +0000354 virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
Argyrios Kyrtzidis32a03792008-11-08 16:45:02 +0000355 SourceLocation KWLoc, const CXXScopeSpec &SS,
356 IdentifierInfo *Name, SourceLocation NameLoc,
Douglas Gregorcd72ba92009-02-06 22:42:48 +0000357 AttributeList *Attr);
Ted Kremenek21475702008-09-05 17:16:31 +0000358
Douglas Gregor91f84212008-12-11 16:49:14 +0000359 virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner2cc35ae2008-08-23 02:00:52 +0000360 IdentifierInfo *ClassName,
361 llvm::SmallVectorImpl<DeclTy*> &Decls);
Douglas Gregor91f84212008-12-11 16:49:14 +0000362 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner1300fb92007-01-23 23:42:53 +0000363 Declarator &D, ExprTy *BitfieldWidth);
Chris Lattner73bf7b42009-03-05 22:45:59 +0000364
365 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
366 Declarator &D, Expr *BitfieldWidth);
367
Fariborz Jahaniande615832008-04-10 23:32:45 +0000368
369 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
370 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian96376742008-04-11 16:55:42 +0000371 tok::ObjCKeywordKind visibility);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000372
Steve Naroff2e688fd2007-09-14 23:09:53 +0000373 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian343f7092007-09-29 00:54:24 +0000374 virtual void ActOnFields(Scope* S,
Steve Naroff33a1e802007-10-29 21:38:07 +0000375 SourceLocation RecLoc, DeclTy *TagDecl,
376 DeclTy **Fields, unsigned NumFields,
Daniel Dunbar15619c72008-10-03 02:03:53 +0000377 SourceLocation LBrac, SourceLocation RBrac,
378 AttributeList *AttrList);
Douglas Gregor82ac25e2009-01-08 20:45:30 +0000379
380 /// ActOnTagStartDefinition - Invoked when we have entered the
381 /// scope of a tag's definition (e.g., for an enumeration, class,
382 /// struct, or union).
383 virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl);
384
385 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
386 /// the definition of a tag (enumeration, class, struct, or union).
387 virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl);
388
Steve Naroff30d242c2007-09-15 18:49:24 +0000389 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4ef40012007-06-11 01:28:17 +0000390 DeclTy *LastEnumConstant,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000391 SourceLocation IdLoc, IdentifierInfo *Id,
392 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff30d242c2007-09-15 18:49:24 +0000393 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000394 DeclTy **Elements, unsigned NumElements);
Sebastian Redl842ef522008-11-08 13:00:26 +0000395
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +0000396 DeclContext *getContainingDC(DeclContext *DC);
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000397
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000398 /// Set the current declaration context until it gets popped.
Douglas Gregor91f84212008-12-11 16:49:14 +0000399 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattner0a5ff0d2008-04-06 04:47:34 +0000400 void PopDeclContext();
Argyrios Kyrtzidis853fbea2008-06-28 06:07:14 +0000401
Chris Lattner79413952008-12-04 23:50:19 +0000402 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
403 /// to the function decl for the function being parsed. If we're currently
404 /// in a 'block', this returns the containing context.
405 FunctionDecl *getCurFunctionDecl();
406
407 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
408 /// the method decl for the method being parsed. If we're currently
409 /// in a 'block', this returns the containing context.
Daniel Dunbar6e8aa532008-08-11 05:35:13 +0000410 ObjCMethodDecl *getCurMethodDecl();
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000411
Chris Lattner79413952008-12-04 23:50:19 +0000412 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
413 /// or C function we're in, otherwise return null. If we're currently
414 /// in a 'block', this returns the containing context.
415 NamedDecl *getCurFunctionOrMethodDecl();
416
Argyrios Kyrtzidisb8a49202008-04-12 00:47:19 +0000417 /// Add this decl to the scope shadowed decl chains.
418 void PushOnScopeChains(NamedDecl *D, Scope *S);
419
Argyrios Kyrtzidis5b144d52008-09-09 21:18:04 +0000420 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
421 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
422 /// true if 'D' belongs to the given declaration context.
423 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
Douglas Gregor91f84212008-12-11 16:49:14 +0000424 return IdResolver.isDeclInScope(D, Ctx, Context, S);
Argyrios Kyrtzidis5b144d52008-09-09 21:18:04 +0000425 }
426
Eli Friedmanf69d09b2009-02-28 05:41:13 +0000427
428 void RecursiveCalcJumpScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
429 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
430 llvm::DenseMap<Stmt*, void*>& GotoScopeMap,
431 std::vector<void*>& ScopeStack,
432 Stmt* CurStmt);
433
434 void RecursiveCalcLabelScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
435 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
436 std::vector<void*>& ScopeStack,
437 Stmt* CurStmt,
438 Stmt* ParentCompoundStmt);
439
Chris Lattnerefedd9e2008-02-21 01:07:18 +0000440 /// Subroutines of ActOnDeclarator().
Chris Lattner07b201d2007-11-14 06:34:38 +0000441 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000442 Decl *LastDecl);
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000443 bool MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
444 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
Douglas Gregore62c0a42009-02-24 01:23:02 +0000445 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000446 bool MergeVarDecl(VarDecl *New, Decl *Old);
447 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Steve Naroff5bb8f222008-08-08 17:50:35 +0000448 void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000449
450 /// C++ Overloading.
451 bool IsOverload(FunctionDecl *New, Decl* OldD,
452 OverloadedFunctionDecl::function_iterator &MatchedDecl);
Douglas Gregor2fe98832008-11-03 19:09:14 +0000453 ImplicitConversionSequence
454 TryImplicitConversion(Expr* From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000455 bool SuppressUserConversions = false,
456 bool AllowExplicit = false);
Douglas Gregor26bee0b2008-10-31 16:23:19 +0000457 bool IsStandardConversion(Expr *From, QualType ToType,
458 StandardConversionSequence& SCS);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000459 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
460 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
Douglas Gregor78ca74d2009-02-12 00:15:05 +0000461 bool IsComplexPromotion(QualType FromType, QualType ToType);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000462 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregor47d3f272008-12-19 17:40:08 +0000463 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregora119f102008-12-19 19:13:09 +0000464 bool isObjCPointerConversion(QualType FromType, QualType ToType,
465 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregor39c16d42008-10-24 04:54:22 +0000466 bool CheckPointerConversion(Expr *From, QualType ToType);
Sebastian Redl72b597d2009-01-25 19:43:20 +0000467 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
468 QualType &ConvertedType);
469 bool CheckMemberPointerConversion(Expr *From, QualType ToType);
Douglas Gregor9a657932008-10-21 23:43:52 +0000470 bool IsQualificationConversion(QualType FromType, QualType ToType);
Douglas Gregor26bee0b2008-10-31 16:23:19 +0000471 bool IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000472 UserDefinedConversionSequence& User,
Douglas Gregor576e98c2009-01-30 23:27:23 +0000473 bool AllowConversionFunctions,
474 bool AllowExplicit);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000475
476 ImplicitConversionSequence::CompareKind
477 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
478 const ImplicitConversionSequence& ICS2);
479
480 ImplicitConversionSequence::CompareKind
481 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
482 const StandardConversionSequence& SCS2);
483
Douglas Gregore1eb9d82008-10-22 14:17:15 +0000484 ImplicitConversionSequence::CompareKind
485 CompareQualificationConversions(const StandardConversionSequence& SCS1,
486 const StandardConversionSequence& SCS2);
487
Douglas Gregor5c407d92008-10-23 00:40:37 +0000488 ImplicitConversionSequence::CompareKind
489 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
490 const StandardConversionSequence& SCS2);
491
Douglas Gregor2fe98832008-11-03 19:09:14 +0000492 ImplicitConversionSequence
493 TryCopyInitialization(Expr* From, QualType ToType,
494 bool SuppressUserConversions = false);
Douglas Gregor8e1cf602008-10-29 00:13:59 +0000495 bool PerformCopyInitialization(Expr *&From, QualType ToType,
496 const char *Flavor);
497
Douglas Gregor436424c2008-11-18 23:14:02 +0000498 ImplicitConversionSequence
499 TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method);
500 bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method);
501
Douglas Gregor5fb53972009-01-14 15:45:31 +0000502 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
503 bool PerformContextuallyConvertToBool(Expr *&From);
504
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000505 /// OverloadingResult - Capture the result of performing overload
506 /// resolution.
507 enum OverloadingResult {
508 OR_Success, ///< Overload resolution succeeded.
509 OR_No_Viable_Function, ///< No viable function found.
Douglas Gregor171c45a2009-02-18 21:56:37 +0000510 OR_Ambiguous, ///< Ambiguous candidates found.
511 OR_Deleted ///< Overload resoltuion refers to a deleted function.
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000512 };
513
514 void AddOverloadCandidate(FunctionDecl *Function,
515 Expr **Args, unsigned NumArgs,
Douglas Gregor2fe98832008-11-03 19:09:14 +0000516 OverloadCandidateSet& CandidateSet,
517 bool SuppressUserConversions = false);
Douglas Gregor436424c2008-11-18 23:14:02 +0000518 void AddMethodCandidate(CXXMethodDecl *Method,
519 Expr *Object, Expr **Args, unsigned NumArgs,
520 OverloadCandidateSet& CandidateSet,
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000521 bool SuppressUserConversions = false);
Douglas Gregora1f013e2008-11-07 22:36:19 +0000522 void AddConversionCandidate(CXXConversionDecl *Conversion,
523 Expr *From, QualType ToType,
524 OverloadCandidateSet& CandidateSet);
Douglas Gregorab7897a2008-11-19 22:57:39 +0000525 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
Douglas Gregordeaad8c2009-02-26 23:50:07 +0000526 const FunctionProtoType *Proto,
Douglas Gregorab7897a2008-11-19 22:57:39 +0000527 Expr *Object, Expr **Args, unsigned NumArgs,
528 OverloadCandidateSet& CandidateSet);
Douglas Gregor94eabf32009-02-04 16:44:47 +0000529 bool AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
530 SourceLocation OpLoc,
Douglas Gregor436424c2008-11-18 23:14:02 +0000531 Expr **Args, unsigned NumArgs,
Douglas Gregor94eabf32009-02-04 16:44:47 +0000532 OverloadCandidateSet& CandidateSet,
533 SourceRange OpRange = SourceRange());
Douglas Gregora11693b2008-11-12 17:17:38 +0000534 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
535 Expr **Args, unsigned NumArgs,
Douglas Gregorc5e61072009-01-13 00:52:54 +0000536 OverloadCandidateSet& CandidateSet,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000537 bool IsAssignmentOperator = false,
538 unsigned NumContextualBoolArguments = 0);
Douglas Gregord08452f2008-11-19 15:42:04 +0000539 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
540 Expr **Args, unsigned NumArgs,
541 OverloadCandidateSet& CandidateSet);
Douglas Gregore254f902009-02-04 00:32:51 +0000542 void AddArgumentDependentLookupCandidates(DeclarationName Name,
543 Expr **Args, unsigned NumArgs,
544 OverloadCandidateSet& CandidateSet);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000545 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
546 const OverloadCandidate& Cand2);
547 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
548 OverloadCandidateSet::iterator& Best);
549 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
550 bool OnlyViable);
551
Douglas Gregorcd695e52008-11-10 20:40:00 +0000552 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
553 bool Complain);
554 void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
555
Douglas Gregorb8a9a412009-02-04 15:01:18 +0000556 FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee,
557 DeclarationName UnqualifiedName,
Douglas Gregora60a6912008-11-26 06:01:48 +0000558 SourceLocation LParenLoc,
559 Expr **Args, unsigned NumArgs,
560 SourceLocation *CommaLocs,
Douglas Gregore254f902009-02-04 00:32:51 +0000561 SourceLocation RParenLoc,
Douglas Gregorb8a9a412009-02-04 15:01:18 +0000562 bool &ArgumentDependentLookup);
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000563 ExprResult
564 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
565 SourceLocation LParenLoc, Expr **Args,
566 unsigned NumArgs, SourceLocation *CommaLocs,
567 SourceLocation RParenLoc);
Douglas Gregor91cea0a2008-11-19 21:05:33 +0000568 ExprResult
Douglas Gregorb0846b02008-12-06 00:22:45 +0000569 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregor91cea0a2008-11-19 21:05:33 +0000570 Expr **Args, unsigned NumArgs,
571 SourceLocation *CommaLocs,
572 SourceLocation RParenLoc);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000573
Douglas Gregor55297ac2008-12-23 00:26:44 +0000574 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
Douglas Gregore0e79bd2008-11-20 16:27:02 +0000575 SourceLocation MemberLoc,
576 IdentifierInfo &Member);
Douglas Gregor5fb53972009-01-14 15:45:31 +0000577
Chris Lattnerce1da2c2009-01-06 07:27:21 +0000578 /// Helpers for dealing with function parameters.
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000579 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000580 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregorcaa8ace2008-05-07 04:49:29 +0000581 void CheckExtraCXXDefaultArguments(Declarator &D);
Steve Naroff6fbf0dc2007-03-16 00:33:25 +0000582
Douglas Gregor45a33ec2009-01-12 18:45:55 +0000583 Scope *getNonFieldDeclScope(Scope *S);
584
Douglas Gregor34074322009-01-14 22:20:51 +0000585 /// \name Name lookup
586 ///
587 /// These routines provide name lookup that is used during semantic
588 /// analysis to resolve the various kinds of names (identifiers,
589 /// overloaded operator names, constructor names, etc.) into zero or
590 /// more declarations within a particular scope. The major entry
591 /// points are LookupName, which performs unqualified name lookup,
592 /// and LookupQualifiedName, which performs qualified name lookup.
593 ///
594 /// All name lookup is performed based on some specific criteria,
595 /// which specify what names will be visible to name lookup and how
596 /// far name lookup should work. These criteria are important both
597 /// for capturing language semantics (certain lookups will ignore
598 /// certain names, for example) and for performance, since name
599 /// lookup is often a bottleneck in the compilation of C++. Name
Douglas Gregored8f2882009-01-30 01:04:22 +0000600 /// lookup criteria is specified via the LookupCriteria enumeration.
Douglas Gregor34074322009-01-14 22:20:51 +0000601 ///
602 /// The results of name lookup can vary based on the kind of name
603 /// lookup performed, the current language, and the translation
604 /// unit. In C, for example, name lookup will either return nothing
605 /// (no entity found) or a single declaration. In C++, name lookup
606 /// can additionally refer to a set of overloaded functions or
607 /// result in an ambiguity. All of the possible results of name
608 /// lookup are captured by the LookupResult class, which provides
609 /// the ability to distinguish among them.
610 //@{
Douglas Gregord7c4d982008-12-30 03:27:21 +0000611
Douglas Gregored8f2882009-01-30 01:04:22 +0000612 /// @brief Describes the kind of name lookup to perform.
613 enum LookupNameKind {
614 /// Ordinary name lookup, which finds ordinary names (functions,
615 /// variables, typedefs, etc.) in C and most kinds of names
616 /// (functions, variables, members, types, etc.) in C++.
617 LookupOrdinaryName = 0,
618 /// Tag name lookup, which finds the names of enums, classes,
619 /// structs, and unions.
620 LookupTagName,
621 /// Member name lookup, which finds the names of
622 /// class/struct/union members.
623 LookupMemberName,
Douglas Gregor94eabf32009-02-04 16:44:47 +0000624 // Look up of an operator name (e.g., operator+) for use with
625 // operator overloading. This lookup is similar to ordinary name
626 // lookup, but will ignore any declarations that are class
627 // members.
628 LookupOperatorName,
Douglas Gregored8f2882009-01-30 01:04:22 +0000629 /// Look up of a name that precedes the '::' scope resolution
630 /// operator in C++. This lookup completely ignores operator,
631 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
632 LookupNestedNameSpecifierName,
633 /// Look up a namespace name within a C++ using directive or
634 /// namespace alias definition, ignoring non-namespace names (C++
635 /// [basic.lookup.udir]p1).
Douglas Gregoreddf4332009-02-24 20:03:32 +0000636 LookupNamespaceName,
637 // Look up an ordinary name that is going to be redeclared as a
638 // name with linkage. This lookup ignores any declarations that
639 // are outside of the current scope unless they have linkage. See
640 // C99 6.2.2p4-5 and C++ [basic.link]p6.
641 LookupRedeclarationWithLinkage
Douglas Gregor34074322009-01-14 22:20:51 +0000642 };
643
644 /// @brief Represents the results of name lookup.
645 ///
646 /// An instance of the LookupResult class captures the results of a
647 /// single name lookup, which can return no result (nothing found),
648 /// a single declaration, a set of overloaded functions, or an
649 /// ambiguity. Use the getKind() method to determine which of these
650 /// results occurred for a given lookup.
651 ///
652 /// Any non-ambiguous lookup can be converted into a single
Douglas Gregor2ada0482009-02-04 17:27:36 +0000653 /// (possibly NULL) @c NamedDecl* via a conversion function or the
Douglas Gregor34074322009-01-14 22:20:51 +0000654 /// getAsDecl() method. This conversion permits the common-case
655 /// usage in C and Objective-C where name lookup will always return
656 /// a single declaration.
Douglas Gregorf23311d2009-01-17 01:13:24 +0000657 struct LookupResult {
Douglas Gregor34074322009-01-14 22:20:51 +0000658 /// The kind of entity that is actually stored within the
659 /// LookupResult object.
Douglas Gregorf23311d2009-01-17 01:13:24 +0000660 enum {
Douglas Gregor2ada0482009-02-04 17:27:36 +0000661 /// First is a single declaration (a NamedDecl*), which may be NULL.
Douglas Gregor34074322009-01-14 22:20:51 +0000662 SingleDecl,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000663
Douglas Gregor889ceb72009-02-03 19:21:40 +0000664 /// First is a single declaration (an OverloadedFunctionDecl*).
665 OverloadedDeclSingleDecl,
666
Douglas Gregor34074322009-01-14 22:20:51 +0000667 /// [First, Last) is an iterator range represented as opaque
668 /// pointers used to reconstruct IdentifierResolver::iterators.
669 OverloadedDeclFromIdResolver,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000670
Douglas Gregor34074322009-01-14 22:20:51 +0000671 /// [First, Last) is an iterator range represented as opaque
672 /// pointers used to reconstruct DeclContext::lookup_iterators.
673 OverloadedDeclFromDeclContext,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000674
675 /// First is a pointer to a BasePaths structure, which is owned
676 /// by the LookupResult. Last is non-zero to indicate that the
677 /// ambiguity is caused by two names found in base class
678 /// subobjects of different types.
Douglas Gregor889ceb72009-02-03 19:21:40 +0000679 AmbiguousLookupStoresBasePaths,
680
681 /// [First, Last) is an iterator range represented as opaque
682 /// pointers used to reconstruct new'ed Decl*[] array containing
683 /// found ambiguous decls. LookupResult is owner of this array.
684 AmbiguousLookupStoresDecls
685
Douglas Gregor34074322009-01-14 22:20:51 +0000686 } StoredKind;
687
688 /// The first lookup result, whose contents depend on the kind of
Douglas Gregor2ada0482009-02-04 17:27:36 +0000689 /// lookup result. This may be a NamedDecl* (if StoredKind ==
690 /// SingleDecl), OverloadedFunctionDecl* (if StoredKind ==
691 /// OverloadedDeclSingleDecl), the opaque pointer from an
Douglas Gregor34074322009-01-14 22:20:51 +0000692 /// IdentifierResolver::iterator (if StoredKind ==
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000693 /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator
694 /// (if StoredKind == OverloadedDeclFromDeclContext), or a
Douglas Gregor889ceb72009-02-03 19:21:40 +0000695 /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor34074322009-01-14 22:20:51 +0000696 mutable uintptr_t First;
697
698 /// The last lookup result, whose contents depend on the kind of
699 /// lookup result. This may be unused (if StoredKind ==
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000700 /// SingleDecl), it may have the same type as First (for
701 /// overloaded function declarations), or is may be used as a
Douglas Gregor889ceb72009-02-03 19:21:40 +0000702 /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor34074322009-01-14 22:20:51 +0000703 mutable uintptr_t Last;
704
705 /// Context - The context in which we will build any
706 /// OverloadedFunctionDecl nodes needed by the conversion to
707 /// Decl*.
708 ASTContext *Context;
709
Douglas Gregor34074322009-01-14 22:20:51 +0000710 /// @brief The kind of entity found by name lookup.
711 enum LookupKind {
712 /// @brief No entity found met the criteria.
713 NotFound = 0,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000714
Douglas Gregor34074322009-01-14 22:20:51 +0000715 /// @brief Name lookup found a single declaration that met the
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000716 /// criteria. getAsDecl will return this declaration.
Douglas Gregor34074322009-01-14 22:20:51 +0000717 Found,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000718
Douglas Gregor34074322009-01-14 22:20:51 +0000719 /// @brief Name lookup found a set of overloaded functions that
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000720 /// met the criteria. getAsDecl will turn this set of overloaded
721 /// functions into an OverloadedFunctionDecl.
Douglas Gregor34074322009-01-14 22:20:51 +0000722 FoundOverloaded,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000723
724 /// Name lookup results in an ambiguity because multiple
725 /// entities that meet the lookup criteria were found in
726 /// subobjects of different types. For example:
727 /// @code
728 /// struct A { void f(int); }
729 /// struct B { void f(double); }
730 /// struct C : A, B { };
731 /// void test(C c) {
732 /// c.f(0); // error: A::f and B::f come from subobjects of different
733 /// // types. overload resolution is not performed.
734 /// }
735 /// @endcode
736 AmbiguousBaseSubobjectTypes,
737
738 /// Name lookup results in an ambiguity because multiple
739 /// nonstatic entities that meet the lookup criteria were found
740 /// in different subobjects of the same type. For example:
741 /// @code
742 /// struct A { int x; };
743 /// struct B : A { };
744 /// struct C : A { };
745 /// struct D : B, C { };
746 /// int test(D d) {
747 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
748 /// }
749 /// @endcode
Douglas Gregor889ceb72009-02-03 19:21:40 +0000750 AmbiguousBaseSubobjects,
751
752 /// Name lookup results in an ambiguity because multiple definitions
753 /// of entity that meet the lookup criteria were found in different
754 /// declaration contexts.
755 /// @code
756 /// namespace A {
757 /// int i;
758 /// namespace B { int i; }
759 /// int test() {
760 /// using namespace B;
761 /// return i; // error 'i' is found in namespace A and A::B
762 /// }
763 /// }
764 /// @endcode
765 AmbiguousReference
Douglas Gregor34074322009-01-14 22:20:51 +0000766 };
767
Douglas Gregor2ada0482009-02-04 17:27:36 +0000768 static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D);
Douglas Gregor41c8ba82009-01-15 02:19:31 +0000769
Douglas Gregorf23311d2009-01-17 01:13:24 +0000770 static LookupResult CreateLookupResult(ASTContext &Context,
771 IdentifierResolver::iterator F,
772 IdentifierResolver::iterator L);
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000773
Douglas Gregorf23311d2009-01-17 01:13:24 +0000774 static LookupResult CreateLookupResult(ASTContext &Context,
775 DeclContext::lookup_iterator F,
776 DeclContext::lookup_iterator L);
Douglas Gregor34074322009-01-14 22:20:51 +0000777
Douglas Gregorf23311d2009-01-17 01:13:24 +0000778 static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths,
779 bool DifferentSubobjectTypes) {
780 LookupResult Result;
Douglas Gregor889ceb72009-02-03 19:21:40 +0000781 Result.StoredKind = AmbiguousLookupStoresBasePaths;
Douglas Gregorf23311d2009-01-17 01:13:24 +0000782 Result.First = reinterpret_cast<uintptr_t>(Paths);
783 Result.Last = DifferentSubobjectTypes? 1 : 0;
784 Result.Context = &Context;
785 return Result;
786 }
Douglas Gregor41c8ba82009-01-15 02:19:31 +0000787
Douglas Gregor889ceb72009-02-03 19:21:40 +0000788 template <typename Iterator>
789 static LookupResult CreateLookupResult(ASTContext &Context,
790 Iterator B, std::size_t Len) {
Douglas Gregor2ada0482009-02-04 17:27:36 +0000791 NamedDecl ** Array = new NamedDecl*[Len];
Douglas Gregor889ceb72009-02-03 19:21:40 +0000792 for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B)
793 Array[Idx] = *B;
794 LookupResult Result;
795 Result.StoredKind = AmbiguousLookupStoresDecls;
796 Result.First = reinterpret_cast<uintptr_t>(Array);
797 Result.Last = reinterpret_cast<uintptr_t>(Array + Len);
798 Result.Context = &Context;
799 return Result;
800 }
801
Douglas Gregor34074322009-01-14 22:20:51 +0000802 LookupKind getKind() const;
803
804 /// @brief Determine whether name look found something.
805 operator bool() const { return getKind() != NotFound; }
806
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000807 /// @brief Determines whether the lookup resulted in an ambiguity.
Douglas Gregor889ceb72009-02-03 19:21:40 +0000808 bool isAmbiguous() const {
809 return StoredKind == AmbiguousLookupStoresBasePaths ||
810 StoredKind == AmbiguousLookupStoresDecls;
811 }
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000812
Douglas Gregor34074322009-01-14 22:20:51 +0000813 /// @brief Allows conversion of a lookup result into a
814 /// declaration, with the same behavior as getAsDecl.
Douglas Gregor2ada0482009-02-04 17:27:36 +0000815 operator NamedDecl*() const { return getAsDecl(); }
Douglas Gregor34074322009-01-14 22:20:51 +0000816
Douglas Gregor2ada0482009-02-04 17:27:36 +0000817 NamedDecl* getAsDecl() const;
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000818
819 BasePaths *getBasePaths() const;
Douglas Gregor0e8fc3c2009-02-02 21:35:47 +0000820
821 /// \brief Iterate over the results of name lookup.
822 ///
823 /// The @c iterator class provides iteration over the results of a
824 /// non-ambiguous name lookup.
825 class iterator {
826 /// The LookupResult structure we're iterating through.
827 LookupResult *Result;
828
829 /// The current position of this iterator within the sequence of
830 /// results. This value will have the same representation as the
831 /// @c First field in the LookupResult structure.
832 mutable uintptr_t Current;
833
834 public:
Douglas Gregor2ada0482009-02-04 17:27:36 +0000835 typedef NamedDecl * value_type;
836 typedef NamedDecl * reference;
837 typedef NamedDecl * pointer;
Douglas Gregor0e8fc3c2009-02-02 21:35:47 +0000838 typedef std::ptrdiff_t difference_type;
839 typedef std::forward_iterator_tag iterator_category;
840
841 iterator() : Result(0), Current(0) { }
842
843 iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { }
844
845 reference operator*() const;
846
847 pointer operator->() const { return **this; }
848
849 iterator &operator++();
850
851 iterator operator++(int) {
852 iterator tmp(*this);
853 ++(*this);
854 return tmp;
855 }
856
857 friend inline bool operator==(iterator const& x, iterator const& y) {
858 return x.Current == y.Current;
859 }
860
861 friend inline bool operator!=(iterator const& x, iterator const& y) {
862 return x.Current != y.Current;
863 }
864 };
865 friend class iterator;
866
867 iterator begin();
868 iterator end();
Douglas Gregor34074322009-01-14 22:20:51 +0000869 };
870
Douglas Gregor889ceb72009-02-03 19:21:40 +0000871private:
872 typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy;
873
874 std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name,
875 LookupNameKind NameKind,
876 bool RedeclarationOnly);
877
878public:
Douglas Gregored8f2882009-01-30 01:04:22 +0000879 /// Determines whether D is a suitable lookup result according to the
880 /// lookup criteria.
Douglas Gregoreddf4332009-02-24 20:03:32 +0000881 static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind,
Douglas Gregor700792c2009-02-05 19:25:20 +0000882 unsigned IDNS) {
Douglas Gregored8f2882009-01-30 01:04:22 +0000883 switch (NameKind) {
884 case Sema::LookupOrdinaryName:
885 case Sema::LookupTagName:
886 case Sema::LookupMemberName:
Douglas Gregoreddf4332009-02-24 20:03:32 +0000887 case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
Douglas Gregored8f2882009-01-30 01:04:22 +0000888 return D->isInIdentifierNamespace(IDNS);
889
Douglas Gregor94eabf32009-02-04 16:44:47 +0000890 case Sema::LookupOperatorName:
891 return D->isInIdentifierNamespace(IDNS) &&
892 !D->getDeclContext()->isRecord();
893
Douglas Gregored8f2882009-01-30 01:04:22 +0000894 case Sema::LookupNestedNameSpecifierName:
895 return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag);
896
897 case Sema::LookupNamespaceName:
898 return isa<NamespaceDecl>(D);
899 }
900
901 assert(false &&
Douglas Gregor700792c2009-02-05 19:25:20 +0000902 "isAcceptableLookupResult always returns before this point");
Douglas Gregored8f2882009-01-30 01:04:22 +0000903 return false;
904 }
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000905
Douglas Gregored8f2882009-01-30 01:04:22 +0000906 LookupResult LookupName(Scope *S, DeclarationName Name,
907 LookupNameKind NameKind,
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000908 bool RedeclarationOnly = false,
909 bool AllowBuiltinCreation = true,
910 SourceLocation Loc = SourceLocation());
Douglas Gregored8f2882009-01-30 01:04:22 +0000911 LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name,
912 LookupNameKind NameKind,
913 bool RedeclarationOnly = false);
914 LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS,
915 DeclarationName Name,
916 LookupNameKind NameKind,
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000917 bool RedeclarationOnly = false,
918 bool AllowBuiltinCreation = true,
919 SourceLocation Loc = SourceLocation());
Douglas Gregore254f902009-02-04 00:32:51 +0000920
921 typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet;
922 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
923
924 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
925 AssociatedNamespaceSet &AssociatedNamespaces,
926 AssociatedClassSet &AssociatedClasses);
927
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000928 bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
929 SourceLocation NameLoc,
930 SourceRange LookupRange = SourceRange());
Douglas Gregor34074322009-01-14 22:20:51 +0000931 //@}
932
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000933 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000934 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000935 Scope *S, bool ForRedeclaration,
936 SourceLocation Loc);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000937 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
938 Scope *S);
Douglas Gregore711f702009-02-14 18:57:46 +0000939 void AddKnownFunctionAttributes(FunctionDecl *FD);
Douglas Gregor34074322009-01-14 22:20:51 +0000940
941 // More parsing and symbol table subroutines.
942
Steve Naroffa8fd9732007-06-11 00:35:03 +0000943 // Decl attributes - this routine is the top level dispatcher.
Chris Lattner58418ff2008-06-29 00:16:31 +0000944 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnera5741542008-06-28 23:58:55 +0000945 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lamb025b5fb2008-02-04 02:31:56 +0000946
Steve Naroff15833ed2008-02-10 21:38:56 +0000947 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
948 bool &IncompleteImpl);
Fariborz Jahanian7988d7d2008-12-05 18:18:52 +0000949 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
950 ObjCMethodDecl *IntfMethod);
Sebastian Redlc4704762008-11-11 11:37:55 +0000951
952 NamespaceDecl *GetStdNamespace();
Fariborz Jahanian8e1555c2009-01-12 19:55:42 +0000953
954 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
Steve Naroffde680012009-02-26 19:11:32 +0000955 ObjCInterfaceDecl *IDecl);
Steve Naroff15833ed2008-02-10 21:38:56 +0000956
Chris Lattnerce1da2c2009-01-06 07:27:21 +0000957 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbarc7dfbfd2008-09-04 20:01:15 +0000958 /// methods declared in protocol, and those referenced by it.
959 /// \param IDecl - Used for checking for methods which may have been
960 /// inherited.
Steve Naroffa36992242008-02-08 22:06:17 +0000961 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
962 ObjCProtocolDecl *PDecl,
Fariborz Jahanianadf84f32007-10-02 20:06:01 +0000963 bool& IncompleteImpl,
Steve Naroff71c3c1c2007-10-08 21:05:34 +0000964 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbarc7dfbfd2008-09-04 20:01:15 +0000965 const llvm::DenseSet<Selector> &ClsMap,
966 ObjCInterfaceDecl *IDecl);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000967
Steve Naroffd1741552007-10-02 21:43:37 +0000968 /// CheckImplementationIvars - This routine checks if the instance variables
969 /// listed in the implelementation match those listed in the interface.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000970 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
971 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff15833ed2008-02-10 21:38:56 +0000972 SourceLocation Loc);
Steve Naroffd1741552007-10-02 21:43:37 +0000973
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000974 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
Chris Lattner9ef10f42009-03-01 00:56:52 +0000975 /// remains unimplemented in the class or category @implementation.
976 void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl,
977 ObjCContainerDecl* IDecl,
978 bool IncompleteImpl = false);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000979
Fariborz Jahanian458f7112007-10-05 18:00:57 +0000980 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
981 /// true, or false, accordingly.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000982 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Naroffa0ed1652008-10-21 10:37:50 +0000983 const ObjCMethodDecl *PrevMethod,
984 bool matchBasedOnSizeAndAlignment = false);
Steve Naroff7f549f12007-10-10 21:53:07 +0000985
Steve Naroff5811baf2007-10-14 00:58:41 +0000986 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
987 /// unit are added to a global pool. This allows us to efficiently associate
988 /// a selector with a method declaraation for purposes of typechecking
989 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000990 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff5811baf2007-10-14 00:58:41 +0000991
Steve Naroff4a82d812008-09-30 14:38:43 +0000992 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
993 /// there are multiple signatures.
994 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
995
Steve Naroff5811baf2007-10-14 00:58:41 +0000996 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000997 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000998 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000999 // Statement Parsing Callbacks: SemaStmt.cpp.
Steve Naroff3273c222007-03-14 21:52:03 +00001000public:
Sebastian Redl52f03ba2008-12-21 12:04:03 +00001001 virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
1002
1003 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
1004 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1005 MultiStmtArg Elts,
1006 bool isStmtExpr);
1007 virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
1008 SourceLocation EndLoc);
Sebastian Redl1cbb59182008-12-28 16:13:43 +00001009 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
1010 SourceLocation DotDotDotLoc, ExprArg RHSVal,
Chris Lattner34a22092009-03-04 04:23:07 +00001011 SourceLocation ColonLoc);
1012 virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt);
1013
Sebastian Redl1cbb59182008-12-28 16:13:43 +00001014 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1015 SourceLocation ColonLoc,
1016 StmtArg SubStmt, Scope *CurScope);
Sebastian Redl6a8002e2009-01-11 00:38:46 +00001017 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
1018 IdentifierInfo *II,
1019 SourceLocation ColonLoc,
1020 StmtArg SubStmt);
1021 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
1022 StmtArg ThenVal, SourceLocation ElseLoc,
1023 StmtArg ElseVal);
1024 virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
1025 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1026 StmtArg Switch, StmtArg Body);
Sebastian Redlfbfaafc2009-01-16 23:28:06 +00001027 virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
1028 StmtArg Body);
1029 virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
1030 SourceLocation WhileLoc, ExprArg Cond);
1031
1032 virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
1033 SourceLocation LParenLoc,
1034 StmtArg First, ExprArg Second,
1035 ExprArg Third, SourceLocation RParenLoc,
1036 StmtArg Body);
1037 virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1038 SourceLocation LParenLoc,
1039 StmtArg First, ExprArg Second,
1040 SourceLocation RParenLoc, StmtArg Body);
Sebastian Redl573feed2009-01-18 13:19:59 +00001041
1042 virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1043 SourceLocation LabelLoc,
1044 IdentifierInfo *LabelII);
1045 virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1046 SourceLocation StarLoc,
1047 ExprArg DestExp);
1048 virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
1049 Scope *CurScope);
1050 virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
1051 Scope *CurScope);
1052
1053 virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
1054 ExprArg RetValExp);
1055 OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
1056 Expr *RetValExp);
1057
Sebastian Redl24b8e152009-01-18 16:53:17 +00001058 virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1059 bool IsSimple,
1060 bool IsVolatile,
1061 unsigned NumOutputs,
1062 unsigned NumInputs,
1063 std::string *Names,
1064 MultiExprArg Constraints,
1065 MultiExprArg Exprs,
1066 ExprArg AsmString,
1067 MultiExprArg Clobbers,
1068 SourceLocation RParenLoc);
Sebastian Redl481bf3f2009-01-18 17:43:11 +00001069
1070 virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
1071 SourceLocation RParen,
Steve Naroff371b8fb2009-03-03 19:52:17 +00001072 DeclTy *Parm, StmtArg Body,
Sebastian Redl481bf3f2009-01-18 17:43:11 +00001073 StmtArg CatchList);
1074
1075 virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
1076 StmtArg Body);
1077
1078 virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
1079 StmtArg Try,
1080 StmtArg Catch, StmtArg Finally);
1081
1082 virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Steve Naroff5ee2c022009-02-11 20:05:44 +00001083 ExprArg Throw,
1084 Scope *CurScope);
Sebastian Redl481bf3f2009-01-18 17:43:11 +00001085 virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1086 ExprArg SynchExpr,
1087 StmtArg SynchBody);
Sebastian Redlb219c902008-12-21 16:41:36 +00001088
Sebastian Redl54c04d42008-12-22 19:15:10 +00001089 virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D);
1090 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
1091 DeclTy *ExDecl,
1092 StmtArg HandlerBlock);
Sebastian Redl9b244a82008-12-22 21:35:02 +00001093 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
1094 StmtArg TryBlock,
1095 MultiStmtArg Handlers);
Sebastian Redlb219c902008-12-21 16:41:36 +00001096
Chris Lattner7cee11f2006-11-03 06:42:29 +00001097 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +00001098 // Expression Parsing Callbacks: SemaExpr.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +00001099
Douglas Gregor171c45a2009-02-18 21:56:37 +00001100 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
Chris Lattner4bf74fd2009-02-15 22:43:40 +00001101
Chris Lattner7cee11f2006-11-03 06:42:29 +00001102 // Primary Expressions.
Douglas Gregor87f95b02009-02-26 21:00:50 +00001103 virtual SourceRange getExprRange(ExprTy *E) const;
1104
Sebastian Redlffbcf962009-01-18 18:53:16 +00001105 virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
1106 IdentifierInfo &II,
1107 bool HasTrailingLParen,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001108 const CXXScopeSpec *SS = 0,
1109 bool isAddressOfOperand = false);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001110 virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S,
Douglas Gregor7911b372008-11-19 19:09:45 +00001111 SourceLocation OperatorLoc,
1112 OverloadedOperatorKind Op,
1113 bool HasTrailingLParen,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001114 const CXXScopeSpec &SS,
1115 bool isAddressOfOperand);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001116 virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S,
Douglas Gregor7911b372008-11-19 19:09:45 +00001117 SourceLocation OperatorLoc,
1118 TypeTy *Ty,
1119 bool HasTrailingLParen,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001120 const CXXScopeSpec &SS,
1121 bool isAddressOfOperand);
Douglas Gregorc7acfdf2009-01-06 05:10:23 +00001122 DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
1123 bool TypeDependent, bool ValueDependent,
1124 const CXXScopeSpec *SS = 0);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001125 OwningExprResult
Douglas Gregor9ac7a072009-01-07 00:43:41 +00001126 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1127 FieldDecl *Field,
1128 Expr *BaseObjectExpr = 0,
1129 SourceLocation OpLoc = SourceLocation());
Sebastian Redlffbcf962009-01-18 18:53:16 +00001130 OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
1131 DeclarationName Name,
1132 bool HasTrailingLParen,
1133 const CXXScopeSpec *SS,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001134 bool isAddressOfOperand = false);
Douglas Gregor4ea80432008-11-18 15:03:34 +00001135
Sebastian Redlffbcf962009-01-18 18:53:16 +00001136 virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
1137 tok::TokenKind Kind);
1138 virtual OwningExprResult ActOnNumericConstant(const Token &);
1139 virtual OwningExprResult ActOnCharacterConstant(const Token &);
1140 virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
1141 ExprArg Val);
Chris Lattner697e5d62006-11-09 06:32:27 +00001142
Steve Naroff83895f72007-09-16 03:34:24 +00001143 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner697e5d62006-11-09 06:32:27 +00001144 /// fragments (e.g. "foo" "bar" L"baz").
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001145 virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
1146 unsigned NumToks);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001147
Chris Lattner7cee11f2006-11-03 06:42:29 +00001148 // Binary/Unary Operators. 'Tok' is the token for the operator.
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001149 virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1150 tok::TokenKind Op, ExprArg Input);
1151 virtual OwningExprResult
Sebastian Redl6f282892008-11-11 17:56:53 +00001152 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1153 void *TyOrEx, const SourceRange &ArgRange);
1154
Chris Lattner8dff0172009-01-24 20:17:12 +00001155 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R);
Sebastian Redl6f282892008-11-11 17:56:53 +00001156 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1157 const SourceRange &R, bool isSizeof);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001158
1159 virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1160 tok::TokenKind Kind,
1161 ExprArg Input);
1162
1163 virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
1164 SourceLocation LLoc,
1165 ExprArg Idx,
1166 SourceLocation RLoc);
1167 virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base,
1168 SourceLocation OpLoc,
1169 tok::TokenKind OpKind,
1170 SourceLocation MemberLoc,
Fariborz Jahanianb8d091c2009-03-04 22:30:12 +00001171 IdentifierInfo &Member,
1172 DeclTy *ImplDecl=0);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001173 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
Douglas Gregor97fd6e22008-12-22 05:46:06 +00001174 FunctionDecl *FDecl,
Douglas Gregordeaad8c2009-02-26 23:50:07 +00001175 const FunctionProtoType *Proto,
Douglas Gregor97fd6e22008-12-22 05:46:06 +00001176 Expr **Args, unsigned NumArgs,
1177 SourceLocation RParenLoc);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001178
Steve Naroff83895f72007-09-16 03:34:24 +00001179 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner7cee11f2006-11-03 06:42:29 +00001180 /// This provides the location of the left/right parens and a list of comma
1181 /// locations.
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001182 virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn,
1183 SourceLocation LParenLoc,
1184 MultiExprArg Args,
1185 SourceLocation *CommaLocs,
1186 SourceLocation RParenLoc);
1187
Sebastian Redlb5d49352009-01-19 22:31:54 +00001188 virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
1189 SourceLocation RParenLoc, ExprArg Op);
1190
1191 virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1192 TypeTy *Ty,
1193 SourceLocation RParenLoc,
1194 ExprArg Op);
1195
1196 virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
1197 MultiExprArg InitList,
1198 InitListDesignations &Designators,
1199 SourceLocation RParenLoc);
1200
Douglas Gregore4a0bb72009-01-22 00:58:24 +00001201 virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
1202 SourceLocation Loc,
1203 bool UsedColonSyntax,
1204 OwningExprResult Init);
1205
Sebastian Redlb5d49352009-01-19 22:31:54 +00001206 virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1207 tok::TokenKind Kind,
1208 ExprArg LHS, ExprArg RHS);
1209 OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1210 unsigned Opc, Expr *lhs, Expr *rhs);
Douglas Gregor7d5fc7e2008-11-06 23:29:22 +00001211
Steve Naroff83895f72007-09-16 03:34:24 +00001212 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner7cee11f2006-11-03 06:42:29 +00001213 /// in the case of a the GNU conditional expr extension.
Sebastian Redlb5d49352009-01-19 22:31:54 +00001214 virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1215 SourceLocation ColonLoc,
1216 ExprArg Cond, ExprArg LHS,
1217 ExprArg RHS);
Chris Lattner29375652006-12-04 18:06:35 +00001218
Steve Naroff66356bd2007-09-16 14:56:35 +00001219 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1220 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Chris Lattnereefa10e2007-05-28 06:56:27 +00001221 IdentifierInfo *LabelII);
1222
Steve Naroff66356bd2007-09-16 14:56:35 +00001223 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattner366727f2007-07-24 16:58:17 +00001224 SourceLocation RPLoc); // "({..})"
Chris Lattnerf17bd422007-08-30 17:45:32 +00001225
1226 /// __builtin_offsetof(type, a.b[123][456].c)
Douglas Gregor55297ac2008-12-23 00:26:44 +00001227 virtual ExprResult ActOnBuiltinOffsetOf(Scope *S,
1228 SourceLocation BuiltinLoc,
Chris Lattnerf17bd422007-08-30 17:45:32 +00001229 SourceLocation TypeLoc, TypeTy *Arg1,
1230 OffsetOfComponent *CompPtr,
1231 unsigned NumComponents,
1232 SourceLocation RParenLoc);
1233
Steve Naroff78864672007-08-01 22:05:33 +00001234 // __builtin_types_compatible_p(type1, type2)
Steve Naroff66356bd2007-09-16 14:56:35 +00001235 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff78864672007-08-01 22:05:33 +00001236 TypeTy *arg1, TypeTy *arg2,
1237 SourceLocation RPLoc);
Steve Naroff9efdabc2007-08-03 21:21:27 +00001238
1239 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff66356bd2007-09-16 14:56:35 +00001240 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroff9efdabc2007-08-03 21:21:27 +00001241 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
1242 SourceLocation RPLoc);
Chris Lattner366727f2007-07-24 16:58:17 +00001243
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001244 // __builtin_va_arg(expr, type)
1245 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1246 ExprTy *expr, TypeTy *type,
1247 SourceLocation RPLoc);
Steve Naroffc540d662008-09-03 18:15:37 +00001248
Douglas Gregor3be4b122008-11-29 04:51:27 +00001249 // __null
1250 virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1251
Steve Naroffc540d662008-09-03 18:15:37 +00001252 //===------------------------- "Block" Extension ------------------------===//
1253
1254 /// ActOnBlockStart - This callback is invoked when a block literal is
1255 /// started.
Steve Naroff1d95e5a2008-10-10 01:28:17 +00001256 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1257
1258 /// ActOnBlockArguments - This callback allows processing of block arguments.
1259 /// If there are no arguments, this is still invoked.
Mike Stump82f071f2009-02-04 22:31:32 +00001260 virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
Steve Naroffc540d662008-09-03 18:15:37 +00001261
1262 /// ActOnBlockError - If there is an error parsing a block, this callback
1263 /// is invoked to pop the information about the block from the action impl.
1264 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1265
1266 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1267 /// literal was successfully completed. ^(int x){...}
1268 virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
1269 Scope *CurScope);
1270
Chris Lattner4bf74fd2009-02-15 22:43:40 +00001271 //===---------------------------- C++ Features --------------------------===//
1272
Argyrios Kyrtzidis08114892008-04-27 13:50:30 +00001273 // Act on C++ namespaces
1274 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
1275 IdentifierInfo *Ident,
1276 SourceLocation LBrace);
1277 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
1278
Douglas Gregord7c4d982008-12-30 03:27:21 +00001279 virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
1280 SourceLocation UsingLoc,
1281 SourceLocation NamespcLoc,
1282 const CXXScopeSpec &SS,
1283 SourceLocation IdentLoc,
1284 IdentifierInfo *NamespcName,
1285 AttributeList *AttrList);
1286
Douglas Gregor889ceb72009-02-03 19:21:40 +00001287 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
1288
Argyrios Kyrtzidis9a1191c2008-10-06 17:10:33 +00001289 /// AddCXXDirectInitializerToDecl - This action is called immediately after
1290 /// ActOnDeclarator, when a C++ direct initializer is present.
1291 /// e.g: "int x(1);"
1292 virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
1293 SourceLocation LParenLoc,
1294 ExprTy **Exprs, unsigned NumExprs,
1295 SourceLocation *CommaLocs,
1296 SourceLocation RParenLoc);
1297
Douglas Gregor6f543152008-11-05 15:29:30 +00001298 /// InitializationKind - Represents which kind of C++ initialization
1299 /// [dcl.init] a routine is to perform.
1300 enum InitializationKind {
1301 IK_Direct, ///< Direct initialization
1302 IK_Copy, ///< Copy initialization
1303 IK_Default ///< Default initialization
1304 };
1305
Douglas Gregorc28b57d2008-11-03 20:45:27 +00001306 CXXConstructorDecl *
Douglas Gregor6f543152008-11-05 15:29:30 +00001307 PerformInitializationByConstructor(QualType ClassType,
1308 Expr **Args, unsigned NumArgs,
1309 SourceLocation Loc, SourceRange Range,
Chris Lattnerf3d3fae2008-11-24 05:29:24 +00001310 DeclarationName InitEntity,
Douglas Gregor6f543152008-11-05 15:29:30 +00001311 InitializationKind Kind);
Douglas Gregorc28b57d2008-11-03 20:45:27 +00001312
Douglas Gregore200adc2008-10-27 19:41:14 +00001313 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
1314 virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
1315 SourceLocation LAngleBracketLoc, TypeTy *Ty,
1316 SourceLocation RAngleBracketLoc,
1317 SourceLocation LParenLoc, ExprTy *E,
1318 SourceLocation RParenLoc);
Bill Wendling4073ed52007-02-13 01:51:42 +00001319
Sebastian Redlc4704762008-11-11 11:37:55 +00001320 /// ActOnCXXTypeidOfType - Parse typeid( type-id ).
1321 virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
1322 SourceLocation LParenLoc, bool isType,
1323 void *TyOrExpr, SourceLocation RParenLoc);
1324
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001325 //// ActOnCXXThis - Parse 'this' pointer.
1326 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
1327
Steve Naroff66356bd2007-09-16 14:56:35 +00001328 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
1329 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Bill Wendlingbf313b02007-02-13 20:09:46 +00001330 tok::TokenKind Kind);
Anders Carlsson76f4a902007-08-21 17:43:55 +00001331
Chris Lattnerb7e656b2008-02-26 00:51:44 +00001332 //// ActOnCXXThrow - Parse throw expressions.
1333 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
1334 ExprTy *expr);
1335
Argyrios Kyrtzidis857fcc22008-08-22 15:38:55 +00001336 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
1337 /// Can be interpreted either as function-style casting ("int(x)")
1338 /// or class type construction ("ClassType(x,y,z)")
1339 /// or creation of a value-initialized type ("int()").
1340 virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
1341 TypeTy *TypeRep,
1342 SourceLocation LParenLoc,
1343 ExprTy **Exprs,
1344 unsigned NumExprs,
1345 SourceLocation *CommaLocs,
1346 SourceLocation RParenLoc);
1347
Sebastian Redlbd150f42008-11-21 19:14:01 +00001348 /// ActOnCXXNew - Parsed a C++ 'new' expression.
1349 virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1350 SourceLocation PlacementLParen,
1351 ExprTy **PlacementArgs, unsigned NumPlaceArgs,
1352 SourceLocation PlacementRParen,
Sebastian Redl351bb782008-12-02 14:43:59 +00001353 bool ParenTypeId, Declarator &D,
Sebastian Redlbd150f42008-11-21 19:14:01 +00001354 SourceLocation ConstructorLParen,
1355 ExprTy **ConstructorArgs, unsigned NumConsArgs,
1356 SourceLocation ConstructorRParen);
Sebastian Redl351bb782008-12-02 14:43:59 +00001357 bool CheckAllocatedType(QualType AllocType, const Declarator &D);
Sebastian Redl1df2bbe2009-02-09 18:24:27 +00001358 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
1359 bool UseGlobal, QualType AllocType, bool IsArray,
Sebastian Redlfaf68082008-12-03 20:26:15 +00001360 Expr **PlaceArgs, unsigned NumPlaceArgs,
1361 FunctionDecl *&OperatorNew,
1362 FunctionDecl *&OperatorDelete);
Sebastian Redl1df2bbe2009-02-09 18:24:27 +00001363 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
1364 DeclarationName Name, Expr** Args,
1365 unsigned NumArgs, DeclContext *Ctx,
Sebastian Redl33a31012008-12-04 22:20:51 +00001366 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlfaf68082008-12-03 20:26:15 +00001367 void DeclareGlobalNewDelete();
1368 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
1369 QualType Argument);
Sebastian Redlbd150f42008-11-21 19:14:01 +00001370
1371 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
1372 virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
1373 bool ArrayForm, ExprTy *Operand);
1374
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +00001375 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
1376 /// C++ if/switch/while/for statement.
1377 /// e.g: "if (int x = f()) {...}"
1378 virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
1379 SourceLocation StartLoc,
1380 Declarator &D,
1381 SourceLocation EqualLoc,
1382 ExprTy *AssignExprVal);
1383
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001384 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
1385 /// pseudo-functions.
1386 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
1387 SourceLocation KWLoc,
1388 SourceLocation LParen,
1389 TypeTy *Ty,
1390 SourceLocation RParen);
1391
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001392 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
1393 /// global scope ('::').
1394 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
1395 SourceLocation CCLoc);
1396
1397 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1398 /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now
1399 /// we want to resolve "bar::". 'SS' is empty or the previously parsed
1400 /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar',
1401 /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'.
1402 /// Returns a CXXScopeTy* object representing the C++ scope.
1403 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1404 const CXXScopeSpec &SS,
1405 SourceLocation IdLoc,
1406 SourceLocation CCLoc,
Douglas Gregorae2fbad2008-11-17 20:34:05 +00001407 IdentifierInfo &II);
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001408
Douglas Gregor7f741122009-02-25 19:37:18 +00001409 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1410 /// nested-name-specifier that involves a template-id, e.g.,
1411 /// "foo::bar<int, float>::", and now we need to build a scope
1412 /// specifier. \p SS is empty or the previously parsed nested-name
1413 /// part ("foo::"), \p Type is the already-parsed class template
1414 /// specialization (or other template-id that names a type), \p
1415 /// TypeRange is the source range where the type is located, and \p
1416 /// CCLoc is the location of the trailing '::'.
1417 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1418 const CXXScopeSpec &SS,
1419 TypeTy *Type,
1420 SourceRange TypeRange,
1421 SourceLocation CCLoc);
1422
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001423 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1424 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1425 /// After this method is called, according to [C++ 3.4.3p3], names should be
1426 /// looked up in the declarator-id's scope, until the declarator is parsed and
1427 /// ActOnCXXExitDeclaratorScope is called.
1428 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1429 virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
1430
1431 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1432 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1433 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1434 /// Used to indicate that names should revert to being looked up in the
1435 /// defining scope.
Douglas Gregor29e174c2008-12-16 00:38:16 +00001436 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001437
Anders Carlsson76f4a902007-08-21 17:43:55 +00001438 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnere002fbe2007-12-12 01:04:12 +00001439 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
1440 ExprTy **Strings,
1441 unsigned NumStrings);
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001442 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner37390be2007-10-16 22:51:17 +00001443 SourceLocation EncodeLoc,
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001444 SourceLocation LParenLoc,
1445 TypeTy *Ty,
1446 SourceLocation RParenLoc);
1447
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001448 // ParseObjCSelectorExpression - Build selector expression for @selector
1449 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
1450 SourceLocation AtLoc,
Fariborz Jahanian6bd1d612007-10-16 23:21:02 +00001451 SourceLocation SelLoc,
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001452 SourceLocation LParenLoc,
1453 SourceLocation RParenLoc);
1454
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001455 // ParseObjCProtocolExpression - Build protocol expression for @protocol
1456 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
1457 SourceLocation AtLoc,
1458 SourceLocation ProtoLoc,
1459 SourceLocation LParenLoc,
1460 SourceLocation RParenLoc);
Douglas Gregor556877c2008-04-13 21:30:24 +00001461
1462 //===--------------------------------------------------------------------===//
Douglas Gregor07665a62009-01-05 19:45:36 +00001463 // C++ Declarations
1464 //
1465 virtual DeclTy *ActOnStartLinkageSpecification(Scope *S,
1466 SourceLocation ExternLoc,
1467 SourceLocation LangLoc,
1468 const char *Lang,
1469 unsigned StrSize,
1470 SourceLocation LBraceLoc);
1471 virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S,
1472 DeclTy *LinkageSpec,
1473 SourceLocation RBraceLoc);
1474
1475
1476 //===--------------------------------------------------------------------===//
Douglas Gregor556877c2008-04-13 21:30:24 +00001477 // C++ Classes
1478 //
Argyrios Kyrtzidis32a03792008-11-08 16:45:02 +00001479 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
1480 const CXXScopeSpec *SS);
Douglas Gregor61956c42008-10-31 09:07:45 +00001481
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001482 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
1483 Declarator &D, ExprTy *BitfieldWidth,
1484 ExprTy *Init, DeclTy *LastInGroup);
1485
Douglas Gregore8381c02008-11-05 04:29:56 +00001486 virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD,
1487 Scope *S,
1488 IdentifierInfo *MemberOrBase,
1489 SourceLocation IdLoc,
1490 SourceLocation LParenLoc,
1491 ExprTy **Args, unsigned NumArgs,
1492 SourceLocation *CommaLocs,
1493 SourceLocation RParenLoc);
1494
Douglas Gregor05379422008-11-03 17:51:48 +00001495 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
1496
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001497 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
1498 DeclTy *TagDecl,
1499 SourceLocation LBrac,
1500 SourceLocation RBrac);
1501
Douglas Gregor4d87df52008-12-16 21:30:33 +00001502 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1503 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param);
1504 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1505
Douglas Gregor831c93f2008-11-05 20:51:48 +00001506 bool CheckConstructorDeclarator(Declarator &D, QualType &R,
1507 FunctionDecl::StorageClass& SC);
Douglas Gregor4d87df52008-12-16 21:30:33 +00001508 bool CheckConstructor(CXXConstructorDecl *Constructor);
Douglas Gregor831c93f2008-11-05 20:51:48 +00001509 bool CheckDestructorDeclarator(Declarator &D, QualType &R,
1510 FunctionDecl::StorageClass& SC);
Douglas Gregordbc5daf2008-11-07 20:08:42 +00001511 bool CheckConversionDeclarator(Declarator &D, QualType &R,
1512 FunctionDecl::StorageClass& SC);
Douglas Gregordbc5daf2008-11-07 20:08:42 +00001513 DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregor61956c42008-10-31 09:07:45 +00001514
Douglas Gregor5c407d92008-10-23 00:40:37 +00001515 //===--------------------------------------------------------------------===//
1516 // C++ Derived Classes
1517 //
1518
1519 /// ActOnBaseSpecifier - Parsed a base specifier
Douglas Gregor463421d2009-03-03 04:44:36 +00001520 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
1521 SourceRange SpecifierRange,
1522 bool Virtual, AccessSpecifier Access,
1523 QualType BaseType,
1524 SourceLocation BaseLoc);
Douglas Gregor5c407d92008-10-23 00:40:37 +00001525 virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl,
1526 SourceRange SpecifierRange,
1527 bool Virtual, AccessSpecifier Access,
Douglas Gregor463421d2009-03-03 04:44:36 +00001528 TypeTy *basetype, SourceLocation
1529 BaseLoc);
Douglas Gregor5c407d92008-10-23 00:40:37 +00001530
Douglas Gregor463421d2009-03-03 04:44:36 +00001531 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
1532 unsigned NumBases);
Douglas Gregor5c407d92008-10-23 00:40:37 +00001533 virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
1534 unsigned NumBases);
1535
1536 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregor39c16d42008-10-24 04:54:22 +00001537 bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
Douglas Gregor960b5bc2009-01-15 00:26:24 +00001538 bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria,
1539 BasePaths &Paths);
Douglas Gregorcea4e7432008-10-24 16:17:19 +00001540 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
1541 SourceLocation Loc, SourceRange Range);
Douglas Gregor1c846b02009-01-16 00:38:09 +00001542 std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
Douglas Gregor556877c2008-04-13 21:30:24 +00001543
Douglas Gregor11d0c4c2008-11-06 22:13:31 +00001544 //===--------------------------------------------------------------------===//
1545 // C++ Overloaded Operators [C++ 13.5]
1546 //
1547
1548 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
1549
Douglas Gregor5101c242008-12-05 18:15:24 +00001550 //===--------------------------------------------------------------------===//
1551 // C++ Templates [C++ 14]
1552 //
Douglas Gregor8bf42052009-02-09 18:46:07 +00001553 virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S,
1554 DeclTy *&TemplateDecl,
1555 const CXXScopeSpec *SS = 0);
Douglas Gregor5101c242008-12-05 18:15:24 +00001556 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001557 TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl);
1558
1559 virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename,
1560 SourceLocation KeyLoc,
1561 IdentifierInfo *ParamName,
1562 SourceLocation ParamNameLoc,
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001563 unsigned Depth, unsigned Position);
Douglas Gregordba32632009-02-10 19:49:53 +00001564 virtual void ActOnTypeParameterDefault(DeclTy *TypeParam,
1565 SourceLocation EqualLoc,
1566 SourceLocation DefaultLoc,
1567 TypeTy *Default);
1568
Douglas Gregor463421d2009-03-03 04:44:36 +00001569 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001570 virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001571 unsigned Depth,
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001572 unsigned Position);
Douglas Gregordba32632009-02-10 19:49:53 +00001573 virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam,
1574 SourceLocation EqualLoc,
1575 ExprArg Default);
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001576 virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S,
1577 SourceLocation TmpLoc,
1578 TemplateParamsTy *Params,
1579 IdentifierInfo *ParamName,
1580 SourceLocation ParamNameLoc,
1581 unsigned Depth,
1582 unsigned Position);
Douglas Gregordba32632009-02-10 19:49:53 +00001583 virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam,
1584 SourceLocation EqualLoc,
1585 ExprArg Default);
1586
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001587 virtual TemplateParamsTy *
1588 ActOnTemplateParameterList(unsigned Depth,
1589 SourceLocation ExportLoc,
1590 SourceLocation TemplateLoc,
1591 SourceLocation LAngleLoc,
1592 DeclTy **Params, unsigned NumParams,
1593 SourceLocation RAngleLoc);
Douglas Gregordba32632009-02-10 19:49:53 +00001594 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
1595 TemplateParameterList *OldParams);
1596
Douglas Gregorcd72ba92009-02-06 22:42:48 +00001597 virtual DeclTy *
1598 ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK,
1599 SourceLocation KWLoc, const CXXScopeSpec &SS,
1600 IdentifierInfo *Name, SourceLocation NameLoc,
1601 AttributeList *Attr,
1602 MultiTemplateParamsArg TemplateParameterLists);
1603
Douglas Gregorc40290e2009-03-09 23:48:35 +00001604 QualType CheckClassTemplateId(ClassTemplateDecl *ClassTemplate,
1605 SourceLocation TemplateLoc,
1606 SourceLocation LAngleLoc,
1607 const TemplateArgument *TemplateArgs,
1608 unsigned NumTemplateArgs,
1609 SourceLocation RAngleLoc);
1610
Douglas Gregor67a65642009-02-17 23:15:12 +00001611 virtual TypeResult
1612 ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc,
1613 SourceLocation LAngleLoc,
1614 ASTTemplateArgsPtr TemplateArgs,
1615 SourceLocation *TemplateArgLocs,
1616 SourceLocation RAngleLoc,
1617 const CXXScopeSpec *SS);
1618
Douglas Gregorf47b9112009-02-25 22:02:03 +00001619 bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate,
1620 ClassTemplateSpecializationDecl *PrevDecl,
1621 SourceLocation TemplateNameLoc,
1622 SourceRange ScopeSpecifierRange);
1623
Douglas Gregor67a65642009-02-17 23:15:12 +00001624 virtual DeclTy *
1625 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
1626 SourceLocation KWLoc,
1627 const CXXScopeSpec &SS,
1628 DeclTy *Template,
1629 SourceLocation TemplateNameLoc,
Douglas Gregor8bf42052009-02-09 18:46:07 +00001630 SourceLocation LAngleLoc,
Douglas Gregor67b556a2009-02-09 19:34:22 +00001631 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregord32e0282009-02-09 23:23:08 +00001632 SourceLocation *TemplateArgLocs,
Douglas Gregor8bf42052009-02-09 18:46:07 +00001633 SourceLocation RAngleLoc,
Douglas Gregor67a65642009-02-17 23:15:12 +00001634 AttributeList *Attr,
1635 MultiTemplateParamsArg TemplateParameterLists);
Douglas Gregor8bf42052009-02-09 18:46:07 +00001636
Douglas Gregord32e0282009-02-09 23:23:08 +00001637 bool CheckTemplateArgumentList(TemplateDecl *Template,
1638 SourceLocation TemplateLoc,
1639 SourceLocation LAngleLoc,
Douglas Gregorc40290e2009-03-09 23:48:35 +00001640 const TemplateArgument *TemplateArgs,
1641 unsigned NumTemplateArgs,
Douglas Gregor264ec4f2009-02-17 01:05:43 +00001642 SourceLocation RAngleLoc,
1643 llvm::SmallVectorImpl<TemplateArgument> &Converted);
Douglas Gregord32e0282009-02-09 23:23:08 +00001644
1645 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg,
1646 SourceLocation ArgLoc);
Douglas Gregor264ec4f2009-02-17 01:05:43 +00001647 bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,
1648 NamedDecl *&Entity);
1649 bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member);
Douglas Gregor463421d2009-03-03 04:44:36 +00001650 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
1651 QualType InstantiatedParamType, Expr *&Arg,
Douglas Gregor264ec4f2009-02-17 01:05:43 +00001652 llvm::SmallVectorImpl<TemplateArgument> *Converted = 0);
Douglas Gregord32e0282009-02-09 23:23:08 +00001653 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg);
Douglas Gregorcd72ba92009-02-06 22:42:48 +00001654 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
1655 TemplateParameterList *Old,
1656 bool Complain,
Douglas Gregor85e0f662009-02-10 00:24:35 +00001657 bool IsTemplateTemplateParm = false,
1658 SourceLocation TemplateArgLoc
1659 = SourceLocation());
Douglas Gregorcd72ba92009-02-06 22:42:48 +00001660
1661 bool CheckTemplateDeclScope(Scope *S,
1662 MultiTemplateParamsArg &TemplateParameterLists);
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001663
Douglas Gregorfe1e1102009-02-27 19:31:52 +00001664 //===--------------------------------------------------------------------===//
1665 // C++ Template Instantiation
1666 //
1667 QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
1668 unsigned NumTemplateArgs,
1669 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor463421d2009-03-03 04:44:36 +00001670 bool
1671 InstantiateBaseSpecifiers(ClassTemplateSpecializationDecl *ClassTemplateSpec,
1672 ClassTemplateDecl *ClassTemplate);
1673 bool
1674 InstantiateClassTemplateSpecialization(
1675 ClassTemplateSpecializationDecl *ClassTemplateSpec,
1676 bool ExplicitInstantiation);
Douglas Gregorfe1e1102009-02-27 19:31:52 +00001677
Steve Naroff09bf8152007-09-06 21:24:23 +00001678 // Objective-C declarations.
Chris Lattnerdf59f5a2008-07-26 04:13:19 +00001679 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
1680 IdentifierInfo *ClassName,
1681 SourceLocation ClassLoc,
1682 IdentifierInfo *SuperName,
1683 SourceLocation SuperLoc,
1684 DeclTy * const *ProtoRefs,
1685 unsigned NumProtoRefs,
1686 SourceLocation EndProtoLoc,
1687 AttributeList *AttrList);
Fariborz Jahanian49c64252007-10-11 23:42:27 +00001688
1689 virtual DeclTy *ActOnCompatiblityAlias(
1690 SourceLocation AtCompatibilityAliasLoc,
1691 IdentifierInfo *AliasName, SourceLocation AliasLocation,
1692 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff41d09ad2009-03-05 15:22:01 +00001693
1694 void CheckForwardProtocolDeclarationForCircularDependency(
1695 IdentifierInfo *PName,
1696 SourceLocation &PLoc, SourceLocation PrevLoc,
1697 const ObjCList<ObjCProtocolDecl> &PList);
Steve Naroff09bf8152007-09-06 21:24:23 +00001698
Steve Naroff93eb5f12007-10-10 17:32:04 +00001699 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman7dd8e722008-02-20 22:57:40 +00001700 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian39d641f2007-09-17 21:07:36 +00001701 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattner3bbae002008-07-26 04:03:38 +00001702 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar26e2ab42008-09-26 04:48:09 +00001703 SourceLocation EndProtoLoc,
1704 AttributeList *AttrList);
Fariborz Jahanian39d641f2007-09-17 21:07:36 +00001705
Chris Lattnerb1f3c942008-07-26 04:07:02 +00001706 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
1707 IdentifierInfo *ClassName,
1708 SourceLocation ClassLoc,
1709 IdentifierInfo *CategoryName,
1710 SourceLocation CategoryLoc,
1711 DeclTy * const *ProtoRefs,
1712 unsigned NumProtoRefs,
1713 SourceLocation EndProtoLoc);
Fariborz Jahanian867a7eb2007-09-18 20:26:58 +00001714
Steve Naroff93eb5f12007-10-10 17:32:04 +00001715 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman7dd8e722008-02-20 22:57:40 +00001716 SourceLocation AtClassImplLoc,
Fariborz Jahanianbfe13c52007-09-25 18:38:09 +00001717 IdentifierInfo *ClassName, SourceLocation ClassLoc,
1718 IdentifierInfo *SuperClassname,
1719 SourceLocation SuperClassLoc);
1720
Steve Naroff93eb5f12007-10-10 17:32:04 +00001721 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahanian89b8ef92007-10-02 16:38:50 +00001722 SourceLocation AtCatImplLoc,
1723 IdentifierInfo *ClassName,
1724 SourceLocation ClassLoc,
1725 IdentifierInfo *CatName,
1726 SourceLocation CatLoc);
1727
Steve Naroff93eb5f12007-10-10 17:32:04 +00001728 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroff0c37b0c2007-10-02 22:39:18 +00001729 IdentifierInfo **IdentList,
1730 unsigned NumElts);
Fariborz Jahanian876e27d2007-09-21 15:40:54 +00001731
Steve Naroff93eb5f12007-10-10 17:32:04 +00001732 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001733 const IdentifierLocPair *IdentList,
Fariborz Jahanian1470e932008-12-17 01:07:27 +00001734 unsigned NumElts,
1735 AttributeList *attrList);
Fariborz Jahanianea7a98d2007-10-05 21:01:53 +00001736
Chris Lattner3bbae002008-07-26 04:03:38 +00001737 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001738 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian70e8f102007-10-11 00:55:41 +00001739 unsigned NumProtocols,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001740 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001741
Daniel Dunbare8a06e62008-09-23 21:53:23 +00001742 /// Ensure attributes are consistent with type.
1743 /// \param [in, out] Attributes The attributes to check; they will
1744 /// be modified to be consistent with \arg PropertyTy.
1745 void CheckObjCPropertyAttributes(QualType PropertyTy,
1746 SourceLocation Loc,
1747 unsigned &Attributes);
Steve Naroff35c62ae2009-01-08 17:28:14 +00001748 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001749 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1750 ObjCPropertyDecl *SuperProperty,
Chris Lattner86d7d912008-11-24 03:54:41 +00001751 const IdentifierInfo *Name);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001752 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanian0a070ff2008-04-24 19:58:34 +00001753
Fariborz Jahaniand2c2ad52008-12-06 23:03:39 +00001754 void MergeProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +00001755 DeclTy *MergeProtocols);
1756
Fariborz Jahanian33afd772009-03-02 19:05:07 +00001757 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
1758 ObjCInterfaceDecl *ID);
1759
Fariborz Jahaniand2c2ad52008-12-06 23:03:39 +00001760 void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +00001761 ObjCProtocolDecl *PDecl);
1762
Steve Naroffcac26f42007-11-11 17:19:15 +00001763 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
1764 DeclTy **allMethods = 0, unsigned allNum = 0,
1765 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahanian2a4dd312007-09-26 18:27:25 +00001766
Fariborz Jahanian0152a1a2008-04-14 23:36:35 +00001767 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian8d916862008-05-05 18:51:55 +00001768 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanian09367d62008-05-06 18:09:04 +00001769 Selector GetterSel, Selector SetterSel,
Fariborz Jahanianf8ef9f32008-11-26 20:01:34 +00001770 DeclTy *ClassCategory, bool *OverridingProperty,
Fariborz Jahanian8d916862008-05-05 18:51:55 +00001771 tok::ObjCKeywordKind MethodImplKind);
1772
Fariborz Jahanianffe97a32008-04-18 00:19:30 +00001773 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
1774 SourceLocation PropertyLoc,
1775 bool ImplKind, DeclTy *ClassImplDecl,
1776 IdentifierInfo *PropertyId,
1777 IdentifierInfo *PropertyIvar);
1778
Steve Naroff161a92b2007-10-26 20:53:56 +00001779 virtual DeclTy *ActOnMethodDeclaration(
1780 SourceLocation BeginLoc, // location of the + or -.
1781 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanianb5605172007-11-09 19:52:12 +00001782 tok::TokenKind MethodType,
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001783 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanian7a9c4742007-10-31 23:53:01 +00001784 Selector Sel,
Steve Narofff73590d2007-09-27 14:38:14 +00001785 // optional arguments. The number of types/arguments is obtained
1786 // from the Sel.getNumArgs().
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001787 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Fariborz Jahaniane84858c2009-01-09 00:38:19 +00001788 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroffd8ea1ac2007-11-15 12:35:21 +00001789 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
1790 bool isVariadic = false);
Steve Naroff077c83b2007-10-16 23:12:48 +00001791
Steve Naroffb162f172009-02-26 15:55:06 +00001792 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
1793 // Will search "local" class/category implementations for a method decl.
Fariborz Jahanian4f4de6c2009-03-04 18:15:57 +00001794 // Will also search in class's root looking for instance method.
Steve Naroffb162f172009-02-26 15:55:06 +00001795 // Returns 0 if no method is found.
Steve Naroffed031702009-03-08 18:56:13 +00001796 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
1797 ObjCInterfaceDecl *CDecl);
1798 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
1799 ObjCInterfaceDecl *ClassDecl);
Steve Naroffb162f172009-02-26 15:55:06 +00001800
Steve Naroff9527bbf2009-03-09 21:12:44 +00001801 virtual OwningExprResult ActOnClassPropertyRefExpr(
1802 IdentifierInfo &receiverName,
1803 IdentifierInfo &propertyName,
1804 SourceLocation &receiverNameLoc,
1805 SourceLocation &propertyNameLoc);
1806
Steve Narofff73590d2007-09-27 14:38:14 +00001807 // ActOnClassMessage - used for both unary and keyword messages.
1808 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001809 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +00001810 virtual ExprResult ActOnClassMessage(
Fariborz Jahaniand98a7342007-11-12 20:13:27 +00001811 Scope *S,
Anders Carlsson978f08d2009-02-14 18:21:46 +00001812 IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,
1813 SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001814 ExprTy **ArgExprs, unsigned NumArgs);
Steve Narofff73590d2007-09-27 14:38:14 +00001815
1816 // ActOnInstanceMessage - used for both unary and keyword messages.
1817 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001818 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +00001819 virtual ExprResult ActOnInstanceMessage(
Steve Naroff80175062007-09-28 22:22:11 +00001820 ExprTy *receiver, Selector Sel,
Anders Carlsson978f08d2009-02-14 18:21:46 +00001821 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001822 ExprTy **ArgExprs, unsigned NumArgs);
Daniel Dunbar54603742008-10-14 05:35:18 +00001823
1824 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
1825 virtual void ActOnPragmaPack(PragmaPackKind Kind,
1826 IdentifierInfo *Name,
1827 ExprTy *Alignment,
1828 SourceLocation PragmaLoc,
1829 SourceLocation LParenLoc,
1830 SourceLocation RParenLoc);
Chris Lattner31180bb2009-02-17 01:09:29 +00001831
1832 /// getPragmaPackAlignment() - Return the current alignment as specified by
1833 /// the current #pragma pack directive, or 0 if none is currently active.
1834 unsigned getPragmaPackAlignment() const;
1835
1836 /// FreePackedContext - Deallocate and null out PackContext.
1837 void FreePackedContext();
Daniel Dunbar54603742008-10-14 05:35:18 +00001838
Chris Lattnera65e1f32008-01-16 19:17:22 +00001839 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
1840 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregora11693b2008-11-12 17:17:38 +00001841 /// If isLvalue, the result of the cast is an lvalue.
1842 void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
Chris Lattnera65e1f32008-01-16 19:17:22 +00001843
Steve Naroff71b59a92007-06-04 22:22:31 +00001844 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner08464942007-12-28 05:29:59 +00001845 // functions and arrays to their respective pointers (C99 6.3.2.1).
1846 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3e113402008-05-27 03:33:27 +00001847
Steve Naroff31090012007-07-16 21:54:35 +00001848 // DefaultFunctionArrayConversion - converts functions and arrays
1849 // to their respective pointers (C99 6.3.2.1).
1850 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001851
Steve Naroff0b661582007-08-28 23:30:39 +00001852 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
1853 // do not have a prototype. Integer promotions are performed on each
1854 // argument, and arguments that have type float are promoted to double.
Chris Lattner08464942007-12-28 05:29:59 +00001855 void DefaultArgumentPromotion(Expr *&Expr);
Anders Carlssona7d069d2009-01-16 16:48:51 +00001856
1857 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
1858 enum VariadicCallType {
1859 VariadicFunction,
1860 VariadicBlock,
1861 VariadicMethod
1862 };
1863
1864 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
1865 // will warn if the resulting type is not a POD type.
1866 void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
Steve Naroff0b661582007-08-28 23:30:39 +00001867
Steve Naroff71b59a92007-06-04 22:22:31 +00001868 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
1869 // operands and then handles various conversions that are common to binary
1870 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
1871 // routine returns the first non-arithmetic type found. The client is
1872 // responsible for emitting appropriate error diagnostics.
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001873 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
1874 bool isCompAssign = false);
Chris Lattner940cfeb2008-01-04 18:22:42 +00001875
Douglas Gregora11693b2008-11-12 17:17:38 +00001876 /// UsualArithmeticConversionsType - handles the various conversions
1877 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
1878 /// and returns the result type of that conversion.
1879 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
1880
1881
Chris Lattner940cfeb2008-01-04 18:22:42 +00001882 /// AssignConvertType - All of the 'assignment' semantic checks return this
1883 /// enum to indicate whether the assignment was allowed. These checks are
1884 /// done for simple assignments, as well as initialization, return from
1885 /// function, argument passing, etc. The query is phrased in terms of a
1886 /// source and destination type.
Chris Lattner9bad62c2008-01-04 18:04:52 +00001887 enum AssignConvertType {
Chris Lattner940cfeb2008-01-04 18:22:42 +00001888 /// Compatible - the types are compatible according to the standard.
Steve Naroff17f76e02007-05-03 21:03:48 +00001889 Compatible,
Chris Lattner940cfeb2008-01-04 18:22:42 +00001890
1891 /// PointerToInt - The assignment converts a pointer to an int, which we
1892 /// accept as an extension.
1893 PointerToInt,
1894
1895 /// IntToPointer - The assignment converts an int to a pointer, which we
1896 /// accept as an extension.
1897 IntToPointer,
1898
1899 /// FunctionVoidPointer - The assignment is between a function pointer and
1900 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattner0a788432008-01-03 22:56:36 +00001901 FunctionVoidPointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +00001902
1903 /// IncompatiblePointer - The assignment is between two pointers types that
1904 /// are not compatible, but we accept them as an extension.
Steve Naroff1f4d7272007-05-11 04:00:31 +00001905 IncompatiblePointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +00001906
1907 /// CompatiblePointerDiscardsQualifiers - The assignment discards
1908 /// c/v/r qualifiers, which we accept as an extension.
1909 CompatiblePointerDiscardsQualifiers,
Steve Naroff081c7422008-09-04 15:10:53 +00001910
Anders Carlssondb5a9b62009-01-30 23:17:46 +00001911 /// IncompatibleVectors - The assignment is between two vector types that
1912 /// have the same size, which we accept as an extension.
1913 IncompatibleVectors,
1914
Steve Naroff991e99d2008-09-04 15:31:07 +00001915 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff081c7422008-09-04 15:10:53 +00001916 /// pointer. We disallow this.
1917 IntToBlockPointer,
1918
Steve Naroff991e99d2008-09-04 15:31:07 +00001919 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff081c7422008-09-04 15:10:53 +00001920 /// pointers types that are not compatible.
1921 IncompatibleBlockPointer,
1922
Steve Naroff8afa9892008-10-14 22:18:38 +00001923 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
1924 /// id type and something else (that is incompatible with it). For example,
1925 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
1926 IncompatibleObjCQualifiedId,
1927
Chris Lattner940cfeb2008-01-04 18:22:42 +00001928 /// Incompatible - We reject this conversion outright, it is invalid to
1929 /// represent it in the AST.
1930 Incompatible
Steve Naroff17f76e02007-05-03 21:03:48 +00001931 };
Chris Lattner9bad62c2008-01-04 18:04:52 +00001932
1933 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
1934 /// assignment conversion type specified by ConvTy. This returns true if the
1935 /// conversion was invalid or false if the conversion was accepted.
1936 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
1937 SourceLocation Loc,
1938 QualType DstType, QualType SrcType,
1939 Expr *SrcExpr, const char *Flavor);
1940
1941 /// CheckAssignmentConstraints - Perform type checking for assignment,
1942 /// argument passing, variable initialization, and function return values.
1943 /// This routine is only used by the following two methods. C99 6.5.16.
1944 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001945
Steve Naroff83895f72007-09-16 03:34:24 +00001946 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff66356bd2007-09-16 14:56:35 +00001947 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001948 // this routine performs the default function/array converions.
Chris Lattner9bad62c2008-01-04 18:04:52 +00001949 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
1950 Expr *&rExpr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001951 // CheckCompoundAssignmentConstraints - Type check without performing any
1952 // conversions. For compound assignments, the "Check...Operands" methods
1953 // perform the necessary conversions.
Chris Lattner9bad62c2008-01-04 18:04:52 +00001954 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
1955 QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001956
Steve Naroff98cf3e92007-06-06 18:38:38 +00001957 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner9bad62c2008-01-04 18:04:52 +00001958 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
1959 QualType rhsType);
Steve Naroff081c7422008-09-04 15:10:53 +00001960
1961 // Helper function for CheckAssignmentConstraints involving two
1962 // blcok pointer types.
1963 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
1964 QualType rhsType);
Douglas Gregoraa1e21d2008-09-12 00:47:35 +00001965
1966 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregor39c16d42008-10-24 04:54:22 +00001967
Douglas Gregor47d3f272008-12-19 17:40:08 +00001968 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +00001969 const char *Flavor, bool AllowExplicit = false);
1970 bool PerformImplicitConversion(Expr *&From, QualType ToType,
1971 const ImplicitConversionSequence& ICS,
Douglas Gregor47d3f272008-12-19 17:40:08 +00001972 const char *Flavor);
Douglas Gregor39c16d42008-10-24 04:54:22 +00001973 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor47d3f272008-12-19 17:40:08 +00001974 const StandardConversionSequence& SCS,
1975 const char *Flavor);
Sebastian Redl112a97662009-02-07 00:15:38 +00001976
Steve Naroff8eeeb132007-05-08 21:09:37 +00001977 /// the following "Check" methods will return a valid/converted QualType
1978 /// or a null QualType (indicating an error diagnostic was issued).
Sebastian Redl112a97662009-02-07 00:15:38 +00001979
1980 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
Chris Lattner5c11c412007-12-12 05:47:28 +00001981 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Sebastian Redl5822f082009-02-07 20:10:22 +00001982 QualType CheckPointerToMemberOperands( // C++ 5.5
Sebastian Redl112a97662009-02-07 00:15:38 +00001983 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001984 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Sebastian Redl112a97662009-02-07 00:15:38 +00001985 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001986 inline QualType CheckRemainderOperands( // C99 6.5.5
Sebastian Redl112a97662009-02-07 00:15:38 +00001987 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001988 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001989 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001990 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001991 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001992 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001993 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnerb620c342007-08-26 01:18:55 +00001994 inline QualType CheckCompareOperands( // C99 6.5.8/9
1995 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001996 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Sebastian Redl112a97662009-02-07 00:15:38 +00001997 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001998 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff7a5af782007-07-13 16:58:59 +00001999 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Naroff35d85152007-05-07 00:24:15 +00002000 // CheckAssignmentOperands is used for both simple and compound assignment.
2001 // For simple assignment, pass both expressions and a null converted type.
2002 // For compound assignment, pass both expressions and the converted type.
2003 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0c1c7ed2007-08-24 22:33:52 +00002004 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Steve Naroff218bc2b2007-05-04 21:54:46 +00002005 inline QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner326f7572008-11-18 01:30:42 +00002006 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Steve Narofff8a28c52007-05-15 20:29:32 +00002007 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff7a5af782007-07-13 16:58:59 +00002008 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begeman191a6b12008-07-14 18:02:46 +00002009
2010 /// type checking for vector binary operators.
2011 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
2012 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
2013 SourceLocation l, bool isRel);
Steve Naroff95af0132007-03-30 23:47:58 +00002014
Steve Naroff83895f72007-09-16 03:34:24 +00002015 /// type checking unary operators (subroutines of ActOnUnaryOp).
Steve Naroff9358c712007-05-27 23:58:33 +00002016 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redle10c2c32008-12-20 09:35:34 +00002017 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
2018 bool isInc);
Steve Naroff71ce2e02007-05-18 22:53:50 +00002019 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
2020 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattner709322b2009-02-17 08:12:06 +00002021 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
Steve Narofff8fd09e2007-07-27 22:15:19 +00002022
2023 /// type checking primary expressions.
Nate Begemance4d7fc2008-04-18 23:10:10 +00002024 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Narofff8fd09e2007-07-27 22:15:19 +00002025 IdentifierInfo &Comp, SourceLocation CmpLoc);
2026
Steve Naroff2fea1392007-09-02 02:04:30 +00002027 /// type checking declaration initializers (C99 6.7.8)
Douglas Gregor6f543152008-11-05 15:29:30 +00002028 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor5fb53972009-01-14 15:45:31 +00002029 SourceLocation InitLoc,DeclarationName InitEntity,
2030 bool DirectInit);
Douglas Gregor85df8d82009-01-29 00:45:39 +00002031 bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
Steve Naroff98f72032008-01-10 22:15:12 +00002032 bool CheckForConstantInitializer(Expr *e, QualType t);
Steve Naroff91f78082007-12-10 22:44:33 +00002033
Douglas Gregora5c9e1a2009-02-02 17:43:21 +00002034 bool CheckValueInitialization(QualType Type, SourceLocation Loc);
Argyrios Kyrtzidis2ade3902008-08-16 20:27:34 +00002035
Douglas Gregor8e1cf602008-10-29 00:13:59 +00002036 // type checking C++ declaration initializers (C++ [dcl.init]).
2037
2038 /// ReferenceCompareResult - Expresses the result of comparing two
2039 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
2040 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
2041 enum ReferenceCompareResult {
2042 /// Ref_Incompatible - The two types are incompatible, so direct
2043 /// reference binding is not possible.
2044 Ref_Incompatible = 0,
2045 /// Ref_Related - The two types are reference-related, which means
2046 /// that their unqualified forms (T1 and T2) are either the same
2047 /// or T1 is a base class of T2.
2048 Ref_Related,
2049 /// Ref_Compatible_With_Added_Qualification - The two types are
2050 /// reference-compatible with added qualification, meaning that
2051 /// they are reference-compatible and the qualifiers on T1 (cv1)
2052 /// are greater than the qualifiers on T2 (cv2).
2053 Ref_Compatible_With_Added_Qualification,
2054 /// Ref_Compatible - The two types are reference-compatible and
2055 /// have equivalent qualifiers (cv1 == cv2).
2056 Ref_Compatible
2057 };
2058
Douglas Gregor786ab212008-10-29 02:00:59 +00002059 ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
2060 bool& DerivedToBase);
Douglas Gregor8e1cf602008-10-29 00:13:59 +00002061
2062 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor2fe98832008-11-03 19:09:14 +00002063 ImplicitConversionSequence *ICS = 0,
Douglas Gregor5fb53972009-01-14 15:45:31 +00002064 bool SuppressUserConversions = false,
2065 bool AllowExplicit = false);
Douglas Gregor8e1cf602008-10-29 00:13:59 +00002066
Argyrios Kyrtzidis2ade3902008-08-16 20:27:34 +00002067 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar94834d82008-08-20 03:55:42 +00002068 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroffaf2a0222008-01-22 00:55:40 +00002069
Anders Carlsson24c59952007-11-27 07:16:40 +00002070 // CheckVectorCast - check type constraints for vectors.
2071 // Since vectors are an extension, there are no C standard reference for this.
2072 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssonde71adf2007-11-27 05:51:55 +00002073 // returns true if the cast is invalid
2074 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
2075
Daniel Dunbaraa9326c2008-09-11 00:01:56 +00002076 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
2077 /// \param Method - May be null.
2078 /// \param [out] ReturnType - The return type of the send.
2079 /// \return true iff there were any incompatible types.
Daniel Dunbarce05c8e2008-09-11 00:50:25 +00002080 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattnere4b95692008-11-24 03:33:13 +00002081 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbaraa9326c2008-09-11 00:01:56 +00002082 SourceLocation lbrac, SourceLocation rbrac,
2083 QualType &ReturnType);
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +00002084
2085 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
2086 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff077c83b2007-10-16 23:12:48 +00002087
Chris Lattnerfc1c44a2007-08-23 05:46:52 +00002088 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
2089 /// the specified width and sign. If an overflow occurs, detect it and emit
2090 /// the specified diagnostic.
2091 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
2092 unsigned NewWidth, bool NewSign,
2093 SourceLocation Loc, unsigned DiagID);
2094
Chris Lattner2a3569b2008-04-07 05:30:13 +00002095 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
2096 bool ForCompare);
2097
Anders Carlssona6b508a2008-11-04 16:57:32 +00002098 /// Checks that the Objective-C declaration is declared in the global scope.
2099 /// Emits an error and marks the declaration as invalid if it's not declared
2100 /// in the global scope.
2101 bool CheckObjCDeclScope(Decl *D);
2102
Anders Carlsson7e13ab82007-10-15 20:28:48 +00002103 void InitBuiltinVaListType();
Eli Friedman149614b2008-06-03 21:01:11 +00002104
Anders Carlssone54e8a12008-11-30 19:50:32 +00002105 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
2106 /// and reports the appropriate diagnostics. Returns false on success.
2107 /// Can optionally return the value of the expression.
Anders Carlsson5df391e2008-12-06 20:33:04 +00002108 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson1dbffc62008-12-01 02:17:22 +00002109
Anders Carlsson5df391e2008-12-06 20:33:04 +00002110 /// VerifyBitField - verifies that a bit field expression is an ICE and has
2111 /// the correct width, and that the field type is valid.
2112 /// Returns false on success.
2113 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
2114 QualType FieldTy, const Expr *BitWidth);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00002115
Chris Lattnerb87b1b32007-08-10 20:18:51 +00002116 //===--------------------------------------------------------------------===//
2117 // Extra semantic analysis beyond the C type system
Chris Lattner08464942007-12-28 05:29:59 +00002118private:
Sebastian Redlc215cfc2009-01-19 00:08:26 +00002119 Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl,
2120 CallExpr *TheCall);
Chris Lattnera26fb342009-02-18 17:49:48 +00002121 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
2122 unsigned ByteNo) const;
Chris Lattner6436fb62009-02-18 06:01:06 +00002123 bool CheckObjCString(Expr *Arg);
Chris Lattner08464942007-12-28 05:29:59 +00002124 bool SemaBuiltinVAStart(CallExpr *TheCall);
2125 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedmanf8353032008-05-20 08:23:37 +00002126 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00002127 Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbarb7257262008-07-21 22:59:13 +00002128 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbarb0d34c82008-09-03 21:13:56 +00002129 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Ted Kremenek6dfeb552009-01-12 23:09:09 +00002130 bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg,
Douglas Gregore711f702009-02-14 18:57:46 +00002131 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek6dfeb552009-01-12 23:09:09 +00002132 void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr,
2133 CallExpr *TheCall, bool HasVAListArg,
Douglas Gregore711f702009-02-14 18:57:46 +00002134 unsigned format_idx, unsigned firstDataArg);
2135 void CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
2136 unsigned format_idx, unsigned firstDataArg);
Ted Kremenekcff94fa2007-08-17 16:46:58 +00002137 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
2138 SourceLocation ReturnLoc);
Ted Kremenek43fb8b02007-11-25 00:58:00 +00002139 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Chris Lattner7cee11f2006-11-03 06:42:29 +00002140};
2141
Steve Naroffc540d662008-09-03 18:15:37 +00002142/// BlockSemaInfo - When a block is being parsed, this contains information
2143/// about the block. It is pointed to from Sema::CurBlock.
2144struct BlockSemaInfo {
2145 llvm::SmallVector<ParmVarDecl*, 8> Params;
Steve Naroffc540d662008-09-03 18:15:37 +00002146 bool hasPrototype;
2147 bool isVariadic;
Mike Stumpa6703322009-02-19 22:01:56 +00002148 bool hasBlockDeclRefExprs;
2149
Steve Naroff44078b92008-10-08 18:44:00 +00002150 BlockDecl *TheDecl;
2151
Chris Lattner1fa74d92009-02-18 07:09:44 +00002152 /// TheScope - This is the scope for the block itself, which contains
Steve Naroffc540d662008-09-03 18:15:37 +00002153 /// arguments etc.
2154 Scope *TheScope;
2155
2156 /// ReturnType - This will get set to block result type, by looking at
2157 /// return types, if any, in the block body.
2158 Type *ReturnType;
2159
2160 /// PrevBlockInfo - If this is nested inside another block, this points
2161 /// to the outer block.
2162 BlockSemaInfo *PrevBlockInfo;
2163};
Ted Kremenek5a201952009-02-07 01:47:29 +00002164
2165//===--------------------------------------------------------------------===//
2166// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
2167template <typename T>
2168class ExprOwningPtr : public Action::ExprArg {
2169public:
2170 ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {};
2171
2172 void reset(T* p) { Action::ExprArg::operator=(p); }
2173 T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
2174 T* take() { return static_cast<T*>(Action::ExprArg::take()); }
2175 T* release() { return take(); }
2176
2177 T& operator*() const { return *get(); }
2178 T* operator->() const { return get(); }
2179};
2180
Chris Lattner7cee11f2006-11-03 06:42:29 +00002181} // end namespace clang
Chris Lattner7cee11f2006-11-03 06:42:29 +00002182
2183#endif