blob: c4964bf69bdc09a3c22202da4147f1dea9439c0f [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the Sema class, which performs semantic analysis and
11// builds ASTs.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_SEMA_H
16#define LLVM_CLANG_AST_SEMA_H
17
Chris Lattner7f925cc2008-04-11 07:00:53 +000018#include "IdentifierResolver.h"
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +000019#include "CXXFieldCollector.h"
Douglas Gregor8e9bebd2008-10-21 16:13:35 +000020#include "SemaOverload.h"
Douglas Gregoreb11cd02009-01-14 22:20:51 +000021#include "clang/AST/DeclBase.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000022#include "clang/Parse/Action.h"
Chris Lattner500d3292009-01-29 05:15:15 +000023#include "clang/Sema/SemaDiagnostic.h"
Anders Carlssonc1fcb772007-07-22 07:07:56 +000024#include "llvm/ADT/SmallVector.h"
Fariborz Jahanian85ff2642007-10-05 18:00:57 +000025#include "llvm/ADT/DenseSet.h"
Chris Lattnerf3876682007-10-07 01:13:46 +000026#include "llvm/ADT/SmallPtrSet.h"
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +000027#include "llvm/ADT/OwningPtr.h"
Steve Naroff61d68522009-03-05 15:22:01 +000028#include "clang/AST/DeclObjC.h"
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +000029#include <string>
Douglas Gregor94b1dd22008-10-24 04:54:22 +000030#include <vector>
Reid Spencer5f016e22007-07-11 17:01:13 +000031
Chris Lattnerf4021e72007-08-23 05:46:52 +000032namespace llvm {
33 class APSInt;
34}
35
Reid Spencer5f016e22007-07-11 17:01:13 +000036namespace clang {
37 class ASTContext;
Chris Lattner2ae34ed2008-02-06 00:46:58 +000038 class ASTConsumer;
Reid Spencer5f016e22007-07-11 17:01:13 +000039 class Preprocessor;
40 class Decl;
Chris Lattnerb048c982008-04-06 04:47:34 +000041 class DeclContext;
Daniel Dunbar12bc6922008-08-11 03:27:53 +000042 class DeclSpec;
Steve Naroffe8043c32008-04-01 23:04:06 +000043 class NamedDecl;
Sebastian Redl798d1192008-12-13 16:23:55 +000044 class Stmt;
Reid Spencer5f016e22007-07-11 17:01:13 +000045 class Expr;
Steve Naroff6f9f3072007-09-02 15:34:30 +000046 class InitListExpr;
Douglas Gregor05c13a32009-01-22 00:58:24 +000047 class DesignatedInitExpr;
Chris Lattner925e60d2007-12-28 05:29:59 +000048 class CallExpr;
Douglas Gregor1a49af92009-01-06 05:10:23 +000049 class DeclRefExpr;
Reid Spencer5f016e22007-07-11 17:01:13 +000050 class VarDecl;
51 class ParmVarDecl;
52 class TypedefDecl;
53 class FunctionDecl;
54 class QualType;
Sebastian Redl43af76e2009-03-07 12:16:37 +000055 class LangOptions;
Chris Lattnerd2177732007-07-20 16:59:19 +000056 class Token;
Reid Spencer5f016e22007-07-11 17:01:13 +000057 class IntegerLiteral;
Steve Naroffa49e1fa2008-01-22 00:55:40 +000058 class StringLiteral;
Reid Spencer5f016e22007-07-11 17:01:13 +000059 class ArrayType;
60 class LabelStmt;
Anders Carlssonc1fcb772007-07-22 07:07:56 +000061 class SwitchStmt;
Nate Begeman213541a2008-04-18 23:10:10 +000062 class ExtVectorType;
Steve Naroffbea0b342007-07-29 16:33:31 +000063 class TypedefDecl;
Douglas Gregoraaba5e32009-02-04 19:02:06 +000064 class TemplateDecl;
Douglas Gregor3e00bad2009-02-17 01:05:43 +000065 class TemplateArgument;
Douglas Gregorddc29e12009-02-06 22:42:48 +000066 class TemplateParameterList;
Douglas Gregorc15cb382009-02-09 23:23:08 +000067 class TemplateTemplateParmDecl;
Douglas Gregor88b70942009-02-25 22:02:03 +000068 class ClassTemplateDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000069 class ObjCInterfaceDecl;
Steve Naroffe8043c32008-04-01 23:04:06 +000070 class ObjCCompatibleAliasDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000071 class ObjCProtocolDecl;
Chris Lattnercddc8882009-03-01 00:56:52 +000072 class ObjCImplDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000073 class ObjCImplementationDecl;
74 class ObjCCategoryImplDecl;
75 class ObjCCategoryDecl;
76 class ObjCIvarDecl;
77 class ObjCMethodDecl;
Fariborz Jahanian02edb982008-05-01 00:03:38 +000078 class ObjCPropertyDecl;
Steve Naroff0701bbb2009-01-08 17:28:14 +000079 class ObjCContainerDecl;
Steve Naroff4eb206b2008-09-03 18:15:37 +000080 struct BlockSemaInfo;
Douglas Gregor94b1dd22008-10-24 04:54:22 +000081 class BasePaths;
Sebastian Redl43af76e2009-03-07 12:16:37 +000082 struct MemberLookupCriteria;
Steve Naroffbea0b342007-07-29 16:33:31 +000083
Reid Spencer5f016e22007-07-11 17:01:13 +000084/// Sema - This implements semantic analysis and AST building for C.
85class Sema : public Action {
Chris Lattnerf50adff2009-02-17 00:58:30 +000086 Sema(const Sema&); // DO NOT IMPLEMENT
87 void operator=(const Sema&); // DO NOT IMPLEMENT
Chris Lattner0b2f4da2008-06-29 00:28:59 +000088public:
Chris Lattner53ebff32009-01-22 19:21:44 +000089 const LangOptions &LangOpts;
Reid Spencer5f016e22007-07-11 17:01:13 +000090 Preprocessor &PP;
Reid Spencer5f016e22007-07-11 17:01:13 +000091 ASTContext &Context;
Chris Lattner2ae34ed2008-02-06 00:46:58 +000092 ASTConsumer &Consumer;
Chris Lattner3cfa9282008-11-22 08:28:49 +000093 Diagnostic &Diags;
94 SourceManager &SourceMgr;
Steve Naroff03300712007-11-12 13:56:41 +000095
Argyrios Kyrtzidis53d0ea52008-06-28 06:07:14 +000096 /// CurContext - This is the current declaration context of parsing.
Chris Lattnerb048c982008-04-06 04:47:34 +000097 DeclContext *CurContext;
Chris Lattner0ed844b2008-04-04 06:12:32 +000098
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000099 /// PreDeclaratorDC - Keeps the declaration context before switching to the
100 /// context of a declarator's nested-name-specifier.
101 DeclContext *PreDeclaratorDC;
102
Steve Naroff4eb206b2008-09-03 18:15:37 +0000103 /// CurBlock - If inside of a block definition, this contains a pointer to
104 /// the active block object that represents it.
105 BlockSemaInfo *CurBlock;
106
Steve Narofff3cf8972009-02-28 16:48:43 +0000107 /// ActiveScope - If inside of a function, method, or block definition,
108 /// this contains a pointer to the active scope that represents it.
109 Scope *ActiveScope;
110
Daniel Dunbar4cde9272008-10-14 05:35:18 +0000111 /// PackContext - Manages the stack for #pragma pack. An alignment
112 /// of 0 indicates default alignment.
Chris Lattner574aa402009-02-17 01:09:29 +0000113 void *PackContext; // Really a "PragmaPackStack*"
Daniel Dunbar4cde9272008-10-14 05:35:18 +0000114
Anders Carlssonc1fcb772007-07-22 07:07:56 +0000115 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffbea0b342007-07-29 16:33:31 +0000116
Nate Begeman213541a2008-04-18 23:10:10 +0000117 /// ExtVectorDecls - This is a list all the extended vector types. This allows
118 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroffbea0b342007-07-29 16:33:31 +0000119 /// This is only necessary for issuing pretty diagnostics.
Nate Begeman213541a2008-04-18 23:10:10 +0000120 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattner59907c42007-08-10 20:18:51 +0000121
Steve Naroffe84a8642008-09-28 14:55:53 +0000122 /// ObjCImplementations - Keep track of all class @implementations
123 /// so we can emit errors on duplicates.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000124 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattnerf3876682007-10-07 01:13:46 +0000125
Steve Naroffe84a8642008-09-28 14:55:53 +0000126 /// ObjCCategoryImpls - Maintain a list of category implementations so
127 /// we can check for duplicates and find local method declarations.
128 llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
129
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000130 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanian05672a02007-10-09 18:03:53 +0000131 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner4de884d2007-10-09 18:18:24 +0000132 /// find the declarations when needed.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000133 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff31102512008-04-02 18:30:49 +0000134
135 /// ObjCInterfaceDecls - Keep track of all class declarations declared
136 /// with @interface, so that we can emit errors on duplicates and
137 /// find the declarations when needed.
138 typedef llvm::DenseMap<const IdentifierInfo*,
139 ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
140 ObjCInterfaceDeclsTy ObjCInterfaceDecls;
141
Steve Naroffe8043c32008-04-01 23:04:06 +0000142 /// ObjCAliasDecls - Keep track of all class declarations declared
143 /// with @compatibility_alias, so that we can emit errors on duplicates and
144 /// find the declarations when needed. This construct is ancient and will
145 /// likely never be seen. Nevertheless, it is here for compatibility.
Steve Naroffc822ff42008-04-02 00:39:51 +0000146 typedef llvm::DenseMap<const IdentifierInfo*,
147 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroffe8043c32008-04-01 23:04:06 +0000148 ObjCAliasTy ObjCAliasDecls;
Steve Naroff31102512008-04-02 18:30:49 +0000149
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000150 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
151 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
152
Douglas Gregor63935192009-03-02 00:19:53 +0000153 /// \brief A mapping from external names to the most recent
154 /// locally-scoped external declaration with that name.
155 ///
156 /// This map contains external declarations introduced in local
157 /// scoped, e.g.,
158 ///
159 /// \code
160 /// void f() {
161 /// void foo(int, int);
162 /// }
163 /// \endcode
164 ///
165 /// Here, the name "foo" will be associated with the declaration on
166 /// "foo" within f. This name is not visible outside of
167 /// "f". However, we still find it in two cases:
168 ///
169 /// - If we are declaring another external with the name "foo", we
170 /// can find "foo" as a previous declaration, so that the types
171 /// of this external declaration can be checked for
172 /// compatibility.
173 ///
174 /// - If we would implicitly declare "foo" (e.g., due to a call to
175 /// "foo" in C when no prototype or definition is visible), then
176 /// we find this declaration of "foo" and complain that it is
177 /// not visible.
178 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
179
Chris Lattner7f925cc2008-04-11 07:00:53 +0000180 IdentifierResolver IdResolver;
181
Chris Lattner59907c42007-08-10 20:18:51 +0000182 // Enum values used by KnownFunctionIDs (see below).
183 enum {
Ted Kremenek7ff22b22008-06-16 18:00:42 +0000184 id_NSLog,
Douglas Gregor3c385e52009-02-14 18:57:46 +0000185 id_NSLogv,
Daniel Dunbarde454282008-10-02 18:44:07 +0000186 id_asprintf,
Chris Lattner59907c42007-08-10 20:18:51 +0000187 id_vasprintf,
Chris Lattner59907c42007-08-10 20:18:51 +0000188 id_num_known_functions
189 };
190
191 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
192 /// of known functions used by the semantic analysis to do various
193 /// kinds of checking (e.g. checking format string errors in printf calls).
194 /// This list is populated upon the creation of a Sema object.
Chris Lattner06f54852008-08-23 02:00:52 +0000195 IdentifierInfo* KnownFunctionIDs[id_num_known_functions];
Daniel Dunbar662e8b52008-08-14 22:04:54 +0000196
Steve Naroffe440eb82007-10-10 17:32:04 +0000197 /// Translation Unit Scope - useful to Objective-C actions that need
198 /// to lookup file scope declarations in the "ordinary" C decl namespace.
199 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroffb216c882007-10-09 22:01:59 +0000200 Scope *TUScope;
Sebastian Redlc42e1182008-11-11 11:37:55 +0000201
202 /// The C++ "std" namespace, where the standard library resides. Cached here
203 /// by GetStdNamespace
204 NamespaceDecl *StdNamespace;
Sebastian Redlb5a57a62008-12-03 20:26:15 +0000205
206 /// A flag to remember whether the implicit forms of operator new and delete
207 /// have been declared.
208 bool GlobalNewDeleteDeclared;
Steve Naroff3b950172007-10-10 21:53:07 +0000209
Steve Naroff58ff9e82007-10-14 00:58:41 +0000210 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000211 struct ObjCMethodList {
212 ObjCMethodDecl *Method;
213 ObjCMethodList *Next;
Steve Naroff58ff9e82007-10-14 00:58:41 +0000214
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000215 ObjCMethodList() {
Steve Naroff58ff9e82007-10-14 00:58:41 +0000216 Method = 0;
217 Next = 0;
218 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000219 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff58ff9e82007-10-14 00:58:41 +0000220 Method = M;
221 Next = C;
222 }
223 };
224 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
225 /// messages to "id". We need to maintain a list, since selectors can have
226 /// differing signatures across classes. In Cocoa, this happens to be
227 /// extremely uncommon (only 1% of selectors are "overloaded").
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000228 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
229 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Steve Naroff6b9dfd42009-03-04 15:11:40 +0000230
231 /// Private Helper predicate to check for 'self'.
232 bool isSelfExpr(Expr *RExpr);
Reid Spencer5f016e22007-07-11 17:01:13 +0000233public:
Chris Lattner2ae34ed2008-02-06 00:46:58 +0000234 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
Chris Lattner574aa402009-02-17 01:09:29 +0000235 ~Sema() {
236 if (PackContext) FreePackedContext();
237 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000238
Chris Lattner53ebff32009-01-22 19:21:44 +0000239 const LangOptions &getLangOptions() const { return LangOpts; }
Chris Lattner3cfa9282008-11-22 08:28:49 +0000240 Diagnostic &getDiagnostics() const { return Diags; }
241 SourceManager &getSourceManager() const { return SourceMgr; }
242
Chris Lattnerebf5ddf2008-11-18 21:53:24 +0000243 /// The primitive diagnostic helpers.
Chris Lattner3cfa9282008-11-22 08:28:49 +0000244 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
Douglas Gregoree1828a2009-03-10 18:03:33 +0000245 DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
Douglas Gregor27b152f2009-03-10 18:52:44 +0000246 if (!Diags.isBuiltinNote(DiagID) &&
247 !ActiveTemplateInstantiations.empty() &&
Douglas Gregordf667e72009-03-10 20:44:00 +0000248 ActiveTemplateInstantiations.back()
Douglas Gregor27b152f2009-03-10 18:52:44 +0000249 != LastTemplateInstantiationErrorContext)
Douglas Gregoree1828a2009-03-10 18:03:33 +0000250 DB << PostDiagnosticHook(PrintInstantiationStackHook, this);
251 return DB;
Chris Lattner3cfa9282008-11-22 08:28:49 +0000252 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000253
Chris Lattner394a3fd2007-08-31 04:53:24 +0000254 virtual void DeleteExpr(ExprTy *E);
255 virtual void DeleteStmt(StmtTy *S);
256
Sebastian Redl798d1192008-12-13 16:23:55 +0000257 OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); }
Sebastian Redl0eb23302009-01-19 00:08:26 +0000258 OwningExprResult Owned(ExprResult R) {
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000259 if (R.isInvalid())
Steve Naroff872b9ac2009-01-21 22:32:33 +0000260 return ExprError();
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000261 return OwningExprResult(*this, R.get());
Sebastian Redl0eb23302009-01-19 00:08:26 +0000262 }
Sebastian Redl798d1192008-12-13 16:23:55 +0000263 OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
264
Chris Lattner9299f3f2008-08-23 03:19:52 +0000265 virtual void ActOnEndOfTranslationUnit();
Sebastian Redlb8a6aca2009-01-19 22:31:54 +0000266
Reid Spencer5f016e22007-07-11 17:01:13 +0000267 //===--------------------------------------------------------------------===//
268 // Type Analysis / Processing: SemaType.cpp.
269 //
Chris Lattnerfca0ddd2008-06-26 06:27:57 +0000270 QualType ConvertDeclSpecToType(const DeclSpec &DS);
Chris Lattnerc9b346d2008-06-29 00:50:08 +0000271 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Douglas Gregorcd281c32009-02-28 00:25:32 +0000272 QualType BuildPointerType(QualType T, unsigned Quals,
273 SourceLocation Loc, DeclarationName Entity);
274 QualType BuildReferenceType(QualType T, unsigned Quals,
275 SourceLocation Loc, DeclarationName Entity);
276 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
277 Expr *ArraySize, unsigned Quals,
278 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor724651c2009-02-28 01:04:19 +0000279 QualType BuildFunctionType(QualType T,
280 QualType *ParamTypes, unsigned NumParamTypes,
281 bool Variadic, unsigned Quals,
282 SourceLocation Loc, DeclarationName Entity);
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000283 QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0);
Douglas Gregor10bd3682008-11-17 22:58:34 +0000284 DeclarationName GetNameForDeclarator(Declarator &D);
285
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000286 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahanian306d68f2007-11-08 23:49:49 +0000287
Douglas Gregor57373262008-10-22 14:17:15 +0000288 bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
289
Sebastian Redlcee63fb2008-12-02 14:43:59 +0000290 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Sebastian Redl37d6de32008-11-08 13:00:26 +0000291
Douglas Gregor86447ec2009-03-09 16:13:40 +0000292 bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned diag,
Douglas Gregor4ec339f2009-01-19 19:26:10 +0000293 SourceRange Range1 = SourceRange(),
294 SourceRange Range2 = SourceRange(),
295 QualType PrintType = QualType());
296
Reid Spencer5f016e22007-07-11 17:01:13 +0000297 //===--------------------------------------------------------------------===//
298 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
299 //
Chris Lattner21ff9c92009-03-05 01:25:28 +0000300
301 /// getDeclName - Return a pretty name for the specified decl if possible, or
302 /// an empty string if not. This is used for pretty crash reporting.
303 virtual std::string getDeclName(DeclTy *D);
304
Douglas Gregor1a51b4a2009-02-09 15:09:02 +0000305 virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Douglas Gregorb696ea32009-02-04 17:00:24 +0000306 Scope *S, const CXXScopeSpec *SS);
Chris Lattner76a642f2009-02-15 22:43:40 +0000307 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){
Douglas Gregor584049d2008-12-15 23:53:10 +0000308 return ActOnDeclarator(S, D, LastInGroup, false);
309 }
310 DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
311 bool IsFunctionDefinition);
Douglas Gregor63935192009-03-02 00:19:53 +0000312 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl,
313 Scope *S);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000314 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
315 QualType R, Decl* LastDeclarator,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000316 Decl* PrevDecl, bool& InvalidDecl,
317 bool &Redeclaration);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000318 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000319 QualType R, Decl* LastDeclarator,
Douglas Gregor8f301052009-02-24 19:23:27 +0000320 NamedDecl* PrevDecl, bool& InvalidDecl,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000321 bool &Redeclaration);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000322 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
323 QualType R, Decl *LastDeclarator,
Douglas Gregor04495c82009-02-24 01:23:02 +0000324 NamedDecl* PrevDecl,
325 bool IsFunctionDefinition,
Douglas Gregorcda9c672009-02-16 17:45:42 +0000326 bool& InvalidDecl, bool &Redeclaration);
Chris Lattner04421082008-04-08 04:40:51 +0000327 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
328 virtual void ActOnParamDefaultArgument(DeclTy *param,
329 SourceLocation EqualLoc,
330 ExprTy *defarg);
Douglas Gregor61366e92008-12-24 00:01:03 +0000331 virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
332 SourceLocation EqualLoc);
Douglas Gregor72b505b2008-12-16 21:30:33 +0000333 virtual void ActOnParamDefaultArgumentError(DeclTy *param);
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000334 virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
335 void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit);
Douglas Gregor27c8dc02008-10-29 00:13:59 +0000336 void ActOnUninitializedDecl(DeclTy *dcl);
Reid Spencer5f016e22007-07-11 17:01:13 +0000337 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
338
Douglas Gregorbe109b32009-01-23 16:23:13 +0000339 virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D);
Chris Lattnerb652cea2007-10-09 17:14:05 +0000340 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000341 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Steve Naroffebf64432009-02-28 16:59:13 +0000342 virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D);
Sebastian Redlb8a6aca2009-01-19 22:31:54 +0000343
Sebastian Redl798d1192008-12-13 16:23:55 +0000344 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
Sebastian Redl798d1192008-12-13 16:23:55 +0000345 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000346
Steve Naroffb216c882007-10-09 22:01:59 +0000347 /// Scope actions.
348 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
349 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000350
351 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
352 /// no declarator (e.g. "struct foo;") is parsed.
Sebastian Redla4ed0d82008-12-28 15:28:59 +0000353 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Reid Spencer5f016e22007-07-11 17:01:13 +0000354
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000355 bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
356 RecordDecl *AnonRecord);
357 virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
358 RecordDecl *Record);
359
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000360 virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000361 SourceLocation KWLoc, const CXXScopeSpec &SS,
362 IdentifierInfo *Name, SourceLocation NameLoc,
Douglas Gregorddc29e12009-02-06 22:42:48 +0000363 AttributeList *Attr);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000364
Douglas Gregor44b43212008-12-11 16:49:14 +0000365 virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner06f54852008-08-23 02:00:52 +0000366 IdentifierInfo *ClassName,
367 llvm::SmallVectorImpl<DeclTy*> &Decls);
Douglas Gregor44b43212008-12-11 16:49:14 +0000368 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Reid Spencer5f016e22007-07-11 17:01:13 +0000369 Declarator &D, ExprTy *BitfieldWidth);
Chris Lattner24793662009-03-05 22:45:59 +0000370
371 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
372 Declarator &D, Expr *BitfieldWidth);
373
Fariborz Jahanian1d78cc42008-04-10 23:32:45 +0000374
375 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
376 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian45bc03f2008-04-11 16:55:42 +0000377 tok::ObjCKeywordKind visibility);
Fariborz Jahanian1d78cc42008-04-10 23:32:45 +0000378
Steve Narofff13271f2007-09-14 23:09:53 +0000379 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian9d048ff2007-09-29 00:54:24 +0000380 virtual void ActOnFields(Scope* S,
Steve Naroff60fccee2007-10-29 21:38:07 +0000381 SourceLocation RecLoc, DeclTy *TagDecl,
382 DeclTy **Fields, unsigned NumFields,
Daniel Dunbar1bfe1c22008-10-03 02:03:53 +0000383 SourceLocation LBrac, SourceLocation RBrac,
384 AttributeList *AttrList);
Douglas Gregor72de6672009-01-08 20:45:30 +0000385
386 /// ActOnTagStartDefinition - Invoked when we have entered the
387 /// scope of a tag's definition (e.g., for an enumeration, class,
388 /// struct, or union).
389 virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl);
390
391 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
392 /// the definition of a tag (enumeration, class, struct, or union).
393 virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl);
394
Steve Naroff08d92e42007-09-15 18:49:24 +0000395 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Reid Spencer5f016e22007-07-11 17:01:13 +0000396 DeclTy *LastEnumConstant,
397 SourceLocation IdLoc, IdentifierInfo *Id,
398 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff08d92e42007-09-15 18:49:24 +0000399 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Reid Spencer5f016e22007-07-11 17:01:13 +0000400 DeclTy **Elements, unsigned NumElements);
Sebastian Redl37d6de32008-11-08 13:00:26 +0000401
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +0000402 DeclContext *getContainingDC(DeclContext *DC);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000403
Chris Lattner0ed844b2008-04-04 06:12:32 +0000404 /// Set the current declaration context until it gets popped.
Douglas Gregor44b43212008-12-11 16:49:14 +0000405 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattnerb048c982008-04-06 04:47:34 +0000406 void PopDeclContext();
Argyrios Kyrtzidis53d0ea52008-06-28 06:07:14 +0000407
Chris Lattner371f2582008-12-04 23:50:19 +0000408 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
409 /// to the function decl for the function being parsed. If we're currently
410 /// in a 'block', this returns the containing context.
411 FunctionDecl *getCurFunctionDecl();
412
413 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
414 /// the method decl for the method being parsed. If we're currently
415 /// in a 'block', this returns the containing context.
Daniel Dunbarc4a1dea2008-08-11 05:35:13 +0000416 ObjCMethodDecl *getCurMethodDecl();
Chris Lattner0ed844b2008-04-04 06:12:32 +0000417
Chris Lattner371f2582008-12-04 23:50:19 +0000418 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
419 /// or C function we're in, otherwise return null. If we're currently
420 /// in a 'block', this returns the containing context.
421 NamedDecl *getCurFunctionOrMethodDecl();
422
Argyrios Kyrtzidis87f3ff02008-04-12 00:47:19 +0000423 /// Add this decl to the scope shadowed decl chains.
424 void PushOnScopeChains(NamedDecl *D, Scope *S);
425
Argyrios Kyrtzidis15a12d02008-09-09 21:18:04 +0000426 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
427 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
428 /// true if 'D' belongs to the given declaration context.
429 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
Douglas Gregor44b43212008-12-11 16:49:14 +0000430 return IdResolver.isDeclInScope(D, Ctx, Context, S);
Argyrios Kyrtzidis15a12d02008-09-09 21:18:04 +0000431 }
432
Eli Friedman8f17b662009-02-28 05:41:13 +0000433
434 void RecursiveCalcJumpScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
435 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
436 llvm::DenseMap<Stmt*, void*>& GotoScopeMap,
437 std::vector<void*>& ScopeStack,
438 Stmt* CurStmt);
439
440 void RecursiveCalcLabelScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
441 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
442 std::vector<void*>& ScopeStack,
443 Stmt* CurStmt,
444 Stmt* ParentCompoundStmt);
445
Chris Lattnerf1d705c2008-02-21 01:07:18 +0000446 /// Subroutines of ActOnDeclarator().
Chris Lattner41af0932007-11-14 06:34:38 +0000447 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000448 Decl *LastDecl);
Douglas Gregorcda9c672009-02-16 17:45:42 +0000449 bool MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
450 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
Douglas Gregor04495c82009-02-24 01:23:02 +0000451 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregorcda9c672009-02-16 17:45:42 +0000452 bool MergeVarDecl(VarDecl *New, Decl *Old);
453 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Steve Naroffff9eb1f2008-08-08 17:50:35 +0000454 void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000455
456 /// C++ Overloading.
457 bool IsOverload(FunctionDecl *New, Decl* OldD,
458 OverloadedFunctionDecl::function_iterator &MatchedDecl);
Douglas Gregor225c41e2008-11-03 19:09:14 +0000459 ImplicitConversionSequence
460 TryImplicitConversion(Expr* From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000461 bool SuppressUserConversions = false,
462 bool AllowExplicit = false);
Douglas Gregor60d62c22008-10-31 16:23:19 +0000463 bool IsStandardConversion(Expr *From, QualType ToType,
464 StandardConversionSequence& SCS);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000465 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
466 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
Douglas Gregor5cdf8212009-02-12 00:15:05 +0000467 bool IsComplexPromotion(QualType FromType, QualType ToType);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000468 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregor45920e82008-12-19 17:40:08 +0000469 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregorc7887512008-12-19 19:13:09 +0000470 bool isObjCPointerConversion(QualType FromType, QualType ToType,
471 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregor94b1dd22008-10-24 04:54:22 +0000472 bool CheckPointerConversion(Expr *From, QualType ToType);
Sebastian Redl4433aaf2009-01-25 19:43:20 +0000473 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
474 QualType &ConvertedType);
475 bool CheckMemberPointerConversion(Expr *From, QualType ToType);
Douglas Gregor98cd5992008-10-21 23:43:52 +0000476 bool IsQualificationConversion(QualType FromType, QualType ToType);
Douglas Gregor60d62c22008-10-31 16:23:19 +0000477 bool IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000478 UserDefinedConversionSequence& User,
Douglas Gregor734d9862009-01-30 23:27:23 +0000479 bool AllowConversionFunctions,
480 bool AllowExplicit);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000481
482 ImplicitConversionSequence::CompareKind
483 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
484 const ImplicitConversionSequence& ICS2);
485
486 ImplicitConversionSequence::CompareKind
487 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
488 const StandardConversionSequence& SCS2);
489
Douglas Gregor57373262008-10-22 14:17:15 +0000490 ImplicitConversionSequence::CompareKind
491 CompareQualificationConversions(const StandardConversionSequence& SCS1,
492 const StandardConversionSequence& SCS2);
493
Douglas Gregorbc0805a2008-10-23 00:40:37 +0000494 ImplicitConversionSequence::CompareKind
495 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
496 const StandardConversionSequence& SCS2);
497
Douglas Gregor225c41e2008-11-03 19:09:14 +0000498 ImplicitConversionSequence
499 TryCopyInitialization(Expr* From, QualType ToType,
500 bool SuppressUserConversions = false);
Douglas Gregor27c8dc02008-10-29 00:13:59 +0000501 bool PerformCopyInitialization(Expr *&From, QualType ToType,
502 const char *Flavor);
503
Douglas Gregor96176b32008-11-18 23:14:02 +0000504 ImplicitConversionSequence
505 TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method);
506 bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method);
507
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000508 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
509 bool PerformContextuallyConvertToBool(Expr *&From);
510
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000511 /// OverloadingResult - Capture the result of performing overload
512 /// resolution.
513 enum OverloadingResult {
514 OR_Success, ///< Overload resolution succeeded.
515 OR_No_Viable_Function, ///< No viable function found.
Douglas Gregor48f3bb92009-02-18 21:56:37 +0000516 OR_Ambiguous, ///< Ambiguous candidates found.
517 OR_Deleted ///< Overload resoltuion refers to a deleted function.
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000518 };
519
520 void AddOverloadCandidate(FunctionDecl *Function,
521 Expr **Args, unsigned NumArgs,
Douglas Gregor225c41e2008-11-03 19:09:14 +0000522 OverloadCandidateSet& CandidateSet,
523 bool SuppressUserConversions = false);
Douglas Gregor96176b32008-11-18 23:14:02 +0000524 void AddMethodCandidate(CXXMethodDecl *Method,
525 Expr *Object, Expr **Args, unsigned NumArgs,
526 OverloadCandidateSet& CandidateSet,
Douglas Gregor88a35142008-12-22 05:46:06 +0000527 bool SuppressUserConversions = false);
Douglas Gregorf1991ea2008-11-07 22:36:19 +0000528 void AddConversionCandidate(CXXConversionDecl *Conversion,
529 Expr *From, QualType ToType,
530 OverloadCandidateSet& CandidateSet);
Douglas Gregor106c6eb2008-11-19 22:57:39 +0000531 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
Douglas Gregor72564e72009-02-26 23:50:07 +0000532 const FunctionProtoType *Proto,
Douglas Gregor106c6eb2008-11-19 22:57:39 +0000533 Expr *Object, Expr **Args, unsigned NumArgs,
534 OverloadCandidateSet& CandidateSet);
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000535 bool AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
536 SourceLocation OpLoc,
Douglas Gregor96176b32008-11-18 23:14:02 +0000537 Expr **Args, unsigned NumArgs,
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000538 OverloadCandidateSet& CandidateSet,
539 SourceRange OpRange = SourceRange());
Douglas Gregoreb8f3062008-11-12 17:17:38 +0000540 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
541 Expr **Args, unsigned NumArgs,
Douglas Gregor88b4bf22009-01-13 00:52:54 +0000542 OverloadCandidateSet& CandidateSet,
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000543 bool IsAssignmentOperator = false,
544 unsigned NumContextualBoolArguments = 0);
Douglas Gregor74253732008-11-19 15:42:04 +0000545 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
546 Expr **Args, unsigned NumArgs,
547 OverloadCandidateSet& CandidateSet);
Douglas Gregorfa047642009-02-04 00:32:51 +0000548 void AddArgumentDependentLookupCandidates(DeclarationName Name,
549 Expr **Args, unsigned NumArgs,
550 OverloadCandidateSet& CandidateSet);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000551 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
552 const OverloadCandidate& Cand2);
553 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
554 OverloadCandidateSet::iterator& Best);
555 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
556 bool OnlyViable);
557
Douglas Gregor904eed32008-11-10 20:40:00 +0000558 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
559 bool Complain);
560 void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
561
Douglas Gregor17330012009-02-04 15:01:18 +0000562 FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee,
563 DeclarationName UnqualifiedName,
Douglas Gregor0a396682008-11-26 06:01:48 +0000564 SourceLocation LParenLoc,
565 Expr **Args, unsigned NumArgs,
566 SourceLocation *CommaLocs,
Douglas Gregorfa047642009-02-04 00:32:51 +0000567 SourceLocation RParenLoc,
Douglas Gregor17330012009-02-04 15:01:18 +0000568 bool &ArgumentDependentLookup);
Douglas Gregor88a35142008-12-22 05:46:06 +0000569 ExprResult
570 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
571 SourceLocation LParenLoc, Expr **Args,
572 unsigned NumArgs, SourceLocation *CommaLocs,
573 SourceLocation RParenLoc);
Douglas Gregorf9eb9052008-11-19 21:05:33 +0000574 ExprResult
Douglas Gregor5c37de72008-12-06 00:22:45 +0000575 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregorf9eb9052008-11-19 21:05:33 +0000576 Expr **Args, unsigned NumArgs,
577 SourceLocation *CommaLocs,
578 SourceLocation RParenLoc);
Douglas Gregor8e9bebd2008-10-21 16:13:35 +0000579
Douglas Gregor3fc749d2008-12-23 00:26:44 +0000580 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
Douglas Gregor8ba10742008-11-20 16:27:02 +0000581 SourceLocation MemberLoc,
582 IdentifierInfo &Member);
Douglas Gregor09f41cf2009-01-14 15:45:31 +0000583
Chris Lattner823c44e2009-01-06 07:27:21 +0000584 /// Helpers for dealing with function parameters.
Chris Lattner04421082008-04-08 04:40:51 +0000585 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattner04421082008-04-08 04:40:51 +0000586 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregor6d6eb572008-05-07 04:49:29 +0000587 void CheckExtraCXXDefaultArguments(Declarator &D);
Reid Spencer5f016e22007-07-11 17:01:13 +0000588
Douglas Gregor1a0d31a2009-01-12 18:45:55 +0000589 Scope *getNonFieldDeclScope(Scope *S);
590
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000591 /// \name Name lookup
592 ///
593 /// These routines provide name lookup that is used during semantic
594 /// analysis to resolve the various kinds of names (identifiers,
595 /// overloaded operator names, constructor names, etc.) into zero or
596 /// more declarations within a particular scope. The major entry
597 /// points are LookupName, which performs unqualified name lookup,
598 /// and LookupQualifiedName, which performs qualified name lookup.
599 ///
600 /// All name lookup is performed based on some specific criteria,
601 /// which specify what names will be visible to name lookup and how
602 /// far name lookup should work. These criteria are important both
603 /// for capturing language semantics (certain lookups will ignore
604 /// certain names, for example) and for performance, since name
605 /// lookup is often a bottleneck in the compilation of C++. Name
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000606 /// lookup criteria is specified via the LookupCriteria enumeration.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000607 ///
608 /// The results of name lookup can vary based on the kind of name
609 /// lookup performed, the current language, and the translation
610 /// unit. In C, for example, name lookup will either return nothing
611 /// (no entity found) or a single declaration. In C++, name lookup
612 /// can additionally refer to a set of overloaded functions or
613 /// result in an ambiguity. All of the possible results of name
614 /// lookup are captured by the LookupResult class, which provides
615 /// the ability to distinguish among them.
616 //@{
Douglas Gregorf780abc2008-12-30 03:27:21 +0000617
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000618 /// @brief Describes the kind of name lookup to perform.
619 enum LookupNameKind {
620 /// Ordinary name lookup, which finds ordinary names (functions,
621 /// variables, typedefs, etc.) in C and most kinds of names
622 /// (functions, variables, members, types, etc.) in C++.
623 LookupOrdinaryName = 0,
624 /// Tag name lookup, which finds the names of enums, classes,
625 /// structs, and unions.
626 LookupTagName,
627 /// Member name lookup, which finds the names of
628 /// class/struct/union members.
629 LookupMemberName,
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000630 // Look up of an operator name (e.g., operator+) for use with
631 // operator overloading. This lookup is similar to ordinary name
632 // lookup, but will ignore any declarations that are class
633 // members.
634 LookupOperatorName,
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000635 /// Look up of a name that precedes the '::' scope resolution
636 /// operator in C++. This lookup completely ignores operator,
637 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
638 LookupNestedNameSpecifierName,
639 /// Look up a namespace name within a C++ using directive or
640 /// namespace alias definition, ignoring non-namespace names (C++
641 /// [basic.lookup.udir]p1).
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000642 LookupNamespaceName,
643 // Look up an ordinary name that is going to be redeclared as a
644 // name with linkage. This lookup ignores any declarations that
645 // are outside of the current scope unless they have linkage. See
646 // C99 6.2.2p4-5 and C++ [basic.link]p6.
647 LookupRedeclarationWithLinkage
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000648 };
649
650 /// @brief Represents the results of name lookup.
651 ///
652 /// An instance of the LookupResult class captures the results of a
653 /// single name lookup, which can return no result (nothing found),
654 /// a single declaration, a set of overloaded functions, or an
655 /// ambiguity. Use the getKind() method to determine which of these
656 /// results occurred for a given lookup.
657 ///
658 /// Any non-ambiguous lookup can be converted into a single
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000659 /// (possibly NULL) @c NamedDecl* via a conversion function or the
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000660 /// getAsDecl() method. This conversion permits the common-case
661 /// usage in C and Objective-C where name lookup will always return
662 /// a single declaration.
Douglas Gregor69d993a2009-01-17 01:13:24 +0000663 struct LookupResult {
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000664 /// The kind of entity that is actually stored within the
665 /// LookupResult object.
Douglas Gregor69d993a2009-01-17 01:13:24 +0000666 enum {
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000667 /// First is a single declaration (a NamedDecl*), which may be NULL.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000668 SingleDecl,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000669
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000670 /// First is a single declaration (an OverloadedFunctionDecl*).
671 OverloadedDeclSingleDecl,
672
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000673 /// [First, Last) is an iterator range represented as opaque
674 /// pointers used to reconstruct IdentifierResolver::iterators.
675 OverloadedDeclFromIdResolver,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000676
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000677 /// [First, Last) is an iterator range represented as opaque
678 /// pointers used to reconstruct DeclContext::lookup_iterators.
679 OverloadedDeclFromDeclContext,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000680
681 /// First is a pointer to a BasePaths structure, which is owned
682 /// by the LookupResult. Last is non-zero to indicate that the
683 /// ambiguity is caused by two names found in base class
684 /// subobjects of different types.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000685 AmbiguousLookupStoresBasePaths,
686
687 /// [First, Last) is an iterator range represented as opaque
688 /// pointers used to reconstruct new'ed Decl*[] array containing
689 /// found ambiguous decls. LookupResult is owner of this array.
690 AmbiguousLookupStoresDecls
691
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000692 } StoredKind;
693
694 /// The first lookup result, whose contents depend on the kind of
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000695 /// lookup result. This may be a NamedDecl* (if StoredKind ==
696 /// SingleDecl), OverloadedFunctionDecl* (if StoredKind ==
697 /// OverloadedDeclSingleDecl), the opaque pointer from an
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000698 /// IdentifierResolver::iterator (if StoredKind ==
Douglas Gregor7176fff2009-01-15 00:26:24 +0000699 /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator
700 /// (if StoredKind == OverloadedDeclFromDeclContext), or a
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000701 /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000702 mutable uintptr_t First;
703
704 /// The last lookup result, whose contents depend on the kind of
705 /// lookup result. This may be unused (if StoredKind ==
Douglas Gregor7176fff2009-01-15 00:26:24 +0000706 /// SingleDecl), it may have the same type as First (for
707 /// overloaded function declarations), or is may be used as a
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000708 /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000709 mutable uintptr_t Last;
710
711 /// Context - The context in which we will build any
712 /// OverloadedFunctionDecl nodes needed by the conversion to
713 /// Decl*.
714 ASTContext *Context;
715
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000716 /// @brief The kind of entity found by name lookup.
717 enum LookupKind {
718 /// @brief No entity found met the criteria.
719 NotFound = 0,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000720
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000721 /// @brief Name lookup found a single declaration that met the
Douglas Gregor7176fff2009-01-15 00:26:24 +0000722 /// criteria. getAsDecl will return this declaration.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000723 Found,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000724
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000725 /// @brief Name lookup found a set of overloaded functions that
Douglas Gregor7176fff2009-01-15 00:26:24 +0000726 /// met the criteria. getAsDecl will turn this set of overloaded
727 /// functions into an OverloadedFunctionDecl.
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000728 FoundOverloaded,
Douglas Gregor7176fff2009-01-15 00:26:24 +0000729
730 /// Name lookup results in an ambiguity because multiple
731 /// entities that meet the lookup criteria were found in
732 /// subobjects of different types. For example:
733 /// @code
734 /// struct A { void f(int); }
735 /// struct B { void f(double); }
736 /// struct C : A, B { };
737 /// void test(C c) {
738 /// c.f(0); // error: A::f and B::f come from subobjects of different
739 /// // types. overload resolution is not performed.
740 /// }
741 /// @endcode
742 AmbiguousBaseSubobjectTypes,
743
744 /// Name lookup results in an ambiguity because multiple
745 /// nonstatic entities that meet the lookup criteria were found
746 /// in different subobjects of the same type. For example:
747 /// @code
748 /// struct A { int x; };
749 /// struct B : A { };
750 /// struct C : A { };
751 /// struct D : B, C { };
752 /// int test(D d) {
753 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
754 /// }
755 /// @endcode
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000756 AmbiguousBaseSubobjects,
757
758 /// Name lookup results in an ambiguity because multiple definitions
759 /// of entity that meet the lookup criteria were found in different
760 /// declaration contexts.
761 /// @code
762 /// namespace A {
763 /// int i;
764 /// namespace B { int i; }
765 /// int test() {
766 /// using namespace B;
767 /// return i; // error 'i' is found in namespace A and A::B
768 /// }
769 /// }
770 /// @endcode
771 AmbiguousReference
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000772 };
773
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000774 static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D);
Douglas Gregor4bb64e72009-01-15 02:19:31 +0000775
Douglas Gregor69d993a2009-01-17 01:13:24 +0000776 static LookupResult CreateLookupResult(ASTContext &Context,
777 IdentifierResolver::iterator F,
778 IdentifierResolver::iterator L);
Douglas Gregor7176fff2009-01-15 00:26:24 +0000779
Douglas Gregor69d993a2009-01-17 01:13:24 +0000780 static LookupResult CreateLookupResult(ASTContext &Context,
781 DeclContext::lookup_iterator F,
782 DeclContext::lookup_iterator L);
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000783
Douglas Gregor69d993a2009-01-17 01:13:24 +0000784 static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths,
785 bool DifferentSubobjectTypes) {
786 LookupResult Result;
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000787 Result.StoredKind = AmbiguousLookupStoresBasePaths;
Douglas Gregor69d993a2009-01-17 01:13:24 +0000788 Result.First = reinterpret_cast<uintptr_t>(Paths);
789 Result.Last = DifferentSubobjectTypes? 1 : 0;
790 Result.Context = &Context;
791 return Result;
792 }
Douglas Gregor4bb64e72009-01-15 02:19:31 +0000793
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000794 template <typename Iterator>
795 static LookupResult CreateLookupResult(ASTContext &Context,
796 Iterator B, std::size_t Len) {
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000797 NamedDecl ** Array = new NamedDecl*[Len];
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000798 for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B)
799 Array[Idx] = *B;
800 LookupResult Result;
801 Result.StoredKind = AmbiguousLookupStoresDecls;
802 Result.First = reinterpret_cast<uintptr_t>(Array);
803 Result.Last = reinterpret_cast<uintptr_t>(Array + Len);
804 Result.Context = &Context;
805 return Result;
806 }
807
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000808 LookupKind getKind() const;
809
810 /// @brief Determine whether name look found something.
811 operator bool() const { return getKind() != NotFound; }
812
Douglas Gregor7176fff2009-01-15 00:26:24 +0000813 /// @brief Determines whether the lookup resulted in an ambiguity.
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000814 bool isAmbiguous() const {
815 return StoredKind == AmbiguousLookupStoresBasePaths ||
816 StoredKind == AmbiguousLookupStoresDecls;
817 }
Douglas Gregor7176fff2009-01-15 00:26:24 +0000818
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000819 /// @brief Allows conversion of a lookup result into a
820 /// declaration, with the same behavior as getAsDecl.
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000821 operator NamedDecl*() const { return getAsDecl(); }
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000822
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000823 NamedDecl* getAsDecl() const;
Douglas Gregor7176fff2009-01-15 00:26:24 +0000824
825 BasePaths *getBasePaths() const;
Douglas Gregord8635172009-02-02 21:35:47 +0000826
827 /// \brief Iterate over the results of name lookup.
828 ///
829 /// The @c iterator class provides iteration over the results of a
830 /// non-ambiguous name lookup.
831 class iterator {
832 /// The LookupResult structure we're iterating through.
833 LookupResult *Result;
834
835 /// The current position of this iterator within the sequence of
836 /// results. This value will have the same representation as the
837 /// @c First field in the LookupResult structure.
838 mutable uintptr_t Current;
839
840 public:
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000841 typedef NamedDecl * value_type;
842 typedef NamedDecl * reference;
843 typedef NamedDecl * pointer;
Douglas Gregord8635172009-02-02 21:35:47 +0000844 typedef std::ptrdiff_t difference_type;
845 typedef std::forward_iterator_tag iterator_category;
846
847 iterator() : Result(0), Current(0) { }
848
849 iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { }
850
851 reference operator*() const;
852
853 pointer operator->() const { return **this; }
854
855 iterator &operator++();
856
857 iterator operator++(int) {
858 iterator tmp(*this);
859 ++(*this);
860 return tmp;
861 }
862
863 friend inline bool operator==(iterator const& x, iterator const& y) {
864 return x.Current == y.Current;
865 }
866
867 friend inline bool operator!=(iterator const& x, iterator const& y) {
868 return x.Current != y.Current;
869 }
870 };
871 friend class iterator;
872
873 iterator begin();
874 iterator end();
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000875 };
876
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000877private:
878 typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy;
879
880 std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name,
881 LookupNameKind NameKind,
882 bool RedeclarationOnly);
883
884public:
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000885 /// Determines whether D is a suitable lookup result according to the
886 /// lookup criteria.
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000887 static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind,
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000888 unsigned IDNS) {
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000889 switch (NameKind) {
890 case Sema::LookupOrdinaryName:
891 case Sema::LookupTagName:
892 case Sema::LookupMemberName:
Douglas Gregord6f7e9d2009-02-24 20:03:32 +0000893 case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000894 return D->isInIdentifierNamespace(IDNS);
895
Douglas Gregorf680a0f2009-02-04 16:44:47 +0000896 case Sema::LookupOperatorName:
897 return D->isInIdentifierNamespace(IDNS) &&
898 !D->getDeclContext()->isRecord();
899
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000900 case Sema::LookupNestedNameSpecifierName:
901 return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag);
902
903 case Sema::LookupNamespaceName:
904 return isa<NamespaceDecl>(D);
905 }
906
907 assert(false &&
Douglas Gregor7dda67d2009-02-05 19:25:20 +0000908 "isAcceptableLookupResult always returns before this point");
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000909 return false;
910 }
Douglas Gregor7176fff2009-01-15 00:26:24 +0000911
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000912 LookupResult LookupName(Scope *S, DeclarationName Name,
913 LookupNameKind NameKind,
Douglas Gregor3e41d602009-02-13 23:20:09 +0000914 bool RedeclarationOnly = false,
915 bool AllowBuiltinCreation = true,
916 SourceLocation Loc = SourceLocation());
Douglas Gregor4c921ae2009-01-30 01:04:22 +0000917 LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name,
918 LookupNameKind NameKind,
919 bool RedeclarationOnly = false);
920 LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS,
921 DeclarationName Name,
922 LookupNameKind NameKind,
Douglas Gregor3e41d602009-02-13 23:20:09 +0000923 bool RedeclarationOnly = false,
924 bool AllowBuiltinCreation = true,
925 SourceLocation Loc = SourceLocation());
Douglas Gregorfa047642009-02-04 00:32:51 +0000926
927 typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet;
928 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
929
930 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
931 AssociatedNamespaceSet &AssociatedNamespaces,
932 AssociatedClassSet &AssociatedClasses);
933
Douglas Gregor7176fff2009-01-15 00:26:24 +0000934 bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
935 SourceLocation NameLoc,
936 SourceRange LookupRange = SourceRange());
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000937 //@}
938
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000939 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000940 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Douglas Gregor3e41d602009-02-13 23:20:09 +0000941 Scope *S, bool ForRedeclaration,
942 SourceLocation Loc);
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000943 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
944 Scope *S);
Douglas Gregor3c385e52009-02-14 18:57:46 +0000945 void AddKnownFunctionAttributes(FunctionDecl *FD);
Douglas Gregoreb11cd02009-01-14 22:20:51 +0000946
947 // More parsing and symbol table subroutines.
948
Reid Spencer5f016e22007-07-11 17:01:13 +0000949 // Decl attributes - this routine is the top level dispatcher.
Chris Lattnere5c5ee12008-06-29 00:16:31 +0000950 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnerf2e4bd52008-06-28 23:58:55 +0000951 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lambebb97e92008-02-04 02:31:56 +0000952
Steve Naroff3c2eb662008-02-10 21:38:56 +0000953 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
954 bool &IncompleteImpl);
Fariborz Jahanian8daab972008-12-05 18:18:52 +0000955 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
956 ObjCMethodDecl *IntfMethod);
Sebastian Redlc42e1182008-11-11 11:37:55 +0000957
958 NamespaceDecl *GetStdNamespace();
Fariborz Jahaniand1fa6442009-01-12 19:55:42 +0000959
960 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
Steve Naroff22dc0b02009-02-26 19:11:32 +0000961 ObjCInterfaceDecl *IDecl);
Steve Naroff3c2eb662008-02-10 21:38:56 +0000962
Chris Lattner823c44e2009-01-06 07:27:21 +0000963 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000964 /// methods declared in protocol, and those referenced by it.
965 /// \param IDecl - Used for checking for methods which may have been
966 /// inherited.
Steve Naroffefe7f362008-02-08 22:06:17 +0000967 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
968 ObjCProtocolDecl *PDecl,
Fariborz Jahanianca3adf72007-10-02 20:06:01 +0000969 bool& IncompleteImpl,
Steve Naroffeefc4182007-10-08 21:05:34 +0000970 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000971 const llvm::DenseSet<Selector> &ClsMap,
972 ObjCInterfaceDecl *IDecl);
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000973
Steve Naroffa5997c42007-10-02 21:43:37 +0000974 /// CheckImplementationIvars - This routine checks if the instance variables
975 /// listed in the implelementation match those listed in the interface.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000976 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
977 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff3c2eb662008-02-10 21:38:56 +0000978 SourceLocation Loc);
Steve Naroffa5997c42007-10-02 21:43:37 +0000979
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000980 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
Chris Lattnercddc8882009-03-01 00:56:52 +0000981 /// remains unimplemented in the class or category @implementation.
982 void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl,
983 ObjCContainerDecl* IDecl,
984 bool IncompleteImpl = false);
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000985
Fariborz Jahanian85ff2642007-10-05 18:00:57 +0000986 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
987 /// true, or false, accordingly.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000988 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Narofffe6b0dc2008-10-21 10:37:50 +0000989 const ObjCMethodDecl *PrevMethod,
990 bool matchBasedOnSizeAndAlignment = false);
Steve Naroff3b950172007-10-10 21:53:07 +0000991
Steve Naroff58ff9e82007-10-14 00:58:41 +0000992 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
993 /// unit are added to a global pool. This allows us to efficiently associate
994 /// a selector with a method declaraation for purposes of typechecking
995 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000996 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff58ff9e82007-10-14 00:58:41 +0000997
Steve Naroff037cda52008-09-30 14:38:43 +0000998 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
999 /// there are multiple signatures.
1000 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
1001
Steve Naroff58ff9e82007-10-14 00:58:41 +00001002 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001003 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Reid Spencer5f016e22007-07-11 17:01:13 +00001004 //===--------------------------------------------------------------------===//
1005 // Statement Parsing Callbacks: SemaStmt.cpp.
1006public:
Sebastian Redla60528c2008-12-21 12:04:03 +00001007 virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
1008
1009 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
1010 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1011 MultiStmtArg Elts,
1012 bool isStmtExpr);
1013 virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
1014 SourceLocation EndLoc);
Sebastian Redl117054a2008-12-28 16:13:43 +00001015 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
1016 SourceLocation DotDotDotLoc, ExprArg RHSVal,
Chris Lattner24e1e702009-03-04 04:23:07 +00001017 SourceLocation ColonLoc);
1018 virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt);
1019
Sebastian Redl117054a2008-12-28 16:13:43 +00001020 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1021 SourceLocation ColonLoc,
1022 StmtArg SubStmt, Scope *CurScope);
Sebastian Redlde307472009-01-11 00:38:46 +00001023 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
1024 IdentifierInfo *II,
1025 SourceLocation ColonLoc,
1026 StmtArg SubStmt);
1027 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
1028 StmtArg ThenVal, SourceLocation ElseLoc,
1029 StmtArg ElseVal);
1030 virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
1031 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1032 StmtArg Switch, StmtArg Body);
Sebastian Redlf05b1522009-01-16 23:28:06 +00001033 virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
1034 StmtArg Body);
1035 virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
1036 SourceLocation WhileLoc, ExprArg Cond);
1037
1038 virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
1039 SourceLocation LParenLoc,
1040 StmtArg First, ExprArg Second,
1041 ExprArg Third, SourceLocation RParenLoc,
1042 StmtArg Body);
1043 virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1044 SourceLocation LParenLoc,
1045 StmtArg First, ExprArg Second,
1046 SourceLocation RParenLoc, StmtArg Body);
Sebastian Redl4cffe2f2009-01-18 13:19:59 +00001047
1048 virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1049 SourceLocation LabelLoc,
1050 IdentifierInfo *LabelII);
1051 virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1052 SourceLocation StarLoc,
1053 ExprArg DestExp);
1054 virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
1055 Scope *CurScope);
1056 virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
1057 Scope *CurScope);
1058
1059 virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
1060 ExprArg RetValExp);
1061 OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
1062 Expr *RetValExp);
1063
Sebastian Redl3037ed02009-01-18 16:53:17 +00001064 virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1065 bool IsSimple,
1066 bool IsVolatile,
1067 unsigned NumOutputs,
1068 unsigned NumInputs,
1069 std::string *Names,
1070 MultiExprArg Constraints,
1071 MultiExprArg Exprs,
1072 ExprArg AsmString,
1073 MultiExprArg Clobbers,
1074 SourceLocation RParenLoc);
Sebastian Redl431e90e2009-01-18 17:43:11 +00001075
1076 virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
1077 SourceLocation RParen,
Steve Naroff7ba138a2009-03-03 19:52:17 +00001078 DeclTy *Parm, StmtArg Body,
Sebastian Redl431e90e2009-01-18 17:43:11 +00001079 StmtArg CatchList);
1080
1081 virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
1082 StmtArg Body);
1083
1084 virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
1085 StmtArg Try,
1086 StmtArg Catch, StmtArg Finally);
1087
1088 virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Steve Naroffe21dd6f2009-02-11 20:05:44 +00001089 ExprArg Throw,
1090 Scope *CurScope);
Sebastian Redl431e90e2009-01-18 17:43:11 +00001091 virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1092 ExprArg SynchExpr,
1093 StmtArg SynchBody);
Sebastian Redla0fd8652008-12-21 16:41:36 +00001094
Sebastian Redl4b07b292008-12-22 19:15:10 +00001095 virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D);
1096 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
1097 DeclTy *ExDecl,
1098 StmtArg HandlerBlock);
Sebastian Redl8351da02008-12-22 21:35:02 +00001099 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
1100 StmtArg TryBlock,
1101 MultiStmtArg Handlers);
Sebastian Redla0fd8652008-12-21 16:41:36 +00001102
Reid Spencer5f016e22007-07-11 17:01:13 +00001103 //===--------------------------------------------------------------------===//
1104 // Expression Parsing Callbacks: SemaExpr.cpp.
1105
Douglas Gregor48f3bb92009-02-18 21:56:37 +00001106 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
Chris Lattner76a642f2009-02-15 22:43:40 +00001107
Reid Spencer5f016e22007-07-11 17:01:13 +00001108 // Primary Expressions.
Douglas Gregor4b2d3f72009-02-26 21:00:50 +00001109 virtual SourceRange getExprRange(ExprTy *E) const;
1110
Sebastian Redlcd965b92009-01-18 18:53:16 +00001111 virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
1112 IdentifierInfo &II,
1113 bool HasTrailingLParen,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001114 const CXXScopeSpec *SS = 0,
1115 bool isAddressOfOperand = false);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001116 virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S,
Douglas Gregor487a75a2008-11-19 19:09:45 +00001117 SourceLocation OperatorLoc,
1118 OverloadedOperatorKind Op,
1119 bool HasTrailingLParen,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001120 const CXXScopeSpec &SS,
1121 bool isAddressOfOperand);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001122 virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S,
Douglas Gregor487a75a2008-11-19 19:09:45 +00001123 SourceLocation OperatorLoc,
1124 TypeTy *Ty,
1125 bool HasTrailingLParen,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001126 const CXXScopeSpec &SS,
1127 bool isAddressOfOperand);
Douglas Gregor1a49af92009-01-06 05:10:23 +00001128 DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
1129 bool TypeDependent, bool ValueDependent,
1130 const CXXScopeSpec *SS = 0);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001131 OwningExprResult
Douglas Gregorbcbffc42009-01-07 00:43:41 +00001132 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1133 FieldDecl *Field,
1134 Expr *BaseObjectExpr = 0,
1135 SourceLocation OpLoc = SourceLocation());
Sebastian Redlcd965b92009-01-18 18:53:16 +00001136 OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
1137 DeclarationName Name,
1138 bool HasTrailingLParen,
1139 const CXXScopeSpec *SS,
Sebastian Redlebc07d52009-02-03 20:19:35 +00001140 bool isAddressOfOperand = false);
Douglas Gregor10c42622008-11-18 15:03:34 +00001141
Sebastian Redlcd965b92009-01-18 18:53:16 +00001142 virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
1143 tok::TokenKind Kind);
1144 virtual OwningExprResult ActOnNumericConstant(const Token &);
1145 virtual OwningExprResult ActOnCharacterConstant(const Token &);
1146 virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
1147 ExprArg Val);
Reid Spencer5f016e22007-07-11 17:01:13 +00001148
Steve Narofff69936d2007-09-16 03:34:24 +00001149 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Reid Spencer5f016e22007-07-11 17:01:13 +00001150 /// fragments (e.g. "foo" "bar" L"baz").
Sebastian Redl0eb23302009-01-19 00:08:26 +00001151 virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
1152 unsigned NumToks);
Sebastian Redlcd965b92009-01-18 18:53:16 +00001153
Reid Spencer5f016e22007-07-11 17:01:13 +00001154 // Binary/Unary Operators. 'Tok' is the token for the operator.
Sebastian Redl0eb23302009-01-19 00:08:26 +00001155 virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1156 tok::TokenKind Op, ExprArg Input);
1157 virtual OwningExprResult
Sebastian Redl05189992008-11-11 17:56:53 +00001158 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1159 void *TyOrEx, const SourceRange &ArgRange);
1160
Chris Lattner31e21e02009-01-24 20:17:12 +00001161 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R);
Sebastian Redl05189992008-11-11 17:56:53 +00001162 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1163 const SourceRange &R, bool isSizeof);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001164
1165 virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1166 tok::TokenKind Kind,
1167 ExprArg Input);
1168
1169 virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
1170 SourceLocation LLoc,
1171 ExprArg Idx,
1172 SourceLocation RLoc);
1173 virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base,
1174 SourceLocation OpLoc,
1175 tok::TokenKind OpKind,
1176 SourceLocation MemberLoc,
Fariborz Jahaniana6e3ac52009-03-04 22:30:12 +00001177 IdentifierInfo &Member,
1178 DeclTy *ImplDecl=0);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001179 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
Douglas Gregor88a35142008-12-22 05:46:06 +00001180 FunctionDecl *FDecl,
Douglas Gregor72564e72009-02-26 23:50:07 +00001181 const FunctionProtoType *Proto,
Douglas Gregor88a35142008-12-22 05:46:06 +00001182 Expr **Args, unsigned NumArgs,
1183 SourceLocation RParenLoc);
Sebastian Redl0eb23302009-01-19 00:08:26 +00001184
Steve Narofff69936d2007-09-16 03:34:24 +00001185 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Reid Spencer5f016e22007-07-11 17:01:13 +00001186 /// This provides the location of the left/right parens and a list of comma
1187 /// locations.
Sebastian Redl0eb23302009-01-19 00:08:26 +00001188 virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn,
1189 SourceLocation LParenLoc,
1190 MultiExprArg Args,
1191 SourceLocation *CommaLocs,
1192 SourceLocation RParenLoc);
1193
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001194 virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
1195 SourceLocation RParenLoc, ExprArg Op);
1196
1197 virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1198 TypeTy *Ty,
1199 SourceLocation RParenLoc,
1200 ExprArg Op);
1201
1202 virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
1203 MultiExprArg InitList,
1204 InitListDesignations &Designators,
1205 SourceLocation RParenLoc);
1206
Douglas Gregor05c13a32009-01-22 00:58:24 +00001207 virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
1208 SourceLocation Loc,
1209 bool UsedColonSyntax,
1210 OwningExprResult Init);
1211
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001212 virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1213 tok::TokenKind Kind,
1214 ExprArg LHS, ExprArg RHS);
1215 OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1216 unsigned Opc, Expr *lhs, Expr *rhs);
Douglas Gregoreaebc752008-11-06 23:29:22 +00001217
Steve Narofff69936d2007-09-16 03:34:24 +00001218 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Reid Spencer5f016e22007-07-11 17:01:13 +00001219 /// in the case of a the GNU conditional expr extension.
Sebastian Redlb8a6aca2009-01-19 22:31:54 +00001220 virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1221 SourceLocation ColonLoc,
1222 ExprArg Cond, ExprArg LHS,
1223 ExprArg RHS);
Reid Spencer5f016e22007-07-11 17:01:13 +00001224
Steve Naroff1b273c42007-09-16 14:56:35 +00001225 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1226 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +00001227 IdentifierInfo *LabelII);
1228
Steve Naroff1b273c42007-09-16 14:56:35 +00001229 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattnerab18c4c2007-07-24 16:58:17 +00001230 SourceLocation RPLoc); // "({..})"
Chris Lattner73d0d4f2007-08-30 17:45:32 +00001231
1232 /// __builtin_offsetof(type, a.b[123][456].c)
Douglas Gregor3fc749d2008-12-23 00:26:44 +00001233 virtual ExprResult ActOnBuiltinOffsetOf(Scope *S,
1234 SourceLocation BuiltinLoc,
Chris Lattner73d0d4f2007-08-30 17:45:32 +00001235 SourceLocation TypeLoc, TypeTy *Arg1,
1236 OffsetOfComponent *CompPtr,
1237 unsigned NumComponents,
1238 SourceLocation RParenLoc);
1239
Steve Naroffd34e9152007-08-01 22:05:33 +00001240 // __builtin_types_compatible_p(type1, type2)
Steve Naroff1b273c42007-09-16 14:56:35 +00001241 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroffd34e9152007-08-01 22:05:33 +00001242 TypeTy *arg1, TypeTy *arg2,
1243 SourceLocation RPLoc);
Steve Naroffd04fdd52007-08-03 21:21:27 +00001244
1245 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff1b273c42007-09-16 14:56:35 +00001246 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroffd04fdd52007-08-03 21:21:27 +00001247 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
1248 SourceLocation RPLoc);
Chris Lattnerab18c4c2007-07-24 16:58:17 +00001249
Anders Carlsson7c50aca2007-10-15 20:28:48 +00001250 // __builtin_va_arg(expr, type)
1251 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1252 ExprTy *expr, TypeTy *type,
1253 SourceLocation RPLoc);
Steve Naroff4eb206b2008-09-03 18:15:37 +00001254
Douglas Gregor2d8b2732008-11-29 04:51:27 +00001255 // __null
1256 virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1257
Steve Naroff4eb206b2008-09-03 18:15:37 +00001258 //===------------------------- "Block" Extension ------------------------===//
1259
1260 /// ActOnBlockStart - This callback is invoked when a block literal is
1261 /// started.
Steve Naroff090276f2008-10-10 01:28:17 +00001262 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1263
1264 /// ActOnBlockArguments - This callback allows processing of block arguments.
1265 /// If there are no arguments, this is still invoked.
Mike Stump98eb8a72009-02-04 22:31:32 +00001266 virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
Steve Naroff4eb206b2008-09-03 18:15:37 +00001267
1268 /// ActOnBlockError - If there is an error parsing a block, this callback
1269 /// is invoked to pop the information about the block from the action impl.
1270 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1271
1272 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1273 /// literal was successfully completed. ^(int x){...}
1274 virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
1275 Scope *CurScope);
1276
Chris Lattner76a642f2009-02-15 22:43:40 +00001277 //===---------------------------- C++ Features --------------------------===//
1278
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +00001279 // Act on C++ namespaces
1280 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
1281 IdentifierInfo *Ident,
1282 SourceLocation LBrace);
1283 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
1284
Douglas Gregorf780abc2008-12-30 03:27:21 +00001285 virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
1286 SourceLocation UsingLoc,
1287 SourceLocation NamespcLoc,
1288 const CXXScopeSpec &SS,
1289 SourceLocation IdentLoc,
1290 IdentifierInfo *NamespcName,
1291 AttributeList *AttrList);
1292
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001293 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
1294
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +00001295 /// AddCXXDirectInitializerToDecl - This action is called immediately after
1296 /// ActOnDeclarator, when a C++ direct initializer is present.
1297 /// e.g: "int x(1);"
1298 virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
1299 SourceLocation LParenLoc,
1300 ExprTy **Exprs, unsigned NumExprs,
1301 SourceLocation *CommaLocs,
1302 SourceLocation RParenLoc);
1303
Douglas Gregorf03d7c72008-11-05 15:29:30 +00001304 /// InitializationKind - Represents which kind of C++ initialization
1305 /// [dcl.init] a routine is to perform.
1306 enum InitializationKind {
1307 IK_Direct, ///< Direct initialization
1308 IK_Copy, ///< Copy initialization
1309 IK_Default ///< Default initialization
1310 };
1311
Douglas Gregor18fe5682008-11-03 20:45:27 +00001312 CXXConstructorDecl *
Douglas Gregorf03d7c72008-11-05 15:29:30 +00001313 PerformInitializationByConstructor(QualType ClassType,
1314 Expr **Args, unsigned NumArgs,
1315 SourceLocation Loc, SourceRange Range,
Chris Lattnerd9d22dd2008-11-24 05:29:24 +00001316 DeclarationName InitEntity,
Douglas Gregorf03d7c72008-11-05 15:29:30 +00001317 InitializationKind Kind);
Douglas Gregor18fe5682008-11-03 20:45:27 +00001318
Douglas Gregor49badde2008-10-27 19:41:14 +00001319 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
1320 virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
1321 SourceLocation LAngleBracketLoc, TypeTy *Ty,
1322 SourceLocation RAngleBracketLoc,
1323 SourceLocation LParenLoc, ExprTy *E,
1324 SourceLocation RParenLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001325
Sebastian Redlc42e1182008-11-11 11:37:55 +00001326 /// ActOnCXXTypeidOfType - Parse typeid( type-id ).
1327 virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
1328 SourceLocation LParenLoc, bool isType,
1329 void *TyOrExpr, SourceLocation RParenLoc);
1330
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00001331 //// ActOnCXXThis - Parse 'this' pointer.
1332 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
1333
Steve Naroff1b273c42007-09-16 14:56:35 +00001334 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
1335 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +00001336 tok::TokenKind Kind);
Anders Carlsson55085182007-08-21 17:43:55 +00001337
Chris Lattner50dd2892008-02-26 00:51:44 +00001338 //// ActOnCXXThrow - Parse throw expressions.
1339 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
1340 ExprTy *expr);
1341
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +00001342 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
1343 /// Can be interpreted either as function-style casting ("int(x)")
1344 /// or class type construction ("ClassType(x,y,z)")
1345 /// or creation of a value-initialized type ("int()").
1346 virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
1347 TypeTy *TypeRep,
1348 SourceLocation LParenLoc,
1349 ExprTy **Exprs,
1350 unsigned NumExprs,
1351 SourceLocation *CommaLocs,
1352 SourceLocation RParenLoc);
1353
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001354 /// ActOnCXXNew - Parsed a C++ 'new' expression.
1355 virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1356 SourceLocation PlacementLParen,
1357 ExprTy **PlacementArgs, unsigned NumPlaceArgs,
1358 SourceLocation PlacementRParen,
Sebastian Redlcee63fb2008-12-02 14:43:59 +00001359 bool ParenTypeId, Declarator &D,
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001360 SourceLocation ConstructorLParen,
1361 ExprTy **ConstructorArgs, unsigned NumConsArgs,
1362 SourceLocation ConstructorRParen);
Sebastian Redlcee63fb2008-12-02 14:43:59 +00001363 bool CheckAllocatedType(QualType AllocType, const Declarator &D);
Sebastian Redl00e68e22009-02-09 18:24:27 +00001364 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
1365 bool UseGlobal, QualType AllocType, bool IsArray,
Sebastian Redlb5a57a62008-12-03 20:26:15 +00001366 Expr **PlaceArgs, unsigned NumPlaceArgs,
1367 FunctionDecl *&OperatorNew,
1368 FunctionDecl *&OperatorDelete);
Sebastian Redl00e68e22009-02-09 18:24:27 +00001369 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
1370 DeclarationName Name, Expr** Args,
1371 unsigned NumArgs, DeclContext *Ctx,
Sebastian Redl7f662392008-12-04 22:20:51 +00001372 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlb5a57a62008-12-03 20:26:15 +00001373 void DeclareGlobalNewDelete();
1374 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
1375 QualType Argument);
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001376
1377 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
1378 virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
1379 bool ArrayForm, ExprTy *Operand);
1380
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00001381 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
1382 /// C++ if/switch/while/for statement.
1383 /// e.g: "if (int x = f()) {...}"
1384 virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
1385 SourceLocation StartLoc,
1386 Declarator &D,
1387 SourceLocation EqualLoc,
1388 ExprTy *AssignExprVal);
1389
Sebastian Redl64b45f72009-01-05 20:52:13 +00001390 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
1391 /// pseudo-functions.
1392 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
1393 SourceLocation KWLoc,
1394 SourceLocation LParen,
1395 TypeTy *Ty,
1396 SourceLocation RParen);
1397
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001398 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
1399 /// global scope ('::').
1400 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
1401 SourceLocation CCLoc);
1402
1403 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1404 /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now
1405 /// we want to resolve "bar::". 'SS' is empty or the previously parsed
1406 /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar',
1407 /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'.
1408 /// Returns a CXXScopeTy* object representing the C++ scope.
1409 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1410 const CXXScopeSpec &SS,
1411 SourceLocation IdLoc,
1412 SourceLocation CCLoc,
Douglas Gregor2def4832008-11-17 20:34:05 +00001413 IdentifierInfo &II);
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001414
Douglas Gregor39a8de12009-02-25 19:37:18 +00001415 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1416 /// nested-name-specifier that involves a template-id, e.g.,
1417 /// "foo::bar<int, float>::", and now we need to build a scope
1418 /// specifier. \p SS is empty or the previously parsed nested-name
1419 /// part ("foo::"), \p Type is the already-parsed class template
1420 /// specialization (or other template-id that names a type), \p
1421 /// TypeRange is the source range where the type is located, and \p
1422 /// CCLoc is the location of the trailing '::'.
1423 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1424 const CXXScopeSpec &SS,
1425 TypeTy *Type,
1426 SourceRange TypeRange,
1427 SourceLocation CCLoc);
1428
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001429 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1430 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1431 /// After this method is called, according to [C++ 3.4.3p3], names should be
1432 /// looked up in the declarator-id's scope, until the declarator is parsed and
1433 /// ActOnCXXExitDeclaratorScope is called.
1434 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1435 virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
1436
1437 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1438 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1439 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1440 /// Used to indicate that names should revert to being looked up in the
1441 /// defining scope.
Douglas Gregor0a59acb2008-12-16 00:38:16 +00001442 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00001443
Anders Carlsson55085182007-08-21 17:43:55 +00001444 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnerb3a99cd2007-12-12 01:04:12 +00001445 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
1446 ExprTy **Strings,
1447 unsigned NumStrings);
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001448 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner674af952007-10-16 22:51:17 +00001449 SourceLocation EncodeLoc,
Anders Carlssonf9bcf012007-08-22 15:14:15 +00001450 SourceLocation LParenLoc,
1451 TypeTy *Ty,
1452 SourceLocation RParenLoc);
1453
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001454 // ParseObjCSelectorExpression - Build selector expression for @selector
1455 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
1456 SourceLocation AtLoc,
Fariborz Jahanian2a35fa92007-10-16 23:21:02 +00001457 SourceLocation SelLoc,
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001458 SourceLocation LParenLoc,
1459 SourceLocation RParenLoc);
1460
Fariborz Jahanian390d50a2007-10-17 16:58:11 +00001461 // ParseObjCProtocolExpression - Build protocol expression for @protocol
1462 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
1463 SourceLocation AtLoc,
1464 SourceLocation ProtoLoc,
1465 SourceLocation LParenLoc,
1466 SourceLocation RParenLoc);
Douglas Gregore37ac4f2008-04-13 21:30:24 +00001467
1468 //===--------------------------------------------------------------------===//
Douglas Gregor074149e2009-01-05 19:45:36 +00001469 // C++ Declarations
1470 //
1471 virtual DeclTy *ActOnStartLinkageSpecification(Scope *S,
1472 SourceLocation ExternLoc,
1473 SourceLocation LangLoc,
1474 const char *Lang,
1475 unsigned StrSize,
1476 SourceLocation LBraceLoc);
1477 virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S,
1478 DeclTy *LinkageSpec,
1479 SourceLocation RBraceLoc);
1480
1481
1482 //===--------------------------------------------------------------------===//
Douglas Gregore37ac4f2008-04-13 21:30:24 +00001483 // C++ Classes
1484 //
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001485 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
1486 const CXXScopeSpec *SS);
Douglas Gregorb48fe382008-10-31 09:07:45 +00001487
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00001488 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
1489 Declarator &D, ExprTy *BitfieldWidth,
1490 ExprTy *Init, DeclTy *LastInGroup);
1491
Douglas Gregor7ad83902008-11-05 04:29:56 +00001492 virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD,
1493 Scope *S,
1494 IdentifierInfo *MemberOrBase,
1495 SourceLocation IdLoc,
1496 SourceLocation LParenLoc,
1497 ExprTy **Args, unsigned NumArgs,
1498 SourceLocation *CommaLocs,
1499 SourceLocation RParenLoc);
1500
Douglas Gregor396b7cd2008-11-03 17:51:48 +00001501 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
1502
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +00001503 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
1504 DeclTy *TagDecl,
1505 SourceLocation LBrac,
1506 SourceLocation RBrac);
1507
Douglas Gregor72b505b2008-12-16 21:30:33 +00001508 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1509 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param);
1510 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1511
Douglas Gregor42a552f2008-11-05 20:51:48 +00001512 bool CheckConstructorDeclarator(Declarator &D, QualType &R,
1513 FunctionDecl::StorageClass& SC);
Douglas Gregor72b505b2008-12-16 21:30:33 +00001514 bool CheckConstructor(CXXConstructorDecl *Constructor);
Douglas Gregor42a552f2008-11-05 20:51:48 +00001515 bool CheckDestructorDeclarator(Declarator &D, QualType &R,
1516 FunctionDecl::StorageClass& SC);
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001517 bool CheckConversionDeclarator(Declarator &D, QualType &R,
1518 FunctionDecl::StorageClass& SC);
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001519 DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregorb48fe382008-10-31 09:07:45 +00001520
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001521 //===--------------------------------------------------------------------===//
1522 // C++ Derived Classes
1523 //
1524
1525 /// ActOnBaseSpecifier - Parsed a base specifier
Douglas Gregor2943aed2009-03-03 04:44:36 +00001526 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
1527 SourceRange SpecifierRange,
1528 bool Virtual, AccessSpecifier Access,
1529 QualType BaseType,
1530 SourceLocation BaseLoc);
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001531 virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl,
1532 SourceRange SpecifierRange,
1533 bool Virtual, AccessSpecifier Access,
Douglas Gregor2943aed2009-03-03 04:44:36 +00001534 TypeTy *basetype, SourceLocation
1535 BaseLoc);
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001536
Douglas Gregor2943aed2009-03-03 04:44:36 +00001537 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
1538 unsigned NumBases);
Douglas Gregorbc0805a2008-10-23 00:40:37 +00001539 virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
1540 unsigned NumBases);
1541
1542 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00001543 bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
Douglas Gregor7176fff2009-01-15 00:26:24 +00001544 bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria,
1545 BasePaths &Paths);
Douglas Gregor0575d4a2008-10-24 16:17:19 +00001546 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
1547 SourceLocation Loc, SourceRange Range);
Douglas Gregor4dc6b1c2009-01-16 00:38:09 +00001548 std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
Douglas Gregore37ac4f2008-04-13 21:30:24 +00001549
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +00001550 //===--------------------------------------------------------------------===//
1551 // C++ Overloaded Operators [C++ 13.5]
1552 //
1553
1554 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
1555
Douglas Gregor72c3f312008-12-05 18:15:24 +00001556 //===--------------------------------------------------------------------===//
1557 // C++ Templates [C++ 14]
1558 //
Douglas Gregor55f6b142009-02-09 18:46:07 +00001559 virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S,
1560 DeclTy *&TemplateDecl,
1561 const CXXScopeSpec *SS = 0);
Douglas Gregor72c3f312008-12-05 18:15:24 +00001562 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001563 TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl);
1564
1565 virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename,
1566 SourceLocation KeyLoc,
1567 IdentifierInfo *ParamName,
1568 SourceLocation ParamNameLoc,
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001569 unsigned Depth, unsigned Position);
Douglas Gregord684b002009-02-10 19:49:53 +00001570 virtual void ActOnTypeParameterDefault(DeclTy *TypeParam,
1571 SourceLocation EqualLoc,
1572 SourceLocation DefaultLoc,
1573 TypeTy *Default);
1574
Douglas Gregor2943aed2009-03-03 04:44:36 +00001575 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001576 virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001577 unsigned Depth,
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001578 unsigned Position);
Douglas Gregord684b002009-02-10 19:49:53 +00001579 virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam,
1580 SourceLocation EqualLoc,
1581 ExprArg Default);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001582 virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S,
1583 SourceLocation TmpLoc,
1584 TemplateParamsTy *Params,
1585 IdentifierInfo *ParamName,
1586 SourceLocation ParamNameLoc,
1587 unsigned Depth,
1588 unsigned Position);
Douglas Gregord684b002009-02-10 19:49:53 +00001589 virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam,
1590 SourceLocation EqualLoc,
1591 ExprArg Default);
1592
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00001593 virtual TemplateParamsTy *
1594 ActOnTemplateParameterList(unsigned Depth,
1595 SourceLocation ExportLoc,
1596 SourceLocation TemplateLoc,
1597 SourceLocation LAngleLoc,
1598 DeclTy **Params, unsigned NumParams,
1599 SourceLocation RAngleLoc);
Douglas Gregord684b002009-02-10 19:49:53 +00001600 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
1601 TemplateParameterList *OldParams);
1602
Douglas Gregorddc29e12009-02-06 22:42:48 +00001603 virtual DeclTy *
1604 ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK,
1605 SourceLocation KWLoc, const CXXScopeSpec &SS,
1606 IdentifierInfo *Name, SourceLocation NameLoc,
1607 AttributeList *Attr,
1608 MultiTemplateParamsArg TemplateParameterLists);
1609
Douglas Gregor40808ce2009-03-09 23:48:35 +00001610 QualType CheckClassTemplateId(ClassTemplateDecl *ClassTemplate,
1611 SourceLocation TemplateLoc,
1612 SourceLocation LAngleLoc,
1613 const TemplateArgument *TemplateArgs,
1614 unsigned NumTemplateArgs,
1615 SourceLocation RAngleLoc);
1616
Douglas Gregorcc636682009-02-17 23:15:12 +00001617 virtual TypeResult
1618 ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc,
1619 SourceLocation LAngleLoc,
1620 ASTTemplateArgsPtr TemplateArgs,
1621 SourceLocation *TemplateArgLocs,
1622 SourceLocation RAngleLoc,
1623 const CXXScopeSpec *SS);
1624
Douglas Gregor88b70942009-02-25 22:02:03 +00001625 bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate,
1626 ClassTemplateSpecializationDecl *PrevDecl,
1627 SourceLocation TemplateNameLoc,
1628 SourceRange ScopeSpecifierRange);
1629
Douglas Gregorcc636682009-02-17 23:15:12 +00001630 virtual DeclTy *
1631 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
1632 SourceLocation KWLoc,
1633 const CXXScopeSpec &SS,
1634 DeclTy *Template,
1635 SourceLocation TemplateNameLoc,
Douglas Gregor55f6b142009-02-09 18:46:07 +00001636 SourceLocation LAngleLoc,
Douglas Gregor5908e9f2009-02-09 19:34:22 +00001637 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregorc15cb382009-02-09 23:23:08 +00001638 SourceLocation *TemplateArgLocs,
Douglas Gregor55f6b142009-02-09 18:46:07 +00001639 SourceLocation RAngleLoc,
Douglas Gregorcc636682009-02-17 23:15:12 +00001640 AttributeList *Attr,
1641 MultiTemplateParamsArg TemplateParameterLists);
Douglas Gregor55f6b142009-02-09 18:46:07 +00001642
Douglas Gregorc15cb382009-02-09 23:23:08 +00001643 bool CheckTemplateArgumentList(TemplateDecl *Template,
1644 SourceLocation TemplateLoc,
1645 SourceLocation LAngleLoc,
Douglas Gregor40808ce2009-03-09 23:48:35 +00001646 const TemplateArgument *TemplateArgs,
1647 unsigned NumTemplateArgs,
Douglas Gregor3e00bad2009-02-17 01:05:43 +00001648 SourceLocation RAngleLoc,
1649 llvm::SmallVectorImpl<TemplateArgument> &Converted);
Douglas Gregorc15cb382009-02-09 23:23:08 +00001650
1651 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg,
1652 SourceLocation ArgLoc);
Douglas Gregor3e00bad2009-02-17 01:05:43 +00001653 bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,
1654 NamedDecl *&Entity);
1655 bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member);
Douglas Gregor2943aed2009-03-03 04:44:36 +00001656 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
1657 QualType InstantiatedParamType, Expr *&Arg,
Douglas Gregor3e00bad2009-02-17 01:05:43 +00001658 llvm::SmallVectorImpl<TemplateArgument> *Converted = 0);
Douglas Gregorc15cb382009-02-09 23:23:08 +00001659 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg);
Douglas Gregorddc29e12009-02-06 22:42:48 +00001660 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
1661 TemplateParameterList *Old,
1662 bool Complain,
Douglas Gregordd0574e2009-02-10 00:24:35 +00001663 bool IsTemplateTemplateParm = false,
1664 SourceLocation TemplateArgLoc
1665 = SourceLocation());
Douglas Gregorddc29e12009-02-06 22:42:48 +00001666
1667 bool CheckTemplateDeclScope(Scope *S,
1668 MultiTemplateParamsArg &TemplateParameterLists);
Douglas Gregoraaba5e32009-02-04 19:02:06 +00001669
Douglas Gregor99ebf652009-02-27 19:31:52 +00001670 //===--------------------------------------------------------------------===//
1671 // C++ Template Instantiation
1672 //
Douglas Gregor26dce442009-03-10 00:06:19 +00001673
1674 /// \brief A template instantiation that is currently in progress.
1675 struct ActiveTemplateInstantiation {
Douglas Gregordf667e72009-03-10 20:44:00 +00001676 /// \brief The kind of template instantiation we are performing
1677 enum {
1678 /// We are instantiating a template declaration. The entity is
1679 /// the declaration we're instantiation (e.g., a
1680 /// ClassTemplateSpecializationDecl).
1681 TemplateInstantiation,
1682
1683 /// We are instantiating a default argument for a template
1684 /// parameter. The Entity is the template, and
1685 /// TemplateArgs/NumTemplateArguments provides the template
1686 /// arguments as specified.
1687 DefaultTemplateArgumentInstantiation
1688 } Kind;
1689
Douglas Gregor26dce442009-03-10 00:06:19 +00001690 /// \brief The point of instantiation within the source code.
1691 SourceLocation PointOfInstantiation;
1692
1693 /// \brief The entity that is being instantiated.
Douglas Gregordf667e72009-03-10 20:44:00 +00001694 uintptr_t Entity;
1695
1696 // \brief If this the instantiation of a default template
1697 // argument, the list of tempalte arguments.
1698 const TemplateArgument *TemplateArgs;
1699
1700 /// \brief The number of template arguments in TemplateArgs.
1701 unsigned NumTemplateArgs;
Douglas Gregor26dce442009-03-10 00:06:19 +00001702
1703 /// \brief The source range that covers the construct that cause
1704 /// the instantiation, e.g., the template-id that causes a class
1705 /// template instantiation.
1706 SourceRange InstantiationRange;
Douglas Gregordf667e72009-03-10 20:44:00 +00001707
1708 friend bool operator==(const ActiveTemplateInstantiation &X,
1709 const ActiveTemplateInstantiation &Y) {
1710 if (X.Kind != Y.Kind)
1711 return false;
1712
1713 if (X.Entity != Y.Entity)
1714 return false;
1715
1716 switch (X.Kind) {
1717 case TemplateInstantiation:
1718 return true;
1719
1720 case DefaultTemplateArgumentInstantiation:
1721 return X.TemplateArgs == Y.TemplateArgs;
1722 }
1723
1724 return true;
1725 }
1726
1727 friend bool operator!=(const ActiveTemplateInstantiation &X,
1728 const ActiveTemplateInstantiation &Y) {
1729 return !(X == Y);
1730 }
Douglas Gregor26dce442009-03-10 00:06:19 +00001731 };
1732
1733 /// \brief List of active template instantiations.
1734 ///
1735 /// This vector is treated as a stack. As one template instantiation
1736 /// requires another template instantiation, additional
1737 /// instantiations are pushed onto the stack up to a
1738 /// user-configurable limit LangOptions::InstantiationDepth.
1739 llvm::SmallVector<ActiveTemplateInstantiation, 16>
1740 ActiveTemplateInstantiations;
1741
Douglas Gregor27b152f2009-03-10 18:52:44 +00001742 /// \brief The last template from which a template instantiation
1743 /// error or warning was produced.
1744 ///
1745 /// This value is used to suppress printing of redundant template
1746 /// instantiation backtraces when there are multiple errors in the
1747 /// same instantiation. FIXME: Does this belong in Sema? It's tough
1748 /// to implement it anywhere else.
Douglas Gregordf667e72009-03-10 20:44:00 +00001749 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
Douglas Gregor27b152f2009-03-10 18:52:44 +00001750
Douglas Gregor26dce442009-03-10 00:06:19 +00001751 /// \brief A stack object to be created when performing template
1752 /// instantiation.
1753 ///
1754 /// Construction of an object of type \c InstantiatingTemplate
1755 /// pushes the current instantiation onto the stack of active
1756 /// instantiations. If the size of this stack exceeds the maximum
1757 /// number of recursive template instantiations, construction
1758 /// produces an error and evaluates true.
1759 ///
1760 /// Destruction of this object will pop the named instantiation off
1761 /// the stack.
1762 struct InstantiatingTemplate {
Douglas Gregordf667e72009-03-10 20:44:00 +00001763 /// \brief Note that we are instantiating a class template.
Douglas Gregor26dce442009-03-10 00:06:19 +00001764 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
1765 ClassTemplateSpecializationDecl *Entity,
1766 SourceRange InstantiationRange = SourceRange());
Douglas Gregordf667e72009-03-10 20:44:00 +00001767
1768 /// \brief Note that we are instantiating a default argument in a
1769 /// template-id.
1770 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
1771 TemplateDecl *Template,
1772 const TemplateArgument *TemplateArgs,
1773 unsigned NumTemplateArgs,
1774 SourceRange InstantiationRange = SourceRange());
1775
Douglas Gregor26dce442009-03-10 00:06:19 +00001776 ~InstantiatingTemplate();
1777
1778 /// \brief Determines whether we have exceeded the maximum
1779 /// recursive template instantiations.
1780 operator bool() const { return Invalid; }
1781
1782 private:
1783 Sema &SemaRef;
1784 bool Invalid;
1785
Douglas Gregordf667e72009-03-10 20:44:00 +00001786 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
1787 SourceRange InstantiationRange);
1788
Douglas Gregor26dce442009-03-10 00:06:19 +00001789 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
1790
1791 InstantiatingTemplate&
1792 operator=(const InstantiatingTemplate&); // not implemented
1793 };
1794
Douglas Gregoree1828a2009-03-10 18:03:33 +00001795 static void PrintInstantiationStackHook(unsigned DiagID, void *Cookie);
1796 void PrintInstantiationStack();
1797
Douglas Gregor99ebf652009-02-27 19:31:52 +00001798 QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
1799 unsigned NumTemplateArgs,
1800 SourceLocation Loc, DeclarationName Entity);
Douglas Gregor2943aed2009-03-03 04:44:36 +00001801 bool
1802 InstantiateBaseSpecifiers(ClassTemplateSpecializationDecl *ClassTemplateSpec,
1803 ClassTemplateDecl *ClassTemplate);
1804 bool
1805 InstantiateClassTemplateSpecialization(
1806 ClassTemplateSpecializationDecl *ClassTemplateSpec,
1807 bool ExplicitInstantiation);
Douglas Gregor99ebf652009-02-27 19:31:52 +00001808
Steve Naroff3536b442007-09-06 21:24:23 +00001809 // Objective-C declarations.
Chris Lattner06036d32008-07-26 04:13:19 +00001810 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
1811 IdentifierInfo *ClassName,
1812 SourceLocation ClassLoc,
1813 IdentifierInfo *SuperName,
1814 SourceLocation SuperLoc,
1815 DeclTy * const *ProtoRefs,
1816 unsigned NumProtoRefs,
1817 SourceLocation EndProtoLoc,
1818 AttributeList *AttrList);
Fariborz Jahanian243b64b2007-10-11 23:42:27 +00001819
1820 virtual DeclTy *ActOnCompatiblityAlias(
1821 SourceLocation AtCompatibilityAliasLoc,
1822 IdentifierInfo *AliasName, SourceLocation AliasLocation,
1823 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff61d68522009-03-05 15:22:01 +00001824
1825 void CheckForwardProtocolDeclarationForCircularDependency(
1826 IdentifierInfo *PName,
1827 SourceLocation &PLoc, SourceLocation PrevLoc,
1828 const ObjCList<ObjCProtocolDecl> &PList);
Steve Naroff3536b442007-09-06 21:24:23 +00001829
Steve Naroffe440eb82007-10-10 17:32:04 +00001830 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman1abc7f62008-02-20 22:57:40 +00001831 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian25e077d2007-09-17 21:07:36 +00001832 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattnere13b9592008-07-26 04:03:38 +00001833 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar246e70f2008-09-26 04:48:09 +00001834 SourceLocation EndProtoLoc,
1835 AttributeList *AttrList);
Fariborz Jahanian25e077d2007-09-17 21:07:36 +00001836
Chris Lattner6bd6d0b2008-07-26 04:07:02 +00001837 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
1838 IdentifierInfo *ClassName,
1839 SourceLocation ClassLoc,
1840 IdentifierInfo *CategoryName,
1841 SourceLocation CategoryLoc,
1842 DeclTy * const *ProtoRefs,
1843 unsigned NumProtoRefs,
1844 SourceLocation EndProtoLoc);
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +00001845
Steve Naroffe440eb82007-10-10 17:32:04 +00001846 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman1abc7f62008-02-20 22:57:40 +00001847 SourceLocation AtClassImplLoc,
Fariborz Jahanianccb4f312007-09-25 18:38:09 +00001848 IdentifierInfo *ClassName, SourceLocation ClassLoc,
1849 IdentifierInfo *SuperClassname,
1850 SourceLocation SuperClassLoc);
1851
Steve Naroffe440eb82007-10-10 17:32:04 +00001852 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +00001853 SourceLocation AtCatImplLoc,
1854 IdentifierInfo *ClassName,
1855 SourceLocation ClassLoc,
1856 IdentifierInfo *CatName,
1857 SourceLocation CatLoc);
1858
Steve Naroffe440eb82007-10-10 17:32:04 +00001859 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroff37e58d12007-10-02 22:39:18 +00001860 IdentifierInfo **IdentList,
1861 unsigned NumElts);
Fariborz Jahanian894c57f2007-09-21 15:40:54 +00001862
Steve Naroffe440eb82007-10-10 17:32:04 +00001863 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattner7caeabd2008-07-21 22:17:28 +00001864 const IdentifierLocPair *IdentList,
Fariborz Jahanianbc1c8772008-12-17 01:07:27 +00001865 unsigned NumElts,
1866 AttributeList *attrList);
Fariborz Jahanian245f92a2007-10-05 21:01:53 +00001867
Chris Lattnere13b9592008-07-26 04:03:38 +00001868 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattner7caeabd2008-07-21 22:17:28 +00001869 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +00001870 unsigned NumProtocols,
Chris Lattner7caeabd2008-07-21 22:17:28 +00001871 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanian02edb982008-05-01 00:03:38 +00001872
Daniel Dunbar95e61fb2008-09-23 21:53:23 +00001873 /// Ensure attributes are consistent with type.
1874 /// \param [in, out] Attributes The attributes to check; they will
1875 /// be modified to be consistent with \arg PropertyTy.
1876 void CheckObjCPropertyAttributes(QualType PropertyTy,
1877 SourceLocation Loc,
1878 unsigned &Attributes);
Steve Naroff0701bbb2009-01-08 17:28:14 +00001879 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Fariborz Jahanian02edb982008-05-01 00:03:38 +00001880 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1881 ObjCPropertyDecl *SuperProperty,
Chris Lattner8ec03f52008-11-24 03:54:41 +00001882 const IdentifierInfo *Name);
Fariborz Jahanian02edb982008-05-01 00:03:38 +00001883 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanianb5e02242008-04-24 19:58:34 +00001884
Fariborz Jahanian1ac2bc42008-12-06 23:03:39 +00001885 void MergeProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanianaebf0cb2008-05-02 19:17:30 +00001886 DeclTy *MergeProtocols);
1887
Fariborz Jahanianb7f95f52009-03-02 19:05:07 +00001888 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
1889 ObjCInterfaceDecl *ID);
1890
Fariborz Jahanian1ac2bc42008-12-06 23:03:39 +00001891 void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanianaebf0cb2008-05-02 19:17:30 +00001892 ObjCProtocolDecl *PDecl);
1893
Steve Naroff0416fb92007-11-11 17:19:15 +00001894 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
1895 DeclTy **allMethods = 0, unsigned allNum = 0,
1896 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +00001897
Fariborz Jahanian1de1e742008-04-14 23:36:35 +00001898 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian46b55e52008-05-05 18:51:55 +00001899 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanian5251e132008-05-06 18:09:04 +00001900 Selector GetterSel, Selector SetterSel,
Fariborz Jahanian8cf0bb32008-11-26 20:01:34 +00001901 DeclTy *ClassCategory, bool *OverridingProperty,
Fariborz Jahanian46b55e52008-05-05 18:51:55 +00001902 tok::ObjCKeywordKind MethodImplKind);
1903
Fariborz Jahanianf624f812008-04-18 00:19:30 +00001904 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
1905 SourceLocation PropertyLoc,
1906 bool ImplKind, DeclTy *ClassImplDecl,
1907 IdentifierInfo *PropertyId,
1908 IdentifierInfo *PropertyIvar);
1909
Steve Naroffbef11852007-10-26 20:53:56 +00001910 virtual DeclTy *ActOnMethodDeclaration(
1911 SourceLocation BeginLoc, // location of the + or -.
1912 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanian1f7b6f82007-11-09 19:52:12 +00001913 tok::TokenKind MethodType,
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001914 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanianf1de0ca2007-10-31 23:53:01 +00001915 Selector Sel,
Steve Naroff68d331a2007-09-27 14:38:14 +00001916 // optional arguments. The number of types/arguments is obtained
1917 // from the Sel.getNumArgs().
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001918 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Fariborz Jahanian439c6582009-01-09 00:38:19 +00001919 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroff335eafa2007-11-15 12:35:21 +00001920 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
1921 bool isVariadic = false);
Steve Naroff81bfde92007-10-16 23:12:48 +00001922
Steve Narofff1afaf62009-02-26 15:55:06 +00001923 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
1924 // Will search "local" class/category implementations for a method decl.
Fariborz Jahanian175ba1e2009-03-04 18:15:57 +00001925 // Will also search in class's root looking for instance method.
Steve Narofff1afaf62009-02-26 15:55:06 +00001926 // Returns 0 if no method is found.
Steve Naroff5609ec02009-03-08 18:56:13 +00001927 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
1928 ObjCInterfaceDecl *CDecl);
1929 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
1930 ObjCInterfaceDecl *ClassDecl);
Steve Narofff1afaf62009-02-26 15:55:06 +00001931
Steve Naroff61f72cb2009-03-09 21:12:44 +00001932 virtual OwningExprResult ActOnClassPropertyRefExpr(
1933 IdentifierInfo &receiverName,
1934 IdentifierInfo &propertyName,
1935 SourceLocation &receiverNameLoc,
1936 SourceLocation &propertyNameLoc);
1937
Steve Naroff68d331a2007-09-27 14:38:14 +00001938 // ActOnClassMessage - used for both unary and keyword messages.
1939 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff49f109c2007-11-15 13:05:42 +00001940 // is obtained from NumArgs.
Steve Naroff68d331a2007-09-27 14:38:14 +00001941 virtual ExprResult ActOnClassMessage(
Fariborz Jahanian0523aaf2007-11-12 20:13:27 +00001942 Scope *S,
Anders Carlssonff975cf2009-02-14 18:21:46 +00001943 IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,
1944 SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac,
Steve Naroff49f109c2007-11-15 13:05:42 +00001945 ExprTy **ArgExprs, unsigned NumArgs);
Steve Naroff68d331a2007-09-27 14:38:14 +00001946
1947 // ActOnInstanceMessage - used for both unary and keyword messages.
1948 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff49f109c2007-11-15 13:05:42 +00001949 // is obtained from NumArgs.
Steve Naroff68d331a2007-09-27 14:38:14 +00001950 virtual ExprResult ActOnInstanceMessage(
Steve Naroffbcfb06a2007-09-28 22:22:11 +00001951 ExprTy *receiver, Selector Sel,
Anders Carlssonff975cf2009-02-14 18:21:46 +00001952 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroff49f109c2007-11-15 13:05:42 +00001953 ExprTy **ArgExprs, unsigned NumArgs);
Daniel Dunbar4cde9272008-10-14 05:35:18 +00001954
1955 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
1956 virtual void ActOnPragmaPack(PragmaPackKind Kind,
1957 IdentifierInfo *Name,
1958 ExprTy *Alignment,
1959 SourceLocation PragmaLoc,
1960 SourceLocation LParenLoc,
1961 SourceLocation RParenLoc);
Chris Lattner574aa402009-02-17 01:09:29 +00001962
1963 /// getPragmaPackAlignment() - Return the current alignment as specified by
1964 /// the current #pragma pack directive, or 0 if none is currently active.
1965 unsigned getPragmaPackAlignment() const;
1966
1967 /// FreePackedContext - Deallocate and null out PackContext.
1968 void FreePackedContext();
Daniel Dunbar4cde9272008-10-14 05:35:18 +00001969
Chris Lattner1e0a3902008-01-16 19:17:22 +00001970 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
1971 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregoreb8f3062008-11-12 17:17:38 +00001972 /// If isLvalue, the result of the cast is an lvalue.
1973 void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
Chris Lattner1e0a3902008-01-16 19:17:22 +00001974
Reid Spencer5f016e22007-07-11 17:01:13 +00001975 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner925e60d2007-12-28 05:29:59 +00001976 // functions and arrays to their respective pointers (C99 6.3.2.1).
1977 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3c0eb162008-05-27 03:33:27 +00001978
Steve Naroffc80b4ee2007-07-16 21:54:35 +00001979 // DefaultFunctionArrayConversion - converts functions and arrays
1980 // to their respective pointers (C99 6.3.2.1).
1981 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroff90045e82007-07-13 23:32:42 +00001982
Steve Naroffb291ab62007-08-28 23:30:39 +00001983 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
1984 // do not have a prototype. Integer promotions are performed on each
1985 // argument, and arguments that have type float are promoted to double.
Chris Lattner925e60d2007-12-28 05:29:59 +00001986 void DefaultArgumentPromotion(Expr *&Expr);
Anders Carlssondce5e2c2009-01-16 16:48:51 +00001987
1988 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
1989 enum VariadicCallType {
1990 VariadicFunction,
1991 VariadicBlock,
1992 VariadicMethod
1993 };
1994
1995 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
1996 // will warn if the resulting type is not a POD type.
1997 void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
Steve Naroffb291ab62007-08-28 23:30:39 +00001998
Reid Spencer5f016e22007-07-11 17:01:13 +00001999 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
2000 // operands and then handles various conversions that are common to binary
2001 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
2002 // routine returns the first non-arithmetic type found. The client is
2003 // responsible for emitting appropriate error diagnostics.
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00002004 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
2005 bool isCompAssign = false);
Chris Lattnerb7b61152008-01-04 18:22:42 +00002006
Douglas Gregoreb8f3062008-11-12 17:17:38 +00002007 /// UsualArithmeticConversionsType - handles the various conversions
2008 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
2009 /// and returns the result type of that conversion.
2010 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
2011
2012
Chris Lattnerb7b61152008-01-04 18:22:42 +00002013 /// AssignConvertType - All of the 'assignment' semantic checks return this
2014 /// enum to indicate whether the assignment was allowed. These checks are
2015 /// done for simple assignments, as well as initialization, return from
2016 /// function, argument passing, etc. The query is phrased in terms of a
2017 /// source and destination type.
Chris Lattner5cf216b2008-01-04 18:04:52 +00002018 enum AssignConvertType {
Chris Lattnerb7b61152008-01-04 18:22:42 +00002019 /// Compatible - the types are compatible according to the standard.
Reid Spencer5f016e22007-07-11 17:01:13 +00002020 Compatible,
Chris Lattnerb7b61152008-01-04 18:22:42 +00002021
2022 /// PointerToInt - The assignment converts a pointer to an int, which we
2023 /// accept as an extension.
2024 PointerToInt,
2025
2026 /// IntToPointer - The assignment converts an int to a pointer, which we
2027 /// accept as an extension.
2028 IntToPointer,
2029
2030 /// FunctionVoidPointer - The assignment is between a function pointer and
2031 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattnerbfe639e2008-01-03 22:56:36 +00002032 FunctionVoidPointer,
Chris Lattnerb7b61152008-01-04 18:22:42 +00002033
2034 /// IncompatiblePointer - The assignment is between two pointers types that
2035 /// are not compatible, but we accept them as an extension.
Reid Spencer5f016e22007-07-11 17:01:13 +00002036 IncompatiblePointer,
Chris Lattnerb7b61152008-01-04 18:22:42 +00002037
2038 /// CompatiblePointerDiscardsQualifiers - The assignment discards
2039 /// c/v/r qualifiers, which we accept as an extension.
2040 CompatiblePointerDiscardsQualifiers,
Steve Naroff1c7d0672008-09-04 15:10:53 +00002041
Anders Carlssonb0f90cc2009-01-30 23:17:46 +00002042 /// IncompatibleVectors - The assignment is between two vector types that
2043 /// have the same size, which we accept as an extension.
2044 IncompatibleVectors,
2045
Steve Naroffbfdcae62008-09-04 15:31:07 +00002046 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff1c7d0672008-09-04 15:10:53 +00002047 /// pointer. We disallow this.
2048 IntToBlockPointer,
2049
Steve Naroffbfdcae62008-09-04 15:31:07 +00002050 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff1c7d0672008-09-04 15:10:53 +00002051 /// pointers types that are not compatible.
2052 IncompatibleBlockPointer,
2053
Steve Naroff39579072008-10-14 22:18:38 +00002054 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
2055 /// id type and something else (that is incompatible with it). For example,
2056 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
2057 IncompatibleObjCQualifiedId,
2058
Chris Lattnerb7b61152008-01-04 18:22:42 +00002059 /// Incompatible - We reject this conversion outright, it is invalid to
2060 /// represent it in the AST.
2061 Incompatible
Reid Spencer5f016e22007-07-11 17:01:13 +00002062 };
Chris Lattner5cf216b2008-01-04 18:04:52 +00002063
2064 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
2065 /// assignment conversion type specified by ConvTy. This returns true if the
2066 /// conversion was invalid or false if the conversion was accepted.
2067 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
2068 SourceLocation Loc,
2069 QualType DstType, QualType SrcType,
2070 Expr *SrcExpr, const char *Flavor);
2071
2072 /// CheckAssignmentConstraints - Perform type checking for assignment,
2073 /// argument passing, variable initialization, and function return values.
2074 /// This routine is only used by the following two methods. C99 6.5.16.
2075 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroff90045e82007-07-13 23:32:42 +00002076
Steve Narofff69936d2007-09-16 03:34:24 +00002077 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff1b273c42007-09-16 14:56:35 +00002078 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroff90045e82007-07-13 23:32:42 +00002079 // this routine performs the default function/array converions.
Chris Lattner5cf216b2008-01-04 18:04:52 +00002080 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
2081 Expr *&rExpr);
Steve Naroff90045e82007-07-13 23:32:42 +00002082 // CheckCompoundAssignmentConstraints - Type check without performing any
2083 // conversions. For compound assignments, the "Check...Operands" methods
2084 // perform the necessary conversions.
Chris Lattner5cf216b2008-01-04 18:04:52 +00002085 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
2086 QualType rhs);
Steve Naroff90045e82007-07-13 23:32:42 +00002087
Reid Spencer5f016e22007-07-11 17:01:13 +00002088 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner5cf216b2008-01-04 18:04:52 +00002089 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
2090 QualType rhsType);
Steve Naroff1c7d0672008-09-04 15:10:53 +00002091
2092 // Helper function for CheckAssignmentConstraints involving two
2093 // blcok pointer types.
2094 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
2095 QualType rhsType);
Douglas Gregor77a52232008-09-12 00:47:35 +00002096
2097 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00002098
Douglas Gregor45920e82008-12-19 17:40:08 +00002099 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00002100 const char *Flavor, bool AllowExplicit = false);
2101 bool PerformImplicitConversion(Expr *&From, QualType ToType,
2102 const ImplicitConversionSequence& ICS,
Douglas Gregor45920e82008-12-19 17:40:08 +00002103 const char *Flavor);
Douglas Gregor94b1dd22008-10-24 04:54:22 +00002104 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor45920e82008-12-19 17:40:08 +00002105 const StandardConversionSequence& SCS,
2106 const char *Flavor);
Sebastian Redl22460502009-02-07 00:15:38 +00002107
Reid Spencer5f016e22007-07-11 17:01:13 +00002108 /// the following "Check" methods will return a valid/converted QualType
2109 /// or a null QualType (indicating an error diagnostic was issued).
Sebastian Redl22460502009-02-07 00:15:38 +00002110
2111 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
Chris Lattnerca5eede2007-12-12 05:47:28 +00002112 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Sebastian Redl7c8bd602009-02-07 20:10:22 +00002113 QualType CheckPointerToMemberOperands( // C++ 5.5
Sebastian Redl22460502009-02-07 00:15:38 +00002114 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
Reid Spencer5f016e22007-07-11 17:01:13 +00002115 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Sebastian Redl22460502009-02-07 00:15:38 +00002116 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002117 inline QualType CheckRemainderOperands( // C99 6.5.5
Sebastian Redl22460502009-02-07 00:15:38 +00002118 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002119 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00002120 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002121 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00002122 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002123 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff9f5fa9b2007-08-24 19:07:16 +00002124 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnera5937dd2007-08-26 01:18:55 +00002125 inline QualType CheckCompareOperands( // C99 6.5.8/9
2126 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Reid Spencer5f016e22007-07-11 17:01:13 +00002127 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Sebastian Redl22460502009-02-07 00:15:38 +00002128 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +00002129 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff49b45262007-07-13 16:58:59 +00002130 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002131 // CheckAssignmentOperands is used for both simple and compound assignment.
2132 // For simple assignment, pass both expressions and a null converted type.
2133 // For compound assignment, pass both expressions and the converted type.
2134 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Narofff1120de2007-08-24 22:33:52 +00002135 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Reid Spencer5f016e22007-07-11 17:01:13 +00002136 inline QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner29a1cfb2008-11-18 01:30:42 +00002137 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002138 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff49b45262007-07-13 16:58:59 +00002139 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begemanbe2341d2008-07-14 18:02:46 +00002140
2141 /// type checking for vector binary operators.
2142 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
2143 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
2144 SourceLocation l, bool isRel);
Reid Spencer5f016e22007-07-11 17:01:13 +00002145
Steve Narofff69936d2007-09-16 03:34:24 +00002146 /// type checking unary operators (subroutines of ActOnUnaryOp).
Reid Spencer5f016e22007-07-11 17:01:13 +00002147 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redle6d5a4a2008-12-20 09:35:34 +00002148 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
2149 bool isInc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002150 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
2151 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattnerba27e2a2009-02-17 08:12:06 +00002152 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
Steve Naroffe1b31fe2007-07-27 22:15:19 +00002153
2154 /// type checking primary expressions.
Nate Begeman213541a2008-04-18 23:10:10 +00002155 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Naroffe1b31fe2007-07-27 22:15:19 +00002156 IdentifierInfo &Comp, SourceLocation CmpLoc);
2157
Steve Narofff0090632007-09-02 02:04:30 +00002158 /// type checking declaration initializers (C99 6.7.8)
Douglas Gregorf03d7c72008-11-05 15:29:30 +00002159 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00002160 SourceLocation InitLoc,DeclarationName InitEntity,
2161 bool DirectInit);
Douglas Gregorc34ee5e2009-01-29 00:45:39 +00002162 bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
Steve Naroffd0091aa2008-01-10 22:15:12 +00002163 bool CheckForConstantInitializer(Expr *e, QualType t);
Steve Naroff2fdc3742007-12-10 22:44:33 +00002164
Douglas Gregor87fd7032009-02-02 17:43:21 +00002165 bool CheckValueInitialization(QualType Type, SourceLocation Loc);
Argyrios Kyrtzidis6c2dc4d2008-08-16 20:27:34 +00002166
Douglas Gregor27c8dc02008-10-29 00:13:59 +00002167 // type checking C++ declaration initializers (C++ [dcl.init]).
2168
2169 /// ReferenceCompareResult - Expresses the result of comparing two
2170 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
2171 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
2172 enum ReferenceCompareResult {
2173 /// Ref_Incompatible - The two types are incompatible, so direct
2174 /// reference binding is not possible.
2175 Ref_Incompatible = 0,
2176 /// Ref_Related - The two types are reference-related, which means
2177 /// that their unqualified forms (T1 and T2) are either the same
2178 /// or T1 is a base class of T2.
2179 Ref_Related,
2180 /// Ref_Compatible_With_Added_Qualification - The two types are
2181 /// reference-compatible with added qualification, meaning that
2182 /// they are reference-compatible and the qualifiers on T1 (cv1)
2183 /// are greater than the qualifiers on T2 (cv2).
2184 Ref_Compatible_With_Added_Qualification,
2185 /// Ref_Compatible - The two types are reference-compatible and
2186 /// have equivalent qualifiers (cv1 == cv2).
2187 Ref_Compatible
2188 };
2189
Douglas Gregor15da57e2008-10-29 02:00:59 +00002190 ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
2191 bool& DerivedToBase);
Douglas Gregor27c8dc02008-10-29 00:13:59 +00002192
2193 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor225c41e2008-11-03 19:09:14 +00002194 ImplicitConversionSequence *ICS = 0,
Douglas Gregor09f41cf2009-01-14 15:45:31 +00002195 bool SuppressUserConversions = false,
2196 bool AllowExplicit = false);
Douglas Gregor27c8dc02008-10-29 00:13:59 +00002197
Argyrios Kyrtzidis6c2dc4d2008-08-16 20:27:34 +00002198 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar58d5ebb2008-08-20 03:55:42 +00002199 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroffa49e1fa2008-01-22 00:55:40 +00002200
Anders Carlsson584b2472007-11-27 07:16:40 +00002201 // CheckVectorCast - check type constraints for vectors.
2202 // Since vectors are an extension, there are no C standard reference for this.
2203 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssona64db8f2007-11-27 05:51:55 +00002204 // returns true if the cast is invalid
2205 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
2206
Daniel Dunbar637cebb2008-09-11 00:01:56 +00002207 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
2208 /// \param Method - May be null.
2209 /// \param [out] ReturnType - The return type of the send.
2210 /// \return true iff there were any incompatible types.
Daniel Dunbar91e19b22008-09-11 00:50:25 +00002211 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattner077bf5e2008-11-24 03:33:13 +00002212 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbar637cebb2008-09-11 00:01:56 +00002213 SourceLocation lbrac, SourceLocation rbrac,
2214 QualType &ReturnType);
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00002215
2216 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
2217 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff81bfde92007-10-16 23:12:48 +00002218
Chris Lattnerf4021e72007-08-23 05:46:52 +00002219 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
2220 /// the specified width and sign. If an overflow occurs, detect it and emit
2221 /// the specified diagnostic.
2222 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
2223 unsigned NewWidth, bool NewSign,
2224 SourceLocation Loc, unsigned DiagID);
2225
Chris Lattnereca7be62008-04-07 05:30:13 +00002226 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
2227 bool ForCompare);
2228
Anders Carlsson15281452008-11-04 16:57:32 +00002229 /// Checks that the Objective-C declaration is declared in the global scope.
2230 /// Emits an error and marks the declaration as invalid if it's not declared
2231 /// in the global scope.
2232 bool CheckObjCDeclScope(Decl *D);
2233
Anders Carlsson7c50aca2007-10-15 20:28:48 +00002234 void InitBuiltinVaListType();
Eli Friedman1b76ada2008-06-03 21:01:11 +00002235
Anders Carlssone21555e2008-11-30 19:50:32 +00002236 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
2237 /// and reports the appropriate diagnostics. Returns false on success.
2238 /// Can optionally return the value of the expression.
Anders Carlsson9f1e5722008-12-06 20:33:04 +00002239 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson4000ea62008-12-01 02:17:22 +00002240
Anders Carlsson9f1e5722008-12-06 20:33:04 +00002241 /// VerifyBitField - verifies that a bit field expression is an ICE and has
2242 /// the correct width, and that the field type is valid.
2243 /// Returns false on success.
2244 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
2245 QualType FieldTy, const Expr *BitWidth);
Sebastian Redl0eb23302009-01-19 00:08:26 +00002246
Chris Lattner59907c42007-08-10 20:18:51 +00002247 //===--------------------------------------------------------------------===//
2248 // Extra semantic analysis beyond the C type system
Chris Lattner925e60d2007-12-28 05:29:59 +00002249private:
Sebastian Redl0eb23302009-01-19 00:08:26 +00002250 Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl,
2251 CallExpr *TheCall);
Chris Lattner60800082009-02-18 17:49:48 +00002252 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
2253 unsigned ByteNo) const;
Chris Lattner69039812009-02-18 06:01:06 +00002254 bool CheckObjCString(Expr *Arg);
Chris Lattner925e60d2007-12-28 05:29:59 +00002255 bool SemaBuiltinVAStart(CallExpr *TheCall);
2256 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedman6cfda232008-05-20 08:23:37 +00002257 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Sebastian Redl0eb23302009-01-19 00:08:26 +00002258 Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbar4493f792008-07-21 22:59:13 +00002259 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbard5f8a4f2008-09-03 21:13:56 +00002260 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Ted Kremenekd30ef872009-01-12 23:09:09 +00002261 bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg,
Douglas Gregor3c385e52009-02-14 18:57:46 +00002262 unsigned format_idx, unsigned firstDataArg);
Ted Kremenekd30ef872009-01-12 23:09:09 +00002263 void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr,
2264 CallExpr *TheCall, bool HasVAListArg,
Douglas Gregor3c385e52009-02-14 18:57:46 +00002265 unsigned format_idx, unsigned firstDataArg);
2266 void CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
2267 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek06de2762007-08-17 16:46:58 +00002268 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
2269 SourceLocation ReturnLoc);
Ted Kremenek588e5eb2007-11-25 00:58:00 +00002270 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Reid Spencer5f016e22007-07-11 17:01:13 +00002271};
2272
Steve Naroff4eb206b2008-09-03 18:15:37 +00002273/// BlockSemaInfo - When a block is being parsed, this contains information
2274/// about the block. It is pointed to from Sema::CurBlock.
2275struct BlockSemaInfo {
2276 llvm::SmallVector<ParmVarDecl*, 8> Params;
Steve Naroff4eb206b2008-09-03 18:15:37 +00002277 bool hasPrototype;
2278 bool isVariadic;
Mike Stumpb83d2872009-02-19 22:01:56 +00002279 bool hasBlockDeclRefExprs;
2280
Steve Naroff1c90bfc2008-10-08 18:44:00 +00002281 BlockDecl *TheDecl;
2282
Chris Lattnerda425eb2009-02-18 07:09:44 +00002283 /// TheScope - This is the scope for the block itself, which contains
Steve Naroff4eb206b2008-09-03 18:15:37 +00002284 /// arguments etc.
2285 Scope *TheScope;
2286
2287 /// ReturnType - This will get set to block result type, by looking at
2288 /// return types, if any, in the block body.
2289 Type *ReturnType;
2290
2291 /// PrevBlockInfo - If this is nested inside another block, this points
2292 /// to the outer block.
2293 BlockSemaInfo *PrevBlockInfo;
2294};
Ted Kremenek8189cde2009-02-07 01:47:29 +00002295
2296//===--------------------------------------------------------------------===//
2297// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
2298template <typename T>
2299class ExprOwningPtr : public Action::ExprArg {
2300public:
2301 ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {};
2302
2303 void reset(T* p) { Action::ExprArg::operator=(p); }
2304 T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
2305 T* take() { return static_cast<T*>(Action::ExprArg::take()); }
2306 T* release() { return take(); }
2307
2308 T& operator*() const { return *get(); }
2309 T* operator->() const { return get(); }
2310};
2311
Reid Spencer5f016e22007-07-11 17:01:13 +00002312} // end namespace clang
2313
2314#endif