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