blob: de9b4cd013ab8ab53e9fd7d9751895f52a3af7fa [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"
Douglas Gregorb9ef0552009-01-16 00:38:09 +000028#include <string>
Douglas Gregorbb461502008-10-24 04:54:22 +000029#include <vector>
Chris Lattner4b009652007-07-25 00:24:17 +000030
Chris Lattner3429a812007-08-23 05:46:52 +000031namespace llvm {
32 class APSInt;
33}
34
Chris Lattner4b009652007-07-25 00:24:17 +000035namespace clang {
36 class ASTContext;
Chris Lattnera8c2d592008-02-06 00:46:58 +000037 class ASTConsumer;
Chris Lattner4b009652007-07-25 00:24:17 +000038 class Preprocessor;
39 class Decl;
Chris Lattnerf3874bc2008-04-06 04:47:34 +000040 class DeclContext;
Daniel Dunbar8d03cbe2008-08-11 03:27:53 +000041 class DeclSpec;
Steve Naroffe57c21a2008-04-01 23:04:06 +000042 class NamedDecl;
Sebastian Redl91f9b0a2008-12-13 16:23:55 +000043 class Stmt;
Chris Lattner4b009652007-07-25 00:24:17 +000044 class Expr;
Steve Naroff9091f3f2007-09-02 15:34:30 +000045 class InitListExpr;
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +000046 class DesignatedInitExpr;
Chris Lattner83bd5eb2007-12-28 05:29:59 +000047 class CallExpr;
Douglas Gregor566782a2009-01-06 05:10:23 +000048 class DeclRefExpr;
Chris Lattner4b009652007-07-25 00:24:17 +000049 class VarDecl;
50 class ParmVarDecl;
51 class TypedefDecl;
52 class FunctionDecl;
53 class QualType;
Chris Lattner3496d522007-09-04 02:45:27 +000054 struct LangOptions;
Chris Lattner4b009652007-07-25 00:24:17 +000055 class Token;
56 class IntegerLiteral;
Steve Naroff0d4e6ad2008-01-22 00:55:40 +000057 class StringLiteral;
Chris Lattner4b009652007-07-25 00:24:17 +000058 class ArrayType;
59 class LabelStmt;
60 class SwitchStmt;
Nate Begemanaf6ed502008-04-18 23:10:10 +000061 class ExtVectorType;
Steve Naroff82113e32007-07-29 16:33:31 +000062 class TypedefDecl;
Douglas Gregor279272e2009-02-04 19:02:06 +000063 class TemplateDecl;
Douglas Gregorad964b32009-02-17 01:05:43 +000064 class TemplateArgument;
Douglas Gregord406b032009-02-06 22:42:48 +000065 class TemplateParameterList;
Douglas Gregor35d81bb2009-02-09 23:23:08 +000066 class TemplateTemplateParmDecl;
Douglas Gregor0d93f692009-02-25 22:02:03 +000067 class ClassTemplateDecl;
Ted Kremenek42730c52008-01-07 19:49:32 +000068 class ObjCInterfaceDecl;
Steve Naroffe57c21a2008-04-01 23:04:06 +000069 class ObjCCompatibleAliasDecl;
Ted Kremenek42730c52008-01-07 19:49:32 +000070 class ObjCProtocolDecl;
Chris Lattner7cc13bf2009-03-01 00:56:52 +000071 class ObjCImplDecl;
Ted Kremenek42730c52008-01-07 19:49:32 +000072 class ObjCImplementationDecl;
73 class ObjCCategoryImplDecl;
74 class ObjCCategoryDecl;
75 class ObjCIvarDecl;
76 class ObjCMethodDecl;
Fariborz Jahanianed986602008-05-01 00:03:38 +000077 class ObjCPropertyDecl;
Steve Naroffab63fd62009-01-08 17:28:14 +000078 class ObjCContainerDecl;
Steve Naroff52a81c02008-09-03 18:15:37 +000079 struct BlockSemaInfo;
Douglas Gregorbb461502008-10-24 04:54:22 +000080 class BasePaths;
Douglas Gregor29dfa2f2009-01-15 00:26:24 +000081 class MemberLookupCriteria;
Steve Naroff82113e32007-07-29 16:33:31 +000082
Chris Lattner4b009652007-07-25 00:24:17 +000083/// Sema - This implements semantic analysis and AST building for C.
84class Sema : public Action {
Chris Lattner767678f2009-02-17 00:58:30 +000085 Sema(const Sema&); // DO NOT IMPLEMENT
86 void operator=(const Sema&); // DO NOT IMPLEMENT
Chris Lattnerf6690152008-06-29 00:28:59 +000087public:
Chris Lattner6d89a8a2009-01-22 19:21:44 +000088 const LangOptions &LangOpts;
Chris Lattner4b009652007-07-25 00:24:17 +000089 Preprocessor &PP;
Chris Lattner4b009652007-07-25 00:24:17 +000090 ASTContext &Context;
Chris Lattnera8c2d592008-02-06 00:46:58 +000091 ASTConsumer &Consumer;
Chris Lattnerf9ea6a42008-11-22 08:28:49 +000092 Diagnostic &Diags;
93 SourceManager &SourceMgr;
Steve Naroffdd2e26c2007-11-12 13:56:41 +000094
Argiris Kirtzidis95256e62008-06-28 06:07:14 +000095 /// CurContext - This is the current declaration context of parsing.
Chris Lattnerf3874bc2008-04-06 04:47:34 +000096 DeclContext *CurContext;
Chris Lattnereee57c02008-04-04 06:12:32 +000097
Argiris Kirtzidis054a2632008-11-08 17:17:31 +000098 /// PreDeclaratorDC - Keeps the declaration context before switching to the
99 /// context of a declarator's nested-name-specifier.
100 DeclContext *PreDeclaratorDC;
101
Steve Naroff52a81c02008-09-03 18:15:37 +0000102 /// CurBlock - If inside of a block definition, this contains a pointer to
103 /// the active block object that represents it.
104 BlockSemaInfo *CurBlock;
105
Steve Naroff313c4162009-02-28 16:48:43 +0000106 /// ActiveScope - If inside of a function, method, or block definition,
107 /// this contains a pointer to the active scope that represents it.
108 Scope *ActiveScope;
109
Daniel Dunbar81c7d472008-10-14 05:35:18 +0000110 /// PackContext - Manages the stack for #pragma pack. An alignment
111 /// of 0 indicates default alignment.
Chris Lattnera8699562009-02-17 01:09:29 +0000112 void *PackContext; // Really a "PragmaPackStack*"
Daniel Dunbar81c7d472008-10-14 05:35:18 +0000113
Chris Lattner4b009652007-07-25 00:24:17 +0000114 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroff82113e32007-07-29 16:33:31 +0000115
Nate Begemanaf6ed502008-04-18 23:10:10 +0000116 /// ExtVectorDecls - This is a list all the extended vector types. This allows
117 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroff82113e32007-07-29 16:33:31 +0000118 /// This is only necessary for issuing pretty diagnostics.
Nate Begemanaf6ed502008-04-18 23:10:10 +0000119 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattner2e64c072007-08-10 20:18:51 +0000120
Steve Naroff4b9846d2008-09-28 14:55:53 +0000121 /// ObjCImplementations - Keep track of all class @implementations
122 /// so we can emit errors on duplicates.
Ted Kremenek42730c52008-01-07 19:49:32 +0000123 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattnera7a191c2007-10-07 01:13:46 +0000124
Steve Naroff4b9846d2008-09-28 14:55:53 +0000125 /// ObjCCategoryImpls - Maintain a list of category implementations so
126 /// we can check for duplicates and find local method declarations.
127 llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
128
Ted Kremenek42730c52008-01-07 19:49:32 +0000129 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanianac142de2007-10-09 18:03:53 +0000130 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner042e6e82007-10-09 18:18:24 +0000131 /// find the declarations when needed.
Ted Kremenek42730c52008-01-07 19:49:32 +0000132 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff15208162008-04-02 18:30:49 +0000133
134 /// ObjCInterfaceDecls - Keep track of all class declarations declared
135 /// with @interface, so that we can emit errors on duplicates and
136 /// find the declarations when needed.
137 typedef llvm::DenseMap<const IdentifierInfo*,
138 ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
139 ObjCInterfaceDeclsTy ObjCInterfaceDecls;
140
Steve Naroffe57c21a2008-04-01 23:04:06 +0000141 /// ObjCAliasDecls - Keep track of all class declarations declared
142 /// with @compatibility_alias, so that we can emit errors on duplicates and
143 /// find the declarations when needed. This construct is ancient and will
144 /// likely never be seen. Nevertheless, it is here for compatibility.
Steve Naroff64334ea2008-04-02 00:39:51 +0000145 typedef llvm::DenseMap<const IdentifierInfo*,
146 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroffe57c21a2008-04-01 23:04:06 +0000147 ObjCAliasTy ObjCAliasDecls;
Steve Naroff15208162008-04-02 18:30:49 +0000148
Argiris Kirtzidis38f16712008-07-01 10:37:29 +0000149 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
150 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
151
Douglas Gregore6b5d1d2009-03-02 00:19:53 +0000152 /// \brief A mapping from external names to the most recent
153 /// locally-scoped external declaration with that name.
154 ///
155 /// This map contains external declarations introduced in local
156 /// scoped, e.g.,
157 ///
158 /// \code
159 /// void f() {
160 /// void foo(int, int);
161 /// }
162 /// \endcode
163 ///
164 /// Here, the name "foo" will be associated with the declaration on
165 /// "foo" within f. This name is not visible outside of
166 /// "f". However, we still find it in two cases:
167 ///
168 /// - If we are declaring another external with the name "foo", we
169 /// can find "foo" as a previous declaration, so that the types
170 /// of this external declaration can be checked for
171 /// compatibility.
172 ///
173 /// - If we would implicitly declare "foo" (e.g., due to a call to
174 /// "foo" in C when no prototype or definition is visible), then
175 /// we find this declaration of "foo" and complain that it is
176 /// not visible.
177 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
178
Chris Lattner2a1e2ed2008-04-11 07:00:53 +0000179 IdentifierResolver IdResolver;
180
Chris Lattner2e64c072007-08-10 20:18:51 +0000181 // Enum values used by KnownFunctionIDs (see below).
182 enum {
Ted Kremenek225a14c2008-06-16 18:00:42 +0000183 id_NSLog,
Douglas Gregorb5af7382009-02-14 18:57:46 +0000184 id_NSLogv,
Daniel Dunbar0ab03e62008-10-02 18:44:07 +0000185 id_asprintf,
Chris Lattner2e64c072007-08-10 20:18:51 +0000186 id_vasprintf,
Chris Lattner2e64c072007-08-10 20:18:51 +0000187 id_num_known_functions
188 };
189
190 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
191 /// of known functions used by the semantic analysis to do various
192 /// kinds of checking (e.g. checking format string errors in printf calls).
193 /// This list is populated upon the creation of a Sema object.
Chris Lattnerf7df4d12008-08-23 02:00:52 +0000194 IdentifierInfo* KnownFunctionIDs[id_num_known_functions];
Daniel Dunbar4837ae72008-08-14 22:04:54 +0000195
Steve Naroff415c1832007-10-10 17:32:04 +0000196 /// Translation Unit Scope - useful to Objective-C actions that need
197 /// to lookup file scope declarations in the "ordinary" C decl namespace.
198 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroff9637a9b2007-10-09 22:01:59 +0000199 Scope *TUScope;
Sebastian Redlb93b49c2008-11-11 11:37:55 +0000200
201 /// The C++ "std" namespace, where the standard library resides. Cached here
202 /// by GetStdNamespace
203 NamespaceDecl *StdNamespace;
Sebastian Redlb5ee8742008-12-03 20:26:15 +0000204
205 /// A flag to remember whether the implicit forms of operator new and delete
206 /// have been declared.
207 bool GlobalNewDeleteDeclared;
Steve Naroffee1de132007-10-10 21:53:07 +0000208
Steve Naroff8255b042007-10-14 00:58:41 +0000209 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremenek42730c52008-01-07 19:49:32 +0000210 struct ObjCMethodList {
211 ObjCMethodDecl *Method;
212 ObjCMethodList *Next;
Steve Naroff8255b042007-10-14 00:58:41 +0000213
Ted Kremenek42730c52008-01-07 19:49:32 +0000214 ObjCMethodList() {
Steve Naroff8255b042007-10-14 00:58:41 +0000215 Method = 0;
216 Next = 0;
217 }
Ted Kremenek42730c52008-01-07 19:49:32 +0000218 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff8255b042007-10-14 00:58:41 +0000219 Method = M;
220 Next = C;
221 }
222 };
223 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
224 /// messages to "id". We need to maintain a list, since selectors can have
225 /// differing signatures across classes. In Cocoa, this happens to be
226 /// extremely uncommon (only 1% of selectors are "overloaded").
Ted Kremenek42730c52008-01-07 19:49:32 +0000227 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
228 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Steve Naroffff6c8022009-03-04 15:11:40 +0000229
230 /// Private Helper predicate to check for 'self'.
231 bool isSelfExpr(Expr *RExpr);
Chris Lattner4b009652007-07-25 00:24:17 +0000232public:
Chris Lattnera8c2d592008-02-06 00:46:58 +0000233 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
Chris Lattnera8699562009-02-17 01:09:29 +0000234 ~Sema() {
235 if (PackContext) FreePackedContext();
236 }
Chris Lattner4b009652007-07-25 00:24:17 +0000237
Chris Lattner6d89a8a2009-01-22 19:21:44 +0000238 const LangOptions &getLangOptions() const { return LangOpts; }
Chris Lattnerf9ea6a42008-11-22 08:28:49 +0000239 Diagnostic &getDiagnostics() const { return Diags; }
240 SourceManager &getSourceManager() const { return SourceMgr; }
241
Chris Lattner429558c2008-11-18 21:53:24 +0000242 /// The primitive diagnostic helpers.
Chris Lattnerf9ea6a42008-11-22 08:28:49 +0000243 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
244 return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
245 }
Chris Lattner4b009652007-07-25 00:24:17 +0000246
Chris Lattnerb26b7ad2007-08-31 04:53:24 +0000247 virtual void DeleteExpr(ExprTy *E);
248 virtual void DeleteStmt(StmtTy *S);
249
Sebastian Redl91f9b0a2008-12-13 16:23:55 +0000250 OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); }
Sebastian Redl8b769972009-01-19 00:08:26 +0000251 OwningExprResult Owned(ExprResult R) {
Douglas Gregor10a18fc2009-01-26 22:44:13 +0000252 if (R.isInvalid())
Steve Naroff27959652009-01-21 22:32:33 +0000253 return ExprError();
Douglas Gregor10a18fc2009-01-26 22:44:13 +0000254 return OwningExprResult(*this, R.get());
Sebastian Redl8b769972009-01-19 00:08:26 +0000255 }
Sebastian Redl91f9b0a2008-12-13 16:23:55 +0000256 OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
257
Chris Lattnerc1aea812008-08-23 03:19:52 +0000258 virtual void ActOnEndOfTranslationUnit();
Sebastian Redl5457c5e2009-01-19 22:31:54 +0000259
Chris Lattner4b009652007-07-25 00:24:17 +0000260 //===--------------------------------------------------------------------===//
261 // Type Analysis / Processing: SemaType.cpp.
262 //
Chris Lattner99dbc962008-06-26 06:27:57 +0000263 QualType ConvertDeclSpecToType(const DeclSpec &DS);
Chris Lattner65a57042008-06-29 00:50:08 +0000264 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000265 QualType BuildPointerType(QualType T, unsigned Quals,
266 SourceLocation Loc, DeclarationName Entity);
267 QualType BuildReferenceType(QualType T, unsigned Quals,
268 SourceLocation Loc, DeclarationName Entity);
269 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
270 Expr *ArraySize, unsigned Quals,
271 SourceLocation Loc, DeclarationName Entity);
Douglas Gregorc0139ca2009-02-28 01:04:19 +0000272 QualType BuildFunctionType(QualType T,
273 QualType *ParamTypes, unsigned NumParamTypes,
274 bool Variadic, unsigned Quals,
275 SourceLocation Loc, DeclarationName Entity);
Sebastian Redl66df3ef2008-12-02 14:43:59 +0000276 QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0);
Douglas Gregor6704b312008-11-17 22:58:34 +0000277 DeclarationName GetNameForDeclarator(Declarator &D);
278
Ted Kremenek42730c52008-01-07 19:49:32 +0000279 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahaniandfb1c372007-11-08 23:49:49 +0000280
Douglas Gregorccc0ccc2008-10-22 14:17:15 +0000281 bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
282
Sebastian Redl66df3ef2008-12-02 14:43:59 +0000283 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Sebastian Redlf831eeb2008-11-08 13:00:26 +0000284
Douglas Gregor46fe06e2009-01-19 19:26:10 +0000285 bool DiagnoseIncompleteType(SourceLocation Loc, QualType T, unsigned diag,
286 SourceRange Range1 = SourceRange(),
287 SourceRange Range2 = SourceRange(),
288 QualType PrintType = QualType());
289
Chris Lattner4b009652007-07-25 00:24:17 +0000290 //===--------------------------------------------------------------------===//
291 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
292 //
Chris Lattnerd042d0f2009-03-05 01:25:28 +0000293
294 /// getDeclName - Return a pretty name for the specified decl if possible, or
295 /// an empty string if not. This is used for pretty crash reporting.
296 virtual std::string getDeclName(DeclTy *D);
297
Douglas Gregora60c62e2009-02-09 15:09:02 +0000298 virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Douglas Gregor1075a162009-02-04 17:00:24 +0000299 Scope *S, const CXXScopeSpec *SS);
Chris Lattner2cb744b2009-02-15 22:43:40 +0000300 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){
Douglas Gregorc5cbc242008-12-15 23:53:10 +0000301 return ActOnDeclarator(S, D, LastInGroup, false);
302 }
303 DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
304 bool IsFunctionDefinition);
Douglas Gregore6b5d1d2009-03-02 00:19:53 +0000305 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl,
306 Scope *S);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000307 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
308 QualType R, Decl* LastDeclarator,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000309 Decl* PrevDecl, bool& InvalidDecl,
310 bool &Redeclaration);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000311 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000312 QualType R, Decl* LastDeclarator,
Douglas Gregor92c47912009-02-24 19:23:27 +0000313 NamedDecl* PrevDecl, bool& InvalidDecl,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000314 bool &Redeclaration);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000315 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
316 QualType R, Decl *LastDeclarator,
Douglas Gregoraf682022009-02-24 01:23:02 +0000317 NamedDecl* PrevDecl,
318 bool IsFunctionDefinition,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000319 bool& InvalidDecl, bool &Redeclaration);
Chris Lattner3e254fb2008-04-08 04:40:51 +0000320 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
321 virtual void ActOnParamDefaultArgument(DeclTy *param,
322 SourceLocation EqualLoc,
323 ExprTy *defarg);
Douglas Gregor62ae25a2008-12-24 00:01:03 +0000324 virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
325 SourceLocation EqualLoc);
Douglas Gregor605de8d2008-12-16 21:30:33 +0000326 virtual void ActOnParamDefaultArgumentError(DeclTy *param);
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000327 virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
328 void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit);
Douglas Gregor81c29152008-10-29 00:13:59 +0000329 void ActOnUninitializedDecl(DeclTy *dcl);
Chris Lattner4b009652007-07-25 00:24:17 +0000330 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
331
Douglas Gregor65075ec2009-01-23 16:23:13 +0000332 virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D);
Chris Lattnerea148702007-10-09 17:14:05 +0000333 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argiris Kirtzidis38f16712008-07-01 10:37:29 +0000334 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Steve Naroff8df46022009-02-28 16:59:13 +0000335 virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D);
Sebastian Redl5457c5e2009-01-19 22:31:54 +0000336
Sebastian Redl91f9b0a2008-12-13 16:23:55 +0000337 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
Sebastian Redl91f9b0a2008-12-13 16:23:55 +0000338 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlsson4f7f4412008-02-08 00:33:21 +0000339
Steve Naroff9637a9b2007-10-09 22:01:59 +0000340 /// Scope actions.
341 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
342 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Chris Lattner4b009652007-07-25 00:24:17 +0000343
344 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
345 /// no declarator (e.g. "struct foo;") is parsed.
Sebastian Redlb7605e82008-12-28 15:28:59 +0000346 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Chris Lattner4b009652007-07-25 00:24:17 +0000347
Douglas Gregor723d3332009-01-07 00:43:41 +0000348 bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
349 RecordDecl *AnonRecord);
350 virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
351 RecordDecl *Record);
352
Douglas Gregor98b27542009-01-17 00:42:38 +0000353 virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
Argiris Kirtzidis311db8c2008-11-08 16:45:02 +0000354 SourceLocation KWLoc, const CXXScopeSpec &SS,
355 IdentifierInfo *Name, SourceLocation NameLoc,
Douglas Gregord406b032009-02-06 22:42:48 +0000356 AttributeList *Attr);
Ted Kremenek46a837c2008-09-05 17:16:31 +0000357
Douglas Gregor8acb7272008-12-11 16:49:14 +0000358 virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattnerf7df4d12008-08-23 02:00:52 +0000359 IdentifierInfo *ClassName,
360 llvm::SmallVectorImpl<DeclTy*> &Decls);
Douglas Gregor8acb7272008-12-11 16:49:14 +0000361 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner4b009652007-07-25 00:24:17 +0000362 Declarator &D, ExprTy *BitfieldWidth);
Fariborz Jahanian751c6172008-04-10 23:32:45 +0000363
364 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
365 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian4e0bb982008-04-11 16:55:42 +0000366 tok::ObjCKeywordKind visibility);
Fariborz Jahanian751c6172008-04-10 23:32:45 +0000367
Steve Naroffffeaa552007-09-14 23:09:53 +0000368 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000369 virtual void ActOnFields(Scope* S,
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000370 SourceLocation RecLoc, DeclTy *TagDecl,
371 DeclTy **Fields, unsigned NumFields,
Daniel Dunbarf3944442008-10-03 02:03:53 +0000372 SourceLocation LBrac, SourceLocation RBrac,
373 AttributeList *AttrList);
Douglas Gregordb568cf2009-01-08 20:45:30 +0000374
375 /// ActOnTagStartDefinition - Invoked when we have entered the
376 /// scope of a tag's definition (e.g., for an enumeration, class,
377 /// struct, or union).
378 virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl);
379
380 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
381 /// the definition of a tag (enumeration, class, struct, or union).
382 virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl);
383
Steve Naroff0acc9c92007-09-15 18:49:24 +0000384 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4b009652007-07-25 00:24:17 +0000385 DeclTy *LastEnumConstant,
386 SourceLocation IdLoc, IdentifierInfo *Id,
387 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff0acc9c92007-09-15 18:49:24 +0000388 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Chris Lattner4b009652007-07-25 00:24:17 +0000389 DeclTy **Elements, unsigned NumElements);
Sebastian Redlf831eeb2008-11-08 13:00:26 +0000390
Argiris Kirtzidis054a2632008-11-08 17:17:31 +0000391 DeclContext *getContainingDC(DeclContext *DC);
Argiris Kirtzidis38f16712008-07-01 10:37:29 +0000392
Chris Lattnereee57c02008-04-04 06:12:32 +0000393 /// Set the current declaration context until it gets popped.
Douglas Gregor8acb7272008-12-11 16:49:14 +0000394 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattnerf3874bc2008-04-06 04:47:34 +0000395 void PopDeclContext();
Argiris Kirtzidis95256e62008-06-28 06:07:14 +0000396
Chris Lattnere5cb5862008-12-04 23:50:19 +0000397 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
398 /// to the function decl for the function being parsed. If we're currently
399 /// in a 'block', this returns the containing context.
400 FunctionDecl *getCurFunctionDecl();
401
402 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
403 /// the method decl for the method being parsed. If we're currently
404 /// in a 'block', this returns the containing context.
Daniel Dunbar64789f82008-08-11 05:35:13 +0000405 ObjCMethodDecl *getCurMethodDecl();
Chris Lattnereee57c02008-04-04 06:12:32 +0000406
Chris Lattnere5cb5862008-12-04 23:50:19 +0000407 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
408 /// or C function we're in, otherwise return null. If we're currently
409 /// in a 'block', this returns the containing context.
410 NamedDecl *getCurFunctionOrMethodDecl();
411
Argiris Kirtzidis951f25b2008-04-12 00:47:19 +0000412 /// Add this decl to the scope shadowed decl chains.
413 void PushOnScopeChains(NamedDecl *D, Scope *S);
414
Argiris Kirtzidis90842b62008-09-09 21:18:04 +0000415 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
416 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
417 /// true if 'D' belongs to the given declaration context.
418 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
Douglas Gregor8acb7272008-12-11 16:49:14 +0000419 return IdResolver.isDeclInScope(D, Ctx, Context, S);
Argiris Kirtzidis90842b62008-09-09 21:18:04 +0000420 }
421
Eli Friedman9c0e6f92009-02-28 05:41:13 +0000422
423 void RecursiveCalcJumpScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
424 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
425 llvm::DenseMap<Stmt*, void*>& GotoScopeMap,
426 std::vector<void*>& ScopeStack,
427 Stmt* CurStmt);
428
429 void RecursiveCalcLabelScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
430 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
431 std::vector<void*>& ScopeStack,
432 Stmt* CurStmt,
433 Stmt* ParentCompoundStmt);
434
Chris Lattner9e982502008-02-21 01:07:18 +0000435 /// Subroutines of ActOnDeclarator().
Chris Lattner82bb4792007-11-14 06:34:38 +0000436 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000437 Decl *LastDecl);
Douglas Gregor083c23e2009-02-16 17:45:42 +0000438 bool MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
439 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
Douglas Gregoraf682022009-02-24 01:23:02 +0000440 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregor083c23e2009-02-16 17:45:42 +0000441 bool MergeVarDecl(VarDecl *New, Decl *Old);
442 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Steve Naroffb5e78152008-08-08 17:50:35 +0000443 void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000444
445 /// C++ Overloading.
446 bool IsOverload(FunctionDecl *New, Decl* OldD,
447 OverloadedFunctionDecl::function_iterator &MatchedDecl);
Douglas Gregora3b34bb2008-11-03 19:09:14 +0000448 ImplicitConversionSequence
449 TryImplicitConversion(Expr* From, QualType ToType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000450 bool SuppressUserConversions = false,
451 bool AllowExplicit = false);
Douglas Gregorb72e9da2008-10-31 16:23:19 +0000452 bool IsStandardConversion(Expr *From, QualType ToType,
453 StandardConversionSequence& SCS);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000454 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
455 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
Douglas Gregore819caf2009-02-12 00:15:05 +0000456 bool IsComplexPromotion(QualType FromType, QualType ToType);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000457 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregor6fd35572008-12-19 17:40:08 +0000458 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregor932778b2008-12-19 19:13:09 +0000459 bool isObjCPointerConversion(QualType FromType, QualType ToType,
460 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregorbb461502008-10-24 04:54:22 +0000461 bool CheckPointerConversion(Expr *From, QualType ToType);
Sebastian Redlba387562009-01-25 19:43:20 +0000462 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
463 QualType &ConvertedType);
464 bool CheckMemberPointerConversion(Expr *From, QualType ToType);
Douglas Gregor6573cfd2008-10-21 23:43:52 +0000465 bool IsQualificationConversion(QualType FromType, QualType ToType);
Douglas Gregorb72e9da2008-10-31 16:23:19 +0000466 bool IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000467 UserDefinedConversionSequence& User,
Douglas Gregorb206cc42009-01-30 23:27:23 +0000468 bool AllowConversionFunctions,
469 bool AllowExplicit);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000470
471 ImplicitConversionSequence::CompareKind
472 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
473 const ImplicitConversionSequence& ICS2);
474
475 ImplicitConversionSequence::CompareKind
476 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
477 const StandardConversionSequence& SCS2);
478
Douglas Gregorccc0ccc2008-10-22 14:17:15 +0000479 ImplicitConversionSequence::CompareKind
480 CompareQualificationConversions(const StandardConversionSequence& SCS1,
481 const StandardConversionSequence& SCS2);
482
Douglas Gregor14046502008-10-23 00:40:37 +0000483 ImplicitConversionSequence::CompareKind
484 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
485 const StandardConversionSequence& SCS2);
486
Douglas Gregora3b34bb2008-11-03 19:09:14 +0000487 ImplicitConversionSequence
488 TryCopyInitialization(Expr* From, QualType ToType,
489 bool SuppressUserConversions = false);
Douglas Gregor81c29152008-10-29 00:13:59 +0000490 bool PerformCopyInitialization(Expr *&From, QualType ToType,
491 const char *Flavor);
492
Douglas Gregor5ed15042008-11-18 23:14:02 +0000493 ImplicitConversionSequence
494 TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method);
495 bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method);
496
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000497 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
498 bool PerformContextuallyConvertToBool(Expr *&From);
499
Douglas Gregord2baafd2008-10-21 16:13:35 +0000500 /// OverloadingResult - Capture the result of performing overload
501 /// resolution.
502 enum OverloadingResult {
503 OR_Success, ///< Overload resolution succeeded.
504 OR_No_Viable_Function, ///< No viable function found.
Douglas Gregoraa57e862009-02-18 21:56:37 +0000505 OR_Ambiguous, ///< Ambiguous candidates found.
506 OR_Deleted ///< Overload resoltuion refers to a deleted function.
Douglas Gregord2baafd2008-10-21 16:13:35 +0000507 };
508
509 void AddOverloadCandidate(FunctionDecl *Function,
510 Expr **Args, unsigned NumArgs,
Douglas Gregora3b34bb2008-11-03 19:09:14 +0000511 OverloadCandidateSet& CandidateSet,
512 bool SuppressUserConversions = false);
Douglas Gregor5ed15042008-11-18 23:14:02 +0000513 void AddMethodCandidate(CXXMethodDecl *Method,
514 Expr *Object, Expr **Args, unsigned NumArgs,
515 OverloadCandidateSet& CandidateSet,
Douglas Gregor3257fb52008-12-22 05:46:06 +0000516 bool SuppressUserConversions = false);
Douglas Gregor60714f92008-11-07 22:36:19 +0000517 void AddConversionCandidate(CXXConversionDecl *Conversion,
518 Expr *From, QualType ToType,
519 OverloadCandidateSet& CandidateSet);
Douglas Gregor67fdb5b2008-11-19 22:57:39 +0000520 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
Douglas Gregor4fa58902009-02-26 23:50:07 +0000521 const FunctionProtoType *Proto,
Douglas Gregor67fdb5b2008-11-19 22:57:39 +0000522 Expr *Object, Expr **Args, unsigned NumArgs,
523 OverloadCandidateSet& CandidateSet);
Douglas Gregor48a87322009-02-04 16:44:47 +0000524 bool AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
525 SourceLocation OpLoc,
Douglas Gregor5ed15042008-11-18 23:14:02 +0000526 Expr **Args, unsigned NumArgs,
Douglas Gregor48a87322009-02-04 16:44:47 +0000527 OverloadCandidateSet& CandidateSet,
528 SourceRange OpRange = SourceRange());
Douglas Gregor70d26122008-11-12 17:17:38 +0000529 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
530 Expr **Args, unsigned NumArgs,
Douglas Gregorab141112009-01-13 00:52:54 +0000531 OverloadCandidateSet& CandidateSet,
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000532 bool IsAssignmentOperator = false,
533 unsigned NumContextualBoolArguments = 0);
Douglas Gregor4f6904d2008-11-19 15:42:04 +0000534 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
535 Expr **Args, unsigned NumArgs,
536 OverloadCandidateSet& CandidateSet);
Douglas Gregoraa1da4a2009-02-04 00:32:51 +0000537 void AddArgumentDependentLookupCandidates(DeclarationName Name,
538 Expr **Args, unsigned NumArgs,
539 OverloadCandidateSet& CandidateSet);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000540 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
541 const OverloadCandidate& Cand2);
542 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
543 OverloadCandidateSet::iterator& Best);
544 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
545 bool OnlyViable);
546
Douglas Gregor45014fd2008-11-10 20:40:00 +0000547 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
548 bool Complain);
549 void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
550
Douglas Gregor4646f9c2009-02-04 15:01:18 +0000551 FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee,
552 DeclarationName UnqualifiedName,
Douglas Gregorbf4f0582008-11-26 06:01:48 +0000553 SourceLocation LParenLoc,
554 Expr **Args, unsigned NumArgs,
555 SourceLocation *CommaLocs,
Douglas Gregoraa1da4a2009-02-04 00:32:51 +0000556 SourceLocation RParenLoc,
Douglas Gregor4646f9c2009-02-04 15:01:18 +0000557 bool &ArgumentDependentLookup);
Douglas Gregor3257fb52008-12-22 05:46:06 +0000558 ExprResult
559 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
560 SourceLocation LParenLoc, Expr **Args,
561 unsigned NumArgs, SourceLocation *CommaLocs,
562 SourceLocation RParenLoc);
Douglas Gregor10f3c502008-11-19 21:05:33 +0000563 ExprResult
Douglas Gregora133e262008-12-06 00:22:45 +0000564 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregor10f3c502008-11-19 21:05:33 +0000565 Expr **Args, unsigned NumArgs,
566 SourceLocation *CommaLocs,
567 SourceLocation RParenLoc);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000568
Douglas Gregorddfd9d52008-12-23 00:26:44 +0000569 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
Douglas Gregor7f3fec52008-11-20 16:27:02 +0000570 SourceLocation MemberLoc,
571 IdentifierInfo &Member);
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000572
Chris Lattner7898bf62009-01-06 07:27:21 +0000573 /// Helpers for dealing with function parameters.
Chris Lattner3e254fb2008-04-08 04:40:51 +0000574 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattner3e254fb2008-04-08 04:40:51 +0000575 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregor2b9422f2008-05-07 04:49:29 +0000576 void CheckExtraCXXDefaultArguments(Declarator &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000577
Douglas Gregor5eca99e2009-01-12 18:45:55 +0000578 Scope *getNonFieldDeclScope(Scope *S);
579
Douglas Gregor78d70132009-01-14 22:20:51 +0000580 /// \name Name lookup
581 ///
582 /// These routines provide name lookup that is used during semantic
583 /// analysis to resolve the various kinds of names (identifiers,
584 /// overloaded operator names, constructor names, etc.) into zero or
585 /// more declarations within a particular scope. The major entry
586 /// points are LookupName, which performs unqualified name lookup,
587 /// and LookupQualifiedName, which performs qualified name lookup.
588 ///
589 /// All name lookup is performed based on some specific criteria,
590 /// which specify what names will be visible to name lookup and how
591 /// far name lookup should work. These criteria are important both
592 /// for capturing language semantics (certain lookups will ignore
593 /// certain names, for example) and for performance, since name
594 /// lookup is often a bottleneck in the compilation of C++. Name
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000595 /// lookup criteria is specified via the LookupCriteria enumeration.
Douglas Gregor78d70132009-01-14 22:20:51 +0000596 ///
597 /// The results of name lookup can vary based on the kind of name
598 /// lookup performed, the current language, and the translation
599 /// unit. In C, for example, name lookup will either return nothing
600 /// (no entity found) or a single declaration. In C++, name lookup
601 /// can additionally refer to a set of overloaded functions or
602 /// result in an ambiguity. All of the possible results of name
603 /// lookup are captured by the LookupResult class, which provides
604 /// the ability to distinguish among them.
605 //@{
Douglas Gregor5ff0ee52008-12-30 03:27:21 +0000606
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000607 /// @brief Describes the kind of name lookup to perform.
608 enum LookupNameKind {
609 /// Ordinary name lookup, which finds ordinary names (functions,
610 /// variables, typedefs, etc.) in C and most kinds of names
611 /// (functions, variables, members, types, etc.) in C++.
612 LookupOrdinaryName = 0,
613 /// Tag name lookup, which finds the names of enums, classes,
614 /// structs, and unions.
615 LookupTagName,
616 /// Member name lookup, which finds the names of
617 /// class/struct/union members.
618 LookupMemberName,
Douglas Gregor48a87322009-02-04 16:44:47 +0000619 // Look up of an operator name (e.g., operator+) for use with
620 // operator overloading. This lookup is similar to ordinary name
621 // lookup, but will ignore any declarations that are class
622 // members.
623 LookupOperatorName,
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000624 /// Look up of a name that precedes the '::' scope resolution
625 /// operator in C++. This lookup completely ignores operator,
626 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
627 LookupNestedNameSpecifierName,
628 /// Look up a namespace name within a C++ using directive or
629 /// namespace alias definition, ignoring non-namespace names (C++
630 /// [basic.lookup.udir]p1).
Douglas Gregor1c52c632009-02-24 20:03:32 +0000631 LookupNamespaceName,
632 // Look up an ordinary name that is going to be redeclared as a
633 // name with linkage. This lookup ignores any declarations that
634 // are outside of the current scope unless they have linkage. See
635 // C99 6.2.2p4-5 and C++ [basic.link]p6.
636 LookupRedeclarationWithLinkage
Douglas Gregor78d70132009-01-14 22:20:51 +0000637 };
638
639 /// @brief Represents the results of name lookup.
640 ///
641 /// An instance of the LookupResult class captures the results of a
642 /// single name lookup, which can return no result (nothing found),
643 /// a single declaration, a set of overloaded functions, or an
644 /// ambiguity. Use the getKind() method to determine which of these
645 /// results occurred for a given lookup.
646 ///
647 /// Any non-ambiguous lookup can be converted into a single
Douglas Gregor09be81b2009-02-04 17:27:36 +0000648 /// (possibly NULL) @c NamedDecl* via a conversion function or the
Douglas Gregor78d70132009-01-14 22:20:51 +0000649 /// getAsDecl() method. This conversion permits the common-case
650 /// usage in C and Objective-C where name lookup will always return
651 /// a single declaration.
Douglas Gregord07474b2009-01-17 01:13:24 +0000652 struct LookupResult {
Douglas Gregor78d70132009-01-14 22:20:51 +0000653 /// The kind of entity that is actually stored within the
654 /// LookupResult object.
Douglas Gregord07474b2009-01-17 01:13:24 +0000655 enum {
Douglas Gregor09be81b2009-02-04 17:27:36 +0000656 /// First is a single declaration (a NamedDecl*), which may be NULL.
Douglas Gregor78d70132009-01-14 22:20:51 +0000657 SingleDecl,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000658
Douglas Gregor7a7be652009-02-03 19:21:40 +0000659 /// First is a single declaration (an OverloadedFunctionDecl*).
660 OverloadedDeclSingleDecl,
661
Douglas Gregor78d70132009-01-14 22:20:51 +0000662 /// [First, Last) is an iterator range represented as opaque
663 /// pointers used to reconstruct IdentifierResolver::iterators.
664 OverloadedDeclFromIdResolver,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000665
Douglas Gregor78d70132009-01-14 22:20:51 +0000666 /// [First, Last) is an iterator range represented as opaque
667 /// pointers used to reconstruct DeclContext::lookup_iterators.
668 OverloadedDeclFromDeclContext,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000669
670 /// First is a pointer to a BasePaths structure, which is owned
671 /// by the LookupResult. Last is non-zero to indicate that the
672 /// ambiguity is caused by two names found in base class
673 /// subobjects of different types.
Douglas Gregor7a7be652009-02-03 19:21:40 +0000674 AmbiguousLookupStoresBasePaths,
675
676 /// [First, Last) is an iterator range represented as opaque
677 /// pointers used to reconstruct new'ed Decl*[] array containing
678 /// found ambiguous decls. LookupResult is owner of this array.
679 AmbiguousLookupStoresDecls
680
Douglas Gregor78d70132009-01-14 22:20:51 +0000681 } StoredKind;
682
683 /// The first lookup result, whose contents depend on the kind of
Douglas Gregor09be81b2009-02-04 17:27:36 +0000684 /// lookup result. This may be a NamedDecl* (if StoredKind ==
685 /// SingleDecl), OverloadedFunctionDecl* (if StoredKind ==
686 /// OverloadedDeclSingleDecl), the opaque pointer from an
Douglas Gregor78d70132009-01-14 22:20:51 +0000687 /// IdentifierResolver::iterator (if StoredKind ==
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000688 /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator
689 /// (if StoredKind == OverloadedDeclFromDeclContext), or a
Douglas Gregor7a7be652009-02-03 19:21:40 +0000690 /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor78d70132009-01-14 22:20:51 +0000691 mutable uintptr_t First;
692
693 /// The last lookup result, whose contents depend on the kind of
694 /// lookup result. This may be unused (if StoredKind ==
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000695 /// SingleDecl), it may have the same type as First (for
696 /// overloaded function declarations), or is may be used as a
Douglas Gregor7a7be652009-02-03 19:21:40 +0000697 /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor78d70132009-01-14 22:20:51 +0000698 mutable uintptr_t Last;
699
700 /// Context - The context in which we will build any
701 /// OverloadedFunctionDecl nodes needed by the conversion to
702 /// Decl*.
703 ASTContext *Context;
704
Douglas Gregor78d70132009-01-14 22:20:51 +0000705 /// @brief The kind of entity found by name lookup.
706 enum LookupKind {
707 /// @brief No entity found met the criteria.
708 NotFound = 0,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000709
Douglas Gregor78d70132009-01-14 22:20:51 +0000710 /// @brief Name lookup found a single declaration that met the
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000711 /// criteria. getAsDecl will return this declaration.
Douglas Gregor78d70132009-01-14 22:20:51 +0000712 Found,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000713
Douglas Gregor78d70132009-01-14 22:20:51 +0000714 /// @brief Name lookup found a set of overloaded functions that
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000715 /// met the criteria. getAsDecl will turn this set of overloaded
716 /// functions into an OverloadedFunctionDecl.
Douglas Gregor78d70132009-01-14 22:20:51 +0000717 FoundOverloaded,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000718
719 /// Name lookup results in an ambiguity because multiple
720 /// entities that meet the lookup criteria were found in
721 /// subobjects of different types. For example:
722 /// @code
723 /// struct A { void f(int); }
724 /// struct B { void f(double); }
725 /// struct C : A, B { };
726 /// void test(C c) {
727 /// c.f(0); // error: A::f and B::f come from subobjects of different
728 /// // types. overload resolution is not performed.
729 /// }
730 /// @endcode
731 AmbiguousBaseSubobjectTypes,
732
733 /// Name lookup results in an ambiguity because multiple
734 /// nonstatic entities that meet the lookup criteria were found
735 /// in different subobjects of the same type. For example:
736 /// @code
737 /// struct A { int x; };
738 /// struct B : A { };
739 /// struct C : A { };
740 /// struct D : B, C { };
741 /// int test(D d) {
742 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
743 /// }
744 /// @endcode
Douglas Gregor7a7be652009-02-03 19:21:40 +0000745 AmbiguousBaseSubobjects,
746
747 /// Name lookup results in an ambiguity because multiple definitions
748 /// of entity that meet the lookup criteria were found in different
749 /// declaration contexts.
750 /// @code
751 /// namespace A {
752 /// int i;
753 /// namespace B { int i; }
754 /// int test() {
755 /// using namespace B;
756 /// return i; // error 'i' is found in namespace A and A::B
757 /// }
758 /// }
759 /// @endcode
760 AmbiguousReference
Douglas Gregor78d70132009-01-14 22:20:51 +0000761 };
762
Douglas Gregor09be81b2009-02-04 17:27:36 +0000763 static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D);
Douglas Gregor6beddfe2009-01-15 02:19:31 +0000764
Douglas Gregord07474b2009-01-17 01:13:24 +0000765 static LookupResult CreateLookupResult(ASTContext &Context,
766 IdentifierResolver::iterator F,
767 IdentifierResolver::iterator L);
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000768
Douglas Gregord07474b2009-01-17 01:13:24 +0000769 static LookupResult CreateLookupResult(ASTContext &Context,
770 DeclContext::lookup_iterator F,
771 DeclContext::lookup_iterator L);
Douglas Gregor78d70132009-01-14 22:20:51 +0000772
Douglas Gregord07474b2009-01-17 01:13:24 +0000773 static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths,
774 bool DifferentSubobjectTypes) {
775 LookupResult Result;
Douglas Gregor7a7be652009-02-03 19:21:40 +0000776 Result.StoredKind = AmbiguousLookupStoresBasePaths;
Douglas Gregord07474b2009-01-17 01:13:24 +0000777 Result.First = reinterpret_cast<uintptr_t>(Paths);
778 Result.Last = DifferentSubobjectTypes? 1 : 0;
779 Result.Context = &Context;
780 return Result;
781 }
Douglas Gregor6beddfe2009-01-15 02:19:31 +0000782
Douglas Gregor7a7be652009-02-03 19:21:40 +0000783 template <typename Iterator>
784 static LookupResult CreateLookupResult(ASTContext &Context,
785 Iterator B, std::size_t Len) {
Douglas Gregor09be81b2009-02-04 17:27:36 +0000786 NamedDecl ** Array = new NamedDecl*[Len];
Douglas Gregor7a7be652009-02-03 19:21:40 +0000787 for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B)
788 Array[Idx] = *B;
789 LookupResult Result;
790 Result.StoredKind = AmbiguousLookupStoresDecls;
791 Result.First = reinterpret_cast<uintptr_t>(Array);
792 Result.Last = reinterpret_cast<uintptr_t>(Array + Len);
793 Result.Context = &Context;
794 return Result;
795 }
796
Douglas Gregor78d70132009-01-14 22:20:51 +0000797 LookupKind getKind() const;
798
799 /// @brief Determine whether name look found something.
800 operator bool() const { return getKind() != NotFound; }
801
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000802 /// @brief Determines whether the lookup resulted in an ambiguity.
Douglas Gregor7a7be652009-02-03 19:21:40 +0000803 bool isAmbiguous() const {
804 return StoredKind == AmbiguousLookupStoresBasePaths ||
805 StoredKind == AmbiguousLookupStoresDecls;
806 }
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000807
Douglas Gregor78d70132009-01-14 22:20:51 +0000808 /// @brief Allows conversion of a lookup result into a
809 /// declaration, with the same behavior as getAsDecl.
Douglas Gregor09be81b2009-02-04 17:27:36 +0000810 operator NamedDecl*() const { return getAsDecl(); }
Douglas Gregor78d70132009-01-14 22:20:51 +0000811
Douglas Gregor09be81b2009-02-04 17:27:36 +0000812 NamedDecl* getAsDecl() const;
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000813
814 BasePaths *getBasePaths() const;
Douglas Gregorbd4b0852009-02-02 21:35:47 +0000815
816 /// \brief Iterate over the results of name lookup.
817 ///
818 /// The @c iterator class provides iteration over the results of a
819 /// non-ambiguous name lookup.
820 class iterator {
821 /// The LookupResult structure we're iterating through.
822 LookupResult *Result;
823
824 /// The current position of this iterator within the sequence of
825 /// results. This value will have the same representation as the
826 /// @c First field in the LookupResult structure.
827 mutable uintptr_t Current;
828
829 public:
Douglas Gregor09be81b2009-02-04 17:27:36 +0000830 typedef NamedDecl * value_type;
831 typedef NamedDecl * reference;
832 typedef NamedDecl * pointer;
Douglas Gregorbd4b0852009-02-02 21:35:47 +0000833 typedef std::ptrdiff_t difference_type;
834 typedef std::forward_iterator_tag iterator_category;
835
836 iterator() : Result(0), Current(0) { }
837
838 iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { }
839
840 reference operator*() const;
841
842 pointer operator->() const { return **this; }
843
844 iterator &operator++();
845
846 iterator operator++(int) {
847 iterator tmp(*this);
848 ++(*this);
849 return tmp;
850 }
851
852 friend inline bool operator==(iterator const& x, iterator const& y) {
853 return x.Current == y.Current;
854 }
855
856 friend inline bool operator!=(iterator const& x, iterator const& y) {
857 return x.Current != y.Current;
858 }
859 };
860 friend class iterator;
861
862 iterator begin();
863 iterator end();
Douglas Gregor78d70132009-01-14 22:20:51 +0000864 };
865
Douglas Gregor7a7be652009-02-03 19:21:40 +0000866private:
867 typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy;
868
869 std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name,
870 LookupNameKind NameKind,
871 bool RedeclarationOnly);
872
873public:
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000874 /// Determines whether D is a suitable lookup result according to the
875 /// lookup criteria.
Douglas Gregor1c52c632009-02-24 20:03:32 +0000876 static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind,
Douglas Gregorb96b92d2009-02-05 19:25:20 +0000877 unsigned IDNS) {
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000878 switch (NameKind) {
879 case Sema::LookupOrdinaryName:
880 case Sema::LookupTagName:
881 case Sema::LookupMemberName:
Douglas Gregor1c52c632009-02-24 20:03:32 +0000882 case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000883 return D->isInIdentifierNamespace(IDNS);
884
Douglas Gregor48a87322009-02-04 16:44:47 +0000885 case Sema::LookupOperatorName:
886 return D->isInIdentifierNamespace(IDNS) &&
887 !D->getDeclContext()->isRecord();
888
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000889 case Sema::LookupNestedNameSpecifierName:
890 return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag);
891
892 case Sema::LookupNamespaceName:
893 return isa<NamespaceDecl>(D);
894 }
895
896 assert(false &&
Douglas Gregorb96b92d2009-02-05 19:25:20 +0000897 "isAcceptableLookupResult always returns before this point");
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000898 return false;
899 }
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000900
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000901 LookupResult LookupName(Scope *S, DeclarationName Name,
902 LookupNameKind NameKind,
Douglas Gregor411889e2009-02-13 23:20:09 +0000903 bool RedeclarationOnly = false,
904 bool AllowBuiltinCreation = true,
905 SourceLocation Loc = SourceLocation());
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000906 LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name,
907 LookupNameKind NameKind,
908 bool RedeclarationOnly = false);
909 LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS,
910 DeclarationName Name,
911 LookupNameKind NameKind,
Douglas Gregor411889e2009-02-13 23:20:09 +0000912 bool RedeclarationOnly = false,
913 bool AllowBuiltinCreation = true,
914 SourceLocation Loc = SourceLocation());
Douglas Gregoraa1da4a2009-02-04 00:32:51 +0000915
916 typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet;
917 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
918
919 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
920 AssociatedNamespaceSet &AssociatedNamespaces,
921 AssociatedClassSet &AssociatedClasses);
922
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000923 bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
924 SourceLocation NameLoc,
925 SourceRange LookupRange = SourceRange());
Douglas Gregor78d70132009-01-14 22:20:51 +0000926 //@}
927
Ted Kremenek42730c52008-01-07 19:49:32 +0000928 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000929 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Douglas Gregor411889e2009-02-13 23:20:09 +0000930 Scope *S, bool ForRedeclaration,
931 SourceLocation Loc);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000932 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
933 Scope *S);
Douglas Gregorb5af7382009-02-14 18:57:46 +0000934 void AddKnownFunctionAttributes(FunctionDecl *FD);
Douglas Gregor78d70132009-01-14 22:20:51 +0000935
936 // More parsing and symbol table subroutines.
937
Chris Lattner4b009652007-07-25 00:24:17 +0000938 // Decl attributes - this routine is the top level dispatcher.
Chris Lattner2024f0a2008-06-29 00:16:31 +0000939 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnerd7e83d82008-06-28 23:58:55 +0000940 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lamb2a72bb32008-02-04 02:31:56 +0000941
Steve Naroffb4f48512008-02-10 21:38:56 +0000942 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
943 bool &IncompleteImpl);
Fariborz Jahanian4e0f6452008-12-05 18:18:52 +0000944 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
945 ObjCMethodDecl *IntfMethod);
Sebastian Redlb93b49c2008-11-11 11:37:55 +0000946
947 NamespaceDecl *GetStdNamespace();
Fariborz Jahanianf96ee9e2009-01-12 19:55:42 +0000948
949 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
Steve Naroffb0bf2c92009-02-26 19:11:32 +0000950 ObjCInterfaceDecl *IDecl);
Steve Naroffb4f48512008-02-10 21:38:56 +0000951
Chris Lattner7898bf62009-01-06 07:27:21 +0000952 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbar1d706e92008-09-04 20:01:15 +0000953 /// methods declared in protocol, and those referenced by it.
954 /// \param IDecl - Used for checking for methods which may have been
955 /// inherited.
Steve Naroffb268d2a2008-02-08 22:06:17 +0000956 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
957 ObjCProtocolDecl *PDecl,
Fariborz Jahaniand3952f32007-10-02 20:06:01 +0000958 bool& IncompleteImpl,
Steve Naroff7711ee32007-10-08 21:05:34 +0000959 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbar1d706e92008-09-04 20:01:15 +0000960 const llvm::DenseSet<Selector> &ClsMap,
961 ObjCInterfaceDecl *IDecl);
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +0000962
Steve Naroff89529b12007-10-02 21:43:37 +0000963 /// CheckImplementationIvars - This routine checks if the instance variables
964 /// listed in the implelementation match those listed in the interface.
Ted Kremenek42730c52008-01-07 19:49:32 +0000965 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
966 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroffb4f48512008-02-10 21:38:56 +0000967 SourceLocation Loc);
Steve Naroff89529b12007-10-02 21:43:37 +0000968
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +0000969 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
Chris Lattner7cc13bf2009-03-01 00:56:52 +0000970 /// remains unimplemented in the class or category @implementation.
971 void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl,
972 ObjCContainerDecl* IDecl,
973 bool IncompleteImpl = false);
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +0000974
Fariborz Jahanian67907bd2007-10-05 18:00:57 +0000975 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
976 /// true, or false, accordingly.
Ted Kremenek42730c52008-01-07 19:49:32 +0000977 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Naroffb91afca2008-10-21 10:37:50 +0000978 const ObjCMethodDecl *PrevMethod,
979 bool matchBasedOnSizeAndAlignment = false);
Steve Naroffee1de132007-10-10 21:53:07 +0000980
Steve Naroff8255b042007-10-14 00:58:41 +0000981 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
982 /// unit are added to a global pool. This allows us to efficiently associate
983 /// a selector with a method declaraation for purposes of typechecking
984 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremenek42730c52008-01-07 19:49:32 +0000985 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff8255b042007-10-14 00:58:41 +0000986
Steve Naroff68354f32008-09-30 14:38:43 +0000987 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
988 /// there are multiple signatures.
989 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
990
Steve Naroff8255b042007-10-14 00:58:41 +0000991 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremenek42730c52008-01-07 19:49:32 +0000992 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Chris Lattner4b009652007-07-25 00:24:17 +0000993 //===--------------------------------------------------------------------===//
994 // Statement Parsing Callbacks: SemaStmt.cpp.
995public:
Sebastian Redl76b9ddb2008-12-21 12:04:03 +0000996 virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
997
998 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
999 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1000 MultiStmtArg Elts,
1001 bool isStmtExpr);
1002 virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
1003 SourceLocation EndLoc);
Sebastian Redl0a23e8f2008-12-28 16:13:43 +00001004 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
1005 SourceLocation DotDotDotLoc, ExprArg RHSVal,
Chris Lattnerdaac6942009-03-04 04:23:07 +00001006 SourceLocation ColonLoc);
1007 virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt);
1008
Sebastian Redl0a23e8f2008-12-28 16:13:43 +00001009 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1010 SourceLocation ColonLoc,
1011 StmtArg SubStmt, Scope *CurScope);
Sebastian Redl2437ec62009-01-11 00:38:46 +00001012 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
1013 IdentifierInfo *II,
1014 SourceLocation ColonLoc,
1015 StmtArg SubStmt);
1016 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
1017 StmtArg ThenVal, SourceLocation ElseLoc,
1018 StmtArg ElseVal);
1019 virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
1020 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1021 StmtArg Switch, StmtArg Body);
Sebastian Redl19c74d32009-01-16 23:28:06 +00001022 virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
1023 StmtArg Body);
1024 virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
1025 SourceLocation WhileLoc, ExprArg Cond);
1026
1027 virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
1028 SourceLocation LParenLoc,
1029 StmtArg First, ExprArg Second,
1030 ExprArg Third, SourceLocation RParenLoc,
1031 StmtArg Body);
1032 virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1033 SourceLocation LParenLoc,
1034 StmtArg First, ExprArg Second,
1035 SourceLocation RParenLoc, StmtArg Body);
Sebastian Redl539eb572009-01-18 13:19:59 +00001036
1037 virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1038 SourceLocation LabelLoc,
1039 IdentifierInfo *LabelII);
1040 virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1041 SourceLocation StarLoc,
1042 ExprArg DestExp);
1043 virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
1044 Scope *CurScope);
1045 virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
1046 Scope *CurScope);
1047
1048 virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
1049 ExprArg RetValExp);
1050 OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
1051 Expr *RetValExp);
1052
Sebastian Redlc6b86332009-01-18 16:53:17 +00001053 virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1054 bool IsSimple,
1055 bool IsVolatile,
1056 unsigned NumOutputs,
1057 unsigned NumInputs,
1058 std::string *Names,
1059 MultiExprArg Constraints,
1060 MultiExprArg Exprs,
1061 ExprArg AsmString,
1062 MultiExprArg Clobbers,
1063 SourceLocation RParenLoc);
Sebastian Redlb3860a72009-01-18 17:43:11 +00001064
1065 virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
1066 SourceLocation RParen,
Steve Naroff0e8b96a2009-03-03 19:52:17 +00001067 DeclTy *Parm, StmtArg Body,
Sebastian Redlb3860a72009-01-18 17:43:11 +00001068 StmtArg CatchList);
1069
1070 virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
1071 StmtArg Body);
1072
1073 virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
1074 StmtArg Try,
1075 StmtArg Catch, StmtArg Finally);
1076
1077 virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Steve Naroff590fe482009-02-11 20:05:44 +00001078 ExprArg Throw,
1079 Scope *CurScope);
Sebastian Redlb3860a72009-01-18 17:43:11 +00001080 virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1081 ExprArg SynchExpr,
1082 StmtArg SynchBody);
Sebastian Redlb12ac332008-12-21 16:41:36 +00001083
Sebastian Redl743c8162008-12-22 19:15:10 +00001084 virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D);
1085 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
1086 DeclTy *ExDecl,
1087 StmtArg HandlerBlock);
Sebastian Redl237116b2008-12-22 21:35:02 +00001088 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
1089 StmtArg TryBlock,
1090 MultiStmtArg Handlers);
Sebastian Redlb12ac332008-12-21 16:41:36 +00001091
Chris Lattner4b009652007-07-25 00:24:17 +00001092 //===--------------------------------------------------------------------===//
1093 // Expression Parsing Callbacks: SemaExpr.cpp.
1094
Douglas Gregoraa57e862009-02-18 21:56:37 +00001095 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
Chris Lattner2cb744b2009-02-15 22:43:40 +00001096
Chris Lattner4b009652007-07-25 00:24:17 +00001097 // Primary Expressions.
Douglas Gregor3bb30002009-02-26 21:00:50 +00001098 virtual SourceRange getExprRange(ExprTy *E) const;
1099
Sebastian Redlcd883f72009-01-18 18:53:16 +00001100 virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
1101 IdentifierInfo &II,
1102 bool HasTrailingLParen,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001103 const CXXScopeSpec *SS = 0,
1104 bool isAddressOfOperand = false);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001105 virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S,
Douglas Gregor24094772008-11-19 19:09:45 +00001106 SourceLocation OperatorLoc,
1107 OverloadedOperatorKind Op,
1108 bool HasTrailingLParen,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001109 const CXXScopeSpec &SS,
1110 bool isAddressOfOperand);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001111 virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S,
Douglas Gregor24094772008-11-19 19:09:45 +00001112 SourceLocation OperatorLoc,
1113 TypeTy *Ty,
1114 bool HasTrailingLParen,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001115 const CXXScopeSpec &SS,
1116 bool isAddressOfOperand);
Douglas Gregor566782a2009-01-06 05:10:23 +00001117 DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
1118 bool TypeDependent, bool ValueDependent,
1119 const CXXScopeSpec *SS = 0);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001120 OwningExprResult
Douglas Gregor723d3332009-01-07 00:43:41 +00001121 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1122 FieldDecl *Field,
1123 Expr *BaseObjectExpr = 0,
1124 SourceLocation OpLoc = SourceLocation());
Sebastian Redlcd883f72009-01-18 18:53:16 +00001125 OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
1126 DeclarationName Name,
1127 bool HasTrailingLParen,
1128 const CXXScopeSpec *SS,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001129 bool isAddressOfOperand = false);
Douglas Gregoraee3bf82008-11-18 15:03:34 +00001130
Sebastian Redlcd883f72009-01-18 18:53:16 +00001131 virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
1132 tok::TokenKind Kind);
1133 virtual OwningExprResult ActOnNumericConstant(const Token &);
1134 virtual OwningExprResult ActOnCharacterConstant(const Token &);
1135 virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
1136 ExprArg Val);
Chris Lattner4b009652007-07-25 00:24:17 +00001137
Steve Naroff87d58b42007-09-16 03:34:24 +00001138 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner4b009652007-07-25 00:24:17 +00001139 /// fragments (e.g. "foo" "bar" L"baz").
Sebastian Redl8b769972009-01-19 00:08:26 +00001140 virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
1141 unsigned NumToks);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001142
Chris Lattner4b009652007-07-25 00:24:17 +00001143 // Binary/Unary Operators. 'Tok' is the token for the operator.
Sebastian Redl8b769972009-01-19 00:08:26 +00001144 virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1145 tok::TokenKind Op, ExprArg Input);
1146 virtual OwningExprResult
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001147 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1148 void *TyOrEx, const SourceRange &ArgRange);
1149
Chris Lattner8d9f7962009-01-24 20:17:12 +00001150 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R);
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001151 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1152 const SourceRange &R, bool isSizeof);
Sebastian Redl8b769972009-01-19 00:08:26 +00001153
1154 virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1155 tok::TokenKind Kind,
1156 ExprArg Input);
1157
1158 virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
1159 SourceLocation LLoc,
1160 ExprArg Idx,
1161 SourceLocation RLoc);
1162 virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base,
1163 SourceLocation OpLoc,
1164 tok::TokenKind OpKind,
1165 SourceLocation MemberLoc,
Fariborz Jahanian0cc2ac12009-03-04 22:30:12 +00001166 IdentifierInfo &Member,
1167 DeclTy *ImplDecl=0);
Sebastian Redl8b769972009-01-19 00:08:26 +00001168 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
Douglas Gregor3257fb52008-12-22 05:46:06 +00001169 FunctionDecl *FDecl,
Douglas Gregor4fa58902009-02-26 23:50:07 +00001170 const FunctionProtoType *Proto,
Douglas Gregor3257fb52008-12-22 05:46:06 +00001171 Expr **Args, unsigned NumArgs,
1172 SourceLocation RParenLoc);
Sebastian Redl8b769972009-01-19 00:08:26 +00001173
Steve Naroff87d58b42007-09-16 03:34:24 +00001174 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner4b009652007-07-25 00:24:17 +00001175 /// This provides the location of the left/right parens and a list of comma
1176 /// locations.
Sebastian Redl8b769972009-01-19 00:08:26 +00001177 virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn,
1178 SourceLocation LParenLoc,
1179 MultiExprArg Args,
1180 SourceLocation *CommaLocs,
1181 SourceLocation RParenLoc);
1182
Sebastian Redl5457c5e2009-01-19 22:31:54 +00001183 virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
1184 SourceLocation RParenLoc, ExprArg Op);
1185
1186 virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1187 TypeTy *Ty,
1188 SourceLocation RParenLoc,
1189 ExprArg Op);
1190
1191 virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
1192 MultiExprArg InitList,
1193 InitListDesignations &Designators,
1194 SourceLocation RParenLoc);
1195
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001196 virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
1197 SourceLocation Loc,
1198 bool UsedColonSyntax,
1199 OwningExprResult Init);
1200
Sebastian Redl5457c5e2009-01-19 22:31:54 +00001201 virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1202 tok::TokenKind Kind,
1203 ExprArg LHS, ExprArg RHS);
1204 OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1205 unsigned Opc, Expr *lhs, Expr *rhs);
Douglas Gregord7f915e2008-11-06 23:29:22 +00001206
Steve Naroff87d58b42007-09-16 03:34:24 +00001207 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner4b009652007-07-25 00:24:17 +00001208 /// in the case of a the GNU conditional expr extension.
Sebastian Redl5457c5e2009-01-19 22:31:54 +00001209 virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1210 SourceLocation ColonLoc,
1211 ExprArg Cond, ExprArg LHS,
1212 ExprArg RHS);
Chris Lattner4b009652007-07-25 00:24:17 +00001213
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001214 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1215 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Chris Lattner4b009652007-07-25 00:24:17 +00001216 IdentifierInfo *LabelII);
1217
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001218 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattner4b009652007-07-25 00:24:17 +00001219 SourceLocation RPLoc); // "({..})"
Chris Lattner0d9bcea2007-08-30 17:45:32 +00001220
1221 /// __builtin_offsetof(type, a.b[123][456].c)
Douglas Gregorddfd9d52008-12-23 00:26:44 +00001222 virtual ExprResult ActOnBuiltinOffsetOf(Scope *S,
1223 SourceLocation BuiltinLoc,
Chris Lattner0d9bcea2007-08-30 17:45:32 +00001224 SourceLocation TypeLoc, TypeTy *Arg1,
1225 OffsetOfComponent *CompPtr,
1226 unsigned NumComponents,
1227 SourceLocation RParenLoc);
1228
Steve Naroff63bad2d2007-08-01 22:05:33 +00001229 // __builtin_types_compatible_p(type1, type2)
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001230 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff63bad2d2007-08-01 22:05:33 +00001231 TypeTy *arg1, TypeTy *arg2,
1232 SourceLocation RPLoc);
Steve Naroff93c53012007-08-03 21:21:27 +00001233
1234 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001235 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroff93c53012007-08-03 21:21:27 +00001236 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
1237 SourceLocation RPLoc);
Chris Lattner4b009652007-07-25 00:24:17 +00001238
Anders Carlsson36760332007-10-15 20:28:48 +00001239 // __builtin_va_arg(expr, type)
1240 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1241 ExprTy *expr, TypeTy *type,
1242 SourceLocation RPLoc);
Steve Naroff52a81c02008-09-03 18:15:37 +00001243
Douglas Gregorad4b3792008-11-29 04:51:27 +00001244 // __null
1245 virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1246
Steve Naroff52a81c02008-09-03 18:15:37 +00001247 //===------------------------- "Block" Extension ------------------------===//
1248
1249 /// ActOnBlockStart - This callback is invoked when a block literal is
1250 /// started.
Steve Naroff52059382008-10-10 01:28:17 +00001251 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1252
1253 /// ActOnBlockArguments - This callback allows processing of block arguments.
1254 /// If there are no arguments, this is still invoked.
Mike Stumpc1fddff2009-02-04 22:31:32 +00001255 virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
Steve Naroff52a81c02008-09-03 18:15:37 +00001256
1257 /// ActOnBlockError - If there is an error parsing a block, this callback
1258 /// is invoked to pop the information about the block from the action impl.
1259 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1260
1261 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1262 /// literal was successfully completed. ^(int x){...}
1263 virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
1264 Scope *CurScope);
1265
Chris Lattner2cb744b2009-02-15 22:43:40 +00001266 //===---------------------------- C++ Features --------------------------===//
1267
Argiris Kirtzidis03e6aaf2008-04-27 13:50:30 +00001268 // Act on C++ namespaces
1269 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
1270 IdentifierInfo *Ident,
1271 SourceLocation LBrace);
1272 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
1273
Douglas Gregor5ff0ee52008-12-30 03:27:21 +00001274 virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
1275 SourceLocation UsingLoc,
1276 SourceLocation NamespcLoc,
1277 const CXXScopeSpec &SS,
1278 SourceLocation IdentLoc,
1279 IdentifierInfo *NamespcName,
1280 AttributeList *AttrList);
1281
Douglas Gregor7a7be652009-02-03 19:21:40 +00001282 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
1283
Argiris Kirtzidis9e55d462008-10-06 17:10:33 +00001284 /// AddCXXDirectInitializerToDecl - This action is called immediately after
1285 /// ActOnDeclarator, when a C++ direct initializer is present.
1286 /// e.g: "int x(1);"
1287 virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
1288 SourceLocation LParenLoc,
1289 ExprTy **Exprs, unsigned NumExprs,
1290 SourceLocation *CommaLocs,
1291 SourceLocation RParenLoc);
1292
Douglas Gregor6428e762008-11-05 15:29:30 +00001293 /// InitializationKind - Represents which kind of C++ initialization
1294 /// [dcl.init] a routine is to perform.
1295 enum InitializationKind {
1296 IK_Direct, ///< Direct initialization
1297 IK_Copy, ///< Copy initialization
1298 IK_Default ///< Default initialization
1299 };
1300
Douglas Gregor5870a952008-11-03 20:45:27 +00001301 CXXConstructorDecl *
Douglas Gregor6428e762008-11-05 15:29:30 +00001302 PerformInitializationByConstructor(QualType ClassType,
1303 Expr **Args, unsigned NumArgs,
1304 SourceLocation Loc, SourceRange Range,
Chris Lattner271d4c22008-11-24 05:29:24 +00001305 DeclarationName InitEntity,
Douglas Gregor6428e762008-11-05 15:29:30 +00001306 InitializationKind Kind);
Douglas Gregor5870a952008-11-03 20:45:27 +00001307
Douglas Gregor21a04f32008-10-27 19:41:14 +00001308 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
1309 virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
1310 SourceLocation LAngleBracketLoc, TypeTy *Ty,
1311 SourceLocation RAngleBracketLoc,
1312 SourceLocation LParenLoc, ExprTy *E,
1313 SourceLocation RParenLoc);
Chris Lattner4b009652007-07-25 00:24:17 +00001314
Sebastian Redlb93b49c2008-11-11 11:37:55 +00001315 /// ActOnCXXTypeidOfType - Parse typeid( type-id ).
1316 virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
1317 SourceLocation LParenLoc, bool isType,
1318 void *TyOrExpr, SourceLocation RParenLoc);
1319
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001320 //// ActOnCXXThis - Parse 'this' pointer.
1321 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
1322
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001323 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
1324 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Chris Lattner4b009652007-07-25 00:24:17 +00001325 tok::TokenKind Kind);
Anders Carlssona66cad42007-08-21 17:43:55 +00001326
Chris Lattnera7447ba2008-02-26 00:51:44 +00001327 //// ActOnCXXThrow - Parse throw expressions.
1328 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
1329 ExprTy *expr);
1330
Argiris Kirtzidis7a1e7412008-08-22 15:38:55 +00001331 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
1332 /// Can be interpreted either as function-style casting ("int(x)")
1333 /// or class type construction ("ClassType(x,y,z)")
1334 /// or creation of a value-initialized type ("int()").
1335 virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
1336 TypeTy *TypeRep,
1337 SourceLocation LParenLoc,
1338 ExprTy **Exprs,
1339 unsigned NumExprs,
1340 SourceLocation *CommaLocs,
1341 SourceLocation RParenLoc);
1342
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001343 /// ActOnCXXNew - Parsed a C++ 'new' expression.
1344 virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1345 SourceLocation PlacementLParen,
1346 ExprTy **PlacementArgs, unsigned NumPlaceArgs,
1347 SourceLocation PlacementRParen,
Sebastian Redl66df3ef2008-12-02 14:43:59 +00001348 bool ParenTypeId, Declarator &D,
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001349 SourceLocation ConstructorLParen,
1350 ExprTy **ConstructorArgs, unsigned NumConsArgs,
1351 SourceLocation ConstructorRParen);
Sebastian Redl66df3ef2008-12-02 14:43:59 +00001352 bool CheckAllocatedType(QualType AllocType, const Declarator &D);
Sebastian Redl3b7ec4b2009-02-09 18:24:27 +00001353 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
1354 bool UseGlobal, QualType AllocType, bool IsArray,
Sebastian Redlb5ee8742008-12-03 20:26:15 +00001355 Expr **PlaceArgs, unsigned NumPlaceArgs,
1356 FunctionDecl *&OperatorNew,
1357 FunctionDecl *&OperatorDelete);
Sebastian Redl3b7ec4b2009-02-09 18:24:27 +00001358 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
1359 DeclarationName Name, Expr** Args,
1360 unsigned NumArgs, DeclContext *Ctx,
Sebastian Redlec5f3262008-12-04 22:20:51 +00001361 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlb5ee8742008-12-03 20:26:15 +00001362 void DeclareGlobalNewDelete();
1363 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
1364 QualType Argument);
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001365
1366 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
1367 virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
1368 bool ArrayForm, ExprTy *Operand);
1369
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +00001370 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
1371 /// C++ if/switch/while/for statement.
1372 /// e.g: "if (int x = f()) {...}"
1373 virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
1374 SourceLocation StartLoc,
1375 Declarator &D,
1376 SourceLocation EqualLoc,
1377 ExprTy *AssignExprVal);
1378
Sebastian Redl39c0f6f2009-01-05 20:52:13 +00001379 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
1380 /// pseudo-functions.
1381 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
1382 SourceLocation KWLoc,
1383 SourceLocation LParen,
1384 TypeTy *Ty,
1385 SourceLocation RParen);
1386
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001387 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
1388 /// global scope ('::').
1389 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
1390 SourceLocation CCLoc);
1391
1392 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1393 /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now
1394 /// we want to resolve "bar::". 'SS' is empty or the previously parsed
1395 /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar',
1396 /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'.
1397 /// Returns a CXXScopeTy* object representing the C++ scope.
1398 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1399 const CXXScopeSpec &SS,
1400 SourceLocation IdLoc,
1401 SourceLocation CCLoc,
Douglas Gregorb0212bd2008-11-17 20:34:05 +00001402 IdentifierInfo &II);
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001403
Douglas Gregor0c281a82009-02-25 19:37:18 +00001404 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1405 /// nested-name-specifier that involves a template-id, e.g.,
1406 /// "foo::bar<int, float>::", and now we need to build a scope
1407 /// specifier. \p SS is empty or the previously parsed nested-name
1408 /// part ("foo::"), \p Type is the already-parsed class template
1409 /// specialization (or other template-id that names a type), \p
1410 /// TypeRange is the source range where the type is located, and \p
1411 /// CCLoc is the location of the trailing '::'.
1412 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1413 const CXXScopeSpec &SS,
1414 TypeTy *Type,
1415 SourceRange TypeRange,
1416 SourceLocation CCLoc);
1417
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001418 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1419 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1420 /// After this method is called, according to [C++ 3.4.3p3], names should be
1421 /// looked up in the declarator-id's scope, until the declarator is parsed and
1422 /// ActOnCXXExitDeclaratorScope is called.
1423 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1424 virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
1425
1426 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1427 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1428 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1429 /// Used to indicate that names should revert to being looked up in the
1430 /// defining scope.
Douglas Gregor24effa82008-12-16 00:38:16 +00001431 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001432
Anders Carlssona66cad42007-08-21 17:43:55 +00001433 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnerddd3e632007-12-12 01:04:12 +00001434 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
1435 ExprTy **Strings,
1436 unsigned NumStrings);
Anders Carlsson8be1d402007-08-22 15:14:15 +00001437 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattnercfd61c82007-10-16 22:51:17 +00001438 SourceLocation EncodeLoc,
Anders Carlsson8be1d402007-08-22 15:14:15 +00001439 SourceLocation LParenLoc,
1440 TypeTy *Ty,
1441 SourceLocation RParenLoc);
1442
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001443 // ParseObjCSelectorExpression - Build selector expression for @selector
1444 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
1445 SourceLocation AtLoc,
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001446 SourceLocation SelLoc,
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001447 SourceLocation LParenLoc,
1448 SourceLocation RParenLoc);
1449
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001450 // ParseObjCProtocolExpression - Build protocol expression for @protocol
1451 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
1452 SourceLocation AtLoc,
1453 SourceLocation ProtoLoc,
1454 SourceLocation LParenLoc,
1455 SourceLocation RParenLoc);
Douglas Gregorec93f442008-04-13 21:30:24 +00001456
1457 //===--------------------------------------------------------------------===//
Douglas Gregord8028382009-01-05 19:45:36 +00001458 // C++ Declarations
1459 //
1460 virtual DeclTy *ActOnStartLinkageSpecification(Scope *S,
1461 SourceLocation ExternLoc,
1462 SourceLocation LangLoc,
1463 const char *Lang,
1464 unsigned StrSize,
1465 SourceLocation LBraceLoc);
1466 virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S,
1467 DeclTy *LinkageSpec,
1468 SourceLocation RBraceLoc);
1469
1470
1471 //===--------------------------------------------------------------------===//
Douglas Gregorec93f442008-04-13 21:30:24 +00001472 // C++ Classes
1473 //
Argiris Kirtzidis311db8c2008-11-08 16:45:02 +00001474 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
1475 const CXXScopeSpec *SS);
Douglas Gregorf15ac4b2008-10-31 09:07:45 +00001476
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001477 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
1478 Declarator &D, ExprTy *BitfieldWidth,
1479 ExprTy *Init, DeclTy *LastInGroup);
1480
Douglas Gregora65e8dd2008-11-05 04:29:56 +00001481 virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD,
1482 Scope *S,
1483 IdentifierInfo *MemberOrBase,
1484 SourceLocation IdLoc,
1485 SourceLocation LParenLoc,
1486 ExprTy **Args, unsigned NumArgs,
1487 SourceLocation *CommaLocs,
1488 SourceLocation RParenLoc);
1489
Douglas Gregore640ab62008-11-03 17:51:48 +00001490 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
1491
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001492 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
1493 DeclTy *TagDecl,
1494 SourceLocation LBrac,
1495 SourceLocation RBrac);
1496
Douglas Gregor605de8d2008-12-16 21:30:33 +00001497 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1498 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param);
1499 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1500
Douglas Gregor8210a8e2008-11-05 20:51:48 +00001501 bool CheckConstructorDeclarator(Declarator &D, QualType &R,
1502 FunctionDecl::StorageClass& SC);
Douglas Gregor605de8d2008-12-16 21:30:33 +00001503 bool CheckConstructor(CXXConstructorDecl *Constructor);
Douglas Gregor8210a8e2008-11-05 20:51:48 +00001504 bool CheckDestructorDeclarator(Declarator &D, QualType &R,
1505 FunctionDecl::StorageClass& SC);
Douglas Gregor3ef6c972008-11-07 20:08:42 +00001506 bool CheckConversionDeclarator(Declarator &D, QualType &R,
1507 FunctionDecl::StorageClass& SC);
Douglas Gregor3ef6c972008-11-07 20:08:42 +00001508 DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregorf15ac4b2008-10-31 09:07:45 +00001509
Douglas Gregor14046502008-10-23 00:40:37 +00001510 //===--------------------------------------------------------------------===//
1511 // C++ Derived Classes
1512 //
1513
1514 /// ActOnBaseSpecifier - Parsed a base specifier
Douglas Gregored3a3982009-03-03 04:44:36 +00001515 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
1516 SourceRange SpecifierRange,
1517 bool Virtual, AccessSpecifier Access,
1518 QualType BaseType,
1519 SourceLocation BaseLoc);
Douglas Gregor14046502008-10-23 00:40:37 +00001520 virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl,
1521 SourceRange SpecifierRange,
1522 bool Virtual, AccessSpecifier Access,
Douglas Gregored3a3982009-03-03 04:44:36 +00001523 TypeTy *basetype, SourceLocation
1524 BaseLoc);
Douglas Gregor14046502008-10-23 00:40:37 +00001525
Douglas Gregored3a3982009-03-03 04:44:36 +00001526 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
1527 unsigned NumBases);
Douglas Gregor14046502008-10-23 00:40:37 +00001528 virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
1529 unsigned NumBases);
1530
1531 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregorbb461502008-10-24 04:54:22 +00001532 bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
Douglas Gregor29dfa2f2009-01-15 00:26:24 +00001533 bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria,
1534 BasePaths &Paths);
Douglas Gregor651d1cc2008-10-24 16:17:19 +00001535 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
1536 SourceLocation Loc, SourceRange Range);
Douglas Gregorb9ef0552009-01-16 00:38:09 +00001537 std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
Douglas Gregorec93f442008-04-13 21:30:24 +00001538
Douglas Gregore60e5d32008-11-06 22:13:31 +00001539 //===--------------------------------------------------------------------===//
1540 // C++ Overloaded Operators [C++ 13.5]
1541 //
1542
1543 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
1544
Douglas Gregordd861062008-12-05 18:15:24 +00001545 //===--------------------------------------------------------------------===//
1546 // C++ Templates [C++ 14]
1547 //
Douglas Gregor8e458f42009-02-09 18:46:07 +00001548 virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S,
1549 DeclTy *&TemplateDecl,
1550 const CXXScopeSpec *SS = 0);
Douglas Gregordd861062008-12-05 18:15:24 +00001551 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
Douglas Gregor279272e2009-02-04 19:02:06 +00001552 TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl);
1553
1554 virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename,
1555 SourceLocation KeyLoc,
1556 IdentifierInfo *ParamName,
1557 SourceLocation ParamNameLoc,
Douglas Gregor52473432008-12-24 02:52:09 +00001558 unsigned Depth, unsigned Position);
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001559 virtual void ActOnTypeParameterDefault(DeclTy *TypeParam,
1560 SourceLocation EqualLoc,
1561 SourceLocation DefaultLoc,
1562 TypeTy *Default);
1563
Douglas Gregored3a3982009-03-03 04:44:36 +00001564 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Douglas Gregor52473432008-12-24 02:52:09 +00001565 virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
Douglas Gregor279272e2009-02-04 19:02:06 +00001566 unsigned Depth,
Douglas Gregor52473432008-12-24 02:52:09 +00001567 unsigned Position);
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001568 virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam,
1569 SourceLocation EqualLoc,
1570 ExprArg Default);
Douglas Gregor279272e2009-02-04 19:02:06 +00001571 virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S,
1572 SourceLocation TmpLoc,
1573 TemplateParamsTy *Params,
1574 IdentifierInfo *ParamName,
1575 SourceLocation ParamNameLoc,
1576 unsigned Depth,
1577 unsigned Position);
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001578 virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam,
1579 SourceLocation EqualLoc,
1580 ExprArg Default);
1581
Douglas Gregor52473432008-12-24 02:52:09 +00001582 virtual TemplateParamsTy *
1583 ActOnTemplateParameterList(unsigned Depth,
1584 SourceLocation ExportLoc,
1585 SourceLocation TemplateLoc,
1586 SourceLocation LAngleLoc,
1587 DeclTy **Params, unsigned NumParams,
1588 SourceLocation RAngleLoc);
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001589 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
1590 TemplateParameterList *OldParams);
1591
Douglas Gregord406b032009-02-06 22:42:48 +00001592 virtual DeclTy *
1593 ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK,
1594 SourceLocation KWLoc, const CXXScopeSpec &SS,
1595 IdentifierInfo *Name, SourceLocation NameLoc,
1596 AttributeList *Attr,
1597 MultiTemplateParamsArg TemplateParameterLists);
1598
Douglas Gregora08b6c72009-02-17 23:15:12 +00001599 virtual TypeResult
1600 ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc,
1601 SourceLocation LAngleLoc,
1602 ASTTemplateArgsPtr TemplateArgs,
1603 SourceLocation *TemplateArgLocs,
1604 SourceLocation RAngleLoc,
1605 const CXXScopeSpec *SS);
1606
Douglas Gregor0d93f692009-02-25 22:02:03 +00001607 bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate,
1608 ClassTemplateSpecializationDecl *PrevDecl,
1609 SourceLocation TemplateNameLoc,
1610 SourceRange ScopeSpecifierRange);
1611
Douglas Gregora08b6c72009-02-17 23:15:12 +00001612 virtual DeclTy *
1613 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
1614 SourceLocation KWLoc,
1615 const CXXScopeSpec &SS,
1616 DeclTy *Template,
1617 SourceLocation TemplateNameLoc,
Douglas Gregor8e458f42009-02-09 18:46:07 +00001618 SourceLocation LAngleLoc,
Douglas Gregor6f37b582009-02-09 19:34:22 +00001619 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001620 SourceLocation *TemplateArgLocs,
Douglas Gregor8e458f42009-02-09 18:46:07 +00001621 SourceLocation RAngleLoc,
Douglas Gregora08b6c72009-02-17 23:15:12 +00001622 AttributeList *Attr,
1623 MultiTemplateParamsArg TemplateParameterLists);
Douglas Gregor8e458f42009-02-09 18:46:07 +00001624
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001625 bool CheckTemplateArgumentList(TemplateDecl *Template,
1626 SourceLocation TemplateLoc,
1627 SourceLocation LAngleLoc,
1628 ASTTemplateArgsPtr& TemplateArgs,
1629 SourceLocation *TemplateArgLocs,
Douglas Gregorad964b32009-02-17 01:05:43 +00001630 SourceLocation RAngleLoc,
1631 llvm::SmallVectorImpl<TemplateArgument> &Converted);
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001632
1633 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg,
1634 SourceLocation ArgLoc);
Douglas Gregorad964b32009-02-17 01:05:43 +00001635 bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,
1636 NamedDecl *&Entity);
1637 bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member);
Douglas Gregored3a3982009-03-03 04:44:36 +00001638 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
1639 QualType InstantiatedParamType, Expr *&Arg,
Douglas Gregorad964b32009-02-17 01:05:43 +00001640 llvm::SmallVectorImpl<TemplateArgument> *Converted = 0);
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001641 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg);
Douglas Gregord406b032009-02-06 22:42:48 +00001642 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
1643 TemplateParameterList *Old,
1644 bool Complain,
Douglas Gregore8e367f2009-02-10 00:24:35 +00001645 bool IsTemplateTemplateParm = false,
1646 SourceLocation TemplateArgLoc
1647 = SourceLocation());
Douglas Gregord406b032009-02-06 22:42:48 +00001648
1649 bool CheckTemplateDeclScope(Scope *S,
1650 MultiTemplateParamsArg &TemplateParameterLists);
Douglas Gregor279272e2009-02-04 19:02:06 +00001651
Douglas Gregor74296542009-02-27 19:31:52 +00001652 //===--------------------------------------------------------------------===//
1653 // C++ Template Instantiation
1654 //
1655 QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
1656 unsigned NumTemplateArgs,
1657 SourceLocation Loc, DeclarationName Entity);
Douglas Gregored3a3982009-03-03 04:44:36 +00001658 bool
1659 InstantiateBaseSpecifiers(ClassTemplateSpecializationDecl *ClassTemplateSpec,
1660 ClassTemplateDecl *ClassTemplate);
1661 bool
1662 InstantiateClassTemplateSpecialization(
1663 ClassTemplateSpecializationDecl *ClassTemplateSpec,
1664 bool ExplicitInstantiation);
Douglas Gregor74296542009-02-27 19:31:52 +00001665
Steve Naroff81f1bba2007-09-06 21:24:23 +00001666 // Objective-C declarations.
Chris Lattnerae1ae492008-07-26 04:13:19 +00001667 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
1668 IdentifierInfo *ClassName,
1669 SourceLocation ClassLoc,
1670 IdentifierInfo *SuperName,
1671 SourceLocation SuperLoc,
1672 DeclTy * const *ProtoRefs,
1673 unsigned NumProtoRefs,
1674 SourceLocation EndProtoLoc,
1675 AttributeList *AttrList);
Fariborz Jahanian05d212a2007-10-11 23:42:27 +00001676
1677 virtual DeclTy *ActOnCompatiblityAlias(
1678 SourceLocation AtCompatibilityAliasLoc,
1679 IdentifierInfo *AliasName, SourceLocation AliasLocation,
1680 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff81f1bba2007-09-06 21:24:23 +00001681
Steve Naroff415c1832007-10-10 17:32:04 +00001682 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman43f307d2008-02-20 22:57:40 +00001683 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +00001684 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattner2bdedd62008-07-26 04:03:38 +00001685 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar28680d12008-09-26 04:48:09 +00001686 SourceLocation EndProtoLoc,
1687 AttributeList *AttrList);
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +00001688
Chris Lattner45142b92008-07-26 04:07:02 +00001689 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
1690 IdentifierInfo *ClassName,
1691 SourceLocation ClassLoc,
1692 IdentifierInfo *CategoryName,
1693 SourceLocation CategoryLoc,
1694 DeclTy * const *ProtoRefs,
1695 unsigned NumProtoRefs,
1696 SourceLocation EndProtoLoc);
Fariborz Jahanianf25220e2007-09-18 20:26:58 +00001697
Steve Naroff415c1832007-10-10 17:32:04 +00001698 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman43f307d2008-02-20 22:57:40 +00001699 SourceLocation AtClassImplLoc,
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +00001700 IdentifierInfo *ClassName, SourceLocation ClassLoc,
1701 IdentifierInfo *SuperClassname,
1702 SourceLocation SuperClassLoc);
1703
Steve Naroff415c1832007-10-10 17:32:04 +00001704 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahaniana91aa322007-10-02 16:38:50 +00001705 SourceLocation AtCatImplLoc,
1706 IdentifierInfo *ClassName,
1707 SourceLocation ClassLoc,
1708 IdentifierInfo *CatName,
1709 SourceLocation CatLoc);
1710
Steve Naroff415c1832007-10-10 17:32:04 +00001711 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroffb4dfe362007-10-02 22:39:18 +00001712 IdentifierInfo **IdentList,
1713 unsigned NumElts);
Fariborz Jahanianc716c942007-09-21 15:40:54 +00001714
Steve Naroff415c1832007-10-10 17:32:04 +00001715 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattnere705e5e2008-07-21 22:17:28 +00001716 const IdentifierLocPair *IdentList,
Fariborz Jahanian8f9b1b22008-12-17 01:07:27 +00001717 unsigned NumElts,
1718 AttributeList *attrList);
Fariborz Jahaniana096e1d2007-10-05 21:01:53 +00001719
Chris Lattner2bdedd62008-07-26 04:03:38 +00001720 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattnere705e5e2008-07-21 22:17:28 +00001721 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian91193f62007-10-11 00:55:41 +00001722 unsigned NumProtocols,
Chris Lattnere705e5e2008-07-21 22:17:28 +00001723 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanianed986602008-05-01 00:03:38 +00001724
Daniel Dunbar540ff472008-09-23 21:53:23 +00001725 /// Ensure attributes are consistent with type.
1726 /// \param [in, out] Attributes The attributes to check; they will
1727 /// be modified to be consistent with \arg PropertyTy.
1728 void CheckObjCPropertyAttributes(QualType PropertyTy,
1729 SourceLocation Loc,
1730 unsigned &Attributes);
Steve Naroffab63fd62009-01-08 17:28:14 +00001731 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Fariborz Jahanianed986602008-05-01 00:03:38 +00001732 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1733 ObjCPropertyDecl *SuperProperty,
Chris Lattnerd120b9e2008-11-24 03:54:41 +00001734 const IdentifierInfo *Name);
Fariborz Jahanianed986602008-05-01 00:03:38 +00001735 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanian1e89de32008-04-24 19:58:34 +00001736
Fariborz Jahanianacad6d12008-12-06 23:03:39 +00001737 void MergeProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian33973a22008-05-02 19:17:30 +00001738 DeclTy *MergeProtocols);
1739
Fariborz Jahanianffb68822009-03-02 19:05:07 +00001740 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
1741 ObjCInterfaceDecl *ID);
1742
Fariborz Jahanianacad6d12008-12-06 23:03:39 +00001743 void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian33973a22008-05-02 19:17:30 +00001744 ObjCProtocolDecl *PDecl);
1745
Steve Naroffb82c50f2007-11-11 17:19:15 +00001746 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
1747 DeclTy **allMethods = 0, unsigned allNum = 0,
1748 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahaniand34caf92007-09-26 18:27:25 +00001749
Fariborz Jahanian0ceb4be2008-04-14 23:36:35 +00001750 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian4aa72a72008-05-05 18:51:55 +00001751 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanianb7080ae2008-05-06 18:09:04 +00001752 Selector GetterSel, Selector SetterSel,
Fariborz Jahanianbcda0b42008-11-26 20:01:34 +00001753 DeclTy *ClassCategory, bool *OverridingProperty,
Fariborz Jahanian4aa72a72008-05-05 18:51:55 +00001754 tok::ObjCKeywordKind MethodImplKind);
1755
Fariborz Jahanian78f7e312008-04-18 00:19:30 +00001756 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
1757 SourceLocation PropertyLoc,
1758 bool ImplKind, DeclTy *ClassImplDecl,
1759 IdentifierInfo *PropertyId,
1760 IdentifierInfo *PropertyIvar);
1761
Steve Naroff3774dd92007-10-26 20:53:56 +00001762 virtual DeclTy *ActOnMethodDeclaration(
1763 SourceLocation BeginLoc, // location of the + or -.
1764 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanian8473b222007-11-09 19:52:12 +00001765 tok::TokenKind MethodType,
Ted Kremenek42730c52008-01-07 19:49:32 +00001766 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +00001767 Selector Sel,
Steve Naroff4ed9d662007-09-27 14:38:14 +00001768 // optional arguments. The number of types/arguments is obtained
1769 // from the Sel.getNumArgs().
Ted Kremenek42730c52008-01-07 19:49:32 +00001770 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Fariborz Jahanian89d53042009-01-09 00:38:19 +00001771 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroff29fe7462007-11-15 12:35:21 +00001772 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
1773 bool isVariadic = false);
Steve Naroff52664182007-10-16 23:12:48 +00001774
Steve Naroff4b129152009-02-26 15:55:06 +00001775 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
1776 // Will search "local" class/category implementations for a method decl.
Fariborz Jahanian271f9062009-03-04 18:15:57 +00001777 // Will also search in class's root looking for instance method.
Steve Naroff4b129152009-02-26 15:55:06 +00001778 // Returns 0 if no method is found.
Fariborz Jahanian271f9062009-03-04 18:15:57 +00001779 ObjCMethodDecl *LookupPrivateOrRootMethod(Selector Sel, ObjCInterfaceDecl *CDecl);
Steve Naroff4b129152009-02-26 15:55:06 +00001780
Steve Naroff4ed9d662007-09-27 14:38:14 +00001781 // ActOnClassMessage - used for both unary and keyword messages.
1782 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff9f176d12007-11-15 13:05:42 +00001783 // is obtained from NumArgs.
Steve Naroff4ed9d662007-09-27 14:38:14 +00001784 virtual ExprResult ActOnClassMessage(
Fariborz Jahanian2ce5dc52007-11-12 20:13:27 +00001785 Scope *S,
Anders Carlssonb42900d2009-02-14 18:21:46 +00001786 IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,
1787 SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac,
Steve Naroff9f176d12007-11-15 13:05:42 +00001788 ExprTy **ArgExprs, unsigned NumArgs);
Steve Naroff4ed9d662007-09-27 14:38:14 +00001789
1790 // ActOnInstanceMessage - used for both unary and keyword messages.
1791 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff9f176d12007-11-15 13:05:42 +00001792 // is obtained from NumArgs.
Steve Naroff4ed9d662007-09-27 14:38:14 +00001793 virtual ExprResult ActOnInstanceMessage(
Steve Naroff6cb1d362007-09-28 22:22:11 +00001794 ExprTy *receiver, Selector Sel,
Anders Carlssonb42900d2009-02-14 18:21:46 +00001795 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroff9f176d12007-11-15 13:05:42 +00001796 ExprTy **ArgExprs, unsigned NumArgs);
Daniel Dunbar81c7d472008-10-14 05:35:18 +00001797
1798 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
1799 virtual void ActOnPragmaPack(PragmaPackKind Kind,
1800 IdentifierInfo *Name,
1801 ExprTy *Alignment,
1802 SourceLocation PragmaLoc,
1803 SourceLocation LParenLoc,
1804 SourceLocation RParenLoc);
Chris Lattnera8699562009-02-17 01:09:29 +00001805
1806 /// getPragmaPackAlignment() - Return the current alignment as specified by
1807 /// the current #pragma pack directive, or 0 if none is currently active.
1808 unsigned getPragmaPackAlignment() const;
1809
1810 /// FreePackedContext - Deallocate and null out PackContext.
1811 void FreePackedContext();
Daniel Dunbar81c7d472008-10-14 05:35:18 +00001812
Chris Lattnere992d6c2008-01-16 19:17:22 +00001813 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
1814 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregor70d26122008-11-12 17:17:38 +00001815 /// If isLvalue, the result of the cast is an lvalue.
1816 void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
Chris Lattnere992d6c2008-01-16 19:17:22 +00001817
Chris Lattner4b009652007-07-25 00:24:17 +00001818 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner83bd5eb2007-12-28 05:29:59 +00001819 // functions and arrays to their respective pointers (C99 6.3.2.1).
1820 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman86ad5222008-05-27 03:33:27 +00001821
Chris Lattner4b009652007-07-25 00:24:17 +00001822 // DefaultFunctionArrayConversion - converts functions and arrays
1823 // to their respective pointers (C99 6.3.2.1).
1824 void DefaultFunctionArrayConversion(Expr *&expr);
1825
Steve Naroffdb65e052007-08-28 23:30:39 +00001826 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
1827 // do not have a prototype. Integer promotions are performed on each
1828 // argument, and arguments that have type float are promoted to double.
Chris Lattner83bd5eb2007-12-28 05:29:59 +00001829 void DefaultArgumentPromotion(Expr *&Expr);
Anders Carlsson4b8e38c2009-01-16 16:48:51 +00001830
1831 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
1832 enum VariadicCallType {
1833 VariadicFunction,
1834 VariadicBlock,
1835 VariadicMethod
1836 };
1837
1838 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
1839 // will warn if the resulting type is not a POD type.
1840 void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
Steve Naroffdb65e052007-08-28 23:30:39 +00001841
Chris Lattner4b009652007-07-25 00:24:17 +00001842 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
1843 // operands and then handles various conversions that are common to binary
1844 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
1845 // routine returns the first non-arithmetic type found. The client is
1846 // responsible for emitting appropriate error diagnostics.
Steve Naroff8f708362007-08-24 19:07:16 +00001847 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
1848 bool isCompAssign = false);
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001849
Douglas Gregor70d26122008-11-12 17:17:38 +00001850 /// UsualArithmeticConversionsType - handles the various conversions
1851 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
1852 /// and returns the result type of that conversion.
1853 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
1854
1855
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001856 /// AssignConvertType - All of the 'assignment' semantic checks return this
1857 /// enum to indicate whether the assignment was allowed. These checks are
1858 /// done for simple assignments, as well as initialization, return from
1859 /// function, argument passing, etc. The query is phrased in terms of a
1860 /// source and destination type.
Chris Lattner005ed752008-01-04 18:04:52 +00001861 enum AssignConvertType {
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001862 /// Compatible - the types are compatible according to the standard.
Chris Lattner4b009652007-07-25 00:24:17 +00001863 Compatible,
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001864
1865 /// PointerToInt - The assignment converts a pointer to an int, which we
1866 /// accept as an extension.
1867 PointerToInt,
1868
1869 /// IntToPointer - The assignment converts an int to a pointer, which we
1870 /// accept as an extension.
1871 IntToPointer,
1872
1873 /// FunctionVoidPointer - The assignment is between a function pointer and
1874 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattner4ca3d772008-01-03 22:56:36 +00001875 FunctionVoidPointer,
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001876
1877 /// IncompatiblePointer - The assignment is between two pointers types that
1878 /// are not compatible, but we accept them as an extension.
Chris Lattner4b009652007-07-25 00:24:17 +00001879 IncompatiblePointer,
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001880
1881 /// CompatiblePointerDiscardsQualifiers - The assignment discards
1882 /// c/v/r qualifiers, which we accept as an extension.
1883 CompatiblePointerDiscardsQualifiers,
Steve Naroff3454b6c2008-09-04 15:10:53 +00001884
Anders Carlsson355ed052009-01-30 23:17:46 +00001885 /// IncompatibleVectors - The assignment is between two vector types that
1886 /// have the same size, which we accept as an extension.
1887 IncompatibleVectors,
1888
Steve Naroff6f373332008-09-04 15:31:07 +00001889 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff3454b6c2008-09-04 15:10:53 +00001890 /// pointer. We disallow this.
1891 IntToBlockPointer,
1892
Steve Naroff6f373332008-09-04 15:31:07 +00001893 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff3454b6c2008-09-04 15:10:53 +00001894 /// pointers types that are not compatible.
1895 IncompatibleBlockPointer,
1896
Steve Naroff19608432008-10-14 22:18:38 +00001897 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
1898 /// id type and something else (that is incompatible with it). For example,
1899 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
1900 IncompatibleObjCQualifiedId,
1901
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001902 /// Incompatible - We reject this conversion outright, it is invalid to
1903 /// represent it in the AST.
1904 Incompatible
Chris Lattner4b009652007-07-25 00:24:17 +00001905 };
Chris Lattner005ed752008-01-04 18:04:52 +00001906
1907 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
1908 /// assignment conversion type specified by ConvTy. This returns true if the
1909 /// conversion was invalid or false if the conversion was accepted.
1910 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
1911 SourceLocation Loc,
1912 QualType DstType, QualType SrcType,
1913 Expr *SrcExpr, const char *Flavor);
1914
1915 /// CheckAssignmentConstraints - Perform type checking for assignment,
1916 /// argument passing, variable initialization, and function return values.
1917 /// This routine is only used by the following two methods. C99 6.5.16.
1918 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Chris Lattner4b009652007-07-25 00:24:17 +00001919
Steve Naroff87d58b42007-09-16 03:34:24 +00001920 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001921 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Chris Lattner4b009652007-07-25 00:24:17 +00001922 // this routine performs the default function/array converions.
Chris Lattner005ed752008-01-04 18:04:52 +00001923 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
1924 Expr *&rExpr);
Chris Lattner4b009652007-07-25 00:24:17 +00001925 // CheckCompoundAssignmentConstraints - Type check without performing any
1926 // conversions. For compound assignments, the "Check...Operands" methods
1927 // perform the necessary conversions.
Chris Lattner005ed752008-01-04 18:04:52 +00001928 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
1929 QualType rhs);
Chris Lattner4b009652007-07-25 00:24:17 +00001930
1931 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner005ed752008-01-04 18:04:52 +00001932 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
1933 QualType rhsType);
Steve Naroff3454b6c2008-09-04 15:10:53 +00001934
1935 // Helper function for CheckAssignmentConstraints involving two
1936 // blcok pointer types.
1937 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
1938 QualType rhsType);
Douglas Gregor1815b3b2008-09-12 00:47:35 +00001939
1940 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregorbb461502008-10-24 04:54:22 +00001941
Douglas Gregor6fd35572008-12-19 17:40:08 +00001942 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +00001943 const char *Flavor, bool AllowExplicit = false);
1944 bool PerformImplicitConversion(Expr *&From, QualType ToType,
1945 const ImplicitConversionSequence& ICS,
Douglas Gregor6fd35572008-12-19 17:40:08 +00001946 const char *Flavor);
Douglas Gregorbb461502008-10-24 04:54:22 +00001947 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor6fd35572008-12-19 17:40:08 +00001948 const StandardConversionSequence& SCS,
1949 const char *Flavor);
Sebastian Redl95216a62009-02-07 00:15:38 +00001950
Chris Lattner4b009652007-07-25 00:24:17 +00001951 /// the following "Check" methods will return a valid/converted QualType
1952 /// or a null QualType (indicating an error diagnostic was issued).
Sebastian Redl95216a62009-02-07 00:15:38 +00001953
1954 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
Chris Lattner2c8bff72007-12-12 05:47:28 +00001955 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Sebastian Redlaa4c3732009-02-07 20:10:22 +00001956 QualType CheckPointerToMemberOperands( // C++ 5.5
Sebastian Redl95216a62009-02-07 00:15:38 +00001957 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
Chris Lattner4b009652007-07-25 00:24:17 +00001958 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Sebastian Redl95216a62009-02-07 00:15:38 +00001959 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +00001960 inline QualType CheckRemainderOperands( // C99 6.5.5
Sebastian Redl95216a62009-02-07 00:15:38 +00001961 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +00001962 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +00001963 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +00001964 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +00001965 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +00001966 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff8f708362007-08-24 19:07:16 +00001967 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner254f3bc2007-08-26 01:18:55 +00001968 inline QualType CheckCompareOperands( // C99 6.5.8/9
1969 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Chris Lattner4b009652007-07-25 00:24:17 +00001970 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Sebastian Redl95216a62009-02-07 00:15:38 +00001971 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +00001972 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
1973 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
1974 // CheckAssignmentOperands is used for both simple and compound assignment.
1975 // For simple assignment, pass both expressions and a null converted type.
1976 // For compound assignment, pass both expressions and the converted type.
1977 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0f32f432007-08-24 22:33:52 +00001978 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Chris Lattner4b009652007-07-25 00:24:17 +00001979 inline QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner1eafdea2008-11-18 01:30:42 +00001980 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Chris Lattner4b009652007-07-25 00:24:17 +00001981 inline QualType CheckConditionalOperands( // C99 6.5.15
1982 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begemanc5f0f652008-07-14 18:02:46 +00001983
1984 /// type checking for vector binary operators.
1985 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
1986 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
1987 SourceLocation l, bool isRel);
Chris Lattner4b009652007-07-25 00:24:17 +00001988
Steve Naroff87d58b42007-09-16 03:34:24 +00001989 /// type checking unary operators (subroutines of ActOnUnaryOp).
Chris Lattner4b009652007-07-25 00:24:17 +00001990 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redl0440c8c2008-12-20 09:35:34 +00001991 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
1992 bool isInc);
Chris Lattner4b009652007-07-25 00:24:17 +00001993 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
1994 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattner57e5f7e2009-02-17 08:12:06 +00001995 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
Steve Naroff1b8a46c2007-07-27 22:15:19 +00001996
1997 /// type checking primary expressions.
Nate Begemanaf6ed502008-04-18 23:10:10 +00001998 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Naroff1b8a46c2007-07-27 22:15:19 +00001999 IdentifierInfo &Comp, SourceLocation CmpLoc);
2000
Steve Naroffe14e5542007-09-02 02:04:30 +00002001 /// type checking declaration initializers (C99 6.7.8)
Douglas Gregor6428e762008-11-05 15:29:30 +00002002 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +00002003 SourceLocation InitLoc,DeclarationName InitEntity,
2004 bool DirectInit);
Douglas Gregor849afc32009-01-29 00:45:39 +00002005 bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
Steve Narofff0b23542008-01-10 22:15:12 +00002006 bool CheckForConstantInitializer(Expr *e, QualType t);
Steve Naroffcb69fb72007-12-10 22:44:33 +00002007
Douglas Gregor538a4c22009-02-02 17:43:21 +00002008 bool CheckValueInitialization(QualType Type, SourceLocation Loc);
Argiris Kirtzidis95de23a2008-08-16 20:27:34 +00002009
Douglas Gregor81c29152008-10-29 00:13:59 +00002010 // type checking C++ declaration initializers (C++ [dcl.init]).
2011
2012 /// ReferenceCompareResult - Expresses the result of comparing two
2013 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
2014 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
2015 enum ReferenceCompareResult {
2016 /// Ref_Incompatible - The two types are incompatible, so direct
2017 /// reference binding is not possible.
2018 Ref_Incompatible = 0,
2019 /// Ref_Related - The two types are reference-related, which means
2020 /// that their unqualified forms (T1 and T2) are either the same
2021 /// or T1 is a base class of T2.
2022 Ref_Related,
2023 /// Ref_Compatible_With_Added_Qualification - The two types are
2024 /// reference-compatible with added qualification, meaning that
2025 /// they are reference-compatible and the qualifiers on T1 (cv1)
2026 /// are greater than the qualifiers on T2 (cv2).
2027 Ref_Compatible_With_Added_Qualification,
2028 /// Ref_Compatible - The two types are reference-compatible and
2029 /// have equivalent qualifiers (cv1 == cv2).
2030 Ref_Compatible
2031 };
2032
Douglas Gregor2aecd1f2008-10-29 02:00:59 +00002033 ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
2034 bool& DerivedToBase);
Douglas Gregor81c29152008-10-29 00:13:59 +00002035
2036 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregora3b34bb2008-11-03 19:09:14 +00002037 ImplicitConversionSequence *ICS = 0,
Douglas Gregor6214d8a2009-01-14 15:45:31 +00002038 bool SuppressUserConversions = false,
2039 bool AllowExplicit = false);
Douglas Gregor81c29152008-10-29 00:13:59 +00002040
Argiris Kirtzidis95de23a2008-08-16 20:27:34 +00002041 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar5ad49de2008-08-20 03:55:42 +00002042 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroff0d4e6ad2008-01-22 00:55:40 +00002043
Anders Carlsson74375622007-11-27 07:16:40 +00002044 // CheckVectorCast - check type constraints for vectors.
2045 // Since vectors are an extension, there are no C standard reference for this.
2046 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssonf257b4c2007-11-27 05:51:55 +00002047 // returns true if the cast is invalid
2048 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
2049
Daniel Dunbar842b5e22008-09-11 00:01:56 +00002050 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
2051 /// \param Method - May be null.
2052 /// \param [out] ReturnType - The return type of the send.
2053 /// \return true iff there were any incompatible types.
Daniel Dunbar7776e102008-09-11 00:50:25 +00002054 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattner3a8f2942008-11-24 03:33:13 +00002055 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbar842b5e22008-09-11 00:01:56 +00002056 SourceLocation lbrac, SourceLocation rbrac,
2057 QualType &ReturnType);
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +00002058
2059 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
2060 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff52664182007-10-16 23:12:48 +00002061
Chris Lattner3429a812007-08-23 05:46:52 +00002062 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
2063 /// the specified width and sign. If an overflow occurs, detect it and emit
2064 /// the specified diagnostic.
2065 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
2066 unsigned NewWidth, bool NewSign,
2067 SourceLocation Loc, unsigned DiagID);
2068
Chris Lattnerfe1f4032008-04-07 05:30:13 +00002069 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
2070 bool ForCompare);
2071
Anders Carlsson0a6ab172008-11-04 16:57:32 +00002072 /// Checks that the Objective-C declaration is declared in the global scope.
2073 /// Emits an error and marks the declaration as invalid if it's not declared
2074 /// in the global scope.
2075 bool CheckObjCDeclScope(Decl *D);
2076
Anders Carlsson36760332007-10-15 20:28:48 +00002077 void InitBuiltinVaListType();
Eli Friedman48fb3ee2008-06-03 21:01:11 +00002078
Anders Carlssond5201b92008-11-30 19:50:32 +00002079 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
2080 /// and reports the appropriate diagnostics. Returns false on success.
2081 /// Can optionally return the value of the expression.
Anders Carlsson108229a2008-12-06 20:33:04 +00002082 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson511425a2008-12-01 02:17:22 +00002083
Anders Carlsson108229a2008-12-06 20:33:04 +00002084 /// VerifyBitField - verifies that a bit field expression is an ICE and has
2085 /// the correct width, and that the field type is valid.
2086 /// Returns false on success.
2087 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
2088 QualType FieldTy, const Expr *BitWidth);
Sebastian Redl8b769972009-01-19 00:08:26 +00002089
Chris Lattner2e64c072007-08-10 20:18:51 +00002090 //===--------------------------------------------------------------------===//
2091 // Extra semantic analysis beyond the C type system
Chris Lattner83bd5eb2007-12-28 05:29:59 +00002092private:
Sebastian Redl8b769972009-01-19 00:08:26 +00002093 Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl,
2094 CallExpr *TheCall);
Chris Lattnerf17cb362009-02-18 17:49:48 +00002095 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
2096 unsigned ByteNo) const;
Chris Lattner81f5be22009-02-18 06:01:06 +00002097 bool CheckObjCString(Expr *Arg);
Chris Lattner83bd5eb2007-12-28 05:29:59 +00002098 bool SemaBuiltinVAStart(CallExpr *TheCall);
2099 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedman8c50c622008-05-20 08:23:37 +00002100 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Sebastian Redl8b769972009-01-19 00:08:26 +00002101 Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbar5b0de852008-07-21 22:59:13 +00002102 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbar30ad42d2008-09-03 21:13:56 +00002103 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Ted Kremenek8c797c02009-01-12 23:09:09 +00002104 bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg,
Douglas Gregorb5af7382009-02-14 18:57:46 +00002105 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek8c797c02009-01-12 23:09:09 +00002106 void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr,
2107 CallExpr *TheCall, bool HasVAListArg,
Douglas Gregorb5af7382009-02-14 18:57:46 +00002108 unsigned format_idx, unsigned firstDataArg);
2109 void CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
2110 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek45925ab2007-08-17 16:46:58 +00002111 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
2112 SourceLocation ReturnLoc);
Ted Kremenek30c66752007-11-25 00:58:00 +00002113 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Chris Lattner4b009652007-07-25 00:24:17 +00002114};
2115
Steve Naroff52a81c02008-09-03 18:15:37 +00002116/// BlockSemaInfo - When a block is being parsed, this contains information
2117/// about the block. It is pointed to from Sema::CurBlock.
2118struct BlockSemaInfo {
2119 llvm::SmallVector<ParmVarDecl*, 8> Params;
Steve Naroff52a81c02008-09-03 18:15:37 +00002120 bool hasPrototype;
2121 bool isVariadic;
Mike Stumpae93d652009-02-19 22:01:56 +00002122 bool hasBlockDeclRefExprs;
2123
Steve Naroff95029d92008-10-08 18:44:00 +00002124 BlockDecl *TheDecl;
2125
Chris Lattner1f9e60f2009-02-18 07:09:44 +00002126 /// TheScope - This is the scope for the block itself, which contains
Steve Naroff52a81c02008-09-03 18:15:37 +00002127 /// arguments etc.
2128 Scope *TheScope;
2129
2130 /// ReturnType - This will get set to block result type, by looking at
2131 /// return types, if any, in the block body.
2132 Type *ReturnType;
2133
2134 /// PrevBlockInfo - If this is nested inside another block, this points
2135 /// to the outer block.
2136 BlockSemaInfo *PrevBlockInfo;
2137};
Ted Kremenek0c97e042009-02-07 01:47:29 +00002138
2139//===--------------------------------------------------------------------===//
2140// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
2141template <typename T>
2142class ExprOwningPtr : public Action::ExprArg {
2143public:
2144 ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {};
2145
2146 void reset(T* p) { Action::ExprArg::operator=(p); }
2147 T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
2148 T* take() { return static_cast<T*>(Action::ExprArg::take()); }
2149 T* release() { return take(); }
2150
2151 T& operator*() const { return *get(); }
2152 T* operator->() const { return get(); }
2153};
2154
Chris Lattner4b009652007-07-25 00:24:17 +00002155} // end namespace clang
2156
2157#endif