blob: 28cb9bf7153c55799f29e42b22484807bece37ae [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the Sema class, which performs semantic analysis and
11// builds ASTs.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_SEMA_H
16#define LLVM_CLANG_AST_SEMA_H
17
Chris Lattner7f925cc2008-04-11 07:00:53 +000018#include "IdentifierResolver.h"
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +000019#include "CXXFieldCollector.h"
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000020#include "SemaOverload.h"
Douglas Gregoreb11cd02009-01-14 22:20:51 +000021#include "clang/AST/DeclBase.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000022#include "clang/Parse/Action.h"
Chris Lattner500d3292009-01-29 05:15:15 +000023#include "clang/Sema/SemaDiagnostic.h"
Anders Carlssonc1fcb772007-07-22 07:07:56 +000024#include "llvm/ADT/SmallVector.h"
Fariborz Jahanian85ff2642007-10-05 18:00:57 +000025#include "llvm/ADT/DenseSet.h"
Chris Lattnerf3876682007-10-07 01:13:46 +000026#include "llvm/ADT/SmallPtrSet.h"
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +000027#include "llvm/ADT/OwningPtr.h"
Steve Naroff61d68522009-03-05 15:22:01 +000028#include "clang/AST/DeclObjC.h"
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +000029#include <string>
Douglas Gregor94b1dd22008-10-24 04:54:22 +000030#include <vector>
Reid Spencer5f016e22007-07-11 17:01:13 +000031
Chris Lattnerf4021e72007-08-23 05:46:52 +000032namespace llvm {
33 class APSInt;
34}
35
Reid Spencer5f016e22007-07-11 17:01:13 +000036namespace clang {
37 class ASTContext;
Chris Lattner2ae34ed2008-02-06 00:46:58 +000038 class ASTConsumer;
Reid Spencer5f016e22007-07-11 17:01:13 +000039 class Preprocessor;
40 class Decl;
Chris Lattnerb048c982008-04-06 04:47:34 +000041 class DeclContext;
Daniel Dunbar12bc6922008-08-11 03:27:53 +000042 class DeclSpec;
Steve Naroffe8043c32008-04-01 23:04:06 +000043 class NamedDecl;
Sebastian Redl798d1192008-12-13 16:23:55 +000044 class Stmt;
Reid Spencer5f016e22007-07-11 17:01:13 +000045 class Expr;
Steve Naroff6f9f3072007-09-02 15:34:30 +000046 class InitListExpr;
Douglas Gregor05c13a32009-01-22 00:58:24 +000047 class DesignatedInitExpr;
Chris Lattner925e60d2007-12-28 05:29:59 +000048 class CallExpr;
Douglas Gregor1a49af92009-01-06 05:10:23 +000049 class DeclRefExpr;
Reid Spencer5f016e22007-07-11 17:01:13 +000050 class VarDecl;
51 class ParmVarDecl;
52 class TypedefDecl;
53 class FunctionDecl;
54 class QualType;
Sebastian Redl43af76e2009-03-07 12:16:37 +000055 class LangOptions;
Chris Lattnerd2177732007-07-20 16:59:19 +000056 class Token;
Reid Spencer5f016e22007-07-11 17:01:13 +000057 class IntegerLiteral;
Steve Naroffa49e1fa2008-01-22 00:55:40 +000058 class StringLiteral;
Reid Spencer5f016e22007-07-11 17:01:13 +000059 class ArrayType;
60 class LabelStmt;
Anders Carlssonc1fcb772007-07-22 07:07:56 +000061 class SwitchStmt;
Nate Begeman213541a2008-04-18 23:10:10 +000062 class ExtVectorType;
Steve Naroffbea0b342007-07-29 16:33:31 +000063 class TypedefDecl;
Douglas Gregoraaba5e32009-02-04 19:02:06 +000064 class TemplateDecl;
Douglas Gregor3e00bad2009-02-17 01:05:43 +000065 class TemplateArgument;
Douglas Gregorddc29e12009-02-06 22:42:48 +000066 class TemplateParameterList;
Douglas Gregorc15cb382009-02-09 23:23:08 +000067 class TemplateTemplateParmDecl;
Douglas Gregor88b70942009-02-25 22:02:03 +000068 class ClassTemplateDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000069 class ObjCInterfaceDecl;
Steve Naroffe8043c32008-04-01 23:04:06 +000070 class ObjCCompatibleAliasDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000071 class ObjCProtocolDecl;
Chris Lattnercddc8882009-03-01 00:56:52 +000072 class ObjCImplDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000073 class ObjCImplementationDecl;
74 class ObjCCategoryImplDecl;
75 class ObjCCategoryDecl;
76 class ObjCIvarDecl;
77 class ObjCMethodDecl;
Fariborz Jahanian02edb982008-05-01 00:03:38 +000078 class ObjCPropertyDecl;
Steve Naroff0701bbb2009-01-08 17:28:14 +000079 class ObjCContainerDecl;
Steve Naroff4eb206b2008-09-03 18:15:37 +000080 struct BlockSemaInfo;
Douglas Gregor94b1dd22008-10-24 04:54:22 +000081 class BasePaths;
Sebastian Redl43af76e2009-03-07 12:16:37 +000082 struct MemberLookupCriteria;
Steve Naroffbea0b342007-07-29 16:33:31 +000083
Reid Spencer5f016e22007-07-11 17:01:13 +000084/// Sema - This implements semantic analysis and AST building for C.
85class Sema : public Action {
Chris Lattnerf50adff2009-02-17 00:58:30 +000086 Sema(const Sema&); // DO NOT IMPLEMENT
87 void operator=(const Sema&); // DO NOT IMPLEMENT
Chris Lattner0b2f4da2008-06-29 00:28:59 +000088public:
Chris Lattner53ebff32009-01-22 19:21:44 +000089 const LangOptions &LangOpts;
Reid Spencer5f016e22007-07-11 17:01:13 +000090 Preprocessor &PP;
Reid Spencer5f016e22007-07-11 17:01:13 +000091 ASTContext &Context;
Chris Lattner2ae34ed2008-02-06 00:46:58 +000092 ASTConsumer &Consumer;
Chris Lattner3cfa9282008-11-22 08:28:49 +000093 Diagnostic &Diags;
94 SourceManager &SourceMgr;
Steve Naroff03300712007-11-12 13:56:41 +000095
Argyrios Kyrtzidis53d0ea52008-06-28 06:07:14 +000096 /// CurContext - This is the current declaration context of parsing.
Chris Lattnerb048c982008-04-06 04:47:34 +000097 DeclContext *CurContext;
Chris Lattner0ed844b2008-04-04 06:12:32 +000098
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000099 /// PreDeclaratorDC - Keeps the declaration context before switching to the
100 /// context of a declarator's nested-name-specifier.
101 DeclContext *PreDeclaratorDC;
102
Steve Naroff4eb206b2008-09-03 18:15:37 +0000103 /// CurBlock - If inside of a block definition, this contains a pointer to
104 /// the active block object that represents it.
105 BlockSemaInfo *CurBlock;
106
Steve Narofff3cf8972009-02-28 16:48:43 +0000107 /// ActiveScope - If inside of a function, method, or block definition,
108 /// this contains a pointer to the active scope that represents it.
109 Scope *ActiveScope;
110
Daniel Dunbar4cde9272008-10-14 05:35:18 +0000111 /// PackContext - Manages the stack for #pragma pack. An alignment
112 /// of 0 indicates default alignment.
Chris Lattner574aa402009-02-17 01:09:29 +0000113 void *PackContext; // Really a "PragmaPackStack*"
Daniel Dunbar4cde9272008-10-14 05:35:18 +0000114
Anders Carlssonc1fcb772007-07-22 07:07:56 +0000115 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffbea0b342007-07-29 16:33:31 +0000116
Nate Begeman213541a2008-04-18 23:10:10 +0000117 /// ExtVectorDecls - This is a list all the extended vector types. This allows
118 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroffbea0b342007-07-29 16:33:31 +0000119 /// This is only necessary for issuing pretty diagnostics.
Nate Begeman213541a2008-04-18 23:10:10 +0000120 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattner59907c42007-08-10 20:18:51 +0000121
Steve Naroffe84a8642008-09-28 14:55:53 +0000122 /// ObjCImplementations - Keep track of all class @implementations
123 /// so we can emit errors on duplicates.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000124 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattnerf3876682007-10-07 01:13:46 +0000125
Steve Naroffe84a8642008-09-28 14:55:53 +0000126 /// ObjCCategoryImpls - Maintain a list of category implementations so
127 /// we can check for duplicates and find local method declarations.
128 llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
129
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000130 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanian05672a02007-10-09 18:03:53 +0000131 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner4de884d2007-10-09 18:18:24 +0000132 /// find the declarations when needed.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000133 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff31102512008-04-02 18:30:49 +0000134
135 /// ObjCInterfaceDecls - Keep track of all class declarations declared
136 /// with @interface, so that we can emit errors on duplicates and
137 /// find the declarations when needed.
138 typedef llvm::DenseMap<const IdentifierInfo*,
139 ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
140 ObjCInterfaceDeclsTy ObjCInterfaceDecls;
141
Steve Naroffe8043c32008-04-01 23:04:06 +0000142 /// ObjCAliasDecls - Keep track of all class declarations declared
143 /// with @compatibility_alias, so that we can emit errors on duplicates and
144 /// find the declarations when needed. This construct is ancient and will
145 /// likely never be seen. Nevertheless, it is here for compatibility.
Steve Naroffc822ff42008-04-02 00:39:51 +0000146 typedef llvm::DenseMap<const IdentifierInfo*,
147 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroffe8043c32008-04-01 23:04:06 +0000148 ObjCAliasTy ObjCAliasDecls;
Steve Naroff31102512008-04-02 18:30:49 +0000149
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000150 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
151 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
152
Douglas Gregor63935192009-03-02 00:19:53 +0000153 /// \brief A mapping from external names to the most recent
154 /// locally-scoped external declaration with that name.
155 ///
156 /// This map contains external declarations introduced in local
157 /// scoped, e.g.,
158 ///
159 /// \code
160 /// void f() {
161 /// void foo(int, int);
162 /// }
163 /// \endcode
164 ///
165 /// Here, the name "foo" will be associated with the declaration on
166 /// "foo" within f. This name is not visible outside of
167 /// "f". However, we still find it in two cases:
168 ///
169 /// - If we are declaring another external with the name "foo", we
170 /// can find "foo" as a previous declaration, so that the types
171 /// of this external declaration can be checked for
172 /// compatibility.
173 ///
174 /// - If we would implicitly declare "foo" (e.g., due to a call to
175 /// "foo" in C when no prototype or definition is visible), then
176 /// we find this declaration of "foo" and complain that it is
177 /// not visible.
178 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
179
Chris Lattner7f925cc2008-04-11 07:00:53 +0000180 IdentifierResolver IdResolver;
181
Chris Lattner59907c42007-08-10 20:18:51 +0000182 // Enum values used by KnownFunctionIDs (see below).
183 enum {
Ted Kremenek7ff22b22008-06-16 18:00:42 +0000184 id_NSLog,
Douglas Gregor3c385e52009-02-14 18:57:46 +0000185 id_NSLogv,
Daniel Dunbarde454282008-10-02 18:44:07 +0000186 id_asprintf,
Chris Lattner59907c42007-08-10 20:18:51 +0000187 id_vasprintf,
Chris Lattner59907c42007-08-10 20:18:51 +0000188 id_num_known_functions
189 };
190
191 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
192 /// of known functions used by the semantic analysis to do various
193 /// kinds of checking (e.g. checking format string errors in printf calls).
194 /// This list is populated upon the creation of a Sema object.
Chris Lattner06f54852008-08-23 02:00:52 +0000195 IdentifierInfo* KnownFunctionIDs[id_num_known_functions];
Daniel Dunbar662e8b52008-08-14 22:04:54 +0000196
Steve Naroffe440eb82007-10-10 17:32:04 +0000197 /// Translation Unit Scope - useful to Objective-C actions that need
198 /// to lookup file scope declarations in the "ordinary" C decl namespace.
199 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroffb216c882007-10-09 22:01:59 +0000200 Scope *TUScope;
Sebastian Redlc42e1182008-11-11 11:37:55 +0000201
202 /// The C++ "std" namespace, where the standard library resides. Cached here
203 /// by GetStdNamespace
204 NamespaceDecl *StdNamespace;
Sebastian Redlb5a57a62008-12-03 20:26:15 +0000205
206 /// A flag to remember whether the implicit forms of operator new and delete
207 /// have been declared.
208 bool GlobalNewDeleteDeclared;
Steve Naroff3b950172007-10-10 21:53:07 +0000209
Steve Naroff58ff9e82007-10-14 00:58:41 +0000210 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000211 struct ObjCMethodList {
212 ObjCMethodDecl *Method;
213 ObjCMethodList *Next;
Steve Naroff58ff9e82007-10-14 00:58:41 +0000214
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000215 ObjCMethodList() {
Steve Naroff58ff9e82007-10-14 00:58:41 +0000216 Method = 0;
217 Next = 0;
218 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000219 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff58ff9e82007-10-14 00:58:41 +0000220 Method = M;
221 Next = C;
222 }
223 };
224 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
225 /// messages to "id". We need to maintain a list, since selectors can have
226 /// differing signatures across classes. In Cocoa, this happens to be
227 /// extremely uncommon (only 1% of selectors are "overloaded").
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000228 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
229 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Steve Naroff6b9dfd42009-03-04 15:11:40 +0000230
231 /// Private Helper predicate to check for 'self'.
232 bool isSelfExpr(Expr *RExpr);
Reid Spencer5f016e22007-07-11 17:01:13 +0000233public:
Chris Lattner2ae34ed2008-02-06 00:46:58 +0000234 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
Chris Lattner574aa402009-02-17 01:09:29 +0000235 ~Sema() {
236 if (PackContext) FreePackedContext();
237 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000238
Chris Lattner53ebff32009-01-22 19:21:44 +0000239 const LangOptions &getLangOptions() const { return LangOpts; }
Chris Lattner3cfa9282008-11-22 08:28:49 +0000240 Diagnostic &getDiagnostics() const { return Diags; }
241 SourceManager &getSourceManager() const { return SourceMgr; }
242
Chris Lattnerebf5ddf2008-11-18 21:53:24 +0000243 /// The primitive diagnostic helpers.
Chris Lattner3cfa9282008-11-22 08:28:49 +0000244 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
245 return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
246 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000247
Chris Lattner394a3fd2007-08-31 04:53:24 +0000248 virtual void DeleteExpr(ExprTy *E);
249 virtual void DeleteStmt(StmtTy *S);
250
Sebastian Redl798d1192008-12-13 16:23:55 +0000251 OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); }
Sebastian Redl0eb23302009-01-19 00:08:26 +0000252 OwningExprResult Owned(ExprResult R) {
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000253 if (R.isInvalid())
Steve Naroff872b9ac2009-01-21 22:32:33 +0000254 return ExprError();
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000255 return OwningExprResult(*this, R.get());
Sebastian Redl0eb23302009-01-19 00:08:26 +0000256 }
Sebastian Redl798d1192008-12-13 16:23:55 +0000257 OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
258
Chris Lattner9299f3f2008-08-23 03:19:52 +0000259 virtual void ActOnEndOfTranslationUnit();
Sebastian Redlb8a6aca2009-01-19 22:31:54 +0000260
Reid Spencer5f016e22007-07-11 17:01:13 +0000261 //===--------------------------------------------------------------------===//
262 // Type Analysis / Processing: SemaType.cpp.
263 //
Chris Lattnerfca0ddd2008-06-26 06:27:57 +0000264 QualType ConvertDeclSpecToType(const DeclSpec &DS);
Chris Lattnerc9b346d2008-06-29 00:50:08 +0000265 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Douglas Gregorcd281c32009-02-28 00:25:32 +0000266 QualType BuildPointerType(QualType T, unsigned Quals,
267 SourceLocation Loc, DeclarationName Entity);
268 QualType BuildReferenceType(QualType T, unsigned Quals,
269 SourceLocation Loc, DeclarationName Entity);
270 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
271 Expr *ArraySize, unsigned Quals,
272 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor724651c2009-02-28 01:04:19 +0000273 QualType BuildFunctionType(QualType T,
274 QualType *ParamTypes, unsigned NumParamTypes,
275 bool Variadic, unsigned Quals,
276 SourceLocation Loc, DeclarationName Entity);
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000277 QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0);
Douglas Gregor10bd3682008-11-17 22:58:34 +0000278 DeclarationName GetNameForDeclarator(Declarator &D);
279
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000280 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahanian306d68f2007-11-08 23:49:49 +0000281
Douglas Gregor57373262008-10-22 14:17:15 +0000282 bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
283
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000284 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Sebastian Redl37d6de32008-11-08 13:00:26 +0000285
Douglas Gregor4ec339f2009-01-19 19:26:10 +0000286 bool DiagnoseIncompleteType(SourceLocation Loc, QualType T, unsigned diag,
287 SourceRange Range1 = SourceRange(),
288 SourceRange Range2 = SourceRange(),
289 QualType PrintType = QualType());
290
Reid Spencer5f016e22007-07-11 17:01:13 +0000291 //===--------------------------------------------------------------------===//
292 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
293 //
Chris Lattner21ff9c92009-03-05 01:25:28 +0000294
295 /// getDeclName - Return a pretty name for the specified decl if possible, or
296 /// an empty string if not. This is used for pretty crash reporting.
297 virtual std::string getDeclName(DeclTy *D);
298
Douglas Gregor1a51b4a2009-02-09 15:09:02 +0000299 virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Douglas Gregorb696ea32009-02-04 17:00:24 +0000300 Scope *S, const CXXScopeSpec *SS);
Chris Lattner76a642f2009-02-15 22:43:40 +0000301 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){
Douglas Gregor584049d2008-12-15 23:53:10 +0000302 return ActOnDeclarator(S, D, LastInGroup, false);
303 }
304 DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
305 bool IsFunctionDefinition);
Douglas Gregor63935192009-03-02 00:19:53 +0000306 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl,
307 Scope *S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000308 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
309 QualType R, Decl* LastDeclarator,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000310 Decl* PrevDecl, bool& InvalidDecl,
311 bool &Redeclaration);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000312 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000313 QualType R, Decl* LastDeclarator,
Douglas Gregor8f301052009-02-24 19:23:27 +0000314 NamedDecl* PrevDecl, bool& InvalidDecl,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000315 bool &Redeclaration);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000316 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
317 QualType R, Decl *LastDeclarator,
Douglas Gregor04495c82009-02-24 01:23:02 +0000318 NamedDecl* PrevDecl,
319 bool IsFunctionDefinition,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000320 bool& InvalidDecl, bool &Redeclaration);
Chris Lattner04421082008-04-08 04:40:51 +0000321 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
322 virtual void ActOnParamDefaultArgument(DeclTy *param,
323 SourceLocation EqualLoc,
324 ExprTy *defarg);
Douglas Gregor61366e92008-12-24 00:01:03 +0000325 virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
326 SourceLocation EqualLoc);
Douglas Gregor72b505b2008-12-16 21:30:33 +0000327 virtual void ActOnParamDefaultArgumentError(DeclTy *param);
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000328 virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
329 void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit);
Douglas Gregor27c8dc02008-10-29 00:13:59 +0000330 void ActOnUninitializedDecl(DeclTy *dcl);
Reid Spencer5f016e22007-07-11 17:01:13 +0000331 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
332
Douglas Gregorbe109b32009-01-23 16:23:13 +0000333 virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D);
Chris Lattnerb652cea2007-10-09 17:14:05 +0000334 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000335 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Steve Naroffebf64432009-02-28 16:59:13 +0000336 virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D);
Sebastian Redlb8a6aca2009-01-19 22:31:54 +0000337
Sebastian Redl798d1192008-12-13 16:23:55 +0000338 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
Sebastian Redl798d1192008-12-13 16:23:55 +0000339 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000340
Steve Naroffb216c882007-10-09 22:01:59 +0000341 /// Scope actions.
342 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
343 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000344
345 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
346 /// no declarator (e.g. "struct foo;") is parsed.
Sebastian Redla4ed0d82008-12-28 15:28:59 +0000347 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Reid Spencer5f016e22007-07-11 17:01:13 +0000348
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000349 bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
350 RecordDecl *AnonRecord);
351 virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
352 RecordDecl *Record);
353
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000354 virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000355 SourceLocation KWLoc, const CXXScopeSpec &SS,
356 IdentifierInfo *Name, SourceLocation NameLoc,
Douglas Gregorddc29e12009-02-06 22:42:48 +0000357 AttributeList *Attr);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000358
Douglas Gregor44b43212008-12-11 16:49:14 +0000359 virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner06f54852008-08-23 02:00:52 +0000360 IdentifierInfo *ClassName,
361 llvm::SmallVectorImpl<DeclTy*> &Decls);
Douglas Gregor44b43212008-12-11 16:49:14 +0000362 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Reid Spencer5f016e22007-07-11 17:01:13 +0000363 Declarator &D, ExprTy *BitfieldWidth);
Chris Lattner24793662009-03-05 22:45:59 +0000364
365 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
366 Declarator &D, Expr *BitfieldWidth);
367
Fariborz Jahanian1d78cc42008-04-10 23:32:45 +0000368
369 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
370 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian45bc03f2008-04-11 16:55:42 +0000371 tok::ObjCKeywordKind visibility);
Fariborz Jahanian1d78cc42008-04-10 23:32:45 +0000372
Steve Narofff13271f2007-09-14 23:09:53 +0000373 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian9d048ff2007-09-29 00:54:24 +0000374 virtual void ActOnFields(Scope* S,
Steve Naroff60fccee2007-10-29 21:38:07 +0000375 SourceLocation RecLoc, DeclTy *TagDecl,
376 DeclTy **Fields, unsigned NumFields,
Daniel Dunbar1bfe1c22008-10-03 02:03:53 +0000377 SourceLocation LBrac, SourceLocation RBrac,
378 AttributeList *AttrList);
Douglas Gregor72de6672009-01-08 20:45:30 +0000379
380 /// ActOnTagStartDefinition - Invoked when we have entered the
381 /// scope of a tag's definition (e.g., for an enumeration, class,
382 /// struct, or union).
383 virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl);
384
385 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
386 /// the definition of a tag (enumeration, class, struct, or union).
387 virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl);
388
Steve Naroff08d92e42007-09-15 18:49:24 +0000389 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Reid Spencer5f016e22007-07-11 17:01:13 +0000390 DeclTy *LastEnumConstant,
391 SourceLocation IdLoc, IdentifierInfo *Id,
392 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff08d92e42007-09-15 18:49:24 +0000393 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Reid Spencer5f016e22007-07-11 17:01:13 +0000394 DeclTy **Elements, unsigned NumElements);
Sebastian Redl37d6de32008-11-08 13:00:26 +0000395
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +0000396 DeclContext *getContainingDC(DeclContext *DC);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000397
Chris Lattner0ed844b2008-04-04 06:12:32 +0000398 /// Set the current declaration context until it gets popped.
Douglas Gregor44b43212008-12-11 16:49:14 +0000399 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattnerb048c982008-04-06 04:47:34 +0000400 void PopDeclContext();
Argyrios Kyrtzidis53d0ea52008-06-28 06:07:14 +0000401
Chris Lattner371f2582008-12-04 23:50:19 +0000402 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
403 /// to the function decl for the function being parsed. If we're currently
404 /// in a 'block', this returns the containing context.
405 FunctionDecl *getCurFunctionDecl();
406
407 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
408 /// the method decl for the method being parsed. If we're currently
409 /// in a 'block', this returns the containing context.
Daniel Dunbarc4a1dea2008-08-11 05:35:13 +0000410 ObjCMethodDecl *getCurMethodDecl();
Chris Lattner0ed844b2008-04-04 06:12:32 +0000411
Chris Lattner371f2582008-12-04 23:50:19 +0000412 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
413 /// or C function we're in, otherwise return null. If we're currently
414 /// in a 'block', this returns the containing context.
415 NamedDecl *getCurFunctionOrMethodDecl();
416
Argyrios Kyrtzidis87f3ff02008-04-12 00:47:19 +0000417 /// Add this decl to the scope shadowed decl chains.
418 void PushOnScopeChains(NamedDecl *D, Scope *S);
419
Argyrios Kyrtzidis15a12d02008-09-09 21:18:04 +0000420 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
421 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
422 /// true if 'D' belongs to the given declaration context.
423 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
Douglas Gregor44b43212008-12-11 16:49:14 +0000424 return IdResolver.isDeclInScope(D, Ctx, Context, S);
Argyrios Kyrtzidis15a12d02008-09-09 21:18:04 +0000425 }
426
Eli Friedman8f17b662009-02-28 05:41:13 +0000427
428 void RecursiveCalcJumpScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
429 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
430 llvm::DenseMap<Stmt*, void*>& GotoScopeMap,
431 std::vector<void*>& ScopeStack,
432 Stmt* CurStmt);
433
434 void RecursiveCalcLabelScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
435 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
436 std::vector<void*>& ScopeStack,
437 Stmt* CurStmt,
438 Stmt* ParentCompoundStmt);
439
Chris Lattnerf1d705c2008-02-21 01:07:18 +0000440 /// Subroutines of ActOnDeclarator().
Chris Lattner41af0932007-11-14 06:34:38 +0000441 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000442 Decl *LastDecl);
Douglas Gregorcda9c672009-02-16 17:45:42 +0000443 bool MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
444 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
Douglas Gregor04495c82009-02-24 01:23:02 +0000445 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregorcda9c672009-02-16 17:45:42 +0000446 bool MergeVarDecl(VarDecl *New, Decl *Old);
447 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Steve Naroffff9eb1f2008-08-08 17:50:35 +0000448 void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000449
450 /// C++ Overloading.
451 bool IsOverload(FunctionDecl *New, Decl* OldD,
452 OverloadedFunctionDecl::function_iterator &MatchedDecl);
Douglas Gregor225c41e2008-11-03 19:09:14 +0000453 ImplicitConversionSequence
454 TryImplicitConversion(Expr* From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000455 bool SuppressUserConversions = false,
456 bool AllowExplicit = false);
Douglas Gregor60d62c22008-10-31 16:23:19 +0000457 bool IsStandardConversion(Expr *From, QualType ToType,
458 StandardConversionSequence& SCS);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000459 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
460 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
Douglas Gregor5cdf8212009-02-12 00:15:05 +0000461 bool IsComplexPromotion(QualType FromType, QualType ToType);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000462 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregor45920e82008-12-19 17:40:08 +0000463 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregorc7887512008-12-19 19:13:09 +0000464 bool isObjCPointerConversion(QualType FromType, QualType ToType,
465 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregor94b1dd22008-10-24 04:54:22 +0000466 bool CheckPointerConversion(Expr *From, QualType ToType);
Sebastian Redl4433aaf2009-01-25 19:43:20 +0000467 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
468 QualType &ConvertedType);
469 bool CheckMemberPointerConversion(Expr *From, QualType ToType);
Douglas Gregor98cd5992008-10-21 23:43:52 +0000470 bool IsQualificationConversion(QualType FromType, QualType ToType);
Douglas Gregor60d62c22008-10-31 16:23:19 +0000471 bool IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000472 UserDefinedConversionSequence& User,
Douglas Gregor734d9862009-01-30 23:27:23 +0000473 bool AllowConversionFunctions,
474 bool AllowExplicit);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000475
476 ImplicitConversionSequence::CompareKind
477 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
478 const ImplicitConversionSequence& ICS2);
479
480 ImplicitConversionSequence::CompareKind
481 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
482 const StandardConversionSequence& SCS2);
483
Douglas Gregor57373262008-10-22 14:17:15 +0000484 ImplicitConversionSequence::CompareKind
485 CompareQualificationConversions(const StandardConversionSequence& SCS1,
486 const StandardConversionSequence& SCS2);
487
Douglas Gregorbc0805a2008-10-23 00:40:37 +0000488 ImplicitConversionSequence::CompareKind
489 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
490 const StandardConversionSequence& SCS2);
491
Douglas Gregor225c41e2008-11-03 19:09:14 +0000492 ImplicitConversionSequence
493 TryCopyInitialization(Expr* From, QualType ToType,
494 bool SuppressUserConversions = false);
Douglas Gregor27c8dc02008-10-29 00:13:59 +0000495 bool PerformCopyInitialization(Expr *&From, QualType ToType,
496 const char *Flavor);
497
Douglas Gregor96176b32008-11-18 23:14:02 +0000498 ImplicitConversionSequence
499 TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method);
500 bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method);
501
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000502 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
503 bool PerformContextuallyConvertToBool(Expr *&From);
504
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000505 /// OverloadingResult - Capture the result of performing overload
506 /// resolution.
507 enum OverloadingResult {
508 OR_Success, ///< Overload resolution succeeded.
509 OR_No_Viable_Function, ///< No viable function found.
Douglas Gregor48f3bb92009-02-18 21:56:37 +0000510 OR_Ambiguous, ///< Ambiguous candidates found.
511 OR_Deleted ///< Overload resoltuion refers to a deleted function.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000512 };
513
514 void AddOverloadCandidate(FunctionDecl *Function,
515 Expr **Args, unsigned NumArgs,
Douglas Gregor225c41e2008-11-03 19:09:14 +0000516 OverloadCandidateSet& CandidateSet,
517 bool SuppressUserConversions = false);
Douglas Gregor96176b32008-11-18 23:14:02 +0000518 void AddMethodCandidate(CXXMethodDecl *Method,
519 Expr *Object, Expr **Args, unsigned NumArgs,
520 OverloadCandidateSet& CandidateSet,
Douglas Gregor88a35142008-12-22 05:46:06 +0000521 bool SuppressUserConversions = false);
Douglas Gregorf1991ea2008-11-07 22:36:19 +0000522 void AddConversionCandidate(CXXConversionDecl *Conversion,
523 Expr *From, QualType ToType,
524 OverloadCandidateSet& CandidateSet);
Douglas Gregor106c6eb2008-11-19 22:57:39 +0000525 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
Douglas Gregor72564e72009-02-26 23:50:07 +0000526 const FunctionProtoType *Proto,
Douglas Gregor106c6eb2008-11-19 22:57:39 +0000527 Expr *Object, Expr **Args, unsigned NumArgs,
528 OverloadCandidateSet& CandidateSet);
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000529 bool AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
530 SourceLocation OpLoc,
Douglas Gregor96176b32008-11-18 23:14:02 +0000531 Expr **Args, unsigned NumArgs,
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000532 OverloadCandidateSet& CandidateSet,
533 SourceRange OpRange = SourceRange());
Douglas Gregoreb8f3062008-11-12 17:17:38 +0000534 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
535 Expr **Args, unsigned NumArgs,
Douglas Gregor88b4bf22009-01-13 00:52:54 +0000536 OverloadCandidateSet& CandidateSet,
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000537 bool IsAssignmentOperator = false,
538 unsigned NumContextualBoolArguments = 0);
Douglas Gregor74253732008-11-19 15:42:04 +0000539 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
540 Expr **Args, unsigned NumArgs,
541 OverloadCandidateSet& CandidateSet);
Douglas Gregorfa047642009-02-04 00:32:51 +0000542 void AddArgumentDependentLookupCandidates(DeclarationName Name,
543 Expr **Args, unsigned NumArgs,
544 OverloadCandidateSet& CandidateSet);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000545 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
546 const OverloadCandidate& Cand2);
547 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
548 OverloadCandidateSet::iterator& Best);
549 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
550 bool OnlyViable);
551
Douglas Gregor904eed32008-11-10 20:40:00 +0000552 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
553 bool Complain);
554 void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
555
Douglas Gregor17330012009-02-04 15:01:18 +0000556 FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee,
557 DeclarationName UnqualifiedName,
Douglas Gregor0a396682008-11-26 06:01:48 +0000558 SourceLocation LParenLoc,
559 Expr **Args, unsigned NumArgs,
560 SourceLocation *CommaLocs,
Douglas Gregorfa047642009-02-04 00:32:51 +0000561 SourceLocation RParenLoc,
Douglas Gregor17330012009-02-04 15:01:18 +0000562 bool &ArgumentDependentLookup);
Douglas Gregor88a35142008-12-22 05:46:06 +0000563 ExprResult
564 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
565 SourceLocation LParenLoc, Expr **Args,
566 unsigned NumArgs, SourceLocation *CommaLocs,
567 SourceLocation RParenLoc);
Douglas Gregorf9eb9052008-11-19 21:05:33 +0000568 ExprResult
Douglas Gregor5c37de72008-12-06 00:22:45 +0000569 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregorf9eb9052008-11-19 21:05:33 +0000570 Expr **Args, unsigned NumArgs,
571 SourceLocation *CommaLocs,
572 SourceLocation RParenLoc);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000573
Douglas Gregor3fc749d2008-12-23 00:26:44 +0000574 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
Douglas Gregor8ba10742008-11-20 16:27:02 +0000575 SourceLocation MemberLoc,
576 IdentifierInfo &Member);
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000577
Chris Lattner823c44e2009-01-06 07:27:21 +0000578 /// Helpers for dealing with function parameters.
Chris Lattner04421082008-04-08 04:40:51 +0000579 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattner04421082008-04-08 04:40:51 +0000580 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregor6d6eb572008-05-07 04:49:29 +0000581 void CheckExtraCXXDefaultArguments(Declarator &D);
Reid Spencer5f016e22007-07-11 17:01:13 +0000582
Douglas Gregor1a0d31a2009-01-12 18:45:55 +0000583 Scope *getNonFieldDeclScope(Scope *S);
584
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000585 /// \name Name lookup
586 ///
587 /// These routines provide name lookup that is used during semantic
588 /// analysis to resolve the various kinds of names (identifiers,
589 /// overloaded operator names, constructor names, etc.) into zero or
590 /// more declarations within a particular scope. The major entry
591 /// points are LookupName, which performs unqualified name lookup,
592 /// and LookupQualifiedName, which performs qualified name lookup.
593 ///
594 /// All name lookup is performed based on some specific criteria,
595 /// which specify what names will be visible to name lookup and how
596 /// far name lookup should work. These criteria are important both
597 /// for capturing language semantics (certain lookups will ignore
598 /// certain names, for example) and for performance, since name
599 /// lookup is often a bottleneck in the compilation of C++. Name
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000600 /// lookup criteria is specified via the LookupCriteria enumeration.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000601 ///
602 /// The results of name lookup can vary based on the kind of name
603 /// lookup performed, the current language, and the translation
604 /// unit. In C, for example, name lookup will either return nothing
605 /// (no entity found) or a single declaration. In C++, name lookup
606 /// can additionally refer to a set of overloaded functions or
607 /// result in an ambiguity. All of the possible results of name
608 /// lookup are captured by the LookupResult class, which provides
609 /// the ability to distinguish among them.
610 //@{
Douglas Gregorf780abc2008-12-30 03:27:21 +0000611
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000612 /// @brief Describes the kind of name lookup to perform.
613 enum LookupNameKind {
614 /// Ordinary name lookup, which finds ordinary names (functions,
615 /// variables, typedefs, etc.) in C and most kinds of names
616 /// (functions, variables, members, types, etc.) in C++.
617 LookupOrdinaryName = 0,
618 /// Tag name lookup, which finds the names of enums, classes,
619 /// structs, and unions.
620 LookupTagName,
621 /// Member name lookup, which finds the names of
622 /// class/struct/union members.
623 LookupMemberName,
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000624 // Look up of an operator name (e.g., operator+) for use with
625 // operator overloading. This lookup is similar to ordinary name
626 // lookup, but will ignore any declarations that are class
627 // members.
628 LookupOperatorName,
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000629 /// Look up of a name that precedes the '::' scope resolution
630 /// operator in C++. This lookup completely ignores operator,
631 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
632 LookupNestedNameSpecifierName,
633 /// Look up a namespace name within a C++ using directive or
634 /// namespace alias definition, ignoring non-namespace names (C++
635 /// [basic.lookup.udir]p1).
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000636 LookupNamespaceName,
637 // Look up an ordinary name that is going to be redeclared as a
638 // name with linkage. This lookup ignores any declarations that
639 // are outside of the current scope unless they have linkage. See
640 // C99 6.2.2p4-5 and C++ [basic.link]p6.
641 LookupRedeclarationWithLinkage
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000642 };
643
644 /// @brief Represents the results of name lookup.
645 ///
646 /// An instance of the LookupResult class captures the results of a
647 /// single name lookup, which can return no result (nothing found),
648 /// a single declaration, a set of overloaded functions, or an
649 /// ambiguity. Use the getKind() method to determine which of these
650 /// results occurred for a given lookup.
651 ///
652 /// Any non-ambiguous lookup can be converted into a single
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000653 /// (possibly NULL) @c NamedDecl* via a conversion function or the
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000654 /// getAsDecl() method. This conversion permits the common-case
655 /// usage in C and Objective-C where name lookup will always return
656 /// a single declaration.
Douglas Gregor69d993a2009-01-17 01:13:24 +0000657 struct LookupResult {
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000658 /// The kind of entity that is actually stored within the
659 /// LookupResult object.
Douglas Gregor69d993a2009-01-17 01:13:24 +0000660 enum {
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000661 /// First is a single declaration (a NamedDecl*), which may be NULL.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000662 SingleDecl,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000663
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000664 /// First is a single declaration (an OverloadedFunctionDecl*).
665 OverloadedDeclSingleDecl,
666
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000667 /// [First, Last) is an iterator range represented as opaque
668 /// pointers used to reconstruct IdentifierResolver::iterators.
669 OverloadedDeclFromIdResolver,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000670
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000671 /// [First, Last) is an iterator range represented as opaque
672 /// pointers used to reconstruct DeclContext::lookup_iterators.
673 OverloadedDeclFromDeclContext,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000674
675 /// First is a pointer to a BasePaths structure, which is owned
676 /// by the LookupResult. Last is non-zero to indicate that the
677 /// ambiguity is caused by two names found in base class
678 /// subobjects of different types.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000679 AmbiguousLookupStoresBasePaths,
680
681 /// [First, Last) is an iterator range represented as opaque
682 /// pointers used to reconstruct new'ed Decl*[] array containing
683 /// found ambiguous decls. LookupResult is owner of this array.
684 AmbiguousLookupStoresDecls
685
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000686 } StoredKind;
687
688 /// The first lookup result, whose contents depend on the kind of
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000689 /// lookup result. This may be a NamedDecl* (if StoredKind ==
690 /// SingleDecl), OverloadedFunctionDecl* (if StoredKind ==
691 /// OverloadedDeclSingleDecl), the opaque pointer from an
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000692 /// IdentifierResolver::iterator (if StoredKind ==
Douglas Gregor7176fff2009-01-15 00:26:24 +0000693 /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator
694 /// (if StoredKind == OverloadedDeclFromDeclContext), or a
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000695 /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000696 mutable uintptr_t First;
697
698 /// The last lookup result, whose contents depend on the kind of
699 /// lookup result. This may be unused (if StoredKind ==
Douglas Gregor7176fff2009-01-15 00:26:24 +0000700 /// SingleDecl), it may have the same type as First (for
701 /// overloaded function declarations), or is may be used as a
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000702 /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000703 mutable uintptr_t Last;
704
705 /// Context - The context in which we will build any
706 /// OverloadedFunctionDecl nodes needed by the conversion to
707 /// Decl*.
708 ASTContext *Context;
709
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000710 /// @brief The kind of entity found by name lookup.
711 enum LookupKind {
712 /// @brief No entity found met the criteria.
713 NotFound = 0,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000714
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000715 /// @brief Name lookup found a single declaration that met the
Douglas Gregor7176fff2009-01-15 00:26:24 +0000716 /// criteria. getAsDecl will return this declaration.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000717 Found,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000718
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000719 /// @brief Name lookup found a set of overloaded functions that
Douglas Gregor7176fff2009-01-15 00:26:24 +0000720 /// met the criteria. getAsDecl will turn this set of overloaded
721 /// functions into an OverloadedFunctionDecl.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000722 FoundOverloaded,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000723
724 /// Name lookup results in an ambiguity because multiple
725 /// entities that meet the lookup criteria were found in
726 /// subobjects of different types. For example:
727 /// @code
728 /// struct A { void f(int); }
729 /// struct B { void f(double); }
730 /// struct C : A, B { };
731 /// void test(C c) {
732 /// c.f(0); // error: A::f and B::f come from subobjects of different
733 /// // types. overload resolution is not performed.
734 /// }
735 /// @endcode
736 AmbiguousBaseSubobjectTypes,
737
738 /// Name lookup results in an ambiguity because multiple
739 /// nonstatic entities that meet the lookup criteria were found
740 /// in different subobjects of the same type. For example:
741 /// @code
742 /// struct A { int x; };
743 /// struct B : A { };
744 /// struct C : A { };
745 /// struct D : B, C { };
746 /// int test(D d) {
747 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
748 /// }
749 /// @endcode
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000750 AmbiguousBaseSubobjects,
751
752 /// Name lookup results in an ambiguity because multiple definitions
753 /// of entity that meet the lookup criteria were found in different
754 /// declaration contexts.
755 /// @code
756 /// namespace A {
757 /// int i;
758 /// namespace B { int i; }
759 /// int test() {
760 /// using namespace B;
761 /// return i; // error 'i' is found in namespace A and A::B
762 /// }
763 /// }
764 /// @endcode
765 AmbiguousReference
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000766 };
767
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000768 static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D);
Douglas Gregor4bb64e72009-01-15 02:19:31 +0000769
Douglas Gregor69d993a2009-01-17 01:13:24 +0000770 static LookupResult CreateLookupResult(ASTContext &Context,
771 IdentifierResolver::iterator F,
772 IdentifierResolver::iterator L);
Douglas Gregor7176fff2009-01-15 00:26:24 +0000773
Douglas Gregor69d993a2009-01-17 01:13:24 +0000774 static LookupResult CreateLookupResult(ASTContext &Context,
775 DeclContext::lookup_iterator F,
776 DeclContext::lookup_iterator L);
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000777
Douglas Gregor69d993a2009-01-17 01:13:24 +0000778 static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths,
779 bool DifferentSubobjectTypes) {
780 LookupResult Result;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000781 Result.StoredKind = AmbiguousLookupStoresBasePaths;
Douglas Gregor69d993a2009-01-17 01:13:24 +0000782 Result.First = reinterpret_cast<uintptr_t>(Paths);
783 Result.Last = DifferentSubobjectTypes? 1 : 0;
784 Result.Context = &Context;
785 return Result;
786 }
Douglas Gregor4bb64e72009-01-15 02:19:31 +0000787
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000788 template <typename Iterator>
789 static LookupResult CreateLookupResult(ASTContext &Context,
790 Iterator B, std::size_t Len) {
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000791 NamedDecl ** Array = new NamedDecl*[Len];
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000792 for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B)
793 Array[Idx] = *B;
794 LookupResult Result;
795 Result.StoredKind = AmbiguousLookupStoresDecls;
796 Result.First = reinterpret_cast<uintptr_t>(Array);
797 Result.Last = reinterpret_cast<uintptr_t>(Array + Len);
798 Result.Context = &Context;
799 return Result;
800 }
801
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000802 LookupKind getKind() const;
803
804 /// @brief Determine whether name look found something.
805 operator bool() const { return getKind() != NotFound; }
806
Douglas Gregor7176fff2009-01-15 00:26:24 +0000807 /// @brief Determines whether the lookup resulted in an ambiguity.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000808 bool isAmbiguous() const {
809 return StoredKind == AmbiguousLookupStoresBasePaths ||
810 StoredKind == AmbiguousLookupStoresDecls;
811 }
Douglas Gregor7176fff2009-01-15 00:26:24 +0000812
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000813 /// @brief Allows conversion of a lookup result into a
814 /// declaration, with the same behavior as getAsDecl.
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000815 operator NamedDecl*() const { return getAsDecl(); }
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000816
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000817 NamedDecl* getAsDecl() const;
Douglas Gregor7176fff2009-01-15 00:26:24 +0000818
819 BasePaths *getBasePaths() const;
Douglas Gregord8635172009-02-02 21:35:47 +0000820
821 /// \brief Iterate over the results of name lookup.
822 ///
823 /// The @c iterator class provides iteration over the results of a
824 /// non-ambiguous name lookup.
825 class iterator {
826 /// The LookupResult structure we're iterating through.
827 LookupResult *Result;
828
829 /// The current position of this iterator within the sequence of
830 /// results. This value will have the same representation as the
831 /// @c First field in the LookupResult structure.
832 mutable uintptr_t Current;
833
834 public:
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000835 typedef NamedDecl * value_type;
836 typedef NamedDecl * reference;
837 typedef NamedDecl * pointer;
Douglas Gregord8635172009-02-02 21:35:47 +0000838 typedef std::ptrdiff_t difference_type;
839 typedef std::forward_iterator_tag iterator_category;
840
841 iterator() : Result(0), Current(0) { }
842
843 iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { }
844
845 reference operator*() const;
846
847 pointer operator->() const { return **this; }
848
849 iterator &operator++();
850
851 iterator operator++(int) {
852 iterator tmp(*this);
853 ++(*this);
854 return tmp;
855 }
856
857 friend inline bool operator==(iterator const& x, iterator const& y) {
858 return x.Current == y.Current;
859 }
860
861 friend inline bool operator!=(iterator const& x, iterator const& y) {
862 return x.Current != y.Current;
863 }
864 };
865 friend class iterator;
866
867 iterator begin();
868 iterator end();
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000869 };
870
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000871private:
872 typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy;
873
874 std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name,
875 LookupNameKind NameKind,
876 bool RedeclarationOnly);
877
878public:
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000879 /// Determines whether D is a suitable lookup result according to the
880 /// lookup criteria.
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000881 static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind,
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000882 unsigned IDNS) {
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000883 switch (NameKind) {
884 case Sema::LookupOrdinaryName:
885 case Sema::LookupTagName:
886 case Sema::LookupMemberName:
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000887 case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000888 return D->isInIdentifierNamespace(IDNS);
889
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000890 case Sema::LookupOperatorName:
891 return D->isInIdentifierNamespace(IDNS) &&
892 !D->getDeclContext()->isRecord();
893
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000894 case Sema::LookupNestedNameSpecifierName:
895 return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag);
896
897 case Sema::LookupNamespaceName:
898 return isa<NamespaceDecl>(D);
899 }
900
901 assert(false &&
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000902 "isAcceptableLookupResult always returns before this point");
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000903 return false;
904 }
Douglas Gregor7176fff2009-01-15 00:26:24 +0000905
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000906 LookupResult LookupName(Scope *S, DeclarationName Name,
907 LookupNameKind NameKind,
Douglas Gregor3e41d602009-02-13 23:20:09 +0000908 bool RedeclarationOnly = false,
909 bool AllowBuiltinCreation = true,
910 SourceLocation Loc = SourceLocation());
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000911 LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name,
912 LookupNameKind NameKind,
913 bool RedeclarationOnly = false);
914 LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS,
915 DeclarationName Name,
916 LookupNameKind NameKind,
Douglas Gregor3e41d602009-02-13 23:20:09 +0000917 bool RedeclarationOnly = false,
918 bool AllowBuiltinCreation = true,
919 SourceLocation Loc = SourceLocation());
Douglas Gregorfa047642009-02-04 00:32:51 +0000920
921 typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet;
922 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
923
924 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
925 AssociatedNamespaceSet &AssociatedNamespaces,
926 AssociatedClassSet &AssociatedClasses);
927
Douglas Gregor7176fff2009-01-15 00:26:24 +0000928 bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
929 SourceLocation NameLoc,
930 SourceRange LookupRange = SourceRange());
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000931 //@}
932
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000933 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000934 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Douglas Gregor3e41d602009-02-13 23:20:09 +0000935 Scope *S, bool ForRedeclaration,
936 SourceLocation Loc);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000937 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
938 Scope *S);
Douglas Gregor3c385e52009-02-14 18:57:46 +0000939 void AddKnownFunctionAttributes(FunctionDecl *FD);
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000940
941 // More parsing and symbol table subroutines.
942
Reid Spencer5f016e22007-07-11 17:01:13 +0000943 // Decl attributes - this routine is the top level dispatcher.
Chris Lattnere5c5ee12008-06-29 00:16:31 +0000944 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnerf2e4bd52008-06-28 23:58:55 +0000945 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lambebb97e92008-02-04 02:31:56 +0000946
Steve Naroff3c2eb662008-02-10 21:38:56 +0000947 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
948 bool &IncompleteImpl);
Fariborz Jahanian8daab972008-12-05 18:18:52 +0000949 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
950 ObjCMethodDecl *IntfMethod);
Sebastian Redlc42e1182008-11-11 11:37:55 +0000951
952 NamespaceDecl *GetStdNamespace();
Fariborz Jahaniand1fa6442009-01-12 19:55:42 +0000953
954 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
Steve Naroff22dc0b02009-02-26 19:11:32 +0000955 ObjCInterfaceDecl *IDecl);
Steve Naroff3c2eb662008-02-10 21:38:56 +0000956
Chris Lattner823c44e2009-01-06 07:27:21 +0000957 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000958 /// methods declared in protocol, and those referenced by it.
959 /// \param IDecl - Used for checking for methods which may have been
960 /// inherited.
Steve Naroffefe7f362008-02-08 22:06:17 +0000961 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
962 ObjCProtocolDecl *PDecl,
Fariborz Jahanianca3adf72007-10-02 20:06:01 +0000963 bool& IncompleteImpl,
Steve Naroffeefc4182007-10-08 21:05:34 +0000964 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000965 const llvm::DenseSet<Selector> &ClsMap,
966 ObjCInterfaceDecl *IDecl);
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000967
Steve Naroffa5997c42007-10-02 21:43:37 +0000968 /// CheckImplementationIvars - This routine checks if the instance variables
969 /// listed in the implelementation match those listed in the interface.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000970 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
971 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff3c2eb662008-02-10 21:38:56 +0000972 SourceLocation Loc);
Steve Naroffa5997c42007-10-02 21:43:37 +0000973
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000974 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
Chris Lattnercddc8882009-03-01 00:56:52 +0000975 /// remains unimplemented in the class or category @implementation.
976 void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl,
977 ObjCContainerDecl* IDecl,
978 bool IncompleteImpl = false);
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000979
Fariborz Jahanian85ff2642007-10-05 18:00:57 +0000980 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
981 /// true, or false, accordingly.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000982 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Narofffe6b0dc2008-10-21 10:37:50 +0000983 const ObjCMethodDecl *PrevMethod,
984 bool matchBasedOnSizeAndAlignment = false);
Steve Naroff3b950172007-10-10 21:53:07 +0000985
Steve Naroff58ff9e82007-10-14 00:58:41 +0000986 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
987 /// unit are added to a global pool. This allows us to efficiently associate
988 /// a selector with a method declaraation for purposes of typechecking
989 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000990 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff58ff9e82007-10-14 00:58:41 +0000991
Steve Naroff037cda52008-09-30 14:38:43 +0000992 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
993 /// there are multiple signatures.
994 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
995
Steve Naroff58ff9e82007-10-14 00:58:41 +0000996 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000997 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Reid Spencer5f016e22007-07-11 17:01:13 +0000998 //===--------------------------------------------------------------------===//
999 // Statement Parsing Callbacks: SemaStmt.cpp.
1000public:
Sebastian Redla60528c2008-12-21 12:04:03 +00001001 virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
1002
1003 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
1004 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1005 MultiStmtArg Elts,
1006 bool isStmtExpr);
1007 virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
1008 SourceLocation EndLoc);
Sebastian Redl117054a2008-12-28 16:13:43 +00001009 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
1010 SourceLocation DotDotDotLoc, ExprArg RHSVal,
Chris Lattner24e1e702009-03-04 04:23:07 +00001011 SourceLocation ColonLoc);
1012 virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt);
1013
Sebastian Redl117054a2008-12-28 16:13:43 +00001014 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1015 SourceLocation ColonLoc,
1016 StmtArg SubStmt, Scope *CurScope);
Sebastian Redlde307472009-01-11 00:38:46 +00001017 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
1018 IdentifierInfo *II,
1019 SourceLocation ColonLoc,
1020 StmtArg SubStmt);
1021 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
1022 StmtArg ThenVal, SourceLocation ElseLoc,
1023 StmtArg ElseVal);
1024 virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
1025 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1026 StmtArg Switch, StmtArg Body);
Sebastian Redlf05b1522009-01-16 23:28:06 +00001027 virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
1028 StmtArg Body);
1029 virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
1030 SourceLocation WhileLoc, ExprArg Cond);
1031
1032 virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
1033 SourceLocation LParenLoc,
1034 StmtArg First, ExprArg Second,
1035 ExprArg Third, SourceLocation RParenLoc,
1036 StmtArg Body);
1037 virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1038 SourceLocation LParenLoc,
1039 StmtArg First, ExprArg Second,
1040 SourceLocation RParenLoc, StmtArg Body);
Sebastian Redl4cffe2f2009-01-18 13:19:59 +00001041
1042 virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1043 SourceLocation LabelLoc,
1044 IdentifierInfo *LabelII);
1045 virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1046 SourceLocation StarLoc,
1047 ExprArg DestExp);
1048 virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
1049 Scope *CurScope);
1050 virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
1051 Scope *CurScope);
1052
1053 virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
1054 ExprArg RetValExp);
1055 OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
1056 Expr *RetValExp);
1057
Sebastian Redl3037ed02009-01-18 16:53:17 +00001058 virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1059 bool IsSimple,
1060 bool IsVolatile,
1061 unsigned NumOutputs,
1062 unsigned NumInputs,
1063 std::string *Names,
1064 MultiExprArg Constraints,
1065 MultiExprArg Exprs,
1066 ExprArg AsmString,
1067 MultiExprArg Clobbers,
1068 SourceLocation RParenLoc);
Sebastian Redl431e90e2009-01-18 17:43:11 +00001069
1070 virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
1071 SourceLocation RParen,
Steve Naroff7ba138a2009-03-03 19:52:17 +00001072 DeclTy *Parm, StmtArg Body,
Sebastian Redl431e90e2009-01-18 17:43:11 +00001073 StmtArg CatchList);
1074
1075 virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
1076 StmtArg Body);
1077
1078 virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
1079 StmtArg Try,
1080 StmtArg Catch, StmtArg Finally);
1081
1082 virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Steve Naroffe21dd6f2009-02-11 20:05:44 +00001083 ExprArg Throw,
1084 Scope *CurScope);
Sebastian Redl431e90e2009-01-18 17:43:11 +00001085 virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1086 ExprArg SynchExpr,
1087 StmtArg SynchBody);
Sebastian Redla0fd8652008-12-21 16:41:36 +00001088
Sebastian Redl4b07b292008-12-22 19:15:10 +00001089 virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D);
1090 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
1091 DeclTy *ExDecl,
1092 StmtArg HandlerBlock);
Sebastian Redl8351da02008-12-22 21:35:02 +00001093 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
1094 StmtArg TryBlock,
1095 MultiStmtArg Handlers);
Sebastian Redla0fd8652008-12-21 16:41:36 +00001096
Reid Spencer5f016e22007-07-11 17:01:13 +00001097 //===--------------------------------------------------------------------===//
1098 // Expression Parsing Callbacks: SemaExpr.cpp.
1099
Douglas Gregor48f3bb92009-02-18 21:56:37 +00001100 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
Chris Lattner76a642f2009-02-15 22:43:40 +00001101
Reid Spencer5f016e22007-07-11 17:01:13 +00001102 // Primary Expressions.
Douglas Gregor4b2d3f72009-02-26 21:00:50 +00001103 virtual SourceRange getExprRange(ExprTy *E) const;
1104
Sebastian Redlcd965b92009-01-18 18:53:16 +00001105 virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
1106 IdentifierInfo &II,
1107 bool HasTrailingLParen,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001108 const CXXScopeSpec *SS = 0,
1109 bool isAddressOfOperand = false);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001110 virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S,
Douglas Gregor487a75a2008-11-19 19:09:45 +00001111 SourceLocation OperatorLoc,
1112 OverloadedOperatorKind Op,
1113 bool HasTrailingLParen,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001114 const CXXScopeSpec &SS,
1115 bool isAddressOfOperand);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001116 virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S,
Douglas Gregor487a75a2008-11-19 19:09:45 +00001117 SourceLocation OperatorLoc,
1118 TypeTy *Ty,
1119 bool HasTrailingLParen,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001120 const CXXScopeSpec &SS,
1121 bool isAddressOfOperand);
Douglas Gregor1a49af92009-01-06 05:10:23 +00001122 DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
1123 bool TypeDependent, bool ValueDependent,
1124 const CXXScopeSpec *SS = 0);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001125 OwningExprResult
Douglas Gregorbcbffc42009-01-07 00:43:41 +00001126 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1127 FieldDecl *Field,
1128 Expr *BaseObjectExpr = 0,
1129 SourceLocation OpLoc = SourceLocation());
Sebastian Redlcd965b92009-01-18 18:53:16 +00001130 OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
1131 DeclarationName Name,
1132 bool HasTrailingLParen,
1133 const CXXScopeSpec *SS,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001134 bool isAddressOfOperand = false);
Douglas Gregor10c42622008-11-18 15:03:34 +00001135
Sebastian Redlcd965b92009-01-18 18:53:16 +00001136 virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
1137 tok::TokenKind Kind);
1138 virtual OwningExprResult ActOnNumericConstant(const Token &);
1139 virtual OwningExprResult ActOnCharacterConstant(const Token &);
1140 virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
1141 ExprArg Val);
Reid Spencer5f016e22007-07-11 17:01:13 +00001142
Steve Narofff69936d2007-09-16 03:34:24 +00001143 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Reid Spencer5f016e22007-07-11 17:01:13 +00001144 /// fragments (e.g. "foo" "bar" L"baz").
Sebastian Redl0eb23302009-01-19 00:08:26 +00001145 virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
1146 unsigned NumToks);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001147
Reid Spencer5f016e22007-07-11 17:01:13 +00001148 // Binary/Unary Operators. 'Tok' is the token for the operator.
Sebastian Redl0eb23302009-01-19 00:08:26 +00001149 virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1150 tok::TokenKind Op, ExprArg Input);
1151 virtual OwningExprResult
Sebastian Redl05189992008-11-11 17:56:53 +00001152 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1153 void *TyOrEx, const SourceRange &ArgRange);
1154
Chris Lattner31e21e02009-01-24 20:17:12 +00001155 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R);
Sebastian Redl05189992008-11-11 17:56:53 +00001156 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1157 const SourceRange &R, bool isSizeof);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001158
1159 virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1160 tok::TokenKind Kind,
1161 ExprArg Input);
1162
1163 virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
1164 SourceLocation LLoc,
1165 ExprArg Idx,
1166 SourceLocation RLoc);
1167 virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base,
1168 SourceLocation OpLoc,
1169 tok::TokenKind OpKind,
1170 SourceLocation MemberLoc,
Fariborz Jahaniana6e3ac52009-03-04 22:30:12 +00001171 IdentifierInfo &Member,
1172 DeclTy *ImplDecl=0);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001173 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
Douglas Gregor88a35142008-12-22 05:46:06 +00001174 FunctionDecl *FDecl,
Douglas Gregor72564e72009-02-26 23:50:07 +00001175 const FunctionProtoType *Proto,
Douglas Gregor88a35142008-12-22 05:46:06 +00001176 Expr **Args, unsigned NumArgs,
1177 SourceLocation RParenLoc);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001178
Steve Narofff69936d2007-09-16 03:34:24 +00001179 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Reid Spencer5f016e22007-07-11 17:01:13 +00001180 /// This provides the location of the left/right parens and a list of comma
1181 /// locations.
Sebastian Redl0eb23302009-01-19 00:08:26 +00001182 virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn,
1183 SourceLocation LParenLoc,
1184 MultiExprArg Args,
1185 SourceLocation *CommaLocs,
1186 SourceLocation RParenLoc);
1187
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001188 virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
1189 SourceLocation RParenLoc, ExprArg Op);
1190
1191 virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1192 TypeTy *Ty,
1193 SourceLocation RParenLoc,
1194 ExprArg Op);
1195
1196 virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
1197 MultiExprArg InitList,
1198 InitListDesignations &Designators,
1199 SourceLocation RParenLoc);
1200
Douglas Gregor05c13a32009-01-22 00:58:24 +00001201 virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
1202 SourceLocation Loc,
1203 bool UsedColonSyntax,
1204 OwningExprResult Init);
1205
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001206 virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1207 tok::TokenKind Kind,
1208 ExprArg LHS, ExprArg RHS);
1209 OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1210 unsigned Opc, Expr *lhs, Expr *rhs);
Douglas Gregoreaebc752008-11-06 23:29:22 +00001211
Steve Narofff69936d2007-09-16 03:34:24 +00001212 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Reid Spencer5f016e22007-07-11 17:01:13 +00001213 /// in the case of a the GNU conditional expr extension.
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001214 virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1215 SourceLocation ColonLoc,
1216 ExprArg Cond, ExprArg LHS,
1217 ExprArg RHS);
Reid Spencer5f016e22007-07-11 17:01:13 +00001218
Steve Naroff1b273c42007-09-16 14:56:35 +00001219 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1220 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +00001221 IdentifierInfo *LabelII);
1222
Steve Naroff1b273c42007-09-16 14:56:35 +00001223 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattnerab18c4c2007-07-24 16:58:17 +00001224 SourceLocation RPLoc); // "({..})"
Chris Lattner73d0d4f2007-08-30 17:45:32 +00001225
1226 /// __builtin_offsetof(type, a.b[123][456].c)
Douglas Gregor3fc749d2008-12-23 00:26:44 +00001227 virtual ExprResult ActOnBuiltinOffsetOf(Scope *S,
1228 SourceLocation BuiltinLoc,
Chris Lattner73d0d4f2007-08-30 17:45:32 +00001229 SourceLocation TypeLoc, TypeTy *Arg1,
1230 OffsetOfComponent *CompPtr,
1231 unsigned NumComponents,
1232 SourceLocation RParenLoc);
1233
Steve Naroffd34e9152007-08-01 22:05:33 +00001234 // __builtin_types_compatible_p(type1, type2)
Steve Naroff1b273c42007-09-16 14:56:35 +00001235 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroffd34e9152007-08-01 22:05:33 +00001236 TypeTy *arg1, TypeTy *arg2,
1237 SourceLocation RPLoc);
Steve Naroffd04fdd52007-08-03 21:21:27 +00001238
1239 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff1b273c42007-09-16 14:56:35 +00001240 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroffd04fdd52007-08-03 21:21:27 +00001241 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
1242 SourceLocation RPLoc);
Chris Lattnerab18c4c2007-07-24 16:58:17 +00001243
Anders Carlsson7c50aca2007-10-15 20:28:48 +00001244 // __builtin_va_arg(expr, type)
1245 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1246 ExprTy *expr, TypeTy *type,
1247 SourceLocation RPLoc);
Steve Naroff4eb206b2008-09-03 18:15:37 +00001248
Douglas Gregor2d8b2732008-11-29 04:51:27 +00001249 // __null
1250 virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1251
Steve Naroff4eb206b2008-09-03 18:15:37 +00001252 //===------------------------- "Block" Extension ------------------------===//
1253
1254 /// ActOnBlockStart - This callback is invoked when a block literal is
1255 /// started.
Steve Naroff090276f2008-10-10 01:28:17 +00001256 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1257
1258 /// ActOnBlockArguments - This callback allows processing of block arguments.
1259 /// If there are no arguments, this is still invoked.
Mike Stump98eb8a72009-02-04 22:31:32 +00001260 virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
Steve Naroff4eb206b2008-09-03 18:15:37 +00001261
1262 /// ActOnBlockError - If there is an error parsing a block, this callback
1263 /// is invoked to pop the information about the block from the action impl.
1264 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1265
1266 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1267 /// literal was successfully completed. ^(int x){...}
1268 virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
1269 Scope *CurScope);
1270
Chris Lattner76a642f2009-02-15 22:43:40 +00001271 //===---------------------------- C++ Features --------------------------===//
1272
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +00001273 // Act on C++ namespaces
1274 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
1275 IdentifierInfo *Ident,
1276 SourceLocation LBrace);
1277 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
1278
Douglas Gregorf780abc2008-12-30 03:27:21 +00001279 virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
1280 SourceLocation UsingLoc,
1281 SourceLocation NamespcLoc,
1282 const CXXScopeSpec &SS,
1283 SourceLocation IdentLoc,
1284 IdentifierInfo *NamespcName,
1285 AttributeList *AttrList);
1286
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001287 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
1288
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +00001289 /// AddCXXDirectInitializerToDecl - This action is called immediately after
1290 /// ActOnDeclarator, when a C++ direct initializer is present.
1291 /// e.g: "int x(1);"
1292 virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
1293 SourceLocation LParenLoc,
1294 ExprTy **Exprs, unsigned NumExprs,
1295 SourceLocation *CommaLocs,
1296 SourceLocation RParenLoc);
1297
Douglas Gregorf03d7c72008-11-05 15:29:30 +00001298 /// InitializationKind - Represents which kind of C++ initialization
1299 /// [dcl.init] a routine is to perform.
1300 enum InitializationKind {
1301 IK_Direct, ///< Direct initialization
1302 IK_Copy, ///< Copy initialization
1303 IK_Default ///< Default initialization
1304 };
1305
Douglas Gregor18fe5682008-11-03 20:45:27 +00001306 CXXConstructorDecl *
Douglas Gregorf03d7c72008-11-05 15:29:30 +00001307 PerformInitializationByConstructor(QualType ClassType,
1308 Expr **Args, unsigned NumArgs,
1309 SourceLocation Loc, SourceRange Range,
Chris Lattnerd9d22dd2008-11-24 05:29:24 +00001310 DeclarationName InitEntity,
Douglas Gregorf03d7c72008-11-05 15:29:30 +00001311 InitializationKind Kind);
Douglas Gregor18fe5682008-11-03 20:45:27 +00001312
Douglas Gregor49badde2008-10-27 19:41:14 +00001313 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
1314 virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
1315 SourceLocation LAngleBracketLoc, TypeTy *Ty,
1316 SourceLocation RAngleBracketLoc,
1317 SourceLocation LParenLoc, ExprTy *E,
1318 SourceLocation RParenLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001319
Sebastian Redlc42e1182008-11-11 11:37:55 +00001320 /// ActOnCXXTypeidOfType - Parse typeid( type-id ).
1321 virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
1322 SourceLocation LParenLoc, bool isType,
1323 void *TyOrExpr, SourceLocation RParenLoc);
1324
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00001325 //// ActOnCXXThis - Parse 'this' pointer.
1326 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
1327
Steve Naroff1b273c42007-09-16 14:56:35 +00001328 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
1329 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +00001330 tok::TokenKind Kind);
Anders Carlsson55085182007-08-21 17:43:55 +00001331
Chris Lattner50dd2892008-02-26 00:51:44 +00001332 //// ActOnCXXThrow - Parse throw expressions.
1333 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
1334 ExprTy *expr);
1335
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00001336 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
1337 /// Can be interpreted either as function-style casting ("int(x)")
1338 /// or class type construction ("ClassType(x,y,z)")
1339 /// or creation of a value-initialized type ("int()").
1340 virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
1341 TypeTy *TypeRep,
1342 SourceLocation LParenLoc,
1343 ExprTy **Exprs,
1344 unsigned NumExprs,
1345 SourceLocation *CommaLocs,
1346 SourceLocation RParenLoc);
1347
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001348 /// ActOnCXXNew - Parsed a C++ 'new' expression.
1349 virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1350 SourceLocation PlacementLParen,
1351 ExprTy **PlacementArgs, unsigned NumPlaceArgs,
1352 SourceLocation PlacementRParen,
Sebastian Redlcee63fb2008-12-02 14:43:59 +00001353 bool ParenTypeId, Declarator &D,
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001354 SourceLocation ConstructorLParen,
1355 ExprTy **ConstructorArgs, unsigned NumConsArgs,
1356 SourceLocation ConstructorRParen);
Sebastian Redlcee63fb2008-12-02 14:43:59 +00001357 bool CheckAllocatedType(QualType AllocType, const Declarator &D);
Sebastian Redl00e68e22009-02-09 18:24:27 +00001358 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
1359 bool UseGlobal, QualType AllocType, bool IsArray,
Sebastian Redlb5a57a62008-12-03 20:26:15 +00001360 Expr **PlaceArgs, unsigned NumPlaceArgs,
1361 FunctionDecl *&OperatorNew,
1362 FunctionDecl *&OperatorDelete);
Sebastian Redl00e68e22009-02-09 18:24:27 +00001363 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
1364 DeclarationName Name, Expr** Args,
1365 unsigned NumArgs, DeclContext *Ctx,
Sebastian Redl7f662392008-12-04 22:20:51 +00001366 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlb5a57a62008-12-03 20:26:15 +00001367 void DeclareGlobalNewDelete();
1368 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
1369 QualType Argument);
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001370
1371 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
1372 virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
1373 bool ArrayForm, ExprTy *Operand);
1374
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00001375 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
1376 /// C++ if/switch/while/for statement.
1377 /// e.g: "if (int x = f()) {...}"
1378 virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
1379 SourceLocation StartLoc,
1380 Declarator &D,
1381 SourceLocation EqualLoc,
1382 ExprTy *AssignExprVal);
1383
Sebastian Redl64b45f72009-01-05 20:52:13 +00001384 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
1385 /// pseudo-functions.
1386 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
1387 SourceLocation KWLoc,
1388 SourceLocation LParen,
1389 TypeTy *Ty,
1390 SourceLocation RParen);
1391
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001392 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
1393 /// global scope ('::').
1394 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
1395 SourceLocation CCLoc);
1396
1397 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1398 /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now
1399 /// we want to resolve "bar::". 'SS' is empty or the previously parsed
1400 /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar',
1401 /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'.
1402 /// Returns a CXXScopeTy* object representing the C++ scope.
1403 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1404 const CXXScopeSpec &SS,
1405 SourceLocation IdLoc,
1406 SourceLocation CCLoc,
Douglas Gregor2def4832008-11-17 20:34:05 +00001407 IdentifierInfo &II);
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001408
Douglas Gregor39a8de12009-02-25 19:37:18 +00001409 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1410 /// nested-name-specifier that involves a template-id, e.g.,
1411 /// "foo::bar<int, float>::", and now we need to build a scope
1412 /// specifier. \p SS is empty or the previously parsed nested-name
1413 /// part ("foo::"), \p Type is the already-parsed class template
1414 /// specialization (or other template-id that names a type), \p
1415 /// TypeRange is the source range where the type is located, and \p
1416 /// CCLoc is the location of the trailing '::'.
1417 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1418 const CXXScopeSpec &SS,
1419 TypeTy *Type,
1420 SourceRange TypeRange,
1421 SourceLocation CCLoc);
1422
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001423 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1424 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1425 /// After this method is called, according to [C++ 3.4.3p3], names should be
1426 /// looked up in the declarator-id's scope, until the declarator is parsed and
1427 /// ActOnCXXExitDeclaratorScope is called.
1428 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1429 virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
1430
1431 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1432 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1433 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1434 /// Used to indicate that names should revert to being looked up in the
1435 /// defining scope.
Douglas Gregor0a59acb2008-12-16 00:38:16 +00001436 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001437
Anders Carlsson55085182007-08-21 17:43:55 +00001438 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00001439 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
1440 ExprTy **Strings,
1441 unsigned NumStrings);
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001442 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner674af952007-10-16 22:51:17 +00001443 SourceLocation EncodeLoc,
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001444 SourceLocation LParenLoc,
1445 TypeTy *Ty,
1446 SourceLocation RParenLoc);
1447
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001448 // ParseObjCSelectorExpression - Build selector expression for @selector
1449 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
1450 SourceLocation AtLoc,
Fariborz Jahanian2a35fa92007-10-16 23:21:02 +00001451 SourceLocation SelLoc,
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001452 SourceLocation LParenLoc,
1453 SourceLocation RParenLoc);
1454
Fariborz Jahanian390d50a2007-10-17 16:58:11 +00001455 // ParseObjCProtocolExpression - Build protocol expression for @protocol
1456 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
1457 SourceLocation AtLoc,
1458 SourceLocation ProtoLoc,
1459 SourceLocation LParenLoc,
1460 SourceLocation RParenLoc);
Douglas Gregore37ac4f2008-04-13 21:30:24 +00001461
1462 //===--------------------------------------------------------------------===//
Douglas Gregor074149e2009-01-05 19:45:36 +00001463 // C++ Declarations
1464 //
1465 virtual DeclTy *ActOnStartLinkageSpecification(Scope *S,
1466 SourceLocation ExternLoc,
1467 SourceLocation LangLoc,
1468 const char *Lang,
1469 unsigned StrSize,
1470 SourceLocation LBraceLoc);
1471 virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S,
1472 DeclTy *LinkageSpec,
1473 SourceLocation RBraceLoc);
1474
1475
1476 //===--------------------------------------------------------------------===//
Douglas Gregore37ac4f2008-04-13 21:30:24 +00001477 // C++ Classes
1478 //
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001479 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
1480 const CXXScopeSpec *SS);
Douglas Gregorb48fe382008-10-31 09:07:45 +00001481
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00001482 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
1483 Declarator &D, ExprTy *BitfieldWidth,
1484 ExprTy *Init, DeclTy *LastInGroup);
1485
Douglas Gregor7ad83902008-11-05 04:29:56 +00001486 virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD,
1487 Scope *S,
1488 IdentifierInfo *MemberOrBase,
1489 SourceLocation IdLoc,
1490 SourceLocation LParenLoc,
1491 ExprTy **Args, unsigned NumArgs,
1492 SourceLocation *CommaLocs,
1493 SourceLocation RParenLoc);
1494
Douglas Gregor396b7cd2008-11-03 17:51:48 +00001495 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
1496
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00001497 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
1498 DeclTy *TagDecl,
1499 SourceLocation LBrac,
1500 SourceLocation RBrac);
1501
Douglas Gregor72b505b2008-12-16 21:30:33 +00001502 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1503 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param);
1504 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1505
Douglas Gregor42a552f2008-11-05 20:51:48 +00001506 bool CheckConstructorDeclarator(Declarator &D, QualType &R,
1507 FunctionDecl::StorageClass& SC);
Douglas Gregor72b505b2008-12-16 21:30:33 +00001508 bool CheckConstructor(CXXConstructorDecl *Constructor);
Douglas Gregor42a552f2008-11-05 20:51:48 +00001509 bool CheckDestructorDeclarator(Declarator &D, QualType &R,
1510 FunctionDecl::StorageClass& SC);
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001511 bool CheckConversionDeclarator(Declarator &D, QualType &R,
1512 FunctionDecl::StorageClass& SC);
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001513 DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregorb48fe382008-10-31 09:07:45 +00001514
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001515 //===--------------------------------------------------------------------===//
1516 // C++ Derived Classes
1517 //
1518
1519 /// ActOnBaseSpecifier - Parsed a base specifier
Douglas Gregor2943aed2009-03-03 04:44:36 +00001520 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
1521 SourceRange SpecifierRange,
1522 bool Virtual, AccessSpecifier Access,
1523 QualType BaseType,
1524 SourceLocation BaseLoc);
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001525 virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl,
1526 SourceRange SpecifierRange,
1527 bool Virtual, AccessSpecifier Access,
Douglas Gregor2943aed2009-03-03 04:44:36 +00001528 TypeTy *basetype, SourceLocation
1529 BaseLoc);
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001530
Douglas Gregor2943aed2009-03-03 04:44:36 +00001531 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
1532 unsigned NumBases);
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001533 virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
1534 unsigned NumBases);
1535
1536 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00001537 bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
Douglas Gregor7176fff2009-01-15 00:26:24 +00001538 bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria,
1539 BasePaths &Paths);
Douglas Gregor0575d4a2008-10-24 16:17:19 +00001540 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
1541 SourceLocation Loc, SourceRange Range);
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +00001542 std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
Douglas Gregore37ac4f2008-04-13 21:30:24 +00001543
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +00001544 //===--------------------------------------------------------------------===//
1545 // C++ Overloaded Operators [C++ 13.5]
1546 //
1547
1548 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
1549
Douglas Gregor72c3f312008-12-05 18:15:24 +00001550 //===--------------------------------------------------------------------===//
1551 // C++ Templates [C++ 14]
1552 //
Douglas Gregor55f6b142009-02-09 18:46:07 +00001553 virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S,
1554 DeclTy *&TemplateDecl,
1555 const CXXScopeSpec *SS = 0);
Douglas Gregor72c3f312008-12-05 18:15:24 +00001556 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001557 TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl);
1558
1559 virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename,
1560 SourceLocation KeyLoc,
1561 IdentifierInfo *ParamName,
1562 SourceLocation ParamNameLoc,
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001563 unsigned Depth, unsigned Position);
Douglas Gregord684b002009-02-10 19:49:53 +00001564 virtual void ActOnTypeParameterDefault(DeclTy *TypeParam,
1565 SourceLocation EqualLoc,
1566 SourceLocation DefaultLoc,
1567 TypeTy *Default);
1568
Douglas Gregor2943aed2009-03-03 04:44:36 +00001569 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001570 virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001571 unsigned Depth,
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001572 unsigned Position);
Douglas Gregord684b002009-02-10 19:49:53 +00001573 virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam,
1574 SourceLocation EqualLoc,
1575 ExprArg Default);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001576 virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S,
1577 SourceLocation TmpLoc,
1578 TemplateParamsTy *Params,
1579 IdentifierInfo *ParamName,
1580 SourceLocation ParamNameLoc,
1581 unsigned Depth,
1582 unsigned Position);
Douglas Gregord684b002009-02-10 19:49:53 +00001583 virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam,
1584 SourceLocation EqualLoc,
1585 ExprArg Default);
1586
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001587 virtual TemplateParamsTy *
1588 ActOnTemplateParameterList(unsigned Depth,
1589 SourceLocation ExportLoc,
1590 SourceLocation TemplateLoc,
1591 SourceLocation LAngleLoc,
1592 DeclTy **Params, unsigned NumParams,
1593 SourceLocation RAngleLoc);
Douglas Gregord684b002009-02-10 19:49:53 +00001594 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
1595 TemplateParameterList *OldParams);
1596
Douglas Gregorddc29e12009-02-06 22:42:48 +00001597 virtual DeclTy *
1598 ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK,
1599 SourceLocation KWLoc, const CXXScopeSpec &SS,
1600 IdentifierInfo *Name, SourceLocation NameLoc,
1601 AttributeList *Attr,
1602 MultiTemplateParamsArg TemplateParameterLists);
1603
Douglas Gregorcc636682009-02-17 23:15:12 +00001604 virtual TypeResult
1605 ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc,
1606 SourceLocation LAngleLoc,
1607 ASTTemplateArgsPtr TemplateArgs,
1608 SourceLocation *TemplateArgLocs,
1609 SourceLocation RAngleLoc,
1610 const CXXScopeSpec *SS);
1611
Douglas Gregor88b70942009-02-25 22:02:03 +00001612 bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate,
1613 ClassTemplateSpecializationDecl *PrevDecl,
1614 SourceLocation TemplateNameLoc,
1615 SourceRange ScopeSpecifierRange);
1616
Douglas Gregorcc636682009-02-17 23:15:12 +00001617 virtual DeclTy *
1618 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
1619 SourceLocation KWLoc,
1620 const CXXScopeSpec &SS,
1621 DeclTy *Template,
1622 SourceLocation TemplateNameLoc,
Douglas Gregor55f6b142009-02-09 18:46:07 +00001623 SourceLocation LAngleLoc,
Douglas Gregor5908e9f2009-02-09 19:34:22 +00001624 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregorc15cb382009-02-09 23:23:08 +00001625 SourceLocation *TemplateArgLocs,
Douglas Gregor55f6b142009-02-09 18:46:07 +00001626 SourceLocation RAngleLoc,
Douglas Gregorcc636682009-02-17 23:15:12 +00001627 AttributeList *Attr,
1628 MultiTemplateParamsArg TemplateParameterLists);
Douglas Gregor55f6b142009-02-09 18:46:07 +00001629
Douglas Gregorc15cb382009-02-09 23:23:08 +00001630 bool CheckTemplateArgumentList(TemplateDecl *Template,
1631 SourceLocation TemplateLoc,
1632 SourceLocation LAngleLoc,
1633 ASTTemplateArgsPtr& TemplateArgs,
1634 SourceLocation *TemplateArgLocs,
Douglas Gregor3e00bad2009-02-17 01:05:43 +00001635 SourceLocation RAngleLoc,
1636 llvm::SmallVectorImpl<TemplateArgument> &Converted);
Douglas Gregorc15cb382009-02-09 23:23:08 +00001637
1638 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg,
1639 SourceLocation ArgLoc);
Douglas Gregor3e00bad2009-02-17 01:05:43 +00001640 bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,
1641 NamedDecl *&Entity);
1642 bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member);
Douglas Gregor2943aed2009-03-03 04:44:36 +00001643 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
1644 QualType InstantiatedParamType, Expr *&Arg,
Douglas Gregor3e00bad2009-02-17 01:05:43 +00001645 llvm::SmallVectorImpl<TemplateArgument> *Converted = 0);
Douglas Gregorc15cb382009-02-09 23:23:08 +00001646 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg);
Douglas Gregorddc29e12009-02-06 22:42:48 +00001647 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
1648 TemplateParameterList *Old,
1649 bool Complain,
Douglas Gregordd0574e2009-02-10 00:24:35 +00001650 bool IsTemplateTemplateParm = false,
1651 SourceLocation TemplateArgLoc
1652 = SourceLocation());
Douglas Gregorddc29e12009-02-06 22:42:48 +00001653
1654 bool CheckTemplateDeclScope(Scope *S,
1655 MultiTemplateParamsArg &TemplateParameterLists);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001656
Douglas Gregor99ebf652009-02-27 19:31:52 +00001657 //===--------------------------------------------------------------------===//
1658 // C++ Template Instantiation
1659 //
1660 QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
1661 unsigned NumTemplateArgs,
1662 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor2943aed2009-03-03 04:44:36 +00001663 bool
1664 InstantiateBaseSpecifiers(ClassTemplateSpecializationDecl *ClassTemplateSpec,
1665 ClassTemplateDecl *ClassTemplate);
1666 bool
1667 InstantiateClassTemplateSpecialization(
1668 ClassTemplateSpecializationDecl *ClassTemplateSpec,
1669 bool ExplicitInstantiation);
Douglas Gregor99ebf652009-02-27 19:31:52 +00001670
Steve Naroff3536b442007-09-06 21:24:23 +00001671 // Objective-C declarations.
Chris Lattner06036d32008-07-26 04:13:19 +00001672 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
1673 IdentifierInfo *ClassName,
1674 SourceLocation ClassLoc,
1675 IdentifierInfo *SuperName,
1676 SourceLocation SuperLoc,
1677 DeclTy * const *ProtoRefs,
1678 unsigned NumProtoRefs,
1679 SourceLocation EndProtoLoc,
1680 AttributeList *AttrList);
Fariborz Jahanian243b64b2007-10-11 23:42:27 +00001681
1682 virtual DeclTy *ActOnCompatiblityAlias(
1683 SourceLocation AtCompatibilityAliasLoc,
1684 IdentifierInfo *AliasName, SourceLocation AliasLocation,
1685 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff61d68522009-03-05 15:22:01 +00001686
1687 void CheckForwardProtocolDeclarationForCircularDependency(
1688 IdentifierInfo *PName,
1689 SourceLocation &PLoc, SourceLocation PrevLoc,
1690 const ObjCList<ObjCProtocolDecl> &PList);
Steve Naroff3536b442007-09-06 21:24:23 +00001691
Steve Naroffe440eb82007-10-10 17:32:04 +00001692 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman1abc7f62008-02-20 22:57:40 +00001693 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian25e077d2007-09-17 21:07:36 +00001694 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattnere13b9592008-07-26 04:03:38 +00001695 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar246e70f2008-09-26 04:48:09 +00001696 SourceLocation EndProtoLoc,
1697 AttributeList *AttrList);
Fariborz Jahanian25e077d2007-09-17 21:07:36 +00001698
Chris Lattner6bd6d0b2008-07-26 04:07:02 +00001699 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
1700 IdentifierInfo *ClassName,
1701 SourceLocation ClassLoc,
1702 IdentifierInfo *CategoryName,
1703 SourceLocation CategoryLoc,
1704 DeclTy * const *ProtoRefs,
1705 unsigned NumProtoRefs,
1706 SourceLocation EndProtoLoc);
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +00001707
Steve Naroffe440eb82007-10-10 17:32:04 +00001708 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman1abc7f62008-02-20 22:57:40 +00001709 SourceLocation AtClassImplLoc,
Fariborz Jahanianccb4f312007-09-25 18:38:09 +00001710 IdentifierInfo *ClassName, SourceLocation ClassLoc,
1711 IdentifierInfo *SuperClassname,
1712 SourceLocation SuperClassLoc);
1713
Steve Naroffe440eb82007-10-10 17:32:04 +00001714 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +00001715 SourceLocation AtCatImplLoc,
1716 IdentifierInfo *ClassName,
1717 SourceLocation ClassLoc,
1718 IdentifierInfo *CatName,
1719 SourceLocation CatLoc);
1720
Steve Naroffe440eb82007-10-10 17:32:04 +00001721 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroff37e58d12007-10-02 22:39:18 +00001722 IdentifierInfo **IdentList,
1723 unsigned NumElts);
Fariborz Jahanian894c57f2007-09-21 15:40:54 +00001724
Steve Naroffe440eb82007-10-10 17:32:04 +00001725 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattner7caeabd2008-07-21 22:17:28 +00001726 const IdentifierLocPair *IdentList,
Fariborz Jahanianbc1c8772008-12-17 01:07:27 +00001727 unsigned NumElts,
1728 AttributeList *attrList);
Fariborz Jahanian245f92a2007-10-05 21:01:53 +00001729
Chris Lattnere13b9592008-07-26 04:03:38 +00001730 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattner7caeabd2008-07-21 22:17:28 +00001731 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001732 unsigned NumProtocols,
Chris Lattner7caeabd2008-07-21 22:17:28 +00001733 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanian02edb982008-05-01 00:03:38 +00001734
Daniel Dunbar95e61fb2008-09-23 21:53:23 +00001735 /// Ensure attributes are consistent with type.
1736 /// \param [in, out] Attributes The attributes to check; they will
1737 /// be modified to be consistent with \arg PropertyTy.
1738 void CheckObjCPropertyAttributes(QualType PropertyTy,
1739 SourceLocation Loc,
1740 unsigned &Attributes);
Steve Naroff0701bbb2009-01-08 17:28:14 +00001741 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Fariborz Jahanian02edb982008-05-01 00:03:38 +00001742 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1743 ObjCPropertyDecl *SuperProperty,
Chris Lattner8ec03f52008-11-24 03:54:41 +00001744 const IdentifierInfo *Name);
Fariborz Jahanian02edb982008-05-01 00:03:38 +00001745 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanianb5e02242008-04-24 19:58:34 +00001746
Fariborz Jahanian1ac2bc42008-12-06 23:03:39 +00001747 void MergeProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanianaebf0cb2008-05-02 19:17:30 +00001748 DeclTy *MergeProtocols);
1749
Fariborz Jahanianb7f95f52009-03-02 19:05:07 +00001750 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
1751 ObjCInterfaceDecl *ID);
1752
Fariborz Jahanian1ac2bc42008-12-06 23:03:39 +00001753 void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanianaebf0cb2008-05-02 19:17:30 +00001754 ObjCProtocolDecl *PDecl);
1755
Steve Naroff0416fb92007-11-11 17:19:15 +00001756 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
1757 DeclTy **allMethods = 0, unsigned allNum = 0,
1758 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +00001759
Fariborz Jahanian1de1e742008-04-14 23:36:35 +00001760 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian46b55e52008-05-05 18:51:55 +00001761 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanian5251e132008-05-06 18:09:04 +00001762 Selector GetterSel, Selector SetterSel,
Fariborz Jahanian8cf0bb32008-11-26 20:01:34 +00001763 DeclTy *ClassCategory, bool *OverridingProperty,
Fariborz Jahanian46b55e52008-05-05 18:51:55 +00001764 tok::ObjCKeywordKind MethodImplKind);
1765
Fariborz Jahanianf624f812008-04-18 00:19:30 +00001766 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
1767 SourceLocation PropertyLoc,
1768 bool ImplKind, DeclTy *ClassImplDecl,
1769 IdentifierInfo *PropertyId,
1770 IdentifierInfo *PropertyIvar);
1771
Steve Naroffbef11852007-10-26 20:53:56 +00001772 virtual DeclTy *ActOnMethodDeclaration(
1773 SourceLocation BeginLoc, // location of the + or -.
1774 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanian1f7b6f82007-11-09 19:52:12 +00001775 tok::TokenKind MethodType,
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001776 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanianf1de0ca2007-10-31 23:53:01 +00001777 Selector Sel,
Steve Naroff68d331a2007-09-27 14:38:14 +00001778 // optional arguments. The number of types/arguments is obtained
1779 // from the Sel.getNumArgs().
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001780 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Fariborz Jahanian439c6582009-01-09 00:38:19 +00001781 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroff335eafa2007-11-15 12:35:21 +00001782 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
1783 bool isVariadic = false);
Steve Naroff81bfde92007-10-16 23:12:48 +00001784
Steve Narofff1afaf62009-02-26 15:55:06 +00001785 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
1786 // Will search "local" class/category implementations for a method decl.
Fariborz Jahanian175ba1e2009-03-04 18:15:57 +00001787 // Will also search in class's root looking for instance method.
Steve Narofff1afaf62009-02-26 15:55:06 +00001788 // Returns 0 if no method is found.
Fariborz Jahanian175ba1e2009-03-04 18:15:57 +00001789 ObjCMethodDecl *LookupPrivateOrRootMethod(Selector Sel, ObjCInterfaceDecl *CDecl);
Steve Narofff1afaf62009-02-26 15:55:06 +00001790
Steve Naroff68d331a2007-09-27 14:38:14 +00001791 // ActOnClassMessage - used for both unary and keyword messages.
1792 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff49f109c2007-11-15 13:05:42 +00001793 // is obtained from NumArgs.
Steve Naroff68d331a2007-09-27 14:38:14 +00001794 virtual ExprResult ActOnClassMessage(
Fariborz Jahanian0523aaf2007-11-12 20:13:27 +00001795 Scope *S,
Anders Carlssonff975cf2009-02-14 18:21:46 +00001796 IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,
1797 SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac,
Steve Naroff49f109c2007-11-15 13:05:42 +00001798 ExprTy **ArgExprs, unsigned NumArgs);
Steve Naroff68d331a2007-09-27 14:38:14 +00001799
1800 // ActOnInstanceMessage - used for both unary and keyword messages.
1801 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff49f109c2007-11-15 13:05:42 +00001802 // is obtained from NumArgs.
Steve Naroff68d331a2007-09-27 14:38:14 +00001803 virtual ExprResult ActOnInstanceMessage(
Steve Naroffbcfb06a2007-09-28 22:22:11 +00001804 ExprTy *receiver, Selector Sel,
Anders Carlssonff975cf2009-02-14 18:21:46 +00001805 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroff49f109c2007-11-15 13:05:42 +00001806 ExprTy **ArgExprs, unsigned NumArgs);
Daniel Dunbar4cde9272008-10-14 05:35:18 +00001807
1808 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
1809 virtual void ActOnPragmaPack(PragmaPackKind Kind,
1810 IdentifierInfo *Name,
1811 ExprTy *Alignment,
1812 SourceLocation PragmaLoc,
1813 SourceLocation LParenLoc,
1814 SourceLocation RParenLoc);
Chris Lattner574aa402009-02-17 01:09:29 +00001815
1816 /// getPragmaPackAlignment() - Return the current alignment as specified by
1817 /// the current #pragma pack directive, or 0 if none is currently active.
1818 unsigned getPragmaPackAlignment() const;
1819
1820 /// FreePackedContext - Deallocate and null out PackContext.
1821 void FreePackedContext();
Daniel Dunbar4cde9272008-10-14 05:35:18 +00001822
Chris Lattner1e0a3902008-01-16 19:17:22 +00001823 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
1824 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregoreb8f3062008-11-12 17:17:38 +00001825 /// If isLvalue, the result of the cast is an lvalue.
1826 void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
Chris Lattner1e0a3902008-01-16 19:17:22 +00001827
Reid Spencer5f016e22007-07-11 17:01:13 +00001828 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner925e60d2007-12-28 05:29:59 +00001829 // functions and arrays to their respective pointers (C99 6.3.2.1).
1830 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3c0eb162008-05-27 03:33:27 +00001831
Steve Naroffc80b4ee2007-07-16 21:54:35 +00001832 // DefaultFunctionArrayConversion - converts functions and arrays
1833 // to their respective pointers (C99 6.3.2.1).
1834 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroff90045e82007-07-13 23:32:42 +00001835
Steve Naroffb291ab62007-08-28 23:30:39 +00001836 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
1837 // do not have a prototype. Integer promotions are performed on each
1838 // argument, and arguments that have type float are promoted to double.
Chris Lattner925e60d2007-12-28 05:29:59 +00001839 void DefaultArgumentPromotion(Expr *&Expr);
Anders Carlssondce5e2c2009-01-16 16:48:51 +00001840
1841 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
1842 enum VariadicCallType {
1843 VariadicFunction,
1844 VariadicBlock,
1845 VariadicMethod
1846 };
1847
1848 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
1849 // will warn if the resulting type is not a POD type.
1850 void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
Steve Naroffb291ab62007-08-28 23:30:39 +00001851
Reid Spencer5f016e22007-07-11 17:01:13 +00001852 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
1853 // operands and then handles various conversions that are common to binary
1854 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
1855 // routine returns the first non-arithmetic type found. The client is
1856 // responsible for emitting appropriate error diagnostics.
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00001857 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
1858 bool isCompAssign = false);
Chris Lattnerb7b61152008-01-04 18:22:42 +00001859
Douglas Gregoreb8f3062008-11-12 17:17:38 +00001860 /// UsualArithmeticConversionsType - handles the various conversions
1861 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
1862 /// and returns the result type of that conversion.
1863 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
1864
1865
Chris Lattnerb7b61152008-01-04 18:22:42 +00001866 /// AssignConvertType - All of the 'assignment' semantic checks return this
1867 /// enum to indicate whether the assignment was allowed. These checks are
1868 /// done for simple assignments, as well as initialization, return from
1869 /// function, argument passing, etc. The query is phrased in terms of a
1870 /// source and destination type.
Chris Lattner5cf216b2008-01-04 18:04:52 +00001871 enum AssignConvertType {
Chris Lattnerb7b61152008-01-04 18:22:42 +00001872 /// Compatible - the types are compatible according to the standard.
Reid Spencer5f016e22007-07-11 17:01:13 +00001873 Compatible,
Chris Lattnerb7b61152008-01-04 18:22:42 +00001874
1875 /// PointerToInt - The assignment converts a pointer to an int, which we
1876 /// accept as an extension.
1877 PointerToInt,
1878
1879 /// IntToPointer - The assignment converts an int to a pointer, which we
1880 /// accept as an extension.
1881 IntToPointer,
1882
1883 /// FunctionVoidPointer - The assignment is between a function pointer and
1884 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattnerbfe639e2008-01-03 22:56:36 +00001885 FunctionVoidPointer,
Chris Lattnerb7b61152008-01-04 18:22:42 +00001886
1887 /// IncompatiblePointer - The assignment is between two pointers types that
1888 /// are not compatible, but we accept them as an extension.
Reid Spencer5f016e22007-07-11 17:01:13 +00001889 IncompatiblePointer,
Chris Lattnerb7b61152008-01-04 18:22:42 +00001890
1891 /// CompatiblePointerDiscardsQualifiers - The assignment discards
1892 /// c/v/r qualifiers, which we accept as an extension.
1893 CompatiblePointerDiscardsQualifiers,
Steve Naroff1c7d0672008-09-04 15:10:53 +00001894
Anders Carlssonb0f90cc2009-01-30 23:17:46 +00001895 /// IncompatibleVectors - The assignment is between two vector types that
1896 /// have the same size, which we accept as an extension.
1897 IncompatibleVectors,
1898
Steve Naroffbfdcae62008-09-04 15:31:07 +00001899 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff1c7d0672008-09-04 15:10:53 +00001900 /// pointer. We disallow this.
1901 IntToBlockPointer,
1902
Steve Naroffbfdcae62008-09-04 15:31:07 +00001903 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff1c7d0672008-09-04 15:10:53 +00001904 /// pointers types that are not compatible.
1905 IncompatibleBlockPointer,
1906
Steve Naroff39579072008-10-14 22:18:38 +00001907 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
1908 /// id type and something else (that is incompatible with it). For example,
1909 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
1910 IncompatibleObjCQualifiedId,
1911
Chris Lattnerb7b61152008-01-04 18:22:42 +00001912 /// Incompatible - We reject this conversion outright, it is invalid to
1913 /// represent it in the AST.
1914 Incompatible
Reid Spencer5f016e22007-07-11 17:01:13 +00001915 };
Chris Lattner5cf216b2008-01-04 18:04:52 +00001916
1917 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
1918 /// assignment conversion type specified by ConvTy. This returns true if the
1919 /// conversion was invalid or false if the conversion was accepted.
1920 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
1921 SourceLocation Loc,
1922 QualType DstType, QualType SrcType,
1923 Expr *SrcExpr, const char *Flavor);
1924
1925 /// CheckAssignmentConstraints - Perform type checking for assignment,
1926 /// argument passing, variable initialization, and function return values.
1927 /// This routine is only used by the following two methods. C99 6.5.16.
1928 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroff90045e82007-07-13 23:32:42 +00001929
Steve Narofff69936d2007-09-16 03:34:24 +00001930 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff1b273c42007-09-16 14:56:35 +00001931 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroff90045e82007-07-13 23:32:42 +00001932 // this routine performs the default function/array converions.
Chris Lattner5cf216b2008-01-04 18:04:52 +00001933 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
1934 Expr *&rExpr);
Steve Naroff90045e82007-07-13 23:32:42 +00001935 // CheckCompoundAssignmentConstraints - Type check without performing any
1936 // conversions. For compound assignments, the "Check...Operands" methods
1937 // perform the necessary conversions.
Chris Lattner5cf216b2008-01-04 18:04:52 +00001938 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
1939 QualType rhs);
Steve Naroff90045e82007-07-13 23:32:42 +00001940
Reid Spencer5f016e22007-07-11 17:01:13 +00001941 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner5cf216b2008-01-04 18:04:52 +00001942 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
1943 QualType rhsType);
Steve Naroff1c7d0672008-09-04 15:10:53 +00001944
1945 // Helper function for CheckAssignmentConstraints involving two
1946 // blcok pointer types.
1947 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
1948 QualType rhsType);
Douglas Gregor77a52232008-09-12 00:47:35 +00001949
1950 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00001951
Douglas Gregor45920e82008-12-19 17:40:08 +00001952 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00001953 const char *Flavor, bool AllowExplicit = false);
1954 bool PerformImplicitConversion(Expr *&From, QualType ToType,
1955 const ImplicitConversionSequence& ICS,
Douglas Gregor45920e82008-12-19 17:40:08 +00001956 const char *Flavor);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00001957 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor45920e82008-12-19 17:40:08 +00001958 const StandardConversionSequence& SCS,
1959 const char *Flavor);
Sebastian Redl22460502009-02-07 00:15:38 +00001960
Reid Spencer5f016e22007-07-11 17:01:13 +00001961 /// the following "Check" methods will return a valid/converted QualType
1962 /// or a null QualType (indicating an error diagnostic was issued).
Sebastian Redl22460502009-02-07 00:15:38 +00001963
1964 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
Chris Lattnerca5eede2007-12-12 05:47:28 +00001965 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Sebastian Redl7c8bd602009-02-07 20:10:22 +00001966 QualType CheckPointerToMemberOperands( // C++ 5.5
Sebastian Redl22460502009-02-07 00:15:38 +00001967 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
Reid Spencer5f016e22007-07-11 17:01:13 +00001968 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Sebastian Redl22460502009-02-07 00:15:38 +00001969 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00001970 inline QualType CheckRemainderOperands( // C99 6.5.5
Sebastian Redl22460502009-02-07 00:15:38 +00001971 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00001972 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00001973 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00001974 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00001975 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00001976 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00001977 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnera5937dd2007-08-26 01:18:55 +00001978 inline QualType CheckCompareOperands( // C99 6.5.8/9
1979 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Reid Spencer5f016e22007-07-11 17:01:13 +00001980 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Sebastian Redl22460502009-02-07 00:15:38 +00001981 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00001982 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff49b45262007-07-13 16:58:59 +00001983 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001984 // CheckAssignmentOperands is used for both simple and compound assignment.
1985 // For simple assignment, pass both expressions and a null converted type.
1986 // For compound assignment, pass both expressions and the converted type.
1987 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Narofff1120de2007-08-24 22:33:52 +00001988 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Reid Spencer5f016e22007-07-11 17:01:13 +00001989 inline QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner29a1cfb2008-11-18 01:30:42 +00001990 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001991 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff49b45262007-07-13 16:58:59 +00001992 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begemanbe2341d2008-07-14 18:02:46 +00001993
1994 /// type checking for vector binary operators.
1995 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
1996 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
1997 SourceLocation l, bool isRel);
Reid Spencer5f016e22007-07-11 17:01:13 +00001998
Steve Narofff69936d2007-09-16 03:34:24 +00001999 /// type checking unary operators (subroutines of ActOnUnaryOp).
Reid Spencer5f016e22007-07-11 17:01:13 +00002000 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redle6d5a4a2008-12-20 09:35:34 +00002001 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
2002 bool isInc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002003 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
2004 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattnerba27e2a2009-02-17 08:12:06 +00002005 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
Steve Naroffe1b31fe2007-07-27 22:15:19 +00002006
2007 /// type checking primary expressions.
Nate Begeman213541a2008-04-18 23:10:10 +00002008 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Naroffe1b31fe2007-07-27 22:15:19 +00002009 IdentifierInfo &Comp, SourceLocation CmpLoc);
2010
Steve Narofff0090632007-09-02 02:04:30 +00002011 /// type checking declaration initializers (C99 6.7.8)
Douglas Gregorf03d7c72008-11-05 15:29:30 +00002012 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00002013 SourceLocation InitLoc,DeclarationName InitEntity,
2014 bool DirectInit);
Douglas Gregorc34ee5e2009-01-29 00:45:39 +00002015 bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
Steve Naroffd0091aa2008-01-10 22:15:12 +00002016 bool CheckForConstantInitializer(Expr *e, QualType t);
Steve Naroff2fdc3742007-12-10 22:44:33 +00002017
Douglas Gregor87fd7032009-02-02 17:43:21 +00002018 bool CheckValueInitialization(QualType Type, SourceLocation Loc);
Argyrios Kyrtzidis6c2dc4d2008-08-16 20:27:34 +00002019
Douglas Gregor27c8dc02008-10-29 00:13:59 +00002020 // type checking C++ declaration initializers (C++ [dcl.init]).
2021
2022 /// ReferenceCompareResult - Expresses the result of comparing two
2023 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
2024 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
2025 enum ReferenceCompareResult {
2026 /// Ref_Incompatible - The two types are incompatible, so direct
2027 /// reference binding is not possible.
2028 Ref_Incompatible = 0,
2029 /// Ref_Related - The two types are reference-related, which means
2030 /// that their unqualified forms (T1 and T2) are either the same
2031 /// or T1 is a base class of T2.
2032 Ref_Related,
2033 /// Ref_Compatible_With_Added_Qualification - The two types are
2034 /// reference-compatible with added qualification, meaning that
2035 /// they are reference-compatible and the qualifiers on T1 (cv1)
2036 /// are greater than the qualifiers on T2 (cv2).
2037 Ref_Compatible_With_Added_Qualification,
2038 /// Ref_Compatible - The two types are reference-compatible and
2039 /// have equivalent qualifiers (cv1 == cv2).
2040 Ref_Compatible
2041 };
2042
Douglas Gregor15da57e2008-10-29 02:00:59 +00002043 ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
2044 bool& DerivedToBase);
Douglas Gregor27c8dc02008-10-29 00:13:59 +00002045
2046 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor225c41e2008-11-03 19:09:14 +00002047 ImplicitConversionSequence *ICS = 0,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00002048 bool SuppressUserConversions = false,
2049 bool AllowExplicit = false);
Douglas Gregor27c8dc02008-10-29 00:13:59 +00002050
Argyrios Kyrtzidis6c2dc4d2008-08-16 20:27:34 +00002051 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar58d5ebb2008-08-20 03:55:42 +00002052 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroffa49e1fa2008-01-22 00:55:40 +00002053
Anders Carlsson584b2472007-11-27 07:16:40 +00002054 // CheckVectorCast - check type constraints for vectors.
2055 // Since vectors are an extension, there are no C standard reference for this.
2056 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssona64db8f2007-11-27 05:51:55 +00002057 // returns true if the cast is invalid
2058 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
2059
Daniel Dunbar637cebb2008-09-11 00:01:56 +00002060 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
2061 /// \param Method - May be null.
2062 /// \param [out] ReturnType - The return type of the send.
2063 /// \return true iff there were any incompatible types.
Daniel Dunbar91e19b22008-09-11 00:50:25 +00002064 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattner077bf5e2008-11-24 03:33:13 +00002065 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbar637cebb2008-09-11 00:01:56 +00002066 SourceLocation lbrac, SourceLocation rbrac,
2067 QualType &ReturnType);
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00002068
2069 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
2070 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff81bfde92007-10-16 23:12:48 +00002071
Chris Lattnerf4021e72007-08-23 05:46:52 +00002072 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
2073 /// the specified width and sign. If an overflow occurs, detect it and emit
2074 /// the specified diagnostic.
2075 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
2076 unsigned NewWidth, bool NewSign,
2077 SourceLocation Loc, unsigned DiagID);
2078
Chris Lattnereca7be62008-04-07 05:30:13 +00002079 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
2080 bool ForCompare);
2081
Anders Carlsson15281452008-11-04 16:57:32 +00002082 /// Checks that the Objective-C declaration is declared in the global scope.
2083 /// Emits an error and marks the declaration as invalid if it's not declared
2084 /// in the global scope.
2085 bool CheckObjCDeclScope(Decl *D);
2086
Anders Carlsson7c50aca2007-10-15 20:28:48 +00002087 void InitBuiltinVaListType();
Eli Friedman1b76ada2008-06-03 21:01:11 +00002088
Anders Carlssone21555e2008-11-30 19:50:32 +00002089 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
2090 /// and reports the appropriate diagnostics. Returns false on success.
2091 /// Can optionally return the value of the expression.
Anders Carlsson9f1e5722008-12-06 20:33:04 +00002092 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson4000ea62008-12-01 02:17:22 +00002093
Anders Carlsson9f1e5722008-12-06 20:33:04 +00002094 /// VerifyBitField - verifies that a bit field expression is an ICE and has
2095 /// the correct width, and that the field type is valid.
2096 /// Returns false on success.
2097 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
2098 QualType FieldTy, const Expr *BitWidth);
Sebastian Redl0eb23302009-01-19 00:08:26 +00002099
Chris Lattner59907c42007-08-10 20:18:51 +00002100 //===--------------------------------------------------------------------===//
2101 // Extra semantic analysis beyond the C type system
Chris Lattner925e60d2007-12-28 05:29:59 +00002102private:
Sebastian Redl0eb23302009-01-19 00:08:26 +00002103 Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl,
2104 CallExpr *TheCall);
Chris Lattner60800082009-02-18 17:49:48 +00002105 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
2106 unsigned ByteNo) const;
Chris Lattner69039812009-02-18 06:01:06 +00002107 bool CheckObjCString(Expr *Arg);
Chris Lattner925e60d2007-12-28 05:29:59 +00002108 bool SemaBuiltinVAStart(CallExpr *TheCall);
2109 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedman6cfda232008-05-20 08:23:37 +00002110 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Sebastian Redl0eb23302009-01-19 00:08:26 +00002111 Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbar4493f792008-07-21 22:59:13 +00002112 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbard5f8a4f2008-09-03 21:13:56 +00002113 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Ted Kremenekd30ef872009-01-12 23:09:09 +00002114 bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg,
Douglas Gregor3c385e52009-02-14 18:57:46 +00002115 unsigned format_idx, unsigned firstDataArg);
Ted Kremenekd30ef872009-01-12 23:09:09 +00002116 void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr,
2117 CallExpr *TheCall, bool HasVAListArg,
Douglas Gregor3c385e52009-02-14 18:57:46 +00002118 unsigned format_idx, unsigned firstDataArg);
2119 void CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
2120 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek06de2762007-08-17 16:46:58 +00002121 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
2122 SourceLocation ReturnLoc);
Ted Kremenek588e5eb2007-11-25 00:58:00 +00002123 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Reid Spencer5f016e22007-07-11 17:01:13 +00002124};
2125
Steve Naroff4eb206b2008-09-03 18:15:37 +00002126/// BlockSemaInfo - When a block is being parsed, this contains information
2127/// about the block. It is pointed to from Sema::CurBlock.
2128struct BlockSemaInfo {
2129 llvm::SmallVector<ParmVarDecl*, 8> Params;
Steve Naroff4eb206b2008-09-03 18:15:37 +00002130 bool hasPrototype;
2131 bool isVariadic;
Mike Stumpb83d2872009-02-19 22:01:56 +00002132 bool hasBlockDeclRefExprs;
2133
Steve Naroff1c90bfc2008-10-08 18:44:00 +00002134 BlockDecl *TheDecl;
2135
Chris Lattnerda425eb2009-02-18 07:09:44 +00002136 /// TheScope - This is the scope for the block itself, which contains
Steve Naroff4eb206b2008-09-03 18:15:37 +00002137 /// arguments etc.
2138 Scope *TheScope;
2139
2140 /// ReturnType - This will get set to block result type, by looking at
2141 /// return types, if any, in the block body.
2142 Type *ReturnType;
2143
2144 /// PrevBlockInfo - If this is nested inside another block, this points
2145 /// to the outer block.
2146 BlockSemaInfo *PrevBlockInfo;
2147};
Ted Kremenek8189cde2009-02-07 01:47:29 +00002148
2149//===--------------------------------------------------------------------===//
2150// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
2151template <typename T>
2152class ExprOwningPtr : public Action::ExprArg {
2153public:
2154 ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {};
2155
2156 void reset(T* p) { Action::ExprArg::operator=(p); }
2157 T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
2158 T* take() { return static_cast<T*>(Action::ExprArg::take()); }
2159 T* release() { return take(); }
2160
2161 T& operator*() const { return *get(); }
2162 T* operator->() const { return get(); }
2163};
2164
Reid Spencer5f016e22007-07-11 17:01:13 +00002165} // end namespace clang
2166
2167#endif