blob: 9cb47cce4b2998f6d8098bc379a972e1ae5b99f5 [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"
Douglas Gregor1c846b02009-01-16 00:38:09 +000028#include <string>
Douglas Gregor39c16d42008-10-24 04:54:22 +000029#include <vector>
Chris Lattner7cee11f2006-11-03 06:42:29 +000030
Chris Lattnerfc1c44a2007-08-23 05:46:52 +000031namespace llvm {
32 class APSInt;
33}
34
Chris Lattner7cee11f2006-11-03 06:42:29 +000035namespace clang {
Chris Lattnercb6a3822006-11-10 06:20:45 +000036 class ASTContext;
Chris Lattnerfe0e0af2008-02-06 00:46:58 +000037 class ASTConsumer;
Chris Lattner7cee11f2006-11-03 06:42:29 +000038 class Preprocessor;
39 class Decl;
Chris Lattner0a5ff0d2008-04-06 04:47:34 +000040 class DeclContext;
Daniel Dunbar34fb6722008-08-11 03:27:53 +000041 class DeclSpec;
Steve Naroff257520b2008-04-01 23:04:06 +000042 class NamedDecl;
Sebastian Redlc675bab2008-12-13 16:23:55 +000043 class Stmt;
Steve Naroff78403362007-04-02 22:55:05 +000044 class Expr;
Steve Narofff33527a2007-09-02 15:34:30 +000045 class InitListExpr;
Douglas Gregore4a0bb72009-01-22 00:58:24 +000046 class DesignatedInitExpr;
Chris Lattner08464942007-12-28 05:29:59 +000047 class CallExpr;
Douglas Gregorc7acfdf2009-01-06 05:10:23 +000048 class DeclRefExpr;
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +000049 class VarDecl;
Chris Lattner53621a52007-06-13 20:44:40 +000050 class ParmVarDecl;
Chris Lattner01564d92007-01-27 19:27:06 +000051 class TypedefDecl;
52 class FunctionDecl;
Steve Naroffe5aa9be2007-04-05 22:36:20 +000053 class QualType;
Chris Lattner9cf21c52007-09-04 02:45:27 +000054 struct LangOptions;
Chris Lattner146762e2007-07-20 16:59:19 +000055 class Token;
Steve Naroff35d85152007-05-07 00:24:15 +000056 class IntegerLiteral;
Steve Naroffaf2a0222008-01-22 00:55:40 +000057 class StringLiteral;
Steve Naroff8eeeb132007-05-08 21:09:37 +000058 class ArrayType;
Chris Lattnere2473062007-05-28 06:28:18 +000059 class LabelStmt;
Anders Carlsson51873c22007-07-22 07:07:56 +000060 class SwitchStmt;
Nate Begemance4d7fc2008-04-18 23:10:10 +000061 class ExtVectorType;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000062 class TypedefDecl;
Douglas Gregorded2d7b2009-02-04 19:02:06 +000063 class TemplateDecl;
Douglas Gregor264ec4f2009-02-17 01:05:43 +000064 class TemplateArgument;
Douglas Gregorcd72ba92009-02-06 22:42:48 +000065 class TemplateParameterList;
Douglas Gregord32e0282009-02-09 23:23:08 +000066 class TemplateTemplateParmDecl;
Douglas Gregorf47b9112009-02-25 22:02:03 +000067 class ClassTemplateDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000068 class ObjCInterfaceDecl;
Steve Naroff257520b2008-04-01 23:04:06 +000069 class ObjCCompatibleAliasDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000070 class ObjCProtocolDecl;
Chris Lattner9ef10f42009-03-01 00:56:52 +000071 class ObjCImplDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000072 class ObjCImplementationDecl;
73 class ObjCCategoryImplDecl;
74 class ObjCCategoryDecl;
75 class ObjCIvarDecl;
76 class ObjCMethodDecl;
Fariborz Jahanian7cf18862008-05-01 00:03:38 +000077 class ObjCPropertyDecl;
Steve Naroff35c62ae2009-01-08 17:28:14 +000078 class ObjCContainerDecl;
Steve Naroffc540d662008-09-03 18:15:37 +000079 struct BlockSemaInfo;
Douglas Gregor39c16d42008-10-24 04:54:22 +000080 class BasePaths;
Douglas Gregor960b5bc2009-01-15 00:26:24 +000081 class MemberLookupCriteria;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000082
Chris Lattnercc67ec12006-11-09 06:54:47 +000083/// Sema - This implements semantic analysis and AST building for C.
84class Sema : public Action {
Chris Lattner01c3d232009-02-17 00:58:30 +000085 Sema(const Sema&); // DO NOT IMPLEMENT
86 void operator=(const Sema&); // DO NOT IMPLEMENT
Chris Lattnera663a0a2008-06-29 00:28:59 +000087public:
Chris Lattner4da04a4e2009-01-22 19:21:44 +000088 const LangOptions &LangOpts;
Steve Naroff38d31b42007-02-28 01:22:02 +000089 Preprocessor &PP;
Chris Lattnercb6a3822006-11-10 06:20:45 +000090 ASTContext &Context;
Chris Lattnerfe0e0af2008-02-06 00:46:58 +000091 ASTConsumer &Consumer;
Chris Lattnerbc495d72008-11-22 08:28:49 +000092 Diagnostic &Diags;
93 SourceManager &SourceMgr;
Steve Naroffe3d1ab22007-11-12 13:56:41 +000094
Argyrios Kyrtzidis853fbea2008-06-28 06:07:14 +000095 /// CurContext - This is the current declaration context of parsing.
Chris Lattner0a5ff0d2008-04-06 04:47:34 +000096 DeclContext *CurContext;
Chris Lattnerc5ffed42008-04-04 06:12:32 +000097
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000098 /// PreDeclaratorDC - Keeps the declaration context before switching to the
99 /// context of a declarator's nested-name-specifier.
100 DeclContext *PreDeclaratorDC;
101
Steve Naroffc540d662008-09-03 18:15:37 +0000102 /// CurBlock - If inside of a block definition, this contains a pointer to
103 /// the active block object that represents it.
104 BlockSemaInfo *CurBlock;
105
Steve Naroffd123bd02009-02-28 16:48:43 +0000106 /// ActiveScope - If inside of a function, method, or block definition,
107 /// this contains a pointer to the active scope that represents it.
108 Scope *ActiveScope;
109
Daniel Dunbar54603742008-10-14 05:35:18 +0000110 /// PackContext - Manages the stack for #pragma pack. An alignment
111 /// of 0 indicates default alignment.
Chris Lattner31180bb2009-02-17 01:09:29 +0000112 void *PackContext; // Really a "PragmaPackStack*"
Daniel Dunbar54603742008-10-14 05:35:18 +0000113
Anders Carlsson51873c22007-07-22 07:07:56 +0000114 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffddf5a1d2007-07-29 16:33:31 +0000115
Nate Begemance4d7fc2008-04-18 23:10:10 +0000116 /// ExtVectorDecls - This is a list all the extended vector types. This allows
117 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroffddf5a1d2007-07-29 16:33:31 +0000118 /// This is only necessary for issuing pretty diagnostics.
Nate Begemance4d7fc2008-04-18 23:10:10 +0000119 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000120
Steve Naroff8edb5732008-09-28 14:55:53 +0000121 /// ObjCImplementations - Keep track of all class @implementations
122 /// so we can emit errors on duplicates.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000123 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattneree2d8412007-10-07 01:13:46 +0000124
Steve Naroff8edb5732008-09-28 14:55:53 +0000125 /// ObjCCategoryImpls - Maintain a list of category implementations so
126 /// we can check for duplicates and find local method declarations.
127 llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
128
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000129 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanian06f84f52007-10-09 18:03:53 +0000130 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner516ca702007-10-09 18:18:24 +0000131 /// find the declarations when needed.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000132 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff77892752008-04-02 18:30:49 +0000133
134 /// ObjCInterfaceDecls - Keep track of all class declarations declared
135 /// with @interface, so that we can emit errors on duplicates and
136 /// find the declarations when needed.
137 typedef llvm::DenseMap<const IdentifierInfo*,
138 ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
139 ObjCInterfaceDeclsTy ObjCInterfaceDecls;
140
Steve Naroff257520b2008-04-01 23:04:06 +0000141 /// ObjCAliasDecls - Keep track of all class declarations declared
142 /// with @compatibility_alias, so that we can emit errors on duplicates and
143 /// find the declarations when needed. This construct is ancient and will
144 /// likely never be seen. Nevertheless, it is here for compatibility.
Steve Naroff9b94b172008-04-02 00:39:51 +0000145 typedef llvm::DenseMap<const IdentifierInfo*,
146 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroff257520b2008-04-01 23:04:06 +0000147 ObjCAliasTy ObjCAliasDecls;
Steve Naroff77892752008-04-02 18:30:49 +0000148
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000149 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
150 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
151
Douglas Gregor5a80bd12009-03-02 00:19:53 +0000152 /// \brief A mapping from external names to the most recent
153 /// locally-scoped external declaration with that name.
154 ///
155 /// This map contains external declarations introduced in local
156 /// scoped, e.g.,
157 ///
158 /// \code
159 /// void f() {
160 /// void foo(int, int);
161 /// }
162 /// \endcode
163 ///
164 /// Here, the name "foo" will be associated with the declaration on
165 /// "foo" within f. This name is not visible outside of
166 /// "f". However, we still find it in two cases:
167 ///
168 /// - If we are declaring another external with the name "foo", we
169 /// can find "foo" as a previous declaration, so that the types
170 /// of this external declaration can be checked for
171 /// compatibility.
172 ///
173 /// - If we would implicitly declare "foo" (e.g., due to a call to
174 /// "foo" in C when no prototype or definition is visible), then
175 /// we find this declaration of "foo" and complain that it is
176 /// not visible.
177 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
178
Chris Lattnerc5c95b52008-04-11 07:00:53 +0000179 IdentifierResolver IdResolver;
180
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000181 // Enum values used by KnownFunctionIDs (see below).
182 enum {
Ted Kremenek34f664d2008-06-16 18:00:42 +0000183 id_NSLog,
Douglas Gregore711f702009-02-14 18:57:46 +0000184 id_NSLogv,
Daniel Dunbardd9b2d12008-10-02 18:44:07 +0000185 id_asprintf,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000186 id_vasprintf,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000187 id_num_known_functions
188 };
189
190 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
191 /// of known functions used by the semantic analysis to do various
192 /// kinds of checking (e.g. checking format string errors in printf calls).
193 /// This list is populated upon the creation of a Sema object.
Chris Lattner2cc35ae2008-08-23 02:00:52 +0000194 IdentifierInfo* KnownFunctionIDs[id_num_known_functions];
Daniel Dunbar12c9ddc2008-08-14 22:04:54 +0000195
Steve Naroff93eb5f12007-10-10 17:32:04 +0000196 /// Translation Unit Scope - useful to Objective-C actions that need
197 /// to lookup file scope declarations in the "ordinary" C decl namespace.
198 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroffc62adb62007-10-09 22:01:59 +0000199 Scope *TUScope;
Sebastian Redlc4704762008-11-11 11:37:55 +0000200
201 /// The C++ "std" namespace, where the standard library resides. Cached here
202 /// by GetStdNamespace
203 NamespaceDecl *StdNamespace;
Sebastian Redlfaf68082008-12-03 20:26:15 +0000204
205 /// A flag to remember whether the implicit forms of operator new and delete
206 /// have been declared.
207 bool GlobalNewDeleteDeclared;
Steve Naroff7f549f12007-10-10 21:53:07 +0000208
Steve Naroff5811baf2007-10-14 00:58:41 +0000209 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000210 struct ObjCMethodList {
211 ObjCMethodDecl *Method;
212 ObjCMethodList *Next;
Steve Naroff5811baf2007-10-14 00:58:41 +0000213
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000214 ObjCMethodList() {
Steve Naroff5811baf2007-10-14 00:58:41 +0000215 Method = 0;
216 Next = 0;
217 }
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000218 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff5811baf2007-10-14 00:58:41 +0000219 Method = M;
220 Next = C;
221 }
222 };
223 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
224 /// messages to "id". We need to maintain a list, since selectors can have
225 /// differing signatures across classes. In Cocoa, this happens to be
226 /// extremely uncommon (only 1% of selectors are "overloaded").
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000227 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
228 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Steve Naroff3f49fee2009-03-04 15:11:40 +0000229
230 /// Private Helper predicate to check for 'self'.
231 bool isSelfExpr(Expr *RExpr);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000232public:
Chris Lattnerfe0e0af2008-02-06 00:46:58 +0000233 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
Chris Lattner31180bb2009-02-17 01:09:29 +0000234 ~Sema() {
235 if (PackContext) FreePackedContext();
236 }
Chris Lattner7cee11f2006-11-03 06:42:29 +0000237
Chris Lattner4da04a4e2009-01-22 19:21:44 +0000238 const LangOptions &getLangOptions() const { return LangOpts; }
Chris Lattnerbc495d72008-11-22 08:28:49 +0000239 Diagnostic &getDiagnostics() const { return Diags; }
240 SourceManager &getSourceManager() const { return SourceMgr; }
241
Chris Lattner84f1ee32008-11-18 21:53:24 +0000242 /// The primitive diagnostic helpers.
Chris Lattnerbc495d72008-11-22 08:28:49 +0000243 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
244 return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
245 }
Steve Naroff71ce2e02007-05-18 22:53:50 +0000246
Chris Lattner57c523f2007-08-31 04:53:24 +0000247 virtual void DeleteExpr(ExprTy *E);
248 virtual void DeleteStmt(StmtTy *S);
249
Sebastian Redlc675bab2008-12-13 16:23:55 +0000250 OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); }
Sebastian Redlc215cfc2009-01-19 00:08:26 +0000251 OwningExprResult Owned(ExprResult R) {
Douglas Gregorf8298252009-01-26 22:44:13 +0000252 if (R.isInvalid())
Steve Naroffd5129562009-01-21 22:32:33 +0000253 return ExprError();
Douglas Gregorf8298252009-01-26 22:44:13 +0000254 return OwningExprResult(*this, R.get());
Sebastian Redlc215cfc2009-01-19 00:08:26 +0000255 }
Sebastian Redlc675bab2008-12-13 16:23:55 +0000256 OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
257
Chris Lattnerf4404402008-08-23 03:19:52 +0000258 virtual void ActOnEndOfTranslationUnit();
Sebastian Redlb5d49352009-01-19 22:31:54 +0000259
Chris Lattner7cee11f2006-11-03 06:42:29 +0000260 //===--------------------------------------------------------------------===//
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000261 // Type Analysis / Processing: SemaType.cpp.
262 //
Chris Lattner4b413ea2008-06-26 06:27:57 +0000263 QualType ConvertDeclSpecToType(const DeclSpec &DS);
Chris Lattnera7e619c2008-06-29 00:50:08 +0000264 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Douglas Gregor17c0d7b2009-02-28 00:25:32 +0000265 QualType BuildPointerType(QualType T, unsigned Quals,
266 SourceLocation Loc, DeclarationName Entity);
267 QualType BuildReferenceType(QualType T, unsigned Quals,
268 SourceLocation Loc, DeclarationName Entity);
269 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
270 Expr *ArraySize, unsigned Quals,
271 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor6eaaf302009-02-28 01:04:19 +0000272 QualType BuildFunctionType(QualType T,
273 QualType *ParamTypes, unsigned NumParamTypes,
274 bool Variadic, unsigned Quals,
275 SourceLocation Loc, DeclarationName Entity);
Sebastian Redl351bb782008-12-02 14:43:59 +0000276 QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0);
Douglas Gregor92751d42008-11-17 22:58:34 +0000277 DeclarationName GetNameForDeclarator(Declarator &D);
278
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000279 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahanian56ff1462007-11-08 23:49:49 +0000280
Douglas Gregore1eb9d82008-10-22 14:17:15 +0000281 bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
282
Sebastian Redl351bb782008-12-02 14:43:59 +0000283 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Sebastian Redl842ef522008-11-08 13:00:26 +0000284
Douglas Gregordd430f72009-01-19 19:26:10 +0000285 bool DiagnoseIncompleteType(SourceLocation Loc, QualType T, unsigned diag,
286 SourceRange Range1 = SourceRange(),
287 SourceRange Range2 = SourceRange(),
288 QualType PrintType = QualType());
289
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000290 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000291 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000292 //
Douglas Gregor9817f4a2009-02-09 15:09:02 +0000293 virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Douglas Gregor8a6be5e2009-02-04 17:00:24 +0000294 Scope *S, const CXXScopeSpec *SS);
Chris Lattner4bf74fd2009-02-15 22:43:40 +0000295 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){
Douglas Gregorad590502008-12-15 23:53:10 +0000296 return ActOnDeclarator(S, D, LastInGroup, false);
297 }
298 DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
299 bool IsFunctionDefinition);
Douglas Gregor5a80bd12009-03-02 00:19:53 +0000300 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl,
301 Scope *S);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000302 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
303 QualType R, Decl* LastDeclarator,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000304 Decl* PrevDecl, bool& InvalidDecl,
305 bool &Redeclaration);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000306 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000307 QualType R, Decl* LastDeclarator,
Douglas Gregor5d68a202009-02-24 19:23:27 +0000308 NamedDecl* PrevDecl, bool& InvalidDecl,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000309 bool &Redeclaration);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000310 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
311 QualType R, Decl *LastDeclarator,
Douglas Gregore62c0a42009-02-24 01:23:02 +0000312 NamedDecl* PrevDecl,
313 bool IsFunctionDefinition,
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000314 bool& InvalidDecl, bool &Redeclaration);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000315 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
316 virtual void ActOnParamDefaultArgument(DeclTy *param,
317 SourceLocation EqualLoc,
318 ExprTy *defarg);
Douglas Gregor58354032008-12-24 00:01:03 +0000319 virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
320 SourceLocation EqualLoc);
Douglas Gregor4d87df52008-12-16 21:30:33 +0000321 virtual void ActOnParamDefaultArgumentError(DeclTy *param);
Douglas Gregor5fb53972009-01-14 15:45:31 +0000322 virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
323 void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit);
Douglas Gregor8e1cf602008-10-29 00:13:59 +0000324 void ActOnUninitializedDecl(DeclTy *dcl);
Chris Lattner776fac82007-06-09 00:53:06 +0000325 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
326
Douglas Gregor9aa89042009-01-23 16:23:13 +0000327 virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D);
Chris Lattnera55a2cc2007-10-09 17:14:05 +0000328 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000329 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Steve Naroff70f41d62009-02-28 16:59:13 +0000330 virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D);
Sebastian Redlb5d49352009-01-19 22:31:54 +0000331
Sebastian Redlc675bab2008-12-13 16:23:55 +0000332 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
Sebastian Redlc675bab2008-12-13 16:23:55 +0000333 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlsson5c6c0592008-02-08 00:33:21 +0000334
Steve Naroffc62adb62007-10-09 22:01:59 +0000335 /// Scope actions.
336 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
337 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Chris Lattner01564d92007-01-27 19:27:06 +0000338
Chris Lattner200bdc32006-11-19 02:43:37 +0000339 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
340 /// no declarator (e.g. "struct foo;") is parsed.
Sebastian Redla2b5e312008-12-28 15:28:59 +0000341 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Chris Lattner200bdc32006-11-19 02:43:37 +0000342
Douglas Gregor9ac7a072009-01-07 00:43:41 +0000343 bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
344 RecordDecl *AnonRecord);
345 virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
346 RecordDecl *Record);
347
Douglas Gregordee1be82009-01-17 00:42:38 +0000348 virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
Argyrios Kyrtzidis32a03792008-11-08 16:45:02 +0000349 SourceLocation KWLoc, const CXXScopeSpec &SS,
350 IdentifierInfo *Name, SourceLocation NameLoc,
Douglas Gregorcd72ba92009-02-06 22:42:48 +0000351 AttributeList *Attr);
Ted Kremenek21475702008-09-05 17:16:31 +0000352
Douglas Gregor91f84212008-12-11 16:49:14 +0000353 virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner2cc35ae2008-08-23 02:00:52 +0000354 IdentifierInfo *ClassName,
355 llvm::SmallVectorImpl<DeclTy*> &Decls);
Douglas Gregor91f84212008-12-11 16:49:14 +0000356 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner1300fb92007-01-23 23:42:53 +0000357 Declarator &D, ExprTy *BitfieldWidth);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000358
359 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
360 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian96376742008-04-11 16:55:42 +0000361 tok::ObjCKeywordKind visibility);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000362
Steve Naroff2e688fd2007-09-14 23:09:53 +0000363 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian343f7092007-09-29 00:54:24 +0000364 virtual void ActOnFields(Scope* S,
Steve Naroff33a1e802007-10-29 21:38:07 +0000365 SourceLocation RecLoc, DeclTy *TagDecl,
366 DeclTy **Fields, unsigned NumFields,
Daniel Dunbar15619c72008-10-03 02:03:53 +0000367 SourceLocation LBrac, SourceLocation RBrac,
368 AttributeList *AttrList);
Douglas Gregor82ac25e2009-01-08 20:45:30 +0000369
370 /// ActOnTagStartDefinition - Invoked when we have entered the
371 /// scope of a tag's definition (e.g., for an enumeration, class,
372 /// struct, or union).
373 virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl);
374
375 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
376 /// the definition of a tag (enumeration, class, struct, or union).
377 virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl);
378
Steve Naroff30d242c2007-09-15 18:49:24 +0000379 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4ef40012007-06-11 01:28:17 +0000380 DeclTy *LastEnumConstant,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000381 SourceLocation IdLoc, IdentifierInfo *Id,
382 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff30d242c2007-09-15 18:49:24 +0000383 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000384 DeclTy **Elements, unsigned NumElements);
Sebastian Redl842ef522008-11-08 13:00:26 +0000385
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +0000386 DeclContext *getContainingDC(DeclContext *DC);
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000387
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000388 /// Set the current declaration context until it gets popped.
Douglas Gregor91f84212008-12-11 16:49:14 +0000389 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattner0a5ff0d2008-04-06 04:47:34 +0000390 void PopDeclContext();
Argyrios Kyrtzidis853fbea2008-06-28 06:07:14 +0000391
Chris Lattner79413952008-12-04 23:50:19 +0000392 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
393 /// to the function decl for the function being parsed. If we're currently
394 /// in a 'block', this returns the containing context.
395 FunctionDecl *getCurFunctionDecl();
396
397 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
398 /// the method decl for the method being parsed. If we're currently
399 /// in a 'block', this returns the containing context.
Daniel Dunbar6e8aa532008-08-11 05:35:13 +0000400 ObjCMethodDecl *getCurMethodDecl();
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000401
Chris Lattner79413952008-12-04 23:50:19 +0000402 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
403 /// or C function we're in, otherwise return null. If we're currently
404 /// in a 'block', this returns the containing context.
405 NamedDecl *getCurFunctionOrMethodDecl();
406
Argyrios Kyrtzidisb8a49202008-04-12 00:47:19 +0000407 /// Add this decl to the scope shadowed decl chains.
408 void PushOnScopeChains(NamedDecl *D, Scope *S);
409
Argyrios Kyrtzidis5b144d52008-09-09 21:18:04 +0000410 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
411 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
412 /// true if 'D' belongs to the given declaration context.
413 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
Douglas Gregor91f84212008-12-11 16:49:14 +0000414 return IdResolver.isDeclInScope(D, Ctx, Context, S);
Argyrios Kyrtzidis5b144d52008-09-09 21:18:04 +0000415 }
416
Eli Friedmanf69d09b2009-02-28 05:41:13 +0000417
418 void RecursiveCalcJumpScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
419 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
420 llvm::DenseMap<Stmt*, void*>& GotoScopeMap,
421 std::vector<void*>& ScopeStack,
422 Stmt* CurStmt);
423
424 void RecursiveCalcLabelScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
425 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
426 std::vector<void*>& ScopeStack,
427 Stmt* CurStmt,
428 Stmt* ParentCompoundStmt);
429
Chris Lattnerefedd9e2008-02-21 01:07:18 +0000430 /// Subroutines of ActOnDeclarator().
Chris Lattner07b201d2007-11-14 06:34:38 +0000431 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000432 Decl *LastDecl);
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000433 bool MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
434 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
Douglas Gregore62c0a42009-02-24 01:23:02 +0000435 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregor75a45ba2009-02-16 17:45:42 +0000436 bool MergeVarDecl(VarDecl *New, Decl *Old);
437 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Steve Naroff5bb8f222008-08-08 17:50:35 +0000438 void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000439
440 /// C++ Overloading.
441 bool IsOverload(FunctionDecl *New, Decl* OldD,
442 OverloadedFunctionDecl::function_iterator &MatchedDecl);
Douglas Gregor2fe98832008-11-03 19:09:14 +0000443 ImplicitConversionSequence
444 TryImplicitConversion(Expr* From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000445 bool SuppressUserConversions = false,
446 bool AllowExplicit = false);
Douglas Gregor26bee0b2008-10-31 16:23:19 +0000447 bool IsStandardConversion(Expr *From, QualType ToType,
448 StandardConversionSequence& SCS);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000449 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
450 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
Douglas Gregor78ca74d2009-02-12 00:15:05 +0000451 bool IsComplexPromotion(QualType FromType, QualType ToType);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000452 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregor47d3f272008-12-19 17:40:08 +0000453 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregora119f102008-12-19 19:13:09 +0000454 bool isObjCPointerConversion(QualType FromType, QualType ToType,
455 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregor39c16d42008-10-24 04:54:22 +0000456 bool CheckPointerConversion(Expr *From, QualType ToType);
Sebastian Redl72b597d2009-01-25 19:43:20 +0000457 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
458 QualType &ConvertedType);
459 bool CheckMemberPointerConversion(Expr *From, QualType ToType);
Douglas Gregor9a657932008-10-21 23:43:52 +0000460 bool IsQualificationConversion(QualType FromType, QualType ToType);
Douglas Gregor26bee0b2008-10-31 16:23:19 +0000461 bool IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000462 UserDefinedConversionSequence& User,
Douglas Gregor576e98c2009-01-30 23:27:23 +0000463 bool AllowConversionFunctions,
464 bool AllowExplicit);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000465
466 ImplicitConversionSequence::CompareKind
467 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
468 const ImplicitConversionSequence& ICS2);
469
470 ImplicitConversionSequence::CompareKind
471 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
472 const StandardConversionSequence& SCS2);
473
Douglas Gregore1eb9d82008-10-22 14:17:15 +0000474 ImplicitConversionSequence::CompareKind
475 CompareQualificationConversions(const StandardConversionSequence& SCS1,
476 const StandardConversionSequence& SCS2);
477
Douglas Gregor5c407d92008-10-23 00:40:37 +0000478 ImplicitConversionSequence::CompareKind
479 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
480 const StandardConversionSequence& SCS2);
481
Douglas Gregor2fe98832008-11-03 19:09:14 +0000482 ImplicitConversionSequence
483 TryCopyInitialization(Expr* From, QualType ToType,
484 bool SuppressUserConversions = false);
Douglas Gregor8e1cf602008-10-29 00:13:59 +0000485 bool PerformCopyInitialization(Expr *&From, QualType ToType,
486 const char *Flavor);
487
Douglas Gregor436424c2008-11-18 23:14:02 +0000488 ImplicitConversionSequence
489 TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method);
490 bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method);
491
Douglas Gregor5fb53972009-01-14 15:45:31 +0000492 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
493 bool PerformContextuallyConvertToBool(Expr *&From);
494
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000495 /// OverloadingResult - Capture the result of performing overload
496 /// resolution.
497 enum OverloadingResult {
498 OR_Success, ///< Overload resolution succeeded.
499 OR_No_Viable_Function, ///< No viable function found.
Douglas Gregor171c45a2009-02-18 21:56:37 +0000500 OR_Ambiguous, ///< Ambiguous candidates found.
501 OR_Deleted ///< Overload resoltuion refers to a deleted function.
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000502 };
503
504 void AddOverloadCandidate(FunctionDecl *Function,
505 Expr **Args, unsigned NumArgs,
Douglas Gregor2fe98832008-11-03 19:09:14 +0000506 OverloadCandidateSet& CandidateSet,
507 bool SuppressUserConversions = false);
Douglas Gregor436424c2008-11-18 23:14:02 +0000508 void AddMethodCandidate(CXXMethodDecl *Method,
509 Expr *Object, Expr **Args, unsigned NumArgs,
510 OverloadCandidateSet& CandidateSet,
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000511 bool SuppressUserConversions = false);
Douglas Gregora1f013e2008-11-07 22:36:19 +0000512 void AddConversionCandidate(CXXConversionDecl *Conversion,
513 Expr *From, QualType ToType,
514 OverloadCandidateSet& CandidateSet);
Douglas Gregorab7897a2008-11-19 22:57:39 +0000515 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
Douglas Gregordeaad8c2009-02-26 23:50:07 +0000516 const FunctionProtoType *Proto,
Douglas Gregorab7897a2008-11-19 22:57:39 +0000517 Expr *Object, Expr **Args, unsigned NumArgs,
518 OverloadCandidateSet& CandidateSet);
Douglas Gregor94eabf32009-02-04 16:44:47 +0000519 bool AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
520 SourceLocation OpLoc,
Douglas Gregor436424c2008-11-18 23:14:02 +0000521 Expr **Args, unsigned NumArgs,
Douglas Gregor94eabf32009-02-04 16:44:47 +0000522 OverloadCandidateSet& CandidateSet,
523 SourceRange OpRange = SourceRange());
Douglas Gregora11693b2008-11-12 17:17:38 +0000524 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
525 Expr **Args, unsigned NumArgs,
Douglas Gregorc5e61072009-01-13 00:52:54 +0000526 OverloadCandidateSet& CandidateSet,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000527 bool IsAssignmentOperator = false,
528 unsigned NumContextualBoolArguments = 0);
Douglas Gregord08452f2008-11-19 15:42:04 +0000529 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
530 Expr **Args, unsigned NumArgs,
531 OverloadCandidateSet& CandidateSet);
Douglas Gregore254f902009-02-04 00:32:51 +0000532 void AddArgumentDependentLookupCandidates(DeclarationName Name,
533 Expr **Args, unsigned NumArgs,
534 OverloadCandidateSet& CandidateSet);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000535 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
536 const OverloadCandidate& Cand2);
537 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
538 OverloadCandidateSet::iterator& Best);
539 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
540 bool OnlyViable);
541
Douglas Gregorcd695e52008-11-10 20:40:00 +0000542 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
543 bool Complain);
544 void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
545
Douglas Gregorb8a9a412009-02-04 15:01:18 +0000546 FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee,
547 DeclarationName UnqualifiedName,
Douglas Gregora60a6912008-11-26 06:01:48 +0000548 SourceLocation LParenLoc,
549 Expr **Args, unsigned NumArgs,
550 SourceLocation *CommaLocs,
Douglas Gregore254f902009-02-04 00:32:51 +0000551 SourceLocation RParenLoc,
Douglas Gregorb8a9a412009-02-04 15:01:18 +0000552 bool &ArgumentDependentLookup);
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000553 ExprResult
554 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
555 SourceLocation LParenLoc, Expr **Args,
556 unsigned NumArgs, SourceLocation *CommaLocs,
557 SourceLocation RParenLoc);
Douglas Gregor91cea0a2008-11-19 21:05:33 +0000558 ExprResult
Douglas Gregorb0846b02008-12-06 00:22:45 +0000559 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregor91cea0a2008-11-19 21:05:33 +0000560 Expr **Args, unsigned NumArgs,
561 SourceLocation *CommaLocs,
562 SourceLocation RParenLoc);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000563
Douglas Gregor55297ac2008-12-23 00:26:44 +0000564 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
Douglas Gregore0e79bd2008-11-20 16:27:02 +0000565 SourceLocation MemberLoc,
566 IdentifierInfo &Member);
Douglas Gregor5fb53972009-01-14 15:45:31 +0000567
Chris Lattnerce1da2c2009-01-06 07:27:21 +0000568 /// Helpers for dealing with function parameters.
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000569 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000570 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregorcaa8ace2008-05-07 04:49:29 +0000571 void CheckExtraCXXDefaultArguments(Declarator &D);
Steve Naroff6fbf0dc2007-03-16 00:33:25 +0000572
Douglas Gregor45a33ec2009-01-12 18:45:55 +0000573 Scope *getNonFieldDeclScope(Scope *S);
574
Douglas Gregor34074322009-01-14 22:20:51 +0000575 /// \name Name lookup
576 ///
577 /// These routines provide name lookup that is used during semantic
578 /// analysis to resolve the various kinds of names (identifiers,
579 /// overloaded operator names, constructor names, etc.) into zero or
580 /// more declarations within a particular scope. The major entry
581 /// points are LookupName, which performs unqualified name lookup,
582 /// and LookupQualifiedName, which performs qualified name lookup.
583 ///
584 /// All name lookup is performed based on some specific criteria,
585 /// which specify what names will be visible to name lookup and how
586 /// far name lookup should work. These criteria are important both
587 /// for capturing language semantics (certain lookups will ignore
588 /// certain names, for example) and for performance, since name
589 /// lookup is often a bottleneck in the compilation of C++. Name
Douglas Gregored8f2882009-01-30 01:04:22 +0000590 /// lookup criteria is specified via the LookupCriteria enumeration.
Douglas Gregor34074322009-01-14 22:20:51 +0000591 ///
592 /// The results of name lookup can vary based on the kind of name
593 /// lookup performed, the current language, and the translation
594 /// unit. In C, for example, name lookup will either return nothing
595 /// (no entity found) or a single declaration. In C++, name lookup
596 /// can additionally refer to a set of overloaded functions or
597 /// result in an ambiguity. All of the possible results of name
598 /// lookup are captured by the LookupResult class, which provides
599 /// the ability to distinguish among them.
600 //@{
Douglas Gregord7c4d982008-12-30 03:27:21 +0000601
Douglas Gregored8f2882009-01-30 01:04:22 +0000602 /// @brief Describes the kind of name lookup to perform.
603 enum LookupNameKind {
604 /// Ordinary name lookup, which finds ordinary names (functions,
605 /// variables, typedefs, etc.) in C and most kinds of names
606 /// (functions, variables, members, types, etc.) in C++.
607 LookupOrdinaryName = 0,
608 /// Tag name lookup, which finds the names of enums, classes,
609 /// structs, and unions.
610 LookupTagName,
611 /// Member name lookup, which finds the names of
612 /// class/struct/union members.
613 LookupMemberName,
Douglas Gregor94eabf32009-02-04 16:44:47 +0000614 // Look up of an operator name (e.g., operator+) for use with
615 // operator overloading. This lookup is similar to ordinary name
616 // lookup, but will ignore any declarations that are class
617 // members.
618 LookupOperatorName,
Douglas Gregored8f2882009-01-30 01:04:22 +0000619 /// Look up of a name that precedes the '::' scope resolution
620 /// operator in C++. This lookup completely ignores operator,
621 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
622 LookupNestedNameSpecifierName,
623 /// Look up a namespace name within a C++ using directive or
624 /// namespace alias definition, ignoring non-namespace names (C++
625 /// [basic.lookup.udir]p1).
Douglas Gregoreddf4332009-02-24 20:03:32 +0000626 LookupNamespaceName,
627 // Look up an ordinary name that is going to be redeclared as a
628 // name with linkage. This lookup ignores any declarations that
629 // are outside of the current scope unless they have linkage. See
630 // C99 6.2.2p4-5 and C++ [basic.link]p6.
631 LookupRedeclarationWithLinkage
Douglas Gregor34074322009-01-14 22:20:51 +0000632 };
633
634 /// @brief Represents the results of name lookup.
635 ///
636 /// An instance of the LookupResult class captures the results of a
637 /// single name lookup, which can return no result (nothing found),
638 /// a single declaration, a set of overloaded functions, or an
639 /// ambiguity. Use the getKind() method to determine which of these
640 /// results occurred for a given lookup.
641 ///
642 /// Any non-ambiguous lookup can be converted into a single
Douglas Gregor2ada0482009-02-04 17:27:36 +0000643 /// (possibly NULL) @c NamedDecl* via a conversion function or the
Douglas Gregor34074322009-01-14 22:20:51 +0000644 /// getAsDecl() method. This conversion permits the common-case
645 /// usage in C and Objective-C where name lookup will always return
646 /// a single declaration.
Douglas Gregorf23311d2009-01-17 01:13:24 +0000647 struct LookupResult {
Douglas Gregor34074322009-01-14 22:20:51 +0000648 /// The kind of entity that is actually stored within the
649 /// LookupResult object.
Douglas Gregorf23311d2009-01-17 01:13:24 +0000650 enum {
Douglas Gregor2ada0482009-02-04 17:27:36 +0000651 /// First is a single declaration (a NamedDecl*), which may be NULL.
Douglas Gregor34074322009-01-14 22:20:51 +0000652 SingleDecl,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000653
Douglas Gregor889ceb72009-02-03 19:21:40 +0000654 /// First is a single declaration (an OverloadedFunctionDecl*).
655 OverloadedDeclSingleDecl,
656
Douglas Gregor34074322009-01-14 22:20:51 +0000657 /// [First, Last) is an iterator range represented as opaque
658 /// pointers used to reconstruct IdentifierResolver::iterators.
659 OverloadedDeclFromIdResolver,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000660
Douglas Gregor34074322009-01-14 22:20:51 +0000661 /// [First, Last) is an iterator range represented as opaque
662 /// pointers used to reconstruct DeclContext::lookup_iterators.
663 OverloadedDeclFromDeclContext,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000664
665 /// First is a pointer to a BasePaths structure, which is owned
666 /// by the LookupResult. Last is non-zero to indicate that the
667 /// ambiguity is caused by two names found in base class
668 /// subobjects of different types.
Douglas Gregor889ceb72009-02-03 19:21:40 +0000669 AmbiguousLookupStoresBasePaths,
670
671 /// [First, Last) is an iterator range represented as opaque
672 /// pointers used to reconstruct new'ed Decl*[] array containing
673 /// found ambiguous decls. LookupResult is owner of this array.
674 AmbiguousLookupStoresDecls
675
Douglas Gregor34074322009-01-14 22:20:51 +0000676 } StoredKind;
677
678 /// The first lookup result, whose contents depend on the kind of
Douglas Gregor2ada0482009-02-04 17:27:36 +0000679 /// lookup result. This may be a NamedDecl* (if StoredKind ==
680 /// SingleDecl), OverloadedFunctionDecl* (if StoredKind ==
681 /// OverloadedDeclSingleDecl), the opaque pointer from an
Douglas Gregor34074322009-01-14 22:20:51 +0000682 /// IdentifierResolver::iterator (if StoredKind ==
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000683 /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator
684 /// (if StoredKind == OverloadedDeclFromDeclContext), or a
Douglas Gregor889ceb72009-02-03 19:21:40 +0000685 /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor34074322009-01-14 22:20:51 +0000686 mutable uintptr_t First;
687
688 /// The last lookup result, whose contents depend on the kind of
689 /// lookup result. This may be unused (if StoredKind ==
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000690 /// SingleDecl), it may have the same type as First (for
691 /// overloaded function declarations), or is may be used as a
Douglas Gregor889ceb72009-02-03 19:21:40 +0000692 /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor34074322009-01-14 22:20:51 +0000693 mutable uintptr_t Last;
694
695 /// Context - The context in which we will build any
696 /// OverloadedFunctionDecl nodes needed by the conversion to
697 /// Decl*.
698 ASTContext *Context;
699
Douglas Gregor34074322009-01-14 22:20:51 +0000700 /// @brief The kind of entity found by name lookup.
701 enum LookupKind {
702 /// @brief No entity found met the criteria.
703 NotFound = 0,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000704
Douglas Gregor34074322009-01-14 22:20:51 +0000705 /// @brief Name lookup found a single declaration that met the
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000706 /// criteria. getAsDecl will return this declaration.
Douglas Gregor34074322009-01-14 22:20:51 +0000707 Found,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000708
Douglas Gregor34074322009-01-14 22:20:51 +0000709 /// @brief Name lookup found a set of overloaded functions that
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000710 /// met the criteria. getAsDecl will turn this set of overloaded
711 /// functions into an OverloadedFunctionDecl.
Douglas Gregor34074322009-01-14 22:20:51 +0000712 FoundOverloaded,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000713
714 /// Name lookup results in an ambiguity because multiple
715 /// entities that meet the lookup criteria were found in
716 /// subobjects of different types. For example:
717 /// @code
718 /// struct A { void f(int); }
719 /// struct B { void f(double); }
720 /// struct C : A, B { };
721 /// void test(C c) {
722 /// c.f(0); // error: A::f and B::f come from subobjects of different
723 /// // types. overload resolution is not performed.
724 /// }
725 /// @endcode
726 AmbiguousBaseSubobjectTypes,
727
728 /// Name lookup results in an ambiguity because multiple
729 /// nonstatic entities that meet the lookup criteria were found
730 /// in different subobjects of the same type. For example:
731 /// @code
732 /// struct A { int x; };
733 /// struct B : A { };
734 /// struct C : A { };
735 /// struct D : B, C { };
736 /// int test(D d) {
737 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
738 /// }
739 /// @endcode
Douglas Gregor889ceb72009-02-03 19:21:40 +0000740 AmbiguousBaseSubobjects,
741
742 /// Name lookup results in an ambiguity because multiple definitions
743 /// of entity that meet the lookup criteria were found in different
744 /// declaration contexts.
745 /// @code
746 /// namespace A {
747 /// int i;
748 /// namespace B { int i; }
749 /// int test() {
750 /// using namespace B;
751 /// return i; // error 'i' is found in namespace A and A::B
752 /// }
753 /// }
754 /// @endcode
755 AmbiguousReference
Douglas Gregor34074322009-01-14 22:20:51 +0000756 };
757
Douglas Gregor2ada0482009-02-04 17:27:36 +0000758 static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D);
Douglas Gregor41c8ba82009-01-15 02:19:31 +0000759
Douglas Gregorf23311d2009-01-17 01:13:24 +0000760 static LookupResult CreateLookupResult(ASTContext &Context,
761 IdentifierResolver::iterator F,
762 IdentifierResolver::iterator L);
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000763
Douglas Gregorf23311d2009-01-17 01:13:24 +0000764 static LookupResult CreateLookupResult(ASTContext &Context,
765 DeclContext::lookup_iterator F,
766 DeclContext::lookup_iterator L);
Douglas Gregor34074322009-01-14 22:20:51 +0000767
Douglas Gregorf23311d2009-01-17 01:13:24 +0000768 static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths,
769 bool DifferentSubobjectTypes) {
770 LookupResult Result;
Douglas Gregor889ceb72009-02-03 19:21:40 +0000771 Result.StoredKind = AmbiguousLookupStoresBasePaths;
Douglas Gregorf23311d2009-01-17 01:13:24 +0000772 Result.First = reinterpret_cast<uintptr_t>(Paths);
773 Result.Last = DifferentSubobjectTypes? 1 : 0;
774 Result.Context = &Context;
775 return Result;
776 }
Douglas Gregor41c8ba82009-01-15 02:19:31 +0000777
Douglas Gregor889ceb72009-02-03 19:21:40 +0000778 template <typename Iterator>
779 static LookupResult CreateLookupResult(ASTContext &Context,
780 Iterator B, std::size_t Len) {
Douglas Gregor2ada0482009-02-04 17:27:36 +0000781 NamedDecl ** Array = new NamedDecl*[Len];
Douglas Gregor889ceb72009-02-03 19:21:40 +0000782 for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B)
783 Array[Idx] = *B;
784 LookupResult Result;
785 Result.StoredKind = AmbiguousLookupStoresDecls;
786 Result.First = reinterpret_cast<uintptr_t>(Array);
787 Result.Last = reinterpret_cast<uintptr_t>(Array + Len);
788 Result.Context = &Context;
789 return Result;
790 }
791
Douglas Gregor34074322009-01-14 22:20:51 +0000792 LookupKind getKind() const;
793
794 /// @brief Determine whether name look found something.
795 operator bool() const { return getKind() != NotFound; }
796
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000797 /// @brief Determines whether the lookup resulted in an ambiguity.
Douglas Gregor889ceb72009-02-03 19:21:40 +0000798 bool isAmbiguous() const {
799 return StoredKind == AmbiguousLookupStoresBasePaths ||
800 StoredKind == AmbiguousLookupStoresDecls;
801 }
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000802
Douglas Gregor34074322009-01-14 22:20:51 +0000803 /// @brief Allows conversion of a lookup result into a
804 /// declaration, with the same behavior as getAsDecl.
Douglas Gregor2ada0482009-02-04 17:27:36 +0000805 operator NamedDecl*() const { return getAsDecl(); }
Douglas Gregor34074322009-01-14 22:20:51 +0000806
Douglas Gregor2ada0482009-02-04 17:27:36 +0000807 NamedDecl* getAsDecl() const;
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000808
809 BasePaths *getBasePaths() const;
Douglas Gregor0e8fc3c2009-02-02 21:35:47 +0000810
811 /// \brief Iterate over the results of name lookup.
812 ///
813 /// The @c iterator class provides iteration over the results of a
814 /// non-ambiguous name lookup.
815 class iterator {
816 /// The LookupResult structure we're iterating through.
817 LookupResult *Result;
818
819 /// The current position of this iterator within the sequence of
820 /// results. This value will have the same representation as the
821 /// @c First field in the LookupResult structure.
822 mutable uintptr_t Current;
823
824 public:
Douglas Gregor2ada0482009-02-04 17:27:36 +0000825 typedef NamedDecl * value_type;
826 typedef NamedDecl * reference;
827 typedef NamedDecl * pointer;
Douglas Gregor0e8fc3c2009-02-02 21:35:47 +0000828 typedef std::ptrdiff_t difference_type;
829 typedef std::forward_iterator_tag iterator_category;
830
831 iterator() : Result(0), Current(0) { }
832
833 iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { }
834
835 reference operator*() const;
836
837 pointer operator->() const { return **this; }
838
839 iterator &operator++();
840
841 iterator operator++(int) {
842 iterator tmp(*this);
843 ++(*this);
844 return tmp;
845 }
846
847 friend inline bool operator==(iterator const& x, iterator const& y) {
848 return x.Current == y.Current;
849 }
850
851 friend inline bool operator!=(iterator const& x, iterator const& y) {
852 return x.Current != y.Current;
853 }
854 };
855 friend class iterator;
856
857 iterator begin();
858 iterator end();
Douglas Gregor34074322009-01-14 22:20:51 +0000859 };
860
Douglas Gregor889ceb72009-02-03 19:21:40 +0000861private:
862 typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy;
863
864 std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name,
865 LookupNameKind NameKind,
866 bool RedeclarationOnly);
867
868public:
Douglas Gregored8f2882009-01-30 01:04:22 +0000869 /// Determines whether D is a suitable lookup result according to the
870 /// lookup criteria.
Douglas Gregoreddf4332009-02-24 20:03:32 +0000871 static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind,
Douglas Gregor700792c2009-02-05 19:25:20 +0000872 unsigned IDNS) {
Douglas Gregored8f2882009-01-30 01:04:22 +0000873 switch (NameKind) {
874 case Sema::LookupOrdinaryName:
875 case Sema::LookupTagName:
876 case Sema::LookupMemberName:
Douglas Gregoreddf4332009-02-24 20:03:32 +0000877 case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
Douglas Gregored8f2882009-01-30 01:04:22 +0000878 return D->isInIdentifierNamespace(IDNS);
879
Douglas Gregor94eabf32009-02-04 16:44:47 +0000880 case Sema::LookupOperatorName:
881 return D->isInIdentifierNamespace(IDNS) &&
882 !D->getDeclContext()->isRecord();
883
Douglas Gregored8f2882009-01-30 01:04:22 +0000884 case Sema::LookupNestedNameSpecifierName:
885 return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag);
886
887 case Sema::LookupNamespaceName:
888 return isa<NamespaceDecl>(D);
889 }
890
891 assert(false &&
Douglas Gregor700792c2009-02-05 19:25:20 +0000892 "isAcceptableLookupResult always returns before this point");
Douglas Gregored8f2882009-01-30 01:04:22 +0000893 return false;
894 }
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000895
Douglas Gregored8f2882009-01-30 01:04:22 +0000896 LookupResult LookupName(Scope *S, DeclarationName Name,
897 LookupNameKind NameKind,
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000898 bool RedeclarationOnly = false,
899 bool AllowBuiltinCreation = true,
900 SourceLocation Loc = SourceLocation());
Douglas Gregored8f2882009-01-30 01:04:22 +0000901 LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name,
902 LookupNameKind NameKind,
903 bool RedeclarationOnly = false);
904 LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS,
905 DeclarationName Name,
906 LookupNameKind NameKind,
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000907 bool RedeclarationOnly = false,
908 bool AllowBuiltinCreation = true,
909 SourceLocation Loc = SourceLocation());
Douglas Gregore254f902009-02-04 00:32:51 +0000910
911 typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet;
912 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
913
914 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
915 AssociatedNamespaceSet &AssociatedNamespaces,
916 AssociatedClassSet &AssociatedClasses);
917
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000918 bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
919 SourceLocation NameLoc,
920 SourceRange LookupRange = SourceRange());
Douglas Gregor34074322009-01-14 22:20:51 +0000921 //@}
922
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000923 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000924 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000925 Scope *S, bool ForRedeclaration,
926 SourceLocation Loc);
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000927 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
928 Scope *S);
Douglas Gregore711f702009-02-14 18:57:46 +0000929 void AddKnownFunctionAttributes(FunctionDecl *FD);
Douglas Gregor34074322009-01-14 22:20:51 +0000930
931 // More parsing and symbol table subroutines.
932
Steve Naroffa8fd9732007-06-11 00:35:03 +0000933 // Decl attributes - this routine is the top level dispatcher.
Chris Lattner58418ff2008-06-29 00:16:31 +0000934 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnera5741542008-06-28 23:58:55 +0000935 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lamb025b5fb2008-02-04 02:31:56 +0000936
Steve Naroff15833ed2008-02-10 21:38:56 +0000937 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
938 bool &IncompleteImpl);
Fariborz Jahanian7988d7d2008-12-05 18:18:52 +0000939 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
940 ObjCMethodDecl *IntfMethod);
Sebastian Redlc4704762008-11-11 11:37:55 +0000941
942 NamespaceDecl *GetStdNamespace();
Fariborz Jahanian8e1555c2009-01-12 19:55:42 +0000943
944 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
Steve Naroffde680012009-02-26 19:11:32 +0000945 ObjCInterfaceDecl *IDecl);
Steve Naroff15833ed2008-02-10 21:38:56 +0000946
Chris Lattnerce1da2c2009-01-06 07:27:21 +0000947 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbarc7dfbfd2008-09-04 20:01:15 +0000948 /// methods declared in protocol, and those referenced by it.
949 /// \param IDecl - Used for checking for methods which may have been
950 /// inherited.
Steve Naroffa36992242008-02-08 22:06:17 +0000951 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
952 ObjCProtocolDecl *PDecl,
Fariborz Jahanianadf84f32007-10-02 20:06:01 +0000953 bool& IncompleteImpl,
Steve Naroff71c3c1c2007-10-08 21:05:34 +0000954 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbarc7dfbfd2008-09-04 20:01:15 +0000955 const llvm::DenseSet<Selector> &ClsMap,
956 ObjCInterfaceDecl *IDecl);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000957
Steve Naroffd1741552007-10-02 21:43:37 +0000958 /// CheckImplementationIvars - This routine checks if the instance variables
959 /// listed in the implelementation match those listed in the interface.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000960 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
961 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff15833ed2008-02-10 21:38:56 +0000962 SourceLocation Loc);
Steve Naroffd1741552007-10-02 21:43:37 +0000963
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000964 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
Chris Lattner9ef10f42009-03-01 00:56:52 +0000965 /// remains unimplemented in the class or category @implementation.
966 void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl,
967 ObjCContainerDecl* IDecl,
968 bool IncompleteImpl = false);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000969
Fariborz Jahanian458f7112007-10-05 18:00:57 +0000970 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
971 /// true, or false, accordingly.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000972 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Naroffa0ed1652008-10-21 10:37:50 +0000973 const ObjCMethodDecl *PrevMethod,
974 bool matchBasedOnSizeAndAlignment = false);
Steve Naroff7f549f12007-10-10 21:53:07 +0000975
Steve Naroff5811baf2007-10-14 00:58:41 +0000976 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
977 /// unit are added to a global pool. This allows us to efficiently associate
978 /// a selector with a method declaraation for purposes of typechecking
979 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000980 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff5811baf2007-10-14 00:58:41 +0000981
Steve Naroff4a82d812008-09-30 14:38:43 +0000982 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
983 /// there are multiple signatures.
984 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
985
Steve Naroff5811baf2007-10-14 00:58:41 +0000986 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000987 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000988 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000989 // Statement Parsing Callbacks: SemaStmt.cpp.
Steve Naroff3273c222007-03-14 21:52:03 +0000990public:
Sebastian Redl52f03ba2008-12-21 12:04:03 +0000991 virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
992
993 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
994 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
995 MultiStmtArg Elts,
996 bool isStmtExpr);
997 virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
998 SourceLocation EndLoc);
Sebastian Redl1cbb59182008-12-28 16:13:43 +0000999 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
1000 SourceLocation DotDotDotLoc, ExprArg RHSVal,
Chris Lattner34a22092009-03-04 04:23:07 +00001001 SourceLocation ColonLoc);
1002 virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt);
1003
Sebastian Redl1cbb59182008-12-28 16:13:43 +00001004 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1005 SourceLocation ColonLoc,
1006 StmtArg SubStmt, Scope *CurScope);
Sebastian Redl6a8002e2009-01-11 00:38:46 +00001007 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
1008 IdentifierInfo *II,
1009 SourceLocation ColonLoc,
1010 StmtArg SubStmt);
1011 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
1012 StmtArg ThenVal, SourceLocation ElseLoc,
1013 StmtArg ElseVal);
1014 virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
1015 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1016 StmtArg Switch, StmtArg Body);
Sebastian Redlfbfaafc2009-01-16 23:28:06 +00001017 virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
1018 StmtArg Body);
1019 virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
1020 SourceLocation WhileLoc, ExprArg Cond);
1021
1022 virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
1023 SourceLocation LParenLoc,
1024 StmtArg First, ExprArg Second,
1025 ExprArg Third, SourceLocation RParenLoc,
1026 StmtArg Body);
1027 virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1028 SourceLocation LParenLoc,
1029 StmtArg First, ExprArg Second,
1030 SourceLocation RParenLoc, StmtArg Body);
Sebastian Redl573feed2009-01-18 13:19:59 +00001031
1032 virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1033 SourceLocation LabelLoc,
1034 IdentifierInfo *LabelII);
1035 virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1036 SourceLocation StarLoc,
1037 ExprArg DestExp);
1038 virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
1039 Scope *CurScope);
1040 virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
1041 Scope *CurScope);
1042
1043 virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
1044 ExprArg RetValExp);
1045 OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
1046 Expr *RetValExp);
1047
Sebastian Redl24b8e152009-01-18 16:53:17 +00001048 virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1049 bool IsSimple,
1050 bool IsVolatile,
1051 unsigned NumOutputs,
1052 unsigned NumInputs,
1053 std::string *Names,
1054 MultiExprArg Constraints,
1055 MultiExprArg Exprs,
1056 ExprArg AsmString,
1057 MultiExprArg Clobbers,
1058 SourceLocation RParenLoc);
Sebastian Redl481bf3f2009-01-18 17:43:11 +00001059
1060 virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
1061 SourceLocation RParen,
Steve Naroff371b8fb2009-03-03 19:52:17 +00001062 DeclTy *Parm, StmtArg Body,
Sebastian Redl481bf3f2009-01-18 17:43:11 +00001063 StmtArg CatchList);
1064
1065 virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
1066 StmtArg Body);
1067
1068 virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
1069 StmtArg Try,
1070 StmtArg Catch, StmtArg Finally);
1071
1072 virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Steve Naroff5ee2c022009-02-11 20:05:44 +00001073 ExprArg Throw,
1074 Scope *CurScope);
Sebastian Redl481bf3f2009-01-18 17:43:11 +00001075 virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1076 ExprArg SynchExpr,
1077 StmtArg SynchBody);
Sebastian Redlb219c902008-12-21 16:41:36 +00001078
Sebastian Redl54c04d42008-12-22 19:15:10 +00001079 virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D);
1080 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
1081 DeclTy *ExDecl,
1082 StmtArg HandlerBlock);
Sebastian Redl9b244a82008-12-22 21:35:02 +00001083 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
1084 StmtArg TryBlock,
1085 MultiStmtArg Handlers);
Sebastian Redlb219c902008-12-21 16:41:36 +00001086
Chris Lattner7cee11f2006-11-03 06:42:29 +00001087 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +00001088 // Expression Parsing Callbacks: SemaExpr.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +00001089
Douglas Gregor171c45a2009-02-18 21:56:37 +00001090 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
Chris Lattner4bf74fd2009-02-15 22:43:40 +00001091
Chris Lattner7cee11f2006-11-03 06:42:29 +00001092 // Primary Expressions.
Douglas Gregor87f95b02009-02-26 21:00:50 +00001093 virtual SourceRange getExprRange(ExprTy *E) const;
1094
Sebastian Redlffbcf962009-01-18 18:53:16 +00001095 virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
1096 IdentifierInfo &II,
1097 bool HasTrailingLParen,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001098 const CXXScopeSpec *SS = 0,
1099 bool isAddressOfOperand = false);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001100 virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S,
Douglas Gregor7911b372008-11-19 19:09:45 +00001101 SourceLocation OperatorLoc,
1102 OverloadedOperatorKind Op,
1103 bool HasTrailingLParen,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001104 const CXXScopeSpec &SS,
1105 bool isAddressOfOperand);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001106 virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S,
Douglas Gregor7911b372008-11-19 19:09:45 +00001107 SourceLocation OperatorLoc,
1108 TypeTy *Ty,
1109 bool HasTrailingLParen,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001110 const CXXScopeSpec &SS,
1111 bool isAddressOfOperand);
Douglas Gregorc7acfdf2009-01-06 05:10:23 +00001112 DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
1113 bool TypeDependent, bool ValueDependent,
1114 const CXXScopeSpec *SS = 0);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001115 OwningExprResult
Douglas Gregor9ac7a072009-01-07 00:43:41 +00001116 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1117 FieldDecl *Field,
1118 Expr *BaseObjectExpr = 0,
1119 SourceLocation OpLoc = SourceLocation());
Sebastian Redlffbcf962009-01-18 18:53:16 +00001120 OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
1121 DeclarationName Name,
1122 bool HasTrailingLParen,
1123 const CXXScopeSpec *SS,
Sebastian Redl3d3f75a2009-02-03 20:19:35 +00001124 bool isAddressOfOperand = false);
Douglas Gregor4ea80432008-11-18 15:03:34 +00001125
Sebastian Redlffbcf962009-01-18 18:53:16 +00001126 virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
1127 tok::TokenKind Kind);
1128 virtual OwningExprResult ActOnNumericConstant(const Token &);
1129 virtual OwningExprResult ActOnCharacterConstant(const Token &);
1130 virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
1131 ExprArg Val);
Chris Lattner697e5d62006-11-09 06:32:27 +00001132
Steve Naroff83895f72007-09-16 03:34:24 +00001133 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner697e5d62006-11-09 06:32:27 +00001134 /// fragments (e.g. "foo" "bar" L"baz").
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001135 virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
1136 unsigned NumToks);
Sebastian Redlffbcf962009-01-18 18:53:16 +00001137
Chris Lattner7cee11f2006-11-03 06:42:29 +00001138 // Binary/Unary Operators. 'Tok' is the token for the operator.
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001139 virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1140 tok::TokenKind Op, ExprArg Input);
1141 virtual OwningExprResult
Sebastian Redl6f282892008-11-11 17:56:53 +00001142 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1143 void *TyOrEx, const SourceRange &ArgRange);
1144
Chris Lattner8dff0172009-01-24 20:17:12 +00001145 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R);
Sebastian Redl6f282892008-11-11 17:56:53 +00001146 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1147 const SourceRange &R, bool isSizeof);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001148
1149 virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1150 tok::TokenKind Kind,
1151 ExprArg Input);
1152
1153 virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
1154 SourceLocation LLoc,
1155 ExprArg Idx,
1156 SourceLocation RLoc);
1157 virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base,
1158 SourceLocation OpLoc,
1159 tok::TokenKind OpKind,
1160 SourceLocation MemberLoc,
1161 IdentifierInfo &Member);
1162 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
Douglas Gregor97fd6e22008-12-22 05:46:06 +00001163 FunctionDecl *FDecl,
Douglas Gregordeaad8c2009-02-26 23:50:07 +00001164 const FunctionProtoType *Proto,
Douglas Gregor97fd6e22008-12-22 05:46:06 +00001165 Expr **Args, unsigned NumArgs,
1166 SourceLocation RParenLoc);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001167
Steve Naroff83895f72007-09-16 03:34:24 +00001168 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner7cee11f2006-11-03 06:42:29 +00001169 /// This provides the location of the left/right parens and a list of comma
1170 /// locations.
Sebastian Redlc215cfc2009-01-19 00:08:26 +00001171 virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn,
1172 SourceLocation LParenLoc,
1173 MultiExprArg Args,
1174 SourceLocation *CommaLocs,
1175 SourceLocation RParenLoc);
1176
Sebastian Redlb5d49352009-01-19 22:31:54 +00001177 virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
1178 SourceLocation RParenLoc, ExprArg Op);
1179
1180 virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1181 TypeTy *Ty,
1182 SourceLocation RParenLoc,
1183 ExprArg Op);
1184
1185 virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
1186 MultiExprArg InitList,
1187 InitListDesignations &Designators,
1188 SourceLocation RParenLoc);
1189
Douglas Gregore4a0bb72009-01-22 00:58:24 +00001190 virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
1191 SourceLocation Loc,
1192 bool UsedColonSyntax,
1193 OwningExprResult Init);
1194
Sebastian Redlb5d49352009-01-19 22:31:54 +00001195 virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1196 tok::TokenKind Kind,
1197 ExprArg LHS, ExprArg RHS);
1198 OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1199 unsigned Opc, Expr *lhs, Expr *rhs);
Douglas Gregor7d5fc7e2008-11-06 23:29:22 +00001200
Steve Naroff83895f72007-09-16 03:34:24 +00001201 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner7cee11f2006-11-03 06:42:29 +00001202 /// in the case of a the GNU conditional expr extension.
Sebastian Redlb5d49352009-01-19 22:31:54 +00001203 virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1204 SourceLocation ColonLoc,
1205 ExprArg Cond, ExprArg LHS,
1206 ExprArg RHS);
Chris Lattner29375652006-12-04 18:06:35 +00001207
Steve Naroff66356bd2007-09-16 14:56:35 +00001208 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1209 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Chris Lattnereefa10e2007-05-28 06:56:27 +00001210 IdentifierInfo *LabelII);
1211
Steve Naroff66356bd2007-09-16 14:56:35 +00001212 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattner366727f2007-07-24 16:58:17 +00001213 SourceLocation RPLoc); // "({..})"
Chris Lattnerf17bd422007-08-30 17:45:32 +00001214
1215 /// __builtin_offsetof(type, a.b[123][456].c)
Douglas Gregor55297ac2008-12-23 00:26:44 +00001216 virtual ExprResult ActOnBuiltinOffsetOf(Scope *S,
1217 SourceLocation BuiltinLoc,
Chris Lattnerf17bd422007-08-30 17:45:32 +00001218 SourceLocation TypeLoc, TypeTy *Arg1,
1219 OffsetOfComponent *CompPtr,
1220 unsigned NumComponents,
1221 SourceLocation RParenLoc);
1222
Steve Naroff78864672007-08-01 22:05:33 +00001223 // __builtin_types_compatible_p(type1, type2)
Steve Naroff66356bd2007-09-16 14:56:35 +00001224 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff78864672007-08-01 22:05:33 +00001225 TypeTy *arg1, TypeTy *arg2,
1226 SourceLocation RPLoc);
Steve Naroff9efdabc2007-08-03 21:21:27 +00001227
1228 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff66356bd2007-09-16 14:56:35 +00001229 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroff9efdabc2007-08-03 21:21:27 +00001230 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
1231 SourceLocation RPLoc);
Chris Lattner366727f2007-07-24 16:58:17 +00001232
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001233 // __builtin_va_arg(expr, type)
1234 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1235 ExprTy *expr, TypeTy *type,
1236 SourceLocation RPLoc);
Steve Naroffc540d662008-09-03 18:15:37 +00001237
Douglas Gregor3be4b122008-11-29 04:51:27 +00001238 // __null
1239 virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1240
Steve Naroffc540d662008-09-03 18:15:37 +00001241 //===------------------------- "Block" Extension ------------------------===//
1242
1243 /// ActOnBlockStart - This callback is invoked when a block literal is
1244 /// started.
Steve Naroff1d95e5a2008-10-10 01:28:17 +00001245 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1246
1247 /// ActOnBlockArguments - This callback allows processing of block arguments.
1248 /// If there are no arguments, this is still invoked.
Mike Stump82f071f2009-02-04 22:31:32 +00001249 virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
Steve Naroffc540d662008-09-03 18:15:37 +00001250
1251 /// ActOnBlockError - If there is an error parsing a block, this callback
1252 /// is invoked to pop the information about the block from the action impl.
1253 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1254
1255 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1256 /// literal was successfully completed. ^(int x){...}
1257 virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
1258 Scope *CurScope);
1259
Chris Lattner4bf74fd2009-02-15 22:43:40 +00001260 //===---------------------------- C++ Features --------------------------===//
1261
Argyrios Kyrtzidis08114892008-04-27 13:50:30 +00001262 // Act on C++ namespaces
1263 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
1264 IdentifierInfo *Ident,
1265 SourceLocation LBrace);
1266 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
1267
Douglas Gregord7c4d982008-12-30 03:27:21 +00001268 virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
1269 SourceLocation UsingLoc,
1270 SourceLocation NamespcLoc,
1271 const CXXScopeSpec &SS,
1272 SourceLocation IdentLoc,
1273 IdentifierInfo *NamespcName,
1274 AttributeList *AttrList);
1275
Douglas Gregor889ceb72009-02-03 19:21:40 +00001276 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
1277
Argyrios Kyrtzidis9a1191c2008-10-06 17:10:33 +00001278 /// AddCXXDirectInitializerToDecl - This action is called immediately after
1279 /// ActOnDeclarator, when a C++ direct initializer is present.
1280 /// e.g: "int x(1);"
1281 virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
1282 SourceLocation LParenLoc,
1283 ExprTy **Exprs, unsigned NumExprs,
1284 SourceLocation *CommaLocs,
1285 SourceLocation RParenLoc);
1286
Douglas Gregor6f543152008-11-05 15:29:30 +00001287 /// InitializationKind - Represents which kind of C++ initialization
1288 /// [dcl.init] a routine is to perform.
1289 enum InitializationKind {
1290 IK_Direct, ///< Direct initialization
1291 IK_Copy, ///< Copy initialization
1292 IK_Default ///< Default initialization
1293 };
1294
Douglas Gregorc28b57d2008-11-03 20:45:27 +00001295 CXXConstructorDecl *
Douglas Gregor6f543152008-11-05 15:29:30 +00001296 PerformInitializationByConstructor(QualType ClassType,
1297 Expr **Args, unsigned NumArgs,
1298 SourceLocation Loc, SourceRange Range,
Chris Lattnerf3d3fae2008-11-24 05:29:24 +00001299 DeclarationName InitEntity,
Douglas Gregor6f543152008-11-05 15:29:30 +00001300 InitializationKind Kind);
Douglas Gregorc28b57d2008-11-03 20:45:27 +00001301
Douglas Gregore200adc2008-10-27 19:41:14 +00001302 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
1303 virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
1304 SourceLocation LAngleBracketLoc, TypeTy *Ty,
1305 SourceLocation RAngleBracketLoc,
1306 SourceLocation LParenLoc, ExprTy *E,
1307 SourceLocation RParenLoc);
Bill Wendling4073ed52007-02-13 01:51:42 +00001308
Sebastian Redlc4704762008-11-11 11:37:55 +00001309 /// ActOnCXXTypeidOfType - Parse typeid( type-id ).
1310 virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
1311 SourceLocation LParenLoc, bool isType,
1312 void *TyOrExpr, SourceLocation RParenLoc);
1313
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001314 //// ActOnCXXThis - Parse 'this' pointer.
1315 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
1316
Steve Naroff66356bd2007-09-16 14:56:35 +00001317 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
1318 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Bill Wendlingbf313b02007-02-13 20:09:46 +00001319 tok::TokenKind Kind);
Anders Carlsson76f4a902007-08-21 17:43:55 +00001320
Chris Lattnerb7e656b2008-02-26 00:51:44 +00001321 //// ActOnCXXThrow - Parse throw expressions.
1322 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
1323 ExprTy *expr);
1324
Argyrios Kyrtzidis857fcc22008-08-22 15:38:55 +00001325 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
1326 /// Can be interpreted either as function-style casting ("int(x)")
1327 /// or class type construction ("ClassType(x,y,z)")
1328 /// or creation of a value-initialized type ("int()").
1329 virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
1330 TypeTy *TypeRep,
1331 SourceLocation LParenLoc,
1332 ExprTy **Exprs,
1333 unsigned NumExprs,
1334 SourceLocation *CommaLocs,
1335 SourceLocation RParenLoc);
1336
Sebastian Redlbd150f42008-11-21 19:14:01 +00001337 /// ActOnCXXNew - Parsed a C++ 'new' expression.
1338 virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1339 SourceLocation PlacementLParen,
1340 ExprTy **PlacementArgs, unsigned NumPlaceArgs,
1341 SourceLocation PlacementRParen,
Sebastian Redl351bb782008-12-02 14:43:59 +00001342 bool ParenTypeId, Declarator &D,
Sebastian Redlbd150f42008-11-21 19:14:01 +00001343 SourceLocation ConstructorLParen,
1344 ExprTy **ConstructorArgs, unsigned NumConsArgs,
1345 SourceLocation ConstructorRParen);
Sebastian Redl351bb782008-12-02 14:43:59 +00001346 bool CheckAllocatedType(QualType AllocType, const Declarator &D);
Sebastian Redl1df2bbe2009-02-09 18:24:27 +00001347 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
1348 bool UseGlobal, QualType AllocType, bool IsArray,
Sebastian Redlfaf68082008-12-03 20:26:15 +00001349 Expr **PlaceArgs, unsigned NumPlaceArgs,
1350 FunctionDecl *&OperatorNew,
1351 FunctionDecl *&OperatorDelete);
Sebastian Redl1df2bbe2009-02-09 18:24:27 +00001352 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
1353 DeclarationName Name, Expr** Args,
1354 unsigned NumArgs, DeclContext *Ctx,
Sebastian Redl33a31012008-12-04 22:20:51 +00001355 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlfaf68082008-12-03 20:26:15 +00001356 void DeclareGlobalNewDelete();
1357 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
1358 QualType Argument);
Sebastian Redlbd150f42008-11-21 19:14:01 +00001359
1360 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
1361 virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
1362 bool ArrayForm, ExprTy *Operand);
1363
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +00001364 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
1365 /// C++ if/switch/while/for statement.
1366 /// e.g: "if (int x = f()) {...}"
1367 virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
1368 SourceLocation StartLoc,
1369 Declarator &D,
1370 SourceLocation EqualLoc,
1371 ExprTy *AssignExprVal);
1372
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001373 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
1374 /// pseudo-functions.
1375 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
1376 SourceLocation KWLoc,
1377 SourceLocation LParen,
1378 TypeTy *Ty,
1379 SourceLocation RParen);
1380
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001381 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
1382 /// global scope ('::').
1383 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
1384 SourceLocation CCLoc);
1385
1386 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1387 /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now
1388 /// we want to resolve "bar::". 'SS' is empty or the previously parsed
1389 /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar',
1390 /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'.
1391 /// Returns a CXXScopeTy* object representing the C++ scope.
1392 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1393 const CXXScopeSpec &SS,
1394 SourceLocation IdLoc,
1395 SourceLocation CCLoc,
Douglas Gregorae2fbad2008-11-17 20:34:05 +00001396 IdentifierInfo &II);
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001397
Douglas Gregor7f741122009-02-25 19:37:18 +00001398 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1399 /// nested-name-specifier that involves a template-id, e.g.,
1400 /// "foo::bar<int, float>::", and now we need to build a scope
1401 /// specifier. \p SS is empty or the previously parsed nested-name
1402 /// part ("foo::"), \p Type is the already-parsed class template
1403 /// specialization (or other template-id that names a type), \p
1404 /// TypeRange is the source range where the type is located, and \p
1405 /// CCLoc is the location of the trailing '::'.
1406 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1407 const CXXScopeSpec &SS,
1408 TypeTy *Type,
1409 SourceRange TypeRange,
1410 SourceLocation CCLoc);
1411
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001412 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1413 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1414 /// After this method is called, according to [C++ 3.4.3p3], names should be
1415 /// looked up in the declarator-id's scope, until the declarator is parsed and
1416 /// ActOnCXXExitDeclaratorScope is called.
1417 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1418 virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
1419
1420 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1421 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1422 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1423 /// Used to indicate that names should revert to being looked up in the
1424 /// defining scope.
Douglas Gregor29e174c2008-12-16 00:38:16 +00001425 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001426
Anders Carlsson76f4a902007-08-21 17:43:55 +00001427 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnere002fbe2007-12-12 01:04:12 +00001428 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
1429 ExprTy **Strings,
1430 unsigned NumStrings);
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001431 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner37390be2007-10-16 22:51:17 +00001432 SourceLocation EncodeLoc,
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001433 SourceLocation LParenLoc,
1434 TypeTy *Ty,
1435 SourceLocation RParenLoc);
1436
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001437 // ParseObjCSelectorExpression - Build selector expression for @selector
1438 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
1439 SourceLocation AtLoc,
Fariborz Jahanian6bd1d612007-10-16 23:21:02 +00001440 SourceLocation SelLoc,
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001441 SourceLocation LParenLoc,
1442 SourceLocation RParenLoc);
1443
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001444 // ParseObjCProtocolExpression - Build protocol expression for @protocol
1445 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
1446 SourceLocation AtLoc,
1447 SourceLocation ProtoLoc,
1448 SourceLocation LParenLoc,
1449 SourceLocation RParenLoc);
Douglas Gregor556877c2008-04-13 21:30:24 +00001450
1451 //===--------------------------------------------------------------------===//
Douglas Gregor07665a62009-01-05 19:45:36 +00001452 // C++ Declarations
1453 //
1454 virtual DeclTy *ActOnStartLinkageSpecification(Scope *S,
1455 SourceLocation ExternLoc,
1456 SourceLocation LangLoc,
1457 const char *Lang,
1458 unsigned StrSize,
1459 SourceLocation LBraceLoc);
1460 virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S,
1461 DeclTy *LinkageSpec,
1462 SourceLocation RBraceLoc);
1463
1464
1465 //===--------------------------------------------------------------------===//
Douglas Gregor556877c2008-04-13 21:30:24 +00001466 // C++ Classes
1467 //
Argyrios Kyrtzidis32a03792008-11-08 16:45:02 +00001468 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
1469 const CXXScopeSpec *SS);
Douglas Gregor61956c42008-10-31 09:07:45 +00001470
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001471 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
1472 Declarator &D, ExprTy *BitfieldWidth,
1473 ExprTy *Init, DeclTy *LastInGroup);
1474
Douglas Gregore8381c02008-11-05 04:29:56 +00001475 virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD,
1476 Scope *S,
1477 IdentifierInfo *MemberOrBase,
1478 SourceLocation IdLoc,
1479 SourceLocation LParenLoc,
1480 ExprTy **Args, unsigned NumArgs,
1481 SourceLocation *CommaLocs,
1482 SourceLocation RParenLoc);
1483
Douglas Gregor05379422008-11-03 17:51:48 +00001484 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
1485
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001486 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
1487 DeclTy *TagDecl,
1488 SourceLocation LBrac,
1489 SourceLocation RBrac);
1490
Douglas Gregor4d87df52008-12-16 21:30:33 +00001491 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1492 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param);
1493 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1494
Douglas Gregor831c93f2008-11-05 20:51:48 +00001495 bool CheckConstructorDeclarator(Declarator &D, QualType &R,
1496 FunctionDecl::StorageClass& SC);
Douglas Gregor4d87df52008-12-16 21:30:33 +00001497 bool CheckConstructor(CXXConstructorDecl *Constructor);
Douglas Gregor831c93f2008-11-05 20:51:48 +00001498 bool CheckDestructorDeclarator(Declarator &D, QualType &R,
1499 FunctionDecl::StorageClass& SC);
Douglas Gregordbc5daf2008-11-07 20:08:42 +00001500 bool CheckConversionDeclarator(Declarator &D, QualType &R,
1501 FunctionDecl::StorageClass& SC);
Douglas Gregordbc5daf2008-11-07 20:08:42 +00001502 DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregor61956c42008-10-31 09:07:45 +00001503
Douglas Gregor5c407d92008-10-23 00:40:37 +00001504 //===--------------------------------------------------------------------===//
1505 // C++ Derived Classes
1506 //
1507
1508 /// ActOnBaseSpecifier - Parsed a base specifier
Douglas Gregor463421d2009-03-03 04:44:36 +00001509 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
1510 SourceRange SpecifierRange,
1511 bool Virtual, AccessSpecifier Access,
1512 QualType BaseType,
1513 SourceLocation BaseLoc);
Douglas Gregor5c407d92008-10-23 00:40:37 +00001514 virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl,
1515 SourceRange SpecifierRange,
1516 bool Virtual, AccessSpecifier Access,
Douglas Gregor463421d2009-03-03 04:44:36 +00001517 TypeTy *basetype, SourceLocation
1518 BaseLoc);
Douglas Gregor5c407d92008-10-23 00:40:37 +00001519
Douglas Gregor463421d2009-03-03 04:44:36 +00001520 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
1521 unsigned NumBases);
Douglas Gregor5c407d92008-10-23 00:40:37 +00001522 virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
1523 unsigned NumBases);
1524
1525 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregor39c16d42008-10-24 04:54:22 +00001526 bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
Douglas Gregor960b5bc2009-01-15 00:26:24 +00001527 bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria,
1528 BasePaths &Paths);
Douglas Gregorcea4e7432008-10-24 16:17:19 +00001529 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
1530 SourceLocation Loc, SourceRange Range);
Douglas Gregor1c846b02009-01-16 00:38:09 +00001531 std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
Douglas Gregor556877c2008-04-13 21:30:24 +00001532
Douglas Gregor11d0c4c2008-11-06 22:13:31 +00001533 //===--------------------------------------------------------------------===//
1534 // C++ Overloaded Operators [C++ 13.5]
1535 //
1536
1537 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
1538
Douglas Gregor5101c242008-12-05 18:15:24 +00001539 //===--------------------------------------------------------------------===//
1540 // C++ Templates [C++ 14]
1541 //
Douglas Gregor8bf42052009-02-09 18:46:07 +00001542 virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S,
1543 DeclTy *&TemplateDecl,
1544 const CXXScopeSpec *SS = 0);
Douglas Gregor5101c242008-12-05 18:15:24 +00001545 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001546 TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl);
1547
1548 virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename,
1549 SourceLocation KeyLoc,
1550 IdentifierInfo *ParamName,
1551 SourceLocation ParamNameLoc,
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001552 unsigned Depth, unsigned Position);
Douglas Gregordba32632009-02-10 19:49:53 +00001553 virtual void ActOnTypeParameterDefault(DeclTy *TypeParam,
1554 SourceLocation EqualLoc,
1555 SourceLocation DefaultLoc,
1556 TypeTy *Default);
1557
Douglas Gregor463421d2009-03-03 04:44:36 +00001558 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001559 virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001560 unsigned Depth,
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001561 unsigned Position);
Douglas Gregordba32632009-02-10 19:49:53 +00001562 virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam,
1563 SourceLocation EqualLoc,
1564 ExprArg Default);
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001565 virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S,
1566 SourceLocation TmpLoc,
1567 TemplateParamsTy *Params,
1568 IdentifierInfo *ParamName,
1569 SourceLocation ParamNameLoc,
1570 unsigned Depth,
1571 unsigned Position);
Douglas Gregordba32632009-02-10 19:49:53 +00001572 virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam,
1573 SourceLocation EqualLoc,
1574 ExprArg Default);
1575
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001576 virtual TemplateParamsTy *
1577 ActOnTemplateParameterList(unsigned Depth,
1578 SourceLocation ExportLoc,
1579 SourceLocation TemplateLoc,
1580 SourceLocation LAngleLoc,
1581 DeclTy **Params, unsigned NumParams,
1582 SourceLocation RAngleLoc);
Douglas Gregordba32632009-02-10 19:49:53 +00001583 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
1584 TemplateParameterList *OldParams);
1585
Douglas Gregorcd72ba92009-02-06 22:42:48 +00001586 virtual DeclTy *
1587 ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK,
1588 SourceLocation KWLoc, const CXXScopeSpec &SS,
1589 IdentifierInfo *Name, SourceLocation NameLoc,
1590 AttributeList *Attr,
1591 MultiTemplateParamsArg TemplateParameterLists);
1592
Douglas Gregor67a65642009-02-17 23:15:12 +00001593 virtual TypeResult
1594 ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc,
1595 SourceLocation LAngleLoc,
1596 ASTTemplateArgsPtr TemplateArgs,
1597 SourceLocation *TemplateArgLocs,
1598 SourceLocation RAngleLoc,
1599 const CXXScopeSpec *SS);
1600
Douglas Gregorf47b9112009-02-25 22:02:03 +00001601 bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate,
1602 ClassTemplateSpecializationDecl *PrevDecl,
1603 SourceLocation TemplateNameLoc,
1604 SourceRange ScopeSpecifierRange);
1605
Douglas Gregor67a65642009-02-17 23:15:12 +00001606 virtual DeclTy *
1607 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
1608 SourceLocation KWLoc,
1609 const CXXScopeSpec &SS,
1610 DeclTy *Template,
1611 SourceLocation TemplateNameLoc,
Douglas Gregor8bf42052009-02-09 18:46:07 +00001612 SourceLocation LAngleLoc,
Douglas Gregor67b556a2009-02-09 19:34:22 +00001613 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregord32e0282009-02-09 23:23:08 +00001614 SourceLocation *TemplateArgLocs,
Douglas Gregor8bf42052009-02-09 18:46:07 +00001615 SourceLocation RAngleLoc,
Douglas Gregor67a65642009-02-17 23:15:12 +00001616 AttributeList *Attr,
1617 MultiTemplateParamsArg TemplateParameterLists);
Douglas Gregor8bf42052009-02-09 18:46:07 +00001618
Douglas Gregord32e0282009-02-09 23:23:08 +00001619 bool CheckTemplateArgumentList(TemplateDecl *Template,
1620 SourceLocation TemplateLoc,
1621 SourceLocation LAngleLoc,
1622 ASTTemplateArgsPtr& TemplateArgs,
1623 SourceLocation *TemplateArgLocs,
Douglas Gregor264ec4f2009-02-17 01:05:43 +00001624 SourceLocation RAngleLoc,
1625 llvm::SmallVectorImpl<TemplateArgument> &Converted);
Douglas Gregord32e0282009-02-09 23:23:08 +00001626
1627 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg,
1628 SourceLocation ArgLoc);
Douglas Gregor264ec4f2009-02-17 01:05:43 +00001629 bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,
1630 NamedDecl *&Entity);
1631 bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member);
Douglas Gregor463421d2009-03-03 04:44:36 +00001632 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
1633 QualType InstantiatedParamType, Expr *&Arg,
Douglas Gregor264ec4f2009-02-17 01:05:43 +00001634 llvm::SmallVectorImpl<TemplateArgument> *Converted = 0);
Douglas Gregord32e0282009-02-09 23:23:08 +00001635 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg);
Douglas Gregorcd72ba92009-02-06 22:42:48 +00001636 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
1637 TemplateParameterList *Old,
1638 bool Complain,
Douglas Gregor85e0f662009-02-10 00:24:35 +00001639 bool IsTemplateTemplateParm = false,
1640 SourceLocation TemplateArgLoc
1641 = SourceLocation());
Douglas Gregorcd72ba92009-02-06 22:42:48 +00001642
1643 bool CheckTemplateDeclScope(Scope *S,
1644 MultiTemplateParamsArg &TemplateParameterLists);
Douglas Gregorded2d7b2009-02-04 19:02:06 +00001645
Douglas Gregorfe1e1102009-02-27 19:31:52 +00001646 //===--------------------------------------------------------------------===//
1647 // C++ Template Instantiation
1648 //
1649 QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
1650 unsigned NumTemplateArgs,
1651 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor463421d2009-03-03 04:44:36 +00001652 bool
1653 InstantiateBaseSpecifiers(ClassTemplateSpecializationDecl *ClassTemplateSpec,
1654 ClassTemplateDecl *ClassTemplate);
1655 bool
1656 InstantiateClassTemplateSpecialization(
1657 ClassTemplateSpecializationDecl *ClassTemplateSpec,
1658 bool ExplicitInstantiation);
Douglas Gregorfe1e1102009-02-27 19:31:52 +00001659
Steve Naroff09bf8152007-09-06 21:24:23 +00001660 // Objective-C declarations.
Chris Lattnerdf59f5a2008-07-26 04:13:19 +00001661 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
1662 IdentifierInfo *ClassName,
1663 SourceLocation ClassLoc,
1664 IdentifierInfo *SuperName,
1665 SourceLocation SuperLoc,
1666 DeclTy * const *ProtoRefs,
1667 unsigned NumProtoRefs,
1668 SourceLocation EndProtoLoc,
1669 AttributeList *AttrList);
Fariborz Jahanian49c64252007-10-11 23:42:27 +00001670
1671 virtual DeclTy *ActOnCompatiblityAlias(
1672 SourceLocation AtCompatibilityAliasLoc,
1673 IdentifierInfo *AliasName, SourceLocation AliasLocation,
1674 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff09bf8152007-09-06 21:24:23 +00001675
Steve Naroff93eb5f12007-10-10 17:32:04 +00001676 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman7dd8e722008-02-20 22:57:40 +00001677 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian39d641f2007-09-17 21:07:36 +00001678 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattner3bbae002008-07-26 04:03:38 +00001679 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar26e2ab42008-09-26 04:48:09 +00001680 SourceLocation EndProtoLoc,
1681 AttributeList *AttrList);
Fariborz Jahanian39d641f2007-09-17 21:07:36 +00001682
Chris Lattnerb1f3c942008-07-26 04:07:02 +00001683 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
1684 IdentifierInfo *ClassName,
1685 SourceLocation ClassLoc,
1686 IdentifierInfo *CategoryName,
1687 SourceLocation CategoryLoc,
1688 DeclTy * const *ProtoRefs,
1689 unsigned NumProtoRefs,
1690 SourceLocation EndProtoLoc);
Fariborz Jahanian867a7eb2007-09-18 20:26:58 +00001691
Steve Naroff93eb5f12007-10-10 17:32:04 +00001692 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman7dd8e722008-02-20 22:57:40 +00001693 SourceLocation AtClassImplLoc,
Fariborz Jahanianbfe13c52007-09-25 18:38:09 +00001694 IdentifierInfo *ClassName, SourceLocation ClassLoc,
1695 IdentifierInfo *SuperClassname,
1696 SourceLocation SuperClassLoc);
1697
Steve Naroff93eb5f12007-10-10 17:32:04 +00001698 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahanian89b8ef92007-10-02 16:38:50 +00001699 SourceLocation AtCatImplLoc,
1700 IdentifierInfo *ClassName,
1701 SourceLocation ClassLoc,
1702 IdentifierInfo *CatName,
1703 SourceLocation CatLoc);
1704
Steve Naroff93eb5f12007-10-10 17:32:04 +00001705 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroff0c37b0c2007-10-02 22:39:18 +00001706 IdentifierInfo **IdentList,
1707 unsigned NumElts);
Fariborz Jahanian876e27d2007-09-21 15:40:54 +00001708
Steve Naroff93eb5f12007-10-10 17:32:04 +00001709 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001710 const IdentifierLocPair *IdentList,
Fariborz Jahanian1470e932008-12-17 01:07:27 +00001711 unsigned NumElts,
1712 AttributeList *attrList);
Fariborz Jahanianea7a98d2007-10-05 21:01:53 +00001713
Chris Lattner3bbae002008-07-26 04:03:38 +00001714 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001715 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian70e8f102007-10-11 00:55:41 +00001716 unsigned NumProtocols,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001717 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001718
Daniel Dunbare8a06e62008-09-23 21:53:23 +00001719 /// Ensure attributes are consistent with type.
1720 /// \param [in, out] Attributes The attributes to check; they will
1721 /// be modified to be consistent with \arg PropertyTy.
1722 void CheckObjCPropertyAttributes(QualType PropertyTy,
1723 SourceLocation Loc,
1724 unsigned &Attributes);
Steve Naroff35c62ae2009-01-08 17:28:14 +00001725 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001726 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1727 ObjCPropertyDecl *SuperProperty,
Chris Lattner86d7d912008-11-24 03:54:41 +00001728 const IdentifierInfo *Name);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001729 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanian0a070ff2008-04-24 19:58:34 +00001730
Fariborz Jahaniand2c2ad52008-12-06 23:03:39 +00001731 void MergeProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +00001732 DeclTy *MergeProtocols);
1733
Fariborz Jahanian33afd772009-03-02 19:05:07 +00001734 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
1735 ObjCInterfaceDecl *ID);
1736
Fariborz Jahaniand2c2ad52008-12-06 23:03:39 +00001737 void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +00001738 ObjCProtocolDecl *PDecl);
1739
Steve Naroffcac26f42007-11-11 17:19:15 +00001740 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
1741 DeclTy **allMethods = 0, unsigned allNum = 0,
1742 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahanian2a4dd312007-09-26 18:27:25 +00001743
Fariborz Jahanian0152a1a2008-04-14 23:36:35 +00001744 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian8d916862008-05-05 18:51:55 +00001745 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanian09367d62008-05-06 18:09:04 +00001746 Selector GetterSel, Selector SetterSel,
Fariborz Jahanianf8ef9f32008-11-26 20:01:34 +00001747 DeclTy *ClassCategory, bool *OverridingProperty,
Fariborz Jahanian8d916862008-05-05 18:51:55 +00001748 tok::ObjCKeywordKind MethodImplKind);
1749
Fariborz Jahanianffe97a32008-04-18 00:19:30 +00001750 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
1751 SourceLocation PropertyLoc,
1752 bool ImplKind, DeclTy *ClassImplDecl,
1753 IdentifierInfo *PropertyId,
1754 IdentifierInfo *PropertyIvar);
1755
Steve Naroff161a92b2007-10-26 20:53:56 +00001756 virtual DeclTy *ActOnMethodDeclaration(
1757 SourceLocation BeginLoc, // location of the + or -.
1758 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanianb5605172007-11-09 19:52:12 +00001759 tok::TokenKind MethodType,
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001760 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanian7a9c4742007-10-31 23:53:01 +00001761 Selector Sel,
Steve Narofff73590d2007-09-27 14:38:14 +00001762 // optional arguments. The number of types/arguments is obtained
1763 // from the Sel.getNumArgs().
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001764 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Fariborz Jahaniane84858c2009-01-09 00:38:19 +00001765 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroffd8ea1ac2007-11-15 12:35:21 +00001766 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
1767 bool isVariadic = false);
Steve Naroff077c83b2007-10-16 23:12:48 +00001768
Steve Naroffb162f172009-02-26 15:55:06 +00001769 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
1770 // Will search "local" class/category implementations for a method decl.
1771 // Returns 0 if no method is found.
1772 ObjCMethodDecl *LookupPrivateMethod(Selector Sel, ObjCInterfaceDecl *CDecl);
1773
Steve Narofff73590d2007-09-27 14:38:14 +00001774 // ActOnClassMessage - used for both unary and keyword messages.
1775 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001776 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +00001777 virtual ExprResult ActOnClassMessage(
Fariborz Jahaniand98a7342007-11-12 20:13:27 +00001778 Scope *S,
Anders Carlsson978f08d2009-02-14 18:21:46 +00001779 IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,
1780 SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001781 ExprTy **ArgExprs, unsigned NumArgs);
Steve Narofff73590d2007-09-27 14:38:14 +00001782
1783 // ActOnInstanceMessage - used for both unary and keyword messages.
1784 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001785 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +00001786 virtual ExprResult ActOnInstanceMessage(
Steve Naroff80175062007-09-28 22:22:11 +00001787 ExprTy *receiver, Selector Sel,
Anders Carlsson978f08d2009-02-14 18:21:46 +00001788 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001789 ExprTy **ArgExprs, unsigned NumArgs);
Daniel Dunbar54603742008-10-14 05:35:18 +00001790
1791 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
1792 virtual void ActOnPragmaPack(PragmaPackKind Kind,
1793 IdentifierInfo *Name,
1794 ExprTy *Alignment,
1795 SourceLocation PragmaLoc,
1796 SourceLocation LParenLoc,
1797 SourceLocation RParenLoc);
Chris Lattner31180bb2009-02-17 01:09:29 +00001798
1799 /// getPragmaPackAlignment() - Return the current alignment as specified by
1800 /// the current #pragma pack directive, or 0 if none is currently active.
1801 unsigned getPragmaPackAlignment() const;
1802
1803 /// FreePackedContext - Deallocate and null out PackContext.
1804 void FreePackedContext();
Daniel Dunbar54603742008-10-14 05:35:18 +00001805
Chris Lattnera65e1f32008-01-16 19:17:22 +00001806 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
1807 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregora11693b2008-11-12 17:17:38 +00001808 /// If isLvalue, the result of the cast is an lvalue.
1809 void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
Chris Lattnera65e1f32008-01-16 19:17:22 +00001810
Steve Naroff71b59a92007-06-04 22:22:31 +00001811 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner08464942007-12-28 05:29:59 +00001812 // functions and arrays to their respective pointers (C99 6.3.2.1).
1813 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3e113402008-05-27 03:33:27 +00001814
Steve Naroff31090012007-07-16 21:54:35 +00001815 // DefaultFunctionArrayConversion - converts functions and arrays
1816 // to their respective pointers (C99 6.3.2.1).
1817 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001818
Steve Naroff0b661582007-08-28 23:30:39 +00001819 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
1820 // do not have a prototype. Integer promotions are performed on each
1821 // argument, and arguments that have type float are promoted to double.
Chris Lattner08464942007-12-28 05:29:59 +00001822 void DefaultArgumentPromotion(Expr *&Expr);
Anders Carlssona7d069d2009-01-16 16:48:51 +00001823
1824 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
1825 enum VariadicCallType {
1826 VariadicFunction,
1827 VariadicBlock,
1828 VariadicMethod
1829 };
1830
1831 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
1832 // will warn if the resulting type is not a POD type.
1833 void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
Steve Naroff0b661582007-08-28 23:30:39 +00001834
Steve Naroff71b59a92007-06-04 22:22:31 +00001835 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
1836 // operands and then handles various conversions that are common to binary
1837 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
1838 // routine returns the first non-arithmetic type found. The client is
1839 // responsible for emitting appropriate error diagnostics.
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001840 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
1841 bool isCompAssign = false);
Chris Lattner940cfeb2008-01-04 18:22:42 +00001842
Douglas Gregora11693b2008-11-12 17:17:38 +00001843 /// UsualArithmeticConversionsType - handles the various conversions
1844 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
1845 /// and returns the result type of that conversion.
1846 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
1847
1848
Chris Lattner940cfeb2008-01-04 18:22:42 +00001849 /// AssignConvertType - All of the 'assignment' semantic checks return this
1850 /// enum to indicate whether the assignment was allowed. These checks are
1851 /// done for simple assignments, as well as initialization, return from
1852 /// function, argument passing, etc. The query is phrased in terms of a
1853 /// source and destination type.
Chris Lattner9bad62c2008-01-04 18:04:52 +00001854 enum AssignConvertType {
Chris Lattner940cfeb2008-01-04 18:22:42 +00001855 /// Compatible - the types are compatible according to the standard.
Steve Naroff17f76e02007-05-03 21:03:48 +00001856 Compatible,
Chris Lattner940cfeb2008-01-04 18:22:42 +00001857
1858 /// PointerToInt - The assignment converts a pointer to an int, which we
1859 /// accept as an extension.
1860 PointerToInt,
1861
1862 /// IntToPointer - The assignment converts an int to a pointer, which we
1863 /// accept as an extension.
1864 IntToPointer,
1865
1866 /// FunctionVoidPointer - The assignment is between a function pointer and
1867 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattner0a788432008-01-03 22:56:36 +00001868 FunctionVoidPointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +00001869
1870 /// IncompatiblePointer - The assignment is between two pointers types that
1871 /// are not compatible, but we accept them as an extension.
Steve Naroff1f4d7272007-05-11 04:00:31 +00001872 IncompatiblePointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +00001873
1874 /// CompatiblePointerDiscardsQualifiers - The assignment discards
1875 /// c/v/r qualifiers, which we accept as an extension.
1876 CompatiblePointerDiscardsQualifiers,
Steve Naroff081c7422008-09-04 15:10:53 +00001877
Anders Carlssondb5a9b62009-01-30 23:17:46 +00001878 /// IncompatibleVectors - The assignment is between two vector types that
1879 /// have the same size, which we accept as an extension.
1880 IncompatibleVectors,
1881
Steve Naroff991e99d2008-09-04 15:31:07 +00001882 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff081c7422008-09-04 15:10:53 +00001883 /// pointer. We disallow this.
1884 IntToBlockPointer,
1885
Steve Naroff991e99d2008-09-04 15:31:07 +00001886 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff081c7422008-09-04 15:10:53 +00001887 /// pointers types that are not compatible.
1888 IncompatibleBlockPointer,
1889
Steve Naroff8afa9892008-10-14 22:18:38 +00001890 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
1891 /// id type and something else (that is incompatible with it). For example,
1892 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
1893 IncompatibleObjCQualifiedId,
1894
Chris Lattner940cfeb2008-01-04 18:22:42 +00001895 /// Incompatible - We reject this conversion outright, it is invalid to
1896 /// represent it in the AST.
1897 Incompatible
Steve Naroff17f76e02007-05-03 21:03:48 +00001898 };
Chris Lattner9bad62c2008-01-04 18:04:52 +00001899
1900 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
1901 /// assignment conversion type specified by ConvTy. This returns true if the
1902 /// conversion was invalid or false if the conversion was accepted.
1903 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
1904 SourceLocation Loc,
1905 QualType DstType, QualType SrcType,
1906 Expr *SrcExpr, const char *Flavor);
1907
1908 /// CheckAssignmentConstraints - Perform type checking for assignment,
1909 /// argument passing, variable initialization, and function return values.
1910 /// This routine is only used by the following two methods. C99 6.5.16.
1911 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001912
Steve Naroff83895f72007-09-16 03:34:24 +00001913 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff66356bd2007-09-16 14:56:35 +00001914 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001915 // this routine performs the default function/array converions.
Chris Lattner9bad62c2008-01-04 18:04:52 +00001916 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
1917 Expr *&rExpr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001918 // CheckCompoundAssignmentConstraints - Type check without performing any
1919 // conversions. For compound assignments, the "Check...Operands" methods
1920 // perform the necessary conversions.
Chris Lattner9bad62c2008-01-04 18:04:52 +00001921 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
1922 QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001923
Steve Naroff98cf3e92007-06-06 18:38:38 +00001924 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner9bad62c2008-01-04 18:04:52 +00001925 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
1926 QualType rhsType);
Steve Naroff081c7422008-09-04 15:10:53 +00001927
1928 // Helper function for CheckAssignmentConstraints involving two
1929 // blcok pointer types.
1930 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
1931 QualType rhsType);
Douglas Gregoraa1e21d2008-09-12 00:47:35 +00001932
1933 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregor39c16d42008-10-24 04:54:22 +00001934
Douglas Gregor47d3f272008-12-19 17:40:08 +00001935 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +00001936 const char *Flavor, bool AllowExplicit = false);
1937 bool PerformImplicitConversion(Expr *&From, QualType ToType,
1938 const ImplicitConversionSequence& ICS,
Douglas Gregor47d3f272008-12-19 17:40:08 +00001939 const char *Flavor);
Douglas Gregor39c16d42008-10-24 04:54:22 +00001940 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor47d3f272008-12-19 17:40:08 +00001941 const StandardConversionSequence& SCS,
1942 const char *Flavor);
Sebastian Redl112a97662009-02-07 00:15:38 +00001943
Steve Naroff8eeeb132007-05-08 21:09:37 +00001944 /// the following "Check" methods will return a valid/converted QualType
1945 /// or a null QualType (indicating an error diagnostic was issued).
Sebastian Redl112a97662009-02-07 00:15:38 +00001946
1947 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
Chris Lattner5c11c412007-12-12 05:47:28 +00001948 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Sebastian Redl5822f082009-02-07 20:10:22 +00001949 QualType CheckPointerToMemberOperands( // C++ 5.5
Sebastian Redl112a97662009-02-07 00:15:38 +00001950 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001951 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Sebastian Redl112a97662009-02-07 00:15:38 +00001952 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001953 inline QualType CheckRemainderOperands( // C99 6.5.5
Sebastian Redl112a97662009-02-07 00:15:38 +00001954 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001955 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001956 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001957 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001958 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001959 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001960 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnerb620c342007-08-26 01:18:55 +00001961 inline QualType CheckCompareOperands( // C99 6.5.8/9
1962 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001963 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Sebastian Redl112a97662009-02-07 00:15:38 +00001964 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001965 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff7a5af782007-07-13 16:58:59 +00001966 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Naroff35d85152007-05-07 00:24:15 +00001967 // CheckAssignmentOperands is used for both simple and compound assignment.
1968 // For simple assignment, pass both expressions and a null converted type.
1969 // For compound assignment, pass both expressions and the converted type.
1970 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0c1c7ed2007-08-24 22:33:52 +00001971 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001972 inline QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner326f7572008-11-18 01:30:42 +00001973 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Steve Narofff8a28c52007-05-15 20:29:32 +00001974 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff7a5af782007-07-13 16:58:59 +00001975 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begeman191a6b12008-07-14 18:02:46 +00001976
1977 /// type checking for vector binary operators.
1978 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
1979 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
1980 SourceLocation l, bool isRel);
Steve Naroff95af0132007-03-30 23:47:58 +00001981
Steve Naroff83895f72007-09-16 03:34:24 +00001982 /// type checking unary operators (subroutines of ActOnUnaryOp).
Steve Naroff9358c712007-05-27 23:58:33 +00001983 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redle10c2c32008-12-20 09:35:34 +00001984 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
1985 bool isInc);
Steve Naroff71ce2e02007-05-18 22:53:50 +00001986 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
1987 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattner709322b2009-02-17 08:12:06 +00001988 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
Steve Narofff8fd09e2007-07-27 22:15:19 +00001989
1990 /// type checking primary expressions.
Nate Begemance4d7fc2008-04-18 23:10:10 +00001991 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Narofff8fd09e2007-07-27 22:15:19 +00001992 IdentifierInfo &Comp, SourceLocation CmpLoc);
1993
Steve Naroff2fea1392007-09-02 02:04:30 +00001994 /// type checking declaration initializers (C99 6.7.8)
Douglas Gregor6f543152008-11-05 15:29:30 +00001995 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor5fb53972009-01-14 15:45:31 +00001996 SourceLocation InitLoc,DeclarationName InitEntity,
1997 bool DirectInit);
Douglas Gregor85df8d82009-01-29 00:45:39 +00001998 bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
Steve Naroff98f72032008-01-10 22:15:12 +00001999 bool CheckForConstantInitializer(Expr *e, QualType t);
Steve Naroff91f78082007-12-10 22:44:33 +00002000
Douglas Gregora5c9e1a2009-02-02 17:43:21 +00002001 bool CheckValueInitialization(QualType Type, SourceLocation Loc);
Argyrios Kyrtzidis2ade3902008-08-16 20:27:34 +00002002
Douglas Gregor8e1cf602008-10-29 00:13:59 +00002003 // type checking C++ declaration initializers (C++ [dcl.init]).
2004
2005 /// ReferenceCompareResult - Expresses the result of comparing two
2006 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
2007 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
2008 enum ReferenceCompareResult {
2009 /// Ref_Incompatible - The two types are incompatible, so direct
2010 /// reference binding is not possible.
2011 Ref_Incompatible = 0,
2012 /// Ref_Related - The two types are reference-related, which means
2013 /// that their unqualified forms (T1 and T2) are either the same
2014 /// or T1 is a base class of T2.
2015 Ref_Related,
2016 /// Ref_Compatible_With_Added_Qualification - The two types are
2017 /// reference-compatible with added qualification, meaning that
2018 /// they are reference-compatible and the qualifiers on T1 (cv1)
2019 /// are greater than the qualifiers on T2 (cv2).
2020 Ref_Compatible_With_Added_Qualification,
2021 /// Ref_Compatible - The two types are reference-compatible and
2022 /// have equivalent qualifiers (cv1 == cv2).
2023 Ref_Compatible
2024 };
2025
Douglas Gregor786ab212008-10-29 02:00:59 +00002026 ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
2027 bool& DerivedToBase);
Douglas Gregor8e1cf602008-10-29 00:13:59 +00002028
2029 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor2fe98832008-11-03 19:09:14 +00002030 ImplicitConversionSequence *ICS = 0,
Douglas Gregor5fb53972009-01-14 15:45:31 +00002031 bool SuppressUserConversions = false,
2032 bool AllowExplicit = false);
Douglas Gregor8e1cf602008-10-29 00:13:59 +00002033
Argyrios Kyrtzidis2ade3902008-08-16 20:27:34 +00002034 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar94834d82008-08-20 03:55:42 +00002035 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroffaf2a0222008-01-22 00:55:40 +00002036
Anders Carlsson24c59952007-11-27 07:16:40 +00002037 // CheckVectorCast - check type constraints for vectors.
2038 // Since vectors are an extension, there are no C standard reference for this.
2039 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssonde71adf2007-11-27 05:51:55 +00002040 // returns true if the cast is invalid
2041 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
2042
Daniel Dunbaraa9326c2008-09-11 00:01:56 +00002043 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
2044 /// \param Method - May be null.
2045 /// \param [out] ReturnType - The return type of the send.
2046 /// \return true iff there were any incompatible types.
Daniel Dunbarce05c8e2008-09-11 00:50:25 +00002047 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattnere4b95692008-11-24 03:33:13 +00002048 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbaraa9326c2008-09-11 00:01:56 +00002049 SourceLocation lbrac, SourceLocation rbrac,
2050 QualType &ReturnType);
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +00002051
2052 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
2053 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff077c83b2007-10-16 23:12:48 +00002054
Chris Lattnerfc1c44a2007-08-23 05:46:52 +00002055 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
2056 /// the specified width and sign. If an overflow occurs, detect it and emit
2057 /// the specified diagnostic.
2058 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
2059 unsigned NewWidth, bool NewSign,
2060 SourceLocation Loc, unsigned DiagID);
2061
Chris Lattner2a3569b2008-04-07 05:30:13 +00002062 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
2063 bool ForCompare);
2064
Anders Carlssona6b508a2008-11-04 16:57:32 +00002065 /// Checks that the Objective-C declaration is declared in the global scope.
2066 /// Emits an error and marks the declaration as invalid if it's not declared
2067 /// in the global scope.
2068 bool CheckObjCDeclScope(Decl *D);
2069
Anders Carlsson7e13ab82007-10-15 20:28:48 +00002070 void InitBuiltinVaListType();
Eli Friedman149614b2008-06-03 21:01:11 +00002071
Anders Carlssone54e8a12008-11-30 19:50:32 +00002072 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
2073 /// and reports the appropriate diagnostics. Returns false on success.
2074 /// Can optionally return the value of the expression.
Anders Carlsson5df391e2008-12-06 20:33:04 +00002075 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson1dbffc62008-12-01 02:17:22 +00002076
Anders Carlsson5df391e2008-12-06 20:33:04 +00002077 /// VerifyBitField - verifies that a bit field expression is an ICE and has
2078 /// the correct width, and that the field type is valid.
2079 /// Returns false on success.
2080 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
2081 QualType FieldTy, const Expr *BitWidth);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00002082
Chris Lattnerb87b1b32007-08-10 20:18:51 +00002083 //===--------------------------------------------------------------------===//
2084 // Extra semantic analysis beyond the C type system
Chris Lattner08464942007-12-28 05:29:59 +00002085private:
Sebastian Redlc215cfc2009-01-19 00:08:26 +00002086 Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl,
2087 CallExpr *TheCall);
Chris Lattnera26fb342009-02-18 17:49:48 +00002088 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
2089 unsigned ByteNo) const;
Chris Lattner6436fb62009-02-18 06:01:06 +00002090 bool CheckObjCString(Expr *Arg);
Chris Lattner08464942007-12-28 05:29:59 +00002091 bool SemaBuiltinVAStart(CallExpr *TheCall);
2092 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedmanf8353032008-05-20 08:23:37 +00002093 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Sebastian Redlc215cfc2009-01-19 00:08:26 +00002094 Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbarb7257262008-07-21 22:59:13 +00002095 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbarb0d34c82008-09-03 21:13:56 +00002096 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Ted Kremenek6dfeb552009-01-12 23:09:09 +00002097 bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg,
Douglas Gregore711f702009-02-14 18:57:46 +00002098 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek6dfeb552009-01-12 23:09:09 +00002099 void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr,
2100 CallExpr *TheCall, bool HasVAListArg,
Douglas Gregore711f702009-02-14 18:57:46 +00002101 unsigned format_idx, unsigned firstDataArg);
2102 void CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
2103 unsigned format_idx, unsigned firstDataArg);
Ted Kremenekcff94fa2007-08-17 16:46:58 +00002104 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
2105 SourceLocation ReturnLoc);
Ted Kremenek43fb8b02007-11-25 00:58:00 +00002106 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Chris Lattner7cee11f2006-11-03 06:42:29 +00002107};
2108
Steve Naroffc540d662008-09-03 18:15:37 +00002109/// BlockSemaInfo - When a block is being parsed, this contains information
2110/// about the block. It is pointed to from Sema::CurBlock.
2111struct BlockSemaInfo {
2112 llvm::SmallVector<ParmVarDecl*, 8> Params;
Steve Naroffc540d662008-09-03 18:15:37 +00002113 bool hasPrototype;
2114 bool isVariadic;
Mike Stumpa6703322009-02-19 22:01:56 +00002115 bool hasBlockDeclRefExprs;
2116
Steve Naroff44078b92008-10-08 18:44:00 +00002117 BlockDecl *TheDecl;
2118
Chris Lattner1fa74d92009-02-18 07:09:44 +00002119 /// TheScope - This is the scope for the block itself, which contains
Steve Naroffc540d662008-09-03 18:15:37 +00002120 /// arguments etc.
2121 Scope *TheScope;
2122
2123 /// ReturnType - This will get set to block result type, by looking at
2124 /// return types, if any, in the block body.
2125 Type *ReturnType;
2126
2127 /// PrevBlockInfo - If this is nested inside another block, this points
2128 /// to the outer block.
2129 BlockSemaInfo *PrevBlockInfo;
2130};
Ted Kremenek5a201952009-02-07 01:47:29 +00002131
2132//===--------------------------------------------------------------------===//
2133// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
2134template <typename T>
2135class ExprOwningPtr : public Action::ExprArg {
2136public:
2137 ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {};
2138
2139 void reset(T* p) { Action::ExprArg::operator=(p); }
2140 T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
2141 T* take() { return static_cast<T*>(Action::ExprArg::take()); }
2142 T* release() { return take(); }
2143
2144 T& operator*() const { return *get(); }
2145 T* operator->() const { return get(); }
2146};
2147
Chris Lattner7cee11f2006-11-03 06:42:29 +00002148} // end namespace clang
Chris Lattner7cee11f2006-11-03 06:42:29 +00002149
2150#endif