blob: 31a8c3889dbea1fbeb3f974cfbdf1c66195ae440 [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 //
Douglas Gregora60c62e2009-02-09 15:09:02 +0000293 virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Douglas Gregor1075a162009-02-04 17:00:24 +0000294 Scope *S, const CXXScopeSpec *SS);
Chris Lattner2cb744b2009-02-15 22:43:40 +0000295 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){
Douglas Gregorc5cbc242008-12-15 23:53:10 +0000296 return ActOnDeclarator(S, D, LastInGroup, false);
297 }
298 DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
299 bool IsFunctionDefinition);
Douglas Gregore6b5d1d2009-03-02 00:19:53 +0000300 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl,
301 Scope *S);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000302 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
303 QualType R, Decl* LastDeclarator,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000304 Decl* PrevDecl, bool& InvalidDecl,
305 bool &Redeclaration);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000306 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000307 QualType R, Decl* LastDeclarator,
Douglas Gregor92c47912009-02-24 19:23:27 +0000308 NamedDecl* PrevDecl, bool& InvalidDecl,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000309 bool &Redeclaration);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000310 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
311 QualType R, Decl *LastDeclarator,
Douglas Gregoraf682022009-02-24 01:23:02 +0000312 NamedDecl* PrevDecl,
313 bool IsFunctionDefinition,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000314 bool& InvalidDecl, bool &Redeclaration);
Chris Lattner3e254fb2008-04-08 04:40:51 +0000315 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
316 virtual void ActOnParamDefaultArgument(DeclTy *param,
317 SourceLocation EqualLoc,
318 ExprTy *defarg);
Douglas Gregor62ae25a2008-12-24 00:01:03 +0000319 virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
320 SourceLocation EqualLoc);
Douglas Gregor605de8d2008-12-16 21:30:33 +0000321 virtual void ActOnParamDefaultArgumentError(DeclTy *param);
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000322 virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
323 void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit);
Douglas Gregor81c29152008-10-29 00:13:59 +0000324 void ActOnUninitializedDecl(DeclTy *dcl);
Chris Lattner4b009652007-07-25 00:24:17 +0000325 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
326
Douglas Gregor65075ec2009-01-23 16:23:13 +0000327 virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D);
Chris Lattnerea148702007-10-09 17:14:05 +0000328 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argiris Kirtzidis38f16712008-07-01 10:37:29 +0000329 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Steve Naroff8df46022009-02-28 16:59:13 +0000330 virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclTy *D);
Sebastian Redl5457c5e2009-01-19 22:31:54 +0000331
Sebastian Redl91f9b0a2008-12-13 16:23:55 +0000332 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
Sebastian Redl91f9b0a2008-12-13 16:23:55 +0000333 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlsson4f7f4412008-02-08 00:33:21 +0000334
Steve Naroff9637a9b2007-10-09 22:01:59 +0000335 /// Scope actions.
336 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
337 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Chris Lattner4b009652007-07-25 00:24:17 +0000338
339 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
340 /// no declarator (e.g. "struct foo;") is parsed.
Sebastian Redlb7605e82008-12-28 15:28:59 +0000341 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Chris Lattner4b009652007-07-25 00:24:17 +0000342
Douglas Gregor723d3332009-01-07 00:43:41 +0000343 bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
344 RecordDecl *AnonRecord);
345 virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
346 RecordDecl *Record);
347
Douglas Gregor98b27542009-01-17 00:42:38 +0000348 virtual DeclTy *ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
Argiris Kirtzidis311db8c2008-11-08 16:45:02 +0000349 SourceLocation KWLoc, const CXXScopeSpec &SS,
350 IdentifierInfo *Name, SourceLocation NameLoc,
Douglas Gregord406b032009-02-06 22:42:48 +0000351 AttributeList *Attr);
Ted Kremenek46a837c2008-09-05 17:16:31 +0000352
Douglas Gregor8acb7272008-12-11 16:49:14 +0000353 virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattnerf7df4d12008-08-23 02:00:52 +0000354 IdentifierInfo *ClassName,
355 llvm::SmallVectorImpl<DeclTy*> &Decls);
Douglas Gregor8acb7272008-12-11 16:49:14 +0000356 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner4b009652007-07-25 00:24:17 +0000357 Declarator &D, ExprTy *BitfieldWidth);
Fariborz Jahanian751c6172008-04-10 23:32:45 +0000358
359 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
360 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian4e0bb982008-04-11 16:55:42 +0000361 tok::ObjCKeywordKind visibility);
Fariborz Jahanian751c6172008-04-10 23:32:45 +0000362
Steve Naroffffeaa552007-09-14 23:09:53 +0000363 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000364 virtual void ActOnFields(Scope* S,
Steve Naroff1a7fa7b2007-10-29 21:38:07 +0000365 SourceLocation RecLoc, DeclTy *TagDecl,
366 DeclTy **Fields, unsigned NumFields,
Daniel Dunbarf3944442008-10-03 02:03:53 +0000367 SourceLocation LBrac, SourceLocation RBrac,
368 AttributeList *AttrList);
Douglas Gregordb568cf2009-01-08 20:45:30 +0000369
370 /// ActOnTagStartDefinition - Invoked when we have entered the
371 /// scope of a tag's definition (e.g., for an enumeration, class,
372 /// struct, or union).
373 virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl);
374
375 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
376 /// the definition of a tag (enumeration, class, struct, or union).
377 virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl);
378
Steve Naroff0acc9c92007-09-15 18:49:24 +0000379 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4b009652007-07-25 00:24:17 +0000380 DeclTy *LastEnumConstant,
381 SourceLocation IdLoc, IdentifierInfo *Id,
382 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff0acc9c92007-09-15 18:49:24 +0000383 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Chris Lattner4b009652007-07-25 00:24:17 +0000384 DeclTy **Elements, unsigned NumElements);
Sebastian Redlf831eeb2008-11-08 13:00:26 +0000385
Argiris Kirtzidis054a2632008-11-08 17:17:31 +0000386 DeclContext *getContainingDC(DeclContext *DC);
Argiris Kirtzidis38f16712008-07-01 10:37:29 +0000387
Chris Lattnereee57c02008-04-04 06:12:32 +0000388 /// Set the current declaration context until it gets popped.
Douglas Gregor8acb7272008-12-11 16:49:14 +0000389 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattnerf3874bc2008-04-06 04:47:34 +0000390 void PopDeclContext();
Argiris Kirtzidis95256e62008-06-28 06:07:14 +0000391
Chris Lattnere5cb5862008-12-04 23:50:19 +0000392 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
393 /// to the function decl for the function being parsed. If we're currently
394 /// in a 'block', this returns the containing context.
395 FunctionDecl *getCurFunctionDecl();
396
397 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
398 /// the method decl for the method being parsed. If we're currently
399 /// in a 'block', this returns the containing context.
Daniel Dunbar64789f82008-08-11 05:35:13 +0000400 ObjCMethodDecl *getCurMethodDecl();
Chris Lattnereee57c02008-04-04 06:12:32 +0000401
Chris Lattnere5cb5862008-12-04 23:50:19 +0000402 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
403 /// or C function we're in, otherwise return null. If we're currently
404 /// in a 'block', this returns the containing context.
405 NamedDecl *getCurFunctionOrMethodDecl();
406
Argiris Kirtzidis951f25b2008-04-12 00:47:19 +0000407 /// Add this decl to the scope shadowed decl chains.
408 void PushOnScopeChains(NamedDecl *D, Scope *S);
409
Argiris Kirtzidis90842b62008-09-09 21:18:04 +0000410 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
411 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
412 /// true if 'D' belongs to the given declaration context.
413 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
Douglas Gregor8acb7272008-12-11 16:49:14 +0000414 return IdResolver.isDeclInScope(D, Ctx, Context, S);
Argiris Kirtzidis90842b62008-09-09 21:18:04 +0000415 }
416
Eli Friedman9c0e6f92009-02-28 05:41:13 +0000417
418 void RecursiveCalcJumpScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
419 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
420 llvm::DenseMap<Stmt*, void*>& GotoScopeMap,
421 std::vector<void*>& ScopeStack,
422 Stmt* CurStmt);
423
424 void RecursiveCalcLabelScopes(llvm::DenseMap<Stmt*, void*>& LabelScopeMap,
425 llvm::DenseMap<void*, Stmt*>& PopScopeMap,
426 std::vector<void*>& ScopeStack,
427 Stmt* CurStmt,
428 Stmt* ParentCompoundStmt);
429
Chris Lattner9e982502008-02-21 01:07:18 +0000430 /// Subroutines of ActOnDeclarator().
Chris Lattner82bb4792007-11-14 06:34:38 +0000431 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000432 Decl *LastDecl);
Douglas Gregor083c23e2009-02-16 17:45:42 +0000433 bool MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
434 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
Douglas Gregoraf682022009-02-24 01:23:02 +0000435 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregor083c23e2009-02-16 17:45:42 +0000436 bool MergeVarDecl(VarDecl *New, Decl *Old);
437 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Steve Naroffb5e78152008-08-08 17:50:35 +0000438 void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000439
440 /// C++ Overloading.
441 bool IsOverload(FunctionDecl *New, Decl* OldD,
442 OverloadedFunctionDecl::function_iterator &MatchedDecl);
Douglas Gregora3b34bb2008-11-03 19:09:14 +0000443 ImplicitConversionSequence
444 TryImplicitConversion(Expr* From, QualType ToType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000445 bool SuppressUserConversions = false,
446 bool AllowExplicit = false);
Douglas Gregorb72e9da2008-10-31 16:23:19 +0000447 bool IsStandardConversion(Expr *From, QualType ToType,
448 StandardConversionSequence& SCS);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000449 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
450 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
Douglas Gregore819caf2009-02-12 00:15:05 +0000451 bool IsComplexPromotion(QualType FromType, QualType ToType);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000452 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregor6fd35572008-12-19 17:40:08 +0000453 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregor932778b2008-12-19 19:13:09 +0000454 bool isObjCPointerConversion(QualType FromType, QualType ToType,
455 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregorbb461502008-10-24 04:54:22 +0000456 bool CheckPointerConversion(Expr *From, QualType ToType);
Sebastian Redlba387562009-01-25 19:43:20 +0000457 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
458 QualType &ConvertedType);
459 bool CheckMemberPointerConversion(Expr *From, QualType ToType);
Douglas Gregor6573cfd2008-10-21 23:43:52 +0000460 bool IsQualificationConversion(QualType FromType, QualType ToType);
Douglas Gregorb72e9da2008-10-31 16:23:19 +0000461 bool IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000462 UserDefinedConversionSequence& User,
Douglas Gregorb206cc42009-01-30 23:27:23 +0000463 bool AllowConversionFunctions,
464 bool AllowExplicit);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000465
466 ImplicitConversionSequence::CompareKind
467 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
468 const ImplicitConversionSequence& ICS2);
469
470 ImplicitConversionSequence::CompareKind
471 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
472 const StandardConversionSequence& SCS2);
473
Douglas Gregorccc0ccc2008-10-22 14:17:15 +0000474 ImplicitConversionSequence::CompareKind
475 CompareQualificationConversions(const StandardConversionSequence& SCS1,
476 const StandardConversionSequence& SCS2);
477
Douglas Gregor14046502008-10-23 00:40:37 +0000478 ImplicitConversionSequence::CompareKind
479 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
480 const StandardConversionSequence& SCS2);
481
Douglas Gregora3b34bb2008-11-03 19:09:14 +0000482 ImplicitConversionSequence
483 TryCopyInitialization(Expr* From, QualType ToType,
484 bool SuppressUserConversions = false);
Douglas Gregor81c29152008-10-29 00:13:59 +0000485 bool PerformCopyInitialization(Expr *&From, QualType ToType,
486 const char *Flavor);
487
Douglas Gregor5ed15042008-11-18 23:14:02 +0000488 ImplicitConversionSequence
489 TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method);
490 bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method);
491
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000492 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
493 bool PerformContextuallyConvertToBool(Expr *&From);
494
Douglas Gregord2baafd2008-10-21 16:13:35 +0000495 /// OverloadingResult - Capture the result of performing overload
496 /// resolution.
497 enum OverloadingResult {
498 OR_Success, ///< Overload resolution succeeded.
499 OR_No_Viable_Function, ///< No viable function found.
Douglas Gregoraa57e862009-02-18 21:56:37 +0000500 OR_Ambiguous, ///< Ambiguous candidates found.
501 OR_Deleted ///< Overload resoltuion refers to a deleted function.
Douglas Gregord2baafd2008-10-21 16:13:35 +0000502 };
503
504 void AddOverloadCandidate(FunctionDecl *Function,
505 Expr **Args, unsigned NumArgs,
Douglas Gregora3b34bb2008-11-03 19:09:14 +0000506 OverloadCandidateSet& CandidateSet,
507 bool SuppressUserConversions = false);
Douglas Gregor5ed15042008-11-18 23:14:02 +0000508 void AddMethodCandidate(CXXMethodDecl *Method,
509 Expr *Object, Expr **Args, unsigned NumArgs,
510 OverloadCandidateSet& CandidateSet,
Douglas Gregor3257fb52008-12-22 05:46:06 +0000511 bool SuppressUserConversions = false);
Douglas Gregor60714f92008-11-07 22:36:19 +0000512 void AddConversionCandidate(CXXConversionDecl *Conversion,
513 Expr *From, QualType ToType,
514 OverloadCandidateSet& CandidateSet);
Douglas Gregor67fdb5b2008-11-19 22:57:39 +0000515 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
Douglas Gregor4fa58902009-02-26 23:50:07 +0000516 const FunctionProtoType *Proto,
Douglas Gregor67fdb5b2008-11-19 22:57:39 +0000517 Expr *Object, Expr **Args, unsigned NumArgs,
518 OverloadCandidateSet& CandidateSet);
Douglas Gregor48a87322009-02-04 16:44:47 +0000519 bool AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
520 SourceLocation OpLoc,
Douglas Gregor5ed15042008-11-18 23:14:02 +0000521 Expr **Args, unsigned NumArgs,
Douglas Gregor48a87322009-02-04 16:44:47 +0000522 OverloadCandidateSet& CandidateSet,
523 SourceRange OpRange = SourceRange());
Douglas Gregor70d26122008-11-12 17:17:38 +0000524 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
525 Expr **Args, unsigned NumArgs,
Douglas Gregorab141112009-01-13 00:52:54 +0000526 OverloadCandidateSet& CandidateSet,
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000527 bool IsAssignmentOperator = false,
528 unsigned NumContextualBoolArguments = 0);
Douglas Gregor4f6904d2008-11-19 15:42:04 +0000529 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
530 Expr **Args, unsigned NumArgs,
531 OverloadCandidateSet& CandidateSet);
Douglas Gregoraa1da4a2009-02-04 00:32:51 +0000532 void AddArgumentDependentLookupCandidates(DeclarationName Name,
533 Expr **Args, unsigned NumArgs,
534 OverloadCandidateSet& CandidateSet);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000535 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
536 const OverloadCandidate& Cand2);
537 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
538 OverloadCandidateSet::iterator& Best);
539 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
540 bool OnlyViable);
541
Douglas Gregor45014fd2008-11-10 20:40:00 +0000542 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
543 bool Complain);
544 void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
545
Douglas Gregor4646f9c2009-02-04 15:01:18 +0000546 FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee,
547 DeclarationName UnqualifiedName,
Douglas Gregorbf4f0582008-11-26 06:01:48 +0000548 SourceLocation LParenLoc,
549 Expr **Args, unsigned NumArgs,
550 SourceLocation *CommaLocs,
Douglas Gregoraa1da4a2009-02-04 00:32:51 +0000551 SourceLocation RParenLoc,
Douglas Gregor4646f9c2009-02-04 15:01:18 +0000552 bool &ArgumentDependentLookup);
Douglas Gregor3257fb52008-12-22 05:46:06 +0000553 ExprResult
554 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
555 SourceLocation LParenLoc, Expr **Args,
556 unsigned NumArgs, SourceLocation *CommaLocs,
557 SourceLocation RParenLoc);
Douglas Gregor10f3c502008-11-19 21:05:33 +0000558 ExprResult
Douglas Gregora133e262008-12-06 00:22:45 +0000559 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregor10f3c502008-11-19 21:05:33 +0000560 Expr **Args, unsigned NumArgs,
561 SourceLocation *CommaLocs,
562 SourceLocation RParenLoc);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000563
Douglas Gregorddfd9d52008-12-23 00:26:44 +0000564 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
Douglas Gregor7f3fec52008-11-20 16:27:02 +0000565 SourceLocation MemberLoc,
566 IdentifierInfo &Member);
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000567
Chris Lattner7898bf62009-01-06 07:27:21 +0000568 /// Helpers for dealing with function parameters.
Chris Lattner3e254fb2008-04-08 04:40:51 +0000569 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattner3e254fb2008-04-08 04:40:51 +0000570 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregor2b9422f2008-05-07 04:49:29 +0000571 void CheckExtraCXXDefaultArguments(Declarator &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000572
Douglas Gregor5eca99e2009-01-12 18:45:55 +0000573 Scope *getNonFieldDeclScope(Scope *S);
574
Douglas Gregor78d70132009-01-14 22:20:51 +0000575 /// \name Name lookup
576 ///
577 /// These routines provide name lookup that is used during semantic
578 /// analysis to resolve the various kinds of names (identifiers,
579 /// overloaded operator names, constructor names, etc.) into zero or
580 /// more declarations within a particular scope. The major entry
581 /// points are LookupName, which performs unqualified name lookup,
582 /// and LookupQualifiedName, which performs qualified name lookup.
583 ///
584 /// All name lookup is performed based on some specific criteria,
585 /// which specify what names will be visible to name lookup and how
586 /// far name lookup should work. These criteria are important both
587 /// for capturing language semantics (certain lookups will ignore
588 /// certain names, for example) and for performance, since name
589 /// lookup is often a bottleneck in the compilation of C++. Name
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000590 /// lookup criteria is specified via the LookupCriteria enumeration.
Douglas Gregor78d70132009-01-14 22:20:51 +0000591 ///
592 /// The results of name lookup can vary based on the kind of name
593 /// lookup performed, the current language, and the translation
594 /// unit. In C, for example, name lookup will either return nothing
595 /// (no entity found) or a single declaration. In C++, name lookup
596 /// can additionally refer to a set of overloaded functions or
597 /// result in an ambiguity. All of the possible results of name
598 /// lookup are captured by the LookupResult class, which provides
599 /// the ability to distinguish among them.
600 //@{
Douglas Gregor5ff0ee52008-12-30 03:27:21 +0000601
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000602 /// @brief Describes the kind of name lookup to perform.
603 enum LookupNameKind {
604 /// Ordinary name lookup, which finds ordinary names (functions,
605 /// variables, typedefs, etc.) in C and most kinds of names
606 /// (functions, variables, members, types, etc.) in C++.
607 LookupOrdinaryName = 0,
608 /// Tag name lookup, which finds the names of enums, classes,
609 /// structs, and unions.
610 LookupTagName,
611 /// Member name lookup, which finds the names of
612 /// class/struct/union members.
613 LookupMemberName,
Douglas Gregor48a87322009-02-04 16:44:47 +0000614 // Look up of an operator name (e.g., operator+) for use with
615 // operator overloading. This lookup is similar to ordinary name
616 // lookup, but will ignore any declarations that are class
617 // members.
618 LookupOperatorName,
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000619 /// Look up of a name that precedes the '::' scope resolution
620 /// operator in C++. This lookup completely ignores operator,
621 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
622 LookupNestedNameSpecifierName,
623 /// Look up a namespace name within a C++ using directive or
624 /// namespace alias definition, ignoring non-namespace names (C++
625 /// [basic.lookup.udir]p1).
Douglas Gregor1c52c632009-02-24 20:03:32 +0000626 LookupNamespaceName,
627 // Look up an ordinary name that is going to be redeclared as a
628 // name with linkage. This lookup ignores any declarations that
629 // are outside of the current scope unless they have linkage. See
630 // C99 6.2.2p4-5 and C++ [basic.link]p6.
631 LookupRedeclarationWithLinkage
Douglas Gregor78d70132009-01-14 22:20:51 +0000632 };
633
634 /// @brief Represents the results of name lookup.
635 ///
636 /// An instance of the LookupResult class captures the results of a
637 /// single name lookup, which can return no result (nothing found),
638 /// a single declaration, a set of overloaded functions, or an
639 /// ambiguity. Use the getKind() method to determine which of these
640 /// results occurred for a given lookup.
641 ///
642 /// Any non-ambiguous lookup can be converted into a single
Douglas Gregor09be81b2009-02-04 17:27:36 +0000643 /// (possibly NULL) @c NamedDecl* via a conversion function or the
Douglas Gregor78d70132009-01-14 22:20:51 +0000644 /// getAsDecl() method. This conversion permits the common-case
645 /// usage in C and Objective-C where name lookup will always return
646 /// a single declaration.
Douglas Gregord07474b2009-01-17 01:13:24 +0000647 struct LookupResult {
Douglas Gregor78d70132009-01-14 22:20:51 +0000648 /// The kind of entity that is actually stored within the
649 /// LookupResult object.
Douglas Gregord07474b2009-01-17 01:13:24 +0000650 enum {
Douglas Gregor09be81b2009-02-04 17:27:36 +0000651 /// First is a single declaration (a NamedDecl*), which may be NULL.
Douglas Gregor78d70132009-01-14 22:20:51 +0000652 SingleDecl,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000653
Douglas Gregor7a7be652009-02-03 19:21:40 +0000654 /// First is a single declaration (an OverloadedFunctionDecl*).
655 OverloadedDeclSingleDecl,
656
Douglas Gregor78d70132009-01-14 22:20:51 +0000657 /// [First, Last) is an iterator range represented as opaque
658 /// pointers used to reconstruct IdentifierResolver::iterators.
659 OverloadedDeclFromIdResolver,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000660
Douglas Gregor78d70132009-01-14 22:20:51 +0000661 /// [First, Last) is an iterator range represented as opaque
662 /// pointers used to reconstruct DeclContext::lookup_iterators.
663 OverloadedDeclFromDeclContext,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000664
665 /// First is a pointer to a BasePaths structure, which is owned
666 /// by the LookupResult. Last is non-zero to indicate that the
667 /// ambiguity is caused by two names found in base class
668 /// subobjects of different types.
Douglas Gregor7a7be652009-02-03 19:21:40 +0000669 AmbiguousLookupStoresBasePaths,
670
671 /// [First, Last) is an iterator range represented as opaque
672 /// pointers used to reconstruct new'ed Decl*[] array containing
673 /// found ambiguous decls. LookupResult is owner of this array.
674 AmbiguousLookupStoresDecls
675
Douglas Gregor78d70132009-01-14 22:20:51 +0000676 } StoredKind;
677
678 /// The first lookup result, whose contents depend on the kind of
Douglas Gregor09be81b2009-02-04 17:27:36 +0000679 /// lookup result. This may be a NamedDecl* (if StoredKind ==
680 /// SingleDecl), OverloadedFunctionDecl* (if StoredKind ==
681 /// OverloadedDeclSingleDecl), the opaque pointer from an
Douglas Gregor78d70132009-01-14 22:20:51 +0000682 /// IdentifierResolver::iterator (if StoredKind ==
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000683 /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator
684 /// (if StoredKind == OverloadedDeclFromDeclContext), or a
Douglas Gregor7a7be652009-02-03 19:21:40 +0000685 /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor78d70132009-01-14 22:20:51 +0000686 mutable uintptr_t First;
687
688 /// The last lookup result, whose contents depend on the kind of
689 /// lookup result. This may be unused (if StoredKind ==
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000690 /// SingleDecl), it may have the same type as First (for
691 /// overloaded function declarations), or is may be used as a
Douglas Gregor7a7be652009-02-03 19:21:40 +0000692 /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor78d70132009-01-14 22:20:51 +0000693 mutable uintptr_t Last;
694
695 /// Context - The context in which we will build any
696 /// OverloadedFunctionDecl nodes needed by the conversion to
697 /// Decl*.
698 ASTContext *Context;
699
Douglas Gregor78d70132009-01-14 22:20:51 +0000700 /// @brief The kind of entity found by name lookup.
701 enum LookupKind {
702 /// @brief No entity found met the criteria.
703 NotFound = 0,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000704
Douglas Gregor78d70132009-01-14 22:20:51 +0000705 /// @brief Name lookup found a single declaration that met the
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000706 /// criteria. getAsDecl will return this declaration.
Douglas Gregor78d70132009-01-14 22:20:51 +0000707 Found,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000708
Douglas Gregor78d70132009-01-14 22:20:51 +0000709 /// @brief Name lookup found a set of overloaded functions that
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000710 /// met the criteria. getAsDecl will turn this set of overloaded
711 /// functions into an OverloadedFunctionDecl.
Douglas Gregor78d70132009-01-14 22:20:51 +0000712 FoundOverloaded,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000713
714 /// Name lookup results in an ambiguity because multiple
715 /// entities that meet the lookup criteria were found in
716 /// subobjects of different types. For example:
717 /// @code
718 /// struct A { void f(int); }
719 /// struct B { void f(double); }
720 /// struct C : A, B { };
721 /// void test(C c) {
722 /// c.f(0); // error: A::f and B::f come from subobjects of different
723 /// // types. overload resolution is not performed.
724 /// }
725 /// @endcode
726 AmbiguousBaseSubobjectTypes,
727
728 /// Name lookup results in an ambiguity because multiple
729 /// nonstatic entities that meet the lookup criteria were found
730 /// in different subobjects of the same type. For example:
731 /// @code
732 /// struct A { int x; };
733 /// struct B : A { };
734 /// struct C : A { };
735 /// struct D : B, C { };
736 /// int test(D d) {
737 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
738 /// }
739 /// @endcode
Douglas Gregor7a7be652009-02-03 19:21:40 +0000740 AmbiguousBaseSubobjects,
741
742 /// Name lookup results in an ambiguity because multiple definitions
743 /// of entity that meet the lookup criteria were found in different
744 /// declaration contexts.
745 /// @code
746 /// namespace A {
747 /// int i;
748 /// namespace B { int i; }
749 /// int test() {
750 /// using namespace B;
751 /// return i; // error 'i' is found in namespace A and A::B
752 /// }
753 /// }
754 /// @endcode
755 AmbiguousReference
Douglas Gregor78d70132009-01-14 22:20:51 +0000756 };
757
Douglas Gregor09be81b2009-02-04 17:27:36 +0000758 static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D);
Douglas Gregor6beddfe2009-01-15 02:19:31 +0000759
Douglas Gregord07474b2009-01-17 01:13:24 +0000760 static LookupResult CreateLookupResult(ASTContext &Context,
761 IdentifierResolver::iterator F,
762 IdentifierResolver::iterator L);
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000763
Douglas Gregord07474b2009-01-17 01:13:24 +0000764 static LookupResult CreateLookupResult(ASTContext &Context,
765 DeclContext::lookup_iterator F,
766 DeclContext::lookup_iterator L);
Douglas Gregor78d70132009-01-14 22:20:51 +0000767
Douglas Gregord07474b2009-01-17 01:13:24 +0000768 static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths,
769 bool DifferentSubobjectTypes) {
770 LookupResult Result;
Douglas Gregor7a7be652009-02-03 19:21:40 +0000771 Result.StoredKind = AmbiguousLookupStoresBasePaths;
Douglas Gregord07474b2009-01-17 01:13:24 +0000772 Result.First = reinterpret_cast<uintptr_t>(Paths);
773 Result.Last = DifferentSubobjectTypes? 1 : 0;
774 Result.Context = &Context;
775 return Result;
776 }
Douglas Gregor6beddfe2009-01-15 02:19:31 +0000777
Douglas Gregor7a7be652009-02-03 19:21:40 +0000778 template <typename Iterator>
779 static LookupResult CreateLookupResult(ASTContext &Context,
780 Iterator B, std::size_t Len) {
Douglas Gregor09be81b2009-02-04 17:27:36 +0000781 NamedDecl ** Array = new NamedDecl*[Len];
Douglas Gregor7a7be652009-02-03 19:21:40 +0000782 for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B)
783 Array[Idx] = *B;
784 LookupResult Result;
785 Result.StoredKind = AmbiguousLookupStoresDecls;
786 Result.First = reinterpret_cast<uintptr_t>(Array);
787 Result.Last = reinterpret_cast<uintptr_t>(Array + Len);
788 Result.Context = &Context;
789 return Result;
790 }
791
Douglas Gregor78d70132009-01-14 22:20:51 +0000792 LookupKind getKind() const;
793
794 /// @brief Determine whether name look found something.
795 operator bool() const { return getKind() != NotFound; }
796
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000797 /// @brief Determines whether the lookup resulted in an ambiguity.
Douglas Gregor7a7be652009-02-03 19:21:40 +0000798 bool isAmbiguous() const {
799 return StoredKind == AmbiguousLookupStoresBasePaths ||
800 StoredKind == AmbiguousLookupStoresDecls;
801 }
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000802
Douglas Gregor78d70132009-01-14 22:20:51 +0000803 /// @brief Allows conversion of a lookup result into a
804 /// declaration, with the same behavior as getAsDecl.
Douglas Gregor09be81b2009-02-04 17:27:36 +0000805 operator NamedDecl*() const { return getAsDecl(); }
Douglas Gregor78d70132009-01-14 22:20:51 +0000806
Douglas Gregor09be81b2009-02-04 17:27:36 +0000807 NamedDecl* getAsDecl() const;
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000808
809 BasePaths *getBasePaths() const;
Douglas Gregorbd4b0852009-02-02 21:35:47 +0000810
811 /// \brief Iterate over the results of name lookup.
812 ///
813 /// The @c iterator class provides iteration over the results of a
814 /// non-ambiguous name lookup.
815 class iterator {
816 /// The LookupResult structure we're iterating through.
817 LookupResult *Result;
818
819 /// The current position of this iterator within the sequence of
820 /// results. This value will have the same representation as the
821 /// @c First field in the LookupResult structure.
822 mutable uintptr_t Current;
823
824 public:
Douglas Gregor09be81b2009-02-04 17:27:36 +0000825 typedef NamedDecl * value_type;
826 typedef NamedDecl * reference;
827 typedef NamedDecl * pointer;
Douglas Gregorbd4b0852009-02-02 21:35:47 +0000828 typedef std::ptrdiff_t difference_type;
829 typedef std::forward_iterator_tag iterator_category;
830
831 iterator() : Result(0), Current(0) { }
832
833 iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { }
834
835 reference operator*() const;
836
837 pointer operator->() const { return **this; }
838
839 iterator &operator++();
840
841 iterator operator++(int) {
842 iterator tmp(*this);
843 ++(*this);
844 return tmp;
845 }
846
847 friend inline bool operator==(iterator const& x, iterator const& y) {
848 return x.Current == y.Current;
849 }
850
851 friend inline bool operator!=(iterator const& x, iterator const& y) {
852 return x.Current != y.Current;
853 }
854 };
855 friend class iterator;
856
857 iterator begin();
858 iterator end();
Douglas Gregor78d70132009-01-14 22:20:51 +0000859 };
860
Douglas Gregor7a7be652009-02-03 19:21:40 +0000861private:
862 typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy;
863
864 std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name,
865 LookupNameKind NameKind,
866 bool RedeclarationOnly);
867
868public:
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000869 /// Determines whether D is a suitable lookup result according to the
870 /// lookup criteria.
Douglas Gregor1c52c632009-02-24 20:03:32 +0000871 static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind,
Douglas Gregorb96b92d2009-02-05 19:25:20 +0000872 unsigned IDNS) {
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000873 switch (NameKind) {
874 case Sema::LookupOrdinaryName:
875 case Sema::LookupTagName:
876 case Sema::LookupMemberName:
Douglas Gregor1c52c632009-02-24 20:03:32 +0000877 case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000878 return D->isInIdentifierNamespace(IDNS);
879
Douglas Gregor48a87322009-02-04 16:44:47 +0000880 case Sema::LookupOperatorName:
881 return D->isInIdentifierNamespace(IDNS) &&
882 !D->getDeclContext()->isRecord();
883
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000884 case Sema::LookupNestedNameSpecifierName:
885 return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag);
886
887 case Sema::LookupNamespaceName:
888 return isa<NamespaceDecl>(D);
889 }
890
891 assert(false &&
Douglas Gregorb96b92d2009-02-05 19:25:20 +0000892 "isAcceptableLookupResult always returns before this point");
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000893 return false;
894 }
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000895
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000896 LookupResult LookupName(Scope *S, DeclarationName Name,
897 LookupNameKind NameKind,
Douglas Gregor411889e2009-02-13 23:20:09 +0000898 bool RedeclarationOnly = false,
899 bool AllowBuiltinCreation = true,
900 SourceLocation Loc = SourceLocation());
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000901 LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name,
902 LookupNameKind NameKind,
903 bool RedeclarationOnly = false);
904 LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS,
905 DeclarationName Name,
906 LookupNameKind NameKind,
Douglas Gregor411889e2009-02-13 23:20:09 +0000907 bool RedeclarationOnly = false,
908 bool AllowBuiltinCreation = true,
909 SourceLocation Loc = SourceLocation());
Douglas Gregoraa1da4a2009-02-04 00:32:51 +0000910
911 typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet;
912 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
913
914 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
915 AssociatedNamespaceSet &AssociatedNamespaces,
916 AssociatedClassSet &AssociatedClasses);
917
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000918 bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
919 SourceLocation NameLoc,
920 SourceRange LookupRange = SourceRange());
Douglas Gregor78d70132009-01-14 22:20:51 +0000921 //@}
922
Ted Kremenek42730c52008-01-07 19:49:32 +0000923 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000924 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Douglas Gregor411889e2009-02-13 23:20:09 +0000925 Scope *S, bool ForRedeclaration,
926 SourceLocation Loc);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000927 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
928 Scope *S);
Douglas Gregorb5af7382009-02-14 18:57:46 +0000929 void AddKnownFunctionAttributes(FunctionDecl *FD);
Douglas Gregor78d70132009-01-14 22:20:51 +0000930
931 // More parsing and symbol table subroutines.
932
Chris Lattner4b009652007-07-25 00:24:17 +0000933 // Decl attributes - this routine is the top level dispatcher.
Chris Lattner2024f0a2008-06-29 00:16:31 +0000934 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnerd7e83d82008-06-28 23:58:55 +0000935 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lamb2a72bb32008-02-04 02:31:56 +0000936
Steve Naroffb4f48512008-02-10 21:38:56 +0000937 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
938 bool &IncompleteImpl);
Fariborz Jahanian4e0f6452008-12-05 18:18:52 +0000939 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
940 ObjCMethodDecl *IntfMethod);
Sebastian Redlb93b49c2008-11-11 11:37:55 +0000941
942 NamespaceDecl *GetStdNamespace();
Fariborz Jahanianf96ee9e2009-01-12 19:55:42 +0000943
944 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
Steve Naroffb0bf2c92009-02-26 19:11:32 +0000945 ObjCInterfaceDecl *IDecl);
Steve Naroffb4f48512008-02-10 21:38:56 +0000946
Chris Lattner7898bf62009-01-06 07:27:21 +0000947 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbar1d706e92008-09-04 20:01:15 +0000948 /// methods declared in protocol, and those referenced by it.
949 /// \param IDecl - Used for checking for methods which may have been
950 /// inherited.
Steve Naroffb268d2a2008-02-08 22:06:17 +0000951 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
952 ObjCProtocolDecl *PDecl,
Fariborz Jahaniand3952f32007-10-02 20:06:01 +0000953 bool& IncompleteImpl,
Steve Naroff7711ee32007-10-08 21:05:34 +0000954 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbar1d706e92008-09-04 20:01:15 +0000955 const llvm::DenseSet<Selector> &ClsMap,
956 ObjCInterfaceDecl *IDecl);
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +0000957
Steve Naroff89529b12007-10-02 21:43:37 +0000958 /// CheckImplementationIvars - This routine checks if the instance variables
959 /// listed in the implelementation match those listed in the interface.
Ted Kremenek42730c52008-01-07 19:49:32 +0000960 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
961 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroffb4f48512008-02-10 21:38:56 +0000962 SourceLocation Loc);
Steve Naroff89529b12007-10-02 21:43:37 +0000963
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +0000964 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
Chris Lattner7cc13bf2009-03-01 00:56:52 +0000965 /// remains unimplemented in the class or category @implementation.
966 void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl,
967 ObjCContainerDecl* IDecl,
968 bool IncompleteImpl = false);
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +0000969
Fariborz Jahanian67907bd2007-10-05 18:00:57 +0000970 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
971 /// true, or false, accordingly.
Ted Kremenek42730c52008-01-07 19:49:32 +0000972 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Naroffb91afca2008-10-21 10:37:50 +0000973 const ObjCMethodDecl *PrevMethod,
974 bool matchBasedOnSizeAndAlignment = false);
Steve Naroffee1de132007-10-10 21:53:07 +0000975
Steve Naroff8255b042007-10-14 00:58:41 +0000976 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
977 /// unit are added to a global pool. This allows us to efficiently associate
978 /// a selector with a method declaraation for purposes of typechecking
979 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremenek42730c52008-01-07 19:49:32 +0000980 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff8255b042007-10-14 00:58:41 +0000981
Steve Naroff68354f32008-09-30 14:38:43 +0000982 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
983 /// there are multiple signatures.
984 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
985
Steve Naroff8255b042007-10-14 00:58:41 +0000986 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremenek42730c52008-01-07 19:49:32 +0000987 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Chris Lattner4b009652007-07-25 00:24:17 +0000988 //===--------------------------------------------------------------------===//
989 // Statement Parsing Callbacks: SemaStmt.cpp.
990public:
Sebastian Redl76b9ddb2008-12-21 12:04:03 +0000991 virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
992
993 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
994 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
995 MultiStmtArg Elts,
996 bool isStmtExpr);
997 virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
998 SourceLocation EndLoc);
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000999 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
1000 SourceLocation DotDotDotLoc, ExprArg RHSVal,
Chris Lattnerdaac6942009-03-04 04:23:07 +00001001 SourceLocation ColonLoc);
1002 virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt);
1003
Sebastian Redl0a23e8f2008-12-28 16:13:43 +00001004 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1005 SourceLocation ColonLoc,
1006 StmtArg SubStmt, Scope *CurScope);
Sebastian Redl2437ec62009-01-11 00:38:46 +00001007 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
1008 IdentifierInfo *II,
1009 SourceLocation ColonLoc,
1010 StmtArg SubStmt);
1011 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
1012 StmtArg ThenVal, SourceLocation ElseLoc,
1013 StmtArg ElseVal);
1014 virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
1015 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1016 StmtArg Switch, StmtArg Body);
Sebastian Redl19c74d32009-01-16 23:28:06 +00001017 virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
1018 StmtArg Body);
1019 virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
1020 SourceLocation WhileLoc, ExprArg Cond);
1021
1022 virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
1023 SourceLocation LParenLoc,
1024 StmtArg First, ExprArg Second,
1025 ExprArg Third, SourceLocation RParenLoc,
1026 StmtArg Body);
1027 virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1028 SourceLocation LParenLoc,
1029 StmtArg First, ExprArg Second,
1030 SourceLocation RParenLoc, StmtArg Body);
Sebastian Redl539eb572009-01-18 13:19:59 +00001031
1032 virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1033 SourceLocation LabelLoc,
1034 IdentifierInfo *LabelII);
1035 virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1036 SourceLocation StarLoc,
1037 ExprArg DestExp);
1038 virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
1039 Scope *CurScope);
1040 virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
1041 Scope *CurScope);
1042
1043 virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
1044 ExprArg RetValExp);
1045 OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
1046 Expr *RetValExp);
1047
Sebastian Redlc6b86332009-01-18 16:53:17 +00001048 virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1049 bool IsSimple,
1050 bool IsVolatile,
1051 unsigned NumOutputs,
1052 unsigned NumInputs,
1053 std::string *Names,
1054 MultiExprArg Constraints,
1055 MultiExprArg Exprs,
1056 ExprArg AsmString,
1057 MultiExprArg Clobbers,
1058 SourceLocation RParenLoc);
Sebastian Redlb3860a72009-01-18 17:43:11 +00001059
1060 virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
1061 SourceLocation RParen,
Steve Naroff0e8b96a2009-03-03 19:52:17 +00001062 DeclTy *Parm, StmtArg Body,
Sebastian Redlb3860a72009-01-18 17:43:11 +00001063 StmtArg CatchList);
1064
1065 virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
1066 StmtArg Body);
1067
1068 virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
1069 StmtArg Try,
1070 StmtArg Catch, StmtArg Finally);
1071
1072 virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Steve Naroff590fe482009-02-11 20:05:44 +00001073 ExprArg Throw,
1074 Scope *CurScope);
Sebastian Redlb3860a72009-01-18 17:43:11 +00001075 virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1076 ExprArg SynchExpr,
1077 StmtArg SynchBody);
Sebastian Redlb12ac332008-12-21 16:41:36 +00001078
Sebastian Redl743c8162008-12-22 19:15:10 +00001079 virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D);
1080 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
1081 DeclTy *ExDecl,
1082 StmtArg HandlerBlock);
Sebastian Redl237116b2008-12-22 21:35:02 +00001083 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
1084 StmtArg TryBlock,
1085 MultiStmtArg Handlers);
Sebastian Redlb12ac332008-12-21 16:41:36 +00001086
Chris Lattner4b009652007-07-25 00:24:17 +00001087 //===--------------------------------------------------------------------===//
1088 // Expression Parsing Callbacks: SemaExpr.cpp.
1089
Douglas Gregoraa57e862009-02-18 21:56:37 +00001090 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
Chris Lattner2cb744b2009-02-15 22:43:40 +00001091
Chris Lattner4b009652007-07-25 00:24:17 +00001092 // Primary Expressions.
Douglas Gregor3bb30002009-02-26 21:00:50 +00001093 virtual SourceRange getExprRange(ExprTy *E) const;
1094
Sebastian Redlcd883f72009-01-18 18:53:16 +00001095 virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
1096 IdentifierInfo &II,
1097 bool HasTrailingLParen,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001098 const CXXScopeSpec *SS = 0,
1099 bool isAddressOfOperand = false);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001100 virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S,
Douglas Gregor24094772008-11-19 19:09:45 +00001101 SourceLocation OperatorLoc,
1102 OverloadedOperatorKind Op,
1103 bool HasTrailingLParen,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001104 const CXXScopeSpec &SS,
1105 bool isAddressOfOperand);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001106 virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S,
Douglas Gregor24094772008-11-19 19:09:45 +00001107 SourceLocation OperatorLoc,
1108 TypeTy *Ty,
1109 bool HasTrailingLParen,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001110 const CXXScopeSpec &SS,
1111 bool isAddressOfOperand);
Douglas Gregor566782a2009-01-06 05:10:23 +00001112 DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
1113 bool TypeDependent, bool ValueDependent,
1114 const CXXScopeSpec *SS = 0);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001115 OwningExprResult
Douglas Gregor723d3332009-01-07 00:43:41 +00001116 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1117 FieldDecl *Field,
1118 Expr *BaseObjectExpr = 0,
1119 SourceLocation OpLoc = SourceLocation());
Sebastian Redlcd883f72009-01-18 18:53:16 +00001120 OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
1121 DeclarationName Name,
1122 bool HasTrailingLParen,
1123 const CXXScopeSpec *SS,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001124 bool isAddressOfOperand = false);
Douglas Gregoraee3bf82008-11-18 15:03:34 +00001125
Sebastian Redlcd883f72009-01-18 18:53:16 +00001126 virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
1127 tok::TokenKind Kind);
1128 virtual OwningExprResult ActOnNumericConstant(const Token &);
1129 virtual OwningExprResult ActOnCharacterConstant(const Token &);
1130 virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
1131 ExprArg Val);
Chris Lattner4b009652007-07-25 00:24:17 +00001132
Steve Naroff87d58b42007-09-16 03:34:24 +00001133 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner4b009652007-07-25 00:24:17 +00001134 /// fragments (e.g. "foo" "bar" L"baz").
Sebastian Redl8b769972009-01-19 00:08:26 +00001135 virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
1136 unsigned NumToks);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001137
Chris Lattner4b009652007-07-25 00:24:17 +00001138 // Binary/Unary Operators. 'Tok' is the token for the operator.
Sebastian Redl8b769972009-01-19 00:08:26 +00001139 virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1140 tok::TokenKind Op, ExprArg Input);
1141 virtual OwningExprResult
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001142 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1143 void *TyOrEx, const SourceRange &ArgRange);
1144
Chris Lattner8d9f7962009-01-24 20:17:12 +00001145 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R);
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001146 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1147 const SourceRange &R, bool isSizeof);
Sebastian Redl8b769972009-01-19 00:08:26 +00001148
1149 virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1150 tok::TokenKind Kind,
1151 ExprArg Input);
1152
1153 virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
1154 SourceLocation LLoc,
1155 ExprArg Idx,
1156 SourceLocation RLoc);
1157 virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base,
1158 SourceLocation OpLoc,
1159 tok::TokenKind OpKind,
1160 SourceLocation MemberLoc,
Fariborz Jahanian0cc2ac12009-03-04 22:30:12 +00001161 IdentifierInfo &Member,
1162 DeclTy *ImplDecl=0);
Sebastian Redl8b769972009-01-19 00:08:26 +00001163 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
Douglas Gregor3257fb52008-12-22 05:46:06 +00001164 FunctionDecl *FDecl,
Douglas Gregor4fa58902009-02-26 23:50:07 +00001165 const FunctionProtoType *Proto,
Douglas Gregor3257fb52008-12-22 05:46:06 +00001166 Expr **Args, unsigned NumArgs,
1167 SourceLocation RParenLoc);
Sebastian Redl8b769972009-01-19 00:08:26 +00001168
Steve Naroff87d58b42007-09-16 03:34:24 +00001169 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner4b009652007-07-25 00:24:17 +00001170 /// This provides the location of the left/right parens and a list of comma
1171 /// locations.
Sebastian Redl8b769972009-01-19 00:08:26 +00001172 virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn,
1173 SourceLocation LParenLoc,
1174 MultiExprArg Args,
1175 SourceLocation *CommaLocs,
1176 SourceLocation RParenLoc);
1177
Sebastian Redl5457c5e2009-01-19 22:31:54 +00001178 virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
1179 SourceLocation RParenLoc, ExprArg Op);
1180
1181 virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1182 TypeTy *Ty,
1183 SourceLocation RParenLoc,
1184 ExprArg Op);
1185
1186 virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
1187 MultiExprArg InitList,
1188 InitListDesignations &Designators,
1189 SourceLocation RParenLoc);
1190
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001191 virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
1192 SourceLocation Loc,
1193 bool UsedColonSyntax,
1194 OwningExprResult Init);
1195
Sebastian Redl5457c5e2009-01-19 22:31:54 +00001196 virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1197 tok::TokenKind Kind,
1198 ExprArg LHS, ExprArg RHS);
1199 OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1200 unsigned Opc, Expr *lhs, Expr *rhs);
Douglas Gregord7f915e2008-11-06 23:29:22 +00001201
Steve Naroff87d58b42007-09-16 03:34:24 +00001202 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner4b009652007-07-25 00:24:17 +00001203 /// in the case of a the GNU conditional expr extension.
Sebastian Redl5457c5e2009-01-19 22:31:54 +00001204 virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1205 SourceLocation ColonLoc,
1206 ExprArg Cond, ExprArg LHS,
1207 ExprArg RHS);
Chris Lattner4b009652007-07-25 00:24:17 +00001208
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001209 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1210 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Chris Lattner4b009652007-07-25 00:24:17 +00001211 IdentifierInfo *LabelII);
1212
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001213 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattner4b009652007-07-25 00:24:17 +00001214 SourceLocation RPLoc); // "({..})"
Chris Lattner0d9bcea2007-08-30 17:45:32 +00001215
1216 /// __builtin_offsetof(type, a.b[123][456].c)
Douglas Gregorddfd9d52008-12-23 00:26:44 +00001217 virtual ExprResult ActOnBuiltinOffsetOf(Scope *S,
1218 SourceLocation BuiltinLoc,
Chris Lattner0d9bcea2007-08-30 17:45:32 +00001219 SourceLocation TypeLoc, TypeTy *Arg1,
1220 OffsetOfComponent *CompPtr,
1221 unsigned NumComponents,
1222 SourceLocation RParenLoc);
1223
Steve Naroff63bad2d2007-08-01 22:05:33 +00001224 // __builtin_types_compatible_p(type1, type2)
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001225 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff63bad2d2007-08-01 22:05:33 +00001226 TypeTy *arg1, TypeTy *arg2,
1227 SourceLocation RPLoc);
Steve Naroff93c53012007-08-03 21:21:27 +00001228
1229 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001230 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroff93c53012007-08-03 21:21:27 +00001231 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
1232 SourceLocation RPLoc);
Chris Lattner4b009652007-07-25 00:24:17 +00001233
Anders Carlsson36760332007-10-15 20:28:48 +00001234 // __builtin_va_arg(expr, type)
1235 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1236 ExprTy *expr, TypeTy *type,
1237 SourceLocation RPLoc);
Steve Naroff52a81c02008-09-03 18:15:37 +00001238
Douglas Gregorad4b3792008-11-29 04:51:27 +00001239 // __null
1240 virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1241
Steve Naroff52a81c02008-09-03 18:15:37 +00001242 //===------------------------- "Block" Extension ------------------------===//
1243
1244 /// ActOnBlockStart - This callback is invoked when a block literal is
1245 /// started.
Steve Naroff52059382008-10-10 01:28:17 +00001246 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1247
1248 /// ActOnBlockArguments - This callback allows processing of block arguments.
1249 /// If there are no arguments, this is still invoked.
Mike Stumpc1fddff2009-02-04 22:31:32 +00001250 virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
Steve Naroff52a81c02008-09-03 18:15:37 +00001251
1252 /// ActOnBlockError - If there is an error parsing a block, this callback
1253 /// is invoked to pop the information about the block from the action impl.
1254 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1255
1256 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1257 /// literal was successfully completed. ^(int x){...}
1258 virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
1259 Scope *CurScope);
1260
Chris Lattner2cb744b2009-02-15 22:43:40 +00001261 //===---------------------------- C++ Features --------------------------===//
1262
Argiris Kirtzidis03e6aaf2008-04-27 13:50:30 +00001263 // Act on C++ namespaces
1264 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
1265 IdentifierInfo *Ident,
1266 SourceLocation LBrace);
1267 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
1268
Douglas Gregor5ff0ee52008-12-30 03:27:21 +00001269 virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
1270 SourceLocation UsingLoc,
1271 SourceLocation NamespcLoc,
1272 const CXXScopeSpec &SS,
1273 SourceLocation IdentLoc,
1274 IdentifierInfo *NamespcName,
1275 AttributeList *AttrList);
1276
Douglas Gregor7a7be652009-02-03 19:21:40 +00001277 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
1278
Argiris Kirtzidis9e55d462008-10-06 17:10:33 +00001279 /// AddCXXDirectInitializerToDecl - This action is called immediately after
1280 /// ActOnDeclarator, when a C++ direct initializer is present.
1281 /// e.g: "int x(1);"
1282 virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
1283 SourceLocation LParenLoc,
1284 ExprTy **Exprs, unsigned NumExprs,
1285 SourceLocation *CommaLocs,
1286 SourceLocation RParenLoc);
1287
Douglas Gregor6428e762008-11-05 15:29:30 +00001288 /// InitializationKind - Represents which kind of C++ initialization
1289 /// [dcl.init] a routine is to perform.
1290 enum InitializationKind {
1291 IK_Direct, ///< Direct initialization
1292 IK_Copy, ///< Copy initialization
1293 IK_Default ///< Default initialization
1294 };
1295
Douglas Gregor5870a952008-11-03 20:45:27 +00001296 CXXConstructorDecl *
Douglas Gregor6428e762008-11-05 15:29:30 +00001297 PerformInitializationByConstructor(QualType ClassType,
1298 Expr **Args, unsigned NumArgs,
1299 SourceLocation Loc, SourceRange Range,
Chris Lattner271d4c22008-11-24 05:29:24 +00001300 DeclarationName InitEntity,
Douglas Gregor6428e762008-11-05 15:29:30 +00001301 InitializationKind Kind);
Douglas Gregor5870a952008-11-03 20:45:27 +00001302
Douglas Gregor21a04f32008-10-27 19:41:14 +00001303 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
1304 virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
1305 SourceLocation LAngleBracketLoc, TypeTy *Ty,
1306 SourceLocation RAngleBracketLoc,
1307 SourceLocation LParenLoc, ExprTy *E,
1308 SourceLocation RParenLoc);
Chris Lattner4b009652007-07-25 00:24:17 +00001309
Sebastian Redlb93b49c2008-11-11 11:37:55 +00001310 /// ActOnCXXTypeidOfType - Parse typeid( type-id ).
1311 virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
1312 SourceLocation LParenLoc, bool isType,
1313 void *TyOrExpr, SourceLocation RParenLoc);
1314
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001315 //// ActOnCXXThis - Parse 'this' pointer.
1316 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
1317
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001318 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
1319 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Chris Lattner4b009652007-07-25 00:24:17 +00001320 tok::TokenKind Kind);
Anders Carlssona66cad42007-08-21 17:43:55 +00001321
Chris Lattnera7447ba2008-02-26 00:51:44 +00001322 //// ActOnCXXThrow - Parse throw expressions.
1323 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
1324 ExprTy *expr);
1325
Argiris Kirtzidis7a1e7412008-08-22 15:38:55 +00001326 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
1327 /// Can be interpreted either as function-style casting ("int(x)")
1328 /// or class type construction ("ClassType(x,y,z)")
1329 /// or creation of a value-initialized type ("int()").
1330 virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
1331 TypeTy *TypeRep,
1332 SourceLocation LParenLoc,
1333 ExprTy **Exprs,
1334 unsigned NumExprs,
1335 SourceLocation *CommaLocs,
1336 SourceLocation RParenLoc);
1337
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001338 /// ActOnCXXNew - Parsed a C++ 'new' expression.
1339 virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1340 SourceLocation PlacementLParen,
1341 ExprTy **PlacementArgs, unsigned NumPlaceArgs,
1342 SourceLocation PlacementRParen,
Sebastian Redl66df3ef2008-12-02 14:43:59 +00001343 bool ParenTypeId, Declarator &D,
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001344 SourceLocation ConstructorLParen,
1345 ExprTy **ConstructorArgs, unsigned NumConsArgs,
1346 SourceLocation ConstructorRParen);
Sebastian Redl66df3ef2008-12-02 14:43:59 +00001347 bool CheckAllocatedType(QualType AllocType, const Declarator &D);
Sebastian Redl3b7ec4b2009-02-09 18:24:27 +00001348 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
1349 bool UseGlobal, QualType AllocType, bool IsArray,
Sebastian Redlb5ee8742008-12-03 20:26:15 +00001350 Expr **PlaceArgs, unsigned NumPlaceArgs,
1351 FunctionDecl *&OperatorNew,
1352 FunctionDecl *&OperatorDelete);
Sebastian Redl3b7ec4b2009-02-09 18:24:27 +00001353 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
1354 DeclarationName Name, Expr** Args,
1355 unsigned NumArgs, DeclContext *Ctx,
Sebastian Redlec5f3262008-12-04 22:20:51 +00001356 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlb5ee8742008-12-03 20:26:15 +00001357 void DeclareGlobalNewDelete();
1358 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
1359 QualType Argument);
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001360
1361 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
1362 virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
1363 bool ArrayForm, ExprTy *Operand);
1364
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +00001365 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
1366 /// C++ if/switch/while/for statement.
1367 /// e.g: "if (int x = f()) {...}"
1368 virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
1369 SourceLocation StartLoc,
1370 Declarator &D,
1371 SourceLocation EqualLoc,
1372 ExprTy *AssignExprVal);
1373
Sebastian Redl39c0f6f2009-01-05 20:52:13 +00001374 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
1375 /// pseudo-functions.
1376 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
1377 SourceLocation KWLoc,
1378 SourceLocation LParen,
1379 TypeTy *Ty,
1380 SourceLocation RParen);
1381
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001382 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
1383 /// global scope ('::').
1384 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
1385 SourceLocation CCLoc);
1386
1387 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1388 /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now
1389 /// we want to resolve "bar::". 'SS' is empty or the previously parsed
1390 /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar',
1391 /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'.
1392 /// Returns a CXXScopeTy* object representing the C++ scope.
1393 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1394 const CXXScopeSpec &SS,
1395 SourceLocation IdLoc,
1396 SourceLocation CCLoc,
Douglas Gregorb0212bd2008-11-17 20:34:05 +00001397 IdentifierInfo &II);
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001398
Douglas Gregor0c281a82009-02-25 19:37:18 +00001399 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1400 /// nested-name-specifier that involves a template-id, e.g.,
1401 /// "foo::bar<int, float>::", and now we need to build a scope
1402 /// specifier. \p SS is empty or the previously parsed nested-name
1403 /// part ("foo::"), \p Type is the already-parsed class template
1404 /// specialization (or other template-id that names a type), \p
1405 /// TypeRange is the source range where the type is located, and \p
1406 /// CCLoc is the location of the trailing '::'.
1407 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1408 const CXXScopeSpec &SS,
1409 TypeTy *Type,
1410 SourceRange TypeRange,
1411 SourceLocation CCLoc);
1412
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001413 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1414 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1415 /// After this method is called, according to [C++ 3.4.3p3], names should be
1416 /// looked up in the declarator-id's scope, until the declarator is parsed and
1417 /// ActOnCXXExitDeclaratorScope is called.
1418 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1419 virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
1420
1421 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1422 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1423 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1424 /// Used to indicate that names should revert to being looked up in the
1425 /// defining scope.
Douglas Gregor24effa82008-12-16 00:38:16 +00001426 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001427
Anders Carlssona66cad42007-08-21 17:43:55 +00001428 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnerddd3e632007-12-12 01:04:12 +00001429 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
1430 ExprTy **Strings,
1431 unsigned NumStrings);
Anders Carlsson8be1d402007-08-22 15:14:15 +00001432 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattnercfd61c82007-10-16 22:51:17 +00001433 SourceLocation EncodeLoc,
Anders Carlsson8be1d402007-08-22 15:14:15 +00001434 SourceLocation LParenLoc,
1435 TypeTy *Ty,
1436 SourceLocation RParenLoc);
1437
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001438 // ParseObjCSelectorExpression - Build selector expression for @selector
1439 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
1440 SourceLocation AtLoc,
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001441 SourceLocation SelLoc,
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001442 SourceLocation LParenLoc,
1443 SourceLocation RParenLoc);
1444
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001445 // ParseObjCProtocolExpression - Build protocol expression for @protocol
1446 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
1447 SourceLocation AtLoc,
1448 SourceLocation ProtoLoc,
1449 SourceLocation LParenLoc,
1450 SourceLocation RParenLoc);
Douglas Gregorec93f442008-04-13 21:30:24 +00001451
1452 //===--------------------------------------------------------------------===//
Douglas Gregord8028382009-01-05 19:45:36 +00001453 // C++ Declarations
1454 //
1455 virtual DeclTy *ActOnStartLinkageSpecification(Scope *S,
1456 SourceLocation ExternLoc,
1457 SourceLocation LangLoc,
1458 const char *Lang,
1459 unsigned StrSize,
1460 SourceLocation LBraceLoc);
1461 virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S,
1462 DeclTy *LinkageSpec,
1463 SourceLocation RBraceLoc);
1464
1465
1466 //===--------------------------------------------------------------------===//
Douglas Gregorec93f442008-04-13 21:30:24 +00001467 // C++ Classes
1468 //
Argiris Kirtzidis311db8c2008-11-08 16:45:02 +00001469 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
1470 const CXXScopeSpec *SS);
Douglas Gregorf15ac4b2008-10-31 09:07:45 +00001471
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001472 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
1473 Declarator &D, ExprTy *BitfieldWidth,
1474 ExprTy *Init, DeclTy *LastInGroup);
1475
Douglas Gregora65e8dd2008-11-05 04:29:56 +00001476 virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD,
1477 Scope *S,
1478 IdentifierInfo *MemberOrBase,
1479 SourceLocation IdLoc,
1480 SourceLocation LParenLoc,
1481 ExprTy **Args, unsigned NumArgs,
1482 SourceLocation *CommaLocs,
1483 SourceLocation RParenLoc);
1484
Douglas Gregore640ab62008-11-03 17:51:48 +00001485 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
1486
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001487 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
1488 DeclTy *TagDecl,
1489 SourceLocation LBrac,
1490 SourceLocation RBrac);
1491
Douglas Gregor605de8d2008-12-16 21:30:33 +00001492 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1493 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param);
1494 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1495
Douglas Gregor8210a8e2008-11-05 20:51:48 +00001496 bool CheckConstructorDeclarator(Declarator &D, QualType &R,
1497 FunctionDecl::StorageClass& SC);
Douglas Gregor605de8d2008-12-16 21:30:33 +00001498 bool CheckConstructor(CXXConstructorDecl *Constructor);
Douglas Gregor8210a8e2008-11-05 20:51:48 +00001499 bool CheckDestructorDeclarator(Declarator &D, QualType &R,
1500 FunctionDecl::StorageClass& SC);
Douglas Gregor3ef6c972008-11-07 20:08:42 +00001501 bool CheckConversionDeclarator(Declarator &D, QualType &R,
1502 FunctionDecl::StorageClass& SC);
Douglas Gregor3ef6c972008-11-07 20:08:42 +00001503 DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregorf15ac4b2008-10-31 09:07:45 +00001504
Douglas Gregor14046502008-10-23 00:40:37 +00001505 //===--------------------------------------------------------------------===//
1506 // C++ Derived Classes
1507 //
1508
1509 /// ActOnBaseSpecifier - Parsed a base specifier
Douglas Gregored3a3982009-03-03 04:44:36 +00001510 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
1511 SourceRange SpecifierRange,
1512 bool Virtual, AccessSpecifier Access,
1513 QualType BaseType,
1514 SourceLocation BaseLoc);
Douglas Gregor14046502008-10-23 00:40:37 +00001515 virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl,
1516 SourceRange SpecifierRange,
1517 bool Virtual, AccessSpecifier Access,
Douglas Gregored3a3982009-03-03 04:44:36 +00001518 TypeTy *basetype, SourceLocation
1519 BaseLoc);
Douglas Gregor14046502008-10-23 00:40:37 +00001520
Douglas Gregored3a3982009-03-03 04:44:36 +00001521 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
1522 unsigned NumBases);
Douglas Gregor14046502008-10-23 00:40:37 +00001523 virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
1524 unsigned NumBases);
1525
1526 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregorbb461502008-10-24 04:54:22 +00001527 bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
Douglas Gregor29dfa2f2009-01-15 00:26:24 +00001528 bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria,
1529 BasePaths &Paths);
Douglas Gregor651d1cc2008-10-24 16:17:19 +00001530 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
1531 SourceLocation Loc, SourceRange Range);
Douglas Gregorb9ef0552009-01-16 00:38:09 +00001532 std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
Douglas Gregorec93f442008-04-13 21:30:24 +00001533
Douglas Gregore60e5d32008-11-06 22:13:31 +00001534 //===--------------------------------------------------------------------===//
1535 // C++ Overloaded Operators [C++ 13.5]
1536 //
1537
1538 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
1539
Douglas Gregordd861062008-12-05 18:15:24 +00001540 //===--------------------------------------------------------------------===//
1541 // C++ Templates [C++ 14]
1542 //
Douglas Gregor8e458f42009-02-09 18:46:07 +00001543 virtual TemplateNameKind isTemplateName(IdentifierInfo &II, Scope *S,
1544 DeclTy *&TemplateDecl,
1545 const CXXScopeSpec *SS = 0);
Douglas Gregordd861062008-12-05 18:15:24 +00001546 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
Douglas Gregor279272e2009-02-04 19:02:06 +00001547 TemplateDecl *AdjustDeclIfTemplate(DeclTy *&Decl);
1548
1549 virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename,
1550 SourceLocation KeyLoc,
1551 IdentifierInfo *ParamName,
1552 SourceLocation ParamNameLoc,
Douglas Gregor52473432008-12-24 02:52:09 +00001553 unsigned Depth, unsigned Position);
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001554 virtual void ActOnTypeParameterDefault(DeclTy *TypeParam,
1555 SourceLocation EqualLoc,
1556 SourceLocation DefaultLoc,
1557 TypeTy *Default);
1558
Douglas Gregored3a3982009-03-03 04:44:36 +00001559 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Douglas Gregor52473432008-12-24 02:52:09 +00001560 virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
Douglas Gregor279272e2009-02-04 19:02:06 +00001561 unsigned Depth,
Douglas Gregor52473432008-12-24 02:52:09 +00001562 unsigned Position);
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001563 virtual void ActOnNonTypeTemplateParameterDefault(DeclTy *TemplateParam,
1564 SourceLocation EqualLoc,
1565 ExprArg Default);
Douglas Gregor279272e2009-02-04 19:02:06 +00001566 virtual DeclTy *ActOnTemplateTemplateParameter(Scope *S,
1567 SourceLocation TmpLoc,
1568 TemplateParamsTy *Params,
1569 IdentifierInfo *ParamName,
1570 SourceLocation ParamNameLoc,
1571 unsigned Depth,
1572 unsigned Position);
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001573 virtual void ActOnTemplateTemplateParameterDefault(DeclTy *TemplateParam,
1574 SourceLocation EqualLoc,
1575 ExprArg Default);
1576
Douglas Gregor52473432008-12-24 02:52:09 +00001577 virtual TemplateParamsTy *
1578 ActOnTemplateParameterList(unsigned Depth,
1579 SourceLocation ExportLoc,
1580 SourceLocation TemplateLoc,
1581 SourceLocation LAngleLoc,
1582 DeclTy **Params, unsigned NumParams,
1583 SourceLocation RAngleLoc);
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001584 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
1585 TemplateParameterList *OldParams);
1586
Douglas Gregord406b032009-02-06 22:42:48 +00001587 virtual DeclTy *
1588 ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK,
1589 SourceLocation KWLoc, const CXXScopeSpec &SS,
1590 IdentifierInfo *Name, SourceLocation NameLoc,
1591 AttributeList *Attr,
1592 MultiTemplateParamsArg TemplateParameterLists);
1593
Douglas Gregora08b6c72009-02-17 23:15:12 +00001594 virtual TypeResult
1595 ActOnClassTemplateId(DeclTy *Template, SourceLocation TemplateLoc,
1596 SourceLocation LAngleLoc,
1597 ASTTemplateArgsPtr TemplateArgs,
1598 SourceLocation *TemplateArgLocs,
1599 SourceLocation RAngleLoc,
1600 const CXXScopeSpec *SS);
1601
Douglas Gregor0d93f692009-02-25 22:02:03 +00001602 bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate,
1603 ClassTemplateSpecializationDecl *PrevDecl,
1604 SourceLocation TemplateNameLoc,
1605 SourceRange ScopeSpecifierRange);
1606
Douglas Gregora08b6c72009-02-17 23:15:12 +00001607 virtual DeclTy *
1608 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
1609 SourceLocation KWLoc,
1610 const CXXScopeSpec &SS,
1611 DeclTy *Template,
1612 SourceLocation TemplateNameLoc,
Douglas Gregor8e458f42009-02-09 18:46:07 +00001613 SourceLocation LAngleLoc,
Douglas Gregor6f37b582009-02-09 19:34:22 +00001614 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001615 SourceLocation *TemplateArgLocs,
Douglas Gregor8e458f42009-02-09 18:46:07 +00001616 SourceLocation RAngleLoc,
Douglas Gregora08b6c72009-02-17 23:15:12 +00001617 AttributeList *Attr,
1618 MultiTemplateParamsArg TemplateParameterLists);
Douglas Gregor8e458f42009-02-09 18:46:07 +00001619
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001620 bool CheckTemplateArgumentList(TemplateDecl *Template,
1621 SourceLocation TemplateLoc,
1622 SourceLocation LAngleLoc,
1623 ASTTemplateArgsPtr& TemplateArgs,
1624 SourceLocation *TemplateArgLocs,
Douglas Gregorad964b32009-02-17 01:05:43 +00001625 SourceLocation RAngleLoc,
1626 llvm::SmallVectorImpl<TemplateArgument> &Converted);
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001627
1628 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg,
1629 SourceLocation ArgLoc);
Douglas Gregorad964b32009-02-17 01:05:43 +00001630 bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,
1631 NamedDecl *&Entity);
1632 bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member);
Douglas Gregored3a3982009-03-03 04:44:36 +00001633 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
1634 QualType InstantiatedParamType, Expr *&Arg,
Douglas Gregorad964b32009-02-17 01:05:43 +00001635 llvm::SmallVectorImpl<TemplateArgument> *Converted = 0);
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001636 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg);
Douglas Gregord406b032009-02-06 22:42:48 +00001637 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
1638 TemplateParameterList *Old,
1639 bool Complain,
Douglas Gregore8e367f2009-02-10 00:24:35 +00001640 bool IsTemplateTemplateParm = false,
1641 SourceLocation TemplateArgLoc
1642 = SourceLocation());
Douglas Gregord406b032009-02-06 22:42:48 +00001643
1644 bool CheckTemplateDeclScope(Scope *S,
1645 MultiTemplateParamsArg &TemplateParameterLists);
Douglas Gregor279272e2009-02-04 19:02:06 +00001646
Douglas Gregor74296542009-02-27 19:31:52 +00001647 //===--------------------------------------------------------------------===//
1648 // C++ Template Instantiation
1649 //
1650 QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
1651 unsigned NumTemplateArgs,
1652 SourceLocation Loc, DeclarationName Entity);
Douglas Gregored3a3982009-03-03 04:44:36 +00001653 bool
1654 InstantiateBaseSpecifiers(ClassTemplateSpecializationDecl *ClassTemplateSpec,
1655 ClassTemplateDecl *ClassTemplate);
1656 bool
1657 InstantiateClassTemplateSpecialization(
1658 ClassTemplateSpecializationDecl *ClassTemplateSpec,
1659 bool ExplicitInstantiation);
Douglas Gregor74296542009-02-27 19:31:52 +00001660
Steve Naroff81f1bba2007-09-06 21:24:23 +00001661 // Objective-C declarations.
Chris Lattnerae1ae492008-07-26 04:13:19 +00001662 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
1663 IdentifierInfo *ClassName,
1664 SourceLocation ClassLoc,
1665 IdentifierInfo *SuperName,
1666 SourceLocation SuperLoc,
1667 DeclTy * const *ProtoRefs,
1668 unsigned NumProtoRefs,
1669 SourceLocation EndProtoLoc,
1670 AttributeList *AttrList);
Fariborz Jahanian05d212a2007-10-11 23:42:27 +00001671
1672 virtual DeclTy *ActOnCompatiblityAlias(
1673 SourceLocation AtCompatibilityAliasLoc,
1674 IdentifierInfo *AliasName, SourceLocation AliasLocation,
1675 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff81f1bba2007-09-06 21:24:23 +00001676
Steve Naroff415c1832007-10-10 17:32:04 +00001677 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman43f307d2008-02-20 22:57:40 +00001678 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +00001679 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattner2bdedd62008-07-26 04:03:38 +00001680 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar28680d12008-09-26 04:48:09 +00001681 SourceLocation EndProtoLoc,
1682 AttributeList *AttrList);
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +00001683
Chris Lattner45142b92008-07-26 04:07:02 +00001684 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
1685 IdentifierInfo *ClassName,
1686 SourceLocation ClassLoc,
1687 IdentifierInfo *CategoryName,
1688 SourceLocation CategoryLoc,
1689 DeclTy * const *ProtoRefs,
1690 unsigned NumProtoRefs,
1691 SourceLocation EndProtoLoc);
Fariborz Jahanianf25220e2007-09-18 20:26:58 +00001692
Steve Naroff415c1832007-10-10 17:32:04 +00001693 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman43f307d2008-02-20 22:57:40 +00001694 SourceLocation AtClassImplLoc,
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +00001695 IdentifierInfo *ClassName, SourceLocation ClassLoc,
1696 IdentifierInfo *SuperClassname,
1697 SourceLocation SuperClassLoc);
1698
Steve Naroff415c1832007-10-10 17:32:04 +00001699 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahaniana91aa322007-10-02 16:38:50 +00001700 SourceLocation AtCatImplLoc,
1701 IdentifierInfo *ClassName,
1702 SourceLocation ClassLoc,
1703 IdentifierInfo *CatName,
1704 SourceLocation CatLoc);
1705
Steve Naroff415c1832007-10-10 17:32:04 +00001706 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroffb4dfe362007-10-02 22:39:18 +00001707 IdentifierInfo **IdentList,
1708 unsigned NumElts);
Fariborz Jahanianc716c942007-09-21 15:40:54 +00001709
Steve Naroff415c1832007-10-10 17:32:04 +00001710 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattnere705e5e2008-07-21 22:17:28 +00001711 const IdentifierLocPair *IdentList,
Fariborz Jahanian8f9b1b22008-12-17 01:07:27 +00001712 unsigned NumElts,
1713 AttributeList *attrList);
Fariborz Jahaniana096e1d2007-10-05 21:01:53 +00001714
Chris Lattner2bdedd62008-07-26 04:03:38 +00001715 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattnere705e5e2008-07-21 22:17:28 +00001716 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian91193f62007-10-11 00:55:41 +00001717 unsigned NumProtocols,
Chris Lattnere705e5e2008-07-21 22:17:28 +00001718 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanianed986602008-05-01 00:03:38 +00001719
Daniel Dunbar540ff472008-09-23 21:53:23 +00001720 /// Ensure attributes are consistent with type.
1721 /// \param [in, out] Attributes The attributes to check; they will
1722 /// be modified to be consistent with \arg PropertyTy.
1723 void CheckObjCPropertyAttributes(QualType PropertyTy,
1724 SourceLocation Loc,
1725 unsigned &Attributes);
Steve Naroffab63fd62009-01-08 17:28:14 +00001726 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Fariborz Jahanianed986602008-05-01 00:03:38 +00001727 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1728 ObjCPropertyDecl *SuperProperty,
Chris Lattnerd120b9e2008-11-24 03:54:41 +00001729 const IdentifierInfo *Name);
Fariborz Jahanianed986602008-05-01 00:03:38 +00001730 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanian1e89de32008-04-24 19:58:34 +00001731
Fariborz Jahanianacad6d12008-12-06 23:03:39 +00001732 void MergeProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian33973a22008-05-02 19:17:30 +00001733 DeclTy *MergeProtocols);
1734
Fariborz Jahanianffb68822009-03-02 19:05:07 +00001735 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
1736 ObjCInterfaceDecl *ID);
1737
Fariborz Jahanianacad6d12008-12-06 23:03:39 +00001738 void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian33973a22008-05-02 19:17:30 +00001739 ObjCProtocolDecl *PDecl);
1740
Steve Naroffb82c50f2007-11-11 17:19:15 +00001741 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
1742 DeclTy **allMethods = 0, unsigned allNum = 0,
1743 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahaniand34caf92007-09-26 18:27:25 +00001744
Fariborz Jahanian0ceb4be2008-04-14 23:36:35 +00001745 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian4aa72a72008-05-05 18:51:55 +00001746 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanianb7080ae2008-05-06 18:09:04 +00001747 Selector GetterSel, Selector SetterSel,
Fariborz Jahanianbcda0b42008-11-26 20:01:34 +00001748 DeclTy *ClassCategory, bool *OverridingProperty,
Fariborz Jahanian4aa72a72008-05-05 18:51:55 +00001749 tok::ObjCKeywordKind MethodImplKind);
1750
Fariborz Jahanian78f7e312008-04-18 00:19:30 +00001751 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
1752 SourceLocation PropertyLoc,
1753 bool ImplKind, DeclTy *ClassImplDecl,
1754 IdentifierInfo *PropertyId,
1755 IdentifierInfo *PropertyIvar);
1756
Steve Naroff3774dd92007-10-26 20:53:56 +00001757 virtual DeclTy *ActOnMethodDeclaration(
1758 SourceLocation BeginLoc, // location of the + or -.
1759 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanian8473b222007-11-09 19:52:12 +00001760 tok::TokenKind MethodType,
Ted Kremenek42730c52008-01-07 19:49:32 +00001761 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +00001762 Selector Sel,
Steve Naroff4ed9d662007-09-27 14:38:14 +00001763 // optional arguments. The number of types/arguments is obtained
1764 // from the Sel.getNumArgs().
Ted Kremenek42730c52008-01-07 19:49:32 +00001765 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Fariborz Jahanian89d53042009-01-09 00:38:19 +00001766 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroff29fe7462007-11-15 12:35:21 +00001767 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
1768 bool isVariadic = false);
Steve Naroff52664182007-10-16 23:12:48 +00001769
Steve Naroff4b129152009-02-26 15:55:06 +00001770 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
1771 // Will search "local" class/category implementations for a method decl.
Fariborz Jahanian271f9062009-03-04 18:15:57 +00001772 // Will also search in class's root looking for instance method.
Steve Naroff4b129152009-02-26 15:55:06 +00001773 // Returns 0 if no method is found.
Fariborz Jahanian271f9062009-03-04 18:15:57 +00001774 ObjCMethodDecl *LookupPrivateOrRootMethod(Selector Sel, ObjCInterfaceDecl *CDecl);
Steve Naroff4b129152009-02-26 15:55:06 +00001775
Steve Naroff4ed9d662007-09-27 14:38:14 +00001776 // ActOnClassMessage - used for both unary and keyword messages.
1777 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff9f176d12007-11-15 13:05:42 +00001778 // is obtained from NumArgs.
Steve Naroff4ed9d662007-09-27 14:38:14 +00001779 virtual ExprResult ActOnClassMessage(
Fariborz Jahanian2ce5dc52007-11-12 20:13:27 +00001780 Scope *S,
Anders Carlssonb42900d2009-02-14 18:21:46 +00001781 IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,
1782 SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac,
Steve Naroff9f176d12007-11-15 13:05:42 +00001783 ExprTy **ArgExprs, unsigned NumArgs);
Steve Naroff4ed9d662007-09-27 14:38:14 +00001784
1785 // ActOnInstanceMessage - used for both unary and keyword messages.
1786 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff9f176d12007-11-15 13:05:42 +00001787 // is obtained from NumArgs.
Steve Naroff4ed9d662007-09-27 14:38:14 +00001788 virtual ExprResult ActOnInstanceMessage(
Steve Naroff6cb1d362007-09-28 22:22:11 +00001789 ExprTy *receiver, Selector Sel,
Anders Carlssonb42900d2009-02-14 18:21:46 +00001790 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroff9f176d12007-11-15 13:05:42 +00001791 ExprTy **ArgExprs, unsigned NumArgs);
Daniel Dunbar81c7d472008-10-14 05:35:18 +00001792
1793 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
1794 virtual void ActOnPragmaPack(PragmaPackKind Kind,
1795 IdentifierInfo *Name,
1796 ExprTy *Alignment,
1797 SourceLocation PragmaLoc,
1798 SourceLocation LParenLoc,
1799 SourceLocation RParenLoc);
Chris Lattnera8699562009-02-17 01:09:29 +00001800
1801 /// getPragmaPackAlignment() - Return the current alignment as specified by
1802 /// the current #pragma pack directive, or 0 if none is currently active.
1803 unsigned getPragmaPackAlignment() const;
1804
1805 /// FreePackedContext - Deallocate and null out PackContext.
1806 void FreePackedContext();
Daniel Dunbar81c7d472008-10-14 05:35:18 +00001807
Chris Lattnere992d6c2008-01-16 19:17:22 +00001808 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
1809 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregor70d26122008-11-12 17:17:38 +00001810 /// If isLvalue, the result of the cast is an lvalue.
1811 void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
Chris Lattnere992d6c2008-01-16 19:17:22 +00001812
Chris Lattner4b009652007-07-25 00:24:17 +00001813 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner83bd5eb2007-12-28 05:29:59 +00001814 // functions and arrays to their respective pointers (C99 6.3.2.1).
1815 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman86ad5222008-05-27 03:33:27 +00001816
Chris Lattner4b009652007-07-25 00:24:17 +00001817 // DefaultFunctionArrayConversion - converts functions and arrays
1818 // to their respective pointers (C99 6.3.2.1).
1819 void DefaultFunctionArrayConversion(Expr *&expr);
1820
Steve Naroffdb65e052007-08-28 23:30:39 +00001821 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
1822 // do not have a prototype. Integer promotions are performed on each
1823 // argument, and arguments that have type float are promoted to double.
Chris Lattner83bd5eb2007-12-28 05:29:59 +00001824 void DefaultArgumentPromotion(Expr *&Expr);
Anders Carlsson4b8e38c2009-01-16 16:48:51 +00001825
1826 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
1827 enum VariadicCallType {
1828 VariadicFunction,
1829 VariadicBlock,
1830 VariadicMethod
1831 };
1832
1833 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
1834 // will warn if the resulting type is not a POD type.
1835 void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
Steve Naroffdb65e052007-08-28 23:30:39 +00001836
Chris Lattner4b009652007-07-25 00:24:17 +00001837 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
1838 // operands and then handles various conversions that are common to binary
1839 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
1840 // routine returns the first non-arithmetic type found. The client is
1841 // responsible for emitting appropriate error diagnostics.
Steve Naroff8f708362007-08-24 19:07:16 +00001842 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
1843 bool isCompAssign = false);
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001844
Douglas Gregor70d26122008-11-12 17:17:38 +00001845 /// UsualArithmeticConversionsType - handles the various conversions
1846 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
1847 /// and returns the result type of that conversion.
1848 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
1849
1850
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001851 /// AssignConvertType - All of the 'assignment' semantic checks return this
1852 /// enum to indicate whether the assignment was allowed. These checks are
1853 /// done for simple assignments, as well as initialization, return from
1854 /// function, argument passing, etc. The query is phrased in terms of a
1855 /// source and destination type.
Chris Lattner005ed752008-01-04 18:04:52 +00001856 enum AssignConvertType {
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001857 /// Compatible - the types are compatible according to the standard.
Chris Lattner4b009652007-07-25 00:24:17 +00001858 Compatible,
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001859
1860 /// PointerToInt - The assignment converts a pointer to an int, which we
1861 /// accept as an extension.
1862 PointerToInt,
1863
1864 /// IntToPointer - The assignment converts an int to a pointer, which we
1865 /// accept as an extension.
1866 IntToPointer,
1867
1868 /// FunctionVoidPointer - The assignment is between a function pointer and
1869 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattner4ca3d772008-01-03 22:56:36 +00001870 FunctionVoidPointer,
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001871
1872 /// IncompatiblePointer - The assignment is between two pointers types that
1873 /// are not compatible, but we accept them as an extension.
Chris Lattner4b009652007-07-25 00:24:17 +00001874 IncompatiblePointer,
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001875
1876 /// CompatiblePointerDiscardsQualifiers - The assignment discards
1877 /// c/v/r qualifiers, which we accept as an extension.
1878 CompatiblePointerDiscardsQualifiers,
Steve Naroff3454b6c2008-09-04 15:10:53 +00001879
Anders Carlsson355ed052009-01-30 23:17:46 +00001880 /// IncompatibleVectors - The assignment is between two vector types that
1881 /// have the same size, which we accept as an extension.
1882 IncompatibleVectors,
1883
Steve Naroff6f373332008-09-04 15:31:07 +00001884 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff3454b6c2008-09-04 15:10:53 +00001885 /// pointer. We disallow this.
1886 IntToBlockPointer,
1887
Steve Naroff6f373332008-09-04 15:31:07 +00001888 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff3454b6c2008-09-04 15:10:53 +00001889 /// pointers types that are not compatible.
1890 IncompatibleBlockPointer,
1891
Steve Naroff19608432008-10-14 22:18:38 +00001892 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
1893 /// id type and something else (that is incompatible with it). For example,
1894 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
1895 IncompatibleObjCQualifiedId,
1896
Chris Lattnerd951b7b2008-01-04 18:22:42 +00001897 /// Incompatible - We reject this conversion outright, it is invalid to
1898 /// represent it in the AST.
1899 Incompatible
Chris Lattner4b009652007-07-25 00:24:17 +00001900 };
Chris Lattner005ed752008-01-04 18:04:52 +00001901
1902 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
1903 /// assignment conversion type specified by ConvTy. This returns true if the
1904 /// conversion was invalid or false if the conversion was accepted.
1905 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
1906 SourceLocation Loc,
1907 QualType DstType, QualType SrcType,
1908 Expr *SrcExpr, const char *Flavor);
1909
1910 /// CheckAssignmentConstraints - Perform type checking for assignment,
1911 /// argument passing, variable initialization, and function return values.
1912 /// This routine is only used by the following two methods. C99 6.5.16.
1913 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Chris Lattner4b009652007-07-25 00:24:17 +00001914
Steve Naroff87d58b42007-09-16 03:34:24 +00001915 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001916 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Chris Lattner4b009652007-07-25 00:24:17 +00001917 // this routine performs the default function/array converions.
Chris Lattner005ed752008-01-04 18:04:52 +00001918 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
1919 Expr *&rExpr);
Chris Lattner4b009652007-07-25 00:24:17 +00001920 // CheckCompoundAssignmentConstraints - Type check without performing any
1921 // conversions. For compound assignments, the "Check...Operands" methods
1922 // perform the necessary conversions.
Chris Lattner005ed752008-01-04 18:04:52 +00001923 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
1924 QualType rhs);
Chris Lattner4b009652007-07-25 00:24:17 +00001925
1926 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner005ed752008-01-04 18:04:52 +00001927 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
1928 QualType rhsType);
Steve Naroff3454b6c2008-09-04 15:10:53 +00001929
1930 // Helper function for CheckAssignmentConstraints involving two
1931 // blcok pointer types.
1932 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
1933 QualType rhsType);
Douglas Gregor1815b3b2008-09-12 00:47:35 +00001934
1935 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregorbb461502008-10-24 04:54:22 +00001936
Douglas Gregor6fd35572008-12-19 17:40:08 +00001937 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +00001938 const char *Flavor, bool AllowExplicit = false);
1939 bool PerformImplicitConversion(Expr *&From, QualType ToType,
1940 const ImplicitConversionSequence& ICS,
Douglas Gregor6fd35572008-12-19 17:40:08 +00001941 const char *Flavor);
Douglas Gregorbb461502008-10-24 04:54:22 +00001942 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor6fd35572008-12-19 17:40:08 +00001943 const StandardConversionSequence& SCS,
1944 const char *Flavor);
Sebastian Redl95216a62009-02-07 00:15:38 +00001945
Chris Lattner4b009652007-07-25 00:24:17 +00001946 /// the following "Check" methods will return a valid/converted QualType
1947 /// or a null QualType (indicating an error diagnostic was issued).
Sebastian Redl95216a62009-02-07 00:15:38 +00001948
1949 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
Chris Lattner2c8bff72007-12-12 05:47:28 +00001950 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Sebastian Redlaa4c3732009-02-07 20:10:22 +00001951 QualType CheckPointerToMemberOperands( // C++ 5.5
Sebastian Redl95216a62009-02-07 00:15:38 +00001952 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
Chris Lattner4b009652007-07-25 00:24:17 +00001953 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Sebastian Redl95216a62009-02-07 00:15:38 +00001954 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +00001955 inline QualType CheckRemainderOperands( // C99 6.5.5
Sebastian Redl95216a62009-02-07 00:15:38 +00001956 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +00001957 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +00001958 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +00001959 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +00001960 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +00001961 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff8f708362007-08-24 19:07:16 +00001962 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner254f3bc2007-08-26 01:18:55 +00001963 inline QualType CheckCompareOperands( // C99 6.5.8/9
1964 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Chris Lattner4b009652007-07-25 00:24:17 +00001965 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Sebastian Redl95216a62009-02-07 00:15:38 +00001966 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +00001967 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
1968 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
1969 // CheckAssignmentOperands is used for both simple and compound assignment.
1970 // For simple assignment, pass both expressions and a null converted type.
1971 // For compound assignment, pass both expressions and the converted type.
1972 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0f32f432007-08-24 22:33:52 +00001973 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Chris Lattner4b009652007-07-25 00:24:17 +00001974 inline QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner1eafdea2008-11-18 01:30:42 +00001975 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Chris Lattner4b009652007-07-25 00:24:17 +00001976 inline QualType CheckConditionalOperands( // C99 6.5.15
1977 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begemanc5f0f652008-07-14 18:02:46 +00001978
1979 /// type checking for vector binary operators.
1980 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
1981 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
1982 SourceLocation l, bool isRel);
Chris Lattner4b009652007-07-25 00:24:17 +00001983
Steve Naroff87d58b42007-09-16 03:34:24 +00001984 /// type checking unary operators (subroutines of ActOnUnaryOp).
Chris Lattner4b009652007-07-25 00:24:17 +00001985 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redl0440c8c2008-12-20 09:35:34 +00001986 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
1987 bool isInc);
Chris Lattner4b009652007-07-25 00:24:17 +00001988 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
1989 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattner57e5f7e2009-02-17 08:12:06 +00001990 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
Steve Naroff1b8a46c2007-07-27 22:15:19 +00001991
1992 /// type checking primary expressions.
Nate Begemanaf6ed502008-04-18 23:10:10 +00001993 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Naroff1b8a46c2007-07-27 22:15:19 +00001994 IdentifierInfo &Comp, SourceLocation CmpLoc);
1995
Steve Naroffe14e5542007-09-02 02:04:30 +00001996 /// type checking declaration initializers (C99 6.7.8)
Douglas Gregor6428e762008-11-05 15:29:30 +00001997 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +00001998 SourceLocation InitLoc,DeclarationName InitEntity,
1999 bool DirectInit);
Douglas Gregor849afc32009-01-29 00:45:39 +00002000 bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
Steve Narofff0b23542008-01-10 22:15:12 +00002001 bool CheckForConstantInitializer(Expr *e, QualType t);
Steve Naroffcb69fb72007-12-10 22:44:33 +00002002
Douglas Gregor538a4c22009-02-02 17:43:21 +00002003 bool CheckValueInitialization(QualType Type, SourceLocation Loc);
Argiris Kirtzidis95de23a2008-08-16 20:27:34 +00002004
Douglas Gregor81c29152008-10-29 00:13:59 +00002005 // type checking C++ declaration initializers (C++ [dcl.init]).
2006
2007 /// ReferenceCompareResult - Expresses the result of comparing two
2008 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
2009 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
2010 enum ReferenceCompareResult {
2011 /// Ref_Incompatible - The two types are incompatible, so direct
2012 /// reference binding is not possible.
2013 Ref_Incompatible = 0,
2014 /// Ref_Related - The two types are reference-related, which means
2015 /// that their unqualified forms (T1 and T2) are either the same
2016 /// or T1 is a base class of T2.
2017 Ref_Related,
2018 /// Ref_Compatible_With_Added_Qualification - The two types are
2019 /// reference-compatible with added qualification, meaning that
2020 /// they are reference-compatible and the qualifiers on T1 (cv1)
2021 /// are greater than the qualifiers on T2 (cv2).
2022 Ref_Compatible_With_Added_Qualification,
2023 /// Ref_Compatible - The two types are reference-compatible and
2024 /// have equivalent qualifiers (cv1 == cv2).
2025 Ref_Compatible
2026 };
2027
Douglas Gregor2aecd1f2008-10-29 02:00:59 +00002028 ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
2029 bool& DerivedToBase);
Douglas Gregor81c29152008-10-29 00:13:59 +00002030
2031 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregora3b34bb2008-11-03 19:09:14 +00002032 ImplicitConversionSequence *ICS = 0,
Douglas Gregor6214d8a2009-01-14 15:45:31 +00002033 bool SuppressUserConversions = false,
2034 bool AllowExplicit = false);
Douglas Gregor81c29152008-10-29 00:13:59 +00002035
Argiris Kirtzidis95de23a2008-08-16 20:27:34 +00002036 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar5ad49de2008-08-20 03:55:42 +00002037 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroff0d4e6ad2008-01-22 00:55:40 +00002038
Anders Carlsson74375622007-11-27 07:16:40 +00002039 // CheckVectorCast - check type constraints for vectors.
2040 // Since vectors are an extension, there are no C standard reference for this.
2041 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssonf257b4c2007-11-27 05:51:55 +00002042 // returns true if the cast is invalid
2043 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
2044
Daniel Dunbar842b5e22008-09-11 00:01:56 +00002045 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
2046 /// \param Method - May be null.
2047 /// \param [out] ReturnType - The return type of the send.
2048 /// \return true iff there were any incompatible types.
Daniel Dunbar7776e102008-09-11 00:50:25 +00002049 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattner3a8f2942008-11-24 03:33:13 +00002050 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbar842b5e22008-09-11 00:01:56 +00002051 SourceLocation lbrac, SourceLocation rbrac,
2052 QualType &ReturnType);
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +00002053
2054 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
2055 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff52664182007-10-16 23:12:48 +00002056
Chris Lattner3429a812007-08-23 05:46:52 +00002057 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
2058 /// the specified width and sign. If an overflow occurs, detect it and emit
2059 /// the specified diagnostic.
2060 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
2061 unsigned NewWidth, bool NewSign,
2062 SourceLocation Loc, unsigned DiagID);
2063
Chris Lattnerfe1f4032008-04-07 05:30:13 +00002064 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
2065 bool ForCompare);
2066
Anders Carlsson0a6ab172008-11-04 16:57:32 +00002067 /// Checks that the Objective-C declaration is declared in the global scope.
2068 /// Emits an error and marks the declaration as invalid if it's not declared
2069 /// in the global scope.
2070 bool CheckObjCDeclScope(Decl *D);
2071
Anders Carlsson36760332007-10-15 20:28:48 +00002072 void InitBuiltinVaListType();
Eli Friedman48fb3ee2008-06-03 21:01:11 +00002073
Anders Carlssond5201b92008-11-30 19:50:32 +00002074 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
2075 /// and reports the appropriate diagnostics. Returns false on success.
2076 /// Can optionally return the value of the expression.
Anders Carlsson108229a2008-12-06 20:33:04 +00002077 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson511425a2008-12-01 02:17:22 +00002078
Anders Carlsson108229a2008-12-06 20:33:04 +00002079 /// VerifyBitField - verifies that a bit field expression is an ICE and has
2080 /// the correct width, and that the field type is valid.
2081 /// Returns false on success.
2082 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
2083 QualType FieldTy, const Expr *BitWidth);
Sebastian Redl8b769972009-01-19 00:08:26 +00002084
Chris Lattner2e64c072007-08-10 20:18:51 +00002085 //===--------------------------------------------------------------------===//
2086 // Extra semantic analysis beyond the C type system
Chris Lattner83bd5eb2007-12-28 05:29:59 +00002087private:
Sebastian Redl8b769972009-01-19 00:08:26 +00002088 Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl,
2089 CallExpr *TheCall);
Chris Lattnerf17cb362009-02-18 17:49:48 +00002090 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
2091 unsigned ByteNo) const;
Chris Lattner81f5be22009-02-18 06:01:06 +00002092 bool CheckObjCString(Expr *Arg);
Chris Lattner83bd5eb2007-12-28 05:29:59 +00002093 bool SemaBuiltinVAStart(CallExpr *TheCall);
2094 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedman8c50c622008-05-20 08:23:37 +00002095 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Sebastian Redl8b769972009-01-19 00:08:26 +00002096 Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbar5b0de852008-07-21 22:59:13 +00002097 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbar30ad42d2008-09-03 21:13:56 +00002098 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Ted Kremenek8c797c02009-01-12 23:09:09 +00002099 bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg,
Douglas Gregorb5af7382009-02-14 18:57:46 +00002100 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek8c797c02009-01-12 23:09:09 +00002101 void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr,
2102 CallExpr *TheCall, bool HasVAListArg,
Douglas Gregorb5af7382009-02-14 18:57:46 +00002103 unsigned format_idx, unsigned firstDataArg);
2104 void CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
2105 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek45925ab2007-08-17 16:46:58 +00002106 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
2107 SourceLocation ReturnLoc);
Ted Kremenek30c66752007-11-25 00:58:00 +00002108 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Chris Lattner4b009652007-07-25 00:24:17 +00002109};
2110
Steve Naroff52a81c02008-09-03 18:15:37 +00002111/// BlockSemaInfo - When a block is being parsed, this contains information
2112/// about the block. It is pointed to from Sema::CurBlock.
2113struct BlockSemaInfo {
2114 llvm::SmallVector<ParmVarDecl*, 8> Params;
Steve Naroff52a81c02008-09-03 18:15:37 +00002115 bool hasPrototype;
2116 bool isVariadic;
Mike Stumpae93d652009-02-19 22:01:56 +00002117 bool hasBlockDeclRefExprs;
2118
Steve Naroff95029d92008-10-08 18:44:00 +00002119 BlockDecl *TheDecl;
2120
Chris Lattner1f9e60f2009-02-18 07:09:44 +00002121 /// TheScope - This is the scope for the block itself, which contains
Steve Naroff52a81c02008-09-03 18:15:37 +00002122 /// arguments etc.
2123 Scope *TheScope;
2124
2125 /// ReturnType - This will get set to block result type, by looking at
2126 /// return types, if any, in the block body.
2127 Type *ReturnType;
2128
2129 /// PrevBlockInfo - If this is nested inside another block, this points
2130 /// to the outer block.
2131 BlockSemaInfo *PrevBlockInfo;
2132};
Ted Kremenek0c97e042009-02-07 01:47:29 +00002133
2134//===--------------------------------------------------------------------===//
2135// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
2136template <typename T>
2137class ExprOwningPtr : public Action::ExprArg {
2138public:
2139 ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {};
2140
2141 void reset(T* p) { Action::ExprArg::operator=(p); }
2142 T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
2143 T* take() { return static_cast<T*>(Action::ExprArg::take()); }
2144 T* release() { return take(); }
2145
2146 T& operator*() const { return *get(); }
2147 T* operator->() const { return get(); }
2148};
2149
Chris Lattner4b009652007-07-25 00:24:17 +00002150} // end namespace clang
2151
2152#endif